@preprio/toolkit 0.5.0-rc.4 → 0.5.1-dom.0
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 +67 -2
- package/dist/astro/index.cjs +1 -1
- package/dist/astro/index.js +1 -1
- package/dist/auto.cjs +4572 -0
- package/dist/auto.d.cts +42 -0
- package/dist/auto.d.ts +42 -0
- package/dist/auto.js +105 -0
- package/dist/browser/auto.js +117 -0
- package/dist/chunk-5I5TQ3NO.js +74 -0
- package/dist/chunk-AZC4BZJI.js +447 -0
- package/dist/{chunk-TG6N3C22.js → chunk-IKOOXTPM.js} +1 -1
- package/dist/{chunk-AHBN6FQP.js → chunk-IOSO232M.js} +4 -2
- package/dist/{chunk-PDNCNTDB.js → chunk-RRM5762S.js} +2 -71
- package/dist/chunk-SZTHSJUA.js +326 -0
- package/dist/{chunk-46ISDRHT.js → chunk-TEB7M7EM.js} +0 -4
- package/dist/chunk-UK664KSV.js +6 -0
- package/dist/{chunk-74KY5EAM.js → chunk-ZFGVP2GW.js} +28 -447
- package/dist/html-live-DzmEG9wU.d.cts +42 -0
- package/dist/html-live-DzmEG9wU.d.ts +42 -0
- package/dist/index.cjs +177 -2
- package/dist/index.d.cts +31 -28
- package/dist/index.d.ts +31 -28
- package/dist/index.js +21 -154
- package/dist/{live-preview-H4643QYF.js → live-preview-IYAS7PYV.js} +3 -2
- package/dist/nextjs/components.cjs +1 -1
- package/dist/nextjs/components.d.cts +2 -1
- package/dist/nextjs/components.d.ts +2 -1
- package/dist/nextjs/components.js +6 -3
- package/dist/nextjs/index.cjs +1 -1
- package/dist/nextjs/index.js +1 -1
- package/dist/nextjs/live-action.js +5 -3
- package/dist/nextjs/live.js +1 -1
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/pixel-DwW7cXJm.d.cts +49 -0
- package/dist/pixel-DwW7cXJm.d.ts +49 -0
- 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/{pixel-CX422dCO.d.cts → types-DtMa_-f2.d.cts} +1 -49
- package/dist/{pixel-CX422dCO.d.ts → types-DtMa_-f2.d.ts} +1 -49
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Every integration is the same three steps:
|
|
|
18
18
|
2. **Layout** — mounts the preview toolbar and the tracking pixel.
|
|
19
19
|
3. **Data fetching** — forwards the Prepr headers on your GraphQL requests, so Prepr returns personalized content.
|
|
20
20
|
|
|
21
|
-
Jump to your framework: [Next.js](#nextjs) · [Astro](#astro) · [SvelteKit](#sveltekit) · [Nuxt](#nuxt) · [React without a framework](#react-no-framework) · [anything else](#any-other-framework).
|
|
21
|
+
Jump to your framework: [Next.js](#nextjs) · [Astro](#astro) · [SvelteKit](#sveltekit) · [Nuxt](#nuxt) · [React without a framework](#react-no-framework) · [PHP, Ruby, Python and other backends](#any-backend-drop-in-script) · [anything else](#any-other-framework).
|
|
22
22
|
|
|
23
23
|
Coming from `@preprio/prepr-nextjs`? See the [migration guide](https://github.com/preprio/prepr-toolkit/blob/main/MIGRATION.md).
|
|
24
24
|
|
|
@@ -399,7 +399,9 @@ On Next.js 15 and older the action does nothing and pages update on save.
|
|
|
399
399
|
For Astro and Nuxt, see their sections. The framework-free core exports,
|
|
400
400
|
`normalizeQuery(query, result, { log })`, `startHtmlLivePreview()` and
|
|
401
401
|
`readLiveLogFromRequest(request)` from `@preprio/toolkit`, cover any other
|
|
402
|
-
server-rendered stack.
|
|
402
|
+
server-rendered stack. A backend that cannot run them uses
|
|
403
|
+
`startHtmlLivePreview({ apply: 'dom' })`; see
|
|
404
|
+
[Any backend](#any-backend-drop-in-script).
|
|
403
405
|
|
|
404
406
|
## Astro
|
|
405
407
|
|
|
@@ -685,6 +687,49 @@ This double-counts the first pageview, since the pixel's own install event fires
|
|
|
685
687
|
|
|
686
688
|
The `id` is your access token, and in a client-rendered app it is public — bundled into JS and visible in devtools. Use a tracking-only token; do not derive it from a browser-exposed GraphQL URL, which would also expose content read access.
|
|
687
689
|
|
|
690
|
+
## Any backend: drop-in script
|
|
691
|
+
|
|
692
|
+
For server-rendered sites whose backend is not JavaScript (Laravel, Symfony, Rails, Django, …). The browser side needs one script tag; live preview needs no server support.
|
|
693
|
+
|
|
694
|
+
**1. Render the props** into the page on preview deployments only, as JSON:
|
|
695
|
+
|
|
696
|
+
```html
|
|
697
|
+
<script type="application/json" data-prepr-toolbar-props>
|
|
698
|
+
{
|
|
699
|
+
"props": {
|
|
700
|
+
"activeSegment": null,
|
|
701
|
+
"activeVariant": null,
|
|
702
|
+
"segments": [{ "_id": "…", "name": "Students" }]
|
|
703
|
+
},
|
|
704
|
+
"options": { "locale": "nl" }
|
|
705
|
+
}
|
|
706
|
+
</script>
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
`segments` comes from a `{ _Segments { _id name } }` query against your preview GraphQL URL; `activeSegment` / `activeVariant` from the `Prepr-Segments` / `Prepr-ABtesting` cookies (see [How It Works](#middleware)). Escape the JSON for a `<script>` element (`<` as `\u003c`).
|
|
710
|
+
|
|
711
|
+
**2. Load the script**, from your bundle or a CDN:
|
|
712
|
+
|
|
713
|
+
```javascript
|
|
714
|
+
import '@preprio/toolkit/auto';
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
```html
|
|
718
|
+
<script
|
|
719
|
+
type="module"
|
|
720
|
+
src="https://cdn.jsdelivr.net/npm/@preprio/toolkit@VERSION/dist/browser/auto.js"
|
|
721
|
+
></script>
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
It mounts the toolbar, click-to-edit and live preview, and does nothing on a page without the props tag. Client-side page swaps (Livewire `wire:navigate`, Turbo, htmx) are handled: when `<body>` is replaced the preview starts again on the new page.
|
|
725
|
+
|
|
726
|
+
**Live preview.** Inside the Prepr editor, text the editor types is written straight into the elements whose edit links point at the changed field. Images, links and added or reordered blocks appear on save, when the page is requested again. Two attributes tune it:
|
|
727
|
+
|
|
728
|
+
- `data-prepr-live="html"` on an element (or an ancestor) writes rich text as markup, reduced to formatting tags first. Without it, rich text waits for save, so it never loses its formatting while the editor types.
|
|
729
|
+
- `data-prepr-live="off"` leaves an element alone, for values the template reformats (dates, truncation) that should wait for save.
|
|
730
|
+
|
|
731
|
+
Set `"live": "server"` in the payload if your server applies the editor's changes itself (see [`readLiveLogFromRequest`](#live-preview-beta)), or `"live": false` to turn live preview off.
|
|
732
|
+
|
|
688
733
|
## Any other framework
|
|
689
734
|
|
|
690
735
|
The core is runtime-neutral: it works off a WHATWG `Request` and hands back the headers to forward to Prepr plus the cookies to persist. Adapting it to Express, Hono, Fastify, or a plain server is roughly twenty lines.
|
|
@@ -847,6 +892,26 @@ controller.destroy();
|
|
|
847
892
|
|
|
848
893
|
`trackEvent` and `setTrackingParam` are independent of `loadTrackingPixel` — they work against `window.prepr` however it got installed, including a legacy HTML snippet already on the page. If no pixel is installed at all they warn once in the console and return without throwing.
|
|
849
894
|
|
|
895
|
+
#### `startHtmlLivePreview(options?)`
|
|
896
|
+
|
|
897
|
+
Live preview for server-rendered pages without a client framework. A no-op outside the Prepr editor. Returns `{ stop() }`.
|
|
898
|
+
|
|
899
|
+
| Option | Type | Default | Description |
|
|
900
|
+
| ---------------------- | ------------------- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
901
|
+
| `apply` | `'server' \| 'dom'` | `'server'` | `'server'` requests the page again with the changes (the server applies them with `normalizeQuery`). `'dom'` writes plain-text changes into the page directly and needs no server support; rich text waits for save unless the element opts in with `data-prepr-live="html"`. |
|
|
902
|
+
| `allowedEditorOrigins` | `string[]` | `*.prepr.io` | As in [Preview options](#preview-options). |
|
|
903
|
+
| `strictMode` | `boolean` | `false` | As in [Preview options](#preview-options). |
|
|
904
|
+
|
|
905
|
+
Every mode renders the stored page again on save.
|
|
906
|
+
|
|
907
|
+
#### `applyPatchLogToDom(log, root?)`
|
|
908
|
+
|
|
909
|
+
The `'dom'` mode on its own: writes a parsed patch log's text changes into the elements that render them and returns `{ applied, skipped }`. For custom setups; `startHtmlLivePreview` and `@preprio/toolkit/auto` call it for you.
|
|
910
|
+
|
|
911
|
+
#### `startPreprAuto()`
|
|
912
|
+
|
|
913
|
+
From `@preprio/toolkit/auto`, which also calls it on import. Starts the preview from the page's `data-prepr-toolbar-props` JSON and returns a function that stops it. See [Any backend](#any-backend-drop-in-script).
|
|
914
|
+
|
|
850
915
|
#### `stegaClean(value)`
|
|
851
916
|
|
|
852
917
|
Strips stega-encoded characters from a string. Rarely needed, since cleaning is automatic (see [Visual editing](#visual-editing)), but available when you need a clean value for comparison, sorting, or a non-DOM API.
|
package/dist/astro/index.cjs
CHANGED
package/dist/astro/index.js
CHANGED