@kerebron/extension-menu 0.4.27 → 0.4.29
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.
- package/esm/CustomMenuPlugin.d.ts +117 -0
- package/esm/CustomMenuPlugin.d.ts.map +1 -0
- package/esm/CustomMenuPlugin.js +1634 -0
- package/esm/CustomMenuPlugin.js.map +1 -0
- package/esm/ExtensionCustomMenu.d.ts +11 -0
- package/esm/ExtensionCustomMenu.d.ts.map +1 -0
- package/esm/ExtensionCustomMenu.js +19 -0
- package/esm/ExtensionCustomMenu.js.map +1 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/buildMenu.d.ts +5 -0
- package/esm/buildMenu.d.ts.map +1 -0
- package/esm/buildMenu.js +447 -0
- package/esm/buildMenu.js.map +1 -0
- package/esm/icons.d.ts +15 -0
- package/esm/icons.d.ts.map +1 -0
- package/esm/icons.js +213 -0
- package/esm/icons.js.map +1 -0
- package/esm/menu.d.ts +83 -0
- package/esm/menu.d.ts.map +1 -0
- package/esm/menu.js +334 -0
- package/esm/menu.js.map +1 -0
- package/esm/mod.d.ts +3 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +3 -0
- package/esm/mod.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/prompt.d.ts +36 -0
- package/esm/prompt.d.ts.map +1 -0
- package/esm/prompt.js +165 -0
- package/esm/prompt.js.map +1 -0
- package/package.json +6 -3
- package/src/CustomMenuPlugin.ts +1996 -0
- package/src/ExtensionCustomMenu.ts +29 -0
- package/src/_dnt.shims.ts +60 -0
- package/src/buildMenu.ts +560 -0
- package/src/icons.ts +262 -0
- package/src/menu.ts +473 -0
- package/src/mod.ts +9 -0
- package/src/prompt.ts +205 -0
package/src/icons.ts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { IconSpec } from './menu.js';
|
|
2
|
+
|
|
3
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
4
|
+
const XLINK = 'http://www.w3.org/1999/xlink';
|
|
5
|
+
|
|
6
|
+
const prefix = 'kb-icon';
|
|
7
|
+
|
|
8
|
+
function hashPath(path: string) {
|
|
9
|
+
let hash = 0;
|
|
10
|
+
for (let i = 0; i < path.length; i++) {
|
|
11
|
+
hash = (((hash << 5) - hash) + path.charCodeAt(i)) | 0;
|
|
12
|
+
}
|
|
13
|
+
return hash;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getIcon(
|
|
17
|
+
root: Document | ShadowRoot,
|
|
18
|
+
icon: { path: string; width: number; height: number } | {
|
|
19
|
+
text: string;
|
|
20
|
+
css?: string;
|
|
21
|
+
} | { dom: Node },
|
|
22
|
+
): HTMLElement {
|
|
23
|
+
let doc = (root.nodeType == 9 ? root as Document : root.ownerDocument) ||
|
|
24
|
+
document;
|
|
25
|
+
let node = doc.createElement('div');
|
|
26
|
+
node.className = prefix;
|
|
27
|
+
if ((icon as any).path) {
|
|
28
|
+
let { path, width, height } = icon as {
|
|
29
|
+
path: string;
|
|
30
|
+
width: number;
|
|
31
|
+
height: number;
|
|
32
|
+
};
|
|
33
|
+
let name = 'pm-icon-' + hashPath(path).toString(16);
|
|
34
|
+
if (!doc.getElementById(name)) {
|
|
35
|
+
buildSVG(
|
|
36
|
+
root,
|
|
37
|
+
name,
|
|
38
|
+
icon as { path: string; width: number; height: number },
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
let svg = node.appendChild(doc.createElementNS(SVG, 'svg'));
|
|
42
|
+
svg.style.width = (width / height) + 'em';
|
|
43
|
+
let use = svg.appendChild(doc.createElementNS(SVG, 'use'));
|
|
44
|
+
use.setAttributeNS(
|
|
45
|
+
XLINK,
|
|
46
|
+
'href',
|
|
47
|
+
/([^#]*)/.exec(doc.location.toString())![1] + '#' + name,
|
|
48
|
+
);
|
|
49
|
+
} else if ((icon as any).dom) {
|
|
50
|
+
node.appendChild((icon as any).dom.cloneNode(true));
|
|
51
|
+
} else {
|
|
52
|
+
let { text, css } = icon as { text: string; css?: string };
|
|
53
|
+
node.appendChild(doc.createElement('span')).textContent = text || '';
|
|
54
|
+
if (css) (node.firstChild as HTMLElement).style.cssText = css;
|
|
55
|
+
}
|
|
56
|
+
return node;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function buildSVG(
|
|
60
|
+
root: Document | ShadowRoot,
|
|
61
|
+
name: string,
|
|
62
|
+
data: { width: number; height: number; path: string },
|
|
63
|
+
) {
|
|
64
|
+
let [doc, top] = root.nodeType == 9
|
|
65
|
+
? [root as Document, (root as Document).body]
|
|
66
|
+
: [root.ownerDocument || document, root];
|
|
67
|
+
let collection = doc.getElementById(prefix + '-collection') as Element;
|
|
68
|
+
if (!collection) {
|
|
69
|
+
collection = doc.createElementNS(SVG, 'svg');
|
|
70
|
+
collection.id = prefix + '-collection';
|
|
71
|
+
(collection as HTMLElement).style.display = 'none';
|
|
72
|
+
top.insertBefore(collection, top.firstChild);
|
|
73
|
+
}
|
|
74
|
+
let sym = doc.createElementNS(SVG, 'symbol');
|
|
75
|
+
sym.id = name;
|
|
76
|
+
sym.setAttribute('viewBox', '0 0 ' + data.width + ' ' + data.height);
|
|
77
|
+
let path = sym.appendChild(doc.createElementNS(SVG, 'path'));
|
|
78
|
+
path.setAttribute('d', data.path);
|
|
79
|
+
collection.appendChild(sym);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// A set of basic editor-related icons. Contains the properties
|
|
83
|
+
/// `join`, `lift`, `selectParentNode`, `undo`, `redo`, `strong`, `em`,
|
|
84
|
+
/// `code`, `link`, `bulletList`, `orderedList`, and `blockquote`, each
|
|
85
|
+
/// holding an object that can be used as the `icon` option to
|
|
86
|
+
/// `MenuItem`.
|
|
87
|
+
export const icons: { [name: string]: IconSpec } = {
|
|
88
|
+
join: {
|
|
89
|
+
width: 800,
|
|
90
|
+
height: 900,
|
|
91
|
+
path:
|
|
92
|
+
'M0 75h800v125h-800z M0 825h800v-125h-800z M250 400h100v-100h100v100h100v100h-100v100h-100v-100h-100z',
|
|
93
|
+
},
|
|
94
|
+
lift: {
|
|
95
|
+
width: 1024,
|
|
96
|
+
height: 1024,
|
|
97
|
+
path:
|
|
98
|
+
'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',
|
|
99
|
+
},
|
|
100
|
+
selectParentNode: {
|
|
101
|
+
width: 24,
|
|
102
|
+
height: 24,
|
|
103
|
+
path:
|
|
104
|
+
'M3 5h2V3c-1.1 0-2 .9-2 2zm0 8h2v-2H3v2zm4 8h2v-2H7v2zM3 9h2V7H3v2zm10-6h-2v2h2V3zm6 0v2h2c0-1.1-.9-2-2-2zM5 21v-2H3c0 1.1.9 2 2 2zm-2-4h2v-2H3v2zM9 3H7v2h2V3zm2 18h2v-2h-2v2zm8-8h2v-2h-2v2zm0 8c1.1 0 2-.9 2-2h-2v2zm0-12h2V7h-2v2zm0 8h2v-2h-2v2zm-4 4h2v-2h-2v2zm0-16h2V3h-2v2z',
|
|
105
|
+
},
|
|
106
|
+
undo: {
|
|
107
|
+
width: 24,
|
|
108
|
+
height: 24,
|
|
109
|
+
path:
|
|
110
|
+
'M12.5 8c-2.65 0-5.05 1-6.9 2.6L2 7v9h9l-3.62-3.62c1.39-1.16 3.16-1.88 5.12-1.88 3.54 0 6.55 2.31 7.6 5.5l2.37-.78C21.08 11.03 17.15 8 12.5 8z',
|
|
111
|
+
},
|
|
112
|
+
redo: {
|
|
113
|
+
width: 24,
|
|
114
|
+
height: 24,
|
|
115
|
+
path:
|
|
116
|
+
'M18.4 10.6C16.55 8.99 14.15 8 11.5 8c-4.65 0-8.58 3.03-9.96 7.22L3.9 16c1.05-3.19 4.05-5.5 7.6-5.5 1.95 0 3.73.72 5.12 1.88L13 16h9V7l-3.6 3.6z',
|
|
117
|
+
},
|
|
118
|
+
strong: {
|
|
119
|
+
width: 805,
|
|
120
|
+
height: 1024,
|
|
121
|
+
path:
|
|
122
|
+
'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',
|
|
123
|
+
},
|
|
124
|
+
em: {
|
|
125
|
+
width: 585,
|
|
126
|
+
height: 1024,
|
|
127
|
+
path:
|
|
128
|
+
'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',
|
|
129
|
+
},
|
|
130
|
+
underline: {
|
|
131
|
+
width: 585,
|
|
132
|
+
height: 1024,
|
|
133
|
+
path: 'M0 908h1024v64H0Z',
|
|
134
|
+
},
|
|
135
|
+
code: {
|
|
136
|
+
width: 896,
|
|
137
|
+
height: 1024,
|
|
138
|
+
path:
|
|
139
|
+
'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',
|
|
140
|
+
},
|
|
141
|
+
link: {
|
|
142
|
+
width: 951,
|
|
143
|
+
height: 1024,
|
|
144
|
+
path:
|
|
145
|
+
'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',
|
|
146
|
+
},
|
|
147
|
+
bulletList: {
|
|
148
|
+
width: 768,
|
|
149
|
+
height: 896,
|
|
150
|
+
path:
|
|
151
|
+
'M0 512h128v-128h-128v128zM0 256h128v-128h-128v128zM0 768h128v-128h-128v128zM256 512h512v-128h-512v128zM256 256h512v-128h-512v128zM256 768h512v-128h-512v128z',
|
|
152
|
+
},
|
|
153
|
+
orderedList: {
|
|
154
|
+
width: 768,
|
|
155
|
+
height: 896,
|
|
156
|
+
path:
|
|
157
|
+
'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',
|
|
158
|
+
},
|
|
159
|
+
taskList: {
|
|
160
|
+
width: 24,
|
|
161
|
+
height: 24,
|
|
162
|
+
path:
|
|
163
|
+
'M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z',
|
|
164
|
+
},
|
|
165
|
+
blockquote: {
|
|
166
|
+
width: 640,
|
|
167
|
+
height: 896,
|
|
168
|
+
path:
|
|
169
|
+
'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',
|
|
170
|
+
},
|
|
171
|
+
insert: {
|
|
172
|
+
width: 24,
|
|
173
|
+
height: 24,
|
|
174
|
+
path: 'M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z',
|
|
175
|
+
},
|
|
176
|
+
type: {
|
|
177
|
+
width: 20,
|
|
178
|
+
height: 22,
|
|
179
|
+
path: 'M2.5 3v3h5.5v13h4V6H17.5V3H2.5z',
|
|
180
|
+
},
|
|
181
|
+
table: {
|
|
182
|
+
width: 24,
|
|
183
|
+
height: 24,
|
|
184
|
+
path:
|
|
185
|
+
'M3 3v18h18V3H3zm8 16H5v-6h6v6zm0-8H5V5h6v6zm8 8h-6v-6h6v6zm0-8h-6V5h6v6z',
|
|
186
|
+
},
|
|
187
|
+
image: {
|
|
188
|
+
width: 24,
|
|
189
|
+
height: 24,
|
|
190
|
+
path:
|
|
191
|
+
'M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z',
|
|
192
|
+
},
|
|
193
|
+
horizontalRule: {
|
|
194
|
+
width: 24,
|
|
195
|
+
height: 24,
|
|
196
|
+
path: 'M4 11h16v2H4z',
|
|
197
|
+
},
|
|
198
|
+
heading: {
|
|
199
|
+
width: 18,
|
|
200
|
+
height: 23,
|
|
201
|
+
path: 'M2.5 3v17h3v-7h7v7h3V3h-3v8h-7V3h-3z',
|
|
202
|
+
},
|
|
203
|
+
strike: {
|
|
204
|
+
width: 24,
|
|
205
|
+
height: 24,
|
|
206
|
+
path: 'M10 19h4v-3h-4v3zM5 4v3h5v3h4V7h5V4H5zM3 14h18v-2H3v2z',
|
|
207
|
+
},
|
|
208
|
+
highlight: {
|
|
209
|
+
width: 24,
|
|
210
|
+
height: 24,
|
|
211
|
+
path:
|
|
212
|
+
'M17.75 7L14 3.25l-10 10V17h3.75l10-10zm2.96-2.96a.996.996 0 0 0 0-1.41L18.37.29a.996.996 0 0 0-1.41 0L15 2.25 18.75 6l1.96-1.96zM2 20h20v4H2z',
|
|
213
|
+
},
|
|
214
|
+
indent: {
|
|
215
|
+
width: 24,
|
|
216
|
+
height: 24,
|
|
217
|
+
path:
|
|
218
|
+
'M3 21h18v-2H3v2zM3 8v8l4-4-4-4zm8 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z',
|
|
219
|
+
},
|
|
220
|
+
outdent: {
|
|
221
|
+
width: 24,
|
|
222
|
+
height: 24,
|
|
223
|
+
path:
|
|
224
|
+
'M3 21h18v-2H3v2zM7 8v8l-4-4 4-4zm4 9h10v-2H11v2zM3 3v2h18V3H3zm8 6h10V7H11v2zm0 4h10v-2H11v2z',
|
|
225
|
+
},
|
|
226
|
+
superscript: {
|
|
227
|
+
width: 24,
|
|
228
|
+
height: 24,
|
|
229
|
+
path:
|
|
230
|
+
'M22 7h-2v1h3v1h-4V7c0-.55.45-1 1-1h2V5h-3V4h3c.55 0 1 .45 1 1v1c0 .55-.45 1-1 1zM5.88 20h2.66l3.4-5.42h.12l3.4 5.42h2.66l-4.65-7.27L17.81 6h-2.68l-3.07 4.99h-.12L8.87 6H6.19l4.32 6.73L5.88 20z',
|
|
231
|
+
},
|
|
232
|
+
subscript: {
|
|
233
|
+
width: 24,
|
|
234
|
+
height: 24,
|
|
235
|
+
path:
|
|
236
|
+
'M22 18h-2v1h3v1h-4v-2c0-.55.45-1 1-1h2v-1h-3v-1h3c.55 0 1 .45 1 1v1c0 .55-.45 1-1 1zM5.88 18h2.66l3.4-5.42h.12l3.4 5.42h2.66l-4.65-7.27L17.81 4h-2.68l-3.07 4.99h-.12L8.87 4H6.19l4.32 6.73L5.88 18z',
|
|
237
|
+
},
|
|
238
|
+
alignLeft: {
|
|
239
|
+
width: 24,
|
|
240
|
+
height: 24,
|
|
241
|
+
path:
|
|
242
|
+
'M15 15H3v2h12v-2zm0-8H3v2h12V7zM3 13h18v-2H3v2zm0 8h18v-2H3v2zM3 3v2h18V3H3z',
|
|
243
|
+
},
|
|
244
|
+
alignCenter: {
|
|
245
|
+
width: 24,
|
|
246
|
+
height: 24,
|
|
247
|
+
path:
|
|
248
|
+
'M7 15v2h10v-2H7zm-4 6h18v-2H3v2zm0-8h18v-2H3v2zm4-6v2h10V7H7zM3 3v2h18V3H3z',
|
|
249
|
+
},
|
|
250
|
+
alignRight: {
|
|
251
|
+
width: 24,
|
|
252
|
+
height: 24,
|
|
253
|
+
path:
|
|
254
|
+
'M3 21h18v-2H3v2zm6-4h12v-2H9v2zm-6-4h18v-2H3v2zm6-4h12V7H9v2zM3 3v2h18V3H3z',
|
|
255
|
+
},
|
|
256
|
+
alignJustify: {
|
|
257
|
+
width: 24,
|
|
258
|
+
height: 24,
|
|
259
|
+
path:
|
|
260
|
+
'M3 21h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18v-2H3v2zm0-4h18V7H3v2zm0-6v2h18V3H3z',
|
|
261
|
+
},
|
|
262
|
+
};
|