@maily-to/core 2.0.0-beta.19 → 2.0.0-beta.20
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-DbMPOkxh.cjs} +89 -0
- package/dist/{use-maily-editor-BUmWtE7-.mjs → use-maily-editor-DrOZ-GOZ.mjs} +84 -1
- package/dist/{use-maily-editor-PPpYUhSF.cjs → use-maily-editor-nTLB-Tv3.cjs} +89 -0
- package/package.json +5 -5
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-DrOZ-GOZ.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,
|
|
@@ -3163,6 +3209,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
3163
3209
|
...WRAPPER_TYPES,
|
|
3164
3210
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
3165
3211
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
3212
|
+
_maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
3166
3213
|
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
3167
3214
|
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
3168
3215
|
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
@@ -3389,6 +3436,38 @@ function setCellParagraphs(document) {
|
|
|
3389
3436
|
}
|
|
3390
3437
|
}
|
|
3391
3438
|
}
|
|
3439
|
+
function removeComments(document) {
|
|
3440
|
+
const walker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_COMMENT);
|
|
3441
|
+
const comments = [];
|
|
3442
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
3443
|
+
for (const comment of comments) comment.remove();
|
|
3444
|
+
}
|
|
3445
|
+
function isBlankText(node) {
|
|
3446
|
+
return node.nodeName === "BR" || node.nodeType === Node.TEXT_NODE && !node.textContent?.replace(/[\s\u00a0]/g, "");
|
|
3447
|
+
}
|
|
3448
|
+
function setTextDivs(document) {
|
|
3449
|
+
const divs = document.querySelectorAll(`div[style]:not([${_maily_to_shared.DATA_NODE_TYPE_KEY}])`);
|
|
3450
|
+
for (const div of Array.from(divs).reverse()) {
|
|
3451
|
+
const children = Array.from(div.childNodes);
|
|
3452
|
+
if (children.length > 0 && children.every(isBlankText)) {
|
|
3453
|
+
div.replaceChildren();
|
|
3454
|
+
continue;
|
|
3455
|
+
}
|
|
3456
|
+
if (!(children.every(isPhrasing) && div.textContent?.trim())) continue;
|
|
3457
|
+
const paragraph = document.createElement("p");
|
|
3458
|
+
paragraph.setAttribute("style", (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)({ margin: "0" }, (0, _maily_to_shared.parseInlineStyles)(div.getAttribute("style") ?? ""))));
|
|
3459
|
+
paragraph.append(...children);
|
|
3460
|
+
div.replaceWith(paragraph);
|
|
3461
|
+
}
|
|
3462
|
+
}
|
|
3463
|
+
function unwrapBodyDiv(document) {
|
|
3464
|
+
const [only, ...rest] = Array.from(document.body.children);
|
|
3465
|
+
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;
|
|
3466
|
+
const style = (0, _maily_to_shared.mergeInlineStyles)((0, _maily_to_shared.parseInlineStyles)(document.body.getAttribute("style") ?? ""), (0, _maily_to_shared.parseInlineStyles)(only.getAttribute("style") ?? ""));
|
|
3467
|
+
const merged = (0, _maily_to_shared.stringifyInlineStyles)(style);
|
|
3468
|
+
if (merged) document.body.setAttribute("style", merged);
|
|
3469
|
+
only.replaceWith(...Array.from(only.childNodes));
|
|
3470
|
+
}
|
|
3392
3471
|
function getSoleImage(anchor) {
|
|
3393
3472
|
const images = anchor.querySelectorAll("img");
|
|
3394
3473
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -3461,8 +3540,11 @@ function getNormalizedHtml(html) {
|
|
|
3461
3540
|
if (!parsed.body) return html;
|
|
3462
3541
|
setRuleStyles(parsed);
|
|
3463
3542
|
removeHidden(parsed);
|
|
3543
|
+
removeComments(parsed);
|
|
3544
|
+
unwrapBodyDiv(parsed);
|
|
3464
3545
|
setLinkedImages(parsed);
|
|
3465
3546
|
setVariables(parsed);
|
|
3547
|
+
setTextDivs(parsed);
|
|
3466
3548
|
setCellParagraphs(parsed);
|
|
3467
3549
|
const style = getBodyStyle(parsed);
|
|
3468
3550
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -3507,6 +3589,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
3507
3589
|
BodyExtension,
|
|
3508
3590
|
ContainerExtension,
|
|
3509
3591
|
SectionExtension,
|
|
3592
|
+
DivExtension,
|
|
3510
3593
|
RepeatExtension,
|
|
3511
3594
|
ColumnsExtension,
|
|
3512
3595
|
ColumnExtension,
|
|
@@ -3699,6 +3782,12 @@ Object.defineProperty(exports, "DEFAULT_SLASH_COMMANDS", {
|
|
|
3699
3782
|
return DEFAULT_SLASH_COMMANDS;
|
|
3700
3783
|
}
|
|
3701
3784
|
});
|
|
3785
|
+
Object.defineProperty(exports, "DivExtension", {
|
|
3786
|
+
enumerable: true,
|
|
3787
|
+
get: function() {
|
|
3788
|
+
return DivExtension;
|
|
3789
|
+
}
|
|
3790
|
+
});
|
|
3702
3791
|
Object.defineProperty(exports, "Document", {
|
|
3703
3792
|
enumerable: true,
|
|
3704
3793
|
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,
|
|
@@ -4068,6 +4114,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
4068
4114
|
...WRAPPER_TYPES,
|
|
4069
4115
|
MAILY_NODE_TYPES.COLUMNS,
|
|
4070
4116
|
MAILY_NODE_TYPES.COLUMN,
|
|
4117
|
+
MAILY_NODE_TYPES.DIV,
|
|
4071
4118
|
MAILY_NODE_TYPES.PARAGRAPH,
|
|
4072
4119
|
MAILY_NODE_TYPES.HEADING,
|
|
4073
4120
|
MAILY_NODE_TYPES.IMAGE,
|
|
@@ -4294,6 +4341,38 @@ function setCellParagraphs(document) {
|
|
|
4294
4341
|
}
|
|
4295
4342
|
}
|
|
4296
4343
|
}
|
|
4344
|
+
function removeComments(document) {
|
|
4345
|
+
const walker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_COMMENT);
|
|
4346
|
+
const comments = [];
|
|
4347
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
4348
|
+
for (const comment of comments) comment.remove();
|
|
4349
|
+
}
|
|
4350
|
+
function isBlankText(node) {
|
|
4351
|
+
return node.nodeName === "BR" || node.nodeType === Node.TEXT_NODE && !node.textContent?.replace(/[\s\u00a0]/g, "");
|
|
4352
|
+
}
|
|
4353
|
+
function setTextDivs(document) {
|
|
4354
|
+
const divs = document.querySelectorAll(`div[style]:not([${DATA_NODE_TYPE_KEY}])`);
|
|
4355
|
+
for (const div of Array.from(divs).reverse()) {
|
|
4356
|
+
const children = Array.from(div.childNodes);
|
|
4357
|
+
if (children.length > 0 && children.every(isBlankText)) {
|
|
4358
|
+
div.replaceChildren();
|
|
4359
|
+
continue;
|
|
4360
|
+
}
|
|
4361
|
+
if (!(children.every(isPhrasing) && div.textContent?.trim())) continue;
|
|
4362
|
+
const paragraph = document.createElement("p");
|
|
4363
|
+
paragraph.setAttribute("style", stringifyInlineStyles(mergeInlineStyles({ margin: "0" }, parseInlineStyles(div.getAttribute("style") ?? ""))));
|
|
4364
|
+
paragraph.append(...children);
|
|
4365
|
+
div.replaceWith(paragraph);
|
|
4366
|
+
}
|
|
4367
|
+
}
|
|
4368
|
+
function unwrapBodyDiv(document) {
|
|
4369
|
+
const [only, ...rest] = Array.from(document.body.children);
|
|
4370
|
+
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;
|
|
4371
|
+
const style = mergeInlineStyles(parseInlineStyles(document.body.getAttribute("style") ?? ""), parseInlineStyles(only.getAttribute("style") ?? ""));
|
|
4372
|
+
const merged = stringifyInlineStyles(style);
|
|
4373
|
+
if (merged) document.body.setAttribute("style", merged);
|
|
4374
|
+
only.replaceWith(...Array.from(only.childNodes));
|
|
4375
|
+
}
|
|
4297
4376
|
function getSoleImage(anchor) {
|
|
4298
4377
|
const images = anchor.querySelectorAll("img");
|
|
4299
4378
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -4366,8 +4445,11 @@ function getNormalizedHtml(html) {
|
|
|
4366
4445
|
if (!parsed.body) return html;
|
|
4367
4446
|
setRuleStyles(parsed);
|
|
4368
4447
|
removeHidden(parsed);
|
|
4448
|
+
removeComments(parsed);
|
|
4449
|
+
unwrapBodyDiv(parsed);
|
|
4369
4450
|
setLinkedImages(parsed);
|
|
4370
4451
|
setVariables(parsed);
|
|
4452
|
+
setTextDivs(parsed);
|
|
4371
4453
|
setCellParagraphs(parsed);
|
|
4372
4454
|
const style = getBodyStyle(parsed);
|
|
4373
4455
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -4412,6 +4494,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
4412
4494
|
BodyExtension,
|
|
4413
4495
|
ContainerExtension,
|
|
4414
4496
|
SectionExtension,
|
|
4497
|
+
DivExtension,
|
|
4415
4498
|
RepeatExtension,
|
|
4416
4499
|
ColumnsExtension,
|
|
4417
4500
|
ColumnExtension,
|
|
@@ -4603,4 +4686,4 @@ function _temp(extension_0) {
|
|
|
4603
4686
|
return extension_0.name === "collaboration";
|
|
4604
4687
|
}
|
|
4605
4688
|
//#endregion
|
|
4606
|
-
export {
|
|
4689
|
+
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,
|
|
@@ -4100,6 +4146,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
4100
4146
|
...WRAPPER_TYPES,
|
|
4101
4147
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
4102
4148
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
4149
|
+
_maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
4103
4150
|
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
4104
4151
|
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
4105
4152
|
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
@@ -4326,6 +4373,38 @@ function setCellParagraphs(document) {
|
|
|
4326
4373
|
}
|
|
4327
4374
|
}
|
|
4328
4375
|
}
|
|
4376
|
+
function removeComments(document) {
|
|
4377
|
+
const walker = document.createTreeWalker(document.documentElement, NodeFilter.SHOW_COMMENT);
|
|
4378
|
+
const comments = [];
|
|
4379
|
+
while (walker.nextNode()) comments.push(walker.currentNode);
|
|
4380
|
+
for (const comment of comments) comment.remove();
|
|
4381
|
+
}
|
|
4382
|
+
function isBlankText(node) {
|
|
4383
|
+
return node.nodeName === "BR" || node.nodeType === Node.TEXT_NODE && !node.textContent?.replace(/[\s\u00a0]/g, "");
|
|
4384
|
+
}
|
|
4385
|
+
function setTextDivs(document) {
|
|
4386
|
+
const divs = document.querySelectorAll(`div[style]:not([${_maily_to_shared.DATA_NODE_TYPE_KEY}])`);
|
|
4387
|
+
for (const div of Array.from(divs).reverse()) {
|
|
4388
|
+
const children = Array.from(div.childNodes);
|
|
4389
|
+
if (children.length > 0 && children.every(isBlankText)) {
|
|
4390
|
+
div.replaceChildren();
|
|
4391
|
+
continue;
|
|
4392
|
+
}
|
|
4393
|
+
if (!(children.every(isPhrasing) && div.textContent?.trim())) continue;
|
|
4394
|
+
const paragraph = document.createElement("p");
|
|
4395
|
+
paragraph.setAttribute("style", (0, _maily_to_shared.stringifyInlineStyles)((0, _maily_to_shared.mergeInlineStyles)({ margin: "0" }, (0, _maily_to_shared.parseInlineStyles)(div.getAttribute("style") ?? ""))));
|
|
4396
|
+
paragraph.append(...children);
|
|
4397
|
+
div.replaceWith(paragraph);
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
function unwrapBodyDiv(document) {
|
|
4401
|
+
const [only, ...rest] = Array.from(document.body.children);
|
|
4402
|
+
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;
|
|
4403
|
+
const style = (0, _maily_to_shared.mergeInlineStyles)((0, _maily_to_shared.parseInlineStyles)(document.body.getAttribute("style") ?? ""), (0, _maily_to_shared.parseInlineStyles)(only.getAttribute("style") ?? ""));
|
|
4404
|
+
const merged = (0, _maily_to_shared.stringifyInlineStyles)(style);
|
|
4405
|
+
if (merged) document.body.setAttribute("style", merged);
|
|
4406
|
+
only.replaceWith(...Array.from(only.childNodes));
|
|
4407
|
+
}
|
|
4329
4408
|
function getSoleImage(anchor) {
|
|
4330
4409
|
const images = anchor.querySelectorAll("img");
|
|
4331
4410
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -4398,8 +4477,11 @@ function getNormalizedHtml(html) {
|
|
|
4398
4477
|
if (!parsed.body) return html;
|
|
4399
4478
|
setRuleStyles(parsed);
|
|
4400
4479
|
removeHidden(parsed);
|
|
4480
|
+
removeComments(parsed);
|
|
4481
|
+
unwrapBodyDiv(parsed);
|
|
4401
4482
|
setLinkedImages(parsed);
|
|
4402
4483
|
setVariables(parsed);
|
|
4484
|
+
setTextDivs(parsed);
|
|
4403
4485
|
setCellParagraphs(parsed);
|
|
4404
4486
|
const style = getBodyStyle(parsed);
|
|
4405
4487
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -4444,6 +4526,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
4444
4526
|
BodyExtension,
|
|
4445
4527
|
ContainerExtension,
|
|
4446
4528
|
SectionExtension,
|
|
4529
|
+
DivExtension,
|
|
4447
4530
|
RepeatExtension,
|
|
4448
4531
|
ColumnsExtension,
|
|
4449
4532
|
ColumnExtension,
|
|
@@ -4707,6 +4790,12 @@ Object.defineProperty(exports, "DEFAULT_SLASH_COMMANDS", {
|
|
|
4707
4790
|
return DEFAULT_SLASH_COMMANDS;
|
|
4708
4791
|
}
|
|
4709
4792
|
});
|
|
4793
|
+
Object.defineProperty(exports, "DivExtension", {
|
|
4794
|
+
enumerable: true,
|
|
4795
|
+
get: function() {
|
|
4796
|
+
return DivExtension;
|
|
4797
|
+
}
|
|
4798
|
+
});
|
|
4710
4799
|
Object.defineProperty(exports, "Document", {
|
|
4711
4800
|
enumerable: true,
|
|
4712
4801
|
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.20",
|
|
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.20"
|
|
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
|
-
"@maily-to/extension-inline-suggestion": "0.0.1",
|
|
112
110
|
"@maily-to/extension-variable": "0.0.1",
|
|
113
|
-
"@maily-to/
|
|
111
|
+
"@maily-to/extension-inline-suggestion": "0.0.1",
|
|
112
|
+
"@maily-to/render": "2.0.0-beta.20",
|
|
113
|
+
"@maily-to/extension-ai-actions": "0.0.1",
|
|
114
114
|
"@maily-to/tsconfig": "0.0.0"
|
|
115
115
|
},
|
|
116
116
|
"peerDependencies": {
|