@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
@@ -1,245 +0,0 @@
1
- import { Plugin } from 'prosemirror-state';
2
- import { renderGrouped } from './menu.js';
3
- const CSS_PREFIX = 'kb-menu';
4
- function isIOS() {
5
- if (typeof navigator == 'undefined')
6
- return false;
7
- let agent = navigator?.userAgent;
8
- return !/Edge\/\d/.test(agent) && /AppleWebKit/.test(agent) &&
9
- /Mobile\/\w+/.test(agent);
10
- }
11
- class MenuBarView {
12
- constructor(editorView, options) {
13
- Object.defineProperty(this, "editorView", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: editorView
18
- });
19
- Object.defineProperty(this, "options", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: options
24
- });
25
- Object.defineProperty(this, "wrapper", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- Object.defineProperty(this, "menu", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: void 0
36
- });
37
- Object.defineProperty(this, "spacer", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: null
42
- });
43
- Object.defineProperty(this, "maxHeight", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: 0
48
- });
49
- Object.defineProperty(this, "widthForMaxHeight", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: 0
54
- });
55
- Object.defineProperty(this, "floating", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: false
60
- });
61
- Object.defineProperty(this, "contentUpdate", {
62
- enumerable: true,
63
- configurable: true,
64
- writable: true,
65
- value: void 0
66
- });
67
- Object.defineProperty(this, "scrollHandler", {
68
- enumerable: true,
69
- configurable: true,
70
- writable: true,
71
- value: null
72
- });
73
- Object.defineProperty(this, "root", {
74
- enumerable: true,
75
- configurable: true,
76
- writable: true,
77
- value: void 0
78
- });
79
- this.root = editorView.root;
80
- this.wrapper = document.createElement('div');
81
- this.wrapper.classList.add(CSS_PREFIX + '__wrapper');
82
- this.menu = document.createElement('div');
83
- this.menu.classList.add(CSS_PREFIX);
84
- this.wrapper.appendChild(this.menu);
85
- this.menu.className = CSS_PREFIX;
86
- if (editorView.dom.parentNode) {
87
- editorView.dom.parentNode.replaceChild(this.wrapper, editorView.dom);
88
- }
89
- this.wrapper.appendChild(editorView.dom);
90
- let { dom, update } = renderGrouped(this.editorView, this.options.content);
91
- this.contentUpdate = update;
92
- this.menu.appendChild(dom);
93
- this.update();
94
- if (options.floating && !isIOS()) {
95
- this.updateFloat();
96
- let potentialScrollers = getAllWrapping(this.wrapper);
97
- this.scrollHandler = (e) => {
98
- let root = this.editorView.root;
99
- if (!(root.body || root).contains(this.wrapper)) {
100
- potentialScrollers.forEach((el) => el.removeEventListener('scroll', this.scrollHandler));
101
- }
102
- else {
103
- this.updateFloat(e.target.getBoundingClientRect
104
- ? e.target
105
- : undefined);
106
- }
107
- };
108
- potentialScrollers.forEach((el) => el.addEventListener('scroll', this.scrollHandler));
109
- }
110
- }
111
- update() {
112
- if (this.editorView.root != this.root) {
113
- let { dom, update } = renderGrouped(this.editorView, this.options.content);
114
- this.contentUpdate = update;
115
- this.menu.replaceChild(dom, this.menu.firstChild);
116
- this.root = this.editorView.root;
117
- }
118
- // this.contentUpdate(this.editorView.state);
119
- if (this.floating) {
120
- this.updateScrollCursor();
121
- }
122
- else {
123
- if (this.menu.offsetWidth != this.widthForMaxHeight) {
124
- this.widthForMaxHeight = this.menu.offsetWidth;
125
- this.maxHeight = 0;
126
- }
127
- if (this.menu.offsetHeight > this.maxHeight) {
128
- this.maxHeight = this.menu.offsetHeight;
129
- }
130
- }
131
- }
132
- updateScrollCursor() {
133
- let selection = this.editorView.root.getSelection();
134
- if (!selection.focusNode)
135
- return;
136
- let rects = selection.getRangeAt(0).getClientRects();
137
- let selRect = rects[selectionIsInverted(selection) ? 0 : rects.length - 1];
138
- if (!selRect)
139
- return;
140
- let menuRect = this.menu.getBoundingClientRect();
141
- if (selRect.top < menuRect.bottom && selRect.bottom > menuRect.top) {
142
- let scrollable = findWrappingScrollable(this.wrapper);
143
- if (scrollable)
144
- scrollable.scrollTop -= menuRect.bottom - selRect.top;
145
- }
146
- }
147
- updateFloat(scrollAncestor) {
148
- let parent = this.wrapper, editorRect = parent.getBoundingClientRect(), top = scrollAncestor
149
- ? Math.max(0, scrollAncestor.getBoundingClientRect().top)
150
- : 0;
151
- if (this.floating) {
152
- if (editorRect.top >= top || editorRect.bottom < this.menu.offsetHeight + 10) {
153
- this.floating = false;
154
- this.menu.style.position =
155
- this.menu.style.left =
156
- this.menu.style.top =
157
- this.menu.style.width =
158
- '';
159
- this.menu.style.display = '';
160
- this.spacer.parentNode.removeChild(this.spacer);
161
- this.spacer = null;
162
- }
163
- else {
164
- let border = (parent.offsetWidth - parent.clientWidth) / 2;
165
- this.menu.style.left = (editorRect.left + border) + 'px';
166
- this.menu.style.display = editorRect.top >
167
- this.editorView.dom.ownerDocument.defaultView
168
- .innerHeight
169
- ? 'none'
170
- : '';
171
- if (scrollAncestor)
172
- this.menu.style.top = top + 'px';
173
- }
174
- }
175
- else {
176
- if (editorRect.top < top && editorRect.bottom >= this.menu.offsetHeight + 10) {
177
- this.floating = true;
178
- let menuRect = this.menu.getBoundingClientRect();
179
- this.menu.style.left = menuRect.left + 'px';
180
- this.menu.style.width = menuRect.width + 'px';
181
- if (scrollAncestor)
182
- this.menu.style.top = top + 'px';
183
- this.menu.style.position = 'fixed';
184
- this.spacer = document.createElement('div');
185
- this.spacer.classList.add(CSS_PREFIX + '__spacer');
186
- this.spacer.style.height = `${menuRect.height}px`;
187
- parent.insertBefore(this.spacer, this.menu);
188
- }
189
- }
190
- }
191
- destroy() {
192
- if (this.wrapper.parentNode) {
193
- this.wrapper.parentNode.replaceChild(this.editorView.dom, this.wrapper);
194
- }
195
- }
196
- }
197
- // Not precise, but close enough
198
- function selectionIsInverted(selection) {
199
- if (selection.anchorNode == selection.focusNode) {
200
- return selection.anchorOffset > selection.focusOffset;
201
- }
202
- return selection.anchorNode.compareDocumentPosition(selection.focusNode) ==
203
- Node.DOCUMENT_POSITION_FOLLOWING;
204
- }
205
- function findWrappingScrollable(node) {
206
- for (let cur = node.parentNode; cur; cur = cur.parentNode) {
207
- if (cur.scrollHeight > cur.clientHeight) {
208
- return cur;
209
- }
210
- }
211
- }
212
- function getAllWrapping(node) {
213
- let res = [node.ownerDocument.defaultView];
214
- for (let cur = node.parentNode; cur; cur = cur.parentNode) {
215
- res.push(cur);
216
- }
217
- return res;
218
- }
219
- export class MenuPlugin extends Plugin {
220
- constructor(options) {
221
- super({
222
- view(editorView) {
223
- return new MenuBarView(editorView, options);
224
- },
225
- });
226
- }
227
- }
228
- /*
229
- /// A plugin that will place a menu bar above the editor. Note that
230
- /// this involves wrapping the editor in an additional `<div>`.
231
- export function menuBar(options: {
232
- /// Provides the content of the menu, as a nested array to be
233
- /// passed to `renderGrouped`.
234
- content: readonly (readonly MenuElement[])[]
235
-
236
- /// Determines whether the menu floats, i.e. whether it sticks to
237
- /// the top of the viewport when the editor is partially scrolled
238
- /// out of view.
239
- floating?: boolean
240
- }): Plugin {
241
- return new Plugin({
242
- view(editorView) { return new MenuBarView(editorView, options) }
243
- })
244
- }
245
- */