@preprio/toolkit 0.1.0-beta.6 → 0.2.0-beta.3
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 +178 -13
- package/dist/astro/index.cjs +37 -15
- package/dist/astro/index.d.cts +38 -8
- package/dist/astro/index.d.ts +38 -8
- package/dist/astro/index.js +37 -15
- package/dist/{chunk-NLQIRN5O.js → chunk-6OOGNVJ4.js} +83 -41
- package/dist/index.cjs +102 -55
- package/dist/index.d.cts +59 -16
- package/dist/index.d.ts +59 -16
- package/dist/index.js +22 -16
- package/dist/nextjs/components.cjs +103 -50
- package/dist/nextjs/components.d.cts +16 -9
- package/dist/nextjs/components.d.ts +16 -9
- package/dist/nextjs/components.js +23 -11
- package/dist/nextjs/index.cjs +37 -15
- package/dist/nextjs/index.d.cts +46 -16
- package/dist/nextjs/index.d.ts +46 -16
- package/dist/nextjs/index.js +37 -15
- package/dist/nuxt/index.cjs +37 -15
- package/dist/nuxt/index.d.cts +62 -32
- package/dist/nuxt/index.d.ts +62 -32
- package/dist/nuxt/index.js +37 -15
- package/dist/{pixel-DVSJQC0K.d.cts → pixel-763p7m6A.d.cts} +64 -1
- package/dist/{pixel-DVSJQC0K.d.ts → pixel-763p7m6A.d.ts} +64 -1
- package/dist/react/components.cjs +2237 -0
- package/dist/react/components.d.cts +167 -0
- package/dist/react/components.d.ts +167 -0
- package/dist/react/components.js +2212 -0
- package/dist/react/index.cjs +32 -0
- package/dist/react/index.d.cts +1 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +9 -0
- package/dist/sveltekit/index.cjs +37 -15
- package/dist/sveltekit/index.d.cts +62 -32
- package/dist/sveltekit/index.d.ts +62 -32
- package/dist/sveltekit/index.js +37 -15
- package/package.json +13 -2
- package/src/astro/PreprToolbar.astro +16 -10
- package/src/nuxt/PreprToolbar.vue +10 -8
- package/src/sveltekit/PreprToolbar.svelte +11 -4
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
type Dictionary = Record<string, unknown>;
|
|
2
|
+
declare const dictionaries: {
|
|
3
|
+
en: Dictionary;
|
|
4
|
+
nl: Dictionary;
|
|
5
|
+
};
|
|
6
|
+
type Locale = keyof typeof dictionaries;
|
|
7
|
+
|
|
8
|
+
interface PreprSegment {
|
|
9
|
+
readonly _id: string;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
14
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
15
|
+
*/
|
|
16
|
+
type PreprFeatureConfig = boolean | {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
20
|
+
interface PreprFeatures {
|
|
21
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
22
|
+
segments?: PreprFeatureConfig;
|
|
23
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
24
|
+
abTesting?: PreprFeatureConfig;
|
|
25
|
+
/**
|
|
26
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
27
|
+
* tooltip/overlay and the close-edit pill.
|
|
28
|
+
*
|
|
29
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
30
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
31
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
32
|
+
* to visitors. See iframe-bridge.ts.
|
|
33
|
+
*/
|
|
34
|
+
editMode?: PreprFeatureConfig;
|
|
35
|
+
}
|
|
36
|
+
interface PreprToolbarOptions {
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
locale?: Locale;
|
|
39
|
+
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
40
|
+
features?: PreprFeatures;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for the preview runtime. Two independent axes: `features` decides
|
|
44
|
+
* *what runs*, `ui` decides *whether the toolbar is visible*.
|
|
45
|
+
*/
|
|
46
|
+
interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Mount the visible `<prepr-toolbar>` element. Default `true`.
|
|
49
|
+
*
|
|
50
|
+
* `false` keeps every non-visual side effect wired — click-to-edit, the
|
|
51
|
+
* editor bridge, scroll restore, cookies and headers — with no chrome of its
|
|
52
|
+
* own. That is how a site gets live editing, or editor scroll restore, while
|
|
53
|
+
* rendering its own UI instead of the bar.
|
|
54
|
+
*
|
|
55
|
+
* Already implied inside the editor's iframe (the CMS owns the chrome there)
|
|
56
|
+
* and by `?prepr_hide_bar=true`, so this option is for consumers who want a
|
|
57
|
+
* headless preview by their own choice.
|
|
58
|
+
*/
|
|
59
|
+
ui?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
62
|
+
* Intended for self-hosted editors; when set, the wildcard no longer applies.
|
|
63
|
+
*/
|
|
64
|
+
allowedEditorOrigins?: string[];
|
|
65
|
+
}
|
|
66
|
+
interface PreprToolbarProps {
|
|
67
|
+
readonly activeSegment: string | null;
|
|
68
|
+
readonly activeVariant: string | null;
|
|
69
|
+
/** Available segments to personalize on. */
|
|
70
|
+
readonly segments?: readonly PreprSegment[];
|
|
71
|
+
/** @deprecated Alias for `segments`. */
|
|
72
|
+
readonly data?: readonly PreprSegment[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Prop type for the framework `<PreprToolbar>` components: the toolbar data
|
|
76
|
+
* plus the options bag core `createPreprPreview` accepts.
|
|
77
|
+
*/
|
|
78
|
+
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
79
|
+
options?: PreprPreviewOptions;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Navigation seam that keeps the controller framework-free. Next.js/Astro inject
|
|
84
|
+
* their router here; the default uses `window.location`.
|
|
85
|
+
*/
|
|
86
|
+
interface PreprNavigationAdapter {
|
|
87
|
+
navigate(url: string): void;
|
|
88
|
+
currentPath(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Refresh after a preview-mode toggle. Defaults to `window.location.reload()`;
|
|
91
|
+
* SPA routers can pass a soft refresh like Next.js `router.refresh()`.
|
|
92
|
+
*/
|
|
93
|
+
reload?(): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
98
|
+
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
99
|
+
* up the handoff.
|
|
100
|
+
*
|
|
101
|
+
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
102
|
+
* contract must be reproduced exactly:
|
|
103
|
+
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
104
|
+
* lands and replaces `.process`.
|
|
105
|
+
* - `.t` must be a `Date.now()` timestamp.
|
|
106
|
+
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
107
|
+
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
108
|
+
*/
|
|
109
|
+
/** Config accepted by the CDN pixel. */
|
|
110
|
+
interface PreprPixelConfig {
|
|
111
|
+
destinations?: {
|
|
112
|
+
googleTagManager?: boolean;
|
|
113
|
+
};
|
|
114
|
+
variantImpressionThreshold?: number;
|
|
115
|
+
}
|
|
116
|
+
type PreprQueueArgs = unknown[];
|
|
117
|
+
interface PreprQueueFn {
|
|
118
|
+
(...args: PreprQueueArgs): void;
|
|
119
|
+
queue: PreprQueueArgs[];
|
|
120
|
+
t: number;
|
|
121
|
+
process?: (...args: PreprQueueArgs) => void;
|
|
122
|
+
}
|
|
123
|
+
declare global {
|
|
124
|
+
interface Window {
|
|
125
|
+
prepr?: PreprQueueFn;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface PreprPreviewProps extends PreprToolbarComponentProps {
|
|
130
|
+
/**
|
|
131
|
+
* Router binding for segment/variant switches and the preview-mode refresh.
|
|
132
|
+
* Optional: the default adapter drives `window.location`, which is correct
|
|
133
|
+
* for any router that keeps the URL bar in sync.
|
|
134
|
+
*
|
|
135
|
+
* Pass one to get soft navigation instead of full page loads. Only worth it
|
|
136
|
+
* with `segments` or `abTesting` enabled — with both off the sole reachable
|
|
137
|
+
* path is the preview-mode refresh, which reloads either way.
|
|
138
|
+
*/
|
|
139
|
+
navigation?: PreprNavigationAdapter;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Mounts the Prepr preview runtime — the toolbar, click-to-edit, and the
|
|
143
|
+
* editor bridge — in any React app. Renders nothing: the toolbar UI is a
|
|
144
|
+
* custom element `createPreprPreview` mounts imperatively.
|
|
145
|
+
*
|
|
146
|
+
* Framework-free. Next.js users want `PreprToolbar` from
|
|
147
|
+
* `@preprio/toolkit/nextjs` instead, which binds the App Router for them.
|
|
148
|
+
*
|
|
149
|
+
* Mount it once per page. Two mounted copies start two editor bridges and
|
|
150
|
+
* announce the preview twice.
|
|
151
|
+
*/
|
|
152
|
+
declare function PreprPreview({ options, navigation, ...props }: PreprPreviewProps): null;
|
|
153
|
+
interface PreprTrackingPixelProps {
|
|
154
|
+
/** Prepr tracking/access token. */
|
|
155
|
+
id: string;
|
|
156
|
+
config?: PreprPixelConfig;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Loads Prepr's CDN tracking pixel on mount. Renders nothing.
|
|
160
|
+
*
|
|
161
|
+
* The pixel queues a single `pageload` event when it installs. Client-side
|
|
162
|
+
* route changes emit nothing on their own — call `trackEvent('pageload')` from
|
|
163
|
+
* the router to count them.
|
|
164
|
+
*/
|
|
165
|
+
declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): null;
|
|
166
|
+
|
|
167
|
+
export { PreprPreview, type PreprPreviewProps, PreprTrackingPixel, type PreprTrackingPixelProps };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
type Dictionary = Record<string, unknown>;
|
|
2
|
+
declare const dictionaries: {
|
|
3
|
+
en: Dictionary;
|
|
4
|
+
nl: Dictionary;
|
|
5
|
+
};
|
|
6
|
+
type Locale = keyof typeof dictionaries;
|
|
7
|
+
|
|
8
|
+
interface PreprSegment {
|
|
9
|
+
readonly _id: string;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Per-feature config. `false` is shorthand for `{ enabled: false }`; the object
|
|
14
|
+
* form leaves room for per-feature options later without a breaking change.
|
|
15
|
+
*/
|
|
16
|
+
type PreprFeatureConfig = boolean | {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
};
|
|
19
|
+
/** Toolkit features a consumer can turn off. Omitted keys stay enabled. */
|
|
20
|
+
interface PreprFeatures {
|
|
21
|
+
/** Segment picker, `Prepr-Segments` header and its cookie/query param. */
|
|
22
|
+
segments?: PreprFeatureConfig;
|
|
23
|
+
/** A/B variant switch, `Prepr-ABtesting` header and its cookie/query param. */
|
|
24
|
+
abTesting?: PreprFeatureConfig;
|
|
25
|
+
/**
|
|
26
|
+
* The site's own click-to-edit: the toolbar's Edit mode control, the stega
|
|
27
|
+
* tooltip/overlay and the close-edit pill.
|
|
28
|
+
*
|
|
29
|
+
* NOT a security control, and NOT the Prepr editor's live preview. When the
|
|
30
|
+
* site is framed by the editor, `prepr:initVE` still activates edit mode —
|
|
31
|
+
* that is the CMS operating inside its own iframe, not an affordance offered
|
|
32
|
+
* to visitors. See iframe-bridge.ts.
|
|
33
|
+
*/
|
|
34
|
+
editMode?: PreprFeatureConfig;
|
|
35
|
+
}
|
|
36
|
+
interface PreprToolbarOptions {
|
|
37
|
+
debug?: boolean;
|
|
38
|
+
locale?: Locale;
|
|
39
|
+
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
40
|
+
features?: PreprFeatures;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Options for the preview runtime. Two independent axes: `features` decides
|
|
44
|
+
* *what runs*, `ui` decides *whether the toolbar is visible*.
|
|
45
|
+
*/
|
|
46
|
+
interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
47
|
+
/**
|
|
48
|
+
* Mount the visible `<prepr-toolbar>` element. Default `true`.
|
|
49
|
+
*
|
|
50
|
+
* `false` keeps every non-visual side effect wired — click-to-edit, the
|
|
51
|
+
* editor bridge, scroll restore, cookies and headers — with no chrome of its
|
|
52
|
+
* own. That is how a site gets live editing, or editor scroll restore, while
|
|
53
|
+
* rendering its own UI instead of the bar.
|
|
54
|
+
*
|
|
55
|
+
* Already implied inside the editor's iframe (the CMS owns the chrome there)
|
|
56
|
+
* and by `?prepr_hide_bar=true`, so this option is for consumers who want a
|
|
57
|
+
* headless preview by their own choice.
|
|
58
|
+
*/
|
|
59
|
+
ui?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
62
|
+
* Intended for self-hosted editors; when set, the wildcard no longer applies.
|
|
63
|
+
*/
|
|
64
|
+
allowedEditorOrigins?: string[];
|
|
65
|
+
}
|
|
66
|
+
interface PreprToolbarProps {
|
|
67
|
+
readonly activeSegment: string | null;
|
|
68
|
+
readonly activeVariant: string | null;
|
|
69
|
+
/** Available segments to personalize on. */
|
|
70
|
+
readonly segments?: readonly PreprSegment[];
|
|
71
|
+
/** @deprecated Alias for `segments`. */
|
|
72
|
+
readonly data?: readonly PreprSegment[];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Prop type for the framework `<PreprToolbar>` components: the toolbar data
|
|
76
|
+
* plus the options bag core `createPreprPreview` accepts.
|
|
77
|
+
*/
|
|
78
|
+
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
79
|
+
options?: PreprPreviewOptions;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Navigation seam that keeps the controller framework-free. Next.js/Astro inject
|
|
84
|
+
* their router here; the default uses `window.location`.
|
|
85
|
+
*/
|
|
86
|
+
interface PreprNavigationAdapter {
|
|
87
|
+
navigate(url: string): void;
|
|
88
|
+
currentPath(): string;
|
|
89
|
+
/**
|
|
90
|
+
* Refresh after a preview-mode toggle. Defaults to `window.location.reload()`;
|
|
91
|
+
* SPA routers can pass a soft refresh like Next.js `router.refresh()`.
|
|
92
|
+
*/
|
|
93
|
+
reload?(): void;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
98
|
+
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
99
|
+
* up the handoff.
|
|
100
|
+
*
|
|
101
|
+
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
102
|
+
* contract must be reproduced exactly:
|
|
103
|
+
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
104
|
+
* lands and replaces `.process`.
|
|
105
|
+
* - `.t` must be a `Date.now()` timestamp.
|
|
106
|
+
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
107
|
+
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
108
|
+
*/
|
|
109
|
+
/** Config accepted by the CDN pixel. */
|
|
110
|
+
interface PreprPixelConfig {
|
|
111
|
+
destinations?: {
|
|
112
|
+
googleTagManager?: boolean;
|
|
113
|
+
};
|
|
114
|
+
variantImpressionThreshold?: number;
|
|
115
|
+
}
|
|
116
|
+
type PreprQueueArgs = unknown[];
|
|
117
|
+
interface PreprQueueFn {
|
|
118
|
+
(...args: PreprQueueArgs): void;
|
|
119
|
+
queue: PreprQueueArgs[];
|
|
120
|
+
t: number;
|
|
121
|
+
process?: (...args: PreprQueueArgs) => void;
|
|
122
|
+
}
|
|
123
|
+
declare global {
|
|
124
|
+
interface Window {
|
|
125
|
+
prepr?: PreprQueueFn;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
interface PreprPreviewProps extends PreprToolbarComponentProps {
|
|
130
|
+
/**
|
|
131
|
+
* Router binding for segment/variant switches and the preview-mode refresh.
|
|
132
|
+
* Optional: the default adapter drives `window.location`, which is correct
|
|
133
|
+
* for any router that keeps the URL bar in sync.
|
|
134
|
+
*
|
|
135
|
+
* Pass one to get soft navigation instead of full page loads. Only worth it
|
|
136
|
+
* with `segments` or `abTesting` enabled — with both off the sole reachable
|
|
137
|
+
* path is the preview-mode refresh, which reloads either way.
|
|
138
|
+
*/
|
|
139
|
+
navigation?: PreprNavigationAdapter;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Mounts the Prepr preview runtime — the toolbar, click-to-edit, and the
|
|
143
|
+
* editor bridge — in any React app. Renders nothing: the toolbar UI is a
|
|
144
|
+
* custom element `createPreprPreview` mounts imperatively.
|
|
145
|
+
*
|
|
146
|
+
* Framework-free. Next.js users want `PreprToolbar` from
|
|
147
|
+
* `@preprio/toolkit/nextjs` instead, which binds the App Router for them.
|
|
148
|
+
*
|
|
149
|
+
* Mount it once per page. Two mounted copies start two editor bridges and
|
|
150
|
+
* announce the preview twice.
|
|
151
|
+
*/
|
|
152
|
+
declare function PreprPreview({ options, navigation, ...props }: PreprPreviewProps): null;
|
|
153
|
+
interface PreprTrackingPixelProps {
|
|
154
|
+
/** Prepr tracking/access token. */
|
|
155
|
+
id: string;
|
|
156
|
+
config?: PreprPixelConfig;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Loads Prepr's CDN tracking pixel on mount. Renders nothing.
|
|
160
|
+
*
|
|
161
|
+
* The pixel queues a single `pageload` event when it installs. Client-side
|
|
162
|
+
* route changes emit nothing on their own — call `trackEvent('pageload')` from
|
|
163
|
+
* the router to count them.
|
|
164
|
+
*/
|
|
165
|
+
declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): null;
|
|
166
|
+
|
|
167
|
+
export { PreprPreview, type PreprPreviewProps, PreprTrackingPixel, type PreprTrackingPixelProps };
|