@nuucognition/ncm-ui 0.1.0-dev.1 → 0.1.1-beta.0
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/README.md +90 -0
- package/dist/blocks/admonition/index.d.ts +2 -3
- package/dist/blocks/admonition/index.js +63 -12
- package/dist/blocks/aside/index.d.ts +2 -3
- package/dist/blocks/aside/index.js +63 -12
- package/dist/blocks/attribution/index.d.ts +2 -3
- package/dist/blocks/blockquote/index.d.ts +5 -4
- package/dist/blocks/blockquote/index.js +52 -7
- package/dist/blocks/chart/index.d.ts +2 -3
- package/dist/blocks/code/index.d.ts +2 -3
- package/dist/blocks/code/index.js +2 -2
- package/dist/blocks/container/index.d.ts +2 -3
- package/dist/blocks/container/index.js +50 -5
- package/dist/blocks/custom-code/index.d.ts +2 -3
- package/dist/blocks/dataview/index.d.ts +2 -3
- package/dist/blocks/definition/index.d.ts +2 -3
- package/dist/blocks/definition/index.js +63 -12
- package/dist/blocks/embed/index.d.ts +2 -3
- package/dist/blocks/embedding/index.d.ts +2 -3
- package/dist/blocks/embedding/index.js +50 -5
- package/dist/blocks/figure/index.d.ts +2 -3
- package/dist/blocks/figure/index.js +50 -5
- package/dist/blocks/footnote/index.d.ts +2 -3
- package/dist/blocks/footnote/index.js +63 -12
- package/dist/blocks/frontmatter/index.d.ts +2 -3
- package/dist/blocks/header/index.d.ts +2 -3
- package/dist/blocks/header/index.js +50 -5
- package/dist/blocks/horizontal-rule/index.d.ts +2 -3
- package/dist/blocks/html/index.d.ts +3 -4
- package/dist/blocks/index.d.ts +1 -2
- package/dist/blocks/index.js +63 -12
- package/dist/blocks/latex/index.d.ts +2 -3
- package/dist/blocks/link/index.d.ts +2 -3
- package/dist/blocks/list/index.d.ts +2 -3
- package/dist/blocks/list/index.js +57 -7
- package/dist/blocks/math/index.d.ts +2 -3
- package/dist/blocks/mermaid/index.d.ts +2 -3
- package/dist/blocks/page-breaker/index.d.ts +2 -3
- package/dist/blocks/paragraph/index.d.ts +2 -3
- package/dist/blocks/paragraph/index.js +50 -5
- package/dist/blocks/spoiler/index.d.ts +2 -3
- package/dist/blocks/spoiler/index.js +63 -12
- package/dist/blocks/table/index.d.ts +2 -3
- package/dist/blocks/table/index.js +50 -5
- package/dist/blocks/task-list/index.d.ts +2 -3
- package/dist/blocks/task-list/index.js +52 -6
- package/dist/components/index.d.ts +34 -4
- package/dist/components/index.js +101 -14
- package/dist/components/ncm-block.d.ts +2 -3
- package/dist/components/ncm-block.js +63 -12
- package/dist/components/ncm-document.d.ts +4 -4
- package/dist/components/ncm-document.js +63 -12
- package/dist/context/index.d.ts +2 -3
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +63 -12
- package/dist/hooks/use-block-renderer.js +63 -12
- package/dist/hooks/use-ncm-config.d.ts +1 -2
- package/dist/index.d.ts +3 -4
- package/dist/index.js +102 -15
- package/dist/inline/index.d.ts +4 -4
- package/dist/inline/index.js +51 -6
- package/dist/lib/defaults.js +63 -12
- package/dist/{references-Bs5wJybr.d.ts → references-BYW5pnj_.d.ts} +4 -4
- package/dist/styles/nuu.css +304 -42
- package/dist/styles/paper.css +62 -1
- package/dist/{use-ncm-config-D0doMYTH.d.ts → use-ncm-config-CnntcShj.d.ts} +55 -4
- package/package.json +5 -4
|
@@ -646,9 +646,10 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
646
646
|
case "image": {
|
|
647
647
|
const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
|
|
648
648
|
return /* @__PURE__ */ jsx(
|
|
649
|
-
|
|
649
|
+
EmbedImage,
|
|
650
650
|
{
|
|
651
|
-
"data-ncm-token": "image",
|
|
651
|
+
attrs: { "data-ncm-token": "image" },
|
|
652
|
+
target: token.src,
|
|
652
653
|
src,
|
|
653
654
|
alt: token.alt,
|
|
654
655
|
title: token.title
|
|
@@ -682,10 +683,13 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
682
683
|
}
|
|
683
684
|
if (embedType === "image") {
|
|
684
685
|
return /* @__PURE__ */ jsx(
|
|
685
|
-
|
|
686
|
+
EmbedImage,
|
|
686
687
|
{
|
|
687
|
-
|
|
688
|
-
|
|
688
|
+
attrs: {
|
|
689
|
+
"data-ncm-token": "wiki_embed",
|
|
690
|
+
"data-ncm-wikiembed-type": embedType
|
|
691
|
+
},
|
|
692
|
+
target: token.target,
|
|
689
693
|
src: url,
|
|
690
694
|
alt: token.display ?? token.target,
|
|
691
695
|
className: config.embeddings?.imageClassName
|
|
@@ -716,6 +720,22 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
716
720
|
}
|
|
717
721
|
);
|
|
718
722
|
}
|
|
723
|
+
const onEmbedClick = config.embeddings?.onEmbedClick;
|
|
724
|
+
if (onEmbedClick) {
|
|
725
|
+
const handleClick = (e) => {
|
|
726
|
+
onEmbedClick(token.target, result, e);
|
|
727
|
+
};
|
|
728
|
+
return /* @__PURE__ */ jsx(
|
|
729
|
+
"button",
|
|
730
|
+
{
|
|
731
|
+
type: "button",
|
|
732
|
+
"data-ncm-token": "wiki_embed",
|
|
733
|
+
"data-ncm-wikiembed-type": embedType,
|
|
734
|
+
onClick: handleClick,
|
|
735
|
+
children: token.display ?? token.target
|
|
736
|
+
}
|
|
737
|
+
);
|
|
738
|
+
}
|
|
719
739
|
return /* @__PURE__ */ jsx(
|
|
720
740
|
"a",
|
|
721
741
|
{
|
|
@@ -734,6 +754,31 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
734
754
|
return null;
|
|
735
755
|
}
|
|
736
756
|
}
|
|
757
|
+
function EmbedImage({ attrs, target, src, alt, title, className }) {
|
|
758
|
+
const config = useNcmConfig();
|
|
759
|
+
const Fallback = config.embeddings?.renderImageError;
|
|
760
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
761
|
+
useEffect(() => {
|
|
762
|
+
setFailedSrc(null);
|
|
763
|
+
}, [src]);
|
|
764
|
+
if (!Fallback) {
|
|
765
|
+
return /* @__PURE__ */ jsx("img", { ...attrs, src, alt, title, className });
|
|
766
|
+
}
|
|
767
|
+
if (failedSrc === src) {
|
|
768
|
+
return /* @__PURE__ */ jsx(Fallback, { target, src, alt, retry: () => setFailedSrc(null) });
|
|
769
|
+
}
|
|
770
|
+
return /* @__PURE__ */ jsx(
|
|
771
|
+
"img",
|
|
772
|
+
{
|
|
773
|
+
...attrs,
|
|
774
|
+
src,
|
|
775
|
+
alt,
|
|
776
|
+
title,
|
|
777
|
+
className,
|
|
778
|
+
onError: () => setFailedSrc(src)
|
|
779
|
+
}
|
|
780
|
+
);
|
|
781
|
+
}
|
|
737
782
|
function renderReadingText(content, opts) {
|
|
738
783
|
if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
739
784
|
const { bionic = false, beeline = false } = opts;
|
|
@@ -769,7 +814,7 @@ function renderReadingText(content, opts) {
|
|
|
769
814
|
return /* @__PURE__ */ jsx(Fragment, { children: pieces });
|
|
770
815
|
}
|
|
771
816
|
function BlockquoteBlock({ block, className }) {
|
|
772
|
-
const lines = block.content.split("\n")
|
|
817
|
+
const lines = block.content.split("\n");
|
|
773
818
|
return /* @__PURE__ */ jsx(
|
|
774
819
|
"blockquote",
|
|
775
820
|
{
|
|
@@ -779,7 +824,7 @@ function BlockquoteBlock({ block, className }) {
|
|
|
779
824
|
"data-block-id": block.id,
|
|
780
825
|
"data-ncm-blockquote": "",
|
|
781
826
|
className,
|
|
782
|
-
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(InlineContent, { content: line }) }, index))
|
|
827
|
+
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index))
|
|
783
828
|
}
|
|
784
829
|
);
|
|
785
830
|
}
|
|
@@ -919,7 +964,7 @@ function CodeBlock({ block, className }) {
|
|
|
919
964
|
"data-ncm-language": block.language,
|
|
920
965
|
className: cn("relative", className),
|
|
921
966
|
children: [
|
|
922
|
-
codeConfig.copyButton
|
|
967
|
+
codeConfig.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
923
968
|
/* @__PURE__ */ jsx(CustomRenderer, { code: block.content, language: block.language }),
|
|
924
969
|
languageLabel
|
|
925
970
|
]
|
|
@@ -938,7 +983,7 @@ function CodeBlock({ block, className }) {
|
|
|
938
983
|
"data-ncm-language": block.language,
|
|
939
984
|
className: cn("relative", className),
|
|
940
985
|
children: [
|
|
941
|
-
codeConfig?.copyButton
|
|
986
|
+
codeConfig?.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
942
987
|
/* @__PURE__ */ jsx("pre", { "data-ncm-code-pre": "", children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
|
|
943
988
|
codeConfig?.lineNumbers && /* @__PURE__ */ jsx(LineNumbers, { count: lineCount }),
|
|
944
989
|
/* @__PURE__ */ jsx("code", { "data-ncm-code": "", className: "flex-1", children: /* @__PURE__ */ jsx(DefaultShikiRenderer, { code: block.content, language: block.language }) })
|
|
@@ -1390,10 +1435,12 @@ function LinkBlock({ block, className }) {
|
|
|
1390
1435
|
function ListBlock({ block, className }) {
|
|
1391
1436
|
const isOrdered = block.type === "list_ordered";
|
|
1392
1437
|
const Tag = isOrdered ? "ol" : "ul";
|
|
1438
|
+
const start = isOrdered && typeof block.marker === "number" && block.marker !== 1 ? block.marker : void 0;
|
|
1393
1439
|
return /* @__PURE__ */ jsx(
|
|
1394
1440
|
Tag,
|
|
1395
1441
|
{
|
|
1396
1442
|
role: "list",
|
|
1443
|
+
start,
|
|
1397
1444
|
"data-ncm-block": block.id,
|
|
1398
1445
|
"data-ncm-stable": block.stableId,
|
|
1399
1446
|
"data-ncm-type": block.type,
|
|
@@ -1405,6 +1452,9 @@ function ListBlock({ block, className }) {
|
|
|
1405
1452
|
}
|
|
1406
1453
|
);
|
|
1407
1454
|
}
|
|
1455
|
+
function ItemContent({ content }) {
|
|
1456
|
+
return content.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" });
|
|
1457
|
+
}
|
|
1408
1458
|
function nestedItemIdKey(id) {
|
|
1409
1459
|
if (!id) {
|
|
1410
1460
|
return void 0;
|
|
@@ -1421,7 +1471,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1421
1471
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
|
|
1422
1472
|
const key = nestedItemIdKey(itemIds?.[index]) ?? `item-${index}`;
|
|
1423
1473
|
if (typeof item === "string") {
|
|
1424
|
-
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(
|
|
1474
|
+
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(ItemContent, { content: item }) }, key);
|
|
1425
1475
|
}
|
|
1426
1476
|
if (isTypedNestedList(item)) {
|
|
1427
1477
|
return /* @__PURE__ */ jsx(NestedTypedList, { list: item }, key);
|
|
@@ -1431,7 +1481,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1431
1481
|
const content = typeof first === "string" ? first : "";
|
|
1432
1482
|
const nestedContent = processNestedItems(rest, ordered);
|
|
1433
1483
|
return /* @__PURE__ */ jsxs("li", { "data-ncm-list-item": "", children: [
|
|
1434
|
-
/* @__PURE__ */ jsx(
|
|
1484
|
+
/* @__PURE__ */ jsx(ItemContent, { content }),
|
|
1435
1485
|
nestedContent
|
|
1436
1486
|
] }, key);
|
|
1437
1487
|
}
|
|
@@ -1590,6 +1640,7 @@ function TableBlock({ block, className }) {
|
|
|
1590
1640
|
function TaskItems({ items }) {
|
|
1591
1641
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item) => {
|
|
1592
1642
|
const status = item.checked ? "Completed" : "Incomplete";
|
|
1643
|
+
const text = serializeInlineContent(item.content);
|
|
1593
1644
|
return /* @__PURE__ */ jsxs(
|
|
1594
1645
|
"li",
|
|
1595
1646
|
{
|
|
@@ -1616,7 +1667,7 @@ function TaskItems({ items }) {
|
|
|
1616
1667
|
":",
|
|
1617
1668
|
" "
|
|
1618
1669
|
] }),
|
|
1619
|
-
/* @__PURE__ */ jsx(InlineContent, { content:
|
|
1670
|
+
text.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: text }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" })
|
|
1620
1671
|
] })
|
|
1621
1672
|
] }),
|
|
1622
1673
|
item.children ? /* @__PURE__ */ jsx("ul", { role: "list", "data-ncm-list-nested": "", className: "ml-6 list-none", children: /* @__PURE__ */ jsx(TaskItems, { items: item.children.items }) }) : null
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { C as CodeConfig, E as EmbeddingsConfig, I as InlineConfig, N as NcmConfig,
|
|
2
|
-
export { B as BlockReferenceScope, a as BlockReferenceScopeProps, b as BlockReferenceScopeValue, I as InertReferenceScope, N as NcmReferencesProvider, c as NcmReferencesProviderProps, R as ReferenceCounts, d as ReferenceKind, e as computeReferenceBases, u as useBlockReferenceScope } from '../references-
|
|
3
|
-
import 'react/jsx-runtime';
|
|
1
|
+
export { C as CodeConfig, E as EmbeddingsConfig, I as ImageErrorProps, a as InlineConfig, N as NcmConfig, b as NcmProvider, c as NcmProviderProps, u as useNcmConfig } from '../use-ncm-config-CnntcShj.js';
|
|
2
|
+
export { B as BlockReferenceScope, a as BlockReferenceScopeProps, b as BlockReferenceScopeValue, I as InertReferenceScope, N as NcmReferencesProvider, c as NcmReferencesProviderProps, R as ReferenceCounts, d as ReferenceKind, e as computeReferenceBases, u as useBlockReferenceScope } from '../references-BYW5pnj_.js';
|
|
4
3
|
import 'react';
|
|
5
4
|
import '@nuucognition/mesh-core';
|
|
6
5
|
import '@nuucognition/ncm';
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export { u as useNcmConfig } from '../use-ncm-config-
|
|
1
|
+
export { u as useNcmConfig } from '../use-ncm-config-CnntcShj.js';
|
|
2
2
|
export { useBlockRenderer, useCustomCodeRenderer } from './use-block-renderer.js';
|
|
3
|
-
import 'react/jsx-runtime';
|
|
4
3
|
import 'react';
|
|
5
4
|
import '@nuucognition/mesh-core';
|
|
6
5
|
import '@nuucognition/ncm';
|
package/dist/hooks/index.js
CHANGED
|
@@ -650,9 +650,10 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
650
650
|
case "image": {
|
|
651
651
|
const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
|
|
652
652
|
return /* @__PURE__ */ jsx(
|
|
653
|
-
|
|
653
|
+
EmbedImage,
|
|
654
654
|
{
|
|
655
|
-
"data-ncm-token": "image",
|
|
655
|
+
attrs: { "data-ncm-token": "image" },
|
|
656
|
+
target: token.src,
|
|
656
657
|
src,
|
|
657
658
|
alt: token.alt,
|
|
658
659
|
title: token.title
|
|
@@ -686,10 +687,13 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
686
687
|
}
|
|
687
688
|
if (embedType === "image") {
|
|
688
689
|
return /* @__PURE__ */ jsx(
|
|
689
|
-
|
|
690
|
+
EmbedImage,
|
|
690
691
|
{
|
|
691
|
-
|
|
692
|
-
|
|
692
|
+
attrs: {
|
|
693
|
+
"data-ncm-token": "wiki_embed",
|
|
694
|
+
"data-ncm-wikiembed-type": embedType
|
|
695
|
+
},
|
|
696
|
+
target: token.target,
|
|
693
697
|
src: url,
|
|
694
698
|
alt: token.display ?? token.target,
|
|
695
699
|
className: config.embeddings?.imageClassName
|
|
@@ -720,6 +724,22 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
720
724
|
}
|
|
721
725
|
);
|
|
722
726
|
}
|
|
727
|
+
const onEmbedClick = config.embeddings?.onEmbedClick;
|
|
728
|
+
if (onEmbedClick) {
|
|
729
|
+
const handleClick = (e) => {
|
|
730
|
+
onEmbedClick(token.target, result, e);
|
|
731
|
+
};
|
|
732
|
+
return /* @__PURE__ */ jsx(
|
|
733
|
+
"button",
|
|
734
|
+
{
|
|
735
|
+
type: "button",
|
|
736
|
+
"data-ncm-token": "wiki_embed",
|
|
737
|
+
"data-ncm-wikiembed-type": embedType,
|
|
738
|
+
onClick: handleClick,
|
|
739
|
+
children: token.display ?? token.target
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
723
743
|
return /* @__PURE__ */ jsx(
|
|
724
744
|
"a",
|
|
725
745
|
{
|
|
@@ -738,6 +758,31 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
738
758
|
return null;
|
|
739
759
|
}
|
|
740
760
|
}
|
|
761
|
+
function EmbedImage({ attrs, target, src, alt, title, className }) {
|
|
762
|
+
const config = useNcmConfig();
|
|
763
|
+
const Fallback = config.embeddings?.renderImageError;
|
|
764
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
765
|
+
useEffect(() => {
|
|
766
|
+
setFailedSrc(null);
|
|
767
|
+
}, [src]);
|
|
768
|
+
if (!Fallback) {
|
|
769
|
+
return /* @__PURE__ */ jsx("img", { ...attrs, src, alt, title, className });
|
|
770
|
+
}
|
|
771
|
+
if (failedSrc === src) {
|
|
772
|
+
return /* @__PURE__ */ jsx(Fallback, { target, src, alt, retry: () => setFailedSrc(null) });
|
|
773
|
+
}
|
|
774
|
+
return /* @__PURE__ */ jsx(
|
|
775
|
+
"img",
|
|
776
|
+
{
|
|
777
|
+
...attrs,
|
|
778
|
+
src,
|
|
779
|
+
alt,
|
|
780
|
+
title,
|
|
781
|
+
className,
|
|
782
|
+
onError: () => setFailedSrc(src)
|
|
783
|
+
}
|
|
784
|
+
);
|
|
785
|
+
}
|
|
741
786
|
function renderReadingText(content, opts) {
|
|
742
787
|
if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
743
788
|
const { bionic = false, beeline = false } = opts;
|
|
@@ -773,7 +818,7 @@ function renderReadingText(content, opts) {
|
|
|
773
818
|
return /* @__PURE__ */ jsx(Fragment, { children: pieces });
|
|
774
819
|
}
|
|
775
820
|
function BlockquoteBlock({ block, className }) {
|
|
776
|
-
const lines = block.content.split("\n")
|
|
821
|
+
const lines = block.content.split("\n");
|
|
777
822
|
return /* @__PURE__ */ jsx(
|
|
778
823
|
"blockquote",
|
|
779
824
|
{
|
|
@@ -783,7 +828,7 @@ function BlockquoteBlock({ block, className }) {
|
|
|
783
828
|
"data-block-id": block.id,
|
|
784
829
|
"data-ncm-blockquote": "",
|
|
785
830
|
className,
|
|
786
|
-
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(InlineContent, { content: line }) }, index))
|
|
831
|
+
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index))
|
|
787
832
|
}
|
|
788
833
|
);
|
|
789
834
|
}
|
|
@@ -923,7 +968,7 @@ function CodeBlock({ block, className }) {
|
|
|
923
968
|
"data-ncm-language": block.language,
|
|
924
969
|
className: cn("relative", className),
|
|
925
970
|
children: [
|
|
926
|
-
codeConfig.copyButton
|
|
971
|
+
codeConfig.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
927
972
|
/* @__PURE__ */ jsx(CustomRenderer, { code: block.content, language: block.language }),
|
|
928
973
|
languageLabel
|
|
929
974
|
]
|
|
@@ -942,7 +987,7 @@ function CodeBlock({ block, className }) {
|
|
|
942
987
|
"data-ncm-language": block.language,
|
|
943
988
|
className: cn("relative", className),
|
|
944
989
|
children: [
|
|
945
|
-
codeConfig?.copyButton
|
|
990
|
+
codeConfig?.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
946
991
|
/* @__PURE__ */ jsx("pre", { "data-ncm-code-pre": "", children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
|
|
947
992
|
codeConfig?.lineNumbers && /* @__PURE__ */ jsx(LineNumbers, { count: lineCount }),
|
|
948
993
|
/* @__PURE__ */ jsx("code", { "data-ncm-code": "", className: "flex-1", children: /* @__PURE__ */ jsx(DefaultShikiRenderer, { code: block.content, language: block.language }) })
|
|
@@ -1394,10 +1439,12 @@ function LinkBlock({ block, className }) {
|
|
|
1394
1439
|
function ListBlock({ block, className }) {
|
|
1395
1440
|
const isOrdered = block.type === "list_ordered";
|
|
1396
1441
|
const Tag = isOrdered ? "ol" : "ul";
|
|
1442
|
+
const start = isOrdered && typeof block.marker === "number" && block.marker !== 1 ? block.marker : void 0;
|
|
1397
1443
|
return /* @__PURE__ */ jsx(
|
|
1398
1444
|
Tag,
|
|
1399
1445
|
{
|
|
1400
1446
|
role: "list",
|
|
1447
|
+
start,
|
|
1401
1448
|
"data-ncm-block": block.id,
|
|
1402
1449
|
"data-ncm-stable": block.stableId,
|
|
1403
1450
|
"data-ncm-type": block.type,
|
|
@@ -1409,6 +1456,9 @@ function ListBlock({ block, className }) {
|
|
|
1409
1456
|
}
|
|
1410
1457
|
);
|
|
1411
1458
|
}
|
|
1459
|
+
function ItemContent({ content }) {
|
|
1460
|
+
return content.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" });
|
|
1461
|
+
}
|
|
1412
1462
|
function nestedItemIdKey(id) {
|
|
1413
1463
|
if (!id) {
|
|
1414
1464
|
return void 0;
|
|
@@ -1425,7 +1475,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1425
1475
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
|
|
1426
1476
|
const key = nestedItemIdKey(itemIds?.[index]) ?? `item-${index}`;
|
|
1427
1477
|
if (typeof item === "string") {
|
|
1428
|
-
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(
|
|
1478
|
+
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(ItemContent, { content: item }) }, key);
|
|
1429
1479
|
}
|
|
1430
1480
|
if (isTypedNestedList(item)) {
|
|
1431
1481
|
return /* @__PURE__ */ jsx(NestedTypedList, { list: item }, key);
|
|
@@ -1435,7 +1485,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1435
1485
|
const content = typeof first === "string" ? first : "";
|
|
1436
1486
|
const nestedContent = processNestedItems(rest, ordered);
|
|
1437
1487
|
return /* @__PURE__ */ jsxs("li", { "data-ncm-list-item": "", children: [
|
|
1438
|
-
/* @__PURE__ */ jsx(
|
|
1488
|
+
/* @__PURE__ */ jsx(ItemContent, { content }),
|
|
1439
1489
|
nestedContent
|
|
1440
1490
|
] }, key);
|
|
1441
1491
|
}
|
|
@@ -1594,6 +1644,7 @@ function TableBlock({ block, className }) {
|
|
|
1594
1644
|
function TaskItems({ items }) {
|
|
1595
1645
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item) => {
|
|
1596
1646
|
const status = item.checked ? "Completed" : "Incomplete";
|
|
1647
|
+
const text = serializeInlineContent(item.content);
|
|
1597
1648
|
return /* @__PURE__ */ jsxs(
|
|
1598
1649
|
"li",
|
|
1599
1650
|
{
|
|
@@ -1620,7 +1671,7 @@ function TaskItems({ items }) {
|
|
|
1620
1671
|
":",
|
|
1621
1672
|
" "
|
|
1622
1673
|
] }),
|
|
1623
|
-
/* @__PURE__ */ jsx(InlineContent, { content:
|
|
1674
|
+
text.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: text }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" })
|
|
1624
1675
|
] })
|
|
1625
1676
|
] }),
|
|
1626
1677
|
item.children ? /* @__PURE__ */ jsx("ul", { role: "list", "data-ncm-list-nested": "", className: "ml-6 list-none", children: /* @__PURE__ */ jsx(TaskItems, { items: item.children.items }) }) : null
|
|
@@ -650,9 +650,10 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
650
650
|
case "image": {
|
|
651
651
|
const src = config.inline?.resolveAssetPath?.(token.src) ?? token.src;
|
|
652
652
|
return /* @__PURE__ */ jsx(
|
|
653
|
-
|
|
653
|
+
EmbedImage,
|
|
654
654
|
{
|
|
655
|
-
"data-ncm-token": "image",
|
|
655
|
+
attrs: { "data-ncm-token": "image" },
|
|
656
|
+
target: token.src,
|
|
656
657
|
src,
|
|
657
658
|
alt: token.alt,
|
|
658
659
|
title: token.title
|
|
@@ -686,10 +687,13 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
686
687
|
}
|
|
687
688
|
if (embedType === "image") {
|
|
688
689
|
return /* @__PURE__ */ jsx(
|
|
689
|
-
|
|
690
|
+
EmbedImage,
|
|
690
691
|
{
|
|
691
|
-
|
|
692
|
-
|
|
692
|
+
attrs: {
|
|
693
|
+
"data-ncm-token": "wiki_embed",
|
|
694
|
+
"data-ncm-wikiembed-type": embedType
|
|
695
|
+
},
|
|
696
|
+
target: token.target,
|
|
693
697
|
src: url,
|
|
694
698
|
alt: token.display ?? token.target,
|
|
695
699
|
className: config.embeddings?.imageClassName
|
|
@@ -720,6 +724,22 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
720
724
|
}
|
|
721
725
|
);
|
|
722
726
|
}
|
|
727
|
+
const onEmbedClick = config.embeddings?.onEmbedClick;
|
|
728
|
+
if (onEmbedClick) {
|
|
729
|
+
const handleClick = (e) => {
|
|
730
|
+
onEmbedClick(token.target, result, e);
|
|
731
|
+
};
|
|
732
|
+
return /* @__PURE__ */ jsx(
|
|
733
|
+
"button",
|
|
734
|
+
{
|
|
735
|
+
type: "button",
|
|
736
|
+
"data-ncm-token": "wiki_embed",
|
|
737
|
+
"data-ncm-wikiembed-type": embedType,
|
|
738
|
+
onClick: handleClick,
|
|
739
|
+
children: token.display ?? token.target
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
723
743
|
return /* @__PURE__ */ jsx(
|
|
724
744
|
"a",
|
|
725
745
|
{
|
|
@@ -738,6 +758,31 @@ function TokenRenderer({ token, disableBionic, disableBeeline }) {
|
|
|
738
758
|
return null;
|
|
739
759
|
}
|
|
740
760
|
}
|
|
761
|
+
function EmbedImage({ attrs, target, src, alt, title, className }) {
|
|
762
|
+
const config = useNcmConfig();
|
|
763
|
+
const Fallback = config.embeddings?.renderImageError;
|
|
764
|
+
const [failedSrc, setFailedSrc] = useState(null);
|
|
765
|
+
useEffect(() => {
|
|
766
|
+
setFailedSrc(null);
|
|
767
|
+
}, [src]);
|
|
768
|
+
if (!Fallback) {
|
|
769
|
+
return /* @__PURE__ */ jsx("img", { ...attrs, src, alt, title, className });
|
|
770
|
+
}
|
|
771
|
+
if (failedSrc === src) {
|
|
772
|
+
return /* @__PURE__ */ jsx(Fallback, { target, src, alt, retry: () => setFailedSrc(null) });
|
|
773
|
+
}
|
|
774
|
+
return /* @__PURE__ */ jsx(
|
|
775
|
+
"img",
|
|
776
|
+
{
|
|
777
|
+
...attrs,
|
|
778
|
+
src,
|
|
779
|
+
alt,
|
|
780
|
+
title,
|
|
781
|
+
className,
|
|
782
|
+
onError: () => setFailedSrc(src)
|
|
783
|
+
}
|
|
784
|
+
);
|
|
785
|
+
}
|
|
741
786
|
function renderReadingText(content, opts) {
|
|
742
787
|
if (!content) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
743
788
|
const { bionic = false, beeline = false } = opts;
|
|
@@ -773,7 +818,7 @@ function renderReadingText(content, opts) {
|
|
|
773
818
|
return /* @__PURE__ */ jsx(Fragment, { children: pieces });
|
|
774
819
|
}
|
|
775
820
|
function BlockquoteBlock({ block, className }) {
|
|
776
|
-
const lines = block.content.split("\n")
|
|
821
|
+
const lines = block.content.split("\n");
|
|
777
822
|
return /* @__PURE__ */ jsx(
|
|
778
823
|
"blockquote",
|
|
779
824
|
{
|
|
@@ -783,7 +828,7 @@ function BlockquoteBlock({ block, className }) {
|
|
|
783
828
|
"data-block-id": block.id,
|
|
784
829
|
"data-ncm-blockquote": "",
|
|
785
830
|
className,
|
|
786
|
-
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsx(InlineContent, { content: line }) }, index))
|
|
831
|
+
children: lines.length <= 1 ? /* @__PURE__ */ jsx(InlineContent, { content: block.content }) : lines.map((line, index) => /* @__PURE__ */ jsx("p", { children: line.trim().length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: line }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" }) }, index))
|
|
787
832
|
}
|
|
788
833
|
);
|
|
789
834
|
}
|
|
@@ -923,7 +968,7 @@ function CodeBlock({ block, className }) {
|
|
|
923
968
|
"data-ncm-language": block.language,
|
|
924
969
|
className: cn("relative", className),
|
|
925
970
|
children: [
|
|
926
|
-
codeConfig.copyButton
|
|
971
|
+
codeConfig.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
927
972
|
/* @__PURE__ */ jsx(CustomRenderer, { code: block.content, language: block.language }),
|
|
928
973
|
languageLabel
|
|
929
974
|
]
|
|
@@ -942,7 +987,7 @@ function CodeBlock({ block, className }) {
|
|
|
942
987
|
"data-ncm-language": block.language,
|
|
943
988
|
className: cn("relative", className),
|
|
944
989
|
children: [
|
|
945
|
-
codeConfig?.copyButton
|
|
990
|
+
codeConfig?.copyButton === true && /* @__PURE__ */ jsx(CopyButton, { content: block.content }),
|
|
946
991
|
/* @__PURE__ */ jsx("pre", { "data-ncm-code-pre": "", children: /* @__PURE__ */ jsxs("div", { className: "flex", children: [
|
|
947
992
|
codeConfig?.lineNumbers && /* @__PURE__ */ jsx(LineNumbers, { count: lineCount }),
|
|
948
993
|
/* @__PURE__ */ jsx("code", { "data-ncm-code": "", className: "flex-1", children: /* @__PURE__ */ jsx(DefaultShikiRenderer, { code: block.content, language: block.language }) })
|
|
@@ -1394,10 +1439,12 @@ function LinkBlock({ block, className }) {
|
|
|
1394
1439
|
function ListBlock({ block, className }) {
|
|
1395
1440
|
const isOrdered = block.type === "list_ordered";
|
|
1396
1441
|
const Tag = isOrdered ? "ol" : "ul";
|
|
1442
|
+
const start = isOrdered && typeof block.marker === "number" && block.marker !== 1 ? block.marker : void 0;
|
|
1397
1443
|
return /* @__PURE__ */ jsx(
|
|
1398
1444
|
Tag,
|
|
1399
1445
|
{
|
|
1400
1446
|
role: "list",
|
|
1447
|
+
start,
|
|
1401
1448
|
"data-ncm-block": block.id,
|
|
1402
1449
|
"data-ncm-stable": block.stableId,
|
|
1403
1450
|
"data-ncm-type": block.type,
|
|
@@ -1409,6 +1456,9 @@ function ListBlock({ block, className }) {
|
|
|
1409
1456
|
}
|
|
1410
1457
|
);
|
|
1411
1458
|
}
|
|
1459
|
+
function ItemContent({ content }) {
|
|
1460
|
+
return content.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" });
|
|
1461
|
+
}
|
|
1412
1462
|
function nestedItemIdKey(id) {
|
|
1413
1463
|
if (!id) {
|
|
1414
1464
|
return void 0;
|
|
@@ -1425,7 +1475,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1425
1475
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
|
|
1426
1476
|
const key = nestedItemIdKey(itemIds?.[index]) ?? `item-${index}`;
|
|
1427
1477
|
if (typeof item === "string") {
|
|
1428
|
-
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(
|
|
1478
|
+
return /* @__PURE__ */ jsx("li", { "data-ncm-list-item": "", children: /* @__PURE__ */ jsx(ItemContent, { content: item }) }, key);
|
|
1429
1479
|
}
|
|
1430
1480
|
if (isTypedNestedList(item)) {
|
|
1431
1481
|
return /* @__PURE__ */ jsx(NestedTypedList, { list: item }, key);
|
|
@@ -1435,7 +1485,7 @@ function ListItems({ items, itemIds, ordered }) {
|
|
|
1435
1485
|
const content = typeof first === "string" ? first : "";
|
|
1436
1486
|
const nestedContent = processNestedItems(rest, ordered);
|
|
1437
1487
|
return /* @__PURE__ */ jsxs("li", { "data-ncm-list-item": "", children: [
|
|
1438
|
-
/* @__PURE__ */ jsx(
|
|
1488
|
+
/* @__PURE__ */ jsx(ItemContent, { content }),
|
|
1439
1489
|
nestedContent
|
|
1440
1490
|
] }, key);
|
|
1441
1491
|
}
|
|
@@ -1594,6 +1644,7 @@ function TableBlock({ block, className }) {
|
|
|
1594
1644
|
function TaskItems({ items }) {
|
|
1595
1645
|
return /* @__PURE__ */ jsx(Fragment, { children: items.map((item) => {
|
|
1596
1646
|
const status = item.checked ? "Completed" : "Incomplete";
|
|
1647
|
+
const text = serializeInlineContent(item.content);
|
|
1597
1648
|
return /* @__PURE__ */ jsxs(
|
|
1598
1649
|
"li",
|
|
1599
1650
|
{
|
|
@@ -1620,7 +1671,7 @@ function TaskItems({ items }) {
|
|
|
1620
1671
|
":",
|
|
1621
1672
|
" "
|
|
1622
1673
|
] }),
|
|
1623
|
-
/* @__PURE__ */ jsx(InlineContent, { content:
|
|
1674
|
+
text.length > 0 ? /* @__PURE__ */ jsx(InlineContent, { content: text }) : /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xA0" })
|
|
1624
1675
|
] })
|
|
1625
1676
|
] }),
|
|
1626
1677
|
item.children ? /* @__PURE__ */ jsx("ul", { role: "list", "data-ncm-list-nested": "", className: "ml-6 list-none", children: /* @__PURE__ */ jsx(TaskItems, { items: item.children.items }) }) : null
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { C as CodeConfig, E as EmbeddingsConfig, I as InlineConfig, N as NcmConfig,
|
|
2
|
-
export { B as BlockReferenceScope, a as BlockReferenceScopeProps, b as BlockReferenceScopeValue, I as InertReferenceScope, N as NcmReferencesProvider, c as NcmReferencesProviderProps, R as ReferenceCounts, d as ReferenceKind, e as computeReferenceBases, u as useBlockReferenceScope } from './references-
|
|
1
|
+
export { C as CodeConfig, E as EmbeddingsConfig, I as ImageErrorProps, a as InlineConfig, N as NcmConfig, b as NcmProvider, c as NcmProviderProps, u as useNcmConfig } from './use-ncm-config-CnntcShj.js';
|
|
2
|
+
export { B as BlockReferenceScope, a as BlockReferenceScopeProps, b as BlockReferenceScopeValue, I as InertReferenceScope, N as NcmReferencesProvider, c as NcmReferencesProviderProps, R as ReferenceCounts, d as ReferenceKind, e as computeReferenceBases, u as useBlockReferenceScope } from './references-BYW5pnj_.js';
|
|
3
3
|
export { B as BlockRenderer, a as BlockRendererProps, b as BlockRendererRegistry, C as CompleteBlockRendererRegistry, E as EmbeddingRendererProps, c as EmbeddingRendererRegistry, K as KeyedBlockType } from './renderers-C5f41FCy.js';
|
|
4
4
|
export { B as BoldToken, C as CodeToken, I as ImageToken, a as InlineRefToken, b as InlineToken, c as ItalicToken, L as LatexToken, d as LinkToken, S as StrikethroughToken, T as TextToken } from './inline-DwUYUmk4.js';
|
|
5
|
-
export { BlockShell, BlockShellProps, ChildBlocks, ChildBlocksProps, blockDataAttributes, blockKey } from './components/index.js';
|
|
5
|
+
export { BlockShell, BlockShellProps, ChildBlocks, ChildBlocksProps, NcmBlockPreview, NcmBlockPreviewProps, blockDataAttributes, blockKey } from './components/index.js';
|
|
6
6
|
export { NcmBlock, NcmBlockProps } from './components/ncm-block.js';
|
|
7
7
|
export { NcmDocument, NcmDocumentProps, NcmTheme } from './components/ncm-document.js';
|
|
8
8
|
export { AdmonitionBlock, AdmonitionBlockProps } from './blocks/admonition/index.js';
|
|
@@ -36,7 +36,6 @@ export { InlineContent, InlineContentProps, ReferenceMarker, ReferenceMarkerProp
|
|
|
36
36
|
export { useBlockRenderer, useCustomCodeRenderer } from './hooks/use-block-renderer.js';
|
|
37
37
|
export { defaultRenderers } from './lib/defaults.js';
|
|
38
38
|
export { cn } from './lib/utils.js';
|
|
39
|
-
import 'react/jsx-runtime';
|
|
40
39
|
import 'react';
|
|
41
40
|
import '@nuucognition/mesh-core';
|
|
42
41
|
import '@nuucognition/ncm';
|