@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.
- package/CHANGELOG.md +857 -4
- package/README.md +46 -15
- package/dist/auth/auth.d.ts +104 -1
- package/dist/auth/hosted.d.ts +22 -0
- package/dist/auth/index.d.ts +13 -7
- package/dist/auth/operations.d.ts +85 -64
- package/dist/auth/ops.d.ts +99 -0
- package/dist/auth.js +786 -106
- package/dist/chunk-IGNLWT3H.js +35 -0
- package/dist/chunk-OHYVKTGB.js +45 -0
- package/dist/chunk-TAL5H6VA.js +39 -0
- package/dist/client.js +25 -31
- package/dist/codegen/block-registry.d.ts +13 -19
- package/dist/codegen/block-registry.js +3 -31
- package/dist/codegen/block-scaffold.d.ts +12 -21
- package/dist/codegen/block-scaffold.js +3 -41
- package/dist/codegen/index.d.ts +9 -4
- package/dist/codegen/index.js +7 -11
- package/dist/codegen/item-registry.d.ts +28 -0
- package/dist/codegen/item-registry.js +7 -0
- package/dist/codegen/item-scaffold.d.ts +29 -0
- package/dist/codegen/item-scaffold.js +7 -0
- package/dist/codegen/preset.d.ts +14 -7
- package/dist/codegen/shared.d.ts +20 -9
- package/dist/content/content-renderer.d.ts +90 -24
- package/dist/content/index.d.ts +13 -7
- package/dist/content/richtext.d.ts +66 -18
- package/dist/content.js +227 -80
- package/dist/data/builtins.d.ts +369 -92
- package/dist/data/client.d.ts +97 -25
- package/dist/data/document.d.ts +251 -0
- package/dist/data/index.d.ts +38 -19
- package/dist/data/manifest.d.ts +290 -8
- package/dist/data/schema.d.ts +78 -8
- package/dist/data/selection.d.ts +231 -37
- package/dist/data/subjects.d.ts +221 -0
- package/dist/data/subscription-document.d.ts +75 -0
- package/dist/data/subscriptions.d.ts +181 -0
- package/dist/data/transport.d.ts +255 -37
- package/dist/data/ws-transport.d.ts +197 -0
- package/dist/data.js +1419 -45
- package/dist/graphql/cdn-route.d.ts +12 -28
- package/dist/media/index.d.ts +6 -2
- package/dist/media/media.d.ts +2 -2
- package/dist/media/screen-capture.d.ts +81 -0
- package/dist/media.js +97 -0
- package/dist/next.js +663 -182
- package/dist/push.js +700 -90
- package/dist/react/FoirFeedback.d.ts +62 -0
- package/dist/react/feedback-notes.d.ts +101 -0
- package/dist/react/index.d.ts +7 -1
- package/dist/react.js +1272 -194
- package/dist/realtime.js +1 -1
- package/dist/server/events-client.d.ts +279 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server.js +298 -0
- package/dist/transport/foir-http.d.ts +23 -6
- package/dist/transport/persisted-query.d.ts +68 -0
- package/dist/transport/retry.d.ts +1 -1
- package/package.json +13 -1
- 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
|
|
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__ */
|
|
28
|
+
return /* @__PURE__ */ jsx(TypographyContext.Provider, { value: tokens, children });
|
|
43
29
|
}
|
|
44
30
|
function useRichTextTypography() {
|
|
45
31
|
return useContext(TypographyContext);
|
|
46
32
|
}
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
67
|
+
const passages = passagesOf(value);
|
|
68
|
+
if (passages.length === 0) {
|
|
62
69
|
if (value.html) {
|
|
63
|
-
return /* @__PURE__ */
|
|
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
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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 (
|
|
119
|
-
|
|
120
|
-
const
|
|
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
|
-
|
|
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
|
|
228
|
+
return /* @__PURE__ */ jsx("span", { children: el }, key);
|
|
129
229
|
}
|
|
130
|
-
function pickTag(
|
|
230
|
+
function pickTag(passage, token, fallback) {
|
|
131
231
|
if (token?.tag) return token.tag;
|
|
132
|
-
|
|
133
|
-
|
|
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,
|
|
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 (
|
|
152
|
-
style.textAlign =
|
|
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
|
};
|