@maily-to/core 2.0.0-beta.7 → 2.0.0-beta.8

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.
Files changed (48) hide show
  1. package/dist/blocks/index.cjs +8 -1
  2. package/dist/blocks/index.d.cts +1 -38
  3. package/dist/blocks/index.d.mts +14 -6
  4. package/dist/blocks/index.d.mts.map +1 -1
  5. package/dist/blocks/index.mjs +2 -2
  6. package/dist/extensions/index.cjs +252 -303
  7. package/dist/extensions/index.d.cts +1 -379
  8. package/dist/extensions/index.d.mts +127 -224
  9. package/dist/extensions/index.d.mts.map +1 -1
  10. package/dist/extensions/index.mjs +238 -271
  11. package/dist/index.cjs +4423 -12618
  12. package/dist/index.d.cts +1 -165
  13. package/dist/index.d.mts +701 -121
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +8460 -11567
  16. package/dist/{slash-command-BmWRVPbv.d.mts → slash-command-BrwA1bHs.d.mts} +10 -11
  17. package/dist/slash-command-BrwA1bHs.d.mts.map +1 -0
  18. package/dist/theme-D1CI7_8s.d.mts +70 -0
  19. package/dist/theme-D1CI7_8s.d.mts.map +1 -0
  20. package/dist/typography-BdOKvXfQ.mjs +911 -0
  21. package/dist/typography-D-VnwOSw.cjs +970 -0
  22. package/dist/typography-DW7VApAR.cjs +1072 -0
  23. package/dist/use-maily-editor-BP6Mt8Nn.cjs +3991 -0
  24. package/dist/use-maily-editor-DFuhg38t.cjs +4939 -0
  25. package/dist/use-maily-editor-xVILP7H8.mjs +4488 -0
  26. package/package.json +82 -74
  27. package/readme.md +169 -128
  28. package/src/styles/index.css +2537 -0
  29. package/dist/blocks/index.d.cts.map +0 -1
  30. package/dist/chunk-CfYAbeIz.mjs +0 -13
  31. package/dist/extensions/index.d.cts.map +0 -1
  32. package/dist/extensions/index.mjs.map +0 -1
  33. package/dist/index.css +0 -2312
  34. package/dist/index.d.cts.map +0 -1
  35. package/dist/index.mjs.map +0 -1
  36. package/dist/slash-command-BmWRVPbv.d.mts.map +0 -1
  37. package/dist/slash-command-CK0-1FwR.d.cts +0 -39
  38. package/dist/slash-command-CK0-1FwR.d.cts.map +0 -1
  39. package/dist/spacer-DBtsr3hu.cjs +0 -5768
  40. package/dist/spacer-DzZWX-wB.mjs +0 -5456
  41. package/dist/spacer-DzZWX-wB.mjs.map +0 -1
  42. package/dist/typography-CWL13acR.cjs +0 -400
  43. package/dist/typography-DhrUe809.mjs +0 -282
  44. package/dist/typography-DhrUe809.mjs.map +0 -1
  45. package/dist/variable-C9S9ZoHv.d.cts +0 -108
  46. package/dist/variable-C9S9ZoHv.d.cts.map +0 -1
  47. package/dist/variable-DVwGrg2a.d.mts +0 -108
  48. package/dist/variable-DVwGrg2a.d.mts.map +0 -1
@@ -1,112 +1,133 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_spacer = require("../spacer-DBtsr3hu.cjs");
3
- let react_compiler_runtime = require("react/compiler-runtime");
4
- let _maily_to_shared = require("@maily-to/shared");
5
- require("react");
6
- let _tiptap_react = require("@tiptap/react");
2
+ const require_use_maily_editor = require("../use-maily-editor-BP6Mt8Nn.cjs");
7
3
  let react_jsx_runtime = require("react/jsx-runtime");
8
4
  let lucide_react = require("lucide-react");
5
+ let _maily_to_shared = require("@maily-to/shared");
6
+ let _tiptap_react = require("@tiptap/react");
9
7
  let _tiptap_pm_state = require("@tiptap/pm/state");
10
8
  let _tiptap_core = require("@tiptap/core");
11
- let _tiptap_pm_view = require("@tiptap/pm/view");
12
- //#region src/extensions/link-card/link-card-view.tsx
13
- function LinkCardView(props) {
14
- const $ = (0, react_compiler_runtime.c)(19);
15
- if ($[0] !== "69aaa7785e48c4c895e2bec2928cedb20ea9840e6ddc6ed2b2a59ef98dd54807") {
16
- for (let $i = 0; $i < 19; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
17
- $[0] = "69aaa7785e48c4c895e2bec2928cedb20ea9840e6ddc6ed2b2a59ef98dd54807";
9
+ //#region src/extensions/collaboration-attributes/collaboration-attributes.ts
10
+ const COLLABORATION_ATTRIBUTES_META = "collaborationAttributes";
11
+ function getAttributePaths(attributes, prefix = "") {
12
+ return Object.entries(attributes).flatMap(([name, value]) => {
13
+ return (0, _maily_to_shared.isMergeableObject)(value) ? getAttributePaths(value, `${prefix}${name}.`) : [[`${prefix}${name}`, value]];
14
+ });
15
+ }
16
+ function setAttributes(editor, changes) {
17
+ const attributes = structuredClone(editor.state.doc.attrs);
18
+ for (const [path, value] of changes) {
19
+ const names = path.split(".");
20
+ const last = names.pop();
21
+ let target = attributes;
22
+ for (const name of names) {
23
+ target[name] = (0, _maily_to_shared.isMergeableObject)(target[name]) ? target[name] : {};
24
+ target = target[name];
25
+ }
26
+ if (value === void 0) delete target[last];
27
+ else target[last] = value;
18
28
  }
19
- const { editor, node, getPos } = props;
20
- const { title, description, link, linkTitle, image, subTitle, badgeText } = node.attrs;
21
- let t0;
22
- if ($[1] !== editor.commands || $[2] !== editor.isEditable || $[3] !== getPos) {
23
- t0 = () => {
24
- if (!editor.isEditable) return;
25
- const pos = getPos();
26
- if (pos === void 0) return;
27
- editor.commands.setNodeSelection(pos);
29
+ const { tr } = editor.state;
30
+ for (const [name, value] of Object.entries(attributes)) if (JSON.stringify(tr.doc.attrs[name]) !== JSON.stringify(value)) tr.setDocAttribute(name, value);
31
+ if (!tr.docChanged) return;
32
+ editor.view.dispatch(tr.setMeta(COLLABORATION_ATTRIBUTES_META, true).setMeta("addToHistory", false));
33
+ }
34
+ const CollaborationAttributesExtension = _tiptap_core.Extension.create({
35
+ name: "collaborationAttributes",
36
+ addOptions() {
37
+ return {
38
+ document: null,
39
+ field: "maily"
40
+ };
41
+ },
42
+ addStorage() {
43
+ return { unobserve: null };
44
+ },
45
+ onCreate() {
46
+ const { document, field } = this.options;
47
+ if (!document) return;
48
+ const map = document.getMap(field);
49
+ const observer = (event) => {
50
+ if (event.transaction.origin === this.editor) return;
51
+ setAttributes(this.editor, [...event.keysChanged].map((path) => [path, map.get(path)]));
28
52
  };
29
- $[1] = editor.commands;
30
- $[2] = editor.isEditable;
31
- $[3] = getPos;
32
- $[4] = t0;
33
- } else t0 = $[4];
34
- const handleClick = t0;
35
- const isEmpty = !title && !description && !image;
36
- let t1;
37
- if ($[5] !== badgeText || $[6] !== description || $[7] !== editor.isEditable || $[8] !== image || $[9] !== isEmpty || $[10] !== link || $[11] !== linkTitle || $[12] !== subTitle || $[13] !== title) {
38
- t1 = isEmpty ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_spacer.ImageState.Root, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_spacer.ImageState.Icon, { icon: lucide_react.SquareArrowOutUpRightIcon }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_spacer.ImageState.Label, { children: "Link Card" })] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
39
- className: "mly:flex mly:flex-col mly:rounded-lg mly:border mly:border-gray-300",
40
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [image && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
41
- className: "mly:relative mly:mb-1.5 mly:w-full mly:shrink-0",
42
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
43
- src: image,
44
- alt: "link-card",
45
- className: "mly:mb-0! mly:h-full mly:w-full mly:rounded-t-lg",
46
- draggable: editor.isEditable
47
- })
48
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
49
- className: "mly:flex mly:items-stretch mly:p-3",
50
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
51
- className: "mly:flex mly:flex-col",
52
- children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
53
- className: "mly:mb-1.5! mly:flex mly:items-center mly:gap-1.5",
54
- children: [
55
- /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
56
- className: "mly:mb-0! mly:text-lg! mly:font-semibold",
57
- children: title
58
- }),
59
- badgeText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
60
- className: "mly:font-base! mly:rounded-md mly:bg-yellow-200 mly:px-2 mly:py-1 mly:text-xs mly:leading-none mly:font-semibold",
61
- children: badgeText
62
- }),
63
- " ",
64
- subTitle && !badgeText && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
65
- className: "mly:font-base! mly:rounded-md mly:text-xs mly:leading-none mly:text-gray-400",
66
- children: subTitle
67
- })
68
- ]
69
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
70
- className: "mly:my-0! mly:text-base! mly:text-gray-500",
71
- children: [
72
- description,
73
- " ",
74
- linkTitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
75
- href: link,
76
- className: "mly:font-semibold",
77
- children: linkTitle
78
- }) : null
79
- ]
80
- })]
81
- })
82
- })] })
83
- });
84
- $[5] = badgeText;
85
- $[6] = description;
86
- $[7] = editor.isEditable;
87
- $[8] = image;
88
- $[9] = isEmpty;
89
- $[10] = link;
90
- $[11] = linkTitle;
91
- $[12] = subTitle;
92
- $[13] = title;
93
- $[14] = t1;
94
- } else t1 = $[14];
95
- let t2;
96
- if ($[15] !== editor.isEditable || $[16] !== handleClick || $[17] !== t1) {
97
- t2 = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, {
98
- className: "not-prose mly:cursor-default",
99
- draggable: editor.isEditable,
100
- "data-drag-handle": editor.isEditable,
101
- onClick: handleClick,
102
- children: t1
103
- });
104
- $[15] = editor.isEditable;
105
- $[16] = handleClick;
106
- $[17] = t1;
107
- $[18] = t2;
108
- } else t2 = $[18];
109
- return t2;
53
+ setAttributes(this.editor, [...map.entries()]);
54
+ map.observe(observer);
55
+ this.storage.unobserve = () => map.unobserve(observer);
56
+ },
57
+ onTransaction({ transaction }) {
58
+ const { document, field } = this.options;
59
+ if (!document || transaction.getMeta(COLLABORATION_ATTRIBUTES_META) || transaction.before.attrs === transaction.doc.attrs) return;
60
+ const map = document.getMap(field);
61
+ const before = new Map(getAttributePaths(transaction.before.attrs));
62
+ const after = new Map(getAttributePaths(transaction.doc.attrs));
63
+ document.transact(() => {
64
+ for (const [path, value] of after) if (before.get(path) !== value) map.set(path, value);
65
+ for (const path of before.keys()) if (!after.has(path)) map.delete(path);
66
+ }, this.editor);
67
+ },
68
+ onDestroy() {
69
+ this.storage.unobserve?.();
70
+ this.storage.unobserve = null;
71
+ }
72
+ });
73
+ //#endregion
74
+ //#region src/extensions/link-card/link-card-view.tsx
75
+ function LinkCardView(props) {
76
+ const { editor, getPos, node } = props;
77
+ const { badgeText, description, image, link, linkTitle, subTitle, title } = node.attrs;
78
+ const handleClick = () => {
79
+ if (!editor.isEditable) return;
80
+ const pos = getPos();
81
+ if (pos === void 0) return;
82
+ editor.commands.setNodeSelection(pos);
83
+ };
84
+ const isEmpty = !(title || description || image);
85
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, {
86
+ "data-drag-handle": editor.isEditable,
87
+ "data-mly-link-card": "",
88
+ draggable: editor.isEditable,
89
+ onClick: handleClick,
90
+ children: isEmpty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_use_maily_editor.ImageState, {
91
+ icon: lucide_react.SquareArrowOutUpRightIcon,
92
+ state: "idle",
93
+ children: "Link Card"
94
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [image ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
95
+ alt: title || "Link card",
96
+ "data-mly-link-card-image": "",
97
+ draggable: false,
98
+ src: image
99
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
100
+ "data-mly-link-card-content": "",
101
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
102
+ "data-mly-link-card-heading": "",
103
+ children: [
104
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
105
+ "data-mly-link-card-title": "",
106
+ children: title
107
+ }),
108
+ badgeText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
109
+ "data-mly-link-card-badge": "",
110
+ children: badgeText
111
+ }) : null,
112
+ subTitle && !badgeText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
113
+ "data-mly-link-card-sub-title": "",
114
+ children: subTitle
115
+ }) : null
116
+ ]
117
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
118
+ "data-mly-link-card-description": "",
119
+ children: [
120
+ description,
121
+ " ",
122
+ linkTitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
123
+ "data-mly-link-card-cta": "",
124
+ href: link,
125
+ children: linkTitle
126
+ }) : null
127
+ ]
128
+ })]
129
+ })] })
130
+ });
110
131
  }
111
132
  //#endregion
112
133
  //#region src/extensions/link-card/link-card.ts
@@ -115,6 +136,9 @@ const LinkCardExtension = _tiptap_core.Node.create({
115
136
  group: "block",
116
137
  atom: true,
117
138
  draggable: true,
139
+ addOptions() {
140
+ return { HTMLAttributes: {} };
141
+ },
118
142
  addAttributes() {
119
143
  return {
120
144
  title: {
@@ -154,224 +178,149 @@ const LinkCardExtension = _tiptap_core.Node.create({
154
178
  }
155
179
  };
156
180
  },
181
+ addCommands() {
182
+ return {
183
+ setLinkCard: (attrs) => ({ commands }) => {
184
+ return commands.insertContent({
185
+ type: this.name,
186
+ attrs
187
+ });
188
+ },
189
+ updateLinkCardAttributes: (attrs) => ({ commands }) => {
190
+ return commands.updateAttributes(this.name, attrs);
191
+ }
192
+ };
193
+ },
157
194
  parseHTML() {
158
195
  return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
159
196
  },
160
197
  renderHTML({ HTMLAttributes }) {
161
- return ["div", (0, _tiptap_core.mergeAttributes)(HTMLAttributes, {
198
+ return ["div", (0, _tiptap_core.mergeAttributes)({
162
199
  [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name,
163
200
  contenteditable: false
164
- })];
201
+ }, this.options.HTMLAttributes, HTMLAttributes)];
202
+ },
203
+ addNodeView() {
204
+ return (0, _tiptap_react.ReactNodeViewRenderer)(LinkCardView, { attrs: () => ({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.LINK_CARD }) });
205
+ }
206
+ });
207
+ //#endregion
208
+ //#region src/extensions/theme/theme.ts
209
+ const SCOPE_ATTRIBUTE = "data-mly-theme-scope";
210
+ const THEME_ATTRIBUTE = "theme";
211
+ function getDocumentTheme(doc) {
212
+ return doc.attrs.theme;
213
+ }
214
+ function getClearedDeclarations(declarations) {
215
+ return Object.fromEntries(Object.keys(declarations).map((property) => {
216
+ return [property, null];
217
+ }));
218
+ }
219
+ const ThemeExtension = _tiptap_core.Extension.create({
220
+ name: _maily_to_shared.MAILY_EXTENSION_TYPES.THEME,
221
+ addOptions() {
222
+ return { theme: {} };
165
223
  },
166
224
  addCommands() {
167
225
  return {
168
- setLinkCard: (attrs) => {
169
- return ({ commands }) => {
170
- return commands.insertContent({
171
- type: this.name,
172
- attrs
173
- });
174
- };
226
+ setNodeTheme: (theme) => ({ dispatch, tr }) => {
227
+ if (dispatch) tr.setDocAttribute(THEME_ATTRIBUTE, theme);
228
+ return true;
175
229
  },
176
- updateLinkCardAttributes: (attrs) => {
177
- return ({ commands }) => {
178
- return commands.updateAttributes(this.name, attrs);
179
- };
230
+ updateNodeTheme: (theme) => ({ dispatch, state, tr }) => {
231
+ if (dispatch) tr.setDocAttribute(THEME_ATTRIBUTE, require_use_maily_editor.getMergedNodeTheme({
232
+ theme: getDocumentTheme(state.doc) ?? {},
233
+ update: theme
234
+ }));
235
+ return true;
236
+ },
237
+ updateShellTheme: (theme) => ({ dispatch, state, tr }) => {
238
+ if (dispatch) {
239
+ tr.setDocAttribute(THEME_ATTRIBUTE, require_use_maily_editor.getMergedNodeTheme({
240
+ theme: getDocumentTheme(state.doc) ?? {},
241
+ update: theme
242
+ }));
243
+ for (const [type, declarations] of Object.entries(theme)) {
244
+ if (!declarations) continue;
245
+ const cleared = getClearedDeclarations(declarations);
246
+ const shells = require_use_maily_editor.getShellNodes({
247
+ doc: state.doc,
248
+ type
249
+ });
250
+ for (const shell of shells) tr.setNodeAttribute(shell.position, "style", require_use_maily_editor.setStyleDeclarations(shell.node.attrs.style, cleared));
251
+ }
252
+ }
253
+ return true;
180
254
  }
181
255
  };
182
256
  },
183
- addNodeView() {
184
- return (0, _tiptap_react.ReactNodeViewRenderer)(LinkCardView, {
185
- className: "mly:relative",
186
- attrs: (props) => {
187
- return {
188
- [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name,
189
- ...props.node.attrs.visibilityRule ? { [_maily_to_shared.DATA_VISIBILITY_RULE_KEY]: "" } : {}
190
- };
191
- }
192
- });
193
- }
194
- });
195
- //#endregion
196
- //#region ../extension-inline-suggestion/dist/index.mjs
197
- const ESCAPE_KEY = "Escape";
198
- const SPACE_KEY = " ";
199
- const TAB_KEY = "Tab";
200
- const INLINE_SUGGESTION_PLUGIN_KEY = "inlineSuggestion";
201
- const inlineSuggestionPluginKey = new _tiptap_pm_state.PluginKey(INLINE_SUGGESTION_PLUGIN_KEY);
202
- const InlineSuggestion = _tiptap_core.Extension.create(() => {
203
- let requestVersion = 0;
204
- let abortController = null;
205
- let debounceTimer = null;
206
- function abortInflight() {
207
- if (abortController) {
208
- abortController.abort();
209
- abortController = null;
210
- }
211
- if (debounceTimer) {
212
- clearTimeout(debounceTimer);
213
- debounceTimer = null;
214
- }
215
- }
216
- return {
217
- name: INLINE_SUGGESTION_PLUGIN_KEY,
218
- addOptions() {
219
- return {
220
- suggest: async () => {
221
- console.warn(`${_maily_to_shared.MAILY_ERROR_PREFIX}: You must provide a "suggest" function to the InlineSuggestion extension.`);
222
- return "";
223
- },
224
- debounceTime: 250,
225
- triggerKey: SPACE_KEY,
226
- acceptKey: TAB_KEY
227
- };
228
- },
229
- addStorage() {
230
- return {
231
- currentSuggestion: void 0,
232
- nodeDetails: void 0
233
- };
234
- },
235
- onDestroy() {
236
- abortInflight();
237
- },
238
- onSelectionUpdate({ editor }) {
239
- const { currentSuggestion } = this.storage;
240
- if (!currentSuggestion) return;
241
- editor.commands.dismissSuggestion();
242
- },
243
- addCommands() {
257
+ addGlobalAttributes() {
258
+ return [{
259
+ types: [_maily_to_shared.MAILY_NODE_TYPES.DOCUMENT],
260
+ attributes: { theme: {
261
+ default: this.options.theme,
262
+ renderHTML: () => ({})
263
+ } }
264
+ }];
265
+ },
266
+ addProseMirrorPlugins() {
267
+ const fallback = this.options.theme;
268
+ const scope = `mly-theme-${Math.random().toString(36).slice(2, 10)}`;
269
+ const getScopedCss = (theme) => {
270
+ return require_use_maily_editor.getThemeCss({
271
+ scope: `[${SCOPE_ATTRIBUTE}="${scope}"]`,
272
+ theme: theme ?? fallback
273
+ });
274
+ };
275
+ return [new _tiptap_pm_state.Plugin({ view(view) {
276
+ view.dom.setAttribute(SCOPE_ATTRIBUTE, scope);
277
+ const element = document.createElement("style");
278
+ element.textContent = getScopedCss(getDocumentTheme(view.state.doc));
279
+ document.head.append(element);
244
280
  return {
245
- fetchSuggestion: () => ({ editor }) => {
246
- abortInflight();
247
- const version = ++requestVersion;
248
- const debounceMs = this.options.debounceTime ?? 250;
249
- debounceTimer = setTimeout(() => {
250
- const { state } = editor;
251
- const { $from } = state.selection;
252
- const node = $from.parent;
253
- const existingText = node.textContent;
254
- if (!existingText) return;
255
- if ($from.parentOffset < node.content.size) return;
256
- abortController = new AbortController();
257
- const { signal } = abortController;
258
- this.options.suggest(existingText, {
259
- editor,
260
- signal
261
- }).then((response) => {
262
- if (version !== requestVersion || signal.aborted) return;
263
- const trimmed = response.replace(/^\s+/, "");
264
- if (!trimmed) return;
265
- const { $from: current$from } = editor.state.selection;
266
- const freshFrom = current$from.start() - 1;
267
- const freshTo = current$from.end() + 1;
268
- this.storage.currentSuggestion = trimmed;
269
- this.storage.nodeDetails = {
270
- from: freshFrom,
271
- to: freshTo
272
- };
273
- editor.view.dispatch(editor.view.state.tr.setMeta("addToHistory", false));
274
- }).catch((err) => {
275
- if (err instanceof DOMException && err.name === "AbortError") return;
276
- console.error(`${_maily_to_shared.MAILY_ERROR_PREFIX}: Failed to fetch inline suggestion for "${existingText}".`, err);
277
- });
278
- }, debounceMs);
279
- return true;
281
+ update(current, prevState) {
282
+ const next = getDocumentTheme(current.state.doc);
283
+ if (getDocumentTheme(prevState.doc) === next) return;
284
+ element.textContent = getScopedCss(next);
280
285
  },
281
- insertSuggestion: () => ({ chain }) => {
282
- const suggestion = this.storage.currentSuggestion;
283
- if (!suggestion) return false;
284
- abortInflight();
285
- this.storage.currentSuggestion = void 0;
286
- this.storage.nodeDetails = void 0;
287
- return chain().insertContent(suggestion).run();
288
- },
289
- dismissSuggestion: () => ({ tr, dispatch }) => {
290
- if (!this.storage.currentSuggestion) return false;
291
- abortInflight();
292
- this.storage.currentSuggestion = void 0;
293
- this.storage.nodeDetails = void 0;
294
- if (dispatch) dispatch(tr.setMeta("addToHistory", false));
295
- return true;
286
+ destroy() {
287
+ element.remove();
288
+ view.dom.removeAttribute(SCOPE_ATTRIBUTE);
296
289
  }
297
290
  };
298
- },
299
- addProseMirrorPlugins() {
300
- const { storage, editor } = this;
301
- const acceptKey = this.options.acceptKey ?? TAB_KEY;
302
- const triggerKey = this.options.triggerKey;
303
- let lastData = {
304
- currentSuggestion: void 0,
305
- nodeDetails: void 0
306
- };
307
- return [new _tiptap_pm_state.Plugin({
308
- key: inlineSuggestionPluginKey,
309
- state: {
310
- init() {
311
- return _tiptap_pm_view.DecorationSet.empty;
312
- },
313
- apply(tr, oldDecorations) {
314
- const { currentSuggestion, nodeDetails } = storage;
315
- if (currentSuggestion === lastData.currentSuggestion && nodeDetails === lastData.nodeDetails) return oldDecorations.map(tr.mapping, tr.doc);
316
- lastData = {
317
- currentSuggestion,
318
- nodeDetails
319
- };
320
- if (currentSuggestion && nodeDetails) {
321
- const { from, to } = nodeDetails;
322
- if (from < 0 || to > tr.doc.content.size || from >= to) return _tiptap_pm_view.DecorationSet.empty;
323
- const decoration = _tiptap_pm_view.Decoration.node(from, to, { "data-inline-suggestion": currentSuggestion });
324
- return _tiptap_pm_view.DecorationSet.create(tr.doc, [decoration]);
325
- }
326
- return _tiptap_pm_view.DecorationSet.empty;
327
- }
328
- },
329
- props: {
330
- decorations(state) {
331
- return this.getState(state);
332
- },
333
- handleKeyDown(_view, event) {
334
- const hasSuggestion = !!storage.currentSuggestion;
335
- if (event.key === acceptKey && hasSuggestion) {
336
- event.preventDefault();
337
- event.stopPropagation();
338
- editor.commands.insertSuggestion();
339
- return true;
340
- }
341
- if (event.key === ESCAPE_KEY && hasSuggestion) {
342
- editor.commands.dismissSuggestion();
343
- return true;
344
- }
345
- if (hasSuggestion) editor.commands.dismissSuggestion();
346
- if (triggerKey !== null && event.key === triggerKey) requestAnimationFrame(() => {
347
- editor.commands.fetchSuggestion();
348
- });
349
- return false;
350
- }
351
- }
352
- })];
353
- }
354
- };
291
+ } })];
292
+ }
355
293
  });
356
294
  //#endregion
357
- exports.AIActions = require_spacer.AIActions;
358
- exports.BlockquoteExtension = require_spacer.BlockquoteExtension;
359
- exports.ButtonExtension = require_spacer.ButtonExtension;
360
- exports.ColumnExtension = require_spacer.ColumnExtension;
361
- exports.ColumnsExtension = require_spacer.ColumnsExtension;
362
- exports.FontStyleExtension = require_spacer.FontStyleExtension;
363
- exports.FooterExtension = require_spacer.FooterExtension;
364
- exports.HorizontalRuleExtension = require_spacer.HorizontalRuleExtension;
365
- exports.HtmlCodeBlockExtension = require_spacer.HtmlCodeBlockExtension;
366
- exports.ImageUploadExtension = require_spacer.ImageUploadExtension;
367
- exports.InlineImageExtension = require_spacer.InlineImageExtension;
368
- exports.InlineSuggestion = InlineSuggestion;
295
+ exports.ALLOWED_IMAGE_MIME_TYPES = require_use_maily_editor.ALLOWED_IMAGE_MIME_TYPES;
296
+ exports.BlockquoteExtension = require_use_maily_editor.BlockquoteExtension;
297
+ exports.BodyExtension = require_use_maily_editor.BodyExtension;
298
+ exports.BoldExtension = require_use_maily_editor.BoldExtension;
299
+ exports.ButtonExtension = require_use_maily_editor.ButtonExtension;
300
+ exports.CollaborationAttributesExtension = CollaborationAttributesExtension;
301
+ exports.ColumnExtension = require_use_maily_editor.ColumnExtension;
302
+ exports.ColumnsExtension = require_use_maily_editor.ColumnsExtension;
303
+ exports.ContainerExtension = require_use_maily_editor.ContainerExtension;
304
+ exports.DEFAULT_EXTENSIONS = require_use_maily_editor.DEFAULT_EXTENSIONS;
305
+ exports.DEFAULT_SLASH_COMMANDS = require_use_maily_editor.DEFAULT_SLASH_COMMANDS;
306
+ exports.FooterExtension = require_use_maily_editor.FooterExtension;
307
+ exports.HorizontalRuleExtension = require_use_maily_editor.HorizontalRuleExtension;
308
+ exports.HtmlCodeBlockExtension = require_use_maily_editor.HtmlCodeBlockExtension;
309
+ exports.IMAGE_UPLOAD_STATUSES = require_use_maily_editor.IMAGE_UPLOAD_STATUSES;
310
+ exports.ImageExtension = require_use_maily_editor.ImageExtension;
311
+ exports.ImageUploadExtension = require_use_maily_editor.ImageUploadExtension;
312
+ exports.InlineImageExtension = require_use_maily_editor.InlineImageExtension;
313
+ exports.InlineSpanExtension = require_use_maily_editor.InlineSpanExtension;
369
314
  exports.LinkCardExtension = LinkCardExtension;
370
- exports.RepeatExtension = require_spacer.RepeatExtension;
371
- exports.ResizableImageExtension = require_spacer.ResizableImageExtension;
372
- exports.SectionExtension = require_spacer.SectionExtension;
373
- exports.SlashCommandExtension = require_spacer.SlashCommandExtension;
374
- exports.SpacerExtension = require_spacer.SpacerExtension;
375
- exports.VariableExtension = require_spacer.VariableExtension;
376
- exports.VisibilityExtension = require_spacer.VisibilityExtension;
377
- exports.inlineSuggestionPluginKey = inlineSuggestionPluginKey;
315
+ exports.ProtectVariableTrigger = require_use_maily_editor.ProtectVariableTrigger;
316
+ exports.STYLE_SUPPORTED_TYPES = require_use_maily_editor.STYLE_SUPPORTED_TYPES;
317
+ exports.SectionExtension = require_use_maily_editor.SectionExtension;
318
+ exports.SlashCommandExtension = require_use_maily_editor.SlashCommandExtension;
319
+ exports.SpacerExtension = require_use_maily_editor.SpacerExtension;
320
+ exports.SpanExtension = require_use_maily_editor.SpanExtension;
321
+ exports.StyleExtension = require_use_maily_editor.StyleExtension;
322
+ exports.ThemeExtension = ThemeExtension;
323
+ exports.VISIBILITY_SUPPORTED_TYPES = require_use_maily_editor.VISIBILITY_SUPPORTED_TYPES;
324
+ exports.VariableExtension = require_use_maily_editor.VariableExtension;
325
+ exports.VisibilityExtension = require_use_maily_editor.VisibilityExtension;
326
+ exports.getNormalizedHtml = require_use_maily_editor.getNormalizedHtml;