@livetemplate/client 0.11.4 → 0.11.6

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.
@@ -104,4 +104,125 @@ export declare function handleToastDirectives(rootElement: Element): void;
104
104
  * the user clicks outside the toast stack. Called once at connect time.
105
105
  */
106
106
  export declare function setupToastClickOutside(): void;
107
+ /**
108
+ * Activate Declarative Shadow DOM for `<template shadowrootmode>` elements
109
+ * that the client inserted via DOM APIs (innerHTML setter, morphdom's
110
+ * createElement+appendChild path). The HTML parser activates declarative
111
+ * shadow roots only at parse time or via setHTMLUnsafe / parseHTMLUnsafe;
112
+ * a `<template shadowrootmode>` set via `.innerHTML = ...` is parked as a
113
+ * plain template with content but no attached shadow root. This sweep
114
+ * closes that gap so server-emitted shadow roots survive a client
115
+ * re-render.
116
+ *
117
+ * For each matching template found under rootElement:
118
+ * - attach a shadow root on the parent (open by default; "closed" when
119
+ * shadowrootmode="closed");
120
+ * - move the template's content into the shadow root (replaceChildren
121
+ * accepts a DocumentFragment and re-parents its children atomically,
122
+ * so re-renders cleanly reset prior shadow content);
123
+ * - remove the template.
124
+ *
125
+ * Hosts that can't accept a shadow root (a small fixed set: <input>,
126
+ * <textarea>, void elements, etc.) silently drop the template — better
127
+ * than an unhandled exception that kills the render.
128
+ *
129
+ * Closed-mode roots are tracked in a module-level WeakMap so re-renders
130
+ * can locate them (parent.shadowRoot returns null for closed roots).
131
+ *
132
+ * Idempotent: a re-run with no remaining templates is one qsa walk and
133
+ * an early return (sub-millisecond on hundreds-of-rows pages).
134
+ *
135
+ * Known limitations:
136
+ *
137
+ * - Nested DSD is inert on EVERY render, not just re-renders. A
138
+ * `<template>`'s content lives in a DocumentFragment (`tpl.content`),
139
+ * not in the light DOM, and `querySelectorAll` does not descend into
140
+ * that fragment. So a `<template shadowrootmode>` nested inside
141
+ * another `<template>` is never in the qsa result. Once the outer
142
+ * shadow has been attached, the inner template ends up behind a
143
+ * shadow boundary — still unreachable. The fix would be a recursive
144
+ * sweep per new shadow root from within this loop.
145
+ *
146
+ * - Shadow-root options (`delegatesFocus`, `clonable`, `serializable`,
147
+ * even `mode`) are fixed at first attach. A re-render that toggles
148
+ * `shadowrootdelegatesfocus` on a host that already has a shadow root
149
+ * won't change the existing root's focus behaviour — re-attach isn't
150
+ * possible. Matches the HTML parser, which would have made the same
151
+ * one-shot decision; if the server needs to flip these flags, it
152
+ * needs to swap the host element entirely. The mode-mismatch case
153
+ * also logs a console.warn so the divergence is visible.
154
+ */
155
+ export declare function handleShadowRootHydration(rootElement: Element): void;
156
+ /**
157
+ * Apply area-select directives. `lvt-fx:area-select="<actionName>"` on
158
+ * an element (typically an `<img>` inside a positioned parent) lets
159
+ * the user drag a rectangle locally — a `<div>` overlay tracks the
160
+ * gesture in real time without a server round-trip — and on
161
+ * `pointerup` dispatches a single livetemplate action with the final
162
+ * `{x, y, w, h}` as 0..1 fractions of the element's rendered bounding
163
+ * rect. The image's intrinsic dimensions don't matter for the
164
+ * fractions: any uniform scale (zoom, responsive layout) preserves
165
+ * the fraction. The consumer scales to pixels using the natural size
166
+ * if it needs them.
167
+ *
168
+ * Contract:
169
+ * - Host's `parentElement` must establish a positioning context
170
+ * (`position: relative` / `absolute` / `fixed`). The overlay is
171
+ * `position: absolute` inside that parent so it follows the host
172
+ * on scroll / reflow.
173
+ * - Consumers usually pair this with `touch-action: none` on the
174
+ * host so iOS Safari doesn't interpret the drag as a pinch/scroll.
175
+ * - `<img>` and other natively-draggable hosts work automatically:
176
+ * the directive calls `preventDefault()` on `dragstart` so the
177
+ * browser's native drag (which would otherwise steal the gesture)
178
+ * is suppressed.
179
+ * - On pointer-cancel (e.g. system gesture, app switch), the overlay
180
+ * is removed and no action is dispatched — same effect as cancelling
181
+ * a click on `mouseleave`.
182
+ * - Drags smaller than `MIN_AREA_FRACTION` in BOTH dimensions are
183
+ * dropped — a click on the host still fires normal `click`
184
+ * handlers via the compatibility mouse events.
185
+ * - For text-bearing hosts, set `user-select: none` (the directive
186
+ * deliberately does NOT call `preventDefault()` on `pointerdown`
187
+ * so click handlers still receive the gesture; that means the
188
+ * browser's default text-selection-on-drag behaviour also fires
189
+ * unless the host opts out via CSS).
190
+ * - The overlay uses `z-index: var(--lvt-area-select-z-index, 9999)`.
191
+ * 9999 is high enough for most use cases but can collide with
192
+ * portals / modals / drawers that also sit at a high z-index.
193
+ * Set `--lvt-area-select-z-index` on the host (or any ancestor)
194
+ * to override. Color + fill follow the same pattern via
195
+ * `--lvt-area-select-color` and `--lvt-area-select-fill`.
196
+ * - **No keyboard equivalent.** Pointer-only by design (a keyboard-
197
+ * selected rectangle requires a different UX — focus + arrow keys
198
+ * to position + arrow keys to size). Consumers needing a11y for
199
+ * area selection should provide a parallel form-based affordance.
200
+ *
201
+ * Idempotent across renders: an element re-armed with the same action
202
+ * keeps its existing listeners. A different action causes a tear-down
203
+ * and re-arm. Disconnected elements (and elements whose attribute was
204
+ * cleared by a server diff) get their listeners cleaned up by the
205
+ * sweep at the top of every call — we use a regular Map (not WeakMap)
206
+ * specifically so the sweep can iterate.
207
+ *
208
+ * Module-level singleton: `areaSelectArmed` is shared across all
209
+ * LiveTemplateClient instances in the same window. If two clients
210
+ * ever arm the same element with different actions, the second wins
211
+ * and the first client's send() is orphaned. Single-client use is
212
+ * unaffected.
213
+ */
214
+ export declare function handleAreaSelectDirectives(rootElement: Element, send: (message: {
215
+ action: string;
216
+ data: Record<string, unknown>;
217
+ }) => void): void;
218
+ /**
219
+ * Cancel area-select listeners for every armed element under root.
220
+ * Mirrors teardownAutoClickTimers: meant for the client's disconnect /
221
+ * destroy lifecycle so the module-level singleton doesn't outlive a
222
+ * client that was torn down without a subsequent
223
+ * handleAreaSelectDirectives call (e.g. network error closed the
224
+ * socket while an element was armed). Without this, a SPA that mounts
225
+ * + tears down livetemplate trees would leak listeners across mounts.
226
+ */
227
+ export declare function teardownAreaSelectForRoot(rootElement: Element): void;
107
228
  //# sourceMappingURL=directives.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../../dom/directives.ts"],"names":[],"mappings":"AA4CA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iCAAiC,IAAI,IAAI,CAKxD;AAsBD;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,OAAO,GAAG,IAAI,CA0CvF;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAWrE;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,OAAO,EACpB,SAAS,EAAE,MAAM,EACjB,UAAU,CAAC,EAAE,MAAM,GAClB,IAAI,CAiBN;AAiLD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAiBpE;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAUvE;AAaD,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAMjE;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAG9C;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CA8FpE;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAMpE;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CAQlE;AAwCD;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,OAAO,GAAG,IAAI,CA4BhE;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,IAAI,IAAI,CAW7C"}
1
+ {"version":3,"file":"directives.d.ts","sourceRoot":"","sources":["../../dom/directives.ts"],"names":[],"m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