yamlover 0.3.4 → 0.3.6
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/bin/yamlover.js +199 -112
- package/dist/client/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/client/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/client/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/client/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/client/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/client/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/client/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/client/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/client/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/client/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/client/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/client/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/client/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/client/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/client/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/client/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/client/assets/_commonjs-dynamic-modules-TDtrdbi3.js +1 -0
- package/dist/client/assets/decoded-CFkcuQ1f.js +1 -0
- package/dist/client/assets/djvu-B3wuFWwI.js +1 -0
- package/dist/client/assets/docx-putHYXzO.js +230 -0
- package/dist/client/assets/heic-oIxhIbIW.js +66 -0
- package/dist/client/assets/imagemap-CUKUIcGe.js +1 -0
- package/dist/client/assets/index-CQ3TGVSx.js +617 -0
- package/dist/client/assets/index-wTjOzmSY.css +1 -0
- package/dist/client/assets/map-CZS083CS.js +1 -0
- package/dist/client/assets/paged-CjxSuuik.js +1 -0
- package/dist/client/assets/panzoom-C7OuIIda.js +4 -0
- package/dist/client/assets/panzoom-CIGW-MKW.css +1 -0
- package/dist/client/assets/pdf-Dz3gUx0B.js +12 -0
- package/dist/client/assets/pdf-m5e3jsV4.css +1 -0
- package/dist/client/assets/pdf.worker.min-qwK7q_zL.mjs +28 -0
- package/dist/client/assets/psd-C8yNwHFw.js +11 -0
- package/dist/client/assets/spreadsheet-DBv7aqoN.js +38 -0
- package/dist/client/assets/tiff-73RKtIux.js +1 -0
- package/{index.html → dist/client/index.html} +2 -1
- package/package.json +18 -21
- package/src/client/App.tsx +0 -424
- package/src/client/NodeView.tsx +0 -422
- package/src/client/TaskStrip.tsx +0 -34
- package/src/client/Tree.tsx +0 -97
- package/src/client/api.ts +0 -213
- package/src/client/icons.ts +0 -91
- package/src/client/links.tsx +0 -108
- package/src/client/live.ts +0 -42
- package/src/client/main.tsx +0 -10
- package/src/client/paste-html.ts +0 -228
- package/src/client/paste-links.ts +0 -42
- package/src/client/paths.ts +0 -139
- package/src/client/render.tsx +0 -339
- package/src/client/renderers/annotate.tsx +0 -641
- package/src/client/renderers/asciidoc.tsx +0 -36
- package/src/client/renderers/chapter.tsx +0 -142
- package/src/client/renderers/csv.tsx +0 -234
- package/src/client/renderers/decoded.tsx +0 -72
- package/src/client/renderers/djvu.tsx +0 -271
- package/src/client/renderers/djvuWorker.ts +0 -99
- package/src/client/renderers/doc.tsx +0 -40
- package/src/client/renderers/docx.tsx +0 -49
- package/src/client/renderers/epub.tsx +0 -147
- package/src/client/renderers/explorer.tsx +0 -294
- package/src/client/renderers/fb2.tsx +0 -149
- package/src/client/renderers/headings.ts +0 -69
- package/src/client/renderers/heic.tsx +0 -23
- package/src/client/renderers/imagemap.tsx +0 -170
- package/src/client/renderers/kml.ts +0 -46
- package/src/client/renderers/latex.tsx +0 -37
- package/src/client/renderers/map.tsx +0 -205
- package/src/client/renderers/marklower.tsx +0 -120
- package/src/client/renderers/markup.tsx +0 -64
- package/src/client/renderers/media.tsx +0 -19
- package/src/client/renderers/paged.ts +0 -137
- package/src/client/renderers/panzoom.ts +0 -101
- package/src/client/renderers/pdf.tsx +0 -316
- package/src/client/renderers/plaintext.tsx +0 -120
- package/src/client/renderers/plantuml.tsx +0 -83
- package/src/client/renderers/psd.tsx +0 -25
- package/src/client/renderers/registry.tsx +0 -411
- package/src/client/renderers/rtf.tsx +0 -210
- package/src/client/renderers/spreadsheet.tsx +0 -105
- package/src/client/renderers/tag.tsx +0 -113
- package/src/client/renderers/text.tsx +0 -42
- package/src/client/renderers/tiff.tsx +0 -33
- package/src/client/styles.css +0 -1212
- package/src/client/vendor/README.md +0 -30
- package/src/client/vite-env.d.ts +0 -31
- package/src/server/api.ts +0 -147
- package/src/server/embed.ts +0 -187
- package/src/server/engine-api.ts +0 -1563
- package/src/server/gitignore.ts +0 -81
- package/src/server/node-kind.ts +0 -61
- package/src/server/tasks.ts +0 -83
- package/src/server/yamlover.ts +0 -1133
- /package/{src/client/vendor/djvu.js → dist/client/assets/djvu-Ci0lFKxE.js} +0 -0
package/src/client/render.tsx
DELETED
|
@@ -1,339 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
|
|
3
|
-
// Keep in sync with LINK_KEY / BINARY_KEY in src/server/yamlover.ts.
|
|
4
|
-
//
|
|
5
|
-
// A node shown only as a link (a container past the one-level view, or any binary
|
|
6
|
-
// leaf) arrives as `{ [LINK_KEY]: {kind, path, count|size} }` — the same marker in
|
|
7
|
-
// the value and the schema — so every representation renders the same hyperlink.
|
|
8
|
-
//
|
|
9
|
-
// The bytes of a selected binary leaf arrive as `{ [BINARY_KEY]: {format,size,
|
|
10
|
-
// base64} }`, rendered as `!!binary` (YAML) or the metadata object (JSON).
|
|
11
|
-
//
|
|
12
|
-
// An `x-yamlover.rel` pointer arrives as `{ [REF_KEY]: {text, path} }` — the
|
|
13
|
-
// pointer string rendered as a hyperlink that navigates to the resolved `path`
|
|
14
|
-
// (or as plain text when `path` is null, i.e. the pointer does not resolve).
|
|
15
|
-
const LINK_KEY = "$yamloverLink";
|
|
16
|
-
const BINARY_KEY = "$yamloverBinary";
|
|
17
|
-
const REF_KEY = "$yamloverRef";
|
|
18
|
-
// An omni/mix node (a `!!var` self-value + fields, or a `!!mix` of items + fields) arrives as
|
|
19
|
-
// `{ [MIXED_KEY]: {kind, value?, entries:[{key,value}]} }`, rendered in yamlover as a leading
|
|
20
|
-
// scalar (omni) then each entry positional (`- v`, key=null) or keyed (`k: v`).
|
|
21
|
-
const MIXED_KEY = "$yamloverMixed";
|
|
22
|
-
|
|
23
|
-
export interface Link {
|
|
24
|
-
kind: "object" | "array" | "scalar" | "binary" | "omni" | "mix";
|
|
25
|
-
type?: string; // the target's JSON-Schema type; with the facets, the routing key
|
|
26
|
-
path: string;
|
|
27
|
-
title?: string; // the target's schema title, when set (used as a link label)
|
|
28
|
-
count?: number;
|
|
29
|
-
size?: number;
|
|
30
|
-
format?: string | null;
|
|
31
|
-
valueType?: string | null; // renderer dispatch facets (TYPES.md §9) — carried so a chunk routes correctly
|
|
32
|
-
hasKeyed?: boolean;
|
|
33
|
-
hasOrdinal?: boolean;
|
|
34
|
-
value?: unknown; // for a link to a scalar: its value, shown as the label
|
|
35
|
-
color?: string | null; // for a link to a pure color tag: its explicit color (badges)
|
|
36
|
-
concrete?: string | null; // how the target is stored; `dir`/`yamlover` → a folder icon
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface Ref {
|
|
40
|
-
text: string;
|
|
41
|
-
path: string | null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface Mixed {
|
|
45
|
-
kind: "omni" | "mix";
|
|
46
|
-
value?: unknown; // omni: the node's own scalar self-value
|
|
47
|
-
entries: { key: string | null; value: unknown }[]; // key=null ⇒ positional item, else keyed field
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
interface BinaryPayload {
|
|
51
|
-
format: string | null;
|
|
52
|
-
size: number;
|
|
53
|
-
base64: string;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function asSingle<T>(v: unknown, key: string): T | null {
|
|
57
|
-
if (v && typeof v === "object" && !Array.isArray(v)) {
|
|
58
|
-
const keys = Object.keys(v as object);
|
|
59
|
-
if (keys.length === 1 && keys[0] === key) return (v as any)[key] as T;
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Read a one-level link marker (a nested container or binary shown as a
|
|
65
|
-
* hyperlink), or null when `v` is not one. Exported for custom renderers that
|
|
66
|
-
* need to treat a child's link specially (e.g. the chapter renderer). */
|
|
67
|
-
export const asLink = (v: unknown) => asSingle<Link>(v, LINK_KEY);
|
|
68
|
-
const asBinary = (v: unknown) => asSingle<BinaryPayload>(v, BINARY_KEY);
|
|
69
|
-
const asRef = (v: unknown) => asSingle<Ref>(v, REF_KEY);
|
|
70
|
-
const asMixed = (v: unknown) => asSingle<Mixed>(v, MIXED_KEY);
|
|
71
|
-
|
|
72
|
-
/** The scalar SELF-VALUE a string/scalar renderer should show. An OMNI node (a scalar that also
|
|
73
|
-
* carries fields — e.g. a markdown doc that gained `yamlover-annotations` keys) projects its page
|
|
74
|
-
* `value` as a `$yamloverMixed` marker, so peel it to the self-value; a plain scalar passes
|
|
75
|
-
* through. Pairs with the facet-tolerant dispatch (TYPES.md §9): routing keeps an annotated string
|
|
76
|
-
* on its renderer, and this hands that renderer the string — not the marker object. */
|
|
77
|
-
export function scalarValue(v: unknown): unknown {
|
|
78
|
-
const m = asMixed(v);
|
|
79
|
-
return m && m.kind === "omni" ? m.value : v;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
type Syntax = "yaml" | "json";
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Render a one-level value or schema in YAML or JSON syntax, syntax-highlighted,
|
|
86
|
-
* with nested containers as hyperlinks. Used for every RHS representation so they
|
|
87
|
-
* behave identically: scalars shown, nested objects/arrays clicked to descend.
|
|
88
|
-
*/
|
|
89
|
-
export function Render({
|
|
90
|
-
value,
|
|
91
|
-
syntax,
|
|
92
|
-
onNavigate,
|
|
93
|
-
}: {
|
|
94
|
-
value: unknown;
|
|
95
|
-
syntax: Syntax;
|
|
96
|
-
onNavigate: (path: string) => void;
|
|
97
|
-
}) {
|
|
98
|
-
const bin = asBinary(value);
|
|
99
|
-
if (bin && syntax === "yaml") return <BinaryYaml bin={bin} />;
|
|
100
|
-
const v = bin ?? value; // JSON shows the {format,size,base64} metadata object
|
|
101
|
-
|
|
102
|
-
const out: ReactNode[] = [];
|
|
103
|
-
const kc = { n: 0 };
|
|
104
|
-
if (syntax === "yaml") emitYaml(v, 0, out, kc, onNavigate);
|
|
105
|
-
else emitJson(v, 0, out, kc, onNavigate);
|
|
106
|
-
return <>{out}</>;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/** A selected binary leaf as a YAML `!!binary` block (a comment carries the
|
|
110
|
-
* format/size; the base64 is the block scalar's content, canonically wrapped at
|
|
111
|
-
* 76 columns and indented two spaces). */
|
|
112
|
-
function BinaryYaml({ bin }: { bin: BinaryPayload }) {
|
|
113
|
-
const lines: string[] = [];
|
|
114
|
-
for (let i = 0; i < bin.base64.length; i += 76) lines.push(" " + bin.base64.slice(i, i + 76));
|
|
115
|
-
return (
|
|
116
|
-
<>
|
|
117
|
-
<span className="b">!!binary</span> <span className="punct">|</span>{" "}
|
|
118
|
-
<span className="c">{`# ${bin.format ?? "binary"}, ${bin.size} bytes`}</span>
|
|
119
|
-
{"\n"}
|
|
120
|
-
<span className="s">{lines.join("\n")}</span>
|
|
121
|
-
</>
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
interface KC {
|
|
126
|
-
n: number;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function linkNode(link: Link, syntax: Syntax, kc: KC, onNavigate: (p: string) => void): ReactNode {
|
|
130
|
-
// a scalar child links by its rendered value (`~`/`null`, quoted/bare per syntax);
|
|
131
|
-
// a container by its `{ … }`/`[ … ]` summary
|
|
132
|
-
const label = link.kind === "scalar" ? scalarLabel(link.value, syntax) : linkLabel(link);
|
|
133
|
-
return (
|
|
134
|
-
<a
|
|
135
|
-
key={kc.n++}
|
|
136
|
-
className="descend"
|
|
137
|
-
href={link.path}
|
|
138
|
-
onClick={(e) => {
|
|
139
|
-
e.preventDefault();
|
|
140
|
-
onNavigate(link.path);
|
|
141
|
-
}}
|
|
142
|
-
>
|
|
143
|
-
{label}
|
|
144
|
-
</a>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/** A scalar value as it would render in `syntax` — used as a scalar link's label. */
|
|
149
|
-
function scalarLabel(v: unknown, syntax: Syntax): string {
|
|
150
|
-
if (v === null || v === undefined) return syntax === "json" ? "null" : "~";
|
|
151
|
-
if (typeof v === "boolean" || typeof v === "number") return String(v);
|
|
152
|
-
return syntax === "json" ? JSON.stringify(v) : String(v);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/** A `rel` pointer: its text as a hyperlink to the resolved `path`, or — when the
|
|
156
|
-
* pointer does not resolve — plain string text (no link). */
|
|
157
|
-
function refNode(ref: Ref, syntax: Syntax, kc: KC, onNavigate: (p: string) => void): ReactNode {
|
|
158
|
-
const text = syntax === "json" ? JSON.stringify(ref.text) : ref.text;
|
|
159
|
-
if (!ref.path) return <span className="s" key={kc.n++}>{text}</span>;
|
|
160
|
-
const target = ref.path;
|
|
161
|
-
return (
|
|
162
|
-
<a
|
|
163
|
-
key={kc.n++}
|
|
164
|
-
className="descend"
|
|
165
|
-
href={target}
|
|
166
|
-
onClick={(e) => {
|
|
167
|
-
e.preventDefault();
|
|
168
|
-
onNavigate(target);
|
|
169
|
-
}}
|
|
170
|
-
>
|
|
171
|
-
{text}
|
|
172
|
-
</a>
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function linkLabel(link: Link): string {
|
|
177
|
-
const n = link.count ?? 0;
|
|
178
|
-
if (link.kind === "array") return `[ array with ${n} ${n === 1 ? "item" : "items"} ]`;
|
|
179
|
-
if (link.kind === "binary") return `< binary of ${link.size ?? 0} bytes >`;
|
|
180
|
-
if (link.kind === "mix") return `{ mixed with ${n} ${n === 1 ? "entry" : "entries"} }`;
|
|
181
|
-
if (link.kind === "omni") return `{ variant ${scalarLabel(link.value, "yaml")} + ${n} ${n === 1 ? "field" : "fields"} }`;
|
|
182
|
-
return `{ object with ${n} ${n === 1 ? "property" : "properties"} }`;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function scalarNode(v: unknown, syntax: Syntax, kc: KC): ReactNode {
|
|
186
|
-
if (v === null) return <span className="null" key={kc.n++}>{syntax === "json" ? "null" : "~"}</span>;
|
|
187
|
-
if (typeof v === "boolean") return <span className="b" key={kc.n++}>{String(v)}</span>;
|
|
188
|
-
if (typeof v === "number") return <span className="n" key={kc.n++}>{String(v)}</span>;
|
|
189
|
-
const text = syntax === "json" ? JSON.stringify(v) : String(v);
|
|
190
|
-
return <span className="s" key={kc.n++}>{text}</span>;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
const isObj = (v: unknown): v is Record<string, unknown> =>
|
|
194
|
-
typeof v === "object" && v !== null && !Array.isArray(v);
|
|
195
|
-
|
|
196
|
-
// --------------------------------------------------------------------------- //
|
|
197
|
-
// YAML
|
|
198
|
-
// --------------------------------------------------------------------------- //
|
|
199
|
-
function emitYaml(value: unknown, indent: number, out: ReactNode[], kc: KC, nav: (p: string) => void): void {
|
|
200
|
-
const link = asLink(value);
|
|
201
|
-
if (link) {
|
|
202
|
-
out.push(linkNode(link, "yaml", kc, nav), "\n");
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
const ref = asRef(value);
|
|
206
|
-
if (ref) {
|
|
207
|
-
out.push(refNode(ref, "yaml", kc, nav), "\n");
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
const mixed = asMixed(value);
|
|
211
|
-
if (mixed) {
|
|
212
|
-
const pad = " ".repeat(indent);
|
|
213
|
-
// omni: the node's own scalar value on its own line first (`!!var 5` → `5`)
|
|
214
|
-
if (mixed.kind === "omni") out.push(pad, scalarNode(mixed.value, "yaml", kc), "\n");
|
|
215
|
-
for (const e of mixed.entries) {
|
|
216
|
-
if (e.key === null) {
|
|
217
|
-
out.push(pad, <span className="punct" key={kc.n++}>{"- "}</span>);
|
|
218
|
-
emitYamlChild(e.value, indent, out, kc, nav, true);
|
|
219
|
-
} else {
|
|
220
|
-
out.push(pad, <span className="k" key={kc.n++}>{e.key}</span>, <span className="punct" key={kc.n++}>:</span>);
|
|
221
|
-
emitYamlChild(e.value, indent, out, kc, nav);
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
if (isObj(value)) {
|
|
227
|
-
const entries = Object.entries(value);
|
|
228
|
-
if (!entries.length) {
|
|
229
|
-
out.push(<span className="punct" key={kc.n++}>{"{}"}</span>, "\n");
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const pad = " ".repeat(indent);
|
|
233
|
-
for (const [k, v] of entries) {
|
|
234
|
-
out.push(pad, <span className="k" key={kc.n++}>{k}</span>, <span className="punct" key={kc.n++}>:</span>);
|
|
235
|
-
emitYamlChild(v, indent, out, kc, nav);
|
|
236
|
-
}
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
if (Array.isArray(value)) {
|
|
240
|
-
if (!value.length) {
|
|
241
|
-
out.push(<span className="punct" key={kc.n++}>{"[]"}</span>, "\n");
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
const pad = " ".repeat(indent);
|
|
245
|
-
for (const item of value) {
|
|
246
|
-
out.push(pad, <span className="punct" key={kc.n++}>{"- "}</span>);
|
|
247
|
-
emitYamlChild(item, indent, out, kc, nav, true);
|
|
248
|
-
}
|
|
249
|
-
return;
|
|
250
|
-
}
|
|
251
|
-
out.push(scalarNode(value, "yaml", kc), "\n");
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Render a value that follows a `key:` or `- ` — inline for scalars/links/empties,
|
|
255
|
-
// or a newline then a nested block.
|
|
256
|
-
function emitYamlChild(
|
|
257
|
-
v: unknown,
|
|
258
|
-
indent: number,
|
|
259
|
-
out: ReactNode[],
|
|
260
|
-
kc: KC,
|
|
261
|
-
nav: (p: string) => void,
|
|
262
|
-
inArray = false,
|
|
263
|
-
): void {
|
|
264
|
-
const link = asLink(v);
|
|
265
|
-
const ref = asRef(v);
|
|
266
|
-
if (link) {
|
|
267
|
-
out.push(" ", linkNode(link, "yaml", kc, nav), "\n");
|
|
268
|
-
} else if (ref) {
|
|
269
|
-
out.push(" ", refNode(ref, "yaml", kc, nav), "\n");
|
|
270
|
-
} else if (isObj(v) && Object.keys(v).length === 0) {
|
|
271
|
-
out.push(" ", <span className="punct" key={kc.n++}>{"{}"}</span>, "\n");
|
|
272
|
-
} else if (Array.isArray(v) && v.length === 0) {
|
|
273
|
-
out.push(" ", <span className="punct" key={kc.n++}>{"[]"}</span>, "\n");
|
|
274
|
-
} else if (isObj(v) || Array.isArray(v)) {
|
|
275
|
-
out.push("\n");
|
|
276
|
-
emitYaml(v, indent + 2, out, kc, nav);
|
|
277
|
-
} else {
|
|
278
|
-
out.push(" ", scalarNode(v, "yaml", kc), "\n");
|
|
279
|
-
}
|
|
280
|
-
void inArray;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// --------------------------------------------------------------------------- //
|
|
284
|
-
// JSON (nested containers become links, so the view is not strictly valid JSON —
|
|
285
|
-
// it is the same one-level representation, in JSON syntax)
|
|
286
|
-
// --------------------------------------------------------------------------- //
|
|
287
|
-
function emitJson(value: unknown, indent: number, out: ReactNode[], kc: KC, nav: (p: string) => void): void {
|
|
288
|
-
const link = asLink(value);
|
|
289
|
-
if (link) {
|
|
290
|
-
out.push(linkNode(link, "json", kc, nav));
|
|
291
|
-
return;
|
|
292
|
-
}
|
|
293
|
-
const ref = asRef(value);
|
|
294
|
-
if (ref) {
|
|
295
|
-
out.push(refNode(ref, "json", kc, nav));
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
const mixed = asMixed(value);
|
|
299
|
-
const objEntries: [string, unknown][] | null = mixed
|
|
300
|
-
? [
|
|
301
|
-
...(mixed.kind === "omni" ? ([["$value", mixed.value]] as [string, unknown][]) : []),
|
|
302
|
-
...mixed.entries.map((e, i): [string, unknown] => [e.key ?? String(i), e.value]),
|
|
303
|
-
]
|
|
304
|
-
: isObj(value)
|
|
305
|
-
? Object.entries(value)
|
|
306
|
-
: null;
|
|
307
|
-
if (objEntries) {
|
|
308
|
-
const entries = objEntries;
|
|
309
|
-
if (!entries.length) {
|
|
310
|
-
out.push(<span className="punct" key={kc.n++}>{"{}"}</span>);
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
const pad = " ".repeat(indent + 2);
|
|
314
|
-
out.push(<span className="punct" key={kc.n++}>{"{"}</span>, "\n");
|
|
315
|
-
entries.forEach(([k, v], i) => {
|
|
316
|
-
out.push(pad, <span className="k" key={kc.n++}>{`"${k}"`}</span>, <span className="punct" key={kc.n++}>{": "}</span>);
|
|
317
|
-
emitJson(v, indent + 2, out, kc, nav);
|
|
318
|
-
out.push(i < entries.length - 1 ? "," : "", "\n");
|
|
319
|
-
});
|
|
320
|
-
out.push(" ".repeat(indent), <span className="punct" key={kc.n++}>{"}"}</span>);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
if (Array.isArray(value)) {
|
|
324
|
-
if (!value.length) {
|
|
325
|
-
out.push(<span className="punct" key={kc.n++}>{"[]"}</span>);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const pad = " ".repeat(indent + 2);
|
|
329
|
-
out.push(<span className="punct" key={kc.n++}>{"["}</span>, "\n");
|
|
330
|
-
value.forEach((item, i) => {
|
|
331
|
-
out.push(pad);
|
|
332
|
-
emitJson(item, indent + 2, out, kc, nav);
|
|
333
|
-
out.push(i < value.length - 1 ? "," : "", "\n");
|
|
334
|
-
});
|
|
335
|
-
out.push(" ".repeat(indent), <span className="punct" key={kc.n++}>{"]"}</span>);
|
|
336
|
-
return;
|
|
337
|
-
}
|
|
338
|
-
out.push(scalarNode(value, "json", kc));
|
|
339
|
-
}
|