yamlover 0.3.23 → 0.3.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/bin/yamlover.js +30 -15
- package/dist/builtin-taxonomy/$defs/.yamlover/meta.yamlover +3 -0
- package/dist/builtin-taxonomy/$defs/chapter +1 -0
- package/dist/builtin-taxonomy/$defs/config +4 -0
- package/dist/builtin-taxonomy/$defs/table +29 -0
- package/dist/client/assets/{decoded-D6QOaoKb.js → decoded-BfD5vW9k.js} +1 -1
- package/dist/client/assets/{djvu-E4zw82nI.js → djvu-DNElocuz.js} +1 -1
- package/dist/client/assets/{docx-BCPZI9sD.js → docx-C3gzsgKj.js} +1 -1
- package/dist/client/assets/{heic-BMjqVVlg.js → heic-CZ82O7cO.js} +1 -1
- package/dist/client/assets/imagemap-B0by6U04.js +1 -0
- package/dist/client/assets/index-C3Raqez8.css +1 -0
- package/dist/client/assets/index-DHpG_wBG.js +665 -0
- package/dist/client/assets/{map-BWtVwabj.js → map-Byy6U5tc.js} +1 -1
- package/dist/client/assets/{openable-DClR-5sz.js → openable-d9huG_69.js} +1 -1
- package/dist/client/assets/{paged-BrajMFZP.js → paged-DFA2Muzj.js} +1 -1
- package/dist/client/assets/{pdf-DLY4bQIN.js → pdf-DYI9E6LP.js} +1 -1
- package/dist/client/assets/{psd-DpmZVKKr.js → psd-CmNn7r6o.js} +1 -1
- package/dist/client/assets/{spreadsheet-CxTCFdEW.js → spreadsheet-DQ1DIIfm.js} +1 -1
- package/dist/client/assets/{tiff-BB8pmY6L.js → tiff-BoTWsGfS.js} +1 -1
- package/dist/client/index.html +12 -2
- package/dist/server.js +482 -80
- package/package.json +1 -1
- package/dist/client/assets/imagemap-Dn9snPoS.js +0 -1
- package/dist/client/assets/index-BpjZr9s_.css +0 -1
- package/dist/client/assets/index-CteLUngZ.js +0 -638
package/dist/server.js
CHANGED
|
@@ -62331,6 +62331,7 @@ var require_ignore = __commonJS({
|
|
|
62331
62331
|
// src/server/engine-api.ts
|
|
62332
62332
|
import path10 from "node:path";
|
|
62333
62333
|
import fs10 from "node:fs";
|
|
62334
|
+
import os from "node:os";
|
|
62334
62335
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
62335
62336
|
|
|
62336
62337
|
// ../parser/ts/src/ir.ts
|
|
@@ -62374,7 +62375,8 @@ function resolveDocument(doc) {
|
|
|
62374
62375
|
node.entries?.forEach((e3, i2) => {
|
|
62375
62376
|
const seg = e3.key != null ? ":" + e3.key : "[" + i2 + "]";
|
|
62376
62377
|
if (isPointer(e3.value)) {
|
|
62377
|
-
const
|
|
62378
|
+
const host = hasRelindex(e3.value) ? hostPositions(chain, i2) : void 0;
|
|
62379
|
+
const target = resolve(doc, chains, chain, e3.value, /* @__PURE__ */ new Set([e3.value]), keys, host);
|
|
62378
62380
|
out.push({ from: prefix + seg, holder: base, label: e3.key, pos: i2, raw: e3.value.raw, edge: e3.edge, target, ptr: e3.value, docRoot: dr });
|
|
62379
62381
|
} else {
|
|
62380
62382
|
walk(e3.value, dr);
|
|
@@ -62400,6 +62402,21 @@ function resolveDocument(doc) {
|
|
|
62400
62402
|
walk(doc.root, ":");
|
|
62401
62403
|
return out;
|
|
62402
62404
|
}
|
|
62405
|
+
function hasRelindex(p2) {
|
|
62406
|
+
return p2.steps.some((s2) => s2.sel === "relindex");
|
|
62407
|
+
}
|
|
62408
|
+
function hostPositions(chain, entryIdx) {
|
|
62409
|
+
const pos = [];
|
|
62410
|
+
for (let i2 = 1; i2 < chain.length; i2++) {
|
|
62411
|
+
const idx = chain[i2 - 1].entries?.findIndex((e3) => e3.value === chain[i2]) ?? -1;
|
|
62412
|
+
pos[i2] = idx >= 0 ? idx : void 0;
|
|
62413
|
+
}
|
|
62414
|
+
pos[chain.length] = entryIdx;
|
|
62415
|
+
return pos;
|
|
62416
|
+
}
|
|
62417
|
+
function relRaw(k) {
|
|
62418
|
+
return `[.${k === 0 ? "" : k > 0 ? "+" + k : k}]`;
|
|
62419
|
+
}
|
|
62403
62420
|
function anchorKeyOf(a2) {
|
|
62404
62421
|
return a2.ordinal ? null : lastKey(a2.path);
|
|
62405
62422
|
}
|
|
@@ -62438,7 +62455,7 @@ function realizeAnchors(doc, chains) {
|
|
|
62438
62455
|
}
|
|
62439
62456
|
return { edges, keys };
|
|
62440
62457
|
}
|
|
62441
|
-
function resolve(doc, chains, fromChain, ptr, visited, anchorKeys) {
|
|
62458
|
+
function resolve(doc, chains, fromChain, ptr, visited, anchorKeys, host) {
|
|
62442
62459
|
const root = doc.root;
|
|
62443
62460
|
let steps = ptr.steps;
|
|
62444
62461
|
let chain;
|
|
@@ -62480,7 +62497,16 @@ function resolve(doc, chains, fromChain, ptr, visited, anchorKeys) {
|
|
|
62480
62497
|
}
|
|
62481
62498
|
const node = chain[chain.length - 1];
|
|
62482
62499
|
if (node === void 0) return { kind: "unresolved", reason: "empty resolution scope" };
|
|
62483
|
-
|
|
62500
|
+
let idx;
|
|
62501
|
+
if (st.sel === "key") idx = node.entries?.findIndex((e3) => e3.key === st.name) ?? -1;
|
|
62502
|
+
else if (st.sel === "index") idx = st.n;
|
|
62503
|
+
else {
|
|
62504
|
+
const at = host?.[chain.length];
|
|
62505
|
+
if (at === void 0) return { kind: "unresolved", reason: `relative index ${relRaw(st.k)} has no host frame at this depth (URIs.md \xA7Relative indexes)` };
|
|
62506
|
+
idx = at + st.k;
|
|
62507
|
+
if (idx < 0) return { kind: "unresolved", reason: `relative index ${relRaw(st.k)} out of range (position ${at})` };
|
|
62508
|
+
}
|
|
62509
|
+
const entry = idx >= 0 ? node.entries?.[idx] : void 0;
|
|
62484
62510
|
if (!entry) {
|
|
62485
62511
|
if (st.sel === "key") {
|
|
62486
62512
|
const via = anchorKeys?.get(node)?.get(st.name);
|
|
@@ -62490,13 +62516,14 @@ function resolve(doc, chains, fromChain, ptr, visited, anchorKeys) {
|
|
|
62490
62516
|
}
|
|
62491
62517
|
}
|
|
62492
62518
|
if (!node.entries) return isWorld ? external() : { kind: "unresolved", reason: "step into a node with no fields" };
|
|
62493
|
-
return isWorld ? external() : { kind: "unresolved", reason: `no ${st.sel === "key" ? `key "${st.name}"` : `index [${st.n}]`}` };
|
|
62519
|
+
return isWorld ? external() : { kind: "unresolved", reason: `no ${st.sel === "key" ? `key "${st.name}"` : st.sel === "index" ? `index [${st.n}]` : `entry at relative index ${relRaw(st.k)} (position ${idx})`}` };
|
|
62494
62520
|
}
|
|
62495
62521
|
if (isPointer(entry.value)) {
|
|
62496
62522
|
if (visited.has(entry.value)) return { kind: "unresolved", reason: "pointer cycle" };
|
|
62497
62523
|
const next = new Set(visited);
|
|
62498
62524
|
next.add(entry.value);
|
|
62499
|
-
const
|
|
62525
|
+
const innerHost = hasRelindex(entry.value) ? hostPositions(chain, idx) : void 0;
|
|
62526
|
+
const r2 = resolve(doc, chains, chain, entry.value, next, anchorKeys, innerHost);
|
|
62500
62527
|
if (r2.kind !== "node") return r2;
|
|
62501
62528
|
chain = chains.get(r2.node) ?? [r2.node];
|
|
62502
62529
|
} else {
|
|
@@ -62535,7 +62562,7 @@ function pathOf(chain) {
|
|
|
62535
62562
|
|
|
62536
62563
|
// ../engine/ts/src/store.ts
|
|
62537
62564
|
import { DatabaseSync } from "node:sqlite";
|
|
62538
|
-
var SCHEMA_VERSION =
|
|
62565
|
+
var SCHEMA_VERSION = 6;
|
|
62539
62566
|
var SCHEMA = `
|
|
62540
62567
|
CREATE TABLE IF NOT EXISTS node (
|
|
62541
62568
|
path TEXT PRIMARY KEY,
|
|
@@ -62565,8 +62592,14 @@ CREATE TABLE IF NOT EXISTS file (
|
|
|
62565
62592
|
CREATE TABLE IF NOT EXISTS dangling (
|
|
62566
62593
|
from_path TEXT NOT NULL, -- the entry holding the pointer
|
|
62567
62594
|
raw TEXT NOT NULL, -- the pointer text as authored
|
|
62568
|
-
reason TEXT NOT NULL
|
|
62595
|
+
reason TEXT NOT NULL, -- why it did not resolve (externals: the authority)
|
|
62596
|
+
holder TEXT NOT NULL, -- the mapping that holds the entry
|
|
62597
|
+
label TEXT, -- the entry's key; null for keyless/positional
|
|
62598
|
+
pos INTEGER, -- the entry's index in the holder (source order)
|
|
62599
|
+
edge TEXT NOT NULL, -- ref | back (as authored)
|
|
62600
|
+
external INTEGER NOT NULL DEFAULT 0 -- 1 = an external-authority link, not an error
|
|
62569
62601
|
);
|
|
62602
|
+
CREATE INDEX IF NOT EXISTS dangling_holder ON dangling (holder);
|
|
62570
62603
|
`;
|
|
62571
62604
|
function encodeScalarValue(v) {
|
|
62572
62605
|
if (typeof v === "number" && !Number.isFinite(v)) return JSON.stringify({ "@nonfinite": String(v) });
|
|
@@ -62631,10 +62664,10 @@ var Store = class {
|
|
|
62631
62664
|
insNode.run(path11, node.kind, format, value, hash, size, isArray ? 1 : 0, meta);
|
|
62632
62665
|
if (parent !== null) insEdge.run(parent, path11, label, "contain", pos);
|
|
62633
62666
|
});
|
|
62634
|
-
const insDangling = this.db.prepare(
|
|
62667
|
+
const insDangling = this.db.prepare(INSERT_DANGLING);
|
|
62635
62668
|
for (const r2 of resolveDocument(doc)) {
|
|
62636
62669
|
if (r2.target.kind === "node") insEdge.run(r2.holder, r2.target.path, r2.label, r2.edge, r2.pos);
|
|
62637
|
-
else
|
|
62670
|
+
else insDanglingRef(insDangling, r2);
|
|
62638
62671
|
}
|
|
62639
62672
|
if (files) {
|
|
62640
62673
|
const insFile = this.db.prepare("INSERT OR REPLACE INTO file (path, hash, size, mtime_ms) VALUES (?, ?, ?, ?)");
|
|
@@ -62675,7 +62708,7 @@ var Store = class {
|
|
|
62675
62708
|
const insEdge = this.db.prepare(
|
|
62676
62709
|
`INSERT INTO edge (from_path, to_path, label, kind, pos) VALUES (?, ?, ?, ?, ?)`
|
|
62677
62710
|
);
|
|
62678
|
-
const insDangling = this.db.prepare(
|
|
62711
|
+
const insDangling = this.db.prepare(INSERT_DANGLING);
|
|
62679
62712
|
const insFile = this.db.prepare("INSERT OR REPLACE INTO file (path, hash, size, mtime_ms) VALUES (?, ?, ?, ?)");
|
|
62680
62713
|
this.db.exec("BEGIN");
|
|
62681
62714
|
try {
|
|
@@ -62684,7 +62717,7 @@ var Store = class {
|
|
|
62684
62717
|
};
|
|
62685
62718
|
delUnder("path", "node");
|
|
62686
62719
|
delUnder("from_path", "edge");
|
|
62687
|
-
delUnder("
|
|
62720
|
+
delUnder("holder", "dangling");
|
|
62688
62721
|
if (relPrefix) this.db.prepare("DELETE FROM file WHERE substr(path,1,?) = ?").run(relPrefix.length, relPrefix);
|
|
62689
62722
|
walkNodes(doc.root, ":", (p2, node, parent, label, pos) => {
|
|
62690
62723
|
if (!underP(p2)) return;
|
|
@@ -62701,7 +62734,7 @@ var Store = class {
|
|
|
62701
62734
|
for (const r2 of edges) {
|
|
62702
62735
|
if (!underP(r2.holder)) continue;
|
|
62703
62736
|
if (r2.target.kind === "node") insEdge.run(r2.holder, r2.target.path, r2.label, r2.edge, r2.pos);
|
|
62704
|
-
else
|
|
62737
|
+
else insDanglingRef(insDangling, r2);
|
|
62705
62738
|
}
|
|
62706
62739
|
for (const f2 of files) insFile.run(f2.path, f2.hash, f2.size, f2.mtimeMs);
|
|
62707
62740
|
this.db.exec("COMMIT");
|
|
@@ -62835,14 +62868,27 @@ var Store = class {
|
|
|
62835
62868
|
throw e3;
|
|
62836
62869
|
}
|
|
62837
62870
|
}
|
|
62838
|
-
/** The pointers that failed to resolve at index time (ENGINE.md: reported, never dropped).
|
|
62871
|
+
/** The pointers that failed to resolve at index time (ENGINE.md: reported, never dropped).
|
|
62872
|
+
* External-authority links are not errors, so they are excluded here. */
|
|
62839
62873
|
dangling() {
|
|
62840
|
-
return this.db.prepare("SELECT * FROM dangling").all().map((r2) => ({
|
|
62874
|
+
return this.db.prepare("SELECT * FROM dangling WHERE external = 0").all().map((r2) => ({
|
|
62841
62875
|
from: r2.from_path,
|
|
62842
62876
|
raw: r2.raw,
|
|
62843
62877
|
reason: r2.reason
|
|
62844
62878
|
}));
|
|
62845
62879
|
}
|
|
62880
|
+
/** A node's pointer ENTRIES with no local target — unresolved (dangling) plus external-
|
|
62881
|
+
* authority links — in source order. These are the entries {@link entries} cannot list (no
|
|
62882
|
+
* edge exists), returned so a projection can still show the authored pointer in place. */
|
|
62883
|
+
unrealizedRefs(holder) {
|
|
62884
|
+
return this.db.prepare("SELECT label, pos, raw, edge, external FROM dangling WHERE holder = ? ORDER BY pos").all(holder).map((r2) => ({
|
|
62885
|
+
label: r2.label ?? null,
|
|
62886
|
+
pos: r2.pos ?? null,
|
|
62887
|
+
raw: r2.raw,
|
|
62888
|
+
edge: r2.edge,
|
|
62889
|
+
external: r2.external === 1
|
|
62890
|
+
}));
|
|
62891
|
+
}
|
|
62846
62892
|
/** A node's attributes (null if no such path). */
|
|
62847
62893
|
node(path11) {
|
|
62848
62894
|
const row = this.db.prepare("SELECT * FROM node WHERE path = ?").get(path11);
|
|
@@ -62905,6 +62951,13 @@ var Store = class {
|
|
|
62905
62951
|
return { out, in: [...inc, ...derivedIn] };
|
|
62906
62952
|
}
|
|
62907
62953
|
};
|
|
62954
|
+
var INSERT_DANGLING = "INSERT INTO dangling (from_path, raw, reason, holder, label, pos, edge, external) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
62955
|
+
function insDanglingRef(stmt, r2) {
|
|
62956
|
+
if (r2.target.kind === "node") return;
|
|
62957
|
+
const ext = r2.target.kind === "external";
|
|
62958
|
+
const reason = r2.target.kind === "external" ? r2.target.authority : r2.target.reason;
|
|
62959
|
+
stmt.run(r2.from, r2.raw, reason, r2.anchor ? "" : r2.holder, r2.label, r2.pos, r2.edge, ext ? 1 : 0);
|
|
62960
|
+
}
|
|
62908
62961
|
function walkNodes(node, path11, visit2, parent = null, label = null, pos = null) {
|
|
62909
62962
|
visit2(path11, node, parent, label, pos);
|
|
62910
62963
|
if (!node.entries) return;
|
|
@@ -62915,6 +62968,7 @@ function walkNodes(node, path11, visit2, parent = null, label = null, pos = null
|
|
|
62915
62968
|
});
|
|
62916
62969
|
}
|
|
62917
62970
|
function formatFromMeta(node) {
|
|
62971
|
+
if (node.meta?.derivedFormat) return node.meta.derivedFormat;
|
|
62918
62972
|
const s2 = node.meta?.schema;
|
|
62919
62973
|
if (!s2) return null;
|
|
62920
62974
|
if (isPointer(s2)) {
|
|
@@ -63112,6 +63166,7 @@ function portionsToSteps(portions) {
|
|
|
63112
63166
|
}
|
|
63113
63167
|
function portionToSteps(p2) {
|
|
63114
63168
|
if (p2 === "..") return [{ sel: "parent" }];
|
|
63169
|
+
if (p2.startsWith("..") && p2[2] === "[") return [{ sel: "parent" }, ...indexGroups(p2.slice(2), p2, "portion")];
|
|
63115
63170
|
let name = "";
|
|
63116
63171
|
let i2 = 0;
|
|
63117
63172
|
if (p2[0] === "'" || p2[0] === '"') {
|
|
@@ -63149,15 +63204,40 @@ function portionToSteps(p2) {
|
|
|
63149
63204
|
}
|
|
63150
63205
|
const steps = [];
|
|
63151
63206
|
if (name !== "") steps.push({ sel: "key", name });
|
|
63152
|
-
|
|
63153
|
-
|
|
63207
|
+
if (i2 < p2.length) steps.push(...indexGroups(p2.slice(i2), p2, "portion"));
|
|
63208
|
+
return steps;
|
|
63209
|
+
}
|
|
63210
|
+
function indexGroups(s2, whole, noun) {
|
|
63211
|
+
const steps = [];
|
|
63212
|
+
let i2 = 0;
|
|
63213
|
+
while (i2 < s2.length) {
|
|
63214
|
+
if (s2[i2] !== "[") throw new SyntaxError(`pointer: malformed ${noun} "${whole}"`);
|
|
63154
63215
|
let j = i2 + 1;
|
|
63216
|
+
if (s2[j] === ".") {
|
|
63217
|
+
j++;
|
|
63218
|
+
let k = 0;
|
|
63219
|
+
if (s2[j] === "+" || s2[j] === "-") {
|
|
63220
|
+
const sign = s2[j] === "-" ? -1 : 1;
|
|
63221
|
+
j++;
|
|
63222
|
+
let digits2 = "";
|
|
63223
|
+
while (j < s2.length && s2[j] >= "0" && s2[j] <= "9") {
|
|
63224
|
+
digits2 += s2[j];
|
|
63225
|
+
j++;
|
|
63226
|
+
}
|
|
63227
|
+
if (digits2 === "") throw new SyntaxError(`pointer: malformed index in "${whole}"`);
|
|
63228
|
+
k = sign * Number.parseInt(digits2, 10);
|
|
63229
|
+
}
|
|
63230
|
+
if (s2[j] !== "]") throw new SyntaxError(`pointer: malformed index in "${whole}"`);
|
|
63231
|
+
steps.push({ sel: "relindex", k });
|
|
63232
|
+
i2 = j + 1;
|
|
63233
|
+
continue;
|
|
63234
|
+
}
|
|
63155
63235
|
let digits = "";
|
|
63156
|
-
while (j <
|
|
63157
|
-
digits +=
|
|
63236
|
+
while (j < s2.length && s2[j] >= "0" && s2[j] <= "9") {
|
|
63237
|
+
digits += s2[j];
|
|
63158
63238
|
j++;
|
|
63159
63239
|
}
|
|
63160
|
-
if (digits === "" ||
|
|
63240
|
+
if (digits === "" || s2[j] !== "]") throw new SyntaxError(`pointer: malformed index in "${whole}"`);
|
|
63161
63241
|
steps.push({ sel: "index", n: Number.parseInt(digits, 10) });
|
|
63162
63242
|
i2 = j + 1;
|
|
63163
63243
|
}
|
|
@@ -63173,10 +63253,17 @@ function renderPointer(p2, opts = {}) {
|
|
|
63173
63253
|
const sep2 = spaced ? ": " : ":";
|
|
63174
63254
|
const toks = [];
|
|
63175
63255
|
for (const st of p2.steps) {
|
|
63176
|
-
if (st.sel === "parent")
|
|
63177
|
-
|
|
63178
|
-
|
|
63179
|
-
|
|
63256
|
+
if (st.sel === "parent") {
|
|
63257
|
+
toks.push("..");
|
|
63258
|
+
continue;
|
|
63259
|
+
}
|
|
63260
|
+
if (st.sel === "key") {
|
|
63261
|
+
toks.push(colonSegment(st.name));
|
|
63262
|
+
continue;
|
|
63263
|
+
}
|
|
63264
|
+
const t3 = st.sel === "index" ? `[${st.n}]` : `[.${st.k === 0 ? "" : (st.k > 0 ? "+" : "") + st.k}]`;
|
|
63265
|
+
if (toks.length > 0 && (st.sel === "relindex" || !toks[toks.length - 1].endsWith(".."))) toks[toks.length - 1] += t3;
|
|
63266
|
+
else toks.push(t3);
|
|
63180
63267
|
}
|
|
63181
63268
|
const body = toks.join(sep2);
|
|
63182
63269
|
switch (p2.base.scope) {
|
|
@@ -63244,6 +63331,7 @@ function readUntilSlash(s2) {
|
|
|
63244
63331
|
}
|
|
63245
63332
|
function segToSteps(seg) {
|
|
63246
63333
|
if (seg === "..") return [{ sel: "parent" }];
|
|
63334
|
+
if (seg.startsWith("..") && seg[2] === "[") return [{ sel: "parent" }, ...indexGroups(seg.slice(2), seg, "segment")];
|
|
63247
63335
|
let i2 = 0;
|
|
63248
63336
|
let name = "";
|
|
63249
63337
|
for (; i2 < seg.length; i2++) {
|
|
@@ -63258,18 +63346,7 @@ function segToSteps(seg) {
|
|
|
63258
63346
|
}
|
|
63259
63347
|
const steps = [];
|
|
63260
63348
|
if (name !== "") steps.push({ sel: "key", name: unescape(name) });
|
|
63261
|
-
|
|
63262
|
-
if (seg[i2] !== "[") throw new SyntaxError(`pointer: malformed segment "${seg}"`);
|
|
63263
|
-
let j = i2 + 1;
|
|
63264
|
-
let digits = "";
|
|
63265
|
-
while (j < seg.length && seg[j] >= "0" && seg[j] <= "9") {
|
|
63266
|
-
digits += seg[j];
|
|
63267
|
-
j++;
|
|
63268
|
-
}
|
|
63269
|
-
if (digits === "" || seg[j] !== "]") throw new SyntaxError(`pointer: malformed index in "${seg}"`);
|
|
63270
|
-
steps.push({ sel: "index", n: Number.parseInt(digits, 10) });
|
|
63271
|
-
i2 = j + 1;
|
|
63272
|
-
}
|
|
63349
|
+
if (i2 < seg.length) steps.push(...indexGroups(seg.slice(i2), seg, "segment"));
|
|
63273
63350
|
return steps;
|
|
63274
63351
|
}
|
|
63275
63352
|
function unescape(s2) {
|
|
@@ -63291,6 +63368,7 @@ function makeAnchor(body, fail, yaml = false) {
|
|
|
63291
63368
|
body = body.slice(0, -2);
|
|
63292
63369
|
}
|
|
63293
63370
|
const path11 = parsePointer(body, yaml);
|
|
63371
|
+
if (path11.steps.some((s2) => s2.sel === "relindex")) fail('an anchor may not claim a position \u2014 "[.\xB1k]" is link-only');
|
|
63294
63372
|
if (!ordinal) {
|
|
63295
63373
|
const last = path11.steps[path11.steps.length - 1];
|
|
63296
63374
|
if (last === void 0) fail('an anchor path needs a key segment (or a trailing "[]" for ordinal membership)');
|
|
@@ -64916,7 +64994,7 @@ function applyMeta(node, meta) {
|
|
|
64916
64994
|
if (!m) continue;
|
|
64917
64995
|
if (m.uniqueItems) e3.value = { ...e3.value, meta: { ...e3.value.meta, set: true } };
|
|
64918
64996
|
if (e3.value.kind === "blob") continue;
|
|
64919
|
-
if (m.format && !e3.value.meta?.schema) e3.value = { ...e3.value, meta: { ...e3.value.meta,
|
|
64997
|
+
if (m.format && !e3.value.meta?.schema) e3.value = { ...e3.value, meta: { ...e3.value.meta, derivedFormat: m.format } };
|
|
64920
64998
|
}
|
|
64921
64999
|
return node;
|
|
64922
65000
|
}
|
|
@@ -64935,7 +65013,7 @@ function blob(abs, format, ctx) {
|
|
|
64935
65013
|
}
|
|
64936
65014
|
function textScalar(abs, format, ctx) {
|
|
64937
65015
|
const text = readTracked(ctx, abs).toString("utf8");
|
|
64938
|
-
return { kind: "scalar", value: text, raw: text, meta: {
|
|
65016
|
+
return { kind: "scalar", value: text, raw: text, meta: { derivedFormat: format } };
|
|
64939
65017
|
}
|
|
64940
65018
|
function parsedScalar(abs, ext, ctx) {
|
|
64941
65019
|
const lang = ext === ".json" || ext === ".json5" || ext === ".json5p" ? "json5p" : ext === ".yaml" || ext === ".yml" ? "yaml" : "yamlover";
|
|
@@ -64983,7 +65061,7 @@ function applySchemas(root, defsRoot, builtinDefs) {
|
|
|
64983
65061
|
return v && !isPointer(v) && v.kind === "scalar" && v.value != null ? String(v.value) : null;
|
|
64984
65062
|
};
|
|
64985
65063
|
const hasFormat = (inst) => {
|
|
64986
|
-
if (inst.kind === "blob") return true;
|
|
65064
|
+
if (inst.kind === "blob" || inst.meta?.derivedFormat) return true;
|
|
64987
65065
|
const s2 = inst.meta?.schema;
|
|
64988
65066
|
return !!s2 && !isPointer(s2) && s2.kind === "mapping" && !!field(s2, "format");
|
|
64989
65067
|
};
|
|
@@ -65000,7 +65078,7 @@ function applySchemas(root, defsRoot, builtinDefs) {
|
|
|
65000
65078
|
const applyItems = (inst, items, depth) => {
|
|
65001
65079
|
const { node: itemsNode } = resolveSchema(items);
|
|
65002
65080
|
const anyOf = itemsNode ? field(itemsNode, "anyOf") : null;
|
|
65003
|
-
const elems = (inst.entries ?? []).filter((e3) => e3.key == null && !isPointer(e3.value));
|
|
65081
|
+
const elems = (inst.entries ?? []).filter((e3) => e3.key == null && !isPointer(e3.value) && !(e3.value.meta?.schema && isPointer(e3.value.meta.schema)));
|
|
65004
65082
|
if (anyOf && !isPointer(anyOf) && anyOf.entries) {
|
|
65005
65083
|
const branches = anyOf.entries.map((e3) => e3.value).map((b) => ({ ptr: b, ...resolveSchema(b) }));
|
|
65006
65084
|
for (const e3 of elems) {
|
|
@@ -65019,7 +65097,7 @@ function applySchemas(root, defsRoot, builtinDefs) {
|
|
|
65019
65097
|
const stype = str(s2, "type");
|
|
65020
65098
|
const named = name && (stype === "object" || stype === "variant" || stype === "mixed" || !!field(s2, "allOf"));
|
|
65021
65099
|
const fmt = str(s2, "format") ?? (named ? `x-yamlover-${name}` : null);
|
|
65022
|
-
if (fmt && !hasFormat(inst)) inst.meta = { ...inst.meta,
|
|
65100
|
+
if (fmt && !hasFormat(inst)) inst.meta = { ...inst.meta, derivedFormat: fmt };
|
|
65023
65101
|
if (stype === "object" || stype === "variant" || stype === "mixed" || stype === "array" || field(s2, "items")) {
|
|
65024
65102
|
const props = field(s2, "properties");
|
|
65025
65103
|
const addl = field(s2, "additionalProperties");
|
|
@@ -65044,9 +65122,6 @@ function applySchemas(root, defsRoot, builtinDefs) {
|
|
|
65044
65122
|
};
|
|
65045
65123
|
walk(root);
|
|
65046
65124
|
}
|
|
65047
|
-
function inlineFormat(format) {
|
|
65048
|
-
return { kind: "mapping", entries: [{ key: "format", edge: "contain", value: { kind: "scalar", value: format, raw: format } }], array: false };
|
|
65049
|
-
}
|
|
65050
65125
|
function applyBody(dir, node, ctx) {
|
|
65051
65126
|
const file = path2.join(dir, YAMLOVER_DIR, "body.yamlover");
|
|
65052
65127
|
if (!fs2.existsSync(file)) return node;
|
|
@@ -65189,11 +65264,21 @@ var DOC_FORMATS = {
|
|
|
65189
65264
|
import * as path3 from "node:path";
|
|
65190
65265
|
|
|
65191
65266
|
// ../parser/ts/src/serialize-common.ts
|
|
65267
|
+
var LossyError = class extends Error {
|
|
65268
|
+
};
|
|
65192
65269
|
function anchorBody(a2) {
|
|
65193
65270
|
return renderPointer(a2.path) + (a2.ordinal ? "[]" : "");
|
|
65194
65271
|
}
|
|
65195
65272
|
|
|
65196
65273
|
// ../parser/ts/src/serialize-yamlover.ts
|
|
65274
|
+
function schemaText(v) {
|
|
65275
|
+
const text = isPointer(v) ? `*${renderPointer(v)}` : schemaNodeText(v);
|
|
65276
|
+
if (/[>\n]/.test(text)) throw new LossyError(`a !!<\u2026> schema tag cannot contain ">" or a newline: ${text}`);
|
|
65277
|
+
return text;
|
|
65278
|
+
}
|
|
65279
|
+
function schemaTagToken(v) {
|
|
65280
|
+
return `!!<${schemaText(v)}>`;
|
|
65281
|
+
}
|
|
65197
65282
|
function pointerToken(raw) {
|
|
65198
65283
|
if (raw !== raw.trim()) return `*'${raw.replace(/'/g, "''")}'`;
|
|
65199
65284
|
return "*" + raw;
|
|
@@ -65222,6 +65307,73 @@ function hasUnquotedSpace(s2) {
|
|
|
65222
65307
|
}
|
|
65223
65308
|
return false;
|
|
65224
65309
|
}
|
|
65310
|
+
function dq(s2) {
|
|
65311
|
+
return JSON.stringify(s2);
|
|
65312
|
+
}
|
|
65313
|
+
function keyText(key) {
|
|
65314
|
+
const needsQuote = key === "" || key !== key.trim() || /[\u0000-\u001f\u007f]/.test(key) || key.includes(": ") || // splitKV would split at the inner colon
|
|
65315
|
+
key === "-" || key.startsWith("- ") || /^['"]/.test(key) || key.includes("\\");
|
|
65316
|
+
if (needsQuote) return dq(key);
|
|
65317
|
+
return key.replace(/[/[\]*&#~?!()<>=|]/g, (c3) => "\\" + c3);
|
|
65318
|
+
}
|
|
65319
|
+
function schemaNodeText(n2) {
|
|
65320
|
+
if (n2.kind === "mapping") {
|
|
65321
|
+
const ents = n2.entries;
|
|
65322
|
+
const keyed = ents.filter((e3) => e3.key !== null);
|
|
65323
|
+
if (keyed.length === ents.length && ents.length === 1 && ents[0].edge !== "back") {
|
|
65324
|
+
const e3 = ents[0];
|
|
65325
|
+
const v = isPointer(e3.value) ? flowPtr(e3.value) : flowText(e3.value);
|
|
65326
|
+
return `${keyText(e3.key)}: ${v}`;
|
|
65327
|
+
}
|
|
65328
|
+
if (keyed.length > 0) {
|
|
65329
|
+
throw new LossyError("an inline !!<\u2026> schema holds at most one top-level key");
|
|
65330
|
+
}
|
|
65331
|
+
}
|
|
65332
|
+
return flowText(n2);
|
|
65333
|
+
}
|
|
65334
|
+
function flowText(n2) {
|
|
65335
|
+
if (n2.kind === "blob") throw new LossyError("a blob has no flow form");
|
|
65336
|
+
if (n2.meta?.schema !== void 0 || n2.meta?.set === true) {
|
|
65337
|
+
throw new LossyError("tags inside an inline !!<\u2026> schema are not serializable");
|
|
65338
|
+
}
|
|
65339
|
+
const ents = n2.entries ?? [];
|
|
65340
|
+
if (n2.kind === "scalar") {
|
|
65341
|
+
if (ents.length > 0) throw new LossyError("a value-plus-fields node has no flow form");
|
|
65342
|
+
return flowTok(n2);
|
|
65343
|
+
}
|
|
65344
|
+
if (ents.length === 0) return n2.array ? "[]" : "{}";
|
|
65345
|
+
const keyed = ents.filter((e3) => e3.key !== null);
|
|
65346
|
+
if (keyed.length > 0 && keyed.length < ents.length) throw new LossyError("a mixed container has no flow form");
|
|
65347
|
+
if (ents.some((e3) => e3.edge === "back")) throw new LossyError("back-edges inside an inline !!<\u2026> schema are not serializable");
|
|
65348
|
+
const item = (e3) => {
|
|
65349
|
+
const v = isPointer(e3.value) ? flowPtr(e3.value) : flowText(e3.value);
|
|
65350
|
+
return e3.key === null ? v : `${flowKey(e3.key)}: ${v}`;
|
|
65351
|
+
};
|
|
65352
|
+
return keyed.length === 0 ? `[${ents.map(item).join(", ")}]` : `{${ents.map(item).join(", ")}}`;
|
|
65353
|
+
}
|
|
65354
|
+
function nonFinite(v) {
|
|
65355
|
+
return Number.isNaN(v) ? ".nan" : v === Infinity ? ".inf" : "-.inf";
|
|
65356
|
+
}
|
|
65357
|
+
function flowTok(s2) {
|
|
65358
|
+
const v = s2.value;
|
|
65359
|
+
if (v === null) return "null";
|
|
65360
|
+
if (typeof v === "boolean") return v ? "true" : "false";
|
|
65361
|
+
if (typeof v === "number") {
|
|
65362
|
+
if (!Number.isFinite(v)) return nonFinite(v);
|
|
65363
|
+
return String(v);
|
|
65364
|
+
}
|
|
65365
|
+
if (v !== "" && /^[^,:[\]{}'"#\s]+$/.test(v) && !"*&~!|>".includes(v[0]) && plainScalar(v).value === v) return v;
|
|
65366
|
+
if (/[\n\r\u0000-\u0008\u000b-\u001f\u007f]/.test(v)) throw new LossyError("a control character has no flow form inside a !!<\u2026> tag");
|
|
65367
|
+
return `'${v.replace(/'/g, "''")}'`;
|
|
65368
|
+
}
|
|
65369
|
+
function flowPtr(p2) {
|
|
65370
|
+
const compact2 = renderPointer(p2, { spaced: false });
|
|
65371
|
+
if (/['"\s]/.test(compact2)) throw new LossyError(`pointer "*${compact2}" does not fit a flow context`);
|
|
65372
|
+
return `*${compact2}`;
|
|
65373
|
+
}
|
|
65374
|
+
function flowKey(k) {
|
|
65375
|
+
return /^[\w.$/-]+$/.test(k) ? k : `'${k.replace(/'/g, "''")}'`;
|
|
65376
|
+
}
|
|
65225
65377
|
|
|
65226
65378
|
// ../engine/ts/src/rewrite.ts
|
|
65227
65379
|
function under(p2, x2) {
|
|
@@ -65369,7 +65521,8 @@ function nominalPath(doc, e3) {
|
|
|
65369
65521
|
if (up === null) return null;
|
|
65370
65522
|
p2 = up === ":" ? "" : up;
|
|
65371
65523
|
} else if (st.sel === "key") p2 += ":" + st.name;
|
|
65372
|
-
else p2 += "[" + st.n + "]";
|
|
65524
|
+
else if (st.sel === "index") p2 += "[" + st.n + "]";
|
|
65525
|
+
else return null;
|
|
65373
65526
|
}
|
|
65374
65527
|
return p2 === "" ? ":" : p2;
|
|
65375
65528
|
}
|
|
@@ -65556,7 +65709,9 @@ var DEFAULT_SETTINGS = {
|
|
|
65556
65709
|
exports: [],
|
|
65557
65710
|
annotations: ":annotations",
|
|
65558
65711
|
tags: ":tags",
|
|
65559
|
-
sidecars: "per-directory"
|
|
65712
|
+
sidecars: "per-directory",
|
|
65713
|
+
width: void 0,
|
|
65714
|
+
theme: void 0
|
|
65560
65715
|
};
|
|
65561
65716
|
var DEFAULT_SETTINGS_SOURCE = `# .yamlover/settings.yamlover \u2014 project settings for this root (created with defaults).
|
|
65562
65717
|
# Settings are DEFAULTS, never constraints: they only say where the server CREATES things when you
|
|
@@ -65569,6 +65724,7 @@ var DEFAULT_SETTINGS_SOURCE = `# .yamlover/settings.yamlover \u2014 project sett
|
|
|
65569
65724
|
annotations: *:: annotations # create new annotations in :annotations
|
|
65570
65725
|
tags: *:: tags # create new tags in :tags
|
|
65571
65726
|
sidecars: per-directory # where derived thumbnail/crop blobs go (enum, not a path)
|
|
65727
|
+
# width: 100 # reading width (ch) for prose views; browser settings override it
|
|
65572
65728
|
`;
|
|
65573
65729
|
function ensureSettingsFile(absRoot) {
|
|
65574
65730
|
const file = path6.join(absRoot, ".yamlover", "settings.yamlover");
|
|
@@ -65592,9 +65748,20 @@ function loadSettings(absRoot) {
|
|
|
65592
65748
|
exports: exportsSetting(valueAt(root, "exports")),
|
|
65593
65749
|
annotations: locationSetting(valueAt(root, "annotations"), DEFAULT_SETTINGS.annotations),
|
|
65594
65750
|
tags: locationSetting(valueAt(root, "tags"), DEFAULT_SETTINGS.tags),
|
|
65595
|
-
sidecars: sidecarLocation(valueAt(root, "sidecars"), DEFAULT_SETTINGS.sidecars)
|
|
65751
|
+
sidecars: sidecarLocation(valueAt(root, "sidecars"), DEFAULT_SETTINGS.sidecars),
|
|
65752
|
+
width: intSetting(valueAt(root, "width"), 20, 400),
|
|
65753
|
+
theme: enumSetting(valueAt(root, "theme"), ["dark", "light"])
|
|
65596
65754
|
};
|
|
65597
65755
|
}
|
|
65756
|
+
function intSetting(v, min, max) {
|
|
65757
|
+
if (v === void 0 || isPointer(v) || v.kind !== "scalar") return void 0;
|
|
65758
|
+
const n2 = typeof v.value === "number" ? v.value : NaN;
|
|
65759
|
+
return Number.isInteger(n2) && n2 >= min && n2 <= max ? n2 : void 0;
|
|
65760
|
+
}
|
|
65761
|
+
function enumSetting(v, values) {
|
|
65762
|
+
if (v === void 0 || isPointer(v) || v.kind !== "scalar") return void 0;
|
|
65763
|
+
return values.includes(v.value) ? v.value : void 0;
|
|
65764
|
+
}
|
|
65598
65765
|
function uriSetting(v) {
|
|
65599
65766
|
if (v === void 0) return void 0;
|
|
65600
65767
|
if (isPointer(v)) return v.base.scope === "link" ? v.base.authority : void 0;
|
|
@@ -65744,7 +65911,12 @@ function parsePortion(r2) {
|
|
|
65744
65911
|
const test = parseValTest(r2);
|
|
65745
65912
|
if (test !== null) return [test];
|
|
65746
65913
|
const steps = parsePointer(r2).steps;
|
|
65747
|
-
return steps.map((st) =>
|
|
65914
|
+
return steps.map((st) => {
|
|
65915
|
+
if (st.sel === "key") return { kind: "key", name: st.name };
|
|
65916
|
+
if (st.sel === "index") return { kind: "index", n: st.n };
|
|
65917
|
+
if (st.sel === "relindex") throw new SyntaxError('query: a relative index "[.\xB1k]" is a link step, not a query portion (URIs.md \xA7Relative indexes)');
|
|
65918
|
+
return { kind: "spine" };
|
|
65919
|
+
});
|
|
65748
65920
|
}
|
|
65749
65921
|
function parseValTest(r2) {
|
|
65750
65922
|
const m = CMP.exec(r2);
|
|
@@ -66434,7 +66606,11 @@ function findGitRoot(start) {
|
|
|
66434
66606
|
|
|
66435
66607
|
// src/server/node-kind.ts
|
|
66436
66608
|
function ownedEntries(s2, p2) {
|
|
66437
|
-
|
|
66609
|
+
const own = s2.entries(p2).filter((e3) => e3.kind !== "back");
|
|
66610
|
+
const unrealized = s2.unrealizedRefs(p2).filter((u2) => u2.edge !== "back");
|
|
66611
|
+
if (unrealized.length === 0) return own;
|
|
66612
|
+
for (const u2 of unrealized) own.push({ to: "", label: u2.label, pos: u2.pos, kind: "ref", raw: u2.raw });
|
|
66613
|
+
return own.sort((a2, b) => (a2.pos ?? 0) - (b.pos ?? 0));
|
|
66438
66614
|
}
|
|
66439
66615
|
function displayKind(s2, p2, row) {
|
|
66440
66616
|
const ents = ownedEntries(s2, p2);
|
|
@@ -66529,6 +66705,7 @@ function createHandlers(dataRoot, opts = {}) {
|
|
|
66529
66705
|
const rootName = path10.basename(path10.resolve(dataRoot)) || "/";
|
|
66530
66706
|
const dbPath = path10.join(dataRoot, ".yamlover", "index.db");
|
|
66531
66707
|
const settingsFile = path10.join(dataRoot, ".yamlover", "settings.yamlover");
|
|
66708
|
+
const settingsRel = path10.relative(dataRoot, settingsFile).split(path10.sep).join("/");
|
|
66532
66709
|
if (opts.ensureSettings) {
|
|
66533
66710
|
try {
|
|
66534
66711
|
ensureSettingsFile(dataRoot);
|
|
@@ -66555,6 +66732,7 @@ function createHandlers(dataRoot, opts = {}) {
|
|
|
66555
66732
|
};
|
|
66556
66733
|
const broadcast = (diff2) => {
|
|
66557
66734
|
if (diff2.added.length + diff2.changed.length + diff2.removed.length + diff2.moved.length === 0) return;
|
|
66735
|
+
if (diff2.changed.includes(settingsRel) || diff2.added.includes(settingsRel)) settings = loadSettings(dataRoot);
|
|
66558
66736
|
const toClient = (rel) => segsToStr(rel.split("/"));
|
|
66559
66737
|
sseWrite({
|
|
66560
66738
|
type: "diff",
|
|
@@ -66867,6 +67045,17 @@ function createHandlers(dataRoot, opts = {}) {
|
|
|
66867
67045
|
).then((body) => sendJson(res, 200, body)).catch((e3) => sendJson(res, 400, { error: String(e3.message || e3) }));
|
|
66868
67046
|
return;
|
|
66869
67047
|
}
|
|
67048
|
+
if (req.method === "POST" && url.pathname === "/api/preview") {
|
|
67049
|
+
readBody(req).then((data) => sendJson(res, 200, previewPayload(String(data.source ?? "")))).catch((e3) => sendJson(res, 400, { error: String(e3.message || e3) }));
|
|
67050
|
+
return;
|
|
67051
|
+
}
|
|
67052
|
+
if (req.method === "POST" && url.pathname === "/api/edit-text") {
|
|
67053
|
+
readBody(req).then((data) => {
|
|
67054
|
+
const d = data;
|
|
67055
|
+
sendJson(res, 200, { source: applyTextEdits(String(d.source ?? ""), Array.isArray(d.edits) ? d.edits : []) });
|
|
67056
|
+
}).catch((e3) => sendJson(res, 400, { error: String(e3.message || e3) }));
|
|
67057
|
+
return;
|
|
67058
|
+
}
|
|
66870
67059
|
if (req.method === "POST" && url.pathname === "/api/mv") {
|
|
66871
67060
|
readBody(req).then(
|
|
66872
67061
|
(data) => enqueue(async () => {
|
|
@@ -66912,20 +67101,6 @@ function createHandlers(dataRoot, opts = {}) {
|
|
|
66912
67101
|
sendJson(res, 200, { source, settings, path: ":.yamlover:settings.yamlover" });
|
|
66913
67102
|
return;
|
|
66914
67103
|
}
|
|
66915
|
-
if (req.method === "POST" && url.pathname === "/api/config") {
|
|
66916
|
-
readBody(req).then(
|
|
66917
|
-
(data) => enqueue(async () => {
|
|
66918
|
-
const source = String(data?.source ?? "");
|
|
66919
|
-
parseYamlover(source, settingsFile);
|
|
66920
|
-
fs10.mkdirSync(path10.dirname(settingsFile), { recursive: true });
|
|
66921
|
-
fs10.writeFileSync(settingsFile, source);
|
|
66922
|
-
settings = loadSettings(dataRoot);
|
|
66923
|
-
broadcast(await doReindexFile(settingsFile));
|
|
66924
|
-
return { ok: true, settings };
|
|
66925
|
-
})
|
|
66926
|
-
).then((body) => sendJson(res, 200, body)).catch((e3) => sendJson(res, 400, { error: String(e3.message || e3) }));
|
|
66927
|
-
return;
|
|
66928
|
-
}
|
|
66929
67104
|
const segs = strToSegs(url.searchParams.get("path") || ":");
|
|
66930
67105
|
const p2 = storePath(segs);
|
|
66931
67106
|
const depth = parseDepth(url.searchParams.get("depth"));
|
|
@@ -67030,6 +67205,7 @@ function createHandlers(dataRoot, opts = {}) {
|
|
|
67030
67205
|
return Object.assign(handler, {
|
|
67031
67206
|
ready,
|
|
67032
67207
|
close: () => {
|
|
67208
|
+
if (closed) return;
|
|
67033
67209
|
closed = true;
|
|
67034
67210
|
stopWatch?.();
|
|
67035
67211
|
for (const r2 of sseClients) r2.end();
|
|
@@ -67074,12 +67250,12 @@ var hasSubchapterChild = (s2, p2) => s2.children(p2).some((c3) => {
|
|
|
67074
67250
|
});
|
|
67075
67251
|
function downstreamEntries(s2, p2) {
|
|
67076
67252
|
const isSet = !!s2.node(p2)?.meta?.set;
|
|
67077
|
-
let own = s2
|
|
67078
|
-
const seen = new Set(own.map((e3) => relKey(e3.label, e3.to)));
|
|
67253
|
+
let own = ownedEntries(s2, p2).filter((e3) => !(e3.kind === "contain" && isHidden(s2, e3.to)));
|
|
67254
|
+
const seen = new Set(own.map((e3) => relKey(e3.label, e3.to || e3.raw || "")));
|
|
67079
67255
|
if (isSet) {
|
|
67080
67256
|
const kept = /* @__PURE__ */ new Set();
|
|
67081
67257
|
own = own.filter((e3) => {
|
|
67082
|
-
const k = relKey(e3.label, e3.to);
|
|
67258
|
+
const k = relKey(e3.label, e3.to || e3.raw || "");
|
|
67083
67259
|
if (kept.has(k)) return false;
|
|
67084
67260
|
kept.add(k);
|
|
67085
67261
|
return true;
|
|
@@ -67108,6 +67284,7 @@ function projectValue(dataRoot, s2, segs, depth, top) {
|
|
|
67108
67284
|
const currentDoc = documentRootSegs(s2, segs);
|
|
67109
67285
|
const project = (c3) => {
|
|
67110
67286
|
if (c3.kind === "contain") return projectValue(dataRoot, s2, [...segs, c3.label ?? c3.pos ?? 0], depth - 1, false);
|
|
67287
|
+
if (!c3.to) return refMarker(c3.raw ?? "", null);
|
|
67111
67288
|
const targetSegs = storePathToSegs(c3.to);
|
|
67112
67289
|
return depth === Infinity ? refMarker(refPointerText(s2, targetSegs, currentDoc), segsToStr(targetSegs)) : linkMarker(dataRoot, s2, targetSegs);
|
|
67113
67290
|
};
|
|
@@ -67115,6 +67292,7 @@ function projectValue(dataRoot, s2, segs, depth, top) {
|
|
|
67115
67292
|
if (k === "omni" || k === "mix") {
|
|
67116
67293
|
const entries = kids.map((c3) => ({ key: c3.label, value: project(c3) }));
|
|
67117
67294
|
const marker = { kind: k, entries };
|
|
67295
|
+
if (row.format) marker.format = row.format;
|
|
67118
67296
|
if (k === "omni") {
|
|
67119
67297
|
marker.value = row.type === "blob" ? binaryValueMarker(segs, row) : wireScalar(row.value);
|
|
67120
67298
|
if (typeof row.meta?.selfAt === "number") marker.selfAt = row.meta.selfAt;
|
|
@@ -67145,8 +67323,25 @@ function irNodeAt(doc, segs) {
|
|
|
67145
67323
|
}
|
|
67146
67324
|
return node;
|
|
67147
67325
|
}
|
|
67326
|
+
function scalarRawToken(node) {
|
|
67327
|
+
if (isPointer(node) || node.kind !== "scalar") return void 0;
|
|
67328
|
+
const raw = node.raw;
|
|
67329
|
+
if (raw == null || raw.includes("\n")) return void 0;
|
|
67330
|
+
const v = node.value;
|
|
67331
|
+
if (typeof v === "string" && v.includes("\n")) return void 0;
|
|
67332
|
+
const plain = v === null ? "null" : String(v);
|
|
67333
|
+
return raw === plain ? void 0 : raw;
|
|
67334
|
+
}
|
|
67148
67335
|
function tagOf(n2) {
|
|
67149
|
-
|
|
67336
|
+
const parts = [];
|
|
67337
|
+
if (n2.meta?.schema !== void 0) {
|
|
67338
|
+
try {
|
|
67339
|
+
parts.push(schemaTagToken(n2.meta.schema));
|
|
67340
|
+
} catch {
|
|
67341
|
+
}
|
|
67342
|
+
}
|
|
67343
|
+
if (n2.meta?.set) parts.push("!!set");
|
|
67344
|
+
return parts.length ? parts.join(" ") : void 0;
|
|
67150
67345
|
}
|
|
67151
67346
|
function nodeDeco(bucket, node) {
|
|
67152
67347
|
const anchors = (node.meta?.anchors ?? []).map(anchorBody);
|
|
@@ -67163,7 +67358,9 @@ function collectComments(doc, segs, depth) {
|
|
|
67163
67358
|
{
|
|
67164
67359
|
const self2 = {};
|
|
67165
67360
|
nodeDeco(self2, root);
|
|
67166
|
-
|
|
67361
|
+
const raw = scalarRawToken(root);
|
|
67362
|
+
if (raw) self2.raw = raw;
|
|
67363
|
+
if (self2.anchors || self2.tag || self2.valueTrailing || self2.raw) out[""] = self2;
|
|
67167
67364
|
}
|
|
67168
67365
|
const head = (root.meta?.head ?? []).map((c3) => c3.text);
|
|
67169
67366
|
if (head.length > 0) out.$head = head;
|
|
@@ -67186,7 +67383,11 @@ function collectComments(doc, segs, depth) {
|
|
|
67186
67383
|
const leadComment = e3.meta?.comments?.find((c3) => c3.placement === "leading");
|
|
67187
67384
|
if (e3.meta?.blankBefore || leadComment?.blankBefore) bucket.blankBefore = true;
|
|
67188
67385
|
if (isPointer(e3.value)) bucket.pointer = renderPointer(e3.value);
|
|
67189
|
-
else
|
|
67386
|
+
else {
|
|
67387
|
+
nodeDeco(bucket, e3.value);
|
|
67388
|
+
const raw = scalarRawToken(e3.value);
|
|
67389
|
+
if (raw) bucket.raw = raw;
|
|
67390
|
+
}
|
|
67190
67391
|
if (Object.keys(bucket).length > 0) out[rel + cont] = bucket;
|
|
67191
67392
|
if (e3.edge === "contain" && !isPointer(e3.value)) walk(e3.value, rel + cont, d - 1, false);
|
|
67192
67393
|
}
|
|
@@ -67203,7 +67404,7 @@ function projectSchema(dataRoot, s2, segs, depth, top) {
|
|
|
67203
67404
|
const schema = { type: typeName(s2, p2, row) };
|
|
67204
67405
|
if (row.format) schema.format = row.format;
|
|
67205
67406
|
const kids = downstreamEntries(s2, p2);
|
|
67206
|
-
const sub = (c3) => c3.kind === "contain" ? projectSchema(dataRoot, s2, [...segs, c3.label ?? c3.pos ?? 0], depth - 1, false) : linkMarker(dataRoot, s2, storePathToSegs(c3.to));
|
|
67407
|
+
const sub = (c3) => c3.kind === "contain" ? projectSchema(dataRoot, s2, [...segs, c3.label ?? c3.pos ?? 0], depth - 1, false) : c3.to ? linkMarker(dataRoot, s2, storePathToSegs(c3.to)) : refMarker(c3.raw ?? "", null);
|
|
67207
67408
|
if (k === "object" || k === "mix" || k === "omni") {
|
|
67208
67409
|
const props = {};
|
|
67209
67410
|
for (const c3 of kids) props[c3.label ?? `[${c3.pos}]`] = sub(c3);
|
|
@@ -67235,7 +67436,9 @@ function linkMarker(dataRoot, s2, segs) {
|
|
|
67235
67436
|
else if (k === "omni" || k === "mix") {
|
|
67236
67437
|
info.count = ownedEntries(s2, p2).length;
|
|
67237
67438
|
if (k === "omni") info.value = wireScalar(row.value);
|
|
67238
|
-
} else
|
|
67439
|
+
} else {
|
|
67440
|
+
info.count = ownedEntries(s2, p2).filter((e3) => !(e3.kind === "contain" && isHidden(s2, e3.to))).length;
|
|
67441
|
+
}
|
|
67239
67442
|
if (row.format === TAG_FORMAT) {
|
|
67240
67443
|
const c3 = s2.node(p2 + ":color")?.value;
|
|
67241
67444
|
if (typeof c3 === "string") info.color = c3;
|
|
@@ -67318,7 +67521,13 @@ function chapterOrderedChildren(s2, p2, format) {
|
|
|
67318
67521
|
const bodyPos = /* @__PURE__ */ new Map();
|
|
67319
67522
|
for (const e3 of s2.entries(p2)) if (e3.kind === "ref" && !bodyPos.has(e3.to)) bodyPos.set(e3.to, e3.pos ?? 0);
|
|
67320
67523
|
if (bodyPos.size === 0) return kids;
|
|
67321
|
-
const
|
|
67524
|
+
const maxPos = Math.max(...bodyPos.values(), ...kids.map((c3) => c3.pos ?? 0));
|
|
67525
|
+
const key = (c3) => {
|
|
67526
|
+
const bp = bodyPos.get(c3.to);
|
|
67527
|
+
if (bp != null) return bp;
|
|
67528
|
+
if (c3.label != null) return maxPos + 1 + (c3.pos ?? 0);
|
|
67529
|
+
return c3.pos ?? 0;
|
|
67530
|
+
};
|
|
67322
67531
|
return kids.map((c3, i2) => ({ c: c3, i: i2 })).sort((a2, b) => key(a2.c) - key(b.c) || a2.i - b.i).map((x2) => x2.c);
|
|
67323
67532
|
}
|
|
67324
67533
|
function labelFor(s2, p2, keyOrIdx) {
|
|
@@ -67663,16 +67872,24 @@ function nearestDirSegs(dataRoot, segs) {
|
|
|
67663
67872
|
}
|
|
67664
67873
|
return null;
|
|
67665
67874
|
}
|
|
67666
|
-
|
|
67875
|
+
var YAMLOVER_ONLY = /\.yamlover$/i;
|
|
67876
|
+
var BLOCK_YAML = /\.(ya?ml|yamlover)$/i;
|
|
67877
|
+
var JSON_FILE = /\.(json|json5|json5p)$/i;
|
|
67878
|
+
function resolveBacking(dataRoot, s2, segs) {
|
|
67667
67879
|
const docSegs = documentRootSegs(s2, segs);
|
|
67668
67880
|
const docFs = path10.resolve(dataRoot, ...docSegs.map(String));
|
|
67669
67881
|
const dirBacked = fs10.existsSync(docFs) && fs10.statSync(docFs).isDirectory();
|
|
67670
67882
|
const bodyFile = dirBacked ? path10.join(docFs, ".yamlover", "body.yamlover") : docFs;
|
|
67671
|
-
if (!bodyFile.endsWith(".yamlover") || !fs10.existsSync(bodyFile)) {
|
|
67672
|
-
throw new Error("unsupported chapter source (need a .yamlover body)");
|
|
67673
|
-
}
|
|
67674
67883
|
return { docSegs, bodyFile, dirBacked };
|
|
67675
67884
|
}
|
|
67885
|
+
function chapterSource(dataRoot, s2, segs, allow = YAMLOVER_ONLY) {
|
|
67886
|
+
const r2 = resolveBacking(dataRoot, s2, segs);
|
|
67887
|
+
const okExt = r2.dirBacked ? r2.bodyFile.endsWith(".yamlover") : allow.test(r2.bodyFile);
|
|
67888
|
+
if (!okExt || !fs10.existsSync(r2.bodyFile)) {
|
|
67889
|
+
throw new Error("unsupported edit source (need a .yamlover / .yaml / .yml body)");
|
|
67890
|
+
}
|
|
67891
|
+
return r2;
|
|
67892
|
+
}
|
|
67676
67893
|
function pasteIntoChapter(dataRoot, s2, segs, name, bytes) {
|
|
67677
67894
|
const { docSegs, bodyFile, dirBacked } = chapterSource(dataRoot, s2, segs);
|
|
67678
67895
|
const writeDirSegs = dirBacked ? docSegs : docSegs.slice(0, -1);
|
|
@@ -67902,8 +68119,11 @@ function textChunkLines(text, indent) {
|
|
|
67902
68119
|
function chapterEntries(lines, r2) {
|
|
67903
68120
|
const starts = [];
|
|
67904
68121
|
if (r2.marker >= 0) {
|
|
67905
|
-
const
|
|
67906
|
-
if (
|
|
68122
|
+
const raw = lines[r2.marker].replace(/^\s*/, "");
|
|
68123
|
+
if (raw === "-" || raw.startsWith("- ")) {
|
|
68124
|
+
const inline = raw.replace(/^-\s*/, "").replace(/^!!<[^>]*>\s*/, "");
|
|
68125
|
+
if (inline.trim()) starts.push({ key: /^-/.test(inline) ? null : inline.match(/^([^:\s]+):/)?.[1] ?? null, start: r2.marker, inline: true });
|
|
68126
|
+
}
|
|
67907
68127
|
}
|
|
67908
68128
|
for (let i2 = r2.lo; i2 < r2.hi; i2++) {
|
|
67909
68129
|
if (!isContentLine2(lines[i2])) continue;
|
|
@@ -67934,7 +68154,8 @@ function entryHead(lines, e3) {
|
|
|
67934
68154
|
function isContainerEntry(lines, e3, childIndent) {
|
|
67935
68155
|
const head = entryHead(lines, e3);
|
|
67936
68156
|
if (/^[|>][+-]?\d*$/.test(head.trim())) return itemHasFields(lines, e3, childIndent);
|
|
67937
|
-
|
|
68157
|
+
const bare = head.replace(/\s+#.*$/, "");
|
|
68158
|
+
if (/^[^\s"'*|>#-][^:]*:(\s|$)/.test(bare)) return true;
|
|
67938
68159
|
for (let i2 = e3.start + 1; i2 < e3.end; i2++) {
|
|
67939
68160
|
if (!isContentLine2(lines[i2])) continue;
|
|
67940
68161
|
const ind = indentOf2(lines[i2]);
|
|
@@ -68140,6 +68361,76 @@ function setRootTag(lines, meta) {
|
|
|
68140
68361
|
if (existing >= 0) lines[existing] = `!!<${meta}>`;
|
|
68141
68362
|
else lines.splice(Math.max(at, 0), 0, `!!<${meta}>`);
|
|
68142
68363
|
}
|
|
68364
|
+
function flowValueStart(raw, e3) {
|
|
68365
|
+
let i2 = indentOf2(raw);
|
|
68366
|
+
if (raw.startsWith("- ", i2)) i2 += 2;
|
|
68367
|
+
while (raw[i2] === " ") i2++;
|
|
68368
|
+
if (raw.startsWith("!!<", i2)) {
|
|
68369
|
+
const gt = raw.indexOf(">", i2);
|
|
68370
|
+
if (gt < 0) return -1;
|
|
68371
|
+
i2 = gt + 1;
|
|
68372
|
+
while (raw[i2] === " ") i2++;
|
|
68373
|
+
}
|
|
68374
|
+
if (e3.key !== null) {
|
|
68375
|
+
const c3 = raw.indexOf(":", i2);
|
|
68376
|
+
if (c3 < 0) return -1;
|
|
68377
|
+
i2 = c3 + 1;
|
|
68378
|
+
while (raw[i2] === " ") i2++;
|
|
68379
|
+
}
|
|
68380
|
+
return raw[i2] === "[" ? i2 : -1;
|
|
68381
|
+
}
|
|
68382
|
+
function scanFlowSeq(s2, open) {
|
|
68383
|
+
let depth = 0;
|
|
68384
|
+
let q = null;
|
|
68385
|
+
const cells = [];
|
|
68386
|
+
let cellStart = open + 1;
|
|
68387
|
+
for (let j = open; j < s2.length; j++) {
|
|
68388
|
+
const ch = s2[j];
|
|
68389
|
+
if (q) {
|
|
68390
|
+
if (ch === q) {
|
|
68391
|
+
if (q === "'" && s2[j + 1] === "'") j++;
|
|
68392
|
+
else q = null;
|
|
68393
|
+
}
|
|
68394
|
+
continue;
|
|
68395
|
+
}
|
|
68396
|
+
if (ch === "'" || ch === '"') q = ch;
|
|
68397
|
+
else if (ch === "[") depth++;
|
|
68398
|
+
else if (ch === "]") {
|
|
68399
|
+
depth--;
|
|
68400
|
+
if (depth === 0) {
|
|
68401
|
+
if (j > open + 1 || s2.slice(open + 1, j).trim().length) cells.push({ start: cellStart, end: j });
|
|
68402
|
+
return { close: j, cells };
|
|
68403
|
+
}
|
|
68404
|
+
} else if (ch === "," && depth === 1) {
|
|
68405
|
+
cells.push({ start: cellStart, end: j });
|
|
68406
|
+
cellStart = j + 1;
|
|
68407
|
+
}
|
|
68408
|
+
}
|
|
68409
|
+
return null;
|
|
68410
|
+
}
|
|
68411
|
+
function flowCellToken(s2) {
|
|
68412
|
+
const plain = s2.length > 0 && s2 === s2.trim() && !/[\s,[\]:#'"{}]/.test(s2) && !/^[*&\-|>!]/.test(s2);
|
|
68413
|
+
return plain ? s2 : `'${s2.replace(/'/g, "''")}'`;
|
|
68414
|
+
}
|
|
68415
|
+
function editFlowRowCell(lines, row, cellIdx, op, valueSrc) {
|
|
68416
|
+
const raw = lines[row.start];
|
|
68417
|
+
const open = flowValueStart(raw, row);
|
|
68418
|
+
if (open < 0) return false;
|
|
68419
|
+
const scan2 = scanFlowSeq(raw, open);
|
|
68420
|
+
if (!scan2) return false;
|
|
68421
|
+
if (op !== "emplace" && op !== "replace") throw new Error(`a flow-row cell supports emplace/replace only (got \`${op}\`)`);
|
|
68422
|
+
const payload = payloadFacets(valueSrc);
|
|
68423
|
+
if (payload.scalar === void 0) throw new Error("a flow-row cell takes a scalar value");
|
|
68424
|
+
const parsed = parseYamlover(payload.scalar, "cell").root;
|
|
68425
|
+
if (parsed.kind !== "scalar") throw new Error("a flow-row cell takes a scalar value");
|
|
68426
|
+
const text = String(parsed.value ?? "");
|
|
68427
|
+
if (text.includes("\n")) throw new Error("a flow-row cell cannot hold multi-line text \u2014 rewrite the row in block form (TABLE.md)");
|
|
68428
|
+
const cell = scan2.cells[cellIdx];
|
|
68429
|
+
if (!cell) throw new Error(`no cell [${cellIdx}] in the flow row (${scan2.cells.length} cells)`);
|
|
68430
|
+
const lead = cellIdx === 0 ? "" : " ";
|
|
68431
|
+
lines[row.start] = raw.slice(0, cell.start) + lead + flowCellToken(text) + raw.slice(cell.end);
|
|
68432
|
+
return true;
|
|
68433
|
+
}
|
|
68143
68434
|
function editChapterSource(src, within, op, valueSrc, meta) {
|
|
68144
68435
|
const lines = src.split("\n");
|
|
68145
68436
|
if (within.length === 0) {
|
|
@@ -68153,9 +68444,62 @@ function editChapterSource(src, within, op, valueSrc, meta) {
|
|
|
68153
68444
|
}
|
|
68154
68445
|
throw new Error(`\`${op}\` at a document root needs a key or index target`);
|
|
68155
68446
|
}
|
|
68447
|
+
const last = within[within.length - 1];
|
|
68448
|
+
if (within.length >= 2 && typeof last === "number") {
|
|
68449
|
+
const parentR = reachChapter(lines, within.slice(0, -2));
|
|
68450
|
+
const rowEntry = findEntry(lines, parentR, within[within.length - 2]);
|
|
68451
|
+
if (rowEntry && !isContainerEntry(lines, rowEntry, parentR.indent + 2) && editFlowRowCell(lines, rowEntry, last, op, valueSrc)) {
|
|
68452
|
+
return lines.join("\n");
|
|
68453
|
+
}
|
|
68454
|
+
}
|
|
68156
68455
|
assignAt(lines, reachChapter(lines, within.slice(0, -1)), within[within.length - 1], op, valueSrc, meta);
|
|
68157
68456
|
return lines.join("\n");
|
|
68158
68457
|
}
|
|
68458
|
+
function jsonValueSpan(src, es, ee) {
|
|
68459
|
+
const last = src[ee - 1];
|
|
68460
|
+
if (last === '"' || last === "'") {
|
|
68461
|
+
for (let j2 = ee - 2; j2 >= es; j2--) {
|
|
68462
|
+
if (src[j2] !== last) continue;
|
|
68463
|
+
let bs = 0;
|
|
68464
|
+
for (let k = j2 - 1; k >= es && src[k] === "\\"; k--) bs++;
|
|
68465
|
+
if (bs % 2 === 0) return [j2, ee];
|
|
68466
|
+
}
|
|
68467
|
+
throw new Error("could not locate the string value in the source");
|
|
68468
|
+
}
|
|
68469
|
+
let j = ee;
|
|
68470
|
+
while (j > es && !/[\s,:{}[\]]/.test(src[j - 1])) j--;
|
|
68471
|
+
return [j, ee];
|
|
68472
|
+
}
|
|
68473
|
+
function yamloverScalarToJsonToken(valueSrc) {
|
|
68474
|
+
const root = parseYamlover(valueSrc, "<edit>").root;
|
|
68475
|
+
if (root.kind !== "scalar") throw new Error("only a scalar value is editable in a JSON file");
|
|
68476
|
+
const v = root.value;
|
|
68477
|
+
if (v === null) return "null";
|
|
68478
|
+
if (typeof v === "boolean") return v ? "true" : "false";
|
|
68479
|
+
if (typeof v === "number") return /^[-+]?(\d+\.?\d*|\.\d+)([eE][-+]?\d+)?$/.test(root.raw) ? root.raw : String(v);
|
|
68480
|
+
return JSON.stringify(v);
|
|
68481
|
+
}
|
|
68482
|
+
function editJsonScalar(src, within, token) {
|
|
68483
|
+
if (within.length === 0) throw new Error("cannot edit the JSON document root as a scalar value");
|
|
68484
|
+
let node = parseJson5p(src, "<edit>").root;
|
|
68485
|
+
for (let k = 0; k < within.length; k++) {
|
|
68486
|
+
const seg = within[k];
|
|
68487
|
+
const entries = node.entries ?? [];
|
|
68488
|
+
const entry = typeof seg === "number" ? entries.filter((e3) => e3.edge === "contain" && e3.key === null)[seg] : entries.find((e3) => e3.edge === "contain" && e3.key === seg);
|
|
68489
|
+
if (!entry) throw new Error(`no entry at ${typeof seg === "number" ? `[${seg}]` : seg}`);
|
|
68490
|
+
const value = entry.value;
|
|
68491
|
+
if (k === within.length - 1) {
|
|
68492
|
+
if (isPointer(value) || value.kind !== "scalar") throw new Error("only a scalar value is editable in a JSON file");
|
|
68493
|
+
const span = entry.meta?.span;
|
|
68494
|
+
if (!span) throw new Error("no source span for the target value");
|
|
68495
|
+
const [vs, ve] = jsonValueSpan(src, span.start, span.end);
|
|
68496
|
+
return src.slice(0, vs) + token + src.slice(ve);
|
|
68497
|
+
}
|
|
68498
|
+
if (isPointer(value) || value.kind !== "mapping") throw new Error(`cannot descend into a non-container at ${typeof seg === "number" ? `[${seg}]` : seg}`);
|
|
68499
|
+
node = value;
|
|
68500
|
+
}
|
|
68501
|
+
throw new Error("empty JSON edit path");
|
|
68502
|
+
}
|
|
68159
68503
|
var isPointerValue = (src) => /^\*\S*$/.test(src.trim()) && !src.includes("\n");
|
|
68160
68504
|
function isPlainDir(dataRoot, s2, segs) {
|
|
68161
68505
|
if (!segs.every((g) => typeof g === "string")) return false;
|
|
@@ -68178,6 +68522,7 @@ function bornAsDocument(dataRoot, e3, tag) {
|
|
|
68178
68522
|
}
|
|
68179
68523
|
function applyEdits2(dataRoot, s2, edits) {
|
|
68180
68524
|
const byFile = /* @__PURE__ */ new Map();
|
|
68525
|
+
const jsonByFile = /* @__PURE__ */ new Map();
|
|
68181
68526
|
const appended = [];
|
|
68182
68527
|
const created = [];
|
|
68183
68528
|
for (const e3 of edits) {
|
|
@@ -68191,7 +68536,15 @@ function applyEdits2(dataRoot, s2, edits) {
|
|
|
68191
68536
|
created.push(segsToStr([...editSegs, final]));
|
|
68192
68537
|
continue;
|
|
68193
68538
|
}
|
|
68194
|
-
const
|
|
68539
|
+
const backing = resolveBacking(dataRoot, s2, editSegs);
|
|
68540
|
+
if (!backing.dirBacked && JSON_FILE.test(backing.bodyFile)) {
|
|
68541
|
+
if (op !== "emplace") throw new Error("only scalar value edits (emplace) are supported for JSON files");
|
|
68542
|
+
const jlist = jsonByFile.get(backing.bodyFile) ?? [];
|
|
68543
|
+
jlist.push({ within: editSegs.slice(backing.docSegs.length), valueSrc: String(e3.yamlover ?? "") });
|
|
68544
|
+
jsonByFile.set(backing.bodyFile, jlist);
|
|
68545
|
+
continue;
|
|
68546
|
+
}
|
|
68547
|
+
const { docSegs, bodyFile, dirBacked } = chapterSource(dataRoot, s2, editSegs, BLOCK_YAML);
|
|
68195
68548
|
if (op === "insert" && !e3.concrete?.includes("/")) {
|
|
68196
68549
|
const last = editSegs[editSegs.length - 1];
|
|
68197
68550
|
if (typeof last !== "number") appended.push(editSegs);
|
|
@@ -68232,8 +68585,55 @@ function applyEdits2(dataRoot, s2, edits) {
|
|
|
68232
68585
|
fs10.writeFileSync(bodyFile, src);
|
|
68233
68586
|
touched.push(bodyFile);
|
|
68234
68587
|
}
|
|
68588
|
+
for (const [file, jedits] of jsonByFile) {
|
|
68589
|
+
let src = fs10.readFileSync(file, "utf8");
|
|
68590
|
+
for (const j of jedits) {
|
|
68591
|
+
src = editJsonScalar(src, j.within, yamloverScalarToJsonToken(j.valueSrc));
|
|
68592
|
+
}
|
|
68593
|
+
fs10.writeFileSync(file, src);
|
|
68594
|
+
touched.push(file);
|
|
68595
|
+
}
|
|
68235
68596
|
return { touched, created, appended };
|
|
68236
68597
|
}
|
|
68598
|
+
var PREVIEW_ROOT = path10.join(os.tmpdir(), ".yamlover-preview-nonexistent");
|
|
68599
|
+
function previewPayload(source) {
|
|
68600
|
+
const doc = parseYamlover(source, "<preview>");
|
|
68601
|
+
doc.root.meta = { ...doc.root.meta, documentRoot: true, ...doc.head?.length ? { head: doc.head } : {} };
|
|
68602
|
+
const s2 = new Store(":memory:");
|
|
68603
|
+
try {
|
|
68604
|
+
s2.indexDocument(doc);
|
|
68605
|
+
const row = s2.node(":");
|
|
68606
|
+
return {
|
|
68607
|
+
path: ":",
|
|
68608
|
+
type: tocType(s2, ":", row),
|
|
68609
|
+
format: row.format ?? null,
|
|
68610
|
+
...facetsOf(s2, ":", row),
|
|
68611
|
+
concrete: "yamlover",
|
|
68612
|
+
// by construction — the document IS yamlover text
|
|
68613
|
+
documentPath: ":",
|
|
68614
|
+
title: titleOf(s2, ":"),
|
|
68615
|
+
description: descriptionOf(s2, ":"),
|
|
68616
|
+
value: projectValue(PREVIEW_ROOT, s2, [], Infinity, true),
|
|
68617
|
+
comments: collectComments(doc, [], Infinity),
|
|
68618
|
+
relations: {}
|
|
68619
|
+
// a standalone document has no project around it
|
|
68620
|
+
};
|
|
68621
|
+
} finally {
|
|
68622
|
+
s2.close();
|
|
68623
|
+
}
|
|
68624
|
+
}
|
|
68625
|
+
function applyTextEdits(src, edits) {
|
|
68626
|
+
let out = src;
|
|
68627
|
+
for (const e3 of edits) {
|
|
68628
|
+
if (e3.concrete || e3.name) throw new Error("`concrete`/`name` are only for file-backed edits");
|
|
68629
|
+
const valueSrc = String(e3.yamlover ?? "");
|
|
68630
|
+
const meta = e3.meta === void 0 ? void 0 : e3.meta === null ? null : String(e3.meta);
|
|
68631
|
+
if (valueSrc && !isPointerValue(valueSrc)) parseYamlover(valueSrc, "<edit>");
|
|
68632
|
+
out = editChapterSource(out, strToSegs(String(e3.path ?? "")), String(e3.op ?? ""), valueSrc, meta);
|
|
68633
|
+
}
|
|
68634
|
+
parseYamlover(out, "<edit-result>");
|
|
68635
|
+
return out;
|
|
68636
|
+
}
|
|
68237
68637
|
function firstContentIndent2(lines) {
|
|
68238
68638
|
for (const l2 of lines) if (isContentLine2(l2)) return indentOf2(l2);
|
|
68239
68639
|
return 0;
|
|
@@ -68354,8 +68754,10 @@ function notFound(res, url) {
|
|
|
68354
68754
|
sendJson(res, 404, { error: `no such node/endpoint: ${url.pathname}?${url.searchParams}` });
|
|
68355
68755
|
}
|
|
68356
68756
|
export {
|
|
68757
|
+
applyTextEdits,
|
|
68357
68758
|
createHandlers,
|
|
68358
|
-
mergeAgentDoc
|
|
68759
|
+
mergeAgentDoc,
|
|
68760
|
+
previewPayload
|
|
68359
68761
|
};
|
|
68360
68762
|
/*! Bundled license information:
|
|
68361
68763
|
|