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