@blockslides/extension-bubble-menu-preset 0.1.3 → 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.
- package/dist/index.cjs +344 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -2
- package/dist/index.d.ts +23 -2
- package/dist/index.js +337 -21
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
- package/src/bubble-menu-preset.ts +363 -26
package/dist/index.cjs
CHANGED
|
@@ -21,6 +21,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
BubbleMenuPreset: () => BubbleMenuPreset,
|
|
24
|
+
DEFAULT_ALIGNMENTS: () => DEFAULT_ALIGNMENTS,
|
|
25
|
+
DEFAULT_COLOR_PALETTE: () => DEFAULT_COLOR_PALETTE,
|
|
26
|
+
DEFAULT_FONTS: () => DEFAULT_FONTS,
|
|
27
|
+
DEFAULT_FONT_SIZES: () => DEFAULT_FONT_SIZES,
|
|
28
|
+
DEFAULT_HIGHLIGHT_PALETTE: () => DEFAULT_HIGHLIGHT_PALETTE,
|
|
29
|
+
DEFAULT_ITEMS: () => DEFAULT_ITEMS,
|
|
30
|
+
buildMenuElement: () => buildMenuElement,
|
|
24
31
|
default: () => BubbleMenuPreset
|
|
25
32
|
});
|
|
26
33
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -28,6 +35,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
28
35
|
// src/bubble-menu-preset.ts
|
|
29
36
|
var import_core = require("@blockslides/core");
|
|
30
37
|
var import_extension_bubble_menu = require("@blockslides/extension-bubble-menu");
|
|
38
|
+
var import_state = require("@blockslides/pm/state");
|
|
31
39
|
var STYLE_ID = "blockslides-bubble-menu-preset-styles";
|
|
32
40
|
var DEFAULT_ITEMS = [
|
|
33
41
|
"undo",
|
|
@@ -51,7 +59,20 @@ var DEFAULT_FONTS = [
|
|
|
51
59
|
"Courier New",
|
|
52
60
|
"Monaco"
|
|
53
61
|
];
|
|
54
|
-
var DEFAULT_FONT_SIZES = [
|
|
62
|
+
var DEFAULT_FONT_SIZES = [
|
|
63
|
+
"12px",
|
|
64
|
+
"14px",
|
|
65
|
+
"16px",
|
|
66
|
+
"18px",
|
|
67
|
+
"20px",
|
|
68
|
+
"24px",
|
|
69
|
+
"32px",
|
|
70
|
+
"40px",
|
|
71
|
+
"48px",
|
|
72
|
+
"56px",
|
|
73
|
+
"64px",
|
|
74
|
+
"72px"
|
|
75
|
+
];
|
|
55
76
|
var DEFAULT_ALIGNMENTS = ["left", "center", "right", "justify"];
|
|
56
77
|
var DEFAULT_COLOR_PALETTE = [
|
|
57
78
|
"#000000",
|
|
@@ -157,13 +178,19 @@ var BubbleMenuPreset = import_core.Extension.create({
|
|
|
157
178
|
updateDelay: 250,
|
|
158
179
|
resizeDelay: 60,
|
|
159
180
|
appendTo: void 0,
|
|
160
|
-
shouldShow: null,
|
|
161
181
|
options: {
|
|
162
182
|
placement: "top",
|
|
163
183
|
strategy: "absolute",
|
|
164
184
|
offset: 8,
|
|
165
185
|
flip: {},
|
|
166
186
|
shift: {}
|
|
187
|
+
},
|
|
188
|
+
shouldShow: ({ state, editor }) => {
|
|
189
|
+
const { selection } = state;
|
|
190
|
+
const imageSelection = selection instanceof import_state.NodeSelection && ["image", "imageBlock"].includes(selection.node.type.name) || editor.isActive("image") || editor.isActive("imageBlock");
|
|
191
|
+
if (imageSelection) return true;
|
|
192
|
+
if ((0, import_core.isTextSelection)(selection) && !selection.empty && !imageSelection) return true;
|
|
193
|
+
return false;
|
|
167
194
|
}
|
|
168
195
|
};
|
|
169
196
|
},
|
|
@@ -220,10 +247,14 @@ function buildMenuElement(editor, opts) {
|
|
|
220
247
|
element.className = `bs-bubble-menu-preset ${(_a = opts.className) != null ? _a : ""}`.trim();
|
|
221
248
|
element.setAttribute("data-bubble-menu-preset", "true");
|
|
222
249
|
element.tabIndex = 0;
|
|
223
|
-
const
|
|
224
|
-
|
|
250
|
+
const textToolbar = document.createElement("div");
|
|
251
|
+
textToolbar.className = "bs-bmp-toolbar";
|
|
252
|
+
const imageToolbar = document.createElement("div");
|
|
253
|
+
imageToolbar.className = "bs-bmp-toolbar bs-bmp-toolbar-image";
|
|
225
254
|
let fontFamilySelect = null;
|
|
226
255
|
let fontSizeSelect = null;
|
|
256
|
+
let imageAlignSelect = null;
|
|
257
|
+
let imageDisplaySelect = null;
|
|
227
258
|
const normalizeFontFamily = (value) => {
|
|
228
259
|
var _a2;
|
|
229
260
|
if (!value) return value;
|
|
@@ -242,6 +273,21 @@ function buildMenuElement(editor, opts) {
|
|
|
242
273
|
fontSize: styles.fontSize || void 0
|
|
243
274
|
};
|
|
244
275
|
};
|
|
276
|
+
const isImageSelection = () => {
|
|
277
|
+
const sel = editor.state.selection;
|
|
278
|
+
if (sel instanceof import_state.NodeSelection) {
|
|
279
|
+
return ["image", "imageBlock"].includes(sel.node.type.name);
|
|
280
|
+
}
|
|
281
|
+
return editor.isActive("image") || editor.isActive("imageBlock");
|
|
282
|
+
};
|
|
283
|
+
const getImageAttrs = () => {
|
|
284
|
+
const sel = editor.state.selection;
|
|
285
|
+
if (sel instanceof import_state.NodeSelection && ["image", "imageBlock"].includes(sel.node.type.name)) {
|
|
286
|
+
return sel.node.attrs || {};
|
|
287
|
+
}
|
|
288
|
+
if (editor.isActive("imageBlock")) return editor.getAttributes("imageBlock") || {};
|
|
289
|
+
return editor.getAttributes("image") || {};
|
|
290
|
+
};
|
|
245
291
|
const ensureOptionExists = (select, value) => {
|
|
246
292
|
const exists = Array.from(select.options).some((opt) => opt.value === value);
|
|
247
293
|
if (!exists) {
|
|
@@ -275,13 +321,16 @@ function buildMenuElement(editor, opts) {
|
|
|
275
321
|
return (_d = (_c = (_b = runner[name](...args)).run) == null ? void 0 : _c.call(_b)) != null ? _d : false;
|
|
276
322
|
};
|
|
277
323
|
const closePopovers = () => {
|
|
278
|
-
popovers.forEach((p) =>
|
|
324
|
+
popovers.forEach((p) => {
|
|
325
|
+
p.classList.add("bs-bmp-hidden");
|
|
326
|
+
p.style.display = "none";
|
|
327
|
+
});
|
|
279
328
|
};
|
|
280
329
|
const runWithFocus = (fn) => {
|
|
281
330
|
if (!fn) return false;
|
|
282
331
|
return !!fn();
|
|
283
332
|
};
|
|
284
|
-
const addButton = (item, label, onClick, opts2 = {}) => {
|
|
333
|
+
const addButton = (container, item, label, onClick, opts2 = {}) => {
|
|
285
334
|
const btn = document.createElement("button");
|
|
286
335
|
btn.type = "button";
|
|
287
336
|
btn.className = `bs-bmp-btn bs-bmp-btn-${item}`;
|
|
@@ -299,16 +348,16 @@ function buildMenuElement(editor, opts) {
|
|
|
299
348
|
onClick();
|
|
300
349
|
});
|
|
301
350
|
}
|
|
302
|
-
|
|
351
|
+
container.appendChild(btn);
|
|
303
352
|
};
|
|
304
353
|
const addUndoRedo = () => {
|
|
305
354
|
const hasUndo = typeof getCommand("undo") === "function";
|
|
306
355
|
const hasRedo = typeof getCommand("redo") === "function";
|
|
307
|
-
addButton("undo", DEFAULT_LABELS.undo, () => runWithFocus(() => runChainCommand("undo")), {
|
|
356
|
+
addButton(textToolbar, "undo", DEFAULT_LABELS.undo, () => runWithFocus(() => runChainCommand("undo")), {
|
|
308
357
|
disabled: !hasUndo,
|
|
309
358
|
title: "Undo"
|
|
310
359
|
});
|
|
311
|
-
addButton("redo", DEFAULT_LABELS.redo, () => runWithFocus(() => runChainCommand("redo")), {
|
|
360
|
+
addButton(textToolbar, "redo", DEFAULT_LABELS.redo, () => runWithFocus(() => runChainCommand("redo")), {
|
|
312
361
|
disabled: !hasRedo,
|
|
313
362
|
title: "Redo"
|
|
314
363
|
});
|
|
@@ -335,7 +384,7 @@ function buildMenuElement(editor, opts) {
|
|
|
335
384
|
});
|
|
336
385
|
fontFamilySelect = select;
|
|
337
386
|
wrapper.appendChild(select);
|
|
338
|
-
|
|
387
|
+
textToolbar.appendChild(wrapper);
|
|
339
388
|
};
|
|
340
389
|
const addFontSize = () => {
|
|
341
390
|
const hasCommand = typeof getCommand("setFontSize") === "function";
|
|
@@ -358,12 +407,13 @@ function buildMenuElement(editor, opts) {
|
|
|
358
407
|
});
|
|
359
408
|
fontSizeSelect = select;
|
|
360
409
|
wrapper.appendChild(select);
|
|
361
|
-
|
|
410
|
+
textToolbar.appendChild(wrapper);
|
|
362
411
|
};
|
|
363
412
|
const addToggleMark = (item, commandName, title) => {
|
|
364
413
|
const fn = getCommand(commandName);
|
|
365
414
|
const disabled = typeof fn !== "function";
|
|
366
415
|
addButton(
|
|
416
|
+
textToolbar,
|
|
367
417
|
item,
|
|
368
418
|
DEFAULT_LABELS[item],
|
|
369
419
|
() => {
|
|
@@ -398,8 +448,8 @@ function buildMenuElement(editor, opts) {
|
|
|
398
448
|
});
|
|
399
449
|
popovers.push(popover);
|
|
400
450
|
cleanupFns.push(destroy);
|
|
401
|
-
|
|
402
|
-
|
|
451
|
+
textToolbar.appendChild(toggle);
|
|
452
|
+
textToolbar.appendChild(popover);
|
|
403
453
|
};
|
|
404
454
|
const addHighlightColor = () => {
|
|
405
455
|
const hasToggle = typeof getCommand("toggleHighlight") === "function";
|
|
@@ -427,13 +477,14 @@ function buildMenuElement(editor, opts) {
|
|
|
427
477
|
});
|
|
428
478
|
popovers.push(popover);
|
|
429
479
|
cleanupFns.push(destroy);
|
|
430
|
-
|
|
431
|
-
|
|
480
|
+
textToolbar.appendChild(toggle);
|
|
481
|
+
textToolbar.appendChild(popover);
|
|
432
482
|
};
|
|
433
483
|
const addLink = () => {
|
|
434
484
|
const hasToggle = typeof getCommand("toggleLink") === "function";
|
|
435
485
|
const hasUnset = typeof getCommand("unsetLink") === "function";
|
|
436
486
|
addButton(
|
|
487
|
+
textToolbar,
|
|
437
488
|
"link",
|
|
438
489
|
DEFAULT_LABELS.link,
|
|
439
490
|
() => {
|
|
@@ -479,7 +530,139 @@ function buildMenuElement(editor, opts) {
|
|
|
479
530
|
(_b = (_a2 = editor.commands).setMeta) == null ? void 0 : _b.call(_a2, "bubbleMenu", "updatePosition");
|
|
480
531
|
});
|
|
481
532
|
wrapper.appendChild(select);
|
|
482
|
-
|
|
533
|
+
textToolbar.appendChild(wrapper);
|
|
534
|
+
};
|
|
535
|
+
const addImageControls = () => {
|
|
536
|
+
const addImageButton = (label, title, handler) => {
|
|
537
|
+
const btn = document.createElement("button");
|
|
538
|
+
btn.type = "button";
|
|
539
|
+
btn.className = "bs-bmp-btn bs-bmp-btn-image";
|
|
540
|
+
btn.textContent = label;
|
|
541
|
+
btn.title = title;
|
|
542
|
+
btn.setAttribute("aria-label", title);
|
|
543
|
+
btn.addEventListener("click", () => {
|
|
544
|
+
closePopovers();
|
|
545
|
+
handler();
|
|
546
|
+
});
|
|
547
|
+
imageToolbar.appendChild(btn);
|
|
548
|
+
};
|
|
549
|
+
const { popover: replacePopover, show: showReplacePopover } = createReplacePopover({
|
|
550
|
+
getCurrentValue: () => {
|
|
551
|
+
var _a2;
|
|
552
|
+
return (_a2 = getImageAttrs().src) != null ? _a2 : "";
|
|
553
|
+
},
|
|
554
|
+
onSave: (next) => {
|
|
555
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
556
|
+
const chain = (_a2 = editor.chain) == null ? void 0 : _a2.call(editor);
|
|
557
|
+
const runner = typeof (chain == null ? void 0 : chain.focus) === "function" ? chain.focus() : chain;
|
|
558
|
+
if (editor.isActive("imageBlock") && typeof (runner == null ? void 0 : runner.setImageBlockMetadata) === "function") {
|
|
559
|
+
(_c = (_b = runner.setImageBlockMetadata({ src: next })).run) == null ? void 0 : _c.call(_b);
|
|
560
|
+
} else if (typeof (runner == null ? void 0 : runner.updateAttributes) === "function") {
|
|
561
|
+
(_e = (_d = runner.updateAttributes("image", { src: next })).run) == null ? void 0 : _e.call(_d);
|
|
562
|
+
} else if (typeof (runner == null ? void 0 : runner.replaceImageBlock) === "function") {
|
|
563
|
+
(_g = (_f = runner.replaceImageBlock({ src: next })).run) == null ? void 0 : _g.call(_f);
|
|
564
|
+
}
|
|
565
|
+
(_i = (_h = editor.commands).setMeta) == null ? void 0 : _i.call(_h, "bubbleMenu", "updatePosition");
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
popovers.push(replacePopover);
|
|
569
|
+
imageToolbar.appendChild(replacePopover);
|
|
570
|
+
addImageButton("Replace", "Replace image", () => {
|
|
571
|
+
closePopovers();
|
|
572
|
+
showReplacePopover();
|
|
573
|
+
});
|
|
574
|
+
const alignWrapper = document.createElement("div");
|
|
575
|
+
alignWrapper.className = "bs-bmp-select";
|
|
576
|
+
const alignSelect = document.createElement("select");
|
|
577
|
+
alignSelect.className = "bs-bmp-select-input";
|
|
578
|
+
alignSelect.title = "Align image";
|
|
579
|
+
["left", "center", "right"].forEach((alignment) => {
|
|
580
|
+
const option = document.createElement("option");
|
|
581
|
+
option.value = alignment;
|
|
582
|
+
option.textContent = alignment.charAt(0).toUpperCase() + alignment.slice(1);
|
|
583
|
+
alignSelect.appendChild(option);
|
|
584
|
+
});
|
|
585
|
+
alignSelect.addEventListener("change", () => {
|
|
586
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
587
|
+
const value = alignSelect.value;
|
|
588
|
+
const chain = (_a2 = editor.chain) == null ? void 0 : _a2.call(editor);
|
|
589
|
+
const runner = typeof (chain == null ? void 0 : chain.focus) === "function" ? chain.focus() : chain;
|
|
590
|
+
if (editor.isActive("imageBlock") && typeof (runner == null ? void 0 : runner.setImageBlockAlignment) === "function") {
|
|
591
|
+
(_c = (_b = runner.setImageBlockAlignment(value)).run) == null ? void 0 : _c.call(_b);
|
|
592
|
+
} else if (typeof (runner == null ? void 0 : runner.updateAttributes) === "function") {
|
|
593
|
+
(_e = (_d = runner.updateAttributes("image", { align: value })).run) == null ? void 0 : _e.call(_d);
|
|
594
|
+
}
|
|
595
|
+
(_g = (_f = editor.commands).setMeta) == null ? void 0 : _g.call(_f, "bubbleMenu", "updatePosition");
|
|
596
|
+
});
|
|
597
|
+
alignWrapper.appendChild(alignSelect);
|
|
598
|
+
imageToolbar.appendChild(alignWrapper);
|
|
599
|
+
imageAlignSelect = alignSelect;
|
|
600
|
+
const displayWrapper = document.createElement("div");
|
|
601
|
+
displayWrapper.className = "bs-bmp-select";
|
|
602
|
+
const displaySelect = document.createElement("select");
|
|
603
|
+
displaySelect.className = "bs-bmp-select-input";
|
|
604
|
+
displaySelect.title = "Image fit";
|
|
605
|
+
["default", "cover", "contain", "fill"].forEach((mode) => {
|
|
606
|
+
const option = document.createElement("option");
|
|
607
|
+
option.value = mode;
|
|
608
|
+
option.textContent = mode.charAt(0).toUpperCase() + mode.slice(1);
|
|
609
|
+
displaySelect.appendChild(option);
|
|
610
|
+
});
|
|
611
|
+
displaySelect.addEventListener("change", () => {
|
|
612
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
613
|
+
const value = displaySelect.value;
|
|
614
|
+
const chain = (_a2 = editor.chain) == null ? void 0 : _a2.call(editor);
|
|
615
|
+
const runner = typeof (chain == null ? void 0 : chain.focus) === "function" ? chain.focus() : chain;
|
|
616
|
+
if (editor.isActive("imageBlock") && typeof (runner == null ? void 0 : runner.setImageBlockLayout) === "function") {
|
|
617
|
+
if (value === "cover" && typeof (runner == null ? void 0 : runner.setImageBlockFullBleed) === "function") {
|
|
618
|
+
runner.setImageBlockFullBleed(true);
|
|
619
|
+
}
|
|
620
|
+
(_c = (_b = runner.setImageBlockLayout(value === "default" ? "cover" : value)).run) == null ? void 0 : _c.call(_b);
|
|
621
|
+
} else if (typeof (runner == null ? void 0 : runner.updateAttributes) === "function") {
|
|
622
|
+
(_e = (_d = runner.updateAttributes("image", { display: value })).run) == null ? void 0 : _e.call(_d);
|
|
623
|
+
}
|
|
624
|
+
(_g = (_f = editor.commands).setMeta) == null ? void 0 : _g.call(_f, "bubbleMenu", "updatePosition");
|
|
625
|
+
});
|
|
626
|
+
displayWrapper.appendChild(displaySelect);
|
|
627
|
+
imageToolbar.appendChild(displayWrapper);
|
|
628
|
+
imageDisplaySelect = displaySelect;
|
|
629
|
+
addImageButton("Full width", "Set image width to 100%", () => {
|
|
630
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
631
|
+
const chain = (_a2 = editor.chain) == null ? void 0 : _a2.call(editor);
|
|
632
|
+
const runner = typeof (chain == null ? void 0 : chain.focus) === "function" ? chain.focus() : chain;
|
|
633
|
+
if (editor.isActive("imageBlock") && typeof (runner == null ? void 0 : runner.setImageBlockDimensions) === "function") {
|
|
634
|
+
(_c = (_b = runner.setImageBlockDimensions({ width: "100%", height: null })).run) == null ? void 0 : _c.call(_b);
|
|
635
|
+
} else if (typeof (runner == null ? void 0 : runner.updateAttributes) === "function") {
|
|
636
|
+
(_e = (_d = runner.updateAttributes("image", { width: "100%", height: null })).run) == null ? void 0 : _e.call(_d);
|
|
637
|
+
}
|
|
638
|
+
(_g = (_f = editor.commands).setMeta) == null ? void 0 : _g.call(_f, "bubbleMenu", "updatePosition");
|
|
639
|
+
});
|
|
640
|
+
const { popover: altPopover, show: showAltPopover } = createAltPopover({
|
|
641
|
+
getCurrentValue: () => {
|
|
642
|
+
var _a2;
|
|
643
|
+
return (_a2 = getImageAttrs().alt) != null ? _a2 : "";
|
|
644
|
+
},
|
|
645
|
+
onSave: (next) => {
|
|
646
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
647
|
+
const chain = (_a2 = editor.chain) == null ? void 0 : _a2.call(editor);
|
|
648
|
+
const runner = typeof (chain == null ? void 0 : chain.focus) === "function" ? chain.focus() : chain;
|
|
649
|
+
if (editor.isActive("imageBlock") && typeof (runner == null ? void 0 : runner.setImageBlockMetadata) === "function") {
|
|
650
|
+
(_c = (_b = runner.setImageBlockMetadata({ alt: next })).run) == null ? void 0 : _c.call(_b);
|
|
651
|
+
} else if (typeof (runner == null ? void 0 : runner.updateAttributes) === "function") {
|
|
652
|
+
(_e = (_d = runner.updateAttributes("image", { alt: next })).run) == null ? void 0 : _e.call(_d);
|
|
653
|
+
}
|
|
654
|
+
(_g = (_f = editor.commands).setMeta) == null ? void 0 : _g.call(_f, "bubbleMenu", "updatePosition");
|
|
655
|
+
}
|
|
656
|
+
});
|
|
657
|
+
popovers.push(altPopover);
|
|
658
|
+
imageToolbar.appendChild(altPopover);
|
|
659
|
+
addImageButton("Alt", "Set alt text", () => {
|
|
660
|
+
closePopovers();
|
|
661
|
+
showAltPopover();
|
|
662
|
+
});
|
|
663
|
+
addImageButton("Delete", "Delete image", () => {
|
|
664
|
+
editor.chain().focus().deleteSelection().run();
|
|
665
|
+
});
|
|
483
666
|
};
|
|
484
667
|
opts.items.forEach((item) => {
|
|
485
668
|
switch (item) {
|
|
@@ -519,8 +702,11 @@ function buildMenuElement(editor, opts) {
|
|
|
519
702
|
break;
|
|
520
703
|
}
|
|
521
704
|
});
|
|
522
|
-
|
|
705
|
+
addImageControls();
|
|
706
|
+
element.appendChild(textToolbar);
|
|
707
|
+
element.appendChild(imageToolbar);
|
|
523
708
|
const syncSelectionState = () => {
|
|
709
|
+
if (isImageSelection()) return;
|
|
524
710
|
const attrs = editor.getAttributes("textStyle") || {};
|
|
525
711
|
let family = attrs.fontFamily;
|
|
526
712
|
let size = attrs.fontSize;
|
|
@@ -532,10 +718,26 @@ function buildMenuElement(editor, opts) {
|
|
|
532
718
|
setSelectValue(fontFamilySelect, normalizeFontFamily(family));
|
|
533
719
|
setSelectValue(fontSizeSelect, size);
|
|
534
720
|
};
|
|
535
|
-
const
|
|
721
|
+
const syncImageState = () => {
|
|
722
|
+
if (!isImageSelection()) return;
|
|
723
|
+
const attrs = getImageAttrs();
|
|
724
|
+
const fitValue = editor.isActive("imageBlock") ? attrs.layout || "cover" : attrs.display || "default";
|
|
725
|
+
setSelectValue(imageAlignSelect, attrs.align);
|
|
726
|
+
setSelectValue(imageDisplaySelect, fitValue);
|
|
727
|
+
};
|
|
728
|
+
const syncToolbarVisibility = () => {
|
|
729
|
+
const imageVisible = isImageSelection();
|
|
730
|
+
textToolbar.style.display = imageVisible ? "none" : "";
|
|
731
|
+
imageToolbar.style.display = imageVisible ? "" : "none";
|
|
732
|
+
};
|
|
733
|
+
const handleSelectionUpdate = () => {
|
|
734
|
+
syncToolbarVisibility();
|
|
735
|
+
syncSelectionState();
|
|
736
|
+
syncImageState();
|
|
737
|
+
};
|
|
536
738
|
const handleTransaction = ({ transaction }) => {
|
|
537
739
|
if (!transaction || transaction.docChanged || transaction.selectionSet) {
|
|
538
|
-
|
|
740
|
+
handleSelectionUpdate();
|
|
539
741
|
}
|
|
540
742
|
};
|
|
541
743
|
editor.on("selectionUpdate", handleSelectionUpdate);
|
|
@@ -544,7 +746,9 @@ function buildMenuElement(editor, opts) {
|
|
|
544
746
|
editor.off("selectionUpdate", handleSelectionUpdate);
|
|
545
747
|
editor.off("transaction", handleTransaction);
|
|
546
748
|
});
|
|
749
|
+
syncToolbarVisibility();
|
|
547
750
|
syncSelectionState();
|
|
751
|
+
syncImageState();
|
|
548
752
|
return {
|
|
549
753
|
element,
|
|
550
754
|
cleanup: () => {
|
|
@@ -652,6 +856,99 @@ function createColorPopover(args) {
|
|
|
652
856
|
};
|
|
653
857
|
return { toggle, popover, destroy };
|
|
654
858
|
}
|
|
859
|
+
function createAltPopover(args) {
|
|
860
|
+
const popover = document.createElement("div");
|
|
861
|
+
popover.className = "bs-bmp-popover bs-bmp-popover-alt bs-bmp-hidden";
|
|
862
|
+
const input = document.createElement("input");
|
|
863
|
+
input.type = "text";
|
|
864
|
+
input.className = "bs-bmp-text-input";
|
|
865
|
+
input.placeholder = "Describe the image";
|
|
866
|
+
popover.appendChild(input);
|
|
867
|
+
const actions = document.createElement("div");
|
|
868
|
+
actions.className = "bs-bmp-popover-actions";
|
|
869
|
+
const cancel = document.createElement("button");
|
|
870
|
+
cancel.type = "button";
|
|
871
|
+
cancel.className = "bs-bmp-btn bs-bmp-btn-ghost";
|
|
872
|
+
cancel.textContent = "Cancel";
|
|
873
|
+
cancel.addEventListener("click", () => hide());
|
|
874
|
+
const save = document.createElement("button");
|
|
875
|
+
save.type = "button";
|
|
876
|
+
save.className = "bs-bmp-btn";
|
|
877
|
+
save.textContent = "Save";
|
|
878
|
+
save.addEventListener("click", () => {
|
|
879
|
+
args.onSave(input.value.trim());
|
|
880
|
+
hide();
|
|
881
|
+
});
|
|
882
|
+
actions.appendChild(cancel);
|
|
883
|
+
actions.appendChild(save);
|
|
884
|
+
popover.appendChild(actions);
|
|
885
|
+
const hide = () => popover.classList.add("bs-bmp-hidden");
|
|
886
|
+
const show = () => {
|
|
887
|
+
input.value = args.getCurrentValue();
|
|
888
|
+
popover.classList.remove("bs-bmp-hidden");
|
|
889
|
+
popover.style.display = "";
|
|
890
|
+
input.focus();
|
|
891
|
+
input.select();
|
|
892
|
+
};
|
|
893
|
+
input.addEventListener("keydown", (event) => {
|
|
894
|
+
if (event.key === "Enter") {
|
|
895
|
+
event.preventDefault();
|
|
896
|
+
save.click();
|
|
897
|
+
}
|
|
898
|
+
if (event.key === "Escape") hide();
|
|
899
|
+
});
|
|
900
|
+
hide();
|
|
901
|
+
return { popover, show, hide };
|
|
902
|
+
}
|
|
903
|
+
function createReplacePopover(args) {
|
|
904
|
+
const popover = document.createElement("div");
|
|
905
|
+
popover.className = "bs-bmp-popover bs-bmp-popover-replace bs-bmp-hidden";
|
|
906
|
+
const input = document.createElement("input");
|
|
907
|
+
input.type = "url";
|
|
908
|
+
input.className = "bs-bmp-text-input";
|
|
909
|
+
input.placeholder = "https://...";
|
|
910
|
+
popover.appendChild(input);
|
|
911
|
+
const actions = document.createElement("div");
|
|
912
|
+
actions.className = "bs-bmp-popover-actions";
|
|
913
|
+
const cancel = document.createElement("button");
|
|
914
|
+
cancel.type = "button";
|
|
915
|
+
cancel.className = "bs-bmp-btn bs-bmp-btn-ghost";
|
|
916
|
+
cancel.textContent = "Cancel";
|
|
917
|
+
cancel.addEventListener("click", () => hide());
|
|
918
|
+
const save = document.createElement("button");
|
|
919
|
+
save.type = "button";
|
|
920
|
+
save.className = "bs-bmp-btn";
|
|
921
|
+
save.textContent = "Replace";
|
|
922
|
+
save.addEventListener("click", () => {
|
|
923
|
+
const val = input.value.trim();
|
|
924
|
+
if (!val) return;
|
|
925
|
+
args.onSave(val);
|
|
926
|
+
hide();
|
|
927
|
+
});
|
|
928
|
+
actions.appendChild(cancel);
|
|
929
|
+
actions.appendChild(save);
|
|
930
|
+
popover.appendChild(actions);
|
|
931
|
+
const hide = () => {
|
|
932
|
+
popover.classList.add("bs-bmp-hidden");
|
|
933
|
+
popover.style.display = "none";
|
|
934
|
+
};
|
|
935
|
+
const show = () => {
|
|
936
|
+
input.value = args.getCurrentValue();
|
|
937
|
+
popover.classList.remove("bs-bmp-hidden");
|
|
938
|
+
popover.style.display = "";
|
|
939
|
+
input.focus();
|
|
940
|
+
input.select();
|
|
941
|
+
};
|
|
942
|
+
input.addEventListener("keydown", (event) => {
|
|
943
|
+
if (event.key === "Enter") {
|
|
944
|
+
event.preventDefault();
|
|
945
|
+
save.click();
|
|
946
|
+
}
|
|
947
|
+
if (event.key === "Escape") hide();
|
|
948
|
+
});
|
|
949
|
+
hide();
|
|
950
|
+
return { popover, show, hide };
|
|
951
|
+
}
|
|
655
952
|
function injectStyles() {
|
|
656
953
|
if (typeof document === "undefined") return;
|
|
657
954
|
if (document.getElementById(STYLE_ID)) return;
|
|
@@ -722,7 +1019,7 @@ function injectStyles() {
|
|
|
722
1019
|
z-index: 999;
|
|
723
1020
|
}
|
|
724
1021
|
.bs-bmp-hidden {
|
|
725
|
-
display: none;
|
|
1022
|
+
display: none !important;
|
|
726
1023
|
}
|
|
727
1024
|
.bs-bmp-popover-header,
|
|
728
1025
|
.bs-bmp-popover-footer {
|
|
@@ -768,11 +1065,37 @@ function injectStyles() {
|
|
|
768
1065
|
border-radius: 8px;
|
|
769
1066
|
background: #ffffff;
|
|
770
1067
|
}
|
|
1068
|
+
.bs-bmp-popover-alt,
|
|
1069
|
+
.bs-bmp-popover-replace {
|
|
1070
|
+
display: flex;
|
|
1071
|
+
flex-direction: column;
|
|
1072
|
+
gap: 8px;
|
|
1073
|
+
width: 260px;
|
|
1074
|
+
}
|
|
1075
|
+
.bs-bmp-text-input {
|
|
1076
|
+
width: 100%;
|
|
1077
|
+
padding: 8px 10px;
|
|
1078
|
+
border: 1px solid #e5e7eb;
|
|
1079
|
+
border-radius: 10px;
|
|
1080
|
+
font-size: 13px;
|
|
1081
|
+
}
|
|
1082
|
+
.bs-bmp-popover-actions {
|
|
1083
|
+
display: flex;
|
|
1084
|
+
justify-content: flex-end;
|
|
1085
|
+
gap: 6px;
|
|
1086
|
+
}
|
|
771
1087
|
`;
|
|
772
1088
|
document.head.appendChild(style);
|
|
773
1089
|
}
|
|
774
1090
|
// Annotate the CommonJS export names for ESM import in node:
|
|
775
1091
|
0 && (module.exports = {
|
|
776
|
-
BubbleMenuPreset
|
|
1092
|
+
BubbleMenuPreset,
|
|
1093
|
+
DEFAULT_ALIGNMENTS,
|
|
1094
|
+
DEFAULT_COLOR_PALETTE,
|
|
1095
|
+
DEFAULT_FONTS,
|
|
1096
|
+
DEFAULT_FONT_SIZES,
|
|
1097
|
+
DEFAULT_HIGHLIGHT_PALETTE,
|
|
1098
|
+
DEFAULT_ITEMS,
|
|
1099
|
+
buildMenuElement
|
|
777
1100
|
});
|
|
778
1101
|
//# sourceMappingURL=index.cjs.map
|