@react-email/editor 0.0.0-experimental.42 → 0.0.0-experimental.44
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/core/index.cjs +4 -3
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +3 -3
- package/dist/core/index.mjs +3 -3
- package/dist/{create-paste-handler-CGR738bC.d.mts → create-paste-handler-DsJYKisA.d.mts} +1 -1
- package/dist/{create-paste-handler-CGR738bC.d.mts.map → create-paste-handler-DsJYKisA.d.mts.map} +1 -1
- package/dist/{event-bus-CHEzOS_O.mjs → event-bus-BFzKTuhV.mjs} +34 -3
- package/dist/event-bus-BFzKTuhV.mjs.map +1 -0
- package/dist/{event-bus-fb8U7hrl.cjs → event-bus-D-uahiao.cjs} +58 -3
- package/dist/{extension-BZsTEb_s.mjs → extension-B_ImOuII.mjs} +298 -11
- package/dist/extension-B_ImOuII.mjs.map +1 -0
- package/dist/{extension-D23sh0Nj.cjs → extension-DHsEsAaO.cjs} +298 -35
- package/dist/extensions/index.cjs +3 -3
- package/dist/extensions/index.d.cts +3 -1
- package/dist/extensions/index.d.cts.map +1 -1
- package/dist/extensions/index.d.mts +4 -2
- package/dist/extensions/index.d.mts.map +1 -1
- package/dist/extensions/index.mjs +3 -3
- package/dist/{extensions-D-VkzZTa.mjs → extensions-CLBkYvzM.mjs} +76 -45
- package/dist/extensions-CLBkYvzM.mjs.map +1 -0
- package/dist/{extensions-wGY7l1wH.cjs → extensions-ZVX3PUnH.cjs} +83 -52
- package/dist/{styles-C-cCyJCn.cjs → global-content-6jVh6L0b.mjs} +87 -17
- package/dist/global-content-6jVh6L0b.mjs.map +1 -0
- package/dist/{styles-_TMw3YxC.mjs → global-content-D3TNgSN6.cjs} +130 -2
- package/dist/{index-CxX7W63O.d.mts → index-BL2rehV8.d.mts} +68 -4
- package/dist/index-BL2rehV8.d.mts.map +1 -0
- package/dist/{index-C4KcMQ0R.d.cts → index-DJgMqa5C.d.cts} +67 -3
- package/dist/index-DJgMqa5C.d.cts.map +1 -0
- package/dist/index.cjs +5 -10
- package/dist/index.css +339 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +3 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +8 -13
- package/dist/index.mjs.map +1 -1
- package/dist/plugins/index.cjs +1 -5
- package/dist/plugins/index.d.cts +5 -123
- package/dist/plugins/index.d.cts.map +1 -1
- package/dist/plugins/index.d.mts +5 -123
- package/dist/plugins/index.d.mts.map +1 -1
- package/dist/plugins/index.mjs +2 -2
- package/dist/{root-Jq1R3tkX.cjs → root-CEAehvsX.cjs} +75 -88
- package/dist/{root-pS4l8bVZ.mjs → root-CJuwiIRn.mjs} +83 -84
- package/dist/root-CJuwiIRn.mjs.map +1 -0
- package/dist/{set-text-alignment-OA8IMWmO.mjs → set-text-alignment-GMXOPMlJ.mjs} +1 -1
- package/dist/{set-text-alignment-OA8IMWmO.mjs.map → set-text-alignment-GMXOPMlJ.mjs.map} +1 -1
- package/dist/types-BNEbRz-a.d.cts +47 -0
- package/dist/types-BNEbRz-a.d.cts.map +1 -0
- package/dist/types-C8k-blF7.d.mts +47 -0
- package/dist/types-C8k-blF7.d.mts.map +1 -0
- package/dist/ui/index.cjs +2970 -20
- package/dist/ui/index.d.cts +472 -160
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.mts +514 -202
- package/dist/ui/index.d.mts.map +1 -1
- package/dist/ui/index.mjs +2929 -3
- package/dist/ui/index.mjs.map +1 -1
- package/dist/ui/inspector/inspector.css +338 -0
- package/dist/ui/themes/default.css +339 -0
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.mjs +1 -1
- package/package.json +6 -4
- package/readme.md +69 -0
- package/dist/event-bus-CHEzOS_O.mjs.map +0 -1
- package/dist/extension-BZsTEb_s.mjs.map +0 -1
- package/dist/extensions-D-VkzZTa.mjs.map +0 -1
- package/dist/global-content-D_WYaFgX.mjs +0 -78
- package/dist/global-content-D_WYaFgX.mjs.map +0 -1
- package/dist/global-content-bJgotqmA.cjs +0 -89
- package/dist/index-C4KcMQ0R.d.cts.map +0 -1
- package/dist/index-CxX7W63O.d.mts.map +0 -1
- package/dist/root-pS4l8bVZ.mjs.map +0 -1
- package/dist/styles-_TMw3YxC.mjs.map +0 -1
- /package/dist/{set-text-alignment-Cv72txmv.cjs → set-text-alignment-aNb7Ml9N.cjs} +0 -0
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
const require_event_bus = require('./event-bus-
|
|
2
|
-
const
|
|
3
|
-
const require_global_content = require('./global-content-bJgotqmA.cjs');
|
|
4
|
-
let _tiptap_extensions = require("@tiptap/extensions");
|
|
1
|
+
const require_event_bus = require('./event-bus-D-uahiao.cjs');
|
|
2
|
+
const require_global_content = require('./global-content-D3TNgSN6.cjs');
|
|
5
3
|
let _tiptap_react = require("@tiptap/react");
|
|
6
4
|
let react = require("react");
|
|
7
5
|
react = require_event_bus.__toESM(react);
|
|
@@ -10,6 +8,7 @@ let _react_email_components = require("@react-email/components");
|
|
|
10
8
|
_react_email_components = require_event_bus.__toESM(_react_email_components);
|
|
11
9
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
12
10
|
let _tiptap_core = require("@tiptap/core");
|
|
11
|
+
let _tiptap_extensions = require("@tiptap/extensions");
|
|
13
12
|
let _tiptap_starter_kit = require("@tiptap/starter-kit");
|
|
14
13
|
_tiptap_starter_kit = require_event_bus.__toESM(_tiptap_starter_kit);
|
|
15
14
|
let _tiptap_extension_blockquote = require("@tiptap/extension-blockquote");
|
|
@@ -236,6 +235,13 @@ var EmailMark = class EmailMark extends _tiptap_core.Mark {
|
|
|
236
235
|
//#endregion
|
|
237
236
|
//#region src/core/serializer/compose-react-email.tsx
|
|
238
237
|
const NODES_WITH_INCREMENTED_CHILD_DEPTH = new Set(["bulletList", "orderedList"]);
|
|
238
|
+
function getMarkRank(schema, markName) {
|
|
239
|
+
return schema.marks[markName]?.rank ?? Number.MAX_SAFE_INTEGER;
|
|
240
|
+
}
|
|
241
|
+
/** Sort marks by schema rank (Tiptap extension priority → ProseMirror order). */
|
|
242
|
+
function sortMarksBySchema(marks, schema) {
|
|
243
|
+
return [...marks].sort((a, b) => getMarkRank(schema, b.type) - getMarkRank(schema, a.type));
|
|
244
|
+
}
|
|
239
245
|
const composeReactEmail = async ({ editor, preview }) => {
|
|
240
246
|
const data = editor.getJSON();
|
|
241
247
|
const extensions = editor.extensionManager.extensions;
|
|
@@ -245,7 +251,7 @@ const composeReactEmail = async ({ editor, preview }) => {
|
|
|
245
251
|
if (!content) return;
|
|
246
252
|
return content.map((node, index) => {
|
|
247
253
|
const style = serializerPlugin?.getNodeStyles(node, depth, editor) ?? {};
|
|
248
|
-
const inlineStyles =
|
|
254
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
249
255
|
if (!node.type) return null;
|
|
250
256
|
const emailNode = typeToExtensionMap[node.type];
|
|
251
257
|
if (!emailNode || !(emailNode instanceof require_event_bus.EmailNode)) return null;
|
|
@@ -263,7 +269,7 @@ const composeReactEmail = async ({ editor, preview }) => {
|
|
|
263
269
|
extension: emailNode,
|
|
264
270
|
children: parseContent(node.content, childDepth)
|
|
265
271
|
}, index);
|
|
266
|
-
if (node.marks) for (const mark of node.marks) {
|
|
272
|
+
if (node.marks) for (const mark of sortMarksBySchema(node.marks, editor.schema)) {
|
|
267
273
|
const emailMark = typeToExtensionMap[mark.type];
|
|
268
274
|
if (emailMark instanceof EmailMark) {
|
|
269
275
|
const MarkComponent = emailMark.config.renderToReactEmail;
|
|
@@ -366,7 +372,7 @@ const Blockquote = require_event_bus.EmailNode.from(_tiptap_extension_blockquote
|
|
|
366
372
|
className: node.attrs?.class || void 0,
|
|
367
373
|
style: {
|
|
368
374
|
...style,
|
|
369
|
-
...
|
|
375
|
+
...require_global_content.inlineCssToJs(node.attrs?.style),
|
|
370
376
|
...getTextAlignment(node.attrs?.align || node.attrs?.alignment)
|
|
371
377
|
},
|
|
372
378
|
children
|
|
@@ -405,7 +411,7 @@ const Body = require_event_bus.EmailNode.create({
|
|
|
405
411
|
];
|
|
406
412
|
},
|
|
407
413
|
renderToReactEmail({ children, node, style }) {
|
|
408
|
-
const inlineStyles =
|
|
414
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
409
415
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
410
416
|
className: node.attrs?.class || void 0,
|
|
411
417
|
style: {
|
|
@@ -443,7 +449,7 @@ const BulletList = require_event_bus.EmailNode.from(_tiptap_extension_bullet_lis
|
|
|
443
449
|
className: node.attrs?.class || void 0,
|
|
444
450
|
style: {
|
|
445
451
|
...style,
|
|
446
|
-
...
|
|
452
|
+
...require_global_content.inlineCssToJs(node.attrs?.style)
|
|
447
453
|
},
|
|
448
454
|
children
|
|
449
455
|
}));
|
|
@@ -511,7 +517,7 @@ const Button = require_event_bus.EmailNode.create({
|
|
|
511
517
|
};
|
|
512
518
|
},
|
|
513
519
|
renderToReactEmail({ children, node, style }) {
|
|
514
|
-
const inlineStyles =
|
|
520
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
515
521
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Row, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
|
|
516
522
|
align: node.attrs?.align || node.attrs?.alignment,
|
|
517
523
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Button, {
|
|
@@ -574,31 +580,11 @@ const ClassAttribute = _tiptap_core.Extension.create({
|
|
|
574
580
|
const Code = EmailMark.from(_tiptap_extension_code.default, ({ children, node, style }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", {
|
|
575
581
|
style: {
|
|
576
582
|
...style,
|
|
577
|
-
...
|
|
583
|
+
...require_global_content.inlineCssToJs(node.attrs?.style)
|
|
578
584
|
},
|
|
579
585
|
children
|
|
580
586
|
}));
|
|
581
587
|
|
|
582
|
-
//#endregion
|
|
583
|
-
//#region src/utils/prism-utils.ts
|
|
584
|
-
const publicURL = "/styles/prism";
|
|
585
|
-
function loadPrismTheme(theme) {
|
|
586
|
-
const link = document.createElement("link");
|
|
587
|
-
link.rel = "stylesheet";
|
|
588
|
-
link.href = `${publicURL}/prism-${theme}.css`;
|
|
589
|
-
link.setAttribute("data-prism-theme", "");
|
|
590
|
-
document.head.appendChild(link);
|
|
591
|
-
}
|
|
592
|
-
function removePrismTheme() {
|
|
593
|
-
const existingTheme = document.querySelectorAll("link[rel=\"stylesheet\"][data-prism-theme]");
|
|
594
|
-
if (existingTheme.length > 0) existingTheme.forEach((cssLinkTag) => {
|
|
595
|
-
cssLinkTag.remove();
|
|
596
|
-
});
|
|
597
|
-
}
|
|
598
|
-
function hasPrismThemeLoaded(theme) {
|
|
599
|
-
return !!document.querySelector(`link[rel="stylesheet"][data-prism-theme][href="${publicURL}/prism-${theme}.css"]`);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
588
|
//#endregion
|
|
603
589
|
//#region src/extensions/prism-plugin.ts
|
|
604
590
|
const PRISM_LANGUAGE_LOADED_META = "prismLanguageLoaded";
|
|
@@ -636,7 +622,7 @@ function getDecorations({ doc, name, defaultLanguage, defaultTheme, loadingLangu
|
|
|
636
622
|
loadingLanguages.delete(language);
|
|
637
623
|
});
|
|
638
624
|
}
|
|
639
|
-
if (!hasPrismThemeLoaded(theme)) loadPrismTheme(theme);
|
|
625
|
+
if (!require_event_bus.hasPrismThemeLoaded(theme)) require_event_bus.loadPrismTheme(theme);
|
|
640
626
|
html = prismjs.default.highlight(block.node.textContent, prismjs.default.languages[language], language);
|
|
641
627
|
} catch {
|
|
642
628
|
html = prismjs.default.highlight(block.node.textContent, prismjs.default.languages.javascript, "js");
|
|
@@ -704,7 +690,7 @@ function PrismPlugin({ name, defaultLanguage, defaultTheme }) {
|
|
|
704
690
|
} },
|
|
705
691
|
destroy() {
|
|
706
692
|
pluginView = null;
|
|
707
|
-
removePrismTheme();
|
|
693
|
+
require_event_bus.removePrismTheme();
|
|
708
694
|
}
|
|
709
695
|
});
|
|
710
696
|
return prismjsPlugin;
|
|
@@ -899,7 +885,7 @@ const Container = require_event_bus.EmailNode.create({
|
|
|
899
885
|
})];
|
|
900
886
|
},
|
|
901
887
|
renderToReactEmail({ children, node, style }) {
|
|
902
|
-
const inlineStyles =
|
|
888
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
903
889
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Container, {
|
|
904
890
|
className: node.attrs?.class || void 0,
|
|
905
891
|
align: style.align || "center",
|
|
@@ -947,7 +933,7 @@ const Div = require_event_bus.EmailNode.create({
|
|
|
947
933
|
return { ...require_event_bus.createStandardAttributes([...require_event_bus.COMMON_HTML_ATTRIBUTES, ...require_event_bus.LAYOUT_ATTRIBUTES]) };
|
|
948
934
|
},
|
|
949
935
|
renderToReactEmail({ children, node, style }) {
|
|
950
|
-
const inlineStyles =
|
|
936
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
951
937
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
952
938
|
className: node.attrs?.class || void 0,
|
|
953
939
|
style: {
|
|
@@ -990,7 +976,7 @@ function useEditor({ content, extensions = [], onUpdate, onPaste, onUploadImage,
|
|
|
990
976
|
const [contentError, setContentError] = react.useState(null);
|
|
991
977
|
const isCollaborative = hasCollaborationExtension(extensions);
|
|
992
978
|
const effectiveExtensions = react.useMemo(() => [
|
|
993
|
-
StarterKit,
|
|
979
|
+
StarterKit.configure({ UndoRedo: false }),
|
|
994
980
|
...isCollaborative ? [] : [_tiptap_extensions.UndoRedo],
|
|
995
981
|
...extensions
|
|
996
982
|
], [extensions, isCollaborative]);
|
|
@@ -1074,7 +1060,7 @@ const Divider = require_event_bus.EmailNode.from(_tiptap_extension_horizontal_ru
|
|
|
1074
1060
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Hr, {
|
|
1075
1061
|
...rest,
|
|
1076
1062
|
className: "node-hr",
|
|
1077
|
-
style:
|
|
1063
|
+
style: require_global_content.inlineCssToJs(node.attrs.style)
|
|
1078
1064
|
}) });
|
|
1079
1065
|
});
|
|
1080
1066
|
}
|
|
@@ -1083,7 +1069,7 @@ const Divider = require_event_bus.EmailNode.from(_tiptap_extension_horizontal_ru
|
|
|
1083
1069
|
className: node.attrs?.class || void 0,
|
|
1084
1070
|
style: {
|
|
1085
1071
|
...style,
|
|
1086
|
-
...
|
|
1072
|
+
...require_global_content.inlineCssToJs(node.attrs?.style)
|
|
1087
1073
|
}
|
|
1088
1074
|
});
|
|
1089
1075
|
});
|
|
@@ -1101,7 +1087,7 @@ const Heading = require_event_bus.EmailNode.from(_tiptap_extension_heading.Headi
|
|
|
1101
1087
|
const attrs = {
|
|
1102
1088
|
...rest,
|
|
1103
1089
|
className: `node-h${level} ${className}`,
|
|
1104
|
-
style:
|
|
1090
|
+
style: require_global_content.inlineCssToJs(node.attrs.style)
|
|
1105
1091
|
};
|
|
1106
1092
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_tiptap_react.NodeViewWrapper, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Heading, {
|
|
1107
1093
|
as: `h${level}`,
|
|
@@ -1115,7 +1101,7 @@ const Heading = require_event_bus.EmailNode.from(_tiptap_extension_heading.Headi
|
|
|
1115
1101
|
className: node.attrs?.class || void 0,
|
|
1116
1102
|
style: {
|
|
1117
1103
|
...style,
|
|
1118
|
-
...
|
|
1104
|
+
...require_global_content.inlineCssToJs(node.attrs?.style),
|
|
1119
1105
|
...getTextAlignment(node.attrs?.align ?? node.attrs?.alignment)
|
|
1120
1106
|
},
|
|
1121
1107
|
children
|
|
@@ -1163,7 +1149,7 @@ const PreservedStyle = EmailMark.create({
|
|
|
1163
1149
|
},
|
|
1164
1150
|
renderToReactEmail({ children, mark }) {
|
|
1165
1151
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
1166
|
-
style: mark.attrs?.style ?
|
|
1152
|
+
style: mark.attrs?.style ? require_global_content.inlineCssToJs(mark.attrs.style) : void 0,
|
|
1167
1153
|
children
|
|
1168
1154
|
});
|
|
1169
1155
|
}
|
|
@@ -1212,7 +1198,7 @@ function processStylesForUnlink(styleString) {
|
|
|
1212
1198
|
//#endregion
|
|
1213
1199
|
//#region src/extensions/link.tsx
|
|
1214
1200
|
const Link = EmailMark.from(_tiptap_extension_link.default, ({ children, mark, style }) => {
|
|
1215
|
-
const linkMarkStyle = mark.attrs?.style ?
|
|
1201
|
+
const linkMarkStyle = mark.attrs?.style ? require_global_content.inlineCssToJs(mark.attrs.style) : {};
|
|
1216
1202
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Link, {
|
|
1217
1203
|
href: mark.attrs?.href ?? void 0,
|
|
1218
1204
|
rel: mark.attrs?.rel ?? void 0,
|
|
@@ -1289,7 +1275,7 @@ const ListItem = require_event_bus.EmailNode.from(_tiptap_extension_list_item.de
|
|
|
1289
1275
|
className: node.attrs?.class || void 0,
|
|
1290
1276
|
style: {
|
|
1291
1277
|
...style,
|
|
1292
|
-
...
|
|
1278
|
+
...require_global_content.inlineCssToJs(node.attrs?.style),
|
|
1293
1279
|
...getTextAlignment(node.attrs?.align || node.attrs?.alignment)
|
|
1294
1280
|
},
|
|
1295
1281
|
children
|
|
@@ -1377,7 +1363,7 @@ const OrderedList = require_event_bus.EmailNode.from(_tiptap_extension_ordered_l
|
|
|
1377
1363
|
start: node.attrs?.start,
|
|
1378
1364
|
style: {
|
|
1379
1365
|
...style,
|
|
1380
|
-
...
|
|
1366
|
+
...require_global_content.inlineCssToJs(node.attrs?.style)
|
|
1381
1367
|
},
|
|
1382
1368
|
children
|
|
1383
1369
|
}));
|
|
@@ -1390,7 +1376,7 @@ const Paragraph = require_event_bus.EmailNode.from(_tiptap_extension_paragraph.d
|
|
|
1390
1376
|
className: node.attrs?.class || void 0,
|
|
1391
1377
|
style: {
|
|
1392
1378
|
...style,
|
|
1393
|
-
...
|
|
1379
|
+
...require_global_content.inlineCssToJs(node.attrs?.style),
|
|
1394
1380
|
...getTextAlignment(node.attrs?.align || node.attrs?.alignment)
|
|
1395
1381
|
},
|
|
1396
1382
|
children: isEmpty ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("br", {}) : children
|
|
@@ -1450,6 +1436,9 @@ const PreviewText = _tiptap_core.Node.create({
|
|
|
1450
1436
|
|
|
1451
1437
|
//#endregion
|
|
1452
1438
|
//#region src/extensions/section.tsx
|
|
1439
|
+
function isSectionEmpty(node) {
|
|
1440
|
+
return node.textContent === "" && node.content.size <= node.childCount * 2;
|
|
1441
|
+
}
|
|
1453
1442
|
const Section$1 = require_event_bus.EmailNode.create({
|
|
1454
1443
|
name: "section",
|
|
1455
1444
|
group: "block",
|
|
@@ -1469,6 +1458,46 @@ const Section$1 = require_event_bus.EmailNode.create({
|
|
|
1469
1458
|
0
|
|
1470
1459
|
];
|
|
1471
1460
|
},
|
|
1461
|
+
addKeyboardShortcuts() {
|
|
1462
|
+
return { Backspace: ({ editor }) => {
|
|
1463
|
+
const { state } = editor;
|
|
1464
|
+
const { selection } = state;
|
|
1465
|
+
const { empty, $from } = selection;
|
|
1466
|
+
if (!empty) return false;
|
|
1467
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
1468
|
+
if ($from.node(depth).type.name !== "section") continue;
|
|
1469
|
+
if ($from.parentOffset !== 0) return false;
|
|
1470
|
+
let atStart = true;
|
|
1471
|
+
for (let d = depth; d < $from.depth; d++) if ($from.index(d) !== 0) {
|
|
1472
|
+
atStart = false;
|
|
1473
|
+
break;
|
|
1474
|
+
}
|
|
1475
|
+
if (!atStart) return false;
|
|
1476
|
+
if (!isSectionEmpty($from.node(depth))) return false;
|
|
1477
|
+
const tr = state.tr;
|
|
1478
|
+
const from = $from.before(depth);
|
|
1479
|
+
const to = $from.after(depth);
|
|
1480
|
+
if ($from.node(depth - 1).childCount === 1) tr.replaceWith(from, to, state.schema.nodes.paragraph.create());
|
|
1481
|
+
else tr.delete(from, to);
|
|
1482
|
+
editor.view.dispatch(tr);
|
|
1483
|
+
return true;
|
|
1484
|
+
}
|
|
1485
|
+
for (let depth = $from.depth; depth >= 1; depth--) {
|
|
1486
|
+
if ($from.pos !== $from.start(depth)) break;
|
|
1487
|
+
const indexInParent = $from.index(depth - 1);
|
|
1488
|
+
if (indexInParent === 0) continue;
|
|
1489
|
+
const prevNode = $from.node(depth - 1).child(indexInParent - 1);
|
|
1490
|
+
if (prevNode.type.name === "section" && isSectionEmpty(prevNode)) {
|
|
1491
|
+
const deleteFrom = $from.before(depth) - prevNode.nodeSize;
|
|
1492
|
+
const deleteTo = $from.before(depth);
|
|
1493
|
+
editor.view.dispatch(state.tr.delete(deleteFrom, deleteTo));
|
|
1494
|
+
return true;
|
|
1495
|
+
}
|
|
1496
|
+
break;
|
|
1497
|
+
}
|
|
1498
|
+
return false;
|
|
1499
|
+
} };
|
|
1500
|
+
},
|
|
1472
1501
|
addCommands() {
|
|
1473
1502
|
return { insertSection: () => ({ commands }) => {
|
|
1474
1503
|
return commands.insertContent({
|
|
@@ -1481,7 +1510,7 @@ const Section$1 = require_event_bus.EmailNode.create({
|
|
|
1481
1510
|
} };
|
|
1482
1511
|
},
|
|
1483
1512
|
renderToReactEmail({ children, node, style }) {
|
|
1484
|
-
const inlineStyles =
|
|
1513
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
1485
1514
|
const textAlign = node.attrs?.align || node.attrs?.alignment;
|
|
1486
1515
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Section, {
|
|
1487
1516
|
className: node.attrs?.class || void 0,
|
|
@@ -1616,7 +1645,7 @@ const Table = require_event_bus.EmailNode.create({
|
|
|
1616
1645
|
];
|
|
1617
1646
|
},
|
|
1618
1647
|
renderToReactEmail({ children, node, style }) {
|
|
1619
|
-
const inlineStyles =
|
|
1648
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
1620
1649
|
const alignment = node.attrs?.align || node.attrs?.alignment;
|
|
1621
1650
|
const width = node.attrs?.width;
|
|
1622
1651
|
const centeringStyles = alignment === "center" ? {
|
|
@@ -1626,7 +1655,7 @@ const Table = require_event_bus.EmailNode.create({
|
|
|
1626
1655
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Section, {
|
|
1627
1656
|
className: node.attrs?.class || void 0,
|
|
1628
1657
|
align: alignment,
|
|
1629
|
-
style:
|
|
1658
|
+
style: require_global_content.resolveConflictingStyles(style, {
|
|
1630
1659
|
...inlineStyles,
|
|
1631
1660
|
...centeringStyles
|
|
1632
1661
|
}),
|
|
@@ -1668,7 +1697,7 @@ const TableRow = require_event_bus.EmailNode.create({
|
|
|
1668
1697
|
];
|
|
1669
1698
|
},
|
|
1670
1699
|
renderToReactEmail({ children, node, style }) {
|
|
1671
|
-
const inlineStyles =
|
|
1700
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
1672
1701
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
|
|
1673
1702
|
className: node.attrs?.class || void 0,
|
|
1674
1703
|
style: {
|
|
@@ -1713,7 +1742,7 @@ const TableCell = require_event_bus.EmailNode.create({
|
|
|
1713
1742
|
];
|
|
1714
1743
|
},
|
|
1715
1744
|
renderToReactEmail({ children, node, style }) {
|
|
1716
|
-
const inlineStyles =
|
|
1745
|
+
const inlineStyles = require_global_content.inlineCssToJs(node.attrs?.style);
|
|
1717
1746
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_react_email_components.Column, {
|
|
1718
1747
|
className: node.attrs?.class || void 0,
|
|
1719
1748
|
align: node.attrs?.align || node.attrs?.alignment,
|
|
@@ -1935,7 +1964,8 @@ const starterKitExtensions = {
|
|
|
1935
1964
|
AlignmentAttribute,
|
|
1936
1965
|
StyleAttribute,
|
|
1937
1966
|
ClassAttribute,
|
|
1938
|
-
MaxNesting
|
|
1967
|
+
MaxNesting,
|
|
1968
|
+
UndoRedo: _tiptap_extensions.UndoRedo
|
|
1939
1969
|
};
|
|
1940
1970
|
const StarterKit = _tiptap_core.Extension.create({
|
|
1941
1971
|
name: "reactEmailStarterKit",
|
|
@@ -2062,7 +2092,8 @@ const StarterKit = _tiptap_core.Extension.create({
|
|
|
2062
2092
|
"bulletList",
|
|
2063
2093
|
"orderedList"
|
|
2064
2094
|
]
|
|
2065
|
-
}
|
|
2095
|
+
},
|
|
2096
|
+
UndoRedo: {}
|
|
2066
2097
|
};
|
|
2067
2098
|
},
|
|
2068
2099
|
addExtensions() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Node, mergeAttributes } from "@tiptap/core";
|
|
1
2
|
|
|
2
3
|
//#region src/utils/styles.ts
|
|
3
4
|
const WHITE_SPACE_REGEX = /\s+/;
|
|
@@ -8,6 +9,17 @@ const BORDER_WIDTH_TO_STYLE = {
|
|
|
8
9
|
borderBottomWidth: "borderBottomStyle",
|
|
9
10
|
borderLeftWidth: "borderLeftStyle"
|
|
10
11
|
};
|
|
12
|
+
const jsToInlineCss = (styleObject) => {
|
|
13
|
+
const parts = [];
|
|
14
|
+
for (const key in styleObject) {
|
|
15
|
+
const value = styleObject[key];
|
|
16
|
+
if (value !== 0 && value !== void 0 && value !== null && value !== "") {
|
|
17
|
+
const formattedKey = key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
18
|
+
parts.push(`${formattedKey}:${value}`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return parts.join(";") + (parts.length ? ";" : "");
|
|
22
|
+
};
|
|
11
23
|
const inlineCssToJs = (inlineStyle, options = {}) => {
|
|
12
24
|
const styleObject = {};
|
|
13
25
|
if (!inlineStyle || inlineStyle === "" || typeof inlineStyle === "object") return styleObject;
|
|
@@ -191,21 +203,79 @@ function resolveConflictingStyles(resetStyles, inlineStyles) {
|
|
|
191
203
|
}
|
|
192
204
|
|
|
193
205
|
//#endregion
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
206
|
+
//#region src/extensions/global-content.ts
|
|
207
|
+
const GLOBAL_CONTENT_NODE_TYPE = "globalContent";
|
|
208
|
+
let cachedGlobalPosition = null;
|
|
209
|
+
function findGlobalContentPositions(doc) {
|
|
210
|
+
const positions = [];
|
|
211
|
+
doc.descendants((node, position) => {
|
|
212
|
+
if (node.type.name === GLOBAL_CONTENT_NODE_TYPE) positions.push(position);
|
|
213
|
+
});
|
|
214
|
+
return positions;
|
|
215
|
+
}
|
|
216
|
+
function getCachedGlobalContentPosition(doc) {
|
|
217
|
+
if (cachedGlobalPosition != null) try {
|
|
218
|
+
if (doc.nodeAt(cachedGlobalPosition)?.type.name === GLOBAL_CONTENT_NODE_TYPE) return cachedGlobalPosition;
|
|
219
|
+
} catch {
|
|
220
|
+
cachedGlobalPosition = null;
|
|
221
|
+
}
|
|
222
|
+
cachedGlobalPosition = findGlobalContentPositions(doc)[0] ?? null;
|
|
223
|
+
return cachedGlobalPosition;
|
|
224
|
+
}
|
|
225
|
+
function getGlobalContent(key, editor) {
|
|
226
|
+
const position = getCachedGlobalContentPosition(editor.state.doc);
|
|
227
|
+
if (cachedGlobalPosition == null) return null;
|
|
228
|
+
return editor.state.doc.nodeAt(position)?.attrs.data[key] ?? null;
|
|
229
|
+
}
|
|
230
|
+
const GlobalContent = Node.create({
|
|
231
|
+
name: GLOBAL_CONTENT_NODE_TYPE,
|
|
232
|
+
addOptions() {
|
|
233
|
+
return {
|
|
234
|
+
key: GLOBAL_CONTENT_NODE_TYPE,
|
|
235
|
+
data: {}
|
|
236
|
+
};
|
|
237
|
+
},
|
|
238
|
+
group: "block",
|
|
239
|
+
selectable: false,
|
|
240
|
+
draggable: false,
|
|
241
|
+
atom: true,
|
|
242
|
+
addAttributes() {
|
|
243
|
+
return { data: { default: this.options.data } };
|
|
244
|
+
},
|
|
245
|
+
parseHTML() {
|
|
246
|
+
return [{ tag: `div[data-type="${this.name}"]` }];
|
|
247
|
+
},
|
|
248
|
+
renderHTML({ HTMLAttributes }) {
|
|
249
|
+
return ["div", mergeAttributes(HTMLAttributes, {
|
|
250
|
+
"data-type": this.name,
|
|
251
|
+
style: "width: 100%; height: 1px; visibility: hidden; background-color: transparent;"
|
|
252
|
+
})];
|
|
253
|
+
},
|
|
254
|
+
addCommands() {
|
|
255
|
+
return { setGlobalContent: (key, value) => ({ tr, dispatch }) => {
|
|
256
|
+
const ensureGlobalPosition = () => {
|
|
257
|
+
const positions = findGlobalContentPositions(tr.doc);
|
|
258
|
+
for (let i = positions.length - 1; i > 0; i--) tr.delete(positions[i], positions[i] + 1);
|
|
259
|
+
const pos = positions[0] ?? -1;
|
|
260
|
+
if (pos >= 0) cachedGlobalPosition = pos;
|
|
261
|
+
else {
|
|
262
|
+
cachedGlobalPosition = 0;
|
|
263
|
+
tr.insert(0, this.type.create());
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
if (dispatch) {
|
|
267
|
+
ensureGlobalPosition();
|
|
268
|
+
if (cachedGlobalPosition == null) return false;
|
|
269
|
+
tr.setNodeAttribute(cachedGlobalPosition, "data", {
|
|
270
|
+
...tr.doc.nodeAt(cachedGlobalPosition)?.attrs.data,
|
|
271
|
+
[key]: value
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return true;
|
|
275
|
+
} };
|
|
276
|
+
}
|
|
205
277
|
});
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
});
|
|
278
|
+
|
|
279
|
+
//#endregion
|
|
280
|
+
export { inlineCssToJs as a, expandShorthandProperties as i, getGlobalContent as n, jsToInlineCss as o, ensureBorderStyleFallback as r, resolveConflictingStyles as s, GlobalContent as t };
|
|
281
|
+
//# sourceMappingURL=global-content-6jVh6L0b.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"global-content-6jVh6L0b.mjs","names":[],"sources":["../src/utils/styles.ts","../src/extensions/global-content.ts"],"sourcesContent":["import type { CssJs } from '../plugins/email-theming/types';\n\nconst WHITE_SPACE_REGEX = /\\s+/;\n\nconst BORDER_WIDTH_TO_STYLE: Record<string, string> = {\n borderWidth: 'borderStyle',\n borderTopWidth: 'borderTopStyle',\n borderRightWidth: 'borderRightStyle',\n borderBottomWidth: 'borderBottomStyle',\n borderLeftWidth: 'borderLeftStyle',\n};\n\nexport const jsToInlineCss = (styleObject: { [key: string]: any }) => {\n const parts: string[] = [];\n\n for (const key in styleObject) {\n const value = styleObject[key];\n if (value !== 0 && value !== undefined && value !== null && value !== '') {\n const KEBAB_CASE_REGEX = /[A-Z]/g;\n const formattedKey = key.replace(\n KEBAB_CASE_REGEX,\n (match) => `-${match.toLowerCase()}`,\n );\n parts.push(`${formattedKey}:${value}`);\n }\n }\n\n return parts.join(';') + (parts.length ? ';' : '');\n};\n\nexport const inlineCssToJs = (\n inlineStyle: string,\n options: { removeUnit?: boolean } = {},\n) => {\n const styleObject: { [key: string]: string } = {};\n\n if (!inlineStyle || inlineStyle === '' || typeof inlineStyle === 'object') {\n return styleObject;\n }\n\n inlineStyle.split(';').forEach((style: string) => {\n if (style.trim()) {\n const [key, value] = style.split(':');\n const valueTrimmed = value?.trim();\n\n if (!valueTrimmed) {\n return;\n }\n\n const formattedKey = key\n .trim()\n .replace(/-\\w/g, (match) => match[1].toUpperCase());\n\n const UNIT_REGEX = /px|%/g;\n const sanitizedValue = options?.removeUnit\n ? valueTrimmed.replace(UNIT_REGEX, '')\n : valueTrimmed;\n\n styleObject[formattedKey] = sanitizedValue;\n }\n });\n\n return styleObject;\n};\n\n/**\n * Expands CSS shorthand properties (margin, padding) into their longhand equivalents.\n * This prevents shorthand properties from overriding specific longhand properties in email clients.\n *\n * @param styles - Style object that may contain shorthand properties\n * @returns New style object with shorthand properties expanded to longhand\n *\n * @example\n * expandShorthandProperties({ margin: '0', paddingTop: '10px' })\n * // Returns: { marginTop: '0', marginRight: '0', marginBottom: '0', marginLeft: '0', paddingTop: '10px' }\n */\nexport function expandShorthandProperties(\n styles: Record<string, string>,\n): Record<string, string> {\n if (!styles || typeof styles !== 'object') {\n return {};\n }\n\n const expanded: Record<string, any> = {};\n\n for (const key in styles) {\n const value = styles[key];\n if (value === undefined || value === null || value === '') {\n continue;\n }\n\n switch (key) {\n case 'margin': {\n const values = parseShorthandValue(value);\n expanded.marginTop = values.top;\n expanded.marginRight = values.right;\n expanded.marginBottom = values.bottom;\n expanded.marginLeft = values.left;\n break;\n }\n case 'padding': {\n const values = parseShorthandValue(value);\n expanded.paddingTop = values.top;\n expanded.paddingRight = values.right;\n expanded.paddingBottom = values.bottom;\n expanded.paddingLeft = values.left;\n break;\n }\n case 'border': {\n const values = convertBorderValue(value);\n expanded.borderStyle = values.style;\n expanded.borderWidth = values.width;\n expanded.borderColor = values.color;\n break;\n }\n case 'borderTopLeftRadius':\n case 'borderTopRightRadius':\n case 'borderBottomLeftRadius':\n case 'borderBottomRightRadius': {\n // Always preserve the longhand property\n expanded[key] = value;\n\n // When all four corners are present and identical, also add the shorthand\n if (\n styles.borderTopLeftRadius &&\n styles.borderTopRightRadius &&\n styles.borderBottomLeftRadius &&\n styles.borderBottomRightRadius\n ) {\n const values = [\n styles.borderTopLeftRadius,\n styles.borderTopRightRadius,\n styles.borderBottomLeftRadius,\n styles.borderBottomRightRadius,\n ];\n\n if (new Set(values).size === 1) {\n expanded.borderRadius = values[0];\n }\n }\n\n break;\n }\n\n default: {\n // Keep all other properties as-is\n expanded[key] = value;\n }\n }\n }\n\n return expanded;\n}\n\n/**\n * Parses CSS shorthand value (1-4 values) into individual side values.\n * Follows CSS specification for shorthand property value parsing.\n *\n * @param value - Shorthand value string (e.g., '0', '10px 20px', '5px 10px 15px 20px')\n * @returns Object with top, right, bottom, left values\n */\nfunction parseShorthandValue(value: string | number): {\n top: string;\n right: string;\n bottom: string;\n left: string;\n} {\n const stringValue = String(value).trim();\n const parts = stringValue.split(WHITE_SPACE_REGEX);\n const len = parts.length;\n\n if (len === 1) {\n return { top: parts[0], right: parts[0], bottom: parts[0], left: parts[0] };\n }\n if (len === 2) {\n return { top: parts[0], right: parts[1], bottom: parts[0], left: parts[1] };\n }\n if (len === 3) {\n return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[1] };\n }\n if (len === 4) {\n return { top: parts[0], right: parts[1], bottom: parts[2], left: parts[3] };\n }\n\n return {\n top: stringValue,\n right: stringValue,\n bottom: stringValue,\n left: stringValue,\n };\n}\n\nfunction convertBorderValue(value: string | number): {\n style: string;\n width: string;\n color: string;\n} {\n const stringValue = String(value).trim();\n const parts = stringValue.split(WHITE_SPACE_REGEX);\n\n switch (parts.length) {\n case 1:\n // border: 1px → all sides\n return {\n style: 'solid',\n width: parts[0],\n color: 'black',\n };\n case 2:\n // border: 1px solid → top/bottom, left/right\n return {\n style: parts[1],\n width: parts[0],\n color: 'black',\n };\n case 3:\n // border: 1px solid #000 → top, left/right, bottom\n return {\n style: parts[1],\n width: parts[0],\n color: parts[2],\n };\n case 4:\n // border: 1px solid #000 #fff → top, right, bottom, left\n return {\n style: parts[1],\n width: parts[0],\n color: parts[2],\n };\n default:\n // Invalid format, return the original value for all sides\n return {\n style: 'solid',\n width: stringValue,\n color: 'black',\n };\n }\n}\n\n/**\n * When a border-width is present but border-style is missing, browsers default\n * to `none` and the border is invisible. This adds `solid` as a sensible\n * fallback so borders show up immediately after setting a width.\n */\nexport function ensureBorderStyleFallback(\n styles: Record<string, string | number>,\n): Record<string, string | number> {\n for (const [widthKey, styleKey] of Object.entries(BORDER_WIDTH_TO_STYLE)) {\n const widthValue = styles[widthKey];\n if (!widthValue || widthValue === '0' || widthValue === '0px') {\n continue;\n }\n if (!styles[styleKey]) {\n // Keep shorthand borderStyle authoritative for each side when present.\n if (styleKey !== 'borderStyle' && styles.borderStyle) {\n continue;\n }\n styles[styleKey] = 'solid';\n }\n }\n return styles;\n}\n\n/**\n * Resolves conflicts between reset styles and inline styles by expanding\n * shorthand properties (margin, padding) to longhand before merging.\n * This prevents shorthand properties from overriding specific longhand properties.\n *\n * @param resetStyles - Base reset styles that may contain shorthand properties\n * @param inlineStyles - Inline styles that should override reset styles\n * @returns Merged styles with inline styles taking precedence\n */\nexport function resolveConflictingStyles(\n resetStyles: CssJs['reset'],\n inlineStyles: Record<string, string>,\n) {\n const expandedResetStyles = expandShorthandProperties(\n resetStyles as Record<string, string>,\n );\n const expandedInlineStyles = expandShorthandProperties(inlineStyles);\n\n return {\n ...expandedResetStyles,\n ...expandedInlineStyles,\n };\n}\n","import { type Editor, mergeAttributes, Node } from '@tiptap/core';\n\nconst GLOBAL_CONTENT_NODE_TYPE = 'globalContent' as const;\n\nexport interface GlobalContentOptions {\n key: string;\n data: Record<string, unknown>;\n}\n\ndeclare module '@tiptap/core' {\n interface GlobalContent<ReturnType> {\n setGlobalContent: (key: string, value: unknown) => ReturnType;\n }\n\n interface Commands<ReturnType> {\n globalContent: GlobalContent<ReturnType>;\n }\n}\n\nlet cachedGlobalPosition: number | null = null;\n\nfunction findGlobalContentPositions(doc: Editor['state']['doc']) {\n const positions: number[] = [];\n\n doc.descendants((node, position) => {\n if (node.type.name === GLOBAL_CONTENT_NODE_TYPE) {\n positions.push(position);\n }\n });\n\n return positions;\n}\n\nfunction getCachedGlobalContentPosition(doc: Editor['state']['doc']) {\n if (cachedGlobalPosition != null) {\n try {\n if (\n doc.nodeAt(cachedGlobalPosition)?.type.name === GLOBAL_CONTENT_NODE_TYPE\n ) {\n return cachedGlobalPosition;\n }\n } catch {\n cachedGlobalPosition = null;\n }\n }\n\n const positions = findGlobalContentPositions(doc);\n cachedGlobalPosition = positions[0] ?? null;\n return cachedGlobalPosition;\n}\n\nexport function getGlobalContent(key: string, editor: Editor): unknown | null {\n const position = getCachedGlobalContentPosition(editor.state.doc);\n if (cachedGlobalPosition == null) {\n return null;\n }\n return editor.state.doc.nodeAt(position)?.attrs.data[key] ?? null;\n}\n\nexport const GlobalContent = Node.create<GlobalContentOptions>({\n name: GLOBAL_CONTENT_NODE_TYPE,\n\n addOptions() {\n return {\n key: GLOBAL_CONTENT_NODE_TYPE,\n data: {},\n };\n },\n\n group: 'block',\n\n selectable: false,\n draggable: false,\n atom: true,\n\n addAttributes() {\n return {\n data: {\n default: this.options.data,\n },\n };\n },\n\n parseHTML() {\n return [{ tag: `div[data-type=\"${this.name}\"]` }];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\n 'div',\n mergeAttributes(HTMLAttributes, {\n 'data-type': this.name,\n // The node needs to have a width and height, so then\n // internal TipTap extension can find the first node position\n // and calculate the correct position of the document container\n style:\n 'width: 100%; height: 1px; visibility: hidden; background-color: transparent;',\n }),\n ];\n },\n\n addCommands() {\n return {\n setGlobalContent:\n (key: string, value: unknown) =>\n ({ tr, dispatch }) => {\n const ensureGlobalPosition = () => {\n const positions = findGlobalContentPositions(tr.doc);\n\n for (let i = positions.length - 1; i > 0; i--) {\n tr.delete(positions[i], positions[i] + 1);\n }\n\n const pos = positions[0] ?? -1;\n if (pos >= 0) {\n cachedGlobalPosition = pos;\n } else {\n cachedGlobalPosition = 0;\n tr.insert(0, this.type.create());\n }\n };\n\n if (dispatch) {\n ensureGlobalPosition();\n\n if (cachedGlobalPosition == null) {\n return false;\n }\n tr.setNodeAttribute(cachedGlobalPosition, 'data', {\n ...tr.doc.nodeAt(cachedGlobalPosition)?.attrs.data,\n [key]: value,\n });\n }\n\n return true;\n },\n };\n },\n});\n"],"mappings":";;;AAEA,MAAM,oBAAoB;AAE1B,MAAM,wBAAgD;CACpD,aAAa;CACb,gBAAgB;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AC7C,MAAM;KACR,CAAC;;AAGJ,UAAO;KAEZ;;CAEJ,CAAC"}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const require_event_bus = require('./event-bus-D-uahiao.cjs');
|
|
2
|
+
let _tiptap_core = require("@tiptap/core");
|
|
3
|
+
|
|
1
4
|
//#region src/utils/styles.ts
|
|
2
5
|
const WHITE_SPACE_REGEX = /\s+/;
|
|
3
6
|
const BORDER_WIDTH_TO_STYLE = {
|
|
@@ -7,6 +10,17 @@ const BORDER_WIDTH_TO_STYLE = {
|
|
|
7
10
|
borderBottomWidth: "borderBottomStyle",
|
|
8
11
|
borderLeftWidth: "borderLeftStyle"
|
|
9
12
|
};
|
|
13
|
+
const jsToInlineCss = (styleObject) => {
|
|
14
|
+
const parts = [];
|
|
15
|
+
for (const key in styleObject) {
|
|
16
|
+
const value = styleObject[key];
|
|
17
|
+
if (value !== 0 && value !== void 0 && value !== null && value !== "") {
|
|
18
|
+
const formattedKey = key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
19
|
+
parts.push(`${formattedKey}:${value}`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return parts.join(";") + (parts.length ? ";" : "");
|
|
23
|
+
};
|
|
10
24
|
const inlineCssToJs = (inlineStyle, options = {}) => {
|
|
11
25
|
const styleObject = {};
|
|
12
26
|
if (!inlineStyle || inlineStyle === "" || typeof inlineStyle === "object") return styleObject;
|
|
@@ -190,5 +204,119 @@ function resolveConflictingStyles(resetStyles, inlineStyles) {
|
|
|
190
204
|
}
|
|
191
205
|
|
|
192
206
|
//#endregion
|
|
193
|
-
|
|
194
|
-
|
|
207
|
+
//#region src/extensions/global-content.ts
|
|
208
|
+
const GLOBAL_CONTENT_NODE_TYPE = "globalContent";
|
|
209
|
+
let cachedGlobalPosition = null;
|
|
210
|
+
function findGlobalContentPositions(doc) {
|
|
211
|
+
const positions = [];
|
|
212
|
+
doc.descendants((node, position) => {
|
|
213
|
+
if (node.type.name === GLOBAL_CONTENT_NODE_TYPE) positions.push(position);
|
|
214
|
+
});
|
|
215
|
+
return positions;
|
|
216
|
+
}
|
|
217
|
+
function getCachedGlobalContentPosition(doc) {
|
|
218
|
+
if (cachedGlobalPosition != null) try {
|
|
219
|
+
if (doc.nodeAt(cachedGlobalPosition)?.type.name === GLOBAL_CONTENT_NODE_TYPE) return cachedGlobalPosition;
|
|
220
|
+
} catch {
|
|
221
|
+
cachedGlobalPosition = null;
|
|
222
|
+
}
|
|
223
|
+
cachedGlobalPosition = findGlobalContentPositions(doc)[0] ?? null;
|
|
224
|
+
return cachedGlobalPosition;
|
|
225
|
+
}
|
|
226
|
+
function getGlobalContent(key, editor) {
|
|
227
|
+
const position = getCachedGlobalContentPosition(editor.state.doc);
|
|
228
|
+
if (cachedGlobalPosition == null) return null;
|
|
229
|
+
return editor.state.doc.nodeAt(position)?.attrs.data[key] ?? null;
|
|
230
|
+
}
|
|
231
|
+
const GlobalContent = _tiptap_core.Node.create({
|
|
232
|
+
name: GLOBAL_CONTENT_NODE_TYPE,
|
|
233
|
+
addOptions() {
|
|
234
|
+
return {
|
|
235
|
+
key: GLOBAL_CONTENT_NODE_TYPE,
|
|
236
|
+
data: {}
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
group: "block",
|
|
240
|
+
selectable: false,
|
|
241
|
+
draggable: false,
|
|
242
|
+
atom: true,
|
|
243
|
+
addAttributes() {
|
|
244
|
+
return { data: { default: this.options.data } };
|
|
245
|
+
},
|
|
246
|
+
parseHTML() {
|
|
247
|
+
return [{ tag: `div[data-type="${this.name}"]` }];
|
|
248
|
+
},
|
|
249
|
+
renderHTML({ HTMLAttributes }) {
|
|
250
|
+
return ["div", (0, _tiptap_core.mergeAttributes)(HTMLAttributes, {
|
|
251
|
+
"data-type": this.name,
|
|
252
|
+
style: "width: 100%; height: 1px; visibility: hidden; background-color: transparent;"
|
|
253
|
+
})];
|
|
254
|
+
},
|
|
255
|
+
addCommands() {
|
|
256
|
+
return { setGlobalContent: (key, value) => ({ tr, dispatch }) => {
|
|
257
|
+
const ensureGlobalPosition = () => {
|
|
258
|
+
const positions = findGlobalContentPositions(tr.doc);
|
|
259
|
+
for (let i = positions.length - 1; i > 0; i--) tr.delete(positions[i], positions[i] + 1);
|
|
260
|
+
const pos = positions[0] ?? -1;
|
|
261
|
+
if (pos >= 0) cachedGlobalPosition = pos;
|
|
262
|
+
else {
|
|
263
|
+
cachedGlobalPosition = 0;
|
|
264
|
+
tr.insert(0, this.type.create());
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
if (dispatch) {
|
|
268
|
+
ensureGlobalPosition();
|
|
269
|
+
if (cachedGlobalPosition == null) return false;
|
|
270
|
+
tr.setNodeAttribute(cachedGlobalPosition, "data", {
|
|
271
|
+
...tr.doc.nodeAt(cachedGlobalPosition)?.attrs.data,
|
|
272
|
+
[key]: value
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
} };
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
Object.defineProperty(exports, 'GlobalContent', {
|
|
282
|
+
enumerable: true,
|
|
283
|
+
get: function () {
|
|
284
|
+
return GlobalContent;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
Object.defineProperty(exports, 'ensureBorderStyleFallback', {
|
|
288
|
+
enumerable: true,
|
|
289
|
+
get: function () {
|
|
290
|
+
return ensureBorderStyleFallback;
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
Object.defineProperty(exports, 'expandShorthandProperties', {
|
|
294
|
+
enumerable: true,
|
|
295
|
+
get: function () {
|
|
296
|
+
return expandShorthandProperties;
|
|
297
|
+
}
|
|
298
|
+
});
|
|
299
|
+
Object.defineProperty(exports, 'getGlobalContent', {
|
|
300
|
+
enumerable: true,
|
|
301
|
+
get: function () {
|
|
302
|
+
return getGlobalContent;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
Object.defineProperty(exports, 'inlineCssToJs', {
|
|
306
|
+
enumerable: true,
|
|
307
|
+
get: function () {
|
|
308
|
+
return inlineCssToJs;
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
Object.defineProperty(exports, 'jsToInlineCss', {
|
|
312
|
+
enumerable: true,
|
|
313
|
+
get: function () {
|
|
314
|
+
return jsToInlineCss;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
Object.defineProperty(exports, 'resolveConflictingStyles', {
|
|
318
|
+
enumerable: true,
|
|
319
|
+
get: function () {
|
|
320
|
+
return resolveConflictingStyles;
|
|
321
|
+
}
|
|
322
|
+
});
|