@maily-to/core 2.0.0-beta.7 → 2.0.0-beta.9
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/blocks/index.cjs +8 -1
- package/dist/blocks/index.d.cts +1 -38
- package/dist/blocks/index.d.mts +14 -6
- package/dist/blocks/index.d.mts.map +1 -1
- package/dist/blocks/index.mjs +2 -2
- package/dist/extensions/index.cjs +266 -286
- package/dist/extensions/index.d.cts +1 -379
- package/dist/extensions/index.d.mts +127 -224
- package/dist/extensions/index.d.mts.map +1 -1
- package/dist/extensions/index.mjs +238 -271
- package/dist/index.cjs +8826 -11828
- package/dist/index.d.cts +1 -165
- package/dist/index.d.mts +701 -121
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +8460 -11567
- package/dist/{slash-command-BmWRVPbv.d.mts → slash-command-BrwA1bHs.d.mts} +10 -11
- package/dist/slash-command-BrwA1bHs.d.mts.map +1 -0
- package/dist/theme-D1CI7_8s.d.mts +70 -0
- package/dist/theme-D1CI7_8s.d.mts.map +1 -0
- package/dist/typography-BdOKvXfQ.mjs +911 -0
- package/dist/typography-D-VnwOSw.cjs +970 -0
- package/dist/typography-DW7VApAR.cjs +1072 -0
- package/dist/use-maily-editor-Atvy2kSO.cjs +3993 -0
- package/dist/use-maily-editor-CByaDhmT.cjs +4955 -0
- package/dist/use-maily-editor-idL0RNsG.mjs +4504 -0
- package/package.json +82 -74
- package/readme.md +169 -128
- package/src/styles/index.css +2537 -0
- package/dist/blocks/index.d.cts.map +0 -1
- package/dist/chunk-CfYAbeIz.mjs +0 -13
- package/dist/extensions/index.d.cts.map +0 -1
- package/dist/extensions/index.mjs.map +0 -1
- package/dist/index.css +0 -2312
- package/dist/index.d.cts.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/slash-command-BmWRVPbv.d.mts.map +0 -1
- package/dist/slash-command-CK0-1FwR.d.cts +0 -39
- package/dist/slash-command-CK0-1FwR.d.cts.map +0 -1
- package/dist/spacer-DBtsr3hu.cjs +0 -5768
- package/dist/spacer-DzZWX-wB.mjs +0 -5456
- package/dist/spacer-DzZWX-wB.mjs.map +0 -1
- package/dist/typography-CWL13acR.cjs +0 -400
- package/dist/typography-DhrUe809.mjs +0 -282
- package/dist/typography-DhrUe809.mjs.map +0 -1
- package/dist/variable-C9S9ZoHv.d.cts +0 -108
- package/dist/variable-C9S9ZoHv.d.cts.map +0 -1
- package/dist/variable-DVwGrg2a.d.mts +0 -108
- package/dist/variable-DVwGrg2a.d.mts.map +0 -1
|
@@ -0,0 +1,3993 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
+
key = keys[i];
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: ((k) => from[k]).bind(null, key),
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
//#endregion
|
|
32
|
+
const require_typography = require("./typography-D-VnwOSw.cjs");
|
|
33
|
+
let react = require("react");
|
|
34
|
+
let _base_ui_utils_useIsoLayoutEffect = require("@base-ui/utils/useIsoLayoutEffect");
|
|
35
|
+
let _base_ui_utils_useRefWithInit = require("@base-ui/utils/useRefWithInit");
|
|
36
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
37
|
+
let lucide_react = require("lucide-react");
|
|
38
|
+
let _base_ui_react_tooltip = require("@base-ui/react/tooltip");
|
|
39
|
+
let _floating_ui_react = require("@floating-ui/react");
|
|
40
|
+
let _floating_ui_utils_dom = require("@floating-ui/utils/dom");
|
|
41
|
+
let _maily_to_shared = require("@maily-to/shared");
|
|
42
|
+
let _tiptap_react = require("@tiptap/react");
|
|
43
|
+
let zustand = require("zustand");
|
|
44
|
+
let _tiptap_pm_state = require("@tiptap/pm/state");
|
|
45
|
+
let _tiptap_extension_paragraph = require("@tiptap/extension-paragraph");
|
|
46
|
+
let _tiptap_extension_text = require("@tiptap/extension-text");
|
|
47
|
+
let _tiptap_extensions = require("@tiptap/extensions");
|
|
48
|
+
let _tiptap_extension_document = require("@tiptap/extension-document");
|
|
49
|
+
let _tiptap_core = require("@tiptap/core");
|
|
50
|
+
let _tiptap_suggestion = require("@tiptap/suggestion");
|
|
51
|
+
let _tiptap_extension_code = require("@tiptap/extension-code");
|
|
52
|
+
let _tiptap_extension_hard_break = require("@tiptap/extension-hard-break");
|
|
53
|
+
let _tiptap_extension_heading = require("@tiptap/extension-heading");
|
|
54
|
+
let _tiptap_extension_highlight = require("@tiptap/extension-highlight");
|
|
55
|
+
let _tiptap_extension_italic = require("@tiptap/extension-italic");
|
|
56
|
+
let _tiptap_extension_link = require("@tiptap/extension-link");
|
|
57
|
+
let _tiptap_extension_list = require("@tiptap/extension-list");
|
|
58
|
+
let _tiptap_extension_strike = require("@tiptap/extension-strike");
|
|
59
|
+
let _tiptap_extension_text_style = require("@tiptap/extension-text-style");
|
|
60
|
+
let _tiptap_extension_typography = require("@tiptap/extension-typography");
|
|
61
|
+
let _tiptap_extension_underline = require("@tiptap/extension-underline");
|
|
62
|
+
let _tiptap_extension_unique_id = require("@tiptap/extension-unique-id");
|
|
63
|
+
let _tiptap_extension_blockquote = require("@tiptap/extension-blockquote");
|
|
64
|
+
let _tiptap_extension_bold = require("@tiptap/extension-bold");
|
|
65
|
+
let _tiptap_extension_horizontal_rule = require("@tiptap/extension-horizontal-rule");
|
|
66
|
+
let _tiptap_extension_code_block_lowlight = require("@tiptap/extension-code-block-lowlight");
|
|
67
|
+
let highlight_js_lib_languages_xml = require("highlight.js/lib/languages/xml");
|
|
68
|
+
highlight_js_lib_languages_xml = __toESM(highlight_js_lib_languages_xml, 1);
|
|
69
|
+
let lowlight = require("lowlight");
|
|
70
|
+
let _tiptap_extension_file_handler = require("@tiptap/extension-file-handler");
|
|
71
|
+
let _tiptap_extension_image = require("@tiptap/extension-image");
|
|
72
|
+
let _tiptap_extension_table = require("@tiptap/extension-table");
|
|
73
|
+
let _tiptap_pm_history = require("@tiptap/pm/history");
|
|
74
|
+
let _tiptap_pm_model = require("@tiptap/pm/model");
|
|
75
|
+
//#region src/hooks/use-value-as-ref.ts
|
|
76
|
+
/**
|
|
77
|
+
* Untracks the provided value by turning it into a ref to remove its reactivity.
|
|
78
|
+
*
|
|
79
|
+
* Used to access the passed value inside `React.useEffect` without causing the effect to re-run when the value changes.
|
|
80
|
+
*/
|
|
81
|
+
function useValueAsRef(value) {
|
|
82
|
+
const latest = (0, _base_ui_utils_useRefWithInit.useRefWithInit)(createLatestRef, value).current;
|
|
83
|
+
latest.next = value;
|
|
84
|
+
(0, _base_ui_utils_useIsoLayoutEffect.useIsoLayoutEffect)(latest.effect);
|
|
85
|
+
return latest;
|
|
86
|
+
}
|
|
87
|
+
function createLatestRef(value) {
|
|
88
|
+
const latest = {
|
|
89
|
+
current: value,
|
|
90
|
+
next: value,
|
|
91
|
+
effect: () => {
|
|
92
|
+
latest.current = latest.next;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return latest;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
//#region src/components/icons/arrow-icon.tsx
|
|
99
|
+
function ArrowIcon(props) {
|
|
100
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("svg", {
|
|
101
|
+
"data-mly-arrow-icon": "",
|
|
102
|
+
fill: "none",
|
|
103
|
+
height: "10",
|
|
104
|
+
viewBox: "0 0 20 10",
|
|
105
|
+
width: "20",
|
|
106
|
+
...props,
|
|
107
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
108
|
+
d: "M9.66437 2.60207L4.80758 6.97318C4.07308 7.63423 3.11989 8 2.13172 8H0V10H20V8H18.5349C17.5468 8 16.5936 7.63423 15.8591 6.97318L11.0023 2.60207C10.622 2.2598 10.0447 2.25979 9.66437 2.60207Z",
|
|
109
|
+
"data-mly-arrow-fill": ""
|
|
110
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
|
|
111
|
+
d: "M8.99542 1.85876C9.75604 1.17425 10.9106 1.17422 11.6713 1.85878L16.5281 6.22989C17.0789 6.72568 17.7938 7.00001 18.5349 7.00001L15.89 7L11.0023 2.60207C10.622 2.2598 10.0447 2.2598 9.66436 2.60207L4.77734 7L2.13171 7.00001C2.87284 7.00001 3.58774 6.72568 4.13861 6.22989L8.99542 1.85876Z",
|
|
112
|
+
"data-mly-arrow-border": ""
|
|
113
|
+
})]
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/hooks/use-editor-instance.ts
|
|
118
|
+
const EDITOR_INSTANCE_NOT_FOUND_ERROR = `Editor instance not found. Make sure to use the EditorContext.Provider or useEditor hook.
|
|
119
|
+
|
|
120
|
+
Please create an issue at ${_maily_to_shared.MAILY_BUG_REPORT_URL} if you think this is a bug.
|
|
121
|
+
`;
|
|
122
|
+
/**
|
|
123
|
+
* Returns the active Tiptap editor instance, preferring the explicitly
|
|
124
|
+
* passed editor over the one from EditorContext. Throws if neither exists.
|
|
125
|
+
*/
|
|
126
|
+
function useEditorInstance(editor) {
|
|
127
|
+
const { editor: currentEditor } = (0, _tiptap_react.useCurrentEditor)();
|
|
128
|
+
const editorInstance = (0, react.useMemo)(() => editor || currentEditor, [editor, currentEditor]);
|
|
129
|
+
(0, _maily_to_shared.invariant)(editorInstance, EDITOR_INSTANCE_NOT_FOUND_ERROR);
|
|
130
|
+
return editorInstance;
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
//#region src/hooks/use-floating-store.ts
|
|
134
|
+
/**
|
|
135
|
+
* Global Zustand store that tracks FloatingUI contexts for all
|
|
136
|
+
* bubble menus. Menus register on mount and unregister on unmount
|
|
137
|
+
* so the editor can coordinate which menu is visible.
|
|
138
|
+
*/
|
|
139
|
+
const useFloatingStore = (0, zustand.create)((set, get, store) => ({
|
|
140
|
+
contexts: [],
|
|
141
|
+
isDragContextOpen: false,
|
|
142
|
+
setDragContextOpen: (open) => {
|
|
143
|
+
set({ isDragContextOpen: open });
|
|
144
|
+
},
|
|
145
|
+
register: (id, context) => {
|
|
146
|
+
set((state) => {
|
|
147
|
+
if (state.contexts.find((item) => item.id === id)) return state;
|
|
148
|
+
return { contexts: [...state.contexts, {
|
|
149
|
+
id,
|
|
150
|
+
value: context
|
|
151
|
+
}] };
|
|
152
|
+
});
|
|
153
|
+
return () => {
|
|
154
|
+
get().unregister(id);
|
|
155
|
+
};
|
|
156
|
+
},
|
|
157
|
+
unregister: (id) => {
|
|
158
|
+
set((state) => ({ contexts: state.contexts.filter((item) => item.id !== id) }));
|
|
159
|
+
},
|
|
160
|
+
update: (id, context) => {
|
|
161
|
+
set((state) => ({ contexts: state.contexts.map((item) => item.id === id ? {
|
|
162
|
+
...item,
|
|
163
|
+
value: context
|
|
164
|
+
} : item) }));
|
|
165
|
+
},
|
|
166
|
+
getContext: (id) => get().contexts.find((item) => item.id === id)?.value,
|
|
167
|
+
getAll: () => get().contexts,
|
|
168
|
+
reset: () => {
|
|
169
|
+
set(store.getInitialState());
|
|
170
|
+
}
|
|
171
|
+
}));
|
|
172
|
+
/** Registers a floating menu's context on mount and cleans up on unmount. */
|
|
173
|
+
function useRegisterFloatingContext(id, context) {
|
|
174
|
+
const register = useFloatingStore((state) => state.register);
|
|
175
|
+
(0, react.useEffect)(() => {
|
|
176
|
+
return register(id, context);
|
|
177
|
+
}, [
|
|
178
|
+
id,
|
|
179
|
+
context,
|
|
180
|
+
register
|
|
181
|
+
]);
|
|
182
|
+
}
|
|
183
|
+
//#endregion
|
|
184
|
+
//#region src/hooks/use-on-selection-update.ts
|
|
185
|
+
function useOnSelectionUpdate(editor, onSelectionUpdate) {
|
|
186
|
+
const callback = useValueAsRef(onSelectionUpdate);
|
|
187
|
+
(0, react.useEffect)(() => {
|
|
188
|
+
const handler = () => {
|
|
189
|
+
callback.current();
|
|
190
|
+
};
|
|
191
|
+
handler();
|
|
192
|
+
editor.on("selectionUpdate", handler);
|
|
193
|
+
return () => {
|
|
194
|
+
editor.off("selectionUpdate", handler);
|
|
195
|
+
};
|
|
196
|
+
}, [callback, editor]);
|
|
197
|
+
}
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region src/types/floating-ui.ts
|
|
200
|
+
/**
|
|
201
|
+
* Stable IDs for each floating bubble menu. Used to register, look up,
|
|
202
|
+
* and coordinate visibility of menus through the floating store.
|
|
203
|
+
*/
|
|
204
|
+
const FLOATING_ELEMENT_ATTRIBUTE = "data-mly-floating-element";
|
|
205
|
+
const FLOATING_ELEMENT_IDS = {
|
|
206
|
+
TEXT_BUBBLE_MENU: "text-bubble-menu",
|
|
207
|
+
VARIABLE_BUBBLE_MENU: "variable-bubble-menu",
|
|
208
|
+
SPACER_BUBBLE_MENU: "spacer-bubble-menu",
|
|
209
|
+
SECTION_BUBBLE_MENU: "section-bubble-menu",
|
|
210
|
+
COLUMNS_BUBBLE_MENU: "columns-bubble-menu",
|
|
211
|
+
INLINE_IMAGE_BUBBLE_MENU: "inline-image-bubble-menu",
|
|
212
|
+
IMAGE_BUBBLE_MENU: "image-bubble-menu",
|
|
213
|
+
BUTTON_BUBBLE_MENU: "button-bubble-menu",
|
|
214
|
+
HTML_CODE_BLOCK_BUBBLE_MENU: "html-code-block-bubble-menu",
|
|
215
|
+
REPEAT_BUBBLE_MENU: "repeat-bubble-menu",
|
|
216
|
+
LINK_CARD_BUBBLE_MENU: "link-card-bubble-menu"
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Priority order for bubble menu visibility. When multiple menus
|
|
220
|
+
* could be active (e.g. text inside a button inside a section),
|
|
221
|
+
* the first matching menu in this list wins.
|
|
222
|
+
*/
|
|
223
|
+
const FLOATING_ELEMENT_ORDER = [
|
|
224
|
+
FLOATING_ELEMENT_IDS.BUTTON_BUBBLE_MENU,
|
|
225
|
+
FLOATING_ELEMENT_IDS.HTML_CODE_BLOCK_BUBBLE_MENU,
|
|
226
|
+
FLOATING_ELEMENT_IDS.VARIABLE_BUBBLE_MENU,
|
|
227
|
+
FLOATING_ELEMENT_IDS.SPACER_BUBBLE_MENU,
|
|
228
|
+
FLOATING_ELEMENT_IDS.COLUMNS_BUBBLE_MENU,
|
|
229
|
+
FLOATING_ELEMENT_IDS.REPEAT_BUBBLE_MENU,
|
|
230
|
+
FLOATING_ELEMENT_IDS.SECTION_BUBBLE_MENU,
|
|
231
|
+
FLOATING_ELEMENT_IDS.INLINE_IMAGE_BUBBLE_MENU,
|
|
232
|
+
FLOATING_ELEMENT_IDS.IMAGE_BUBBLE_MENU,
|
|
233
|
+
FLOATING_ELEMENT_IDS.LINK_CARD_BUBBLE_MENU,
|
|
234
|
+
FLOATING_ELEMENT_IDS.TEXT_BUBBLE_MENU
|
|
235
|
+
];
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region src/utils/selection.ts
|
|
238
|
+
const CONTAINER_NODES = [
|
|
239
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
240
|
+
_maily_to_shared.MAILY_NODE_TYPES.REPEAT,
|
|
241
|
+
_maily_to_shared.MAILY_NODE_TYPES.SECTION,
|
|
242
|
+
_maily_to_shared.MAILY_NODE_TYPES.BUTTON,
|
|
243
|
+
_maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK
|
|
244
|
+
];
|
|
245
|
+
function clearInitialNodeSelection(editor) {
|
|
246
|
+
const { state } = editor;
|
|
247
|
+
if (!(state.selection instanceof _tiptap_pm_state.NodeSelection)) return;
|
|
248
|
+
const textSelection = _tiptap_pm_state.Selection.findFrom(state.doc.resolve(0), 1, true);
|
|
249
|
+
if (textSelection) editor.view.dispatch(state.tr.setSelection(textSelection));
|
|
250
|
+
editor.view.dom.blur();
|
|
251
|
+
}
|
|
252
|
+
function findNodeClientRect(editor, nodeType) {
|
|
253
|
+
const activeNode = (0, _tiptap_react.findParentNode)((node) => node.type.name === nodeType)(editor.state.selection);
|
|
254
|
+
if (!activeNode) return null;
|
|
255
|
+
const dom = editor.view.nodeDOM(activeNode.pos);
|
|
256
|
+
return dom instanceof HTMLElement ? dom.getBoundingClientRect() : null;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Returns a DOMRect for the current selection. For nodes inside a
|
|
260
|
+
* container (columns, repeat, section, button, html code block), returns the
|
|
261
|
+
* container's rect so the bubble menu stays anchored to the block rather than
|
|
262
|
+
* the inline selection.
|
|
263
|
+
*/
|
|
264
|
+
function getCurrentSelectionRect(editor) {
|
|
265
|
+
const { selection } = editor.state;
|
|
266
|
+
const { ranges } = selection;
|
|
267
|
+
const from = Math.min(...ranges.map((range) => range.$from.pos));
|
|
268
|
+
const to = Math.max(...ranges.map((range) => range.$to.pos));
|
|
269
|
+
for (const nodeType of CONTAINER_NODES) if (editor.isActive(nodeType)) return findNodeClientRect(editor, nodeType) ?? (0, _tiptap_react.posToDOMRect)(editor.view, from, to);
|
|
270
|
+
if ((0, _tiptap_react.isNodeSelection)(selection)) {
|
|
271
|
+
const node = editor.view.nodeDOM(from);
|
|
272
|
+
if (node instanceof HTMLElement) return node.getBoundingClientRect();
|
|
273
|
+
}
|
|
274
|
+
return (0, _tiptap_react.posToDOMRect)(editor.view, from, to);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Returns true if the current selection is non-empty, non-collapsed,
|
|
278
|
+
* and not on a disallowed node type.
|
|
279
|
+
*/
|
|
280
|
+
function isValidSelection(editor, notAllowedNodes = []) {
|
|
281
|
+
const { doc, selection } = editor.state;
|
|
282
|
+
const { empty, from, to } = selection;
|
|
283
|
+
const isEmptyTextBlock = !doc.textBetween(from, to).length && (0, _tiptap_react.isTextSelection)(selection);
|
|
284
|
+
const isNotAllowedNode = (0, _tiptap_react.isNodeSelection)(selection) && notAllowedNodes.includes(selection.node.type.name);
|
|
285
|
+
return !isEmptyTextBlock && !empty && !isNotAllowedNode;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Sets cursor position at mouse coordinates to prevent flicker
|
|
289
|
+
* when clicking outside the floating bubble menu. Only moves the
|
|
290
|
+
* cursor if the target position is inside an inline-content parent
|
|
291
|
+
* (skips block nodes like images and lists).
|
|
292
|
+
*/
|
|
293
|
+
function moveCursorToCoords(editor, coords) {
|
|
294
|
+
const { state, view } = editor;
|
|
295
|
+
const position = view.posAtCoords(coords);
|
|
296
|
+
if (!position || position.pos <= 0) return;
|
|
297
|
+
const $pos = state.doc.resolve(position.pos);
|
|
298
|
+
if (!$pos.parent.inlineContent) return;
|
|
299
|
+
view.dispatch(state.tr.setSelection(_tiptap_pm_state.Selection.near($pos)));
|
|
300
|
+
}
|
|
301
|
+
//#endregion
|
|
302
|
+
//#region src/components/interface/floating-element.tsx
|
|
303
|
+
const FLOATING_ELEMENT_PADDING = 8;
|
|
304
|
+
const FLOATING_ELEMENT_HEIGHT = 28;
|
|
305
|
+
const NOT_ALLOWED_NODES = [
|
|
306
|
+
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
307
|
+
_maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE,
|
|
308
|
+
_maily_to_shared.MAILY_NODE_TYPES.SPACER,
|
|
309
|
+
_maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE
|
|
310
|
+
];
|
|
311
|
+
const FloatingElement = (0, react.forwardRef)((props, ref) => {
|
|
312
|
+
const { children, editor: defaultEditor, floatingId, onOpenChange, open: defaultOpen, placement = "top" } = props;
|
|
313
|
+
const editor = useEditorInstance(defaultEditor);
|
|
314
|
+
const isDragContextOpen = useFloatingStore((state) => {
|
|
315
|
+
return state.isDragContextOpen;
|
|
316
|
+
});
|
|
317
|
+
const preventShowRef = (0, react.useRef)(false);
|
|
318
|
+
const [isOpen, setIsOpen] = (0, react.useState)(defaultOpen ?? false);
|
|
319
|
+
const openRef = useValueAsRef(isOpen);
|
|
320
|
+
const elementRef = (0, react.useRef)(null);
|
|
321
|
+
const handleOpenChange = (0, react.useCallback)((open, _event, reason) => {
|
|
322
|
+
if (!open && reason === "escape-key" && elementRef.current?.contains(document.activeElement)) editor.commands.focus();
|
|
323
|
+
setIsOpen(open);
|
|
324
|
+
onOpenChange?.(open);
|
|
325
|
+
openRef.current = open;
|
|
326
|
+
}, [
|
|
327
|
+
editor,
|
|
328
|
+
onOpenChange,
|
|
329
|
+
openRef
|
|
330
|
+
]);
|
|
331
|
+
const handleOutsidePress = (0, react.useCallback)((event) => {
|
|
332
|
+
const target = event.target;
|
|
333
|
+
const editorWrapper = editor.view.dom.parentElement;
|
|
334
|
+
if (!(0, _floating_ui_utils_dom.isHTMLElement)(target) || !editorWrapper) return false;
|
|
335
|
+
if (target.closest(`[data-mly-floating-element]`)) return false;
|
|
336
|
+
return !editorWrapper.contains(target);
|
|
337
|
+
}, [editor]);
|
|
338
|
+
const bubbleMenuOffset = (state) => {
|
|
339
|
+
const { contexts } = useFloatingStore.getState();
|
|
340
|
+
const index = [...contexts.filter((context) => context.id !== floatingId && context.value.open && context.value.placement === state.placement).map((context) => context.id), floatingId].sort((a, b) => FLOATING_ELEMENT_ORDER.indexOf(a) - FLOATING_ELEMENT_ORDER.indexOf(b)).indexOf(floatingId);
|
|
341
|
+
if (index === 0) return 8;
|
|
342
|
+
return index * 36 + 8;
|
|
343
|
+
};
|
|
344
|
+
const { context, floatingStyles, placement: floatingPlacement, refs } = (0, _floating_ui_react.useFloating)({
|
|
345
|
+
nodeId: floatingId,
|
|
346
|
+
open: isOpen,
|
|
347
|
+
onOpenChange: handleOpenChange,
|
|
348
|
+
whileElementsMounted: _floating_ui_react.autoUpdate,
|
|
349
|
+
placement,
|
|
350
|
+
middleware: [
|
|
351
|
+
(0, _floating_ui_react.shift)({ padding: 8 }),
|
|
352
|
+
(0, _floating_ui_react.offset)(bubbleMenuOffset),
|
|
353
|
+
(0, _floating_ui_react.flip)()
|
|
354
|
+
]
|
|
355
|
+
});
|
|
356
|
+
useRegisterFloatingContext(floatingId, context);
|
|
357
|
+
const dismiss = (0, _floating_ui_react.useDismiss)(context, {
|
|
358
|
+
enabled: true,
|
|
359
|
+
escapeKey: true,
|
|
360
|
+
outsidePress: handleOutsidePress
|
|
361
|
+
});
|
|
362
|
+
const { getReferenceProps } = (0, _floating_ui_react.useInteractions)([dismiss]);
|
|
363
|
+
const handleSelectionChange = (0, react.useCallback)(() => {
|
|
364
|
+
const preventShow = preventShowRef.current;
|
|
365
|
+
const rect = getCurrentSelectionRect(editor);
|
|
366
|
+
if (rect && defaultOpen !== void 0 && !preventShow) {
|
|
367
|
+
setIsOpen(defaultOpen);
|
|
368
|
+
refs.setReference({ getBoundingClientRect: () => rect });
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
if (!isValidSelection(editor, NOT_ALLOWED_NODES) || preventShow || !editor.isEditable) {
|
|
372
|
+
setIsOpen(false);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
setIsOpen(true);
|
|
376
|
+
refs.setReference({ getBoundingClientRect: () => rect });
|
|
377
|
+
}, [
|
|
378
|
+
defaultOpen,
|
|
379
|
+
editor,
|
|
380
|
+
refs
|
|
381
|
+
]);
|
|
382
|
+
useOnSelectionUpdate(editor, handleSelectionChange);
|
|
383
|
+
(0, react.useEffect)(() => {
|
|
384
|
+
const editorView = editor.view;
|
|
385
|
+
const handleMouseDown = (event) => {
|
|
386
|
+
if (event.button !== 0) return;
|
|
387
|
+
preventShowRef.current = true;
|
|
388
|
+
if (event.detail <= 1) moveCursorToCoords(editor, {
|
|
389
|
+
left: event.clientX,
|
|
390
|
+
top: event.clientY
|
|
391
|
+
});
|
|
392
|
+
};
|
|
393
|
+
const handleMouseUp = () => {
|
|
394
|
+
if (!preventShowRef.current) return;
|
|
395
|
+
preventShowRef.current = false;
|
|
396
|
+
handleSelectionChange();
|
|
397
|
+
};
|
|
398
|
+
editorView.dom.addEventListener("mousedown", handleMouseDown);
|
|
399
|
+
editorView.root.addEventListener("mouseup", handleMouseUp);
|
|
400
|
+
return () => {
|
|
401
|
+
editorView.dom.removeEventListener("mousedown", handleMouseDown);
|
|
402
|
+
editorView.root.removeEventListener("mouseup", handleMouseUp);
|
|
403
|
+
};
|
|
404
|
+
}, [editor, handleSelectionChange]);
|
|
405
|
+
(0, react.useEffect)(() => {
|
|
406
|
+
const handleResize = () => {
|
|
407
|
+
if (!openRef.current) return;
|
|
408
|
+
handleSelectionChange();
|
|
409
|
+
};
|
|
410
|
+
window.addEventListener("resize", handleResize);
|
|
411
|
+
window.addEventListener("scroll", handleResize);
|
|
412
|
+
return () => {
|
|
413
|
+
window.removeEventListener("resize", handleResize);
|
|
414
|
+
window.removeEventListener("scroll", handleResize);
|
|
415
|
+
};
|
|
416
|
+
}, [handleSelectionChange, openRef]);
|
|
417
|
+
(0, react.useEffect)(() => {
|
|
418
|
+
const editorViewDom = editor.view.dom;
|
|
419
|
+
const handleDrag = () => {
|
|
420
|
+
handleOpenChange(false);
|
|
421
|
+
};
|
|
422
|
+
editorViewDom.addEventListener("dragstart", handleDrag);
|
|
423
|
+
editorViewDom.addEventListener("dragover", handleDrag);
|
|
424
|
+
return () => {
|
|
425
|
+
editorViewDom.removeEventListener("dragstart", handleDrag);
|
|
426
|
+
editorViewDom.removeEventListener("dragover", handleDrag);
|
|
427
|
+
};
|
|
428
|
+
}, [editor, handleOpenChange]);
|
|
429
|
+
const finalRef = (0, _floating_ui_react.useMergeRefs)([
|
|
430
|
+
refs.setFloating,
|
|
431
|
+
elementRef,
|
|
432
|
+
ref
|
|
433
|
+
]);
|
|
434
|
+
const zIndex = (0, react.useMemo)(() => 99 - FLOATING_ELEMENT_ORDER.toReversed().indexOf(floatingId) * (floatingPlacement === "top" ? 1 : -1), [floatingId, floatingPlacement]);
|
|
435
|
+
if (!isOpen || isDragContextOpen) return null;
|
|
436
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
437
|
+
...getReferenceProps(),
|
|
438
|
+
[FLOATING_ELEMENT_ATTRIBUTE]: floatingId,
|
|
439
|
+
ref: finalRef,
|
|
440
|
+
style: {
|
|
441
|
+
...floatingStyles,
|
|
442
|
+
zIndex
|
|
443
|
+
},
|
|
444
|
+
children
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
FloatingElement.displayName = "FloatingElement";
|
|
448
|
+
//#endregion
|
|
449
|
+
//#region src/components/interface/tooltip.tsx
|
|
450
|
+
const Tooltip = _base_ui_react_tooltip.Tooltip.Root;
|
|
451
|
+
const TooltipProvider = _base_ui_react_tooltip.Tooltip.Provider;
|
|
452
|
+
const TooltipTrigger = _base_ui_react_tooltip.Tooltip.Trigger;
|
|
453
|
+
function TooltipPositioner(props) {
|
|
454
|
+
const { container, sideOffset = 8, ...rest } = props;
|
|
455
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Portal, {
|
|
456
|
+
container,
|
|
457
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Positioner, {
|
|
458
|
+
sideOffset,
|
|
459
|
+
...rest
|
|
460
|
+
})
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
function TooltipPopup(props) {
|
|
464
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Popup, {
|
|
465
|
+
"data-mly-tooltip": "",
|
|
466
|
+
...props
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function TooltipArrow(props) {
|
|
470
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_base_ui_react_tooltip.Tooltip.Arrow, {
|
|
471
|
+
"data-mly-tooltip-arrow": "",
|
|
472
|
+
...props,
|
|
473
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArrowIcon, {})
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/utils/theme.ts
|
|
478
|
+
const HEADING_LEVEL_PATTERN = /^h[1-6]$/;
|
|
479
|
+
function getThemeSelector(type) {
|
|
480
|
+
const nodeType = HEADING_LEVEL_PATTERN.test(type) ? _maily_to_shared.MAILY_NODE_TYPES.HEADING : type;
|
|
481
|
+
return `${nodeType === type ? "" : type}[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${nodeType}"]`;
|
|
482
|
+
}
|
|
483
|
+
function getNodeTheme(editor) {
|
|
484
|
+
return editor.state.doc.attrs.theme ?? {};
|
|
485
|
+
}
|
|
486
|
+
function getMergedNodeTheme(options) {
|
|
487
|
+
const { theme, update } = options;
|
|
488
|
+
const merged = (0, _maily_to_shared.deepMerge)(theme, update);
|
|
489
|
+
const next = {};
|
|
490
|
+
for (const [type, declarations] of Object.entries(merged)) {
|
|
491
|
+
if (!declarations) continue;
|
|
492
|
+
const kept = {};
|
|
493
|
+
for (const [property, value] of Object.entries(declarations)) {
|
|
494
|
+
if (value === null || value === void 0 || value === "") continue;
|
|
495
|
+
kept[property] = value;
|
|
496
|
+
}
|
|
497
|
+
if (Object.keys(kept).length > 0) next[type] = kept;
|
|
498
|
+
}
|
|
499
|
+
return next;
|
|
500
|
+
}
|
|
501
|
+
function getNodeStyleState(options) {
|
|
502
|
+
const { editor, type } = options;
|
|
503
|
+
const attrs = editor.getAttributes(type);
|
|
504
|
+
const authored = (0, _maily_to_shared.parseInlineStyles)(attrs.style ?? "");
|
|
505
|
+
const theme = (0, _maily_to_shared.getThemeDeclarations)({
|
|
506
|
+
attrs,
|
|
507
|
+
theme: getNodeTheme(editor),
|
|
508
|
+
type
|
|
509
|
+
}) ?? {};
|
|
510
|
+
return {
|
|
511
|
+
authored,
|
|
512
|
+
resolved: (0, _maily_to_shared.mergeInlineStyles)(theme, authored)
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function getTypeSelector(type) {
|
|
516
|
+
return `[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${type}"]`;
|
|
517
|
+
}
|
|
518
|
+
function getSuppressionRules(options) {
|
|
519
|
+
const { declarations, scope, selector } = options;
|
|
520
|
+
const outside = _maily_to_shared.BLOCK_CONTAINER_TYPES.map(getTypeSelector).join(",");
|
|
521
|
+
const rules = [];
|
|
522
|
+
if (declarations.marginTop && declarations.marginTop !== "0") {
|
|
523
|
+
const absorbers = _maily_to_shared.MARGIN_TOP_ABSORBER_TYPES.map((type) => {
|
|
524
|
+
return `${scope} ${getTypeSelector(type)}+${selector}`;
|
|
525
|
+
});
|
|
526
|
+
rules.push(`${[`${scope} ${selector}:first-child`, ...absorbers].join(",")}{margin-top:0}`);
|
|
527
|
+
}
|
|
528
|
+
if (declarations.marginBottom && declarations.marginBottom !== "0") {
|
|
529
|
+
const absorbers = _maily_to_shared.MARGIN_BOTTOM_ABSORBER_TYPES.map((type) => {
|
|
530
|
+
return `${scope} ${selector}:has(+${getTypeSelector(type)})`;
|
|
531
|
+
});
|
|
532
|
+
rules.push(`${[`${scope} ${selector}:last-child`, ...absorbers].join(",")}{margin-bottom:0}`);
|
|
533
|
+
}
|
|
534
|
+
if (rules.length > 0) rules.push(`${scope} :not(${outside})>${selector}{margin-top:0;margin-bottom:0}`);
|
|
535
|
+
return rules;
|
|
536
|
+
}
|
|
537
|
+
function getThemeCss(options) {
|
|
538
|
+
const { scope, theme } = options;
|
|
539
|
+
const rules = [];
|
|
540
|
+
for (const [type, declarations] of Object.entries(theme)) {
|
|
541
|
+
const selector = getThemeSelector(type);
|
|
542
|
+
const style = (0, _maily_to_shared.stringifyInlineStyles)(declarations);
|
|
543
|
+
if (style) {
|
|
544
|
+
rules.push(`${scope} ${selector}{${style}}`);
|
|
545
|
+
rules.push(...getSuppressionRules({
|
|
546
|
+
declarations,
|
|
547
|
+
scope,
|
|
548
|
+
selector
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return rules.join("");
|
|
553
|
+
}
|
|
554
|
+
function getChildEntries(options) {
|
|
555
|
+
const { offset, parent, type } = options;
|
|
556
|
+
const entries = [];
|
|
557
|
+
let position = offset;
|
|
558
|
+
parent.forEach((child) => {
|
|
559
|
+
if (child.type.name === type) entries.push({
|
|
560
|
+
node: child,
|
|
561
|
+
position
|
|
562
|
+
});
|
|
563
|
+
position += child.nodeSize;
|
|
564
|
+
});
|
|
565
|
+
return entries;
|
|
566
|
+
}
|
|
567
|
+
function getShellNodes(options) {
|
|
568
|
+
const { doc, type } = options;
|
|
569
|
+
const bodies = getChildEntries({
|
|
570
|
+
offset: 0,
|
|
571
|
+
parent: doc,
|
|
572
|
+
type: _maily_to_shared.MAILY_NODE_TYPES.BODY
|
|
573
|
+
});
|
|
574
|
+
if (type === _maily_to_shared.MAILY_NODE_TYPES.BODY) return bodies;
|
|
575
|
+
return bodies.flatMap((body) => {
|
|
576
|
+
return getChildEntries({
|
|
577
|
+
offset: body.position + 1,
|
|
578
|
+
parent: body.node,
|
|
579
|
+
type
|
|
580
|
+
});
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
//#endregion
|
|
584
|
+
//#region src/extensions/document/document.ts
|
|
585
|
+
const DOCUMENT_VERSION = 2;
|
|
586
|
+
const Document = _tiptap_extension_document.Document.extend({
|
|
587
|
+
content: _maily_to_shared.MAILY_NODE_TYPES.BODY,
|
|
588
|
+
addAttributes() {
|
|
589
|
+
return {
|
|
590
|
+
...this.parent?.(),
|
|
591
|
+
version: { default: DOCUMENT_VERSION }
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
});
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region ../extension-variable/dist/index.mjs
|
|
597
|
+
function getMarksAt(options) {
|
|
598
|
+
const { pos, state } = options;
|
|
599
|
+
return (state.storedMarks ?? state.doc.resolve(pos).marks()).map((mark) => {
|
|
600
|
+
return {
|
|
601
|
+
attrs: mark.attrs,
|
|
602
|
+
type: mark.type.name
|
|
603
|
+
};
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Returns the suggestion options for a trigger of the Variable extension. These
|
|
608
|
+
* options are used to create a `Suggestion` ProseMirror plugin. Each plugin lets
|
|
609
|
+
* you define a different trigger that opens the variable menu. For example,
|
|
610
|
+
* you can define a `{{` trigger to insert variables and a `#` trigger to insert
|
|
611
|
+
* tags.
|
|
612
|
+
*/
|
|
613
|
+
function getSuggestionOptions(options) {
|
|
614
|
+
const { addSpaceSuffix = true, char = _maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER, editor: tiptapEditor, extensionName, overrideSuggestionOptions, shouldScrollIntoView = false } = options;
|
|
615
|
+
return {
|
|
616
|
+
editor: tiptapEditor,
|
|
617
|
+
char,
|
|
618
|
+
pluginKey: new _tiptap_pm_state.PluginKey(`variable-${char}`),
|
|
619
|
+
command: ({ editor, props, range }) => {
|
|
620
|
+
if (editor.view.state.selection.$to.nodeAfter?.text?.startsWith(" ")) range.to += 1;
|
|
621
|
+
const marks = getMarksAt({
|
|
622
|
+
pos: range.from,
|
|
623
|
+
state: editor.view.state
|
|
624
|
+
});
|
|
625
|
+
let chain = editor.chain().focus().insertContentAt(range, [{
|
|
626
|
+
type: extensionName,
|
|
627
|
+
attrs: {
|
|
628
|
+
...props,
|
|
629
|
+
variableSuggestionChar: char
|
|
630
|
+
},
|
|
631
|
+
marks
|
|
632
|
+
}, ...addSpaceSuffix ? [{
|
|
633
|
+
type: "text",
|
|
634
|
+
text: " ",
|
|
635
|
+
marks
|
|
636
|
+
}] : []]);
|
|
637
|
+
if (shouldScrollIntoView) chain = chain.scrollIntoView();
|
|
638
|
+
chain.run();
|
|
639
|
+
editor.view.dom.ownerDocument.defaultView?.getSelection()?.collapseToEnd();
|
|
640
|
+
},
|
|
641
|
+
allow: ({ range, state }) => {
|
|
642
|
+
return !!state.doc.resolve(range.from).parent.type.contentMatch.matchType(state.schema.nodes[extensionName]);
|
|
643
|
+
},
|
|
644
|
+
...overrideSuggestionOptions
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
function getSuggestions(options) {
|
|
648
|
+
return (options.options.suggestions.length ? options.options.suggestions : [options.options.suggestion]).map((suggestion) => getSuggestionOptions({
|
|
649
|
+
addSpaceSuffix: options.options.addSpaceSuffix,
|
|
650
|
+
char: suggestion.char,
|
|
651
|
+
editor: options.editor,
|
|
652
|
+
extensionName: options.name,
|
|
653
|
+
overrideSuggestionOptions: suggestion,
|
|
654
|
+
shouldScrollIntoView: options.options.shouldScrollIntoView
|
|
655
|
+
}));
|
|
656
|
+
}
|
|
657
|
+
function getSuggestionFromChar(options, char) {
|
|
658
|
+
const suggestions = getSuggestions(options);
|
|
659
|
+
return suggestions.find((item) => item.char === char) ?? suggestions[0] ?? null;
|
|
660
|
+
}
|
|
661
|
+
function getVariableLabel$1(node, suggestion) {
|
|
662
|
+
return `${suggestion?.char ?? _maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER}${node.attrs.label ?? node.attrs.id}`;
|
|
663
|
+
}
|
|
664
|
+
const Variable = _tiptap_core.Node.create({
|
|
665
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.VARIABLE,
|
|
666
|
+
priority: 101,
|
|
667
|
+
group: "inline",
|
|
668
|
+
inline: true,
|
|
669
|
+
selectable: true,
|
|
670
|
+
atom: true,
|
|
671
|
+
addOptions() {
|
|
672
|
+
return {
|
|
673
|
+
addSpaceSuffix: true,
|
|
674
|
+
deleteTriggerWithBackspace: false,
|
|
675
|
+
HTMLAttributes: {},
|
|
676
|
+
renderHTML({ node, options, suggestion }) {
|
|
677
|
+
return [
|
|
678
|
+
"span",
|
|
679
|
+
(0, _tiptap_core.mergeAttributes)(options.HTMLAttributes),
|
|
680
|
+
getVariableLabel$1(node, suggestion)
|
|
681
|
+
];
|
|
682
|
+
},
|
|
683
|
+
renderText({ node, suggestion }) {
|
|
684
|
+
return getVariableLabel$1(node, suggestion);
|
|
685
|
+
},
|
|
686
|
+
shouldScrollIntoView: false,
|
|
687
|
+
suggestion: {},
|
|
688
|
+
suggestions: []
|
|
689
|
+
};
|
|
690
|
+
},
|
|
691
|
+
addAttributes() {
|
|
692
|
+
return {
|
|
693
|
+
id: {
|
|
694
|
+
parseHTML: (element) => element.getAttribute("data-id"),
|
|
695
|
+
renderHTML: (attributes) => attributes.id ? { "data-id": attributes.id } : {}
|
|
696
|
+
},
|
|
697
|
+
label: {
|
|
698
|
+
default: _maily_to_shared.DEFAULT_VARIABLE_ATTRIBUTES.label,
|
|
699
|
+
parseHTML: (element) => element.getAttribute("data-label"),
|
|
700
|
+
renderHTML: (attributes) => attributes.label ? { "data-label": attributes.label } : {}
|
|
701
|
+
},
|
|
702
|
+
variableSuggestionChar: {
|
|
703
|
+
default: _maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER,
|
|
704
|
+
parseHTML: (element) => element.getAttribute("data-variable-suggestion-char") ?? _maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER,
|
|
705
|
+
renderHTML: (attributes) => ({ "data-variable-suggestion-char": attributes.variableSuggestionChar })
|
|
706
|
+
},
|
|
707
|
+
fallback: {
|
|
708
|
+
default: _maily_to_shared.DEFAULT_VARIABLE_ATTRIBUTES.fallback,
|
|
709
|
+
parseHTML: (element) => element.getAttribute("data-fallback"),
|
|
710
|
+
renderHTML: (attributes) => attributes.fallback ? { "data-fallback": attributes.fallback } : {}
|
|
711
|
+
},
|
|
712
|
+
required: {
|
|
713
|
+
default: _maily_to_shared.DEFAULT_VARIABLE_ATTRIBUTES.required,
|
|
714
|
+
parseHTML: (element) => element.getAttribute("data-required") !== "false",
|
|
715
|
+
renderHTML: (attributes) => ({ "data-required": String(attributes.required) })
|
|
716
|
+
},
|
|
717
|
+
isDefaultEditable: {
|
|
718
|
+
default: _maily_to_shared.DEFAULT_VARIABLE_ATTRIBUTES.isDefaultEditable,
|
|
719
|
+
parseHTML: (element) => element.getAttribute("data-is-default-editable") !== "false" && element.getAttribute("data-hide-default-value") !== "true",
|
|
720
|
+
renderHTML: (attributes) => ({ "data-is-default-editable": String(attributes.isDefaultEditable) })
|
|
721
|
+
}
|
|
722
|
+
};
|
|
723
|
+
},
|
|
724
|
+
addCommands() {
|
|
725
|
+
return { insertVariable: (attrs) => ({ commands, state }) => commands.insertContent({
|
|
726
|
+
type: this.name,
|
|
727
|
+
attrs,
|
|
728
|
+
marks: getMarksAt({
|
|
729
|
+
pos: state.selection.from,
|
|
730
|
+
state
|
|
731
|
+
})
|
|
732
|
+
}) };
|
|
733
|
+
},
|
|
734
|
+
parseHTML() {
|
|
735
|
+
return [{ tag: `span[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
|
|
736
|
+
},
|
|
737
|
+
renderHTML({ HTMLAttributes, node }) {
|
|
738
|
+
const options = {
|
|
739
|
+
...this.options,
|
|
740
|
+
HTMLAttributes: (0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes)
|
|
741
|
+
};
|
|
742
|
+
return this.options.renderHTML({
|
|
743
|
+
node,
|
|
744
|
+
options,
|
|
745
|
+
suggestion: getSuggestionFromChar(this, node.attrs.variableSuggestionChar)
|
|
746
|
+
});
|
|
747
|
+
},
|
|
748
|
+
renderText({ node }) {
|
|
749
|
+
return this.options.renderText({
|
|
750
|
+
node,
|
|
751
|
+
options: this.options,
|
|
752
|
+
suggestion: getSuggestionFromChar(this, node.attrs.variableSuggestionChar)
|
|
753
|
+
});
|
|
754
|
+
},
|
|
755
|
+
addKeyboardShortcuts() {
|
|
756
|
+
return { Backspace: () => this.editor.commands.command(({ state, tr }) => {
|
|
757
|
+
const { anchor, empty } = state.selection;
|
|
758
|
+
if (!empty) return false;
|
|
759
|
+
let matched = null;
|
|
760
|
+
let matchedPos = 0;
|
|
761
|
+
state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
|
|
762
|
+
if (node.type.name === this.name) {
|
|
763
|
+
matched = node;
|
|
764
|
+
matchedPos = pos;
|
|
765
|
+
return false;
|
|
766
|
+
}
|
|
767
|
+
return true;
|
|
768
|
+
});
|
|
769
|
+
if (!matched) return false;
|
|
770
|
+
const variableNode = matched;
|
|
771
|
+
tr.insertText(this.options.deleteTriggerWithBackspace ? "" : variableNode.attrs.variableSuggestionChar, matchedPos, matchedPos + variableNode.nodeSize);
|
|
772
|
+
return true;
|
|
773
|
+
}) };
|
|
774
|
+
},
|
|
775
|
+
addProseMirrorPlugins() {
|
|
776
|
+
return getSuggestions(this).map(_tiptap_suggestion.Suggestion);
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
//#endregion
|
|
780
|
+
//#region src/utils/variable.ts
|
|
781
|
+
const VARIABLE_SUGGESTION_POPOVER_ID = "mly-variable-suggestion-popover";
|
|
782
|
+
function getVariableLabel(item) {
|
|
783
|
+
return item.label ?? item.id ?? "";
|
|
784
|
+
}
|
|
785
|
+
/**
|
|
786
|
+
* Filters the variable list by query prefix. If no exact match exists,
|
|
787
|
+
* appends a dynamic entry so users can create variables on the fly.
|
|
788
|
+
*/
|
|
789
|
+
function filterVariableSuggestions(variables = [], opts) {
|
|
790
|
+
if (typeof variables === "function") return variables(opts);
|
|
791
|
+
const query = opts.query.toLowerCase();
|
|
792
|
+
const filtered = variables.filter((item) => getVariableLabel(item).toLowerCase().startsWith(query));
|
|
793
|
+
if (!variables.some((item) => getVariableLabel(item).toLowerCase() === query) && query.length > 0) filtered.push({
|
|
794
|
+
id: opts.query,
|
|
795
|
+
label: opts.query,
|
|
796
|
+
required: true,
|
|
797
|
+
isDefaultEditable: true
|
|
798
|
+
});
|
|
799
|
+
return filtered;
|
|
800
|
+
}
|
|
801
|
+
//#endregion
|
|
802
|
+
//#region src/components/interface/suggestion.tsx
|
|
803
|
+
function SuggestionWrapper(props) {
|
|
804
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
805
|
+
...props,
|
|
806
|
+
"data-mly-suggestion": ""
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
function SuggestionHeader(props) {
|
|
810
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
811
|
+
...props,
|
|
812
|
+
"data-mly-suggestion-header": ""
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
function SuggestionKeyIcon(props) {
|
|
816
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
817
|
+
"data-mly-suggestion-key": "",
|
|
818
|
+
children: props.children
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
function SuggestionFooter() {
|
|
822
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
823
|
+
"data-mly-suggestion-footer": "",
|
|
824
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
825
|
+
"data-mly-suggestion-hint": "",
|
|
826
|
+
children: [
|
|
827
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SuggestionKeyIcon, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowDownIcon, { size: 12 }) }),
|
|
828
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SuggestionKeyIcon, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowUpIcon, { size: 12 }) }),
|
|
829
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Navigate" })
|
|
830
|
+
]
|
|
831
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SuggestionKeyIcon, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.CornerDownLeftIcon, { size: 12 }) })]
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
//#endregion
|
|
835
|
+
//#region src/hooks/use-scroll-into-view.ts
|
|
836
|
+
function useScrollIntoView(deps = []) {
|
|
837
|
+
const containerRef = (0, react.useRef)(null);
|
|
838
|
+
const activeRef = (0, react.useRef)(null);
|
|
839
|
+
(0, react.useLayoutEffect)(() => {
|
|
840
|
+
const container = containerRef.current;
|
|
841
|
+
const activeElement = activeRef.current;
|
|
842
|
+
if (!container || !activeElement) return;
|
|
843
|
+
const { offsetHeight, offsetTop } = activeElement;
|
|
844
|
+
container.scrollTop = offsetTop - container.getBoundingClientRect().height / 2 + offsetHeight / 2;
|
|
845
|
+
}, deps);
|
|
846
|
+
return {
|
|
847
|
+
activeRef,
|
|
848
|
+
containerRef
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
//#endregion
|
|
852
|
+
//#region src/utils/composite.ts
|
|
853
|
+
const ARROW_UP = "ArrowUp";
|
|
854
|
+
const ARROW_DOWN = "ArrowDown";
|
|
855
|
+
const HOME = "Home";
|
|
856
|
+
const ENTER = "Enter";
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/extensions/variable/variable-suggestions-popover.tsx
|
|
859
|
+
const NAVIGATION_KEYS$1 = /* @__PURE__ */ new Set([
|
|
860
|
+
ARROW_UP,
|
|
861
|
+
ARROW_DOWN,
|
|
862
|
+
ENTER,
|
|
863
|
+
HOME,
|
|
864
|
+
"End"
|
|
865
|
+
]);
|
|
866
|
+
const VariableSuggestionsPopover = (0, react.forwardRef)((props, ref) => {
|
|
867
|
+
const { items, onSelectItem } = props;
|
|
868
|
+
const [selectedIndex, setSelectedIndex] = (0, react.useState)(0);
|
|
869
|
+
const [prevItems, setPrevItems] = (0, react.useState)(items);
|
|
870
|
+
const { activeRef: activeItemRef, containerRef: scrollContainerRef } = useScrollIntoView([selectedIndex]);
|
|
871
|
+
if (prevItems !== items) {
|
|
872
|
+
setPrevItems(items);
|
|
873
|
+
setSelectedIndex(0);
|
|
874
|
+
if (scrollContainerRef.current) scrollContainerRef.current.scrollTop = 0;
|
|
875
|
+
}
|
|
876
|
+
(0, react.useImperativeHandle)(ref, () => ({ onKeyDown: (event) => {
|
|
877
|
+
if (!NAVIGATION_KEYS$1.has(event.key) || !items.length) return false;
|
|
878
|
+
let newIndex = selectedIndex;
|
|
879
|
+
let shouldSelect = false;
|
|
880
|
+
switch (event.key) {
|
|
881
|
+
case HOME:
|
|
882
|
+
newIndex = 0;
|
|
883
|
+
break;
|
|
884
|
+
case "End":
|
|
885
|
+
newIndex = items.length - 1;
|
|
886
|
+
break;
|
|
887
|
+
case ARROW_UP:
|
|
888
|
+
newIndex = (selectedIndex + items.length - 1) % items.length;
|
|
889
|
+
break;
|
|
890
|
+
case ARROW_DOWN:
|
|
891
|
+
newIndex = (selectedIndex + 1) % items.length;
|
|
892
|
+
break;
|
|
893
|
+
case ENTER:
|
|
894
|
+
shouldSelect = true;
|
|
895
|
+
break;
|
|
896
|
+
default: return false;
|
|
897
|
+
}
|
|
898
|
+
event.preventDefault();
|
|
899
|
+
if (shouldSelect) {
|
|
900
|
+
const item = items[selectedIndex];
|
|
901
|
+
if (item) onSelectItem(item);
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
if (newIndex !== selectedIndex) setSelectedIndex(newIndex);
|
|
905
|
+
return true;
|
|
906
|
+
} }));
|
|
907
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(SuggestionWrapper, { children: [
|
|
908
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(SuggestionHeader, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: "Variables" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SuggestionKeyIcon, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.BracesIcon, { size: 12 }) })] }),
|
|
909
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
910
|
+
"data-mly-suggestion-body": "",
|
|
911
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
912
|
+
"data-axis": "y",
|
|
913
|
+
"data-mly-scroll-fade": "",
|
|
914
|
+
"data-mly-suggestion-scroll": "",
|
|
915
|
+
ref: scrollContainerRef,
|
|
916
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
917
|
+
"data-mly-suggestion-items": "",
|
|
918
|
+
children: [items.map((item, index) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
|
|
919
|
+
"data-mly-suggestion-item": "",
|
|
920
|
+
"data-selected": index === selectedIndex ? "" : void 0,
|
|
921
|
+
onClick: () => onSelectItem(item),
|
|
922
|
+
ref: index === selectedIndex ? activeItemRef : null,
|
|
923
|
+
type: "button",
|
|
924
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.BracesIcon, {
|
|
925
|
+
"data-mly-suggestion-item-icon": "",
|
|
926
|
+
size: 12
|
|
927
|
+
}), item.label || item.id]
|
|
928
|
+
}, item.id ?? index)), items.length === 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
929
|
+
"data-mly-suggestion-empty": "",
|
|
930
|
+
children: "No result"
|
|
931
|
+
}) : null]
|
|
932
|
+
})
|
|
933
|
+
})
|
|
934
|
+
}),
|
|
935
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SuggestionFooter, {})
|
|
936
|
+
] });
|
|
937
|
+
});
|
|
938
|
+
VariableSuggestionsPopover.displayName = "VariableSuggestionsPopover";
|
|
939
|
+
//#endregion
|
|
940
|
+
//#region src/extensions/variable/variable-suggestion-list.tsx
|
|
941
|
+
const VariableSuggestionList = (0, react.forwardRef)((props, ref) => {
|
|
942
|
+
const { command: selectItem, items } = props;
|
|
943
|
+
const popoverRef = (0, react.useRef)(null);
|
|
944
|
+
(0, react.useImperativeHandle)(ref, () => ({ onKeyDown: ({ event }) => popoverRef.current?.onKeyDown(event) ?? false }));
|
|
945
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(VariableSuggestionsPopover, {
|
|
946
|
+
items,
|
|
947
|
+
onSelectItem: (value) => {
|
|
948
|
+
selectItem({
|
|
949
|
+
id: value.id,
|
|
950
|
+
isDefaultEditable: value.isDefaultEditable ?? value.hideDefaultValue !== true,
|
|
951
|
+
label: value.label,
|
|
952
|
+
required: value.required ?? true
|
|
953
|
+
});
|
|
954
|
+
},
|
|
955
|
+
ref: popoverRef
|
|
956
|
+
});
|
|
957
|
+
});
|
|
958
|
+
VariableSuggestionList.displayName = "VariableSuggestionList";
|
|
959
|
+
//#endregion
|
|
960
|
+
//#region src/extensions/variable/variable-suggestion.ts
|
|
961
|
+
async function updatePosition$1(editor, element, range) {
|
|
962
|
+
const position = await (0, _floating_ui_react.computePosition)({ getBoundingClientRect: () => (0, _tiptap_react.posToDOMRect)(editor.view, range.from, range.to) }, element, {
|
|
963
|
+
placement: "bottom-start",
|
|
964
|
+
strategy: "absolute",
|
|
965
|
+
middleware: [
|
|
966
|
+
(0, _floating_ui_react.shift)(),
|
|
967
|
+
(0, _floating_ui_react.flip)(),
|
|
968
|
+
(0, _floating_ui_react.offset)(8)
|
|
969
|
+
]
|
|
970
|
+
});
|
|
971
|
+
element.style.width = "max-content";
|
|
972
|
+
element.style.position = position.strategy;
|
|
973
|
+
element.style.left = `${position.x}px`;
|
|
974
|
+
element.style.top = `${position.y}px`;
|
|
975
|
+
element.style.zIndex = "9999";
|
|
976
|
+
}
|
|
977
|
+
function getVariableSuggestions(char = _maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER) {
|
|
978
|
+
return {
|
|
979
|
+
char,
|
|
980
|
+
items: ({ editor, query }) => filterVariableSuggestions(editor.storage.variable?.variables, {
|
|
981
|
+
editor,
|
|
982
|
+
query
|
|
983
|
+
}),
|
|
984
|
+
render: () => {
|
|
985
|
+
let component = null;
|
|
986
|
+
return {
|
|
987
|
+
onStart: async (props) => {
|
|
988
|
+
const { editor, range } = props;
|
|
989
|
+
const parentElement = editor.view.dom.parentElement;
|
|
990
|
+
if (!parentElement) return;
|
|
991
|
+
component = new _tiptap_react.ReactRenderer(VariableSuggestionList, {
|
|
992
|
+
editor,
|
|
993
|
+
props
|
|
994
|
+
});
|
|
995
|
+
if (!props.clientRect) return;
|
|
996
|
+
component.element.style.position = "absolute";
|
|
997
|
+
component.element.id = VARIABLE_SUGGESTION_POPOVER_ID;
|
|
998
|
+
parentElement.append(component.element);
|
|
999
|
+
await updatePosition$1(editor, component.element, range);
|
|
1000
|
+
},
|
|
1001
|
+
onUpdate: async (props) => {
|
|
1002
|
+
const { editor, range } = props;
|
|
1003
|
+
if (!component) return;
|
|
1004
|
+
component.updateProps(props);
|
|
1005
|
+
if (!props.clientRect) return;
|
|
1006
|
+
await updatePosition$1(editor, component.element, range);
|
|
1007
|
+
},
|
|
1008
|
+
onKeyDown(props) {
|
|
1009
|
+
if (!component) return false;
|
|
1010
|
+
if (props.event.key === "Escape") {
|
|
1011
|
+
component.destroy();
|
|
1012
|
+
return true;
|
|
1013
|
+
}
|
|
1014
|
+
return component.ref?.onKeyDown(props) ?? false;
|
|
1015
|
+
},
|
|
1016
|
+
onExit() {
|
|
1017
|
+
if (!component) return;
|
|
1018
|
+
component.element.remove();
|
|
1019
|
+
component.destroy();
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
};
|
|
1024
|
+
}
|
|
1025
|
+
//#endregion
|
|
1026
|
+
//#region src/extensions/variable/variable-view.tsx
|
|
1027
|
+
function VariableView(props) {
|
|
1028
|
+
const { node } = props;
|
|
1029
|
+
const { id, label } = node.attrs;
|
|
1030
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_tiptap_react.NodeViewWrapper, {
|
|
1031
|
+
as: "span",
|
|
1032
|
+
"data-mly-variable": "",
|
|
1033
|
+
children: [
|
|
1034
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1035
|
+
"data-mly-variable-trigger": "",
|
|
1036
|
+
children: [_maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER, "\xA0"]
|
|
1037
|
+
}),
|
|
1038
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1039
|
+
"data-mly-variable-label": "",
|
|
1040
|
+
children: label ?? id
|
|
1041
|
+
}),
|
|
1042
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
1043
|
+
"data-mly-variable-trigger": "",
|
|
1044
|
+
children: ["\xA0", _maily_to_shared.DEFAULT_VARIABLE_END_TRIGGER]
|
|
1045
|
+
})
|
|
1046
|
+
]
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region src/extensions/variable/variable.ts
|
|
1051
|
+
const VariableExtension = Variable.extend({
|
|
1052
|
+
addOptions() {
|
|
1053
|
+
return {
|
|
1054
|
+
...this.parent?.(),
|
|
1055
|
+
isIdEditable: true,
|
|
1056
|
+
variables: void 0
|
|
1057
|
+
};
|
|
1058
|
+
},
|
|
1059
|
+
addStorage() {
|
|
1060
|
+
return {
|
|
1061
|
+
isIdEditable: this.options.isIdEditable,
|
|
1062
|
+
variables: this.options.variables
|
|
1063
|
+
};
|
|
1064
|
+
},
|
|
1065
|
+
addNodeView() {
|
|
1066
|
+
return (0, _tiptap_react.ReactNodeViewRenderer)(VariableView, { attrs: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name } });
|
|
1067
|
+
}
|
|
1068
|
+
}).configure({ suggestion: getVariableSuggestions() });
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/utils/spacing.ts
|
|
1071
|
+
const MIN_SPACER_HEIGHT = 1;
|
|
1072
|
+
const MAX_SPACER_HEIGHT = 1e3;
|
|
1073
|
+
const SPACER_SPACING = [
|
|
1074
|
+
{
|
|
1075
|
+
displayValue: "XS",
|
|
1076
|
+
label: "Extra Small",
|
|
1077
|
+
value: 4
|
|
1078
|
+
},
|
|
1079
|
+
{
|
|
1080
|
+
displayValue: "SM",
|
|
1081
|
+
label: "Small",
|
|
1082
|
+
value: 8
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
displayValue: "MD",
|
|
1086
|
+
label: "Medium",
|
|
1087
|
+
value: 16
|
|
1088
|
+
},
|
|
1089
|
+
{
|
|
1090
|
+
displayValue: "LG",
|
|
1091
|
+
label: "Large",
|
|
1092
|
+
value: 32
|
|
1093
|
+
},
|
|
1094
|
+
{
|
|
1095
|
+
displayValue: "XL",
|
|
1096
|
+
label: "Extra Large",
|
|
1097
|
+
value: 64
|
|
1098
|
+
}
|
|
1099
|
+
];
|
|
1100
|
+
const SPACING_PRESETS = [
|
|
1101
|
+
{
|
|
1102
|
+
label: "None",
|
|
1103
|
+
value: 0
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
label: "Small",
|
|
1107
|
+
value: 8
|
|
1108
|
+
},
|
|
1109
|
+
{
|
|
1110
|
+
label: "Medium",
|
|
1111
|
+
value: 16
|
|
1112
|
+
},
|
|
1113
|
+
{
|
|
1114
|
+
label: "Large",
|
|
1115
|
+
value: 32
|
|
1116
|
+
}
|
|
1117
|
+
];
|
|
1118
|
+
//#endregion
|
|
1119
|
+
//#region src/utils/columns.ts
|
|
1120
|
+
function getClosestColumns(editor) {
|
|
1121
|
+
return (0, _tiptap_core.findParentNode)((node) => node.type.name === _maily_to_shared.MAILY_NODE_TYPES.COLUMNS)(editor.state.selection);
|
|
1122
|
+
}
|
|
1123
|
+
function getColumnWidths(editor) {
|
|
1124
|
+
const columns = getClosestColumns(editor);
|
|
1125
|
+
if (!columns) return [];
|
|
1126
|
+
const widths = [];
|
|
1127
|
+
columns.node.forEach((child) => {
|
|
1128
|
+
if (child.type.name === _maily_to_shared.MAILY_NODE_TYPES.COLUMN) {
|
|
1129
|
+
const width = child.attrs.width;
|
|
1130
|
+
widths.push(typeof width === "number" ? width : null);
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
return widths;
|
|
1134
|
+
}
|
|
1135
|
+
function updateColumnWidth(editor, columnIndex, width) {
|
|
1136
|
+
const columns = getClosestColumns(editor);
|
|
1137
|
+
if (!columns) return false;
|
|
1138
|
+
const { node: columnsNode, pos: columnsPos } = columns;
|
|
1139
|
+
const { dispatch, state } = editor.view;
|
|
1140
|
+
const { selection, tr } = state;
|
|
1141
|
+
const selectionRelative = {
|
|
1142
|
+
from: selection.from - columnsPos,
|
|
1143
|
+
to: selection.to - columnsPos
|
|
1144
|
+
};
|
|
1145
|
+
const updatedContent = [];
|
|
1146
|
+
columnsNode.content.forEach((child, _, index) => {
|
|
1147
|
+
updatedContent.push(child.type.create({
|
|
1148
|
+
...child.attrs,
|
|
1149
|
+
width: index === columnIndex ? width : child.attrs.width
|
|
1150
|
+
}, child.content));
|
|
1151
|
+
});
|
|
1152
|
+
const transaction = tr.replaceWith(columnsPos, columnsPos + columnsNode.nodeSize, columnsNode.type.create(columnsNode.attrs, updatedContent, columnsNode.marks));
|
|
1153
|
+
dispatch(transaction.setSelection(_tiptap_pm_state.TextSelection.create(transaction.doc, columnsPos + selectionRelative.from, columnsPos + selectionRelative.to)));
|
|
1154
|
+
return true;
|
|
1155
|
+
}
|
|
1156
|
+
function addColumn(editor) {
|
|
1157
|
+
const columns = getClosestColumns(editor);
|
|
1158
|
+
if (!columns) return false;
|
|
1159
|
+
const { node: columnsNode, pos: columnsPos } = columns;
|
|
1160
|
+
const { dispatch, state } = editor.view;
|
|
1161
|
+
const { tr } = state;
|
|
1162
|
+
const newColumn = state.schema.nodes[_maily_to_shared.MAILY_NODE_TYPES.COLUMN].create({ width: null }, state.schema.nodes[_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH].create());
|
|
1163
|
+
const updatedContent = [];
|
|
1164
|
+
columnsNode.content.forEach((child) => {
|
|
1165
|
+
updatedContent.push(child);
|
|
1166
|
+
});
|
|
1167
|
+
updatedContent.push(newColumn);
|
|
1168
|
+
const updatedColumnsNode = columnsNode.type.create({
|
|
1169
|
+
...columnsNode.attrs,
|
|
1170
|
+
columnCount: columnsNode.childCount + 1
|
|
1171
|
+
}, updatedContent);
|
|
1172
|
+
const transaction = tr.replaceWith(columnsPos, columnsPos + columnsNode.nodeSize, updatedColumnsNode);
|
|
1173
|
+
dispatch(transaction.setSelection(_tiptap_pm_state.TextSelection.create(transaction.doc, columnsPos + 3)));
|
|
1174
|
+
return true;
|
|
1175
|
+
}
|
|
1176
|
+
function removeColumn(editor) {
|
|
1177
|
+
const columns = getClosestColumns(editor);
|
|
1178
|
+
if (!columns) return false;
|
|
1179
|
+
const { node: columnsNode, pos: columnsPos } = columns;
|
|
1180
|
+
if (columnsNode.childCount <= 1) return false;
|
|
1181
|
+
const { dispatch, state } = editor.view;
|
|
1182
|
+
const { selection, tr } = state;
|
|
1183
|
+
const removeIndex = columnsNode.childCount - 1;
|
|
1184
|
+
const updatedContent = [];
|
|
1185
|
+
columnsNode.content.forEach((child, _, childIndex) => {
|
|
1186
|
+
if (childIndex !== removeIndex) updatedContent.push(child);
|
|
1187
|
+
});
|
|
1188
|
+
const updatedColumnsNode = columnsNode.type.create({
|
|
1189
|
+
...columnsNode.attrs,
|
|
1190
|
+
columnCount: columnsNode.childCount - 1
|
|
1191
|
+
}, updatedContent);
|
|
1192
|
+
const selectionFrom = selection.from - columnsPos;
|
|
1193
|
+
const transaction = tr.replaceWith(columnsPos, columnsPos + columnsNode.nodeSize, updatedColumnsNode);
|
|
1194
|
+
const maxPos = columnsPos + updatedColumnsNode.nodeSize - 1;
|
|
1195
|
+
dispatch(transaction.setSelection(_tiptap_pm_state.TextSelection.near(transaction.doc.resolve(Math.min(columnsPos + selectionFrom, maxPos)))));
|
|
1196
|
+
return true;
|
|
1197
|
+
}
|
|
1198
|
+
function goToSiblingColumn(editor, direction) {
|
|
1199
|
+
const { $from } = editor.state.selection;
|
|
1200
|
+
let columnDepth = -1;
|
|
1201
|
+
for (let depth = $from.depth; depth > 0; depth--) if ($from.node(depth).type.name === _maily_to_shared.MAILY_NODE_TYPES.COLUMN) {
|
|
1202
|
+
columnDepth = depth;
|
|
1203
|
+
break;
|
|
1204
|
+
}
|
|
1205
|
+
if (columnDepth === -1) return false;
|
|
1206
|
+
const columnsDepth = columnDepth - 1;
|
|
1207
|
+
const columnIndex = $from.index(columnsDepth);
|
|
1208
|
+
const targetIndex = direction === "next" ? columnIndex + 1 : columnIndex - 1;
|
|
1209
|
+
if (targetIndex < 0 || targetIndex >= $from.node(columnsDepth).childCount) return false;
|
|
1210
|
+
const targetPos = direction === "next" ? $from.after(columnDepth) + 1 : $from.before(columnDepth) - 1;
|
|
1211
|
+
const { tr } = editor.state;
|
|
1212
|
+
tr.setSelection(_tiptap_pm_state.TextSelection.near(tr.doc.resolve(targetPos), direction === "next" ? 1 : -1));
|
|
1213
|
+
editor.view.dispatch(tr);
|
|
1214
|
+
return true;
|
|
1215
|
+
}
|
|
1216
|
+
//#endregion
|
|
1217
|
+
//#region src/utils/exit-on-triple-enter.ts
|
|
1218
|
+
/**
|
|
1219
|
+
* Exits a container node when the user presses Enter three times
|
|
1220
|
+
* (i.e. the last three children are empty). Deletes the trailing
|
|
1221
|
+
* empty blocks and inserts a paragraph after the container.
|
|
1222
|
+
*/
|
|
1223
|
+
function exitOnTripleEnter(options) {
|
|
1224
|
+
const { editor, exitDepthOffset = 0, nodeName } = options;
|
|
1225
|
+
const { state } = editor;
|
|
1226
|
+
const { $from, empty } = state.selection;
|
|
1227
|
+
if (!empty) return false;
|
|
1228
|
+
let nodeDepth = -1;
|
|
1229
|
+
for (let d = $from.depth; d > 0; d--) if ($from.node(d).type.name === nodeName) {
|
|
1230
|
+
nodeDepth = d;
|
|
1231
|
+
break;
|
|
1232
|
+
}
|
|
1233
|
+
if (nodeDepth === -1) return false;
|
|
1234
|
+
const node = $from.node(nodeDepth);
|
|
1235
|
+
const lastChildIndex = node.childCount - 1;
|
|
1236
|
+
if (node.childCount < 3 || $from.index(nodeDepth) !== lastChildIndex || $from.parent.content.size !== 0 || node.child(lastChildIndex - 1).content.size !== 0 || node.child(lastChildIndex - 2).content.size !== 0) return false;
|
|
1237
|
+
const exitDepth = nodeDepth + exitDepthOffset;
|
|
1238
|
+
const deleteCount = Math.min(3, node.childCount - 1);
|
|
1239
|
+
let deleteFrom = $from.start(nodeDepth);
|
|
1240
|
+
for (let i = 0; i < node.childCount - deleteCount; i++) deleteFrom += node.child(i).nodeSize;
|
|
1241
|
+
return editor.chain().command(({ tr }) => {
|
|
1242
|
+
const afterNode = $from.after(exitDepth);
|
|
1243
|
+
tr.delete(deleteFrom, $from.end(nodeDepth));
|
|
1244
|
+
const mappedPos = tr.mapping.map(afterNode);
|
|
1245
|
+
tr.insert(mappedPos, editor.schema.nodes.paragraph.create());
|
|
1246
|
+
tr.setSelection(_tiptap_pm_state.TextSelection.near(tr.doc.resolve(mappedPos + 1)));
|
|
1247
|
+
return true;
|
|
1248
|
+
}).run();
|
|
1249
|
+
}
|
|
1250
|
+
//#endregion
|
|
1251
|
+
//#region src/extensions/columns/column.ts
|
|
1252
|
+
const DEFAULT_COLUMN_WIDTH = null;
|
|
1253
|
+
const ColumnExtension = _tiptap_core.Node.create({
|
|
1254
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
1255
|
+
group: "column",
|
|
1256
|
+
content: "block+",
|
|
1257
|
+
defining: true,
|
|
1258
|
+
isolating: true,
|
|
1259
|
+
addAttributes() {
|
|
1260
|
+
return {
|
|
1261
|
+
width: {
|
|
1262
|
+
default: DEFAULT_COLUMN_WIDTH,
|
|
1263
|
+
parseHTML: (element) => {
|
|
1264
|
+
return (0, _maily_to_shared.getColumnWidth)(element.style.width) ?? DEFAULT_COLUMN_WIDTH;
|
|
1265
|
+
},
|
|
1266
|
+
renderHTML: (attributes) => {
|
|
1267
|
+
const width = attributes.width;
|
|
1268
|
+
if (width === null) return {};
|
|
1269
|
+
const value = (0, _maily_to_shared.getColumnWidthValue)(width);
|
|
1270
|
+
return { style: `width:${value};max-width:${value}` };
|
|
1271
|
+
}
|
|
1272
|
+
},
|
|
1273
|
+
verticalAlign: {
|
|
1274
|
+
default: "top",
|
|
1275
|
+
parseHTML: (element) => {
|
|
1276
|
+
if (element.style.verticalAlign) return element.style.verticalAlign;
|
|
1277
|
+
if (element.style.justifyContent === "center") return "middle";
|
|
1278
|
+
if (element.style.justifyContent === "flex-end") return "bottom";
|
|
1279
|
+
return "top";
|
|
1280
|
+
},
|
|
1281
|
+
renderHTML: (attributes) => {
|
|
1282
|
+
const verticalAlign = attributes.verticalAlign;
|
|
1283
|
+
if (!verticalAlign || verticalAlign === "top") return {};
|
|
1284
|
+
if (verticalAlign === "middle") return { style: "display:flex;flex-direction:column;justify-content:center" };
|
|
1285
|
+
if (verticalAlign === "bottom") return { style: "display:flex;flex-direction:column;justify-content:flex-end" };
|
|
1286
|
+
return {};
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
};
|
|
1290
|
+
},
|
|
1291
|
+
addCommands() {
|
|
1292
|
+
return { updateColumn: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs) };
|
|
1293
|
+
},
|
|
1294
|
+
addKeyboardShortcuts() {
|
|
1295
|
+
return {
|
|
1296
|
+
Tab: ({ editor }) => goToSiblingColumn(editor, "next"),
|
|
1297
|
+
"Shift-Tab": ({ editor }) => goToSiblingColumn(editor, "previous"),
|
|
1298
|
+
Enter: ({ editor }) => {
|
|
1299
|
+
return exitOnTripleEnter({
|
|
1300
|
+
editor,
|
|
1301
|
+
exitDepthOffset: -1,
|
|
1302
|
+
nodeName: this.name
|
|
1303
|
+
});
|
|
1304
|
+
}
|
|
1305
|
+
};
|
|
1306
|
+
},
|
|
1307
|
+
parseHTML() {
|
|
1308
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.COLUMN}"]` }];
|
|
1309
|
+
},
|
|
1310
|
+
renderHTML({ HTMLAttributes }) {
|
|
1311
|
+
return [
|
|
1312
|
+
"div",
|
|
1313
|
+
(0, _tiptap_core.mergeAttributes)(HTMLAttributes, { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.COLUMN }),
|
|
1314
|
+
0
|
|
1315
|
+
];
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
const ColumnsExtension = _tiptap_core.Node.create({
|
|
1319
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
1320
|
+
group: "block",
|
|
1321
|
+
content: "column+",
|
|
1322
|
+
defining: true,
|
|
1323
|
+
isolating: true,
|
|
1324
|
+
draggable: true,
|
|
1325
|
+
addAttributes() {
|
|
1326
|
+
return {
|
|
1327
|
+
columnCount: {
|
|
1328
|
+
default: 2,
|
|
1329
|
+
parseHTML: (element) => Number(element.getAttribute("data-column-count")) || 2,
|
|
1330
|
+
renderHTML: (attributes) => ({ "data-column-count": attributes.columnCount })
|
|
1331
|
+
},
|
|
1332
|
+
gap: {
|
|
1333
|
+
default: 8,
|
|
1334
|
+
parseHTML: (element) => Number(element.getAttribute("data-gap")) || 8,
|
|
1335
|
+
renderHTML: (attributes) => ({
|
|
1336
|
+
"data-gap": attributes.gap,
|
|
1337
|
+
style: `gap:${attributes.gap}px`
|
|
1338
|
+
})
|
|
1339
|
+
}
|
|
1340
|
+
};
|
|
1341
|
+
},
|
|
1342
|
+
addCommands() {
|
|
1343
|
+
return {
|
|
1344
|
+
setColumns: (columnCount = 2) => ({ tr, dispatch, editor }) => {
|
|
1345
|
+
const columnNodes = Array.from({ length: columnCount }, () => editor.schema.nodes[_maily_to_shared.MAILY_NODE_TYPES.COLUMN].createAndFill({}, editor.schema.nodes.paragraph.create())).filter((node) => node !== null);
|
|
1346
|
+
const columnsNode = editor.schema.nodes[this.name].createAndFill({ columnCount }, columnNodes);
|
|
1347
|
+
if (!columnsNode) return false;
|
|
1348
|
+
const { $from } = tr.selection;
|
|
1349
|
+
const isEmptyBlock = $from.parent.isTextblock && $from.parent.content.size === 0;
|
|
1350
|
+
const insertFrom = isEmptyBlock ? $from.before($from.depth) : $from.after($from.depth);
|
|
1351
|
+
const insertTo = isEmptyBlock ? $from.after($from.depth) : insertFrom;
|
|
1352
|
+
tr.replaceWith(insertFrom, insertTo, columnsNode);
|
|
1353
|
+
tr.setSelection(_tiptap_pm_state.TextSelection.near(tr.doc.resolve(insertFrom + 3)));
|
|
1354
|
+
if (dispatch) dispatch(tr);
|
|
1355
|
+
return true;
|
|
1356
|
+
},
|
|
1357
|
+
updateColumns: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
1358
|
+
};
|
|
1359
|
+
},
|
|
1360
|
+
parseHTML() {
|
|
1361
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.COLUMNS}"]` }];
|
|
1362
|
+
},
|
|
1363
|
+
renderHTML({ HTMLAttributes }) {
|
|
1364
|
+
return [
|
|
1365
|
+
"div",
|
|
1366
|
+
(0, _tiptap_core.mergeAttributes)(HTMLAttributes, { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.COLUMNS }),
|
|
1367
|
+
0
|
|
1368
|
+
];
|
|
1369
|
+
}
|
|
1370
|
+
});
|
|
1371
|
+
//#endregion
|
|
1372
|
+
//#region src/extensions/visibility/visibility.ts
|
|
1373
|
+
const VISIBILITY_SUPPORTED_TYPES = [
|
|
1374
|
+
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
1375
|
+
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
1376
|
+
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
1377
|
+
_maily_to_shared.MAILY_NODE_TYPES.SPACER,
|
|
1378
|
+
_maily_to_shared.MAILY_NODE_TYPES.SECTION,
|
|
1379
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
1380
|
+
_maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST,
|
|
1381
|
+
_maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST,
|
|
1382
|
+
_maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE,
|
|
1383
|
+
_maily_to_shared.MAILY_NODE_TYPES.BUTTON,
|
|
1384
|
+
_maily_to_shared.MAILY_NODE_TYPES.REPEAT,
|
|
1385
|
+
_maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK,
|
|
1386
|
+
_maily_to_shared.MAILY_NODE_TYPES.LINK_CARD
|
|
1387
|
+
];
|
|
1388
|
+
function getRuleAttributes(rule) {
|
|
1389
|
+
const attributes = {
|
|
1390
|
+
"data-visibility-action": rule.action,
|
|
1391
|
+
"data-visibility-operator": rule.operator,
|
|
1392
|
+
"data-visibility-variable": rule.variable
|
|
1393
|
+
};
|
|
1394
|
+
if ((0, _maily_to_shared.getVisibilityValueSupport)(rule.operator)) attributes["data-visibility-value"] = rule.value;
|
|
1395
|
+
return attributes;
|
|
1396
|
+
}
|
|
1397
|
+
const VisibilityExtension = _tiptap_core.Extension.create({
|
|
1398
|
+
name: _maily_to_shared.MAILY_EXTENSION_TYPES.VISIBILITY,
|
|
1399
|
+
addOptions() {
|
|
1400
|
+
return { types: VISIBILITY_SUPPORTED_TYPES };
|
|
1401
|
+
},
|
|
1402
|
+
addGlobalAttributes() {
|
|
1403
|
+
return [{
|
|
1404
|
+
types: this.options.types,
|
|
1405
|
+
attributes: { visibilityRule: {
|
|
1406
|
+
default: null,
|
|
1407
|
+
keepOnSplit: false,
|
|
1408
|
+
parseHTML: (element) => (0, _maily_to_shared.getVisibilityRule)({
|
|
1409
|
+
action: element.getAttribute("data-visibility-action"),
|
|
1410
|
+
operator: element.getAttribute("data-visibility-operator"),
|
|
1411
|
+
value: element.getAttribute("data-visibility-value"),
|
|
1412
|
+
variable: element.getAttribute("data-visibility-variable")
|
|
1413
|
+
}),
|
|
1414
|
+
renderHTML: (attributes) => {
|
|
1415
|
+
const rule = attributes.visibilityRule;
|
|
1416
|
+
return rule ? getRuleAttributes(rule) : {};
|
|
1417
|
+
}
|
|
1418
|
+
} }
|
|
1419
|
+
}];
|
|
1420
|
+
},
|
|
1421
|
+
addCommands() {
|
|
1422
|
+
return {
|
|
1423
|
+
setVisibilityRule: (typeOrName, rule) => ({ commands }) => commands.updateAttributes(typeOrName, { visibilityRule: rule }),
|
|
1424
|
+
unsetVisibilityRule: (typeOrName) => ({ commands }) => commands.updateAttributes(typeOrName, { visibilityRule: null })
|
|
1425
|
+
};
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1428
|
+
//#endregion
|
|
1429
|
+
//#region src/utils/collaboration.ts
|
|
1430
|
+
const Y_SYNC_META_KEY = "y-sync$";
|
|
1431
|
+
function isRemoteChange(tr) {
|
|
1432
|
+
return Boolean(tr.getMeta(Y_SYNC_META_KEY));
|
|
1433
|
+
}
|
|
1434
|
+
//#endregion
|
|
1435
|
+
//#region src/extensions/variable/protect-variable-trigger.ts
|
|
1436
|
+
const ProtectVariableTrigger = _tiptap_core.Extension.create({
|
|
1437
|
+
name: "protectVariableTrigger",
|
|
1438
|
+
addProseMirrorPlugins() {
|
|
1439
|
+
return [new _tiptap_pm_state.Plugin({ appendTransaction(transactions, _oldState, newState) {
|
|
1440
|
+
if (!transactions.some((tr) => tr.docChanged) || transactions.some(isRemoteChange)) return null;
|
|
1441
|
+
let hasVariable = false;
|
|
1442
|
+
newState.doc.descendants((node) => {
|
|
1443
|
+
if (node.type.name === _maily_to_shared.MAILY_NODE_TYPES.VARIABLE) {
|
|
1444
|
+
hasVariable = true;
|
|
1445
|
+
return false;
|
|
1446
|
+
}
|
|
1447
|
+
return true;
|
|
1448
|
+
});
|
|
1449
|
+
if (hasVariable) return null;
|
|
1450
|
+
const paragraph = newState.doc.firstChild;
|
|
1451
|
+
if (!paragraph) return null;
|
|
1452
|
+
if (paragraph.textContent.startsWith(_maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER)) return null;
|
|
1453
|
+
const tr = newState.tr;
|
|
1454
|
+
const start = 1;
|
|
1455
|
+
return tr.replaceWith(start, start + paragraph.content.size, newState.schema.text(_maily_to_shared.DEFAULT_VARIABLE_START_TRIGGER));
|
|
1456
|
+
} })];
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
//#endregion
|
|
1460
|
+
//#region src/extensions/repeat/repeat.ts
|
|
1461
|
+
const DEFAULT_REPEAT_EACH = "{{items}}";
|
|
1462
|
+
const RepeatExtension = _tiptap_core.Node.create({
|
|
1463
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.REPEAT,
|
|
1464
|
+
group: "block",
|
|
1465
|
+
content: "block+",
|
|
1466
|
+
defining: true,
|
|
1467
|
+
isolating: true,
|
|
1468
|
+
draggable: true,
|
|
1469
|
+
addOptions() {
|
|
1470
|
+
return { HTMLAttributes: {} };
|
|
1471
|
+
},
|
|
1472
|
+
addAttributes() {
|
|
1473
|
+
return { each: {
|
|
1474
|
+
default: DEFAULT_REPEAT_EACH,
|
|
1475
|
+
parseHTML: (element) => {
|
|
1476
|
+
return element.getAttribute("data-each") || "{{items}}";
|
|
1477
|
+
},
|
|
1478
|
+
renderHTML: (attributes) => ({ "data-each": attributes.each })
|
|
1479
|
+
} };
|
|
1480
|
+
},
|
|
1481
|
+
addCommands() {
|
|
1482
|
+
return {
|
|
1483
|
+
setRepeat: (attrs) => ({ commands }) => commands.insertContent({
|
|
1484
|
+
type: this.name,
|
|
1485
|
+
attrs: { ...attrs },
|
|
1486
|
+
content: [{ type: _maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH }]
|
|
1487
|
+
}),
|
|
1488
|
+
updateRepeat: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
1489
|
+
};
|
|
1490
|
+
},
|
|
1491
|
+
addKeyboardShortcuts() {
|
|
1492
|
+
return { "Mod-Backspace": ({ editor }) => editor.commands.deleteNode(this.name) };
|
|
1493
|
+
},
|
|
1494
|
+
parseHTML() {
|
|
1495
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
|
|
1496
|
+
},
|
|
1497
|
+
renderHTML({ HTMLAttributes }) {
|
|
1498
|
+
return [
|
|
1499
|
+
"div",
|
|
1500
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes),
|
|
1501
|
+
0
|
|
1502
|
+
];
|
|
1503
|
+
}
|
|
1504
|
+
});
|
|
1505
|
+
//#endregion
|
|
1506
|
+
//#region src/extensions/blockquote/blockquote.ts
|
|
1507
|
+
const BlockquoteExtension = _tiptap_extension_blockquote.Blockquote.extend({ renderHTML({ HTMLAttributes }) {
|
|
1508
|
+
return [
|
|
1509
|
+
"blockquote",
|
|
1510
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE }, this.options.HTMLAttributes, HTMLAttributes),
|
|
1511
|
+
0
|
|
1512
|
+
];
|
|
1513
|
+
} });
|
|
1514
|
+
//#endregion
|
|
1515
|
+
//#region src/extensions/body/body.ts
|
|
1516
|
+
const BodyExtension = _tiptap_core.Node.create({
|
|
1517
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.BODY,
|
|
1518
|
+
content: `${_maily_to_shared.MAILY_NODE_TYPES.CONTAINER}+`,
|
|
1519
|
+
defining: true,
|
|
1520
|
+
parseHTML() {
|
|
1521
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.BODY}"]` }];
|
|
1522
|
+
},
|
|
1523
|
+
renderHTML({ HTMLAttributes }) {
|
|
1524
|
+
return [
|
|
1525
|
+
"div",
|
|
1526
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.BODY }, HTMLAttributes),
|
|
1527
|
+
0
|
|
1528
|
+
];
|
|
1529
|
+
}
|
|
1530
|
+
});
|
|
1531
|
+
//#endregion
|
|
1532
|
+
//#region src/utils/table.ts
|
|
1533
|
+
function getSingleCell(element) {
|
|
1534
|
+
if (isDataTable(element)) return null;
|
|
1535
|
+
const cells = element.querySelectorAll(":scope > tbody > tr > td");
|
|
1536
|
+
return cells.length === 1 ? cells[0] : null;
|
|
1537
|
+
}
|
|
1538
|
+
function isDataTable(element) {
|
|
1539
|
+
const border = element.getAttribute("border");
|
|
1540
|
+
return element.querySelector(":scope > thead, :scope > tbody > tr > th") !== null || border !== null && border !== "0";
|
|
1541
|
+
}
|
|
1542
|
+
function isBodyTable(element) {
|
|
1543
|
+
return element.parentElement?.tagName === "BODY";
|
|
1544
|
+
}
|
|
1545
|
+
//#endregion
|
|
1546
|
+
//#region src/utils/style.ts
|
|
1547
|
+
const BOLD_FONT_WEIGHTS = [
|
|
1548
|
+
"bold",
|
|
1549
|
+
"bolder",
|
|
1550
|
+
String(_maily_to_shared.FONT_WEIGHTS.BOLD)
|
|
1551
|
+
];
|
|
1552
|
+
const MARKED_TEXT_DECORATIONS = ["underline", "line-through"];
|
|
1553
|
+
function isBoldFontWeight(value) {
|
|
1554
|
+
return BOLD_FONT_WEIGHTS.includes(value.trim().toLowerCase());
|
|
1555
|
+
}
|
|
1556
|
+
function isItalicFontStyle(value) {
|
|
1557
|
+
return value.trim().toLowerCase() === _maily_to_shared.FONT_STYLES.ITALIC;
|
|
1558
|
+
}
|
|
1559
|
+
function isMarkedTextDecoration(value) {
|
|
1560
|
+
const decoration = value.toLowerCase();
|
|
1561
|
+
return MARKED_TEXT_DECORATIONS.some((keyword) => {
|
|
1562
|
+
return decoration.includes(keyword);
|
|
1563
|
+
});
|
|
1564
|
+
}
|
|
1565
|
+
const CLAIMED_BY_MARKS = {
|
|
1566
|
+
fontStyle: isItalicFontStyle,
|
|
1567
|
+
fontWeight: isBoldFontWeight,
|
|
1568
|
+
textDecoration: isMarkedTextDecoration,
|
|
1569
|
+
textDecorationLine: isMarkedTextDecoration
|
|
1570
|
+
};
|
|
1571
|
+
const CLAIMED_ON_SPAN = {
|
|
1572
|
+
...CLAIMED_BY_MARKS,
|
|
1573
|
+
color: true
|
|
1574
|
+
};
|
|
1575
|
+
const CLAIMED_ON_INLINE_IMAGE = { display: true };
|
|
1576
|
+
const CLAIMED_ON_COLUMNS = {
|
|
1577
|
+
gap: true,
|
|
1578
|
+
columnGap: true,
|
|
1579
|
+
rowGap: true
|
|
1580
|
+
};
|
|
1581
|
+
const CLAIMED_ON_COLUMN = {
|
|
1582
|
+
display: true,
|
|
1583
|
+
flexDirection: true,
|
|
1584
|
+
justifyContent: true,
|
|
1585
|
+
maxWidth: true,
|
|
1586
|
+
width: true,
|
|
1587
|
+
verticalAlign: true
|
|
1588
|
+
};
|
|
1589
|
+
function getUnclaimedStyle(options) {
|
|
1590
|
+
const { style, claimed } = options;
|
|
1591
|
+
if (!style) return null;
|
|
1592
|
+
const declarations = (0, _maily_to_shared.parseInlineStyles)(style);
|
|
1593
|
+
for (const [property, claims] of Object.entries(claimed)) {
|
|
1594
|
+
const value = declarations[property];
|
|
1595
|
+
if (value === void 0) continue;
|
|
1596
|
+
if (claims === true || claims(value)) delete declarations[property];
|
|
1597
|
+
}
|
|
1598
|
+
return (0, _maily_to_shared.stringifyInlineStyles)(declarations) || null;
|
|
1599
|
+
}
|
|
1600
|
+
function getMarkStyle(style) {
|
|
1601
|
+
return getUnclaimedStyle({
|
|
1602
|
+
style,
|
|
1603
|
+
claimed: CLAIMED_BY_MARKS
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
function getSpanStyle(style) {
|
|
1607
|
+
return getUnclaimedStyle({
|
|
1608
|
+
style,
|
|
1609
|
+
claimed: CLAIMED_ON_SPAN
|
|
1610
|
+
});
|
|
1611
|
+
}
|
|
1612
|
+
function getInlineImageStyle(element) {
|
|
1613
|
+
return getUnclaimedStyle({
|
|
1614
|
+
style: getElementStyle(element),
|
|
1615
|
+
claimed: CLAIMED_ON_INLINE_IMAGE
|
|
1616
|
+
});
|
|
1617
|
+
}
|
|
1618
|
+
function getColumnsStyle(style) {
|
|
1619
|
+
return getUnclaimedStyle({
|
|
1620
|
+
style,
|
|
1621
|
+
claimed: CLAIMED_ON_COLUMNS
|
|
1622
|
+
});
|
|
1623
|
+
}
|
|
1624
|
+
function getColumnStyle(style) {
|
|
1625
|
+
return getUnclaimedStyle({
|
|
1626
|
+
style,
|
|
1627
|
+
claimed: CLAIMED_ON_COLUMN
|
|
1628
|
+
});
|
|
1629
|
+
}
|
|
1630
|
+
const TABLE_ALIGNMENT = {
|
|
1631
|
+
center: {
|
|
1632
|
+
marginLeft: "auto",
|
|
1633
|
+
marginRight: "auto"
|
|
1634
|
+
},
|
|
1635
|
+
left: { marginRight: "auto" },
|
|
1636
|
+
right: { marginLeft: "auto" }
|
|
1637
|
+
};
|
|
1638
|
+
function toCssLength(value) {
|
|
1639
|
+
const trimmed = value.trim();
|
|
1640
|
+
return /^\d+(?:\.\d+)?$/.test(trimmed) ? `${trimmed}px` : trimmed;
|
|
1641
|
+
}
|
|
1642
|
+
function getPresentationalStyle(element) {
|
|
1643
|
+
const style = {};
|
|
1644
|
+
const width = element.getAttribute("width");
|
|
1645
|
+
const height = element.getAttribute("height");
|
|
1646
|
+
const align = element.getAttribute("align");
|
|
1647
|
+
const verticalAlign = element.getAttribute("valign");
|
|
1648
|
+
const backgroundColor = element.getAttribute("bgcolor");
|
|
1649
|
+
if (width) style.width = toCssLength(width);
|
|
1650
|
+
if (height) style.height = toCssLength(height);
|
|
1651
|
+
if (align) Object.assign(style, element.tagName === "TABLE" ? TABLE_ALIGNMENT[align.toLowerCase()] : { textAlign: align });
|
|
1652
|
+
if (verticalAlign) style.verticalAlign = verticalAlign;
|
|
1653
|
+
if (backgroundColor) style.backgroundColor = backgroundColor;
|
|
1654
|
+
return style;
|
|
1655
|
+
}
|
|
1656
|
+
function getWrapperAlignment(element) {
|
|
1657
|
+
const align = element.getAttribute("align")?.toLowerCase();
|
|
1658
|
+
if (!align || align === _maily_to_shared.TEXT_ALIGNMENTS.LEFT || align === _maily_to_shared.TEXT_ALIGNMENTS.CENTER) return {};
|
|
1659
|
+
return TABLE_ALIGNMENT[align] ?? {};
|
|
1660
|
+
}
|
|
1661
|
+
function getWrapperStyle(element) {
|
|
1662
|
+
const cell = getSingleCell(element);
|
|
1663
|
+
const style = (0, _maily_to_shared.mergeInlineStyles)(getWrapperAlignment(element), (0, _maily_to_shared.parseInlineStyles)(element.getAttribute("style") ?? ""));
|
|
1664
|
+
const inner = cell?.getAttribute("style");
|
|
1665
|
+
return (0, _maily_to_shared.stringifyInlineStyles)(inner ? (0, _maily_to_shared.mergeInlineStyles)(style, (0, _maily_to_shared.parseInlineStyles)(inner)) : style) || null;
|
|
1666
|
+
}
|
|
1667
|
+
function getElementStyle(element) {
|
|
1668
|
+
const authored = element.getAttribute("style");
|
|
1669
|
+
const presentational = getPresentationalStyle(element);
|
|
1670
|
+
if (Object.keys(presentational).length === 0) return authored;
|
|
1671
|
+
return (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)(presentational, authored ? (0, _maily_to_shared.parseInlineStyles)(authored) : {})) || null;
|
|
1672
|
+
}
|
|
1673
|
+
function setStyleDeclarations(style, declarations) {
|
|
1674
|
+
const merged = style ? (0, _maily_to_shared.parseInlineStyles)(style) : {};
|
|
1675
|
+
for (const [property, value] of Object.entries(declarations)) if (value === null || value === void 0 || value === "") delete merged[property];
|
|
1676
|
+
else merged[property] = value;
|
|
1677
|
+
return (0, _maily_to_shared.stringifyInlineStyles)(merged) || null;
|
|
1678
|
+
}
|
|
1679
|
+
//#endregion
|
|
1680
|
+
//#region src/extensions/bold/bold.ts
|
|
1681
|
+
const BoldExtension = _tiptap_extension_bold.Bold.extend({ parseHTML() {
|
|
1682
|
+
return [
|
|
1683
|
+
{ tag: "strong" },
|
|
1684
|
+
{
|
|
1685
|
+
tag: "b",
|
|
1686
|
+
getAttrs: (element) => {
|
|
1687
|
+
return element.style.fontWeight !== "normal" && null;
|
|
1688
|
+
}
|
|
1689
|
+
},
|
|
1690
|
+
{
|
|
1691
|
+
style: "font-weight=400",
|
|
1692
|
+
clearMark: (mark) => {
|
|
1693
|
+
return mark.type.name === this.name;
|
|
1694
|
+
}
|
|
1695
|
+
},
|
|
1696
|
+
{
|
|
1697
|
+
style: "font-weight",
|
|
1698
|
+
getAttrs: (value) => {
|
|
1699
|
+
return isBoldFontWeight(value) && null;
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
];
|
|
1703
|
+
} });
|
|
1704
|
+
//#endregion
|
|
1705
|
+
//#region src/extensions/button/button.ts
|
|
1706
|
+
const DEFAULT_BUTTON_ALIGN = _maily_to_shared.TEXT_ALIGNMENTS.CENTER;
|
|
1707
|
+
const ButtonExtension = _tiptap_core.Node.create({
|
|
1708
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.BUTTON,
|
|
1709
|
+
group: "block",
|
|
1710
|
+
content: "(inline)*",
|
|
1711
|
+
defining: true,
|
|
1712
|
+
isolating: true,
|
|
1713
|
+
addOptions() {
|
|
1714
|
+
return { HTMLAttributes: {} };
|
|
1715
|
+
},
|
|
1716
|
+
addAttributes() {
|
|
1717
|
+
return {
|
|
1718
|
+
url: {
|
|
1719
|
+
default: "",
|
|
1720
|
+
parseHTML: (element) => element.getAttribute("data-url") || "",
|
|
1721
|
+
renderHTML: (attributes) => ({ "data-url": attributes.url })
|
|
1722
|
+
},
|
|
1723
|
+
kind: {
|
|
1724
|
+
default: _maily_to_shared.DEFAULT_BUTTON_KIND,
|
|
1725
|
+
parseHTML: (element) => {
|
|
1726
|
+
const kind = element.getAttribute("data-kind");
|
|
1727
|
+
return (0, _maily_to_shared.isAllowedButtonKind)(kind) ? kind : _maily_to_shared.DEFAULT_BUTTON_KIND;
|
|
1728
|
+
},
|
|
1729
|
+
renderHTML: (attributes) => ({ "data-kind": attributes.kind })
|
|
1730
|
+
},
|
|
1731
|
+
align: {
|
|
1732
|
+
default: DEFAULT_BUTTON_ALIGN,
|
|
1733
|
+
parseHTML: (element) => {
|
|
1734
|
+
const align = element.getAttribute("data-align");
|
|
1735
|
+
return (0, _maily_to_shared.isAllowedTextAlignment)(align) ? align : DEFAULT_BUTTON_ALIGN;
|
|
1736
|
+
},
|
|
1737
|
+
renderHTML: (attributes) => ({ "data-align": attributes.align })
|
|
1738
|
+
}
|
|
1739
|
+
};
|
|
1740
|
+
},
|
|
1741
|
+
addCommands() {
|
|
1742
|
+
return {
|
|
1743
|
+
setButton: (attrs) => ({ commands }) => commands.insertContent({
|
|
1744
|
+
type: this.name,
|
|
1745
|
+
attrs: { ...attrs },
|
|
1746
|
+
content: [{
|
|
1747
|
+
type: _maily_to_shared.MAILY_NODE_TYPES.TEXT,
|
|
1748
|
+
text: "Button"
|
|
1749
|
+
}]
|
|
1750
|
+
}),
|
|
1751
|
+
updateButtonAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
1752
|
+
};
|
|
1753
|
+
},
|
|
1754
|
+
addKeyboardShortcuts() {
|
|
1755
|
+
return {
|
|
1756
|
+
"Mod-Backspace": ({ editor }) => editor.commands.deleteNode(this.name),
|
|
1757
|
+
Backspace: ({ editor }) => {
|
|
1758
|
+
const { $anchor, empty } = editor.state.selection;
|
|
1759
|
+
if (!empty || $anchor.parent.type.name !== this.name || $anchor.parent.content.size > 0) return false;
|
|
1760
|
+
return editor.commands.deleteNode(this.name);
|
|
1761
|
+
},
|
|
1762
|
+
Enter: ({ editor }) => {
|
|
1763
|
+
const { $from, empty } = editor.state.selection;
|
|
1764
|
+
if (!empty || $from.parent.type.name !== this.name) return false;
|
|
1765
|
+
if (!($from.parentOffset === $from.parent.nodeSize - 2)) return false;
|
|
1766
|
+
return editor.chain().insertContent({
|
|
1767
|
+
type: _maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
1768
|
+
content: []
|
|
1769
|
+
}).run();
|
|
1770
|
+
}
|
|
1771
|
+
};
|
|
1772
|
+
},
|
|
1773
|
+
parseHTML() {
|
|
1774
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
|
|
1775
|
+
},
|
|
1776
|
+
renderHTML({ HTMLAttributes }) {
|
|
1777
|
+
return [
|
|
1778
|
+
"div",
|
|
1779
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes),
|
|
1780
|
+
0
|
|
1781
|
+
];
|
|
1782
|
+
}
|
|
1783
|
+
});
|
|
1784
|
+
//#endregion
|
|
1785
|
+
//#region src/extensions/container/container.ts
|
|
1786
|
+
const ContainerExtension = _tiptap_core.Node.create({
|
|
1787
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.CONTAINER,
|
|
1788
|
+
group: "block",
|
|
1789
|
+
content: "block+",
|
|
1790
|
+
defining: true,
|
|
1791
|
+
isolating: true,
|
|
1792
|
+
parseHTML() {
|
|
1793
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.CONTAINER}"]` }, {
|
|
1794
|
+
tag: "table",
|
|
1795
|
+
priority: 60,
|
|
1796
|
+
getAttrs: (element) => {
|
|
1797
|
+
if (!element.style.maxWidth) return false;
|
|
1798
|
+
return getSingleCell(element) ? null : false;
|
|
1799
|
+
},
|
|
1800
|
+
contentElement: (element) => getSingleCell(element) ?? element
|
|
1801
|
+
}];
|
|
1802
|
+
},
|
|
1803
|
+
renderHTML({ HTMLAttributes }) {
|
|
1804
|
+
return [
|
|
1805
|
+
"div",
|
|
1806
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.CONTAINER }, HTMLAttributes),
|
|
1807
|
+
0
|
|
1808
|
+
];
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
//#endregion
|
|
1812
|
+
//#region src/extensions/footer/footer.ts
|
|
1813
|
+
const FooterExtension = _tiptap_core.Node.create({
|
|
1814
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.FOOTER,
|
|
1815
|
+
group: "block",
|
|
1816
|
+
content: "inline*",
|
|
1817
|
+
addOptions() {
|
|
1818
|
+
return { HTMLAttributes: {} };
|
|
1819
|
+
},
|
|
1820
|
+
addCommands() {
|
|
1821
|
+
return {
|
|
1822
|
+
setFooter: () => ({ commands }) => commands.setNode(this.name),
|
|
1823
|
+
updateFooterAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
1824
|
+
};
|
|
1825
|
+
},
|
|
1826
|
+
parseHTML() {
|
|
1827
|
+
return [{ tag: `small[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
|
|
1828
|
+
},
|
|
1829
|
+
renderHTML({ HTMLAttributes }) {
|
|
1830
|
+
return [
|
|
1831
|
+
"small",
|
|
1832
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes),
|
|
1833
|
+
0
|
|
1834
|
+
];
|
|
1835
|
+
}
|
|
1836
|
+
});
|
|
1837
|
+
//#endregion
|
|
1838
|
+
//#region src/extensions/horizontal-rule/horizontal-rule.ts
|
|
1839
|
+
const HorizontalRuleExtension = _tiptap_extension_horizontal_rule.HorizontalRule.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE } });
|
|
1840
|
+
//#endregion
|
|
1841
|
+
//#region src/extensions/html-code-block/html-code-block-view.tsx
|
|
1842
|
+
const PREVIEW_RESET = `
|
|
1843
|
+
* { font-family: 'Inter', sans-serif; }
|
|
1844
|
+
blockquote, h1, h2, h3, img, li, ol, p, ul {
|
|
1845
|
+
margin-top: 0;
|
|
1846
|
+
margin-bottom: 0;
|
|
1847
|
+
}
|
|
1848
|
+
`;
|
|
1849
|
+
function HtmlCodeBlockView(props) {
|
|
1850
|
+
const { node, updateAttributes } = props;
|
|
1851
|
+
const { activeTab, language } = node.attrs;
|
|
1852
|
+
/**
|
|
1853
|
+
* A `<style>` in the source belongs to the document head, so the preview
|
|
1854
|
+
* hoists every one of them above the body it renders.
|
|
1855
|
+
*/
|
|
1856
|
+
const html = (0, react.useMemo)(() => {
|
|
1857
|
+
const source = node.content.content.reduce((text, child) => {
|
|
1858
|
+
if (child.type.name !== _maily_to_shared.MAILY_NODE_TYPES.TEXT) return text;
|
|
1859
|
+
return text + child.text;
|
|
1860
|
+
}, "");
|
|
1861
|
+
const parsed = new DOMParser().parseFromString(source, "text/html");
|
|
1862
|
+
return `<style>${Array.from(parsed.querySelectorAll("style")).map((element) => {
|
|
1863
|
+
return element.innerHTML;
|
|
1864
|
+
}).join("\n")}</style>${parsed.body.innerHTML}`;
|
|
1865
|
+
}, [node]);
|
|
1866
|
+
const isEmpty = html === "<style></style>";
|
|
1867
|
+
const setPreviewElement = (element) => {
|
|
1868
|
+
if (!element || element.shadowRoot) return;
|
|
1869
|
+
const shadow = element.attachShadow({ mode: "open" });
|
|
1870
|
+
const sheet = new CSSStyleSheet();
|
|
1871
|
+
sheet.replaceSync(PREVIEW_RESET);
|
|
1872
|
+
shadow.adoptedStyleSheets = [sheet];
|
|
1873
|
+
const container = document.createElement("div");
|
|
1874
|
+
container.innerHTML = html;
|
|
1875
|
+
shadow.append(container);
|
|
1876
|
+
};
|
|
1877
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_tiptap_react.NodeViewWrapper, {
|
|
1878
|
+
"data-drag-handle": false,
|
|
1879
|
+
draggable: false,
|
|
1880
|
+
children: [activeTab === _maily_to_shared.HTML_CODE_BLOCK_TABS.CODE && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
1881
|
+
"data-mly-html-code-block": "",
|
|
1882
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewContent, {
|
|
1883
|
+
as: "code",
|
|
1884
|
+
className: language ? `language-${language}` : void 0
|
|
1885
|
+
})
|
|
1886
|
+
}), activeTab === _maily_to_shared.HTML_CODE_BLOCK_TABS.PREVIEW && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1887
|
+
contentEditable: false,
|
|
1888
|
+
"data-empty": isEmpty ? "" : void 0,
|
|
1889
|
+
"data-mly-html-code-block-preview": "",
|
|
1890
|
+
onClick: () => {
|
|
1891
|
+
if (isEmpty) updateAttributes({ activeTab: _maily_to_shared.HTML_CODE_BLOCK_TABS.CODE });
|
|
1892
|
+
},
|
|
1893
|
+
ref: setPreviewElement
|
|
1894
|
+
})]
|
|
1895
|
+
});
|
|
1896
|
+
}
|
|
1897
|
+
//#endregion
|
|
1898
|
+
//#region src/extensions/html-code-block/html-code-block.ts
|
|
1899
|
+
const lowlight$1 = (0, lowlight.createLowlight)(lowlight.common);
|
|
1900
|
+
lowlight$1.register("html", highlight_js_lib_languages_xml.default);
|
|
1901
|
+
const HtmlCodeBlockExtension = _tiptap_extension_code_block_lowlight.CodeBlockLowlight.extend({
|
|
1902
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK,
|
|
1903
|
+
content: "(text|variable)*",
|
|
1904
|
+
addAttributes() {
|
|
1905
|
+
return {
|
|
1906
|
+
...this.parent?.(),
|
|
1907
|
+
activeTab: { default: _maily_to_shared.DEFAULT_HTML_CODE_BLOCK_TAB }
|
|
1908
|
+
};
|
|
1909
|
+
},
|
|
1910
|
+
addNodeView() {
|
|
1911
|
+
return (0, _tiptap_react.ReactNodeViewRenderer)(HtmlCodeBlockView, { attrs: (props) => {
|
|
1912
|
+
const { node } = props;
|
|
1913
|
+
const { activeTab } = node.attrs;
|
|
1914
|
+
return {
|
|
1915
|
+
"data-active-tab": activeTab,
|
|
1916
|
+
[_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK
|
|
1917
|
+
};
|
|
1918
|
+
} });
|
|
1919
|
+
},
|
|
1920
|
+
addCommands() {
|
|
1921
|
+
return {
|
|
1922
|
+
setHtmlCodeBlock: (attrs) => {
|
|
1923
|
+
return ({ commands }) => {
|
|
1924
|
+
return commands.setNode(this.name, attrs);
|
|
1925
|
+
};
|
|
1926
|
+
},
|
|
1927
|
+
updateHtmlCodeBlock: (attrs) => {
|
|
1928
|
+
return ({ commands }) => {
|
|
1929
|
+
return commands.updateAttributes(this.name, attrs);
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
},
|
|
1934
|
+
addKeyboardShortcuts() {
|
|
1935
|
+
return {
|
|
1936
|
+
...this.parent?.(),
|
|
1937
|
+
/**
|
|
1938
|
+
* Without this the browser selects the whole document from inside a code
|
|
1939
|
+
* block, because the block is one text node and nothing scopes the
|
|
1940
|
+
* selection to it.
|
|
1941
|
+
*/
|
|
1942
|
+
"Mod-a": ({ editor }) => {
|
|
1943
|
+
const $pos = editor.state.selection.$anchor;
|
|
1944
|
+
if ($pos.node($pos.depth).type.name !== this.name) return false;
|
|
1945
|
+
let depth = $pos.depth;
|
|
1946
|
+
for (let level = depth; level > 0; level -= 1) if ($pos.node(level).type.name === this.name) {
|
|
1947
|
+
depth = level;
|
|
1948
|
+
break;
|
|
1949
|
+
}
|
|
1950
|
+
const from = editor.state.doc.resolve($pos.before(depth) + 1);
|
|
1951
|
+
const to = editor.state.doc.resolve($pos.after(depth) - 1);
|
|
1952
|
+
const transaction = editor.state.tr.setSelection(_tiptap_pm_state.TextSelection.between(from, to));
|
|
1953
|
+
editor.view.dispatch(transaction);
|
|
1954
|
+
return true;
|
|
1955
|
+
},
|
|
1956
|
+
"Mod-Backspace": ({ editor }) => {
|
|
1957
|
+
return editor.commands.deleteNode(this.name);
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
}
|
|
1961
|
+
}).configure({ lowlight: lowlight$1 });
|
|
1962
|
+
//#endregion
|
|
1963
|
+
//#region src/extensions/image-upload/upload-image-file.ts
|
|
1964
|
+
function notifyUploadStatusChanged(editor) {
|
|
1965
|
+
editor.view.dispatch(editor.state.tr.setMeta("__mly_image_upload_status_changed", true));
|
|
1966
|
+
}
|
|
1967
|
+
function getUploadOptions(editor) {
|
|
1968
|
+
const extension = editor.extensionManager.extensions.find((candidate) => candidate.name === IMAGE_UPLOAD_EXTENSION_NAME);
|
|
1969
|
+
(0, _maily_to_shared.invariant)(extension, `You must add the "${IMAGE_UPLOAD_EXTENSION_NAME}" extension to the editor to upload images.`);
|
|
1970
|
+
return extension.options;
|
|
1971
|
+
}
|
|
1972
|
+
function findImageByBlobUrl(editor, blobUrl) {
|
|
1973
|
+
let found = null;
|
|
1974
|
+
editor.state.doc.descendants((node, pos) => {
|
|
1975
|
+
if (found) return false;
|
|
1976
|
+
if (node.type.name === _maily_to_shared.MAILY_NODE_TYPES.IMAGE && node.attrs.src === blobUrl) {
|
|
1977
|
+
found = {
|
|
1978
|
+
node,
|
|
1979
|
+
pos
|
|
1980
|
+
};
|
|
1981
|
+
return false;
|
|
1982
|
+
}
|
|
1983
|
+
return true;
|
|
1984
|
+
});
|
|
1985
|
+
return found;
|
|
1986
|
+
}
|
|
1987
|
+
function updateImageByBlobUrl(editor, blobUrl, attrs) {
|
|
1988
|
+
const found = findImageByBlobUrl(editor, blobUrl);
|
|
1989
|
+
if (!found) return;
|
|
1990
|
+
const { tr } = editor.state;
|
|
1991
|
+
tr.setNodeMarkup(found.pos, void 0, {
|
|
1992
|
+
...found.node.attrs,
|
|
1993
|
+
...attrs
|
|
1994
|
+
});
|
|
1995
|
+
editor.view.dispatch(tr);
|
|
1996
|
+
}
|
|
1997
|
+
function removeImageByBlobUrl(editor, blobUrl) {
|
|
1998
|
+
const found = findImageByBlobUrl(editor, blobUrl);
|
|
1999
|
+
if (!found) return;
|
|
2000
|
+
editor.view.dispatch(editor.state.tr.delete(found.pos, found.pos + found.node.nodeSize));
|
|
2001
|
+
}
|
|
2002
|
+
function uploadImageFile(editor, file, position) {
|
|
2003
|
+
const { onImageUpload, onImageUploadError } = getUploadOptions(editor);
|
|
2004
|
+
if (!onImageUpload) return;
|
|
2005
|
+
const blobUrl = URL.createObjectURL(file);
|
|
2006
|
+
if (!editor.chain().insertContentAt(position, {
|
|
2007
|
+
type: _maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
2008
|
+
attrs: { src: blobUrl }
|
|
2009
|
+
}).run()) {
|
|
2010
|
+
URL.revokeObjectURL(blobUrl);
|
|
2011
|
+
return;
|
|
2012
|
+
}
|
|
2013
|
+
const context = {
|
|
2014
|
+
position,
|
|
2015
|
+
removeImage: () => removeImageByBlobUrl(editor, blobUrl)
|
|
2016
|
+
};
|
|
2017
|
+
const { uploads } = editor.storage.imageUpload;
|
|
2018
|
+
uploads.set(blobUrl, IMAGE_UPLOAD_STATUSES.LOADING);
|
|
2019
|
+
notifyUploadStatusChanged(editor);
|
|
2020
|
+
onImageUpload(file, context).then((url) => {
|
|
2021
|
+
uploads.delete(blobUrl);
|
|
2022
|
+
notifyUploadStatusChanged(editor);
|
|
2023
|
+
updateImageByBlobUrl(editor, blobUrl, { src: url });
|
|
2024
|
+
URL.revokeObjectURL(blobUrl);
|
|
2025
|
+
}).catch((error) => {
|
|
2026
|
+
uploads.set(blobUrl, IMAGE_UPLOAD_STATUSES.ERROR);
|
|
2027
|
+
notifyUploadStatusChanged(editor);
|
|
2028
|
+
onImageUploadError?.(error, file, context);
|
|
2029
|
+
URL.revokeObjectURL(blobUrl);
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2032
|
+
//#endregion
|
|
2033
|
+
//#region src/extensions/image-upload/image-upload.ts
|
|
2034
|
+
const IMAGE_UPLOAD_EXTENSION_NAME = "imageUpload";
|
|
2035
|
+
const IMAGE_UPLOAD_STATUSES = {
|
|
2036
|
+
IDLE: "idle",
|
|
2037
|
+
LOADING: "loading",
|
|
2038
|
+
ERROR: "error",
|
|
2039
|
+
LOADED: "loaded"
|
|
2040
|
+
};
|
|
2041
|
+
const ALLOWED_IMAGE_MIME_TYPES = [
|
|
2042
|
+
"image/jpeg",
|
|
2043
|
+
"image/png",
|
|
2044
|
+
"image/gif",
|
|
2045
|
+
"image/webp",
|
|
2046
|
+
"image/svg+xml"
|
|
2047
|
+
];
|
|
2048
|
+
const ImageUploadExtension = _tiptap_core.Extension.create({
|
|
2049
|
+
name: IMAGE_UPLOAD_EXTENSION_NAME,
|
|
2050
|
+
addOptions() {
|
|
2051
|
+
return {
|
|
2052
|
+
onImageUpload: void 0,
|
|
2053
|
+
onImageUploadError: void 0
|
|
2054
|
+
};
|
|
2055
|
+
},
|
|
2056
|
+
addStorage() {
|
|
2057
|
+
return { uploads: /* @__PURE__ */ new Map() };
|
|
2058
|
+
},
|
|
2059
|
+
addExtensions() {
|
|
2060
|
+
return [_tiptap_extension_file_handler.FileHandler.configure({
|
|
2061
|
+
allowedMimeTypes: [...ALLOWED_IMAGE_MIME_TYPES],
|
|
2062
|
+
onDrop: (editor, files, pos) => {
|
|
2063
|
+
for (const file of files) uploadImageFile(editor, file, pos);
|
|
2064
|
+
},
|
|
2065
|
+
onPaste: (editor, files) => {
|
|
2066
|
+
for (const file of files) uploadImageFile(editor, file, editor.state.selection.from);
|
|
2067
|
+
}
|
|
2068
|
+
})];
|
|
2069
|
+
}
|
|
2070
|
+
});
|
|
2071
|
+
//#endregion
|
|
2072
|
+
//#region src/utils/pointer.ts
|
|
2073
|
+
function capturePointer(options) {
|
|
2074
|
+
const { element, pointerId } = options;
|
|
2075
|
+
try {
|
|
2076
|
+
element.setPointerCapture(pointerId);
|
|
2077
|
+
return true;
|
|
2078
|
+
} catch {
|
|
2079
|
+
return false;
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
function releasePointer(options) {
|
|
2083
|
+
const { element, pointerId } = options;
|
|
2084
|
+
try {
|
|
2085
|
+
element.releasePointerCapture(pointerId);
|
|
2086
|
+
return true;
|
|
2087
|
+
} catch {
|
|
2088
|
+
return false;
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
//#endregion
|
|
2092
|
+
//#region src/hooks/use-image-resize-controller.ts
|
|
2093
|
+
function useImageResizeController(options) {
|
|
2094
|
+
const { align, onWidthChange = _maily_to_shared.noop, onWidthCommitted = _maily_to_shared.noop } = options;
|
|
2095
|
+
const containerRef = (0, react.useRef)(null);
|
|
2096
|
+
const imageWrapperRef = (0, react.useRef)(null);
|
|
2097
|
+
const [shouldShowDragHandles, setShouldShowDragHandles] = (0, react.useState)(false);
|
|
2098
|
+
const [isResizing, setIsResizing] = (0, react.useState)(false);
|
|
2099
|
+
return {
|
|
2100
|
+
containerRef,
|
|
2101
|
+
handleResize: (0, react.useCallback)((event, initialResizeParams) => {
|
|
2102
|
+
let activeResizeState = initialResizeParams;
|
|
2103
|
+
let nextWidth = (0, _maily_to_shared.clampImageWidthPercentage)(Math.round((0, _maily_to_shared.percentage)(initialResizeParams.initialWidth, containerRef.current?.clientWidth ?? 0)));
|
|
2104
|
+
const targetElement = event.currentTarget;
|
|
2105
|
+
capturePointer({
|
|
2106
|
+
element: targetElement,
|
|
2107
|
+
pointerId: event.pointerId
|
|
2108
|
+
});
|
|
2109
|
+
const handlePointerMove = (moveEvent) => {
|
|
2110
|
+
const imageWrapper = imageWrapperRef.current;
|
|
2111
|
+
const container = containerRef.current;
|
|
2112
|
+
if (!activeResizeState || !imageWrapper || !container) return;
|
|
2113
|
+
const pointerDeltaX = moveEvent.clientX - activeResizeState.initialClientX;
|
|
2114
|
+
const { handleUsed, initialWidth } = activeResizeState;
|
|
2115
|
+
const delta = handleUsed === "left" ? -pointerDeltaX : pointerDeltaX;
|
|
2116
|
+
const maxWidth = container.clientWidth;
|
|
2117
|
+
const newWidthInPixels = (0, _maily_to_shared.clamp)(initialWidth + (align === _maily_to_shared.TEXT_ALIGNMENTS.CENTER ? delta * 2 : delta), [0, maxWidth]);
|
|
2118
|
+
nextWidth = (0, _maily_to_shared.clamp)(Math.round((0, _maily_to_shared.percentage)(newWidthInPixels, maxWidth)), [_maily_to_shared.MIN_IMAGE_WIDTH_PERCENTAGE, _maily_to_shared.MAX_IMAGE_WIDTH_PERCENTAGE]);
|
|
2119
|
+
imageWrapper.style.width = `${nextWidth}%`;
|
|
2120
|
+
onWidthChange(nextWidth);
|
|
2121
|
+
};
|
|
2122
|
+
const handlePointerUp = (upEvent) => {
|
|
2123
|
+
activeResizeState = null;
|
|
2124
|
+
setIsResizing(false);
|
|
2125
|
+
releasePointer({
|
|
2126
|
+
element: targetElement,
|
|
2127
|
+
pointerId: upEvent.pointerId
|
|
2128
|
+
});
|
|
2129
|
+
onWidthChange(nextWidth);
|
|
2130
|
+
onWidthCommitted(nextWidth);
|
|
2131
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
2132
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
2133
|
+
};
|
|
2134
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
2135
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
2136
|
+
setIsResizing(true);
|
|
2137
|
+
}, [
|
|
2138
|
+
align,
|
|
2139
|
+
onWidthChange,
|
|
2140
|
+
onWidthCommitted
|
|
2141
|
+
]),
|
|
2142
|
+
imageWrapperRef,
|
|
2143
|
+
isResizing,
|
|
2144
|
+
setShouldShowDragHandles,
|
|
2145
|
+
shouldShowDragHandles
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
//#endregion
|
|
2149
|
+
//#region src/extensions/image/image-handle.tsx
|
|
2150
|
+
function ImageHandle(props) {
|
|
2151
|
+
const { handle, ...rest } = props;
|
|
2152
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2153
|
+
...rest,
|
|
2154
|
+
"data-mly-image-handle": "",
|
|
2155
|
+
"data-side": handle
|
|
2156
|
+
});
|
|
2157
|
+
}
|
|
2158
|
+
//#endregion
|
|
2159
|
+
//#region src/components/interface/visually-hidden.tsx
|
|
2160
|
+
function VisuallyHidden(props) {
|
|
2161
|
+
const { style, ...rest } = props;
|
|
2162
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2163
|
+
"data-mly-visually-hidden": "",
|
|
2164
|
+
...rest,
|
|
2165
|
+
style: {
|
|
2166
|
+
border: 0,
|
|
2167
|
+
clipPath: "inset(50%)",
|
|
2168
|
+
height: 1,
|
|
2169
|
+
margin: -1,
|
|
2170
|
+
overflow: "hidden",
|
|
2171
|
+
padding: 0,
|
|
2172
|
+
position: "absolute",
|
|
2173
|
+
whiteSpace: "nowrap",
|
|
2174
|
+
width: 1,
|
|
2175
|
+
...style
|
|
2176
|
+
}
|
|
2177
|
+
});
|
|
2178
|
+
}
|
|
2179
|
+
//#endregion
|
|
2180
|
+
//#region src/extensions/image/image-state.tsx
|
|
2181
|
+
function ImageState(props) {
|
|
2182
|
+
const { children, icon: Icon, state, ...rest } = props;
|
|
2183
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2184
|
+
...rest,
|
|
2185
|
+
"data-mly-image-state": "",
|
|
2186
|
+
"data-state": state,
|
|
2187
|
+
children: [Icon ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Icon, {
|
|
2188
|
+
size: 16,
|
|
2189
|
+
strokeWidth: 2.5
|
|
2190
|
+
}) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2191
|
+
"data-mly-image-state-label": "",
|
|
2192
|
+
children
|
|
2193
|
+
})]
|
|
2194
|
+
});
|
|
2195
|
+
}
|
|
2196
|
+
function ImageIdleState() {
|
|
2197
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageState, {
|
|
2198
|
+
state: "idle",
|
|
2199
|
+
children: "No image"
|
|
2200
|
+
});
|
|
2201
|
+
}
|
|
2202
|
+
function ImageErrorState() {
|
|
2203
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageState, {
|
|
2204
|
+
role: "alert",
|
|
2205
|
+
state: "error",
|
|
2206
|
+
children: "Failed to upload image"
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
function ImageVariableState() {
|
|
2210
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageState, {
|
|
2211
|
+
state: "variable",
|
|
2212
|
+
children: "Dynamic image source"
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
function ImageLoadingState(props) {
|
|
2216
|
+
const { alt, src } = props;
|
|
2217
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2218
|
+
"aria-busy": "true",
|
|
2219
|
+
"data-mly-image-loading": "",
|
|
2220
|
+
children: [
|
|
2221
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
2222
|
+
alt: alt ?? void 0,
|
|
2223
|
+
"data-mly-image-preview": "",
|
|
2224
|
+
src
|
|
2225
|
+
}),
|
|
2226
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { "data-mly-image-spinner": "" }),
|
|
2227
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(VisuallyHidden, {
|
|
2228
|
+
role: "status",
|
|
2229
|
+
children: "Uploading image"
|
|
2230
|
+
})
|
|
2231
|
+
]
|
|
2232
|
+
});
|
|
2233
|
+
}
|
|
2234
|
+
function ImagePlaceholder(props) {
|
|
2235
|
+
const { onFileSelect } = props;
|
|
2236
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(ImageState, {
|
|
2237
|
+
state: "placeholder",
|
|
2238
|
+
children: ["Click or drop an image here", /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
|
|
2239
|
+
accept: ALLOWED_IMAGE_MIME_TYPES.join(","),
|
|
2240
|
+
"data-mly-image-input": "",
|
|
2241
|
+
onChange: (event) => {
|
|
2242
|
+
const file = event.target.files?.[0];
|
|
2243
|
+
if (file) onFileSelect(file);
|
|
2244
|
+
},
|
|
2245
|
+
type: "file"
|
|
2246
|
+
})]
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
//#endregion
|
|
2250
|
+
//#region src/extensions/image/image-view.tsx
|
|
2251
|
+
function useUploadStatus(editor, src) {
|
|
2252
|
+
const status = (0, _tiptap_react.useEditorState)({
|
|
2253
|
+
editor,
|
|
2254
|
+
selector: (ctx) => src ? ctx.editor.storage.imageUpload?.uploads.get(src) : void 0
|
|
2255
|
+
});
|
|
2256
|
+
if (!src) return IMAGE_UPLOAD_STATUSES.IDLE;
|
|
2257
|
+
return status ?? IMAGE_UPLOAD_STATUSES.LOADED;
|
|
2258
|
+
}
|
|
2259
|
+
function ImageView(props) {
|
|
2260
|
+
const { editor, getPos, node, updateAttributes } = props;
|
|
2261
|
+
const { align, alt, src, width, style } = node.attrs;
|
|
2262
|
+
const { width: _width, maxWidth: _maxWidth, height: _height, ...authoredStyle } = (0, _maily_to_shared.parseInlineStyles)(style ?? "");
|
|
2263
|
+
const isSrcVariable = !!src && (0, _maily_to_shared.hasVariableInText)(src);
|
|
2264
|
+
const status = useUploadStatus(editor, isSrcVariable ? void 0 : src);
|
|
2265
|
+
const { containerRef, handleResize, imageWrapperRef, isResizing, setShouldShowDragHandles, shouldShowDragHandles } = useImageResizeController({
|
|
2266
|
+
align,
|
|
2267
|
+
onWidthCommitted: (0, react.useCallback)((committed) => updateAttributes({ width: `${committed}%` }), [updateAttributes])
|
|
2268
|
+
});
|
|
2269
|
+
const handlePointerDown = (0, react.useCallback)((handle, event) => {
|
|
2270
|
+
const imageWrapper = imageWrapperRef.current;
|
|
2271
|
+
if (!imageWrapper) return;
|
|
2272
|
+
event.preventDefault();
|
|
2273
|
+
handleResize(event, {
|
|
2274
|
+
handleUsed: handle,
|
|
2275
|
+
initialClientX: event.clientX,
|
|
2276
|
+
initialWidth: imageWrapper.clientWidth
|
|
2277
|
+
});
|
|
2278
|
+
}, [handleResize, imageWrapperRef]);
|
|
2279
|
+
const handleFileSelect = (0, react.useCallback)((file) => {
|
|
2280
|
+
const pos = getPos();
|
|
2281
|
+
if (pos == null) return;
|
|
2282
|
+
editor.view.dispatch(editor.state.tr.delete(pos, pos + node.nodeSize));
|
|
2283
|
+
uploadImageFile(editor, file, pos);
|
|
2284
|
+
}, [
|
|
2285
|
+
editor,
|
|
2286
|
+
getPos,
|
|
2287
|
+
node.nodeSize
|
|
2288
|
+
]);
|
|
2289
|
+
const isLoaded = status === IMAGE_UPLOAD_STATUSES.LOADED;
|
|
2290
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, {
|
|
2291
|
+
"data-drag-handle": editor.isEditable && isLoaded,
|
|
2292
|
+
"data-mly-image-view": "",
|
|
2293
|
+
draggable: editor.isEditable && isLoaded,
|
|
2294
|
+
onMouseEnter: () => setShouldShowDragHandles(editor.isEditable),
|
|
2295
|
+
onMouseLeave: () => setShouldShowDragHandles(false),
|
|
2296
|
+
ref: containerRef,
|
|
2297
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2298
|
+
"data-align": align,
|
|
2299
|
+
"data-mly-image-wrapper": "",
|
|
2300
|
+
ref: imageWrapperRef,
|
|
2301
|
+
style: { width },
|
|
2302
|
+
children: [
|
|
2303
|
+
isSrcVariable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageVariableState, {}) : null,
|
|
2304
|
+
!isSrcVariable && status === IMAGE_UPLOAD_STATUSES.IDLE ? editor.isEditable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImagePlaceholder, { onFileSelect: handleFileSelect }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageIdleState, {}) : null,
|
|
2305
|
+
!isSrcVariable && status === IMAGE_UPLOAD_STATUSES.LOADING ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageLoadingState, {
|
|
2306
|
+
alt,
|
|
2307
|
+
src
|
|
2308
|
+
}) : null,
|
|
2309
|
+
status === IMAGE_UPLOAD_STATUSES.ERROR ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageErrorState, {}) : null,
|
|
2310
|
+
!isSrcVariable && isLoaded ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
2311
|
+
alt: alt ?? void 0,
|
|
2312
|
+
contentEditable: false,
|
|
2313
|
+
"data-mly-image": "",
|
|
2314
|
+
draggable: editor.isEditable,
|
|
2315
|
+
src,
|
|
2316
|
+
style: authoredStyle
|
|
2317
|
+
}), shouldShowDragHandles || isResizing ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageHandle, {
|
|
2318
|
+
handle: "left",
|
|
2319
|
+
onPointerDown: (event) => handlePointerDown("left", event)
|
|
2320
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageHandle, {
|
|
2321
|
+
handle: "right",
|
|
2322
|
+
onPointerDown: (event) => handlePointerDown("right", event)
|
|
2323
|
+
})] }) : null] }) : null
|
|
2324
|
+
]
|
|
2325
|
+
})
|
|
2326
|
+
});
|
|
2327
|
+
}
|
|
2328
|
+
//#endregion
|
|
2329
|
+
//#region src/extensions/image/image.ts
|
|
2330
|
+
const DEFAULT_IMAGE_ALIGN = _maily_to_shared.DEFAULT_TEXT_ALIGN;
|
|
2331
|
+
const DEFAULT_IMAGE_WIDTH = "100%";
|
|
2332
|
+
const UNITLESS_REGEX = /^-?\d*\.?\d+$/;
|
|
2333
|
+
const ImageExtension = _tiptap_extension_image.Image.extend({
|
|
2334
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
2335
|
+
addAttributes() {
|
|
2336
|
+
return {
|
|
2337
|
+
...this.parent?.(),
|
|
2338
|
+
width: {
|
|
2339
|
+
default: DEFAULT_IMAGE_WIDTH,
|
|
2340
|
+
parseHTML: (element) => {
|
|
2341
|
+
const width = element.style.width || element.getAttribute("width");
|
|
2342
|
+
if (!width) return DEFAULT_IMAGE_WIDTH;
|
|
2343
|
+
return UNITLESS_REGEX.test(width) ? `${width}px` : width;
|
|
2344
|
+
},
|
|
2345
|
+
renderHTML: (attributes) => ({ width: attributes.width })
|
|
2346
|
+
},
|
|
2347
|
+
align: {
|
|
2348
|
+
default: DEFAULT_IMAGE_ALIGN,
|
|
2349
|
+
parseHTML: (element) => {
|
|
2350
|
+
const align = element.getAttribute("data-align");
|
|
2351
|
+
return (0, _maily_to_shared.isAllowedTextAlignment)(align) ? align : DEFAULT_IMAGE_ALIGN;
|
|
2352
|
+
},
|
|
2353
|
+
renderHTML: (attributes) => ({ "data-align": attributes.align })
|
|
2354
|
+
},
|
|
2355
|
+
externalLink: {
|
|
2356
|
+
default: null,
|
|
2357
|
+
parseHTML: (element) => element.getAttribute("data-external-link"),
|
|
2358
|
+
renderHTML: (attributes) => attributes.externalLink ? { "data-external-link": attributes.externalLink } : {}
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2361
|
+
},
|
|
2362
|
+
addNodeView() {
|
|
2363
|
+
return (0, _tiptap_react.ReactNodeViewRenderer)(ImageView, { attrs: () => ({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.IMAGE }) });
|
|
2364
|
+
}
|
|
2365
|
+
}).configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.IMAGE } });
|
|
2366
|
+
//#endregion
|
|
2367
|
+
//#region src/extensions/inline-image/inline-image.ts
|
|
2368
|
+
const DEFAULT_INLINE_IMAGE_SIZE = 20;
|
|
2369
|
+
const INLINE_PARENTS = /* @__PURE__ */ new Set([
|
|
2370
|
+
"A",
|
|
2371
|
+
"B",
|
|
2372
|
+
"EM",
|
|
2373
|
+
"I",
|
|
2374
|
+
"SPAN",
|
|
2375
|
+
"STRONG"
|
|
2376
|
+
]);
|
|
2377
|
+
const InlineImageExtension = _tiptap_core.Node.create({
|
|
2378
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE,
|
|
2379
|
+
group: "inline",
|
|
2380
|
+
inline: true,
|
|
2381
|
+
atom: true,
|
|
2382
|
+
selectable: true,
|
|
2383
|
+
addOptions() {
|
|
2384
|
+
return { HTMLAttributes: {} };
|
|
2385
|
+
},
|
|
2386
|
+
addAttributes() {
|
|
2387
|
+
return {
|
|
2388
|
+
src: {
|
|
2389
|
+
default: "",
|
|
2390
|
+
parseHTML: (element) => element.getAttribute("src") || "",
|
|
2391
|
+
renderHTML: (attributes) => attributes.src ? { src: attributes.src } : {}
|
|
2392
|
+
},
|
|
2393
|
+
alt: {
|
|
2394
|
+
default: null,
|
|
2395
|
+
parseHTML: (element) => element.getAttribute("alt"),
|
|
2396
|
+
renderHTML: (attributes) => attributes.alt ? { alt: attributes.alt } : {}
|
|
2397
|
+
},
|
|
2398
|
+
title: {
|
|
2399
|
+
default: null,
|
|
2400
|
+
parseHTML: (element) => element.getAttribute("title"),
|
|
2401
|
+
renderHTML: (attributes) => attributes.title ? { title: attributes.title } : {}
|
|
2402
|
+
},
|
|
2403
|
+
width: {
|
|
2404
|
+
default: DEFAULT_INLINE_IMAGE_SIZE,
|
|
2405
|
+
parseHTML: (element) => Number(element.getAttribute("width")) || DEFAULT_INLINE_IMAGE_SIZE,
|
|
2406
|
+
renderHTML: (attributes) => ({ width: attributes.width })
|
|
2407
|
+
},
|
|
2408
|
+
height: {
|
|
2409
|
+
default: DEFAULT_INLINE_IMAGE_SIZE,
|
|
2410
|
+
parseHTML: (element) => Number(element.getAttribute("height")) || DEFAULT_INLINE_IMAGE_SIZE,
|
|
2411
|
+
renderHTML: (attributes) => ({ height: attributes.height })
|
|
2412
|
+
},
|
|
2413
|
+
externalLink: {
|
|
2414
|
+
default: null,
|
|
2415
|
+
parseHTML: (element) => element.getAttribute("data-external-link"),
|
|
2416
|
+
renderHTML: (attributes) => attributes.externalLink ? { "data-external-link": attributes.externalLink } : {}
|
|
2417
|
+
}
|
|
2418
|
+
};
|
|
2419
|
+
},
|
|
2420
|
+
addCommands() {
|
|
2421
|
+
return {
|
|
2422
|
+
setInlineImage: (attrs) => ({ commands }) => commands.insertContent({
|
|
2423
|
+
type: this.name,
|
|
2424
|
+
attrs
|
|
2425
|
+
}),
|
|
2426
|
+
updateInlineImageAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
2427
|
+
};
|
|
2428
|
+
},
|
|
2429
|
+
parseHTML() {
|
|
2430
|
+
return [{ tag: `img[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }, {
|
|
2431
|
+
tag: "img[src]",
|
|
2432
|
+
priority: 60,
|
|
2433
|
+
getAttrs: (element) => {
|
|
2434
|
+
const parent = element.parentElement;
|
|
2435
|
+
return parent && INLINE_PARENTS.has(parent.tagName) ? null : false;
|
|
2436
|
+
}
|
|
2437
|
+
}];
|
|
2438
|
+
},
|
|
2439
|
+
renderHTML({ HTMLAttributes }) {
|
|
2440
|
+
return ["img", (0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes)];
|
|
2441
|
+
}
|
|
2442
|
+
});
|
|
2443
|
+
//#endregion
|
|
2444
|
+
//#region src/extensions/inline-span/inline-span.ts
|
|
2445
|
+
const InlineSpanExtension = _tiptap_core.Node.create({
|
|
2446
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.INLINE_SPAN,
|
|
2447
|
+
group: "inline",
|
|
2448
|
+
inline: true,
|
|
2449
|
+
atom: true,
|
|
2450
|
+
selectable: true,
|
|
2451
|
+
parseHTML() {
|
|
2452
|
+
return [{
|
|
2453
|
+
tag: "span[style]",
|
|
2454
|
+
priority: 60,
|
|
2455
|
+
getAttrs: (element) => {
|
|
2456
|
+
return element.childNodes.length === 0 ? null : false;
|
|
2457
|
+
}
|
|
2458
|
+
}];
|
|
2459
|
+
},
|
|
2460
|
+
renderHTML({ HTMLAttributes }) {
|
|
2461
|
+
return ["span", (0, _tiptap_core.mergeAttributes)(HTMLAttributes)];
|
|
2462
|
+
}
|
|
2463
|
+
});
|
|
2464
|
+
//#endregion
|
|
2465
|
+
//#region src/extensions/paragraph/paragraph.ts
|
|
2466
|
+
const ParagraphExtension = _tiptap_extension_paragraph.Paragraph.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH } });
|
|
2467
|
+
//#endregion
|
|
2468
|
+
//#region src/extensions/placeholder/placeholder.ts
|
|
2469
|
+
const PlaceholderExtension = _tiptap_extensions.Placeholder.configure({
|
|
2470
|
+
placeholder: ({ node }) => {
|
|
2471
|
+
const { name } = node.type;
|
|
2472
|
+
if (name === _maily_to_shared.MAILY_NODE_TYPES.HEADING) return `Heading ${node.attrs.level}`;
|
|
2473
|
+
else if (name === _maily_to_shared.MAILY_NODE_TYPES.HTML_CODE_BLOCK) return "Type your HTML code...";
|
|
2474
|
+
else if ([
|
|
2475
|
+
_maily_to_shared.MAILY_NODE_TYPES.BUTTON,
|
|
2476
|
+
_maily_to_shared.MAILY_NODE_TYPES.SECTION,
|
|
2477
|
+
_maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST,
|
|
2478
|
+
_maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST,
|
|
2479
|
+
_maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM,
|
|
2480
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
2481
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
2482
|
+
_maily_to_shared.MAILY_NODE_TYPES.REPEAT,
|
|
2483
|
+
_maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE
|
|
2484
|
+
].includes(name)) return "";
|
|
2485
|
+
return "Write something or / to see commands";
|
|
2486
|
+
},
|
|
2487
|
+
includeChildren: true
|
|
2488
|
+
});
|
|
2489
|
+
//#endregion
|
|
2490
|
+
//#region src/extensions/section/section.ts
|
|
2491
|
+
const SectionExtension = _tiptap_core.Node.create({
|
|
2492
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.SECTION,
|
|
2493
|
+
group: "block",
|
|
2494
|
+
content: "block+",
|
|
2495
|
+
defining: true,
|
|
2496
|
+
isolating: true,
|
|
2497
|
+
addCommands() {
|
|
2498
|
+
return {
|
|
2499
|
+
setSection: () => ({ commands }) => commands.insertContent({
|
|
2500
|
+
type: this.name,
|
|
2501
|
+
content: [{ type: _maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH }]
|
|
2502
|
+
}),
|
|
2503
|
+
updateSection: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
2504
|
+
};
|
|
2505
|
+
},
|
|
2506
|
+
addKeyboardShortcuts() {
|
|
2507
|
+
return { Enter: ({ editor }) => {
|
|
2508
|
+
return exitOnTripleEnter({
|
|
2509
|
+
editor,
|
|
2510
|
+
nodeName: this.name
|
|
2511
|
+
});
|
|
2512
|
+
} };
|
|
2513
|
+
},
|
|
2514
|
+
parseHTML() {
|
|
2515
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.SECTION}"]` }];
|
|
2516
|
+
},
|
|
2517
|
+
renderHTML({ HTMLAttributes }) {
|
|
2518
|
+
return [
|
|
2519
|
+
"div",
|
|
2520
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.SECTION }, HTMLAttributes),
|
|
2521
|
+
0
|
|
2522
|
+
];
|
|
2523
|
+
}
|
|
2524
|
+
});
|
|
2525
|
+
//#endregion
|
|
2526
|
+
//#region src/extensions/slash-command/default-slash-commands.tsx
|
|
2527
|
+
const DEFAULT_SLASH_COMMANDS = [{
|
|
2528
|
+
title: "Blocks",
|
|
2529
|
+
commands: [
|
|
2530
|
+
require_typography.text,
|
|
2531
|
+
require_typography.heading1,
|
|
2532
|
+
require_typography.heading2,
|
|
2533
|
+
require_typography.heading3,
|
|
2534
|
+
require_typography.bulletList,
|
|
2535
|
+
require_typography.orderedList,
|
|
2536
|
+
require_typography.blockquote,
|
|
2537
|
+
require_typography.image,
|
|
2538
|
+
require_typography.inlineImage,
|
|
2539
|
+
require_typography.divider,
|
|
2540
|
+
require_typography.spacer,
|
|
2541
|
+
require_typography.section,
|
|
2542
|
+
require_typography.columns,
|
|
2543
|
+
require_typography.repeat,
|
|
2544
|
+
require_typography.button,
|
|
2545
|
+
require_typography.linkCard,
|
|
2546
|
+
require_typography.footer,
|
|
2547
|
+
require_typography.hardBreak,
|
|
2548
|
+
require_typography.clearLine
|
|
2549
|
+
]
|
|
2550
|
+
}, {
|
|
2551
|
+
title: "Components",
|
|
2552
|
+
commands: [
|
|
2553
|
+
{
|
|
2554
|
+
id: "headers",
|
|
2555
|
+
title: "Headers",
|
|
2556
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Heading1Icon, { size: 16 }),
|
|
2557
|
+
description: "Pre-designed headers block",
|
|
2558
|
+
searchTerms: ["header", "headers"],
|
|
2559
|
+
commands: [
|
|
2560
|
+
require_typography.headerLogoWithTextVertical,
|
|
2561
|
+
require_typography.headerLogoWithTextHorizontal,
|
|
2562
|
+
require_typography.headerLogoWithCoverImage
|
|
2563
|
+
]
|
|
2564
|
+
},
|
|
2565
|
+
{
|
|
2566
|
+
id: "footers",
|
|
2567
|
+
title: "Footers",
|
|
2568
|
+
icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.FootprintsIcon, { size: 16 }),
|
|
2569
|
+
description: "Pre-designed footers block",
|
|
2570
|
+
searchTerms: ["footer", "footers"],
|
|
2571
|
+
commands: [
|
|
2572
|
+
require_typography.footerCopyrightText,
|
|
2573
|
+
require_typography.footerCommunityFeedbackCta,
|
|
2574
|
+
require_typography.footerCompanySignature
|
|
2575
|
+
]
|
|
2576
|
+
},
|
|
2577
|
+
require_typography.htmlCodeBlock
|
|
2578
|
+
]
|
|
2579
|
+
}];
|
|
2580
|
+
//#endregion
|
|
2581
|
+
//#region src/utils/slash-command.ts
|
|
2582
|
+
const SLASH_COMMAND_SUGGESTION_POPOVER_ID = "mly-slash-command-suggestion-popover";
|
|
2583
|
+
function isNestedCommand(item) {
|
|
2584
|
+
return "commands" in item && Array.isArray(item.commands) && !!item.id;
|
|
2585
|
+
}
|
|
2586
|
+
function match(item, search) {
|
|
2587
|
+
return item.title.toLowerCase().includes(search) || (item.description?.toLowerCase().includes(search) ?? false) || item.searchTerms.some((term) => term.toLowerCase().includes(search));
|
|
2588
|
+
}
|
|
2589
|
+
function findNestedCommand(groups, id) {
|
|
2590
|
+
const lowerId = id.toLowerCase();
|
|
2591
|
+
for (const group of groups) for (const command of group.commands) if (isNestedCommand(command) && command.id.toLowerCase() === lowerId) return command;
|
|
2592
|
+
}
|
|
2593
|
+
function getVisibleGroups(options) {
|
|
2594
|
+
const { editor, groups } = options;
|
|
2595
|
+
const isVisible = (item) => {
|
|
2596
|
+
return item.render?.(editor) !== null;
|
|
2597
|
+
};
|
|
2598
|
+
return groups.map((group) => {
|
|
2599
|
+
return {
|
|
2600
|
+
...group,
|
|
2601
|
+
commands: group.commands.filter(isVisible).map((item) => {
|
|
2602
|
+
return isNestedCommand(item) ? {
|
|
2603
|
+
...item,
|
|
2604
|
+
commands: item.commands.filter(isVisible)
|
|
2605
|
+
} : item;
|
|
2606
|
+
})
|
|
2607
|
+
};
|
|
2608
|
+
});
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2611
|
+
* Filters slash command groups by query. Supports nested commands
|
|
2612
|
+
* via dot notation (e.g. "headers.h1"). When a nested group matches,
|
|
2613
|
+
* it's expanded inline and made navigable.
|
|
2614
|
+
*/
|
|
2615
|
+
function filterSlashCommands(options) {
|
|
2616
|
+
const { editor, query } = options;
|
|
2617
|
+
const groups = getVisibleGroups({
|
|
2618
|
+
editor,
|
|
2619
|
+
groups: options.groups
|
|
2620
|
+
});
|
|
2621
|
+
const search = query.toLowerCase();
|
|
2622
|
+
const subCommandMatch = /^([^.]+)\./.exec(search);
|
|
2623
|
+
if (subCommandMatch) {
|
|
2624
|
+
const [fullMatch, subCommandId] = subCommandMatch;
|
|
2625
|
+
const subCommand = findNestedCommand(groups, subCommandId);
|
|
2626
|
+
if (!subCommand) return [];
|
|
2627
|
+
const remainingSearch = search.slice(fullMatch.length);
|
|
2628
|
+
const filtered = subCommand.commands.filter((item) => !remainingSearch || match(item, remainingSearch));
|
|
2629
|
+
return filtered.length ? [{
|
|
2630
|
+
...subCommand,
|
|
2631
|
+
commands: filtered
|
|
2632
|
+
}] : [];
|
|
2633
|
+
}
|
|
2634
|
+
return groups.map((group) => ({
|
|
2635
|
+
...group,
|
|
2636
|
+
commands: group.commands.flatMap((item) => {
|
|
2637
|
+
if (!isNestedCommand(item)) return !search || match(item, search) ? [item] : [];
|
|
2638
|
+
const navigable = {
|
|
2639
|
+
...item,
|
|
2640
|
+
command: ({ editor, range }) => {
|
|
2641
|
+
editor.chain().focus().insertContentAt(range, `/${item.id}.`).run();
|
|
2642
|
+
}
|
|
2643
|
+
};
|
|
2644
|
+
if (match(navigable, search)) return [navigable];
|
|
2645
|
+
return item.commands.some((child) => match(child, search)) ? item.commands : [];
|
|
2646
|
+
})
|
|
2647
|
+
})).filter((group) => group.commands.length > 0);
|
|
2648
|
+
}
|
|
2649
|
+
//#endregion
|
|
2650
|
+
//#region src/hooks/use-delayed-state.ts
|
|
2651
|
+
function useDelayedState(isOpen, options = {}) {
|
|
2652
|
+
const { delay = 200 } = options;
|
|
2653
|
+
const [value, setValue] = (0, react.useState)(false);
|
|
2654
|
+
const timerRef = (0, react.useRef)(0);
|
|
2655
|
+
(0, react.useEffect)(() => {
|
|
2656
|
+
window.clearTimeout(timerRef.current);
|
|
2657
|
+
if (!isOpen) {
|
|
2658
|
+
timerRef.current = 0;
|
|
2659
|
+
setValue(false);
|
|
2660
|
+
return;
|
|
2661
|
+
}
|
|
2662
|
+
timerRef.current = window.setTimeout(() => {
|
|
2663
|
+
setValue(true);
|
|
2664
|
+
timerRef.current = 0;
|
|
2665
|
+
}, delay);
|
|
2666
|
+
return () => {
|
|
2667
|
+
if (!timerRef.current) return;
|
|
2668
|
+
window.clearTimeout(timerRef.current);
|
|
2669
|
+
timerRef.current = 0;
|
|
2670
|
+
};
|
|
2671
|
+
}, [delay, isOpen]);
|
|
2672
|
+
return value;
|
|
2673
|
+
}
|
|
2674
|
+
//#endregion
|
|
2675
|
+
//#region src/extensions/slash-command/slash-command-item.tsx
|
|
2676
|
+
function SlashCommandItem(props) {
|
|
2677
|
+
const { editor, hoveredKey, isSelected, item, itemKey, onHover, ...rest } = props;
|
|
2678
|
+
const isHovered = hoveredKey === itemKey;
|
|
2679
|
+
const isNested = "commands" in item;
|
|
2680
|
+
const open = useDelayedState(Boolean(item.preview) && (isHovered || isSelected && !hoveredKey));
|
|
2681
|
+
const rendered = item.render ? item.render(editor) : null;
|
|
2682
|
+
const isCustomRow = rendered !== null && rendered !== true && rendered !== void 0;
|
|
2683
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Tooltip, {
|
|
2684
|
+
open,
|
|
2685
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipTrigger, { render: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
2686
|
+
...rest,
|
|
2687
|
+
"data-mly-slash-command-item": "",
|
|
2688
|
+
"data-selected": isSelected ? "" : void 0,
|
|
2689
|
+
onMouseEnter: () => onHover(true),
|
|
2690
|
+
onMouseLeave: () => onHover(false),
|
|
2691
|
+
type: "button",
|
|
2692
|
+
children: isCustomRow ? rendered : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2693
|
+
item.icon ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2694
|
+
"data-mly-slash-command-icon": "",
|
|
2695
|
+
children: item.icon
|
|
2696
|
+
}) : null,
|
|
2697
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
|
|
2698
|
+
"data-mly-slash-command-text": "",
|
|
2699
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2700
|
+
"data-mly-slash-command-title": "",
|
|
2701
|
+
children: item.title
|
|
2702
|
+
}), item.description ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2703
|
+
"data-mly-slash-command-description": "",
|
|
2704
|
+
children: item.description
|
|
2705
|
+
}) : null]
|
|
2706
|
+
}),
|
|
2707
|
+
isNested ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2708
|
+
"data-mly-slash-command-chevron": "",
|
|
2709
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRightIcon, {
|
|
2710
|
+
size: 14,
|
|
2711
|
+
strokeWidth: 2.5
|
|
2712
|
+
})
|
|
2713
|
+
}) : null
|
|
2714
|
+
] })
|
|
2715
|
+
}) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipPositioner, {
|
|
2716
|
+
side: "right",
|
|
2717
|
+
sideOffset: 8,
|
|
2718
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TooltipPopup, {
|
|
2719
|
+
"data-variant": "preview",
|
|
2720
|
+
children: typeof item.preview === "function" ? item.preview(editor) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("figure", {
|
|
2721
|
+
"data-mly-slash-command-preview": "",
|
|
2722
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
2723
|
+
alt: item.title,
|
|
2724
|
+
src: item.preview
|
|
2725
|
+
})
|
|
2726
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
|
|
2727
|
+
"data-mly-slash-command-preview-description": "",
|
|
2728
|
+
children: item.description
|
|
2729
|
+
})] })
|
|
2730
|
+
})
|
|
2731
|
+
})]
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
//#endregion
|
|
2735
|
+
//#region src/extensions/slash-command/slash-command-suggestion-list.tsx
|
|
2736
|
+
const NAVIGATION_KEYS = /* @__PURE__ */ new Set([
|
|
2737
|
+
ARROW_UP,
|
|
2738
|
+
ARROW_DOWN,
|
|
2739
|
+
ENTER,
|
|
2740
|
+
HOME,
|
|
2741
|
+
"End"
|
|
2742
|
+
]);
|
|
2743
|
+
const SlashCommandSuggestionList = (0, react.forwardRef)((props, ref) => {
|
|
2744
|
+
const { command: selectItem, editor, items: groups } = props;
|
|
2745
|
+
const flattened = groups.flatMap((group) => group.commands);
|
|
2746
|
+
const [selectedIndex, setSelectedIndex] = (0, react.useState)(0);
|
|
2747
|
+
const [hoveredKey, setHoveredKey] = (0, react.useState)(null);
|
|
2748
|
+
const [prevGroups, setPrevGroups] = (0, react.useState)(groups);
|
|
2749
|
+
const { activeRef: activeItemRef, containerRef: scrollContainerRef } = useScrollIntoView([selectedIndex]);
|
|
2750
|
+
if (prevGroups !== groups) {
|
|
2751
|
+
setPrevGroups(groups);
|
|
2752
|
+
setSelectedIndex(0);
|
|
2753
|
+
if (scrollContainerRef.current) scrollContainerRef.current.scrollTop = 0;
|
|
2754
|
+
}
|
|
2755
|
+
const selectCommand = (item) => {
|
|
2756
|
+
selectItem(item);
|
|
2757
|
+
};
|
|
2758
|
+
(0, react.useImperativeHandle)(ref, () => ({ onKeyDown: ({ event }) => {
|
|
2759
|
+
if (!NAVIGATION_KEYS.has(event.key) || !flattened.length) return false;
|
|
2760
|
+
let newIndex = selectedIndex;
|
|
2761
|
+
let shouldSelect = false;
|
|
2762
|
+
switch (event.key) {
|
|
2763
|
+
case HOME:
|
|
2764
|
+
newIndex = 0;
|
|
2765
|
+
break;
|
|
2766
|
+
case "End":
|
|
2767
|
+
newIndex = flattened.length - 1;
|
|
2768
|
+
break;
|
|
2769
|
+
case ARROW_UP:
|
|
2770
|
+
newIndex = (selectedIndex + flattened.length - 1) % flattened.length;
|
|
2771
|
+
break;
|
|
2772
|
+
case ARROW_DOWN:
|
|
2773
|
+
newIndex = (selectedIndex + 1) % flattened.length;
|
|
2774
|
+
break;
|
|
2775
|
+
case ENTER:
|
|
2776
|
+
shouldSelect = true;
|
|
2777
|
+
break;
|
|
2778
|
+
default: return false;
|
|
2779
|
+
}
|
|
2780
|
+
event.preventDefault();
|
|
2781
|
+
if (shouldSelect) {
|
|
2782
|
+
const item = flattened[selectedIndex];
|
|
2783
|
+
if (item) selectCommand(item);
|
|
2784
|
+
return true;
|
|
2785
|
+
}
|
|
2786
|
+
if (newIndex !== selectedIndex) setSelectedIndex(newIndex);
|
|
2787
|
+
return true;
|
|
2788
|
+
} }));
|
|
2789
|
+
if (!groups || groups.length === 0) return null;
|
|
2790
|
+
let itemIndex = -1;
|
|
2791
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(SuggestionWrapper, {
|
|
2792
|
+
"data-variant": "slash-command",
|
|
2793
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2794
|
+
"data-mly-suggestion-body": "",
|
|
2795
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2796
|
+
"data-axis": "y",
|
|
2797
|
+
"data-mly-scroll-fade": "",
|
|
2798
|
+
"data-mly-suggestion-scroll": "",
|
|
2799
|
+
ref: scrollContainerRef,
|
|
2800
|
+
children: groups.map((group, groupIndex) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2801
|
+
"data-first": groupIndex === 0 ? "" : void 0,
|
|
2802
|
+
"data-mly-slash-command-group": "",
|
|
2803
|
+
children: group.title
|
|
2804
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2805
|
+
"data-mly-suggestion-items": "",
|
|
2806
|
+
children: group.commands.map((item) => {
|
|
2807
|
+
itemIndex += 1;
|
|
2808
|
+
const isSelected = itemIndex === selectedIndex;
|
|
2809
|
+
const itemKey = `${groupIndex}-${itemIndex}`;
|
|
2810
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SlashCommandItem, {
|
|
2811
|
+
editor,
|
|
2812
|
+
hoveredKey,
|
|
2813
|
+
isSelected,
|
|
2814
|
+
item,
|
|
2815
|
+
itemKey,
|
|
2816
|
+
onClick: () => selectCommand(item),
|
|
2817
|
+
onHover: (isHovered) => setHoveredKey(isHovered ? itemKey : null),
|
|
2818
|
+
ref: isSelected ? activeItemRef : null
|
|
2819
|
+
}, item.title);
|
|
2820
|
+
})
|
|
2821
|
+
})] }, group.title))
|
|
2822
|
+
})
|
|
2823
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SuggestionFooter, {})]
|
|
2824
|
+
});
|
|
2825
|
+
});
|
|
2826
|
+
SlashCommandSuggestionList.displayName = "SlashCommandSuggestionList";
|
|
2827
|
+
//#endregion
|
|
2828
|
+
//#region src/extensions/slash-command/slash-command-suggestion.ts
|
|
2829
|
+
async function updatePosition(editor, element, range) {
|
|
2830
|
+
const position = await (0, _floating_ui_react.computePosition)({ getBoundingClientRect: () => (0, _tiptap_react.posToDOMRect)(editor.view, range.from, range.to) }, element, {
|
|
2831
|
+
placement: "bottom-start",
|
|
2832
|
+
strategy: "absolute",
|
|
2833
|
+
middleware: [
|
|
2834
|
+
(0, _floating_ui_react.shift)(),
|
|
2835
|
+
(0, _floating_ui_react.flip)(),
|
|
2836
|
+
(0, _floating_ui_react.offset)(8)
|
|
2837
|
+
]
|
|
2838
|
+
});
|
|
2839
|
+
element.style.width = "max-content";
|
|
2840
|
+
element.style.position = position.strategy;
|
|
2841
|
+
element.style.left = `${position.x}px`;
|
|
2842
|
+
element.style.top = `${position.y}px`;
|
|
2843
|
+
element.style.zIndex = "9999";
|
|
2844
|
+
}
|
|
2845
|
+
function getSlashCommandSuggestions() {
|
|
2846
|
+
return {
|
|
2847
|
+
char: "/",
|
|
2848
|
+
items: ({ editor, query }) => filterSlashCommands({
|
|
2849
|
+
editor,
|
|
2850
|
+
groups: editor.storage.slashCommand?.commands ?? [],
|
|
2851
|
+
query
|
|
2852
|
+
}),
|
|
2853
|
+
command: ({ editor, props, range }) => {
|
|
2854
|
+
props.command({
|
|
2855
|
+
editor,
|
|
2856
|
+
range
|
|
2857
|
+
});
|
|
2858
|
+
},
|
|
2859
|
+
render: () => {
|
|
2860
|
+
let component = null;
|
|
2861
|
+
return {
|
|
2862
|
+
onStart: async (props) => {
|
|
2863
|
+
const { editor, range } = props;
|
|
2864
|
+
const parentElement = editor.view.dom.parentElement;
|
|
2865
|
+
if (!parentElement) return;
|
|
2866
|
+
component = new _tiptap_react.ReactRenderer(SlashCommandSuggestionList, {
|
|
2867
|
+
editor,
|
|
2868
|
+
props
|
|
2869
|
+
});
|
|
2870
|
+
if (!props.clientRect) return;
|
|
2871
|
+
component.element.style.position = "absolute";
|
|
2872
|
+
component.element.id = SLASH_COMMAND_SUGGESTION_POPOVER_ID;
|
|
2873
|
+
parentElement.append(component.element);
|
|
2874
|
+
await updatePosition(editor, component.element, range);
|
|
2875
|
+
},
|
|
2876
|
+
onUpdate: async (props) => {
|
|
2877
|
+
const { editor, range } = props;
|
|
2878
|
+
if (!component) return;
|
|
2879
|
+
component.updateProps(props);
|
|
2880
|
+
if (!props.clientRect) return;
|
|
2881
|
+
await updatePosition(editor, component.element, range);
|
|
2882
|
+
},
|
|
2883
|
+
onKeyDown(props) {
|
|
2884
|
+
if (!component) return false;
|
|
2885
|
+
if (props.event.key === "Escape") {
|
|
2886
|
+
component.destroy();
|
|
2887
|
+
return true;
|
|
2888
|
+
}
|
|
2889
|
+
return component.ref?.onKeyDown(props) ?? false;
|
|
2890
|
+
},
|
|
2891
|
+
onExit() {
|
|
2892
|
+
if (!component) return;
|
|
2893
|
+
component.element.remove();
|
|
2894
|
+
component.destroy();
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
}
|
|
2898
|
+
};
|
|
2899
|
+
}
|
|
2900
|
+
//#endregion
|
|
2901
|
+
//#region src/extensions/slash-command/slash-command.ts
|
|
2902
|
+
const SlashCommandExtension = _tiptap_core.Extension.create({
|
|
2903
|
+
name: "slashCommand",
|
|
2904
|
+
priority: 101,
|
|
2905
|
+
addOptions() {
|
|
2906
|
+
return {
|
|
2907
|
+
commands: DEFAULT_SLASH_COMMANDS,
|
|
2908
|
+
suggestion: getSlashCommandSuggestions()
|
|
2909
|
+
};
|
|
2910
|
+
},
|
|
2911
|
+
addStorage() {
|
|
2912
|
+
return { commands: this.options.commands };
|
|
2913
|
+
},
|
|
2914
|
+
addProseMirrorPlugins() {
|
|
2915
|
+
return [(0, _tiptap_suggestion.Suggestion)({
|
|
2916
|
+
editor: this.editor,
|
|
2917
|
+
...this.options.suggestion
|
|
2918
|
+
})];
|
|
2919
|
+
}
|
|
2920
|
+
});
|
|
2921
|
+
//#endregion
|
|
2922
|
+
//#region src/hooks/use-spacer-resize-controller.ts
|
|
2923
|
+
function useSpacerResizeController(options) {
|
|
2924
|
+
const { height, onHeightChange = _maily_to_shared.noop, onHeightCommitted = _maily_to_shared.noop } = options;
|
|
2925
|
+
const containerRef = (0, react.useRef)(null);
|
|
2926
|
+
const spacerWrapperRef = (0, react.useRef)(null);
|
|
2927
|
+
const [shouldShowDragHandles, setShouldShowDragHandles] = (0, react.useState)(false);
|
|
2928
|
+
const [isResizing, setIsResizing] = (0, react.useState)(false);
|
|
2929
|
+
const heightRef = useValueAsRef(height);
|
|
2930
|
+
return {
|
|
2931
|
+
containerRef,
|
|
2932
|
+
handleResize: (0, react.useCallback)((event, initialResizeParams) => {
|
|
2933
|
+
let activeResizeState = initialResizeParams;
|
|
2934
|
+
let nextHeight = heightRef.current;
|
|
2935
|
+
const targetElement = event.currentTarget;
|
|
2936
|
+
capturePointer({
|
|
2937
|
+
element: targetElement,
|
|
2938
|
+
pointerId: event.pointerId
|
|
2939
|
+
});
|
|
2940
|
+
const handlePointerMove = (moveEvent) => {
|
|
2941
|
+
const spacerWrapper = spacerWrapperRef.current;
|
|
2942
|
+
if (!activeResizeState || !spacerWrapper) return;
|
|
2943
|
+
const pointerDeltaY = moveEvent.clientY - activeResizeState.initialClientY;
|
|
2944
|
+
const { handleUsed, initialHeight } = activeResizeState;
|
|
2945
|
+
const delta = handleUsed === "top" ? -pointerDeltaY : pointerDeltaY;
|
|
2946
|
+
nextHeight = (0, _maily_to_shared.clamp)(Math.round(initialHeight + delta), [1, MAX_SPACER_HEIGHT]);
|
|
2947
|
+
spacerWrapper.style.height = `${nextHeight}px`;
|
|
2948
|
+
onHeightChange(nextHeight);
|
|
2949
|
+
};
|
|
2950
|
+
const handlePointerUp = (upEvent) => {
|
|
2951
|
+
activeResizeState = null;
|
|
2952
|
+
setIsResizing(false);
|
|
2953
|
+
releasePointer({
|
|
2954
|
+
element: targetElement,
|
|
2955
|
+
pointerId: upEvent.pointerId
|
|
2956
|
+
});
|
|
2957
|
+
onHeightChange(nextHeight);
|
|
2958
|
+
onHeightCommitted(nextHeight);
|
|
2959
|
+
window.removeEventListener("pointermove", handlePointerMove);
|
|
2960
|
+
window.removeEventListener("pointerup", handlePointerUp);
|
|
2961
|
+
};
|
|
2962
|
+
window.addEventListener("pointermove", handlePointerMove);
|
|
2963
|
+
window.addEventListener("pointerup", handlePointerUp);
|
|
2964
|
+
setIsResizing(true);
|
|
2965
|
+
}, [
|
|
2966
|
+
heightRef,
|
|
2967
|
+
onHeightChange,
|
|
2968
|
+
onHeightCommitted
|
|
2969
|
+
]),
|
|
2970
|
+
isResizing,
|
|
2971
|
+
setShouldShowDragHandles,
|
|
2972
|
+
shouldShowDragHandles,
|
|
2973
|
+
spacerWrapperRef
|
|
2974
|
+
};
|
|
2975
|
+
}
|
|
2976
|
+
//#endregion
|
|
2977
|
+
//#region src/extensions/spacer/spacer-handle.tsx
|
|
2978
|
+
function SpacerHandle(props) {
|
|
2979
|
+
const { handle, ...rest } = props;
|
|
2980
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2981
|
+
...rest,
|
|
2982
|
+
"data-mly-spacer-handle": "",
|
|
2983
|
+
"data-side": handle
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
//#endregion
|
|
2987
|
+
//#region src/extensions/spacer/spacer-view.tsx
|
|
2988
|
+
function SpacerView(props) {
|
|
2989
|
+
const { editor, getPos, node, updateAttributes } = props;
|
|
2990
|
+
const { height } = node.attrs;
|
|
2991
|
+
const { containerRef, handleResize, isResizing, setShouldShowDragHandles, shouldShowDragHandles, spacerWrapperRef } = useSpacerResizeController({
|
|
2992
|
+
height,
|
|
2993
|
+
onHeightCommitted: (0, react.useCallback)((committed) => updateAttributes({ height: committed }), [updateAttributes])
|
|
2994
|
+
});
|
|
2995
|
+
const handlePointerDown = (0, react.useCallback)((handle, event) => {
|
|
2996
|
+
const spacerWrapper = spacerWrapperRef.current;
|
|
2997
|
+
if (!spacerWrapper) return;
|
|
2998
|
+
event.preventDefault();
|
|
2999
|
+
handleResize(event, {
|
|
3000
|
+
handleUsed: handle,
|
|
3001
|
+
initialClientY: event.clientY,
|
|
3002
|
+
initialHeight: spacerWrapper.clientHeight
|
|
3003
|
+
});
|
|
3004
|
+
}, [handleResize, spacerWrapperRef]);
|
|
3005
|
+
const handleSelect = (0, react.useCallback)(() => {
|
|
3006
|
+
const position = getPos();
|
|
3007
|
+
if (typeof position !== "number") return;
|
|
3008
|
+
editor.commands.setNodeSelection(position);
|
|
3009
|
+
}, [editor, getPos]);
|
|
3010
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, {
|
|
3011
|
+
"data-drag-handle": editor.isEditable,
|
|
3012
|
+
"data-mly-spacer-view": "",
|
|
3013
|
+
draggable: editor.isEditable,
|
|
3014
|
+
onMouseEnter: () => setShouldShowDragHandles(editor.isEditable),
|
|
3015
|
+
onMouseLeave: () => setShouldShowDragHandles(false),
|
|
3016
|
+
onPointerDown: handleSelect,
|
|
3017
|
+
ref: containerRef,
|
|
3018
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
3019
|
+
"data-mly-spacer-wrapper": "",
|
|
3020
|
+
ref: spacerWrapperRef,
|
|
3021
|
+
style: { height: `${height}px` },
|
|
3022
|
+
children: shouldShowDragHandles || isResizing ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(SpacerHandle, {
|
|
3023
|
+
handle: "top",
|
|
3024
|
+
onPointerDown: (event) => handlePointerDown("top", event)
|
|
3025
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SpacerHandle, {
|
|
3026
|
+
handle: "bottom",
|
|
3027
|
+
onPointerDown: (event) => handlePointerDown("bottom", event)
|
|
3028
|
+
})] }) : null
|
|
3029
|
+
})
|
|
3030
|
+
});
|
|
3031
|
+
}
|
|
3032
|
+
const SpacerExtension = _tiptap_core.Node.create({
|
|
3033
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.SPACER,
|
|
3034
|
+
priority: 1e3,
|
|
3035
|
+
group: "block",
|
|
3036
|
+
draggable: true,
|
|
3037
|
+
addOptions() {
|
|
3038
|
+
return { HTMLAttributes: {} };
|
|
3039
|
+
},
|
|
3040
|
+
addAttributes() {
|
|
3041
|
+
return { height: {
|
|
3042
|
+
default: 8,
|
|
3043
|
+
parseHTML: (element) => Number(element.getAttribute("data-height")) || 8,
|
|
3044
|
+
renderHTML: (attributes) => ({ "data-height": attributes.height })
|
|
3045
|
+
} };
|
|
3046
|
+
},
|
|
3047
|
+
addCommands() {
|
|
3048
|
+
return {
|
|
3049
|
+
setSpacer: (attrs) => ({ commands }) => commands.insertContent({
|
|
3050
|
+
type: this.name,
|
|
3051
|
+
attrs
|
|
3052
|
+
}),
|
|
3053
|
+
unsetSpacer: () => ({ commands }) => commands.deleteNode(this.name),
|
|
3054
|
+
updateSpacerAttributes: (attrs) => ({ commands }) => commands.updateAttributes(this.name, attrs)
|
|
3055
|
+
};
|
|
3056
|
+
},
|
|
3057
|
+
parseHTML() {
|
|
3058
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
|
|
3059
|
+
},
|
|
3060
|
+
renderHTML({ HTMLAttributes, node }) {
|
|
3061
|
+
const { height } = node.attrs;
|
|
3062
|
+
return ["div", (0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name }, this.options.HTMLAttributes, HTMLAttributes, {
|
|
3063
|
+
contenteditable: "false",
|
|
3064
|
+
style: `height:${height}px`
|
|
3065
|
+
})];
|
|
3066
|
+
},
|
|
3067
|
+
addNodeView() {
|
|
3068
|
+
return (0, _tiptap_react.ReactNodeViewRenderer)(SpacerView, { attrs: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name } });
|
|
3069
|
+
}
|
|
3070
|
+
});
|
|
3071
|
+
//#endregion
|
|
3072
|
+
//#region src/extensions/span/span.ts
|
|
3073
|
+
const SpanExtension = _tiptap_core.Mark.create({
|
|
3074
|
+
name: _maily_to_shared.MAILY_MARK_TYPES.SPAN,
|
|
3075
|
+
addAttributes() {
|
|
3076
|
+
return { style: {
|
|
3077
|
+
default: null,
|
|
3078
|
+
parseHTML: (element) => getSpanStyle(element.getAttribute("style")),
|
|
3079
|
+
renderHTML: (attributes) => {
|
|
3080
|
+
if (typeof attributes.style !== "string") return {};
|
|
3081
|
+
return { style: attributes.style };
|
|
3082
|
+
}
|
|
3083
|
+
} };
|
|
3084
|
+
},
|
|
3085
|
+
parseHTML() {
|
|
3086
|
+
return [{
|
|
3087
|
+
tag: "span[style]",
|
|
3088
|
+
getAttrs: (element) => getSpanStyle(element.getAttribute("style")) ? null : false
|
|
3089
|
+
}];
|
|
3090
|
+
},
|
|
3091
|
+
renderHTML({ HTMLAttributes }) {
|
|
3092
|
+
return [
|
|
3093
|
+
"span",
|
|
3094
|
+
(0, _tiptap_core.mergeAttributes)(HTMLAttributes),
|
|
3095
|
+
0
|
|
3096
|
+
];
|
|
3097
|
+
}
|
|
3098
|
+
});
|
|
3099
|
+
//#endregion
|
|
3100
|
+
//#region src/extensions/style/style.ts
|
|
3101
|
+
const WRAPPER_TYPES = [
|
|
3102
|
+
_maily_to_shared.MAILY_NODE_TYPES.BODY,
|
|
3103
|
+
_maily_to_shared.MAILY_NODE_TYPES.CONTAINER,
|
|
3104
|
+
_maily_to_shared.MAILY_NODE_TYPES.SECTION
|
|
3105
|
+
];
|
|
3106
|
+
const STYLE_SUPPORTED_TYPES = [
|
|
3107
|
+
...WRAPPER_TYPES,
|
|
3108
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
3109
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
3110
|
+
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
3111
|
+
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
3112
|
+
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
3113
|
+
_maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE,
|
|
3114
|
+
_maily_to_shared.MAILY_NODE_TYPES.INLINE_SPAN,
|
|
3115
|
+
_maily_to_shared.MAILY_NODE_TYPES.SPACER,
|
|
3116
|
+
_maily_to_shared.MAILY_NODE_TYPES.BUTTON,
|
|
3117
|
+
_maily_to_shared.MAILY_NODE_TYPES.FOOTER,
|
|
3118
|
+
_maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE,
|
|
3119
|
+
_maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE,
|
|
3120
|
+
_maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST,
|
|
3121
|
+
_maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST,
|
|
3122
|
+
_maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM,
|
|
3123
|
+
_maily_to_shared.MAILY_NODE_TYPES.TABLE,
|
|
3124
|
+
_maily_to_shared.MAILY_NODE_TYPES.TABLE_ROW,
|
|
3125
|
+
_maily_to_shared.MAILY_NODE_TYPES.TABLE_CELL,
|
|
3126
|
+
_maily_to_shared.MAILY_NODE_TYPES.TABLE_HEADER
|
|
3127
|
+
];
|
|
3128
|
+
const STYLE_SUPPORTED_MARK_TYPES = [
|
|
3129
|
+
_maily_to_shared.MAILY_MARK_TYPES.BOLD,
|
|
3130
|
+
_maily_to_shared.MAILY_MARK_TYPES.ITALIC,
|
|
3131
|
+
_maily_to_shared.MAILY_MARK_TYPES.STRIKE,
|
|
3132
|
+
_maily_to_shared.MAILY_MARK_TYPES.UNDERLINE,
|
|
3133
|
+
_maily_to_shared.MAILY_MARK_TYPES.LINK,
|
|
3134
|
+
_maily_to_shared.MAILY_MARK_TYPES.CODE
|
|
3135
|
+
];
|
|
3136
|
+
function getStyleAttribute(parseHTML) {
|
|
3137
|
+
return { style: {
|
|
3138
|
+
default: null,
|
|
3139
|
+
parseHTML,
|
|
3140
|
+
renderHTML: (attributes) => typeof attributes.style === "string" ? { style: attributes.style } : {}
|
|
3141
|
+
} };
|
|
3142
|
+
}
|
|
3143
|
+
const StyleExtension = _tiptap_core.Extension.create({
|
|
3144
|
+
name: _maily_to_shared.MAILY_EXTENSION_TYPES.STYLE,
|
|
3145
|
+
addOptions() {
|
|
3146
|
+
return {
|
|
3147
|
+
fontFamilies: _maily_to_shared.DEFAULT_FONT_FAMILIES,
|
|
3148
|
+
markTypes: STYLE_SUPPORTED_MARK_TYPES,
|
|
3149
|
+
types: STYLE_SUPPORTED_TYPES
|
|
3150
|
+
};
|
|
3151
|
+
},
|
|
3152
|
+
addCommands() {
|
|
3153
|
+
return { updateNodeStyle: (typeOrName, declarations) => ({ commands, editor }) => commands.updateAttributes(typeOrName, { style: setStyleDeclarations(editor.getAttributes(typeOrName).style, declarations) }) };
|
|
3154
|
+
},
|
|
3155
|
+
addGlobalAttributes() {
|
|
3156
|
+
return [
|
|
3157
|
+
{
|
|
3158
|
+
types: this.options.types.filter((type) => !WRAPPER_TYPES.includes(type) && type !== _maily_to_shared.MAILY_NODE_TYPES.COLUMNS && type !== _maily_to_shared.MAILY_NODE_TYPES.COLUMN && type !== _maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE),
|
|
3159
|
+
attributes: getStyleAttribute(getElementStyle)
|
|
3160
|
+
},
|
|
3161
|
+
{
|
|
3162
|
+
types: [_maily_to_shared.MAILY_NODE_TYPES.INLINE_IMAGE],
|
|
3163
|
+
attributes: getStyleAttribute(getInlineImageStyle)
|
|
3164
|
+
},
|
|
3165
|
+
{
|
|
3166
|
+
types: [_maily_to_shared.MAILY_NODE_TYPES.COLUMNS],
|
|
3167
|
+
attributes: getStyleAttribute((element) => getColumnsStyle(getElementStyle(element)))
|
|
3168
|
+
},
|
|
3169
|
+
{
|
|
3170
|
+
types: [_maily_to_shared.MAILY_NODE_TYPES.COLUMN],
|
|
3171
|
+
attributes: getStyleAttribute((element) => getColumnStyle(getElementStyle(element)))
|
|
3172
|
+
},
|
|
3173
|
+
{
|
|
3174
|
+
types: this.options.types.filter((type) => WRAPPER_TYPES.includes(type)),
|
|
3175
|
+
attributes: getStyleAttribute(getWrapperStyle)
|
|
3176
|
+
},
|
|
3177
|
+
{
|
|
3178
|
+
types: this.options.markTypes,
|
|
3179
|
+
attributes: getStyleAttribute((element) => getMarkStyle(element.getAttribute("style")))
|
|
3180
|
+
}
|
|
3181
|
+
];
|
|
3182
|
+
}
|
|
3183
|
+
});
|
|
3184
|
+
//#endregion
|
|
3185
|
+
//#region src/extensions/table/table.ts
|
|
3186
|
+
function getNumericAttribute(name) {
|
|
3187
|
+
return {
|
|
3188
|
+
default: 0,
|
|
3189
|
+
parseHTML: (element) => Number(element.getAttribute(name)) || 0,
|
|
3190
|
+
renderHTML: (attributes) => ({ [name]: attributes[name] })
|
|
3191
|
+
};
|
|
3192
|
+
}
|
|
3193
|
+
const TableExtension = _tiptap_extension_table.Table.extend({ addAttributes() {
|
|
3194
|
+
return {
|
|
3195
|
+
...this.parent?.(),
|
|
3196
|
+
border: getNumericAttribute("border"),
|
|
3197
|
+
cellpadding: getNumericAttribute("cellpadding"),
|
|
3198
|
+
cellspacing: getNumericAttribute("cellspacing"),
|
|
3199
|
+
responsive: {
|
|
3200
|
+
default: false,
|
|
3201
|
+
parseHTML: (element) => {
|
|
3202
|
+
if (element.getAttribute("data-mly-responsive") === "stack") return true;
|
|
3203
|
+
return element.querySelectorAll(":scope > tbody > tr > td[data-id=\"__react-email-column\"]").length > 1;
|
|
3204
|
+
},
|
|
3205
|
+
renderHTML: (attributes) => attributes.responsive ? { "data-mly-responsive": "stack" } : {}
|
|
3206
|
+
}
|
|
3207
|
+
};
|
|
3208
|
+
} }).configure({
|
|
3209
|
+
HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.TABLE },
|
|
3210
|
+
resizable: false,
|
|
3211
|
+
View: null
|
|
3212
|
+
});
|
|
3213
|
+
//#endregion
|
|
3214
|
+
//#region src/extensions/table/table-cell.ts
|
|
3215
|
+
const TableCellExtension = _tiptap_extension_table.TableCell.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.TABLE_CELL } });
|
|
3216
|
+
//#endregion
|
|
3217
|
+
//#region src/extensions/table/table-header.ts
|
|
3218
|
+
const TableHeaderExtension = _tiptap_extension_table.TableHeader.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.TABLE_HEADER } });
|
|
3219
|
+
//#endregion
|
|
3220
|
+
//#region src/extensions/table/table-row.ts
|
|
3221
|
+
const TableRowExtension = _tiptap_extension_table.TableRow.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.TABLE_ROW } });
|
|
3222
|
+
//#endregion
|
|
3223
|
+
//#region src/utils/extensions.ts
|
|
3224
|
+
function mergeExtensions(defaults, overrides) {
|
|
3225
|
+
const overrideNames = new Set(overrides.map((extension) => extension.name));
|
|
3226
|
+
return [...defaults.filter((extension) => !overrideNames.has(extension.name)), ...overrides];
|
|
3227
|
+
}
|
|
3228
|
+
//#endregion
|
|
3229
|
+
//#region src/utils/html.ts
|
|
3230
|
+
const LITERAL_SELECTORS = [
|
|
3231
|
+
"code",
|
|
3232
|
+
"pre",
|
|
3233
|
+
"script",
|
|
3234
|
+
"style",
|
|
3235
|
+
`[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.VARIABLE}"]`
|
|
3236
|
+
].join(",");
|
|
3237
|
+
const PHRASING_TAGS = /* @__PURE__ */ new Set([
|
|
3238
|
+
"A",
|
|
3239
|
+
"ABBR",
|
|
3240
|
+
"B",
|
|
3241
|
+
"BR",
|
|
3242
|
+
"CITE",
|
|
3243
|
+
"CODE",
|
|
3244
|
+
"EM",
|
|
3245
|
+
"FONT",
|
|
3246
|
+
"I",
|
|
3247
|
+
"IMG",
|
|
3248
|
+
"KBD",
|
|
3249
|
+
"MARK",
|
|
3250
|
+
"Q",
|
|
3251
|
+
"S",
|
|
3252
|
+
"SMALL",
|
|
3253
|
+
"SPAN",
|
|
3254
|
+
"STRIKE",
|
|
3255
|
+
"STRONG",
|
|
3256
|
+
"SUB",
|
|
3257
|
+
"SUP",
|
|
3258
|
+
"U"
|
|
3259
|
+
]);
|
|
3260
|
+
const HIDDEN_SELECTORS = ["[data-skip-in-text=\"true\"]", ".preheader"].join(",");
|
|
3261
|
+
const INHERITED_PROPERTIES = /* @__PURE__ */ new Set([
|
|
3262
|
+
"color",
|
|
3263
|
+
"direction",
|
|
3264
|
+
"fontFamily",
|
|
3265
|
+
"fontSize",
|
|
3266
|
+
"fontStyle",
|
|
3267
|
+
"fontVariant",
|
|
3268
|
+
"fontWeight",
|
|
3269
|
+
"letterSpacing",
|
|
3270
|
+
"lineHeight",
|
|
3271
|
+
"listStyle",
|
|
3272
|
+
"listStyleType",
|
|
3273
|
+
"textAlign",
|
|
3274
|
+
"textIndent",
|
|
3275
|
+
"textTransform",
|
|
3276
|
+
"whiteSpace",
|
|
3277
|
+
"wordSpacing"
|
|
3278
|
+
]);
|
|
3279
|
+
function getRules(document) {
|
|
3280
|
+
const rules = [];
|
|
3281
|
+
for (const source of document.querySelectorAll("style")) {
|
|
3282
|
+
const sheet = window.document.createElement("style");
|
|
3283
|
+
sheet.textContent = source.textContent;
|
|
3284
|
+
window.document.head.append(sheet);
|
|
3285
|
+
for (const rule of Array.from(sheet.sheet?.cssRules ?? [])) if (rule instanceof CSSStyleRule) rules.push(rule);
|
|
3286
|
+
sheet.remove();
|
|
3287
|
+
}
|
|
3288
|
+
return rules;
|
|
3289
|
+
}
|
|
3290
|
+
function setRuleStyles(document) {
|
|
3291
|
+
const declared = /* @__PURE__ */ new Map();
|
|
3292
|
+
for (const rule of getRules(document)) {
|
|
3293
|
+
const style = (0, _maily_to_shared.parseInlineStyles)(rule.style.cssText);
|
|
3294
|
+
for (const element of document.querySelectorAll(rule.selectorText)) declared.set(element, {
|
|
3295
|
+
...declared.get(element),
|
|
3296
|
+
...style
|
|
3297
|
+
});
|
|
3298
|
+
}
|
|
3299
|
+
const authored = /* @__PURE__ */ new Map();
|
|
3300
|
+
for (const [element] of declared) authored.set(element, (0, _maily_to_shared.parseInlineStyles)(element.getAttribute("style") ?? ""));
|
|
3301
|
+
for (const [element, style] of declared) for (const [property, value] of Object.entries(style)) {
|
|
3302
|
+
if (!INHERITED_PROPERTIES.has(property)) continue;
|
|
3303
|
+
for (let ancestor = element.parentElement; ancestor && ancestor !== document.body; ancestor = ancestor.parentElement) {
|
|
3304
|
+
const above = authored.get(ancestor)?.[property] ?? declared.get(ancestor)?.[property];
|
|
3305
|
+
if (above === void 0) continue;
|
|
3306
|
+
if (above === value) delete style[property];
|
|
3307
|
+
break;
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
for (const [element, style] of declared) {
|
|
3311
|
+
const merged = (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)(style, authored.get(element) ?? {}));
|
|
3312
|
+
if (merged) element.setAttribute("style", merged);
|
|
3313
|
+
}
|
|
3314
|
+
}
|
|
3315
|
+
function removeHidden(document) {
|
|
3316
|
+
for (const element of document.querySelectorAll(HIDDEN_SELECTORS)) element.remove();
|
|
3317
|
+
for (const element of document.querySelectorAll("[style]")) if (element.style.display === "none") element.remove();
|
|
3318
|
+
}
|
|
3319
|
+
function isPhrasing(node) {
|
|
3320
|
+
return node.nodeType === Node.TEXT_NODE || PHRASING_TAGS.has(node.nodeName);
|
|
3321
|
+
}
|
|
3322
|
+
function setCellParagraphs(document) {
|
|
3323
|
+
for (const parent of document.querySelectorAll("td, th")) {
|
|
3324
|
+
const runs = [[]];
|
|
3325
|
+
for (const child of parent.childNodes) if (isPhrasing(child)) runs.at(-1).push(child);
|
|
3326
|
+
else runs.push([]);
|
|
3327
|
+
for (const run of runs) {
|
|
3328
|
+
if (!run.some((node) => node.textContent?.trim())) continue;
|
|
3329
|
+
const paragraph = document.createElement("p");
|
|
3330
|
+
paragraph.setAttribute("style", "margin:0");
|
|
3331
|
+
run[0].before(paragraph);
|
|
3332
|
+
paragraph.append(...run);
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
function getSoleImage(anchor) {
|
|
3337
|
+
const images = anchor.querySelectorAll("img");
|
|
3338
|
+
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
3339
|
+
}
|
|
3340
|
+
function getSpacingAsMargin(style) {
|
|
3341
|
+
const moved = {};
|
|
3342
|
+
for (const [property, value] of Object.entries(style)) {
|
|
3343
|
+
const key = property.startsWith("padding") ? property.replace("padding", "margin") : property;
|
|
3344
|
+
moved[key] = value;
|
|
3345
|
+
}
|
|
3346
|
+
return moved;
|
|
3347
|
+
}
|
|
3348
|
+
function setLinkedImages(document) {
|
|
3349
|
+
for (const anchor of document.querySelectorAll("a[href]")) {
|
|
3350
|
+
const image = getSoleImage(anchor);
|
|
3351
|
+
if (!image) continue;
|
|
3352
|
+
const anchorStyle = anchor.getAttribute("style");
|
|
3353
|
+
if (anchorStyle) {
|
|
3354
|
+
image.setAttribute("style", (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)(getSpacingAsMargin((0, _maily_to_shared.parseInlineStyles)(anchorStyle)), (0, _maily_to_shared.parseInlineStyles)(image.getAttribute("style") ?? ""))));
|
|
3355
|
+
anchor.removeAttribute("style");
|
|
3356
|
+
}
|
|
3357
|
+
image.setAttribute("data-external-link", anchor.getAttribute("href") ?? "");
|
|
3358
|
+
anchor.removeAttribute("href");
|
|
3359
|
+
}
|
|
3360
|
+
}
|
|
3361
|
+
function getBodyWrapper(document) {
|
|
3362
|
+
for (const table of document.body.querySelectorAll("table")) if (!(table.style.maxWidth || !isBodyTable(table)) && getSingleCell(table)) return table;
|
|
3363
|
+
return null;
|
|
3364
|
+
}
|
|
3365
|
+
/**
|
|
3366
|
+
* Every HTML document has exactly one `<body>` and it is the document, so its
|
|
3367
|
+
* style has to reach the body node however the source wrote it. React Email
|
|
3368
|
+
* splits that style in two — background on `<body>`, the rest on an inner cell,
|
|
3369
|
+
* because Yahoo and AOL drop body styles — so the wrapper it writes is merged
|
|
3370
|
+
* in and unwrapped rather than surviving as a stray table.
|
|
3371
|
+
*/
|
|
3372
|
+
function getBodyStyle(document) {
|
|
3373
|
+
const authored = (0, _maily_to_shared.parseInlineStyles)(document.body.getAttribute("style") ?? "");
|
|
3374
|
+
const wrapper = getBodyWrapper(document);
|
|
3375
|
+
const cell = wrapper ? getSingleCell(wrapper) : null;
|
|
3376
|
+
if (!(wrapper && cell)) return (0, _maily_to_shared.stringifyInlineStyles)(authored) || null;
|
|
3377
|
+
const merged = (0, _maily_to_shared.mergeInlineStyles)(authored, (0, _maily_to_shared.parseInlineStyles)(getWrapperStyle(wrapper) ?? ""));
|
|
3378
|
+
wrapper.replaceWith(...Array.from(cell.childNodes));
|
|
3379
|
+
return (0, _maily_to_shared.stringifyInlineStyles)(merged) || null;
|
|
3380
|
+
}
|
|
3381
|
+
function getVariableElement(document, variable) {
|
|
3382
|
+
const element = document.createElement("span");
|
|
3383
|
+
element.setAttribute(_maily_to_shared.DATA_NODE_TYPE_KEY, _maily_to_shared.MAILY_NODE_TYPES.VARIABLE);
|
|
3384
|
+
element.setAttribute("data-id", variable.id);
|
|
3385
|
+
element.setAttribute("data-required", String(variable.required));
|
|
3386
|
+
element.setAttribute("data-is-default-editable", String(variable.isDefaultEditable));
|
|
3387
|
+
if (variable.fallback) element.setAttribute("data-fallback", variable.fallback);
|
|
3388
|
+
if (variable.label) element.setAttribute("data-label", variable.label);
|
|
3389
|
+
if (variable.style) element.setAttribute("style", variable.style);
|
|
3390
|
+
return element;
|
|
3391
|
+
}
|
|
3392
|
+
function setVariables(document) {
|
|
3393
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
|
|
3394
|
+
const texts = [];
|
|
3395
|
+
while (walker.nextNode()) {
|
|
3396
|
+
const text = walker.currentNode;
|
|
3397
|
+
if ((0, _maily_to_shared.hasVariableInText)(text.data) && !text.parentElement?.closest(LITERAL_SELECTORS)) texts.push(text);
|
|
3398
|
+
}
|
|
3399
|
+
for (const text of texts) text.replaceWith(...(0, _maily_to_shared.getVariableSegments)(text.data).map((segment) => {
|
|
3400
|
+
return segment.isReference ? getVariableElement(document, (0, _maily_to_shared.deserializeVariableFromText)(segment.text)) : segment.text;
|
|
3401
|
+
}));
|
|
3402
|
+
}
|
|
3403
|
+
function getNormalizedHtml(html) {
|
|
3404
|
+
const parsed = new DOMParser().parseFromString(html, "text/html");
|
|
3405
|
+
if (!parsed.body) return html;
|
|
3406
|
+
setRuleStyles(parsed);
|
|
3407
|
+
removeHidden(parsed);
|
|
3408
|
+
setLinkedImages(parsed);
|
|
3409
|
+
setVariables(parsed);
|
|
3410
|
+
setCellParagraphs(parsed);
|
|
3411
|
+
const style = getBodyStyle(parsed);
|
|
3412
|
+
if (!style) return parsed.body.innerHTML;
|
|
3413
|
+
const wrapper = parsed.createElement("div");
|
|
3414
|
+
wrapper.setAttribute(_maily_to_shared.DATA_NODE_TYPE_KEY, _maily_to_shared.MAILY_NODE_TYPES.BODY);
|
|
3415
|
+
wrapper.setAttribute("style", style);
|
|
3416
|
+
wrapper.append(...Array.from(parsed.body.childNodes));
|
|
3417
|
+
return wrapper.outerHTML;
|
|
3418
|
+
}
|
|
3419
|
+
//#endregion
|
|
3420
|
+
//#region src/utils/paste.ts
|
|
3421
|
+
function isPlainPaste(view) {
|
|
3422
|
+
const { input } = view;
|
|
3423
|
+
return Boolean(input?.shiftKey) || Boolean(view.state.selection.$from.parent.type.spec.code);
|
|
3424
|
+
}
|
|
3425
|
+
function isHtmlSource(text) {
|
|
3426
|
+
return text.startsWith("<") && text.endsWith(">");
|
|
3427
|
+
}
|
|
3428
|
+
function pasteHtmlSource(options) {
|
|
3429
|
+
const { event, view } = options;
|
|
3430
|
+
const text = event.clipboardData?.getData("text/plain")?.trim() ?? "";
|
|
3431
|
+
if (event.clipboardData?.getData("text/html") || isPlainPaste(view) || !isHtmlSource(text)) return false;
|
|
3432
|
+
const element = document.createElement("div");
|
|
3433
|
+
element.innerHTML = getNormalizedHtml(text);
|
|
3434
|
+
const parsed = _tiptap_pm_model.DOMParser.fromSchema(view.state.schema).parse(element);
|
|
3435
|
+
const container = parsed.firstChild?.firstChild;
|
|
3436
|
+
if (!container?.content.size) return false;
|
|
3437
|
+
const wasEmpty = (0, _tiptap_core.isNodeEmpty)(view.state.doc);
|
|
3438
|
+
const from = view.state.selection.from;
|
|
3439
|
+
view.dispatch(view.state.tr.insertText(text).setMeta("paste", true));
|
|
3440
|
+
const converted = (0, _tiptap_pm_history.closeHistory)(view.state.tr);
|
|
3441
|
+
const to = view.state.selection.from;
|
|
3442
|
+
if (wasEmpty) converted.replaceWith(0, view.state.doc.content.size, parsed.content);
|
|
3443
|
+
else converted.replaceRange(from, to, _tiptap_pm_model.Slice.maxOpen(container.content));
|
|
3444
|
+
view.dispatch(converted.setMeta("paste", true));
|
|
3445
|
+
return true;
|
|
3446
|
+
}
|
|
3447
|
+
//#endregion
|
|
3448
|
+
//#region src/hooks/use-maily-editor.ts
|
|
3449
|
+
const DEFAULT_EXTENSIONS = [
|
|
3450
|
+
Document,
|
|
3451
|
+
BodyExtension,
|
|
3452
|
+
ContainerExtension,
|
|
3453
|
+
SectionExtension,
|
|
3454
|
+
RepeatExtension,
|
|
3455
|
+
ColumnsExtension,
|
|
3456
|
+
ColumnExtension,
|
|
3457
|
+
ParagraphExtension,
|
|
3458
|
+
_tiptap_extension_heading.Heading.configure({
|
|
3459
|
+
levels: [
|
|
3460
|
+
1,
|
|
3461
|
+
2,
|
|
3462
|
+
3
|
|
3463
|
+
],
|
|
3464
|
+
HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.HEADING }
|
|
3465
|
+
}),
|
|
3466
|
+
_tiptap_extension_text.Text,
|
|
3467
|
+
PlaceholderExtension,
|
|
3468
|
+
_tiptap_extension_hard_break.HardBreak,
|
|
3469
|
+
BoldExtension,
|
|
3470
|
+
_tiptap_extension_italic.Italic,
|
|
3471
|
+
_tiptap_extension_strike.Strike,
|
|
3472
|
+
_tiptap_extension_underline.Underline,
|
|
3473
|
+
_tiptap_extension_link.Link.configure({
|
|
3474
|
+
openOnClick: false,
|
|
3475
|
+
HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_MARK_TYPES.LINK }
|
|
3476
|
+
}),
|
|
3477
|
+
_tiptap_extension_code.Code.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_MARK_TYPES.CODE } }),
|
|
3478
|
+
_tiptap_extension_text_style.TextStyleKit.configure({
|
|
3479
|
+
fontFamily: false,
|
|
3480
|
+
fontSize: false,
|
|
3481
|
+
lineHeight: false,
|
|
3482
|
+
backgroundColor: false,
|
|
3483
|
+
textStyle: false
|
|
3484
|
+
}),
|
|
3485
|
+
_tiptap_extension_text_style.TextStyle.extend({ parseHTML() {
|
|
3486
|
+
return [{
|
|
3487
|
+
tag: "span[style]",
|
|
3488
|
+
consuming: false,
|
|
3489
|
+
getAttrs: (element) => element.style.color ? {} : false
|
|
3490
|
+
}];
|
|
3491
|
+
} }),
|
|
3492
|
+
_tiptap_extension_highlight.Highlight.configure({ multicolor: true }),
|
|
3493
|
+
SpanExtension,
|
|
3494
|
+
InlineSpanExtension,
|
|
3495
|
+
HorizontalRuleExtension,
|
|
3496
|
+
ImageExtension,
|
|
3497
|
+
ImageUploadExtension,
|
|
3498
|
+
InlineImageExtension,
|
|
3499
|
+
SpacerExtension,
|
|
3500
|
+
ButtonExtension,
|
|
3501
|
+
FooterExtension,
|
|
3502
|
+
BlockquoteExtension,
|
|
3503
|
+
HtmlCodeBlockExtension,
|
|
3504
|
+
_tiptap_extension_list.BulletList.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST } }),
|
|
3505
|
+
_tiptap_extension_list.ListItem.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM } }),
|
|
3506
|
+
_tiptap_extension_list.OrderedList.configure({ HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST } }),
|
|
3507
|
+
TableExtension,
|
|
3508
|
+
TableRowExtension,
|
|
3509
|
+
TableCellExtension,
|
|
3510
|
+
TableHeaderExtension,
|
|
3511
|
+
StyleExtension,
|
|
3512
|
+
VisibilityExtension,
|
|
3513
|
+
VariableExtension,
|
|
3514
|
+
SlashCommandExtension,
|
|
3515
|
+
_tiptap_extension_typography.Typography,
|
|
3516
|
+
_tiptap_extensions.UndoRedo,
|
|
3517
|
+
_tiptap_extensions.Dropcursor.configure({
|
|
3518
|
+
color: "#d1d5dc",
|
|
3519
|
+
width: 2
|
|
3520
|
+
}),
|
|
3521
|
+
_tiptap_extensions.Gapcursor,
|
|
3522
|
+
_tiptap_extensions.Selection,
|
|
3523
|
+
_tiptap_extensions.Focus,
|
|
3524
|
+
_tiptap_extension_unique_id.UniqueID.configure({
|
|
3525
|
+
types: [
|
|
3526
|
+
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
3527
|
+
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
3528
|
+
_maily_to_shared.MAILY_NODE_TYPES.SECTION,
|
|
3529
|
+
_maily_to_shared.MAILY_NODE_TYPES.REPEAT,
|
|
3530
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
3531
|
+
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
3532
|
+
_maily_to_shared.MAILY_NODE_TYPES.BULLET_LIST,
|
|
3533
|
+
_maily_to_shared.MAILY_NODE_TYPES.ORDERED_LIST,
|
|
3534
|
+
_maily_to_shared.MAILY_NODE_TYPES.LIST_ITEM,
|
|
3535
|
+
_maily_to_shared.MAILY_NODE_TYPES.HORIZONTAL_RULE,
|
|
3536
|
+
_maily_to_shared.MAILY_NODE_TYPES.BLOCKQUOTE
|
|
3537
|
+
],
|
|
3538
|
+
filterTransaction: (tr) => !isRemoteChange(tr)
|
|
3539
|
+
})
|
|
3540
|
+
];
|
|
3541
|
+
function useMailyEditor(options, dependencies) {
|
|
3542
|
+
const { content, editorProps, extensions: userExtensions, ...rest } = options;
|
|
3543
|
+
const merged = userExtensions ? mergeExtensions(DEFAULT_EXTENSIONS, userExtensions) : DEFAULT_EXTENSIONS;
|
|
3544
|
+
const extensions = merged.some((extension) => extension.name === "collaboration") ? merged.filter((extension) => extension.name !== _tiptap_extensions.UndoRedo.name) : merged;
|
|
3545
|
+
return (0, _tiptap_react.useEditor)({
|
|
3546
|
+
enableContentCheck: typeof content !== "string",
|
|
3547
|
+
onContentError: ({ error }) => {
|
|
3548
|
+
console.error(error);
|
|
3549
|
+
},
|
|
3550
|
+
...rest,
|
|
3551
|
+
content: typeof content === "string" ? getNormalizedHtml(content) : content,
|
|
3552
|
+
editorProps: {
|
|
3553
|
+
...editorProps,
|
|
3554
|
+
attributes: (state) => ({
|
|
3555
|
+
role: "textbox",
|
|
3556
|
+
spellcheck: "false",
|
|
3557
|
+
...typeof editorProps?.attributes === "function" ? editorProps.attributes(state) : editorProps?.attributes
|
|
3558
|
+
}),
|
|
3559
|
+
handlePaste: (view, event, slice) => {
|
|
3560
|
+
return pasteHtmlSource({
|
|
3561
|
+
event,
|
|
3562
|
+
view
|
|
3563
|
+
}) || (editorProps?.handlePaste?.(view, event, slice) ?? false);
|
|
3564
|
+
},
|
|
3565
|
+
transformPastedHTML: (html, view) => {
|
|
3566
|
+
const normalized = getNormalizedHtml(html);
|
|
3567
|
+
return editorProps?.transformPastedHTML?.(normalized, view) ?? normalized;
|
|
3568
|
+
}
|
|
3569
|
+
},
|
|
3570
|
+
extensions
|
|
3571
|
+
}, dependencies);
|
|
3572
|
+
}
|
|
3573
|
+
//#endregion
|
|
3574
|
+
Object.defineProperty(exports, "ALLOWED_IMAGE_MIME_TYPES", {
|
|
3575
|
+
enumerable: true,
|
|
3576
|
+
get: function() {
|
|
3577
|
+
return ALLOWED_IMAGE_MIME_TYPES;
|
|
3578
|
+
}
|
|
3579
|
+
});
|
|
3580
|
+
Object.defineProperty(exports, "ArrowIcon", {
|
|
3581
|
+
enumerable: true,
|
|
3582
|
+
get: function() {
|
|
3583
|
+
return ArrowIcon;
|
|
3584
|
+
}
|
|
3585
|
+
});
|
|
3586
|
+
Object.defineProperty(exports, "BlockquoteExtension", {
|
|
3587
|
+
enumerable: true,
|
|
3588
|
+
get: function() {
|
|
3589
|
+
return BlockquoteExtension;
|
|
3590
|
+
}
|
|
3591
|
+
});
|
|
3592
|
+
Object.defineProperty(exports, "BodyExtension", {
|
|
3593
|
+
enumerable: true,
|
|
3594
|
+
get: function() {
|
|
3595
|
+
return BodyExtension;
|
|
3596
|
+
}
|
|
3597
|
+
});
|
|
3598
|
+
Object.defineProperty(exports, "BoldExtension", {
|
|
3599
|
+
enumerable: true,
|
|
3600
|
+
get: function() {
|
|
3601
|
+
return BoldExtension;
|
|
3602
|
+
}
|
|
3603
|
+
});
|
|
3604
|
+
Object.defineProperty(exports, "ButtonExtension", {
|
|
3605
|
+
enumerable: true,
|
|
3606
|
+
get: function() {
|
|
3607
|
+
return ButtonExtension;
|
|
3608
|
+
}
|
|
3609
|
+
});
|
|
3610
|
+
Object.defineProperty(exports, "ColumnExtension", {
|
|
3611
|
+
enumerable: true,
|
|
3612
|
+
get: function() {
|
|
3613
|
+
return ColumnExtension;
|
|
3614
|
+
}
|
|
3615
|
+
});
|
|
3616
|
+
Object.defineProperty(exports, "ColumnsExtension", {
|
|
3617
|
+
enumerable: true,
|
|
3618
|
+
get: function() {
|
|
3619
|
+
return ColumnsExtension;
|
|
3620
|
+
}
|
|
3621
|
+
});
|
|
3622
|
+
Object.defineProperty(exports, "ContainerExtension", {
|
|
3623
|
+
enumerable: true,
|
|
3624
|
+
get: function() {
|
|
3625
|
+
return ContainerExtension;
|
|
3626
|
+
}
|
|
3627
|
+
});
|
|
3628
|
+
Object.defineProperty(exports, "DEFAULT_EXTENSIONS", {
|
|
3629
|
+
enumerable: true,
|
|
3630
|
+
get: function() {
|
|
3631
|
+
return DEFAULT_EXTENSIONS;
|
|
3632
|
+
}
|
|
3633
|
+
});
|
|
3634
|
+
Object.defineProperty(exports, "DEFAULT_REPEAT_EACH", {
|
|
3635
|
+
enumerable: true,
|
|
3636
|
+
get: function() {
|
|
3637
|
+
return DEFAULT_REPEAT_EACH;
|
|
3638
|
+
}
|
|
3639
|
+
});
|
|
3640
|
+
Object.defineProperty(exports, "DEFAULT_SLASH_COMMANDS", {
|
|
3641
|
+
enumerable: true,
|
|
3642
|
+
get: function() {
|
|
3643
|
+
return DEFAULT_SLASH_COMMANDS;
|
|
3644
|
+
}
|
|
3645
|
+
});
|
|
3646
|
+
Object.defineProperty(exports, "Document", {
|
|
3647
|
+
enumerable: true,
|
|
3648
|
+
get: function() {
|
|
3649
|
+
return Document;
|
|
3650
|
+
}
|
|
3651
|
+
});
|
|
3652
|
+
Object.defineProperty(exports, "FLOATING_ELEMENT_HEIGHT", {
|
|
3653
|
+
enumerable: true,
|
|
3654
|
+
get: function() {
|
|
3655
|
+
return FLOATING_ELEMENT_HEIGHT;
|
|
3656
|
+
}
|
|
3657
|
+
});
|
|
3658
|
+
Object.defineProperty(exports, "FLOATING_ELEMENT_IDS", {
|
|
3659
|
+
enumerable: true,
|
|
3660
|
+
get: function() {
|
|
3661
|
+
return FLOATING_ELEMENT_IDS;
|
|
3662
|
+
}
|
|
3663
|
+
});
|
|
3664
|
+
Object.defineProperty(exports, "FLOATING_ELEMENT_ORDER", {
|
|
3665
|
+
enumerable: true,
|
|
3666
|
+
get: function() {
|
|
3667
|
+
return FLOATING_ELEMENT_ORDER;
|
|
3668
|
+
}
|
|
3669
|
+
});
|
|
3670
|
+
Object.defineProperty(exports, "FLOATING_ELEMENT_PADDING", {
|
|
3671
|
+
enumerable: true,
|
|
3672
|
+
get: function() {
|
|
3673
|
+
return FLOATING_ELEMENT_PADDING;
|
|
3674
|
+
}
|
|
3675
|
+
});
|
|
3676
|
+
Object.defineProperty(exports, "FloatingElement", {
|
|
3677
|
+
enumerable: true,
|
|
3678
|
+
get: function() {
|
|
3679
|
+
return FloatingElement;
|
|
3680
|
+
}
|
|
3681
|
+
});
|
|
3682
|
+
Object.defineProperty(exports, "FooterExtension", {
|
|
3683
|
+
enumerable: true,
|
|
3684
|
+
get: function() {
|
|
3685
|
+
return FooterExtension;
|
|
3686
|
+
}
|
|
3687
|
+
});
|
|
3688
|
+
Object.defineProperty(exports, "HorizontalRuleExtension", {
|
|
3689
|
+
enumerable: true,
|
|
3690
|
+
get: function() {
|
|
3691
|
+
return HorizontalRuleExtension;
|
|
3692
|
+
}
|
|
3693
|
+
});
|
|
3694
|
+
Object.defineProperty(exports, "HtmlCodeBlockExtension", {
|
|
3695
|
+
enumerable: true,
|
|
3696
|
+
get: function() {
|
|
3697
|
+
return HtmlCodeBlockExtension;
|
|
3698
|
+
}
|
|
3699
|
+
});
|
|
3700
|
+
Object.defineProperty(exports, "IMAGE_UPLOAD_STATUSES", {
|
|
3701
|
+
enumerable: true,
|
|
3702
|
+
get: function() {
|
|
3703
|
+
return IMAGE_UPLOAD_STATUSES;
|
|
3704
|
+
}
|
|
3705
|
+
});
|
|
3706
|
+
Object.defineProperty(exports, "ImageExtension", {
|
|
3707
|
+
enumerable: true,
|
|
3708
|
+
get: function() {
|
|
3709
|
+
return ImageExtension;
|
|
3710
|
+
}
|
|
3711
|
+
});
|
|
3712
|
+
Object.defineProperty(exports, "ImageState", {
|
|
3713
|
+
enumerable: true,
|
|
3714
|
+
get: function() {
|
|
3715
|
+
return ImageState;
|
|
3716
|
+
}
|
|
3717
|
+
});
|
|
3718
|
+
Object.defineProperty(exports, "ImageUploadExtension", {
|
|
3719
|
+
enumerable: true,
|
|
3720
|
+
get: function() {
|
|
3721
|
+
return ImageUploadExtension;
|
|
3722
|
+
}
|
|
3723
|
+
});
|
|
3724
|
+
Object.defineProperty(exports, "InlineImageExtension", {
|
|
3725
|
+
enumerable: true,
|
|
3726
|
+
get: function() {
|
|
3727
|
+
return InlineImageExtension;
|
|
3728
|
+
}
|
|
3729
|
+
});
|
|
3730
|
+
Object.defineProperty(exports, "InlineSpanExtension", {
|
|
3731
|
+
enumerable: true,
|
|
3732
|
+
get: function() {
|
|
3733
|
+
return InlineSpanExtension;
|
|
3734
|
+
}
|
|
3735
|
+
});
|
|
3736
|
+
Object.defineProperty(exports, "MAX_SPACER_HEIGHT", {
|
|
3737
|
+
enumerable: true,
|
|
3738
|
+
get: function() {
|
|
3739
|
+
return MAX_SPACER_HEIGHT;
|
|
3740
|
+
}
|
|
3741
|
+
});
|
|
3742
|
+
Object.defineProperty(exports, "MIN_SPACER_HEIGHT", {
|
|
3743
|
+
enumerable: true,
|
|
3744
|
+
get: function() {
|
|
3745
|
+
return MIN_SPACER_HEIGHT;
|
|
3746
|
+
}
|
|
3747
|
+
});
|
|
3748
|
+
Object.defineProperty(exports, "ProtectVariableTrigger", {
|
|
3749
|
+
enumerable: true,
|
|
3750
|
+
get: function() {
|
|
3751
|
+
return ProtectVariableTrigger;
|
|
3752
|
+
}
|
|
3753
|
+
});
|
|
3754
|
+
Object.defineProperty(exports, "SPACER_SPACING", {
|
|
3755
|
+
enumerable: true,
|
|
3756
|
+
get: function() {
|
|
3757
|
+
return SPACER_SPACING;
|
|
3758
|
+
}
|
|
3759
|
+
});
|
|
3760
|
+
Object.defineProperty(exports, "SPACING_PRESETS", {
|
|
3761
|
+
enumerable: true,
|
|
3762
|
+
get: function() {
|
|
3763
|
+
return SPACING_PRESETS;
|
|
3764
|
+
}
|
|
3765
|
+
});
|
|
3766
|
+
Object.defineProperty(exports, "STYLE_SUPPORTED_TYPES", {
|
|
3767
|
+
enumerable: true,
|
|
3768
|
+
get: function() {
|
|
3769
|
+
return STYLE_SUPPORTED_TYPES;
|
|
3770
|
+
}
|
|
3771
|
+
});
|
|
3772
|
+
Object.defineProperty(exports, "SectionExtension", {
|
|
3773
|
+
enumerable: true,
|
|
3774
|
+
get: function() {
|
|
3775
|
+
return SectionExtension;
|
|
3776
|
+
}
|
|
3777
|
+
});
|
|
3778
|
+
Object.defineProperty(exports, "SlashCommandExtension", {
|
|
3779
|
+
enumerable: true,
|
|
3780
|
+
get: function() {
|
|
3781
|
+
return SlashCommandExtension;
|
|
3782
|
+
}
|
|
3783
|
+
});
|
|
3784
|
+
Object.defineProperty(exports, "SpacerExtension", {
|
|
3785
|
+
enumerable: true,
|
|
3786
|
+
get: function() {
|
|
3787
|
+
return SpacerExtension;
|
|
3788
|
+
}
|
|
3789
|
+
});
|
|
3790
|
+
Object.defineProperty(exports, "SpanExtension", {
|
|
3791
|
+
enumerable: true,
|
|
3792
|
+
get: function() {
|
|
3793
|
+
return SpanExtension;
|
|
3794
|
+
}
|
|
3795
|
+
});
|
|
3796
|
+
Object.defineProperty(exports, "StyleExtension", {
|
|
3797
|
+
enumerable: true,
|
|
3798
|
+
get: function() {
|
|
3799
|
+
return StyleExtension;
|
|
3800
|
+
}
|
|
3801
|
+
});
|
|
3802
|
+
Object.defineProperty(exports, "Tooltip", {
|
|
3803
|
+
enumerable: true,
|
|
3804
|
+
get: function() {
|
|
3805
|
+
return Tooltip;
|
|
3806
|
+
}
|
|
3807
|
+
});
|
|
3808
|
+
Object.defineProperty(exports, "TooltipArrow", {
|
|
3809
|
+
enumerable: true,
|
|
3810
|
+
get: function() {
|
|
3811
|
+
return TooltipArrow;
|
|
3812
|
+
}
|
|
3813
|
+
});
|
|
3814
|
+
Object.defineProperty(exports, "TooltipPopup", {
|
|
3815
|
+
enumerable: true,
|
|
3816
|
+
get: function() {
|
|
3817
|
+
return TooltipPopup;
|
|
3818
|
+
}
|
|
3819
|
+
});
|
|
3820
|
+
Object.defineProperty(exports, "TooltipPositioner", {
|
|
3821
|
+
enumerable: true,
|
|
3822
|
+
get: function() {
|
|
3823
|
+
return TooltipPositioner;
|
|
3824
|
+
}
|
|
3825
|
+
});
|
|
3826
|
+
Object.defineProperty(exports, "TooltipProvider", {
|
|
3827
|
+
enumerable: true,
|
|
3828
|
+
get: function() {
|
|
3829
|
+
return TooltipProvider;
|
|
3830
|
+
}
|
|
3831
|
+
});
|
|
3832
|
+
Object.defineProperty(exports, "TooltipTrigger", {
|
|
3833
|
+
enumerable: true,
|
|
3834
|
+
get: function() {
|
|
3835
|
+
return TooltipTrigger;
|
|
3836
|
+
}
|
|
3837
|
+
});
|
|
3838
|
+
Object.defineProperty(exports, "VARIABLE_SUGGESTION_POPOVER_ID", {
|
|
3839
|
+
enumerable: true,
|
|
3840
|
+
get: function() {
|
|
3841
|
+
return VARIABLE_SUGGESTION_POPOVER_ID;
|
|
3842
|
+
}
|
|
3843
|
+
});
|
|
3844
|
+
Object.defineProperty(exports, "VISIBILITY_SUPPORTED_TYPES", {
|
|
3845
|
+
enumerable: true,
|
|
3846
|
+
get: function() {
|
|
3847
|
+
return VISIBILITY_SUPPORTED_TYPES;
|
|
3848
|
+
}
|
|
3849
|
+
});
|
|
3850
|
+
Object.defineProperty(exports, "VariableExtension", {
|
|
3851
|
+
enumerable: true,
|
|
3852
|
+
get: function() {
|
|
3853
|
+
return VariableExtension;
|
|
3854
|
+
}
|
|
3855
|
+
});
|
|
3856
|
+
Object.defineProperty(exports, "VisibilityExtension", {
|
|
3857
|
+
enumerable: true,
|
|
3858
|
+
get: function() {
|
|
3859
|
+
return VisibilityExtension;
|
|
3860
|
+
}
|
|
3861
|
+
});
|
|
3862
|
+
Object.defineProperty(exports, "VisuallyHidden", {
|
|
3863
|
+
enumerable: true,
|
|
3864
|
+
get: function() {
|
|
3865
|
+
return VisuallyHidden;
|
|
3866
|
+
}
|
|
3867
|
+
});
|
|
3868
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
3869
|
+
enumerable: true,
|
|
3870
|
+
get: function() {
|
|
3871
|
+
return __exportAll;
|
|
3872
|
+
}
|
|
3873
|
+
});
|
|
3874
|
+
Object.defineProperty(exports, "addColumn", {
|
|
3875
|
+
enumerable: true,
|
|
3876
|
+
get: function() {
|
|
3877
|
+
return addColumn;
|
|
3878
|
+
}
|
|
3879
|
+
});
|
|
3880
|
+
Object.defineProperty(exports, "clearInitialNodeSelection", {
|
|
3881
|
+
enumerable: true,
|
|
3882
|
+
get: function() {
|
|
3883
|
+
return clearInitialNodeSelection;
|
|
3884
|
+
}
|
|
3885
|
+
});
|
|
3886
|
+
Object.defineProperty(exports, "filterVariableSuggestions", {
|
|
3887
|
+
enumerable: true,
|
|
3888
|
+
get: function() {
|
|
3889
|
+
return filterVariableSuggestions;
|
|
3890
|
+
}
|
|
3891
|
+
});
|
|
3892
|
+
Object.defineProperty(exports, "getColumnWidths", {
|
|
3893
|
+
enumerable: true,
|
|
3894
|
+
get: function() {
|
|
3895
|
+
return getColumnWidths;
|
|
3896
|
+
}
|
|
3897
|
+
});
|
|
3898
|
+
Object.defineProperty(exports, "getMergedNodeTheme", {
|
|
3899
|
+
enumerable: true,
|
|
3900
|
+
get: function() {
|
|
3901
|
+
return getMergedNodeTheme;
|
|
3902
|
+
}
|
|
3903
|
+
});
|
|
3904
|
+
Object.defineProperty(exports, "getNodeStyleState", {
|
|
3905
|
+
enumerable: true,
|
|
3906
|
+
get: function() {
|
|
3907
|
+
return getNodeStyleState;
|
|
3908
|
+
}
|
|
3909
|
+
});
|
|
3910
|
+
Object.defineProperty(exports, "getNodeTheme", {
|
|
3911
|
+
enumerable: true,
|
|
3912
|
+
get: function() {
|
|
3913
|
+
return getNodeTheme;
|
|
3914
|
+
}
|
|
3915
|
+
});
|
|
3916
|
+
Object.defineProperty(exports, "getNormalizedHtml", {
|
|
3917
|
+
enumerable: true,
|
|
3918
|
+
get: function() {
|
|
3919
|
+
return getNormalizedHtml;
|
|
3920
|
+
}
|
|
3921
|
+
});
|
|
3922
|
+
Object.defineProperty(exports, "getShellNodes", {
|
|
3923
|
+
enumerable: true,
|
|
3924
|
+
get: function() {
|
|
3925
|
+
return getShellNodes;
|
|
3926
|
+
}
|
|
3927
|
+
});
|
|
3928
|
+
Object.defineProperty(exports, "getThemeCss", {
|
|
3929
|
+
enumerable: true,
|
|
3930
|
+
get: function() {
|
|
3931
|
+
return getThemeCss;
|
|
3932
|
+
}
|
|
3933
|
+
});
|
|
3934
|
+
Object.defineProperty(exports, "getVariableSuggestions", {
|
|
3935
|
+
enumerable: true,
|
|
3936
|
+
get: function() {
|
|
3937
|
+
return getVariableSuggestions;
|
|
3938
|
+
}
|
|
3939
|
+
});
|
|
3940
|
+
Object.defineProperty(exports, "mergeExtensions", {
|
|
3941
|
+
enumerable: true,
|
|
3942
|
+
get: function() {
|
|
3943
|
+
return mergeExtensions;
|
|
3944
|
+
}
|
|
3945
|
+
});
|
|
3946
|
+
Object.defineProperty(exports, "removeColumn", {
|
|
3947
|
+
enumerable: true,
|
|
3948
|
+
get: function() {
|
|
3949
|
+
return removeColumn;
|
|
3950
|
+
}
|
|
3951
|
+
});
|
|
3952
|
+
Object.defineProperty(exports, "setStyleDeclarations", {
|
|
3953
|
+
enumerable: true,
|
|
3954
|
+
get: function() {
|
|
3955
|
+
return setStyleDeclarations;
|
|
3956
|
+
}
|
|
3957
|
+
});
|
|
3958
|
+
Object.defineProperty(exports, "updateColumnWidth", {
|
|
3959
|
+
enumerable: true,
|
|
3960
|
+
get: function() {
|
|
3961
|
+
return updateColumnWidth;
|
|
3962
|
+
}
|
|
3963
|
+
});
|
|
3964
|
+
Object.defineProperty(exports, "useEditorInstance", {
|
|
3965
|
+
enumerable: true,
|
|
3966
|
+
get: function() {
|
|
3967
|
+
return useEditorInstance;
|
|
3968
|
+
}
|
|
3969
|
+
});
|
|
3970
|
+
Object.defineProperty(exports, "useFloatingStore", {
|
|
3971
|
+
enumerable: true,
|
|
3972
|
+
get: function() {
|
|
3973
|
+
return useFloatingStore;
|
|
3974
|
+
}
|
|
3975
|
+
});
|
|
3976
|
+
Object.defineProperty(exports, "useMailyEditor", {
|
|
3977
|
+
enumerable: true,
|
|
3978
|
+
get: function() {
|
|
3979
|
+
return useMailyEditor;
|
|
3980
|
+
}
|
|
3981
|
+
});
|
|
3982
|
+
Object.defineProperty(exports, "useOnSelectionUpdate", {
|
|
3983
|
+
enumerable: true,
|
|
3984
|
+
get: function() {
|
|
3985
|
+
return useOnSelectionUpdate;
|
|
3986
|
+
}
|
|
3987
|
+
});
|
|
3988
|
+
Object.defineProperty(exports, "useValueAsRef", {
|
|
3989
|
+
enumerable: true,
|
|
3990
|
+
get: function() {
|
|
3991
|
+
return useValueAsRef;
|
|
3992
|
+
}
|
|
3993
|
+
});
|