@maily-to/core 2.0.0-beta.19 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/blocks/index.cjs +1 -1
- package/dist/extensions/index.cjs +16 -46
- package/dist/extensions/index.d.mts +4 -1
- package/dist/extensions/index.d.mts.map +1 -1
- package/dist/extensions/index.mjs +2 -2
- package/dist/index.cjs +2943 -8136
- package/dist/index.mjs +1 -1
- package/dist/{use-maily-editor-CXUuyvCp.cjs → use-maily-editor-BknxsMea.cjs} +92 -1
- package/dist/{use-maily-editor-BUmWtE7-.mjs → use-maily-editor-BrlfN_JG.mjs} +87 -2
- package/dist/{use-maily-editor-PPpYUhSF.cjs → use-maily-editor-N14dfe6r.cjs} +92 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as MAX_SPACER_HEIGHT, G as getVariableSuggestions, H as SPACER_SPACING, I as addColumn, J as Document, L as getColumnWidths, M as VISIBILITY_SUPPORTED_TYPES, Q as getShellNodes, R as removeColumn, U as SPACING_PRESETS, V as MIN_SPACER_HEIGHT, W as VariableExtension, X as getNodeStyleState, Z as getNodeTheme, at as TooltipTrigger, ct as FloatingElement, dt as FLOATING_ELEMENT_ORDER, et as Tooltip, ft as useOnSelectionUpdate, g as VisuallyHidden, gt as useValueAsRef, ht as ArrowIcon, i as mergeExtensions, it as TooltipProvider, j as ProtectVariableTrigger, lt as clearInitialNodeSelection, mt as useEditorInstance, n as useMailyEditor, nt as TooltipPopup, ot as FLOATING_ELEMENT_HEIGHT, pt as useFloatingStore, q as filterVariableSuggestions, r as getNormalizedHtml, rt as TooltipPositioner, st as FLOATING_ELEMENT_PADDING, t as DEFAULT_EXTENSIONS, tt as TooltipArrow, ut as FLOATING_ELEMENT_IDS, z as updateColumnWidth } from "./use-maily-editor-BrlfN_JG.mjs";
|
|
2
2
|
import { c } from "react/compiler-runtime";
|
|
3
3
|
import { ColorPicker as ColorPicker$1 } from "cromia";
|
|
4
4
|
import { Fragment, createContext, forwardRef, use, useCallback, useEffect, useId, useImperativeHandle, useRef, useState } from "react";
|
|
@@ -1820,6 +1820,52 @@ const ContainerExtension = _tiptap_core.Node.create({
|
|
|
1820
1820
|
}
|
|
1821
1821
|
});
|
|
1822
1822
|
//#endregion
|
|
1823
|
+
//#region src/extensions/div/div.ts
|
|
1824
|
+
const DivExtension = _tiptap_core.Node.create({
|
|
1825
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
1826
|
+
group: "block",
|
|
1827
|
+
content: "block+",
|
|
1828
|
+
defining: true,
|
|
1829
|
+
isolating: true,
|
|
1830
|
+
addKeyboardShortcuts() {
|
|
1831
|
+
return {
|
|
1832
|
+
Enter: ({ editor }) => exitOnTripleEnter({
|
|
1833
|
+
editor,
|
|
1834
|
+
nodeName: this.name
|
|
1835
|
+
}),
|
|
1836
|
+
Backspace: ({ editor }) => {
|
|
1837
|
+
const { $from, empty } = editor.state.selection;
|
|
1838
|
+
if (!empty || $from.parentOffset !== 0) return false;
|
|
1839
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
1840
|
+
const node = $from.node(depth);
|
|
1841
|
+
if (node.type.name !== this.name) continue;
|
|
1842
|
+
const only = node.childCount === 1 ? node.firstChild : null;
|
|
1843
|
+
if (!(only?.isTextblock && only.content.size === 0)) return false;
|
|
1844
|
+
return editor.commands.deleteRange({
|
|
1845
|
+
from: $from.before(depth),
|
|
1846
|
+
to: $from.after(depth)
|
|
1847
|
+
});
|
|
1848
|
+
}
|
|
1849
|
+
return false;
|
|
1850
|
+
}
|
|
1851
|
+
};
|
|
1852
|
+
},
|
|
1853
|
+
parseHTML() {
|
|
1854
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.DIV}"]` }, {
|
|
1855
|
+
tag: `div:not([${_maily_to_shared.DATA_NODE_TYPE_KEY}])`,
|
|
1856
|
+
priority: 40,
|
|
1857
|
+
getAttrs: (element) => element.getAttribute("style") ? null : false
|
|
1858
|
+
}];
|
|
1859
|
+
},
|
|
1860
|
+
renderHTML({ HTMLAttributes }) {
|
|
1861
|
+
return [
|
|
1862
|
+
"div",
|
|
1863
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.DIV }, HTMLAttributes),
|
|
1864
|
+
0
|
|
1865
|
+
];
|
|
1866
|
+
}
|
|
1867
|
+
});
|
|
1868
|
+
//#endregion
|
|
1823
1869
|
//#region src/extensions/footer/footer.ts
|
|
1824
1870
|
const FooterExtension = _tiptap_core.Node.create({
|
|
1825
1871
|
name: _maily_to_shared.MAILY_NODE_TYPES.FOOTER,
|
|
@@ -2488,7 +2534,8 @@ const InlineImageExtension = _tiptap_core.Node.create({
|
|
|
2488
2534
|
priority: 60,
|
|
2489
2535
|
getAttrs: (element) => {
|
|
2490
2536
|
const parent = element.parentElement;
|
|
2491
|
-
|
|
2537
|
+
if (!parent) return false;
|
|
2538
|
+
return INLINE_PARENTS.has(parent.tagName) || parent.textContent?.trim() ? null : false;
|
|
2492
2539
|
}
|
|
2493
2540
|
}];
|
|
2494
2541
|
},
|
|
@@ -3163,6 +3210,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
3163
3210
|
...WRAPPER_TYPES,
|
|
3164
3211
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
3165
3212
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
3213
|
+
_maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
3166
3214
|
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
3167
3215
|
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
3168
3216
|
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
@@ -3263,6 +3311,7 @@ const TableExtension = _tiptap_extension_table.Table.extend({ addAttributes() {
|
|
|
3263
3311
|
};
|
|
3264
3312
|
} }).configure({
|
|
3265
3313
|
HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.TABLE },
|
|
3314
|
+
cellMinWidth: 0,
|
|
3266
3315
|
resizable: false,
|
|
3267
3316
|
View: null
|
|
3268
3317
|
});
|
|
@@ -3389,6 +3438,38 @@ function setCellParagraphs(document) {
|
|
|
3389
3438
|
}
|
|
3390
3439
|
}
|
|
3391
3440
|
}
|
|
3441
|
+
function removeComments(document) {
|
|
3442
|
+
const walker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_COMMENT);
|
|
3443
|
+
const comments = [];
|
|
3444
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
3445
|
+
for (const comment of comments) comment.remove();
|
|
3446
|
+
}
|
|
3447
|
+
function isBlankText(node) {
|
|
3448
|
+
return node.nodeName === "BR" || node.nodeType === Node.TEXT_NODE && !node.textContent?.replace(/[\s\u00a0]/g, "");
|
|
3449
|
+
}
|
|
3450
|
+
function setTextDivs(document) {
|
|
3451
|
+
const divs = document.querySelectorAll(`div[style]:not([${_maily_to_shared.DATA_NODE_TYPE_KEY}])`);
|
|
3452
|
+
for (const div of Array.from(divs).reverse()) {
|
|
3453
|
+
const children = Array.from(div.childNodes);
|
|
3454
|
+
if (children.length > 0 && children.every(isBlankText)) {
|
|
3455
|
+
div.replaceChildren();
|
|
3456
|
+
continue;
|
|
3457
|
+
}
|
|
3458
|
+
if (!(children.every(isPhrasing) && div.textContent?.trim())) continue;
|
|
3459
|
+
const paragraph = document.createElement("p");
|
|
3460
|
+
paragraph.setAttribute("style", (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)({ margin: "0" }, (0, _maily_to_shared.parseInlineStyles)(div.getAttribute("style") ?? ""))));
|
|
3461
|
+
paragraph.append(...children);
|
|
3462
|
+
div.replaceWith(paragraph);
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3465
|
+
function unwrapBodyDiv(document) {
|
|
3466
|
+
const [only, ...rest] = Array.from(document.body.children);
|
|
3467
|
+
if (rest.length > 0 || !(only instanceof HTMLElement) || only.tagName !== "DIV" || only.hasAttribute(_maily_to_shared.DATA_NODE_TYPE_KEY) || only.style.maxWidth || only.style.width || Array.from(only.childNodes).every(isPhrasing)) return;
|
|
3468
|
+
const style = (0, _maily_to_shared.mergeInlineStyles)((0, _maily_to_shared.parseInlineStyles)(document.body.getAttribute("style") ?? ""), (0, _maily_to_shared.parseInlineStyles)(only.getAttribute("style") ?? ""));
|
|
3469
|
+
const merged = (0, _maily_to_shared.stringifyInlineStyles)(style);
|
|
3470
|
+
if (merged) document.body.setAttribute("style", merged);
|
|
3471
|
+
only.replaceWith(...Array.from(only.childNodes));
|
|
3472
|
+
}
|
|
3392
3473
|
function getSoleImage(anchor) {
|
|
3393
3474
|
const images = anchor.querySelectorAll("img");
|
|
3394
3475
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -3461,8 +3542,11 @@ function getNormalizedHtml(html) {
|
|
|
3461
3542
|
if (!parsed.body) return html;
|
|
3462
3543
|
setRuleStyles(parsed);
|
|
3463
3544
|
removeHidden(parsed);
|
|
3545
|
+
removeComments(parsed);
|
|
3546
|
+
unwrapBodyDiv(parsed);
|
|
3464
3547
|
setLinkedImages(parsed);
|
|
3465
3548
|
setVariables(parsed);
|
|
3549
|
+
setTextDivs(parsed);
|
|
3466
3550
|
setCellParagraphs(parsed);
|
|
3467
3551
|
const style = getBodyStyle(parsed);
|
|
3468
3552
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -3507,6 +3591,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
3507
3591
|
BodyExtension,
|
|
3508
3592
|
ContainerExtension,
|
|
3509
3593
|
SectionExtension,
|
|
3594
|
+
DivExtension,
|
|
3510
3595
|
RepeatExtension,
|
|
3511
3596
|
ColumnsExtension,
|
|
3512
3597
|
ColumnExtension,
|
|
@@ -3699,6 +3784,12 @@ Object.defineProperty(exports, "DEFAULT_SLASH_COMMANDS", {
|
|
|
3699
3784
|
return DEFAULT_SLASH_COMMANDS;
|
|
3700
3785
|
}
|
|
3701
3786
|
});
|
|
3787
|
+
Object.defineProperty(exports, "DivExtension", {
|
|
3788
|
+
enumerable: true,
|
|
3789
|
+
get: function() {
|
|
3790
|
+
return DivExtension;
|
|
3791
|
+
}
|
|
3792
|
+
});
|
|
3702
3793
|
Object.defineProperty(exports, "Document", {
|
|
3703
3794
|
enumerable: true,
|
|
3704
3795
|
get: function() {
|
|
@@ -2143,6 +2143,52 @@ const ContainerExtension = Node$1.create({
|
|
|
2143
2143
|
}
|
|
2144
2144
|
});
|
|
2145
2145
|
//#endregion
|
|
2146
|
+
//#region src/extensions/div/div.ts
|
|
2147
|
+
const DivExtension = Node$1.create({
|
|
2148
|
+
name: MAILY_NODE_TYPES.DIV,
|
|
2149
|
+
group: "block",
|
|
2150
|
+
content: "block+",
|
|
2151
|
+
defining: true,
|
|
2152
|
+
isolating: true,
|
|
2153
|
+
addKeyboardShortcuts() {
|
|
2154
|
+
return {
|
|
2155
|
+
Enter: ({ editor }) => exitOnTripleEnter({
|
|
2156
|
+
editor,
|
|
2157
|
+
nodeName: this.name
|
|
2158
|
+
}),
|
|
2159
|
+
Backspace: ({ editor }) => {
|
|
2160
|
+
const { $from, empty } = editor.state.selection;
|
|
2161
|
+
if (!empty || $from.parentOffset !== 0) return false;
|
|
2162
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
2163
|
+
const node = $from.node(depth);
|
|
2164
|
+
if (node.type.name !== this.name) continue;
|
|
2165
|
+
const only = node.childCount === 1 ? node.firstChild : null;
|
|
2166
|
+
if (!(only?.isTextblock && only.content.size === 0)) return false;
|
|
2167
|
+
return editor.commands.deleteRange({
|
|
2168
|
+
from: $from.before(depth),
|
|
2169
|
+
to: $from.after(depth)
|
|
2170
|
+
});
|
|
2171
|
+
}
|
|
2172
|
+
return false;
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
},
|
|
2176
|
+
parseHTML() {
|
|
2177
|
+
return [{ tag: `div[${DATA_NODE_TYPE_KEY}="${MAILY_NODE_TYPES.DIV}"]` }, {
|
|
2178
|
+
tag: `div:not([${DATA_NODE_TYPE_KEY}])`,
|
|
2179
|
+
priority: 40,
|
|
2180
|
+
getAttrs: (element) => element.getAttribute("style") ? null : false
|
|
2181
|
+
}];
|
|
2182
|
+
},
|
|
2183
|
+
renderHTML({ HTMLAttributes }) {
|
|
2184
|
+
return [
|
|
2185
|
+
"div",
|
|
2186
|
+
mergeAttributes({ [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.DIV }, HTMLAttributes),
|
|
2187
|
+
0
|
|
2188
|
+
];
|
|
2189
|
+
}
|
|
2190
|
+
});
|
|
2191
|
+
//#endregion
|
|
2146
2192
|
//#region src/extensions/footer/footer.ts
|
|
2147
2193
|
const FooterExtension = Node$1.create({
|
|
2148
2194
|
name: MAILY_NODE_TYPES.FOOTER,
|
|
@@ -3174,7 +3220,8 @@ const InlineImageExtension = Node$1.create({
|
|
|
3174
3220
|
priority: 60,
|
|
3175
3221
|
getAttrs: (element) => {
|
|
3176
3222
|
const parent = element.parentElement;
|
|
3177
|
-
|
|
3223
|
+
if (!parent) return false;
|
|
3224
|
+
return INLINE_PARENTS.has(parent.tagName) || parent.textContent?.trim() ? null : false;
|
|
3178
3225
|
}
|
|
3179
3226
|
}];
|
|
3180
3227
|
},
|
|
@@ -4068,6 +4115,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
4068
4115
|
...WRAPPER_TYPES,
|
|
4069
4116
|
MAILY_NODE_TYPES.COLUMNS,
|
|
4070
4117
|
MAILY_NODE_TYPES.COLUMN,
|
|
4118
|
+
MAILY_NODE_TYPES.DIV,
|
|
4071
4119
|
MAILY_NODE_TYPES.PARAGRAPH,
|
|
4072
4120
|
MAILY_NODE_TYPES.HEADING,
|
|
4073
4121
|
MAILY_NODE_TYPES.IMAGE,
|
|
@@ -4168,6 +4216,7 @@ const TableExtension = Table.extend({ addAttributes() {
|
|
|
4168
4216
|
};
|
|
4169
4217
|
} }).configure({
|
|
4170
4218
|
HTMLAttributes: { [DATA_NODE_TYPE_KEY]: MAILY_NODE_TYPES.TABLE },
|
|
4219
|
+
cellMinWidth: 0,
|
|
4171
4220
|
resizable: false,
|
|
4172
4221
|
View: null
|
|
4173
4222
|
});
|
|
@@ -4294,6 +4343,38 @@ function setCellParagraphs(document) {
|
|
|
4294
4343
|
}
|
|
4295
4344
|
}
|
|
4296
4345
|
}
|
|
4346
|
+
function removeComments(document) {
|
|
4347
|
+
const walker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_COMMENT);
|
|
4348
|
+
const comments = [];
|
|
4349
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
4350
|
+
for (const comment of comments) comment.remove();
|
|
4351
|
+
}
|
|
4352
|
+
function isBlankText(node) {
|
|
4353
|
+
return node.nodeName === "BR" || node.nodeType === Node.TEXT_NODE && !node.textContent?.replace(/[\s\u00a0]/g, "");
|
|
4354
|
+
}
|
|
4355
|
+
function setTextDivs(document) {
|
|
4356
|
+
const divs = document.querySelectorAll(`div[style]:not([${DATA_NODE_TYPE_KEY}])`);
|
|
4357
|
+
for (const div of Array.from(divs).reverse()) {
|
|
4358
|
+
const children = Array.from(div.childNodes);
|
|
4359
|
+
if (children.length > 0 && children.every(isBlankText)) {
|
|
4360
|
+
div.replaceChildren();
|
|
4361
|
+
continue;
|
|
4362
|
+
}
|
|
4363
|
+
if (!(children.every(isPhrasing) && div.textContent?.trim())) continue;
|
|
4364
|
+
const paragraph = document.createElement("p");
|
|
4365
|
+
paragraph.setAttribute("style", stringifyInlineStyles(mergeInlineStyles({ margin: "0" }, parseInlineStyles(div.getAttribute("style") ?? ""))));
|
|
4366
|
+
paragraph.append(...children);
|
|
4367
|
+
div.replaceWith(paragraph);
|
|
4368
|
+
}
|
|
4369
|
+
}
|
|
4370
|
+
function unwrapBodyDiv(document) {
|
|
4371
|
+
const [only, ...rest] = Array.from(document.body.children);
|
|
4372
|
+
if (rest.length > 0 || !(only instanceof HTMLElement) || only.tagName !== "DIV" || only.hasAttribute(DATA_NODE_TYPE_KEY) || only.style.maxWidth || only.style.width || Array.from(only.childNodes).every(isPhrasing)) return;
|
|
4373
|
+
const style = mergeInlineStyles(parseInlineStyles(document.body.getAttribute("style") ?? ""), parseInlineStyles(only.getAttribute("style") ?? ""));
|
|
4374
|
+
const merged = stringifyInlineStyles(style);
|
|
4375
|
+
if (merged) document.body.setAttribute("style", merged);
|
|
4376
|
+
only.replaceWith(...Array.from(only.childNodes));
|
|
4377
|
+
}
|
|
4297
4378
|
function getSoleImage(anchor) {
|
|
4298
4379
|
const images = anchor.querySelectorAll("img");
|
|
4299
4380
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -4366,8 +4447,11 @@ function getNormalizedHtml(html) {
|
|
|
4366
4447
|
if (!parsed.body) return html;
|
|
4367
4448
|
setRuleStyles(parsed);
|
|
4368
4449
|
removeHidden(parsed);
|
|
4450
|
+
removeComments(parsed);
|
|
4451
|
+
unwrapBodyDiv(parsed);
|
|
4369
4452
|
setLinkedImages(parsed);
|
|
4370
4453
|
setVariables(parsed);
|
|
4454
|
+
setTextDivs(parsed);
|
|
4371
4455
|
setCellParagraphs(parsed);
|
|
4372
4456
|
const style = getBodyStyle(parsed);
|
|
4373
4457
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -4412,6 +4496,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
4412
4496
|
BodyExtension,
|
|
4413
4497
|
ContainerExtension,
|
|
4414
4498
|
SectionExtension,
|
|
4499
|
+
DivExtension,
|
|
4415
4500
|
RepeatExtension,
|
|
4416
4501
|
ColumnsExtension,
|
|
4417
4502
|
ColumnExtension,
|
|
@@ -4603,4 +4688,4 @@ function _temp(extension_0) {
|
|
|
4603
4688
|
return extension_0.name === "collaboration";
|
|
4604
4689
|
}
|
|
4605
4690
|
//#endregion
|
|
4606
|
-
export {
|
|
4691
|
+
export { getThemeCss as $, DEFAULT_REPEAT_EACH as A, MAX_SPACER_HEIGHT as B, DivExtension as C, setStyleDeclarations as D, BoldExtension as E, ColumnExtension as F, getVariableSuggestions as G, SPACER_SPACING as H, addColumn as I, Document$1 as J, VARIABLE_SUGGESTION_POPOVER_ID as K, getColumnWidths as L, VISIBILITY_SUPPORTED_TYPES as M, VisibilityExtension as N, BodyExtension as O, ColumnsExtension as P, getShellNodes as Q, removeColumn as R, FooterExtension as S, ButtonExtension as T, SPACING_PRESETS as U, MIN_SPACER_HEIGHT as V, VariableExtension as W, getNodeStyleState as X, getMergedNodeTheme as Y, getNodeTheme as Z, ALLOWED_IMAGE_MIME_TYPES as _, STYLE_SUPPORTED_TYPES as a, TooltipTrigger as at, HtmlCodeBlockExtension as b, SpacerExtension as c, FloatingElement as ct, SectionExtension as d, FLOATING_ELEMENT_ORDER as dt, Tooltip$1 as et, InlineSpanExtension as f, useOnSelectionUpdate as ft, VisuallyHidden as g, useValueAsRef as gt, ImageState as h, ArrowIcon as ht, mergeExtensions as i, TooltipProvider as it, ProtectVariableTrigger as j, BlockquoteExtension as k, SlashCommandExtension as l, clearInitialNodeSelection as lt, ImageExtension as m, useEditorInstance as mt, useMailyEditor as n, TooltipPopup as nt, StyleExtension as o, FLOATING_ELEMENT_HEIGHT as ot, InlineImageExtension as p, useFloatingStore as pt, filterVariableSuggestions as q, getNormalizedHtml as r, TooltipPositioner as rt, SpanExtension as s, FLOATING_ELEMENT_PADDING as st, DEFAULT_EXTENSIONS as t, TooltipArrow as tt, DEFAULT_SLASH_COMMANDS as u, FLOATING_ELEMENT_IDS as ut, IMAGE_UPLOAD_STATUSES as v, ContainerExtension as w, HorizontalRuleExtension as x, ImageUploadExtension as y, updateColumnWidth as z };
|
|
@@ -2175,6 +2175,52 @@ const ContainerExtension = _tiptap_core.Node.create({
|
|
|
2175
2175
|
}
|
|
2176
2176
|
});
|
|
2177
2177
|
//#endregion
|
|
2178
|
+
//#region src/extensions/div/div.ts
|
|
2179
|
+
const DivExtension = _tiptap_core.Node.create({
|
|
2180
|
+
name: _maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
2181
|
+
group: "block",
|
|
2182
|
+
content: "block+",
|
|
2183
|
+
defining: true,
|
|
2184
|
+
isolating: true,
|
|
2185
|
+
addKeyboardShortcuts() {
|
|
2186
|
+
return {
|
|
2187
|
+
Enter: ({ editor }) => exitOnTripleEnter({
|
|
2188
|
+
editor,
|
|
2189
|
+
nodeName: this.name
|
|
2190
|
+
}),
|
|
2191
|
+
Backspace: ({ editor }) => {
|
|
2192
|
+
const { $from, empty } = editor.state.selection;
|
|
2193
|
+
if (!empty || $from.parentOffset !== 0) return false;
|
|
2194
|
+
for (let depth = $from.depth; depth > 0; depth -= 1) {
|
|
2195
|
+
const node = $from.node(depth);
|
|
2196
|
+
if (node.type.name !== this.name) continue;
|
|
2197
|
+
const only = node.childCount === 1 ? node.firstChild : null;
|
|
2198
|
+
if (!(only?.isTextblock && only.content.size === 0)) return false;
|
|
2199
|
+
return editor.commands.deleteRange({
|
|
2200
|
+
from: $from.before(depth),
|
|
2201
|
+
to: $from.after(depth)
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
return false;
|
|
2205
|
+
}
|
|
2206
|
+
};
|
|
2207
|
+
},
|
|
2208
|
+
parseHTML() {
|
|
2209
|
+
return [{ tag: `div[${_maily_to_shared.DATA_NODE_TYPE_KEY}="${_maily_to_shared.MAILY_NODE_TYPES.DIV}"]` }, {
|
|
2210
|
+
tag: `div:not([${_maily_to_shared.DATA_NODE_TYPE_KEY}])`,
|
|
2211
|
+
priority: 40,
|
|
2212
|
+
getAttrs: (element) => element.getAttribute("style") ? null : false
|
|
2213
|
+
}];
|
|
2214
|
+
},
|
|
2215
|
+
renderHTML({ HTMLAttributes }) {
|
|
2216
|
+
return [
|
|
2217
|
+
"div",
|
|
2218
|
+
(0, _tiptap_core.mergeAttributes)({ [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.DIV }, HTMLAttributes),
|
|
2219
|
+
0
|
|
2220
|
+
];
|
|
2221
|
+
}
|
|
2222
|
+
});
|
|
2223
|
+
//#endregion
|
|
2178
2224
|
//#region src/extensions/footer/footer.ts
|
|
2179
2225
|
const FooterExtension = _tiptap_core.Node.create({
|
|
2180
2226
|
name: _maily_to_shared.MAILY_NODE_TYPES.FOOTER,
|
|
@@ -3206,7 +3252,8 @@ const InlineImageExtension = _tiptap_core.Node.create({
|
|
|
3206
3252
|
priority: 60,
|
|
3207
3253
|
getAttrs: (element) => {
|
|
3208
3254
|
const parent = element.parentElement;
|
|
3209
|
-
|
|
3255
|
+
if (!parent) return false;
|
|
3256
|
+
return INLINE_PARENTS.has(parent.tagName) || parent.textContent?.trim() ? null : false;
|
|
3210
3257
|
}
|
|
3211
3258
|
}];
|
|
3212
3259
|
},
|
|
@@ -4100,6 +4147,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
4100
4147
|
...WRAPPER_TYPES,
|
|
4101
4148
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
4102
4149
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
4150
|
+
_maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
4103
4151
|
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
4104
4152
|
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
4105
4153
|
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
@@ -4200,6 +4248,7 @@ const TableExtension = _tiptap_extension_table.Table.extend({ addAttributes() {
|
|
|
4200
4248
|
};
|
|
4201
4249
|
} }).configure({
|
|
4202
4250
|
HTMLAttributes: { [_maily_to_shared.DATA_NODE_TYPE_KEY]: _maily_to_shared.MAILY_NODE_TYPES.TABLE },
|
|
4251
|
+
cellMinWidth: 0,
|
|
4203
4252
|
resizable: false,
|
|
4204
4253
|
View: null
|
|
4205
4254
|
});
|
|
@@ -4326,6 +4375,38 @@ function setCellParagraphs(document) {
|
|
|
4326
4375
|
}
|
|
4327
4376
|
}
|
|
4328
4377
|
}
|
|
4378
|
+
function removeComments(document) {
|
|
4379
|
+
const walker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_COMMENT);
|
|
4380
|
+
const comments = [];
|
|
4381
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
4382
|
+
for (const comment of comments) comment.remove();
|
|
4383
|
+
}
|
|
4384
|
+
function isBlankText(node) {
|
|
4385
|
+
return node.nodeName === "BR" || node.nodeType === Node.TEXT_NODE && !node.textContent?.replace(/[\s\u00a0]/g, "");
|
|
4386
|
+
}
|
|
4387
|
+
function setTextDivs(document) {
|
|
4388
|
+
const divs = document.querySelectorAll(`div[style]:not([${_maily_to_shared.DATA_NODE_TYPE_KEY}])`);
|
|
4389
|
+
for (const div of Array.from(divs).reverse()) {
|
|
4390
|
+
const children = Array.from(div.childNodes);
|
|
4391
|
+
if (children.length > 0 && children.every(isBlankText)) {
|
|
4392
|
+
div.replaceChildren();
|
|
4393
|
+
continue;
|
|
4394
|
+
}
|
|
4395
|
+
if (!(children.every(isPhrasing) && div.textContent?.trim())) continue;
|
|
4396
|
+
const paragraph = document.createElement("p");
|
|
4397
|
+
paragraph.setAttribute("style", (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)({ margin: "0" }, (0, _maily_to_shared.parseInlineStyles)(div.getAttribute("style") ?? ""))));
|
|
4398
|
+
paragraph.append(...children);
|
|
4399
|
+
div.replaceWith(paragraph);
|
|
4400
|
+
}
|
|
4401
|
+
}
|
|
4402
|
+
function unwrapBodyDiv(document) {
|
|
4403
|
+
const [only, ...rest] = Array.from(document.body.children);
|
|
4404
|
+
if (rest.length > 0 || !(only instanceof HTMLElement) || only.tagName !== "DIV" || only.hasAttribute(_maily_to_shared.DATA_NODE_TYPE_KEY) || only.style.maxWidth || only.style.width || Array.from(only.childNodes).every(isPhrasing)) return;
|
|
4405
|
+
const style = (0, _maily_to_shared.mergeInlineStyles)((0, _maily_to_shared.parseInlineStyles)(document.body.getAttribute("style") ?? ""), (0, _maily_to_shared.parseInlineStyles)(only.getAttribute("style") ?? ""));
|
|
4406
|
+
const merged = (0, _maily_to_shared.stringifyInlineStyles)(style);
|
|
4407
|
+
if (merged) document.body.setAttribute("style", merged);
|
|
4408
|
+
only.replaceWith(...Array.from(only.childNodes));
|
|
4409
|
+
}
|
|
4329
4410
|
function getSoleImage(anchor) {
|
|
4330
4411
|
const images = anchor.querySelectorAll("img");
|
|
4331
4412
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -4398,8 +4479,11 @@ function getNormalizedHtml(html) {
|
|
|
4398
4479
|
if (!parsed.body) return html;
|
|
4399
4480
|
setRuleStyles(parsed);
|
|
4400
4481
|
removeHidden(parsed);
|
|
4482
|
+
removeComments(parsed);
|
|
4483
|
+
unwrapBodyDiv(parsed);
|
|
4401
4484
|
setLinkedImages(parsed);
|
|
4402
4485
|
setVariables(parsed);
|
|
4486
|
+
setTextDivs(parsed);
|
|
4403
4487
|
setCellParagraphs(parsed);
|
|
4404
4488
|
const style = getBodyStyle(parsed);
|
|
4405
4489
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -4444,6 +4528,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
4444
4528
|
BodyExtension,
|
|
4445
4529
|
ContainerExtension,
|
|
4446
4530
|
SectionExtension,
|
|
4531
|
+
DivExtension,
|
|
4447
4532
|
RepeatExtension,
|
|
4448
4533
|
ColumnsExtension,
|
|
4449
4534
|
ColumnExtension,
|
|
@@ -4707,6 +4792,12 @@ Object.defineProperty(exports, "DEFAULT_SLASH_COMMANDS", {
|
|
|
4707
4792
|
return DEFAULT_SLASH_COMMANDS;
|
|
4708
4793
|
}
|
|
4709
4794
|
});
|
|
4795
|
+
Object.defineProperty(exports, "DivExtension", {
|
|
4796
|
+
enumerable: true,
|
|
4797
|
+
get: function() {
|
|
4798
|
+
return DivExtension;
|
|
4799
|
+
}
|
|
4800
|
+
});
|
|
4710
4801
|
Object.defineProperty(exports, "Document", {
|
|
4711
4802
|
enumerable: true,
|
|
4712
4803
|
get: function() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@maily-to/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Powerful editor for creating beautiful, pre-designed, mobile-ready emails.",
|
|
6
6
|
"keywords": [
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"lucide-react": "^1.28.0",
|
|
88
88
|
"unit-field": "^0.0.3",
|
|
89
89
|
"zustand": "^5.0.14",
|
|
90
|
-
"@maily-to/shared": "2.0.0-beta.
|
|
90
|
+
"@maily-to/shared": "2.0.0-beta.21"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@react-email/components": "^1.0.12",
|
|
@@ -107,10 +107,10 @@
|
|
|
107
107
|
"typescript": "^7.0.2",
|
|
108
108
|
"vite-plus": "0.3.0",
|
|
109
109
|
"yjs": "^13.6.33",
|
|
110
|
-
"@maily-to/extension-ai-actions": "0.0.1",
|
|
111
110
|
"@maily-to/extension-inline-suggestion": "0.0.1",
|
|
111
|
+
"@maily-to/extension-ai-actions": "0.0.1",
|
|
112
112
|
"@maily-to/extension-variable": "0.0.1",
|
|
113
|
-
"@maily-to/render": "2.0.0-beta.
|
|
113
|
+
"@maily-to/render": "2.0.0-beta.21",
|
|
114
114
|
"@maily-to/tsconfig": "0.0.0"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|