@seed-hypermedia/client 0.0.81 → 0.0.82
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/block-diff.mjs +1 -1
- package/dist/blocks-to-markdown.d.ts +16 -11
- package/dist/blocks-to-markdown.mjs +1 -1
- package/dist/{chunk-OZKQOI2X.mjs → chunk-3KLY2B27.mjs} +51 -4
- package/dist/{chunk-YH52VFVR.mjs → chunk-TET43O3D.mjs} +296 -178
- package/dist/chunk-XB6E7EVC.mjs +872 -0
- package/dist/index.mjs +3 -3
- package/dist/markdown-to-blocks.d.ts +27 -32
- package/dist/markdown-to-blocks.mjs +3 -1
- package/package.json +1 -1
- package/dist/chunk-H7L4TI6X.mjs +0 -705
package/dist/block-diff.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Seed block tree → Markdown formatter.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
4
|
+
* The lossless half of the markdown pair (see `markdown-to-blocks.ts` for the
|
|
5
|
+
* dialect). Converts HMDocument/HMBlockNode trees to markdown with:
|
|
6
|
+
* - YAML frontmatter carrying every metadata key
|
|
7
|
+
* - a trailing `<!-- id:X [type:T] [attrs:{…}] -->` comment on every block
|
|
8
|
+
* - nesting by indentation, heading level by heading depth
|
|
9
|
+
* - annotations as markdown markers, split at boundaries so they nest
|
|
8
10
|
*
|
|
9
11
|
* This module is purely synchronous and does NOT resolve embeds, mentions,
|
|
10
|
-
* or queries over the network. For resolved output,
|
|
11
|
-
* which
|
|
12
|
+
* or queries over the network. For resolved output, see the
|
|
13
|
+
* `documentToResolvedMarkdown` family below, which is a display format and
|
|
14
|
+
* not round-trip safe.
|
|
12
15
|
*
|
|
13
|
-
* Round-trip
|
|
14
|
-
*
|
|
16
|
+
* Round-trip: `parseMarkdown(blocksToMarkdown(doc))` reproduces `doc`, and
|
|
17
|
+
* exporting that parse reproduces the same markdown. Use
|
|
18
|
+
* `{ipfsGateway: false}` to keep `ipfs://` links verbatim.
|
|
15
19
|
*/
|
|
16
20
|
import type { SeedClient } from './client';
|
|
17
21
|
import type { HMBlockNode, HMComment, HMDocument, HMMetadata } from './hm-types';
|
|
@@ -20,9 +24,10 @@ export type BlocksToMarkdownOptions = {
|
|
|
20
24
|
ipfsGateway?: boolean;
|
|
21
25
|
};
|
|
22
26
|
/**
|
|
23
|
-
* Emit YAML frontmatter from HMMetadata.
|
|
24
|
-
*
|
|
25
|
-
* System fields (authors, version, genesis, account) are
|
|
27
|
+
* Emit YAML frontmatter from HMMetadata. Every defined key is emitted,
|
|
28
|
+
* including nested values and keys this client does not know about.
|
|
29
|
+
* System fields (authors, version, genesis, account) are not metadata and
|
|
30
|
+
* are never present here.
|
|
26
31
|
*/
|
|
27
32
|
export declare function emitFrontmatter(metadata: HMMetadata): string;
|
|
28
33
|
/**
|
|
@@ -24,7 +24,7 @@ function matchBlockIds(oldNodes, newNodes) {
|
|
|
24
24
|
if (oldNode && oldNode.block.type === newNode.block.type) {
|
|
25
25
|
matchedId = oldNode.block.id;
|
|
26
26
|
}
|
|
27
|
-
const matchedChildren = matchBlockIds((oldNode == null ? void 0 : oldNode.children) ?? [], newNode.children);
|
|
27
|
+
const matchedChildren = newNode.block.type === "Table" ? newNode.children : matchBlockIds((oldNode == null ? void 0 : oldNode.children) ?? [], newNode.children);
|
|
28
28
|
return {
|
|
29
29
|
block: { ...newNode.block, id: matchedId },
|
|
30
30
|
children: matchedChildren
|
|
@@ -217,6 +217,19 @@ function computeReplaceOps(oldMap, matchedTree, parentId = "") {
|
|
|
217
217
|
}
|
|
218
218
|
return ops;
|
|
219
219
|
}
|
|
220
|
+
function oldSiblingOrder(oldMap, parentId) {
|
|
221
|
+
const byLeft = /* @__PURE__ */ new Map();
|
|
222
|
+
for (const [id, entry] of Object.entries(oldMap)) {
|
|
223
|
+
if (entry.parent === parentId) byLeft.set(entry.left, id);
|
|
224
|
+
}
|
|
225
|
+
const order = [];
|
|
226
|
+
let cur = byLeft.get("");
|
|
227
|
+
while (cur !== void 0 && !order.includes(cur)) {
|
|
228
|
+
order.push(cur);
|
|
229
|
+
cur = byLeft.get(cur);
|
|
230
|
+
}
|
|
231
|
+
return order;
|
|
232
|
+
}
|
|
220
233
|
function computeReplaceOpsInner(oldMap, matchedTree, parentId, touchedIds) {
|
|
221
234
|
const ops = [];
|
|
222
235
|
const blockIdsAtLevel = [];
|
|
@@ -253,7 +266,9 @@ function computeReplaceOpsInner(oldMap, matchedTree, parentId, touchedIds) {
|
|
|
253
266
|
ops.push(...computeReplaceOpsInner(oldMap, node.children, blockId, touchedIds));
|
|
254
267
|
}
|
|
255
268
|
});
|
|
256
|
-
|
|
269
|
+
const oldOrder = oldSiblingOrder(oldMap, parentId);
|
|
270
|
+
const sameOrder = oldOrder.length === blockIdsAtLevel.length && blockIdsAtLevel.every((id, i) => oldOrder[i] === id);
|
|
271
|
+
if (blockIdsAtLevel.length > 0 && !sameOrder) {
|
|
257
272
|
ops.push({
|
|
258
273
|
type: "MoveBlocks",
|
|
259
274
|
blocks: blockIdsAtLevel,
|
|
@@ -272,12 +287,44 @@ function attrsEqual(a, b) {
|
|
|
272
287
|
}
|
|
273
288
|
return true;
|
|
274
289
|
}
|
|
290
|
+
function compareAnnotations(a, b) {
|
|
291
|
+
var _a, _b, _c, _d;
|
|
292
|
+
const sa = ((_a = a.starts) == null ? void 0 : _a[0]) ?? 0;
|
|
293
|
+
const sb = ((_b = b.starts) == null ? void 0 : _b[0]) ?? 0;
|
|
294
|
+
const ea = ((_c = a.ends) == null ? void 0 : _c[0]) ?? 0;
|
|
295
|
+
const eb = ((_d = b.ends) == null ? void 0 : _d[0]) ?? 0;
|
|
296
|
+
return sa - sb || eb - ea || String(a.type).localeCompare(String(b.type));
|
|
297
|
+
}
|
|
298
|
+
function hasRange(a) {
|
|
299
|
+
const starts = a.starts || [];
|
|
300
|
+
const ends = a.ends || [];
|
|
301
|
+
return starts.some((s, i) => (ends[i] ?? -1) > s);
|
|
302
|
+
}
|
|
303
|
+
function canonicalAnnotation(ann) {
|
|
304
|
+
const a = ann || {};
|
|
305
|
+
const starts = a.starts || [];
|
|
306
|
+
const ends = a.ends || [];
|
|
307
|
+
const keep = starts.map((_, i) => i).filter((i) => (ends[i] ?? -1) > starts[i]);
|
|
308
|
+
const out = {
|
|
309
|
+
type: a.type,
|
|
310
|
+
starts: keep.map((i) => starts[i]),
|
|
311
|
+
ends: keep.map((i) => ends[i])
|
|
312
|
+
};
|
|
313
|
+
if (a.link) out.link = a.link;
|
|
314
|
+
const attrs = a.attributes;
|
|
315
|
+
if (attrs && Object.keys(attrs).length > 0) {
|
|
316
|
+
const sorted = {};
|
|
317
|
+
for (const k of Object.keys(attrs).sort()) sorted[k] = attrs[k];
|
|
318
|
+
out.attributes = sorted;
|
|
319
|
+
}
|
|
320
|
+
return out;
|
|
321
|
+
}
|
|
275
322
|
function isBlockContentEqual(old, newBlock) {
|
|
276
323
|
if (old.type !== newBlock.type) return false;
|
|
277
324
|
if ((old.text || "") !== (newBlock.text || "")) return false;
|
|
278
325
|
if ((old.link || "") !== (newBlock.link || "")) return false;
|
|
279
|
-
const oldAnn = old.annotations || [];
|
|
280
|
-
const newAnn = newBlock.annotations || [];
|
|
326
|
+
const oldAnn = (old.annotations || []).map(canonicalAnnotation).filter(hasRange).sort(compareAnnotations);
|
|
327
|
+
const newAnn = (newBlock.annotations || []).map(canonicalAnnotation).filter(hasRange).sort(compareAnnotations);
|
|
281
328
|
if (oldAnn.length !== newAnn.length) return false;
|
|
282
329
|
if (oldAnn.length > 0 && JSON.stringify(oldAnn) !== JSON.stringify(newAnn)) {
|
|
283
330
|
return false;
|