@maily-to/core 2.0.0-beta.18 → 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 +6 -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-B8nvKyXX.cjs → use-maily-editor-DbMPOkxh.cjs} +150 -16
- package/dist/{use-maily-editor-mwGHSFi6.mjs → use-maily-editor-DrOZ-GOZ.mjs} +245 -91
- package/dist/{use-maily-editor-uwcKnkj2.cjs → use-maily-editor-nTLB-Tv3.cjs} +250 -90
- package/package.json +5 -5
- package/src/styles/index.css +63 -1
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,
|
|
@@ -1851,6 +1897,8 @@ const HorizontalRuleExtension = _tiptap_extension_horizontal_rule.HorizontalRule
|
|
|
1851
1897
|
//#endregion
|
|
1852
1898
|
//#region src/extensions/html-code-block/html-code-block-view.tsx
|
|
1853
1899
|
const PREVIEW_RESET = `
|
|
1900
|
+
html { overflow: hidden; }
|
|
1901
|
+
body { margin: 0; }
|
|
1854
1902
|
* { font-family: 'Inter', sans-serif; }
|
|
1855
1903
|
blockquote, h1, h2, h3, img, li, ol, p, ul {
|
|
1856
1904
|
margin-top: 0;
|
|
@@ -1875,15 +1923,14 @@ function HtmlCodeBlockView(props) {
|
|
|
1875
1923
|
}).join("\n")}</style>${parsed.body.innerHTML}`;
|
|
1876
1924
|
}, [node]);
|
|
1877
1925
|
const isEmpty = html === "<style></style>";
|
|
1878
|
-
const
|
|
1879
|
-
|
|
1880
|
-
const
|
|
1881
|
-
const
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
shadow.append(container);
|
|
1926
|
+
const [height, setHeight] = (0, react.useState)(0);
|
|
1927
|
+
const onPreviewLoad = (event) => {
|
|
1928
|
+
const frameWindow = event.currentTarget.contentWindow;
|
|
1929
|
+
const root = frameWindow?.document.documentElement;
|
|
1930
|
+
if (!frameWindow || !root) return;
|
|
1931
|
+
new frameWindow.ResizeObserver(() => {
|
|
1932
|
+
setHeight(root.offsetHeight);
|
|
1933
|
+
}).observe(root);
|
|
1887
1934
|
};
|
|
1888
1935
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_tiptap_react.NodeViewWrapper, {
|
|
1889
1936
|
"data-drag-handle": false,
|
|
@@ -1901,7 +1948,19 @@ function HtmlCodeBlockView(props) {
|
|
|
1901
1948
|
onClick: () => {
|
|
1902
1949
|
if (isEmpty) updateAttributes({ activeTab: _maily_to_shared.HTML_CODE_BLOCK_TABS.CODE });
|
|
1903
1950
|
},
|
|
1904
|
-
|
|
1951
|
+
children: !isEmpty && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("iframe", {
|
|
1952
|
+
onLoad: onPreviewLoad,
|
|
1953
|
+
sandbox: "allow-same-origin",
|
|
1954
|
+
srcDoc: `<!DOCTYPE html><style>${PREVIEW_RESET}</style>${html}`,
|
|
1955
|
+
style: {
|
|
1956
|
+
border: 0,
|
|
1957
|
+
display: "block",
|
|
1958
|
+
height,
|
|
1959
|
+
pointerEvents: "none",
|
|
1960
|
+
width: "100%"
|
|
1961
|
+
},
|
|
1962
|
+
title: "HTML preview"
|
|
1963
|
+
})
|
|
1905
1964
|
})]
|
|
1906
1965
|
});
|
|
1907
1966
|
}
|
|
@@ -2021,20 +2080,28 @@ function uploadImageFile(editor, file, position) {
|
|
|
2021
2080
|
URL.revokeObjectURL(blobUrl);
|
|
2022
2081
|
return;
|
|
2023
2082
|
}
|
|
2083
|
+
const { uploads, progress } = editor.storage.imageUpload;
|
|
2024
2084
|
const context = {
|
|
2025
2085
|
position,
|
|
2026
|
-
removeImage: () => removeImageByBlobUrl(editor, blobUrl)
|
|
2086
|
+
removeImage: () => removeImageByBlobUrl(editor, blobUrl),
|
|
2087
|
+
setProgress: (fraction) => {
|
|
2088
|
+
const percent = Math.round(Math.min(Math.max(fraction, 0), 1) * 100);
|
|
2089
|
+
if (!uploads.has(blobUrl) || progress.get(blobUrl) === percent) return;
|
|
2090
|
+
progress.set(blobUrl, percent);
|
|
2091
|
+
notifyUploadStatusChanged(editor);
|
|
2092
|
+
}
|
|
2027
2093
|
};
|
|
2028
|
-
const { uploads } = editor.storage.imageUpload;
|
|
2029
2094
|
uploads.set(blobUrl, IMAGE_UPLOAD_STATUSES.LOADING);
|
|
2030
2095
|
notifyUploadStatusChanged(editor);
|
|
2031
2096
|
onImageUpload(file, context).then((url) => {
|
|
2032
2097
|
uploads.delete(blobUrl);
|
|
2098
|
+
progress.delete(blobUrl);
|
|
2033
2099
|
notifyUploadStatusChanged(editor);
|
|
2034
2100
|
updateImageByBlobUrl(editor, blobUrl, { src: url });
|
|
2035
2101
|
URL.revokeObjectURL(blobUrl);
|
|
2036
2102
|
}).catch((error) => {
|
|
2037
2103
|
uploads.set(blobUrl, IMAGE_UPLOAD_STATUSES.ERROR);
|
|
2104
|
+
progress.delete(blobUrl);
|
|
2038
2105
|
notifyUploadStatusChanged(editor);
|
|
2039
2106
|
onImageUploadError?.(error, file, context);
|
|
2040
2107
|
URL.revokeObjectURL(blobUrl);
|
|
@@ -2065,7 +2132,10 @@ const ImageUploadExtension = _tiptap_core.Extension.create({
|
|
|
2065
2132
|
};
|
|
2066
2133
|
},
|
|
2067
2134
|
addStorage() {
|
|
2068
|
-
return {
|
|
2135
|
+
return {
|
|
2136
|
+
uploads: /* @__PURE__ */ new Map(),
|
|
2137
|
+
progress: /* @__PURE__ */ new Map()
|
|
2138
|
+
};
|
|
2069
2139
|
},
|
|
2070
2140
|
addExtensions() {
|
|
2071
2141
|
return [_tiptap_extension_file_handler.FileHandler.configure({
|
|
@@ -2224,7 +2294,7 @@ function ImageVariableState() {
|
|
|
2224
2294
|
});
|
|
2225
2295
|
}
|
|
2226
2296
|
function ImageLoadingState(props) {
|
|
2227
|
-
const { alt, src } = props;
|
|
2297
|
+
const { alt, src, progress } = props;
|
|
2228
2298
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2229
2299
|
"aria-busy": "true",
|
|
2230
2300
|
"data-mly-image-loading": "",
|
|
@@ -2234,7 +2304,20 @@ function ImageLoadingState(props) {
|
|
|
2234
2304
|
"data-mly-image-preview": "",
|
|
2235
2305
|
src
|
|
2236
2306
|
}),
|
|
2237
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2307
|
+
progress !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2308
|
+
"aria-label": "Uploading image",
|
|
2309
|
+
"aria-valuemax": 100,
|
|
2310
|
+
"aria-valuemin": 0,
|
|
2311
|
+
"aria-valuenow": progress,
|
|
2312
|
+
"data-mly-image-progress": "",
|
|
2313
|
+
"data-state": progress !== void 0 && progress < 100 ? "uploading" : "done",
|
|
2314
|
+
role: "progressbar",
|
|
2315
|
+
style: { "--mly-image-progress": progress / 100 }
|
|
2316
|
+
}),
|
|
2317
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
2318
|
+
"data-mly-image-spinner": "",
|
|
2319
|
+
"data-variant": progress === void 0 ? "center" : "corner"
|
|
2320
|
+
}),
|
|
2238
2321
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(VisuallyHidden, {
|
|
2239
2322
|
role: "status",
|
|
2240
2323
|
children: "Uploading image"
|
|
@@ -2267,12 +2350,19 @@ function useUploadStatus(editor, src) {
|
|
|
2267
2350
|
if (!src) return IMAGE_UPLOAD_STATUSES.IDLE;
|
|
2268
2351
|
return status ?? IMAGE_UPLOAD_STATUSES.LOADED;
|
|
2269
2352
|
}
|
|
2353
|
+
function useUploadProgress(editor, src) {
|
|
2354
|
+
return (0, _tiptap_react.useEditorState)({
|
|
2355
|
+
editor,
|
|
2356
|
+
selector: (ctx) => src ? ctx.editor.storage.imageUpload?.progress?.get(src) : void 0
|
|
2357
|
+
});
|
|
2358
|
+
}
|
|
2270
2359
|
function ImageView(props) {
|
|
2271
2360
|
const { editor, getPos, node, updateAttributes } = props;
|
|
2272
2361
|
const { align, alt, src, width, style } = node.attrs;
|
|
2273
2362
|
const { width: _width, maxWidth: _maxWidth, height: _height, ...authoredStyle } = (0, _maily_to_shared.parseInlineStyles)(style ?? "");
|
|
2274
2363
|
const isSrcVariable = !!src && (0, _maily_to_shared.hasVariableInText)(src);
|
|
2275
2364
|
const status = useUploadStatus(editor, isSrcVariable ? void 0 : src);
|
|
2365
|
+
const progress = useUploadProgress(editor, status === IMAGE_UPLOAD_STATUSES.LOADING ? src : void 0);
|
|
2276
2366
|
const { containerRef, handleResize, imageWrapperRef, isResizing, setShouldShowDragHandles, shouldShowDragHandles } = useImageResizeController({
|
|
2277
2367
|
align,
|
|
2278
2368
|
onWidthCommitted: (0, react.useCallback)((committed) => updateAttributes({ width: `${committed}%` }), [updateAttributes])
|
|
@@ -2315,7 +2405,8 @@ function ImageView(props) {
|
|
|
2315
2405
|
!isSrcVariable && status === IMAGE_UPLOAD_STATUSES.IDLE ? editor.isEditable ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImagePlaceholder, { onFileSelect: handleFileSelect }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageIdleState, {}) : null,
|
|
2316
2406
|
!isSrcVariable && status === IMAGE_UPLOAD_STATUSES.LOADING ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageLoadingState, {
|
|
2317
2407
|
alt,
|
|
2318
|
-
src
|
|
2408
|
+
src,
|
|
2409
|
+
progress
|
|
2319
2410
|
}) : null,
|
|
2320
2411
|
status === IMAGE_UPLOAD_STATUSES.ERROR ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageErrorState, {}) : null,
|
|
2321
2412
|
!isSrcVariable && isLoaded ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", {
|
|
@@ -3118,6 +3209,7 @@ const STYLE_SUPPORTED_TYPES = [
|
|
|
3118
3209
|
...WRAPPER_TYPES,
|
|
3119
3210
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMNS,
|
|
3120
3211
|
_maily_to_shared.MAILY_NODE_TYPES.COLUMN,
|
|
3212
|
+
_maily_to_shared.MAILY_NODE_TYPES.DIV,
|
|
3121
3213
|
_maily_to_shared.MAILY_NODE_TYPES.PARAGRAPH,
|
|
3122
3214
|
_maily_to_shared.MAILY_NODE_TYPES.HEADING,
|
|
3123
3215
|
_maily_to_shared.MAILY_NODE_TYPES.IMAGE,
|
|
@@ -3344,6 +3436,38 @@ function setCellParagraphs(document) {
|
|
|
3344
3436
|
}
|
|
3345
3437
|
}
|
|
3346
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
|
+
}
|
|
3347
3471
|
function getSoleImage(anchor) {
|
|
3348
3472
|
const images = anchor.querySelectorAll("img");
|
|
3349
3473
|
return images.length === 1 && anchor.textContent?.trim() === "" ? images[0] : null;
|
|
@@ -3416,8 +3540,11 @@ function getNormalizedHtml(html) {
|
|
|
3416
3540
|
if (!parsed.body) return html;
|
|
3417
3541
|
setRuleStyles(parsed);
|
|
3418
3542
|
removeHidden(parsed);
|
|
3543
|
+
removeComments(parsed);
|
|
3544
|
+
unwrapBodyDiv(parsed);
|
|
3419
3545
|
setLinkedImages(parsed);
|
|
3420
3546
|
setVariables(parsed);
|
|
3547
|
+
setTextDivs(parsed);
|
|
3421
3548
|
setCellParagraphs(parsed);
|
|
3422
3549
|
const style = getBodyStyle(parsed);
|
|
3423
3550
|
if (!style) return parsed.body.innerHTML;
|
|
@@ -3462,6 +3589,7 @@ const DEFAULT_EXTENSIONS = [
|
|
|
3462
3589
|
BodyExtension,
|
|
3463
3590
|
ContainerExtension,
|
|
3464
3591
|
SectionExtension,
|
|
3592
|
+
DivExtension,
|
|
3465
3593
|
RepeatExtension,
|
|
3466
3594
|
ColumnsExtension,
|
|
3467
3595
|
ColumnExtension,
|
|
@@ -3654,6 +3782,12 @@ Object.defineProperty(exports, "DEFAULT_SLASH_COMMANDS", {
|
|
|
3654
3782
|
return DEFAULT_SLASH_COMMANDS;
|
|
3655
3783
|
}
|
|
3656
3784
|
});
|
|
3785
|
+
Object.defineProperty(exports, "DivExtension", {
|
|
3786
|
+
enumerable: true,
|
|
3787
|
+
get: function() {
|
|
3788
|
+
return DivExtension;
|
|
3789
|
+
}
|
|
3790
|
+
});
|
|
3657
3791
|
Object.defineProperty(exports, "Document", {
|
|
3658
3792
|
enumerable: true,
|
|
3659
3793
|
get: function() {
|