@preprio/toolkit 0.5.0-rc.5 → 0.5.0-rc.6
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/README.md +125 -26
- package/dist/astro/index.cjs +126 -30
- package/dist/astro/index.js +130 -30
- package/dist/{chunk-TG6N3C22.js → chunk-IPMB32AZ.js} +1 -1
- package/dist/{chunk-74KY5EAM.js → chunk-KD3GK6TO.js} +2 -0
- package/dist/{chunk-3X55JL52.js → chunk-KZIRM54F.js} +1 -1
- package/dist/{chunk-SBLZANL5.js → chunk-L3SDL6MP.js} +11 -3
- package/dist/{chunk-CMUFTCG3.js → chunk-WHZNCYUS.js} +1 -1
- package/dist/codegen/index.cjs +79 -0
- package/dist/codegen/index.d.cts +46 -0
- package/dist/codegen/index.d.ts +46 -0
- package/dist/codegen/index.js +62 -0
- package/dist/index.cjs +133 -28
- package/dist/index.d.cts +14 -2
- package/dist/index.d.ts +14 -2
- package/dist/index.js +108 -6
- package/dist/{live-preview-H4643QYF.js → live-preview-DLXGXRE5.js} +2 -2
- package/dist/nextjs/components.cjs +11 -3
- package/dist/nextjs/components.js +2 -2
- package/dist/nextjs/index.cjs +124 -28
- package/dist/nextjs/index.js +128 -28
- package/dist/nextjs/live-action.js +3 -3
- package/dist/nextjs/live.js +1 -1
- package/dist/nuxt/chunk-BWPGO25E.js +340 -0
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/nuxt/{live-preview-O2ZTJNW4.js → live-preview-2RCU35W5.js} +6 -337
- package/dist/nuxt/live.cjs +1007 -911
- package/dist/nuxt/live.js +109 -5
- package/dist/react/components.cjs +11 -3
- package/dist/react/components.js +11 -3
- package/dist/sveltekit/chunk-BWPGO25E.js +340 -0
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/dist/sveltekit/{live-preview-O2ZTJNW4.js → live-preview-2RCU35W5.js} +6 -337
- package/dist/sveltekit/live.cjs +1008 -909
- package/dist/sveltekit/live.js +118 -11
- package/package.json +11 -1
package/dist/sveltekit/live.js
CHANGED
|
@@ -1,3 +1,107 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectFields,
|
|
3
|
+
readQueryDocument
|
|
4
|
+
} from "./chunk-BWPGO25E.js";
|
|
5
|
+
|
|
6
|
+
// src/core/live-preview/edit-links.ts
|
|
7
|
+
import {
|
|
8
|
+
vercelStegaCombine,
|
|
9
|
+
vercelStegaDecode,
|
|
10
|
+
vercelStegaSplit
|
|
11
|
+
} from "@vercel/stega";
|
|
12
|
+
var ENTRY_PARAM = "entry";
|
|
13
|
+
var TOP_LEVEL_ENTRY = /^[A-Za-z0-9_]+\.\d+$/;
|
|
14
|
+
function entryIdOf(element) {
|
|
15
|
+
if (!isRecord(element)) return void 0;
|
|
16
|
+
if (typeof element._id === "string") return element._id;
|
|
17
|
+
if (element.__typename !== "Assets" || !Array.isArray(element.items)) {
|
|
18
|
+
return void 0;
|
|
19
|
+
}
|
|
20
|
+
const first = element.items[0];
|
|
21
|
+
return isRecord(first) && typeof first._id === "string" ? first._id : void 0;
|
|
22
|
+
}
|
|
23
|
+
function isRecord(value) {
|
|
24
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
25
|
+
}
|
|
26
|
+
function annotate(value, ctx) {
|
|
27
|
+
if (!ctx.entryId) return value;
|
|
28
|
+
const { cleaned, encoded } = vercelStegaSplit(value);
|
|
29
|
+
if (!encoded) return value;
|
|
30
|
+
let payload;
|
|
31
|
+
try {
|
|
32
|
+
payload = vercelStegaDecode(encoded);
|
|
33
|
+
} catch {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (typeof payload?.href !== "string") return value;
|
|
37
|
+
let url;
|
|
38
|
+
try {
|
|
39
|
+
url = new URL(payload.href);
|
|
40
|
+
} catch {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (url.searchParams.has(ENTRY_PARAM)) return value;
|
|
44
|
+
url.searchParams.set(ENTRY_PARAM, ctx.entryId);
|
|
45
|
+
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
46
|
+
if (!url.searchParams.has("field") && ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) && itemId === ctx.entryOwnerId) {
|
|
47
|
+
url.searchParams.set("field", ctx.entryField);
|
|
48
|
+
}
|
|
49
|
+
return vercelStegaCombine(
|
|
50
|
+
cleaned,
|
|
51
|
+
{ ...payload, href: url.toString() },
|
|
52
|
+
false
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
function walk(value, selections, ctx) {
|
|
56
|
+
if (typeof value === "string") return annotate(value, ctx);
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
let changed2 = false;
|
|
59
|
+
const next2 = value.map((element, index) => {
|
|
60
|
+
const path = [...ctx.path, String(index)];
|
|
61
|
+
const entryId = ctx.inAssets ? void 0 : entryIdOf(element);
|
|
62
|
+
const entry = entryId ? {
|
|
63
|
+
entryId,
|
|
64
|
+
entryField: ctx.ownerId ? path.join(".") : void 0,
|
|
65
|
+
entryOwnerId: ctx.ownerId,
|
|
66
|
+
inAssets: isRecord(element) && element._id === void 0
|
|
67
|
+
} : {};
|
|
68
|
+
const out = walk(element, selections, { ...ctx, ...entry, path });
|
|
69
|
+
if (out !== element) changed2 = true;
|
|
70
|
+
return out;
|
|
71
|
+
});
|
|
72
|
+
return changed2 ? next2 : value;
|
|
73
|
+
}
|
|
74
|
+
if (!isRecord(value)) return value;
|
|
75
|
+
const id = typeof value._id === "string" ? value._id : void 0;
|
|
76
|
+
const typename = typeof value.__typename === "string" ? value.__typename : void 0;
|
|
77
|
+
const fields = ctx.doc && selections ? collectFields(selections, typename, ctx.doc) : null;
|
|
78
|
+
let changed = false;
|
|
79
|
+
const next = {};
|
|
80
|
+
for (const [key, child] of Object.entries(value)) {
|
|
81
|
+
const field = fields?.get(key);
|
|
82
|
+
const name = field?.name ?? key;
|
|
83
|
+
const out = walk(child, field?.selections ?? null, {
|
|
84
|
+
...ctx,
|
|
85
|
+
ownerId: id ?? ctx.ownerId,
|
|
86
|
+
path: id ? [name] : [...ctx.path, name]
|
|
87
|
+
});
|
|
88
|
+
if (out !== child) changed = true;
|
|
89
|
+
next[key] = out;
|
|
90
|
+
}
|
|
91
|
+
return changed ? next : value;
|
|
92
|
+
}
|
|
93
|
+
function annotateEditLinks(result, query, operationName) {
|
|
94
|
+
let doc = null;
|
|
95
|
+
if (query !== void 0) {
|
|
96
|
+
try {
|
|
97
|
+
doc = readQueryDocument(query, operationName);
|
|
98
|
+
} catch {
|
|
99
|
+
doc = null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return walk(result, doc?.operation ?? null, { doc, path: [] });
|
|
103
|
+
}
|
|
104
|
+
|
|
1
105
|
// src/core/live-preview/test-reset.ts
|
|
2
106
|
var resets = /* @__PURE__ */ new Set();
|
|
3
107
|
function onTestReset(reset) {
|
|
@@ -14,11 +118,20 @@ var allowedEditorOrigins;
|
|
|
14
118
|
var strictMode;
|
|
15
119
|
var logListeners = /* @__PURE__ */ new Set();
|
|
16
120
|
var startListeners = /* @__PURE__ */ new Set();
|
|
121
|
+
function constant(value) {
|
|
122
|
+
return {
|
|
123
|
+
subscribe(run) {
|
|
124
|
+
run(value);
|
|
125
|
+
return () => {
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
17
130
|
function isFramed() {
|
|
18
131
|
return typeof window !== "undefined" && window.self !== window.top;
|
|
19
132
|
}
|
|
20
133
|
function startLive() {
|
|
21
|
-
starting ?? (starting = import("./live-preview-
|
|
134
|
+
starting ?? (starting = import("./live-preview-2RCU35W5.js").then(
|
|
22
135
|
({ applyPatchLog, createLiveBridge, createLiveStore }) => {
|
|
23
136
|
applyLog = applyPatchLog;
|
|
24
137
|
const started = createLiveStore();
|
|
@@ -47,21 +160,15 @@ function whenLive(listener) {
|
|
|
47
160
|
return () => startListeners.delete(listener);
|
|
48
161
|
}
|
|
49
162
|
function normalizedQuery(query, data, options = {}) {
|
|
50
|
-
if (!options.enabled
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
run(data);
|
|
54
|
-
return () => {
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
}
|
|
163
|
+
if (!options.enabled) return constant(data);
|
|
164
|
+
const annotated = annotateEditLinks(data, query);
|
|
165
|
+
if (!isFramed()) return constant(annotated);
|
|
59
166
|
if (options.strictMode) strictMode = true;
|
|
60
167
|
if (options.allowedEditorOrigins) {
|
|
61
168
|
allowedEditorOrigins = [...options.allowedEditorOrigins];
|
|
62
169
|
}
|
|
63
170
|
startLive();
|
|
64
|
-
const current = () => log.length && applyLog ? applyLog(query,
|
|
171
|
+
const current = () => log.length && applyLog ? applyLog(query, annotated, log) : annotated;
|
|
65
172
|
return {
|
|
66
173
|
subscribe(run) {
|
|
67
174
|
run(current());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preprio/toolkit",
|
|
3
|
-
"version": "0.5.0-rc.
|
|
3
|
+
"version": "0.5.0-rc.6",
|
|
4
4
|
"description": "Prepr personalization, A/B testing and preview toolkit for React, Next.js, Nuxt, Astro, SvelteKit and Express",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Prepr B.V. (https://prepr.io)",
|
|
@@ -80,6 +80,11 @@
|
|
|
80
80
|
"require": "./dist/astro/index.cjs"
|
|
81
81
|
},
|
|
82
82
|
"./astro/components/*": "./src/astro/*.astro",
|
|
83
|
+
"./codegen": {
|
|
84
|
+
"types": "./dist/codegen/index.d.ts",
|
|
85
|
+
"import": "./dist/codegen/index.js",
|
|
86
|
+
"require": "./dist/codegen/index.cjs"
|
|
87
|
+
},
|
|
83
88
|
"./sveltekit": {
|
|
84
89
|
"types": "./dist/sveltekit/index.d.ts",
|
|
85
90
|
"import": "./dist/sveltekit/index.js",
|
|
@@ -125,6 +130,7 @@
|
|
|
125
130
|
"preact": "^10.29.7"
|
|
126
131
|
},
|
|
127
132
|
"peerDependencies": {
|
|
133
|
+
"graphql": ">=16",
|
|
128
134
|
"next": ">=13",
|
|
129
135
|
"react": ">=17",
|
|
130
136
|
"react-dom": ">=17",
|
|
@@ -132,6 +138,9 @@
|
|
|
132
138
|
"vue": ">=3.3"
|
|
133
139
|
},
|
|
134
140
|
"peerDependenciesMeta": {
|
|
141
|
+
"graphql": {
|
|
142
|
+
"optional": true
|
|
143
|
+
},
|
|
135
144
|
"next": {
|
|
136
145
|
"optional": true
|
|
137
146
|
},
|
|
@@ -153,6 +162,7 @@
|
|
|
153
162
|
"@types/react": "^19.2.17",
|
|
154
163
|
"@types/react-dom": "^19.2.3",
|
|
155
164
|
"browserslist": "^4.28.7",
|
|
165
|
+
"graphql": "^16.14.2",
|
|
156
166
|
"happy-dom": "^20.11.1",
|
|
157
167
|
"lightningcss": "^1.33.0",
|
|
158
168
|
"next": "^16.2.12",
|