@preprio/toolkit 1.0.0-rc.4 → 1.0.0-rc.5
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 +2 -0
- package/dist/astro/index.cjs +36 -17
- package/dist/astro/index.js +38 -18
- package/dist/{chunk-QWTSVPEQ.js → chunk-A4J3JRMY.js} +1 -1
- package/dist/{chunk-K62RW46G.js → chunk-AWFJ67AQ.js} +1 -1
- package/dist/{chunk-6PMBN7OR.js → chunk-GRFTP62X.js} +1 -1
- package/dist/index.cjs +38 -18
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +42 -21
- package/dist/nextjs/components.cjs +1 -1
- package/dist/nextjs/components.js +2 -2
- package/dist/nextjs/index.cjs +99 -19
- package/dist/nextjs/index.d.cts +47 -1
- package/dist/nextjs/index.d.ts +47 -1
- package/dist/nextjs/index.js +100 -20
- package/dist/nextjs/live-action.js +2 -2
- package/dist/nextjs/live.cjs +7 -5
- package/dist/nextjs/live.d.cts +7 -1
- package/dist/nextjs/live.d.ts +7 -1
- package/dist/nextjs/live.js +7 -5
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/nuxt/live.cjs +35 -16
- package/dist/nuxt/live.js +37 -17
- package/dist/react/components.cjs +1 -1
- package/dist/react/components.js +1 -1
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/dist/sveltekit/live.cjs +35 -16
- package/dist/sveltekit/live.js +37 -17
- package/package.json +1 -1
package/dist/sveltekit/index.js
CHANGED
package/dist/sveltekit/live.cjs
CHANGED
|
@@ -1740,34 +1740,53 @@ function entryIdOf(element) {
|
|
|
1740
1740
|
const first = element.items[0];
|
|
1741
1741
|
return isObject(first) && typeof first._id === "string" ? first._id : void 0;
|
|
1742
1742
|
}
|
|
1743
|
-
function
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1743
|
+
function encodeLink(payload) {
|
|
1744
|
+
try {
|
|
1745
|
+
return (0, import_stega.legacyStegaEncode)(payload);
|
|
1746
|
+
} catch {
|
|
1747
|
+
return (0, import_stega.vercelStegaEncode)(payload);
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
function rewriteLink(encoded, entryId, entryField, entryOwnerId) {
|
|
1747
1751
|
let payload;
|
|
1748
1752
|
try {
|
|
1749
1753
|
payload = (0, import_stega.vercelStegaDecode)(encoded);
|
|
1750
1754
|
} catch {
|
|
1751
|
-
return
|
|
1755
|
+
return "";
|
|
1752
1756
|
}
|
|
1753
|
-
if (typeof payload?.href !== "string") return
|
|
1757
|
+
if (typeof payload?.href !== "string") return "";
|
|
1754
1758
|
let url;
|
|
1755
1759
|
try {
|
|
1756
1760
|
url = new URL(payload.href);
|
|
1757
1761
|
} catch {
|
|
1758
|
-
return
|
|
1762
|
+
return "";
|
|
1759
1763
|
}
|
|
1760
|
-
if (url.searchParams.has(ENTRY_PARAM)) return
|
|
1761
|
-
url.searchParams.set(ENTRY_PARAM,
|
|
1764
|
+
if (url.searchParams.has(ENTRY_PARAM)) return "";
|
|
1765
|
+
url.searchParams.set(ENTRY_PARAM, entryId);
|
|
1762
1766
|
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
1763
|
-
if (!url.searchParams.has("field") &&
|
|
1764
|
-
url.searchParams.set("field",
|
|
1767
|
+
if (!url.searchParams.has("field") && entryField && itemId === entryOwnerId) {
|
|
1768
|
+
url.searchParams.set("field", entryField);
|
|
1765
1769
|
}
|
|
1766
|
-
return (
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1770
|
+
return encodeLink({ ...payload, href: url.toString() });
|
|
1771
|
+
}
|
|
1772
|
+
var MAX_REWRITTEN = 1e4;
|
|
1773
|
+
var rewritten = /* @__PURE__ */ new Map();
|
|
1774
|
+
function annotate(value, ctx) {
|
|
1775
|
+
if (!ctx.entryId) return value;
|
|
1776
|
+
const { cleaned, encoded } = (0, import_stega.vercelStegaSplit)(value);
|
|
1777
|
+
if (!encoded) return value;
|
|
1778
|
+
const entryField = ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) ? ctx.entryField : "";
|
|
1779
|
+
const key = `${ctx.entryId}
|
|
1780
|
+
${entryField}
|
|
1781
|
+
${ctx.entryOwnerId ?? ""}
|
|
1782
|
+
${encoded}`;
|
|
1783
|
+
let link = rewritten.get(key);
|
|
1784
|
+
if (link === void 0) {
|
|
1785
|
+
link = rewriteLink(encoded, ctx.entryId, entryField, ctx.entryOwnerId);
|
|
1786
|
+
if (rewritten.size >= MAX_REWRITTEN) rewritten.clear();
|
|
1787
|
+
rewritten.set(key, link);
|
|
1788
|
+
}
|
|
1789
|
+
return link ? cleaned + link : value;
|
|
1771
1790
|
}
|
|
1772
1791
|
function walk(value, selections, ctx) {
|
|
1773
1792
|
if (typeof value === "string") return annotate(value, ctx);
|
package/dist/sveltekit/live.js
CHANGED
|
@@ -6,8 +6,9 @@ import {
|
|
|
6
6
|
|
|
7
7
|
// src/core/live-preview/edit-links.ts
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
legacyStegaEncode,
|
|
10
10
|
vercelStegaDecode,
|
|
11
|
+
vercelStegaEncode,
|
|
11
12
|
vercelStegaSplit
|
|
12
13
|
} from "@vercel/stega";
|
|
13
14
|
var ENTRY_PARAM = "entry";
|
|
@@ -21,34 +22,53 @@ function entryIdOf(element) {
|
|
|
21
22
|
const first = element.items[0];
|
|
22
23
|
return isObject(first) && typeof first._id === "string" ? first._id : void 0;
|
|
23
24
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
function encodeLink(payload) {
|
|
26
|
+
try {
|
|
27
|
+
return legacyStegaEncode(payload);
|
|
28
|
+
} catch {
|
|
29
|
+
return vercelStegaEncode(payload);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function rewriteLink(encoded, entryId, entryField, entryOwnerId) {
|
|
28
33
|
let payload;
|
|
29
34
|
try {
|
|
30
35
|
payload = vercelStegaDecode(encoded);
|
|
31
36
|
} catch {
|
|
32
|
-
return
|
|
37
|
+
return "";
|
|
33
38
|
}
|
|
34
|
-
if (typeof payload?.href !== "string") return
|
|
39
|
+
if (typeof payload?.href !== "string") return "";
|
|
35
40
|
let url;
|
|
36
41
|
try {
|
|
37
42
|
url = new URL(payload.href);
|
|
38
43
|
} catch {
|
|
39
|
-
return
|
|
44
|
+
return "";
|
|
40
45
|
}
|
|
41
|
-
if (url.searchParams.has(ENTRY_PARAM)) return
|
|
42
|
-
url.searchParams.set(ENTRY_PARAM,
|
|
46
|
+
if (url.searchParams.has(ENTRY_PARAM)) return "";
|
|
47
|
+
url.searchParams.set(ENTRY_PARAM, entryId);
|
|
43
48
|
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
44
|
-
if (!url.searchParams.has("field") &&
|
|
45
|
-
url.searchParams.set("field",
|
|
49
|
+
if (!url.searchParams.has("field") && entryField && itemId === entryOwnerId) {
|
|
50
|
+
url.searchParams.set("field", entryField);
|
|
51
|
+
}
|
|
52
|
+
return encodeLink({ ...payload, href: url.toString() });
|
|
53
|
+
}
|
|
54
|
+
var MAX_REWRITTEN = 1e4;
|
|
55
|
+
var rewritten = /* @__PURE__ */ new Map();
|
|
56
|
+
function annotate(value, ctx) {
|
|
57
|
+
if (!ctx.entryId) return value;
|
|
58
|
+
const { cleaned, encoded } = vercelStegaSplit(value);
|
|
59
|
+
if (!encoded) return value;
|
|
60
|
+
const entryField = ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) ? ctx.entryField : "";
|
|
61
|
+
const key = `${ctx.entryId}
|
|
62
|
+
${entryField}
|
|
63
|
+
${ctx.entryOwnerId ?? ""}
|
|
64
|
+
${encoded}`;
|
|
65
|
+
let link = rewritten.get(key);
|
|
66
|
+
if (link === void 0) {
|
|
67
|
+
link = rewriteLink(encoded, ctx.entryId, entryField, ctx.entryOwnerId);
|
|
68
|
+
if (rewritten.size >= MAX_REWRITTEN) rewritten.clear();
|
|
69
|
+
rewritten.set(key, link);
|
|
46
70
|
}
|
|
47
|
-
return
|
|
48
|
-
cleaned,
|
|
49
|
-
{ ...payload, href: url.toString() },
|
|
50
|
-
false
|
|
51
|
-
);
|
|
71
|
+
return link ? cleaned + link : value;
|
|
52
72
|
}
|
|
53
73
|
function walk(value, selections, ctx) {
|
|
54
74
|
if (typeof value === "string") return annotate(value, ctx);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preprio/toolkit",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.5",
|
|
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)",
|