@asteroidcms/core-utils 0.1.6 → 0.1.7
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/client.cjs +53 -45
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +2 -1
- package/dist/client.d.ts +2 -1
- package/dist/client.js +55 -47
- package/dist/client.js.map +1 -1
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -1050,37 +1050,38 @@ function isIconEnabled(el) {
|
|
|
1050
1050
|
if (v === null) return false;
|
|
1051
1051
|
return v !== "false" && v !== "0";
|
|
1052
1052
|
}
|
|
1053
|
-
function enhanceCallouts(root) {
|
|
1053
|
+
function enhanceCallouts(root, calloutIcons) {
|
|
1054
1054
|
const callouts = root.querySelectorAll("aside[data-callout]");
|
|
1055
1055
|
callouts.forEach((el) => {
|
|
1056
|
-
if (el.dataset.rtCalloutEnhanced === "1") return;
|
|
1057
|
-
el.dataset.rtCalloutEnhanced = "1";
|
|
1058
|
-
if (!isIconEnabled(el)) return;
|
|
1059
1056
|
if (el.querySelector(":scope > .rt-callout-icon")) return;
|
|
1057
|
+
if (!isIconEnabled(el)) return;
|
|
1060
1058
|
const variant = calloutVariantOf(el);
|
|
1061
1059
|
const icon = document.createElement("span");
|
|
1062
1060
|
icon.className = "rt-callout-icon";
|
|
1063
1061
|
icon.dataset.variant = variant;
|
|
1064
1062
|
icon.setAttribute("aria-hidden", "true");
|
|
1063
|
+
if (!calloutIcons || !(variant in calloutIcons)) {
|
|
1064
|
+
icon.innerHTML = CALLOUT_ICON_SVG[variant] ?? CALLOUT_ICON_SVG.default;
|
|
1065
|
+
}
|
|
1065
1066
|
el.prepend(icon);
|
|
1066
1067
|
});
|
|
1068
|
+
if (!calloutIcons) return [];
|
|
1067
1069
|
const chips = [];
|
|
1068
1070
|
root.querySelectorAll(
|
|
1069
1071
|
"aside[data-callout] > .rt-callout-icon"
|
|
1070
1072
|
).forEach((chip) => {
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
}
|
|
1073
|
+
const variant = chip.dataset.variant || (chip.parentElement?.getAttribute("data-variant") ?? "default");
|
|
1074
|
+
if (variant in calloutIcons) {
|
|
1075
|
+
chips.push({ el: chip, variant });
|
|
1076
|
+
}
|
|
1075
1077
|
});
|
|
1076
1078
|
return chips;
|
|
1077
1079
|
}
|
|
1078
1080
|
function enhanceBlockquotes(root) {
|
|
1079
1081
|
const quotes = root.querySelectorAll("blockquote");
|
|
1080
1082
|
quotes.forEach((bq) => {
|
|
1081
|
-
if (bq.
|
|
1083
|
+
if (bq.querySelector(":scope > .rt-quote-open")) return;
|
|
1082
1084
|
if (bq.closest('figure[data-variant="pullquote"]')) return;
|
|
1083
|
-
bq.dataset.rtQuoted = "1";
|
|
1084
1085
|
const { first, last } = findQuoteBody(bq);
|
|
1085
1086
|
if (!first || !last) return;
|
|
1086
1087
|
const open = document.createElement("span");
|
|
@@ -1119,11 +1120,10 @@ function highlightCodeBlock(pre) {
|
|
|
1119
1120
|
if (!lang) return;
|
|
1120
1121
|
const code = pre.querySelector("code");
|
|
1121
1122
|
if (!code) return;
|
|
1122
|
-
if (code.
|
|
1123
|
+
if (code.classList.contains("hljs")) return;
|
|
1123
1124
|
const source = code.textContent ?? "";
|
|
1124
1125
|
code.innerHTML = highlightSource(source, lang);
|
|
1125
1126
|
code.classList.add("hljs");
|
|
1126
|
-
code.dataset.rtHighlighted = "1";
|
|
1127
1127
|
}
|
|
1128
1128
|
var DIFF_SEPARATOR_RE = /\n?@@---@@\n?/;
|
|
1129
1129
|
function diffLines(a, b) {
|
|
@@ -1246,8 +1246,7 @@ function buildCodeBlockLabel(pre) {
|
|
|
1246
1246
|
function enhanceCodeBlocks(root) {
|
|
1247
1247
|
const blocks = root.querySelectorAll("pre");
|
|
1248
1248
|
blocks.forEach((pre) => {
|
|
1249
|
-
if (pre.
|
|
1250
|
-
pre.dataset.rtEnhanced = "1";
|
|
1249
|
+
if (pre.classList.contains("rt-codeblock")) return;
|
|
1251
1250
|
pre.classList.add("rt-codeblock");
|
|
1252
1251
|
const variant = pre.dataset.variant;
|
|
1253
1252
|
if (variant === "diff") {
|
|
@@ -1591,7 +1590,7 @@ function BuiltinCalloutIcon({ variant }) {
|
|
|
1591
1590
|
const html = CALLOUT_ICON_SVG[variant] ?? CALLOUT_ICON_SVG.default;
|
|
1592
1591
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { dangerouslySetInnerHTML: { __html: html } });
|
|
1593
1592
|
}
|
|
1594
|
-
|
|
1593
|
+
var RichTextContent = react.memo(function RichTextContent2({
|
|
1595
1594
|
html,
|
|
1596
1595
|
classMap,
|
|
1597
1596
|
as = "div",
|
|
@@ -1609,49 +1608,58 @@ function RichTextContent({
|
|
|
1609
1608
|
[html, merged]
|
|
1610
1609
|
);
|
|
1611
1610
|
const ref = react.useRef(null);
|
|
1612
|
-
const
|
|
1613
|
-
react.
|
|
1611
|
+
const prevSafe = react.useRef("");
|
|
1612
|
+
const chipsRef = react.useRef([]);
|
|
1613
|
+
const onReadyRef = react.useRef(onReady);
|
|
1614
|
+
onReadyRef.current = onReady;
|
|
1615
|
+
const contentRefStable = react.useRef(contentRef);
|
|
1616
|
+
contentRefStable.current = contentRef;
|
|
1617
|
+
const calloutIconsRef = react.useRef(calloutIcons);
|
|
1618
|
+
calloutIconsRef.current = calloutIcons;
|
|
1619
|
+
const [renderKey, setRenderKey] = react.useState(0);
|
|
1620
|
+
react.useLayoutEffect(() => {
|
|
1614
1621
|
ensureCodeBlockStyles();
|
|
1615
1622
|
const root = ref.current;
|
|
1616
1623
|
if (!root) return;
|
|
1617
|
-
if (
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
raf = requestAnimationFrame(() => {
|
|
1631
|
-
raf = 0;
|
|
1632
|
-
apply();
|
|
1633
|
-
});
|
|
1634
|
-
});
|
|
1635
|
-
apply();
|
|
1636
|
-
return () => {
|
|
1637
|
-
mo.disconnect();
|
|
1638
|
-
if (raf) cancelAnimationFrame(raf);
|
|
1639
|
-
};
|
|
1640
|
-
}, [safe, onReady, contentRef]);
|
|
1624
|
+
if (contentRefStable.current) contentRefStable.current.current = root;
|
|
1625
|
+
if (prevSafe.current === safe) return;
|
|
1626
|
+
prevSafe.current = safe;
|
|
1627
|
+
root.innerHTML = safe;
|
|
1628
|
+
enhanceCodeBlocks(root);
|
|
1629
|
+
enhanceBlockquotes(root);
|
|
1630
|
+
const nextChips = enhanceCallouts(root, calloutIconsRef.current);
|
|
1631
|
+
if (!calloutChipsEqual(chipsRef.current, nextChips)) {
|
|
1632
|
+
chipsRef.current = nextChips;
|
|
1633
|
+
if (nextChips.length > 0) setRenderKey((n) => n + 1);
|
|
1634
|
+
}
|
|
1635
|
+
onReadyRef.current?.(root);
|
|
1636
|
+
}, [safe]);
|
|
1641
1637
|
return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
|
|
1642
1638
|
react.createElement(as, {
|
|
1643
1639
|
ref,
|
|
1644
|
-
className
|
|
1645
|
-
dangerouslySetInnerHTML: { __html: safe }
|
|
1640
|
+
className
|
|
1646
1641
|
}),
|
|
1647
|
-
|
|
1642
|
+
chipsRef.current.map(
|
|
1648
1643
|
(chip, i) => reactDom.createPortal(
|
|
1649
|
-
|
|
1644
|
+
calloutIconsRef.current && chip.variant in calloutIconsRef.current ? calloutIconsRef.current[chip.variant] : /* @__PURE__ */ jsxRuntime.jsx(BuiltinCalloutIcon, { variant: chip.variant }),
|
|
1650
1645
|
chip.el,
|
|
1651
1646
|
`${chip.variant}:${i}`
|
|
1652
1647
|
)
|
|
1653
1648
|
)
|
|
1654
1649
|
] });
|
|
1650
|
+
}, richTextPropsEqual);
|
|
1651
|
+
function richTextPropsEqual(prev, next) {
|
|
1652
|
+
if (prev.html !== next.html) return false;
|
|
1653
|
+
if (prev.classMap !== next.classMap) return false;
|
|
1654
|
+
if (prev.as !== next.as) return false;
|
|
1655
|
+
if (prev.className !== next.className) return false;
|
|
1656
|
+
const prevKeys = prev.calloutIcons ? Object.keys(prev.calloutIcons) : [];
|
|
1657
|
+
const nextKeys = next.calloutIcons ? Object.keys(next.calloutIcons) : [];
|
|
1658
|
+
if (prevKeys.length !== nextKeys.length) return false;
|
|
1659
|
+
for (const k of nextKeys) {
|
|
1660
|
+
if (!prevKeys.includes(k)) return false;
|
|
1661
|
+
}
|
|
1662
|
+
return true;
|
|
1655
1663
|
}
|
|
1656
1664
|
|
|
1657
1665
|
// src/utils/extractHeadings.ts
|