payload-live-preview 2.0.0-beta.0 → 2.0.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.
Files changed (109) hide show
  1. package/README.md +60 -775
  2. package/dist/adapters/astro/PreviewBoundary.astro +2 -2
  3. package/dist/adapters/astro/index.d.ts +28 -154
  4. package/dist/adapters/astro/index.js +1 -1
  5. package/dist/adapters/astro/index.js.map +1 -1
  6. package/dist/adapters/astro/middleware-entry.d.ts +3 -2
  7. package/dist/adapters/astro/middleware-entry.js +1 -1
  8. package/dist/adapters/astro/middleware-entry.js.map +1 -1
  9. package/dist/adapters/nextjs/index.d.ts +247 -6
  10. package/dist/adapters/nextjs/index.js +1 -1
  11. package/dist/adapters/nextjs/index.js.map +1 -1
  12. package/dist/adapters/nuxt/index.d.ts +58 -3
  13. package/dist/adapters/nuxt/index.js +1 -1
  14. package/dist/adapters/nuxt/index.js.map +1 -1
  15. package/dist/adapters/nuxt/module.d.ts +82 -0
  16. package/dist/adapters/nuxt/module.js +2 -0
  17. package/dist/adapters/nuxt/module.js.map +1 -0
  18. package/dist/adapters/react/index.d.ts +110 -0
  19. package/dist/adapters/react/index.js +3 -0
  20. package/dist/adapters/react/index.js.map +1 -0
  21. package/dist/adapters/sveltekit/index.d.ts +65 -7
  22. package/dist/adapters/sveltekit/index.js +1 -1
  23. package/dist/adapters/sveltekit/index.js.map +1 -1
  24. package/dist/adapters/vue/index.d.ts +56 -0
  25. package/dist/adapters/vue/index.js +2 -0
  26. package/dist/adapters/vue/index.js.map +1 -0
  27. package/dist/annotate.d.ts +161 -0
  28. package/dist/annotate.js +2 -0
  29. package/dist/annotate.js.map +1 -0
  30. package/dist/client.cjs +1 -1
  31. package/dist/client.cjs.map +1 -1
  32. package/dist/client.d.cts +182 -9
  33. package/dist/client.d.ts +182 -9
  34. package/dist/client.js +1 -1
  35. package/dist/client.js.map +1 -1
  36. package/dist/codegen-astro.js +1 -1
  37. package/dist/codegen-astro.js.map +1 -1
  38. package/dist/codegen-cli.js +1 -1
  39. package/dist/codegen-cli.js.map +1 -1
  40. package/dist/codegen.cjs +1 -1
  41. package/dist/codegen.cjs.map +1 -1
  42. package/dist/codegen.d.cts +129 -4
  43. package/dist/codegen.d.ts +129 -4
  44. package/dist/codegen.js +1 -1
  45. package/dist/codegen.js.map +1 -1
  46. package/dist/core.cjs +1 -1
  47. package/dist/core.cjs.map +1 -1
  48. package/dist/core.d.cts +264 -73
  49. package/dist/core.d.ts +264 -73
  50. package/dist/core.js +1 -1
  51. package/dist/core.js.map +1 -1
  52. package/dist/doctor-cli.d.ts +1 -1
  53. package/dist/doctor-cli.js +1 -1
  54. package/dist/doctor-cli.js.map +1 -1
  55. package/dist/doctor.d.ts +7 -6
  56. package/dist/doctor.js +1 -1
  57. package/dist/doctor.js.map +1 -1
  58. package/dist/document-session-BfBfLVpg.d.ts +53 -0
  59. package/dist/fragment-endpoint-3Mlz7GDz.d.ts +189 -0
  60. package/dist/fragment.cjs +1 -1
  61. package/dist/fragment.cjs.map +1 -1
  62. package/dist/fragment.d.cts +64 -18
  63. package/dist/fragment.d.ts +64 -18
  64. package/dist/fragment.js +1 -1
  65. package/dist/fragment.js.map +1 -1
  66. package/dist/index.cjs +1 -1
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +422 -83
  69. package/dist/index.d.ts +422 -83
  70. package/dist/index.js +1 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/lean.cjs +2 -0
  73. package/dist/lean.cjs.map +1 -0
  74. package/dist/lean.d.cts +44 -0
  75. package/dist/lean.d.ts +44 -0
  76. package/dist/lean.js +2 -0
  77. package/dist/lean.js.map +1 -0
  78. package/dist/lexical.cjs +1 -1
  79. package/dist/lexical.cjs.map +1 -1
  80. package/dist/lexical.d.cts +19 -1
  81. package/dist/lexical.d.ts +19 -1
  82. package/dist/lexical.js +1 -1
  83. package/dist/lexical.js.map +1 -1
  84. package/dist/locals-DBXDMxOA.d.ts +45 -0
  85. package/dist/{middleware-CEPsY1P7.d.ts → middleware-Bx9I7PXW.d.ts} +14 -14
  86. package/dist/migrate.d.ts +4 -3
  87. package/dist/migrate.js +1 -1
  88. package/dist/migrate.js.map +1 -1
  89. package/dist/{options-CEzzfHJu.d.ts → options-BW1eqXvc.d.ts} +90 -2
  90. package/dist/plugins.cjs +1 -1
  91. package/dist/plugins.cjs.map +1 -1
  92. package/dist/plugins.d.cts +111 -6
  93. package/dist/plugins.d.ts +111 -6
  94. package/dist/plugins.js +1 -1
  95. package/dist/plugins.js.map +1 -1
  96. package/dist/{probe-CYtvj_Lm.d.ts → probe-CELeUciC.d.ts} +26 -4
  97. package/dist/server.cjs +1 -1
  98. package/dist/server.cjs.map +1 -1
  99. package/dist/server.d.cts +67 -13
  100. package/dist/server.d.ts +67 -13
  101. package/dist/server.js +1 -1
  102. package/dist/server.js.map +1 -1
  103. package/dist/structural.cjs +2 -2
  104. package/dist/structural.cjs.map +1 -1
  105. package/dist/structural.d.cts +47 -4
  106. package/dist/structural.d.ts +47 -4
  107. package/dist/structural.js +2 -2
  108. package/dist/structural.js.map +1 -1
  109. package/package.json +77 -9
@@ -32,6 +32,12 @@ type PayloadFieldType = 'text' | 'textarea' | 'richText' | 'email' | 'number' |
32
32
  /** `admin.condition` is a function in source and cannot cross `postMessage`; modelled, not consumed. */
33
33
  type PayloadFieldCondition = (data: unknown, siblingData: unknown) => boolean;
34
34
 
35
+ /**
36
+ * `'strict'` (default) strips `id`, `name` and `data-payload-*` and passes
37
+ * other `data-*` only via `allowedDataAttributes`; `'compat'` keeps them.
38
+ */
39
+ type SanitizerPolicyMode = 'compat' | 'strict';
40
+
35
41
  /**
36
42
  * How a bound region is brought up to date: the runtime patches it, a server
37
43
  * renders a `data-payload-fragment` boundary from the unsaved form state, or
@@ -79,7 +85,7 @@ interface CachedElement {
79
85
  /** Nearest enclosing `data-payload-fragment` boundary. Resolved by the cache. */
80
86
  readonly fragmentBoundary?: Element;
81
87
  /** `data-payload-boundary`: an anchor that hides itself while its field is empty. */
82
- readonly boundary?: boolean;
88
+ readonly hidesWhenEmpty?: boolean;
83
89
  /** Write the value into this attribute instead of the content; policed writes. */
84
90
  readonly targetAttribute?: string;
85
91
  /** Optional sibling-field path bound to the element's `href` attribute. */
@@ -94,8 +100,16 @@ interface CachedElement {
94
100
  readonly arraySeparator?: string;
95
101
  /** Optional locale code locked onto this element (overrides the global locale). */
96
102
  readonly locale?: string;
103
+ /** Raw `data-payload-format`; the date and number renderers read the vocabulary. */
104
+ readonly format?: string;
97
105
  /** The document this binding belongs to, from the nearest `data-payload-owner`. */
98
106
  readonly owner?: string;
107
+ /**
108
+ * The value an auto-binding matched on (`data-payload-guessed`), for a
109
+ * binding the runtime found by value rather than one the template declared.
110
+ * Absent for a declared binding.
111
+ */
112
+ readonly guessed?: string;
99
113
  }
100
114
  /** What a renderer is given; `allFields` lets it resolve a sibling field. */
101
115
  interface RenderContext {
@@ -107,6 +121,20 @@ interface RenderContext {
107
121
  readonly schema: PayloadFieldSchema | undefined;
108
122
  /** The project's rich-text renderer, when the client was configured with one. */
109
123
  readonly renderRichText?: RichTextRenderer;
124
+ /**
125
+ * This instance's sanitizer policy, for every HTML write the renderer makes.
126
+ * Absent, the process default set by `setSanitizerPolicy()` applies.
127
+ */
128
+ readonly sanitizerPolicy?: SanitizerPolicyMode;
129
+ /**
130
+ * Say that this write cannot reproduce what the server drew, so
131
+ * `onUnfaithfulPatch` can have a strategy render the region instead of
132
+ * leaving a degraded patch on the page. The built-in rich-text renderer
133
+ * calls it for a Lexical block whose markup it had to drop; a project
134
+ * renderer may call it for any value it can only approximate. `reason`
135
+ * completes the sentence 'field "x" …' in LP0411.
136
+ */
137
+ readonly reportUnfaithful?: (target: CachedElement, reason: string) => void;
110
138
  }
111
139
  /**
112
140
  * A renderer writes one value into its element. It must not throw: one bad
@@ -124,11 +152,13 @@ interface FieldRenderer {
124
152
  * (ADR 0008). All diff memory lives in the closure, one per client.
125
153
  */
126
154
 
155
+ /** @internal */
127
156
  declare function createStructuralArrayRenderer(): FieldRenderer;
128
157
 
129
158
  /**
130
159
  * Structural diff for array and blocks fields. Items with an `id` are keyed
131
160
  * (moves are detected); without ids the diff is positional.
161
+ * @internal
132
162
  */
133
163
  type ArrayPatch = {
134
164
  readonly kind: 'insert';
@@ -162,10 +192,13 @@ type ArrayPatch = {
162
192
  * `data-payload-nested-key` slots. See ADR 0008.
163
193
  */
164
194
 
195
+ /** @internal */
165
196
  declare const KEY_ATTRIBUTE = "data-payload-key";
166
- /** Last value seen per item key, per container; owned by the caller so instances never share it. */
197
+ /** Last value seen per item key, per container; owned by the caller so instances never share it. @internal */
167
198
  type StructuralStore = WeakMap<Element, Map<string, unknown>>;
199
+ /** @internal */
168
200
  declare function createStructuralStore(): StructuralStore;
201
+ /** @internal */
169
202
  interface StructuralApplyOptions {
170
203
  readonly template: string;
171
204
  readonly container: Element;
@@ -176,6 +209,8 @@ interface StructuralApplyOptions {
176
209
  readonly store: StructuralStore;
177
210
  /** Re-render existing items even when unchanged. */
178
211
  readonly forceRender?: boolean;
212
+ /** The instance's policy for item markup; absent, the process default applies. */
213
+ readonly sanitizerPolicy?: SanitizerPolicyMode | undefined;
179
214
  /** Edit a changed item in place instead of replacing it. Default `true`. */
180
215
  readonly morph?: boolean;
181
216
  /** Reported once per container when two items share a key (`LP0405`). */
@@ -185,9 +220,11 @@ interface StructuralApplyOptions {
185
220
  * Returns `true` for a DOM mutation, `false` for an already-current tree, and
186
221
  * `null` when an item's markup has no sanitized element root — preflighted
187
222
  * before any mutation, so the previous DOM and memory stay intact.
223
+ * @internal
188
224
  */
189
225
  declare function applyStructuralPatches(options: StructuralApplyOptions): boolean | null;
190
226
 
227
+ /** @internal */
191
228
  declare const ISLAND_ATTRIBUTE = "data-payload-island";
192
229
 
193
230
  /**
@@ -198,6 +235,7 @@ declare const ISLAND_ATTRIBUTE = "data-payload-island";
198
235
  * See ADR 0008.
199
236
  */
200
237
 
238
+ /** @internal */
201
239
  declare const OWNED_ATTRIBUTE = "data-payload-owned";
202
240
  interface MorphOptions {
203
241
  /** Attributes that key child elements for pairing, tried in order; unkeyed children pair by position. */
@@ -207,8 +245,9 @@ interface MorphOptions {
207
245
  /** Elements whose attributes are synchronised but whose children are left alone (nested structural slots). */
208
246
  readonly retainChildrenOf?: (live: Element, rendered: Element) => boolean;
209
247
  }
248
+ /** @internal */
210
249
  declare function isMorphBoundary(element: Element): boolean;
211
- /** Whether `live` can be edited toward `rendered` instead of being replaced by it. */
250
+ /** Whether `live` can be edited toward `rendered` instead of being replaced by it. @internal */
212
251
  declare function isMorphCompatible(live: Element, rendered: Element): boolean;
213
252
  /**
214
253
  * Morph `live` toward `rendered`. Returns `live` when it was retained, or
@@ -222,22 +261,26 @@ declare function morphElement(live: Element, rendered: Element, options: MorphOp
222
261
  * other way round (`data-payload-depends="price"` on the element bound to
223
262
  * `priceLabel`) because an author names what a binding needs; the runtime
224
263
  * option is keyed by source because the scheduler asks what changed.
264
+ * @internal
225
265
  */
226
266
  type DependencyMap = Readonly<Record<string, readonly string[]>>;
227
267
  /**
228
268
  * Field names from an attribute value. Separators are commas and
229
269
  * whitespace; empty entries are dropped; order is kept, duplicates removed.
270
+ * @internal
230
271
  */
231
272
  declare function parseDependencyList(value: string | null | undefined): readonly string[];
232
273
  /**
233
274
  * Merge dependency maps (source → dependents). Later maps add to earlier
234
275
  * ones; a dependent is listed once per source.
276
+ * @internal
235
277
  */
236
278
  declare function mergeDependencyMaps(...maps: readonly DependencyMap[]): DependencyMap;
237
279
  /**
238
280
  * The map an element's `data-payload-depends` contributes: every declared
239
281
  * source points at this binding's field.
282
+ * @internal
240
283
  */
241
284
  declare function dependencyMapFromBinding(fieldName: string, dependsOn: readonly string[]): DependencyMap;
242
285
 
243
- export { type ArrayPatch, type CachedElement, type CustomRendererKey, type DependencyMap, type FieldRenderer, type FieldType, ISLAND_ATTRIBUTE, KEY_ATTRIBUTE, type MorphOptions, OWNED_ATTRIBUTE, type PayloadBlockSchema, type PayloadFieldCondition, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type RenderContext, type RendererKey, type RichTextRenderer, type StructuralApplyOptions, type StructuralStore, type UpdateSource, applyStructuralPatches, createStructuralArrayRenderer, createStructuralStore, dependencyMapFromBinding, isMorphBoundary, isMorphCompatible, mergeDependencyMaps, morphElement, parseDependencyList };
286
+ export { type ArrayPatch, type CachedElement, type CustomRendererKey, type DependencyMap, type FieldRenderer, type FieldType, ISLAND_ATTRIBUTE, KEY_ATTRIBUTE, type MorphOptions, OWNED_ATTRIBUTE, type PayloadBlockSchema, type PayloadFieldCondition, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type RenderContext, type RendererKey, type RichTextRenderer, type SanitizerPolicyMode, type StructuralApplyOptions, type StructuralStore, type UpdateSource, applyStructuralPatches, createStructuralArrayRenderer, createStructuralStore, dependencyMapFromBinding, isMorphBoundary, isMorphCompatible, mergeDependencyMaps, morphElement, parseDependencyList };
@@ -32,6 +32,12 @@ type PayloadFieldType = 'text' | 'textarea' | 'richText' | 'email' | 'number' |
32
32
  /** `admin.condition` is a function in source and cannot cross `postMessage`; modelled, not consumed. */
33
33
  type PayloadFieldCondition = (data: unknown, siblingData: unknown) => boolean;
34
34
 
35
+ /**
36
+ * `'strict'` (default) strips `id`, `name` and `data-payload-*` and passes
37
+ * other `data-*` only via `allowedDataAttributes`; `'compat'` keeps them.
38
+ */
39
+ type SanitizerPolicyMode = 'compat' | 'strict';
40
+
35
41
  /**
36
42
  * How a bound region is brought up to date: the runtime patches it, a server
37
43
  * renders a `data-payload-fragment` boundary from the unsaved form state, or
@@ -79,7 +85,7 @@ interface CachedElement {
79
85
  /** Nearest enclosing `data-payload-fragment` boundary. Resolved by the cache. */
80
86
  readonly fragmentBoundary?: Element;
81
87
  /** `data-payload-boundary`: an anchor that hides itself while its field is empty. */
82
- readonly boundary?: boolean;
88
+ readonly hidesWhenEmpty?: boolean;
83
89
  /** Write the value into this attribute instead of the content; policed writes. */
84
90
  readonly targetAttribute?: string;
85
91
  /** Optional sibling-field path bound to the element's `href` attribute. */
@@ -94,8 +100,16 @@ interface CachedElement {
94
100
  readonly arraySeparator?: string;
95
101
  /** Optional locale code locked onto this element (overrides the global locale). */
96
102
  readonly locale?: string;
103
+ /** Raw `data-payload-format`; the date and number renderers read the vocabulary. */
104
+ readonly format?: string;
97
105
  /** The document this binding belongs to, from the nearest `data-payload-owner`. */
98
106
  readonly owner?: string;
107
+ /**
108
+ * The value an auto-binding matched on (`data-payload-guessed`), for a
109
+ * binding the runtime found by value rather than one the template declared.
110
+ * Absent for a declared binding.
111
+ */
112
+ readonly guessed?: string;
99
113
  }
100
114
  /** What a renderer is given; `allFields` lets it resolve a sibling field. */
101
115
  interface RenderContext {
@@ -107,6 +121,20 @@ interface RenderContext {
107
121
  readonly schema: PayloadFieldSchema | undefined;
108
122
  /** The project's rich-text renderer, when the client was configured with one. */
109
123
  readonly renderRichText?: RichTextRenderer;
124
+ /**
125
+ * This instance's sanitizer policy, for every HTML write the renderer makes.
126
+ * Absent, the process default set by `setSanitizerPolicy()` applies.
127
+ */
128
+ readonly sanitizerPolicy?: SanitizerPolicyMode;
129
+ /**
130
+ * Say that this write cannot reproduce what the server drew, so
131
+ * `onUnfaithfulPatch` can have a strategy render the region instead of
132
+ * leaving a degraded patch on the page. The built-in rich-text renderer
133
+ * calls it for a Lexical block whose markup it had to drop; a project
134
+ * renderer may call it for any value it can only approximate. `reason`
135
+ * completes the sentence 'field "x" …' in LP0411.
136
+ */
137
+ readonly reportUnfaithful?: (target: CachedElement, reason: string) => void;
110
138
  }
111
139
  /**
112
140
  * A renderer writes one value into its element. It must not throw: one bad
@@ -124,11 +152,13 @@ interface FieldRenderer {
124
152
  * (ADR 0008). All diff memory lives in the closure, one per client.
125
153
  */
126
154
 
155
+ /** @internal */
127
156
  declare function createStructuralArrayRenderer(): FieldRenderer;
128
157
 
129
158
  /**
130
159
  * Structural diff for array and blocks fields. Items with an `id` are keyed
131
160
  * (moves are detected); without ids the diff is positional.
161
+ * @internal
132
162
  */
133
163
  type ArrayPatch = {
134
164
  readonly kind: 'insert';
@@ -162,10 +192,13 @@ type ArrayPatch = {
162
192
  * `data-payload-nested-key` slots. See ADR 0008.
163
193
  */
164
194
 
195
+ /** @internal */
165
196
  declare const KEY_ATTRIBUTE = "data-payload-key";
166
- /** Last value seen per item key, per container; owned by the caller so instances never share it. */
197
+ /** Last value seen per item key, per container; owned by the caller so instances never share it. @internal */
167
198
  type StructuralStore = WeakMap<Element, Map<string, unknown>>;
199
+ /** @internal */
168
200
  declare function createStructuralStore(): StructuralStore;
201
+ /** @internal */
169
202
  interface StructuralApplyOptions {
170
203
  readonly template: string;
171
204
  readonly container: Element;
@@ -176,6 +209,8 @@ interface StructuralApplyOptions {
176
209
  readonly store: StructuralStore;
177
210
  /** Re-render existing items even when unchanged. */
178
211
  readonly forceRender?: boolean;
212
+ /** The instance's policy for item markup; absent, the process default applies. */
213
+ readonly sanitizerPolicy?: SanitizerPolicyMode | undefined;
179
214
  /** Edit a changed item in place instead of replacing it. Default `true`. */
180
215
  readonly morph?: boolean;
181
216
  /** Reported once per container when two items share a key (`LP0405`). */
@@ -185,9 +220,11 @@ interface StructuralApplyOptions {
185
220
  * Returns `true` for a DOM mutation, `false` for an already-current tree, and
186
221
  * `null` when an item's markup has no sanitized element root — preflighted
187
222
  * before any mutation, so the previous DOM and memory stay intact.
223
+ * @internal
188
224
  */
189
225
  declare function applyStructuralPatches(options: StructuralApplyOptions): boolean | null;
190
226
 
227
+ /** @internal */
191
228
  declare const ISLAND_ATTRIBUTE = "data-payload-island";
192
229
 
193
230
  /**
@@ -198,6 +235,7 @@ declare const ISLAND_ATTRIBUTE = "data-payload-island";
198
235
  * See ADR 0008.
199
236
  */
200
237
 
238
+ /** @internal */
201
239
  declare const OWNED_ATTRIBUTE = "data-payload-owned";
202
240
  interface MorphOptions {
203
241
  /** Attributes that key child elements for pairing, tried in order; unkeyed children pair by position. */
@@ -207,8 +245,9 @@ interface MorphOptions {
207
245
  /** Elements whose attributes are synchronised but whose children are left alone (nested structural slots). */
208
246
  readonly retainChildrenOf?: (live: Element, rendered: Element) => boolean;
209
247
  }
248
+ /** @internal */
210
249
  declare function isMorphBoundary(element: Element): boolean;
211
- /** Whether `live` can be edited toward `rendered` instead of being replaced by it. */
250
+ /** Whether `live` can be edited toward `rendered` instead of being replaced by it. @internal */
212
251
  declare function isMorphCompatible(live: Element, rendered: Element): boolean;
213
252
  /**
214
253
  * Morph `live` toward `rendered`. Returns `live` when it was retained, or
@@ -222,22 +261,26 @@ declare function morphElement(live: Element, rendered: Element, options: MorphOp
222
261
  * other way round (`data-payload-depends="price"` on the element bound to
223
262
  * `priceLabel`) because an author names what a binding needs; the runtime
224
263
  * option is keyed by source because the scheduler asks what changed.
264
+ * @internal
225
265
  */
226
266
  type DependencyMap = Readonly<Record<string, readonly string[]>>;
227
267
  /**
228
268
  * Field names from an attribute value. Separators are commas and
229
269
  * whitespace; empty entries are dropped; order is kept, duplicates removed.
270
+ * @internal
230
271
  */
231
272
  declare function parseDependencyList(value: string | null | undefined): readonly string[];
232
273
  /**
233
274
  * Merge dependency maps (source → dependents). Later maps add to earlier
234
275
  * ones; a dependent is listed once per source.
276
+ * @internal
235
277
  */
236
278
  declare function mergeDependencyMaps(...maps: readonly DependencyMap[]): DependencyMap;
237
279
  /**
238
280
  * The map an element's `data-payload-depends` contributes: every declared
239
281
  * source points at this binding's field.
282
+ * @internal
240
283
  */
241
284
  declare function dependencyMapFromBinding(fieldName: string, dependsOn: readonly string[]): DependencyMap;
242
285
 
243
- export { type ArrayPatch, type CachedElement, type CustomRendererKey, type DependencyMap, type FieldRenderer, type FieldType, ISLAND_ATTRIBUTE, KEY_ATTRIBUTE, type MorphOptions, OWNED_ATTRIBUTE, type PayloadBlockSchema, type PayloadFieldCondition, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type RenderContext, type RendererKey, type RichTextRenderer, type StructuralApplyOptions, type StructuralStore, type UpdateSource, applyStructuralPatches, createStructuralArrayRenderer, createStructuralStore, dependencyMapFromBinding, isMorphBoundary, isMorphCompatible, mergeDependencyMaps, morphElement, parseDependencyList };
286
+ export { type ArrayPatch, type CachedElement, type CustomRendererKey, type DependencyMap, type FieldRenderer, type FieldType, ISLAND_ATTRIBUTE, KEY_ATTRIBUTE, type MorphOptions, OWNED_ATTRIBUTE, type PayloadBlockSchema, type PayloadFieldCondition, type PayloadFieldSchema, type PayloadFieldType, type PayloadLivePreviewData, type RenderContext, type RendererKey, type RichTextRenderer, type SanitizerPolicyMode, type StructuralApplyOptions, type StructuralStore, type UpdateSource, applyStructuralPatches, createStructuralArrayRenderer, createStructuralStore, dependencyMapFromBinding, isMorphBoundary, isMorphCompatible, mergeDependencyMaps, morphElement, parseDependencyList };
@@ -1,3 +1,3 @@
1
- var e,t,n=(e=(...e)=>console.warn(...e),(...t)=>{try{("object"==typeof(n=e(...t))&&null!==n||"function"==typeof n)&&"function"==typeof n.then&&Promise.resolve(n).catch(()=>{})}catch{}var n}),o=/* @__PURE__ */new WeakSet;function r(e){return o.add(e),e}function i(e){const n=function(){if(void 0!==t)return t;const e=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();if(void 0===e)return t=null,null;try{t=e.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{t=null}return t}();return null===n?e:n.createHTML(e)}var a=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),l=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,s=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,u=/^[\\/]{2}/,c=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e||0===e.length)return!1;const t=e.trim().replace(c,"");if(0===t.length)return!1;if(l.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(u.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return a.has(e.protocol)}catch{return s.test(t)}}var f=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),d=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),p=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),m=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),h="aria-",v="data-",g={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},y=/* @__PURE__ */new Set(["href","src","cite","poster"]),b=class extends Error{name="SanitizerEnvironmentError"},w=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-nested-key","data-payload-nested-template"]),S="strict";function A(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?k(n,t):8===n.nodeType&&n.remove()}function k(e,t){const n=e.tagName.toLowerCase();if(!p.has(n)||t.allowFormControls&&d.has(n)){if(!t.allowedTags.has(n)){A(e,t);const n=e.parentNode;if(n){for(;e.firstChild;)n.insertBefore(e.firstChild,e);e.remove()}return}!function(e,t,n){const o=n.attrByTag.get(t);for(const t of Array.from(e.attributes)){const r=t.name.toLowerCase();if(r.startsWith("on")||"style"===r)e.removeAttribute(t.name);else{if("strict"===n.mode){if(n.templateMode&&w.has(r))continue;if("id"===r||"name"===r||r.startsWith("data-payload-")){e.removeAttribute(t.name);continue}if(r.startsWith(v)){n.allowedData.has(r)||e.removeAttribute(t.name);continue}if(m.has(r)||r.startsWith(h))continue}else if(m.has(r)||r.startsWith(h)||r.startsWith(v))continue;o?.has(r)?y.has(r)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==r||x(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}}}(e,n,t),"a"===n&&function(e){const t=e.getAttribute("href");null!==t&&function isExternalHttpUrl(e){if(!isSafeUrl(e))return!1;const t=e.trim().replace(c,"");return/^https?:\/\//i.test(t)||u.test(t)}(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),A(e,t)}else e.remove()}function x(e){for(const t of e.split(",")){const e=t.trim();if(0===e.length)continue;const n=e.search(/\s/);if(!isSafeUrl(-1===n?e:e.slice(0,n)))return!1}return!0}var L=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),E=/[&<>"'/`=]/g;function escapeHtml(e){return""===e?"":e.replace(E,e=>L[e])}var M=/\{\{([\s\S]*?)\}\}/g;function T(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);try{return JSON.stringify(e)}catch{return""}}function N(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function _(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function D(e,t){return t.every(e=>void 0!==N(e))?function(e,t){const n=[],o=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=N(e[t]);void 0!==n&&o.set(n,t)}const r=/* @__PURE__ */new Set;for(let i=0;i<t.length;i+=1){const a=t[i],l=N(a);if(void 0===l){n.push({kind:"insert",index:i,value:a});continue}const s=o.get(l);if(void 0===s){n.push({kind:"insert",index:i,value:a});continue}r.add(s);const u=e[s];_(u)===_(a)?(s!==i&&n.push({kind:"move",from:s,to:i,value:a}),C(u,a)||n.push({kind:"update",index:i,value:a})):n.push({kind:"replace",index:i,oldValue:u,value:a})}for(let t=0;t<e.length;t+=1)r.has(t)||n.push({kind:"remove",index:t,value:e[t]});return n}(e,t):function(e,t){const n=[],o=Math.min(e.length,t.length);for(let r=0;r<o;r+=1)C(e[r],t[r])||n.push({kind:"update",index:r,value:t[r]});if(t.length>e.length)for(let o=e.length;o<t.length;o+=1)n.push({kind:"insert",index:o,value:t[o]});if(e.length>t.length)for(let o=t.length;o<e.length;o+=1)n.push({kind:"remove",index:o,value:e[o]});return n}(e,t)}function C(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=e,o=t,r=Object.keys(n),i=Object.keys(o);if(r.length!==i.length)return!1;for(const e of r)if(!Object.is(n[e],o[e]))return!1;return!0}var j="data-payload-island",I="data-payload-owned",O=/* @__PURE__ */new Set(["open","value","checked","selected"]);function W(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function H(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(j)||e.hasAttribute(I))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function U(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!H(e)&&!H(t)}function z(e,t,n){if(!U(e,t))return t;const o=function(e){const t=e.ownerDocument.activeElement;if(!(t instanceof HTMLElement&&e.contains(t)))return null;return{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}}(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||O.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const o=function(e,t){const n=/* @__PURE__ */new Map;let o;for(const r of Array.from(e.children)){const e=W(r,t);void 0!==e&&(n.has(e)?o??=e.slice(e.indexOf("=")+1):n.set(e,r))}return void 0!==o&&t.onDuplicateKey?.(e,o),n}(e,n),r=new Set(o.values()),i=Array.from(e.childNodes).filter(e=>!r.has(e)),a=/* @__PURE__ */new Set,l=/* @__PURE__ */new Set,s=Array.from(t.childNodes);let u=e.firstChild,c=0;for(let t=0;t<s.length;t+=1){const r=s[t];let f=null,d=r instanceof Element?W(r,n):void 0;if(void 0!==d&&l.has(d)&&(d=void 0),void 0!==d){l.add(d);const e=o.get(d);if(void 0!==e&&!a.has(e)&&(f=P(e,r,n)===e?e:null,null===f)){e.replaceWith(r),a.add(r),u=r.nextSibling;continue}}else{for(;c<i.length;){const o=i[c];if(c+=1,!a.has(o)){if(R(o,r)){f=P(o,r,n)===o?o:null,null===f&&(e.replaceChild(r,o),a.add(r),u=r.nextSibling);break}if(o instanceof Element){const n=s[t+1];if(!(r instanceof Element)||void 0!==n&&R(o,n)){c-=1;break}e.replaceChild(r,o),a.add(r),u=r.nextSibling;break}if(!(r instanceof Element)){e.replaceChild(r,o),a.add(r),u=r.nextSibling;break}}}if(null===f&&a.has(r))continue}const p=f??r;for(a.add(p);null!==u&&u!==p&&!a.has(u)&&B(u);)u=u.nextSibling;p!==u&&e.insertBefore(p,u),u=p.nextSibling}for(const t of Array.from(e.childNodes))a.has(t)||t.remove()}(e,t,n),function(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,o]=n??[null,null];null!==e&&null!==o&&t.setSelectionRange(e,o)}catch{}}(o),e}function P(e,t,n){return e instanceof Element&&t instanceof Element?H(e)&&H(t)?e:z(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function B(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function R(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var $=["input","textarea","select","option","button","label","details","summary","dialog","video","audio","progress","meter"],q=["type","name","placeholder","open","disabled","readonly","required","checked","selected","value","min","max","step","rows","cols","for","controls","muted","loop","poster","src"],F=/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/gi,K=/* @__PURE__ */new Map,V="data-payload-key",G="data-payload-nested-key",J="data-payload-nested-template";function X(){/* @__PURE__ */
2
- return new WeakMap}function Z(e){const{template:t,container:n,patches:o,nextItems:r,store:i,forceRender:a=!1}=e,l=Y(n,t,o,r,a,i);return null===l?null:ee(l,i,{morph:e.morph??!0,onDuplicateKey:e.onDuplicateKey})}function Q(e,t){return t.hasAttribute(G)&&t.hasAttribute(J)}function Y(e,t,n,o,r,i){const a=function(e,t,n,o,r,i,a){const l=Array.from(e.children),s=le(l,V),u=/* @__PURE__ */new Set,c=[];for(let f=0;f<n.length;f+=1){const d=n[f],p=ae(d);let m=void 0===p?l[f]??null:se(s,p)??null;null!==m&&u.has(m)&&(m=null),null!==m&&u.add(m);const h=o.replaces.has(f),v=r||o.renders.has(f)||null===m?ue(e.ownerDocument,t,d,f):void 0;if(null===v)return null;const g=void 0===v?[]:te(h?null:m,v,d,i,a);if(null===g)return null;c.push([f,m,v??void 0,g,h])}return c}(e,t,o,function(e){const t=/* @__PURE__ */new Set,n=/* @__PURE__ */new Set;for(const o of e)"insert"===o.kind||"update"===o.kind?t.add(o.index):"replace"===o.kind&&(t.add(o.index),n.add(o.index));return{renders:t,replaces:n}}(n),r,i.get(e),i);return null===a?null:[e,a,o]}function ee(e,t,n){const[o,r,i]=e,a=/* @__PURE__ */new Set;let l=!1;for(const[e,i,s,u,c]of r){let r=i;if(void 0!==s){const e=!(!n.morph||c||null===i)&&z(i,s,{keyAttributes:[V,G],retainChildrenOf:Q,...void 0!==n.onDuplicateKey?{onDuplicateKey:n.onDuplicateKey}:{}})===i;if(!e)for(const[e,t]of u)null!==e&&(oe(e,t),t.replaceWith(e));for(const[,,e]of u)void 0!==e&&ee(e,t,n);e?l=!0:(null!==i&&(i.replaceWith(s),l=!0),r=s)}if(null===r)continue;const f=o.children[e]??null;r!==f&&(o.insertBefore(r,f),l=!0),a.add(r)}for(const e of Array.from(o.children))a.has(e)||(e.remove(),l=!0);const s=function(e,t){let n=t.get(e);return n||(n=/* @__PURE__ */new Map,t.set(e,n)),n}(o,t);s.clear();for(const e of i)ie(s,e);return l}function te(e,t,n,o,r){const i=le(null===e?[]:ne(e),G),a=ae(n),l=void 0!==a?o?.get(a):void 0,s=[];for(const e of ne(t)){const t=e.getAttribute(G);if(null===t)continue;const o=se(i,t)??null,a=e.getAttribute(J),u=a?o:null,c=u?.getAttribute(J)??null;let f;if(a){const o=re(n,t);if(void 0!==o||null!==u){const n=o??[],i=D(null===u?[]:re(l,t)??[],n),s=null!==u&&c!==a;if((i.length>0||s)&&(f=Y(u??e,a,i,n,s,r)??void 0,void 0===f))return null}}s.push([u,e,f])}return s}function ne(e){return Array.from(e.querySelectorAll(`[${G}]`)).filter(t=>{let n=t.parentElement;for(;null!==n&&n!==e;){if(n.hasAttribute(G))return!1;n=n.parentElement}return n===e})}function oe(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}function re(e,t){if("object"!=typeof e||null===e)return;const n=e[t];return Array.isArray(n)?n:void 0}function ie(e,t){const n=ae(t);void 0!==n&&e.set(n,t)}function ae(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function le(e,t){const n=/* @__PURE__ */new Map;for(let o=e.length-1;o>=0;o-=1){const r=e[o];if(void 0===r)continue;const i=r.getAttribute(t);if(null===i)continue;const a=n.get(i);void 0===a?n.set(i,[r]):a.push(r)}return n}function se(e,t){return e.get(t)?.pop()}function ue(e,t,n,o){const r=function sanitizeHtml(e,t){const n=("undefined"==typeof __INLINE_BUILD__||__INLINE_BUILD__,"undefined"==typeof document?void 0:document);if(!n)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new b("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===e)return"";const o=function(e){if(!e){const e=/* @__PURE__ */new Map;for(const[t,n]of Object.entries(g))e.set(t,n);return{allowedTags:f,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:S,allowedData:/* @__PURE__ */new Set}}const t=new Set(f);for(const n of e.additionalAllowedTags??[])t.add(n);if(!0===e.allowFormControls)for(const e of d)t.add(e);const n=/* @__PURE__ */new Map;for(const[e,t]of Object.entries(g))n.set(e,t);for(const[t,o]of Object.entries(e.additionalAllowedAttributes??{})){const e=n.get(t),r=new Set(e??[]);for(const e of o)r.add(e);n.set(t,r)}return{allowedTags:t,attrByTag:n,allowFormControls:!0===e.allowFormControls,templateMode:!0===e.templateMode,mode:e.policy??S,allowedData:new Set((e.allowedDataAttributes??[]).map(e=>e.toLowerCase()))}}(t),r=n.createElement("template");return r.innerHTML=i(e),A(r.content,o),r.innerHTML}(function(e,t,n,o){const r="object"==typeof t&&null!==t?t:null;return e.replace(M,(e,i)=>null!==r&&function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(r,i)?escapeHtml(o(Reflect.get(r,i))):null===r&&"value"===i?escapeHtml(o(t)):"index"===i?String(n):e)}(t,n,o,T),function(e){const t=K.get(e);if(void 0!==t)return t;const n=new Set($);for(const t of e.matchAll(F)){const e=t[1]?.toLowerCase();void 0!==e&&n.add(e)}const o={};for(const e of n)o[e]=q;const r={additionalAllowedTags:[...n],additionalAllowedAttributes:o,allowFormControls:!0,templateMode:!0};return K.set(e,r),r}(t)),a=e.createElement("template");a.innerHTML=i(r);const l=a.content.firstElementChild;if(!l)return null;const s=ae(n);return void 0!==s&&l.setAttribute(V,s),l}function ce(){const e=/* @__PURE__ */new WeakMap,t=/* @__PURE__ */new WeakSet,o=/* @__PURE__ */new WeakMap,i=X();return{name:"structural-array",render:/* @__PURE__ */r((r,a)=>{const l=function(e){return null==e||""===e}(a)?[]:a;if(!Array.isArray(l))return!1;const s=r.element,u=r.arrayTemplate;if(void 0===u||0===u.length)return function(e,t,o){e.has(t)||(e.add(t),n(`[live-preview] LP0403: Skipping structural update for "${o}": <${t.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(t,s,r.fieldName),!1;const c=e.get(s),f=fe(s),d=D(c?.values??f.map((e,t)=>null===e?{__payloadDomPosition:t}:{id:e}),l),p=function(e,t,n){return void 0===e||e.template!==t||!function(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}(e.domSnapshot,n)}(c,u,f);if(0===d.length&&!p)return e.set(s,{values:l.slice(),template:u,domSnapshot:f}),!1;!function(e,t,n,o,r){const i=r.map(de),a=/* @__PURE__ */new Set,l=i.find(e=>!(void 0===e||!a.has(e)&&(a.add(e),1)));if(void 0!==l&&pe(e,t,n,l),i.some(e=>void 0===e)&&me(e,t,"LP0404",`LP0404: an item of "${n}" has no id and pairs by position, so an insert re-renders every row after it. Give items a stable id.`),o?.length===r.length&&r.length>1){const r=new Set(o.map(de).filter(e=>void 0!==e)),a=i.some(e=>void 0!==e&&r.has(e));r.size>0&&!a&&me(e,t,"LP0406",`LP0406: every key of "${n}" changed at once; the source generates ids per message, so no item can be retained across updates.`)}}(o,s,r.fieldName,c?.values,l);const m=Z({template:u,container:s,patches:d,nextItems:l,store:i,forceRender:p,onDuplicateKey:(e,t)=>{pe(o,e,r.fieldName,t)}});return null!==m&&(e.set(s,{values:l.slice(),template:u,domSnapshot:fe(s)}),!!m&&void 0)})}}function fe(e){return Array.from(e.children,e=>e.getAttribute(V))}function de(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function pe(e,t,n,o){me(e,t,"LP0405",`LP0405: two items of "${n}" share the key "${o}"; later ones pair by position. Make \`id\` unique per item.`)}function me(e,t,o,r){let i=e.get(t);void 0===i&&(i=/* @__PURE__ */new Set,e.set(t,i)),i.has(o)||(i.add(o),n(`[live-preview] ${r}`))}function he(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const o of e.split(/[\s,]+/)){const e=o.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}function ve(...e){const t=/* @__PURE__ */new Map;for(const n of e)for(const[e,o]of Object.entries(n)){let n=t.get(e);void 0===n&&(n=/* @__PURE__ */new Set,t.set(e,n));for(const e of o)n.add(e)}const n={};for(const[e,o]of t)n[e]=[...o];return n}function ge(e,t){const n={};for(const o of t)o!==e&&(n[o]=[e]);return n}export{j as ISLAND_ATTRIBUTE,V as KEY_ATTRIBUTE,I as OWNED_ATTRIBUTE,Z as applyStructuralPatches,ce as createStructuralArrayRenderer,X as createStructuralStore,ge as dependencyMapFromBinding,H as isMorphBoundary,U as isMorphCompatible,ve as mergeDependencyMaps,z as morphElement,he as parseDependencyList};
1
+ var e,t,n=(e=(...e)=>console.warn(...e),(...t)=>{try{("object"==typeof(n=e(...t))&&null!==n||"function"==typeof n)&&"function"==typeof n.then&&Promise.resolve(n).catch(()=>{})}catch{}var n}),o=/* @__PURE__ */new WeakSet;function r(e){return o.add(e),e}function i(e){const n=function(){if(void 0!==t)return t;const e=function(){const e=globalThis.trustedTypes;if("object"==typeof e&&null!==e)return"function"==typeof e.createPolicy?e:void 0}();try{t=void 0===e?null:e.createPolicy("payload-live-preview",{createHTML:e=>e})}catch{t=null}return t}();return null===n?e:n.createHTML(e)}var a=/* @__PURE__ */new Set(["http:","https:","mailto:","tel:"]),l=/^\s*(?:javascript|data|vbscript|file|blob|about)\s*:/i,s=/^(?:\.{1,2}\/|[a-zA-Z0-9_-]+\/?)/,c=/^[\\/]{2}/,u=/[\t\n\r]/g;function isSafeUrl(e){if("string"!=typeof e)return!1;const t=e.trim().replace(u,"");if(0===t.length)return!1;if(l.test(t))return!1;if(t.startsWith("#")||t.startsWith("?"))return!0;if(c.test(t))return!0;if(t.startsWith("/"))return!0;try{const e=new URL(t);return a.has(e.protocol)}catch{return s.test(t)}}var f=/* @__PURE__ */new Set;function d(e){f.has(e)||(f.add(e),function(e){try{console.warn(e)}catch{}}(`[live-preview] LP0409: the strict sanitizer removed \`${e}\` from written markup; the 1.x default (\`sanitizerPolicy: 'compat'\`) kept it. ${function(e){return e.startsWith("data-payload-")?"A binding inside CMS content is refused by design — an editor could otherwise aim a write at any element on the page (docs/security.md)":"id"===e||"name"===e?"CMS content that can name an element can shadow a global of that name — DOM clobbering, refused by design (docs/security.md)":"List it in `allowedDataAttributes` if the page needs it, or set `sanitizerPolicy: 'compat'` to keep every `data-*` as 1.x did"}(e)}.`))}var p=/* @__PURE__ */new Set(["p","br","strong","b","em","i","u","s","strike","mark","small","h1","h2","h3","h4","h5","h6","ul","ol","li","dl","dt","dd","blockquote","code","pre","kbd","samp","var","a","span","div","section","article","aside","header","footer","nav","figure","figcaption","img","picture","source","audio","video","sub","sup","hr","time","abbr","cite","q","table","thead","tbody","tfoot","tr","th","td","caption","colgroup","col"]),m=/* @__PURE__ */new Set(["input","button","textarea","select","option","label"]),h=/* @__PURE__ */new Set(["script","style","iframe","object","embed","link","meta","base","form","input","button","select","textarea","svg","math","template","frame","frameset","noframes","noscript"]),y=/* @__PURE__ */new Set(["id","class","lang","dir","title","role","tabindex"]),v="aria-",b="data-",g={a:/* @__PURE__ */new Set(["href","target","rel","download","hreflang","type"]),img:/* @__PURE__ */new Set(["src","srcset","sizes","alt","width","height","loading","decoding"]),picture:/* @__PURE__ */new Set([]),source:/* @__PURE__ */new Set(["src","srcset","sizes","type","media"]),audio:/* @__PURE__ */new Set(["src","controls","autoplay","loop","muted","preload"]),video:/* @__PURE__ */new Set(["src","poster","controls","autoplay","loop","muted","preload","width","height","playsinline"]),time:/* @__PURE__ */new Set(["datetime"]),abbr:/* @__PURE__ */new Set(["title"]),q:/* @__PURE__ */new Set(["cite"]),blockquote:/* @__PURE__ */new Set(["cite"]),table:/* @__PURE__ */new Set(["summary"]),th:/* @__PURE__ */new Set(["colspan","rowspan","scope","headers","abbr"]),td:/* @__PURE__ */new Set(["colspan","rowspan","headers"]),col:/* @__PURE__ */new Set(["span"]),colgroup:/* @__PURE__ */new Set(["span"]),ol:/* @__PURE__ */new Set(["start","reversed","type"]),li:/* @__PURE__ */new Set(["value"]),code:/* @__PURE__ */new Set(["class"]),pre:/* @__PURE__ */new Set(["class"])},w=/* @__PURE__ */new Set(["href","src","cite","poster"]),S=class extends Error{name="SanitizerEnvironmentError"},A=/* @__PURE__ */new Set(["id","name","data-payload-key","data-payload-nested-key","data-payload-nested-template"]);function k(e,t){for(const n of Array.from(e.childNodes))1===n.nodeType?x(n,t):8===n.nodeType&&n.remove()}function x(e,t){const n=e.tagName.toLowerCase();if(!h.has(n)||t.allowFormControls&&m.has(n)){if(!t.allowedTags.has(n))return k(e,t),void e.replaceWith(...e.childNodes);!function(e,t,n){const o=n.attrByTag.get(t);for(const t of Array.from(e.attributes)){const r=t.name.toLowerCase();if(r.startsWith("on")||"style"===r)e.removeAttribute(t.name);else{if("strict"===n.mode){if(n.templateMode&&A.has(r))continue;if("id"===r||"name"===r||r.startsWith("data-payload-")){e.removeAttribute(t.name),d(r);continue}if(r.startsWith(b)){n.allowedData.has(r)||(e.removeAttribute(t.name),d(r));continue}if(y.has(r)||r.startsWith(v))continue}else if(y.has(r)||r.startsWith(v)||r.startsWith(b))continue;o?.has(r)?w.has(r)&&!isSafeUrl(t.value)?e.removeAttribute(t.name):"srcset"!==r||L(t.value)||e.removeAttribute(t.name):e.removeAttribute(t.name)}}}(e,n,t),"a"===n&&function(e){const t=e.getAttribute("href");null!==t&&function isExternalHttpUrl(e){const t=e.trim().replace(u,"");return/^https?:\/\//i.test(t)||c.test(t)}(t)&&(e.setAttribute("rel","noopener noreferrer"),e.hasAttribute("target")||e.setAttribute("target","_blank"))}(e),k(e,t)}else e.remove()}function L(e){for(const t of e.split(",")){const e=t.trim();if(0===e.length)continue;const[n=e]=e.split(/\s/,1);if(!isSafeUrl(n))return!1}return!0}var E=Object.freeze({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;","/":"&#x2F;","`":"&#x60;","=":"&#x3D;"}),M=/[&<>"'/`=]/g;function escapeHtml(e){return e.replace(M,e=>E[e])}var T=/* @__PURE__ */new Set(["style","srcdoc","formaction","form","id","name","is","srcset","imagesrcset"]);function D(e){return!e.startsWith("on")&&!T.has(e)}var N=/\{\{([\s\S]*?)\}\}/g;function _(e){if(null==e)return"";if("string"==typeof e)return e;if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return String(e);try{return JSON.stringify(e)}catch{return""}}function j(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?t:void 0}function C(e){if("object"!=typeof e||null===e)return;const t=e.blockType;return"string"==typeof t?t:void 0}function z(e,t){return t.every(e=>void 0!==j(e))?function(e,t){const n=[],o=/* @__PURE__ */new Map;for(let t=0;t<e.length;t+=1){const n=j(e[t]);void 0!==n&&o.set(n,t)}const r=/* @__PURE__ */new Set;for(let i=0;i<t.length;i+=1){const a=t[i],l=j(a);if(void 0===l){n.push({kind:"insert",index:i,value:a});continue}const s=o.get(l);if(void 0===s){n.push({kind:"insert",index:i,value:a});continue}r.add(s);const c=e[s];C(c)===C(a)?(s!==i&&n.push({kind:"move",from:s,to:i,value:a}),I(c,a)||n.push({kind:"update",index:i,value:a})):n.push({kind:"replace",index:i,oldValue:c,value:a})}for(let t=0;t<e.length;t+=1)r.has(t)||n.push({kind:"remove",index:t,value:e[t]});return n}(e,t):function(e,t){const n=[],o=Math.min(e.length,t.length);for(let r=0;r<o;r+=1)I(e[r],t[r])||n.push({kind:"update",index:r,value:t[r]});if(t.length>e.length)for(let o=e.length;o<t.length;o+=1)n.push({kind:"insert",index:o,value:t[o]});if(e.length>t.length)for(let o=t.length;o<e.length;o+=1)n.push({kind:"remove",index:o,value:e[o]});return n}(e,t)}function I(e,t){if(Object.is(e,t))return!0;if("object"!=typeof e||"object"!=typeof t||null===e||null===t)return!1;const n=e,o=t,r=Object.keys(n),i=Object.keys(o);if(r.length!==i.length)return!1;for(const e of r)if(!Object.is(n[e],o[e]))return!1;return!0}var W="data-payload-island",O="data-payload-owned",P=/* @__PURE__ */new Set(["open","value","checked","selected"]);function H(e,t){for(const n of t.keyAttributes){const t=e.getAttribute(n);if(null!==t&&t.length>0)return`${n}=${t}`}}function U(e){if(e.tagName.toLowerCase().includes("-"))return!0;if(e.hasAttribute(W)||e.hasAttribute(O))return!0;const t=e.getAttribute("contenteditable");return null!==t&&"false"!==t}function $(e,t){return e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI&&!U(e)&&!U(t)}function R(e,t,n){if(!$(e,t))return t;const o=function(e){const t=e.ownerDocument.activeElement;if(!(t instanceof HTMLElement&&e.contains(t)))return null;return{element:t,selection:t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement?[t.selectionStart,t.selectionEnd]:null}}(e);return function(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||P.has(n.name.toLowerCase())||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}(e,t),!0!==n.retainChildrenOf?.(e,t)&&function(e,t,n){const o=function(e,t){const n=/* @__PURE__ */new Map;let o;for(const r of Array.from(e.children)){const e=H(r,t);void 0!==e&&(n.has(e)?o??=e.slice(e.indexOf("=")+1):n.set(e,r))}return void 0!==o&&t.onDuplicateKey?.(e,o),n}(e,n),r=new Set(o.values()),i=Array.from(e.childNodes).filter(e=>!r.has(e)),a=/* @__PURE__ */new Set,l=/* @__PURE__ */new Set,s=Array.from(t.childNodes);let c=e.firstChild,u=0;for(let t=0;t<s.length;t+=1){const r=s[t];let f=null,d=r instanceof Element?H(r,n):void 0;if(void 0!==d&&l.has(d)&&(d=void 0),void 0!==d){l.add(d);const e=o.get(d);if(void 0!==e&&!a.has(e)&&(f=B(e,r,n)===e?e:null,null===f)){e.replaceWith(r),a.add(r),c=r.nextSibling;continue}}else{for(;u<i.length;){const o=i[u];if(u+=1,!a.has(o)){if(F(o,r)){f=B(o,r,n)===o?o:null,null===f&&(e.replaceChild(r,o),a.add(r),c=r.nextSibling);break}if(o instanceof Element){const n=s[t+1];if(!(r instanceof Element)||void 0!==n&&F(o,n)){u-=1;break}e.replaceChild(r,o),a.add(r),c=r.nextSibling;break}if(!(r instanceof Element)){e.replaceChild(r,o),a.add(r),c=r.nextSibling;break}}}if(null===f&&a.has(r))continue}const p=f??r;for(a.add(p);null!==c&&c!==p&&!a.has(c)&&q(c);)c=c.nextSibling;p!==c&&e.insertBefore(p,c),c=p.nextSibling}for(const t of Array.from(e.childNodes))a.has(t)||t.remove()}(e,t,n),function(e){if(null===e)return;const{element:t,selection:n}=e;if(t.ownerDocument.activeElement!==t&&t.isConnected)try{t.focus({preventScroll:!0});const[e,o]=n??[null,null];null!==e&&null!==o&&t.setSelectionRange(e,o)}catch{}}(o),e}function B(e,t,n){return e instanceof Element&&t instanceof Element?U(e)&&U(t)?e:R(e,t,n):(e.nodeValue!==t.nodeValue&&(e.nodeValue=t.nodeValue),e)}function q(e){return e.nodeType===Node.TEXT_NODE&&0===(e.nodeValue??"").trim().length}function F(e,t){return e.nodeType===t.nodeType&&(!(e instanceof Element&&t instanceof Element)||e.tagName===t.tagName&&e.namespaceURI===t.namespaceURI)}var K=["input","textarea","select","option","button","label","details","summary","dialog","video","audio","progress","meter"],V=["type","name","placeholder","open","disabled","readonly","required","checked","selected","value","min","max","step","rows","cols","for","controls","muted","loop","poster","src"],G=/<([a-z][a-z0-9]*(?:-[a-z0-9]+)+)\b/gi,J=/* @__PURE__ */new Map,X="data-payload-key",Z="data-payload-nested-key",Q="data-payload-nested-template";function Y(){/* @__PURE__ */
2
+ return new WeakMap}function ee(e){const t=ne(e.container,e.patches,e);return null===t?null:oe(t,e.store,{morph:e.morph??!0,onDuplicateKey:e.onDuplicateKey})}function te(e,t){return t.hasAttribute(Z)&&t.hasAttribute(Q)}function ne(e,t,n){const o=function(e,t,n){const{template:o,nextItems:r,forceRender:i=!1,store:a,sanitizerPolicy:l}=n,s=a.get(e),c=function(e){const t=e.children,n=t[0];if(void 0===n)return[];const o=[];for(const{name:e,value:r}of Array.from(n.attributes)){if(!D(e)||e.startsWith("data-payload-"))continue;let n=!0;for(let o=1;o<t.length&&n;o+=1)n=t[o]?.getAttribute(e)===r;n&&o.push([e,r])}return o}(e),u=function(e){const t=/* @__PURE__ */new Set;for(const n of e)if("object"==typeof n&&null!==n)for(const e of Object.keys(n))t.add(e);return t}(r),f=Array.from(e.children),d=ue(f,X),p=/* @__PURE__ */new Set,m=[];for(let a=0;a<r.length;a+=1){const h=r[a],y=ce(h);let v=void 0===y?f[a]??null:fe(d,y)??null;null!==v&&p.has(v)&&(v=null),null!==v&&p.add(v);const b=t.replaces.has(a),g=i||t.renders.has(a)||null===v?de(e.ownerDocument,o,h,a,l,c,u):void 0;if(null===g)return null;const w=void 0===g?[]:re(b?null:v,g,h,void 0===y?void 0:s?.get(y),n);if(null===w)return null;m.push([a,v,g,w,b])}return m}(e,function(e){const t=/* @__PURE__ */new Set,n=/* @__PURE__ */new Set;for(const o of e)"insert"===o.kind||"update"===o.kind?t.add(o.index):"replace"===o.kind&&(t.add(o.index),n.add(o.index));return{renders:t,replaces:n}}(t),n);return null===o?null:[e,o,n.nextItems]}function oe(e,t,n){const[o,r,i]=e,a=/* @__PURE__ */new Set;let l=!1;for(const[e,i,s,c,u]of r){let r=i;if(void 0!==s){const e=!(!n.morph||u||null===i)&&R(i,s,{keyAttributes:[X,Z],retainChildrenOf:te,...void 0!==n.onDuplicateKey?{onDuplicateKey:n.onDuplicateKey}:{}})===i;if(!e)for(const[e,t]of c)null!==e&&(ae(e,t),t.replaceWith(e));for(const[,,e]of c)void 0!==e&&oe(e,t,n);e?l=!0:(null!==i&&(i.replaceWith(s),l=!0),r=s)}if(null===r)continue;const f=o.children[e]??null;r!==f&&(o.insertBefore(r,f),l=!0),a.add(r)}for(const e of Array.from(o.children))a.has(e)||(e.remove(),l=!0);const s=function(e,t){let n=t.get(e);return n||(n=/* @__PURE__ */new Map,t.set(e,n)),n}(o,t);s.clear();for(const e of i)se(s,e);return l}function re(e,t,n,o,r){const i=ue(null===e?[]:ie(e),Z),a=[];for(const e of ie(t)){const t=e.getAttribute(Z);if(null===t)continue;const l=fe(i,t)??null,s=e.getAttribute(Q),c=s?l:null,u=c?.getAttribute(Q)??null;let f;if(s){const i=le(n,t);if(void 0!==i||null!==c){const n=i??[],a=z(null===c?[]:le(o,t)??[],n),l=null!==c&&u!==s;if((a.length>0||l)&&(f=ne(c??e,a,{template:s,nextItems:n,forceRender:l,store:r.store,sanitizerPolicy:r.sanitizerPolicy})??void 0,void 0===f))return null}}a.push([c,e,f])}return a}function ie(e){return Array.from(e.querySelectorAll(`[${Z}]`)).filter(t=>{let n=t.parentElement;for(;null!==n&&n!==e;){if(n.hasAttribute(Z))return!1;n=n.parentElement}return n===e})}function ae(e,t){for(const n of Array.from(e.attributes))t.hasAttribute(n.name)||e.removeAttribute(n.name);for(const n of Array.from(t.attributes))e.getAttribute(n.name)!==n.value&&e.setAttribute(n.name,n.value)}function le(e,t){if("object"!=typeof e||null===e)return;const n=e[t];return Array.isArray(n)?n:void 0}function se(e,t){const n=ce(t);void 0!==n&&e.set(n,t)}function ce(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function ue(e,t){const n=/* @__PURE__ */new Map;for(let o=e.length-1;o>=0;o-=1){const r=e[o];if(void 0===r)continue;const i=r.getAttribute(t);if(null===i)continue;const a=n.get(i);void 0===a?n.set(i,[r]):a.push(r)}return n}function fe(e,t){return e.get(t)?.pop()}function de(e,t,n,o,r,a,l){const s=function(e,t,n){const o=("undefined"==typeof __INLINE_BUILD__||__INLINE_BUILD__,"undefined"==typeof document?void 0:document);if(!o)throw"undefined"!=typeof __INLINE_BUILD__&&__INLINE_BUILD__?new Error("sanitizeHtml needs a DOM"):new S("sanitizeHtml needs a DOM; provide one with setSanitizerDocument() during SSR.");if(""===e)return"";const r=function(e,t){const n=e?.policy??t??"strict";if(!e){const e=/* @__PURE__ */new Map;for(const[t,n]of Object.entries(g))e.set(t,n);return{allowedTags:p,attrByTag:e,allowFormControls:!1,templateMode:!1,mode:n,allowedData:/* @__PURE__ */new Set}}const o=new Set(p);if(e.additionalAllowedTags?.forEach(e=>o.add(e)),!0===e.allowFormControls)for(const e of m)o.add(e);const r=/* @__PURE__ */new Map;for(const[e,t]of Object.entries(g))r.set(e,t);for(const[t,n]of Object.entries(e.additionalAllowedAttributes??{})){const e=new Set(r.get(t));for(const t of n)e.add(t);r.set(t,e)}return{allowedTags:o,attrByTag:r,allowFormControls:!0===e.allowFormControls,templateMode:!0===e.templateMode,mode:n,allowedData:new Set(e.allowedDataAttributes?.map(e=>e.toLowerCase()))}}(n,t),a=o.createElement("template");return a.innerHTML=i(e),k(a.content,r),a.innerHTML}(function(e,t,n,o,r){const i="object"==typeof t&&null!==t?t:null;return e.replace(N,(e,a)=>null!==i&&function(e,t){return Object.prototype.hasOwnProperty.call(e,t)}(i,a)?escapeHtml(o(Reflect.get(i,a))):null===i&&"value"===a?escapeHtml(o(t)):"index"===a?String(n):null!==i&&!0===r?.has(a)?"":e)}(t,n,o,_,l),r,function(e){const t=function(e,t){const n=e.get(t);return void 0!==n&&(e.delete(t),e.set(t,n)),n}(J,e);if(void 0!==t)return t;const n=new Set(K);for(const t of e.matchAll(G)){const e=t[1]?.toLowerCase();void 0!==e&&n.add(e)}const o={};for(const e of n)o[e]=V;return i=e,a={additionalAllowedTags:[...n],additionalAllowedAttributes:o,allowFormControls:!0,templateMode:!0},(r=J).set(i,a),function(e){for(const t of e.keys()){if(e.size<=64)break;e.delete(t)}}(r),a;var r,i,a}(t)),c=e.createElement("template");c.innerHTML=i(s);const u=c.content.firstElementChild;if(!u)return null;!function(e,t){for(const[n,o]of t)e.hasAttribute(n)||e.setAttribute(n,o)}(u,a);const f=ce(n);return void 0!==f&&u.setAttribute(X,f),u}function pe(){const e=/* @__PURE__ */new WeakMap,t=/* @__PURE__ */new WeakSet,o=/* @__PURE__ */new WeakMap,i=Y();return{name:"structural-array",render:/* @__PURE__ */r((r,a,l)=>{const s=function(e){return null==e||""===e}(a)?[]:a;if(!Array.isArray(s))return!1;const c=r.element,u=r.arrayTemplate;if(void 0===u||0===u.length)return function(e,t,o){e.has(t)||(e.add(t),n(`[live-preview] LP0403: Skipping structural update for "${o}": <${t.tagName.toLowerCase()} data-payload-structural> needs data-payload-array-template (for example "<li>{{label}}</li>").`))}(t,c,r.fieldName),!1;const f=e.get(c),d=me(c),p=z(f?.values??d.map((e,t)=>null===e?{__payloadDomPosition:t}:{id:e}),s),m=function(e,t,n){return void 0===e||e.template!==t||!function(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}(e.domSnapshot,n)}(f,u,d);if(0===p.length&&!m)return e.set(c,{values:s.slice(),template:u,domSnapshot:d}),!1;!function(e,t,n,o,r){const i=r.map(he),a=/* @__PURE__ */new Set,l=i.find(e=>!(void 0===e||!a.has(e)&&(a.add(e),1)));if(void 0!==l&&ye(e,t,n,l),i.some(e=>void 0===e)&&ve(e,t,"LP0404",`LP0404: an item of "${n}" has no id and pairs by position, so an insert re-renders every row after it. Give items a stable id.`),o?.length===r.length&&r.length>1){const r=new Set(o.map(he).filter(e=>void 0!==e)),a=i.some(e=>void 0!==e&&r.has(e));r.size>0&&!a&&ve(e,t,"LP0406",`LP0406: every key of "${n}" changed at once; the source generates ids per message, so no item can be retained across updates.`)}}(o,c,r.fieldName,f?.values,s);const h=ee({template:u,container:c,patches:p,nextItems:s,store:i,forceRender:m,sanitizerPolicy:l.sanitizerPolicy,onDuplicateKey:(e,t)=>{ye(o,e,r.fieldName,t)}});return null!==h&&(e.set(c,{values:s.slice(),template:u,domSnapshot:me(c)}),!!h&&void 0)})}}function me(e){return Array.from(e.children,e=>e.getAttribute(X))}function he(e){if("object"!=typeof e||null===e)return;const t=e.id;return"string"==typeof t||"number"==typeof t?String(t):void 0}function ye(e,t,n,o){ve(e,t,"LP0405",`LP0405: two items of "${n}" share the key "${o}"; later ones pair by position. Make \`id\` unique per item.`)}function ve(e,t,o,r){let i=e.get(t);void 0===i&&(i=/* @__PURE__ */new Set,e.set(t,i)),i.has(o)||(i.add(o),n(`[live-preview] ${r}`))}function be(e){if(null==e)return[];const t=/* @__PURE__ */new Set,n=[];for(const o of e.split(/[\s,]+/)){const e=o.trim();0===e.length||t.has(e)||(t.add(e),n.push(e))}return n}function ge(...e){const t=/* @__PURE__ */new Map;for(const n of e)for(const[e,o]of Object.entries(n)){let n=t.get(e);void 0===n&&(n=/* @__PURE__ */new Set,t.set(e,n));for(const e of o)n.add(e)}const n={};for(const[e,o]of t)n[e]=[...o];return n}function we(e,t){const n={};for(const o of t)o!==e&&(n[o]=[e]);return n}export{W as ISLAND_ATTRIBUTE,X as KEY_ATTRIBUTE,O as OWNED_ATTRIBUTE,ee as applyStructuralPatches,pe as createStructuralArrayRenderer,Y as createStructuralStore,we as dependencyMapFromBinding,U as isMorphBoundary,$ as isMorphCompatible,ge as mergeDependencyMaps,R as morphElement,be as parseDependencyList};
3
3
  //# sourceMappingURL=structural.js.map