ct-rich-text-editor 1.3.16 → 1.3.18
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/{html2pdf.bundle-eeac9a72.js → html2pdf.bundle-0a42a49f.js} +2 -2
- package/dist/{html2pdf.bundle-eeac9a72.js.map → html2pdf.bundle-0a42a49f.js.map} +1 -1
- package/dist/{html2pdf.bundle.min-92a35c38.js → html2pdf.bundle.min-db02af80.js} +2 -2
- package/dist/{html2pdf.bundle.min-92a35c38.js.map → html2pdf.bundle.min-db02af80.js.map} +1 -1
- package/dist/{index-08a070e9.js → index-2bc5ccbc.js} +2 -2
- package/dist/{index-08a070e9.js.map → index-2bc5ccbc.js.map} +1 -1
- package/dist/{index-3ad5acc7.js → index-7ddd4fcc.js} +2 -2
- package/dist/{index-3ad5acc7.js.map → index-7ddd4fcc.js.map} +1 -1
- package/dist/{index-75a344b6.js → index-dbb526cd.js} +451 -30
- package/dist/index-dbb526cd.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/utils/editorStyleConverter.d.ts +7 -1
- package/package.json +1 -1
- package/dist/index-75a344b6.js.map +0 -1
|
@@ -1479,7 +1479,7 @@ const AiTextTransform = async ({ content, apiKey }) => {
|
|
|
1479
1479
|
const AI_ACTION_COMMAND = createCommand(
|
|
1480
1480
|
"AI_ACTION_COMMAND"
|
|
1481
1481
|
);
|
|
1482
|
-
const ImageView = React__default.lazy(() => import("./index-
|
|
1482
|
+
const ImageView = React__default.lazy(() => import("./index-2bc5ccbc.js"));
|
|
1483
1483
|
function isGoogleDocCheckboxImg(img) {
|
|
1484
1484
|
return img.parentElement != null && img.parentElement.tagName === "LI" && img.previousSibling === null && img.getAttribute("aria-roledescription") === "checkbox";
|
|
1485
1485
|
}
|
|
@@ -15282,7 +15282,7 @@ const EmbedComponent = ({ url, displayType, alignment, nodeKey }) => {
|
|
|
15282
15282
|
}
|
|
15283
15283
|
);
|
|
15284
15284
|
};
|
|
15285
|
-
const FileComponent = React$1.lazy(() => import("./index-
|
|
15285
|
+
const FileComponent = React$1.lazy(() => import("./index-7ddd4fcc.js"));
|
|
15286
15286
|
function convertFileElement(domNode) {
|
|
15287
15287
|
if (domNode instanceof HTMLDivElement) {
|
|
15288
15288
|
const dataUrl = domNode.getAttribute("data-lexical-file-src");
|
|
@@ -19120,6 +19120,7 @@ function AIChatDialog({
|
|
|
19120
19120
|
};
|
|
19121
19121
|
}, [apiKey]);
|
|
19122
19122
|
const handleSubmit = async () => {
|
|
19123
|
+
var _a, _b;
|
|
19123
19124
|
if (!inputValue.trim() || isLoading)
|
|
19124
19125
|
return;
|
|
19125
19126
|
setIsLoading(true);
|
|
@@ -19140,7 +19141,10 @@ function AIChatDialog({
|
|
|
19140
19141
|
setIsLoading(false);
|
|
19141
19142
|
} catch (error) {
|
|
19142
19143
|
console.error("Error processing AI action:", error);
|
|
19143
|
-
|
|
19144
|
+
const apiMessage = ((_b = (_a = error == null ? void 0 : error.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) ?? (error instanceof Error ? error.message : null);
|
|
19145
|
+
const safeMessage = apiMessage && !/^Request failed with status code \d+/.test(apiMessage) ? apiMessage : "Error processing your request. Please try again.";
|
|
19146
|
+
setErrorMessage(safeMessage);
|
|
19147
|
+
toast.error(safeMessage);
|
|
19144
19148
|
setIsLoading(false);
|
|
19145
19149
|
} finally {
|
|
19146
19150
|
setInputValue("");
|
|
@@ -19987,10 +19991,10 @@ const PDF_CONFIG = {
|
|
|
19987
19991
|
};
|
|
19988
19992
|
const loadHtml2Pdf = async () => {
|
|
19989
19993
|
try {
|
|
19990
|
-
const mod = await import("./html2pdf.bundle.min-
|
|
19994
|
+
const mod = await import("./html2pdf.bundle.min-db02af80.js").then((n) => n.h);
|
|
19991
19995
|
return (mod == null ? void 0 : mod.default) || mod;
|
|
19992
19996
|
} catch {
|
|
19993
|
-
const mod2 = await import("./html2pdf.bundle-
|
|
19997
|
+
const mod2 = await import("./html2pdf.bundle-0a42a49f.js").then((n) => n.h);
|
|
19994
19998
|
return (mod2 == null ? void 0 : mod2.default) || mod2;
|
|
19995
19999
|
}
|
|
19996
20000
|
};
|
|
@@ -26492,6 +26496,10 @@ const Toolbar = ({
|
|
|
26492
26496
|
)
|
|
26493
26497
|
}
|
|
26494
26498
|
) }),
|
|
26499
|
+
activeEditor === editor && hiddenItemIds.has("chartInsert") && /* @__PURE__ */ jsxs(DropdownMenuItem, { onClick: openChartDialog, children: [
|
|
26500
|
+
/* @__PURE__ */ jsx("div", { className: "[&>svg]:!cteditor-size-4 cteditor-size-6 cteditor-flex cteditor-items-center cteditor-justify-center", children: /* @__PURE__ */ jsx(ChartBarIcon, {}) }),
|
|
26501
|
+
"Insert Chart"
|
|
26502
|
+
] }),
|
|
26495
26503
|
enableTextFormatting && hiddenItemIds.has("inlineFormats") && /* @__PURE__ */ jsxs(
|
|
26496
26504
|
DropdownMenuItem,
|
|
26497
26505
|
{
|
|
@@ -32541,6 +32549,24 @@ function TableActionMenu({
|
|
|
32541
32549
|
const firstCell = cells[0];
|
|
32542
32550
|
hasColumnHeaders = (firstCell.getHeaderStyles() & TableCellHeaderStates.COLUMN) === TableCellHeaderStates.COLUMN;
|
|
32543
32551
|
headerBackgroundColor = firstCell.getBackgroundColor();
|
|
32552
|
+
if (!headerBackgroundColor) {
|
|
32553
|
+
const cellElement = editor.getElementByKey(firstCell.getKey());
|
|
32554
|
+
if (cellElement) {
|
|
32555
|
+
const inlineBgColor = cellElement.style.backgroundColor;
|
|
32556
|
+
if (inlineBgColor && inlineBgColor !== "rgba(0, 0, 0, 0)") {
|
|
32557
|
+
headerBackgroundColor = inlineBgColor;
|
|
32558
|
+
}
|
|
32559
|
+
}
|
|
32560
|
+
}
|
|
32561
|
+
if (!headerBackgroundColor) {
|
|
32562
|
+
const tableElement = editor.getElementByKey(tableNode.getKey());
|
|
32563
|
+
if (tableElement) {
|
|
32564
|
+
const cssVarColor = tableElement.style.getPropertyValue("--table-header-bg-color");
|
|
32565
|
+
if (cssVarColor) {
|
|
32566
|
+
headerBackgroundColor = cssVarColor;
|
|
32567
|
+
}
|
|
32568
|
+
}
|
|
32569
|
+
}
|
|
32544
32570
|
}
|
|
32545
32571
|
}
|
|
32546
32572
|
const cellColumnIndex = $getTableColumnIndexFromTableCellNode(cell);
|
|
@@ -32751,6 +32777,15 @@ function TableActionMenu({
|
|
|
32751
32777
|
hasHeaderRow = (firstCell.getHeaderStyles() & TableCellHeaderStates.COLUMN) === TableCellHeaderStates.COLUMN;
|
|
32752
32778
|
}
|
|
32753
32779
|
}
|
|
32780
|
+
const rows = Array.from(tableElement.querySelectorAll("tr"));
|
|
32781
|
+
const dataRows = hasHeaderRow ? rows.slice(1) : rows;
|
|
32782
|
+
dataRows.forEach((row, index2) => {
|
|
32783
|
+
if (index2 % 2 === 0) {
|
|
32784
|
+
row.querySelectorAll("td").forEach((cell) => {
|
|
32785
|
+
cell.style.removeProperty("background-color");
|
|
32786
|
+
});
|
|
32787
|
+
}
|
|
32788
|
+
});
|
|
32754
32789
|
tableElement.style.setProperty(
|
|
32755
32790
|
"--table-odd-striping-color",
|
|
32756
32791
|
color
|
|
@@ -32786,6 +32821,15 @@ function TableActionMenu({
|
|
|
32786
32821
|
hasHeaderRow = (firstCell.getHeaderStyles() & TableCellHeaderStates.COLUMN) === TableCellHeaderStates.COLUMN;
|
|
32787
32822
|
}
|
|
32788
32823
|
}
|
|
32824
|
+
const rows = Array.from(tableElement.querySelectorAll("tr"));
|
|
32825
|
+
const dataRows = hasHeaderRow ? rows.slice(1) : rows;
|
|
32826
|
+
dataRows.forEach((row, index2) => {
|
|
32827
|
+
if (index2 % 2 === 1) {
|
|
32828
|
+
row.querySelectorAll("td").forEach((cell) => {
|
|
32829
|
+
cell.style.removeProperty("background-color");
|
|
32830
|
+
});
|
|
32831
|
+
}
|
|
32832
|
+
});
|
|
32789
32833
|
tableElement.style.setProperty(
|
|
32790
32834
|
"--table-even-striping-color",
|
|
32791
32835
|
color
|
|
@@ -34169,7 +34213,25 @@ function TableHoverActionsContainer({
|
|
|
34169
34213
|
const newHeaderCell = updatedCells[index2];
|
|
34170
34214
|
if (newHeaderCell && $isTableCellNode(newHeaderCell)) {
|
|
34171
34215
|
newHeaderCell.setHeaderStyles(TableCellHeaderStates.COLUMN);
|
|
34172
|
-
|
|
34216
|
+
let headerBackgroundColor = cells[0].getBackgroundColor();
|
|
34217
|
+
if (!headerBackgroundColor) {
|
|
34218
|
+
const cellElement = editor.getElementByKey(cells[0].getKey());
|
|
34219
|
+
if (cellElement) {
|
|
34220
|
+
const inlineBgColor = cellElement.style.backgroundColor;
|
|
34221
|
+
if (inlineBgColor && inlineBgColor !== "rgba(0, 0, 0, 0)") {
|
|
34222
|
+
headerBackgroundColor = inlineBgColor;
|
|
34223
|
+
}
|
|
34224
|
+
}
|
|
34225
|
+
}
|
|
34226
|
+
if (!headerBackgroundColor) {
|
|
34227
|
+
const tableElement = editor.getElementByKey(tableNode.getKey());
|
|
34228
|
+
if (tableElement) {
|
|
34229
|
+
const cssVarColor = tableElement.style.getPropertyValue("--table-header-bg-color");
|
|
34230
|
+
if (cssVarColor) {
|
|
34231
|
+
headerBackgroundColor = cssVarColor;
|
|
34232
|
+
}
|
|
34233
|
+
}
|
|
34234
|
+
}
|
|
34173
34235
|
if (headerBackgroundColor) {
|
|
34174
34236
|
newHeaderCell.setBackgroundColor(headerBackgroundColor);
|
|
34175
34237
|
}
|
|
@@ -35234,7 +35296,7 @@ const WordCountPlugin = () => {
|
|
|
35234
35296
|
}
|
|
35235
35297
|
);
|
|
35236
35298
|
};
|
|
35237
|
-
function
|
|
35299
|
+
function exportEditorWithInlineStyle(editor) {
|
|
35238
35300
|
const rootElement = editor.getRootElement();
|
|
35239
35301
|
if (!rootElement)
|
|
35240
35302
|
return "";
|
|
@@ -35242,9 +35304,44 @@ function exportEditorWithStriping(editor) {
|
|
|
35242
35304
|
const liveTables = rootElement.querySelectorAll("table");
|
|
35243
35305
|
liveTables.forEach((table, index2) => {
|
|
35244
35306
|
const colors = detectTableColorsFromVariables(table);
|
|
35245
|
-
|
|
35246
|
-
|
|
35247
|
-
|
|
35307
|
+
const oddColor = (colors == null ? void 0 : colors.odd) || "";
|
|
35308
|
+
const evenColor = (colors == null ? void 0 : colors.even) || "";
|
|
35309
|
+
const headerCells = table.querySelectorAll("th");
|
|
35310
|
+
const headerBgColors = [];
|
|
35311
|
+
headerCells.forEach((th) => {
|
|
35312
|
+
const computed = window.getComputedStyle(th);
|
|
35313
|
+
const bgColor = computed.backgroundColor;
|
|
35314
|
+
if (bgColor && bgColor !== "rgba(0, 0, 0, 0)") {
|
|
35315
|
+
headerBgColors.push(bgColor);
|
|
35316
|
+
} else {
|
|
35317
|
+
headerBgColors.push("");
|
|
35318
|
+
}
|
|
35319
|
+
});
|
|
35320
|
+
const explicitCellColors = /* @__PURE__ */ new Map();
|
|
35321
|
+
const rows = Array.from(table.querySelectorAll("tr"));
|
|
35322
|
+
const firstRow = rows[0];
|
|
35323
|
+
const hasHeaderRow = firstRow && firstRow.querySelectorAll("th").length > 0;
|
|
35324
|
+
const dataRows = hasHeaderRow ? rows.slice(1) : rows;
|
|
35325
|
+
dataRows.forEach((row, rowIndex) => {
|
|
35326
|
+
const cells = row.querySelectorAll("td");
|
|
35327
|
+
cells.forEach((cell, cellIndex) => {
|
|
35328
|
+
const inlineBgColor = cell.style.backgroundColor;
|
|
35329
|
+
if (inlineBgColor && inlineBgColor !== "rgba(0, 0, 0, 0)") {
|
|
35330
|
+
const normalizedBg = normalizeColorForComparison(inlineBgColor);
|
|
35331
|
+
const normalizedOdd = normalizeColorForComparison(oddColor);
|
|
35332
|
+
const normalizedEven = normalizeColorForComparison(evenColor);
|
|
35333
|
+
if (normalizedBg !== "" && normalizedBg !== normalizedOdd && normalizedBg !== normalizedEven) {
|
|
35334
|
+
explicitCellColors.set(`${rowIndex}-${cellIndex}`, inlineBgColor);
|
|
35335
|
+
}
|
|
35336
|
+
}
|
|
35337
|
+
});
|
|
35338
|
+
});
|
|
35339
|
+
tableStyleMap.set(index2, {
|
|
35340
|
+
odd: oddColor,
|
|
35341
|
+
even: evenColor,
|
|
35342
|
+
headerBgColors,
|
|
35343
|
+
explicitCellColors
|
|
35344
|
+
});
|
|
35248
35345
|
});
|
|
35249
35346
|
let htmlString = "";
|
|
35250
35347
|
editor.getEditorState().read(() => {
|
|
@@ -35252,10 +35349,31 @@ function exportEditorWithStriping(editor) {
|
|
|
35252
35349
|
});
|
|
35253
35350
|
return processHtmlForExport(htmlString, tableStyleMap);
|
|
35254
35351
|
}
|
|
35352
|
+
function normalizeColorForComparison(color) {
|
|
35353
|
+
if (!color)
|
|
35354
|
+
return "";
|
|
35355
|
+
color = color.trim().toLowerCase();
|
|
35356
|
+
if (color.startsWith("#")) {
|
|
35357
|
+
if (color.length === 4) {
|
|
35358
|
+
return `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`;
|
|
35359
|
+
}
|
|
35360
|
+
return color;
|
|
35361
|
+
}
|
|
35362
|
+
if (color.includes("rgb")) {
|
|
35363
|
+
const matches = color.match(/\d+/g);
|
|
35364
|
+
if (matches && matches.length >= 3) {
|
|
35365
|
+
const r2 = parseInt(matches[0]);
|
|
35366
|
+
const g2 = parseInt(matches[1]);
|
|
35367
|
+
const b2 = parseInt(matches[2]);
|
|
35368
|
+
return `#${r2.toString(16).padStart(2, "0")}${g2.toString(16).padStart(2, "0")}${b2.toString(16).padStart(2, "0")}`;
|
|
35369
|
+
}
|
|
35370
|
+
}
|
|
35371
|
+
return color;
|
|
35372
|
+
}
|
|
35255
35373
|
function detectTableColorsFromVariables(table) {
|
|
35256
35374
|
const computed = window.getComputedStyle(table);
|
|
35257
|
-
const oddVar = computed.getPropertyValue("--table-
|
|
35258
|
-
const evenVar = computed.getPropertyValue("--table-
|
|
35375
|
+
const oddVar = computed.getPropertyValue("--table-even-striping-color").trim();
|
|
35376
|
+
const evenVar = computed.getPropertyValue("--table-odd-striping-color").trim();
|
|
35259
35377
|
const isValidColor = (c2) => c2 && c2 !== "initial" && c2 !== "inherit" && c2 !== "";
|
|
35260
35378
|
if (isValidColor(oddVar) || isValidColor(evenVar)) {
|
|
35261
35379
|
return {
|
|
@@ -35284,27 +35402,48 @@ function processHtmlForExport(html, tableStyleMap) {
|
|
|
35284
35402
|
const doc = parser.parseFromString(html, "text/html");
|
|
35285
35403
|
const tables = doc.querySelectorAll("table");
|
|
35286
35404
|
tables.forEach((table, index2) => {
|
|
35287
|
-
const
|
|
35288
|
-
if (!
|
|
35405
|
+
const styleInfo = tableStyleMap.get(index2);
|
|
35406
|
+
if (!styleInfo)
|
|
35289
35407
|
return;
|
|
35408
|
+
const headerCells = table.querySelectorAll("th");
|
|
35409
|
+
headerCells.forEach((th, cellIndex) => {
|
|
35410
|
+
const bgColor = styleInfo.headerBgColors[cellIndex];
|
|
35411
|
+
if (bgColor) {
|
|
35412
|
+
const el = th;
|
|
35413
|
+
el.style.setProperty("background-color", bgColor, "important");
|
|
35414
|
+
const textColor = getContrastColor(bgColor);
|
|
35415
|
+
el.style.color = textColor;
|
|
35416
|
+
el.querySelectorAll("*").forEach((nested) => {
|
|
35417
|
+
nested.style.color = textColor;
|
|
35418
|
+
});
|
|
35419
|
+
}
|
|
35420
|
+
});
|
|
35290
35421
|
const tbody = table.querySelector("tbody") || table;
|
|
35291
35422
|
const dataRows = Array.from(tbody.querySelectorAll("tr")).filter(
|
|
35292
35423
|
(row) => row.querySelector("td")
|
|
35293
35424
|
);
|
|
35294
35425
|
dataRows.forEach((row, rowIndex) => {
|
|
35295
|
-
const
|
|
35296
|
-
const
|
|
35297
|
-
|
|
35298
|
-
const
|
|
35299
|
-
|
|
35300
|
-
|
|
35301
|
-
|
|
35426
|
+
const isOddDataRow = rowIndex % 2 === 0;
|
|
35427
|
+
const stripingColor = isOddDataRow ? styleInfo.odd : styleInfo.even;
|
|
35428
|
+
row.querySelectorAll("td").forEach((cell, cellIndex) => {
|
|
35429
|
+
const el = cell;
|
|
35430
|
+
const explicitColor = styleInfo.explicitCellColors.get(`${rowIndex}-${cellIndex}`);
|
|
35431
|
+
if (explicitColor) {
|
|
35432
|
+
const textColor = getContrastColor(explicitColor);
|
|
35433
|
+
el.style.setProperty("background-color", explicitColor, "important");
|
|
35302
35434
|
el.style.color = textColor;
|
|
35303
35435
|
el.querySelectorAll("*").forEach((nested) => {
|
|
35304
35436
|
nested.style.color = textColor;
|
|
35305
35437
|
});
|
|
35306
|
-
})
|
|
35307
|
-
|
|
35438
|
+
} else if (stripingColor) {
|
|
35439
|
+
const textColor = getContrastColor(stripingColor);
|
|
35440
|
+
el.style.setProperty("background-color", stripingColor, "important");
|
|
35441
|
+
el.style.color = textColor;
|
|
35442
|
+
el.querySelectorAll("*").forEach((nested) => {
|
|
35443
|
+
nested.style.color = textColor;
|
|
35444
|
+
});
|
|
35445
|
+
}
|
|
35446
|
+
});
|
|
35308
35447
|
});
|
|
35309
35448
|
});
|
|
35310
35449
|
cleanupHeaderCellStructure(doc.body);
|
|
@@ -35338,8 +35477,19 @@ function applyGenericSafeStyles(container) {
|
|
|
35338
35477
|
el.style.cssText += "; " + styles;
|
|
35339
35478
|
});
|
|
35340
35479
|
};
|
|
35480
|
+
const addStyleIfNotSet = (selector, property, value) => {
|
|
35481
|
+
container.querySelectorAll(selector).forEach((el) => {
|
|
35482
|
+
const currentValue = el.style.getPropertyValue(property);
|
|
35483
|
+
if (!currentValue || currentValue === "initial" || currentValue === "inherit") {
|
|
35484
|
+
el.style.setProperty(property, value);
|
|
35485
|
+
}
|
|
35486
|
+
});
|
|
35487
|
+
};
|
|
35341
35488
|
const fontReset = 'font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 1.5;';
|
|
35342
|
-
addStyle(
|
|
35489
|
+
addStyle(
|
|
35490
|
+
"table, p, span, li, td, th, div, h1, h2, h3, h4, h5, h6",
|
|
35491
|
+
fontReset
|
|
35492
|
+
);
|
|
35343
35493
|
addStyle("th p, td p", "margin: 0; padding: 0;");
|
|
35344
35494
|
addStyle(
|
|
35345
35495
|
"table",
|
|
@@ -35349,7 +35499,8 @@ function applyGenericSafeStyles(container) {
|
|
|
35349
35499
|
"th, td",
|
|
35350
35500
|
"border: 1px solid #dfe1e5; padding: 10px; vertical-align: middle; text-align: left;"
|
|
35351
35501
|
);
|
|
35352
|
-
|
|
35502
|
+
addStyleIfNotSet("th", "background-color", "#f8f9fa");
|
|
35503
|
+
addStyle("th", "font-weight: 600;");
|
|
35353
35504
|
addStyle("img", "max-width: 100%; height: auto; display: block;");
|
|
35354
35505
|
addStyle("h1", "font-size: 2em; font-weight: bold; margin: 0.67em 0;");
|
|
35355
35506
|
addStyle("h2", "font-size: 1.5em; font-weight: bold; margin: 0.75em 0;");
|
|
@@ -35418,6 +35569,168 @@ function getContrastColor(color) {
|
|
|
35418
35569
|
const yiq = (r2 * 299 + g2 * 587 + b2 * 114) / 1e3;
|
|
35419
35570
|
return yiq >= 128 ? "#000000" : "#FFFFFF";
|
|
35420
35571
|
}
|
|
35572
|
+
function normalizeColor(color) {
|
|
35573
|
+
if (!color)
|
|
35574
|
+
return "";
|
|
35575
|
+
color = color.trim().toLowerCase();
|
|
35576
|
+
if (color.startsWith("#")) {
|
|
35577
|
+
return color;
|
|
35578
|
+
}
|
|
35579
|
+
if (color.includes("rgb")) {
|
|
35580
|
+
const matches = color.match(/\d+/g);
|
|
35581
|
+
if (matches && matches.length >= 3) {
|
|
35582
|
+
const r2 = parseInt(matches[0]);
|
|
35583
|
+
const g2 = parseInt(matches[1]);
|
|
35584
|
+
const b2 = parseInt(matches[2]);
|
|
35585
|
+
return `#${r2.toString(16).padStart(2, "0")}${g2.toString(16).padStart(2, "0")}${b2.toString(16).padStart(2, "0")}`;
|
|
35586
|
+
}
|
|
35587
|
+
}
|
|
35588
|
+
return color;
|
|
35589
|
+
}
|
|
35590
|
+
function detectTableStylesFromInline(table) {
|
|
35591
|
+
const result = {
|
|
35592
|
+
hasHeaderRow: false,
|
|
35593
|
+
oddStripingColor: null,
|
|
35594
|
+
evenStripingColor: null,
|
|
35595
|
+
headerBackgroundColors: []
|
|
35596
|
+
};
|
|
35597
|
+
const rows = Array.from(table.querySelectorAll("tr"));
|
|
35598
|
+
if (rows.length === 0)
|
|
35599
|
+
return result;
|
|
35600
|
+
const firstRow = rows[0];
|
|
35601
|
+
const headerCells = firstRow.querySelectorAll("th");
|
|
35602
|
+
const hasThElements = headerCells.length > 0;
|
|
35603
|
+
if (hasThElements) {
|
|
35604
|
+
result.hasHeaderRow = true;
|
|
35605
|
+
headerCells.forEach((th) => {
|
|
35606
|
+
const bgColor = th.style.backgroundColor;
|
|
35607
|
+
if (bgColor) {
|
|
35608
|
+
result.headerBackgroundColors.push(normalizeColor(bgColor));
|
|
35609
|
+
} else {
|
|
35610
|
+
result.headerBackgroundColors.push("");
|
|
35611
|
+
}
|
|
35612
|
+
});
|
|
35613
|
+
} else {
|
|
35614
|
+
const firstRowCells = firstRow.querySelectorAll("td");
|
|
35615
|
+
if (firstRowCells.length > 0) {
|
|
35616
|
+
const firstCell = firstRowCells[0];
|
|
35617
|
+
const bgColor = firstCell.style.backgroundColor;
|
|
35618
|
+
if (bgColor) {
|
|
35619
|
+
const normalizedBg = normalizeColor(bgColor);
|
|
35620
|
+
const isLikelyHeader = normalizedBg === "#f8f9fa" || normalizedBg === "#565656" || firstCell.style.fontWeight === "600" || firstCell.style.fontWeight === "bold";
|
|
35621
|
+
if (isLikelyHeader) {
|
|
35622
|
+
result.hasHeaderRow = true;
|
|
35623
|
+
firstRowCells.forEach((td) => {
|
|
35624
|
+
const cellBg = td.style.backgroundColor;
|
|
35625
|
+
result.headerBackgroundColors.push(
|
|
35626
|
+
cellBg ? normalizeColor(cellBg) : ""
|
|
35627
|
+
);
|
|
35628
|
+
});
|
|
35629
|
+
}
|
|
35630
|
+
}
|
|
35631
|
+
}
|
|
35632
|
+
}
|
|
35633
|
+
const dataRows = result.hasHeaderRow ? rows.slice(1) : rows;
|
|
35634
|
+
const rowColors = [];
|
|
35635
|
+
dataRows.forEach((row) => {
|
|
35636
|
+
const cells = row.querySelectorAll("td");
|
|
35637
|
+
if (cells.length > 0) {
|
|
35638
|
+
const cellColors = [];
|
|
35639
|
+
cells.forEach((cell) => {
|
|
35640
|
+
const bgColor = cell.style.backgroundColor;
|
|
35641
|
+
cellColors.push(bgColor ? normalizeColor(bgColor) : null);
|
|
35642
|
+
});
|
|
35643
|
+
const firstColor = cellColors[0];
|
|
35644
|
+
const allSameColor = cellColors.every((c2) => c2 === firstColor);
|
|
35645
|
+
if (allSameColor && firstColor) {
|
|
35646
|
+
rowColors.push(firstColor);
|
|
35647
|
+
} else {
|
|
35648
|
+
rowColors.push(null);
|
|
35649
|
+
}
|
|
35650
|
+
}
|
|
35651
|
+
});
|
|
35652
|
+
if (rowColors.length >= 2) {
|
|
35653
|
+
const oddRowColors = rowColors.filter((_, i2) => (i2 + 1) % 2 === 0);
|
|
35654
|
+
const evenRowColors = rowColors.filter((_, i2) => (i2 + 1) % 2 === 1);
|
|
35655
|
+
const oddColorCounts = /* @__PURE__ */ new Map();
|
|
35656
|
+
oddRowColors.forEach((c2) => {
|
|
35657
|
+
if (c2 && c2 !== "transparent" && c2 !== "rgba(0, 0, 0, 0)") {
|
|
35658
|
+
oddColorCounts.set(c2, (oddColorCounts.get(c2) || 0) + 1);
|
|
35659
|
+
}
|
|
35660
|
+
});
|
|
35661
|
+
const evenColorCounts = /* @__PURE__ */ new Map();
|
|
35662
|
+
evenRowColors.forEach((c2) => {
|
|
35663
|
+
if (c2 && c2 !== "transparent" && c2 !== "rgba(0, 0, 0, 0)") {
|
|
35664
|
+
evenColorCounts.set(c2, (evenColorCounts.get(c2) || 0) + 1);
|
|
35665
|
+
}
|
|
35666
|
+
});
|
|
35667
|
+
let maxOddCount = 0;
|
|
35668
|
+
let maxOddColor = null;
|
|
35669
|
+
oddColorCounts.forEach((count2, color) => {
|
|
35670
|
+
if (count2 > maxOddCount) {
|
|
35671
|
+
maxOddCount = count2;
|
|
35672
|
+
maxOddColor = color;
|
|
35673
|
+
}
|
|
35674
|
+
});
|
|
35675
|
+
let maxEvenCount = 0;
|
|
35676
|
+
let maxEvenColor = null;
|
|
35677
|
+
evenColorCounts.forEach((count2, color) => {
|
|
35678
|
+
if (count2 > maxEvenCount) {
|
|
35679
|
+
maxEvenCount = count2;
|
|
35680
|
+
maxEvenColor = color;
|
|
35681
|
+
}
|
|
35682
|
+
});
|
|
35683
|
+
if (maxOddColor && (maxOddCount >= 1 || oddRowColors.length <= 2)) {
|
|
35684
|
+
if (maxOddColor !== maxEvenColor || !maxEvenColor) {
|
|
35685
|
+
result.oddStripingColor = maxOddColor;
|
|
35686
|
+
}
|
|
35687
|
+
}
|
|
35688
|
+
if (maxEvenColor && (maxEvenCount >= 1 || evenRowColors.length <= 2)) {
|
|
35689
|
+
if (maxEvenColor !== maxOddColor || !maxOddColor) {
|
|
35690
|
+
result.evenStripingColor = maxEvenColor;
|
|
35691
|
+
}
|
|
35692
|
+
}
|
|
35693
|
+
} else if (rowColors.length === 1 && rowColors[0]) {
|
|
35694
|
+
result.oddStripingColor = rowColors[0];
|
|
35695
|
+
}
|
|
35696
|
+
return result;
|
|
35697
|
+
}
|
|
35698
|
+
function preprocessInitialContent(html) {
|
|
35699
|
+
if (!html || !html.includes("<table")) {
|
|
35700
|
+
return html;
|
|
35701
|
+
}
|
|
35702
|
+
const parser = new DOMParser();
|
|
35703
|
+
const doc = parser.parseFromString(html, "text/html");
|
|
35704
|
+
const tables = doc.querySelectorAll("table");
|
|
35705
|
+
tables.forEach((table) => {
|
|
35706
|
+
const styles = detectTableStylesFromInline(table);
|
|
35707
|
+
if (styles.oddStripingColor) {
|
|
35708
|
+
table.style.setProperty(
|
|
35709
|
+
"--table-odd-striping-color",
|
|
35710
|
+
styles.oddStripingColor
|
|
35711
|
+
);
|
|
35712
|
+
table.classList.add("table-custom-odd-striping");
|
|
35713
|
+
}
|
|
35714
|
+
if (styles.evenStripingColor) {
|
|
35715
|
+
table.style.setProperty(
|
|
35716
|
+
"--table-even-striping-color",
|
|
35717
|
+
styles.evenStripingColor
|
|
35718
|
+
);
|
|
35719
|
+
table.classList.add("table-custom-even-striping");
|
|
35720
|
+
}
|
|
35721
|
+
if (styles.hasHeaderRow) {
|
|
35722
|
+
table.classList.add("has-header-row");
|
|
35723
|
+
const firstHeaderColor = styles.headerBackgroundColors.find((c2) => c2);
|
|
35724
|
+
if (firstHeaderColor) {
|
|
35725
|
+
table.style.setProperty("--table-header-bg-color", firstHeaderColor);
|
|
35726
|
+
}
|
|
35727
|
+
}
|
|
35728
|
+
if (!table.classList.contains("PlaygroundEditorTheme__table")) {
|
|
35729
|
+
table.classList.add("PlaygroundEditorTheme__table");
|
|
35730
|
+
}
|
|
35731
|
+
});
|
|
35732
|
+
return doc.body.innerHTML;
|
|
35733
|
+
}
|
|
35421
35734
|
const useAutoExpandingHeight = ({
|
|
35422
35735
|
minHeight = 150,
|
|
35423
35736
|
maxHeight = 800,
|
|
@@ -35529,7 +35842,7 @@ const OnChangeWrapper = ({
|
|
|
35529
35842
|
}) => {
|
|
35530
35843
|
const [editor] = useLexicalComposerContext();
|
|
35531
35844
|
const handleChange = () => {
|
|
35532
|
-
const exportReady =
|
|
35845
|
+
const exportReady = exportEditorWithInlineStyle(editor);
|
|
35533
35846
|
if (onChange) {
|
|
35534
35847
|
onChange(exportReady);
|
|
35535
35848
|
}
|
|
@@ -35540,19 +35853,127 @@ const InitialContentPlugin = ({
|
|
|
35540
35853
|
initialContent
|
|
35541
35854
|
}) => {
|
|
35542
35855
|
const [editor] = useLexicalComposerContext();
|
|
35856
|
+
const [hasInitialized, setHasInitialized] = useState$1(false);
|
|
35543
35857
|
useEffect$1(() => {
|
|
35544
|
-
if (!initialContent)
|
|
35858
|
+
if (hasInitialized || !initialContent)
|
|
35545
35859
|
return;
|
|
35860
|
+
setHasInitialized(true);
|
|
35861
|
+
const processedHtml = preprocessInitialContent(initialContent);
|
|
35546
35862
|
editor.update(() => {
|
|
35547
35863
|
const parser = new DOMParser();
|
|
35548
|
-
const dom = parser.parseFromString(
|
|
35864
|
+
const dom = parser.parseFromString(processedHtml, "text/html");
|
|
35549
35865
|
const nodes = $generateNodesFromDOM(editor, dom);
|
|
35550
35866
|
const root2 = $getRoot();
|
|
35551
35867
|
root2.clear();
|
|
35552
35868
|
root2.append(...nodes);
|
|
35869
|
+
root2.getChildren().forEach((node) => {
|
|
35870
|
+
if ($isTableNode(node)) {
|
|
35871
|
+
const rows = node.getChildren();
|
|
35872
|
+
if (rows.length > 0) {
|
|
35873
|
+
const firstRow = rows[0];
|
|
35874
|
+
if ($isTableRowNode(firstRow)) {
|
|
35875
|
+
const cells = firstRow.getChildren();
|
|
35876
|
+
let hasHeaderCells = false;
|
|
35877
|
+
const preprocessedTables = dom.querySelectorAll("table");
|
|
35878
|
+
preprocessedTables.forEach((table) => {
|
|
35879
|
+
const firstTr = table.querySelector("tr");
|
|
35880
|
+
if (firstTr && firstTr.querySelectorAll("th").length > 0) {
|
|
35881
|
+
hasHeaderCells = true;
|
|
35882
|
+
}
|
|
35883
|
+
});
|
|
35884
|
+
if (hasHeaderCells) {
|
|
35885
|
+
cells.forEach((cell) => {
|
|
35886
|
+
if ($isTableCellNode(cell)) {
|
|
35887
|
+
cell.setHeaderStyles(TableCellHeaderStates.COLUMN);
|
|
35888
|
+
}
|
|
35889
|
+
});
|
|
35890
|
+
}
|
|
35891
|
+
}
|
|
35892
|
+
}
|
|
35893
|
+
}
|
|
35894
|
+
});
|
|
35553
35895
|
root2.selectEnd();
|
|
35554
35896
|
});
|
|
35555
|
-
|
|
35897
|
+
requestAnimationFrame(() => {
|
|
35898
|
+
const rootElement = editor.getRootElement();
|
|
35899
|
+
if (!rootElement)
|
|
35900
|
+
return;
|
|
35901
|
+
const parser = new DOMParser();
|
|
35902
|
+
const preprocessedDom = parser.parseFromString(processedHtml, "text/html");
|
|
35903
|
+
const preprocessedTables = preprocessedDom.querySelectorAll("table");
|
|
35904
|
+
const liveTables = rootElement.querySelectorAll("table");
|
|
35905
|
+
liveTables.forEach((liveTable, index2) => {
|
|
35906
|
+
const preprocessedTable = preprocessedTables[index2];
|
|
35907
|
+
if (!preprocessedTable)
|
|
35908
|
+
return;
|
|
35909
|
+
const oddColor = preprocessedTable.style.getPropertyValue("--table-odd-striping-color");
|
|
35910
|
+
const evenColor = preprocessedTable.style.getPropertyValue("--table-even-striping-color");
|
|
35911
|
+
const headerBgColor = preprocessedTable.style.getPropertyValue("--table-header-bg-color");
|
|
35912
|
+
const hasHeaderRow = preprocessedTable.classList.contains("has-header-row");
|
|
35913
|
+
const tableWrapper = liveTable.closest(".PlaygroundEditorTheme__tableScrollableWrapper");
|
|
35914
|
+
const targetElement = tableWrapper || liveTable;
|
|
35915
|
+
const normalizeColor2 = (color) => {
|
|
35916
|
+
if (!color)
|
|
35917
|
+
return "";
|
|
35918
|
+
color = color.trim().toLowerCase();
|
|
35919
|
+
if (color.startsWith("#")) {
|
|
35920
|
+
if (color.length === 4) {
|
|
35921
|
+
return `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`;
|
|
35922
|
+
}
|
|
35923
|
+
return color;
|
|
35924
|
+
}
|
|
35925
|
+
if (color.includes("rgb")) {
|
|
35926
|
+
const matches = color.match(/\d+/g);
|
|
35927
|
+
if (matches && matches.length >= 3) {
|
|
35928
|
+
const r2 = parseInt(matches[0]);
|
|
35929
|
+
const g2 = parseInt(matches[1]);
|
|
35930
|
+
const b2 = parseInt(matches[2]);
|
|
35931
|
+
return `#${r2.toString(16).padStart(2, "0")}${g2.toString(16).padStart(2, "0")}${b2.toString(16).padStart(2, "0")}`;
|
|
35932
|
+
}
|
|
35933
|
+
}
|
|
35934
|
+
return color;
|
|
35935
|
+
};
|
|
35936
|
+
const normalizedOdd = normalizeColor2(oddColor);
|
|
35937
|
+
const normalizedEven = normalizeColor2(evenColor);
|
|
35938
|
+
if (oddColor || evenColor) {
|
|
35939
|
+
const rows = Array.from(liveTable.querySelectorAll("tr"));
|
|
35940
|
+
const dataRows = hasHeaderRow ? rows.slice(1) : rows;
|
|
35941
|
+
dataRows.forEach((row) => {
|
|
35942
|
+
row.querySelectorAll("td").forEach((cell) => {
|
|
35943
|
+
const cellElement = cell;
|
|
35944
|
+
const cellBgColor = cellElement.style.backgroundColor;
|
|
35945
|
+
const normalizedCellColor = normalizeColor2(cellBgColor);
|
|
35946
|
+
const isStripingColor = normalizedCellColor === normalizedOdd || normalizedCellColor === normalizedEven;
|
|
35947
|
+
if (isStripingColor || !cellBgColor) {
|
|
35948
|
+
cellElement.style.removeProperty("background-color");
|
|
35949
|
+
cellElement.style.removeProperty("color");
|
|
35950
|
+
cell.querySelectorAll("*").forEach((nested) => {
|
|
35951
|
+
nested.style.removeProperty("color");
|
|
35952
|
+
});
|
|
35953
|
+
} else {
|
|
35954
|
+
cellElement.style.setProperty("background-color", cellBgColor, "important");
|
|
35955
|
+
}
|
|
35956
|
+
});
|
|
35957
|
+
});
|
|
35958
|
+
}
|
|
35959
|
+
if (oddColor) {
|
|
35960
|
+
targetElement.style.setProperty("--table-odd-striping-color", oddColor);
|
|
35961
|
+
targetElement.classList.add("table-custom-odd-striping");
|
|
35962
|
+
}
|
|
35963
|
+
if (evenColor) {
|
|
35964
|
+
targetElement.style.setProperty("--table-even-striping-color", evenColor);
|
|
35965
|
+
targetElement.classList.add("table-custom-even-striping");
|
|
35966
|
+
}
|
|
35967
|
+
if (headerBgColor) {
|
|
35968
|
+
targetElement.style.setProperty("--table-header-bg-color", headerBgColor);
|
|
35969
|
+
liveTable.style.setProperty("--table-header-bg-color", headerBgColor);
|
|
35970
|
+
}
|
|
35971
|
+
if (hasHeaderRow) {
|
|
35972
|
+
targetElement.classList.add("has-header-row");
|
|
35973
|
+
}
|
|
35974
|
+
});
|
|
35975
|
+
});
|
|
35976
|
+
}, [editor, initialContent, hasInitialized]);
|
|
35556
35977
|
return null;
|
|
35557
35978
|
};
|
|
35558
35979
|
const CellBackgroundPersistencePlugin = () => {
|
|
@@ -35954,4 +36375,4 @@ export {
|
|
|
35954
36375
|
useHtmlView as u,
|
|
35955
36376
|
verifyApiKey as v
|
|
35956
36377
|
};
|
|
35957
|
-
//# sourceMappingURL=index-
|
|
36378
|
+
//# sourceMappingURL=index-dbb526cd.js.map
|