@nuucognition/ncm-ui 0.1.1-beta.1 → 0.1.1-beta.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.
- package/dist/blocks/admonition/index.js +102 -35
- package/dist/blocks/aside/index.js +102 -35
- package/dist/blocks/blockquote/index.d.ts +7 -5
- package/dist/blocks/blockquote/index.js +1218 -36
- package/dist/blocks/container/index.js +72 -31
- package/dist/blocks/definition/index.js +101 -34
- package/dist/blocks/embedding/index.js +72 -31
- package/dist/blocks/figure/index.js +72 -31
- package/dist/blocks/footnote/index.js +102 -35
- package/dist/blocks/header/index.js +72 -31
- package/dist/blocks/index.js +102 -35
- package/dist/blocks/list/index.js +72 -31
- package/dist/blocks/paragraph/index.js +72 -31
- package/dist/blocks/spoiler/index.js +102 -35
- package/dist/blocks/table/index.js +72 -31
- package/dist/blocks/task-list/index.js +72 -31
- package/dist/components/index.js +141 -54
- package/dist/components/ncm-block.js +102 -35
- package/dist/components/ncm-document.js +141 -54
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +119 -44
- package/dist/hooks/index.js +102 -35
- package/dist/hooks/use-block-renderer.js +102 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.js +148 -47
- package/dist/inline/index.d.ts +2 -3
- package/dist/inline/index.js +72 -31
- package/dist/lib/defaults.js +102 -35
- package/dist/references-BM-lvGrq.d.ts +99 -0
- package/package.json +3 -3
- package/dist/references-BYW5pnj_.d.ts +0 -63
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
import { Block } from '@nuucognition/ncm';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Numbering for inline references (`^[ref: ...]` / `^[footnote: ...]`).
|
|
7
|
+
*
|
|
8
|
+
* The two kinds are counted **independently**: refs produce `[1] [2] …` and
|
|
9
|
+
* footnotes produce `¹ ² …`.
|
|
10
|
+
*
|
|
11
|
+
* Numbers are assigned by a pure pre-pass over the `blocks` array and looked up
|
|
12
|
+
* by **token content**, never by render order. That makes the marker number a
|
|
13
|
+
* function of the document alone: it is stable under React re-renders,
|
|
14
|
+
* StrictMode double rendering, virtualised or out-of-order block rendering,
|
|
15
|
+
* and it gives every citation of the same source the same number.
|
|
16
|
+
*
|
|
17
|
+
* Refs additionally honour the document's own bibliography. When a paragraph
|
|
18
|
+
* reads `[16] Google Gemini Team. Gemini: …` and a `^[ref: Google Gemini
|
|
19
|
+
* Team. Gemini: …]` token carries that entry, the marker shows `[16]` — the
|
|
20
|
+
* number the source document uses — so the inline citation, the reference
|
|
21
|
+
* list, and the original paper all agree. Refs with no bibliography match are
|
|
22
|
+
* numbered sequentially in first-appearance order, continuing after the
|
|
23
|
+
* highest bibliography number so the two ranges never collide.
|
|
24
|
+
*
|
|
25
|
+
* Footnotes are numbered sequentially in first-appearance order (identical
|
|
26
|
+
* footnote text shares a number).
|
|
27
|
+
*/
|
|
28
|
+
type ReferenceKind = "ref" | "footnote";
|
|
29
|
+
interface ReferenceCounts {
|
|
30
|
+
ref: number;
|
|
31
|
+
footnote: number;
|
|
32
|
+
}
|
|
33
|
+
/** Document-wide numbering: normalised token content → marker number. */
|
|
34
|
+
interface ReferenceNumbering {
|
|
35
|
+
ref: Map<string, number>;
|
|
36
|
+
footnote: Map<string, number>;
|
|
37
|
+
}
|
|
38
|
+
/** Collapse whitespace and case so a token and its bibliography entry compare equal. */
|
|
39
|
+
declare function normalizeReferenceContent(content: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Map every `[n] entry` paragraph in the document to its number. The first
|
|
42
|
+
* paragraph carrying a given entry text wins.
|
|
43
|
+
*/
|
|
44
|
+
declare function collectBibliography(blocks: readonly Block[]): Map<string, number>;
|
|
45
|
+
/**
|
|
46
|
+
* Compute the document-wide numbering (see the module comment for the rules).
|
|
47
|
+
*/
|
|
48
|
+
declare function computeReferenceNumbering(blocks: readonly Block[]): ReferenceNumbering;
|
|
49
|
+
/**
|
|
50
|
+
* Per-block count of inline references, as the *previous* numbering scheme
|
|
51
|
+
* exposed it. Kept for API compatibility; the marker numbers no longer derive
|
|
52
|
+
* from these offsets.
|
|
53
|
+
*/
|
|
54
|
+
declare function computeReferenceBases(blocks: readonly Block[]): Map<string, ReferenceCounts>;
|
|
55
|
+
interface BlockReferenceScopeValue {
|
|
56
|
+
/**
|
|
57
|
+
* The marker number for a token with this `kind` and `content`. Pure with
|
|
58
|
+
* respect to the document: the same content always gets the same number.
|
|
59
|
+
*/
|
|
60
|
+
numberFor(kind: ReferenceKind, content: string): number;
|
|
61
|
+
/**
|
|
62
|
+
* Allocate the next number for `kind` in render order. Legacy API — prefer
|
|
63
|
+
* `numberFor`, which is stable under re-renders.
|
|
64
|
+
*/
|
|
65
|
+
next(kind: ReferenceKind): number;
|
|
66
|
+
}
|
|
67
|
+
interface NcmReferencesProviderProps {
|
|
68
|
+
blocks: readonly Block[];
|
|
69
|
+
children: ReactNode;
|
|
70
|
+
}
|
|
71
|
+
/** Document-root provider — runs the numbering pre-pass over `blocks`. */
|
|
72
|
+
declare function NcmReferencesProvider({ blocks, children }: NcmReferencesProviderProps): react.JSX.Element;
|
|
73
|
+
interface BlockReferenceScopeProps {
|
|
74
|
+
/** Block id. Accepted for API compatibility; numbering is document-wide. */
|
|
75
|
+
blockId?: string;
|
|
76
|
+
children: ReactNode;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Reference scope for one block (or one standalone `InlineContent` fragment).
|
|
80
|
+
*
|
|
81
|
+
* Inside an `NcmDocument` it resolves numbers from the document pre-pass.
|
|
82
|
+
* Standalone — no `NcmReferencesProvider` above it — it numbers the fragment's
|
|
83
|
+
* own tokens by content in first-request order, which is still idempotent
|
|
84
|
+
* under StrictMode double rendering because a repeated request for the same
|
|
85
|
+
* content returns the same number.
|
|
86
|
+
*/
|
|
87
|
+
declare function BlockReferenceScope({ children }: BlockReferenceScopeProps): react.JSX.Element;
|
|
88
|
+
/** Read the active per-block reference scope, if any. */
|
|
89
|
+
declare function useBlockReferenceScope(): BlockReferenceScopeValue | null;
|
|
90
|
+
/**
|
|
91
|
+
* Wrap a subtree so any inline references inside it do NOT take document
|
|
92
|
+
* numbers — used for a reference's own popover content, which the numbering
|
|
93
|
+
* pre-pass deliberately does not descend into.
|
|
94
|
+
*/
|
|
95
|
+
declare function InertReferenceScope({ children }: {
|
|
96
|
+
children: ReactNode;
|
|
97
|
+
}): react.JSX.Element;
|
|
98
|
+
|
|
99
|
+
export { BlockReferenceScope as B, InertReferenceScope as I, NcmReferencesProvider as N, type ReferenceCounts as R, type BlockReferenceScopeProps as a, type BlockReferenceScopeValue as b, type NcmReferencesProviderProps as c, type ReferenceKind as d, type ReferenceNumbering as e, collectBibliography as f, computeReferenceBases as g, computeReferenceNumbering as h, normalizeReferenceContent as n, useBlockReferenceScope as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuucognition/ncm-ui",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.2",
|
|
4
4
|
"description": "React renderers for NUU Cognition Markdown (NCM) blocks — a component library that renders parsed NCM Blocks to accessible, themeable markup.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"tsup": "^8.5.1",
|
|
46
46
|
"typescript": "^5.9.2",
|
|
47
47
|
"vitest": "^2.1.9",
|
|
48
|
-
"@nuucognition/
|
|
49
|
-
"@nuucognition/
|
|
48
|
+
"@nuucognition/typescript-config": "0.0.0",
|
|
49
|
+
"@nuucognition/eslint-config": "0.0.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"react": "^18.0.0 || ^19.0.0",
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import * as react from 'react';
|
|
2
|
-
import { ReactNode } from 'react';
|
|
3
|
-
import { Block } from '@nuucognition/ncm';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Document-order numbering for inline references (`^[ref: ...]` /
|
|
7
|
-
* `^[footnote: ...]`).
|
|
8
|
-
*
|
|
9
|
-
* The two kinds are counted **independently**: refs produce `[1] [2] …` and
|
|
10
|
-
* footnotes produce `¹ ² …`, each with its own running counter across the
|
|
11
|
-
* whole document.
|
|
12
|
-
*
|
|
13
|
-
* Numbering is computed from the `blocks` array — a pure pre-pass that does not
|
|
14
|
-
* depend on React render order — so markers stay stable even if a host
|
|
15
|
-
* virtualises blocks or renders them out of order. The pre-pass yields, per
|
|
16
|
-
* block, the count of each kind in all *preceding* blocks (the "base"); within
|
|
17
|
-
* a block, a `BlockReferenceScope` hands out sequential numbers in render
|
|
18
|
-
* order. Only the within-block step relies on the block's inline content
|
|
19
|
-
* rendering as a synchronous subtree (it always does).
|
|
20
|
-
*/
|
|
21
|
-
type ReferenceKind = "ref" | "footnote";
|
|
22
|
-
interface ReferenceCounts {
|
|
23
|
-
ref: number;
|
|
24
|
-
footnote: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Map each block id to the number of refs/footnotes that precede it in
|
|
28
|
-
* document order — the starting offset for that block's own markers.
|
|
29
|
-
*/
|
|
30
|
-
declare function computeReferenceBases(blocks: readonly Block[]): Map<string, ReferenceCounts>;
|
|
31
|
-
interface BlockReferenceScopeValue {
|
|
32
|
-
/** Allocate the next document-order number for `kind` within this block. */
|
|
33
|
-
next(kind: ReferenceKind): number;
|
|
34
|
-
}
|
|
35
|
-
interface NcmReferencesProviderProps {
|
|
36
|
-
blocks: readonly Block[];
|
|
37
|
-
children: ReactNode;
|
|
38
|
-
}
|
|
39
|
-
/** Document-root provider — runs the numbering pre-pass over `blocks`. */
|
|
40
|
-
declare function NcmReferencesProvider({ blocks, children }: NcmReferencesProviderProps): react.JSX.Element;
|
|
41
|
-
interface BlockReferenceScopeProps {
|
|
42
|
-
/** Block id; resolves the base offset from the document pre-pass. */
|
|
43
|
-
blockId?: string;
|
|
44
|
-
children: ReactNode;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Per-block numbering scope. Seeds a fresh counter from the block's base offset
|
|
48
|
-
* on every render and hands out sequential numbers as markers render. Resetting
|
|
49
|
-
* each render keeps numbering idempotent under React re-renders / StrictMode.
|
|
50
|
-
*/
|
|
51
|
-
declare function BlockReferenceScope({ blockId, children }: BlockReferenceScopeProps): react.JSX.Element;
|
|
52
|
-
/** Read the active per-block reference scope, if any. */
|
|
53
|
-
declare function useBlockReferenceScope(): BlockReferenceScopeValue | null;
|
|
54
|
-
/**
|
|
55
|
-
* Wrap a subtree so any inline references inside it do NOT allocate
|
|
56
|
-
* document-order numbers — used for a reference's own popover content, which
|
|
57
|
-
* the numbering pre-pass deliberately does not descend into.
|
|
58
|
-
*/
|
|
59
|
-
declare function InertReferenceScope({ children }: {
|
|
60
|
-
children: ReactNode;
|
|
61
|
-
}): react.JSX.Element;
|
|
62
|
-
|
|
63
|
-
export { BlockReferenceScope as B, InertReferenceScope as I, NcmReferencesProvider as N, type ReferenceCounts as R, type BlockReferenceScopeProps as a, type BlockReferenceScopeValue as b, type NcmReferencesProviderProps as c, type ReferenceKind as d, computeReferenceBases as e, useBlockReferenceScope as u };
|