@salmonui/rich-text 0.0.0-stage → 0.3.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 +21 -0
- package/README.md +79 -2
- package/dist/blocks/find.d.ts +4 -0
- package/dist/blocks/find.d.ts.map +1 -0
- package/dist/blocks/find.js +14 -0
- package/dist/blocks/find.js.map +1 -0
- package/dist/blocks/from-html.d.ts +10 -0
- package/dist/blocks/from-html.d.ts.map +1 -0
- package/dist/blocks/from-html.js +459 -0
- package/dist/blocks/from-html.js.map +1 -0
- package/dist/blocks/index.d.ts +5 -0
- package/dist/blocks/index.d.ts.map +1 -0
- package/dist/blocks/index.js +4 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/ops.d.ts +27 -0
- package/dist/blocks/ops.d.ts.map +1 -0
- package/dist/blocks/ops.js +172 -0
- package/dist/blocks/ops.js.map +1 -0
- package/dist/blocks/to-html.d.ts +18 -0
- package/dist/blocks/to-html.d.ts.map +1 -0
- package/dist/blocks/to-html.js +207 -0
- package/dist/blocks/to-html.js.map +1 -0
- package/dist/blocks/types.d.ts +76 -0
- package/dist/blocks/types.d.ts.map +1 -0
- package/dist/blocks/types.js +4 -0
- package/dist/blocks/types.js.map +1 -0
- package/dist/collab.d.ts +43 -0
- package/dist/collab.d.ts.map +1 -0
- package/dist/collab.js +45 -0
- package/dist/collab.js.map +1 -0
- package/dist/content/RichTextContent.d.ts +19 -0
- package/dist/content/RichTextContent.d.ts.map +1 -0
- package/dist/content/RichTextContent.js +20 -0
- package/dist/content/RichTextContent.js.map +1 -0
- package/dist/content/index.d.ts +2 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +3 -0
- package/dist/content/index.js.map +1 -0
- package/dist/engine/commands.d.ts +19 -0
- package/dist/engine/commands.d.ts.map +1 -0
- package/dist/engine/commands.js +457 -0
- package/dist/engine/commands.js.map +1 -0
- package/dist/engine/core.d.ts +116 -0
- package/dist/engine/core.d.ts.map +1 -0
- package/dist/engine/core.js +460 -0
- package/dist/engine/core.js.map +1 -0
- package/dist/engine/dom-shim.d.ts +47 -0
- package/dist/engine/dom-shim.d.ts.map +1 -0
- package/dist/engine/dom-shim.js +128 -0
- package/dist/engine/dom-shim.js.map +1 -0
- package/dist/engine/html-out.d.ts +12 -0
- package/dist/engine/html-out.d.ts.map +1 -0
- package/dist/engine/html-out.js +24 -0
- package/dist/engine/html-out.js.map +1 -0
- package/dist/engine/index.d.ts +6 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +5 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/keymap.d.ts +18 -0
- package/dist/engine/keymap.d.ts.map +1 -0
- package/dist/engine/keymap.js +85 -0
- package/dist/engine/keymap.js.map +1 -0
- package/dist/engine/load.d.ts +10 -0
- package/dist/engine/load.d.ts.map +1 -0
- package/dist/engine/load.js +11 -0
- package/dist/engine/load.js.map +1 -0
- package/dist/engine/nodeviews.d.ts +19 -0
- package/dist/engine/nodeviews.d.ts.map +1 -0
- package/dist/engine/nodeviews.js +241 -0
- package/dist/engine/nodeviews.js.map +1 -0
- package/dist/engine/plugins.d.ts +77 -0
- package/dist/engine/plugins.d.ts.map +1 -0
- package/dist/engine/plugins.js +312 -0
- package/dist/engine/plugins.js.map +1 -0
- package/dist/engine/schema.d.ts +11 -0
- package/dist/engine/schema.d.ts.map +1 -0
- package/dist/engine/schema.js +350 -0
- package/dist/engine/schema.js.map +1 -0
- package/dist/engine/serialize.d.ts +13 -0
- package/dist/engine/serialize.d.ts.map +1 -0
- package/dist/engine/serialize.js +119 -0
- package/dist/engine/serialize.js.map +1 -0
- package/dist/engine/snapshot.d.ts +4 -0
- package/dist/engine/snapshot.d.ts.map +1 -0
- package/dist/engine/snapshot.js +62 -0
- package/dist/engine/snapshot.js.map +1 -0
- package/dist/engine/types.d.ts +215 -0
- package/dist/engine/types.d.ts.map +1 -0
- package/dist/engine/types.js +2 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/html/entities.d.ts +7 -0
- package/dist/html/entities.d.ts.map +1 -0
- package/dist/html/entities.js +69 -0
- package/dist/html/entities.js.map +1 -0
- package/dist/html/index.d.ts +7 -0
- package/dist/html/index.d.ts.map +1 -0
- package/dist/html/index.js +9 -0
- package/dist/html/index.js.map +1 -0
- package/dist/html/parse.d.ts +30 -0
- package/dist/html/parse.d.ts.map +1 -0
- package/dist/html/parse.js +394 -0
- package/dist/html/parse.js.map +1 -0
- package/dist/html/paste.d.ts +47 -0
- package/dist/html/paste.d.ts.map +1 -0
- package/dist/html/paste.js +373 -0
- package/dist/html/paste.js.map +1 -0
- package/dist/html/policy.d.ts +56 -0
- package/dist/html/policy.d.ts.map +1 -0
- package/dist/html/policy.js +245 -0
- package/dist/html/policy.js.map +1 -0
- package/dist/html/sanitize.d.ts +60 -0
- package/dist/html/sanitize.d.ts.map +1 -0
- package/dist/html/sanitize.js +699 -0
- package/dist/html/sanitize.js.map +1 -0
- package/dist/html/serialize.d.ts +16 -0
- package/dist/html/serialize.d.ts.map +1 -0
- package/dist/html/serialize.js +68 -0
- package/dist/html/serialize.js.map +1 -0
- package/dist/html/text.d.ts +18 -0
- package/dist/html/text.d.ts.map +1 -0
- package/dist/html/text.js +96 -0
- package/dist/html/text.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/mention/editable.d.ts +15 -0
- package/dist/mention/editable.d.ts.map +1 -0
- package/dist/mention/editable.js +167 -0
- package/dist/mention/editable.js.map +1 -0
- package/dist/mention/index.d.ts +2 -0
- package/dist/mention/index.d.ts.map +1 -0
- package/dist/mention/index.js +3 -0
- package/dist/mention/index.js.map +1 -0
- package/dist/react/RichTextEditor.d.ts +15 -0
- package/dist/react/RichTextEditor.d.ts.map +1 -0
- package/dist/react/RichTextEditor.js +497 -0
- package/dist/react/RichTextEditor.js.map +1 -0
- package/dist/react/block-editor/BlockEditor.d.ts +5 -0
- package/dist/react/block-editor/BlockEditor.d.ts.map +1 -0
- package/dist/react/block-editor/BlockEditor.js +106 -0
- package/dist/react/block-editor/BlockEditor.js.map +1 -0
- package/dist/react/block-editor/controller.d.ts +94 -0
- package/dist/react/block-editor/controller.d.ts.map +1 -0
- package/dist/react/block-editor/controller.js +758 -0
- package/dist/react/block-editor/controller.js.map +1 -0
- package/dist/react/block-editor/index.d.ts +4 -0
- package/dist/react/block-editor/index.d.ts.map +1 -0
- package/dist/react/block-editor/index.js +5 -0
- package/dist/react/block-editor/index.js.map +1 -0
- package/dist/react/block-editor/locale.d.ts +73 -0
- package/dist/react/block-editor/locale.d.ts.map +1 -0
- package/dist/react/block-editor/locale.js +65 -0
- package/dist/react/block-editor/locale.js.map +1 -0
- package/dist/react/block-editor/transforms.d.ts +26 -0
- package/dist/react/block-editor/transforms.d.ts.map +1 -0
- package/dist/react/block-editor/transforms.js +233 -0
- package/dist/react/block-editor/transforms.js.map +1 -0
- package/dist/react/block-editor/types.d.ts +180 -0
- package/dist/react/block-editor/types.d.ts.map +1 -0
- package/dist/react/block-editor/types.js +2 -0
- package/dist/react/block-editor/types.js.map +1 -0
- package/dist/react/block-editor/ui.d.ts +21 -0
- package/dist/react/block-editor/ui.d.ts.map +1 -0
- package/dist/react/block-editor/ui.js +601 -0
- package/dist/react/block-editor/ui.js.map +1 -0
- package/dist/react/client.d.ts +28 -0
- package/dist/react/client.d.ts.map +1 -0
- package/dist/react/client.js +111 -0
- package/dist/react/client.js.map +1 -0
- package/dist/react/dialogs.d.ts +46 -0
- package/dist/react/dialogs.d.ts.map +1 -0
- package/dist/react/dialogs.js +312 -0
- package/dist/react/dialogs.js.map +1 -0
- package/dist/react/emoji-data.d.ts +3 -0
- package/dist/react/emoji-data.d.ts.map +1 -0
- package/dist/react/emoji-data.js +6 -0
- package/dist/react/emoji-data.js.map +1 -0
- package/dist/react/icons.d.ts +5 -0
- package/dist/react/icons.d.ts.map +1 -0
- package/dist/react/icons.js +69 -0
- package/dist/react/icons.js.map +1 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +5 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/items.d.ts +60 -0
- package/dist/react/items.d.ts.map +1 -0
- package/dist/react/items.js +255 -0
- package/dist/react/items.js.map +1 -0
- package/dist/react/locale.d.ts +151 -0
- package/dist/react/locale.d.ts.map +1 -0
- package/dist/react/locale.js +139 -0
- package/dist/react/locale.js.map +1 -0
- package/dist/react/overlay.d.ts +41 -0
- package/dist/react/overlay.d.ts.map +1 -0
- package/dist/react/overlay.js +162 -0
- package/dist/react/overlay.js.map +1 -0
- package/dist/react/store.d.ts +23 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +84 -0
- package/dist/react/store.js.map +1 -0
- package/dist/react/types.d.ts +205 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/types.js +2 -0
- package/dist/react/types.js.map +1 -0
- package/dist/rich-text.css +1555 -0
- package/package.json +61 -4
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
// BlockEditor client UI (lazy chunk): drag handle and block action menu, slash menu, selection toolbar with 'turnInto', context menu, image settings and paste prompt dialogs, print and mentions / labels. Pointer and
|
|
4
|
+
// drag transients are written to the DOM from event handlers, never to React
|
|
5
|
+
// state; open menus and popups are React state (they render markup).
|
|
6
|
+
//
|
|
7
|
+
// Toolbar, Dialog and Popover are the private primitives of the rich text
|
|
8
|
+
// family (../overlay.tsx), replaced by the shared ones when Navigation and
|
|
9
|
+
// Layout ship them.
|
|
10
|
+
import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
11
|
+
import { Button, ToggleButton } from '@salmonui/buttons/button';
|
|
12
|
+
import { Menu, MenuButton } from '@salmonui/buttons/menu';
|
|
13
|
+
import { Mention } from '@salmonui/dropdowns/mention';
|
|
14
|
+
import { Dialog, Popover, ToolbarShell, focusToolbar } from '../overlay.js';
|
|
15
|
+
import { Icon } from '../icons.js';
|
|
16
|
+
import { TRANSFORMS, transformOf } from './transforms.js';
|
|
17
|
+
const SLASH_DEFAULT = [...TRANSFORMS, 'image', 'table', 'divider'];
|
|
18
|
+
const INLINE_DEFAULT = ['bold', 'italic', 'underline', 'strike', 'code', 'link', 'turnInto'];
|
|
19
|
+
const ACTIONS_DEFAULT = ['turnInto', 'duplicate', 'delete', 'moveUp', 'moveDown'];
|
|
20
|
+
const CONTEXT_DEFAULT = ['cut', 'copy', 'duplicate', 'delete', 'moveUp', 'moveDown', 'turnInto'];
|
|
21
|
+
const TEXT_TYPES = new Set(['paragraph', 'heading', 'bulletListItem', 'numberedListItem', 'checklistItem', 'quote', 'callout', 'code', 'toggle']);
|
|
22
|
+
const TABLE_OPS = ['addRowBefore', 'addRowAfter', 'deleteRow', 'addColumnBefore', 'addColumnAfter', 'deleteColumn', 'mergeCells', 'splitCell', 'toggleHeaderRow'];
|
|
23
|
+
const CONTAINERS = new Set(['LI', 'BLOCKQUOTE', 'DETAILS', 'DIV']);
|
|
24
|
+
function useSnapshot(controller, select) {
|
|
25
|
+
return useSyncExternalStore(controller.subscribe, () => select(controller.getSnapshot()), () => select(controller.getSnapshot()));
|
|
26
|
+
}
|
|
27
|
+
function isCustom(item) {
|
|
28
|
+
return typeof item === 'object';
|
|
29
|
+
}
|
|
30
|
+
function rectOf(el) {
|
|
31
|
+
const r = el.getBoundingClientRect();
|
|
32
|
+
return { left: r.left, top: r.top, bottom: r.bottom };
|
|
33
|
+
}
|
|
34
|
+
function blockElementAt(content, target) {
|
|
35
|
+
const el = target instanceof Element ? target.closest('[data-block-id]') : null;
|
|
36
|
+
return el && content.contains(el) ? el : null;
|
|
37
|
+
}
|
|
38
|
+
function isRtl(el) {
|
|
39
|
+
return getComputedStyle(el).direction === 'rtl';
|
|
40
|
+
}
|
|
41
|
+
/** The whole client UI of one BlockEditor. */
|
|
42
|
+
export function BlockEditorUi(p) {
|
|
43
|
+
const { controller, rootRef, contentRef, locale, props, hooks, actions } = p;
|
|
44
|
+
const [menu, setMenu] = useState(null);
|
|
45
|
+
const [dialog, setDialog] = useState(null);
|
|
46
|
+
const [linkEditing, setLinkEditing] = useState(false);
|
|
47
|
+
const fileRef = useRef(null);
|
|
48
|
+
const toolbarRef = useRef(null);
|
|
49
|
+
const readOnly = props.readOnly === true;
|
|
50
|
+
const toolbarVisible = useSnapshot(controller, (s) => s.focused && !s.selectionEmpty && s.textSelection && !s.inCode) && props.inlineToolbar !== false && !readOnly;
|
|
51
|
+
const openBlockMenu = (blockId, anchor) => {
|
|
52
|
+
const id = blockId ?? controller.currentBlockId();
|
|
53
|
+
if (!id)
|
|
54
|
+
return false;
|
|
55
|
+
const el = controller.blockElement(id);
|
|
56
|
+
const at = anchor ?? (el ? rectOf(el) : controller.caretRect());
|
|
57
|
+
if (!at)
|
|
58
|
+
return false;
|
|
59
|
+
setMenu({ kind: 'block', blockId: id, anchor: at });
|
|
60
|
+
return true;
|
|
61
|
+
};
|
|
62
|
+
// Hooks the controller calls (key bindings, slash keys, paste prompt).
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
const h = hooks.current;
|
|
65
|
+
h.action = (id) => {
|
|
66
|
+
switch (id) {
|
|
67
|
+
case 'blockMenu':
|
|
68
|
+
if (toolbarRef.current && focusToolbar(toolbarRef.current))
|
|
69
|
+
return true;
|
|
70
|
+
return openBlockMenu(null);
|
|
71
|
+
case 'contextMenu': {
|
|
72
|
+
if (props.contextMenu === false)
|
|
73
|
+
return false;
|
|
74
|
+
const at = controller.caretRect();
|
|
75
|
+
if (!at)
|
|
76
|
+
return false;
|
|
77
|
+
setMenu({ kind: 'context', blockId: controller.currentBlockId(), anchor: at });
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
case 'print':
|
|
81
|
+
printContent(controller, rootRef.current);
|
|
82
|
+
return true;
|
|
83
|
+
case 'link':
|
|
84
|
+
if (controller.getSnapshot().selectionEmpty)
|
|
85
|
+
return false;
|
|
86
|
+
setLinkEditing(true);
|
|
87
|
+
return true;
|
|
88
|
+
case 'image':
|
|
89
|
+
fileRef.current?.click();
|
|
90
|
+
return true;
|
|
91
|
+
default:
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
h.pastePrompt = () => new Promise((resolve) => setDialog({ kind: 'paste', resolve }));
|
|
96
|
+
});
|
|
97
|
+
const closeMenu = (refocus = true) => {
|
|
98
|
+
setMenu(null);
|
|
99
|
+
if (refocus)
|
|
100
|
+
controller.focus();
|
|
101
|
+
};
|
|
102
|
+
// Context menu on right click.
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
const content = contentRef.current;
|
|
105
|
+
if (!content || props.contextMenu === false)
|
|
106
|
+
return;
|
|
107
|
+
const onContext = (event) => {
|
|
108
|
+
if (event.shiftKey)
|
|
109
|
+
return; // Shift + right click keeps the browser menu.
|
|
110
|
+
event.preventDefault();
|
|
111
|
+
const el = blockElementAt(content, event.target);
|
|
112
|
+
setMenu({ kind: 'context', blockId: el?.getAttribute('data-block-id') ?? controller.currentBlockId(), anchor: { left: event.clientX, top: event.clientY, bottom: event.clientY } });
|
|
113
|
+
};
|
|
114
|
+
content.addEventListener('contextmenu', onContext);
|
|
115
|
+
return () => content.removeEventListener('contextmenu', onContext);
|
|
116
|
+
}, [contentRef, controller, props.contextMenu]);
|
|
117
|
+
const mentionTarget = controller.mentionTarget();
|
|
118
|
+
const triggers = [];
|
|
119
|
+
if (props.mentions)
|
|
120
|
+
triggers.push({ char: props.mentions.trigger ?? '@', data: props.mentions.items });
|
|
121
|
+
if (props.labels)
|
|
122
|
+
triggers.push({ char: props.labels.trigger ?? '#', data: props.labels.items });
|
|
123
|
+
return (_jsxs(_Fragment, { children: [!readOnly && props.draggable !== false ? _jsx(DragHandle, { controller: controller, rootRef: rootRef, contentRef: contentRef, locale: locale, onOpen: openBlockMenu }) : null, !readOnly ? _jsx(SlashMenu, { controller: controller, locale: locale, items: props.slashMenu, hooks: hooks, actions: actions, openFile: () => fileRef.current?.click() }) : null, toolbarVisible || linkEditing ? (_jsx(InlineToolbar, { controller: controller, locale: locale, items: props.inlineToolbar === false ? [] : (props.inlineToolbar ?? INLINE_DEFAULT), transforms: props.transforms ?? TRANSFORMS, actions: actions, toolbarRef: toolbarRef, linkEditing: linkEditing, setLinkEditing: setLinkEditing })) : null, menu ? _jsx(BlockMenu, { menu: menu, controller: controller, locale: locale, props: props, actions: actions, close: closeMenu, openImage: (blockId) => setDialog({ kind: 'image', blockId }) }) : null, dialog?.kind === 'image' ? _jsx(ImageDialog, { controller: controller, blockId: dialog.blockId, locale: locale, close: () => (setDialog(null), controller.focus()) }) : null, dialog?.kind === 'paste' ? (_jsx(PasteDialog, { locale: locale, choose: (choice) => {
|
|
124
|
+
dialog.resolve(choice);
|
|
125
|
+
setDialog(null);
|
|
126
|
+
} })) : null, _jsx("input", { ref: fileRef, type: "file", accept: "image/*,audio/*,video/*", hidden: true, tabIndex: -1, "aria-hidden": "true", className: "salmon-block-editor__file", onChange: (event) => {
|
|
127
|
+
const files = [...(event.currentTarget.files ?? [])];
|
|
128
|
+
event.currentTarget.value = '';
|
|
129
|
+
controller.focus();
|
|
130
|
+
if (files.length)
|
|
131
|
+
void controller.insertFiles(files);
|
|
132
|
+
} }), mentionTarget && triggers.length && !readOnly ? _jsx(Mention, { editor: mentionTarget, triggers: triggers }) : null] }));
|
|
133
|
+
}
|
|
134
|
+
// ---------------------------------------------------------------------------
|
|
135
|
+
// Drag handle: follows the hovered block (or the caret's
|
|
136
|
+
// block); pointer drag moves blocks, a click opens the block action menu.
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
function DragHandle(props) {
|
|
139
|
+
const { controller, rootRef, contentRef, locale, onOpen } = props;
|
|
140
|
+
const handleRef = useRef(null);
|
|
141
|
+
const indicatorRef = useRef(null);
|
|
142
|
+
const hovered = useRef(null);
|
|
143
|
+
const dragged = useRef(false);
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
const root = rootRef.current;
|
|
146
|
+
const content = contentRef.current;
|
|
147
|
+
const handle = handleRef.current;
|
|
148
|
+
const indicator = indicatorRef.current;
|
|
149
|
+
if (!root || !content || !handle || !indicator)
|
|
150
|
+
return;
|
|
151
|
+
let drag = null;
|
|
152
|
+
const place = (el) => {
|
|
153
|
+
if (!el) {
|
|
154
|
+
handle.dataset.visible = 'false';
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const id = el.getAttribute('data-block-id');
|
|
158
|
+
hovered.current = id;
|
|
159
|
+
const r = el.getBoundingClientRect();
|
|
160
|
+
const rr = root.getBoundingClientRect();
|
|
161
|
+
const rtl = isRtl(root);
|
|
162
|
+
const inline = rtl ? rr.right - r.right : r.left - rr.left;
|
|
163
|
+
handle.style.top = `${Math.round(r.top - rr.top)}px`;
|
|
164
|
+
handle.style.insetInlineStart = `${Math.round(inline - handle.offsetWidth - 4)}px`;
|
|
165
|
+
handle.dataset.visible = 'true';
|
|
166
|
+
handle.dataset.blockId = id ?? '';
|
|
167
|
+
};
|
|
168
|
+
const onMove = (event) => {
|
|
169
|
+
if (drag)
|
|
170
|
+
return;
|
|
171
|
+
if (event.target === handle || handle.contains(event.target))
|
|
172
|
+
return;
|
|
173
|
+
const el = blockElementAt(content, event.target);
|
|
174
|
+
if (el)
|
|
175
|
+
place(el);
|
|
176
|
+
};
|
|
177
|
+
// Keyboard users: the handle follows the caret's block.
|
|
178
|
+
const offStore = controller.subscribe(() => {
|
|
179
|
+
if (drag)
|
|
180
|
+
return;
|
|
181
|
+
const snap = controller.getSnapshot();
|
|
182
|
+
if (snap.focused && snap.blockId && snap.blockId !== hovered.current)
|
|
183
|
+
place(controller.blockElement(snap.blockId));
|
|
184
|
+
});
|
|
185
|
+
const dropAt = (event) => {
|
|
186
|
+
if (!drag)
|
|
187
|
+
return null;
|
|
188
|
+
const cr = content.getBoundingClientRect();
|
|
189
|
+
const x = Math.max(cr.left + 4, Math.min(cr.right - 4, event.clientX));
|
|
190
|
+
const hit = document.elementFromPoint(x, Math.max(cr.top + 1, Math.min(cr.bottom - 1, event.clientY)));
|
|
191
|
+
let el = blockElementAt(content, hit);
|
|
192
|
+
if (!el)
|
|
193
|
+
return null;
|
|
194
|
+
const self = controller.blockElement(drag.id);
|
|
195
|
+
// Never into the dragged block itself.
|
|
196
|
+
if (self && (self === el || self.contains(el))) {
|
|
197
|
+
el = self;
|
|
198
|
+
return { position: { before: drag.id }, el, nest: false, after: false };
|
|
199
|
+
}
|
|
200
|
+
const id = el.getAttribute('data-block-id');
|
|
201
|
+
const r = el.getBoundingClientRect();
|
|
202
|
+
const after = event.clientY > r.top + r.height / 2;
|
|
203
|
+
const rtl = isRtl(root);
|
|
204
|
+
const offset = rtl ? r.right - event.clientX : event.clientX - r.left;
|
|
205
|
+
const nest = after && offset > 48 && CONTAINERS.has(el.tagName);
|
|
206
|
+
return { position: nest ? { parent: id, index: 0 } : after ? { after: id } : { before: id }, el, nest, after };
|
|
207
|
+
};
|
|
208
|
+
const showIndicator = (target) => {
|
|
209
|
+
if (!target || ('before' in target.position && target.position.before === drag?.id)) {
|
|
210
|
+
indicator.dataset.visible = 'false';
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const r = target.el.getBoundingClientRect();
|
|
214
|
+
const rr = root.getBoundingClientRect();
|
|
215
|
+
const rtl = isRtl(root);
|
|
216
|
+
const inline = (rtl ? rr.right - r.right : r.left - rr.left) + (target.nest ? 24 : 0);
|
|
217
|
+
indicator.style.top = `${Math.round((target.after ? r.bottom : r.top) - rr.top)}px`;
|
|
218
|
+
indicator.style.insetInlineStart = `${Math.round(inline)}px`;
|
|
219
|
+
indicator.style.inlineSize = `${Math.round(r.width - (target.nest ? 24 : 0))}px`;
|
|
220
|
+
indicator.dataset.visible = 'true';
|
|
221
|
+
};
|
|
222
|
+
const onDown = (event) => {
|
|
223
|
+
const id = handle.dataset.blockId;
|
|
224
|
+
if (!id || event.button !== 0)
|
|
225
|
+
return;
|
|
226
|
+
drag = { id, startX: event.clientX, startY: event.clientY, active: false, drop: null, pointer: event.pointerId };
|
|
227
|
+
handle.setPointerCapture(event.pointerId);
|
|
228
|
+
};
|
|
229
|
+
const onDragMove = (event) => {
|
|
230
|
+
if (!drag || event.pointerId !== drag.pointer)
|
|
231
|
+
return;
|
|
232
|
+
if (!drag.active && Math.hypot(event.clientX - drag.startX, event.clientY - drag.startY) < 4)
|
|
233
|
+
return;
|
|
234
|
+
if (!drag.active) {
|
|
235
|
+
drag.active = true;
|
|
236
|
+
root.dataset.dragging = 'true';
|
|
237
|
+
}
|
|
238
|
+
const target = dropAt(event);
|
|
239
|
+
drag.drop = target && !('before' in target.position && target.position.before === drag.id) ? target.position : null;
|
|
240
|
+
showIndicator(target);
|
|
241
|
+
};
|
|
242
|
+
const end = (event, commit) => {
|
|
243
|
+
if (!drag || event.pointerId !== drag.pointer)
|
|
244
|
+
return;
|
|
245
|
+
const d = drag;
|
|
246
|
+
drag = null;
|
|
247
|
+
indicator.dataset.visible = 'false';
|
|
248
|
+
delete root.dataset.dragging;
|
|
249
|
+
if (handle.hasPointerCapture(event.pointerId))
|
|
250
|
+
handle.releasePointerCapture(event.pointerId);
|
|
251
|
+
if (!d.active)
|
|
252
|
+
return;
|
|
253
|
+
dragged.current = true;
|
|
254
|
+
if (commit && d.drop)
|
|
255
|
+
controller.move(d.id, d.drop, 'pointer');
|
|
256
|
+
};
|
|
257
|
+
const onUp = (event) => end(event, true);
|
|
258
|
+
const onCancel = (event) => end(event, false);
|
|
259
|
+
const onKey = (event) => {
|
|
260
|
+
if (event.key === 'Escape' && drag) {
|
|
261
|
+
const pointer = drag.pointer;
|
|
262
|
+
end({ pointerId: pointer }, false);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
root.addEventListener('pointermove', onMove);
|
|
266
|
+
handle.addEventListener('pointerdown', onDown);
|
|
267
|
+
handle.addEventListener('pointermove', onDragMove);
|
|
268
|
+
handle.addEventListener('pointerup', onUp);
|
|
269
|
+
handle.addEventListener('pointercancel', onCancel);
|
|
270
|
+
window.addEventListener('keydown', onKey, true);
|
|
271
|
+
return () => {
|
|
272
|
+
offStore();
|
|
273
|
+
root.removeEventListener('pointermove', onMove);
|
|
274
|
+
handle.removeEventListener('pointerdown', onDown);
|
|
275
|
+
handle.removeEventListener('pointermove', onDragMove);
|
|
276
|
+
handle.removeEventListener('pointerup', onUp);
|
|
277
|
+
handle.removeEventListener('pointercancel', onCancel);
|
|
278
|
+
window.removeEventListener('keydown', onKey, true);
|
|
279
|
+
};
|
|
280
|
+
}, [controller, rootRef, contentRef]);
|
|
281
|
+
return (_jsxs(_Fragment, { children: [_jsx("button", { ref: handleRef, type: "button", className: "salmon-block-editor__handle", "data-visible": "false", "aria-label": locale.dragHandle, "aria-haspopup": "menu", title: locale.dragHandle, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
|
|
282
|
+
if (dragged.current) {
|
|
283
|
+
dragged.current = false;
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const id = event.currentTarget.dataset.blockId;
|
|
287
|
+
if (id)
|
|
288
|
+
onOpen(id, rectOf(event.currentTarget));
|
|
289
|
+
}, children: _jsx("span", { "aria-hidden": "true", className: "salmon-block-editor__grip" }) }), _jsx("div", { ref: indicatorRef, className: "salmon-block-editor__drop-indicator", "data-visible": "false", "aria-hidden": "true" })] }));
|
|
290
|
+
}
|
|
291
|
+
// ---------------------------------------------------------------------------
|
|
292
|
+
// Block action menu and context menu on the shared Menu.
|
|
293
|
+
// ---------------------------------------------------------------------------
|
|
294
|
+
function BlockMenu(props) {
|
|
295
|
+
const { menu, controller, locale, actions, close, openImage } = props;
|
|
296
|
+
const editor = props.props;
|
|
297
|
+
const ref = useRef(null);
|
|
298
|
+
const block = menu.blockId ? controller.getBlock(menu.blockId) : undefined;
|
|
299
|
+
const transforms = editor.transforms ?? TRANSFORMS;
|
|
300
|
+
const current = block ? transformOf(block) : null;
|
|
301
|
+
const custom = new Map();
|
|
302
|
+
const items = [];
|
|
303
|
+
const turnInto = block && TEXT_TYPES.has(block.type) ? { id: 'turnInto', label: locale.turnInto, items: transforms.map((t) => ({ id: `turnInto:${t}`, label: locale[t], disabled: t === current })) } : null;
|
|
304
|
+
const builtIn = (id) => {
|
|
305
|
+
switch (id) {
|
|
306
|
+
case 'turnInto':
|
|
307
|
+
return turnInto;
|
|
308
|
+
case 'duplicate':
|
|
309
|
+
case 'delete':
|
|
310
|
+
case 'moveUp':
|
|
311
|
+
case 'moveDown':
|
|
312
|
+
case 'cut':
|
|
313
|
+
case 'copy':
|
|
314
|
+
return { id, label: locale[id], disabled: !block && id !== 'cut' && id !== 'copy' };
|
|
315
|
+
default:
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
const entries = menu.kind === 'block' ? (editor.blockActions ?? ACTIONS_DEFAULT) : (editor.contextMenu || CONTEXT_DEFAULT);
|
|
320
|
+
for (const entry of entries) {
|
|
321
|
+
if (isCustom(entry)) {
|
|
322
|
+
custom.set(entry.id, entry);
|
|
323
|
+
items.push({ id: `custom:${entry.id}`, label: entry.label, ...(entry.disabled ? { disabled: true } : {}) });
|
|
324
|
+
}
|
|
325
|
+
else {
|
|
326
|
+
const item = builtIn(entry);
|
|
327
|
+
if (item)
|
|
328
|
+
items.push(item);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (block?.type === 'image')
|
|
332
|
+
items.push({ type: 'separator' }, { id: 'editImage', label: locale.editImage });
|
|
333
|
+
if (block?.type === 'table')
|
|
334
|
+
items.push({ type: 'separator' }, ...TABLE_OPS.map((op) => ({ id: `table:${op}`, label: locale[op] })));
|
|
335
|
+
// First item focused once the popover is placed (a hidden element cannot take focus).
|
|
336
|
+
useEffect(() => {
|
|
337
|
+
const focusFirst = () => ref.current?.querySelector('[role="menuitem"]:not([aria-disabled="true"])')?.focus({ preventScroll: true });
|
|
338
|
+
focusFirst();
|
|
339
|
+
const frame = requestAnimationFrame(() => {
|
|
340
|
+
if (!ref.current?.contains(document.activeElement))
|
|
341
|
+
focusFirst();
|
|
342
|
+
});
|
|
343
|
+
return () => cancelAnimationFrame(frame);
|
|
344
|
+
}, []);
|
|
345
|
+
// Outside press closes.
|
|
346
|
+
useEffect(() => {
|
|
347
|
+
const onDown = (event) => {
|
|
348
|
+
const el = ref.current;
|
|
349
|
+
if (el && !el.contains(event.target) && !event.target.closest?.('.salmon-menu'))
|
|
350
|
+
close(false);
|
|
351
|
+
};
|
|
352
|
+
document.addEventListener('pointerdown', onDown, true);
|
|
353
|
+
return () => document.removeEventListener('pointerdown', onDown, true);
|
|
354
|
+
});
|
|
355
|
+
const onAction = (event) => {
|
|
356
|
+
const id = event.id;
|
|
357
|
+
const blockId = menu.blockId;
|
|
358
|
+
if (id.startsWith('turnInto:') && blockId) {
|
|
359
|
+
close();
|
|
360
|
+
controller.turnInto(blockId, id.slice(9));
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
if (id.startsWith('custom:')) {
|
|
364
|
+
const item = custom.get(id.slice(7));
|
|
365
|
+
close();
|
|
366
|
+
item?.onSelect({ block: blockId ? (controller.getBlock(blockId) ?? null) : null, actions });
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
if (id.startsWith('table:') && blockId) {
|
|
370
|
+
close();
|
|
371
|
+
controller.selectInTable(blockId);
|
|
372
|
+
controller.runAction(id.slice(6));
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
switch (id) {
|
|
376
|
+
case 'duplicate':
|
|
377
|
+
close();
|
|
378
|
+
if (blockId)
|
|
379
|
+
controller.duplicate(blockId);
|
|
380
|
+
break;
|
|
381
|
+
case 'delete':
|
|
382
|
+
close();
|
|
383
|
+
if (blockId)
|
|
384
|
+
controller.delete(blockId);
|
|
385
|
+
break;
|
|
386
|
+
case 'moveUp':
|
|
387
|
+
close();
|
|
388
|
+
if (blockId)
|
|
389
|
+
controller.step(-1, blockId);
|
|
390
|
+
break;
|
|
391
|
+
case 'moveDown':
|
|
392
|
+
close();
|
|
393
|
+
if (blockId)
|
|
394
|
+
controller.step(1, blockId);
|
|
395
|
+
break;
|
|
396
|
+
case 'cut':
|
|
397
|
+
case 'copy':
|
|
398
|
+
close();
|
|
399
|
+
document.execCommand(id);
|
|
400
|
+
break;
|
|
401
|
+
case 'editImage':
|
|
402
|
+
close(false);
|
|
403
|
+
if (blockId)
|
|
404
|
+
openImage(blockId);
|
|
405
|
+
break;
|
|
406
|
+
default:
|
|
407
|
+
close();
|
|
408
|
+
}
|
|
409
|
+
};
|
|
410
|
+
return (_jsx(Popover, { anchor: () => menu.anchor, subscribe: controller.subscribe, className: "salmon-block-editor__menu-popover", placement: "below", children: _jsx("div", { ref: ref, onKeyDown: (event) => {
|
|
411
|
+
if (event.key === 'Escape' || event.key === 'Tab') {
|
|
412
|
+
event.preventDefault();
|
|
413
|
+
event.stopPropagation();
|
|
414
|
+
close();
|
|
415
|
+
}
|
|
416
|
+
}, children: _jsx(Menu, { items: items, onAction: onAction, "aria-label": menu.kind === 'block' ? locale.blockActions : locale.contextMenu }) }) }));
|
|
417
|
+
}
|
|
418
|
+
function SlashMenu(props) {
|
|
419
|
+
const { controller, locale, hooks, actions, openFile } = props;
|
|
420
|
+
const suggest = useSnapshot(controller, (s) => s.suggest);
|
|
421
|
+
const query = suggest?.query ?? null;
|
|
422
|
+
const [active, setActive] = useState(0);
|
|
423
|
+
const [lastQuery, setLastQuery] = useState(null);
|
|
424
|
+
if (query !== lastQuery) {
|
|
425
|
+
setLastQuery(query);
|
|
426
|
+
setActive(0);
|
|
427
|
+
}
|
|
428
|
+
const list = props.items === false ? [] : (props.items ?? SLASH_DEFAULT);
|
|
429
|
+
const entries = list.map((item) => {
|
|
430
|
+
if (isCustom(item)) {
|
|
431
|
+
return {
|
|
432
|
+
id: item.id,
|
|
433
|
+
label: item.label,
|
|
434
|
+
group: item.group ?? locale.groupCustom,
|
|
435
|
+
keywords: item.keywords ?? [],
|
|
436
|
+
run: () => item.onSelect({ block: (controller.currentBlockId() && controller.getBlock(controller.currentBlockId())) || null, actions }),
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
const media = item === 'image' || item === 'table' || item === 'divider';
|
|
440
|
+
return {
|
|
441
|
+
id: item,
|
|
442
|
+
label: locale[item],
|
|
443
|
+
group: media ? locale.groupMedia : locale.groupBasic,
|
|
444
|
+
keywords: [item],
|
|
445
|
+
run: () => {
|
|
446
|
+
if (item === 'image')
|
|
447
|
+
openFile();
|
|
448
|
+
else
|
|
449
|
+
controller.runBlockAction(item);
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
});
|
|
453
|
+
const q = (query ?? '').toLowerCase();
|
|
454
|
+
const shown = q ? entries.filter((e) => e.label.toLowerCase().includes(q) || e.keywords.some((k) => k.toLowerCase().startsWith(q))) : entries;
|
|
455
|
+
const index = shown.length ? Math.min(active, shown.length - 1) : -1;
|
|
456
|
+
const pick = (entry) => {
|
|
457
|
+
if (!entry)
|
|
458
|
+
return;
|
|
459
|
+
controller.engine.completeSuggest(null);
|
|
460
|
+
entry.run();
|
|
461
|
+
};
|
|
462
|
+
useEffect(() => {
|
|
463
|
+
hooks.current.suggestKey = (event) => {
|
|
464
|
+
if (query === null)
|
|
465
|
+
return false;
|
|
466
|
+
switch (event.key) {
|
|
467
|
+
case 'ArrowDown':
|
|
468
|
+
setActive((i) => (shown.length ? (Math.min(i, shown.length - 1) + 1) % shown.length : 0));
|
|
469
|
+
return true;
|
|
470
|
+
case 'ArrowUp':
|
|
471
|
+
setActive((i) => (shown.length ? (Math.min(i, shown.length - 1) - 1 + shown.length) % shown.length : 0));
|
|
472
|
+
return true;
|
|
473
|
+
case 'Enter':
|
|
474
|
+
case 'Tab':
|
|
475
|
+
if (!shown.length)
|
|
476
|
+
return false;
|
|
477
|
+
pick(shown[index]);
|
|
478
|
+
return true;
|
|
479
|
+
case 'Escape':
|
|
480
|
+
controller.engine.dismissSuggest();
|
|
481
|
+
return true;
|
|
482
|
+
default:
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
});
|
|
487
|
+
if (query === null)
|
|
488
|
+
return null;
|
|
489
|
+
const listId = 'salmon-block-editor-slash';
|
|
490
|
+
let group = '';
|
|
491
|
+
return (_jsx(Popover, { anchor: () => controller.caretRect('suggest'), subscribe: controller.subscribe, className: "salmon-block-editor__slash", children: _jsxs("div", { role: "listbox", id: listId, "aria-label": locale.slashMenu, className: "salmon-block-editor__options", children: [shown.length === 0 ? _jsx("div", { className: "salmon-block-editor__empty", children: locale.noResults }) : null, shown.map((entry, i) => {
|
|
492
|
+
const heading = entry.group !== group ? entry.group : null;
|
|
493
|
+
group = entry.group;
|
|
494
|
+
return (_jsxs("div", { role: "presentation", children: [heading ? (_jsx("div", { role: "presentation", className: "salmon-block-editor__group", children: heading })) : null, _jsx("div", { role: "option", id: `${listId}-${entry.id}`, "aria-selected": i === index, "data-item-id": entry.id, className: "salmon-block-editor__option", onMouseDown: (event) => event.preventDefault(), onClick: () => pick(entry), onPointerMove: () => i !== index && setActive(i), children: entry.label })] }, entry.id));
|
|
495
|
+
})] }) }));
|
|
496
|
+
}
|
|
497
|
+
// ---------------------------------------------------------------------------
|
|
498
|
+
// Selection toolbar
|
|
499
|
+
// ---------------------------------------------------------------------------
|
|
500
|
+
const MARK_ITEMS = { bold: 'bold', italic: 'italic', underline: 'underline', strike: 'strikethrough', code: 'inlineCode' };
|
|
501
|
+
function InlineToolbar(props) {
|
|
502
|
+
const { controller, locale, items, transforms, actions, toolbarRef, linkEditing, setLinkEditing } = props;
|
|
503
|
+
const marks = useSnapshot(controller, (s) => s.marks);
|
|
504
|
+
const link = useSnapshot(controller, (s) => s.link);
|
|
505
|
+
const keep = (event) => event.preventDefault();
|
|
506
|
+
const common = { 'data-salmon-toolbar-item': '', tabIndex: -1, size: 'sm', variant: 'ghost', onMouseDown: keep };
|
|
507
|
+
const blockId = controller.currentBlockId();
|
|
508
|
+
const block = blockId ? controller.getBlock(blockId) : undefined;
|
|
509
|
+
if (linkEditing) {
|
|
510
|
+
return (_jsx(Popover, { anchor: () => controller.caretRect(), subscribe: controller.subscribe, className: "salmon-block-editor__toolbar-popover", placement: "above", children: _jsx(LinkForm, { locale: locale, initial: link ?? '', done: (href) => {
|
|
511
|
+
setLinkEditing(false);
|
|
512
|
+
controller.focus();
|
|
513
|
+
if (href === null)
|
|
514
|
+
return;
|
|
515
|
+
if (href)
|
|
516
|
+
controller.engine.commands.setLink({ href });
|
|
517
|
+
else
|
|
518
|
+
controller.engine.commands.unsetLink();
|
|
519
|
+
} }) }));
|
|
520
|
+
}
|
|
521
|
+
return (_jsx(Popover, { anchor: () => controller.caretRect(), subscribe: controller.subscribe, className: "salmon-block-editor__toolbar-popover", placement: "above", children: _jsx(ToolbarShell, { ref: toolbarRef, label: locale.inlineToolbar, className: "salmon-block-editor__toolbar", onEscape: () => controller.focus(), children: items.map((item) => {
|
|
522
|
+
if (isCustom(item)) {
|
|
523
|
+
return (_jsx(Button, { ...common, disabled: item.disabled, onClick: () => item.onSelect({ block: block ?? null, actions }), children: item.label }, item.id));
|
|
524
|
+
}
|
|
525
|
+
if (item === 'link') {
|
|
526
|
+
return _jsx(ToggleButton, { ...common, iconOnly: true, "aria-label": locale.link, pressed: link !== null, iconStart: _jsx(Icon, { name: "link" }), onPressedChange: () => setLinkEditing(true) }, "link");
|
|
527
|
+
}
|
|
528
|
+
if (item === 'turnInto') {
|
|
529
|
+
if (!block || !TEXT_TYPES.has(block.type))
|
|
530
|
+
return null;
|
|
531
|
+
const current = transformOf(block);
|
|
532
|
+
return (_jsx(MenuButton, { ...common, items: transforms.map((t) => ({ id: t, label: locale[t], disabled: t === current })), onAction: (event) => {
|
|
533
|
+
controller.turnInto(block.id, event.id);
|
|
534
|
+
controller.focus();
|
|
535
|
+
}, children: locale.turnInto }, "turnInto"));
|
|
536
|
+
}
|
|
537
|
+
const mark = item;
|
|
538
|
+
const label = mark === 'code' ? locale.inlineCode : locale[mark];
|
|
539
|
+
return (_jsx(ToggleButton, { ...common, iconOnly: true, "aria-label": label, "data-item-id": item, pressed: marks[mark], iconStart: _jsx(Icon, { name: MARK_ITEMS[mark] }), onPressedChange: () => {
|
|
540
|
+
controller.runAction(mark);
|
|
541
|
+
} }, item));
|
|
542
|
+
}) }) }));
|
|
543
|
+
}
|
|
544
|
+
function LinkForm(props) {
|
|
545
|
+
const { locale, initial, done } = props;
|
|
546
|
+
const ref = useRef(null);
|
|
547
|
+
useLayoutEffect(() => {
|
|
548
|
+
ref.current?.focus();
|
|
549
|
+
}, []);
|
|
550
|
+
return (_jsxs("form", { className: "salmon-block-editor__link-form", onSubmit: (event) => {
|
|
551
|
+
event.preventDefault();
|
|
552
|
+
done(ref.current?.value.trim() ?? '');
|
|
553
|
+
}, onKeyDown: (event) => {
|
|
554
|
+
if (event.key === 'Escape') {
|
|
555
|
+
event.preventDefault();
|
|
556
|
+
event.stopPropagation();
|
|
557
|
+
done(null);
|
|
558
|
+
}
|
|
559
|
+
}, children: [_jsx("input", { ref: ref, type: "url", "aria-label": locale.linkUrl, placeholder: "https://", defaultValue: initial, className: "salmon-block-editor__link-input" }), _jsx(Button, { type: "submit", size: "sm", children: locale.apply }), initial ? (_jsx(Button, { type: "button", size: "sm", variant: "ghost", onClick: () => done(''), children: locale.removeLink })) : null] }));
|
|
560
|
+
}
|
|
561
|
+
// ---------------------------------------------------------------------------
|
|
562
|
+
// Dialogs: image settings, paste prompt
|
|
563
|
+
// ---------------------------------------------------------------------------
|
|
564
|
+
function ImageDialog(props) {
|
|
565
|
+
const { controller, blockId, locale, close } = props;
|
|
566
|
+
const block = controller.getBlock(blockId);
|
|
567
|
+
const alt = typeof block?.props?.alt === 'string' ? block.props.alt : '';
|
|
568
|
+
const width = typeof block?.props?.width === 'number' ? block.props.width : undefined;
|
|
569
|
+
return (_jsx(Dialog, { title: locale.editImage, onClose: close, children: _jsxs("form", { onSubmit: (event) => {
|
|
570
|
+
event.preventDefault();
|
|
571
|
+
const data = new FormData(event.currentTarget);
|
|
572
|
+
const w = Number.parseInt(String(data.get('width') ?? ''), 10);
|
|
573
|
+
controller.updateImage(blockId, { alt: String(data.get('alt') ?? ''), width: Number.isFinite(w) && w > 0 ? w : null });
|
|
574
|
+
close();
|
|
575
|
+
}, children: [_jsxs("div", { className: "salmon-rich-text__field", children: [_jsx("label", { htmlFor: `${blockId}-alt`, children: locale.altText }), _jsx("input", { id: `${blockId}-alt`, name: "alt", defaultValue: alt, "data-autofocus": "" })] }), _jsxs("div", { className: "salmon-rich-text__field", children: [_jsx("label", { htmlFor: `${blockId}-width`, children: locale.width }), _jsx("input", { id: `${blockId}-width`, name: "width", type: "number", min: 1, defaultValue: width })] }), _jsxs("div", { className: "salmon-rich-text__dialog-actions", children: [_jsx(Button, { type: "button", variant: "ghost", onClick: close, children: locale.cancel }), _jsx(Button, { type: "submit", children: locale.save })] })] }) }));
|
|
576
|
+
}
|
|
577
|
+
function PasteDialog(props) {
|
|
578
|
+
const { locale, choose } = props;
|
|
579
|
+
return (_jsx(Dialog, { title: locale.pastePrompt, onClose: () => choose(null), children: _jsxs("div", { className: "salmon-rich-text__dialog-actions", children: [_jsx(Button, { "data-autofocus": "", onClick: () => choose('keep'), children: locale.pasteKeep }), _jsx(Button, { onClick: () => choose('clean'), children: locale.pasteClean }), _jsx(Button, { onClick: () => choose('plainText'), children: locale.pastePlain })] }) }));
|
|
580
|
+
}
|
|
581
|
+
// ---------------------------------------------------------------------------
|
|
582
|
+
// Print: the content only, in an isolated frame with the page styles.
|
|
583
|
+
// ---------------------------------------------------------------------------
|
|
584
|
+
function printContent(controller, root) {
|
|
585
|
+
const doc = root?.ownerDocument ?? document;
|
|
586
|
+
doc.querySelector('.salmon-block-editor__print-frame')?.remove();
|
|
587
|
+
const frame = doc.createElement('iframe');
|
|
588
|
+
frame.className = 'salmon-block-editor__print-frame';
|
|
589
|
+
frame.setAttribute('aria-hidden', 'true');
|
|
590
|
+
frame.tabIndex = -1;
|
|
591
|
+
frame.style.cssText = 'position:fixed;inset-inline-start:-10000px;inline-size:1px;block-size:1px;border:0;';
|
|
592
|
+
const styles = [...doc.querySelectorAll('link[rel="stylesheet"], style')].map((el) => el.outerHTML).join('');
|
|
593
|
+
const dir = root ? getComputedStyle(root).direction : 'ltr';
|
|
594
|
+
frame.srcdoc = `<!doctype html><html dir="${dir}"><head><meta charset="utf-8">${styles}</head><body><div class="salmon-rich-text-content salmon-block-editor__print">${controller.getHtml()}</div></body></html>`;
|
|
595
|
+
frame.addEventListener('load', () => {
|
|
596
|
+
frame.contentWindow?.focus();
|
|
597
|
+
frame.contentWindow?.print();
|
|
598
|
+
});
|
|
599
|
+
doc.body.appendChild(frame);
|
|
600
|
+
}
|
|
601
|
+
//# sourceMappingURL=ui.js.map
|