@seed-hypermedia/client 0.0.81 → 0.0.83

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.
Files changed (38) hide show
  1. package/dist/auto-link.d.ts +3 -4
  2. package/dist/auto-link.mjs +3 -3
  3. package/dist/block-diff.mjs +1 -1
  4. package/dist/blocks-to-markdown.d.ts +16 -11
  5. package/dist/blocks-to-markdown.mjs +2 -2
  6. package/dist/capability.mjs +2 -2
  7. package/dist/{chunk-MZENVC36.mjs → chunk-2GOQZ3DV.mjs} +1 -1
  8. package/dist/{chunk-OZKQOI2X.mjs → chunk-3KLY2B27.mjs} +51 -4
  9. package/dist/{chunk-D2LTD2KZ.mjs → chunk-4VD46ULS.mjs} +1 -1
  10. package/dist/{chunk-C42YWLL2.mjs → chunk-CRMBYTZY.mjs} +1 -1
  11. package/dist/{chunk-2OMSCQ56.mjs → chunk-E4PGX55A.mjs} +1 -1
  12. package/dist/{chunk-YH52VFVR.mjs → chunk-E6YSFT63.mjs} +304 -185
  13. package/dist/{chunk-IREIRKVP.mjs → chunk-IOXGTLKJ.mjs} +1 -1
  14. package/dist/{chunk-MZUGCZJ6.mjs → chunk-KMQYEO46.mjs} +38 -11
  15. package/dist/{chunk-LCKCG574.mjs → chunk-NVWWEHIS.mjs} +1 -1
  16. package/dist/{chunk-RCVLNXG6.mjs → chunk-QBYF2PVS.mjs} +1 -1
  17. package/dist/{chunk-55OXHA27.mjs → chunk-SIYJHDMJ.mjs} +4 -2
  18. package/dist/{chunk-WGOIXGRU.mjs → chunk-TUSTJXWH.mjs} +3 -3
  19. package/dist/{chunk-BO2QSSIU.mjs → chunk-V2UNLCDS.mjs} +1 -1
  20. package/dist/{chunk-AIQJ6BI3.mjs → chunk-WJRXPYFE.mjs} +1 -1
  21. package/dist/chunk-XB6E7EVC.mjs +872 -0
  22. package/dist/client.mjs +2 -2
  23. package/dist/comment.mjs +2 -2
  24. package/dist/document-state.mjs +2 -2
  25. package/dist/editorblock-to-hmblock.mjs +2 -2
  26. package/dist/hm-resolver.mjs +2 -2
  27. package/dist/hm-types.d.ts +216 -114
  28. package/dist/hm-types.mjs +5 -1
  29. package/dist/hmblock-to-editorblock.mjs +2 -2
  30. package/dist/index.mjs +15 -15
  31. package/dist/markdown-to-blocks.d.ts +27 -32
  32. package/dist/markdown-to-blocks.mjs +3 -1
  33. package/dist/pdf-to-blocks.mjs +3 -3
  34. package/dist/resource-read.mjs +4 -4
  35. package/dist/tei-to-blocks.mjs +2 -2
  36. package/dist/unicode.mjs +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-H7L4TI6X.mjs +0 -705
@@ -22,10 +22,9 @@ export declare function documentContainsLinkToChild(document: HMDocument, childI
22
22
  * Check if a document has a self-referential Query block
23
23
  * (a query to itself that would automatically include children).
24
24
  *
25
- * A query block is self-referential when one of its `query.includes` entries
26
- * has `space === documentId.uid` AND a path that, after normalization, equals
27
- * the document's path. Empty `space` or `path` does not count as self — that
28
- * represents an unconfigured query block, which the editor renders empty.
25
+ * A query block is self-referential when its target is implicit/empty or one
26
+ * of its `query.includes` entries targets the document. New Collections use
27
+ * the implicit empty target until it is resolved against their published ID.
29
28
  */
30
29
  export declare function documentHasSelfQuery(document: HMDocument, documentId: UnpackedHypermediaId): boolean;
31
30
  /**
@@ -4,13 +4,13 @@ import {
4
4
  documentContainsLinkToChild,
5
5
  documentHasSelfQuery,
6
6
  shouldAutoLinkParent
7
- } from "./chunk-55OXHA27.mjs";
7
+ } from "./chunk-SIYJHDMJ.mjs";
8
8
  import "./chunk-JT57MV7Y.mjs";
9
9
  import "./chunk-PJ2RFT5A.mjs";
10
- import "./chunk-C42YWLL2.mjs";
10
+ import "./chunk-CRMBYTZY.mjs";
11
11
  import "./chunk-LVAHHQIK.mjs";
12
12
  import "./chunk-DR3HJ6BV.mjs";
13
- import "./chunk-MZUGCZJ6.mjs";
13
+ import "./chunk-KMQYEO46.mjs";
14
14
  import "./chunk-7P6ASYW6.mjs";
15
15
  export {
16
16
  autoLinkChildToParent,
@@ -5,7 +5,7 @@ import {
5
5
  matchBlockIds,
6
6
  rebindTableIdentities,
7
7
  toAPIBlockNode
8
- } from "./chunk-OZKQOI2X.mjs";
8
+ } from "./chunk-3KLY2B27.mjs";
9
9
  import "./chunk-7P6ASYW6.mjs";
10
10
  export {
11
11
  computeReplaceOps,
@@ -1,17 +1,21 @@
1
1
  /**
2
2
  * Seed block tree → Markdown formatter.
3
3
  *
4
- * Converts HMDocument/HMBlockNode trees to markdown with:
5
- * - YAML frontmatter (always emitted, all HMMetadata fields)
6
- * - Block IDs preserved as HTML comments (<!-- id:XXXXXXXX -->)
7
- * - Inline annotations rendered as markdown formatting
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, use the CLI's wrapper
11
- * which adds a SeedClient-backed resolve layer on top.
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 compatible: output can be piped back through `parseMarkdown()`
14
- * to recreate the same document with block IDs preserved.
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
- * Only includes fields that have defined, non-empty values.
25
- * System fields (authors, version, genesis, account) are NOT emitted.
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
  /**
@@ -7,8 +7,8 @@ import {
7
7
  emitFrontmatter,
8
8
  parseDraftFilename,
9
9
  slugify
10
- } from "./chunk-YH52VFVR.mjs";
11
- import "./chunk-MZUGCZJ6.mjs";
10
+ } from "./chunk-E6YSFT63.mjs";
11
+ import "./chunk-KMQYEO46.mjs";
12
12
  import "./chunk-7P6ASYW6.mjs";
13
13
  export {
14
14
  blocksToMarkdown,
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  createCapability,
3
3
  resolveCapability
4
- } from "./chunk-BO2QSSIU.mjs";
4
+ } from "./chunk-V2UNLCDS.mjs";
5
5
  import "./chunk-LVAHHQIK.mjs";
6
6
  import "./chunk-NBCHK76Q.mjs";
7
7
  import "./chunk-DR3HJ6BV.mjs";
8
- import "./chunk-MZUGCZJ6.mjs";
8
+ import "./chunk-KMQYEO46.mjs";
9
9
  import "./chunk-3TPCJCVO.mjs";
10
10
  import "./chunk-7P6ASYW6.mjs";
11
11
  export {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  codePointLength
3
- } from "./chunk-MZUGCZJ6.mjs";
3
+ } from "./chunk-KMQYEO46.mjs";
4
4
 
5
5
  // src/tei-to-blocks.ts
6
6
  function generateBlockId() {
@@ -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
- if (blockIdsAtLevel.length > 0) {
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;
@@ -2,7 +2,7 @@ import {
2
2
  entityQueryPathToHmIdPath,
3
3
  parseFragment,
4
4
  unpackHmId
5
- } from "./chunk-MZUGCZJ6.mjs";
5
+ } from "./chunk-KMQYEO46.mjs";
6
6
 
7
7
  // src/hm-resolver.ts
8
8
  async function resolveHypermediaUrl(url, opts) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  packHmId,
3
3
  unpackHmId
4
- } from "./chunk-MZUGCZJ6.mjs";
4
+ } from "./chunk-KMQYEO46.mjs";
5
5
 
6
6
  // src/document-state.ts
7
7
  async function resolveDocumentState(client, targetId) {
@@ -6,7 +6,7 @@ import {
6
6
  HMBlockSchema,
7
7
  codePointLength,
8
8
  toNumber
9
- } from "./chunk-MZUGCZJ6.mjs";
9
+ } from "./chunk-KMQYEO46.mjs";
10
10
 
11
11
  // src/editorblock-to-hmblock.ts
12
12
  function toHMBlockType(editorBlockType) {