@use-kona/editor 0.1.20 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/dist/editor.js +15 -0
  2. package/dist/plugins/DnDPlugin/DnDPlugin.js +35 -26
  3. package/dist/plugins/ListsPlugin/ListsPlugin.js +15 -39
  4. package/dist/plugins/ListsPlugin/styles_module.css +1 -0
  5. package/dist/plugins/TableOfContentsPlugin/TableOfContentsPlugin.js +2 -2
  6. package/dist/{plugins → src/plugins}/CodeBlockPlugin/CodeBlockPlugin.d.ts +1 -2
  7. package/dist/{plugins → src/plugins}/HeadingsPlugin/HeadingsPlugin.d.ts +1 -1
  8. package/dist/{plugins → src/plugins}/LinksPlugin/LinksPlugin.d.ts +1 -1
  9. package/dist/{plugins → src/plugins}/ListsPlugin/ListsPlugin.d.ts +1 -3
  10. package/dist/src/plugins/MenuPlugin/MenuPlugin.d.ts +7 -0
  11. package/dist/src/types.d.ts +60 -0
  12. package/dist/types.d.ts +5 -57
  13. package/dist/utils.js +1 -1
  14. package/package.json +11 -11
  15. package/src/editor.tsx +16 -0
  16. package/src/plugins/DnDPlugin/DnDPlugin.tsx +45 -35
  17. package/src/plugins/ListsPlugin/ListsPlugin.spec.tsx +166 -6
  18. package/src/plugins/ListsPlugin/ListsPlugin.tsx +27 -63
  19. package/src/plugins/ListsPlugin/styles.module.css +1 -0
  20. package/src/plugins/TableOfContentsPlugin/TableOfContentsPlugin.tsx +2 -2
  21. package/src/types.ts +2 -0
  22. package/src/utils.ts +4 -2
  23. package/LICENSE +0 -21
  24. package/dist/plugins/CommandsPlugin/resolveCommands.spec.d.ts +0 -1
  25. package/dist/plugins/CommandsPlugin/resolveCommands.spec.js +0 -323
  26. package/dist/plugins/ListsPlugin/ListsPlugin.spec.d.ts +0 -3
  27. package/dist/plugins/ListsPlugin/ListsPlugin.spec.js +0 -47
  28. package/dist/plugins/MenuPlugin/MenuPlugin.d.ts +0 -7
  29. /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
  30. /package/dist/{core → src/core}/createEditable.d.ts +0 -0
  31. /package/dist/{core → src/core}/createEditor.d.ts +0 -0
  32. /package/dist/{core → src/core}/deserialize.d.ts +0 -0
  33. /package/dist/{core → src/core}/queries.d.ts +0 -0
  34. /package/dist/{core → src/core}/serialize.d.ts +0 -0
  35. /package/dist/{defaultValue.d.ts → src/defaultValue.d.ts} +0 -0
  36. /package/dist/{editor.d.ts → src/editor.d.ts} +0 -0
  37. /package/dist/{elements → src/elements}/BaseElement.d.ts +0 -0
  38. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  39. /package/dist/{plugins → src/plugins}/AttachmentsPlugin/AttachmentsPlugin.d.ts +0 -0
  40. /package/dist/{plugins → src/plugins}/AttachmentsPlugin/index.d.ts +0 -0
  41. /package/dist/{plugins → src/plugins}/AttachmentsPlugin/types.d.ts +0 -0
  42. /package/dist/{plugins → src/plugins}/BasicFormattingPlugin/BasicFormattingPlugin.d.ts +0 -0
  43. /package/dist/{plugins → src/plugins}/BasicFormattingPlugin/index.d.ts +0 -0
  44. /package/dist/{plugins → src/plugins}/BreaksPlugin/BreaksPlugin.d.ts +0 -0
  45. /package/dist/{plugins → src/plugins}/BreaksPlugin/index.d.ts +0 -0
  46. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/CodeBlock.d.ts +0 -0
  47. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/CodeBlockLine.d.ts +0 -0
  48. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/index.d.ts +0 -0
  49. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/types.d.ts +0 -0
  50. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/utils.d.ts +0 -0
  51. /package/dist/{plugins → src/plugins}/CommandsPlugin/CommandsPlugin.d.ts +0 -0
  52. /package/dist/{plugins → src/plugins}/CommandsPlugin/Menu.d.ts +0 -0
  53. /package/dist/{plugins → src/plugins}/CommandsPlugin/actions.d.ts +0 -0
  54. /package/dist/{plugins → src/plugins}/CommandsPlugin/index.d.ts +0 -0
  55. /package/dist/{plugins → src/plugins}/CommandsPlugin/resolveCommands.d.ts +0 -0
  56. /package/dist/{plugins → src/plugins}/CommandsPlugin/types.d.ts +0 -0
  57. /package/dist/{plugins → src/plugins}/CommandsPlugin/useResolvedCommands.d.ts +0 -0
  58. /package/dist/{plugins → src/plugins}/DnDPlugin/DnDPlugin.d.ts +0 -0
  59. /package/dist/{plugins → src/plugins}/DnDPlugin/index.d.ts +0 -0
  60. /package/dist/{plugins → src/plugins}/EmojiPlugin/EmojiPlugin.d.ts +0 -0
  61. /package/dist/{plugins → src/plugins}/EmojiPlugin/Menu.d.ts +0 -0
  62. /package/dist/{plugins → src/plugins}/EmojiPlugin/index.d.ts +0 -0
  63. /package/dist/{plugins → src/plugins}/EmojiPlugin/types.d.ts +0 -0
  64. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/FloatingMenu.d.ts +0 -0
  65. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/FloatingMenuPlugin.d.ts +0 -0
  66. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/index.d.ts +0 -0
  67. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/types.d.ts +0 -0
  68. /package/dist/{plugins → src/plugins}/HeadingsPlugin/index.d.ts +0 -0
  69. /package/dist/{plugins → src/plugins}/HighlightsPlugin/HighlightsPlugin.d.ts +0 -0
  70. /package/dist/{plugins → src/plugins}/HighlightsPlugin/index.d.ts +0 -0
  71. /package/dist/{plugins → src/plugins}/LinksPlugin/Link.d.ts +0 -0
  72. /package/dist/{plugins → src/plugins}/LinksPlugin/constants.d.ts +0 -0
  73. /package/dist/{plugins → src/plugins}/LinksPlugin/index.d.ts +0 -0
  74. /package/dist/{plugins → src/plugins}/LinksPlugin/types.d.ts +0 -0
  75. /package/dist/{plugins → src/plugins}/ListsPlugin/index.d.ts +0 -0
  76. /package/dist/{plugins → src/plugins}/MenuPlugin/Menu.d.ts +0 -0
  77. /package/dist/{plugins → src/plugins}/MenuPlugin/index.d.ts +0 -0
  78. /package/dist/{plugins → src/plugins}/MenuPlugin/types.d.ts +0 -0
  79. /package/dist/{plugins → src/plugins}/NodeIdPlugin/NodeIdPlugin.d.ts +0 -0
  80. /package/dist/{plugins → src/plugins}/NodeIdPlugin/index.d.ts +0 -0
  81. /package/dist/{plugins → src/plugins}/PlaceholderPlugin/PlaceholderPlugin.d.ts +0 -0
  82. /package/dist/{plugins → src/plugins}/PlaceholderPlugin/index.d.ts +0 -0
  83. /package/dist/{plugins → src/plugins}/ShortcutsPlugin/ShortcutsPlugin.d.ts +0 -0
  84. /package/dist/{plugins → src/plugins}/ShortcutsPlugin/index.d.ts +0 -0
  85. /package/dist/{plugins → src/plugins}/TableOfContentsPlugin/TableOfContentsPlugin.d.ts +0 -0
  86. /package/dist/{plugins → src/plugins}/TableOfContentsPlugin/index.d.ts +0 -0
  87. /package/dist/{plugins → src/plugins}/index.d.ts +0 -0
  88. /package/dist/{queries → src/queries}/getMatchedGroups.d.ts +0 -0
  89. /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { useStore } from '@nanostores/react';
2
2
  import { type MapStore, map } from 'nanostores';
3
3
  import type React from 'react';
4
- import { useEffect, useState } from 'react';
4
+ import { useEffect, useRef, useState } from 'react';
5
5
  import {
6
6
  type ConnectDragPreview,
7
7
  type ConnectDragSource,
@@ -92,15 +92,21 @@ export class DnDPlugin implements IPlugin {
92
92
  null,
93
93
  );
94
94
 
95
+ const dropTargetRef = useRef<HTMLElement | null>(null);
96
+
95
97
  const customType = options.customTypes?.[props.element.type];
96
98
  const currentElement = props.element as DnDNode;
97
99
 
100
+ const selected = Array.from($store.selected.values());
101
+
98
102
  const [, drag, preview] = useDrag({
99
103
  type: customType?.type || DnDPlugin.DND_BLOCK_ELEMENT,
100
104
  item: {
101
105
  ...(customType?.getData?.(props.element) || {}),
102
106
  element: props.element,
103
- nodeIds: Array.from($store.selected.values()),
107
+ nodeIds: currentElement?.nodeId && selected.includes(currentElement?.nodeId)
108
+ ? selected
109
+ : [currentElement?.nodeId],
104
110
  },
105
111
  ...(customType?.getDndItem?.(props.element) || {}),
106
112
  canDrag: !isReadOnly,
@@ -124,10 +130,7 @@ export class DnDPlugin implements IPlugin {
124
130
  };
125
131
  },
126
132
  hover(_, monitor) {
127
- const element = ReactEditor.toDOMNode(
128
- editor,
129
- props.element,
130
- ) as HTMLElement;
133
+ const element = dropTargetRef.current;
131
134
  if (!element) return;
132
135
 
133
136
  const hoverBoundingRect = element.getBoundingClientRect();
@@ -151,7 +154,7 @@ export class DnDPlugin implements IPlugin {
151
154
 
152
155
  if (!sourceTo) return;
153
156
 
154
- const dropPath = getDropPath(editor, sourceTo, dropPosition);
157
+ const dropPath = getDropPath(editor, sourceTo);
155
158
 
156
159
  if (!dropPath) return;
157
160
 
@@ -170,7 +173,8 @@ export class DnDPlugin implements IPlugin {
170
173
  return;
171
174
  }
172
175
 
173
- moveNode(editor, sourceTo, dragItem.nodeIds, dropPosition);
176
+ moveNode(editor, sourceTo, dragItem.nodeIds);
177
+ $store.selected.clear();
174
178
  break;
175
179
  }
176
180
  }
@@ -179,6 +183,11 @@ export class DnDPlugin implements IPlugin {
179
183
  },
180
184
  });
181
185
 
186
+ const connectDropRef: ConnectDropTarget = (el) => {
187
+ dropTargetRef.current = el as HTMLElement | null;
188
+ return drop(el);
189
+ };
190
+
182
191
  // biome-ignore lint/correctness/useExhaustiveDependencies: we care only about this dep
183
192
  useEffect(() => {
184
193
  setDropPosition(null);
@@ -195,7 +204,7 @@ export class DnDPlugin implements IPlugin {
195
204
  return options.renderBlock?.({
196
205
  props,
197
206
  dragRef: drag,
198
- dropRef: drop,
207
+ dropRef: connectDropRef,
199
208
  previewRef: preview,
200
209
  position: dropPosition,
201
210
  selected:
@@ -214,44 +223,45 @@ export class DnDPlugin implements IPlugin {
214
223
  const getDropPath = (
215
224
  editor: Editor,
216
225
  targetNodePath: Path,
217
- position: 'top' | 'bottom' | null,
218
226
  ) => {
219
227
  const target = Editor.node(editor, targetNodePath);
220
228
 
221
- switch (position) {
222
- case 'top':
223
- return target[1];
224
- case 'bottom':
225
- return Path.next(target[1]);
226
- }
229
+ return target[1];
227
230
  };
228
231
 
229
232
  const moveNode = (
230
233
  editor: Editor,
231
234
  targetNodePath: Path,
232
235
  nodeIds: string[],
233
- position: 'top' | 'bottom',
234
236
  ) => {
235
- const dropPath = getDropPath(editor, targetNodePath, position);
237
+ const dropPath = getDropPath(editor, targetNodePath);
236
238
 
237
239
  if (!dropPath) return;
240
+ if (!Editor.hasPath(editor, dropPath)) {
241
+ return
242
+ }
238
243
 
239
- // nodeIds.reverse().forEach((nodeId) => {
240
- Transforms.moveNodes(editor, {
241
- // at: sourceNodePath,
242
- at: [],
243
- match: (n) => {
244
- if (!Editor.isBlock(editor, n as CustomElement)) {
245
- return false;
246
- }
247
-
248
- const node = n as DnDNode;
249
- const shouldMove =
250
- typeof node.nodeId === 'string' && nodeIds.includes(node.nodeId);
251
- return shouldMove;
252
- },
253
- to: dropPath,
254
- mode: 'highest',
244
+ Editor.withoutNormalizing(editor, () => {
245
+ Transforms.moveNodes(editor, {
246
+ at: [],
247
+ match: (n) => {
248
+ if (!Editor.isBlock(editor, n as CustomElement)) {
249
+ return false;
250
+ }
251
+
252
+ if (Editor.isEditor(n)) {
253
+ return false;
254
+ }
255
+
256
+ const node = n as DnDNode;
257
+ const shouldMove =
258
+ typeof node.nodeId === 'string' && nodeIds.includes(node.nodeId);
259
+ return shouldMove;
260
+ },
261
+ to: dropPath,
262
+ mode: 'highest',
263
+ });
255
264
  });
256
- // });
265
+ Editor.normalize(editor);
266
+
257
267
  };
@@ -7,9 +7,11 @@ import {
7
7
  type HyperscriptShorthands,
8
8
  } from 'slate-hyperscript';
9
9
  import { describe, expect, it } from 'vitest';
10
+ import { Editor } from 'slate';
10
11
  import { createEditor } from '../../core/createEditor';
11
12
  import { ListsPlugin } from './ListsPlugin';
12
13
 
14
+
13
15
  const elements: HyperscriptShorthands = {
14
16
  paragraph: { type: 'paragraph' },
15
17
  numberedList: { type: ListsPlugin.NUMBERED_LIST_ELEMENT },
@@ -48,9 +50,6 @@ describe('ListsPlugin', () => {
48
50
  <text>Hello world</text>
49
51
  </listItem>
50
52
  </bulletedList>
51
- <paragraph>
52
- <text></text>
53
- </paragraph>
54
53
  </editor>
55
54
  );
56
55
 
@@ -74,12 +73,173 @@ describe('ListsPlugin', () => {
74
73
  <text>Hello world</text>
75
74
  </listItem>
76
75
  </numberedList>
77
- <paragraph>
78
- <text></text>
79
- </paragraph>
80
76
  </editor>
81
77
  );
82
78
 
83
79
  expect(editor.children).toEqual(output.children);
84
80
  });
81
+
82
+ it('should merge two adjacent bulleted lists during normalization', () => {
83
+ const editor = createEditorWithPlugin(
84
+ <paragraph>
85
+ <text />
86
+ </paragraph>,
87
+ );
88
+
89
+ editor.children = [
90
+ {
91
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
92
+ children: [
93
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'one' }] },
94
+ ],
95
+ },
96
+ {
97
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
98
+ children: [
99
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'two' }] },
100
+ ],
101
+ },
102
+ ];
103
+ editor.selection = null;
104
+
105
+ Editor.normalize(editor, { force: true });
106
+
107
+ const output = [
108
+ {
109
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
110
+ children: [
111
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'one' }] },
112
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'two' }] },
113
+ ],
114
+ },
115
+ ];
116
+
117
+ expect(editor.children).toEqual(output);
118
+ });
119
+
120
+ it('should merge two adjacent numbered lists during normalization', () => {
121
+ const editor = createEditorWithPlugin(
122
+ <paragraph>
123
+ <text />
124
+ </paragraph>,
125
+ );
126
+
127
+ editor.children = [
128
+ {
129
+ type: ListsPlugin.NUMBERED_LIST_ELEMENT,
130
+ children: [
131
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'first' }] },
132
+ ],
133
+ },
134
+ {
135
+ type: ListsPlugin.NUMBERED_LIST_ELEMENT,
136
+ children: [
137
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'second' }] },
138
+ ],
139
+ },
140
+ ];
141
+ editor.selection = null;
142
+
143
+ Editor.normalize(editor, { force: true });
144
+
145
+ const output = [
146
+ {
147
+ type: ListsPlugin.NUMBERED_LIST_ELEMENT,
148
+ children: [
149
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'first' }] },
150
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'second' }] },
151
+ ],
152
+ },
153
+ ];
154
+
155
+ expect(editor.children).toEqual(output);
156
+ });
157
+
158
+ it('should not merge lists of different types', () => {
159
+ const editor = createEditorWithPlugin(
160
+ <paragraph>
161
+ <text />
162
+ </paragraph>,
163
+ );
164
+
165
+ editor.children = [
166
+ {
167
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
168
+ children: [
169
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'bullet' }] },
170
+ ],
171
+ },
172
+ {
173
+ type: ListsPlugin.NUMBERED_LIST_ELEMENT,
174
+ children: [
175
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'number' }] },
176
+ ],
177
+ },
178
+ ];
179
+ editor.selection = null;
180
+
181
+ Editor.normalize(editor, { force: true });
182
+
183
+ const output = [
184
+ {
185
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
186
+ children: [
187
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'bullet' }] },
188
+ ],
189
+ },
190
+ {
191
+ type: ListsPlugin.NUMBERED_LIST_ELEMENT,
192
+ children: [
193
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: 'number' }] },
194
+ ],
195
+ },
196
+ ];
197
+
198
+ expect(editor.children).toEqual(output);
199
+ });
200
+
201
+ it('should merge multiple adjacent lists of same type', () => {
202
+ const editor = createEditorWithPlugin(
203
+ <paragraph>
204
+ <text />
205
+ </paragraph>,
206
+ );
207
+
208
+ editor.children = [
209
+ {
210
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
211
+ children: [
212
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: '1' }] },
213
+ ],
214
+ },
215
+ {
216
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
217
+ children: [
218
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: '2' }] },
219
+ ],
220
+ },
221
+ {
222
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
223
+ children: [
224
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: '3' }] },
225
+ ],
226
+ },
227
+ ];
228
+ editor.selection = null;
229
+
230
+ Editor.normalize(editor, { force: true });
231
+
232
+ const output = [
233
+ {
234
+ type: ListsPlugin.BULLETED_LIST_ELEMENT,
235
+ children: [
236
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: '1' }] },
237
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: '2' }] },
238
+ { type: ListsPlugin.LIST_ITEM_ELEMENT, children: [{ text: '3' }] },
239
+ ],
240
+ },
241
+ ];
242
+
243
+ expect(editor.children).toEqual(output);
244
+ });
85
245
  });
@@ -44,8 +44,15 @@ export class ListsPlugin implements IPlugin {
44
44
 
45
45
  editor.normalizeNode = (entry: NodeEntry) => {
46
46
  const [node, path] = entry;
47
- //
47
+
48
48
  if (this.isList(editor, node as CustomElement)) {
49
+ if ((node as CustomElement).children.length === 0) {
50
+ Transforms.removeNodes(editor, {
51
+ at: path,
52
+ });
53
+ return;
54
+ }
55
+
49
56
  /* Unwrap lists around non-list-items */
50
57
  for (const [child, childPath] of Array.from(
51
58
  Node.children(editor, path),
@@ -64,6 +71,7 @@ export class ListsPlugin implements IPlugin {
64
71
  }
65
72
  }
66
73
 
74
+ /* Wrap list items in list if they are not already wrapped */
67
75
  if (this.isListItem(editor, node as CustomElement)) {
68
76
  const parent = Editor.above(editor, {
69
77
  at: path,
@@ -87,39 +95,17 @@ export class ListsPlugin implements IPlugin {
87
95
  }
88
96
  }
89
97
 
90
- if (this.isList(editor, node as CustomElement)) {
91
- if (!Path.hasPrevious(path)) {
92
- normalizeNode(entry);
93
- return;
94
- }
95
-
96
- const prevListItemPath = Editor.before(editor, path, {
97
- unit: 'block',
98
- });
99
-
100
- const prevList =
101
- prevListItemPath &&
102
- Editor.above<CustomElement>(editor, {
103
- at: prevListItemPath,
104
- match: (n) => this.isList(editor, n as CustomElement),
105
- });
98
+ /* Merge adjacent lists */
99
+ if (this.isList(editor, node as CustomElement) && Path.hasPrevious(path)) {
100
+ const prevPath = Path.previous(path);
101
+ const prevNode = Node.get(editor, prevPath) as CustomElement;
106
102
 
107
- if (prevList) {
108
- const currentDepth = this.getListDepth(editor, path);
109
- const prevDepth = this.getListDepth(editor, prevList[1]);
110
-
111
- if (
112
- this.isList(editor, prevList[0] as CustomElement) &&
113
- currentDepth === prevDepth &&
114
- prevList[0].type === (node as CustomElement).type
115
- ) {
116
- try {
117
- Transforms.mergeNodes(editor, {
118
- at: path,
119
- match: (n) => this.isList(editor, n as CustomElement),
120
- });
121
- } catch (e) {}
122
- }
103
+ if (
104
+ this.isList(editor, prevNode) &&
105
+ prevNode.type === (node as CustomElement).type
106
+ ) {
107
+ Transforms.mergeNodes(editor, { at: path });
108
+ return;
123
109
  }
124
110
  }
125
111
 
@@ -424,22 +410,20 @@ export class ListsPlugin implements IPlugin {
424
410
  return;
425
411
  }
426
412
 
413
+ Transforms.setNodes(
414
+ editor,
415
+ { type: listItemType },
416
+ { at: nodes[0][1], split: true },
417
+ );
418
+
427
419
  Transforms.wrapNodes(
428
420
  editor,
429
421
  { type: listType, children: [] },
430
422
  {
431
- mode: 'highest',
432
- match: (n) => {
433
- return Element.isElement(n) && n.type === listItemType;
434
- },
423
+ at: nodes[0][1],
424
+ match: (n) => (n as CustomElement).type === listItemType,
435
425
  },
436
426
  );
437
-
438
- Transforms.setNodes(
439
- editor,
440
- { type: listItemType },
441
- { at: nodes[0][1], split: true },
442
- );
443
427
  }
444
428
  });
445
429
  };
@@ -464,26 +448,6 @@ export class ListsPlugin implements IPlugin {
464
448
  return 0;
465
449
  };
466
450
 
467
- private getListDepth = (editor: Editor, path?: Path) => {
468
- if (path) {
469
- const node = Node.get(editor, path) as CustomElement;
470
- if (!this.isList(editor, node)) {
471
- return 0;
472
- }
473
-
474
- let count = 0;
475
- let parent = Editor.parent(editor, path);
476
-
477
- while (parent && this.isList(editor, parent[0] as CustomElement)) {
478
- count++;
479
- parent = Editor.parent(editor, parent[1]);
480
- }
481
-
482
- return count;
483
- }
484
- return 0;
485
- };
486
-
487
451
  private getListItem = (editor: Editor, path?: Path) => {
488
452
  if (path) {
489
453
  const node = Node.get(editor, path) as CustomElement;
@@ -1,5 +1,6 @@
1
1
  .list {
2
2
  padding: 0;
3
+ margin: 0;
3
4
 
4
5
  & & {
5
6
  margin-left: 32px;
@@ -1,7 +1,7 @@
1
1
  import { useStore } from '@nanostores/react';
2
2
  import { type MapStore, map } from 'nanostores';
3
3
  import { type MouseEvent, useEffect } from 'react';
4
- import { Editor, type NodeEntry, Operation } from 'slate';
4
+ import { Editor, type NodeEntry, Operation, Text } from 'slate';
5
5
  import { ReactEditor } from 'slate-react';
6
6
  import type { CustomElement } from '../../../types';
7
7
  import type { IPlugin, UiParams } from '../../types';
@@ -87,7 +87,7 @@ export class TableOfContentsPlugin implements IPlugin {
87
87
  className={styles[`h${level}`]}
88
88
  onMouseDown={handleMouseDown}
89
89
  >
90
- {node.children[0].text}
90
+ {Text.isText(node.children[0]) ? node.children[0].text : ''}
91
91
  </div>
92
92
  );
93
93
  },
package/src/types.ts CHANGED
@@ -3,6 +3,7 @@ import type {
3
3
  DecoratedRange,
4
4
  Descendant,
5
5
  Editor,
6
+ Location,
6
7
  NodeEntry,
7
8
  NodeMatch,
8
9
  } from 'slate';
@@ -82,6 +83,7 @@ export type EditorRef = {
82
83
  deserialize: (
83
84
  element: HTMLElement,
84
85
  ) => (Descendant | string)[] | string | Descendant | null;
86
+ insertNodes: (nodes: Descendant[], at?: Location) => boolean;
85
87
  isEmpty: () => boolean;
86
88
  deleteNode: (match: NodeMatch<CustomElement>) => void;
87
89
  focus: (mode?: 'end') => void;
package/src/utils.ts CHANGED
@@ -7,8 +7,10 @@ export const isEmpty = (children: Descendant[]) => {
7
7
  return first.text.trim() === '';
8
8
  }
9
9
 
10
- if (children && children.length <= 1 && Text.isText(first?.children?.[0])) {
11
- return first.children.every((child) => child.text?.trim() === '');
10
+ if (children && children.length <= 1 && first && 'children' in first) {
11
+ return first.children.every(
12
+ (child) => Text.isText(child) && child.text?.trim() === '',
13
+ );
12
14
  }
13
15
 
14
16
  return false;
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Kona
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1 +0,0 @@
1
- export {};