kerfjs 4.1.1 → 4.2.0-beta.2
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/CHANGELOG.md +11 -0
- package/dist/actions.d.ts +72 -0
- package/dist/actions.js +26 -0
- package/dist/actions.js.map +1 -0
- package/dist/array-signal.js +3 -104
- package/dist/array-signal.js.map +1 -1
- package/dist/async.d.ts +59 -0
- package/dist/async.js +55 -0
- package/dist/async.js.map +1 -0
- package/dist/attrSelector-Cmu2ZoGO.d.ts +79 -0
- package/dist/chunk-4MY2656S.js +1395 -0
- package/dist/chunk-4MY2656S.js.map +1 -0
- package/dist/{chunk-JXAR5J54.js → chunk-FSAQR6IU.js} +7 -4
- package/dist/chunk-FSAQR6IU.js.map +1 -0
- package/dist/chunk-KEZTD6H4.js +54 -0
- package/dist/chunk-KEZTD6H4.js.map +1 -0
- package/dist/chunk-MRYM3O3V.js +106 -0
- package/dist/chunk-MRYM3O3V.js.map +1 -0
- package/dist/chunk-U32TFTGZ.js +74 -0
- package/dist/chunk-U32TFTGZ.js.map +1 -0
- package/dist/delegate-CL9VTZFb.d.ts +93 -0
- package/dist/html.js +2 -2
- package/dist/imperative.d.ts +34 -0
- package/dist/imperative.js +20 -0
- package/dist/imperative.js.map +1 -0
- package/dist/index.d.ts +21 -219
- package/dist/index.js +13 -1511
- package/dist/index.js.map +1 -1
- package/dist/jsx-runtime.d.ts +13 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/list.d.ts +39 -0
- package/dist/list.js +146 -0
- package/dist/list.js.map +1 -0
- package/dist/mount-Bo2qOx25.d.ts +57 -0
- package/dist/overlay.d.ts +204 -0
- package/dist/overlay.js +406 -0
- package/dist/overlay.js.map +1 -0
- package/dist/remount.d.ts +52 -0
- package/dist/remount.js +45 -0
- package/dist/remount.js.map +1 -0
- package/dist/scope.d.ts +67 -0
- package/dist/scope.js +71 -0
- package/dist/scope.js.map +1 -0
- package/dist/timing.d.ts +65 -0
- package/dist/timing.js +80 -0
- package/dist/timing.js.map +1 -0
- package/package.json +34 -1
- package/dist/chunk-JXAR5J54.js.map +0 -1
package/dist/overlay.js
ADDED
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { mount } from './chunk-4MY2656S.js';
|
|
2
|
+
import { delegate } from './chunk-KEZTD6H4.js';
|
|
3
|
+
import './chunk-QIP723L4.js';
|
|
4
|
+
import './chunk-YHH7OUFA.js';
|
|
5
|
+
import { jsx } from './chunk-FSAQR6IU.js';
|
|
6
|
+
import './chunk-3APBEVHF.js';
|
|
7
|
+
import './chunk-GY4XV2UV.js';
|
|
8
|
+
import './chunk-VVDJLWMP.js';
|
|
9
|
+
|
|
10
|
+
// src/overlay.ts
|
|
11
|
+
var FOCUSABLE = 'a[href],area[href],button:not([disabled]),input:not([disabled]),select:not([disabled]),textarea:not([disabled]),iframe,[tabindex]:not([tabindex="-1"]),[contenteditable="true"]';
|
|
12
|
+
function focusable(root) {
|
|
13
|
+
return Array.from(root.querySelectorAll(FOCUSABLE)).filter(
|
|
14
|
+
(el) => !el.hasAttribute("hidden")
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
function overlay(content, options = {}) {
|
|
18
|
+
const {
|
|
19
|
+
container = document.body,
|
|
20
|
+
className = "kerf-overlay",
|
|
21
|
+
dismiss = ["escape", "backdrop"],
|
|
22
|
+
initialFocus = true,
|
|
23
|
+
trap = true,
|
|
24
|
+
role = "dialog",
|
|
25
|
+
onDismiss,
|
|
26
|
+
outsideIgnore
|
|
27
|
+
} = options;
|
|
28
|
+
const triggers = dismiss === false ? [] : Array.isArray(dismiss) ? dismiss : [dismiss];
|
|
29
|
+
const restoreTo = document.activeElement;
|
|
30
|
+
const wrapper = document.createElement("div");
|
|
31
|
+
wrapper.className = className;
|
|
32
|
+
if (trap) {
|
|
33
|
+
wrapper.setAttribute("role", role);
|
|
34
|
+
wrapper.setAttribute("aria-modal", "true");
|
|
35
|
+
}
|
|
36
|
+
container.appendChild(wrapper);
|
|
37
|
+
const disposeMount = mount(wrapper, typeof content === "function" ? content : () => content);
|
|
38
|
+
const removers = [];
|
|
39
|
+
const resultBox = {};
|
|
40
|
+
const result = new Promise((resolve) => {
|
|
41
|
+
resultBox.resolve = resolve;
|
|
42
|
+
});
|
|
43
|
+
const state = { closed: false };
|
|
44
|
+
function close(value) {
|
|
45
|
+
if (state.closed) return;
|
|
46
|
+
state.closed = true;
|
|
47
|
+
for (const remove of removers) remove();
|
|
48
|
+
disposeMount();
|
|
49
|
+
wrapper.remove();
|
|
50
|
+
if (restoreTo instanceof HTMLElement && restoreTo.isConnected) restoreTo.focus();
|
|
51
|
+
resultBox.resolve?.(value);
|
|
52
|
+
}
|
|
53
|
+
function userDismiss() {
|
|
54
|
+
onDismiss?.();
|
|
55
|
+
close();
|
|
56
|
+
}
|
|
57
|
+
const wantEscape = triggers.includes("escape");
|
|
58
|
+
if (wantEscape || trap) {
|
|
59
|
+
const onKeydown = (event) => {
|
|
60
|
+
if (wantEscape && event.key === "Escape") {
|
|
61
|
+
event.stopPropagation();
|
|
62
|
+
userDismiss();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (trap && event.key === "Tab") {
|
|
66
|
+
const items = focusable(wrapper);
|
|
67
|
+
if (items.length === 0) {
|
|
68
|
+
event.preventDefault();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const first = items[0];
|
|
72
|
+
const last = items[items.length - 1];
|
|
73
|
+
const active = document.activeElement;
|
|
74
|
+
const outside = !wrapper.contains(active);
|
|
75
|
+
if (event.shiftKey && (active === first || outside)) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
last.focus();
|
|
78
|
+
} else if (!event.shiftKey && (active === last || outside)) {
|
|
79
|
+
event.preventDefault();
|
|
80
|
+
first.focus();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
document.addEventListener("keydown", onKeydown, true);
|
|
85
|
+
removers.push(() => document.removeEventListener("keydown", onKeydown, true));
|
|
86
|
+
}
|
|
87
|
+
if (triggers.includes("backdrop")) {
|
|
88
|
+
const onClick = (event) => {
|
|
89
|
+
if (event.target === wrapper) userDismiss();
|
|
90
|
+
};
|
|
91
|
+
wrapper.addEventListener("click", onClick);
|
|
92
|
+
removers.push(() => wrapper.removeEventListener("click", onClick));
|
|
93
|
+
}
|
|
94
|
+
if (triggers.includes("outside")) {
|
|
95
|
+
const ignore = outsideIgnore === void 0 ? [] : Array.isArray(outsideIgnore) ? outsideIgnore : [outsideIgnore];
|
|
96
|
+
const onDocClick = (event) => {
|
|
97
|
+
const target = event.target;
|
|
98
|
+
if (target === null) return;
|
|
99
|
+
if (wrapper.contains(target)) return;
|
|
100
|
+
if (ignore.some((el) => el === target || el.contains(target))) return;
|
|
101
|
+
userDismiss();
|
|
102
|
+
};
|
|
103
|
+
document.addEventListener("click", onDocClick, true);
|
|
104
|
+
removers.push(() => document.removeEventListener("click", onDocClick, true));
|
|
105
|
+
}
|
|
106
|
+
if (initialFocus !== false) {
|
|
107
|
+
if (typeof initialFocus === "string") {
|
|
108
|
+
wrapper.querySelector(initialFocus)?.focus();
|
|
109
|
+
} else {
|
|
110
|
+
const first = focusable(wrapper)[0];
|
|
111
|
+
if (first !== void 0) {
|
|
112
|
+
first.focus();
|
|
113
|
+
} else {
|
|
114
|
+
wrapper.tabIndex = -1;
|
|
115
|
+
wrapper.focus();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { el: wrapper, close, result };
|
|
120
|
+
}
|
|
121
|
+
function confirm(message, options = {}) {
|
|
122
|
+
const {
|
|
123
|
+
container,
|
|
124
|
+
className = "kerf-overlay",
|
|
125
|
+
title,
|
|
126
|
+
okText = "OK",
|
|
127
|
+
cancelText = "Cancel",
|
|
128
|
+
danger = false
|
|
129
|
+
} = options;
|
|
130
|
+
const body = jsx("div", {
|
|
131
|
+
class: "kerf-confirm",
|
|
132
|
+
children: [
|
|
133
|
+
title !== void 0 ? jsx("h2", { class: "kerf-confirm__title", children: title }) : "",
|
|
134
|
+
jsx("p", { class: "kerf-confirm__message", children: message }),
|
|
135
|
+
jsx("div", {
|
|
136
|
+
class: "kerf-confirm__actions",
|
|
137
|
+
children: [
|
|
138
|
+
jsx("button", { type: "button", "data-confirm": "cancel", children: cancelText }),
|
|
139
|
+
jsx("button", {
|
|
140
|
+
type: "button",
|
|
141
|
+
"data-confirm": "ok",
|
|
142
|
+
class: "kerf-confirm__ok",
|
|
143
|
+
children: okText
|
|
144
|
+
})
|
|
145
|
+
]
|
|
146
|
+
})
|
|
147
|
+
]
|
|
148
|
+
});
|
|
149
|
+
const handle = overlay(body, {
|
|
150
|
+
container,
|
|
151
|
+
className: danger ? `${className} kerf-confirm--danger` : className,
|
|
152
|
+
dismiss: ["escape", "backdrop"],
|
|
153
|
+
initialFocus: ".kerf-confirm__ok",
|
|
154
|
+
trap: true
|
|
155
|
+
});
|
|
156
|
+
delegate(handle.el, "click", "[data-confirm]", (_event, el) => {
|
|
157
|
+
handle.close(el.getAttribute("data-confirm") === "ok");
|
|
158
|
+
});
|
|
159
|
+
return handle.result.then((value) => value === true);
|
|
160
|
+
}
|
|
161
|
+
function prompt(message, options = {}) {
|
|
162
|
+
const {
|
|
163
|
+
container,
|
|
164
|
+
className = "kerf-overlay",
|
|
165
|
+
title,
|
|
166
|
+
defaultValue = "",
|
|
167
|
+
placeholder,
|
|
168
|
+
inputType = "text",
|
|
169
|
+
okText = "OK",
|
|
170
|
+
cancelText = "Cancel",
|
|
171
|
+
validate
|
|
172
|
+
} = options;
|
|
173
|
+
const body = jsx("div", {
|
|
174
|
+
class: "kerf-prompt",
|
|
175
|
+
children: [
|
|
176
|
+
title !== void 0 ? jsx("h2", { class: "kerf-prompt__title", children: title }) : "",
|
|
177
|
+
jsx("label", { class: "kerf-prompt__message", children: message }),
|
|
178
|
+
jsx("input", {
|
|
179
|
+
class: "kerf-prompt__input",
|
|
180
|
+
type: inputType,
|
|
181
|
+
value: defaultValue,
|
|
182
|
+
...placeholder !== void 0 ? { placeholder } : {},
|
|
183
|
+
"data-prompt-input": ""
|
|
184
|
+
}),
|
|
185
|
+
jsx("p", { class: "kerf-prompt__error", "data-prompt-error": "", children: "" }),
|
|
186
|
+
jsx("div", {
|
|
187
|
+
class: "kerf-prompt__actions",
|
|
188
|
+
children: [
|
|
189
|
+
jsx("button", { type: "button", "data-prompt": "cancel", children: cancelText }),
|
|
190
|
+
jsx("button", {
|
|
191
|
+
type: "button",
|
|
192
|
+
"data-prompt": "ok",
|
|
193
|
+
class: "kerf-prompt__ok",
|
|
194
|
+
children: okText
|
|
195
|
+
})
|
|
196
|
+
]
|
|
197
|
+
})
|
|
198
|
+
]
|
|
199
|
+
});
|
|
200
|
+
const handle = overlay(body, {
|
|
201
|
+
container,
|
|
202
|
+
className,
|
|
203
|
+
dismiss: ["escape", "backdrop"],
|
|
204
|
+
initialFocus: ".kerf-prompt__input",
|
|
205
|
+
trap: true
|
|
206
|
+
});
|
|
207
|
+
const input = handle.el.querySelector("[data-prompt-input]");
|
|
208
|
+
const errorEl = handle.el.querySelector("[data-prompt-error]");
|
|
209
|
+
errorEl.hidden = true;
|
|
210
|
+
function attemptOk() {
|
|
211
|
+
const value = input.value;
|
|
212
|
+
const error = validate?.(value);
|
|
213
|
+
if (typeof error === "string" && error.length > 0) {
|
|
214
|
+
errorEl.textContent = error;
|
|
215
|
+
errorEl.hidden = false;
|
|
216
|
+
input.focus();
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
handle.close(value);
|
|
220
|
+
}
|
|
221
|
+
delegate(handle.el, "click", "[data-prompt]", (_event, el) => {
|
|
222
|
+
if (el.getAttribute("data-prompt") === "ok") attemptOk();
|
|
223
|
+
else handle.close(null);
|
|
224
|
+
});
|
|
225
|
+
handle.el.addEventListener("keydown", (event) => {
|
|
226
|
+
if (event.key === "Enter" && event.target === input) {
|
|
227
|
+
event.preventDefault();
|
|
228
|
+
attemptOk();
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
return handle.result.then((value) => typeof value === "string" ? value : null);
|
|
232
|
+
}
|
|
233
|
+
function form(fields, options = {}) {
|
|
234
|
+
const { container, className = "kerf-overlay", title, okText = "OK", cancelText = "Cancel" } = options;
|
|
235
|
+
const body = jsx("div", {
|
|
236
|
+
class: "kerf-form",
|
|
237
|
+
children: [
|
|
238
|
+
title !== void 0 ? jsx("h2", { class: "kerf-form__title", children: title }) : "",
|
|
239
|
+
...fields.map(
|
|
240
|
+
(field) => jsx("div", {
|
|
241
|
+
class: "kerf-form__field",
|
|
242
|
+
children: [
|
|
243
|
+
jsx("label", { class: "kerf-form__label", children: field.label ?? field.name }),
|
|
244
|
+
jsx("input", {
|
|
245
|
+
class: "kerf-form__input",
|
|
246
|
+
type: field.type ?? "text",
|
|
247
|
+
name: field.name,
|
|
248
|
+
value: field.defaultValue ?? "",
|
|
249
|
+
...field.placeholder !== void 0 ? { placeholder: field.placeholder } : {},
|
|
250
|
+
"data-field": field.name
|
|
251
|
+
}),
|
|
252
|
+
jsx("p", {
|
|
253
|
+
class: "kerf-form__error",
|
|
254
|
+
"data-field-error": field.name,
|
|
255
|
+
children: ""
|
|
256
|
+
})
|
|
257
|
+
]
|
|
258
|
+
})
|
|
259
|
+
),
|
|
260
|
+
jsx("div", {
|
|
261
|
+
class: "kerf-form__actions",
|
|
262
|
+
children: [
|
|
263
|
+
jsx("button", { type: "button", "data-form": "cancel", children: cancelText }),
|
|
264
|
+
jsx("button", {
|
|
265
|
+
type: "button",
|
|
266
|
+
"data-form": "ok",
|
|
267
|
+
class: "kerf-form__ok",
|
|
268
|
+
children: okText
|
|
269
|
+
})
|
|
270
|
+
]
|
|
271
|
+
})
|
|
272
|
+
]
|
|
273
|
+
});
|
|
274
|
+
const handle = overlay(body, {
|
|
275
|
+
container,
|
|
276
|
+
className,
|
|
277
|
+
dismiss: ["escape", "backdrop"],
|
|
278
|
+
initialFocus: ".kerf-form__input",
|
|
279
|
+
trap: true
|
|
280
|
+
});
|
|
281
|
+
const byAttr = (attr, name) => Array.from(handle.el.querySelectorAll(`[${attr}]`)).find(
|
|
282
|
+
(el) => el.getAttribute(attr) === name
|
|
283
|
+
);
|
|
284
|
+
for (const field of fields) {
|
|
285
|
+
byAttr("data-field-error", field.name).hidden = true;
|
|
286
|
+
}
|
|
287
|
+
function attemptOk() {
|
|
288
|
+
const record = {};
|
|
289
|
+
let firstInvalid = null;
|
|
290
|
+
for (const field of fields) {
|
|
291
|
+
const el = byAttr("data-field", field.name);
|
|
292
|
+
const value = el.value;
|
|
293
|
+
record[field.name] = value;
|
|
294
|
+
const error = field.validate?.(value);
|
|
295
|
+
const errorEl = byAttr("data-field-error", field.name);
|
|
296
|
+
if (typeof error === "string" && error.length > 0) {
|
|
297
|
+
errorEl.textContent = error;
|
|
298
|
+
errorEl.hidden = false;
|
|
299
|
+
if (firstInvalid === null) firstInvalid = el;
|
|
300
|
+
} else {
|
|
301
|
+
errorEl.hidden = true;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
if (firstInvalid !== null) {
|
|
305
|
+
firstInvalid.focus();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
handle.close(record);
|
|
309
|
+
}
|
|
310
|
+
delegate(handle.el, "click", "[data-form]", (_event, el) => {
|
|
311
|
+
if (el.getAttribute("data-form") === "ok") attemptOk();
|
|
312
|
+
else handle.close(null);
|
|
313
|
+
});
|
|
314
|
+
handle.el.addEventListener("keydown", (event) => {
|
|
315
|
+
if (event.key === "Enter" && event.target?.matches("[data-field]")) {
|
|
316
|
+
event.preventDefault();
|
|
317
|
+
attemptOk();
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return handle.result.then(
|
|
321
|
+
(value) => value !== null && typeof value === "object" ? value : null
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
function popover(anchor, content, options = {}) {
|
|
325
|
+
const {
|
|
326
|
+
container,
|
|
327
|
+
className = "kerf-popover",
|
|
328
|
+
placement = "bottom",
|
|
329
|
+
align = "start",
|
|
330
|
+
gap = 4,
|
|
331
|
+
dismiss = ["outside"],
|
|
332
|
+
initialFocus = false,
|
|
333
|
+
outsideIgnore,
|
|
334
|
+
onDismiss
|
|
335
|
+
} = options;
|
|
336
|
+
const extraIgnore = outsideIgnore === void 0 ? [] : Array.isArray(outsideIgnore) ? [...outsideIgnore] : [outsideIgnore];
|
|
337
|
+
const handle = overlay(content, {
|
|
338
|
+
container,
|
|
339
|
+
className,
|
|
340
|
+
dismiss,
|
|
341
|
+
trap: false,
|
|
342
|
+
initialFocus,
|
|
343
|
+
onDismiss,
|
|
344
|
+
outsideIgnore: [anchor, ...extraIgnore]
|
|
345
|
+
});
|
|
346
|
+
handle.el.style.position = "fixed";
|
|
347
|
+
handle.el.style.margin = "0";
|
|
348
|
+
const reposition = () => {
|
|
349
|
+
const a = anchor.getBoundingClientRect();
|
|
350
|
+
const p = handle.el.getBoundingClientRect();
|
|
351
|
+
const vw = window.innerWidth;
|
|
352
|
+
const vh = window.innerHeight;
|
|
353
|
+
const belowTop = a.bottom + gap;
|
|
354
|
+
const aboveTop = a.top - gap - p.height;
|
|
355
|
+
let below = placement !== "top";
|
|
356
|
+
if (below && belowTop + p.height > vh && aboveTop >= 0) below = false;
|
|
357
|
+
else if (!below && aboveTop < 0 && belowTop + p.height <= vh) below = true;
|
|
358
|
+
let left = align === "end" ? a.right - p.width : a.left;
|
|
359
|
+
left = Math.max(0, Math.min(left, vw - p.width));
|
|
360
|
+
handle.el.style.left = `${left}px`;
|
|
361
|
+
handle.el.style.top = `${below ? belowTop : aboveTop}px`;
|
|
362
|
+
};
|
|
363
|
+
reposition();
|
|
364
|
+
window.addEventListener("scroll", reposition, true);
|
|
365
|
+
window.addEventListener("resize", reposition);
|
|
366
|
+
void handle.result.then(() => {
|
|
367
|
+
window.removeEventListener("scroll", reposition, true);
|
|
368
|
+
window.removeEventListener("resize", reposition);
|
|
369
|
+
});
|
|
370
|
+
return handle;
|
|
371
|
+
}
|
|
372
|
+
function toastRegion(container) {
|
|
373
|
+
if (container !== void 0) return container;
|
|
374
|
+
const existing = document.querySelector(".kerf-toasts");
|
|
375
|
+
if (existing !== null) return existing;
|
|
376
|
+
const region = document.createElement("div");
|
|
377
|
+
region.className = "kerf-toasts";
|
|
378
|
+
region.setAttribute("aria-live", "polite");
|
|
379
|
+
document.body.appendChild(region);
|
|
380
|
+
return region;
|
|
381
|
+
}
|
|
382
|
+
function toast(content, options = {}) {
|
|
383
|
+
const { container, className = "kerf-toast", duration = 4e3, role = "status" } = options;
|
|
384
|
+
const el = document.createElement("div");
|
|
385
|
+
el.className = className;
|
|
386
|
+
el.setAttribute("role", role);
|
|
387
|
+
toastRegion(container).appendChild(el);
|
|
388
|
+
const disposeMount = mount(el, typeof content === "function" ? content : () => content);
|
|
389
|
+
const state = {
|
|
390
|
+
dismissed: false,
|
|
391
|
+
timer: void 0
|
|
392
|
+
};
|
|
393
|
+
function dismiss() {
|
|
394
|
+
if (state.dismissed) return;
|
|
395
|
+
state.dismissed = true;
|
|
396
|
+
if (state.timer !== void 0) clearTimeout(state.timer);
|
|
397
|
+
disposeMount();
|
|
398
|
+
el.remove();
|
|
399
|
+
}
|
|
400
|
+
if (duration > 0) state.timer = setTimeout(dismiss, duration);
|
|
401
|
+
return dismiss;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export { confirm, form, overlay, popover, prompt, toast };
|
|
405
|
+
//# sourceMappingURL=overlay.js.map
|
|
406
|
+
//# sourceMappingURL=overlay.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/overlay.ts"],"names":[],"mappings":";;;;;;;;;;AAyEA,IAAM,SAAA,GACJ,iLAAA;AAIF,SAAS,UAAU,IAAA,EAA8B;AAC/C,EAAA,OAAO,MAAM,IAAA,CAAK,IAAA,CAAK,gBAAA,CAA8B,SAAS,CAAC,CAAA,CAAE,MAAA;AAAA,IAC/D,CAAC,EAAA,KAAO,CAAC,EAAA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,GAAa,OAAA,GAAU,MAAM,OAAO,CAAA;AACtF,EAAA,MAAM,KAAA,GAAkF;AAAA,IACtF,SAAA,EAAW,KAAA;AAAA,IACX,KAAA,EAAO;AAAA,GACT;AAEA,EAAA,SAAS,OAAA,GAAgB;AACvB,IAAA,IAAI,MAAM,SAAA,EAAW;AACrB,IAAA,KAAA,CAAM,SAAA,GAAY,IAAA;AAClB,IAAA,IAAI,KAAA,CAAM,KAAA,KAAU,MAAA,EAAW,YAAA,CAAa,MAAM,KAAK,CAAA;AACvD,IAAA,YAAA,EAAa;AACb,IAAA,EAAA,CAAG,MAAA,EAAO;AAAA,EACZ;AAEA,EAAA,IAAI,WAAW,CAAA,EAAG,KAAA,CAAM,KAAA,GAAQ,UAAA,CAAW,SAAS,QAAQ,CAAA;AAC5D,EAAA,OAAO,OAAA;AACT","file":"overlay.js","sourcesContent":["/**\n * `kerfjs/overlay` — the modal / overlay + dismiss manager.\n *\n * Every real kerf app hand-rolls this: `toElement → body.appendChild → mount →\n * wire dismissal → remove`, plus the fiddly parts (Escape, backdrop / outside\n * click, focus trap, restoring focus on close). `window.confirm` is a no-op in\n * Tauri WKWebViews, so a hand-built overlay is mandatory there. This subpath\n * blesses the pattern as three functions over `mount()` — `overlay()`, and the\n * `confirm()` / `toast()` conveniences built on it. No per-instance framework\n * state: each call owns its DOM + listeners in a closure and returns a handle.\n *\n * import { overlay, confirm, toast } from 'kerfjs/overlay';\n *\n * const ok = await confirm('Delete this file?', { danger: true });\n * toast('Saved');\n * const dialog = overlay(<Settings />, { dismiss: ['escape', 'backdrop'] });\n * // …later: dialog.close(); or await dialog.result;\n *\n * Structural only — kerf ships no CSS. The wrapper gets your `className`; style\n * the backdrop / centering / animation yourself.\n */\nimport { delegate } from './delegate.js';\nimport { jsx, type SafeHtml } from './jsx-runtime.js';\nimport { mount, type MountResult } from './mount.js';\n\n/** A user-initiated dismissal trigger. */\nexport type DismissTrigger = 'escape' | 'backdrop' | 'outside';\n\n/** Content for an overlay: static `SafeHtml`, or a render function `mount()` drives reactively. */\nexport type OverlayContent = SafeHtml | (() => MountResult);\n\n/** Options for {@link overlay}. */\nexport interface OverlayOptions {\n /** Where to append the overlay wrapper. Default `document.body`. */\n container?: Element;\n /** Class on the wrapper element (you style it — kerf ships no CSS). Default `'kerf-overlay'`. */\n className?: string;\n /**\n * Which user actions dismiss the overlay. Default `['escape', 'backdrop']`.\n * `'backdrop'` = a click on the wrapper itself (not its content); `'outside'`\n * = a click anywhere outside the wrapper (for anchored popovers). `false`\n * disables user dismissal (close it programmatically).\n */\n dismiss?: DismissTrigger | DismissTrigger[] | false;\n /**\n * Where focus lands on open: a selector, `true` (first focusable element, or\n * the wrapper if none), or `false` (leave focus alone). Default `true`.\n */\n initialFocus?: string | boolean;\n /**\n * Trap Tab / Shift+Tab within the overlay while open and mark it\n * `role=\"dialog\"` / `aria-modal=\"true\"`. Default `true`. Set `false` for a\n * non-modal popover.\n */\n trap?: boolean;\n /** ARIA role for the wrapper when `trap` is on. Default `'dialog'`. */\n role?: string;\n /** Called on any user-initiated dismissal (before `close()` runs). */\n onDismiss?: () => void;\n /** For `'outside'` dismissal: clicks on these elements do NOT count as outside (e.g. the trigger button). */\n outsideIgnore?: Element | readonly Element[];\n}\n\n/** Handle returned by {@link overlay}. Holds no framework state — it's a closure. */\nexport interface OverlayHandle {\n /** The wrapper element (mounted into, appended to `container`). */\n el: HTMLElement;\n /** Tear down: dispose the mount, remove listeners + the node, restore focus, resolve `result`. Idempotent. */\n close(result?: unknown): void;\n /** Resolves with the value passed to `close()` (or `undefined` on user dismissal). */\n result: Promise<unknown>;\n}\n\nconst FOCUSABLE =\n 'a[href],area[href],button:not([disabled]),input:not([disabled]),'\n + 'select:not([disabled]),textarea:not([disabled]),iframe,'\n + '[tabindex]:not([tabindex=\"-1\"]),[contenteditable=\"true\"]';\n\nfunction focusable(root: Element): HTMLElement[] {\n return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE)).filter(\n (el) => !el.hasAttribute('hidden'),\n );\n}\n\n/**\n * Open an overlay: append a wrapper to `container`, `mount()` `content` inside\n * it, wire the requested dismissals + (optionally) a focus trap, and return a\n * handle. See {@link OverlayOptions}.\n */\nexport function overlay(content: OverlayContent, options: OverlayOptions = {}): OverlayHandle {\n const {\n container = document.body,\n className = 'kerf-overlay',\n dismiss = ['escape', 'backdrop'],\n initialFocus = true,\n trap = true,\n role = 'dialog',\n onDismiss,\n outsideIgnore,\n } = options;\n\n const triggers: readonly DismissTrigger[] =\n dismiss === false ? [] : Array.isArray(dismiss) ? dismiss : [dismiss];\n const restoreTo = document.activeElement;\n\n const wrapper = document.createElement('div');\n wrapper.className = className;\n if (trap) {\n wrapper.setAttribute('role', role);\n wrapper.setAttribute('aria-modal', 'true');\n }\n container.appendChild(wrapper);\n\n const disposeMount = mount(wrapper, typeof content === 'function' ? content : () => content);\n\n const removers: Array<() => void> = [];\n const resultBox: { resolve?: (value: unknown) => void } = {};\n const result = new Promise<unknown>((resolve) => {\n resultBox.resolve = resolve;\n });\n const state = { closed: false };\n\n function close(value?: unknown): void {\n if (state.closed) return;\n state.closed = true;\n for (const remove of removers) remove();\n disposeMount();\n wrapper.remove();\n if (restoreTo instanceof HTMLElement && restoreTo.isConnected) restoreTo.focus();\n resultBox.resolve?.(value);\n }\n\n function userDismiss(): void {\n onDismiss?.();\n close();\n }\n\n const wantEscape = triggers.includes('escape');\n if (wantEscape || trap) {\n const onKeydown = (event: KeyboardEvent): void => {\n if (wantEscape && event.key === 'Escape') {\n event.stopPropagation();\n userDismiss();\n return;\n }\n if (trap && event.key === 'Tab') {\n const items = focusable(wrapper);\n if (items.length === 0) {\n event.preventDefault();\n return;\n }\n const first = items[0];\n const last = items[items.length - 1];\n const active = document.activeElement;\n const outside = !wrapper.contains(active);\n if (event.shiftKey && (active === first || outside)) {\n event.preventDefault();\n last.focus();\n } else if (!event.shiftKey && (active === last || outside)) {\n event.preventDefault();\n first.focus();\n }\n }\n };\n document.addEventListener('keydown', onKeydown, true);\n removers.push(() => document.removeEventListener('keydown', onKeydown, true));\n }\n\n if (triggers.includes('backdrop')) {\n const onClick = (event: Event): void => {\n if (event.target === wrapper) userDismiss();\n };\n wrapper.addEventListener('click', onClick);\n removers.push(() => wrapper.removeEventListener('click', onClick));\n }\n\n if (triggers.includes('outside')) {\n const ignore = outsideIgnore === undefined\n ? []\n : Array.isArray(outsideIgnore) ? outsideIgnore : [outsideIgnore];\n // Capture phase: the click that opened this overlay already passed\n // document's capture phase, so this never fires for that opening click.\n const onDocClick = (event: Event): void => {\n const target = event.target as Node | null;\n if (target === null) return;\n if (wrapper.contains(target)) return;\n if (ignore.some((el) => el === target || el.contains(target))) return;\n userDismiss();\n };\n document.addEventListener('click', onDocClick, true);\n removers.push(() => document.removeEventListener('click', onDocClick, true));\n }\n\n if (initialFocus !== false) {\n if (typeof initialFocus === 'string') {\n wrapper.querySelector<HTMLElement>(initialFocus)?.focus();\n } else {\n const first = focusable(wrapper)[0];\n if (first !== undefined) {\n first.focus();\n } else {\n wrapper.tabIndex = -1;\n wrapper.focus();\n }\n }\n }\n\n return { el: wrapper, close, result };\n}\n\n/** Options for {@link confirm}. */\nexport interface ConfirmOptions {\n /** Where to append the overlay. Default `document.body`. */\n container?: Element;\n /** Wrapper class. Default `'kerf-overlay'`. */\n className?: string;\n /** Optional heading above the message. */\n title?: string;\n /** Confirm button label. Default `'OK'`. */\n okText?: string;\n /** Cancel button label. Default `'Cancel'`. */\n cancelText?: string;\n /** Add a `kerf-confirm--danger` class to the wrapper for destructive actions. */\n danger?: boolean;\n}\n\n/**\n * A promise-based `window.confirm` replacement (that global is a no-op in Tauri\n * webviews). Renders a two-button dialog and resolves `true` for OK, `false`\n * for Cancel or any dismissal (Escape / backdrop). Message + labels are\n * auto-escaped (rendered through the JSX runtime).\n */\nexport function confirm(message: string, options: ConfirmOptions = {}): Promise<boolean> {\n const {\n container,\n className = 'kerf-overlay',\n title,\n okText = 'OK',\n cancelText = 'Cancel',\n danger = false,\n } = options;\n\n const body: SafeHtml = jsx('div', {\n class: 'kerf-confirm',\n children: [\n title !== undefined ? jsx('h2', { class: 'kerf-confirm__title', children: title }) : '',\n jsx('p', { class: 'kerf-confirm__message', children: message }),\n jsx('div', {\n class: 'kerf-confirm__actions',\n children: [\n jsx('button', { type: 'button', 'data-confirm': 'cancel', children: cancelText }),\n jsx('button', {\n type: 'button',\n 'data-confirm': 'ok',\n class: 'kerf-confirm__ok',\n children: okText,\n }),\n ],\n }),\n ],\n });\n\n const handle = overlay(body, {\n container,\n className: danger ? `${className} kerf-confirm--danger` : className,\n dismiss: ['escape', 'backdrop'],\n initialFocus: '.kerf-confirm__ok',\n trap: true,\n });\n\n delegate(handle.el, 'click', '[data-confirm]', (_event, el) => {\n handle.close(el.getAttribute('data-confirm') === 'ok');\n });\n\n return handle.result.then((value) => value === true);\n}\n\n/**\n * Validate a single field's value. Return a non-empty error string to BLOCK\n * submission (shown inline next to the field); return `undefined`/`null`/`''` to\n * allow it.\n */\nexport type FieldValidator = (value: string) => string | null | undefined | void;\n\n/** Options for {@link prompt}. */\nexport interface PromptOptions {\n /** Where to append the overlay. Default `document.body`. */\n container?: Element;\n /** Wrapper class. Default `'kerf-overlay'`. */\n className?: string;\n /** Optional heading above the message. */\n title?: string;\n /** Pre-filled input value. Default `''`. */\n defaultValue?: string;\n /** Input placeholder. */\n placeholder?: string;\n /** `type` attribute of the input (`'text'`, `'email'`, `'password'`, …). Default `'text'`. */\n inputType?: string;\n /** Confirm button label. Default `'OK'`. */\n okText?: string;\n /** Cancel button label. Default `'Cancel'`. */\n cancelText?: string;\n /** Block OK while this returns an error string; the message shows inline. */\n validate?: FieldValidator;\n}\n\n/**\n * A promise-based `window.prompt` replacement (that global is a no-op in Tauri\n * webviews). Renders a one-field dialog and resolves the entered **string** on OK\n * (an empty string is a valid result) or `null` on Cancel / dismissal. Enter in\n * the input submits. `message`, the default value, and labels are auto-escaped\n * (rendered through the JSX runtime). Optional `validate` blocks OK inline.\n */\nexport function prompt(message: string, options: PromptOptions = {}): Promise<string | null> {\n const {\n container,\n className = 'kerf-overlay',\n title,\n defaultValue = '',\n placeholder,\n inputType = 'text',\n okText = 'OK',\n cancelText = 'Cancel',\n validate,\n } = options;\n\n const body: SafeHtml = jsx('div', {\n class: 'kerf-prompt',\n children: [\n title !== undefined ? jsx('h2', { class: 'kerf-prompt__title', children: title }) : '',\n jsx('label', { class: 'kerf-prompt__message', children: message }),\n jsx('input', {\n class: 'kerf-prompt__input',\n type: inputType,\n value: defaultValue,\n ...(placeholder !== undefined ? { placeholder } : {}),\n 'data-prompt-input': '',\n }),\n jsx('p', { class: 'kerf-prompt__error', 'data-prompt-error': '', children: '' }),\n jsx('div', {\n class: 'kerf-prompt__actions',\n children: [\n jsx('button', { type: 'button', 'data-prompt': 'cancel', children: cancelText }),\n jsx('button', {\n type: 'button',\n 'data-prompt': 'ok',\n class: 'kerf-prompt__ok',\n children: okText,\n }),\n ],\n }),\n ],\n });\n\n const handle = overlay(body, {\n container,\n className,\n dismiss: ['escape', 'backdrop'],\n initialFocus: '.kerf-prompt__input',\n trap: true,\n });\n\n // Both elements are rendered unconditionally into this call's own wrapper, so\n // the queries cannot miss (asserted non-null rather than guarded).\n const input = handle.el.querySelector<HTMLInputElement>('[data-prompt-input]')!;\n const errorEl = handle.el.querySelector<HTMLElement>('[data-prompt-error]')!;\n errorEl.hidden = true;\n\n function attemptOk(): void {\n const value = input.value;\n const error = validate?.(value);\n if (typeof error === 'string' && error.length > 0) {\n errorEl.textContent = error;\n errorEl.hidden = false;\n input.focus();\n return;\n }\n handle.close(value);\n }\n\n delegate(handle.el, 'click', '[data-prompt]', (_event, el) => {\n if (el.getAttribute('data-prompt') === 'ok') attemptOk();\n else handle.close(null);\n });\n\n // Enter in the field submits, like the native prompt.\n handle.el.addEventListener('keydown', (event: KeyboardEvent) => {\n if (event.key === 'Enter' && event.target === input) {\n event.preventDefault();\n attemptOk();\n }\n });\n\n return handle.result.then((value) => (typeof value === 'string' ? value : null));\n}\n\n/** A single field in a {@link form}. */\nexport interface FormField {\n /** Field name — the key in the resolved record (and the input's `name`). */\n name: string;\n /** Label shown above the input. Defaults to `name`. */\n label?: string;\n /** Pre-filled value. Default `''`. */\n defaultValue?: string;\n /** Input placeholder. */\n placeholder?: string;\n /** `type` attribute of the input. Default `'text'`. */\n type?: string;\n /** Block OK while this returns an error string; the message shows inline for this field. */\n validate?: FieldValidator;\n}\n\n/** Options for {@link form}. */\nexport interface FormOptions {\n /** Where to append the overlay. Default `document.body`. */\n container?: Element;\n /** Wrapper class. Default `'kerf-overlay'`. */\n className?: string;\n /** Optional heading above the fields. */\n title?: string;\n /** Confirm button label. Default `'OK'`. */\n okText?: string;\n /** Cancel button label. Default `'Cancel'`. */\n cancelText?: string;\n}\n\n/**\n * A promise-based multi-field dialog — the two-or-three-input sibling of\n * {@link prompt}. Renders one labeled input per {@link FormField} and resolves a\n * `Record<name, value>` on OK (after every field's `validate` passes) or `null`\n * on Cancel / dismissal. Enter in any field submits. All labels, defaults, and\n * the title are auto-escaped through the JSX runtime.\n */\nexport function form(\n fields: readonly FormField[],\n options: FormOptions = {},\n): Promise<Record<string, string> | null> {\n const { container, className = 'kerf-overlay', title, okText = 'OK', cancelText = 'Cancel' } = options;\n\n const body: SafeHtml = jsx('div', {\n class: 'kerf-form',\n children: [\n title !== undefined ? jsx('h2', { class: 'kerf-form__title', children: title }) : '',\n ...fields.map((field) =>\n jsx('div', {\n class: 'kerf-form__field',\n children: [\n jsx('label', { class: 'kerf-form__label', children: field.label ?? field.name }),\n jsx('input', {\n class: 'kerf-form__input',\n type: field.type ?? 'text',\n name: field.name,\n value: field.defaultValue ?? '',\n ...(field.placeholder !== undefined ? { placeholder: field.placeholder } : {}),\n 'data-field': field.name,\n }),\n jsx('p', {\n class: 'kerf-form__error',\n 'data-field-error': field.name,\n children: '',\n }),\n ],\n }),\n ),\n jsx('div', {\n class: 'kerf-form__actions',\n children: [\n jsx('button', { type: 'button', 'data-form': 'cancel', children: cancelText }),\n jsx('button', {\n type: 'button',\n 'data-form': 'ok',\n class: 'kerf-form__ok',\n children: okText,\n }),\n ],\n }),\n ],\n });\n\n const handle = overlay(body, {\n container,\n className,\n dismiss: ['escape', 'backdrop'],\n initialFocus: '.kerf-form__input',\n trap: true,\n });\n\n // Look up a field's input / error node by attribute value (no selector\n // escaping needed — field names are developer-supplied identifiers). Every\n // field renders both nodes into this wrapper, so the lookup cannot miss.\n const byAttr = <E extends HTMLElement>(attr: string, name: string): E =>\n Array.from(handle.el.querySelectorAll<E>(`[${attr}]`)).find(\n (el) => el.getAttribute(attr) === name,\n )!;\n\n // Start with every field's error hidden.\n for (const field of fields) {\n byAttr<HTMLElement>('data-field-error', field.name).hidden = true;\n }\n\n function attemptOk(): void {\n const record: Record<string, string> = {};\n let firstInvalid: HTMLInputElement | null = null;\n for (const field of fields) {\n const el = byAttr<HTMLInputElement>('data-field', field.name);\n const value = el.value;\n record[field.name] = value;\n const error = field.validate?.(value);\n const errorEl = byAttr<HTMLElement>('data-field-error', field.name);\n if (typeof error === 'string' && error.length > 0) {\n errorEl.textContent = error;\n errorEl.hidden = false;\n if (firstInvalid === null) firstInvalid = el;\n } else {\n errorEl.hidden = true;\n }\n }\n if (firstInvalid !== null) {\n firstInvalid.focus();\n return;\n }\n handle.close(record);\n }\n\n delegate(handle.el, 'click', '[data-form]', (_event, el) => {\n if (el.getAttribute('data-form') === 'ok') attemptOk();\n else handle.close(null);\n });\n\n handle.el.addEventListener('keydown', (event: KeyboardEvent) => {\n if (event.key === 'Enter' && (event.target as Element | null)?.matches('[data-field]')) {\n event.preventDefault();\n attemptOk();\n }\n });\n\n return handle.result.then((value) =>\n value !== null && typeof value === 'object' ? (value as Record<string, string>) : null,\n );\n}\n\n/** Vertical placement of a {@link popover} relative to its anchor. */\nexport type PopoverPlacement = 'bottom' | 'top';\n\n/** Options for {@link popover}. */\nexport interface PopoverOptions {\n /** Where to append the popover wrapper. Default `document.body`. */\n container?: Element;\n /** Class on the wrapper. Default `'kerf-popover'`. */\n className?: string;\n /** Preferred side of the anchor. Flips to the other side if it would overflow the viewport. Default `'bottom'`. */\n placement?: PopoverPlacement;\n /** Horizontal edge to line up with the anchor: `'start'` (left edges) or `'end'` (right edges). Default `'start'`. */\n align?: 'start' | 'end';\n /** Gap in px between the anchor and the popover. Default `4`. */\n gap?: number;\n /**\n * Which user actions dismiss the popover. Default `['outside']` (a click\n * outside the popover, the anchor exempt). Pass `false` to close only via `close()`.\n */\n dismiss?: DismissTrigger | DismissTrigger[] | false;\n /** Focus behavior on open. Default `false` (non-modal — leave focus alone). */\n initialFocus?: string | boolean;\n /** Extra elements (besides the anchor) whose clicks do NOT count as outside. */\n outsideIgnore?: Element | readonly Element[];\n /** Called on any user-initiated dismissal. */\n onDismiss?: () => void;\n}\n\n/**\n * Anchored, non-modal overlay: positions `content` relative to `anchor` (below by\n * default, flipping above if it would overflow, and clamped horizontally to the\n * viewport) and repositions on scroll / resize while open. A thin wrapper over\n * {@link overlay} with non-modal defaults — `trap: false`, `dismiss: ['outside']`,\n * and the anchor added to `outsideIgnore` so the trigger click doesn't self-close.\n * Returns the same {@link OverlayHandle}; `close()` also drops the reposition\n * listeners. `position: fixed` is set inline (you style everything else).\n */\nexport function popover(\n anchor: Element,\n content: OverlayContent,\n options: PopoverOptions = {},\n): OverlayHandle {\n const {\n container,\n className = 'kerf-popover',\n placement = 'bottom',\n align = 'start',\n gap = 4,\n dismiss = ['outside'],\n initialFocus = false,\n outsideIgnore,\n onDismiss,\n } = options;\n\n const extraIgnore = outsideIgnore === undefined\n ? []\n : Array.isArray(outsideIgnore) ? [...outsideIgnore] : [outsideIgnore];\n\n const handle = overlay(content, {\n container,\n className,\n dismiss,\n trap: false,\n initialFocus,\n onDismiss,\n outsideIgnore: [anchor, ...extraIgnore],\n });\n\n handle.el.style.position = 'fixed';\n handle.el.style.margin = '0';\n\n const reposition = (): void => {\n const a = anchor.getBoundingClientRect();\n const p = handle.el.getBoundingClientRect();\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n\n // Vertical: preferred side, flipped only if it overflows and the other side fits.\n const belowTop = a.bottom + gap;\n const aboveTop = a.top - gap - p.height;\n let below = placement !== 'top';\n if (below && belowTop + p.height > vh && aboveTop >= 0) below = false;\n else if (!below && aboveTop < 0 && belowTop + p.height <= vh) below = true;\n\n // Horizontal: align to an anchor edge, then clamp into the viewport.\n let left = align === 'end' ? a.right - p.width : a.left;\n left = Math.max(0, Math.min(left, vw - p.width));\n\n handle.el.style.left = `${left}px`;\n handle.el.style.top = `${below ? belowTop : aboveTop}px`;\n };\n\n reposition();\n window.addEventListener('scroll', reposition, true); // capture: catch scrolls in any container\n window.addEventListener('resize', reposition);\n void handle.result.then(() => {\n window.removeEventListener('scroll', reposition, true);\n window.removeEventListener('resize', reposition);\n });\n\n return handle;\n}\n\n/** Content for a {@link toast}: text, `SafeHtml`, or a render function. */\nexport type ToastContent = string | SafeHtml | (() => MountResult);\n\n/** Options for {@link toast}. */\nexport interface ToastOptions {\n /** Where toasts stack. Default: a lazily-created `<div class=\"kerf-toasts\">` on `document.body`. */\n container?: Element;\n /** Class on the toast element. Default `'kerf-toast'`. */\n className?: string;\n /** Auto-dismiss after this many ms. `0` keeps it until dismissed by hand. Default `4000`. */\n duration?: number;\n /** ARIA role. Default `'status'`. */\n role?: string;\n}\n\n/** The singleton toast region lives in the DOM (queried, not held in a module variable). */\nfunction toastRegion(container?: Element): Element {\n if (container !== undefined) return container;\n const existing = document.querySelector('.kerf-toasts');\n if (existing !== null) return existing;\n const region = document.createElement('div');\n region.className = 'kerf-toasts';\n region.setAttribute('aria-live', 'polite');\n document.body.appendChild(region);\n return region;\n}\n\n/**\n * Show a non-modal, auto-dismissing notification. Stacks in a shared body-level\n * region (or your `container`). Returns a `() => void` that dismisses it early.\n */\nexport function toast(content: ToastContent, options: ToastOptions = {}): () => void {\n const { container, className = 'kerf-toast', duration = 4000, role = 'status' } = options;\n\n const el = document.createElement('div');\n el.className = className;\n el.setAttribute('role', role);\n toastRegion(container).appendChild(el);\n\n const disposeMount = mount(el, typeof content === 'function' ? content : () => content);\n const state: { dismissed: boolean; timer: ReturnType<typeof setTimeout> | undefined } = {\n dismissed: false,\n timer: undefined,\n };\n\n function dismiss(): void {\n if (state.dismissed) return;\n state.dismissed = true;\n if (state.timer !== undefined) clearTimeout(state.timer);\n disposeMount();\n el.remove();\n }\n\n if (duration > 0) state.timer = setTimeout(dismiss, duration);\n return dismiss;\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { M as MountResult } from './mount-Bo2qOx25.js';
|
|
2
|
+
import { ReadonlySignal } from '@preact/signals-core';
|
|
3
|
+
import './jsx-runtime.js';
|
|
4
|
+
import './bindings-CYwoJpQb.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `kerfjs/remount` — force a subtree to be REPLACED, not morphed, when a key changes.
|
|
8
|
+
*
|
|
9
|
+
* kerf morphs by default, which is almost always right. The exception is a
|
|
10
|
+
* library-owned subtree (a highlighted diff, a chart, an editor) that must be
|
|
11
|
+
* torn down and rebuilt on fresh DOM when its identity changes — so the library
|
|
12
|
+
* re-initializes instead of the morph patching stale internals underneath it.
|
|
13
|
+
* The folk pattern is a monotonic counter spent as `data-key={`gen-${n}`}` on a
|
|
14
|
+
* `data-morph-skip` div; `remountOn` names that pattern.
|
|
15
|
+
*
|
|
16
|
+
* import { remountOn } from 'kerfjs/remount';
|
|
17
|
+
*
|
|
18
|
+
* // Replace the diff pane whenever the file (or diff mode) changes:
|
|
19
|
+
* const stop = remountOn(paneEl, () => fileId.value, () => <DiffView id={fileId.value} />);
|
|
20
|
+
* // same key -> the subtree is left entirely alone
|
|
21
|
+
* // key change -> old subtree + its mounts disposed, a fresh one mounted
|
|
22
|
+
*
|
|
23
|
+
* `remountOn` owns `parent`'s children (like `mount()` / `bindList`). It returns
|
|
24
|
+
* a disposer that tears down the current subtree and stops watching the key.
|
|
25
|
+
* Pairs with `kerfjs/imperative`: put the widget's setup/teardown on the fresh
|
|
26
|
+
* node, and `remountOn` drives its re-creation.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/** The key that drives a {@link remountOn}: a signal, or a thunk that reads signals. */
|
|
30
|
+
type RemountKey<K> = ReadonlySignal<K> | (() => K);
|
|
31
|
+
/** Options for {@link remountOn}. */
|
|
32
|
+
interface RemountOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Called after each (re)mount with `parent` — the live, freshly-rendered
|
|
35
|
+
* subtree. This is where you bind a widget to the new DOM (e.g.
|
|
36
|
+
* `imperative(parent.querySelector('.host'), setup)` from `kerfjs/imperative`),
|
|
37
|
+
* because `render` returns a string and has no live node yet. May return a
|
|
38
|
+
* cleanup `() => void` that runs before the NEXT remount and on dispose — return
|
|
39
|
+
* the disposer from `imperative()` here for synchronous teardown.
|
|
40
|
+
*/
|
|
41
|
+
onMount?: (root: HTMLElement) => (() => void) | void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Watch `key` and, whenever it changes (by `Object.is`), dispose the current
|
|
45
|
+
* subtree + its mounts and render a fresh one into `parent` via `mount(render)`.
|
|
46
|
+
* An unchanged key leaves the subtree untouched. `options.onMount(parent)` runs
|
|
47
|
+
* after each (re)mount to bind widgets to the fresh DOM. Returns a disposer that
|
|
48
|
+
* tears down the current subtree and stops watching.
|
|
49
|
+
*/
|
|
50
|
+
declare function remountOn<K>(parent: HTMLElement, key: RemountKey<K>, render: () => MountResult, options?: RemountOptions): () => void;
|
|
51
|
+
|
|
52
|
+
export { type RemountKey, type RemountOptions, remountOn };
|
package/dist/remount.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mount } from './chunk-4MY2656S.js';
|
|
2
|
+
import './chunk-QIP723L4.js';
|
|
3
|
+
import './chunk-YHH7OUFA.js';
|
|
4
|
+
import './chunk-FSAQR6IU.js';
|
|
5
|
+
import { effect } from './chunk-3APBEVHF.js';
|
|
6
|
+
import './chunk-GY4XV2UV.js';
|
|
7
|
+
import './chunk-VVDJLWMP.js';
|
|
8
|
+
|
|
9
|
+
// src/remount.ts
|
|
10
|
+
var UNSET = /* @__PURE__ */ Symbol("kerf.remount.unset");
|
|
11
|
+
function remountOn(parent, key, render, options = {}) {
|
|
12
|
+
const { onMount } = options;
|
|
13
|
+
const readKey = typeof key === "function" ? key : () => key.value;
|
|
14
|
+
let currentKey = UNSET;
|
|
15
|
+
let disposeMount;
|
|
16
|
+
let onMountCleanup;
|
|
17
|
+
function tearDown() {
|
|
18
|
+
if (onMountCleanup !== void 0) {
|
|
19
|
+
onMountCleanup();
|
|
20
|
+
onMountCleanup = void 0;
|
|
21
|
+
}
|
|
22
|
+
if (disposeMount !== void 0) {
|
|
23
|
+
disposeMount();
|
|
24
|
+
disposeMount = void 0;
|
|
25
|
+
}
|
|
26
|
+
parent.replaceChildren();
|
|
27
|
+
}
|
|
28
|
+
const stopWatch = effect(() => {
|
|
29
|
+
const next = readKey();
|
|
30
|
+
if (!Object.is(next, currentKey)) {
|
|
31
|
+
currentKey = next;
|
|
32
|
+
tearDown();
|
|
33
|
+
disposeMount = mount(parent, render);
|
|
34
|
+
onMountCleanup = onMount?.(parent) ?? void 0;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
stopWatch();
|
|
39
|
+
tearDown();
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { remountOn };
|
|
44
|
+
//# sourceMappingURL=remount.js.map
|
|
45
|
+
//# sourceMappingURL=remount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/remount.ts"],"names":[],"mappings":";;;;;;;;;AA0CA,IAAM,KAAA,0BAAe,oBAAoB,CAAA;AASlC,SAAS,UACd,MAAA,EACA,GAAA,EACA,MAAA,EACA,OAAA,GAA0B,EAAC,EACf;AACZ,EAAA,MAAM,EAAE,SAAQ,GAAI,OAAA;AACpB,EAAA,MAAM,UAAU,OAAO,GAAA,KAAQ,UAAA,GAAa,GAAA,GAAM,MAAS,GAAA,CAAI,KAAA;AAC/D,EAAA,IAAI,UAAA,GAA+B,KAAA;AACnC,EAAA,IAAI,YAAA;AACJ,EAAA,IAAI,cAAA;AAEJ,EAAA,SAAS,QAAA,GAAiB;AAIxB,IAAA,IAAI,mBAAmB,MAAA,EAAW;AAChC,MAAA,cAAA,EAAe;AACf,MAAA,cAAA,GAAiB,MAAA;AAAA,IACnB;AACA,IAAA,IAAI,iBAAiB,MAAA,EAAW;AAC9B,MAAA,YAAA,EAAa;AACb,MAAA,YAAA,GAAe,MAAA;AAAA,IACjB;AAGA,IAAA,MAAA,CAAO,eAAA,EAAgB;AAAA,EACzB;AAKA,EAAA,MAAM,SAAA,GAAY,OAAO,MAAM;AAC7B,IAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,IAAA,IAAI,CAAC,MAAA,CAAO,EAAA,CAAG,IAAA,EAAM,UAAU,CAAA,EAAG;AAChC,MAAA,UAAA,GAAa,IAAA;AACb,MAAA,QAAA,EAAS;AACT,MAAA,YAAA,GAAe,KAAA,CAAM,QAAQ,MAAM,CAAA;AACnC,MAAA,cAAA,GAAiB,OAAA,GAAU,MAAM,CAAA,IAAK,MAAA;AAAA,IACxC;AAAA,EACF,CAAC,CAAA;AAED,EAAA,OAAO,MAAM;AACX,IAAA,SAAA,EAAU;AACV,IAAA,QAAA,EAAS;AAAA,EACX,CAAA;AACF","file":"remount.js","sourcesContent":["/**\n * `kerfjs/remount` — force a subtree to be REPLACED, not morphed, when a key changes.\n *\n * kerf morphs by default, which is almost always right. The exception is a\n * library-owned subtree (a highlighted diff, a chart, an editor) that must be\n * torn down and rebuilt on fresh DOM when its identity changes — so the library\n * re-initializes instead of the morph patching stale internals underneath it.\n * The folk pattern is a monotonic counter spent as `data-key={`gen-${n}`}` on a\n * `data-morph-skip` div; `remountOn` names that pattern.\n *\n * import { remountOn } from 'kerfjs/remount';\n *\n * // Replace the diff pane whenever the file (or diff mode) changes:\n * const stop = remountOn(paneEl, () => fileId.value, () => <DiffView id={fileId.value} />);\n * // same key -> the subtree is left entirely alone\n * // key change -> old subtree + its mounts disposed, a fresh one mounted\n *\n * `remountOn` owns `parent`'s children (like `mount()` / `bindList`). It returns\n * a disposer that tears down the current subtree and stops watching the key.\n * Pairs with `kerfjs/imperative`: put the widget's setup/teardown on the fresh\n * node, and `remountOn` drives its re-creation.\n */\nimport { mount, type MountResult } from './mount.js';\nimport { effect, type ReadonlySignal } from './reactive.js';\n\n/** The key that drives a {@link remountOn}: a signal, or a thunk that reads signals. */\nexport type RemountKey<K> = ReadonlySignal<K> | (() => K);\n\n/** Options for {@link remountOn}. */\nexport interface RemountOptions {\n /**\n * Called after each (re)mount with `parent` — the live, freshly-rendered\n * subtree. This is where you bind a widget to the new DOM (e.g.\n * `imperative(parent.querySelector('.host'), setup)` from `kerfjs/imperative`),\n * because `render` returns a string and has no live node yet. May return a\n * cleanup `() => void` that runs before the NEXT remount and on dispose — return\n * the disposer from `imperative()` here for synchronous teardown.\n */\n onMount?: (root: HTMLElement) => (() => void) | void;\n}\n\n/** Distinguishes \"no key seen yet\" from any real key (including `undefined`). */\nconst UNSET = Symbol('kerf.remount.unset');\n\n/**\n * Watch `key` and, whenever it changes (by `Object.is`), dispose the current\n * subtree + its mounts and render a fresh one into `parent` via `mount(render)`.\n * An unchanged key leaves the subtree untouched. `options.onMount(parent)` runs\n * after each (re)mount to bind widgets to the fresh DOM. Returns a disposer that\n * tears down the current subtree and stops watching.\n */\nexport function remountOn<K>(\n parent: HTMLElement,\n key: RemountKey<K>,\n render: () => MountResult,\n options: RemountOptions = {},\n): () => void {\n const { onMount } = options;\n const readKey = typeof key === 'function' ? key : (): K => key.value;\n let currentKey: K | typeof UNSET = UNSET;\n let disposeMount: (() => void) | undefined;\n let onMountCleanup: (() => void) | undefined;\n\n function tearDown(): void {\n // Run the onMount cleanup BEFORE tearing down the DOM, so a synchronous\n // teardown (e.g. an imperative() disposer returned from onMount) fires while\n // its node is still attached.\n if (onMountCleanup !== undefined) {\n onMountCleanup();\n onMountCleanup = undefined;\n }\n if (disposeMount !== undefined) {\n disposeMount();\n disposeMount = undefined;\n }\n // Owning parent's children: clear whatever the old mount left so widgets\n // under it see a real removal (their MutationObserver teardown fires).\n parent.replaceChildren();\n }\n\n // The outer effect tracks ONLY the key. `mount()` starts its own independent\n // effect for `render`, so render's signal reads attach there, not here — the\n // key is the sole dependency that triggers a remount.\n const stopWatch = effect(() => {\n const next = readKey();\n if (!Object.is(next, currentKey)) {\n currentKey = next;\n tearDown();\n disposeMount = mount(parent, render);\n onMountCleanup = onMount?.(parent) ?? undefined;\n }\n });\n\n return () => {\n stopWatch();\n tearDown();\n };\n}\n"]}
|