@kerebron/extension-menu 0.1.2 → 0.2.0

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 (60) hide show
  1. package/assets/menu.css +539 -0
  2. package/package.json +4 -1
  3. package/esm/editor/src/CoreEditor.d.ts +0 -25
  4. package/esm/editor/src/CoreEditor.d.ts.map +0 -1
  5. package/esm/editor/src/CoreEditor.js +0 -194
  6. package/esm/editor/src/Extension.d.ts +0 -26
  7. package/esm/editor/src/Extension.d.ts.map +0 -1
  8. package/esm/editor/src/Extension.js +0 -33
  9. package/esm/editor/src/ExtensionManager.d.ts +0 -32
  10. package/esm/editor/src/ExtensionManager.d.ts.map +0 -1
  11. package/esm/editor/src/ExtensionManager.js +0 -253
  12. package/esm/editor/src/Mark.d.ts +0 -18
  13. package/esm/editor/src/Mark.d.ts.map +0 -1
  14. package/esm/editor/src/Mark.js +0 -34
  15. package/esm/editor/src/Node.d.ts +0 -27
  16. package/esm/editor/src/Node.d.ts.map +0 -1
  17. package/esm/editor/src/Node.js +0 -43
  18. package/esm/editor/src/commands/CommandManager.d.ts +0 -20
  19. package/esm/editor/src/commands/CommandManager.d.ts.map +0 -1
  20. package/esm/editor/src/commands/CommandManager.js +0 -60
  21. package/esm/editor/src/commands/createChainableState.d.ts +0 -3
  22. package/esm/editor/src/commands/createChainableState.d.ts.map +0 -1
  23. package/esm/editor/src/commands/createChainableState.js +0 -29
  24. package/esm/editor/src/commands/mod.d.ts +0 -49
  25. package/esm/editor/src/commands/mod.d.ts.map +0 -1
  26. package/esm/editor/src/commands/mod.js +0 -928
  27. package/esm/editor/src/mod.d.ts +0 -6
  28. package/esm/editor/src/mod.d.ts.map +0 -1
  29. package/esm/editor/src/mod.js +0 -5
  30. package/esm/editor/src/nodeToTreeString.d.ts +0 -4
  31. package/esm/editor/src/nodeToTreeString.d.ts.map +0 -1
  32. package/esm/editor/src/nodeToTreeString.js +0 -56
  33. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts +0 -23
  34. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.d.ts.map +0 -1
  35. package/esm/editor/src/plugins/input-rules/InputRulesPlugin.js +0 -163
  36. package/esm/editor/src/types.d.ts +0 -29
  37. package/esm/editor/src/types.d.ts.map +0 -1
  38. package/esm/editor/src/types.js +0 -1
  39. package/esm/editor/src/utilities/createNodeFromContent.d.ts +0 -8
  40. package/esm/editor/src/utilities/createNodeFromContent.d.ts.map +0 -1
  41. package/esm/editor/src/utilities/createNodeFromContent.js +0 -33
  42. package/esm/editor/src/utilities/getHtmlAttributes.d.ts +0 -4
  43. package/esm/editor/src/utilities/getHtmlAttributes.d.ts.map +0 -1
  44. package/esm/editor/src/utilities/getHtmlAttributes.js +0 -47
  45. package/esm/extension-menu/src/ExtensionMenu.d.ts +0 -17
  46. package/esm/extension-menu/src/ExtensionMenu.d.ts.map +0 -1
  47. package/esm/extension-menu/src/ExtensionMenu.js +0 -318
  48. package/esm/extension-menu/src/MenuPlugin.d.ts +0 -9
  49. package/esm/extension-menu/src/MenuPlugin.d.ts.map +0 -1
  50. package/esm/extension-menu/src/MenuPlugin.js +0 -246
  51. package/esm/extension-menu/src/icons.d.ts +0 -15
  52. package/esm/extension-menu/src/icons.d.ts.map +0 -1
  53. package/esm/extension-menu/src/icons.js +0 -118
  54. package/esm/extension-menu/src/menu.d.ts +0 -86
  55. package/esm/extension-menu/src/menu.d.ts.map +0 -1
  56. package/esm/extension-menu/src/menu.js +0 -353
  57. package/esm/extension-menu/src/prompt.d.ts +0 -36
  58. package/esm/extension-menu/src/prompt.d.ts.map +0 -1
  59. package/esm/extension-menu/src/prompt.js +0 -158
  60. package/esm/package.json +0 -3
@@ -1,118 +0,0 @@
1
- const SVG = 'http://www.w3.org/2000/svg';
2
- const XLINK = 'http://www.w3.org/1999/xlink';
3
- const prefix = 'ProseMirror-icon';
4
- function hashPath(path) {
5
- let hash = 0;
6
- for (let i = 0; i < path.length; i++) {
7
- hash = (((hash << 5) - hash) + path.charCodeAt(i)) | 0;
8
- }
9
- return hash;
10
- }
11
- export function getIcon(root, icon) {
12
- let doc = (root.nodeType == 9 ? root : root.ownerDocument) ||
13
- document;
14
- let node = doc.createElement('div');
15
- node.className = prefix;
16
- if (icon.path) {
17
- let { path, width, height } = icon;
18
- let name = 'pm-icon-' + hashPath(path).toString(16);
19
- if (!doc.getElementById(name)) {
20
- buildSVG(root, name, icon);
21
- }
22
- let svg = node.appendChild(doc.createElementNS(SVG, 'svg'));
23
- svg.style.width = (width / height) + 'em';
24
- let use = svg.appendChild(doc.createElementNS(SVG, 'use'));
25
- use.setAttributeNS(XLINK, 'href', /([^#]*)/.exec(doc.location.toString())[1] + '#' + name);
26
- }
27
- else if (icon.dom) {
28
- node.appendChild(icon.dom.cloneNode(true));
29
- }
30
- else {
31
- let { text, css } = icon;
32
- node.appendChild(doc.createElement('span')).textContent = text || '';
33
- if (css)
34
- node.firstChild.style.cssText = css;
35
- }
36
- return node;
37
- }
38
- function buildSVG(root, name, data) {
39
- let [doc, top] = root.nodeType == 9
40
- ? [root, root.body]
41
- : [root.ownerDocument || document, root];
42
- let collection = doc.getElementById(prefix + '-collection');
43
- if (!collection) {
44
- collection = doc.createElementNS(SVG, 'svg');
45
- collection.id = prefix + '-collection';
46
- collection.style.display = 'none';
47
- top.insertBefore(collection, top.firstChild);
48
- }
49
- let sym = doc.createElementNS(SVG, 'symbol');
50
- sym.id = name;
51
- sym.setAttribute('viewBox', '0 0 ' + data.width + ' ' + data.height);
52
- let path = sym.appendChild(doc.createElementNS(SVG, 'path'));
53
- path.setAttribute('d', data.path);
54
- collection.appendChild(sym);
55
- }
56
- /// A set of basic editor-related icons. Contains the properties
57
- /// `join`, `lift`, `selectParentNode`, `undo`, `redo`, `strong`, `em`,
58
- /// `code`, `link`, `bulletList`, `orderedList`, and `blockquote`, each
59
- /// holding an object that can be used as the `icon` option to
60
- /// `MenuItem`.
61
- export const icons = {
62
- join: {
63
- width: 800,
64
- height: 900,
65
- path: 'M0 75h800v125h-800z M0 825h800v-125h-800z M250 400h100v-100h100v100h100v100h-100v100h-100v-100h-100z',
66
- },
67
- lift: {
68
- width: 1024,
69
- height: 1024,
70
- path: 'M219 310v329q0 7-5 12t-12 5q-8 0-13-5l-164-164q-5-5-5-13t5-13l164-164q5-5 13-5 7 0 12 5t5 12zM1024 749v109q0 7-5 12t-12 5h-987q-7 0-12-5t-5-12v-109q0-7 5-12t12-5h987q7 0 12 5t5 12zM1024 530v109q0 7-5 12t-12 5h-621q-7 0-12-5t-5-12v-109q0-7 5-12t12-5h621q7 0 12 5t5 12zM1024 310v109q0 7-5 12t-12 5h-621q-7 0-12-5t-5-12v-109q0-7 5-12t12-5h621q7 0 12 5t5 12zM1024 91v109q0 7-5 12t-12 5h-987q-7 0-12-5t-5-12v-109q0-7 5-12t12-5h987q7 0 12 5t5 12z',
71
- },
72
- selectParentNode: { text: '\u2b1a', css: 'font-weight: bold' },
73
- undo: {
74
- width: 1024,
75
- height: 1024,
76
- path: 'M761 1024c113-206 132-520-313-509v253l-384-384 384-384v248c534-13 594 472 313 775z',
77
- },
78
- redo: {
79
- width: 1024,
80
- height: 1024,
81
- path: 'M576 248v-248l384 384-384 384v-253c-446-10-427 303-313 509-280-303-221-789 313-775z',
82
- },
83
- strong: {
84
- width: 805,
85
- height: 1024,
86
- path: 'M317 869q42 18 80 18 214 0 214-191 0-65-23-102-15-25-35-42t-38-26-46-14-48-6-54-1q-41 0-57 5 0 30-0 90t-0 90q0 4-0 38t-0 55 2 47 6 38zM309 442q24 4 62 4 46 0 81-7t62-25 42-51 14-81q0-40-16-70t-45-46-61-24-70-8q-28 0-74 7 0 28 2 86t2 86q0 15-0 45t-0 45q0 26 0 39zM0 950l1-53q8-2 48-9t60-15q4-6 7-15t4-19 3-18 1-21 0-19v-37q0-561-12-585-2-4-12-8t-25-6-28-4-27-2-17-1l-2-47q56-1 194-6t213-5q13 0 39 0t38 0q40 0 78 7t73 24 61 40 42 59 16 78q0 29-9 54t-22 41-36 32-41 25-48 22q88 20 146 76t58 141q0 57-20 102t-53 74-78 48-93 27-100 8q-25 0-75-1t-75-1q-60 0-175 6t-132 6z',
87
- },
88
- em: {
89
- width: 585,
90
- height: 1024,
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
- },
93
- code: {
94
- width: 896,
95
- height: 1024,
96
- path: 'M608 192l-96 96 224 224-224 224 96 96 288-320-288-320zM288 192l-288 320 288 320 96-96-224-224 224-224-96-96z',
97
- },
98
- link: {
99
- width: 951,
100
- height: 1024,
101
- path: 'M832 694q0-22-16-38l-118-118q-16-16-38-16-24 0-41 18 1 1 10 10t12 12 8 10 7 14 2 15q0 22-16 38t-38 16q-8 0-15-2t-14-7-10-8-12-12-10-10q-18 17-18 41 0 22 16 38l117 118q15 15 38 15 22 0 38-14l84-83q16-16 16-38zM430 292q0-22-16-38l-117-118q-16-16-38-16-22 0-38 15l-84 83q-16 16-16 38 0 22 16 38l118 118q15 15 38 15 24 0 41-17-1-1-10-10t-12-12-8-10-7-14-2-15q0-22 16-38t38-16q8 0 15 2t14 7 10 8 12 12 10 10q18-17 18-41zM941 694q0 68-48 116l-84 83q-47 47-116 47-69 0-116-48l-117-118q-47-47-47-116 0-70 50-119l-50-50q-49 50-118 50-68 0-116-48l-118-118q-48-48-48-116t48-116l84-83q47-47 116-47 69 0 116 48l117 118q47 47 47 116 0 70-50 119l50 50q49-50 118-50 68 0 116 48l118 118q48 48 48 116z',
102
- },
103
- bulletList: {
104
- width: 768,
105
- height: 896,
106
- path: 'M0 512h128v-128h-128v128zM0 256h128v-128h-128v128zM0 768h128v-128h-128v128zM256 512h512v-128h-512v128zM256 256h512v-128h-512v128zM256 768h512v-128h-512v128z',
107
- },
108
- orderedList: {
109
- width: 768,
110
- height: 896,
111
- path: 'M320 512h448v-128h-448v128zM320 768h448v-128h-448v128zM320 128v128h448v-128h-448zM79 384h78v-256h-36l-85 23v50l43-2v185zM189 590c0-36-12-78-96-78-33 0-64 6-83 16l1 66c21-10 42-15 67-15s32 11 32 28c0 26-30 58-110 112v50h192v-67l-91 2c49-30 87-66 87-113l1-1z',
112
- },
113
- blockquote: {
114
- width: 640,
115
- height: 896,
116
- path: 'M0 448v256h256v-256h-128c0 0 0-128 128-128v-128c0 0-256 0-256 256zM640 320v-128c0 0-256 0-256 256v256h256v-256h-128c0 0 0-128 128-128z',
117
- },
118
- };
@@ -1,86 +0,0 @@
1
- import { EditorView } from 'prosemirror-view';
2
- import { EditorState, Transaction } from 'prosemirror-state';
3
- import { Attrs, NodeType } from 'prosemirror-model';
4
- export interface MenuElement {
5
- render(pm: EditorView): {
6
- dom: HTMLElement;
7
- update: (state: EditorState) => boolean;
8
- };
9
- }
10
- export declare class MenuItem implements MenuElement {
11
- readonly spec: MenuItemSpec;
12
- constructor(spec: MenuItemSpec);
13
- render(view: EditorView): {
14
- dom: any;
15
- update: (state: EditorState) => boolean;
16
- };
17
- }
18
- export type IconSpec = {
19
- path: string;
20
- width: number;
21
- height: number;
22
- } | {
23
- text: string;
24
- css?: string;
25
- } | {
26
- dom: Node;
27
- };
28
- export interface MenuItemSpec {
29
- run: (state: EditorState, dispatch: (tr: Transaction) => void) => boolean;
30
- select?: (state: EditorState) => boolean;
31
- enable?: (state: EditorState) => boolean;
32
- active?: (state: EditorState) => boolean;
33
- render?: (view: EditorView) => HTMLElement;
34
- icon?: IconSpec;
35
- label?: string;
36
- title?: string | ((state: EditorState) => string);
37
- class?: string;
38
- css?: string;
39
- }
40
- export declare class Dropdown implements MenuElement {
41
- readonly options: {
42
- label?: string;
43
- title?: string;
44
- class?: string;
45
- css?: string;
46
- };
47
- content: readonly MenuElement[];
48
- constructor(content: readonly MenuElement[] | MenuElement, options?: {
49
- label?: string;
50
- title?: string;
51
- class?: string;
52
- css?: string;
53
- });
54
- render(view: EditorView): {
55
- dom: any;
56
- update: (state: EditorState) => boolean;
57
- };
58
- expand(dom: HTMLElement, items: readonly Node[]): {
59
- close: () => boolean;
60
- node: any;
61
- };
62
- }
63
- export declare class DropdownSubmenu implements MenuElement {
64
- readonly options: {
65
- label?: string;
66
- };
67
- content: readonly MenuElement[];
68
- constructor(content: readonly MenuElement[] | MenuElement, options?: {
69
- label?: string;
70
- });
71
- render(view: EditorView): {
72
- dom: any;
73
- update: (state: EditorState) => boolean;
74
- };
75
- }
76
- export declare function renderGrouped(view: EditorView, content: readonly (readonly MenuElement[])[]): {
77
- dom: any;
78
- update: (state: EditorState) => boolean;
79
- };
80
- export declare function wrapItem(nodeType: NodeType, options: Partial<MenuItemSpec> & {
81
- attrs?: Attrs | null;
82
- }): MenuItem;
83
- export declare function blockTypeItem(nodeType: NodeType, options: Partial<MenuItemSpec> & {
84
- attrs?: Attrs | null;
85
- }): MenuItem;
86
- //# sourceMappingURL=menu.d.ts.map
@@ -1 +0,0 @@
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;AAKD,qBAAa,QA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,0 @@
1
- import { setBlockType, wrapIn, } from '../../editor/src/commands/mod.js';
2
- import { getIcon } from './icons.js';
3
- const prefix = 'ProseMirror-menu';
4
- /// An icon or label that, when clicked, executes a command.
5
- export class MenuItem {
6
- /// Create a menu item.
7
- constructor(
8
- /// The spec used to create this item.
9
- spec) {
10
- Object.defineProperty(this, "spec", {
11
- enumerable: true,
12
- configurable: true,
13
- writable: true,
14
- value: spec
15
- });
16
- }
17
- /// Renders the icon according to its [display
18
- /// spec](#menu.MenuItemSpec.display), and adds an event handler which
19
- /// executes the command when the representation is clicked.
20
- render(view) {
21
- let spec = this.spec;
22
- let dom = spec.render ? spec.render(view) : null;
23
- if (!dom && spec.icon) {
24
- dom = getIcon(view.root, spec.icon);
25
- }
26
- if (!dom && spec.label) {
27
- dom = document.createElement('div');
28
- dom.appendChild(document.createTextNode(translate(view, spec.label)));
29
- }
30
- if (!dom)
31
- throw new RangeError('MenuItem without icon or label property');
32
- if (spec.title) {
33
- const title = typeof spec.title === 'function'
34
- ? spec.title(view.state)
35
- : spec.title;
36
- dom.setAttribute('title', translate(view, title));
37
- }
38
- if (spec.class)
39
- dom.classList.add(spec.class);
40
- if (spec.css)
41
- dom.style.cssText += spec.css;
42
- dom.addEventListener('mousedown', (e) => {
43
- e.preventDefault();
44
- if (!dom.classList.contains(prefix + '-disabled')) {
45
- spec.run(view.state, view.dispatch);
46
- }
47
- });
48
- function update(state) {
49
- if (spec.select) {
50
- let selected = spec.select(state);
51
- dom.style.display = selected ? '' : 'none';
52
- if (!selected)
53
- return false;
54
- }
55
- let enabled = true;
56
- if (spec.enable) {
57
- enabled = spec.enable(state) || false;
58
- setClass(dom, prefix + '-disabled', !enabled);
59
- }
60
- if (spec.active) {
61
- let active = enabled && spec.active(state) || false;
62
- setClass(dom, prefix + '-active', active);
63
- }
64
- return true;
65
- }
66
- return { dom, update };
67
- }
68
- }
69
- function translate(view, text) {
70
- return view._props.translate
71
- ? view._props.translate(text)
72
- : text;
73
- }
74
- let lastMenuEvent = {
75
- time: 0,
76
- node: null,
77
- };
78
- function markMenuEvent(e) {
79
- lastMenuEvent.time = Date.now();
80
- lastMenuEvent.node = e.target;
81
- }
82
- function isMenuEvent(wrapper) {
83
- return Date.now() - 100 < lastMenuEvent.time &&
84
- lastMenuEvent.node && wrapper.contains(lastMenuEvent.node);
85
- }
86
- /// A drop-down menu, displayed as a label with a downwards-pointing
87
- /// triangle to the right of it.
88
- export class Dropdown {
89
- /// Create a dropdown wrapping the elements.
90
- constructor(content,
91
- /// @internal
92
- options = {}) {
93
- Object.defineProperty(this, "options", {
94
- enumerable: true,
95
- configurable: true,
96
- writable: true,
97
- value: options
98
- });
99
- /// @internal
100
- Object.defineProperty(this, "content", {
101
- enumerable: true,
102
- configurable: true,
103
- writable: true,
104
- value: void 0
105
- });
106
- this.options = options || {};
107
- this.content = Array.isArray(content) ? content : [content];
108
- }
109
- /// Render the dropdown menu and sub-items.
110
- render(view) {
111
- let content = renderDropdownItems(this.content, view);
112
- let win = view.dom.ownerDocument.defaultView;
113
- let label = document.createElement('div');
114
- label.classList.add(prefix + '-dropdown');
115
- if (this.options.class) {
116
- label.classList.add(this.options.class);
117
- }
118
- if (this.options.css)
119
- label.setAttribute('style', this.options.css);
120
- label.appendChild(document.createTextNode(translate(view, this.options.label || '')));
121
- if (this.options.title) {
122
- label.setAttribute('title', translate(view, this.options.title));
123
- }
124
- let wrap = document.createElement('div');
125
- wrap.classList.add(prefix + '-dropdown-wrap');
126
- wrap.appendChild(label);
127
- let open = null;
128
- let listeningOnClose = null;
129
- let close = () => {
130
- if (open && open.close()) {
131
- open = null;
132
- win.removeEventListener('mousedown', listeningOnClose);
133
- }
134
- };
135
- label.addEventListener('mousedown', (e) => {
136
- e.preventDefault();
137
- markMenuEvent(e);
138
- if (open) {
139
- close();
140
- }
141
- else {
142
- open = this.expand(wrap, content.dom);
143
- win.addEventListener('mousedown', listeningOnClose = () => {
144
- if (!isMenuEvent(wrap))
145
- close();
146
- });
147
- }
148
- });
149
- function update(state) {
150
- let inner = content.update(state);
151
- wrap.style.display = inner ? '' : 'none';
152
- return inner;
153
- }
154
- return { dom: wrap, update };
155
- }
156
- /// @internal
157
- expand(dom, items) {
158
- const menuDOM = document.createElement('div');
159
- menuDOM.classList.add(prefix + '-dropdown-menu');
160
- if (this.options.class) {
161
- menuDOM.classList.add(this.options.class);
162
- }
163
- items.forEach((item) => menuDOM.appendChild(item));
164
- let done = false;
165
- function close() {
166
- if (done)
167
- return false;
168
- done = true;
169
- dom.removeChild(menuDOM);
170
- return true;
171
- }
172
- dom.appendChild(menuDOM);
173
- return { close, node: menuDOM };
174
- }
175
- }
176
- function renderDropdownItems(items, view) {
177
- let rendered = [], updates = [];
178
- for (let i = 0; i < items.length; i++) {
179
- let { dom, update } = items[i].render(view);
180
- const item = document.createElement('div');
181
- item.classList.add(prefix + '-dropdown-item');
182
- item.appendChild(dom);
183
- rendered.push(item);
184
- updates.push(update);
185
- }
186
- return { dom: rendered, update: combineUpdates(updates, rendered) };
187
- }
188
- function combineUpdates(updates, nodes) {
189
- return (state) => {
190
- let something = false;
191
- for (let i = 0; i < updates.length; i++) {
192
- let up = updates[i](state);
193
- nodes[i].style.display = up ? '' : 'none';
194
- if (up)
195
- something = true;
196
- }
197
- return something;
198
- };
199
- }
200
- /// Represents a submenu wrapping a group of elements that start
201
- /// hidden and expand to the right when hovered over or tapped.
202
- export class DropdownSubmenu {
203
- /// Creates a submenu for the given group of menu elements. The
204
- /// following options are recognized:
205
- constructor(content,
206
- /// @internal
207
- options = {}) {
208
- Object.defineProperty(this, "options", {
209
- enumerable: true,
210
- configurable: true,
211
- writable: true,
212
- value: options
213
- });
214
- /// @internal
215
- Object.defineProperty(this, "content", {
216
- enumerable: true,
217
- configurable: true,
218
- writable: true,
219
- value: void 0
220
- });
221
- this.content = Array.isArray(content) ? content : [content];
222
- }
223
- /// Renders the submenu.
224
- render(view) {
225
- const items = renderDropdownItems(this.content, view);
226
- const win = view.dom.ownerDocument.defaultView;
227
- const label = document.createElement('div');
228
- label.classList.add(prefix + '-submenu-label');
229
- label.appendChild(document.createTextNode(translate(view, this.options.label || '')));
230
- const wrap = document.createElement('div');
231
- wrap.classList.add(prefix + '-submenu-wrap');
232
- wrap.appendChild(label);
233
- const submenu = document.createElement('div');
234
- submenu.classList.add(prefix + '-submenu');
235
- items.dom.forEach((item) => submenu.appendChild(item));
236
- wrap.appendChild(submenu);
237
- let listeningOnClose = null;
238
- label.addEventListener('mousedown', (e) => {
239
- e.preventDefault();
240
- markMenuEvent(e);
241
- setClass(wrap, prefix + '-submenu-wrap-active', false);
242
- if (!listeningOnClose) {
243
- win.addEventListener('mousedown', listeningOnClose = () => {
244
- if (!isMenuEvent(wrap)) {
245
- wrap.classList.remove(prefix + '-submenu-wrap-active');
246
- win.removeEventListener('mousedown', listeningOnClose);
247
- listeningOnClose = null;
248
- }
249
- });
250
- }
251
- });
252
- function update(state) {
253
- let inner = items.update(state);
254
- wrap.style.display = inner ? '' : 'none';
255
- return inner;
256
- }
257
- return { dom: wrap, update };
258
- }
259
- }
260
- /// Render the given, possibly nested, array of menu elements into a
261
- /// document fragment, placing separators between them (and ensuring no
262
- /// superfluous separators appear when some of the groups turn out to
263
- /// be empty).
264
- export function renderGrouped(view, content) {
265
- let result = document.createDocumentFragment();
266
- let updates = [], separators = [];
267
- for (let i = 0; i < content.length; i++) {
268
- let items = content[i], localUpdates = [], localNodes = [];
269
- for (let j = 0; j < items.length; j++) {
270
- let { dom, update } = items[j].render(view);
271
- let span = document.createElement('span');
272
- span.classList.add(prefix + 'item');
273
- span.appendChild(dom);
274
- result.appendChild(span);
275
- localNodes.push(span);
276
- localUpdates.push(update);
277
- }
278
- if (localUpdates.length) {
279
- updates.push(combineUpdates(localUpdates, localNodes));
280
- if (i < content.length - 1) {
281
- separators.push(result.appendChild(separator()));
282
- }
283
- }
284
- }
285
- function update(state) {
286
- let something = false, needSep = false;
287
- for (let i = 0; i < updates.length; i++) {
288
- let hasContent = updates[i](state);
289
- if (i) {
290
- separators[i - 1].style.display = needSep && hasContent ? '' : 'none';
291
- }
292
- needSep = hasContent;
293
- if (hasContent)
294
- something = true;
295
- }
296
- return something;
297
- }
298
- return { dom: result, update };
299
- }
300
- function separator() {
301
- const elem = document.createElement('div');
302
- elem.classList.add(prefix + 'separator');
303
- return elem;
304
- }
305
- /// Build a menu item for wrapping the selection in a given node type.
306
- /// Adds `run` and `select` properties to the ones present in
307
- /// `options`. `options.attrs` may be an object that provides
308
- /// attributes for the wrapping node.
309
- export function wrapItem(nodeType, options) {
310
- let passedOptions = {
311
- run(state, dispatch) {
312
- return wrapIn(nodeType, options.attrs)(state, dispatch);
313
- },
314
- select(state) {
315
- return wrapIn(nodeType, options.attrs)(state);
316
- },
317
- };
318
- for (let prop in options) {
319
- passedOptions[prop] = options[prop];
320
- }
321
- return new MenuItem(passedOptions);
322
- }
323
- /// Build a menu item for changing the type of the textblock around the
324
- /// selection to the given type. Provides `run`, `active`, and `select`
325
- /// properties. Others must be given in `options`. `options.attrs` may
326
- /// be an object to provide the attributes for the textblock node.
327
- export function blockTypeItem(nodeType, options) {
328
- let command = setBlockType(nodeType, options.attrs);
329
- let passedOptions = {
330
- run: command,
331
- enable(state) {
332
- return command(state);
333
- },
334
- active(state) {
335
- let { $from, to, node } = state.selection;
336
- if (node)
337
- return node.hasMarkup(nodeType, options.attrs);
338
- return to <= $from.end() &&
339
- $from.parent.hasMarkup(nodeType, options.attrs);
340
- },
341
- };
342
- for (let prop in options) {
343
- passedOptions[prop] = options[prop];
344
- }
345
- return new MenuItem(passedOptions);
346
- }
347
- // Work around classList.toggle being broken in IE11
348
- function setClass(dom, cls, on) {
349
- if (on)
350
- dom.classList.add(cls);
351
- else
352
- dom.classList.remove(cls);
353
- }
@@ -1,36 +0,0 @@
1
- import { Attrs } from 'prosemirror-model';
2
- export declare function openPrompt(options: {
3
- title: string;
4
- fields: {
5
- [name: string]: Field;
6
- };
7
- callback: (attrs: Attrs) => void;
8
- }): void;
9
- export declare abstract class Field {
10
- readonly options: {
11
- value?: any;
12
- label: string;
13
- required?: boolean;
14
- validate?: (value: any) => string | null;
15
- clean?: (value: any) => any;
16
- };
17
- constructor(options: {
18
- value?: any;
19
- label: string;
20
- required?: boolean;
21
- validate?: (value: any) => string | null;
22
- clean?: (value: any) => any;
23
- });
24
- abstract render(): HTMLElement;
25
- read(dom: HTMLElement): any;
26
- validateType(value: any): string | null;
27
- validate(value: any): string | null;
28
- clean(value: any): any;
29
- }
30
- export declare class TextField extends Field {
31
- render(): any;
32
- }
33
- export declare class SelectField extends Field {
34
- render(): any;
35
- }
36
- //# sourceMappingURL=prompt.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/extension-menu/src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI1C,wBAAgB,UAAU,CAAC,OAAO,EAAE;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;KAAE,CAAC;IAClC,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC,QA0EA;AA+BD,8BAAsB,KAAK;IAKvB,QAAQ,CAAC,OAAO,EAAE;QAEhB,KAAK,CAAC,EAAE,GAAG,CAAC;QAGZ,KAAK,EAAE,MAAM,CAAC;QAGd,QAAQ,CAAC,EAAE,OAAO,CAAC;QAInB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,GAAG,IAAI,CAAC;QAGzC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;KAC7B;gBAhBQ,OAAO,EAAE;QAEhB,KAAK,CAAC,EAAE,GAAG,CAAC;QAGZ,KAAK,EAAE,MAAM,CAAC;QAGd,QAAQ,CAAC,EAAE,OAAO,CAAC;QAInB,QAAQ,CAAC,E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