@kerebron/extension-menu 0.3.2 → 0.4.1

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 (76) hide show
  1. package/README.md +26 -1
  2. package/assets/custom-menu.css +838 -0
  3. package/assets/menu.css +353 -26
  4. package/esm/_dnt.shims.d.ts +6 -0
  5. package/esm/_dnt.shims.d.ts.map +1 -0
  6. package/esm/_dnt.shims.js +61 -0
  7. package/esm/editor/src/CoreEditor.d.ts +13 -4
  8. package/esm/editor/src/CoreEditor.d.ts.map +1 -1
  9. package/esm/editor/src/CoreEditor.js +64 -12
  10. package/esm/editor/src/Extension.d.ts +6 -1
  11. package/esm/editor/src/Extension.d.ts.map +1 -1
  12. package/esm/editor/src/Extension.js +21 -1
  13. package/esm/editor/src/ExtensionManager.d.ts +5 -6
  14. package/esm/editor/src/ExtensionManager.d.ts.map +1 -1
  15. package/esm/editor/src/ExtensionManager.js +43 -55
  16. package/esm/editor/src/Mark.d.ts +3 -0
  17. package/esm/editor/src/Mark.d.ts.map +1 -1
  18. package/esm/editor/src/Mark.js +11 -0
  19. package/esm/editor/src/Node.d.ts +5 -2
  20. package/esm/editor/src/Node.d.ts.map +1 -1
  21. package/esm/editor/src/Node.js +13 -2
  22. package/esm/editor/src/commands/CommandManager.d.ts +13 -6
  23. package/esm/editor/src/commands/CommandManager.d.ts.map +1 -1
  24. package/esm/editor/src/commands/CommandManager.js +59 -2
  25. package/esm/editor/src/commands/baseCommandFactories.d.ts +3 -0
  26. package/esm/editor/src/commands/baseCommandFactories.d.ts.map +1 -0
  27. package/esm/editor/src/commands/baseCommandFactories.js +836 -0
  28. package/esm/editor/src/commands/keyCommandFactories.d.ts +3 -0
  29. package/esm/editor/src/commands/keyCommandFactories.d.ts.map +1 -0
  30. package/esm/editor/src/commands/keyCommandFactories.js +10 -0
  31. package/esm/editor/src/commands/mod.d.ts +5 -53
  32. package/esm/editor/src/commands/mod.d.ts.map +1 -1
  33. package/esm/editor/src/commands/mod.js +14 -821
  34. package/esm/editor/src/commands/replaceCommandFactories.d.ts +3 -0
  35. package/esm/editor/src/commands/replaceCommandFactories.d.ts.map +1 -0
  36. package/esm/editor/src/commands/replaceCommandFactories.js +94 -0
  37. package/esm/editor/src/commands/types.d.ts +18 -0
  38. package/esm/editor/src/commands/types.d.ts.map +1 -0
  39. package/esm/editor/src/commands/types.js +1 -0
  40. package/esm/editor/src/mod.d.ts +2 -0
  41. package/esm/editor/src/mod.d.ts.map +1 -1
  42. package/esm/editor/src/mod.js +2 -0
  43. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts +6 -0
  44. package/esm/editor/src/plugins/TrackSelecionPlugin.d.ts.map +1 -0
  45. package/esm/editor/src/plugins/TrackSelecionPlugin.js +24 -0
  46. package/esm/editor/src/types.d.ts +19 -1
  47. package/esm/editor/src/types.d.ts.map +1 -1
  48. package/esm/editor/src/ui.d.ts +15 -0
  49. package/esm/editor/src/ui.d.ts.map +1 -0
  50. package/esm/editor/src/ui.js +16 -0
  51. package/esm/editor/src/utilities/SmartOutput.d.ts +9 -7
  52. package/esm/editor/src/utilities/SmartOutput.d.ts.map +1 -1
  53. package/esm/editor/src/utilities/SmartOutput.js +35 -20
  54. package/esm/extension-menu/src/CustomMenuPlugin.d.ts +61 -0
  55. package/esm/extension-menu/src/CustomMenuPlugin.d.ts.map +1 -0
  56. package/esm/extension-menu/src/CustomMenuPlugin.js +1130 -0
  57. package/esm/extension-menu/src/ExtensionCustomMenu.d.ts +11 -0
  58. package/esm/extension-menu/src/ExtensionCustomMenu.d.ts.map +1 -0
  59. package/esm/extension-menu/src/ExtensionCustomMenu.js +23 -0
  60. package/esm/extension-menu/src/buildMenu.d.ts +5 -0
  61. package/esm/extension-menu/src/buildMenu.d.ts.map +1 -0
  62. package/esm/extension-menu/src/{ExtensionMenu.js → buildMenu.js} +88 -75
  63. package/esm/extension-menu/src/icons.d.ts.map +1 -1
  64. package/esm/extension-menu/src/icons.js +5 -0
  65. package/esm/extension-menu/src/menu.d.ts +1 -8
  66. package/esm/extension-menu/src/menu.d.ts.map +1 -1
  67. package/esm/extension-menu/src/menu.js +9 -51
  68. package/esm/extension-menu/src/mod.d.ts +3 -0
  69. package/esm/extension-menu/src/mod.d.ts.map +1 -0
  70. package/esm/extension-menu/src/mod.js +2 -0
  71. package/package.json +8 -4
  72. package/esm/extension-menu/src/ExtensionMenu.d.ts +0 -17
  73. package/esm/extension-menu/src/ExtensionMenu.d.ts.map +0 -1
  74. package/esm/extension-menu/src/MenuPlugin.d.ts +0 -9
  75. package/esm/extension-menu/src/MenuPlugin.d.ts.map +0 -1
  76. package/esm/extension-menu/src/MenuPlugin.js +0 -245
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'prosemirror-state';
2
+ import { Extension } from '../../editor/src/mod.js';
3
+ import { type MenuElement } from './menu.js';
4
+ export interface CustomMenuOptions {
5
+ content: readonly (readonly MenuElement[])[];
6
+ }
7
+ export declare class ExtensionCustomMenu extends Extension {
8
+ name: string;
9
+ getProseMirrorPlugins(): Plugin[];
10
+ }
11
+ //# sourceMappingURL=ExtensionCustomMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExtensionCustomMenu.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/ExtensionCustomMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAI7C,MAAM,WAAW,iBAAiB;IAEhC,OAAO,EAAE,SAAS,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC;CAC9C;AAGD,qBAAa,mBAAoB,SAAQ,SAAS;IAChD,IAAI,SAAgB;IAEX,qBAAqB,IAAI,MAAM,EAAE;CAS3C"}
@@ -0,0 +1,23 @@
1
+ import { Extension } from '../../editor/src/mod.js';
2
+ import { buildMenu } from './buildMenu.js';
3
+ import { CustomMenuPlugin } from './CustomMenuPlugin.js';
4
+ /// Extension for a customizable menu with pinned items
5
+ export class ExtensionCustomMenu extends Extension {
6
+ constructor() {
7
+ super(...arguments);
8
+ Object.defineProperty(this, "name", {
9
+ enumerable: true,
10
+ configurable: true,
11
+ writable: true,
12
+ value: 'customMenu'
13
+ });
14
+ }
15
+ getProseMirrorPlugins() {
16
+ const content = buildMenu(this.editor, this.editor.schema);
17
+ return [
18
+ new CustomMenuPlugin(this.editor, {
19
+ content,
20
+ }),
21
+ ];
22
+ }
23
+ }
@@ -0,0 +1,5 @@
1
+ import { Schema } from 'prosemirror-model';
2
+ import { type CoreEditor } from '../../editor/src/mod.js';
3
+ import { type MenuElement } from './menu.js';
4
+ export declare function buildMenu(editor: CoreEditor, schema: Schema): MenuElement[][];
5
+ //# sourceMappingURL=buildMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildMenu.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/buildMenu.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAGtE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,EAGL,KAAK,WAAW,EAGjB,MAAM,WAAW,CAAC;AAoCnB,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,EAAE,CAgX7E"}
@@ -1,15 +1,8 @@
1
1
  import { NodeSelection } from 'prosemirror-state';
2
- import { Extension } from '../../editor/src/mod.js';
3
- import { toggleMark, wrapInList } from '../../editor/src/commands/mod.js';
4
- import { blockTypeItem, Dropdown, DropdownSubmenu, MenuItem, wrapItem, } from './menu.js';
5
- import { MenuPlugin } from './MenuPlugin.js';
2
+ import { EditorView } from 'prosemirror-view';
3
+ import { Dropdown, DropdownSubmenu, MenuItem, } from './menu.js';
6
4
  import { icons } from './icons.js';
7
5
  import { openPrompt, TextField } from './prompt.js';
8
- export { blockTypeItem, Dropdown, DropdownSubmenu,
9
- // MenuElement,
10
- MenuItem,
11
- // MenuItemSpec,
12
- wrapItem, } from './menu.js';
13
6
  function canInsert(state, nodeType) {
14
7
  let $from = state.selection.$from;
15
8
  for (let d = $from.depth; d >= 0; d--) {
@@ -39,22 +32,60 @@ function markActive(state, type) {
39
32
  else
40
33
  return state.doc.rangeHasMark(from, to, type);
41
34
  }
42
- function markItem(markType, options) {
43
- let passedOptions = {
44
- active(state) {
45
- return markActive(state, markType);
46
- },
47
- };
48
- for (let prop in options) {
49
- passedOptions[prop] = options[prop];
50
- }
51
- return cmdItem(toggleMark(markType), passedOptions);
52
- }
53
- function wrapListItem(nodeType, options) {
54
- return cmdItem(wrapInList(nodeType, options.attrs), options);
55
- }
56
35
  const cut = (arr) => arr.filter((x) => x);
57
36
  export function buildMenu(editor, schema) {
37
+ function markItem(markType, options) {
38
+ let passedOptions = {
39
+ active(state) {
40
+ return markActive(state, markType);
41
+ },
42
+ };
43
+ for (let prop in options) {
44
+ passedOptions[prop] = options[prop];
45
+ }
46
+ return cmdItem(editor.commandFactories.toggleMark(markType), passedOptions);
47
+ }
48
+ function wrapItem(nodeType, options) {
49
+ let passedOptions = {
50
+ run(state, dispatch) {
51
+ return editor.commandFactories.wrapIn(nodeType, options.attrs)(state, dispatch);
52
+ },
53
+ select(state) {
54
+ return editor.commandFactories.wrapIn(nodeType, options.attrs)(state);
55
+ },
56
+ };
57
+ for (let prop in options) {
58
+ passedOptions[prop] = options[prop];
59
+ }
60
+ return new MenuItem(passedOptions);
61
+ }
62
+ function wrapListItem(nodeType, options) {
63
+ return cmdItem(editor.commandFactories.wrapInList(nodeType, options.attrs), options);
64
+ }
65
+ /// Build a menu item for changing the type of the textblock around the
66
+ /// selection to the given type. Provides `run`, `active`, and `select`
67
+ /// properties. Others must be given in `options`. `options.attrs` may
68
+ /// be an object to provide the attributes for the textblock node.
69
+ function blockTypeItem(nodeType, options) {
70
+ let command = editor.commandFactories.setBlockType(nodeType, options.attrs);
71
+ let passedOptions = {
72
+ run: command,
73
+ enable(state) {
74
+ return command(state);
75
+ },
76
+ active(state) {
77
+ let { $from, to, node } = state.selection;
78
+ if (node)
79
+ return node.hasMarkup(nodeType, options.attrs);
80
+ return to <= $from.end() &&
81
+ $from.parent.hasMarkup(nodeType, options.attrs);
82
+ },
83
+ };
84
+ for (let prop in options) {
85
+ passedOptions[prop] = options[prop];
86
+ }
87
+ return new MenuItem(passedOptions);
88
+ }
58
89
  const menu = [];
59
90
  if (schema.marks.strong) {
60
91
  menu.push(new MenuItem({
@@ -78,7 +109,7 @@ export function buildMenu(editor, schema) {
78
109
  label: '_',
79
110
  run: () => editor.chain().toggleUnderline().run(),
80
111
  enable: (state) => editor.can().toggleUnderline().run(),
81
- // icon: icons.underline
112
+ icon: icons.underline,
82
113
  }));
83
114
  }
84
115
  if (schema.marks.code) {
@@ -98,9 +129,9 @@ export function buildMenu(editor, schema) {
98
129
  enable(state) {
99
130
  return !state.selection.empty;
100
131
  },
101
- run(state, dispatch, view) {
132
+ run(state, dispatch) {
102
133
  if (markActive(state, markType)) {
103
- toggleMark(markType)(state, dispatch);
134
+ editor.commandFactories.toggleMark(markType)(state, dispatch);
104
135
  return true;
105
136
  }
106
137
  openPrompt({
@@ -113,10 +144,11 @@ export function buildMenu(editor, schema) {
113
144
  title: new TextField({ label: 'Title' }),
114
145
  },
115
146
  callback(attrs) {
116
- toggleMark(markType, attrs)(view.state, view.dispatch);
117
- view.focus();
147
+ editor.commandFactories.toggleMark(markType, attrs)(editor.view.state, editor.view.dispatch);
148
+ editor.view.focus();
118
149
  },
119
150
  });
151
+ return true;
120
152
  },
121
153
  }));
122
154
  }
@@ -158,11 +190,11 @@ export function buildMenu(editor, schema) {
158
190
  for (let i = 1; i <= 6; i++) {
159
191
  makeHeadMenu.push(blockTypeItem(schema.nodes.heading, {
160
192
  title: 'Change to heading ' + i,
161
- label: 'Level ' + i,
193
+ label: 'Heading ' + i,
162
194
  attrs: { level: i },
163
195
  }));
164
196
  }
165
- typeMenu.push(new DropdownSubmenu(makeHeadMenu, { label: 'Heading' }));
197
+ typeMenu.push(new DropdownSubmenu(makeHeadMenu, { label: 'Headings' }));
166
198
  }
167
199
  blockMenu.push(new MenuItem({
168
200
  title: 'Join with above block',
@@ -189,7 +221,7 @@ export function buildMenu(editor, schema) {
189
221
  label: 'Image',
190
222
  // enable: (state) => editor.can().setHorizontalRule().run(),
191
223
  enable: (state) => canInsert(state, nodeType),
192
- run(state, _, view) {
224
+ run(state, dispatch) {
193
225
  let { from, to } = state.selection, attrs = null;
194
226
  if (state.selection instanceof NodeSelection &&
195
227
  state.selection.node.type == nodeType) {
@@ -213,10 +245,11 @@ export function buildMenu(editor, schema) {
213
245
  }),
214
246
  },
215
247
  callback(attrs) {
216
- view.dispatch(view.state.tr.replaceSelectionWith(nodeType.createAndFill(attrs)));
217
- view.focus();
248
+ editor.view.dispatch(editor.view.state.tr.replaceSelectionWith(nodeType.createAndFill(attrs)));
249
+ editor.view.focus();
218
250
  },
219
251
  });
252
+ return true;
220
253
  },
221
254
  }));
222
255
  }
@@ -232,7 +265,7 @@ export function buildMenu(editor, schema) {
232
265
  label: 'Insert',
233
266
  }));
234
267
  menu.push(new Dropdown(cut(typeMenu), {
235
- label: 'Type...',
268
+ label: 'Type',
236
269
  }));
237
270
  /*
238
271
  r.blockMenu = [
@@ -246,18 +279,27 @@ export function buildMenu(editor, schema) {
246
279
  ]),
247
280
  ];
248
281
  */
249
- menu.push(new MenuItem({
250
- title: 'Undo last change',
251
- run: () => editor.chain().undo().run(),
252
- enable: () => editor.can().undo().run(),
253
- icon: icons.undo,
254
- }));
255
- menu.push(new MenuItem({
256
- title: 'Redo last undone change',
257
- run: () => editor.chain().redo().run(),
258
- enable: () => editor.can().redo().run(),
259
- icon: icons.redo,
260
- }));
282
+ const editorView = editor.view;
283
+ if (editorView instanceof EditorView) {
284
+ menu.push(new MenuItem({
285
+ title: 'Undo last change',
286
+ run: (state, dispatch) => {
287
+ return editor.commandFactories.undo()(editor.view.state, editor.view.dispatch, editorView);
288
+ },
289
+ enable: (state) => {
290
+ return editor.commandFactories.undo()(state);
291
+ },
292
+ icon: icons.undo,
293
+ }));
294
+ menu.push(new MenuItem({
295
+ title: 'Redo last undone change',
296
+ run: (state, dispatch) => {
297
+ return editor.commandFactories.redo()(state, dispatch);
298
+ },
299
+ enable: (state) => editor.commandFactories.redo()(state),
300
+ icon: icons.redo,
301
+ }));
302
+ }
261
303
  if (schema.nodes.table) {
262
304
  const item = (label, cmdName) => {
263
305
  return new MenuItem({
@@ -287,32 +329,3 @@ export function buildMenu(editor, schema) {
287
329
  }
288
330
  return [menu, blockMenu];
289
331
  }
290
- export class ExtensionMenu extends Extension {
291
- constructor(config = { floating: true }) {
292
- super(config);
293
- Object.defineProperty(this, "config", {
294
- enumerable: true,
295
- configurable: true,
296
- writable: true,
297
- value: config
298
- });
299
- Object.defineProperty(this, "name", {
300
- enumerable: true,
301
- configurable: true,
302
- writable: true,
303
- value: 'menu'
304
- });
305
- }
306
- getProseMirrorPlugins(editor, schema) {
307
- const plugins = [];
308
- let content = buildMenu(editor, schema);
309
- if (this.config.modifyMenu) {
310
- content = this.config.modifyMenu(content);
311
- }
312
- plugins.push(new MenuPlugin({
313
- content,
314
- floating: this.config.floating,
315
- }));
316
- return plugins;
317
- }
318
- }
@@ -1 +1 @@
1
- {"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/icons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAerC,wBAAgB,OAAO,CACrB,IAAI,EAAE,QAAQ,GAAG,UAAU,EAC3B,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAChB,WAAW,CAmCb;AA8BD,eAAO,MAAM,KAAK,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAA;CAoE7C,CAAC"}
1
+ {"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/icons.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAerC,wBAAgB,OAAO,CACrB,IAAI,EAAE,QAAQ,GAAG,UAAU,EAC3B,IAAI,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,GAChB,WAAW,CAmCb;AA8BD,eAAO,MAAM,KAAK,EAAE;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAA;CAyE7C,CAAC"}
@@ -90,6 +90,11 @@ export const icons = {
90
90
  height: 1024,
91
91
  path: 'M0 949l9-48q3-1 46-12t63-21q16-20 23-57 0-4 35-165t65-310 29-169v-14q-13-7-31-10t-39-4-33-3l10-58q18 1 68 3t85 4 68 1q27 0 56-1t69-4 56-3q-2 22-10 50-17 5-58 16t-62 19q-4 10-8 24t-5 22-4 26-3 24q-15 84-50 239t-44 203q-1 5-7 33t-11 51-9 47-3 32l0 10q9 2 105 17-1 25-9 56-6 0-18 0t-18 0q-16 0-49-5t-49-5q-78-1-117-1-29 0-81 5t-69 6z',
92
92
  },
93
+ underline: {
94
+ width: 585,
95
+ height: 1024,
96
+ path: 'M0 908h1024v64H0Z',
97
+ },
93
98
  code: {
94
99
  width: 896,
95
100
  height: 1024,
@@ -1,6 +1,5 @@
1
1
  import { EditorView } from 'prosemirror-view';
2
2
  import { EditorState, Transaction } from 'prosemirror-state';
3
- import { Attrs, NodeType } from 'prosemirror-model';
4
3
  export interface MenuElement {
5
4
  render(pm: EditorView): {
6
5
  dom: HTMLElement;
@@ -27,7 +26,7 @@ export type IconSpec = {
27
26
  dom: Node;
28
27
  };
29
28
  export interface MenuItemSpec {
30
- run: (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
29
+ run: (state: EditorState, dispatch: (tr: Transaction) => void) => boolean | Promise<boolean>;
31
30
  select?: (state: EditorState) => boolean;
32
31
  enable?: (state: EditorState) => boolean;
33
32
  active?: (state: EditorState) => boolean;
@@ -79,10 +78,4 @@ export declare function renderGrouped(view: EditorView, content: readonly (reado
79
78
  dom: any;
80
79
  update: (state: EditorState) => boolean;
81
80
  };
82
- export declare function wrapItem(nodeType: NodeType, options: Partial<MenuItemSpec> & {
83
- attrs?: Attrs | null;
84
- }): MenuItem;
85
- export declare function blockTypeItem(nodeType: NodeType, options: Partial<MenuItemSpec> & {
86
- attrs?: Attrs | null;
87
- }): MenuItem;
88
81
  //# sourceMappingURL=menu.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"menu.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/menu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAiB,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAcpD,MAAM,WAAW,WAAW;IAK1B,MAAM,CACJ,EAAE,EAAE,UAAU,GACb;QAAE,GAAG,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAA;KAAE,CAAC;CAClE;AAGD,qBAAa,QAAS,YAAW,WAAW;IAMxC,QAAQ,CAAC,IAAI,EAAE,YAAY;IAL7B,UAAU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,EAChB,OAAO,EAAE,SAAS,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE;;oBAwBrB,WAAW;EAanC"}
@@ -1,4 +1,3 @@
1
- import { setBlockType, wrapIn, } from '../../editor/src/commands/mod.js';
2
1
  import { getIcon } from './icons.js';
3
2
  /// An icon or label that, when clicked, executes a command.
4
3
  export class MenuItem {
@@ -65,7 +64,7 @@ export class MenuItem {
65
64
  spec.run(view.state, view.dispatch);
66
65
  }
67
66
  });
68
- function update(state) {
67
+ const update = (state) => {
69
68
  if (spec.select) {
70
69
  let selected = spec.select(state);
71
70
  dom.style.display = selected ? '' : 'none';
@@ -84,7 +83,7 @@ export class MenuItem {
84
83
  dom.setAttribute('aria-pressed', active.toString());
85
84
  }
86
85
  return true;
87
- }
86
+ };
88
87
  return { dom, update };
89
88
  }
90
89
  }
@@ -164,7 +163,7 @@ export class Dropdown {
164
163
  let close = () => {
165
164
  if (open && open.close()) {
166
165
  open = null;
167
- win.removeEventListener('mousedown', listeningOnClose);
166
+ win?.removeEventListener('mousedown', listeningOnClose);
168
167
  }
169
168
  };
170
169
  label.addEventListener('mousedown', (e) => {
@@ -177,7 +176,7 @@ export class Dropdown {
177
176
  else {
178
177
  open = this.expand(wrap, content.dom);
179
178
  wrap.classList.add('kb-dropdown--open');
180
- win.addEventListener('mousedown', listeningOnClose = () => {
179
+ win?.addEventListener('mousedown', listeningOnClose = () => {
181
180
  if (!isMenuEvent(wrap))
182
181
  close();
183
182
  });
@@ -277,12 +276,13 @@ export class DropdownSubmenu {
277
276
  label.addEventListener('mousedown', (e) => {
278
277
  e.preventDefault();
279
278
  markMenuEvent(e);
280
- setClass(wrap, CSS_PREFIX + '--open', false);
281
- if (!listeningOnClose) {
282
- win.addEventListener('mousedown', listeningOnClose = () => {
279
+ const isOpen = wrap.classList.contains(CSS_PREFIX + '--open');
280
+ setClass(wrap, CSS_PREFIX + '--open', !isOpen);
281
+ if (!isOpen && !listeningOnClose) {
282
+ win?.addEventListener('mousedown', listeningOnClose = () => {
283
283
  if (!isMenuEvent(wrap)) {
284
284
  wrap.classList.remove(CSS_PREFIX + '--open');
285
- win.removeEventListener('mousedown', listeningOnClose);
285
+ win?.removeEventListener('mousedown', listeningOnClose);
286
286
  listeningOnClose = null;
287
287
  }
288
288
  });
@@ -341,48 +341,6 @@ function separator() {
341
341
  elem.classList.add('kb-menu__separator');
342
342
  return elem;
343
343
  }
344
- /// Build a menu item for wrapping the selection in a given node type.
345
- /// Adds `run` and `select` properties to the ones present in
346
- /// `options`. `options.attrs` may be an object that provides
347
- /// attributes for the wrapping node.
348
- export function wrapItem(nodeType, options) {
349
- let passedOptions = {
350
- run(state, dispatch) {
351
- return wrapIn(nodeType, options.attrs)(state, dispatch);
352
- },
353
- select(state) {
354
- return wrapIn(nodeType, options.attrs)(state);
355
- },
356
- };
357
- for (let prop in options) {
358
- passedOptions[prop] = options[prop];
359
- }
360
- return new MenuItem(passedOptions);
361
- }
362
- /// Build a menu item for changing the type of the textblock around the
363
- /// selection to the given type. Provides `run`, `active`, and `select`
364
- /// properties. Others must be given in `options`. `options.attrs` may
365
- /// be an object to provide the attributes for the textblock node.
366
- export function blockTypeItem(nodeType, options) {
367
- let command = setBlockType(nodeType, options.attrs);
368
- let passedOptions = {
369
- run: command,
370
- enable(state) {
371
- return command(state);
372
- },
373
- active(state) {
374
- let { $from, to, node } = state.selection;
375
- if (node)
376
- return node.hasMarkup(nodeType, options.attrs);
377
- return to <= $from.end() &&
378
- $from.parent.hasMarkup(nodeType, options.attrs);
379
- },
380
- };
381
- for (let prop in options) {
382
- passedOptions[prop] = options[prop];
383
- }
384
- return new MenuItem(passedOptions);
385
- }
386
344
  // Work around classList.toggle being broken in IE11
387
345
  function setClass(dom, cls, on) {
388
346
  if (on)
@@ -0,0 +1,3 @@
1
+ export { Dropdown, DropdownSubmenu, type MenuElement, MenuItem, type MenuItemSpec, } from './menu.js';
2
+ export * from './ExtensionCustomMenu.js';
3
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,eAAe,EACf,KAAK,WAAW,EAChB,QAAQ,EACR,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AAEnB,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { Dropdown, DropdownSubmenu, MenuItem, } from './menu.js';
2
+ export * from './ExtensionCustomMenu.js';
package/package.json CHANGED
@@ -1,11 +1,14 @@
1
1
  {
2
2
  "name": "@kerebron/extension-menu",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "license": "MIT",
5
- "module": "./esm/extension-menu/src/ExtensionMenu.js",
5
+ "module": "./esm/extension-menu/src/mod.js",
6
6
  "exports": {
7
7
  ".": {
8
- "import": "./esm/extension-menu/src/ExtensionMenu.js"
8
+ "import": "./esm/extension-menu/src/mod.js"
9
+ },
10
+ "./ExtensionCustomMenu": {
11
+ "import": "./esm/extension-menu/src/ExtensionCustomMenu.js"
9
12
  }
10
13
  },
11
14
  "scripts": {},
@@ -13,7 +16,8 @@
13
16
  "prosemirror-model": "1.25.3",
14
17
  "prosemirror-state": "1.4.3",
15
18
  "prosemirror-transform": "1.10.4",
16
- "prosemirror-view": "1.40.0"
19
+ "prosemirror-view": "1.40.0",
20
+ "@deno/shim-deno": "~0.18.0"
17
21
  },
18
22
  "devDependencies": {
19
23
  "@types/node": "^20.9.0"
@@ -1,17 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- import { Schema } from 'prosemirror-model';
3
- import { type CoreEditor, Extension } from '../../editor/src/mod.js';
4
- import { MenuElement } from './menu.js';
5
- export { blockTypeItem, Dropdown, DropdownSubmenu, MenuItem, wrapItem, } from './menu.js';
6
- export declare function buildMenu(editor: CoreEditor, schema: Schema): MenuElement[][];
7
- export interface MenuConfig {
8
- modifyMenu?(menus: MenuElement[][]): MenuElement[][];
9
- floating: boolean;
10
- }
11
- export declare class ExtensionMenu extends Extension {
12
- protected config: MenuConfig;
13
- name: string;
14
- constructor(config?: MenuConfig);
15
- getProseMirrorPlugins(editor: CoreEditor, schema: Schema): Plugin[];
16
- }
17
- //# sourceMappingURL=ExtensionMenu.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ExtensionMenu.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/ExtensionMenu.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,EAAsB,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,KAAK,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGrE,OAAO,EAIL,WAAW,EAIZ,MAAM,WAAW,CAAC;AAKnB,OAAO,EACL,aAAa,EACb,QAAQ,EACR,eAAe,EAEf,QAAQ,EAER,QAAQ,GACT,MAAM,WAAW,CAAC;AAkDnB,wBAAgB,SAAS,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,EAAE,EAAE,CA2R7E;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,EAAE,GAAG,WAAW,EAAE,EAAE,CAAC;IACrD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,qBAAa,aAAc,SAAQ,SAAS;IAG9B,SAAS,CAAC,MAAM,EAAE,UAAU;IAFxC,IAAI,SAAU;gBAEQ,MAAM,GAAE,UAA+B;IAIpD,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;CAgB7E"}
@@ -1,9 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- import { MenuElement } from './menu.js';
3
- export declare class MenuPlugin extends Plugin {
4
- constructor(options: {
5
- content: readonly (readonly MenuElement[])[];
6
- floating?: boolean;
7
- });
8
- }
9
- //# sourceMappingURL=MenuPlugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MenuPlugin.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/MenuPlugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,MAAM,EAAa,MAAM,mBAAmB,CAAC;AAEnE,OAAO,EAAE,WAAW,EAAiB,MAAM,WAAW,CAAC;AAyLvD,qBAAa,UAAW,SAAQ,MAAM;gBACxB,OAAO,EAAE;QAGnB,OAAO,EAAE,SAAS,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC;QAK7C,QAAQ,CAAC,EAAE,OAAO,CAAC;KACpB;CAOF"}