@use-kona/editor 0.1.21 → 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 (86) hide show
  1. package/dist/plugins/DnDPlugin/DnDPlugin.js +35 -26
  2. package/dist/plugins/ListsPlugin/ListsPlugin.js +15 -39
  3. package/dist/plugins/ListsPlugin/styles_module.css +1 -0
  4. package/dist/plugins/TableOfContentsPlugin/TableOfContentsPlugin.js +2 -2
  5. package/dist/{plugins → src/plugins}/CodeBlockPlugin/CodeBlockPlugin.d.ts +1 -2
  6. package/dist/{plugins → src/plugins}/HeadingsPlugin/HeadingsPlugin.d.ts +1 -1
  7. package/dist/{plugins → src/plugins}/LinksPlugin/LinksPlugin.d.ts +1 -1
  8. package/dist/{plugins → src/plugins}/ListsPlugin/ListsPlugin.d.ts +1 -3
  9. package/dist/src/plugins/MenuPlugin/MenuPlugin.d.ts +7 -0
  10. package/dist/src/types.d.ts +60 -0
  11. package/dist/types.d.ts +5 -58
  12. package/dist/utils.js +1 -1
  13. package/package.json +11 -11
  14. package/src/plugins/DnDPlugin/DnDPlugin.tsx +45 -35
  15. package/src/plugins/ListsPlugin/ListsPlugin.spec.tsx +166 -6
  16. package/src/plugins/ListsPlugin/ListsPlugin.tsx +27 -63
  17. package/src/plugins/ListsPlugin/styles.module.css +1 -0
  18. package/src/plugins/TableOfContentsPlugin/TableOfContentsPlugin.tsx +2 -2
  19. package/src/utils.ts +4 -2
  20. package/LICENSE +0 -21
  21. package/dist/plugins/CommandsPlugin/resolveCommands.spec.d.ts +0 -1
  22. package/dist/plugins/CommandsPlugin/resolveCommands.spec.js +0 -323
  23. package/dist/plugins/ListsPlugin/ListsPlugin.spec.d.ts +0 -3
  24. package/dist/plugins/ListsPlugin/ListsPlugin.spec.js +0 -47
  25. package/dist/plugins/MenuPlugin/MenuPlugin.d.ts +0 -7
  26. /package/dist/{constants.d.ts → src/constants.d.ts} +0 -0
  27. /package/dist/{core → src/core}/createEditable.d.ts +0 -0
  28. /package/dist/{core → src/core}/createEditor.d.ts +0 -0
  29. /package/dist/{core → src/core}/deserialize.d.ts +0 -0
  30. /package/dist/{core → src/core}/queries.d.ts +0 -0
  31. /package/dist/{core → src/core}/serialize.d.ts +0 -0
  32. /package/dist/{defaultValue.d.ts → src/defaultValue.d.ts} +0 -0
  33. /package/dist/{editor.d.ts → src/editor.d.ts} +0 -0
  34. /package/dist/{elements → src/elements}/BaseElement.d.ts +0 -0
  35. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  36. /package/dist/{plugins → src/plugins}/AttachmentsPlugin/AttachmentsPlugin.d.ts +0 -0
  37. /package/dist/{plugins → src/plugins}/AttachmentsPlugin/index.d.ts +0 -0
  38. /package/dist/{plugins → src/plugins}/AttachmentsPlugin/types.d.ts +0 -0
  39. /package/dist/{plugins → src/plugins}/BasicFormattingPlugin/BasicFormattingPlugin.d.ts +0 -0
  40. /package/dist/{plugins → src/plugins}/BasicFormattingPlugin/index.d.ts +0 -0
  41. /package/dist/{plugins → src/plugins}/BreaksPlugin/BreaksPlugin.d.ts +0 -0
  42. /package/dist/{plugins → src/plugins}/BreaksPlugin/index.d.ts +0 -0
  43. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/CodeBlock.d.ts +0 -0
  44. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/CodeBlockLine.d.ts +0 -0
  45. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/index.d.ts +0 -0
  46. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/types.d.ts +0 -0
  47. /package/dist/{plugins → src/plugins}/CodeBlockPlugin/utils.d.ts +0 -0
  48. /package/dist/{plugins → src/plugins}/CommandsPlugin/CommandsPlugin.d.ts +0 -0
  49. /package/dist/{plugins → src/plugins}/CommandsPlugin/Menu.d.ts +0 -0
  50. /package/dist/{plugins → src/plugins}/CommandsPlugin/actions.d.ts +0 -0
  51. /package/dist/{plugins → src/plugins}/CommandsPlugin/index.d.ts +0 -0
  52. /package/dist/{plugins → src/plugins}/CommandsPlugin/resolveCommands.d.ts +0 -0
  53. /package/dist/{plugins → src/plugins}/CommandsPlugin/types.d.ts +0 -0
  54. /package/dist/{plugins → src/plugins}/CommandsPlugin/useResolvedCommands.d.ts +0 -0
  55. /package/dist/{plugins → src/plugins}/DnDPlugin/DnDPlugin.d.ts +0 -0
  56. /package/dist/{plugins → src/plugins}/DnDPlugin/index.d.ts +0 -0
  57. /package/dist/{plugins → src/plugins}/EmojiPlugin/EmojiPlugin.d.ts +0 -0
  58. /package/dist/{plugins → src/plugins}/EmojiPlugin/Menu.d.ts +0 -0
  59. /package/dist/{plugins → src/plugins}/EmojiPlugin/index.d.ts +0 -0
  60. /package/dist/{plugins → src/plugins}/EmojiPlugin/types.d.ts +0 -0
  61. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/FloatingMenu.d.ts +0 -0
  62. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/FloatingMenuPlugin.d.ts +0 -0
  63. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/index.d.ts +0 -0
  64. /package/dist/{plugins → src/plugins}/FloatingMenuPlugin/types.d.ts +0 -0
  65. /package/dist/{plugins → src/plugins}/HeadingsPlugin/index.d.ts +0 -0
  66. /package/dist/{plugins → src/plugins}/HighlightsPlugin/HighlightsPlugin.d.ts +0 -0
  67. /package/dist/{plugins → src/plugins}/HighlightsPlugin/index.d.ts +0 -0
  68. /package/dist/{plugins → src/plugins}/LinksPlugin/Link.d.ts +0 -0
  69. /package/dist/{plugins → src/plugins}/LinksPlugin/constants.d.ts +0 -0
  70. /package/dist/{plugins → src/plugins}/LinksPlugin/index.d.ts +0 -0
  71. /package/dist/{plugins → src/plugins}/LinksPlugin/types.d.ts +0 -0
  72. /package/dist/{plugins → src/plugins}/ListsPlugin/index.d.ts +0 -0
  73. /package/dist/{plugins → src/plugins}/MenuPlugin/Menu.d.ts +0 -0
  74. /package/dist/{plugins → src/plugins}/MenuPlugin/index.d.ts +0 -0
  75. /package/dist/{plugins → src/plugins}/MenuPlugin/types.d.ts +0 -0
  76. /package/dist/{plugins → src/plugins}/NodeIdPlugin/NodeIdPlugin.d.ts +0 -0
  77. /package/dist/{plugins → src/plugins}/NodeIdPlugin/index.d.ts +0 -0
  78. /package/dist/{plugins → src/plugins}/PlaceholderPlugin/PlaceholderPlugin.d.ts +0 -0
  79. /package/dist/{plugins → src/plugins}/PlaceholderPlugin/index.d.ts +0 -0
  80. /package/dist/{plugins → src/plugins}/ShortcutsPlugin/ShortcutsPlugin.d.ts +0 -0
  81. /package/dist/{plugins → src/plugins}/ShortcutsPlugin/index.d.ts +0 -0
  82. /package/dist/{plugins → src/plugins}/TableOfContentsPlugin/TableOfContentsPlugin.d.ts +0 -0
  83. /package/dist/{plugins → src/plugins}/TableOfContentsPlugin/index.d.ts +0 -0
  84. /package/dist/{plugins → src/plugins}/index.d.ts +0 -0
  85. /package/dist/{queries → src/queries}/getMatchedGroups.d.ts +0 -0
  86. /package/dist/{utils.d.ts → src/utils.d.ts} +0 -0
@@ -1,323 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { CommandsResolver } from "./resolveCommands.js";
3
- const editor = {};
4
- const leaf = (params)=>({
5
- name: params.name,
6
- title: params.title,
7
- commandName: params.commandName ?? params.title.toLocaleLowerCase(),
8
- icon: null,
9
- action: ()=>{}
10
- });
11
- const deferred = ()=>{
12
- let resolve = ()=>{};
13
- let reject = ()=>{};
14
- const promise = new Promise((res, rej)=>{
15
- resolve = res;
16
- reject = rej;
17
- });
18
- return {
19
- promise,
20
- resolve,
21
- reject
22
- };
23
- };
24
- describe('CommandsResolver', ()=>{
25
- it('keeps leaf-only legacy behavior', async ()=>{
26
- const resolver = new CommandsResolver();
27
- const rootCommands = [
28
- leaf({
29
- name: 'paragraph',
30
- title: 'Paragraph'
31
- }),
32
- leaf({
33
- name: 'code',
34
- title: 'Code'
35
- })
36
- ];
37
- const request = resolver.resolve({
38
- rootCommands,
39
- filter: '',
40
- path: [],
41
- editor
42
- });
43
- const result = await request.promise;
44
- expect(result.commands.map((item)=>item.command.name)).toEqual([
45
- 'paragraph',
46
- 'code'
47
- ]);
48
- });
49
- it('resolves static submenu with sync getCommands', async ()=>{
50
- const resolver = new CommandsResolver();
51
- const rootCommands = [
52
- {
53
- name: 'insert',
54
- title: 'Insert',
55
- commandName: 'insert',
56
- icon: null,
57
- getCommands: ()=>[
58
- leaf({
59
- name: 'heading-1',
60
- title: 'Heading 1'
61
- })
62
- ]
63
- }
64
- ];
65
- const request = resolver.resolve({
66
- rootCommands,
67
- filter: '',
68
- path: [
69
- {
70
- name: 'insert',
71
- title: 'Insert',
72
- commandName: 'insert'
73
- }
74
- ],
75
- editor
76
- });
77
- const result = await request.promise;
78
- expect(result.commands).toHaveLength(1);
79
- expect(result.commands[0]?.command.name).toBe('heading-1');
80
- });
81
- it('resolves async submenu', async ()=>{
82
- const resolver = new CommandsResolver();
83
- const rootCommands = [
84
- {
85
- name: 'remote',
86
- title: 'Remote',
87
- commandName: 'remote',
88
- icon: null,
89
- getCommands: async ()=>[
90
- leaf({
91
- name: 'code',
92
- title: 'Code'
93
- })
94
- ]
95
- }
96
- ];
97
- const request = resolver.resolve({
98
- rootCommands,
99
- filter: '',
100
- path: [
101
- {
102
- name: 'remote',
103
- title: 'Remote',
104
- commandName: 'remote'
105
- }
106
- ],
107
- editor
108
- });
109
- const result = await request.promise;
110
- expect(result.commands).toHaveLength(1);
111
- expect(result.commands[0]?.command.name).toBe('code');
112
- });
113
- it('searches only root level when path is empty', async ()=>{
114
- const resolver = new CommandsResolver();
115
- const rootCommands = [
116
- {
117
- name: 'insert',
118
- title: 'Insert',
119
- commandName: 'insert',
120
- icon: null,
121
- getCommands: ()=>[
122
- leaf({
123
- name: 'code',
124
- title: 'Code'
125
- })
126
- ]
127
- },
128
- leaf({
129
- name: 'paragraph',
130
- title: 'Paragraph'
131
- })
132
- ];
133
- const request = resolver.resolve({
134
- rootCommands,
135
- filter: 'code',
136
- path: [],
137
- editor
138
- });
139
- const result = await request.promise;
140
- expect(result.commands).toHaveLength(0);
141
- });
142
- it('searches only current nested level', async ()=>{
143
- const resolver = new CommandsResolver();
144
- const rootCommands = [
145
- {
146
- name: 'insert',
147
- title: 'Insert',
148
- commandName: 'insert',
149
- icon: null,
150
- getCommands: ()=>[
151
- leaf({
152
- name: 'code',
153
- title: 'Code'
154
- })
155
- ]
156
- }
157
- ];
158
- const request = resolver.resolve({
159
- rootCommands,
160
- filter: 'code',
161
- path: [
162
- {
163
- name: 'insert',
164
- title: 'Insert',
165
- commandName: 'insert'
166
- }
167
- ],
168
- editor
169
- });
170
- const result = await request.promise;
171
- expect(result.commands).toHaveLength(1);
172
- expect(result.commands[0]?.command.name).toBe('code');
173
- });
174
- it('returns matching submenu commands in query mode', async ()=>{
175
- const resolver = new CommandsResolver();
176
- const rootCommands = [
177
- {
178
- name: 'advanced',
179
- title: 'Advanced',
180
- commandName: 'advanced',
181
- icon: null,
182
- getCommands: ()=>[
183
- leaf({
184
- name: 'code',
185
- title: 'Code'
186
- })
187
- ]
188
- }
189
- ];
190
- const request = resolver.resolve({
191
- rootCommands,
192
- filter: 'adv',
193
- path: [],
194
- editor
195
- });
196
- const result = await request.promise;
197
- expect(result.commands).toHaveLength(1);
198
- expect(result.commands[0]?.command.name).toBe('advanced');
199
- expect(result.commands[0]?.isSubmenu).toBe(true);
200
- });
201
- it('ignores stale out-of-order async responses', async ()=>{
202
- const resolver = new CommandsResolver();
203
- const searchA = deferred();
204
- const searchB = deferred();
205
- const rootCommands = [
206
- {
207
- name: 'remote',
208
- title: 'Remote',
209
- commandName: 'remote',
210
- icon: null,
211
- getCommands: ({ query })=>{
212
- if ('a' === query) return searchA.promise;
213
- return searchB.promise;
214
- }
215
- }
216
- ];
217
- const firstRequest = resolver.resolve({
218
- rootCommands,
219
- filter: 'a',
220
- path: [
221
- {
222
- name: 'remote',
223
- title: 'Remote',
224
- commandName: 'remote'
225
- }
226
- ],
227
- editor
228
- });
229
- const secondRequest = resolver.resolve({
230
- rootCommands,
231
- filter: 'b',
232
- path: [
233
- {
234
- name: 'remote',
235
- title: 'Remote',
236
- commandName: 'remote'
237
- }
238
- ],
239
- editor
240
- });
241
- searchB.resolve([
242
- leaf({
243
- name: 'b',
244
- title: 'Result B',
245
- commandName: 'b'
246
- })
247
- ]);
248
- const secondResult = await secondRequest.promise;
249
- expect(secondResult.commands.map((item)=>item.command.name)).toEqual([
250
- 'b'
251
- ]);
252
- searchA.resolve([
253
- leaf({
254
- name: 'a',
255
- title: 'Result A',
256
- commandName: 'a'
257
- })
258
- ]);
259
- const firstResult = await firstRequest.promise;
260
- expect(firstResult.commands.map((item)=>item.command.name)).toEqual([
261
- 'b'
262
- ]);
263
- expect(resolver.getState().commands.map((item)=>item.command.name)).toEqual([
264
- 'b'
265
- ]);
266
- });
267
- it('clears visible commands while loading new results', async ()=>{
268
- const resolver = new CommandsResolver();
269
- const remoteDeferred = deferred();
270
- const rootCommands = [
271
- leaf({
272
- name: 'paragraph',
273
- title: 'Paragraph'
274
- }),
275
- {
276
- name: 'remote',
277
- title: 'Remote',
278
- commandName: 'remote',
279
- icon: null,
280
- getCommands: ({ query })=>{
281
- if (query) return remoteDeferred.promise;
282
- return [
283
- leaf({
284
- name: 'code',
285
- title: 'Code'
286
- })
287
- ];
288
- }
289
- }
290
- ];
291
- const initial = await resolver.resolve({
292
- rootCommands,
293
- filter: '',
294
- path: [],
295
- editor
296
- }).promise;
297
- const loadingRequest = resolver.resolve({
298
- rootCommands,
299
- filter: 'code',
300
- path: [
301
- {
302
- name: 'remote',
303
- title: 'Remote',
304
- commandName: 'remote'
305
- }
306
- ],
307
- editor
308
- });
309
- expect(loadingRequest.state.isLoading).toBe(true);
310
- expect(initial.commands.length).toBeGreaterThan(0);
311
- expect(loadingRequest.state.commands).toEqual([]);
312
- remoteDeferred.resolve([
313
- leaf({
314
- name: 'code',
315
- title: 'Code'
316
- })
317
- ]);
318
- const settled = await loadingRequest.promise;
319
- expect(settled.isLoading).toBe(false);
320
- expect(settled.commands).toHaveLength(1);
321
- expect(settled.commands[0]?.command.name).toBe('code');
322
- });
323
- });
@@ -1,3 +0,0 @@
1
- /** @jsxRuntime classic */
2
- /** @jsx jsx */
3
- export {};
@@ -1,47 +0,0 @@
1
- import { createHyperscript, createText } from "slate-hyperscript";
2
- import { describe, expect, it } from "vitest";
3
- import { createEditor } from "../../core/createEditor.js";
4
- import { ListsPlugin } from "./ListsPlugin.js";
5
- const ListsPlugin_spec_elements = {
6
- paragraph: {
7
- type: 'paragraph'
8
- },
9
- numberedList: {
10
- type: ListsPlugin.NUMBERED_LIST_ELEMENT
11
- },
12
- bulletedList: {
13
- type: ListsPlugin.BULLETED_LIST_ELEMENT
14
- },
15
- listItem: {
16
- type: ListsPlugin.LIST_ITEM_ELEMENT
17
- }
18
- };
19
- const jsx = createHyperscript({
20
- elements: ListsPlugin_spec_elements,
21
- creators: {
22
- text: createText
23
- }
24
- });
25
- const createEditorWithPlugin = (children)=>{
26
- const editorState = /*#__PURE__*/ jsx("editor", null, children);
27
- const editor = createEditor([
28
- new ListsPlugin()
29
- ])();
30
- editor.children = editorState.children;
31
- editor.selection = editorState.selection;
32
- return editor;
33
- };
34
- describe('ListsPlugin', ()=>{
35
- it('should change current block to bulleted list', ()=>{
36
- const editor = createEditorWithPlugin(/*#__PURE__*/ jsx("paragraph", null, /*#__PURE__*/ jsx("cursor", null), /*#__PURE__*/ jsx("text", null, "Hello world")));
37
- ListsPlugin.toggleList(editor, ListsPlugin.BULLETED_LIST_ELEMENT);
38
- const output = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("bulletedList", null, /*#__PURE__*/ jsx("listItem", null, /*#__PURE__*/ jsx("text", null, "Hello world"))), /*#__PURE__*/ jsx("paragraph", null, /*#__PURE__*/ jsx("text", null)));
39
- expect(editor.children).toEqual(output.children);
40
- });
41
- it('should change current block to numbered list', ()=>{
42
- const editor = createEditorWithPlugin(/*#__PURE__*/ jsx("paragraph", null, /*#__PURE__*/ jsx("cursor", null), /*#__PURE__*/ jsx("text", null, "Hello world")));
43
- ListsPlugin.toggleList(editor, ListsPlugin.NUMBERED_LIST_ELEMENT);
44
- const output = /*#__PURE__*/ jsx("editor", null, /*#__PURE__*/ jsx("numberedList", null, /*#__PURE__*/ jsx("listItem", null, /*#__PURE__*/ jsx("text", null, "Hello world"))), /*#__PURE__*/ jsx("paragraph", null, /*#__PURE__*/ jsx("text", null)));
45
- expect(editor.children).toEqual(output.children);
46
- });
47
- });
@@ -1,7 +0,0 @@
1
- import type { IPlugin, UiParams } from '../../types';
2
- import type { Options } from './types';
3
- export declare class MenuPlugin implements IPlugin {
4
- private options;
5
- constructor(options: Options);
6
- ui: (params: UiParams) => string | number | bigint | boolean | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
7
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes