@blockslides/extension-bubble-menu-preset 0.1.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.
- package/LICENSE.md +36 -0
- package/README.md +74 -0
- package/dist/index.cjs +701 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.js +676 -0
- package/dist/index.js.map +1 -0
- package/package.json +60 -0
- package/src/bubble-menu-preset.ts +809 -0
- package/src/index.ts +3 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
// src/bubble-menu-preset.ts
|
|
2
|
+
import { Extension } from "@blockslides/core";
|
|
3
|
+
import {
|
|
4
|
+
BubbleMenuPlugin
|
|
5
|
+
} from "@blockslides/extension-bubble-menu";
|
|
6
|
+
var STYLE_ID = "blockslides-bubble-menu-preset-styles";
|
|
7
|
+
var DEFAULT_ITEMS = [
|
|
8
|
+
"undo",
|
|
9
|
+
"redo",
|
|
10
|
+
"fontFamily",
|
|
11
|
+
"fontSize",
|
|
12
|
+
"bold",
|
|
13
|
+
"italic",
|
|
14
|
+
"underline",
|
|
15
|
+
"textColor",
|
|
16
|
+
"highlightColor",
|
|
17
|
+
"link",
|
|
18
|
+
"align"
|
|
19
|
+
];
|
|
20
|
+
var DEFAULT_FONTS = [
|
|
21
|
+
"Inter",
|
|
22
|
+
"Arial",
|
|
23
|
+
"Helvetica",
|
|
24
|
+
"Times New Roman",
|
|
25
|
+
"Georgia",
|
|
26
|
+
"Courier New",
|
|
27
|
+
"Monaco"
|
|
28
|
+
];
|
|
29
|
+
var DEFAULT_FONT_SIZES = ["12px", "14px", "16px", "18px", "20px", "24px", "32px", "40px"];
|
|
30
|
+
var DEFAULT_ALIGNMENTS = ["left", "center", "right", "justify"];
|
|
31
|
+
var DEFAULT_COLOR_PALETTE = [
|
|
32
|
+
"#000000",
|
|
33
|
+
"#434343",
|
|
34
|
+
"#666666",
|
|
35
|
+
"#999999",
|
|
36
|
+
"#b7b7b7",
|
|
37
|
+
"#cccccc",
|
|
38
|
+
"#d9d9d9",
|
|
39
|
+
"#efefef",
|
|
40
|
+
"#f3f3f3",
|
|
41
|
+
"#ffffff",
|
|
42
|
+
"#e60000",
|
|
43
|
+
"#ff0000",
|
|
44
|
+
"#ff9900",
|
|
45
|
+
"#ffff00",
|
|
46
|
+
"#00ff00",
|
|
47
|
+
"#00ffff",
|
|
48
|
+
"#4a86e8",
|
|
49
|
+
"#0000ff",
|
|
50
|
+
"#9900ff",
|
|
51
|
+
"#ff00ff",
|
|
52
|
+
"#f4cccc",
|
|
53
|
+
"#fce5cd",
|
|
54
|
+
"#fff2cc",
|
|
55
|
+
"#d9ead3",
|
|
56
|
+
"#d0e0e3",
|
|
57
|
+
"#cfe2f3",
|
|
58
|
+
"#d9d2e9",
|
|
59
|
+
"#ead1dc",
|
|
60
|
+
"#f9cb9c",
|
|
61
|
+
"#ffe599",
|
|
62
|
+
"#b6d7a8",
|
|
63
|
+
"#a2c4c9",
|
|
64
|
+
"#9fc5e8",
|
|
65
|
+
"#b4a7d6",
|
|
66
|
+
"#d5a6bd",
|
|
67
|
+
"#e06666",
|
|
68
|
+
"#f6b26b",
|
|
69
|
+
"#ffd966",
|
|
70
|
+
"#93c47d",
|
|
71
|
+
"#76a5af",
|
|
72
|
+
"#6fa8dc",
|
|
73
|
+
"#8e7cc3",
|
|
74
|
+
"#c27ba0",
|
|
75
|
+
"#cc0000",
|
|
76
|
+
"#e69138",
|
|
77
|
+
"#f1c232",
|
|
78
|
+
"#6aa84f",
|
|
79
|
+
"#45818e",
|
|
80
|
+
"#3d85c6",
|
|
81
|
+
"#674ea7",
|
|
82
|
+
"#a64d79",
|
|
83
|
+
"#990000",
|
|
84
|
+
"#b45f06",
|
|
85
|
+
"#bf9000",
|
|
86
|
+
"#38761d",
|
|
87
|
+
"#134f5c",
|
|
88
|
+
"#0b5394",
|
|
89
|
+
"#351c75",
|
|
90
|
+
"#741b47",
|
|
91
|
+
"#660000",
|
|
92
|
+
"#783f04",
|
|
93
|
+
"#7f6000",
|
|
94
|
+
"#274e13",
|
|
95
|
+
"#0c343d",
|
|
96
|
+
"#073763",
|
|
97
|
+
"#20124d",
|
|
98
|
+
"#4c1130"
|
|
99
|
+
];
|
|
100
|
+
var DEFAULT_HIGHLIGHT_PALETTE = DEFAULT_COLOR_PALETTE;
|
|
101
|
+
var DEFAULT_LABELS = {
|
|
102
|
+
undo: "Undo",
|
|
103
|
+
redo: "Redo",
|
|
104
|
+
fontFamily: "Font",
|
|
105
|
+
fontSize: "Size",
|
|
106
|
+
bold: "B",
|
|
107
|
+
italic: "I",
|
|
108
|
+
underline: "U",
|
|
109
|
+
textColor: "A",
|
|
110
|
+
highlightColor: "Hi",
|
|
111
|
+
link: "Link",
|
|
112
|
+
align: "Align"
|
|
113
|
+
};
|
|
114
|
+
var BubbleMenuPreset = Extension.create({
|
|
115
|
+
name: "bubbleMenuPreset",
|
|
116
|
+
addOptions() {
|
|
117
|
+
return {
|
|
118
|
+
element: null,
|
|
119
|
+
items: DEFAULT_ITEMS,
|
|
120
|
+
className: "",
|
|
121
|
+
injectStyles: true,
|
|
122
|
+
textColors: DEFAULT_COLOR_PALETTE,
|
|
123
|
+
highlightColors: DEFAULT_HIGHLIGHT_PALETTE,
|
|
124
|
+
fonts: DEFAULT_FONTS,
|
|
125
|
+
fontSizes: DEFAULT_FONT_SIZES,
|
|
126
|
+
alignments: DEFAULT_ALIGNMENTS,
|
|
127
|
+
pluginKey: "bubbleMenuPreset",
|
|
128
|
+
updateDelay: 250,
|
|
129
|
+
resizeDelay: 60,
|
|
130
|
+
appendTo: void 0,
|
|
131
|
+
shouldShow: null,
|
|
132
|
+
options: {
|
|
133
|
+
placement: "top",
|
|
134
|
+
strategy: "absolute",
|
|
135
|
+
offset: 8,
|
|
136
|
+
flip: {},
|
|
137
|
+
shift: {}
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
addProseMirrorPlugins() {
|
|
142
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
143
|
+
const options = this.options;
|
|
144
|
+
const editor = this.editor;
|
|
145
|
+
const usingCustomElement = !!options.element;
|
|
146
|
+
const { element, cleanup } = options.element && typeof document !== "undefined" ? { element: options.element, cleanup: () => {
|
|
147
|
+
} } : buildMenuElement(editor, {
|
|
148
|
+
items: (_a = options.items) != null ? _a : DEFAULT_ITEMS,
|
|
149
|
+
className: (_b = options.className) != null ? _b : "",
|
|
150
|
+
injectStyles: options.injectStyles !== false,
|
|
151
|
+
textColors: (_c = options.textColors) != null ? _c : DEFAULT_COLOR_PALETTE,
|
|
152
|
+
highlightColors: (_d = options.highlightColors) != null ? _d : DEFAULT_HIGHLIGHT_PALETTE,
|
|
153
|
+
fonts: (_e = options.fonts) != null ? _e : DEFAULT_FONTS,
|
|
154
|
+
fontSizes: (_f = options.fontSizes) != null ? _f : DEFAULT_FONT_SIZES,
|
|
155
|
+
alignments: (_g = options.alignments) != null ? _g : DEFAULT_ALIGNMENTS
|
|
156
|
+
});
|
|
157
|
+
this.storage.element = element;
|
|
158
|
+
this.storage.cleanup = cleanup;
|
|
159
|
+
this.storage.usingCustomElement = usingCustomElement;
|
|
160
|
+
const pluginOptions = {
|
|
161
|
+
pluginKey: (_h = options.pluginKey) != null ? _h : "bubbleMenuPreset",
|
|
162
|
+
editor,
|
|
163
|
+
element,
|
|
164
|
+
updateDelay: options.updateDelay,
|
|
165
|
+
resizeDelay: options.resizeDelay,
|
|
166
|
+
appendTo: options.appendTo,
|
|
167
|
+
options: options.options,
|
|
168
|
+
getReferencedVirtualElement: options.getReferencedVirtualElement,
|
|
169
|
+
shouldShow: (_i = options.shouldShow) != null ? _i : void 0
|
|
170
|
+
};
|
|
171
|
+
return [BubbleMenuPlugin(pluginOptions)];
|
|
172
|
+
},
|
|
173
|
+
onDestroy() {
|
|
174
|
+
const el = this.storage.element;
|
|
175
|
+
const cleanup = this.storage.cleanup;
|
|
176
|
+
const usingCustomElement = this.storage.usingCustomElement;
|
|
177
|
+
if (cleanup) {
|
|
178
|
+
cleanup();
|
|
179
|
+
}
|
|
180
|
+
if (el && !usingCustomElement) {
|
|
181
|
+
el.remove();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
function buildMenuElement(editor, opts) {
|
|
186
|
+
var _a;
|
|
187
|
+
if (opts.injectStyles) {
|
|
188
|
+
injectStyles();
|
|
189
|
+
}
|
|
190
|
+
const element = document.createElement("div");
|
|
191
|
+
element.className = `bs-bubble-menu-preset ${(_a = opts.className) != null ? _a : ""}`.trim();
|
|
192
|
+
element.setAttribute("data-bubble-menu-preset", "true");
|
|
193
|
+
element.tabIndex = 0;
|
|
194
|
+
const toolbar = document.createElement("div");
|
|
195
|
+
toolbar.className = "bs-bmp-toolbar";
|
|
196
|
+
const popovers = [];
|
|
197
|
+
const cleanupFns = [];
|
|
198
|
+
const getCommand = (name) => {
|
|
199
|
+
var _a2;
|
|
200
|
+
return (_a2 = editor.commands) == null ? void 0 : _a2[name];
|
|
201
|
+
};
|
|
202
|
+
const runChainCommand = (name, ...args) => {
|
|
203
|
+
var _a2, _b, _c, _d;
|
|
204
|
+
const chain = (_a2 = editor.chain) == null ? void 0 : _a2.call(editor);
|
|
205
|
+
if (!chain || typeof chain[name] !== "function") return false;
|
|
206
|
+
const runner = typeof chain.focus === "function" ? chain.focus() : chain;
|
|
207
|
+
if (typeof runner[name] !== "function") return false;
|
|
208
|
+
return (_d = (_c = (_b = runner[name](...args)).run) == null ? void 0 : _c.call(_b)) != null ? _d : false;
|
|
209
|
+
};
|
|
210
|
+
const closePopovers = () => {
|
|
211
|
+
popovers.forEach((p) => p.classList.add("bs-bmp-hidden"));
|
|
212
|
+
};
|
|
213
|
+
const runWithFocus = (fn) => {
|
|
214
|
+
if (!fn) return false;
|
|
215
|
+
return !!fn();
|
|
216
|
+
};
|
|
217
|
+
const addButton = (item, label, onClick, opts2 = {}) => {
|
|
218
|
+
const btn = document.createElement("button");
|
|
219
|
+
btn.type = "button";
|
|
220
|
+
btn.className = `bs-bmp-btn bs-bmp-btn-${item}`;
|
|
221
|
+
btn.textContent = label;
|
|
222
|
+
if (opts2.title) {
|
|
223
|
+
btn.title = opts2.title;
|
|
224
|
+
btn.setAttribute("aria-label", opts2.title);
|
|
225
|
+
}
|
|
226
|
+
if (opts2.disabled) {
|
|
227
|
+
btn.disabled = true;
|
|
228
|
+
btn.classList.add("bs-bmp-disabled");
|
|
229
|
+
} else {
|
|
230
|
+
btn.addEventListener("click", () => {
|
|
231
|
+
closePopovers();
|
|
232
|
+
onClick();
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
toolbar.appendChild(btn);
|
|
236
|
+
};
|
|
237
|
+
const addUndoRedo = () => {
|
|
238
|
+
const hasUndo = typeof getCommand("undo") === "function";
|
|
239
|
+
const hasRedo = typeof getCommand("redo") === "function";
|
|
240
|
+
addButton("undo", DEFAULT_LABELS.undo, () => runWithFocus(() => runChainCommand("undo")), {
|
|
241
|
+
disabled: !hasUndo,
|
|
242
|
+
title: "Undo"
|
|
243
|
+
});
|
|
244
|
+
addButton("redo", DEFAULT_LABELS.redo, () => runWithFocus(() => runChainCommand("redo")), {
|
|
245
|
+
disabled: !hasRedo,
|
|
246
|
+
title: "Redo"
|
|
247
|
+
});
|
|
248
|
+
};
|
|
249
|
+
const addFontFamily = () => {
|
|
250
|
+
const hasCommand = typeof getCommand("setFontFamily") === "function";
|
|
251
|
+
const wrapper = document.createElement("div");
|
|
252
|
+
wrapper.className = "bs-bmp-select";
|
|
253
|
+
const select = document.createElement("select");
|
|
254
|
+
select.className = "bs-bmp-select-input";
|
|
255
|
+
select.title = "Font family";
|
|
256
|
+
opts.fonts.forEach((font) => {
|
|
257
|
+
const option = document.createElement("option");
|
|
258
|
+
option.value = font;
|
|
259
|
+
option.textContent = font;
|
|
260
|
+
option.style.fontFamily = font;
|
|
261
|
+
select.appendChild(option);
|
|
262
|
+
});
|
|
263
|
+
select.disabled = !hasCommand;
|
|
264
|
+
select.addEventListener("change", () => {
|
|
265
|
+
var _a2, _b;
|
|
266
|
+
runWithFocus(() => runChainCommand("setFontFamily", select.value));
|
|
267
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
268
|
+
});
|
|
269
|
+
wrapper.appendChild(select);
|
|
270
|
+
toolbar.appendChild(wrapper);
|
|
271
|
+
};
|
|
272
|
+
const addFontSize = () => {
|
|
273
|
+
const hasCommand = typeof getCommand("setFontSize") === "function";
|
|
274
|
+
const wrapper = document.createElement("div");
|
|
275
|
+
wrapper.className = "bs-bmp-select";
|
|
276
|
+
const select = document.createElement("select");
|
|
277
|
+
select.className = "bs-bmp-select-input";
|
|
278
|
+
select.title = "Font size";
|
|
279
|
+
opts.fontSizes.forEach((size) => {
|
|
280
|
+
const option = document.createElement("option");
|
|
281
|
+
option.value = size;
|
|
282
|
+
option.textContent = size;
|
|
283
|
+
select.appendChild(option);
|
|
284
|
+
});
|
|
285
|
+
select.disabled = !hasCommand;
|
|
286
|
+
select.addEventListener("change", () => {
|
|
287
|
+
var _a2, _b;
|
|
288
|
+
runWithFocus(() => runChainCommand("setFontSize", select.value));
|
|
289
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
290
|
+
});
|
|
291
|
+
wrapper.appendChild(select);
|
|
292
|
+
toolbar.appendChild(wrapper);
|
|
293
|
+
};
|
|
294
|
+
const addToggleMark = (item, commandName, title) => {
|
|
295
|
+
const fn = getCommand(commandName);
|
|
296
|
+
const disabled = typeof fn !== "function";
|
|
297
|
+
addButton(
|
|
298
|
+
item,
|
|
299
|
+
DEFAULT_LABELS[item],
|
|
300
|
+
() => {
|
|
301
|
+
runWithFocus(() => runChainCommand(commandName));
|
|
302
|
+
},
|
|
303
|
+
{ disabled, title }
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
const addTextColor = () => {
|
|
307
|
+
const hasSet = typeof getCommand("setColor") === "function";
|
|
308
|
+
const hasUnset = typeof getCommand("unsetColor") === "function";
|
|
309
|
+
const { popover, toggle, destroy } = createColorPopover({
|
|
310
|
+
label: DEFAULT_LABELS.textColor,
|
|
311
|
+
title: "Text color",
|
|
312
|
+
colors: opts.textColors,
|
|
313
|
+
onSelect: (color) => {
|
|
314
|
+
var _a2, _b;
|
|
315
|
+
if (!hasSet) return;
|
|
316
|
+
runWithFocus(() => runChainCommand("setColor", color));
|
|
317
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
318
|
+
},
|
|
319
|
+
onClear: () => {
|
|
320
|
+
var _a2, _b;
|
|
321
|
+
if (!hasUnset) return;
|
|
322
|
+
runWithFocus(() => runChainCommand("unsetColor"));
|
|
323
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
324
|
+
},
|
|
325
|
+
onToggle: () => {
|
|
326
|
+
var _a2, _b;
|
|
327
|
+
return (_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
popovers.push(popover);
|
|
331
|
+
cleanupFns.push(destroy);
|
|
332
|
+
toolbar.appendChild(toggle);
|
|
333
|
+
toolbar.appendChild(popover);
|
|
334
|
+
};
|
|
335
|
+
const addHighlightColor = () => {
|
|
336
|
+
const hasToggle = typeof getCommand("toggleHighlight") === "function";
|
|
337
|
+
const hasUnset = typeof getCommand("unsetHighlight") === "function";
|
|
338
|
+
const { popover, toggle, destroy } = createColorPopover({
|
|
339
|
+
label: DEFAULT_LABELS.highlightColor,
|
|
340
|
+
title: "Highlight color",
|
|
341
|
+
colors: opts.highlightColors,
|
|
342
|
+
onSelect: (color) => {
|
|
343
|
+
var _a2, _b;
|
|
344
|
+
if (!hasToggle) return;
|
|
345
|
+
runWithFocus(() => runChainCommand("toggleHighlight", { color }));
|
|
346
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
347
|
+
},
|
|
348
|
+
onClear: () => {
|
|
349
|
+
var _a2, _b;
|
|
350
|
+
if (!hasUnset) return;
|
|
351
|
+
runWithFocus(() => runChainCommand("unsetHighlight"));
|
|
352
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
353
|
+
},
|
|
354
|
+
onToggle: () => {
|
|
355
|
+
var _a2, _b;
|
|
356
|
+
return (_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
popovers.push(popover);
|
|
360
|
+
cleanupFns.push(destroy);
|
|
361
|
+
toolbar.appendChild(toggle);
|
|
362
|
+
toolbar.appendChild(popover);
|
|
363
|
+
};
|
|
364
|
+
const addLink = () => {
|
|
365
|
+
const hasToggle = typeof getCommand("toggleLink") === "function";
|
|
366
|
+
const hasUnset = typeof getCommand("unsetLink") === "function";
|
|
367
|
+
addButton(
|
|
368
|
+
"link",
|
|
369
|
+
DEFAULT_LABELS.link,
|
|
370
|
+
() => {
|
|
371
|
+
var _a2, _b;
|
|
372
|
+
const currentHref = (_b = (_a2 = editor.getAttributes("link")) == null ? void 0 : _a2.href) != null ? _b : "";
|
|
373
|
+
const href = window.prompt("Link URL", currentHref);
|
|
374
|
+
if (href === null) return;
|
|
375
|
+
if (!href) {
|
|
376
|
+
if (hasUnset) {
|
|
377
|
+
runWithFocus(() => runChainCommand("unsetLink"));
|
|
378
|
+
}
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
if (hasToggle) {
|
|
382
|
+
runWithFocus(() => runChainCommand("toggleLink", { href }));
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
{ disabled: !hasToggle && !hasUnset, title: "Insert link" }
|
|
386
|
+
);
|
|
387
|
+
};
|
|
388
|
+
const addAlign = () => {
|
|
389
|
+
const hasSet = typeof getCommand("setTextAlign") === "function";
|
|
390
|
+
const hasToggle = typeof getCommand("toggleTextAlign") === "function";
|
|
391
|
+
const wrapper = document.createElement("div");
|
|
392
|
+
wrapper.className = "bs-bmp-select";
|
|
393
|
+
const select = document.createElement("select");
|
|
394
|
+
select.className = "bs-bmp-select-input";
|
|
395
|
+
select.title = "Align";
|
|
396
|
+
opts.alignments.forEach((alignment) => {
|
|
397
|
+
const option = document.createElement("option");
|
|
398
|
+
option.value = alignment;
|
|
399
|
+
option.textContent = alignment.charAt(0).toUpperCase() + alignment.slice(1);
|
|
400
|
+
select.appendChild(option);
|
|
401
|
+
});
|
|
402
|
+
select.disabled = !hasSet && !hasToggle;
|
|
403
|
+
select.addEventListener("change", () => {
|
|
404
|
+
var _a2, _b;
|
|
405
|
+
if (hasToggle) {
|
|
406
|
+
runWithFocus(() => runChainCommand("toggleTextAlign", select.value));
|
|
407
|
+
} else if (hasSet) {
|
|
408
|
+
runWithFocus(() => runChainCommand("setTextAlign", select.value));
|
|
409
|
+
}
|
|
410
|
+
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
411
|
+
});
|
|
412
|
+
wrapper.appendChild(select);
|
|
413
|
+
toolbar.appendChild(wrapper);
|
|
414
|
+
};
|
|
415
|
+
opts.items.forEach((item) => {
|
|
416
|
+
switch (item) {
|
|
417
|
+
case "undo":
|
|
418
|
+
addUndoRedo();
|
|
419
|
+
break;
|
|
420
|
+
case "redo":
|
|
421
|
+
break;
|
|
422
|
+
case "fontFamily":
|
|
423
|
+
addFontFamily();
|
|
424
|
+
break;
|
|
425
|
+
case "fontSize":
|
|
426
|
+
addFontSize();
|
|
427
|
+
break;
|
|
428
|
+
case "bold":
|
|
429
|
+
addToggleMark("bold", "toggleBold", "Bold");
|
|
430
|
+
break;
|
|
431
|
+
case "italic":
|
|
432
|
+
addToggleMark("italic", "toggleItalic", "Italic");
|
|
433
|
+
break;
|
|
434
|
+
case "underline":
|
|
435
|
+
addToggleMark("underline", "toggleUnderline", "Underline");
|
|
436
|
+
break;
|
|
437
|
+
case "textColor":
|
|
438
|
+
addTextColor();
|
|
439
|
+
break;
|
|
440
|
+
case "highlightColor":
|
|
441
|
+
addHighlightColor();
|
|
442
|
+
break;
|
|
443
|
+
case "link":
|
|
444
|
+
addLink();
|
|
445
|
+
break;
|
|
446
|
+
case "align":
|
|
447
|
+
addAlign();
|
|
448
|
+
break;
|
|
449
|
+
default:
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
element.appendChild(toolbar);
|
|
454
|
+
return {
|
|
455
|
+
element,
|
|
456
|
+
cleanup: () => {
|
|
457
|
+
popovers.forEach((p) => p.remove());
|
|
458
|
+
cleanupFns.forEach((fn) => fn());
|
|
459
|
+
element.replaceChildren();
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
function createColorPopover(args) {
|
|
464
|
+
const toggle = document.createElement("button");
|
|
465
|
+
toggle.type = "button";
|
|
466
|
+
toggle.className = "bs-bmp-btn bs-bmp-btn-color";
|
|
467
|
+
toggle.textContent = args.label;
|
|
468
|
+
toggle.title = args.title;
|
|
469
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
470
|
+
const popover = document.createElement("div");
|
|
471
|
+
popover.className = "bs-bmp-popover bs-bmp-hidden";
|
|
472
|
+
popover.setAttribute("role", "menu");
|
|
473
|
+
const header = document.createElement("div");
|
|
474
|
+
header.className = "bs-bmp-popover-header";
|
|
475
|
+
const noneBtn = document.createElement("button");
|
|
476
|
+
noneBtn.type = "button";
|
|
477
|
+
noneBtn.className = "bs-bmp-btn bs-bmp-btn-ghost";
|
|
478
|
+
noneBtn.textContent = "None";
|
|
479
|
+
noneBtn.addEventListener("click", () => {
|
|
480
|
+
args.onClear();
|
|
481
|
+
hide();
|
|
482
|
+
});
|
|
483
|
+
header.appendChild(noneBtn);
|
|
484
|
+
popover.appendChild(header);
|
|
485
|
+
const grid = document.createElement("div");
|
|
486
|
+
grid.className = "bs-bmp-color-grid";
|
|
487
|
+
const columns = 10;
|
|
488
|
+
grid.style.setProperty("--bs-bmp-grid-columns", String(columns));
|
|
489
|
+
args.colors.forEach((color) => {
|
|
490
|
+
const swatch = document.createElement("button");
|
|
491
|
+
swatch.type = "button";
|
|
492
|
+
swatch.className = "bs-bmp-color-swatch";
|
|
493
|
+
swatch.style.backgroundColor = color;
|
|
494
|
+
swatch.setAttribute("aria-label", color);
|
|
495
|
+
swatch.addEventListener("click", (event) => {
|
|
496
|
+
event.stopPropagation();
|
|
497
|
+
args.onSelect(color);
|
|
498
|
+
hide();
|
|
499
|
+
});
|
|
500
|
+
grid.appendChild(swatch);
|
|
501
|
+
});
|
|
502
|
+
popover.appendChild(grid);
|
|
503
|
+
const customRow = document.createElement("div");
|
|
504
|
+
customRow.className = "bs-bmp-popover-footer";
|
|
505
|
+
const customLabel = document.createElement("span");
|
|
506
|
+
customLabel.textContent = "Custom";
|
|
507
|
+
const customInput = document.createElement("input");
|
|
508
|
+
customInput.type = "color";
|
|
509
|
+
customInput.className = "bs-bmp-color-input";
|
|
510
|
+
customInput.addEventListener("input", () => {
|
|
511
|
+
args.onSelect(customInput.value);
|
|
512
|
+
});
|
|
513
|
+
customRow.appendChild(customLabel);
|
|
514
|
+
customRow.appendChild(customInput);
|
|
515
|
+
popover.appendChild(customRow);
|
|
516
|
+
const hide = () => {
|
|
517
|
+
var _a;
|
|
518
|
+
popover.classList.add("bs-bmp-hidden");
|
|
519
|
+
toggle.setAttribute("aria-expanded", "false");
|
|
520
|
+
(_a = args.onToggle) == null ? void 0 : _a.call(args);
|
|
521
|
+
};
|
|
522
|
+
const show = () => {
|
|
523
|
+
var _a;
|
|
524
|
+
popover.classList.remove("bs-bmp-hidden");
|
|
525
|
+
toggle.setAttribute("aria-expanded", "true");
|
|
526
|
+
(_a = args.onToggle) == null ? void 0 : _a.call(args);
|
|
527
|
+
};
|
|
528
|
+
const toggleHandler = (event) => {
|
|
529
|
+
event.stopPropagation();
|
|
530
|
+
if (popover.classList.contains("bs-bmp-hidden")) {
|
|
531
|
+
show();
|
|
532
|
+
} else {
|
|
533
|
+
hide();
|
|
534
|
+
}
|
|
535
|
+
};
|
|
536
|
+
toggle.addEventListener("click", toggleHandler);
|
|
537
|
+
const outsideHandler = (event) => {
|
|
538
|
+
if (popover.contains(event.target) || toggle.contains(event.target)) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
hide();
|
|
542
|
+
};
|
|
543
|
+
document.addEventListener(
|
|
544
|
+
"click",
|
|
545
|
+
outsideHandler,
|
|
546
|
+
{ capture: true }
|
|
547
|
+
);
|
|
548
|
+
const destroy = () => {
|
|
549
|
+
document.removeEventListener("click", outsideHandler, { capture: true });
|
|
550
|
+
toggle.removeEventListener("click", toggleHandler);
|
|
551
|
+
};
|
|
552
|
+
return { toggle, popover, destroy };
|
|
553
|
+
}
|
|
554
|
+
function injectStyles() {
|
|
555
|
+
if (typeof document === "undefined") return;
|
|
556
|
+
if (document.getElementById(STYLE_ID)) return;
|
|
557
|
+
const style = document.createElement("style");
|
|
558
|
+
style.id = STYLE_ID;
|
|
559
|
+
style.textContent = `
|
|
560
|
+
.bs-bubble-menu-preset {
|
|
561
|
+
display: inline-flex;
|
|
562
|
+
align-items: center;
|
|
563
|
+
gap: 8px;
|
|
564
|
+
background: #ffffff;
|
|
565
|
+
border: 1px solid #e5e7eb;
|
|
566
|
+
padding: 8px 10px;
|
|
567
|
+
border-radius: 20%;
|
|
568
|
+
box-shadow: 0 10px 30px rgba(0,0,0,0.12);
|
|
569
|
+
color: #111827;
|
|
570
|
+
font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
571
|
+
}
|
|
572
|
+
.bs-bmp-toolbar {
|
|
573
|
+
display: inline-flex;
|
|
574
|
+
align-items: center;
|
|
575
|
+
gap: 6px;
|
|
576
|
+
}
|
|
577
|
+
.bs-bmp-btn {
|
|
578
|
+
border: none;
|
|
579
|
+
background: transparent;
|
|
580
|
+
color: inherit;
|
|
581
|
+
padding: 6px 8px;
|
|
582
|
+
border-radius: 12px;
|
|
583
|
+
cursor: pointer;
|
|
584
|
+
font-size: 13px;
|
|
585
|
+
line-height: 1;
|
|
586
|
+
transition: background-color 120ms ease, color 120ms ease, box-shadow 120ms ease;
|
|
587
|
+
}
|
|
588
|
+
.bs-bmp-btn:hover {
|
|
589
|
+
background: #f3f4f6;
|
|
590
|
+
}
|
|
591
|
+
.bs-bmp-btn:disabled {
|
|
592
|
+
opacity: 0.45;
|
|
593
|
+
cursor: not-allowed;
|
|
594
|
+
}
|
|
595
|
+
.bs-bmp-select {
|
|
596
|
+
display: inline-flex;
|
|
597
|
+
align-items: center;
|
|
598
|
+
}
|
|
599
|
+
.bs-bmp-select-input {
|
|
600
|
+
border: 1px solid #e5e7eb;
|
|
601
|
+
background: #ffffff;
|
|
602
|
+
color: inherit;
|
|
603
|
+
padding: 6px 8px;
|
|
604
|
+
border-radius: 12px;
|
|
605
|
+
font-size: 13px;
|
|
606
|
+
outline: none;
|
|
607
|
+
}
|
|
608
|
+
.bs-bmp-select-input:focus {
|
|
609
|
+
border-color: #4f46e5;
|
|
610
|
+
box-shadow: 0 0 0 2px rgba(79,70,229,0.15);
|
|
611
|
+
}
|
|
612
|
+
.bs-bmp-popover {
|
|
613
|
+
position: absolute;
|
|
614
|
+
margin-top: 6px;
|
|
615
|
+
padding: 10px;
|
|
616
|
+
background: #ffffff;
|
|
617
|
+
border: 1px solid #e5e7eb;
|
|
618
|
+
border-radius: 12px;
|
|
619
|
+
box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
|
|
620
|
+
z-index: 999;
|
|
621
|
+
}
|
|
622
|
+
.bs-bmp-hidden {
|
|
623
|
+
display: none;
|
|
624
|
+
}
|
|
625
|
+
.bs-bmp-popover-header,
|
|
626
|
+
.bs-bmp-popover-footer {
|
|
627
|
+
display: flex;
|
|
628
|
+
align-items: center;
|
|
629
|
+
justify-content: space-between;
|
|
630
|
+
margin-bottom: 6px;
|
|
631
|
+
}
|
|
632
|
+
.bs-bmp-btn-ghost {
|
|
633
|
+
background: transparent;
|
|
634
|
+
border: none;
|
|
635
|
+
color: inherit;
|
|
636
|
+
padding: 4px 6px;
|
|
637
|
+
border-radius: 8px;
|
|
638
|
+
cursor: pointer;
|
|
639
|
+
}
|
|
640
|
+
.bs-bmp-btn-ghost:hover {
|
|
641
|
+
background: #f3f4f6;
|
|
642
|
+
}
|
|
643
|
+
.bs-bmp-color-grid {
|
|
644
|
+
display: grid;
|
|
645
|
+
grid-template-columns: repeat(var(--bs-bmp-grid-columns, 10), 22px);
|
|
646
|
+
gap: 4px;
|
|
647
|
+
margin-bottom: 8px;
|
|
648
|
+
}
|
|
649
|
+
.bs-bmp-color-swatch {
|
|
650
|
+
width: 22px;
|
|
651
|
+
height: 22px;
|
|
652
|
+
border-radius: 50%;
|
|
653
|
+
border: 1px solid #e5e7eb;
|
|
654
|
+
cursor: pointer;
|
|
655
|
+
padding: 0;
|
|
656
|
+
}
|
|
657
|
+
.bs-bmp-color-swatch:hover {
|
|
658
|
+
outline: 2px solid #4f46e5;
|
|
659
|
+
outline-offset: 2px;
|
|
660
|
+
}
|
|
661
|
+
.bs-bmp-color-input {
|
|
662
|
+
width: 32px;
|
|
663
|
+
height: 28px;
|
|
664
|
+
padding: 0;
|
|
665
|
+
border: 1px solid #e5e7eb;
|
|
666
|
+
border-radius: 8px;
|
|
667
|
+
background: #ffffff;
|
|
668
|
+
}
|
|
669
|
+
`;
|
|
670
|
+
document.head.appendChild(style);
|
|
671
|
+
}
|
|
672
|
+
export {
|
|
673
|
+
BubbleMenuPreset,
|
|
674
|
+
BubbleMenuPreset as default
|
|
675
|
+
};
|
|
676
|
+
//# sourceMappingURL=index.js.map
|