@nuucognition/ncm-ui 0.1.0-dev.1
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/LICENSE +21 -0
- package/README.md +129 -0
- package/dist/blocks/admonition/index.d.ts +13 -0
- package/dist/blocks/admonition/index.js +1713 -0
- package/dist/blocks/aside/index.d.ts +13 -0
- package/dist/blocks/aside/index.js +1713 -0
- package/dist/blocks/attribution/index.d.ts +13 -0
- package/dist/blocks/attribution/index.js +32 -0
- package/dist/blocks/blockquote/index.d.ts +15 -0
- package/dist/blocks/blockquote/index.js +609 -0
- package/dist/blocks/chart/index.d.ts +14 -0
- package/dist/blocks/chart/index.js +29 -0
- package/dist/blocks/code/index.d.ts +15 -0
- package/dist/blocks/code/index.js +163 -0
- package/dist/blocks/container/index.d.ts +17 -0
- package/dist/blocks/container/index.js +633 -0
- package/dist/blocks/custom-code/index.d.ts +15 -0
- package/dist/blocks/custom-code/index.js +31 -0
- package/dist/blocks/dataview/index.d.ts +14 -0
- package/dist/blocks/dataview/index.js +29 -0
- package/dist/blocks/definition/index.d.ts +13 -0
- package/dist/blocks/definition/index.js +1713 -0
- package/dist/blocks/embed/index.d.ts +12 -0
- package/dist/blocks/embed/index.js +46 -0
- package/dist/blocks/embedding/index.d.ts +13 -0
- package/dist/blocks/embedding/index.js +763 -0
- package/dist/blocks/figure/index.d.ts +13 -0
- package/dist/blocks/figure/index.js +656 -0
- package/dist/blocks/footnote/index.d.ts +13 -0
- package/dist/blocks/footnote/index.js +1713 -0
- package/dist/blocks/frontmatter/index.d.ts +16 -0
- package/dist/blocks/frontmatter/index.js +38 -0
- package/dist/blocks/header/index.d.ts +9 -0
- package/dist/blocks/header/index.js +610 -0
- package/dist/blocks/horizontal-rule/index.d.ts +9 -0
- package/dist/blocks/horizontal-rule/index.js +19 -0
- package/dist/blocks/html/index.d.ts +31 -0
- package/dist/blocks/html/index.js +52 -0
- package/dist/blocks/index.d.ts +32 -0
- package/dist/blocks/index.js +1736 -0
- package/dist/blocks/latex/index.d.ts +9 -0
- package/dist/blocks/latex/index.js +107 -0
- package/dist/blocks/link/index.d.ts +14 -0
- package/dist/blocks/link/index.js +27 -0
- package/dist/blocks/list/index.d.ts +9 -0
- package/dist/blocks/list/index.js +675 -0
- package/dist/blocks/math/index.d.ts +13 -0
- package/dist/blocks/math/index.js +88 -0
- package/dist/blocks/mermaid/index.d.ts +14 -0
- package/dist/blocks/mermaid/index.js +29 -0
- package/dist/blocks/page-breaker/index.d.ts +16 -0
- package/dist/blocks/page-breaker/index.js +21 -0
- package/dist/blocks/paragraph/index.d.ts +9 -0
- package/dist/blocks/paragraph/index.js +608 -0
- package/dist/blocks/spoiler/index.d.ts +13 -0
- package/dist/blocks/spoiler/index.js +1713 -0
- package/dist/blocks/table/index.d.ts +9 -0
- package/dist/blocks/table/index.js +619 -0
- package/dist/blocks/task-list/index.d.ts +13 -0
- package/dist/blocks/task-list/index.js +670 -0
- package/dist/components/index.d.ts +599 -0
- package/dist/components/index.js +1840 -0
- package/dist/components/ncm-block.d.ts +28 -0
- package/dist/components/ncm-block.js +1712 -0
- package/dist/components/ncm-document.d.ts +48 -0
- package/dist/components/ncm-document.js +1839 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/index.js +284 -0
- package/dist/hooks/index.d.ts +7 -0
- package/dist/hooks/index.js +1731 -0
- package/dist/hooks/use-block-renderer.d.ts +28 -0
- package/dist/hooks/use-block-renderer.js +1731 -0
- package/dist/hooks/use-ncm-config.d.ts +6 -0
- package/dist/hooks/use-ncm-config.js +11 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +1887 -0
- package/dist/inline/index.d.ts +108 -0
- package/dist/inline/index.js +598 -0
- package/dist/inline-DwUYUmk4.d.ts +75 -0
- package/dist/lib/defaults.d.ts +24 -0
- package/dist/lib/defaults.js +1713 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +10 -0
- package/dist/lib/katex.d.ts +3 -0
- package/dist/lib/katex.js +45 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.js +10 -0
- package/dist/references-Bs5wJybr.d.ts +63 -0
- package/dist/renderers-C5f41FCy.d.ts +99 -0
- package/dist/styles/fonts/OpenDyslexic3-Bold.woff +0 -0
- package/dist/styles/fonts/OpenDyslexic3-Bold.woff2 +0 -0
- package/dist/styles/fonts/OpenDyslexic3-Regular.woff +0 -0
- package/dist/styles/fonts/OpenDyslexic3-Regular.woff2 +0 -0
- package/dist/styles/nuu.css +364 -0
- package/dist/styles/paper.css +332 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js +2 -0
- package/dist/use-ncm-config-D0doMYTH.d.ts +114 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 NUU Cognition
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @nuucognition/ncm-ui
|
|
2
|
+
|
|
3
|
+
React renderers for [NUU Cognition Markdown](https://www.npmjs.com/package/@nuucognition/ncm) (NCM) blocks.
|
|
4
|
+
|
|
5
|
+
`@nuucognition/ncm` turns markdown into a tree of semantic **Blocks**;
|
|
6
|
+
`@nuucognition/ncm-ui` renders those Blocks to accessible, themeable React
|
|
7
|
+
markup. Every block type ships a default renderer, each renderer can be
|
|
8
|
+
overridden, and every block is wrapped in a local error boundary so a single bad
|
|
9
|
+
block never takes down the document.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @nuucognition/ncm @nuucognition/ncm-ui react react-dom
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`react` and `react-dom` (`^18` or `^19`) are **peer dependencies** — they come
|
|
18
|
+
from your app. `@nuucognition/ncm` is a required runtime dependency (you parse
|
|
19
|
+
with it, then render). KaTeX and Shiki are bundled and lazy-loaded.
|
|
20
|
+
|
|
21
|
+
The package emits ESM JavaScript and `.d.ts` files to `dist`, keeps CSS files as
|
|
22
|
+
side effects, and preserves `"use client"` banners for React Server Component
|
|
23
|
+
consumers.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { parseNcm } from "@nuucognition/ncm"
|
|
29
|
+
import { NcmDocument } from "@nuucognition/ncm-ui"
|
|
30
|
+
import "@nuucognition/ncm-ui/styles/nuu.css"
|
|
31
|
+
|
|
32
|
+
const doc = parseNcm(markdown)
|
|
33
|
+
|
|
34
|
+
export function Article() {
|
|
35
|
+
return <NcmDocument blocks={doc.blocks ?? []} />
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Custom renderers can override any block type:
|
|
40
|
+
|
|
41
|
+
```tsx
|
|
42
|
+
<NcmDocument
|
|
43
|
+
blocks={blocks}
|
|
44
|
+
renderers={{
|
|
45
|
+
mermaid: MermaidRenderer,
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Each block is wrapped in a local error boundary. A throwing renderer falls back
|
|
51
|
+
to the escaped-source fallback for that block, while sibling blocks continue to
|
|
52
|
+
render. Unknown block types use the same fallback and emit a warning.
|
|
53
|
+
|
|
54
|
+
## Styles
|
|
55
|
+
|
|
56
|
+
The package ships two prebuilt stylesheets plus the fonts they reference. Import
|
|
57
|
+
whichever theme you want (or neither, if you supply your own):
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
import "@nuucognition/ncm-ui/styles/nuu.css" // default NUU theme
|
|
61
|
+
import "@nuucognition/ncm-ui/styles/paper.css" // editorial "paper" theme
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Both are listed under `sideEffects` so bundlers keep them when tree-shaking.
|
|
65
|
+
|
|
66
|
+
## Subpath Exports
|
|
67
|
+
|
|
68
|
+
The root entry re-exports the common surface. Granular subpaths are available
|
|
69
|
+
for consumers who want to import a single renderer or utility without pulling in
|
|
70
|
+
the rest:
|
|
71
|
+
|
|
72
|
+
| Subpath | Contents |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `.` | `NcmDocument`, `NcmBlock`, default renderers, providers, tokens |
|
|
75
|
+
| `./components/*` | `BlockShell`, `NcmBlock`, `NcmDocument`, and helpers |
|
|
76
|
+
| `./blocks/*` | Individual block renderers (e.g. `./blocks/table`, `./blocks/code`) |
|
|
77
|
+
| `./inline` | Inline token renderers |
|
|
78
|
+
| `./context` | `NcmProvider`, `NcmReferencesProvider`, config/reference hooks |
|
|
79
|
+
| `./hooks/*` | Standalone hooks |
|
|
80
|
+
| `./lib/*` | Rendering utilities |
|
|
81
|
+
| `./types` | Renderer registry and prop types |
|
|
82
|
+
| `./styles/nuu.css`, `./styles/paper.css` | Prebuilt themes |
|
|
83
|
+
|
|
84
|
+
## HTML Rendering
|
|
85
|
+
|
|
86
|
+
`HtmlBlock` is the default renderer for `html` blocks. It renders HTML source as escaped text.
|
|
87
|
+
|
|
88
|
+
Consumers that intentionally support HTML can opt into sanitized injection:
|
|
89
|
+
|
|
90
|
+
```tsx
|
|
91
|
+
import { NcmDocument, SanitizedHtmlBlock } from "@nuucognition/ncm-ui"
|
|
92
|
+
|
|
93
|
+
<NcmDocument
|
|
94
|
+
blocks={blocks}
|
|
95
|
+
renderers={{
|
|
96
|
+
html: SanitizedHtmlBlock,
|
|
97
|
+
}}
|
|
98
|
+
/>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`SanitizedHtmlBlock` runs `@nuucognition/ncm`'s HTML sanitizer before injecting
|
|
102
|
+
markup. Keep `HtmlBlock` as the default for untrusted documents. Use
|
|
103
|
+
`SanitizedHtmlBlock` only when the surface intentionally supports HTML.
|
|
104
|
+
|
|
105
|
+
## Math And Code Rendering
|
|
106
|
+
|
|
107
|
+
KaTeX is lazy-loaded and memoized, so documents without math do not pay the
|
|
108
|
+
KaTeX render cost. Shiki syntax highlighting also loads on demand. The tests
|
|
109
|
+
assert the wrapper attributes around KaTeX output rather than snapshotting the
|
|
110
|
+
full KaTeX markup.
|
|
111
|
+
|
|
112
|
+
## Verification
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
pnpm --filter @nuucognition/ncm-ui lint
|
|
116
|
+
pnpm --filter @nuucognition/ncm-ui typecheck
|
|
117
|
+
pnpm --filter @nuucognition/ncm-ui build
|
|
118
|
+
pnpm --filter @nuucognition/ncm-ui test
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The root NCM gate runs both `@nuucognition/ncm-tests` and `@nuucognition/ncm-ui`:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
pnpm test
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { AdmonitionBlock as AdmonitionBlock$1 } from '@nuucognition/ncm';
|
|
3
|
+
import { a as BlockRendererProps } from '../../renderers-C5f41FCy.js';
|
|
4
|
+
import 'react';
|
|
5
|
+
|
|
6
|
+
type AdmonitionBlockProps = BlockRendererProps<AdmonitionBlock$1>;
|
|
7
|
+
/**
|
|
8
|
+
* Admonition (callout) renderer. Collapsible admonitions render as `<details>`;
|
|
9
|
+
* static ones as a titled region. Child blocks render through `NcmBlock`.
|
|
10
|
+
*/
|
|
11
|
+
declare function AdmonitionBlock({ block, className }: AdmonitionBlockProps): react_jsx_runtime.JSX.Element;
|
|
12
|
+
|
|
13
|
+
export { AdmonitionBlock, type AdmonitionBlockProps };
|