@preprio/toolkit 0.5.0-rc.1 → 0.5.0-rc.11

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/README.md +430 -23
  2. package/dist/astro/index.cjs +1290 -1
  3. package/dist/astro/index.d.cts +47 -1
  4. package/dist/astro/index.d.ts +47 -1
  5. package/dist/astro/index.js +1297 -1
  6. package/dist/{chunk-4JNKYIEV.js → chunk-6423Q744.js} +1449 -642
  7. package/dist/chunk-AOHA5INA.js +26 -0
  8. package/dist/chunk-IPMB32AZ.js +246 -0
  9. package/dist/chunk-KD3GK6TO.js +1221 -0
  10. package/dist/chunk-QSXIHRH4.js +184 -0
  11. package/dist/chunk-S3VT4UWM.js +75 -0
  12. package/dist/chunk-URXSDJOU.js +356 -0
  13. package/dist/codegen/index.cjs +82 -0
  14. package/dist/codegen/index.d.cts +70 -0
  15. package/dist/codegen/index.d.ts +70 -0
  16. package/dist/codegen/index.js +64 -0
  17. package/dist/index.cjs +3367 -416
  18. package/dist/index.d.cts +276 -5
  19. package/dist/index.d.ts +276 -5
  20. package/dist/index.js +307 -144
  21. package/dist/live-preview-DLXGXRE5.js +18 -0
  22. package/dist/nextjs/components.cjs +1608 -386
  23. package/dist/nextjs/components.d.cts +1 -1
  24. package/dist/nextjs/components.d.ts +1 -1
  25. package/dist/nextjs/components.js +4 -1
  26. package/dist/nextjs/index.cjs +1181 -6
  27. package/dist/nextjs/index.d.cts +83 -3
  28. package/dist/nextjs/index.d.ts +83 -3
  29. package/dist/nextjs/index.js +1179 -7
  30. package/dist/nextjs/live-action.cjs +285 -0
  31. package/dist/nextjs/live-action.d.cts +12 -0
  32. package/dist/nextjs/live-action.d.ts +12 -0
  33. package/dist/nextjs/live-action.js +68 -0
  34. package/dist/nextjs/live.cjs +1899 -0
  35. package/dist/nextjs/live.d.cts +54 -0
  36. package/dist/nextjs/live.d.ts +54 -0
  37. package/dist/nextjs/live.js +268 -0
  38. package/dist/nuxt/chunk-BWPGO25E.js +340 -0
  39. package/dist/nuxt/index.cjs +1 -1
  40. package/dist/nuxt/index.js +1 -1
  41. package/dist/nuxt/live-preview-2RCU35W5.js +1189 -0
  42. package/dist/nuxt/live.cjs +1816 -0
  43. package/dist/nuxt/live.d.cts +43 -0
  44. package/dist/nuxt/live.d.ts +43 -0
  45. package/dist/nuxt/live.js +198 -0
  46. package/dist/{pixel-e1fUWl2Y.d.cts → pixel-CX422dCO.d.cts} +18 -3
  47. package/dist/{pixel-e1fUWl2Y.d.ts → pixel-CX422dCO.d.ts} +18 -3
  48. package/dist/react/components.cjs +1608 -386
  49. package/dist/react/components.d.cts +17 -2
  50. package/dist/react/components.d.ts +17 -2
  51. package/dist/react/components.js +1608 -386
  52. package/dist/sveltekit/chunk-BWPGO25E.js +340 -0
  53. package/dist/sveltekit/index.cjs +1 -1
  54. package/dist/sveltekit/index.js +1 -1
  55. package/dist/sveltekit/live-preview-2RCU35W5.js +1189 -0
  56. package/dist/sveltekit/live.cjs +1830 -0
  57. package/dist/sveltekit/live.d.cts +59 -0
  58. package/dist/sveltekit/live.d.ts +59 -0
  59. package/dist/sveltekit/live.js +204 -0
  60. package/package.json +37 -11
  61. package/src/astro/PreprToolbar.astro +7 -1
@@ -0,0 +1,340 @@
1
+ // src/core/live-preview/query-document.ts
2
+ var NAME_START = /[_A-Za-z]/;
3
+ var NAME_CONTINUE = /[_0-9A-Za-z]/;
4
+ var PUNCT = /* @__PURE__ */ new Set([
5
+ "!",
6
+ "$",
7
+ "&",
8
+ "(",
9
+ ")",
10
+ ":",
11
+ "=",
12
+ "@",
13
+ "[",
14
+ "]",
15
+ "{",
16
+ "|",
17
+ "}"
18
+ ]);
19
+ function tokenize(source) {
20
+ const tokens = [];
21
+ let i = 0;
22
+ const n = source.length;
23
+ while (i < n) {
24
+ const ch = source[i];
25
+ if (ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "," || ch === "\uFEFF") {
26
+ i++;
27
+ } else if (ch === "#") {
28
+ while (i < n && source[i] !== "\n" && source[i] !== "\r") i++;
29
+ } else if (ch === "." && source.startsWith("...", i)) {
30
+ tokens.push({ type: "punct", value: "..." });
31
+ i += 3;
32
+ } else if (PUNCT.has(ch)) {
33
+ tokens.push({ type: "punct", value: ch });
34
+ i++;
35
+ } else if (NAME_START.test(ch)) {
36
+ const start = i;
37
+ while (i < n && NAME_CONTINUE.test(source[i])) i++;
38
+ tokens.push({ type: "name", value: source.slice(start, i) });
39
+ } else if (ch === '"') {
40
+ if (source.startsWith('"""', i)) {
41
+ i += 3;
42
+ while (i < n && !source.startsWith('"""', i)) {
43
+ i += source.startsWith('\\"""', i) ? 4 : 1;
44
+ }
45
+ if (i >= n) throw new SyntaxError("Unterminated block string");
46
+ i += 3;
47
+ } else {
48
+ i++;
49
+ while (i < n && source[i] !== '"') {
50
+ if (source[i] === "\n" || source[i] === "\r") {
51
+ throw new SyntaxError("Unterminated string");
52
+ }
53
+ i += source[i] === "\\" ? 2 : 1;
54
+ }
55
+ if (i >= n) throw new SyntaxError("Unterminated string");
56
+ i++;
57
+ }
58
+ tokens.push({ type: "value" });
59
+ } else if (ch === "-" || ch >= "0" && ch <= "9") {
60
+ i++;
61
+ while (i < n && /[0-9.eE+-]/.test(source[i])) i++;
62
+ tokens.push({ type: "value" });
63
+ } else {
64
+ throw new SyntaxError(`Unexpected character "${ch}"`);
65
+ }
66
+ }
67
+ return tokens;
68
+ }
69
+ function parseSource(source, operationName) {
70
+ const tokens = tokenize(source);
71
+ let pos = 0;
72
+ const peek = () => tokens[pos];
73
+ const isPunct = (value) => {
74
+ const t = tokens[pos];
75
+ return t?.type === "punct" && t.value === value;
76
+ };
77
+ const expectPunct = (value) => {
78
+ if (!isPunct(value)) throw new SyntaxError(`Expected "${value}"`);
79
+ pos++;
80
+ };
81
+ const expectName = () => {
82
+ const t = tokens[pos];
83
+ if (t?.type !== "name") throw new SyntaxError("Expected a name");
84
+ pos++;
85
+ return t.value;
86
+ };
87
+ const skipParens = () => {
88
+ expectPunct("(");
89
+ let depth = 1;
90
+ while (depth > 0) {
91
+ const t = tokens[pos++];
92
+ if (!t) throw new SyntaxError("Unbalanced parentheses");
93
+ if (t.type === "punct" && t.value === "(") depth++;
94
+ else if (t.type === "punct" && t.value === ")") depth--;
95
+ }
96
+ };
97
+ const skipDirectives = () => {
98
+ while (isPunct("@")) {
99
+ pos++;
100
+ expectName();
101
+ if (isPunct("(")) skipParens();
102
+ }
103
+ };
104
+ const parseSelectionSet = () => {
105
+ expectPunct("{");
106
+ const selections = [];
107
+ while (!isPunct("}")) {
108
+ if (!peek()) throw new SyntaxError("Unterminated selection set");
109
+ selections.push(parseSelection());
110
+ }
111
+ pos++;
112
+ return selections;
113
+ };
114
+ const parseSelection = () => {
115
+ if (isPunct("...")) {
116
+ pos++;
117
+ const t = peek();
118
+ if (t?.type === "name" && t.value !== "on") {
119
+ pos++;
120
+ skipDirectives();
121
+ return { kind: "spread", name: t.value };
122
+ }
123
+ let on = null;
124
+ if (t?.type === "name") {
125
+ pos++;
126
+ on = expectName();
127
+ }
128
+ skipDirectives();
129
+ return { kind: "inline", on, selections: parseSelectionSet() };
130
+ }
131
+ let name = expectName();
132
+ const key = name;
133
+ if (isPunct(":")) {
134
+ pos++;
135
+ name = expectName();
136
+ }
137
+ let hasArgs = false;
138
+ if (isPunct("(")) {
139
+ hasArgs = true;
140
+ skipParens();
141
+ }
142
+ skipDirectives();
143
+ const selections = isPunct("{") ? parseSelectionSet() : null;
144
+ return { kind: "field", name, key, hasArgs, selections };
145
+ };
146
+ const fragments = /* @__PURE__ */ new Map();
147
+ const operations = [];
148
+ while (pos < tokens.length) {
149
+ if (isPunct("{")) {
150
+ operations.push({ name: null, selections: parseSelectionSet() });
151
+ continue;
152
+ }
153
+ const keyword = expectName();
154
+ if (keyword === "fragment") {
155
+ const name = expectName();
156
+ if (expectName() !== "on") throw new SyntaxError('Expected "on"');
157
+ const on = expectName();
158
+ skipDirectives();
159
+ fragments.set(name, { on, selections: parseSelectionSet() });
160
+ } else if (keyword === "query" || keyword === "mutation" || keyword === "subscription") {
161
+ const t = peek();
162
+ let name = null;
163
+ if (t?.type === "name") name = expectName();
164
+ if (isPunct("(")) skipParens();
165
+ skipDirectives();
166
+ operations.push({ name, selections: parseSelectionSet() });
167
+ } else {
168
+ throw new SyntaxError(`Unexpected "${keyword}"`);
169
+ }
170
+ }
171
+ return { operation: pickOperation(operations, operationName), fragments };
172
+ }
173
+ function pickOperation(operations, operationName) {
174
+ const op = operationName ? operations.find((o) => o.name === operationName) : operations[0];
175
+ if (!op) throw new SyntaxError("The document has no operation");
176
+ return op.selections;
177
+ }
178
+ function fromAstSelections(set) {
179
+ return set.selections.map((s) => {
180
+ if (s.kind === "FragmentSpread")
181
+ return { kind: "spread", name: s.name.value };
182
+ if (s.kind === "InlineFragment") {
183
+ return {
184
+ kind: "inline",
185
+ on: s.typeCondition?.name.value ?? null,
186
+ selections: fromAstSelections(s.selectionSet)
187
+ };
188
+ }
189
+ const name = s.name.value;
190
+ return {
191
+ kind: "field",
192
+ name,
193
+ key: s.alias?.value ?? name,
194
+ hasArgs: Boolean(s.arguments?.length),
195
+ selections: s.selectionSet ? fromAstSelections(s.selectionSet) : null
196
+ };
197
+ });
198
+ }
199
+ function fromAst(doc, operationName) {
200
+ const fragments = /* @__PURE__ */ new Map();
201
+ const operations = [];
202
+ for (const def of doc.definitions ?? []) {
203
+ if (def.kind === "FragmentDefinition" && def.name && def.typeCondition && def.selectionSet) {
204
+ fragments.set(def.name.value, {
205
+ on: def.typeCondition.name.value,
206
+ selections: fromAstSelections(def.selectionSet)
207
+ });
208
+ } else if (def.kind === "OperationDefinition" && def.selectionSet) {
209
+ operations.push({
210
+ name: def.name?.value ?? null,
211
+ selections: fromAstSelections(def.selectionSet)
212
+ });
213
+ }
214
+ }
215
+ return { operation: pickOperation(operations, operationName), fragments };
216
+ }
217
+ var astCache = /* @__PURE__ */ new WeakMap();
218
+ var sourceCache = /* @__PURE__ */ new Map();
219
+ var SOURCE_CACHE_LIMIT = 200;
220
+ function readQueryDocument(query, operationName) {
221
+ const cacheKey = operationName ?? "";
222
+ if (typeof query === "object" && query !== null && query.kind === "Document") {
223
+ let byName = astCache.get(query);
224
+ if (!byName) astCache.set(query, byName = /* @__PURE__ */ new Map());
225
+ let parsed2 = byName.get(cacheKey);
226
+ if (!parsed2) {
227
+ parsed2 = fromAst(
228
+ query,
229
+ operationName
230
+ );
231
+ byName.set(cacheKey, parsed2);
232
+ }
233
+ return parsed2;
234
+ }
235
+ const source = String(query);
236
+ const sourceKey = `${cacheKey}
237
+ ${source}`;
238
+ let parsed = sourceCache.get(sourceKey);
239
+ if (!parsed) {
240
+ parsed = parseSource(source, operationName);
241
+ if (sourceCache.size >= SOURCE_CACHE_LIMIT) {
242
+ sourceCache.delete(sourceCache.keys().next().value);
243
+ }
244
+ sourceCache.set(sourceKey, parsed);
245
+ }
246
+ return parsed;
247
+ }
248
+ var fieldsCache = /* @__PURE__ */ new WeakMap();
249
+ function collectFields(selections, typename, doc, options = {}) {
250
+ const cacheKey = `${options.strict ? "s" : "l"}:${typename ?? ""}`;
251
+ let cached = fieldsCache.get(selections);
252
+ if (!cached) {
253
+ cached = /* @__PURE__ */ new Map();
254
+ fieldsCache.set(selections, cached);
255
+ }
256
+ const hit = cached.get(cacheKey);
257
+ if (hit) return hit;
258
+ const fields = resolveFields(selections, typename, doc, options);
259
+ cached.set(cacheKey, fields);
260
+ return fields;
261
+ }
262
+ function resolveFields(selections, typename, doc, options) {
263
+ const exact = /* @__PURE__ */ new Map();
264
+ const loose = /* @__PURE__ */ new Map();
265
+ const merged = /* @__PURE__ */ new Map();
266
+ const walkedMatched = /* @__PURE__ */ new Set();
267
+ const walkedLoose = /* @__PURE__ */ new Set();
268
+ const add = (target, s) => {
269
+ let field = target.get(s.key);
270
+ if (!field) {
271
+ field = { name: s.name, key: s.key, hasArgs: s.hasArgs, selections: [] };
272
+ target.set(s.key, field);
273
+ merged.set(field, /* @__PURE__ */ new Set());
274
+ }
275
+ const done = merged.get(field);
276
+ if (s.selections && !done.has(s.selections)) {
277
+ done.add(s.selections);
278
+ field.selections = [...field.selections, ...s.selections];
279
+ }
280
+ };
281
+ const applies = (on, list) => conditionMatches(on, typename) || typename !== void 0 && typeConditions(list, doc).includes(typename);
282
+ const walk = (list, matched) => {
283
+ for (const s of list) {
284
+ if (s.kind === "field") {
285
+ add(matched ? exact : loose, s);
286
+ } else if (s.kind === "inline") {
287
+ walk(s.selections, matched && applies(s.on, s.selections));
288
+ } else {
289
+ const fragment = doc.fragments.get(s.name);
290
+ if (!fragment) continue;
291
+ const asMatched = matched && applies(fragment.on, fragment.selections);
292
+ if (walkedMatched.has(fragment)) continue;
293
+ if (!asMatched && walkedLoose.has(fragment)) continue;
294
+ (asMatched ? walkedMatched : walkedLoose).add(fragment);
295
+ walk(fragment.selections, asMatched);
296
+ }
297
+ }
298
+ };
299
+ walk(selections, true);
300
+ if (!options.strict) {
301
+ for (const [key, field] of loose) {
302
+ if (!exact.has(key)) exact.set(key, field);
303
+ }
304
+ }
305
+ return exact;
306
+ }
307
+ function conditionMatches(on, typename) {
308
+ return on === null || typename === void 0 || on === typename;
309
+ }
310
+ var conditionsCache = /* @__PURE__ */ new WeakMap();
311
+ function typeConditions(selections, doc) {
312
+ const hit = conditionsCache.get(selections);
313
+ if (hit) return hit;
314
+ const names = /* @__PURE__ */ new Set();
315
+ const seen = /* @__PURE__ */ new Set();
316
+ const walk = (list) => {
317
+ for (const s of list) {
318
+ if (s.kind === "inline") {
319
+ if (s.on) names.add(s.on);
320
+ walk(s.selections);
321
+ } else if (s.kind === "spread") {
322
+ const fragment = doc.fragments.get(s.name);
323
+ if (!fragment || seen.has(fragment)) continue;
324
+ seen.add(fragment);
325
+ names.add(fragment.on);
326
+ walk(fragment.selections);
327
+ }
328
+ }
329
+ };
330
+ walk(selections);
331
+ const conditions = [...names];
332
+ conditionsCache.set(selections, conditions);
333
+ return conditions;
334
+ }
335
+
336
+ export {
337
+ readQueryDocument,
338
+ collectFields,
339
+ typeConditions
340
+ };
@@ -35,7 +35,7 @@ __export(sveltekit_exports, {
35
35
  module.exports = __toCommonJS(sveltekit_exports);
36
36
 
37
37
  // src/version.ts
38
- var VERSION = "0.5.0-rc.1";
38
+ var VERSION = "0.5.0-rc.11";
39
39
 
40
40
  // src/core/constants.ts
41
41
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var VERSION = "0.5.0-rc.1";
2
+ var VERSION = "0.5.0-rc.11";
3
3
 
4
4
  // src/core/constants.ts
5
5
  var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";