Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/super-editor/src/extensions/block-node/block-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Plugin, PluginKey } from 'prosemirror-state';
import { ReplaceStep } from 'prosemirror-transform';
import { v4 as uuidv4 } from 'uuid';
import { Transaction } from 'prosemirror-state';

Check warning on line 6 in packages/super-editor/src/extensions/block-node/block-node.js

View workflow job for this annotation

GitHub Actions / validate

'Transaction' is defined but never used. Allowed unused vars must match /^_/u

const { findChildren } = helpers;
const SD_BLOCK_ID_ATTRIBUTE_NAME = 'sdBlockId';
Expand Down Expand Up @@ -122,13 +123,12 @@
// Check for new block nodes and if none found, we don't need to do anything
if (hasInitialized && !checkForNewBlockNodesInTrs(transactions)) return null;

let tr = null;
const { tr } = newState;
let changed = false;
newState.doc.descendants((node, pos) => {
// Only allow block nodes with a valid sdBlockId attribute
if (!nodeAllowsSdBlockIdAttr(node) || !nodeNeedsSdBlockId(node)) return null;

tr = tr ?? newState.tr;
tr.setNodeMarkup(
pos,
undefined,
Expand All @@ -141,7 +141,14 @@
changed = true;
});

if (changed && !hasInitialized) hasInitialized = true;
if (changed && !hasInitialized) {
hasInitialized = true;
}

// Restore marks if they exist.
// `tr.setNodeMarkup` resets the stored marks.
tr.setStoredMarks(newState.tr.storedMarks);

return changed ? tr : null;
},
}),
Expand Down Expand Up @@ -171,7 +178,8 @@
/**
* Check for new block nodes in ProseMirror transactions.
* Iterate through the list of transactions, and in each tr check if there are any new block nodes.
* @param {Array<Transaction>} transactions - The ProseMirror transactions to check.
* @readonly
* @param {readonly Transaction[]} transactions - The ProseMirror transactions to check.
* @returns {boolean} - True if new block nodes are found, false otherwise.
*/
export const checkForNewBlockNodesInTrs = (transactions) => {
Expand Down
Loading