@preprio/toolkit 1.0.0-rc.5 → 1.0.0-rc.7
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/dist/astro/index.cjs +93 -4
- package/dist/astro/index.js +93 -4
- package/dist/{chunk-AWFJ67AQ.js → chunk-6EWXOHZZ.js} +1 -1
- package/dist/{chunk-A4J3JRMY.js → chunk-GIZY3JFC.js} +1 -1
- package/dist/{chunk-KM2GME62.js → chunk-J4POHQKB.js} +92 -3
- package/dist/{chunk-GRFTP62X.js → chunk-OKP6KD3I.js} +1 -1
- package/dist/{chunk-A2J7R4LR.js → chunk-WQXLVSHA.js} +1 -1
- package/dist/index.cjs +94 -5
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +6 -6
- package/dist/{live-preview-HCBNBC6C.js → live-preview-PLHDSQ53.js} +2 -2
- package/dist/nextjs/components.cjs +1 -1
- package/dist/nextjs/components.js +2 -2
- package/dist/nextjs/index.cjs +93 -4
- package/dist/nextjs/index.d.cts +6 -2
- package/dist/nextjs/index.d.ts +6 -2
- package/dist/nextjs/index.js +93 -4
- package/dist/nextjs/live-action.js +3 -3
- package/dist/nextjs/live.cjs +117 -10
- package/dist/nextjs/live.d.cts +6 -2
- package/dist/nextjs/live.d.ts +6 -2
- package/dist/nextjs/live.js +18 -8
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/nuxt/{live-preview-KO4IKWTX.js → live-preview-T5YCASSA.js} +92 -3
- package/dist/nuxt/live.cjs +100 -3
- package/dist/nuxt/live.js +1 -1
- 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-T5YCASSA.js} +92 -3
- package/dist/sveltekit/live.cjs +100 -3
- package/dist/sveltekit/live.js +1 -1
- package/package.json +1 -1
|
@@ -150,6 +150,93 @@ 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 INTERNAL_MARK = "uuid#";
|
|
156
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
157
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
158
|
+
var TAGS = /<[^>]+>/g;
|
|
159
|
+
var MAX_PAIRINGS = 25e4;
|
|
160
|
+
function anchorsIn(html) {
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
163
|
+
const attributes = match[1];
|
|
164
|
+
const inner = match[2];
|
|
165
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
166
|
+
out.push({
|
|
167
|
+
start: match.index ?? 0,
|
|
168
|
+
end: (match.index ?? 0) + match[0].length,
|
|
169
|
+
attributes,
|
|
170
|
+
inner,
|
|
171
|
+
href,
|
|
172
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
173
|
+
text: inner.replace(TAGS, "").trim()
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
function fit(pushed, page) {
|
|
179
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
180
|
+
return pushed.text === page.text ? 2 : 1;
|
|
181
|
+
}
|
|
182
|
+
function align(pushed, page) {
|
|
183
|
+
const out = new Array(pushed.length).fill(-1);
|
|
184
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
185
|
+
const cols = page.length + 1;
|
|
186
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
187
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
188
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
189
|
+
const at = i2 * cols + j2;
|
|
190
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
191
|
+
score[at] = Math.max(
|
|
192
|
+
score[at + cols],
|
|
193
|
+
score[at + 1],
|
|
194
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
let i = 0;
|
|
199
|
+
let j = 0;
|
|
200
|
+
while (i < pushed.length && j < page.length) {
|
|
201
|
+
const at = i * cols + j;
|
|
202
|
+
const pair = fit(pushed[i], page[j]);
|
|
203
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
204
|
+
out[i++] = j++;
|
|
205
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
206
|
+
i++;
|
|
207
|
+
} else {
|
|
208
|
+
j++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
function resolveInternalLinks(current, value) {
|
|
214
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
215
|
+
const pushed = anchorsIn(value);
|
|
216
|
+
if (!pushed.some((anchor) => anchor.internal)) return value;
|
|
217
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
218
|
+
const pairs = align(pushed, page);
|
|
219
|
+
let out = "";
|
|
220
|
+
let cursor = 0;
|
|
221
|
+
pushed.forEach((anchor, i) => {
|
|
222
|
+
if (!anchor.internal) return;
|
|
223
|
+
out += value.slice(cursor, anchor.start);
|
|
224
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
225
|
+
if (match?.href != null) {
|
|
226
|
+
const href = match.href;
|
|
227
|
+
const attributes = anchor.attributes.replace(
|
|
228
|
+
HREF,
|
|
229
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
230
|
+
);
|
|
231
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
232
|
+
} else {
|
|
233
|
+
out += anchor.inner;
|
|
234
|
+
}
|
|
235
|
+
cursor = anchor.end;
|
|
236
|
+
});
|
|
237
|
+
return out + value.slice(cursor);
|
|
238
|
+
}
|
|
239
|
+
|
|
153
240
|
// src/core/live-preview/patch.ts
|
|
154
241
|
var INDEX_SEGMENT = /^\d+$/;
|
|
155
242
|
var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
@@ -319,7 +406,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
319
406
|
} else if (!isPatchable(container[key])) {
|
|
320
407
|
return root;
|
|
321
408
|
} else {
|
|
322
|
-
|
|
409
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
410
|
+
next = keepEditLink(container[key], linked);
|
|
323
411
|
}
|
|
324
412
|
if (container[key] === next) return root;
|
|
325
413
|
const newRoot = cloneNode(root);
|
|
@@ -344,7 +432,7 @@ function listKeysOf(entry) {
|
|
|
344
432
|
return keys;
|
|
345
433
|
}
|
|
346
434
|
function buildText(entry, template) {
|
|
347
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
435
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
348
436
|
const full = {
|
|
349
437
|
__typename: "Text",
|
|
350
438
|
_id: entry._id,
|
|
@@ -1168,7 +1256,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1168
1256
|
out[field.key] = [];
|
|
1169
1257
|
continue;
|
|
1170
1258
|
}
|
|
1171
|
-
const
|
|
1259
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1260
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1172
1261
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1173
1262
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1174
1263
|
}
|
package/dist/nuxt/live.cjs
CHANGED
|
@@ -540,6 +540,99 @@ 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
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
550
|
+
out.push({
|
|
551
|
+
start: match.index ?? 0,
|
|
552
|
+
end: (match.index ?? 0) + match[0].length,
|
|
553
|
+
attributes,
|
|
554
|
+
inner,
|
|
555
|
+
href,
|
|
556
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
557
|
+
text: inner.replace(TAGS, "").trim()
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return out;
|
|
561
|
+
}
|
|
562
|
+
function fit(pushed, page) {
|
|
563
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
564
|
+
return pushed.text === page.text ? 2 : 1;
|
|
565
|
+
}
|
|
566
|
+
function align(pushed, page) {
|
|
567
|
+
const out = new Array(pushed.length).fill(-1);
|
|
568
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
569
|
+
const cols = page.length + 1;
|
|
570
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
571
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
572
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
573
|
+
const at = i2 * cols + j2;
|
|
574
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
575
|
+
score[at] = Math.max(
|
|
576
|
+
score[at + cols],
|
|
577
|
+
score[at + 1],
|
|
578
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
let i = 0;
|
|
583
|
+
let j = 0;
|
|
584
|
+
while (i < pushed.length && j < page.length) {
|
|
585
|
+
const at = i * cols + j;
|
|
586
|
+
const pair = fit(pushed[i], page[j]);
|
|
587
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
588
|
+
out[i++] = j++;
|
|
589
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
590
|
+
i++;
|
|
591
|
+
} else {
|
|
592
|
+
j++;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return out;
|
|
596
|
+
}
|
|
597
|
+
function resolveInternalLinks(current, value) {
|
|
598
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
599
|
+
const pushed = anchorsIn(value);
|
|
600
|
+
if (!pushed.some((anchor) => anchor.internal)) 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 (!anchor.internal) 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, INTERNAL_MARK, ANCHOR, HREF, TAGS, MAX_PAIRINGS;
|
|
624
|
+
var init_internal_links = __esm({
|
|
625
|
+
"src/core/live-preview/internal-links.ts"() {
|
|
626
|
+
"use strict";
|
|
627
|
+
INTERNAL_HREF = /^[pa]uuid#/;
|
|
628
|
+
INTERNAL_MARK = "uuid#";
|
|
629
|
+
ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
630
|
+
HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
631
|
+
TAGS = /<[^>]+>/g;
|
|
632
|
+
MAX_PAIRINGS = 25e4;
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
|
|
543
636
|
// src/core/live-preview/patch.ts
|
|
544
637
|
function mergeObject(current, incoming) {
|
|
545
638
|
let changed = false;
|
|
@@ -707,7 +800,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
707
800
|
} else if (!isPatchable(container[key])) {
|
|
708
801
|
return root;
|
|
709
802
|
} else {
|
|
710
|
-
|
|
803
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
804
|
+
next = keepEditLink(container[key], linked);
|
|
711
805
|
}
|
|
712
806
|
if (container[key] === next) return root;
|
|
713
807
|
const newRoot = cloneNode(root);
|
|
@@ -732,7 +826,7 @@ function listKeysOf(entry) {
|
|
|
732
826
|
return keys;
|
|
733
827
|
}
|
|
734
828
|
function buildText(entry, template) {
|
|
735
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
829
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
736
830
|
const full = {
|
|
737
831
|
__typename: "Text",
|
|
738
832
|
_id: entry._id,
|
|
@@ -823,6 +917,7 @@ var init_patch = __esm({
|
|
|
823
917
|
init_guards();
|
|
824
918
|
import_stega2 = require("@vercel/stega");
|
|
825
919
|
init_field_name();
|
|
920
|
+
init_internal_links();
|
|
826
921
|
INDEX_SEGMENT = /^\d+$/;
|
|
827
922
|
FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
828
923
|
}
|
|
@@ -1619,7 +1714,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1619
1714
|
out[field.key] = [];
|
|
1620
1715
|
continue;
|
|
1621
1716
|
}
|
|
1622
|
-
const
|
|
1717
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1718
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1623
1719
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1624
1720
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1625
1721
|
}
|
|
@@ -1685,6 +1781,7 @@ var init_normalize_query = __esm({
|
|
|
1685
1781
|
init_utils();
|
|
1686
1782
|
init_field_name();
|
|
1687
1783
|
init_index_snapshot();
|
|
1784
|
+
init_internal_links();
|
|
1688
1785
|
init_patch();
|
|
1689
1786
|
init_query_document();
|
|
1690
1787
|
init_validate();
|
package/dist/nuxt/live.js
CHANGED
|
@@ -164,7 +164,7 @@ function createLiveStarter(options = {}) {
|
|
|
164
164
|
}
|
|
165
165
|
},
|
|
166
166
|
start() {
|
|
167
|
-
starting ?? (starting = import("./live-preview-
|
|
167
|
+
starting ?? (starting = import("./live-preview-T5YCASSA.js").then((runtime) => {
|
|
168
168
|
const started = runtime.createLiveStore(options.storeOptions?.());
|
|
169
169
|
options.onStart?.(started, runtime);
|
|
170
170
|
bridge = runtime.createLiveBridge(started, {
|
|
@@ -3703,7 +3703,7 @@ function createPreprPreview(opts = {}) {
|
|
|
3703
3703
|
}
|
|
3704
3704
|
|
|
3705
3705
|
// src/version.ts
|
|
3706
|
-
var VERSION = "1.0.0-rc.
|
|
3706
|
+
var VERSION = "1.0.0-rc.7";
|
|
3707
3707
|
|
|
3708
3708
|
// src/core/pixel.ts
|
|
3709
3709
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
package/dist/react/components.js
CHANGED
|
@@ -3679,7 +3679,7 @@ function createPreprPreview(opts = {}) {
|
|
|
3679
3679
|
}
|
|
3680
3680
|
|
|
3681
3681
|
// src/version.ts
|
|
3682
|
-
var VERSION = "1.0.0-rc.
|
|
3682
|
+
var VERSION = "1.0.0-rc.7";
|
|
3683
3683
|
|
|
3684
3684
|
// src/core/pixel.ts
|
|
3685
3685
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
package/dist/sveltekit/index.cjs
CHANGED
package/dist/sveltekit/index.js
CHANGED
|
@@ -150,6 +150,93 @@ 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 INTERNAL_MARK = "uuid#";
|
|
156
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
157
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
158
|
+
var TAGS = /<[^>]+>/g;
|
|
159
|
+
var MAX_PAIRINGS = 25e4;
|
|
160
|
+
function anchorsIn(html) {
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
163
|
+
const attributes = match[1];
|
|
164
|
+
const inner = match[2];
|
|
165
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
166
|
+
out.push({
|
|
167
|
+
start: match.index ?? 0,
|
|
168
|
+
end: (match.index ?? 0) + match[0].length,
|
|
169
|
+
attributes,
|
|
170
|
+
inner,
|
|
171
|
+
href,
|
|
172
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
173
|
+
text: inner.replace(TAGS, "").trim()
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return out;
|
|
177
|
+
}
|
|
178
|
+
function fit(pushed, page) {
|
|
179
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
180
|
+
return pushed.text === page.text ? 2 : 1;
|
|
181
|
+
}
|
|
182
|
+
function align(pushed, page) {
|
|
183
|
+
const out = new Array(pushed.length).fill(-1);
|
|
184
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
185
|
+
const cols = page.length + 1;
|
|
186
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
187
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
188
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
189
|
+
const at = i2 * cols + j2;
|
|
190
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
191
|
+
score[at] = Math.max(
|
|
192
|
+
score[at + cols],
|
|
193
|
+
score[at + 1],
|
|
194
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
let i = 0;
|
|
199
|
+
let j = 0;
|
|
200
|
+
while (i < pushed.length && j < page.length) {
|
|
201
|
+
const at = i * cols + j;
|
|
202
|
+
const pair = fit(pushed[i], page[j]);
|
|
203
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
204
|
+
out[i++] = j++;
|
|
205
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
206
|
+
i++;
|
|
207
|
+
} else {
|
|
208
|
+
j++;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
function resolveInternalLinks(current, value) {
|
|
214
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
215
|
+
const pushed = anchorsIn(value);
|
|
216
|
+
if (!pushed.some((anchor) => anchor.internal)) return value;
|
|
217
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
218
|
+
const pairs = align(pushed, page);
|
|
219
|
+
let out = "";
|
|
220
|
+
let cursor = 0;
|
|
221
|
+
pushed.forEach((anchor, i) => {
|
|
222
|
+
if (!anchor.internal) return;
|
|
223
|
+
out += value.slice(cursor, anchor.start);
|
|
224
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
225
|
+
if (match?.href != null) {
|
|
226
|
+
const href = match.href;
|
|
227
|
+
const attributes = anchor.attributes.replace(
|
|
228
|
+
HREF,
|
|
229
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
230
|
+
);
|
|
231
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
232
|
+
} else {
|
|
233
|
+
out += anchor.inner;
|
|
234
|
+
}
|
|
235
|
+
cursor = anchor.end;
|
|
236
|
+
});
|
|
237
|
+
return out + value.slice(cursor);
|
|
238
|
+
}
|
|
239
|
+
|
|
153
240
|
// src/core/live-preview/patch.ts
|
|
154
241
|
var INDEX_SEGMENT = /^\d+$/;
|
|
155
242
|
var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
@@ -319,7 +406,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
319
406
|
} else if (!isPatchable(container[key])) {
|
|
320
407
|
return root;
|
|
321
408
|
} else {
|
|
322
|
-
|
|
409
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
410
|
+
next = keepEditLink(container[key], linked);
|
|
323
411
|
}
|
|
324
412
|
if (container[key] === next) return root;
|
|
325
413
|
const newRoot = cloneNode(root);
|
|
@@ -344,7 +432,7 @@ function listKeysOf(entry) {
|
|
|
344
432
|
return keys;
|
|
345
433
|
}
|
|
346
434
|
function buildText(entry, template) {
|
|
347
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
435
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
348
436
|
const full = {
|
|
349
437
|
__typename: "Text",
|
|
350
438
|
_id: entry._id,
|
|
@@ -1168,7 +1256,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1168
1256
|
out[field.key] = [];
|
|
1169
1257
|
continue;
|
|
1170
1258
|
}
|
|
1171
|
-
const
|
|
1259
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1260
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1172
1261
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1173
1262
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1174
1263
|
}
|
package/dist/sveltekit/live.cjs
CHANGED
|
@@ -540,6 +540,99 @@ 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
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
550
|
+
out.push({
|
|
551
|
+
start: match.index ?? 0,
|
|
552
|
+
end: (match.index ?? 0) + match[0].length,
|
|
553
|
+
attributes,
|
|
554
|
+
inner,
|
|
555
|
+
href,
|
|
556
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
557
|
+
text: inner.replace(TAGS, "").trim()
|
|
558
|
+
});
|
|
559
|
+
}
|
|
560
|
+
return out;
|
|
561
|
+
}
|
|
562
|
+
function fit(pushed, page) {
|
|
563
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
564
|
+
return pushed.text === page.text ? 2 : 1;
|
|
565
|
+
}
|
|
566
|
+
function align(pushed, page) {
|
|
567
|
+
const out = new Array(pushed.length).fill(-1);
|
|
568
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
569
|
+
const cols = page.length + 1;
|
|
570
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
571
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
572
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
573
|
+
const at = i2 * cols + j2;
|
|
574
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
575
|
+
score[at] = Math.max(
|
|
576
|
+
score[at + cols],
|
|
577
|
+
score[at + 1],
|
|
578
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
let i = 0;
|
|
583
|
+
let j = 0;
|
|
584
|
+
while (i < pushed.length && j < page.length) {
|
|
585
|
+
const at = i * cols + j;
|
|
586
|
+
const pair = fit(pushed[i], page[j]);
|
|
587
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
588
|
+
out[i++] = j++;
|
|
589
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
590
|
+
i++;
|
|
591
|
+
} else {
|
|
592
|
+
j++;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
return out;
|
|
596
|
+
}
|
|
597
|
+
function resolveInternalLinks(current, value) {
|
|
598
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
599
|
+
const pushed = anchorsIn(value);
|
|
600
|
+
if (!pushed.some((anchor) => anchor.internal)) 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 (!anchor.internal) 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, INTERNAL_MARK, ANCHOR, HREF, TAGS, MAX_PAIRINGS;
|
|
624
|
+
var init_internal_links = __esm({
|
|
625
|
+
"src/core/live-preview/internal-links.ts"() {
|
|
626
|
+
"use strict";
|
|
627
|
+
INTERNAL_HREF = /^[pa]uuid#/;
|
|
628
|
+
INTERNAL_MARK = "uuid#";
|
|
629
|
+
ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
630
|
+
HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
631
|
+
TAGS = /<[^>]+>/g;
|
|
632
|
+
MAX_PAIRINGS = 25e4;
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
|
|
543
636
|
// src/core/live-preview/patch.ts
|
|
544
637
|
function mergeObject(current, incoming) {
|
|
545
638
|
let changed = false;
|
|
@@ -707,7 +800,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
707
800
|
} else if (!isPatchable(container[key])) {
|
|
708
801
|
return root;
|
|
709
802
|
} else {
|
|
710
|
-
|
|
803
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
804
|
+
next = keepEditLink(container[key], linked);
|
|
711
805
|
}
|
|
712
806
|
if (container[key] === next) return root;
|
|
713
807
|
const newRoot = cloneNode(root);
|
|
@@ -732,7 +826,7 @@ function listKeysOf(entry) {
|
|
|
732
826
|
return keys;
|
|
733
827
|
}
|
|
734
828
|
function buildText(entry, template) {
|
|
735
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
829
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
736
830
|
const full = {
|
|
737
831
|
__typename: "Text",
|
|
738
832
|
_id: entry._id,
|
|
@@ -823,6 +917,7 @@ var init_patch = __esm({
|
|
|
823
917
|
init_guards();
|
|
824
918
|
import_stega2 = require("@vercel/stega");
|
|
825
919
|
init_field_name();
|
|
920
|
+
init_internal_links();
|
|
826
921
|
INDEX_SEGMENT = /^\d+$/;
|
|
827
922
|
FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
828
923
|
}
|
|
@@ -1619,7 +1714,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1619
1714
|
out[field.key] = [];
|
|
1620
1715
|
continue;
|
|
1621
1716
|
}
|
|
1622
|
-
const
|
|
1717
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1718
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1623
1719
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1624
1720
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1625
1721
|
}
|
|
@@ -1685,6 +1781,7 @@ var init_normalize_query = __esm({
|
|
|
1685
1781
|
init_utils();
|
|
1686
1782
|
init_field_name();
|
|
1687
1783
|
init_index_snapshot();
|
|
1784
|
+
init_internal_links();
|
|
1688
1785
|
init_patch();
|
|
1689
1786
|
init_query_document();
|
|
1690
1787
|
init_validate();
|
package/dist/sveltekit/live.js
CHANGED
|
@@ -155,7 +155,7 @@ function createLiveStarter(options = {}) {
|
|
|
155
155
|
}
|
|
156
156
|
},
|
|
157
157
|
start() {
|
|
158
|
-
starting ?? (starting = import("./live-preview-
|
|
158
|
+
starting ?? (starting = import("./live-preview-T5YCASSA.js").then((runtime) => {
|
|
159
159
|
const started = runtime.createLiveStore(options.storeOptions?.());
|
|
160
160
|
options.onStart?.(started, runtime);
|
|
161
161
|
bridge = runtime.createLiveBridge(started, {
|
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.7",
|
|
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)",
|