@underverse-ui/underverse 2.0.0 → 2.0.2

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.
@@ -1083,6 +1083,9 @@ function getClipboardData(dataTransfer, type) {
1083
1083
  return "";
1084
1084
  }
1085
1085
  }
1086
+ function hasClipboardHtmlTable(dataTransfer) {
1087
+ return /<table(?:\s|>)/i.test(getClipboardData(dataTransfer, "text/html"));
1088
+ }
1086
1089
  function extractClipboardHtmlFragment(html) {
1087
1090
  const startMarker = "<!--StartFragment-->";
1088
1091
  const endMarker = "<!--EndFragment-->";
@@ -1093,6 +1096,13 @@ function extractClipboardHtmlFragment(html) {
1093
1096
  }
1094
1097
  return html;
1095
1098
  }
1099
+ function hasMeaningfulContentOutsideTable(container) {
1100
+ const clone = container.cloneNode(true);
1101
+ clone.querySelectorAll("table, style, script, meta, link").forEach((element) => element.remove());
1102
+ const remainingText = (clone.textContent ?? "").replace(/\u00a0/g, " ").replace(/\u200b/g, "").trim();
1103
+ if (remainingText) return true;
1104
+ return !!clone.querySelector("img, video, audio, iframe, object, embed, svg, canvas, hr, input, textarea, select, button");
1105
+ }
1096
1106
  function normalizeClipboardCellText(value) {
1097
1107
  return value.replace(/\r\n/g, "\n").replace(/\r/g, "\n").replace(/\u00a0/g, " ").replace(/[ \t]+\n/g, "\n").replace(/\n[ \t]+/g, "\n").replace(/\n+$/g, "").replace(/^\n+/g, "").trim();
1098
1108
  }
@@ -1716,7 +1726,10 @@ function getClipboardTableContent(dataTransfer) {
1716
1726
  const fragment = extractClipboardHtmlFragment(html);
1717
1727
  const fragmentDoc = new DOMParser().parseFromString(fragment, "text/html");
1718
1728
  const styleMap = parseClipboardCssClassStyles(doc);
1719
- const table = fragmentDoc.querySelector("table") ?? doc.querySelector("table");
1729
+ const sourceBody = fragmentDoc.querySelector("table") ? fragmentDoc.body : doc.body;
1730
+ const tables = sourceBody.querySelectorAll("table");
1731
+ if (tables.length !== 1 || hasMeaningfulContentOutsideTable(sourceBody)) return null;
1732
+ const table = tables[0];
1720
1733
  if (!(table instanceof HTMLTableElement)) return null;
1721
1734
  return createTableContent(getHtmlTableRows(table, styleMap), 1, {
1722
1735
  backgroundColor: DEFAULT_HTML_TABLE_CELL_BACKGROUND_COLOR
@@ -1866,6 +1879,7 @@ var ClipboardImages = Extension.create({
1866
1879
  editor.chain().focus().insertContent(tableContent).run();
1867
1880
  return true;
1868
1881
  }
1882
+ if (hasClipboardHtmlTable(event.clipboardData)) return false;
1869
1883
  const tsvTableContent = getClipboardTsvTableContent(event.clipboardData);
1870
1884
  if (tsvTableContent) {
1871
1885
  event.preventDefault();
@@ -2065,7 +2079,7 @@ import {
2065
2079
  import { setCellAttr } from "@tiptap/pm/tables";
2066
2080
 
2067
2081
  // src/components/UEditor/colors.tsx
2068
- import { useMemo as useMemo2, useRef as useRef3 } from "react";
2082
+ import React6, { useMemo as useMemo2, useRef as useRef3 } from "react";
2069
2083
  import { Check as Check2, Palette, Paintbrush, Grid } from "lucide-react";
2070
2084
 
2071
2085
  // src/components/UEditor/figma-toolbar-icons.tsx
@@ -2380,12 +2394,25 @@ var EditorColorPalette = ({
2380
2394
  colors,
2381
2395
  currentColor,
2382
2396
  onSelect,
2397
+ onCustomColorSelect,
2383
2398
  label
2384
2399
  }) => {
2385
2400
  const t = useSmartTranslations("UEditor");
2386
2401
  const colorInputRef = useRef3(null);
2387
2402
  const automaticColor = colors[0]?.color ?? "";
2388
2403
  const paletteColors = colors.slice(1);
2404
+ const customColorSelect = onCustomColorSelect ?? onSelect;
2405
+ React6.useEffect(() => {
2406
+ const input = colorInputRef.current;
2407
+ if (!input) return;
2408
+ const commitColor = () => customColorSelect(input.value);
2409
+ input.addEventListener("change", commitColor);
2410
+ return () => input.removeEventListener("change", commitColor);
2411
+ }, [customColorSelect]);
2412
+ React6.useEffect(() => {
2413
+ const input = colorInputRef.current;
2414
+ if (input) input.value = currentColor.startsWith("#") ? currentColor : "#000000";
2415
+ }, [currentColor]);
2389
2416
  return /* @__PURE__ */ jsxs4("div", { className: "w-56 p-2", children: [
2390
2417
  /* @__PURE__ */ jsx6("span", { className: "px-1 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground", children: label }),
2391
2418
  /* @__PURE__ */ jsxs4(
@@ -2439,20 +2466,19 @@ var EditorColorPalette = ({
2439
2466
  }
2440
2467
  ),
2441
2468
  /* @__PURE__ */ jsx6("span", { className: "flex-1 text-center", children: t("colors.moreColors") }),
2442
- /* @__PURE__ */ jsx6(Palette, { className: "h-4 w-4 text-muted-foreground" }),
2443
- /* @__PURE__ */ jsx6(
2444
- "input",
2445
- {
2446
- ref: colorInputRef,
2447
- type: "color",
2448
- value: currentColor.startsWith("#") ? currentColor : "#000000",
2449
- onChange: (event) => onSelect(event.target.value),
2450
- className: "sr-only",
2451
- tabIndex: -1
2452
- }
2453
- )
2469
+ /* @__PURE__ */ jsx6(Palette, { className: "h-4 w-4 text-muted-foreground" })
2454
2470
  ]
2455
2471
  }
2472
+ ),
2473
+ /* @__PURE__ */ jsx6(
2474
+ "input",
2475
+ {
2476
+ ref: colorInputRef,
2477
+ type: "color",
2478
+ defaultValue: currentColor.startsWith("#") ? currentColor : "#000000",
2479
+ className: "sr-only",
2480
+ tabIndex: -1
2481
+ }
2456
2482
  )
2457
2483
  ] });
2458
2484
  };
@@ -4523,4 +4549,4 @@ export {
4523
4549
  EditorToolbar,
4524
4550
  UEDITOR_PROSEMIRROR_CLASS_NAME
4525
4551
  };
4526
- //# sourceMappingURL=chunk-LTIU5FQY.js.map
4552
+ //# sourceMappingURL=chunk-Z6WE65J2.js.map