@relyio/sdk 0.12.0 → 0.14.0

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 (48) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/dist/{chunk-3DRDHXLY.js → chunk-5UMY6CS4.js} +435 -23
  3. package/dist/{chunk-FRJEUAAF.js → chunk-DBBZVZOS.js} +968 -2670
  4. package/dist/{chunk-DXCVO6M5.cjs → chunk-GUPV2M3X.cjs} +969 -2680
  5. package/dist/{chunk-POEEDYFM.js → chunk-PCFTJLEP.js} +543 -260
  6. package/dist/{chunk-FI5VIF4M.cjs → chunk-RSHMA4KT.cjs} +442 -22
  7. package/dist/{chunk-3MSFWXQL.cjs → chunk-X4KSS7PP.cjs} +542 -260
  8. package/dist/client/index.cjs +3 -3
  9. package/dist/client/index.d.cts +4 -5
  10. package/dist/client/index.d.ts +4 -5
  11. package/dist/client/index.js +1 -1
  12. package/dist/{include-paths-CL4gHv6I.d.cts → define-content-type-BUZeWtpk.d.cts} +4458 -1312
  13. package/dist/{include-paths-CrJNTsMl.d.ts → define-content-type-DOrZb_a_.d.ts} +4458 -1312
  14. package/dist/define-schema-5aHmsA8j.d.ts +699 -0
  15. package/dist/define-schema-nCfZeboB.d.cts +699 -0
  16. package/dist/index-B97ZDj44.d.ts +507 -0
  17. package/dist/index-C-pcllqY.d.cts +507 -0
  18. package/dist/index-DOhFQbv7.d.ts +3065 -0
  19. package/dist/index-DgVV5Nj7.d.cts +3065 -0
  20. package/dist/index.cjs +114 -147
  21. package/dist/index.d.cts +49 -87
  22. package/dist/index.d.ts +49 -87
  23. package/dist/index.js +5 -29
  24. package/dist/markdown/index.cjs +13750 -0
  25. package/dist/markdown/index.d.cts +111 -0
  26. package/dist/markdown/index.d.ts +111 -0
  27. package/dist/markdown/index.js +13742 -0
  28. package/dist/rich-text/index.cjs +26 -6
  29. package/dist/rich-text/index.d.cts +3 -148
  30. package/dist/rich-text/index.d.ts +3 -148
  31. package/dist/rich-text/index.js +1 -1
  32. package/dist/rich-text.d-BWc-5gX1.d.cts +326 -0
  33. package/dist/rich-text.d-BWc-5gX1.d.ts +326 -0
  34. package/dist/schema/index.cjs +33 -37
  35. package/dist/schema/index.d.cts +37 -191
  36. package/dist/schema/index.d.ts +37 -191
  37. package/dist/schema/index.js +1 -1
  38. package/dist/types/index.d.cts +2 -3
  39. package/dist/types/index.d.ts +2 -3
  40. package/package.json +14 -3
  41. package/dist/define-schema-DgctHlI2.d.cts +0 -1034
  42. package/dist/define-schema-mrEZbY1h.d.ts +0 -1034
  43. package/dist/index-B9RfZVF1.d.ts +0 -861
  44. package/dist/index-BrvEg6-A.d.cts +0 -3729
  45. package/dist/index-Pw0onkJe.d.ts +0 -3729
  46. package/dist/index-b-AkfTUv.d.cts +0 -861
  47. package/dist/rich-text.d-rKmpgdGd.d.cts +0 -200
  48. package/dist/rich-text.d-rKmpgdGd.d.ts +0 -200
@@ -4,20 +4,252 @@ var chunkMWMSFIWN_cjs = require('./chunk-MWMSFIWN.cjs');
4
4
 
5
5
  /* RelyIO SDK - Built with ❤️ by the RelyIO Team */
6
6
 
7
+ // src/rich-text/anchors.ts
8
+ function richTextHeadingSlug(text) {
9
+ return text.trim().toLowerCase().replace(/[^\p{L}\p{M}\p{N}\s_-]/gu, "").replace(/\s/gu, "-");
10
+ }
11
+ chunkMWMSFIWN_cjs.__name(richTextHeadingSlug, "richTextHeadingSlug");
12
+ function isRecord(value) {
13
+ return typeof value === "object" && value !== null && !Array.isArray(value);
14
+ }
15
+ chunkMWMSFIWN_cjs.__name(isRecord, "isRecord");
16
+ var BUILT_IN_CONTAINERS = /* @__PURE__ */ new Set([
17
+ "paragraph",
18
+ "heading",
19
+ "quote",
20
+ "list",
21
+ "listItem",
22
+ "codeGroup",
23
+ "table",
24
+ "tableRow",
25
+ "tableCell"
26
+ ]);
27
+ function headingText(heading) {
28
+ if (!Array.isArray(heading.children)) return "";
29
+ let text = "";
30
+ for (const child of heading.children) {
31
+ if (!isRecord(child)) continue;
32
+ if (child._type === "lineBreak") text += " ";
33
+ else if (child._type === "text" && typeof child.text === "string") text += child.text;
34
+ }
35
+ return text;
36
+ }
37
+ chunkMWMSFIWN_cjs.__name(headingText, "headingText");
38
+ function richTextHeadingAnchors(value) {
39
+ return anchorsAcross([value]);
40
+ }
41
+ chunkMWMSFIWN_cjs.__name(richTextHeadingAnchors, "richTextHeadingAnchors");
42
+ function entryHeadingAnchors(entry) {
43
+ return anchorsAcross(isRecord(entry) ? Object.values(entry) : []);
44
+ }
45
+ chunkMWMSFIWN_cjs.__name(entryHeadingAnchors, "entryHeadingAnchors");
46
+ function anchorsAcross(values) {
47
+ const anchors = /* @__PURE__ */ new Map();
48
+ const taken = /* @__PURE__ */ new Map();
49
+ const unique = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((slug) => {
50
+ let anchor = slug;
51
+ const seen = taken.get(slug);
52
+ if (seen !== void 0) {
53
+ let count = seen;
54
+ do {
55
+ count += 1;
56
+ anchor = `${slug}-${count}`;
57
+ } while (taken.has(anchor));
58
+ taken.set(slug, count);
59
+ }
60
+ taken.set(anchor, 0);
61
+ return anchor;
62
+ }, "unique");
63
+ const visit = /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((nodes) => {
64
+ for (const node of nodes) {
65
+ if (!isRecord(node) || typeof node._type !== "string") continue;
66
+ if (node._type === "heading") {
67
+ const slug = richTextHeadingSlug(headingText(node));
68
+ if (slug !== "") anchors.set(node, unique(slug));
69
+ continue;
70
+ }
71
+ if (BUILT_IN_CONTAINERS.has(node._type) && Array.isArray(node.children)) visit(node.children);
72
+ }
73
+ }, "visit");
74
+ for (const value of values) {
75
+ if (isRecord(value) && value._type === "richText" && Array.isArray(value.children)) {
76
+ visit(value.children);
77
+ }
78
+ }
79
+ return anchors;
80
+ }
81
+ chunkMWMSFIWN_cjs.__name(anchorsAcross, "anchorsAcross");
82
+
83
+ // src/binding/key-path.ts
84
+ var ITEM_SELECTOR = "[_key==";
85
+ function formatKeyPath(listPath, key, field) {
86
+ const item = `${listPath}${ITEM_SELECTOR}${JSON.stringify(key)}]`;
87
+ return field === void 0 ? item : `${item}.${field}`;
88
+ }
89
+ chunkMWMSFIWN_cjs.__name(formatKeyPath, "formatKeyPath");
90
+ function parseKeyPath(path) {
91
+ const segments = [];
92
+ let at = 0;
93
+ let expectField = true;
94
+ while (at < path.length) {
95
+ if (path.startsWith(ITEM_SELECTOR, at)) {
96
+ const previous = segments[segments.length - 1];
97
+ if (expectField || previous === void 0 || !("field" in previous)) return null;
98
+ const quoted = readQuoted(path, at + ITEM_SELECTOR.length);
99
+ if (quoted === null || path[quoted.end] !== "]") return null;
100
+ segments.push({ key: quoted.value });
101
+ at = quoted.end + 1;
102
+ if (at < path.length && path[at] !== "." && !path.startsWith(ITEM_SELECTOR, at)) return null;
103
+ if (path[at] === ".") {
104
+ at += 1;
105
+ expectField = true;
106
+ }
107
+ continue;
108
+ }
109
+ let end = at;
110
+ while (end < path.length && path[end] !== "." && path[end] !== "[") end += 1;
111
+ const field = path.slice(at, end);
112
+ if (field.length === 0) return null;
113
+ segments.push({ field });
114
+ expectField = false;
115
+ at = end;
116
+ if (path[at] === ".") {
117
+ at += 1;
118
+ expectField = true;
119
+ if (at === path.length) return null;
120
+ } else if (at < path.length && !path.startsWith(ITEM_SELECTOR, at)) {
121
+ return null;
122
+ }
123
+ }
124
+ return segments.length === 0 || expectField ? null : segments;
125
+ }
126
+ chunkMWMSFIWN_cjs.__name(parseKeyPath, "parseKeyPath");
127
+ function readQuoted(path, start) {
128
+ if (path[start] !== '"') return null;
129
+ for (let end = start + 1; end < path.length; end += 1) {
130
+ if (path[end] === "\\") {
131
+ end += 1;
132
+ continue;
133
+ }
134
+ if (path[end] !== '"') continue;
135
+ try {
136
+ const value = JSON.parse(path.slice(start, end + 1));
137
+ return typeof value === "string" && value.length > 0 ? { value, end: end + 1 } : null;
138
+ } catch {
139
+ return null;
140
+ }
141
+ }
142
+ return null;
143
+ }
144
+ chunkMWMSFIWN_cjs.__name(readQuoted, "readQuoted");
145
+
146
+ // src/binding/relyio-field.ts
147
+ var BINDING_VERSION = "1";
148
+ function relyioField(subject, path) {
149
+ if (subject === void 0) return void 0;
150
+ if (isBindingShaped(subject)) return continued(subject, path);
151
+ const field = typeof path === "string" ? path : String(path);
152
+ const metadata = subject._metadata;
153
+ const attributes = {
154
+ "data-relyio-entry": requireMetadata(metadata, "id", field),
155
+ "data-relyio-type": requireMetadata(metadata, "type", field),
156
+ "data-relyio-field": field,
157
+ "data-relyio-locale": requireMetadata(metadata, "locale", field),
158
+ "data-relyio-v": BINDING_VERSION
159
+ };
160
+ requireKeyPath("entry", field, field);
161
+ return attributes;
162
+ }
163
+ chunkMWMSFIWN_cjs.__name(relyioField, "relyioField");
164
+ function isBindingShaped(value) {
165
+ return "data-relyio-field" in value;
166
+ }
167
+ chunkMWMSFIWN_cjs.__name(isBindingShaped, "isBindingShaped");
168
+ function continued(binding, path) {
169
+ const spelled = typeof path === "string" ? path : `{ _key: ${JSON.stringify(path._key)} }`;
170
+ const complete = binding["data-relyio-v"] === BINDING_VERSION && [
171
+ binding["data-relyio-entry"],
172
+ binding["data-relyio-type"],
173
+ binding["data-relyio-field"],
174
+ binding["data-relyio-locale"]
175
+ ].every((value) => typeof value === "string" && value.length > 0);
176
+ if (!complete) {
177
+ throw new TypeError(
178
+ `relyioField(binding, '${spelled}'): the binding is not one relyioField returned \u2014 continue the attributes relyioField(entry, field) gave, or a renderer handed you.`
179
+ );
180
+ }
181
+ const field = typeof path === "string" ? `${binding["data-relyio-field"]}.${path}` : formatKeyPath(binding["data-relyio-field"], path._key);
182
+ requireKeyPath("binding", spelled, field);
183
+ return {
184
+ "data-relyio-entry": binding["data-relyio-entry"],
185
+ "data-relyio-type": binding["data-relyio-type"],
186
+ "data-relyio-field": field,
187
+ "data-relyio-locale": binding["data-relyio-locale"],
188
+ "data-relyio-v": BINDING_VERSION
189
+ };
190
+ }
191
+ chunkMWMSFIWN_cjs.__name(continued, "continued");
192
+ function requireKeyPath(form, given, field) {
193
+ if (parseKeyPath(field) !== null) return;
194
+ throw new TypeError(
195
+ `relyioField(${form}, '${given}'): '${field}' is not a field or a key path. Name a field (\`title\`), or a value inside one by its items\u2019 keys (\`sections[_key=="k1"].heading\`).`
196
+ );
197
+ }
198
+ chunkMWMSFIWN_cjs.__name(requireKeyPath, "requireKeyPath");
199
+ function requireMetadata(metadata, key, field) {
200
+ const value = metadata?.[key];
201
+ if (typeof value !== "string" || value.length === 0) {
202
+ throw new TypeError(
203
+ `relyioField(entry, '${field}'): the entry has no _metadata.${key}, so the field cannot be bound. Pass an entry as the RelyIO API returned it.`
204
+ );
205
+ }
206
+ return value;
207
+ }
208
+ chunkMWMSFIWN_cjs.__name(requireMetadata, "requireMetadata");
209
+
7
210
  // src/rich-text/render.ts
8
211
  var RICH_TEXT_VOID_TAGS = /* @__PURE__ */ new Set([
9
212
  "hr",
10
213
  "br",
11
214
  "input"
12
215
  ]);
216
+ var BUILT_IN_NODES = {
217
+ paragraph: true,
218
+ heading: true,
219
+ quote: true,
220
+ list: true,
221
+ listItem: true,
222
+ codeBlock: true,
223
+ codeGroup: true,
224
+ table: true,
225
+ tableRow: true,
226
+ tableCell: true,
227
+ divider: true,
228
+ text: true,
229
+ lineBreak: true
230
+ };
231
+ function isDeclaredRichTextNode(node) {
232
+ if (typeof node !== "object" || node === null) return false;
233
+ const type = node._type;
234
+ return typeof type === "string" && type !== "" && !Object.prototype.hasOwnProperty.call(BUILT_IN_NODES, type);
235
+ }
236
+ chunkMWMSFIWN_cjs.__name(isDeclaredRichTextNode, "isDeclaredRichTextNode");
13
237
  var PLAIN = Object.freeze({ header: false });
14
238
  var HEADER = Object.freeze({ header: true });
15
- function renderRichText(value, target) {
16
- if (value._type !== "richText") {
17
- const drawn = block(value, target);
239
+ var headingAnchors = /* @__PURE__ */ new Map();
240
+ function renderRichText(value, target, options = {}) {
241
+ const held = value;
242
+ if (held._type !== "richText") {
243
+ const drawn = block(held, target);
18
244
  return drawn === void 0 ? [] : [drawn];
19
245
  }
20
- return Array.isArray(value.children) ? blocks(value.children, target) : [];
246
+ const outer = headingAnchors;
247
+ headingAnchors = options.anchors ?? richTextHeadingAnchors(held);
248
+ try {
249
+ return Array.isArray(held.children) ? blocks(held.children, target) : [];
250
+ } finally {
251
+ headingAnchors = outer;
252
+ }
21
253
  }
22
254
  chunkMWMSFIWN_cjs.__name(renderRichText, "renderRichText");
23
255
  function blocks(nodes, target) {
@@ -38,6 +270,9 @@ var HEADING_TAGS = {
38
270
  6: "h6"
39
271
  };
40
272
  function block(node, target) {
273
+ if (isDeclaredRichTextNode(node)) {
274
+ return target.declared(node, "block");
275
+ }
41
276
  switch (node._type) {
42
277
  case "paragraph": {
43
278
  return target.node(
@@ -49,10 +284,16 @@ function block(node, target) {
49
284
  }
50
285
  case "heading": {
51
286
  const tag = HEADING_TAGS[node.level] ?? "p";
287
+ const anchor = headingAnchors.get(node);
52
288
  return target.node(
53
289
  node,
54
290
  inline(node.children, target),
55
- (contents) => target.element(tag, void 0, contents, node._key),
291
+ (contents) => target.element(
292
+ tag,
293
+ anchor === void 0 ? void 0 : { id: anchor },
294
+ contents,
295
+ node._key
296
+ ),
56
297
  PLAIN
57
298
  );
58
299
  }
@@ -255,6 +496,12 @@ function inline(nodes, target) {
255
496
  runs = [];
256
497
  }, "flush");
257
498
  for (const node of nodes) {
499
+ if (isDeclaredRichTextNode(node)) {
500
+ flush();
501
+ const drawn = target.declared(node, "inline");
502
+ if (drawn !== void 0) out.push(drawn);
503
+ continue;
504
+ }
258
505
  switch (node._type) {
259
506
  case "text": {
260
507
  runs.push({ span: node, drawn: 0 });
@@ -303,9 +550,22 @@ function nextMark(run) {
303
550
  chunkMWMSFIWN_cjs.__name(nextMark, "nextMark");
304
551
  function sameMark(a, b) {
305
552
  if (a?._type !== b._type) return false;
306
- return a._type !== "link" || b._type !== "link" || a.href === b.href;
553
+ if (a._type === "link" && b._type === "link") return a.href === b.href;
554
+ if (a._type === "entryLink" && b._type === "entryLink") {
555
+ return linkedEntryId(a) === linkedEntryId(b) && a.anchor === b.anchor;
556
+ }
557
+ return true;
307
558
  }
308
559
  chunkMWMSFIWN_cjs.__name(sameMark, "sameMark");
560
+ function linkedEntryId(link) {
561
+ const to = link.to;
562
+ if (typeof to === "object" && to !== null && "_metadata" in to) {
563
+ const metadata = to._metadata;
564
+ return metadata?.id ?? to;
565
+ }
566
+ return to;
567
+ }
568
+ chunkMWMSFIWN_cjs.__name(linkedEntryId, "linkedEntryId");
309
569
  var MARK_TAGS = {
310
570
  bold: "strong",
311
571
  italic: "em",
@@ -318,6 +578,9 @@ var MARK_TAGS = {
318
578
  };
319
579
  function applyMark(mark, inner, target) {
320
580
  switch (mark._type) {
581
+ case "entryLink": {
582
+ return [target.entryLink(mark, inner)];
583
+ }
321
584
  case "link": {
322
585
  const href = safeRichTextHref(mark.href);
323
586
  if (href === void 0) return inner;
@@ -391,28 +654,168 @@ function attributesOf(attributes) {
391
654
  return written;
392
655
  }
393
656
  chunkMWMSFIWN_cjs.__name(attributesOf, "attributesOf");
394
- var HTML_TARGET = {
395
- element(tag, attributes, children) {
396
- return RICH_TEXT_VOID_TAGS.has(tag) ? `<${tag}${attributesOf(attributes)}/>` : `<${tag}${attributesOf(attributes)}>${children.join("")}</${tag}>`;
397
- },
398
- text: escapeHtml,
399
- node: /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((_node, contents, draw) => draw(contents), "node"),
400
- mark: /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((_mark, contents, draw) => draw(contents), "mark")
401
- };
402
- function richTextToHtml(value) {
657
+ var VOID_ELEMENTS = /* @__PURE__ */ new Set([
658
+ "area",
659
+ "base",
660
+ "br",
661
+ "col",
662
+ "embed",
663
+ "hr",
664
+ "img",
665
+ "input",
666
+ "link",
667
+ "meta",
668
+ "source",
669
+ "track",
670
+ "wbr"
671
+ ]);
672
+ var RAW_TEXT_ELEMENTS = /* @__PURE__ */ new Set(["script", "style", "textarea", "title"]);
673
+ var BOUND = /\sdata-relyio-entry(?:[\s=/>]|$)/i;
674
+ function tagEnd(html, start) {
675
+ let quote;
676
+ for (let index = start + 1; index < html.length; index++) {
677
+ const character = html[index];
678
+ if (quote !== void 0) {
679
+ if (character === quote) quote = void 0;
680
+ } else if (character === '"' || character === "'") {
681
+ quote = character;
682
+ } else if (character === ">") {
683
+ return index + 1;
684
+ }
685
+ }
686
+ return -1;
687
+ }
688
+ chunkMWMSFIWN_cjs.__name(tagEnd, "tagEnd");
689
+ var TAG_NAME = /^<\/?([A-Za-z][\w:-]*)/;
690
+ function soleElementStartTag(html) {
691
+ const from = html.length - html.trimStart().length;
692
+ const to = html.trimEnd().length;
693
+ const root = TAG_NAME.exec(html.slice(from));
694
+ if (root === null || html[from + 1] === "/") return void 0;
695
+ let depth = 0;
696
+ let index = from;
697
+ let startTag;
698
+ while (index < to) {
699
+ if (depth === 0 && startTag !== void 0) return void 0;
700
+ const open = html.indexOf("<", index);
701
+ if (open !== index) {
702
+ if (depth === 0) return void 0;
703
+ if (open === -1 || open >= to) return void 0;
704
+ index = open;
705
+ continue;
706
+ }
707
+ if (html.startsWith("<!--", index)) {
708
+ if (depth === 0) return void 0;
709
+ const close = html.indexOf("-->", index + 4);
710
+ if (close === -1) return void 0;
711
+ index = close + 3;
712
+ continue;
713
+ }
714
+ const name = TAG_NAME.exec(html.slice(index));
715
+ if (name === null) {
716
+ if (depth === 0) return void 0;
717
+ index += 1;
718
+ continue;
719
+ }
720
+ const end = tagEnd(html, index);
721
+ if (end === -1 || end > to) return void 0;
722
+ const tag = (name[1] ?? "").toLowerCase();
723
+ if (html[index + 1] === "/") {
724
+ depth -= 1;
725
+ if (depth < 0) return void 0;
726
+ index = end;
727
+ continue;
728
+ }
729
+ const selfClosing = html[end - 2] === "/";
730
+ if (startTag === void 0) {
731
+ let insertAt = selfClosing ? end - 2 : end - 1;
732
+ while (insertAt > index && /\s/.test(html[insertAt - 1] ?? "")) insertAt -= 1;
733
+ startTag = { insertAt, tag: html.slice(index, end) };
734
+ }
735
+ if (selfClosing || VOID_ELEMENTS.has(tag)) {
736
+ index = end;
737
+ continue;
738
+ }
739
+ if (RAW_TEXT_ELEMENTS.has(tag)) {
740
+ const close = html.toLowerCase().indexOf(`</${tag}`, end);
741
+ if (close === -1) return void 0;
742
+ depth += 1;
743
+ index = close;
744
+ continue;
745
+ }
746
+ depth += 1;
747
+ index = end;
748
+ }
749
+ return depth === 0 ? startTag : void 0;
750
+ }
751
+ chunkMWMSFIWN_cjs.__name(soleElementStartTag, "soleElementStartTag");
752
+ function stamped(html, binding) {
753
+ if (binding === void 0) return html;
754
+ const root = soleElementStartTag(html);
755
+ if (root === void 0) return html;
756
+ if (BOUND.test(root.tag)) return html;
757
+ return `${html.slice(0, root.insertAt)}${attributesOf(binding)}${html.slice(root.insertAt)}`;
758
+ }
759
+ chunkMWMSFIWN_cjs.__name(stamped, "stamped");
760
+ function htmlTarget(declared2, entryLink, field) {
761
+ return {
762
+ element(tag, attributes, children) {
763
+ return RICH_TEXT_VOID_TAGS.has(tag) ? `<${tag}${attributesOf(attributes)}/>` : `<${tag}${attributesOf(attributes)}>${children.join("")}</${tag}>`;
764
+ },
765
+ text: escapeHtml,
766
+ node: /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((_node, contents, draw) => draw(contents), "node"),
767
+ mark: /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((_mark, contents, draw) => draw(contents), "mark"),
768
+ // A value built by hand holding an entry link no writer draws: its text, with no anchor
769
+ entryLink: /* @__PURE__ */ chunkMWMSFIWN_cjs.__name((link, contents) => entryLink === void 0 ? contents.join("") : entryLink(link, contents.join("")), "entryLink"),
770
+ // A declared node's writer (REL-1807), handed the node's key path below the field's binding and
771
+ // stamped with it (REL-2142); no binding asks the core nothing
772
+ declared(node) {
773
+ const write = Object.prototype.hasOwnProperty.call(declared2, node._type) ? declared2[node._type] : void 0;
774
+ if (write === void 0) return void 0;
775
+ const binding = field === void 0 ? void 0 : relyioField(field, node);
776
+ return stamped(write(node, binding), binding);
777
+ }
778
+ };
779
+ }
780
+ chunkMWMSFIWN_cjs.__name(htmlTarget, "htmlTarget");
781
+ function richTextToHtml(value, ...[options]) {
403
782
  if (value === void 0) return "";
404
- return renderRichText(value, HTML_TARGET).join("");
783
+ const declared2 = options?.declared ?? {};
784
+ const entryLink = options?.entryLink;
785
+ return renderRichText(
786
+ value,
787
+ htmlTarget(declared2, entryLink, options?.field),
788
+ options?.anchors === void 0 ? {} : { anchors: options.anchors }
789
+ ).join("");
405
790
  }
406
791
  chunkMWMSFIWN_cjs.__name(richTextToHtml, "richTextToHtml");
407
792
 
408
793
  // src/rich-text/markdown.ts
409
- function richTextToMarkdown(value) {
794
+ var entryLinkWriter;
795
+ var writers = {};
796
+ function declared(node) {
797
+ const type = node._type;
798
+ const write = Object.prototype.hasOwnProperty.call(writers, type) ? writers[type] : void 0;
799
+ return write === void 0 ? void 0 : write(node);
800
+ }
801
+ chunkMWMSFIWN_cjs.__name(declared, "declared");
802
+ function richTextToMarkdown(value, ...[options]) {
410
803
  if (value === void 0) return "";
411
- const held = value._type === "richText" ? value.children : [value];
804
+ const tree = value;
805
+ const held = tree._type === "richText" ? tree.children : [tree];
412
806
  if (!Array.isArray(held)) return "";
413
- const written = blocks2(held);
414
- return written.length === 0 ? "" : `${written.join("\n\n")}
807
+ const outer = writers;
808
+ const outerLink = entryLinkWriter;
809
+ writers = options?.declared ?? {};
810
+ entryLinkWriter = options?.entryLink;
811
+ try {
812
+ const written = blocks2(held);
813
+ return written.length === 0 ? "" : `${written.join("\n\n")}
415
814
  `;
815
+ } finally {
816
+ writers = outer;
817
+ entryLinkWriter = outerLink;
818
+ }
416
819
  }
417
820
  chunkMWMSFIWN_cjs.__name(richTextToMarkdown, "richTextToMarkdown");
418
821
  function blocks2(nodes) {
@@ -425,6 +828,7 @@ function blocks2(nodes) {
425
828
  }
426
829
  chunkMWMSFIWN_cjs.__name(blocks2, "blocks");
427
830
  function block2(node) {
831
+ if (isDeclaredRichTextNode(node)) return declared(node);
428
832
  switch (node._type) {
429
833
  case "paragraph": {
430
834
  return escapeLineStarts(inline2(node.children, "\\\n"));
@@ -568,6 +972,11 @@ function inline2(nodes, lineBreak) {
568
972
  runs = [];
569
973
  }, "flush");
570
974
  for (const node of nodes) {
975
+ if (isDeclaredRichTextNode(node)) {
976
+ flush();
977
+ out += declared(node) ?? "";
978
+ continue;
979
+ }
571
980
  switch (node._type) {
572
981
  case "text": {
573
982
  runs.push({ span: node, drawn: 0 });
@@ -618,6 +1027,9 @@ function marked2(runs) {
618
1027
  chunkMWMSFIWN_cjs.__name(marked2, "marked");
619
1028
  function applyMark2(mark, inner) {
620
1029
  switch (mark._type) {
1030
+ case "entryLink": {
1031
+ return entryLinkWriter === void 0 || inner === "" ? inner : entryLinkWriter(mark, inner);
1032
+ }
621
1033
  case "link": {
622
1034
  const href = safeRichTextHref(mark.href);
623
1035
  if (href === void 0 || inner === "") return inner;
@@ -678,9 +1090,17 @@ function escapeLineStarts(paragraph) {
678
1090
  chunkMWMSFIWN_cjs.__name(escapeLineStarts, "escapeLineStarts");
679
1091
 
680
1092
  exports.RICH_TEXT_VOID_TAGS = RICH_TEXT_VOID_TAGS;
1093
+ exports.entryHeadingAnchors = entryHeadingAnchors;
1094
+ exports.escapeHtml = escapeHtml;
1095
+ exports.formatKeyPath = formatKeyPath;
1096
+ exports.isDeclaredRichTextNode = isDeclaredRichTextNode;
1097
+ exports.parseKeyPath = parseKeyPath;
1098
+ exports.relyioField = relyioField;
681
1099
  exports.renderRichText = renderRichText;
1100
+ exports.richTextHeadingAnchors = richTextHeadingAnchors;
1101
+ exports.richTextHeadingSlug = richTextHeadingSlug;
682
1102
  exports.richTextToHtml = richTextToHtml;
683
1103
  exports.richTextToMarkdown = richTextToMarkdown;
684
1104
  exports.safeRichTextHref = safeRichTextHref;
685
- //# sourceMappingURL=chunk-FI5VIF4M.cjs.map
686
- //# sourceMappingURL=chunk-FI5VIF4M.cjs.map
1105
+ //# sourceMappingURL=chunk-RSHMA4KT.cjs.map
1106
+ //# sourceMappingURL=chunk-RSHMA4KT.cjs.map