@preprio/toolkit 1.0.0-rc.4 → 1.0.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 +2 -0
- package/dist/astro/index.cjs +126 -18
- package/dist/astro/index.js +128 -19
- package/dist/{chunk-A2J7R4LR.js → chunk-I26P2EQI.js} +1 -1
- package/dist/{chunk-QWTSVPEQ.js → chunk-OCTRCNW2.js} +1 -1
- package/dist/{chunk-KM2GME62.js → chunk-RWFAFYHU.js} +90 -1
- package/dist/{chunk-6PMBN7OR.js → chunk-SAOE54OB.js} +1 -1
- package/dist/{chunk-K62RW46G.js → chunk-WQRPW3TM.js} +1 -1
- package/dist/index.cjs +128 -19
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.js +44 -23
- package/dist/{live-preview-HCBNBC6C.js → live-preview-NUDEDAYQ.js} +2 -2
- package/dist/nextjs/components.cjs +1 -1
- package/dist/nextjs/components.js +2 -2
- package/dist/nextjs/index.cjs +189 -20
- package/dist/nextjs/index.d.cts +47 -1
- package/dist/nextjs/index.d.ts +47 -1
- package/dist/nextjs/index.js +190 -21
- package/dist/nextjs/live-action.js +3 -3
- package/dist/nextjs/live.cjs +102 -6
- package/dist/nextjs/live.d.cts +7 -1
- package/dist/nextjs/live.d.ts +7 -1
- package/dist/nextjs/live.js +8 -6
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/nuxt/{live-preview-KO4IKWTX.js → live-preview-V2X6GPSK.js} +88 -1
- package/dist/nuxt/live.cjs +130 -17
- package/dist/nuxt/live.js +38 -18
- 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-preview-KO4IKWTX.js → live-preview-V2X6GPSK.js} +88 -1
- package/dist/sveltekit/live.cjs +130 -17
- package/dist/sveltekit/live.js +38 -18
- package/package.json +1 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
import {
|
|
3
3
|
isPreviewFromHeaders
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import "../chunk-
|
|
4
|
+
} from "../chunk-SAOE54OB.js";
|
|
5
|
+
import "../chunk-OCTRCNW2.js";
|
|
6
6
|
import {
|
|
7
7
|
parsePatchLog
|
|
8
|
-
} from "../chunk-
|
|
8
|
+
} from "../chunk-RWFAFYHU.js";
|
|
9
9
|
import "../chunk-V7MCHPE7.js";
|
|
10
10
|
|
|
11
11
|
// src/nextjs/live-action.ts
|
package/dist/nextjs/live.cjs
CHANGED
|
@@ -215,6 +215,98 @@ var init_field_name = __esm({
|
|
|
215
215
|
}
|
|
216
216
|
});
|
|
217
217
|
|
|
218
|
+
// src/core/live-preview/internal-links.ts
|
|
219
|
+
function anchorsIn(html) {
|
|
220
|
+
const out = [];
|
|
221
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
222
|
+
const attributes = match[1];
|
|
223
|
+
const inner = match[2];
|
|
224
|
+
out.push({
|
|
225
|
+
start: match.index ?? 0,
|
|
226
|
+
end: (match.index ?? 0) + match[0].length,
|
|
227
|
+
attributes,
|
|
228
|
+
inner,
|
|
229
|
+
href: HREF.exec(attributes)?.[3] ?? null,
|
|
230
|
+
text: inner.replace(TAGS, "").trim()
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
235
|
+
function fit(pushed, page) {
|
|
236
|
+
if (!isInternal(pushed) && pushed.href !== page.href) return 0;
|
|
237
|
+
if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
|
|
238
|
+
return 0;
|
|
239
|
+
return pushed.text === page.text ? 2 : 1;
|
|
240
|
+
}
|
|
241
|
+
function align(pushed, page) {
|
|
242
|
+
const rows = pushed.length + 1;
|
|
243
|
+
const cols = page.length + 1;
|
|
244
|
+
const score = Array.from(
|
|
245
|
+
{ length: rows },
|
|
246
|
+
() => new Array(cols).fill(0)
|
|
247
|
+
);
|
|
248
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
249
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
250
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
251
|
+
score[i2][j2] = Math.max(
|
|
252
|
+
score[i2 + 1][j2],
|
|
253
|
+
score[i2][j2 + 1],
|
|
254
|
+
pair ? pair + score[i2 + 1][j2 + 1] : 0
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const out = new Array(pushed.length).fill(-1);
|
|
259
|
+
let i = 0;
|
|
260
|
+
let j = 0;
|
|
261
|
+
while (i < pushed.length && j < page.length) {
|
|
262
|
+
const pair = fit(pushed[i], page[j]);
|
|
263
|
+
if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
|
|
264
|
+
out[i++] = j++;
|
|
265
|
+
} else if (score[i + 1][j] >= score[i][j + 1]) {
|
|
266
|
+
i++;
|
|
267
|
+
} else {
|
|
268
|
+
j++;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
function resolveInternalLinks(current, value) {
|
|
274
|
+
const pushed = anchorsIn(value);
|
|
275
|
+
if (!pushed.some(isInternal)) return value;
|
|
276
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
277
|
+
const pairs = align(pushed, page);
|
|
278
|
+
let out = "";
|
|
279
|
+
let cursor = 0;
|
|
280
|
+
pushed.forEach((anchor, i) => {
|
|
281
|
+
if (!isInternal(anchor)) return;
|
|
282
|
+
out += value.slice(cursor, anchor.start);
|
|
283
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
284
|
+
if (match?.href != null) {
|
|
285
|
+
const href = match.href;
|
|
286
|
+
const attributes = anchor.attributes.replace(
|
|
287
|
+
HREF,
|
|
288
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
289
|
+
);
|
|
290
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
291
|
+
} else {
|
|
292
|
+
out += anchor.inner;
|
|
293
|
+
}
|
|
294
|
+
cursor = anchor.end;
|
|
295
|
+
});
|
|
296
|
+
return out + value.slice(cursor);
|
|
297
|
+
}
|
|
298
|
+
var INTERNAL_HREF, ANCHOR, HREF, TAGS, isInternal;
|
|
299
|
+
var init_internal_links = __esm({
|
|
300
|
+
"src/core/live-preview/internal-links.ts"() {
|
|
301
|
+
"use strict";
|
|
302
|
+
INTERNAL_HREF = /^[pa]uuid#/;
|
|
303
|
+
ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
304
|
+
HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
305
|
+
TAGS = /<[^>]+>/g;
|
|
306
|
+
isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
218
310
|
// src/core/live-preview/patch.ts
|
|
219
311
|
function mergeObject(current, incoming) {
|
|
220
312
|
let changed = false;
|
|
@@ -382,7 +474,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
382
474
|
} else if (!isPatchable(container[key])) {
|
|
383
475
|
return root;
|
|
384
476
|
} else {
|
|
385
|
-
|
|
477
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
478
|
+
next = keepEditLink(container[key], linked);
|
|
386
479
|
}
|
|
387
480
|
if (container[key] === next) return root;
|
|
388
481
|
const newRoot = cloneNode(root);
|
|
@@ -498,6 +591,7 @@ var init_patch = __esm({
|
|
|
498
591
|
init_guards();
|
|
499
592
|
import_stega = require("@vercel/stega");
|
|
500
593
|
init_field_name();
|
|
594
|
+
init_internal_links();
|
|
501
595
|
INDEX_SEGMENT = /^\d+$/;
|
|
502
596
|
FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
503
597
|
}
|
|
@@ -1798,6 +1892,7 @@ function createLiveStarter(options = {}) {
|
|
|
1798
1892
|
var import_live_action = require("./live-action.cjs");
|
|
1799
1893
|
var debug6 = createScopedLogger("live-preview:next");
|
|
1800
1894
|
var LOG_SYNC_DEBOUNCE_MS = 150;
|
|
1895
|
+
var debounceOf = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : LOG_SYNC_DEBOUNCE_MS;
|
|
1801
1896
|
var starter = createLiveStarter({
|
|
1802
1897
|
storeOptions() {
|
|
1803
1898
|
const skipped = new Set(quarantined());
|
|
@@ -1842,7 +1937,8 @@ function useLive(data, opts) {
|
|
|
1842
1937
|
function PreprRefresh({
|
|
1843
1938
|
enabled = false,
|
|
1844
1939
|
allowedEditorOrigins: origins,
|
|
1845
|
-
strictMode: strict = false
|
|
1940
|
+
strictMode: strict = false,
|
|
1941
|
+
syncDebounceMs
|
|
1846
1942
|
}) {
|
|
1847
1943
|
const router = (0, import_navigation.useRouter)();
|
|
1848
1944
|
const originsKey = origins?.join(" ");
|
|
@@ -1852,7 +1948,7 @@ function PreprRefresh({
|
|
|
1852
1948
|
strictMode: strict,
|
|
1853
1949
|
allowedEditorOrigins: originsKey?.split(" ")
|
|
1854
1950
|
});
|
|
1855
|
-
const sync = createLogSync();
|
|
1951
|
+
const sync = createLogSync(debounceOf(syncDebounceMs));
|
|
1856
1952
|
let unsubscribe = null;
|
|
1857
1953
|
let active = true;
|
|
1858
1954
|
void starter.start().then((started) => {
|
|
@@ -1872,7 +1968,7 @@ function PreprRefresh({
|
|
|
1872
1968
|
unsubscribe?.();
|
|
1873
1969
|
sync.cancel();
|
|
1874
1970
|
};
|
|
1875
|
-
}, [enabled, originsKey, strict, router]);
|
|
1971
|
+
}, [enabled, originsKey, strict, syncDebounceMs, router]);
|
|
1876
1972
|
return null;
|
|
1877
1973
|
}
|
|
1878
1974
|
var STEGA_CHARS = /[\u200b-\u200d\u2060-\u2064\ufeff]/;
|
|
@@ -1947,7 +2043,7 @@ function watchClientRenders(watched) {
|
|
|
1947
2043
|
}, CLIENT_RENDER_MS);
|
|
1948
2044
|
});
|
|
1949
2045
|
}
|
|
1950
|
-
function createLogSync() {
|
|
2046
|
+
function createLogSync(debounceMs) {
|
|
1951
2047
|
let timer = null;
|
|
1952
2048
|
let inFlight = false;
|
|
1953
2049
|
let pending = null;
|
|
@@ -1999,7 +2095,7 @@ function createLogSync() {
|
|
|
1999
2095
|
timer = null;
|
|
2000
2096
|
if (inFlight) pending = log;
|
|
2001
2097
|
else void send(log);
|
|
2002
|
-
},
|
|
2098
|
+
}, debounceMs);
|
|
2003
2099
|
},
|
|
2004
2100
|
cancel() {
|
|
2005
2101
|
cancelled = true;
|
package/dist/nextjs/live.d.cts
CHANGED
|
@@ -23,6 +23,12 @@ interface PreprRefreshProps {
|
|
|
23
23
|
allowedEditorOrigins?: string[];
|
|
24
24
|
/** Your preview token uses GraphQL strict mode; see the toolbar option. */
|
|
25
25
|
strictMode?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* How long typing must pause, in milliseconds, before the unsaved changes
|
|
28
|
+
* go to the server. Default 150. Lower shows changes sooner at the cost of
|
|
29
|
+
* more server renders; raise it when a render is expensive.
|
|
30
|
+
*/
|
|
31
|
+
syncDebounceMs?: number;
|
|
26
32
|
}
|
|
27
33
|
interface UseLiveOptions {
|
|
28
34
|
/** Query (string or DocumentNode) passed as-is to the fetcher. */
|
|
@@ -49,6 +55,6 @@ declare function useLive<T>(data: T, opts?: UseLiveOptions): T;
|
|
|
49
55
|
* Use this or `useLive` with a `query`, not both: a save would refetch and
|
|
50
56
|
* refresh.
|
|
51
57
|
*/
|
|
52
|
-
declare function PreprRefresh({ enabled, allowedEditorOrigins: origins, strictMode: strict, }: PreprRefreshProps): null;
|
|
58
|
+
declare function PreprRefresh({ enabled, allowedEditorOrigins: origins, strictMode: strict, syncDebounceMs, }: PreprRefreshProps): null;
|
|
53
59
|
|
|
54
60
|
export { type LivePreviewConfig, PreprRefresh, type PreprRefreshProps, type UseLiveOptions, initLivePreview, useLive };
|
package/dist/nextjs/live.d.ts
CHANGED
|
@@ -23,6 +23,12 @@ interface PreprRefreshProps {
|
|
|
23
23
|
allowedEditorOrigins?: string[];
|
|
24
24
|
/** Your preview token uses GraphQL strict mode; see the toolbar option. */
|
|
25
25
|
strictMode?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* How long typing must pause, in milliseconds, before the unsaved changes
|
|
28
|
+
* go to the server. Default 150. Lower shows changes sooner at the cost of
|
|
29
|
+
* more server renders; raise it when a render is expensive.
|
|
30
|
+
*/
|
|
31
|
+
syncDebounceMs?: number;
|
|
26
32
|
}
|
|
27
33
|
interface UseLiveOptions {
|
|
28
34
|
/** Query (string or DocumentNode) passed as-is to the fetcher. */
|
|
@@ -49,6 +55,6 @@ declare function useLive<T>(data: T, opts?: UseLiveOptions): T;
|
|
|
49
55
|
* Use this or `useLive` with a `query`, not both: a save would refetch and
|
|
50
56
|
* refresh.
|
|
51
57
|
*/
|
|
52
|
-
declare function PreprRefresh({ enabled, allowedEditorOrigins: origins, strictMode: strict, }: PreprRefreshProps): null;
|
|
58
|
+
declare function PreprRefresh({ enabled, allowedEditorOrigins: origins, strictMode: strict, syncDebounceMs, }: PreprRefreshProps): null;
|
|
53
59
|
|
|
54
60
|
export { type LivePreviewConfig, PreprRefresh, type PreprRefreshProps, type UseLiveOptions, initLivePreview, useLive };
|
package/dist/nextjs/live.js
CHANGED
|
@@ -45,7 +45,7 @@ function createLiveStarter(options = {}) {
|
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
47
|
start() {
|
|
48
|
-
starting ?? (starting = import("../live-preview-
|
|
48
|
+
starting ?? (starting = import("../live-preview-NUDEDAYQ.js").then((runtime) => {
|
|
49
49
|
const started = runtime.createLiveStore(options.storeOptions?.());
|
|
50
50
|
options.onStart?.(started, runtime);
|
|
51
51
|
bridge = runtime.createLiveBridge(started, {
|
|
@@ -76,6 +76,7 @@ function createLiveStarter(options = {}) {
|
|
|
76
76
|
import { syncPreprLiveLog } from "./live-action.js";
|
|
77
77
|
var debug = createScopedLogger("live-preview:next");
|
|
78
78
|
var LOG_SYNC_DEBOUNCE_MS = 150;
|
|
79
|
+
var debounceOf = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : LOG_SYNC_DEBOUNCE_MS;
|
|
79
80
|
var starter = createLiveStarter({
|
|
80
81
|
storeOptions() {
|
|
81
82
|
const skipped = new Set(quarantined());
|
|
@@ -120,7 +121,8 @@ function useLive(data, opts) {
|
|
|
120
121
|
function PreprRefresh({
|
|
121
122
|
enabled = false,
|
|
122
123
|
allowedEditorOrigins: origins,
|
|
123
|
-
strictMode: strict = false
|
|
124
|
+
strictMode: strict = false,
|
|
125
|
+
syncDebounceMs
|
|
124
126
|
}) {
|
|
125
127
|
const router = useRouter();
|
|
126
128
|
const originsKey = origins?.join(" ");
|
|
@@ -130,7 +132,7 @@ function PreprRefresh({
|
|
|
130
132
|
strictMode: strict,
|
|
131
133
|
allowedEditorOrigins: originsKey?.split(" ")
|
|
132
134
|
});
|
|
133
|
-
const sync = createLogSync();
|
|
135
|
+
const sync = createLogSync(debounceOf(syncDebounceMs));
|
|
134
136
|
let unsubscribe = null;
|
|
135
137
|
let active = true;
|
|
136
138
|
void starter.start().then((started) => {
|
|
@@ -150,7 +152,7 @@ function PreprRefresh({
|
|
|
150
152
|
unsubscribe?.();
|
|
151
153
|
sync.cancel();
|
|
152
154
|
};
|
|
153
|
-
}, [enabled, originsKey, strict, router]);
|
|
155
|
+
}, [enabled, originsKey, strict, syncDebounceMs, router]);
|
|
154
156
|
return null;
|
|
155
157
|
}
|
|
156
158
|
var STEGA_CHARS = /[\u200b-\u200d\u2060-\u2064\ufeff]/;
|
|
@@ -225,7 +227,7 @@ function watchClientRenders(watched) {
|
|
|
225
227
|
}, CLIENT_RENDER_MS);
|
|
226
228
|
});
|
|
227
229
|
}
|
|
228
|
-
function createLogSync() {
|
|
230
|
+
function createLogSync(debounceMs) {
|
|
229
231
|
let timer = null;
|
|
230
232
|
let inFlight = false;
|
|
231
233
|
let pending = null;
|
|
@@ -277,7 +279,7 @@ function createLogSync() {
|
|
|
277
279
|
timer = null;
|
|
278
280
|
if (inFlight) pending = log;
|
|
279
281
|
else void send(log);
|
|
280
|
-
},
|
|
282
|
+
}, debounceMs);
|
|
281
283
|
},
|
|
282
284
|
cancel() {
|
|
283
285
|
cancelled = true;
|
package/dist/nuxt/index.cjs
CHANGED
package/dist/nuxt/index.js
CHANGED
|
@@ -150,6 +150,92 @@ function isTextEntry(record) {
|
|
|
150
150
|
return "html" in record || "text" in record && "format" in record;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
|
+
// src/core/live-preview/internal-links.ts
|
|
154
|
+
var INTERNAL_HREF = /^[pa]uuid#/;
|
|
155
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
156
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
157
|
+
var TAGS = /<[^>]+>/g;
|
|
158
|
+
function anchorsIn(html) {
|
|
159
|
+
const out = [];
|
|
160
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
161
|
+
const attributes = match[1];
|
|
162
|
+
const inner = match[2];
|
|
163
|
+
out.push({
|
|
164
|
+
start: match.index ?? 0,
|
|
165
|
+
end: (match.index ?? 0) + match[0].length,
|
|
166
|
+
attributes,
|
|
167
|
+
inner,
|
|
168
|
+
href: HREF.exec(attributes)?.[3] ?? null,
|
|
169
|
+
text: inner.replace(TAGS, "").trim()
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
return out;
|
|
173
|
+
}
|
|
174
|
+
var isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
|
|
175
|
+
function fit(pushed, page) {
|
|
176
|
+
if (!isInternal(pushed) && pushed.href !== page.href) return 0;
|
|
177
|
+
if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
|
|
178
|
+
return 0;
|
|
179
|
+
return pushed.text === page.text ? 2 : 1;
|
|
180
|
+
}
|
|
181
|
+
function align(pushed, page) {
|
|
182
|
+
const rows = pushed.length + 1;
|
|
183
|
+
const cols = page.length + 1;
|
|
184
|
+
const score = Array.from(
|
|
185
|
+
{ length: rows },
|
|
186
|
+
() => new Array(cols).fill(0)
|
|
187
|
+
);
|
|
188
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
189
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
190
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
191
|
+
score[i2][j2] = Math.max(
|
|
192
|
+
score[i2 + 1][j2],
|
|
193
|
+
score[i2][j2 + 1],
|
|
194
|
+
pair ? pair + score[i2 + 1][j2 + 1] : 0
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
const out = new Array(pushed.length).fill(-1);
|
|
199
|
+
let i = 0;
|
|
200
|
+
let j = 0;
|
|
201
|
+
while (i < pushed.length && j < page.length) {
|
|
202
|
+
const pair = fit(pushed[i], page[j]);
|
|
203
|
+
if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
|
|
204
|
+
out[i++] = j++;
|
|
205
|
+
} else if (score[i + 1][j] >= score[i][j + 1]) {
|
|
206
|
+
i++;
|
|
207
|
+
} else {
|
|
208
|
+
j++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
function resolveInternalLinks(current, value) {
|
|
214
|
+
const pushed = anchorsIn(value);
|
|
215
|
+
if (!pushed.some(isInternal)) return value;
|
|
216
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
217
|
+
const pairs = align(pushed, page);
|
|
218
|
+
let out = "";
|
|
219
|
+
let cursor = 0;
|
|
220
|
+
pushed.forEach((anchor, i) => {
|
|
221
|
+
if (!isInternal(anchor)) return;
|
|
222
|
+
out += value.slice(cursor, anchor.start);
|
|
223
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
224
|
+
if (match?.href != null) {
|
|
225
|
+
const href = match.href;
|
|
226
|
+
const attributes = anchor.attributes.replace(
|
|
227
|
+
HREF,
|
|
228
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
229
|
+
);
|
|
230
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
231
|
+
} else {
|
|
232
|
+
out += anchor.inner;
|
|
233
|
+
}
|
|
234
|
+
cursor = anchor.end;
|
|
235
|
+
});
|
|
236
|
+
return out + value.slice(cursor);
|
|
237
|
+
}
|
|
238
|
+
|
|
153
239
|
// src/core/live-preview/patch.ts
|
|
154
240
|
var INDEX_SEGMENT = /^\d+$/;
|
|
155
241
|
var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
@@ -319,7 +405,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
319
405
|
} else if (!isPatchable(container[key])) {
|
|
320
406
|
return root;
|
|
321
407
|
} else {
|
|
322
|
-
|
|
408
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
409
|
+
next = keepEditLink(container[key], linked);
|
|
323
410
|
}
|
|
324
411
|
if (container[key] === next) return root;
|
|
325
412
|
const newRoot = cloneNode(root);
|
package/dist/nuxt/live.cjs
CHANGED
|
@@ -540,6 +540,98 @@ var init_field_name = __esm({
|
|
|
540
540
|
}
|
|
541
541
|
});
|
|
542
542
|
|
|
543
|
+
// src/core/live-preview/internal-links.ts
|
|
544
|
+
function anchorsIn(html) {
|
|
545
|
+
const out = [];
|
|
546
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
547
|
+
const attributes = match[1];
|
|
548
|
+
const inner = match[2];
|
|
549
|
+
out.push({
|
|
550
|
+
start: match.index ?? 0,
|
|
551
|
+
end: (match.index ?? 0) + match[0].length,
|
|
552
|
+
attributes,
|
|
553
|
+
inner,
|
|
554
|
+
href: HREF.exec(attributes)?.[3] ?? null,
|
|
555
|
+
text: inner.replace(TAGS, "").trim()
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return out;
|
|
559
|
+
}
|
|
560
|
+
function fit(pushed, page) {
|
|
561
|
+
if (!isInternal(pushed) && pushed.href !== page.href) return 0;
|
|
562
|
+
if (isInternal(pushed) && page.href !== null && INTERNAL_HREF.test(page.href))
|
|
563
|
+
return 0;
|
|
564
|
+
return pushed.text === page.text ? 2 : 1;
|
|
565
|
+
}
|
|
566
|
+
function align(pushed, page) {
|
|
567
|
+
const rows = pushed.length + 1;
|
|
568
|
+
const cols = page.length + 1;
|
|
569
|
+
const score = Array.from(
|
|
570
|
+
{ length: rows },
|
|
571
|
+
() => new Array(cols).fill(0)
|
|
572
|
+
);
|
|
573
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
574
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
575
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
576
|
+
score[i2][j2] = Math.max(
|
|
577
|
+
score[i2 + 1][j2],
|
|
578
|
+
score[i2][j2 + 1],
|
|
579
|
+
pair ? pair + score[i2 + 1][j2 + 1] : 0
|
|
580
|
+
);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
const out = new Array(pushed.length).fill(-1);
|
|
584
|
+
let i = 0;
|
|
585
|
+
let j = 0;
|
|
586
|
+
while (i < pushed.length && j < page.length) {
|
|
587
|
+
const pair = fit(pushed[i], page[j]);
|
|
588
|
+
if (pair && score[i][j] === pair + score[i + 1][j + 1]) {
|
|
589
|
+
out[i++] = j++;
|
|
590
|
+
} else if (score[i + 1][j] >= score[i][j + 1]) {
|
|
591
|
+
i++;
|
|
592
|
+
} else {
|
|
593
|
+
j++;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return out;
|
|
597
|
+
}
|
|
598
|
+
function resolveInternalLinks(current, value) {
|
|
599
|
+
const pushed = anchorsIn(value);
|
|
600
|
+
if (!pushed.some(isInternal)) return value;
|
|
601
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
602
|
+
const pairs = align(pushed, page);
|
|
603
|
+
let out = "";
|
|
604
|
+
let cursor = 0;
|
|
605
|
+
pushed.forEach((anchor, i) => {
|
|
606
|
+
if (!isInternal(anchor)) return;
|
|
607
|
+
out += value.slice(cursor, anchor.start);
|
|
608
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
609
|
+
if (match?.href != null) {
|
|
610
|
+
const href = match.href;
|
|
611
|
+
const attributes = anchor.attributes.replace(
|
|
612
|
+
HREF,
|
|
613
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
614
|
+
);
|
|
615
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
616
|
+
} else {
|
|
617
|
+
out += anchor.inner;
|
|
618
|
+
}
|
|
619
|
+
cursor = anchor.end;
|
|
620
|
+
});
|
|
621
|
+
return out + value.slice(cursor);
|
|
622
|
+
}
|
|
623
|
+
var INTERNAL_HREF, ANCHOR, HREF, TAGS, isInternal;
|
|
624
|
+
var init_internal_links = __esm({
|
|
625
|
+
"src/core/live-preview/internal-links.ts"() {
|
|
626
|
+
"use strict";
|
|
627
|
+
INTERNAL_HREF = /^[pa]uuid#/;
|
|
628
|
+
ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
629
|
+
HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
630
|
+
TAGS = /<[^>]+>/g;
|
|
631
|
+
isInternal = (anchor) => anchor.href !== null && INTERNAL_HREF.test(anchor.href);
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
|
|
543
635
|
// src/core/live-preview/patch.ts
|
|
544
636
|
function mergeObject(current, incoming) {
|
|
545
637
|
let changed = false;
|
|
@@ -707,7 +799,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
707
799
|
} else if (!isPatchable(container[key])) {
|
|
708
800
|
return root;
|
|
709
801
|
} else {
|
|
710
|
-
|
|
802
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
803
|
+
next = keepEditLink(container[key], linked);
|
|
711
804
|
}
|
|
712
805
|
if (container[key] === next) return root;
|
|
713
806
|
const newRoot = cloneNode(root);
|
|
@@ -823,6 +916,7 @@ var init_patch = __esm({
|
|
|
823
916
|
init_guards();
|
|
824
917
|
import_stega2 = require("@vercel/stega");
|
|
825
918
|
init_field_name();
|
|
919
|
+
init_internal_links();
|
|
826
920
|
INDEX_SEGMENT = /^\d+$/;
|
|
827
921
|
FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
828
922
|
}
|
|
@@ -1741,34 +1835,53 @@ function entryIdOf(element) {
|
|
|
1741
1835
|
const first = element.items[0];
|
|
1742
1836
|
return isObject(first) && typeof first._id === "string" ? first._id : void 0;
|
|
1743
1837
|
}
|
|
1744
|
-
function
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1838
|
+
function encodeLink(payload) {
|
|
1839
|
+
try {
|
|
1840
|
+
return (0, import_stega.legacyStegaEncode)(payload);
|
|
1841
|
+
} catch {
|
|
1842
|
+
return (0, import_stega.vercelStegaEncode)(payload);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
function rewriteLink(encoded, entryId, entryField, entryOwnerId) {
|
|
1748
1846
|
let payload;
|
|
1749
1847
|
try {
|
|
1750
1848
|
payload = (0, import_stega.vercelStegaDecode)(encoded);
|
|
1751
1849
|
} catch {
|
|
1752
|
-
return
|
|
1850
|
+
return "";
|
|
1753
1851
|
}
|
|
1754
|
-
if (typeof payload?.href !== "string") return
|
|
1852
|
+
if (typeof payload?.href !== "string") return "";
|
|
1755
1853
|
let url;
|
|
1756
1854
|
try {
|
|
1757
1855
|
url = new URL(payload.href);
|
|
1758
1856
|
} catch {
|
|
1759
|
-
return
|
|
1857
|
+
return "";
|
|
1760
1858
|
}
|
|
1761
|
-
if (url.searchParams.has(ENTRY_PARAM)) return
|
|
1762
|
-
url.searchParams.set(ENTRY_PARAM,
|
|
1859
|
+
if (url.searchParams.has(ENTRY_PARAM)) return "";
|
|
1860
|
+
url.searchParams.set(ENTRY_PARAM, entryId);
|
|
1763
1861
|
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
1764
|
-
if (!url.searchParams.has("field") &&
|
|
1765
|
-
url.searchParams.set("field",
|
|
1862
|
+
if (!url.searchParams.has("field") && entryField && itemId === entryOwnerId) {
|
|
1863
|
+
url.searchParams.set("field", entryField);
|
|
1766
1864
|
}
|
|
1767
|
-
return (
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1865
|
+
return encodeLink({ ...payload, href: url.toString() });
|
|
1866
|
+
}
|
|
1867
|
+
var MAX_REWRITTEN = 1e4;
|
|
1868
|
+
var rewritten = /* @__PURE__ */ new Map();
|
|
1869
|
+
function annotate(value, ctx) {
|
|
1870
|
+
if (!ctx.entryId) return value;
|
|
1871
|
+
const { cleaned, encoded } = (0, import_stega.vercelStegaSplit)(value);
|
|
1872
|
+
if (!encoded) return value;
|
|
1873
|
+
const entryField = ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) ? ctx.entryField : "";
|
|
1874
|
+
const key = `${ctx.entryId}
|
|
1875
|
+
${entryField}
|
|
1876
|
+
${ctx.entryOwnerId ?? ""}
|
|
1877
|
+
${encoded}`;
|
|
1878
|
+
let link = rewritten.get(key);
|
|
1879
|
+
if (link === void 0) {
|
|
1880
|
+
link = rewriteLink(encoded, ctx.entryId, entryField, ctx.entryOwnerId);
|
|
1881
|
+
if (rewritten.size >= MAX_REWRITTEN) rewritten.clear();
|
|
1882
|
+
rewritten.set(key, link);
|
|
1883
|
+
}
|
|
1884
|
+
return link ? cleaned + link : value;
|
|
1772
1885
|
}
|
|
1773
1886
|
function walk(value, selections, ctx) {
|
|
1774
1887
|
if (typeof value === "string") return annotate(value, ctx);
|
package/dist/nuxt/live.js
CHANGED
|
@@ -15,8 +15,9 @@ import {
|
|
|
15
15
|
|
|
16
16
|
// src/core/live-preview/edit-links.ts
|
|
17
17
|
import {
|
|
18
|
-
|
|
18
|
+
legacyStegaEncode,
|
|
19
19
|
vercelStegaDecode,
|
|
20
|
+
vercelStegaEncode,
|
|
20
21
|
vercelStegaSplit
|
|
21
22
|
} from "@vercel/stega";
|
|
22
23
|
var ENTRY_PARAM = "entry";
|
|
@@ -30,34 +31,53 @@ function entryIdOf(element) {
|
|
|
30
31
|
const first = element.items[0];
|
|
31
32
|
return isObject(first) && typeof first._id === "string" ? first._id : void 0;
|
|
32
33
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
function encodeLink(payload) {
|
|
35
|
+
try {
|
|
36
|
+
return legacyStegaEncode(payload);
|
|
37
|
+
} catch {
|
|
38
|
+
return vercelStegaEncode(payload);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function rewriteLink(encoded, entryId, entryField, entryOwnerId) {
|
|
37
42
|
let payload;
|
|
38
43
|
try {
|
|
39
44
|
payload = vercelStegaDecode(encoded);
|
|
40
45
|
} catch {
|
|
41
|
-
return
|
|
46
|
+
return "";
|
|
42
47
|
}
|
|
43
|
-
if (typeof payload?.href !== "string") return
|
|
48
|
+
if (typeof payload?.href !== "string") return "";
|
|
44
49
|
let url;
|
|
45
50
|
try {
|
|
46
51
|
url = new URL(payload.href);
|
|
47
52
|
} catch {
|
|
48
|
-
return
|
|
53
|
+
return "";
|
|
49
54
|
}
|
|
50
|
-
if (url.searchParams.has(ENTRY_PARAM)) return
|
|
51
|
-
url.searchParams.set(ENTRY_PARAM,
|
|
55
|
+
if (url.searchParams.has(ENTRY_PARAM)) return "";
|
|
56
|
+
url.searchParams.set(ENTRY_PARAM, entryId);
|
|
52
57
|
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
53
|
-
if (!url.searchParams.has("field") &&
|
|
54
|
-
url.searchParams.set("field",
|
|
58
|
+
if (!url.searchParams.has("field") && entryField && itemId === entryOwnerId) {
|
|
59
|
+
url.searchParams.set("field", entryField);
|
|
55
60
|
}
|
|
56
|
-
return
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
return encodeLink({ ...payload, href: url.toString() });
|
|
62
|
+
}
|
|
63
|
+
var MAX_REWRITTEN = 1e4;
|
|
64
|
+
var rewritten = /* @__PURE__ */ new Map();
|
|
65
|
+
function annotate(value, ctx) {
|
|
66
|
+
if (!ctx.entryId) return value;
|
|
67
|
+
const { cleaned, encoded } = vercelStegaSplit(value);
|
|
68
|
+
if (!encoded) return value;
|
|
69
|
+
const entryField = ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) ? ctx.entryField : "";
|
|
70
|
+
const key = `${ctx.entryId}
|
|
71
|
+
${entryField}
|
|
72
|
+
${ctx.entryOwnerId ?? ""}
|
|
73
|
+
${encoded}`;
|
|
74
|
+
let link = rewritten.get(key);
|
|
75
|
+
if (link === void 0) {
|
|
76
|
+
link = rewriteLink(encoded, ctx.entryId, entryField, ctx.entryOwnerId);
|
|
77
|
+
if (rewritten.size >= MAX_REWRITTEN) rewritten.clear();
|
|
78
|
+
rewritten.set(key, link);
|
|
79
|
+
}
|
|
80
|
+
return link ? cleaned + link : value;
|
|
61
81
|
}
|
|
62
82
|
function walk(value, selections, ctx) {
|
|
63
83
|
if (typeof value === "string") return annotate(value, ctx);
|
|
@@ -144,7 +164,7 @@ function createLiveStarter(options = {}) {
|
|
|
144
164
|
}
|
|
145
165
|
},
|
|
146
166
|
start() {
|
|
147
|
-
starting ?? (starting = import("./live-preview-
|
|
167
|
+
starting ?? (starting = import("./live-preview-V2X6GPSK.js").then((runtime) => {
|
|
148
168
|
const started = runtime.createLiveStore(options.storeOptions?.());
|
|
149
169
|
options.onStart?.(started, runtime);
|
|
150
170
|
bridge = runtime.createLiveBridge(started, {
|