@liminis/editor 0.1.0-rc.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 +34 -0
- package/README.md +376 -0
- package/dist/annotations/anchor-align.d.ts +50 -0
- package/dist/annotations/anchor-align.js +74 -0
- package/dist/annotations/anchor-model.d.ts +81 -0
- package/dist/annotations/anchor-model.js +80 -0
- package/dist/annotations/anchor-resolver.d.ts +92 -0
- package/dist/annotations/anchor-resolver.js +231 -0
- package/dist/annotations/block-structure.d.ts +65 -0
- package/dist/annotations/block-structure.js +113 -0
- package/dist/annotations/types.d.ts +159 -0
- package/dist/annotations/types.js +50 -0
- package/dist/annotations.d.ts +25 -0
- package/dist/annotations.js +27 -0
- package/dist/app/App.d.ts +64 -0
- package/dist/app/App.js +180 -0
- package/dist/app/editor/AmbientCorrectionPlugin.d.ts +18 -0
- package/dist/app/editor/AmbientCorrectionPlugin.js +185 -0
- package/dist/app/editor/AnchorScrollPlugin.d.ts +16 -0
- package/dist/app/editor/AnchorScrollPlugin.js +134 -0
- package/dist/app/editor/AnnotationMarkerPlugin.d.ts +24 -0
- package/dist/app/editor/AnnotationMarkerPlugin.js +224 -0
- package/dist/app/editor/AnnotationPlugin.d.ts +42 -0
- package/dist/app/editor/AnnotationPlugin.js +135 -0
- package/dist/app/editor/AnnotationSurface.d.ts +34 -0
- package/dist/app/editor/AnnotationSurface.js +115 -0
- package/dist/app/editor/AssetContext.d.ts +20 -0
- package/dist/app/editor/AssetContext.js +81 -0
- package/dist/app/editor/BlockClickPlugin.d.ts +8 -0
- package/dist/app/editor/BlockClickPlugin.js +126 -0
- package/dist/app/editor/CodeBlockPlugin.d.ts +1 -0
- package/dist/app/editor/CodeBlockPlugin.js +219 -0
- package/dist/app/editor/CorrectionPanelPlugin.d.ts +14 -0
- package/dist/app/editor/CorrectionPanelPlugin.js +333 -0
- package/dist/app/editor/DragHandlePlugin.d.ts +1 -0
- package/dist/app/editor/DragHandlePlugin.js +300 -0
- package/dist/app/editor/Editor.d.ts +84 -0
- package/dist/app/editor/Editor.js +539 -0
- package/dist/app/editor/FrontmatterPlugin.d.ts +19 -0
- package/dist/app/editor/FrontmatterPlugin.js +301 -0
- package/dist/app/editor/ImageModal.d.ts +13 -0
- package/dist/app/editor/ImageModal.js +267 -0
- package/dist/app/editor/ImagePlugin.d.ts +3 -0
- package/dist/app/editor/ImagePlugin.js +187 -0
- package/dist/app/editor/LinkClickPlugin.d.ts +23 -0
- package/dist/app/editor/LinkClickPlugin.js +90 -0
- package/dist/app/editor/MarkdownShortcutsPlugin.d.ts +49 -0
- package/dist/app/editor/MarkdownShortcutsPlugin.js +373 -0
- package/dist/app/editor/OrderedTaskListPlugin.d.ts +21 -0
- package/dist/app/editor/OrderedTaskListPlugin.js +78 -0
- package/dist/app/editor/SearchPlugin.d.ts +1 -0
- package/dist/app/editor/SearchPlugin.js +379 -0
- package/dist/app/editor/SelectionContextMenuPlugin.d.ts +29 -0
- package/dist/app/editor/SelectionContextMenuPlugin.js +160 -0
- package/dist/app/editor/SlashMenu.d.ts +11 -0
- package/dist/app/editor/SlashMenu.js +494 -0
- package/dist/app/editor/SlashMenuPlugin.d.ts +1 -0
- package/dist/app/editor/SlashMenuPlugin.js +168 -0
- package/dist/app/editor/TableActionsPlugin.d.ts +1 -0
- package/dist/app/editor/TableActionsPlugin.js +398 -0
- package/dist/app/editor/TogglePlugin.d.ts +1 -0
- package/dist/app/editor/TogglePlugin.js +159 -0
- package/dist/app/editor/Toolbar.d.ts +10 -0
- package/dist/app/editor/Toolbar.js +263 -0
- package/dist/app/editor/WikiLinkExistencePlugin.d.ts +17 -0
- package/dist/app/editor/WikiLinkExistencePlugin.js +104 -0
- package/dist/app/editor/WikiLinkFormatPlugin.d.ts +17 -0
- package/dist/app/editor/WikiLinkFormatPlugin.js +203 -0
- package/dist/app/editor/annotation-marks.d.ts +177 -0
- package/dist/app/editor/annotation-marks.js +750 -0
- package/dist/app/editor/annotationCommands.d.ts +13 -0
- package/dist/app/editor/annotationCommands.js +11 -0
- package/dist/app/editor/c4/C4InteractiveRenderer.d.ts +35 -0
- package/dist/app/editor/c4/C4InteractiveRenderer.js +299 -0
- package/dist/app/editor/c4/edge-clipping.d.ts +24 -0
- package/dist/app/editor/c4/edge-clipping.js +139 -0
- package/dist/app/editor/c4/hooks/useC4DiagramDrag.d.ts +38 -0
- package/dist/app/editor/c4/hooks/useC4DiagramDrag.js +112 -0
- package/dist/app/editor/c4/layout.d.ts +25 -0
- package/dist/app/editor/c4/layout.js +839 -0
- package/dist/app/editor/c4/parser.d.ts +19 -0
- package/dist/app/editor/c4/parser.js +410 -0
- package/dist/app/editor/c4/render-to-string.d.ts +24 -0
- package/dist/app/editor/c4/render-to-string.js +34 -0
- package/dist/app/editor/c4/renderer.d.ts +64 -0
- package/dist/app/editor/c4/renderer.js +569 -0
- package/dist/app/editor/c4/types.d.ts +203 -0
- package/dist/app/editor/c4/types.js +43 -0
- package/dist/app/editor/correction-yaml.d.ts +10 -0
- package/dist/app/editor/correction-yaml.js +40 -0
- package/dist/app/editor/editorNodes.d.ts +9 -0
- package/dist/app/editor/editorNodes.js +36 -0
- package/dist/app/editor/index.d.ts +1 -0
- package/dist/app/editor/index.js +1 -0
- package/dist/app/editor/mark-overlap-resolver.d.ts +6 -0
- package/dist/app/editor/mark-overlap-resolver.js +45 -0
- package/dist/app/editor/nodes/C4Component.d.ts +14 -0
- package/dist/app/editor/nodes/C4Component.js +284 -0
- package/dist/app/editor/nodes/C4Node.d.ts +32 -0
- package/dist/app/editor/nodes/C4Node.js +112 -0
- package/dist/app/editor/nodes/CalloutNode.d.ts +23 -0
- package/dist/app/editor/nodes/CalloutNode.js +94 -0
- package/dist/app/editor/nodes/CustomLinkNode.d.ts +57 -0
- package/dist/app/editor/nodes/CustomLinkNode.js +209 -0
- package/dist/app/editor/nodes/CustomListItemNode.d.ts +46 -0
- package/dist/app/editor/nodes/CustomListItemNode.js +120 -0
- package/dist/app/editor/nodes/CustomListNode.d.ts +27 -0
- package/dist/app/editor/nodes/CustomListNode.js +54 -0
- package/dist/app/editor/nodes/DefinitionListNode.d.ts +44 -0
- package/dist/app/editor/nodes/DefinitionListNode.js +151 -0
- package/dist/app/editor/nodes/DiagramContextMenu.d.ts +45 -0
- package/dist/app/editor/nodes/DiagramContextMenu.js +116 -0
- package/dist/app/editor/nodes/EquationComponent.d.ts +17 -0
- package/dist/app/editor/nodes/EquationComponent.js +130 -0
- package/dist/app/editor/nodes/EquationNode.d.ts +43 -0
- package/dist/app/editor/nodes/EquationNode.js +179 -0
- package/dist/app/editor/nodes/FootnoteNode.d.ts +40 -0
- package/dist/app/editor/nodes/FootnoteNode.js +151 -0
- package/dist/app/editor/nodes/FrontmatterNode.d.ts +24 -0
- package/dist/app/editor/nodes/FrontmatterNode.js +88 -0
- package/dist/app/editor/nodes/HorizontalRuleNode.d.ts +17 -0
- package/dist/app/editor/nodes/HorizontalRuleNode.js +57 -0
- package/dist/app/editor/nodes/HtmlNode.d.ts +32 -0
- package/dist/app/editor/nodes/HtmlNode.js +121 -0
- package/dist/app/editor/nodes/ImageComponent.d.ts +11 -0
- package/dist/app/editor/nodes/ImageComponent.js +228 -0
- package/dist/app/editor/nodes/ImageNode.d.ts +53 -0
- package/dist/app/editor/nodes/ImageNode.js +183 -0
- package/dist/app/editor/nodes/ListItemParagraphBreakNode.d.ts +42 -0
- package/dist/app/editor/nodes/ListItemParagraphBreakNode.js +95 -0
- package/dist/app/editor/nodes/MermaidComponent.d.ts +11 -0
- package/dist/app/editor/nodes/MermaidComponent.js +216 -0
- package/dist/app/editor/nodes/MermaidNode.d.ts +27 -0
- package/dist/app/editor/nodes/MermaidNode.js +96 -0
- package/dist/app/editor/nodes/ToggleNode.d.ts +56 -0
- package/dist/app/editor/nodes/ToggleNode.js +237 -0
- package/dist/app/editor/nodes/diagram-context-menu.d.ts +11 -0
- package/dist/app/editor/nodes/diagram-context-menu.js +70 -0
- package/dist/app/editor/nodes/diagram-utils.d.ts +13 -0
- package/dist/app/editor/nodes/diagram-utils.js +29 -0
- package/dist/app/editor/nodes/index.d.ts +30 -0
- package/dist/app/editor/nodes/index.js +17 -0
- package/dist/app/editor/utils.d.ts +2 -0
- package/dist/app/editor/utils.js +17 -0
- package/dist/app/mapper/index.d.ts +3 -0
- package/dist/app/mapper/index.js +2 -0
- package/dist/app/mapper/lexicalToMdast.d.ts +62 -0
- package/dist/app/mapper/lexicalToMdast.js +1937 -0
- package/dist/app/mapper/mdastToLexical.d.ts +31 -0
- package/dist/app/mapper/mdastToLexical.js +1075 -0
- package/dist/contract.d.ts +8 -0
- package/dist/contract.js +8 -0
- package/dist/headless.d.ts +40 -0
- package/dist/headless.js +45 -0
- package/dist/host/context.d.ts +20 -0
- package/dist/host/context.js +24 -0
- package/dist/host/defaults.d.ts +21 -0
- package/dist/host/defaults.js +47 -0
- package/dist/host/messages.d.ts +26 -0
- package/dist/host/messages.js +47 -0
- package/dist/host/types.d.ts +75 -0
- package/dist/host/types.js +13 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +51 -0
- package/dist/markdown/annotate-sentinels.d.ts +42 -0
- package/dist/markdown/annotate-sentinels.js +86 -0
- package/dist/markdown/parse.d.ts +56 -0
- package/dist/markdown/parse.js +516 -0
- package/dist/markdown/stringify.d.ts +7 -0
- package/dist/markdown/stringify.js +439 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/LICENSE +21 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/README.md +41 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/from-markdown.d.ts +72 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/from-markdown.js +127 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/index.d.ts +8 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/index.js +6 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/to-markdown.d.ts +17 -0
- package/dist/markdown/vendor/mdast-util-wiki-link/to-markdown.js +33 -0
- package/dist/markdown.d.ts +28 -0
- package/dist/markdown.js +44 -0
- package/dist/mathjax-config.d.ts +89 -0
- package/dist/mathjax-config.js +133 -0
- package/dist/nodes.d.ts +34 -0
- package/dist/nodes.js +34 -0
- package/dist/stores/correctionStore.d.ts +15 -0
- package/dist/stores/correctionStore.js +12 -0
- package/dist/stores/editorStore.d.ts +16 -0
- package/dist/stores/editorStore.js +27 -0
- package/dist/styles.css +2477 -0
- package/dist/types.d.ts +296 -0
- package/dist/types.js +91 -0
- package/dist/utils/file-types.d.ts +10 -0
- package/dist/utils/file-types.js +46 -0
- package/docs/annotations.md +134 -0
- package/docs/decisions/README.md +72 -0
- package/docs/decisions/adr-002.md +27 -0
- package/docs/decisions/adr-007.md +27 -0
- package/docs/decisions/adr-010.md +26 -0
- package/docs/decisions/adr-024.md +124 -0
- package/docs/decisions/adr-024b.md +0 -0
- package/docs/decisions/adr-025.md +103 -0
- package/docs/decisions/adr-027.md +66 -0
- package/docs/decisions/adr-057.md +67 -0
- package/docs/decisions/adr-070.md +131 -0
- package/docs/decisions/adr-075.md +410 -0
- package/docs/decisions/adr-076.md +183 -0
- package/docs/decisions/adr-077.md +410 -0
- package/docs/decisions/adr-078.md +243 -0
- package/docs/decisions/adr-079.md +167 -0
- package/docs/decisions/adr-080.md +325 -0
- package/docs/decisions/adr-081.md +108 -0
- package/docs/decisions/adr-082.md +123 -0
- package/docs/decisions/adr-083.md +204 -0
- package/docs/decisions/adr-084.md +179 -0
- package/docs/editor-api.md +106 -0
- package/docs/markdown-pipeline.md +282 -0
- package/docs/provenance.md +106 -0
- package/docs/zusammen-editor-capability-map.md +232 -0
- package/package.json +175 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from `mdast-util-wiki-link@0.1.2` (MIT, Mark Hudnall — see LICENSE
|
|
3
|
+
* in this directory), with the Liminis trailing-backslash fix applied inline.
|
|
4
|
+
*
|
|
5
|
+
* Why vendored rather than depended-upon-and-patched: the upstream behaviour we
|
|
6
|
+
* need was only reachable through a `pnpm` `patchedDependencies` entry, which
|
|
7
|
+
* does not travel outside the workspace that declares it. An external consumer of the published
|
|
8
|
+
* package would silently get different — and wrong — wiki-link behaviour inside
|
|
9
|
+
* markdown tables (#347). Vendoring makes the package self-contained.
|
|
10
|
+
*
|
|
11
|
+
* Four deliberate divergences from upstream:
|
|
12
|
+
* 1. The trailing-backslash strip (see `exitWikiLink`), previously carried as
|
|
13
|
+
* `liminis-app/patches/mdast-util-wiki-link@0.1.2.patch` in `verveguy/liminis`.
|
|
14
|
+
* 2. Real types instead of `any` on the public option and node shapes.
|
|
15
|
+
* 3. `exitWikiLink` reads the node off `this.stack` rather than off a
|
|
16
|
+
* closure variable shared by every handler in one `fromMarkdown()` call.
|
|
17
|
+
* 4. `top()` asserts the stack frame is actually a wiki-link, so the
|
|
18
|
+
* cannot-nest assumption fails loudly rather than corrupting a sibling node.
|
|
19
|
+
*
|
|
20
|
+
* Nothing else about the parse behaviour changes: `value`, `data.alias`,
|
|
21
|
+
* `data.permalink`, `data.exists`, `data.hName`, `data.hProperties` and
|
|
22
|
+
* `data.hChildren` are computed exactly as upstream computes them.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The node currently being built, read off the compile stack.
|
|
26
|
+
*
|
|
27
|
+
* The type check is not ceremony. Every handler here assumes the top of the
|
|
28
|
+
* stack is the wiki-link it entered, which holds because wiki-links cannot
|
|
29
|
+
* nest — but nothing in this file *enforces* that, and there is no upstream
|
|
30
|
+
* left to diff against. If a future micromark extension change, or a consumer
|
|
31
|
+
* combining extensions, ever let a second wiki-link token open while one is
|
|
32
|
+
* still on the stack, the handlers would quietly write `value`, `alias`,
|
|
33
|
+
* `permalink` and `hChildren` onto the wrong node and the corruption would
|
|
34
|
+
* surface as mis-rendered links, not as an error. Failing loudly here converts
|
|
35
|
+
* that into a stack trace naming this file.
|
|
36
|
+
*/
|
|
37
|
+
function top(stack) {
|
|
38
|
+
const node = stack[stack.length - 1];
|
|
39
|
+
if (node?.type !== 'wikiLink') {
|
|
40
|
+
throw new Error(`wiki-link handler expected a wikiLink on top of the mdast stack, found ${node === undefined ? 'an empty stack' : `a ${String(node.type)}`}. Wiki-links are assumed not to nest; if that changed, these handlers need per-node state.`);
|
|
41
|
+
}
|
|
42
|
+
return node;
|
|
43
|
+
}
|
|
44
|
+
export function fromMarkdown(opts = {}) {
|
|
45
|
+
const permalinks = opts.permalinks || [];
|
|
46
|
+
const defaultPageResolver = (name) => [name.replace(/ /g, '_').toLowerCase()];
|
|
47
|
+
const pageResolver = opts.pageResolver || defaultPageResolver;
|
|
48
|
+
const newClassName = opts.newClassName || 'new';
|
|
49
|
+
const wikiLinkClassName = opts.wikiLinkClassName || 'internal';
|
|
50
|
+
const defaultHrefTemplate = (permalink) => `#/page/${permalink}`;
|
|
51
|
+
const hrefTemplate = opts.hrefTemplate || defaultHrefTemplate;
|
|
52
|
+
function enterWikiLink(token) {
|
|
53
|
+
const node = {
|
|
54
|
+
type: 'wikiLink',
|
|
55
|
+
value: null,
|
|
56
|
+
data: {
|
|
57
|
+
alias: null,
|
|
58
|
+
permalink: null,
|
|
59
|
+
exists: null,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
this.enter(node, token);
|
|
63
|
+
}
|
|
64
|
+
function exitWikiLinkAlias(token) {
|
|
65
|
+
top(this.stack).data.alias = this.sliceSerialize(token);
|
|
66
|
+
}
|
|
67
|
+
function exitWikiLinkTarget(token) {
|
|
68
|
+
top(this.stack).value = this.sliceSerialize(token);
|
|
69
|
+
}
|
|
70
|
+
function exitWikiLink(token) {
|
|
71
|
+
// Read the node off the stack *before* exiting — `this.exit()` pops it, so
|
|
72
|
+
// afterwards `top(this.stack)` is the parent. Upstream reads a closure
|
|
73
|
+
// variable here instead, which every handler produced by one
|
|
74
|
+
// `fromMarkdown()` call shares: `exitWikiLink` would then operate on
|
|
75
|
+
// whichever token last entered, not the one actually exiting. Wiki links
|
|
76
|
+
// cannot nest today, so the two are equivalent in practice — this just
|
|
77
|
+
// declines to inherit the assumption.
|
|
78
|
+
const wikiLink = top(this.stack);
|
|
79
|
+
this.exit(token);
|
|
80
|
+
// --- Liminis divergence from upstream (#347) ------------------------------
|
|
81
|
+
// Strip a trailing backslash from the target only when an alias is present.
|
|
82
|
+
// `parseMarkdown` escapes the alias divider (`\|`) before parsing so GFM
|
|
83
|
+
// table parsing does not split a wiki-link at its pipe; that backslash
|
|
84
|
+
// escapes the pipe for the table parser but is not part of the target. We
|
|
85
|
+
// strip only when an alias exists, so a target that legitimately ends in a
|
|
86
|
+
// backslash is left alone.
|
|
87
|
+
//
|
|
88
|
+
// The strip happens *before* `pageResolver` runs, so `data.permalink` and
|
|
89
|
+
// `data.exists` are computed from the stripped value — matching the patched
|
|
90
|
+
// behaviour this replaces. A post-pass that fixed only `value` would not.
|
|
91
|
+
if (wikiLink.data.alias && wikiLink.value?.endsWith('\\')) {
|
|
92
|
+
wikiLink.value = wikiLink.value.slice(0, -1);
|
|
93
|
+
}
|
|
94
|
+
// --------------------------------------------------------------------------
|
|
95
|
+
const pagePermalinks = pageResolver(wikiLink.value);
|
|
96
|
+
const target = pagePermalinks.find((p) => permalinks.includes(p));
|
|
97
|
+
const exists = target !== undefined;
|
|
98
|
+
const permalink = exists ? target : pagePermalinks[0] || '';
|
|
99
|
+
let displayName = wikiLink.value;
|
|
100
|
+
if (wikiLink.data.alias) {
|
|
101
|
+
displayName = wikiLink.data.alias;
|
|
102
|
+
}
|
|
103
|
+
let classNames = wikiLinkClassName;
|
|
104
|
+
if (!exists) {
|
|
105
|
+
classNames += ' ' + newClassName;
|
|
106
|
+
}
|
|
107
|
+
wikiLink.data.alias = displayName;
|
|
108
|
+
wikiLink.data.permalink = permalink;
|
|
109
|
+
wikiLink.data.exists = exists;
|
|
110
|
+
wikiLink.data.hName = 'a';
|
|
111
|
+
wikiLink.data.hProperties = {
|
|
112
|
+
className: classNames,
|
|
113
|
+
href: hrefTemplate(permalink),
|
|
114
|
+
};
|
|
115
|
+
wikiLink.data.hChildren = [{ type: 'text', value: displayName }];
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
enter: {
|
|
119
|
+
wikiLink: enterWikiLink,
|
|
120
|
+
},
|
|
121
|
+
exit: {
|
|
122
|
+
wikiLinkTarget: exitWikiLinkTarget,
|
|
123
|
+
wikiLinkAlias: exitWikiLinkAlias,
|
|
124
|
+
wikiLink: exitWikiLink,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored `mdast-util-wiki-link` (MIT, Mark Hudnall). See LICENSE and
|
|
3
|
+
* README.md in this directory for provenance and the Liminis divergences.
|
|
4
|
+
*/
|
|
5
|
+
export { fromMarkdown } from './from-markdown.js';
|
|
6
|
+
export type { WikiLinkFromMarkdownOptions } from './from-markdown.js';
|
|
7
|
+
export { toMarkdown } from './to-markdown.js';
|
|
8
|
+
export type { WikiLinkToMarkdownOptions } from './to-markdown.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored from `mdast-util-wiki-link@0.1.2` (MIT, Mark Hudnall — see LICENSE
|
|
3
|
+
* in this directory).
|
|
4
|
+
*
|
|
5
|
+
* One deliberate divergence from upstream: upstream imports
|
|
6
|
+
* `mdast-util-to-markdown/lib/util/safe` from **v0.6.5** of that package, a
|
|
7
|
+
* deep import into a v0 duplicate of the v2 `mdast-util-to-markdown` this
|
|
8
|
+
* package already uses. That duplicate (and upstream's `@babel/runtime`
|
|
9
|
+
* dependency) exists solely to serve this file. Here the same escaping is done
|
|
10
|
+
* through v2's `state.safe()`, which is the supported API and produces the same
|
|
11
|
+
* result for the `{ before: '[', after: ']' }` case this handler uses.
|
|
12
|
+
*/
|
|
13
|
+
import type { Options as ToMarkdownExtension } from 'mdast-util-to-markdown';
|
|
14
|
+
export interface WikiLinkToMarkdownOptions {
|
|
15
|
+
aliasDivider?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function toMarkdown(opts?: WikiLinkToMarkdownOptions): ToMarkdownExtension;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function toMarkdown(opts = {}) {
|
|
2
|
+
const aliasDivider = opts.aliasDivider || ':';
|
|
3
|
+
const handler = (node, _parent, state) => {
|
|
4
|
+
const wikiLink = node;
|
|
5
|
+
const exit = state.enter('wikiLink');
|
|
6
|
+
const nodeValue = state.safe(wikiLink.value, { before: '[', after: ']' });
|
|
7
|
+
// Second deliberate divergence from upstream. Upstream passes the alias
|
|
8
|
+
// through `safe()` unconditionally; `safe(undefined)` yields `''`, which is
|
|
9
|
+
// then unequal to a non-empty target, so a node carrying *no* alias
|
|
10
|
+
// serialized as `[[Target<divider>]]`. That output is malformed — it does
|
|
11
|
+
// not round-trip, parsing back as an empty alias rather than none.
|
|
12
|
+
//
|
|
13
|
+
// Nothing in this repository could reach it (`fromMarkdown` always populates
|
|
14
|
+
// `data.alias`, falling back to the target), so this changes no in-repo
|
|
15
|
+
// behaviour. It only matters to an external host that builds `wikiLink`
|
|
16
|
+
// nodes by hand — which is precisely who the published package is for.
|
|
17
|
+
const rawAlias = wikiLink.data?.alias;
|
|
18
|
+
const hasAlias = typeof rawAlias === 'string' && rawAlias.length > 0;
|
|
19
|
+
const nodeAlias = hasAlias ? state.safe(rawAlias, { before: '[', after: ']' }) : nodeValue;
|
|
20
|
+
const value = nodeAlias !== nodeValue ? `[[${nodeValue}${aliasDivider}${nodeAlias}]]` : `[[${nodeValue}]]`;
|
|
21
|
+
exit();
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
unsafe: [
|
|
26
|
+
{ character: '[', inConstruct: ['phrasing', 'label', 'reference'] },
|
|
27
|
+
{ character: ']', inConstruct: ['label', 'reference'] },
|
|
28
|
+
],
|
|
29
|
+
// `wikiLink` is not a node type mdast knows about — it is contributed by the
|
|
30
|
+
// micromark wiki-link syntax extension — so `Handlers` cannot name it.
|
|
31
|
+
handlers: { wikiLink: handler },
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@liminis/editor/markdown` — the markdown-parsing surface, with no editor.
|
|
3
|
+
*
|
|
4
|
+
* The root barrel (`.`) pulls in Lexical, MathJax, Mermaid and the C4 subsystem,
|
|
5
|
+
* because it exports `<Editor>`/`<App>`. A consumer that only needs to *read*
|
|
6
|
+
* markdown — rendering a search-result snippet, building a table of contents —
|
|
7
|
+
* pays all of that at window startup if it reaches for the barrel. This entry
|
|
8
|
+
* exists so it doesn't have to.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is pure mdast/micromark plus a string helper: no DOM, no
|
|
11
|
+
* Lexical, no React. It is deliberately **not** part of `./headless`, which
|
|
12
|
+
* additionally re-exports `mathjax-config` — whose ~90 bare
|
|
13
|
+
* `import '@mathjax/src/js/input/tex/…Configuration.js'` lines are genuinely
|
|
14
|
+
* side-effectful and cannot be shaken by anyone, costing a ~1.9 MB chunk.
|
|
15
|
+
*
|
|
16
|
+
* Do not add anything to this entry whose import graph reaches Lexical, React,
|
|
17
|
+
* MathJax, or the C4 subsystem. See ADR-075.
|
|
18
|
+
*
|
|
19
|
+
* (The sibling `src/markdown/` directory holds the implementation; `./markdown`
|
|
20
|
+
* resolves to this file, `./markdown/parse` to the module inside it.)
|
|
21
|
+
*/
|
|
22
|
+
export { parseMarkdown } from './markdown/parse.js';
|
|
23
|
+
export type { ParseOptions, ParseResult } from './markdown/parse.js';
|
|
24
|
+
export { isParagraph, isHeading, isList, isListItem, isBlockquote, isCode, isThematicBreak, isTable, isImage, isLink, isHtml, isText, isStrong, isEmphasis, isInlineCode, isDelete, } from './markdown/parse.js';
|
|
25
|
+
export { getFileType } from './utils/file-types.js';
|
|
26
|
+
export type { FileType } from './utils/file-types.js';
|
|
27
|
+
export { fromMarkdown as wikiLinkFromMarkdown, toMarkdown as wikiLinkToMarkdown, } from './markdown/vendor/mdast-util-wiki-link/index.js';
|
|
28
|
+
export type { WikiLinkFromMarkdownOptions, WikiLinkToMarkdownOptions, } from './markdown/vendor/mdast-util-wiki-link/index.js';
|
package/dist/markdown.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@liminis/editor/markdown` — the markdown-parsing surface, with no editor.
|
|
3
|
+
*
|
|
4
|
+
* The root barrel (`.`) pulls in Lexical, MathJax, Mermaid and the C4 subsystem,
|
|
5
|
+
* because it exports `<Editor>`/`<App>`. A consumer that only needs to *read*
|
|
6
|
+
* markdown — rendering a search-result snippet, building a table of contents —
|
|
7
|
+
* pays all of that at window startup if it reaches for the barrel. This entry
|
|
8
|
+
* exists so it doesn't have to.
|
|
9
|
+
*
|
|
10
|
+
* Everything here is pure mdast/micromark plus a string helper: no DOM, no
|
|
11
|
+
* Lexical, no React. It is deliberately **not** part of `./headless`, which
|
|
12
|
+
* additionally re-exports `mathjax-config` — whose ~90 bare
|
|
13
|
+
* `import '@mathjax/src/js/input/tex/…Configuration.js'` lines are genuinely
|
|
14
|
+
* side-effectful and cannot be shaken by anyone, costing a ~1.9 MB chunk.
|
|
15
|
+
*
|
|
16
|
+
* Do not add anything to this entry whose import graph reaches Lexical, React,
|
|
17
|
+
* MathJax, or the C4 subsystem. See ADR-075.
|
|
18
|
+
*
|
|
19
|
+
* (The sibling `src/markdown/` directory holds the implementation; `./markdown`
|
|
20
|
+
* resolves to this file, `./markdown/parse` to the module inside it.)
|
|
21
|
+
*/
|
|
22
|
+
export { parseMarkdown } from './markdown/parse.js';
|
|
23
|
+
export { isParagraph, isHeading, isList, isListItem, isBlockquote, isCode, isThematicBreak, isTable, isImage, isLink, isHtml, isText, isStrong, isEmphasis, isInlineCode, isDelete, } from './markdown/parse.js';
|
|
24
|
+
export { getFileType } from './utils/file-types.js';
|
|
25
|
+
// The vendored wiki-link mdast extension (MIT, landakram/mdast-util-wiki-link),
|
|
26
|
+
// carrying the Liminis trailing-backslash fix for aliased wiki-links inside
|
|
27
|
+
// tables (#347). Exported here so a host building its own mdast pipeline — the
|
|
28
|
+
// Electron main process's canonical chunker is the in-repo one — gets the same
|
|
29
|
+
// *extension* the editor uses, without needing a pnpm patch.
|
|
30
|
+
//
|
|
31
|
+
// These are NOT equivalent to `parseMarkdown`/`stringifyMarkdown`, and the gap
|
|
32
|
+
// is not cosmetic:
|
|
33
|
+
// - `parseMarkdown` escapes the alias divider before parsing. The strip inside
|
|
34
|
+
// `fromMarkdown` only helps once that has happened, so with GFM tables
|
|
35
|
+
// enabled the extension alone lets the table parser reach the `|` first and
|
|
36
|
+
// the row is corrupted (measured: 5 cells and 0 wiki-links where
|
|
37
|
+
// `parseMarkdown` gives 4 and 1).
|
|
38
|
+
// - `parseMarkdown`/`stringifyMarkdown` carry the `_emptyAlias` sentinel that
|
|
39
|
+
// distinguishes `[[target|]]` from `[[target]]`; the extensions do not.
|
|
40
|
+
// - the editor serializes wiki-links through `stringify.ts`'s own handler,
|
|
41
|
+
// not through `toMarkdown` here.
|
|
42
|
+
// See `docs/markdown-pipeline.md` — "What the extensions do not give you".
|
|
43
|
+
// Pure mdast: this entry's isolation contract is preserved.
|
|
44
|
+
export { fromMarkdown as wikiLinkFromMarkdown, toMarkdown as wikiLinkToMarkdown, } from './markdown/vendor/mdast-util-wiki-link/index.js';
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared MathJax v4 configuration module.
|
|
3
|
+
* Provides centralized TeX package imports and factory functions for creating
|
|
4
|
+
* MathJax documents with either liteAdaptor (server/export) or browserAdaptor (desktop).
|
|
5
|
+
*
|
|
6
|
+
* All TeX packages are bundled explicitly for full offline support in Electron and mobile.
|
|
7
|
+
*/
|
|
8
|
+
import '@mathjax/src/js/util/asyncLoad/esm.js';
|
|
9
|
+
import { liteAdaptor } from '@mathjax/src/js/adaptors/liteAdaptor.js';
|
|
10
|
+
import { browserAdaptor } from '@mathjax/src/js/adaptors/browserAdaptor.js';
|
|
11
|
+
import type { LiteElement } from '@mathjax/src/js/adaptors/lite/Element.js';
|
|
12
|
+
import '@mathjax/src/js/input/tex/action/ActionConfiguration.js';
|
|
13
|
+
import '@mathjax/src/js/input/tex/ams/AmsConfiguration.js';
|
|
14
|
+
import '@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js';
|
|
15
|
+
import '@mathjax/src/js/input/tex/autoload/AutoloadConfiguration.js';
|
|
16
|
+
import '@mathjax/src/js/input/tex/base/BaseConfiguration.js';
|
|
17
|
+
import '@mathjax/src/js/input/tex/bbox/BboxConfiguration.js';
|
|
18
|
+
import '@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js';
|
|
19
|
+
import '@mathjax/src/js/input/tex/braket/BraketConfiguration.js';
|
|
20
|
+
import '@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js';
|
|
21
|
+
import '@mathjax/src/js/input/tex/cancel/CancelConfiguration.js';
|
|
22
|
+
import '@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js';
|
|
23
|
+
import '@mathjax/src/js/input/tex/color/ColorConfiguration.js';
|
|
24
|
+
import '@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js';
|
|
25
|
+
import '@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js';
|
|
26
|
+
import '@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js';
|
|
27
|
+
import '@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js';
|
|
28
|
+
import '@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js';
|
|
29
|
+
import '@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js';
|
|
30
|
+
import '@mathjax/src/js/input/tex/html/HtmlConfiguration.js';
|
|
31
|
+
import '@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js';
|
|
32
|
+
import '@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js';
|
|
33
|
+
import '@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js';
|
|
34
|
+
import '@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js';
|
|
35
|
+
import '@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js';
|
|
36
|
+
import '@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js';
|
|
37
|
+
import '@mathjax/src/js/input/tex/require/RequireConfiguration.js';
|
|
38
|
+
import '@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js';
|
|
39
|
+
import '@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js';
|
|
40
|
+
import '@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js';
|
|
41
|
+
import '@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js';
|
|
42
|
+
import '@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js';
|
|
43
|
+
import '@mathjax/src/js/input/tex/verb/VerbConfiguration.js';
|
|
44
|
+
/**
|
|
45
|
+
* All TeX packages bundled for offline support.
|
|
46
|
+
* These correspond to the package configurations imported above.
|
|
47
|
+
*/
|
|
48
|
+
export declare const TEX_PACKAGES: readonly ["base", "ams", "newcommand", "require", "autoload", "configmacros", "action", "amscd", "bbox", "boldsymbol", "braket", "bussproofs", "cancel", "centernot", "color", "colortbl", "empheq", "enclose", "extpfeil", "gensymb", "html", "mathtools", "mhchem", "noerrors", "noundefined", "physics", "setoptions", "tagformat", "textcomp", "textmacros", "unicode", "verb"];
|
|
49
|
+
export type TeXPackage = (typeof TEX_PACKAGES)[number];
|
|
50
|
+
/**
|
|
51
|
+
* MathJax document type, generic over the node type produced by convert().
|
|
52
|
+
* TNode depends on the adaptor: LiteElement for liteAdaptor, HTMLElement for browserAdaptor.
|
|
53
|
+
*/
|
|
54
|
+
export interface MathDocument<TNode> {
|
|
55
|
+
convert(expression: string, options?: {
|
|
56
|
+
display?: boolean;
|
|
57
|
+
}): TNode;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Result of creating a liteAdaptor MathJax instance.
|
|
61
|
+
* Returning both ensures callers use a single adaptor instance.
|
|
62
|
+
*/
|
|
63
|
+
export interface LiteMathJaxInstance {
|
|
64
|
+
adaptor: ReturnType<typeof liteAdaptor>;
|
|
65
|
+
document: MathDocument<LiteElement>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Result of creating a browserAdaptor MathJax instance.
|
|
69
|
+
*/
|
|
70
|
+
export interface BrowserMathJaxInstance {
|
|
71
|
+
adaptor: ReturnType<typeof browserAdaptor>;
|
|
72
|
+
document: MathDocument<HTMLElement>;
|
|
73
|
+
}
|
|
74
|
+
interface LiteAdaptorDocumentOptions {
|
|
75
|
+
fontCache?: 'none' | 'local' | 'global';
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create a MathJax adaptor+document configured for liteAdaptor (server-side/export).
|
|
79
|
+
* Used by routes.ts (mobile API) and EquationNode.tsx (DOM export).
|
|
80
|
+
* Returns both adaptor and document to avoid duplicate adaptor creation.
|
|
81
|
+
*/
|
|
82
|
+
export declare function createLiteAdaptorDocument(options?: LiteAdaptorDocumentOptions): LiteMathJaxInstance;
|
|
83
|
+
/**
|
|
84
|
+
* Create a MathJax adaptor+document configured for browserAdaptor (desktop rendering).
|
|
85
|
+
* Used by EquationComponent.tsx for live equation rendering.
|
|
86
|
+
* Returns both adaptor and document to avoid duplicate adaptor creation.
|
|
87
|
+
*/
|
|
88
|
+
export declare function createBrowserAdaptorDocument(targetDocument: Document): BrowserMathJaxInstance;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared MathJax v4 configuration module.
|
|
3
|
+
* Provides centralized TeX package imports and factory functions for creating
|
|
4
|
+
* MathJax documents with either liteAdaptor (server/export) or browserAdaptor (desktop).
|
|
5
|
+
*
|
|
6
|
+
* All TeX packages are bundled explicitly for full offline support in Electron and mobile.
|
|
7
|
+
*/
|
|
8
|
+
// Import ESM async loader for proper ESM support
|
|
9
|
+
import '@mathjax/src/js/util/asyncLoad/esm.js';
|
|
10
|
+
// Core MathJax imports
|
|
11
|
+
import { mathjax } from '@mathjax/src/js/mathjax.js';
|
|
12
|
+
import { TeX } from '@mathjax/src/js/input/tex.js';
|
|
13
|
+
import { SVG } from '@mathjax/src/js/output/svg.js';
|
|
14
|
+
import { RegisterHTMLHandler } from '@mathjax/src/js/handlers/html.js';
|
|
15
|
+
// Adaptor imports (static ESM, not require())
|
|
16
|
+
import { liteAdaptor } from '@mathjax/src/js/adaptors/liteAdaptor.js';
|
|
17
|
+
import { browserAdaptor } from '@mathjax/src/js/adaptors/browserAdaptor.js';
|
|
18
|
+
// Import all TeX package configurations explicitly
|
|
19
|
+
// These side-effect imports register the packages with the TeX parser
|
|
20
|
+
// NOTE: File names must match the exact CamelCase used in @mathjax/src v4
|
|
21
|
+
import '@mathjax/src/js/input/tex/action/ActionConfiguration.js';
|
|
22
|
+
import '@mathjax/src/js/input/tex/ams/AmsConfiguration.js';
|
|
23
|
+
import '@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js';
|
|
24
|
+
import '@mathjax/src/js/input/tex/autoload/AutoloadConfiguration.js';
|
|
25
|
+
import '@mathjax/src/js/input/tex/base/BaseConfiguration.js';
|
|
26
|
+
import '@mathjax/src/js/input/tex/bbox/BboxConfiguration.js';
|
|
27
|
+
import '@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js';
|
|
28
|
+
import '@mathjax/src/js/input/tex/braket/BraketConfiguration.js';
|
|
29
|
+
import '@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js';
|
|
30
|
+
import '@mathjax/src/js/input/tex/cancel/CancelConfiguration.js';
|
|
31
|
+
import '@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js';
|
|
32
|
+
import '@mathjax/src/js/input/tex/color/ColorConfiguration.js';
|
|
33
|
+
import '@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js';
|
|
34
|
+
import '@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js';
|
|
35
|
+
import '@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js';
|
|
36
|
+
import '@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js';
|
|
37
|
+
import '@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js';
|
|
38
|
+
import '@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js';
|
|
39
|
+
import '@mathjax/src/js/input/tex/html/HtmlConfiguration.js';
|
|
40
|
+
import '@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js';
|
|
41
|
+
import '@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js';
|
|
42
|
+
import '@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js';
|
|
43
|
+
import '@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js';
|
|
44
|
+
import '@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js';
|
|
45
|
+
import '@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js';
|
|
46
|
+
import '@mathjax/src/js/input/tex/require/RequireConfiguration.js';
|
|
47
|
+
import '@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js';
|
|
48
|
+
import '@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js';
|
|
49
|
+
import '@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js';
|
|
50
|
+
import '@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js';
|
|
51
|
+
import '@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js';
|
|
52
|
+
import '@mathjax/src/js/input/tex/verb/VerbConfiguration.js';
|
|
53
|
+
/**
|
|
54
|
+
* All TeX packages bundled for offline support.
|
|
55
|
+
* These correspond to the package configurations imported above.
|
|
56
|
+
*/
|
|
57
|
+
export const TEX_PACKAGES = [
|
|
58
|
+
'base',
|
|
59
|
+
'ams',
|
|
60
|
+
'newcommand',
|
|
61
|
+
'require',
|
|
62
|
+
'autoload',
|
|
63
|
+
'configmacros',
|
|
64
|
+
'action',
|
|
65
|
+
'amscd',
|
|
66
|
+
'bbox',
|
|
67
|
+
'boldsymbol',
|
|
68
|
+
'braket',
|
|
69
|
+
'bussproofs',
|
|
70
|
+
'cancel',
|
|
71
|
+
'centernot',
|
|
72
|
+
'color',
|
|
73
|
+
'colortbl',
|
|
74
|
+
'empheq',
|
|
75
|
+
'enclose',
|
|
76
|
+
'extpfeil',
|
|
77
|
+
'gensymb',
|
|
78
|
+
'html',
|
|
79
|
+
'mathtools',
|
|
80
|
+
'mhchem',
|
|
81
|
+
'noerrors',
|
|
82
|
+
'noundefined',
|
|
83
|
+
'physics',
|
|
84
|
+
'setoptions',
|
|
85
|
+
'tagformat',
|
|
86
|
+
'textcomp',
|
|
87
|
+
'textmacros',
|
|
88
|
+
'unicode',
|
|
89
|
+
'verb',
|
|
90
|
+
];
|
|
91
|
+
/**
|
|
92
|
+
* Track if handlers have been registered to avoid duplicate registration.
|
|
93
|
+
*/
|
|
94
|
+
let liteHandlerRegistered = false;
|
|
95
|
+
let browserHandlerRegistered = false;
|
|
96
|
+
/**
|
|
97
|
+
* Create a MathJax adaptor+document configured for liteAdaptor (server-side/export).
|
|
98
|
+
* Used by routes.ts (mobile API) and EquationNode.tsx (DOM export).
|
|
99
|
+
* Returns both adaptor and document to avoid duplicate adaptor creation.
|
|
100
|
+
*/
|
|
101
|
+
export function createLiteAdaptorDocument(options = {}) {
|
|
102
|
+
const adaptor = liteAdaptor();
|
|
103
|
+
if (!liteHandlerRegistered) {
|
|
104
|
+
RegisterHTMLHandler(adaptor);
|
|
105
|
+
liteHandlerRegistered = true;
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
adaptor,
|
|
109
|
+
document: mathjax.document('', {
|
|
110
|
+
InputJax: new TeX({ packages: TEX_PACKAGES.slice() }),
|
|
111
|
+
OutputJax: new SVG({ fontCache: options.fontCache ?? 'none' }),
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Create a MathJax adaptor+document configured for browserAdaptor (desktop rendering).
|
|
117
|
+
* Used by EquationComponent.tsx for live equation rendering.
|
|
118
|
+
* Returns both adaptor and document to avoid duplicate adaptor creation.
|
|
119
|
+
*/
|
|
120
|
+
export function createBrowserAdaptorDocument(targetDocument) {
|
|
121
|
+
const adaptor = browserAdaptor();
|
|
122
|
+
if (!browserHandlerRegistered) {
|
|
123
|
+
RegisterHTMLHandler(adaptor);
|
|
124
|
+
browserHandlerRegistered = true;
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
adaptor,
|
|
128
|
+
document: mathjax.document(targetDocument, {
|
|
129
|
+
InputJax: new TeX({ packages: TEX_PACKAGES.slice() }),
|
|
130
|
+
OutputJax: new SVG({ fontCache: 'local' }),
|
|
131
|
+
}),
|
|
132
|
+
};
|
|
133
|
+
}
|
package/dist/nodes.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@liminis/editor/nodes` — the headless mapper surface (#954, ADR-079).
|
|
3
|
+
*
|
|
4
|
+
* The seventh declared export subpath, added as a *considered* export under
|
|
5
|
+
* ADR-075's "closed set of declared subpaths" rule (same pattern ADR-077 used
|
|
6
|
+
* to add `./annotations`). It exists because no existing subpath's isolation
|
|
7
|
+
* contract fits: `importMarkdownToLexical`/`exportLexicalToMdast` instantiate
|
|
8
|
+
* Lexical node classes directly, so any entry point exporting them — or the
|
|
9
|
+
* node array a consumer needs to construct a matching `createEditor` — must
|
|
10
|
+
* itself permit Lexical. `./markdown`, `./headless`, `./contract` and
|
|
11
|
+
* `./annotations` are all documented and tested as Lexical-free, and the root
|
|
12
|
+
* barrel (`.`) pulls in the full `<App>`/`<Editor>` React surface (Prism,
|
|
13
|
+
* Mermaid's render path, the C4 subsystem) this subpath exists to avoid.
|
|
14
|
+
*
|
|
15
|
+
* `editorNodes` is re-exported from the same module `Editor.tsx` configures
|
|
16
|
+
* its own `LexicalComposer` with (`./app/editor/editorNodes`) — not a
|
|
17
|
+
* separately hand-maintained copy — so adding a node type to the production
|
|
18
|
+
* editor updates this export automatically (FR-002).
|
|
19
|
+
*
|
|
20
|
+
* **Known exception, carried over from `./headless`: MathJax-lite.**
|
|
21
|
+
* `EquationNode` imports `mathjax-config` at module scope, which statically
|
|
22
|
+
* imports MathJax's lite *and* browser adaptors. Loading this subpath
|
|
23
|
+
* therefore evaluates ~90 side-effectful MathJax TeX-configuration imports —
|
|
24
|
+
* no DOM, no rendering, no MathJax document instantiation. This is not new
|
|
25
|
+
* weight introduced by this subpath; `./headless` already carries the
|
|
26
|
+
* identical exception for the same reason. Splitting `EquationNode`'s import
|
|
27
|
+
* into lazy/eager halves is a real fix but a separate refactor, out of scope
|
|
28
|
+
* for this purely-additive change.
|
|
29
|
+
*
|
|
30
|
+
* See docs/markdown-pipeline.md for an example of building a headless editor
|
|
31
|
+
* from this entry's exports.
|
|
32
|
+
*/
|
|
33
|
+
export { editorNodes } from './app/editor/editorNodes.js';
|
|
34
|
+
export { importMarkdownToLexical, exportLexicalToMdast } from './app/mapper/index.js';
|
package/dist/nodes.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@liminis/editor/nodes` — the headless mapper surface (#954, ADR-079).
|
|
3
|
+
*
|
|
4
|
+
* The seventh declared export subpath, added as a *considered* export under
|
|
5
|
+
* ADR-075's "closed set of declared subpaths" rule (same pattern ADR-077 used
|
|
6
|
+
* to add `./annotations`). It exists because no existing subpath's isolation
|
|
7
|
+
* contract fits: `importMarkdownToLexical`/`exportLexicalToMdast` instantiate
|
|
8
|
+
* Lexical node classes directly, so any entry point exporting them — or the
|
|
9
|
+
* node array a consumer needs to construct a matching `createEditor` — must
|
|
10
|
+
* itself permit Lexical. `./markdown`, `./headless`, `./contract` and
|
|
11
|
+
* `./annotations` are all documented and tested as Lexical-free, and the root
|
|
12
|
+
* barrel (`.`) pulls in the full `<App>`/`<Editor>` React surface (Prism,
|
|
13
|
+
* Mermaid's render path, the C4 subsystem) this subpath exists to avoid.
|
|
14
|
+
*
|
|
15
|
+
* `editorNodes` is re-exported from the same module `Editor.tsx` configures
|
|
16
|
+
* its own `LexicalComposer` with (`./app/editor/editorNodes`) — not a
|
|
17
|
+
* separately hand-maintained copy — so adding a node type to the production
|
|
18
|
+
* editor updates this export automatically (FR-002).
|
|
19
|
+
*
|
|
20
|
+
* **Known exception, carried over from `./headless`: MathJax-lite.**
|
|
21
|
+
* `EquationNode` imports `mathjax-config` at module scope, which statically
|
|
22
|
+
* imports MathJax's lite *and* browser adaptors. Loading this subpath
|
|
23
|
+
* therefore evaluates ~90 side-effectful MathJax TeX-configuration imports —
|
|
24
|
+
* no DOM, no rendering, no MathJax document instantiation. This is not new
|
|
25
|
+
* weight introduced by this subpath; `./headless` already carries the
|
|
26
|
+
* identical exception for the same reason. Splitting `EquationNode`'s import
|
|
27
|
+
* into lazy/eager halves is a real fix but a separate refactor, out of scope
|
|
28
|
+
* for this purely-additive change.
|
|
29
|
+
*
|
|
30
|
+
* See docs/markdown-pipeline.md for an example of building a headless editor
|
|
31
|
+
* from this entry's exports.
|
|
32
|
+
*/
|
|
33
|
+
export { editorNodes } from './app/editor/editorNodes.js';
|
|
34
|
+
export { importMarkdownToLexical, exportLexicalToMdast } from './app/mapper/index.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface CorrectionState {
|
|
2
|
+
isOpen: boolean;
|
|
3
|
+
position: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
selectedText: string;
|
|
8
|
+
open: (position: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}, selectedText: string) => void;
|
|
12
|
+
close: () => void;
|
|
13
|
+
}
|
|
14
|
+
export declare const useCorrectionStore: import("zustand").UseBoundStore<import("zustand").StoreApi<CorrectionState>>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
export const useCorrectionStore = create((set) => ({
|
|
3
|
+
isOpen: false,
|
|
4
|
+
position: { x: 0, y: 0 },
|
|
5
|
+
selectedText: '',
|
|
6
|
+
open: (position, selectedText) => {
|
|
7
|
+
set({ isOpen: true, position, selectedText });
|
|
8
|
+
},
|
|
9
|
+
close: () => {
|
|
10
|
+
set({ isOpen: false });
|
|
11
|
+
},
|
|
12
|
+
}));
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface EditorState {
|
|
2
|
+
/** Whether the current document has frontmatter */
|
|
3
|
+
hasFrontmatter: boolean;
|
|
4
|
+
/** Whether the frontmatter tray is open */
|
|
5
|
+
isFrontmatterOpen: boolean;
|
|
6
|
+
/** Set frontmatter presence (called by editor plugin) */
|
|
7
|
+
setHasFrontmatter: (has: boolean) => void;
|
|
8
|
+
/** Set frontmatter tray state (called by editor plugin) */
|
|
9
|
+
setFrontmatterOpen: (isOpen: boolean) => void;
|
|
10
|
+
/** Toggle frontmatter tray (called by UI button) */
|
|
11
|
+
toggleFrontmatter: () => void;
|
|
12
|
+
/** Reset editor state (when switching documents) */
|
|
13
|
+
reset: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const useEditorStore: import("zustand").UseBoundStore<import("zustand").StoreApi<EditorState>>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
export const useEditorStore = create((set, get) => ({
|
|
3
|
+
hasFrontmatter: false,
|
|
4
|
+
isFrontmatterOpen: false,
|
|
5
|
+
setHasFrontmatter: (has) => {
|
|
6
|
+
set({ hasFrontmatter: has });
|
|
7
|
+
// If no frontmatter, close the tray
|
|
8
|
+
if (!has) {
|
|
9
|
+
set({ isFrontmatterOpen: false });
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
setFrontmatterOpen: (isOpen) => {
|
|
13
|
+
set({ isFrontmatterOpen: isOpen });
|
|
14
|
+
},
|
|
15
|
+
toggleFrontmatter: () => {
|
|
16
|
+
const state = get();
|
|
17
|
+
if (state.hasFrontmatter) {
|
|
18
|
+
set({ isFrontmatterOpen: !state.isFrontmatterOpen });
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
reset: () => {
|
|
22
|
+
set({
|
|
23
|
+
hasFrontmatter: false,
|
|
24
|
+
isFrontmatterOpen: false
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}));
|