Skip to content

Commit eb049e2

Browse files
committed
refactor: remove data-index on numbered list item serialization
1 parent ce882f1 commit eb049e2

File tree

6 files changed

+5
-74
lines changed

6 files changed

+5
-74
lines changed

packages/core/src/api/exporters/html/util/serializeBlocksExternalHTML.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ function serializeBlock<
193193
attr.name !== "data-node-view-wrapper" &&
194194
attr.name !== "data-node-type" &&
195195
attr.name !== "data-id" &&
196-
attr.name !== "data-index" &&
197196
attr.name !== "data-editable",
198197
);
199198

packages/core/src/api/exporters/html/util/serializeBlocksInternalHTML.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ function serializeBlock<
104104
editor: BlockNoteEditor<BSchema, I, S>,
105105
block: PartialBlock<BSchema, I, S>,
106106
serializer: DOMSerializer,
107-
listIndex: number,
108107
options?: { document?: Document },
109108
) {
110109
const BC_NODE = editor.pmSchema.nodes["blockContainer"];
@@ -125,18 +124,6 @@ function serializeBlock<
125124
const impl = editor.blockImplementations[block.type as any].implementation;
126125
const ret = impl.render?.call({}, { ...block, props } as any, editor as any);
127126

128-
if (block.type === "numberedListItem") {
129-
// This is a workaround to make sure there's a list index set.
130-
// Normally, this is set on the internal prosemirror nodes by the NumberedListIndexingPlugin,
131-
// but:
132-
// - (a) this information is not available on the Blocks passed to the serializer. (we only have access to BlockNote Blocks)
133-
// - (b) the NumberedListIndexingPlugin might not even have run, because we can manually call blocksToFullHTML
134-
// with blocks that are not part of the active document
135-
if (ret.dom instanceof HTMLElement) {
136-
ret.dom.setAttribute("data-index", listIndex.toString());
137-
}
138-
}
139-
140127
if (ret.contentDOM && block.content) {
141128
const ic = serializeInlineContentInternalHTML(
142129
editor,
@@ -198,20 +185,8 @@ function serializeBlocks<
198185
const doc = options?.document ?? document;
199186
const fragment = doc.createDocumentFragment();
200187

201-
let listIndex = 0;
202188
for (const block of blocks) {
203-
if (block.type === "numberedListItem") {
204-
listIndex++;
205-
} else {
206-
listIndex = 0;
207-
}
208-
const blockDOM = serializeBlock(
209-
editor,
210-
block,
211-
serializer,
212-
listIndex,
213-
options,
214-
);
189+
const blockDOM = serializeBlock(editor, block, serializer, options);
215190
fragment.appendChild(blockDOM);
216191
}
217192

packages/core/src/extensions/PreviousBlockType/PreviousBlockTypePlugin.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,6 @@ export class PreviousBlockTypePlugin extends BlockNoteExtension {
134134
currentTransactionOriginalOldBlockAttrs[node.node.attrs.id] =
135135
oldAttrs;
136136

137-
// Whenever a transaction is appended by the OrderedListItemIndexPlugin, it's given the metadata:
138-
// { "orderedListIndexing": true }
139-
// These appended transactions happen immediately after any transaction which causes ordered list item
140-
// indices to require updating, including those which trigger animations. Therefore, these animations are
141-
// immediately overridden when the PreviousBlockTypePlugin processes the appended transaction, despite only
142-
// the listItemIndex attribute changing. To solve this, oldAttrs must be edited for transactions with the
143-
// "orderedListIndexing" metadata, so the correct animation can be re-triggered.
144-
if (transaction.getMeta("numberedListIndexing")) {
145-
// If the block existed before the transaction, gets the attributes from before the previous transaction
146-
// (i.e. the transaction that caused list item indices to need updating).
147-
if (node.node.attrs.id in prev.prevTransactionOldBlockAttrs) {
148-
oldAttrs =
149-
prev.prevTransactionOldBlockAttrs[node.node.attrs.id];
150-
}
151-
152-
// Stops list item indices themselves being animated (looks smoother), unless the block's content type is
153-
// changing from a numbered list item to something else.
154-
if (newAttrs.type === "numberedListItem") {
155-
oldAttrs.index = newAttrs.index;
156-
}
157-
}
158-
159137
prev.currentTransactionOldBlockAttrs[node.node.attrs.id] =
160138
oldAttrs;
161139

packages/core/src/extensions/SuggestionMenu/SuggestionPlugin.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,6 @@ export class SuggestionMenuProseMirrorPlugin<
204204
_oldState,
205205
newState,
206206
): SuggestionPluginState => {
207-
// TODO: More clearly define which transactions should be ignored.
208-
if (transaction.getMeta("orderedListIndexing") !== undefined) {
209-
return prev;
210-
}
211-
212207
// Ignore transactions in code blocks.
213208
if (transaction.selection.$from.parent.type.spec.code) {
214209
return prev;

tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/lists/basic.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,14 @@
1515
</div>
1616
<div class="bn-block-outer" data-node-type="blockOuter" data-id="3">
1717
<div class="bn-block" data-node-type="blockContainer" data-id="3">
18-
<div
19-
class="bn-block-content"
20-
data-content-type="numberedListItem"
21-
data-index="1"
22-
>
18+
<div class="bn-block-content" data-content-type="numberedListItem">
2319
<p class="bn-inline-content">Numbered List Item 1</p>
2420
</div>
2521
</div>
2622
</div>
2723
<div class="bn-block-outer" data-node-type="blockOuter" data-id="4">
2824
<div class="bn-block" data-node-type="blockContainer" data-id="4">
29-
<div
30-
class="bn-block-content"
31-
data-content-type="numberedListItem"
32-
data-index="2"
33-
>
25+
<div class="bn-block-content" data-content-type="numberedListItem">
3426
<p class="bn-inline-content">Numbered List Item 2</p>
3527
</div>
3628
</div>

tests/src/unit/core/formatConversion/export/__snapshots__/blocknoteHTML/lists/nested.html

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,14 @@
1414
<div class="bn-block-group" data-node-type="blockGroup">
1515
<div class="bn-block-outer" data-node-type="blockOuter" data-id="3">
1616
<div class="bn-block" data-node-type="blockContainer" data-id="3">
17-
<div
18-
class="bn-block-content"
19-
data-content-type="numberedListItem"
20-
data-index="1"
21-
>
17+
<div class="bn-block-content" data-content-type="numberedListItem">
2218
<p class="bn-inline-content">Numbered List Item 1</p>
2319
</div>
2420
</div>
2521
</div>
2622
<div class="bn-block-outer" data-node-type="blockOuter" data-id="4">
2723
<div class="bn-block" data-node-type="blockContainer" data-id="4">
28-
<div
29-
class="bn-block-content"
30-
data-content-type="numberedListItem"
31-
data-index="2"
32-
>
24+
<div class="bn-block-content" data-content-type="numberedListItem">
3325
<p class="bn-inline-content">Numbered List Item 2</p>
3426
</div>
3527
<div class="bn-block-group" data-node-type="blockGroup">

0 commit comments

Comments
 (0)