@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
package/dist/astro/index.cjs
CHANGED
|
@@ -34,7 +34,7 @@ __export(astro_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(astro_exports);
|
|
35
35
|
|
|
36
36
|
// src/version.ts
|
|
37
|
-
var VERSION = "1.0.0-rc.
|
|
37
|
+
var VERSION = "1.0.0-rc.7";
|
|
38
38
|
|
|
39
39
|
// src/core/constants.ts
|
|
40
40
|
var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
|
|
@@ -563,6 +563,93 @@ function indexSnapshot(data) {
|
|
|
563
563
|
return index;
|
|
564
564
|
}
|
|
565
565
|
|
|
566
|
+
// src/core/live-preview/internal-links.ts
|
|
567
|
+
var INTERNAL_HREF = /^[pa]uuid#/;
|
|
568
|
+
var INTERNAL_MARK = "uuid#";
|
|
569
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
570
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
571
|
+
var TAGS = /<[^>]+>/g;
|
|
572
|
+
var MAX_PAIRINGS = 25e4;
|
|
573
|
+
function anchorsIn(html) {
|
|
574
|
+
const out = [];
|
|
575
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
576
|
+
const attributes = match[1];
|
|
577
|
+
const inner = match[2];
|
|
578
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
579
|
+
out.push({
|
|
580
|
+
start: match.index ?? 0,
|
|
581
|
+
end: (match.index ?? 0) + match[0].length,
|
|
582
|
+
attributes,
|
|
583
|
+
inner,
|
|
584
|
+
href,
|
|
585
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
586
|
+
text: inner.replace(TAGS, "").trim()
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
return out;
|
|
590
|
+
}
|
|
591
|
+
function fit(pushed, page) {
|
|
592
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
593
|
+
return pushed.text === page.text ? 2 : 1;
|
|
594
|
+
}
|
|
595
|
+
function align(pushed, page) {
|
|
596
|
+
const out = new Array(pushed.length).fill(-1);
|
|
597
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
598
|
+
const cols = page.length + 1;
|
|
599
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
600
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
601
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
602
|
+
const at = i2 * cols + j2;
|
|
603
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
604
|
+
score[at] = Math.max(
|
|
605
|
+
score[at + cols],
|
|
606
|
+
score[at + 1],
|
|
607
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
let i = 0;
|
|
612
|
+
let j = 0;
|
|
613
|
+
while (i < pushed.length && j < page.length) {
|
|
614
|
+
const at = i * cols + j;
|
|
615
|
+
const pair = fit(pushed[i], page[j]);
|
|
616
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
617
|
+
out[i++] = j++;
|
|
618
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
619
|
+
i++;
|
|
620
|
+
} else {
|
|
621
|
+
j++;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
return out;
|
|
625
|
+
}
|
|
626
|
+
function resolveInternalLinks(current, value) {
|
|
627
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
628
|
+
const pushed = anchorsIn(value);
|
|
629
|
+
if (!pushed.some((anchor) => anchor.internal)) return value;
|
|
630
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
631
|
+
const pairs = align(pushed, page);
|
|
632
|
+
let out = "";
|
|
633
|
+
let cursor = 0;
|
|
634
|
+
pushed.forEach((anchor, i) => {
|
|
635
|
+
if (!anchor.internal) return;
|
|
636
|
+
out += value.slice(cursor, anchor.start);
|
|
637
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
638
|
+
if (match?.href != null) {
|
|
639
|
+
const href = match.href;
|
|
640
|
+
const attributes = anchor.attributes.replace(
|
|
641
|
+
HREF,
|
|
642
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
643
|
+
);
|
|
644
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
645
|
+
} else {
|
|
646
|
+
out += anchor.inner;
|
|
647
|
+
}
|
|
648
|
+
cursor = anchor.end;
|
|
649
|
+
});
|
|
650
|
+
return out + value.slice(cursor);
|
|
651
|
+
}
|
|
652
|
+
|
|
566
653
|
// src/core/live-preview/patch.ts
|
|
567
654
|
var import_stega2 = require("@vercel/stega");
|
|
568
655
|
var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
@@ -662,7 +749,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
662
749
|
} else if (!isPatchable(container[key])) {
|
|
663
750
|
return root;
|
|
664
751
|
} else {
|
|
665
|
-
|
|
752
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
753
|
+
next = keepEditLink(container[key], linked);
|
|
666
754
|
}
|
|
667
755
|
if (container[key] === next) return root;
|
|
668
756
|
const newRoot = cloneNode(root);
|
|
@@ -687,7 +775,7 @@ function listKeysOf(entry) {
|
|
|
687
775
|
return keys;
|
|
688
776
|
}
|
|
689
777
|
function buildText(entry, template) {
|
|
690
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
778
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
691
779
|
const full = {
|
|
692
780
|
__typename: "Text",
|
|
693
781
|
_id: entry._id,
|
|
@@ -1382,7 +1470,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1382
1470
|
out[field.key] = [];
|
|
1383
1471
|
continue;
|
|
1384
1472
|
}
|
|
1385
|
-
const
|
|
1473
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1474
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1386
1475
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1387
1476
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1388
1477
|
}
|
package/dist/astro/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/version.ts
|
|
2
|
-
var VERSION = "1.0.0-rc.
|
|
2
|
+
var VERSION = "1.0.0-rc.7";
|
|
3
3
|
|
|
4
4
|
// src/core/constants.ts
|
|
5
5
|
var COOKIE_PREVIEW_MODE = "Prepr-Preview-Mode";
|
|
@@ -532,6 +532,93 @@ function indexSnapshot(data) {
|
|
|
532
532
|
return index;
|
|
533
533
|
}
|
|
534
534
|
|
|
535
|
+
// src/core/live-preview/internal-links.ts
|
|
536
|
+
var INTERNAL_HREF = /^[pa]uuid#/;
|
|
537
|
+
var INTERNAL_MARK = "uuid#";
|
|
538
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
539
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
540
|
+
var TAGS = /<[^>]+>/g;
|
|
541
|
+
var MAX_PAIRINGS = 25e4;
|
|
542
|
+
function anchorsIn(html) {
|
|
543
|
+
const out = [];
|
|
544
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
545
|
+
const attributes = match[1];
|
|
546
|
+
const inner = match[2];
|
|
547
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
548
|
+
out.push({
|
|
549
|
+
start: match.index ?? 0,
|
|
550
|
+
end: (match.index ?? 0) + match[0].length,
|
|
551
|
+
attributes,
|
|
552
|
+
inner,
|
|
553
|
+
href,
|
|
554
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
555
|
+
text: inner.replace(TAGS, "").trim()
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
return out;
|
|
559
|
+
}
|
|
560
|
+
function fit(pushed, page) {
|
|
561
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
562
|
+
return pushed.text === page.text ? 2 : 1;
|
|
563
|
+
}
|
|
564
|
+
function align(pushed, page) {
|
|
565
|
+
const out = new Array(pushed.length).fill(-1);
|
|
566
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
567
|
+
const cols = page.length + 1;
|
|
568
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
569
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
570
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
571
|
+
const at = i2 * cols + j2;
|
|
572
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
573
|
+
score[at] = Math.max(
|
|
574
|
+
score[at + cols],
|
|
575
|
+
score[at + 1],
|
|
576
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
577
|
+
);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
let i = 0;
|
|
581
|
+
let j = 0;
|
|
582
|
+
while (i < pushed.length && j < page.length) {
|
|
583
|
+
const at = i * cols + j;
|
|
584
|
+
const pair = fit(pushed[i], page[j]);
|
|
585
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
586
|
+
out[i++] = j++;
|
|
587
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
588
|
+
i++;
|
|
589
|
+
} else {
|
|
590
|
+
j++;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
return out;
|
|
594
|
+
}
|
|
595
|
+
function resolveInternalLinks(current, value) {
|
|
596
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
597
|
+
const pushed = anchorsIn(value);
|
|
598
|
+
if (!pushed.some((anchor) => anchor.internal)) return value;
|
|
599
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
600
|
+
const pairs = align(pushed, page);
|
|
601
|
+
let out = "";
|
|
602
|
+
let cursor = 0;
|
|
603
|
+
pushed.forEach((anchor, i) => {
|
|
604
|
+
if (!anchor.internal) return;
|
|
605
|
+
out += value.slice(cursor, anchor.start);
|
|
606
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
607
|
+
if (match?.href != null) {
|
|
608
|
+
const href = match.href;
|
|
609
|
+
const attributes = anchor.attributes.replace(
|
|
610
|
+
HREF,
|
|
611
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
612
|
+
);
|
|
613
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
614
|
+
} else {
|
|
615
|
+
out += anchor.inner;
|
|
616
|
+
}
|
|
617
|
+
cursor = anchor.end;
|
|
618
|
+
});
|
|
619
|
+
return out + value.slice(cursor);
|
|
620
|
+
}
|
|
621
|
+
|
|
535
622
|
// src/core/live-preview/patch.ts
|
|
536
623
|
import { vercelStegaSplit as vercelStegaSplit2 } from "@vercel/stega";
|
|
537
624
|
var FORBIDDEN_SEGMENTS = /* @__PURE__ */ new Set(["__proto__", "prototype", "constructor"]);
|
|
@@ -631,7 +718,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
631
718
|
} else if (!isPatchable(container[key])) {
|
|
632
719
|
return root;
|
|
633
720
|
} else {
|
|
634
|
-
|
|
721
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
722
|
+
next = keepEditLink(container[key], linked);
|
|
635
723
|
}
|
|
636
724
|
if (container[key] === next) return root;
|
|
637
725
|
const newRoot = cloneNode(root);
|
|
@@ -656,7 +744,7 @@ function listKeysOf(entry) {
|
|
|
656
744
|
return keys;
|
|
657
745
|
}
|
|
658
746
|
function buildText(entry, template) {
|
|
659
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
747
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
660
748
|
const full = {
|
|
661
749
|
__typename: "Text",
|
|
662
750
|
_id: entry._id,
|
|
@@ -1351,7 +1439,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1351
1439
|
out[field.key] = [];
|
|
1352
1440
|
continue;
|
|
1353
1441
|
}
|
|
1354
|
-
const
|
|
1442
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1443
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1355
1444
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1356
1445
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1357
1446
|
}
|
|
@@ -280,6 +280,93 @@ function indexSnapshot(data) {
|
|
|
280
280
|
return index;
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
// src/core/live-preview/internal-links.ts
|
|
284
|
+
var INTERNAL_HREF = /^[pa]uuid#/;
|
|
285
|
+
var INTERNAL_MARK = "uuid#";
|
|
286
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
287
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
288
|
+
var TAGS = /<[^>]+>/g;
|
|
289
|
+
var MAX_PAIRINGS = 25e4;
|
|
290
|
+
function anchorsIn(html) {
|
|
291
|
+
const out = [];
|
|
292
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
293
|
+
const attributes = match[1];
|
|
294
|
+
const inner = match[2];
|
|
295
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
296
|
+
out.push({
|
|
297
|
+
start: match.index ?? 0,
|
|
298
|
+
end: (match.index ?? 0) + match[0].length,
|
|
299
|
+
attributes,
|
|
300
|
+
inner,
|
|
301
|
+
href,
|
|
302
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
303
|
+
text: inner.replace(TAGS, "").trim()
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
function fit(pushed, page) {
|
|
309
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
310
|
+
return pushed.text === page.text ? 2 : 1;
|
|
311
|
+
}
|
|
312
|
+
function align(pushed, page) {
|
|
313
|
+
const out = new Array(pushed.length).fill(-1);
|
|
314
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
315
|
+
const cols = page.length + 1;
|
|
316
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
317
|
+
for (let i2 = pushed.length - 1; i2 >= 0; i2--) {
|
|
318
|
+
for (let j2 = page.length - 1; j2 >= 0; j2--) {
|
|
319
|
+
const at = i2 * cols + j2;
|
|
320
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
321
|
+
score[at] = Math.max(
|
|
322
|
+
score[at + cols],
|
|
323
|
+
score[at + 1],
|
|
324
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
let i = 0;
|
|
329
|
+
let j = 0;
|
|
330
|
+
while (i < pushed.length && j < page.length) {
|
|
331
|
+
const at = i * cols + j;
|
|
332
|
+
const pair = fit(pushed[i], page[j]);
|
|
333
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
334
|
+
out[i++] = j++;
|
|
335
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
336
|
+
i++;
|
|
337
|
+
} else {
|
|
338
|
+
j++;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return out;
|
|
342
|
+
}
|
|
343
|
+
function resolveInternalLinks(current, value) {
|
|
344
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
345
|
+
const pushed = anchorsIn(value);
|
|
346
|
+
if (!pushed.some((anchor) => anchor.internal)) return value;
|
|
347
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
348
|
+
const pairs = align(pushed, page);
|
|
349
|
+
let out = "";
|
|
350
|
+
let cursor = 0;
|
|
351
|
+
pushed.forEach((anchor, i) => {
|
|
352
|
+
if (!anchor.internal) return;
|
|
353
|
+
out += value.slice(cursor, anchor.start);
|
|
354
|
+
const match = pairs[i] >= 0 ? page[pairs[i]] : null;
|
|
355
|
+
if (match?.href != null) {
|
|
356
|
+
const href = match.href;
|
|
357
|
+
const attributes = anchor.attributes.replace(
|
|
358
|
+
HREF,
|
|
359
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
360
|
+
);
|
|
361
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
362
|
+
} else {
|
|
363
|
+
out += anchor.inner;
|
|
364
|
+
}
|
|
365
|
+
cursor = anchor.end;
|
|
366
|
+
});
|
|
367
|
+
return out + value.slice(cursor);
|
|
368
|
+
}
|
|
369
|
+
|
|
283
370
|
// src/core/live-preview/patch.ts
|
|
284
371
|
import { vercelStegaSplit as vercelStegaSplit2 } from "@vercel/stega";
|
|
285
372
|
var INDEX_SEGMENT = /^\d+$/;
|
|
@@ -450,7 +537,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
450
537
|
} else if (!isPatchable(container[key])) {
|
|
451
538
|
return root;
|
|
452
539
|
} else {
|
|
453
|
-
|
|
540
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
541
|
+
next = keepEditLink(container[key], linked);
|
|
454
542
|
}
|
|
455
543
|
if (container[key] === next) return root;
|
|
456
544
|
const newRoot = cloneNode(root);
|
|
@@ -475,7 +563,7 @@ function listKeysOf(entry) {
|
|
|
475
563
|
return keys;
|
|
476
564
|
}
|
|
477
565
|
function buildText(entry, template) {
|
|
478
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
566
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
479
567
|
const full = {
|
|
480
568
|
__typename: "Text",
|
|
481
569
|
_id: entry._id,
|
|
@@ -1181,7 +1269,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
1181
1269
|
out[field.key] = [];
|
|
1182
1270
|
continue;
|
|
1183
1271
|
}
|
|
1184
|
-
const
|
|
1272
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
1273
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
1185
1274
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
1186
1275
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
1187
1276
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -51,7 +51,7 @@ __export(src_exports, {
|
|
|
51
51
|
module.exports = __toCommonJS(src_exports);
|
|
52
52
|
|
|
53
53
|
// src/version.ts
|
|
54
|
-
var VERSION = "1.0.0-rc.
|
|
54
|
+
var VERSION = "1.0.0-rc.7";
|
|
55
55
|
|
|
56
56
|
// src/core/features.ts
|
|
57
57
|
function isEnabled(config) {
|
|
@@ -4046,6 +4046,93 @@ function indexSnapshot(data) {
|
|
|
4046
4046
|
return index;
|
|
4047
4047
|
}
|
|
4048
4048
|
|
|
4049
|
+
// src/core/live-preview/internal-links.ts
|
|
4050
|
+
var INTERNAL_HREF = /^[pa]uuid#/;
|
|
4051
|
+
var INTERNAL_MARK = "uuid#";
|
|
4052
|
+
var ANCHOR = /<a\b([^>]*)>([\s\S]*?)<\/a>/gi;
|
|
4053
|
+
var HREF = /(\shref\s*=\s*)(["'])(.*?)\2/i;
|
|
4054
|
+
var TAGS = /<[^>]+>/g;
|
|
4055
|
+
var MAX_PAIRINGS = 25e4;
|
|
4056
|
+
function anchorsIn(html) {
|
|
4057
|
+
const out = [];
|
|
4058
|
+
for (const match of html.matchAll(ANCHOR)) {
|
|
4059
|
+
const attributes = match[1];
|
|
4060
|
+
const inner = match[2];
|
|
4061
|
+
const href = HREF.exec(attributes)?.[3] ?? null;
|
|
4062
|
+
out.push({
|
|
4063
|
+
start: match.index ?? 0,
|
|
4064
|
+
end: (match.index ?? 0) + match[0].length,
|
|
4065
|
+
attributes,
|
|
4066
|
+
inner,
|
|
4067
|
+
href,
|
|
4068
|
+
internal: href !== null && INTERNAL_HREF.test(href),
|
|
4069
|
+
text: inner.replace(TAGS, "").trim()
|
|
4070
|
+
});
|
|
4071
|
+
}
|
|
4072
|
+
return out;
|
|
4073
|
+
}
|
|
4074
|
+
function fit(pushed, page) {
|
|
4075
|
+
if (pushed.internal ? page.internal : pushed.href !== page.href) return 0;
|
|
4076
|
+
return pushed.text === page.text ? 2 : 1;
|
|
4077
|
+
}
|
|
4078
|
+
function align(pushed, page) {
|
|
4079
|
+
const out = new Array(pushed.length).fill(-1);
|
|
4080
|
+
if (!page.length || pushed.length * page.length > MAX_PAIRINGS) return out;
|
|
4081
|
+
const cols = page.length + 1;
|
|
4082
|
+
const score = new Int32Array((pushed.length + 1) * cols);
|
|
4083
|
+
for (let i3 = pushed.length - 1; i3 >= 0; i3--) {
|
|
4084
|
+
for (let j3 = page.length - 1; j3 >= 0; j3--) {
|
|
4085
|
+
const at = i3 * cols + j3;
|
|
4086
|
+
const pair = fit(pushed[i3], page[j3]);
|
|
4087
|
+
score[at] = Math.max(
|
|
4088
|
+
score[at + cols],
|
|
4089
|
+
score[at + 1],
|
|
4090
|
+
pair ? pair + score[at + cols + 1] : 0
|
|
4091
|
+
);
|
|
4092
|
+
}
|
|
4093
|
+
}
|
|
4094
|
+
let i2 = 0;
|
|
4095
|
+
let j2 = 0;
|
|
4096
|
+
while (i2 < pushed.length && j2 < page.length) {
|
|
4097
|
+
const at = i2 * cols + j2;
|
|
4098
|
+
const pair = fit(pushed[i2], page[j2]);
|
|
4099
|
+
if (pair && score[at] === pair + score[at + cols + 1]) {
|
|
4100
|
+
out[i2++] = j2++;
|
|
4101
|
+
} else if (score[at + cols] >= score[at + 1]) {
|
|
4102
|
+
i2++;
|
|
4103
|
+
} else {
|
|
4104
|
+
j2++;
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
return out;
|
|
4108
|
+
}
|
|
4109
|
+
function resolveInternalLinks(current, value) {
|
|
4110
|
+
if (!value.includes(INTERNAL_MARK)) return value;
|
|
4111
|
+
const pushed = anchorsIn(value);
|
|
4112
|
+
if (!pushed.some((anchor) => anchor.internal)) return value;
|
|
4113
|
+
const page = typeof current === "string" ? anchorsIn(current) : [];
|
|
4114
|
+
const pairs = align(pushed, page);
|
|
4115
|
+
let out = "";
|
|
4116
|
+
let cursor = 0;
|
|
4117
|
+
pushed.forEach((anchor, i2) => {
|
|
4118
|
+
if (!anchor.internal) return;
|
|
4119
|
+
out += value.slice(cursor, anchor.start);
|
|
4120
|
+
const match = pairs[i2] >= 0 ? page[pairs[i2]] : null;
|
|
4121
|
+
if (match?.href != null) {
|
|
4122
|
+
const href = match.href;
|
|
4123
|
+
const attributes = anchor.attributes.replace(
|
|
4124
|
+
HREF,
|
|
4125
|
+
(_all, lead, quote) => `${lead}${quote}${href}${quote}`
|
|
4126
|
+
);
|
|
4127
|
+
out += `<a${attributes}>${anchor.inner}</a>`;
|
|
4128
|
+
} else {
|
|
4129
|
+
out += anchor.inner;
|
|
4130
|
+
}
|
|
4131
|
+
cursor = anchor.end;
|
|
4132
|
+
});
|
|
4133
|
+
return out + value.slice(cursor);
|
|
4134
|
+
}
|
|
4135
|
+
|
|
4049
4136
|
// src/core/live-preview/patch.ts
|
|
4050
4137
|
var import_stega6 = require("@vercel/stega");
|
|
4051
4138
|
var INDEX_SEGMENT2 = /^\d+$/;
|
|
@@ -4216,7 +4303,8 @@ function writeAtPath(root, fullPath, value, markChanged = () => {
|
|
|
4216
4303
|
} else if (!isPatchable(container[key])) {
|
|
4217
4304
|
return root;
|
|
4218
4305
|
} else {
|
|
4219
|
-
|
|
4306
|
+
const linked = typeof value === "string" ? resolveInternalLinks(container[key], value) : value;
|
|
4307
|
+
next = keepEditLink(container[key], linked);
|
|
4220
4308
|
}
|
|
4221
4309
|
if (container[key] === next) return root;
|
|
4222
4310
|
const newRoot = cloneNode(root);
|
|
@@ -4241,7 +4329,7 @@ function listKeysOf(entry) {
|
|
|
4241
4329
|
return keys;
|
|
4242
4330
|
}
|
|
4243
4331
|
function buildText(entry, template) {
|
|
4244
|
-
const body = typeof entry.body === "string" ? entry.body : "";
|
|
4332
|
+
const body = typeof entry.body === "string" ? resolveInternalLinks(null, entry.body) : "";
|
|
4245
4333
|
const full = {
|
|
4246
4334
|
__typename: "Text",
|
|
4247
4335
|
_id: entry._id,
|
|
@@ -4947,7 +5035,8 @@ function fillObject(doc, selections, typename, values, id, ctx) {
|
|
|
4947
5035
|
out[field.key] = [];
|
|
4948
5036
|
continue;
|
|
4949
5037
|
}
|
|
4950
|
-
const
|
|
5038
|
+
const sent = value === void 0 || value !== null && typeof value === "object" ? null : value;
|
|
5039
|
+
const scalar = typeof sent === "string" ? resolveInternalLinks(null, sent) : sent;
|
|
4951
5040
|
const target = typeof scalar === "string" ? editField(field.name) : null;
|
|
4952
5041
|
out[field.key] = target && links ? links.encode(scalar, target) : scalar;
|
|
4953
5042
|
}
|
|
@@ -5412,7 +5501,7 @@ function adopt(node, parent) {
|
|
|
5412
5501
|
// src/core/live-preview/html-live.ts
|
|
5413
5502
|
var debug14 = createScopedLogger("live-preview:html");
|
|
5414
5503
|
var COMPLETE_DOCUMENT = /<\/html>\s*$/i;
|
|
5415
|
-
var SYNC_DEBOUNCE_MS =
|
|
5504
|
+
var SYNC_DEBOUNCE_MS = 0;
|
|
5416
5505
|
function startHtmlLivePreview(options = {}) {
|
|
5417
5506
|
if (typeof window === "undefined" || window.self === window.top) {
|
|
5418
5507
|
return { stop() {
|
package/dist/index.d.cts
CHANGED
|
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
|
|
|
5
5
|
* Package version; must match package.json. Lives in its own leaf module so
|
|
6
6
|
* core can import it without cycling through the barrel.
|
|
7
7
|
*/
|
|
8
|
-
declare const VERSION = "1.0.0-rc.
|
|
8
|
+
declare const VERSION = "1.0.0-rc.7";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
|
|
@@ -449,9 +449,10 @@ interface HtmlLivePreviewOptions {
|
|
|
449
449
|
strictMode?: boolean;
|
|
450
450
|
/**
|
|
451
451
|
* How long typing must pause, in milliseconds, before the page is
|
|
452
|
-
* requested with the unsaved changes. Default
|
|
453
|
-
*
|
|
454
|
-
*
|
|
452
|
+
* requested with the unsaved changes. Default 0: the page is requested as
|
|
453
|
+
* soon as the editor sends a change, which it does after a pause of its
|
|
454
|
+
* own. Requests run one at a time either way; raise this when a render is
|
|
455
|
+
* expensive, to have fewer of them.
|
|
455
456
|
*/
|
|
456
457
|
syncDebounceMs?: number;
|
|
457
458
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j
|
|
|
5
5
|
* Package version; must match package.json. Lives in its own leaf module so
|
|
6
6
|
* core can import it without cycling through the barrel.
|
|
7
7
|
*/
|
|
8
|
-
declare const VERSION = "1.0.0-rc.
|
|
8
|
+
declare const VERSION = "1.0.0-rc.7";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
|
|
@@ -449,9 +449,10 @@ interface HtmlLivePreviewOptions {
|
|
|
449
449
|
strictMode?: boolean;
|
|
450
450
|
/**
|
|
451
451
|
* How long typing must pause, in milliseconds, before the page is
|
|
452
|
-
* requested with the unsaved changes. Default
|
|
453
|
-
*
|
|
454
|
-
*
|
|
452
|
+
* requested with the unsaved changes. Default 0: the page is requested as
|
|
453
|
+
* soon as the editor sends a change, which it does after a pause of its
|
|
454
|
+
* own. Requests run one at a time either way; raise this when a render is
|
|
455
|
+
* expensive, to have fewer of them.
|
|
455
456
|
*/
|
|
456
457
|
syncDebounceMs?: number;
|
|
457
458
|
}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
setTrackingParam,
|
|
9
9
|
stegaClean,
|
|
10
10
|
trackEvent
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-6EWXOHZZ.js";
|
|
12
12
|
import {
|
|
13
13
|
PreprError,
|
|
14
14
|
extractAccessToken,
|
|
@@ -19,15 +19,15 @@ import {
|
|
|
19
19
|
getPreprUUIDFromHeaders,
|
|
20
20
|
getToolbarPropsFromHeaders,
|
|
21
21
|
validatePreprToken
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-OKP6KD3I.js";
|
|
23
23
|
import {
|
|
24
24
|
VERSION,
|
|
25
25
|
resolveFeatures
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-GIZY3JFC.js";
|
|
27
27
|
import {
|
|
28
28
|
createLiveBridge,
|
|
29
29
|
createLiveStore
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-WQXLVSHA.js";
|
|
31
31
|
import "./chunk-Y7JWV7WV.js";
|
|
32
32
|
import {
|
|
33
33
|
COOKIE_HUBSPOT,
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
normalizeQuery,
|
|
49
49
|
parsePatchLog,
|
|
50
50
|
readQueryDocument
|
|
51
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-J4POHQKB.js";
|
|
52
52
|
import {
|
|
53
53
|
createScopedLogger
|
|
54
54
|
} from "./chunk-V7MCHPE7.js";
|
|
@@ -270,7 +270,7 @@ function adopt(node, parent) {
|
|
|
270
270
|
// src/core/live-preview/html-live.ts
|
|
271
271
|
var debug = createScopedLogger("live-preview:html");
|
|
272
272
|
var COMPLETE_DOCUMENT = /<\/html>\s*$/i;
|
|
273
|
-
var SYNC_DEBOUNCE_MS =
|
|
273
|
+
var SYNC_DEBOUNCE_MS = 0;
|
|
274
274
|
function startHtmlLivePreview(options = {}) {
|
|
275
275
|
if (typeof window === "undefined" || window.self === window.top) {
|
|
276
276
|
return { stop() {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createLiveBridge,
|
|
3
3
|
createLiveStore
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WQXLVSHA.js";
|
|
5
5
|
import "./chunk-Y7JWV7WV.js";
|
|
6
6
|
import "./chunk-UTKH7DOI.js";
|
|
7
7
|
import {
|
|
8
8
|
applyPatchLog,
|
|
9
9
|
normalizeQuery,
|
|
10
10
|
parsePatchLog
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-J4POHQKB.js";
|
|
12
12
|
import "./chunk-V7MCHPE7.js";
|
|
13
13
|
export {
|
|
14
14
|
applyPatchLog,
|
|
@@ -3707,7 +3707,7 @@ function createPreprPreview(opts = {}) {
|
|
|
3707
3707
|
var import_react = require("react");
|
|
3708
3708
|
|
|
3709
3709
|
// src/version.ts
|
|
3710
|
-
var VERSION = "1.0.0-rc.
|
|
3710
|
+
var VERSION = "1.0.0-rc.7";
|
|
3711
3711
|
|
|
3712
3712
|
// src/core/pixel.ts
|
|
3713
3713
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|