@foir/sdk 0.7.0 → 0.9.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 (61) hide show
  1. package/CHANGELOG.md +857 -4
  2. package/README.md +46 -15
  3. package/dist/auth/auth.d.ts +104 -1
  4. package/dist/auth/hosted.d.ts +22 -0
  5. package/dist/auth/index.d.ts +13 -7
  6. package/dist/auth/operations.d.ts +85 -64
  7. package/dist/auth/ops.d.ts +99 -0
  8. package/dist/auth.js +786 -106
  9. package/dist/chunk-IGNLWT3H.js +35 -0
  10. package/dist/chunk-OHYVKTGB.js +45 -0
  11. package/dist/chunk-TAL5H6VA.js +39 -0
  12. package/dist/client.js +25 -31
  13. package/dist/codegen/block-registry.d.ts +13 -19
  14. package/dist/codegen/block-registry.js +3 -31
  15. package/dist/codegen/block-scaffold.d.ts +12 -21
  16. package/dist/codegen/block-scaffold.js +3 -41
  17. package/dist/codegen/index.d.ts +9 -4
  18. package/dist/codegen/index.js +7 -11
  19. package/dist/codegen/item-registry.d.ts +28 -0
  20. package/dist/codegen/item-registry.js +7 -0
  21. package/dist/codegen/item-scaffold.d.ts +29 -0
  22. package/dist/codegen/item-scaffold.js +7 -0
  23. package/dist/codegen/preset.d.ts +14 -7
  24. package/dist/codegen/shared.d.ts +20 -9
  25. package/dist/content/content-renderer.d.ts +90 -24
  26. package/dist/content/index.d.ts +13 -7
  27. package/dist/content/richtext.d.ts +66 -18
  28. package/dist/content.js +227 -80
  29. package/dist/data/builtins.d.ts +369 -92
  30. package/dist/data/client.d.ts +97 -25
  31. package/dist/data/document.d.ts +251 -0
  32. package/dist/data/index.d.ts +38 -19
  33. package/dist/data/manifest.d.ts +290 -8
  34. package/dist/data/schema.d.ts +78 -8
  35. package/dist/data/selection.d.ts +231 -37
  36. package/dist/data/subjects.d.ts +221 -0
  37. package/dist/data/subscription-document.d.ts +75 -0
  38. package/dist/data/subscriptions.d.ts +181 -0
  39. package/dist/data/transport.d.ts +255 -37
  40. package/dist/data/ws-transport.d.ts +197 -0
  41. package/dist/data.js +1419 -45
  42. package/dist/graphql/cdn-route.d.ts +12 -28
  43. package/dist/media/index.d.ts +6 -2
  44. package/dist/media/media.d.ts +2 -2
  45. package/dist/media/screen-capture.d.ts +81 -0
  46. package/dist/media.js +97 -0
  47. package/dist/next.js +663 -182
  48. package/dist/push.js +700 -90
  49. package/dist/react/FoirFeedback.d.ts +62 -0
  50. package/dist/react/feedback-notes.d.ts +101 -0
  51. package/dist/react/index.d.ts +7 -1
  52. package/dist/react.js +1272 -194
  53. package/dist/realtime.js +1 -1
  54. package/dist/server/events-client.d.ts +279 -0
  55. package/dist/server/index.d.ts +4 -0
  56. package/dist/server.js +298 -0
  57. package/dist/transport/foir-http.d.ts +23 -6
  58. package/dist/transport/persisted-query.d.ts +68 -0
  59. package/dist/transport/retry.d.ts +1 -1
  60. package/package.json +13 -1
  61. package/dist/chunk-ADO5FJNM.js +0 -30
package/dist/content.js CHANGED
@@ -1,19 +1,5 @@
1
1
  // src/content/content-renderer.tsx
2
- import { Fragment } from "react";
3
- import { Fragment as Fragment2, jsx } from "react/jsx-runtime";
4
- function createContentRenderer(registry) {
5
- return function ContentRenderer({ blocks, ctx }) {
6
- if (!blocks?.length) return null;
7
- let priorityAssigned = false;
8
- return /* @__PURE__ */ jsx(Fragment2, { children: blocks.map((block, i) => {
9
- const Component = registry[block.__typename];
10
- if (!Component) return null;
11
- const priority = !priorityAssigned;
12
- priorityAssigned = true;
13
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Component, { block, ctx, priority }) }, block._id ?? i);
14
- }) });
15
- };
16
- }
2
+ import { Fragment as Fragment2 } from "react";
17
3
 
18
4
  // src/content/richtext.tsx
19
5
  import {
@@ -21,7 +7,7 @@ import {
21
7
  createElement,
22
8
  useContext
23
9
  } from "react";
24
- import { jsx as jsx2 } from "react/jsx-runtime";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
25
11
  function safeHref(url) {
26
12
  if (!url) return "#";
27
13
  const trimmed = url.trim();
@@ -39,28 +25,49 @@ function RichTextTypographyProvider({
39
25
  tokens,
40
26
  children
41
27
  }) {
42
- return /* @__PURE__ */ jsx2(TypographyContext.Provider, { value: tokens, children });
28
+ return /* @__PURE__ */ jsx(TypographyContext.Provider, { value: tokens, children });
43
29
  }
44
30
  function useRichTextTypography() {
45
31
  return useContext(TypographyContext);
46
32
  }
47
- var TEXT_FORMAT_BOLD = 1;
48
- var TEXT_FORMAT_ITALIC = 2;
49
- var TEXT_FORMAT_STRIKETHROUGH = 4;
50
- var TEXT_FORMAT_UNDERLINE = 8;
51
- var TEXT_FORMAT_CODE = 16;
33
+ var DECORATION_TAGS = {
34
+ bold: "strong",
35
+ italic: "em",
36
+ underline: "u",
37
+ strikethrough: "s",
38
+ code: "code",
39
+ subscript: "sub",
40
+ superscript: "sup",
41
+ highlight: "mark"
42
+ };
43
+ function isPassageEntry(entry) {
44
+ if (!entry || typeof entry !== "object") return false;
45
+ const e = entry;
46
+ return e.__typename === "Passage" || e._type === "passage";
47
+ }
48
+ function passagesOf(value) {
49
+ if (!value) return [];
50
+ if (Array.isArray(value.entries)) {
51
+ return value.entries.filter(isPassageEntry);
52
+ }
53
+ const flow = value.json;
54
+ if (flow && typeof flow === "object") {
55
+ const entries = flow.entries;
56
+ if (Array.isArray(entries)) return entries.filter(isPassageEntry);
57
+ }
58
+ return [];
59
+ }
52
60
  function RichTextRenderer({
53
61
  value,
54
62
  className,
55
63
  tokens,
56
64
  fallbackTag = "p"
57
65
  }) {
58
- const contextTokens = useRichTextTypography();
59
- const typography = tokens ?? contextTokens ?? [];
60
66
  if (!value) return null;
61
- if (!value.json) {
67
+ const passages = passagesOf(value);
68
+ if (passages.length === 0) {
62
69
  if (value.html) {
63
- return /* @__PURE__ */ jsx2(
70
+ return /* @__PURE__ */ jsx(
64
71
  "div",
65
72
  {
66
73
  className,
@@ -70,72 +77,164 @@ function RichTextRenderer({
70
77
  }
71
78
  return null;
72
79
  }
73
- const root = value.json && typeof value.json === "object" ? value.json.root ?? null : null;
74
- if (!root || !Array.isArray(root.children) || root.children.length === 0) {
75
- return null;
76
- }
80
+ return /* @__PURE__ */ jsx("div", { className, children: /* @__PURE__ */ jsx(PassageList, { passages, tokens, fallbackTag }) });
81
+ }
82
+ function PassageList({
83
+ passages,
84
+ tokens,
85
+ fallbackTag = "p"
86
+ }) {
87
+ const contextTokens = useRichTextTypography();
88
+ const typography = tokens ?? contextTokens ?? [];
77
89
  const tokenMap = /* @__PURE__ */ new Map();
78
90
  for (const t of typography) {
79
91
  tokenMap.set(t.name, t);
80
92
  }
81
- return /* @__PURE__ */ jsx2("div", { className, children: root.children.map(
82
- (node, i) => renderBlockNode(node, i, tokenMap, fallbackTag)
83
- ) });
84
- }
85
- function renderBlockNode(node, key, tokens, fallbackTag) {
86
- const type = node.type;
87
- if (type === "paragraph" || type === "heading" || type === "quote") {
88
- const styleKey = typeof node.style === "string" && node.style.length > 0 ? node.style : null;
89
- const token = styleKey ? tokens.get(styleKey) ?? null : null;
90
- const tag = pickTag(node, token, fallbackTag);
91
- const styleProps = tokenToCss(token, node.format);
92
- const children = (node.children ?? []).map(
93
- (child, i) => renderInlineNode(child, i)
94
- );
95
- return createElement(tag, { key, style: styleProps }, ...children);
93
+ const out = [];
94
+ let i = 0;
95
+ while (i < passages.length) {
96
+ const passage = passages[i];
97
+ if (passage.list) {
98
+ const run = [];
99
+ while (i < passages.length && passages[i].list) {
100
+ run.push(passages[i]);
101
+ i++;
102
+ }
103
+ out.push(
104
+ /* @__PURE__ */ jsx(
105
+ ListRun,
106
+ {
107
+ run,
108
+ level: minLevel(run),
109
+ tokens: tokenMap
110
+ },
111
+ run[0]._key ?? `list-${out.length}`
112
+ )
113
+ );
114
+ continue;
115
+ }
116
+ out.push(renderPassage(passage, passage._key ?? i, tokenMap, fallbackTag));
117
+ i++;
118
+ }
119
+ return /* @__PURE__ */ jsx(Fragment, { children: out });
120
+ }
121
+ function minLevel(run) {
122
+ let min = Infinity;
123
+ for (const p of run) min = Math.min(min, p.level ?? 1);
124
+ return Number.isFinite(min) ? min : 1;
125
+ }
126
+ function ListRun({
127
+ run,
128
+ level,
129
+ tokens
130
+ }) {
131
+ const items = [];
132
+ let i = 0;
133
+ while (i < run.length) {
134
+ const passage = run[i];
135
+ if ((passage.level ?? 1) > level) {
136
+ const deep = [];
137
+ while (i < run.length && (run[i].level ?? 1) > level) {
138
+ deep.push(run[i]);
139
+ i++;
140
+ }
141
+ const nested = /* @__PURE__ */ jsx(ListRun, { run: deep, level: level + 1, tokens });
142
+ const prev = items[items.length - 1];
143
+ if (prev && !prev.nested) {
144
+ prev.nested = nested;
145
+ } else {
146
+ items.push({
147
+ key: deep[0]._key ?? `d${items.length}`,
148
+ content: null,
149
+ nested,
150
+ type: deep[0].list ?? "bullet"
151
+ });
152
+ }
153
+ continue;
154
+ }
155
+ const token = passage.token ? tokens.get(passage.token) ?? null : null;
156
+ items.push({
157
+ key: passage._key ?? `li${items.length}`,
158
+ content: /* @__PURE__ */ jsx("span", { style: tokenToCss(token, passage.align), children: renderSpans(passage) }),
159
+ nested: null,
160
+ type: passage.list ?? "bullet"
161
+ });
162
+ i++;
96
163
  }
97
- if (type === "list") {
98
- const ordered = node.listType === "number";
99
- const ListTag = ordered ? "ol" : "ul";
100
- return /* @__PURE__ */ jsx2(ListTag, { children: (node.children ?? []).map((child, i) => /* @__PURE__ */ jsx2("li", { children: (child.children ?? []).map((c, j) => renderInlineNode(c, j)) }, i)) }, key);
164
+ const lists = [];
165
+ let group = [];
166
+ const flush = () => {
167
+ if (group.length === 0) return;
168
+ const ListTag = group[0].type === "number" ? "ol" : "ul";
169
+ lists.push(
170
+ /* @__PURE__ */ jsx(ListTag, { children: group.map((item) => /* @__PURE__ */ jsxs("li", { children: [
171
+ item.content,
172
+ item.nested
173
+ ] }, item.key)) }, group[0].key)
174
+ );
175
+ group = [];
176
+ };
177
+ for (const item of items) {
178
+ if (group.length > 0 && group[0].type !== item.type) flush();
179
+ group.push(item);
101
180
  }
102
- if (Array.isArray(node.children)) {
103
- return /* @__PURE__ */ jsx2("div", { children: node.children.map((child, i) => renderInlineNode(child, i)) }, key);
181
+ flush();
182
+ return /* @__PURE__ */ jsx(Fragment, { children: lists });
183
+ }
184
+ function renderPassage(passage, key, tokens, fallbackTag) {
185
+ const token = passage.token ? tokens.get(passage.token) ?? null : null;
186
+ const style = tokenToCss(token, passage.align);
187
+ if (passage.kind === "code") {
188
+ return /* @__PURE__ */ jsx("pre", { style, children: /* @__PURE__ */ jsx(
189
+ "code",
190
+ {
191
+ className: passage.language ? `language-${passage.language}` : void 0,
192
+ children: (passage.spans ?? []).map((s) => s?.text ?? "").join("")
193
+ }
194
+ ) }, key);
104
195
  }
105
- return null;
106
- }
107
- function renderInlineNode(node, key) {
108
- if (node.type === "text") {
109
- const formatBits = typeof node.format === "number" ? node.format : 0;
110
- let el = node.text ?? "";
111
- if (formatBits & TEXT_FORMAT_CODE) el = /* @__PURE__ */ jsx2("code", { children: el });
112
- if (formatBits & TEXT_FORMAT_BOLD) el = /* @__PURE__ */ jsx2("strong", { children: el });
113
- if (formatBits & TEXT_FORMAT_ITALIC) el = /* @__PURE__ */ jsx2("em", { children: el });
114
- if (formatBits & TEXT_FORMAT_UNDERLINE) el = /* @__PURE__ */ jsx2("u", { children: el });
115
- if (formatBits & TEXT_FORMAT_STRIKETHROUGH) el = /* @__PURE__ */ jsx2("s", { children: el });
116
- return /* @__PURE__ */ jsx2("span", { children: el }, key);
196
+ const tag = pickTag(passage, token, fallbackTag);
197
+ return createElement(tag, { key, style }, ...[renderSpans(passage)]);
198
+ }
199
+ function renderSpans(passage) {
200
+ const markDefs = Array.isArray(passage.markDefs) ? passage.markDefs : [];
201
+ return (passage.spans ?? []).flatMap((span, i) => {
202
+ if (!span) return [];
203
+ return [renderSpan(span, i, markDefs)];
204
+ });
205
+ }
206
+ function renderSpan(span, key, markDefs) {
207
+ const parts = (span.text ?? "").split("\n");
208
+ let el = parts.length === 1 ? parts[0] : parts.flatMap(
209
+ (part, i) => i === 0 ? [part] : [/* @__PURE__ */ jsx("br", {}, `br${i}`), part]
210
+ );
211
+ let link = null;
212
+ for (const mark of span.marks ?? []) {
213
+ if (!mark) continue;
214
+ const decorationTag = DECORATION_TAGS[mark];
215
+ if (decorationTag) {
216
+ el = createElement(decorationTag, null, el);
217
+ continue;
218
+ }
219
+ const def = markDefs.find((d) => d._key === mark);
220
+ if (def?.type === "link" && def.href) link = def;
117
221
  }
118
- if (node.type === "linebreak") return /* @__PURE__ */ jsx2("br", {}, key);
119
- if (node.type === "link") {
120
- const href = safeHref(node.url);
121
- const target = node.target;
222
+ if (link?.href) {
223
+ const href = safeHref(link.href);
224
+ const target = link.target;
122
225
  const rel = target && target !== "_self" ? "noopener noreferrer" : void 0;
123
- return /* @__PURE__ */ jsx2("a", { href, target, rel, children: (node.children ?? []).map((c, i) => renderInlineNode(c, i)) }, key);
124
- }
125
- if (Array.isArray(node.children)) {
126
- return /* @__PURE__ */ jsx2("span", { children: node.children.map((c, i) => renderInlineNode(c, i)) }, key);
226
+ el = /* @__PURE__ */ jsx("a", { href, target, rel, children: el });
127
227
  }
128
- return null;
228
+ return /* @__PURE__ */ jsx("span", { children: el }, key);
129
229
  }
130
- function pickTag(node, token, fallback) {
230
+ function pickTag(passage, token, fallback) {
131
231
  if (token?.tag) return token.tag;
132
- if (node.type === "heading" && typeof node.tag === "string") {
133
- return node.tag;
134
- }
135
- if (node.type === "quote") return "blockquote";
232
+ const kind = passage.kind;
233
+ if (kind && /^h[1-6]$/.test(kind)) return kind;
234
+ if (kind === "quote") return "blockquote";
136
235
  return fallback;
137
236
  }
138
- function tokenToCss(token, paragraphFormat) {
237
+ function tokenToCss(token, align) {
139
238
  const style = {};
140
239
  if (token) {
141
240
  const v = token.value;
@@ -148,14 +247,62 @@ function tokenToCss(token, paragraphFormat) {
148
247
  style.textTransform = v.textTransform;
149
248
  }
150
249
  }
151
- if (typeof paragraphFormat === "string" && paragraphFormat !== "") {
152
- style.textAlign = paragraphFormat;
250
+ if (align) {
251
+ style.textAlign = align;
153
252
  }
154
253
  return Object.keys(style).length > 0 ? style : void 0;
155
254
  }
255
+
256
+ // src/content/content-renderer.tsx
257
+ import { Fragment as Fragment3, jsx as jsx2 } from "react/jsx-runtime";
258
+ function DefaultPassageRun({ passages }) {
259
+ return /* @__PURE__ */ jsx2(PassageList, { passages });
260
+ }
261
+ function createContentRenderer(registry, options) {
262
+ const PassageRun = options?.passageRun ?? DefaultPassageRun;
263
+ return function ContentRenderer(props) {
264
+ const { ctx } = props;
265
+ const value = props.items ?? props.blocks;
266
+ const items = Array.isArray(value) ? value : value?.entries ?? null;
267
+ if (!items?.length) return null;
268
+ let priorityAssigned = false;
269
+ const out = [];
270
+ let run = [];
271
+ const flushRun = () => {
272
+ if (run.length === 0) return;
273
+ const priority = !priorityAssigned;
274
+ priorityAssigned = true;
275
+ out.push(
276
+ /* @__PURE__ */ jsx2(Fragment2, { children: /* @__PURE__ */ jsx2(PassageRun, { passages: run, ctx, priority }) }, run[0]._key ?? `run-${out.length}`)
277
+ );
278
+ run = [];
279
+ };
280
+ items.forEach((item, i) => {
281
+ if (!item) return;
282
+ if (isPassageEntry(item)) {
283
+ run.push(item);
284
+ return;
285
+ }
286
+ flushRun();
287
+ const Component = registry[item.__typename];
288
+ if (!Component) return;
289
+ const priority = !priorityAssigned;
290
+ priorityAssigned = true;
291
+ out.push(
292
+ /* @__PURE__ */ jsx2(Fragment2, { children: /* @__PURE__ */ jsx2(Component, { item, block: item, ctx, priority }) }, item._key ?? item._id ?? i)
293
+ );
294
+ });
295
+ flushRun();
296
+ return /* @__PURE__ */ jsx2(Fragment3, { children: out });
297
+ };
298
+ }
156
299
  export {
300
+ PassageList,
157
301
  RichTextRenderer,
158
302
  RichTextTypographyProvider,
159
303
  createContentRenderer,
304
+ isPassageEntry,
305
+ passagesOf,
306
+ safeHref,
160
307
  useRichTextTypography
161
308
  };