@maily-to/core 2.0.0-beta.1 → 2.0.0-beta.11

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 (49) hide show
  1. package/LICENSE +21 -0
  2. package/dist/blocks/index.cjs +8 -1
  3. package/dist/blocks/index.d.cts +1 -38
  4. package/dist/blocks/index.d.mts +14 -6
  5. package/dist/blocks/index.d.mts.map +1 -1
  6. package/dist/blocks/index.mjs +2 -2
  7. package/dist/extensions/index.cjs +266 -286
  8. package/dist/extensions/index.d.cts +1 -379
  9. package/dist/extensions/index.d.mts +127 -224
  10. package/dist/extensions/index.d.mts.map +1 -1
  11. package/dist/extensions/index.mjs +238 -271
  12. package/dist/index.cjs +8717 -11689
  13. package/dist/index.d.cts +1 -107
  14. package/dist/index.d.mts +711 -73
  15. package/dist/index.d.mts.map +1 -1
  16. package/dist/index.mjs +8397 -11474
  17. package/dist/{slash-command-BmWRVPbv.d.mts → slash-command-BrwA1bHs.d.mts} +10 -11
  18. package/dist/slash-command-BrwA1bHs.d.mts.map +1 -0
  19. package/dist/theme-D1CI7_8s.d.mts +70 -0
  20. package/dist/theme-D1CI7_8s.d.mts.map +1 -0
  21. package/dist/typography-BdOKvXfQ.mjs +911 -0
  22. package/dist/typography-D-VnwOSw.cjs +970 -0
  23. package/dist/typography-DW7VApAR.cjs +1072 -0
  24. package/dist/use-maily-editor-Atvy2kSO.cjs +3993 -0
  25. package/dist/use-maily-editor-CByaDhmT.cjs +4955 -0
  26. package/dist/use-maily-editor-idL0RNsG.mjs +4504 -0
  27. package/package.json +102 -90
  28. package/readme.md +177 -133
  29. package/src/styles/index.css +2537 -0
  30. package/dist/blocks/index.d.cts.map +0 -1
  31. package/dist/chunk-CfYAbeIz.mjs +0 -13
  32. package/dist/extensions/index.d.cts.map +0 -1
  33. package/dist/extensions/index.mjs.map +0 -1
  34. package/dist/index.css +0 -2312
  35. package/dist/index.d.cts.map +0 -1
  36. package/dist/index.mjs.map +0 -1
  37. package/dist/slash-command-BmWRVPbv.d.mts.map +0 -1
  38. package/dist/slash-command-CK0-1FwR.d.cts +0 -39
  39. package/dist/slash-command-CK0-1FwR.d.cts.map +0 -1
  40. package/dist/spacer-DBtsr3hu.cjs +0 -5768
  41. package/dist/spacer-DzZWX-wB.mjs +0 -5456
  42. package/dist/spacer-DzZWX-wB.mjs.map +0 -1
  43. package/dist/typography-CWL13acR.cjs +0 -400
  44. package/dist/typography-DhrUe809.mjs +0 -282
  45. package/dist/typography-DhrUe809.mjs.map +0 -1
  46. package/dist/variable-C9S9ZoHv.d.cts +0 -108
  47. package/dist/variable-C9S9ZoHv.d.cts.map +0 -1
  48. package/dist/variable-DVwGrg2a.d.mts +0 -108
  49. package/dist/variable-DVwGrg2a.d.mts.map +0 -1
@@ -1,111 +1,163 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_spacer = require("../spacer-DBtsr3hu.cjs");
2
+ const require_use_maily_editor = require("../use-maily-editor-CByaDhmT.cjs");
3
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");
7
4
  let react_jsx_runtime = require("react/jsx-runtime");
8
5
  let lucide_react = require("lucide-react");
6
+ let _maily_to_shared = require("@maily-to/shared");
7
+ let _tiptap_react = require("@tiptap/react");
9
8
  let _tiptap_pm_state = require("@tiptap/pm/state");
10
9
  let _tiptap_core = require("@tiptap/core");
11
- let _tiptap_pm_view = require("@tiptap/pm/view");
10
+ //#region src/extensions/collaboration-attributes/collaboration-attributes.ts
11
+ const COLLABORATION_ATTRIBUTES_META = "collaborationAttributes";
12
+ function getAttributePaths(attributes, prefix = "") {
13
+ return Object.entries(attributes).flatMap(([name, value]) => {
14
+ return (0, _maily_to_shared.isMergeableObject)(value) ? getAttributePaths(value, `${prefix}${name}.`) : [[`${prefix}${name}`, value]];
15
+ });
16
+ }
17
+ function setAttributes(editor, changes) {
18
+ const attributes = structuredClone(editor.state.doc.attrs);
19
+ for (const [path, value] of changes) {
20
+ const names = path.split(".");
21
+ const last = names.pop();
22
+ let target = attributes;
23
+ for (const name of names) {
24
+ target[name] = (0, _maily_to_shared.isMergeableObject)(target[name]) ? target[name] : {};
25
+ target = target[name];
26
+ }
27
+ if (value === void 0) delete target[last];
28
+ else target[last] = value;
29
+ }
30
+ const { tr } = editor.state;
31
+ for (const [name, value] of Object.entries(attributes)) if (JSON.stringify(tr.doc.attrs[name]) !== JSON.stringify(value)) tr.setDocAttribute(name, value);
32
+ if (!tr.docChanged) return;
33
+ editor.view.dispatch(tr.setMeta(COLLABORATION_ATTRIBUTES_META, true).setMeta("addToHistory", false));
34
+ }
35
+ const CollaborationAttributesExtension = _tiptap_core.Extension.create({
36
+ name: "collaborationAttributes",
37
+ addOptions() {
38
+ return {
39
+ document: null,
40
+ field: "maily"
41
+ };
42
+ },
43
+ addStorage() {
44
+ return { unobserve: null };
45
+ },
46
+ onCreate() {
47
+ const { document, field } = this.options;
48
+ if (!document) return;
49
+ const map = document.getMap(field);
50
+ const observer = (event) => {
51
+ if (event.transaction.origin === this.editor) return;
52
+ setAttributes(this.editor, [...event.keysChanged].map((path) => [path, map.get(path)]));
53
+ };
54
+ setAttributes(this.editor, [...map.entries()]);
55
+ map.observe(observer);
56
+ this.storage.unobserve = () => map.unobserve(observer);
57
+ },
58
+ onTransaction({ transaction }) {
59
+ const { document, field } = this.options;
60
+ if (!document || transaction.getMeta(COLLABORATION_ATTRIBUTES_META) || transaction.before.attrs === transaction.doc.attrs) return;
61
+ const map = document.getMap(field);
62
+ const before = new Map(getAttributePaths(transaction.before.attrs));
63
+ const after = new Map(getAttributePaths(transaction.doc.attrs));
64
+ document.transact(() => {
65
+ for (const [path, value] of after) if (before.get(path) !== value) map.set(path, value);
66
+ for (const path of before.keys()) if (!after.has(path)) map.delete(path);
67
+ }, this.editor);
68
+ },
69
+ onDestroy() {
70
+ this.storage.unobserve?.();
71
+ this.storage.unobserve = null;
72
+ }
73
+ });
74
+ //#endregion
12
75
  //#region src/extensions/link-card/link-card-view.tsx
13
76
  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";
18
- }
19
- const { editor, node, getPos } = props;
20
- const { title, description, link, linkTitle, image, subTitle, badgeText } = node.attrs;
77
+ const $ = (0, react_compiler_runtime.c)(17);
78
+ const { editor, getPos, node } = props;
79
+ const { badgeText, description, image, link, linkTitle, subTitle, title } = node.attrs;
21
80
  let t0;
22
- if ($[1] !== editor.commands || $[2] !== editor.isEditable || $[3] !== getPos) {
81
+ if ($[0] !== editor.commands || $[1] !== editor.isEditable || $[2] !== getPos) {
23
82
  t0 = () => {
24
83
  if (!editor.isEditable) return;
25
84
  const pos = getPos();
26
85
  if (pos === void 0) return;
27
86
  editor.commands.setNodeSelection(pos);
28
87
  };
29
- $[1] = editor.commands;
30
- $[2] = editor.isEditable;
31
- $[3] = getPos;
32
- $[4] = t0;
33
- } else t0 = $[4];
88
+ $[0] = editor.commands;
89
+ $[1] = editor.isEditable;
90
+ $[2] = getPos;
91
+ $[3] = t0;
92
+ } else t0 = $[3];
34
93
  const handleClick = t0;
35
- const isEmpty = !title && !description && !image;
94
+ const isEmpty = !(title || description || image);
36
95
  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];
96
+ if ($[4] !== badgeText || $[5] !== description || $[6] !== image || $[7] !== isEmpty || $[8] !== link || $[9] !== linkTitle || $[10] !== subTitle || $[11] !== title) {
97
+ t1 = isEmpty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_use_maily_editor.ImageState, {
98
+ icon: lucide_react.SquareArrowOutUpRightIcon,
99
+ state: "idle",
100
+ children: "Link Card"
101
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [image ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
102
+ alt: title || "Link card",
103
+ "data-mly-link-card-image": "",
104
+ draggable: false,
105
+ src: image
106
+ }) : null, /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
107
+ "data-mly-link-card-content": "",
108
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
109
+ "data-mly-link-card-heading": "",
110
+ children: [
111
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
112
+ "data-mly-link-card-title": "",
113
+ children: title
114
+ }),
115
+ badgeText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
116
+ "data-mly-link-card-badge": "",
117
+ children: badgeText
118
+ }) : null,
119
+ subTitle && !badgeText ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
120
+ "data-mly-link-card-sub-title": "",
121
+ children: subTitle
122
+ }) : null
123
+ ]
124
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
125
+ "data-mly-link-card-description": "",
126
+ children: [
127
+ description,
128
+ " ",
129
+ linkTitle ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
130
+ "data-mly-link-card-cta": "",
131
+ href: link,
132
+ children: linkTitle
133
+ }) : null
134
+ ]
135
+ })]
136
+ })] });
137
+ $[4] = badgeText;
138
+ $[5] = description;
139
+ $[6] = image;
140
+ $[7] = isEmpty;
141
+ $[8] = link;
142
+ $[9] = linkTitle;
143
+ $[10] = subTitle;
144
+ $[11] = title;
145
+ $[12] = t1;
146
+ } else t1 = $[12];
95
147
  let t2;
96
- if ($[15] !== editor.isEditable || $[16] !== handleClick || $[17] !== t1) {
148
+ if ($[13] !== editor.isEditable || $[14] !== handleClick || $[15] !== t1) {
97
149
  t2 = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, {
98
- className: "not-prose mly:cursor-default",
99
- draggable: editor.isEditable,
100
150
  "data-drag-handle": editor.isEditable,
151
+ "data-mly-link-card": "",
152
+ draggable: editor.isEditable,
101
153
  onClick: handleClick,
102
154
  children: t1
103
155
  });
104
- $[15] = editor.isEditable;
105
- $[16] = handleClick;
106
- $[17] = t1;
107
- $[18] = t2;
108
- } else t2 = $[18];
156
+ $[13] = editor.isEditable;
157
+ $[14] = handleClick;
158
+ $[15] = t1;
159
+ $[16] = t2;
160
+ } else t2 = $[16];
109
161
  return t2;
110
162
  }
111
163
  //#endregion
@@ -115,6 +167,9 @@ const LinkCardExtension = _tiptap_core.Node.create({
115
167
  group: "block",
116
168
  atom: true,
117
169
  draggable: true,
170
+ addOptions() {
171
+ return { HTMLAttributes: {} };
172
+ },
118
173
  addAttributes() {
119
174
  return {
120
175
  title: {
@@ -154,224 +209,149 @@ const LinkCardExtension = _tiptap_core.Node.create({
154
209
  }
155
210
  };
156
211
  },
212
+ addCommands() {
213
+ return {
214
+ setLinkCard: (attrs) => ({ commands }) => {
215
+ return commands.insertContent({
216
+ type: this.name,
217
+ attrs
218
+ });
219
+ },
220
+ updateLinkCardAttributes: (attrs) => ({ commands }) => {
221
+ return commands.updateAttributes(this.name, attrs);
222
+ }
223
+ };
224
+ },
157
225
  parseHTML() {
158
226
  return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${this.name}"]` }];
159
227
  },
160
228
  renderHTML({ HTMLAttributes }) {
161
- return ["div", (0, _tiptap_core.mergeAttributes)(HTMLAttributes, {
229
+ return ["div", (0, _tiptap_core.mergeAttributes)({
162
230
  [_maily_to_shared.DATA_NODE_TYPE_KEY]: this.name,
163
231
  contenteditable: false
164
- })];
232
+ }, this.options.HTMLAttributes, HTMLAttributes)];
233
+ },
234
+ addNodeView() {
235
+ return (0, _tiptap_react.ReactNodeViewRenderer)(LinkCardView, { attrs: () => ({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.LINK_CARD }) });
236
+ }
237
+ });
238
+ //#endregion
239
+ //#region src/extensions/theme/theme.ts
240
+ const SCOPE_ATTRIBUTE = "data-mly-theme-scope";
241
+ const THEME_ATTRIBUTE = "theme";
242
+ function getDocumentTheme(doc) {
243
+ return doc.attrs.theme;
244
+ }
245
+ function getClearedDeclarations(declarations) {
246
+ return Object.fromEntries(Object.keys(declarations).map((property) => {
247
+ return [property, null];
248
+ }));
249
+ }
250
+ const ThemeExtension = _tiptap_core.Extension.create({
251
+ name: _maily_to_shared.MAILY_EXTENSION_TYPES.THEME,
252
+ addOptions() {
253
+ return { theme: {} };
165
254
  },
166
255
  addCommands() {
167
256
  return {
168
- setLinkCard: (attrs) => {
169
- return ({ commands }) => {
170
- return commands.insertContent({
171
- type: this.name,
172
- attrs
173
- });
174
- };
257
+ setNodeTheme: (theme) => ({ dispatch, tr }) => {
258
+ if (dispatch) tr.setDocAttribute(THEME_ATTRIBUTE, theme);
259
+ return true;
175
260
  },
176
- updateLinkCardAttributes: (attrs) => {
177
- return ({ commands }) => {
178
- return commands.updateAttributes(this.name, attrs);
179
- };
261
+ updateNodeTheme: (theme) => ({ dispatch, state, tr }) => {
262
+ if (dispatch) tr.setDocAttribute(THEME_ATTRIBUTE, require_use_maily_editor.getMergedNodeTheme({
263
+ theme: getDocumentTheme(state.doc) ?? {},
264
+ update: theme
265
+ }));
266
+ return true;
267
+ },
268
+ updateShellTheme: (theme) => ({ dispatch, state, tr }) => {
269
+ if (dispatch) {
270
+ tr.setDocAttribute(THEME_ATTRIBUTE, require_use_maily_editor.getMergedNodeTheme({
271
+ theme: getDocumentTheme(state.doc) ?? {},
272
+ update: theme
273
+ }));
274
+ for (const [type, declarations] of Object.entries(theme)) {
275
+ if (!declarations) continue;
276
+ const cleared = getClearedDeclarations(declarations);
277
+ const shells = require_use_maily_editor.getShellNodes({
278
+ doc: state.doc,
279
+ type
280
+ });
281
+ for (const shell of shells) tr.setNodeAttribute(shell.position, "style", require_use_maily_editor.setStyleDeclarations(shell.node.attrs.style, cleared));
282
+ }
283
+ }
284
+ return true;
180
285
  }
181
286
  };
182
287
  },
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() {
288
+ addGlobalAttributes() {
289
+ return [{
290
+ types: [_maily_to_shared.MAILY_NODE_TYPES.DOCUMENT],
291
+ attributes: { theme: {
292
+ default: this.options.theme,
293
+ renderHTML: () => ({})
294
+ } }
295
+ }];
296
+ },
297
+ addProseMirrorPlugins() {
298
+ const fallback = this.options.theme;
299
+ const scope = `mly-theme-${Math.random().toString(36).slice(2, 10)}`;
300
+ const getScopedCss = (theme) => {
301
+ return require_use_maily_editor.getThemeCss({
302
+ scope: `[${SCOPE_ATTRIBUTE}="${scope}"]`,
303
+ theme: theme ?? fallback
304
+ });
305
+ };
306
+ return [new _tiptap_pm_state.Plugin({ view(view) {
307
+ view.dom.setAttribute(SCOPE_ATTRIBUTE, scope);
308
+ const element = document.createElement("style");
309
+ element.textContent = getScopedCss(getDocumentTheme(view.state.doc));
310
+ document.head.append(element);
244
311
  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;
280
- },
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();
312
+ update(current, prevState) {
313
+ const next = getDocumentTheme(current.state.doc);
314
+ if (getDocumentTheme(prevState.doc) === next) return;
315
+ element.textContent = getScopedCss(next);
288
316
  },
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;
317
+ destroy() {
318
+ element.remove();
319
+ view.dom.removeAttribute(SCOPE_ATTRIBUTE);
296
320
  }
297
321
  };
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
- };
322
+ } })];
323
+ }
355
324
  });
356
325
  //#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;
326
+ exports.ALLOWED_IMAGE_MIME_TYPES = require_use_maily_editor.ALLOWED_IMAGE_MIME_TYPES;
327
+ exports.BlockquoteExtension = require_use_maily_editor.BlockquoteExtension;
328
+ exports.BodyExtension = require_use_maily_editor.BodyExtension;
329
+ exports.BoldExtension = require_use_maily_editor.BoldExtension;
330
+ exports.ButtonExtension = require_use_maily_editor.ButtonExtension;
331
+ exports.CollaborationAttributesExtension = CollaborationAttributesExtension;
332
+ exports.ColumnExtension = require_use_maily_editor.ColumnExtension;
333
+ exports.ColumnsExtension = require_use_maily_editor.ColumnsExtension;
334
+ exports.ContainerExtension = require_use_maily_editor.ContainerExtension;
335
+ exports.DEFAULT_EXTENSIONS = require_use_maily_editor.DEFAULT_EXTENSIONS;
336
+ exports.DEFAULT_SLASH_COMMANDS = require_use_maily_editor.DEFAULT_SLASH_COMMANDS;
337
+ exports.FooterExtension = require_use_maily_editor.FooterExtension;
338
+ exports.HorizontalRuleExtension = require_use_maily_editor.HorizontalRuleExtension;
339
+ exports.HtmlCodeBlockExtension = require_use_maily_editor.HtmlCodeBlockExtension;
340
+ exports.IMAGE_UPLOAD_STATUSES = require_use_maily_editor.IMAGE_UPLOAD_STATUSES;
341
+ exports.ImageExtension = require_use_maily_editor.ImageExtension;
342
+ exports.ImageUploadExtension = require_use_maily_editor.ImageUploadExtension;
343
+ exports.InlineImageExtension = require_use_maily_editor.InlineImageExtension;
344
+ exports.InlineSpanExtension = require_use_maily_editor.InlineSpanExtension;
369
345
  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;
346
+ exports.ProtectVariableTrigger = require_use_maily_editor.ProtectVariableTrigger;
347
+ exports.STYLE_SUPPORTED_TYPES = require_use_maily_editor.STYLE_SUPPORTED_TYPES;
348
+ exports.SectionExtension = require_use_maily_editor.SectionExtension;
349
+ exports.SlashCommandExtension = require_use_maily_editor.SlashCommandExtension;
350
+ exports.SpacerExtension = require_use_maily_editor.SpacerExtension;
351
+ exports.SpanExtension = require_use_maily_editor.SpanExtension;
352
+ exports.StyleExtension = require_use_maily_editor.StyleExtension;
353
+ exports.ThemeExtension = ThemeExtension;
354
+ exports.VISIBILITY_SUPPORTED_TYPES = require_use_maily_editor.VISIBILITY_SUPPORTED_TYPES;
355
+ exports.VariableExtension = require_use_maily_editor.VariableExtension;
356
+ exports.VisibilityExtension = require_use_maily_editor.VisibilityExtension;
357
+ exports.getNormalizedHtml = require_use_maily_editor.getNormalizedHtml;