@pure-ds/core 0.7.50 → 0.7.51

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.
@@ -1,480 +1,25 @@
1
- // src/js/common/common.js
2
- function fragmentFromTemplateLike(templateLike) {
3
- const strings = Array.isArray(templateLike?.strings) ? templateLike.strings : [];
4
- const values = Array.isArray(templateLike?.values) ? templateLike.values : [];
5
- const consumedValues = /* @__PURE__ */ new Set();
6
- const htmlParts = [];
7
- const propBindingPattern = /(\s)(\.[\w-]+)=\s*$/;
8
- for (let i = 0; i < strings.length; i += 1) {
9
- let chunk = strings[i] ?? "";
10
- const match = chunk.match(propBindingPattern);
11
- if (match && i < values.length) {
12
- const propToken = match[2];
13
- const propName = propToken.slice(1);
14
- const marker = `pds-val-${i}`;
15
- chunk = chunk.replace(
16
- propBindingPattern,
17
- `$1data-pds-prop="${propName}:${marker}"`
18
- );
19
- consumedValues.add(i);
20
- }
21
- htmlParts.push(chunk);
22
- if (i < values.length && !consumedValues.has(i)) {
23
- htmlParts.push(`<!--pds-val-${i}-->`);
24
- }
25
- }
26
- const tpl = document.createElement("template");
27
- tpl.innerHTML = htmlParts.join("");
28
- const replaceValueAtMarker = (markerNode, value) => {
29
- const parent = markerNode.parentNode;
30
- if (!parent)
31
- return;
32
- if (value == null) {
33
- parent.removeChild(markerNode);
34
- return;
35
- }
36
- const insertValue = (val) => {
37
- if (val == null)
38
- return;
39
- if (val instanceof Node) {
40
- parent.insertBefore(val, markerNode);
41
- return;
42
- }
43
- if (Array.isArray(val)) {
44
- val.forEach((item) => insertValue(item));
45
- return;
46
- }
47
- parent.insertBefore(document.createTextNode(String(val)), markerNode);
48
- };
49
- insertValue(value);
50
- parent.removeChild(markerNode);
51
- };
52
- const walker = document.createTreeWalker(tpl.content, NodeFilter.SHOW_COMMENT);
53
- const markers = [];
54
- while (walker.nextNode()) {
55
- const node = walker.currentNode;
56
- if (node?.nodeValue?.startsWith("pds-val-")) {
57
- markers.push(node);
58
- }
59
- }
60
- markers.forEach((node) => {
61
- const index = Number(node.nodeValue.replace("pds-val-", ""));
62
- replaceValueAtMarker(node, values[index]);
63
- });
64
- const elements = tpl.content.querySelectorAll("*");
65
- elements.forEach((el) => {
66
- const propAttr = el.getAttribute("data-pds-prop");
67
- if (!propAttr)
68
- return;
69
- const [propName, markerValue] = propAttr.split(":");
70
- const index = Number(String(markerValue).replace("pds-val-", ""));
71
- if (propName && Number.isInteger(index)) {
72
- el[propName] = values[index];
73
- }
74
- el.removeAttribute("data-pds-prop");
75
- });
76
- return tpl.content;
77
- }
78
-
79
- // src/js/pds-singleton.js
80
- var PDSBase = class extends EventTarget {
81
- constructor() {
82
- super();
83
- this.mode = null;
84
- this.compiled = null;
85
- this.log = () => {
86
- };
87
- this.logHandler = null;
88
- }
89
- };
90
- var PDS_SINGLETON_KEY = "__PURE_DS_PDS_SINGLETON__";
91
- var globalScope = typeof globalThis !== "undefined" ? globalThis : window;
92
- var existingPDS = globalScope?.[PDS_SINGLETON_KEY];
93
- var PDS = existingPDS && typeof existingPDS.addEventListener === "function" ? existingPDS : new PDSBase();
94
- if (globalScope) {
95
- globalScope[PDS_SINGLETON_KEY] = PDS;
96
- }
97
- if (typeof PDS.log !== "function") {
98
- PDS.log = (level = "log", message, ...data) => {
99
- if (typeof console === "undefined")
100
- return;
101
- const method = typeof console[level] === "function" ? console[level].bind(console) : typeof console.log === "function" ? console.log.bind(console) : null;
102
- if (!method)
103
- return;
104
- if (data.length > 0) {
105
- method(message, ...data);
106
- } else {
107
- method(message);
108
- }
109
- };
110
- }
111
- if (typeof PDS.logHandler !== "function") {
112
- PDS.logHandler = null;
113
- }
114
-
115
- // src/js/common/ask.js
116
- function appendMessageContent(container, message) {
117
- if (message == null)
118
- return;
119
- if (typeof message === "object" && Array.isArray(message.strings) && Array.isArray(message.values)) {
120
- container.appendChild(fragmentFromTemplateLike(message));
121
- return;
122
- }
123
- if (message instanceof Node) {
124
- container.appendChild(message);
125
- return;
126
- }
127
- if (Array.isArray(message)) {
128
- message.forEach((item) => appendMessageContent(container, item));
129
- return;
130
- }
131
- const text = typeof message === "string" ? message : String(message);
132
- container.appendChild(document.createTextNode(text));
133
- }
134
- function validateDialogFormTree(form) {
135
- if (!form)
136
- return true;
137
- let valid = true;
138
- const describeElement = (el) => {
139
- if (!el || typeof el !== "object")
140
- return "<unknown>";
141
- const tag = el.tagName ? String(el.tagName).toLowerCase() : "node";
142
- const id = el.id ? `#${el.id}` : "";
143
- const name = typeof el.getAttribute === "function" ? el.getAttribute("name") : null;
144
- const namePart = name ? `[name="${name}"]` : "";
145
- return `${tag}${id}${namePart}`;
146
- };
147
- const reportInvalidControls = (root, scopeLabel) => {
148
- if (!root || typeof root.querySelectorAll !== "function")
149
- return;
150
- const invalidControls = Array.from(root.querySelectorAll(":invalid"));
151
- if (!invalidControls.length)
152
- return;
153
- const list = invalidControls.map((el) => {
154
- const message = typeof el.validationMessage === "string" ? el.validationMessage : "";
155
- return `${describeElement(el)}${message ? ` \u2014 ${message}` : ""}`;
156
- });
157
- PDS.log("warn", `ask.validateDialogFormTree: invalid controls in ${scopeLabel}:`, list);
158
- };
159
- const runValidity = (target, scopeLabel) => {
160
- try {
161
- const targetValid = typeof target.reportValidity === "function" ? target.reportValidity() : target.checkValidity?.() ?? true;
162
- if (!targetValid) {
163
- reportInvalidControls(target, scopeLabel);
164
- }
165
- return targetValid;
166
- } catch (error) {
167
- PDS.log("error", `ask.validateDialogFormTree: validation threw in ${scopeLabel}`, error);
168
- return false;
169
- }
170
- };
171
- valid = runValidity(form, "host dialog form") && valid;
172
- const nestedLightDomForms = Array.from(form.querySelectorAll("form"));
173
- for (const nestedForm of nestedLightDomForms) {
174
- if (nestedForm === form)
175
- continue;
176
- const nestedValid = runValidity(nestedForm, `nested light DOM form ${describeElement(nestedForm)}`);
177
- valid = nestedValid && valid;
178
- }
179
- const descendants = Array.from(form.querySelectorAll("*"));
180
- for (const host of descendants) {
181
- const root = host?.shadowRoot;
182
- if (!root)
183
- continue;
184
- const nestedForms = Array.from(root.querySelectorAll("form"));
185
- for (const nestedForm of nestedForms) {
186
- const nestedValid = runValidity(
187
- nestedForm,
188
- `shadow form under ${describeElement(host)}`
189
- );
190
- valid = nestedValid && valid;
191
- }
192
- }
193
- return valid;
194
- }
195
- function isSafariBrowser() {
196
- const userAgent = navigator.userAgent;
197
- const isSafariEngine = /Safari/i.test(userAgent);
198
- const isOtherBrowser = /(Chrome|Chromium|CriOS|FxiOS|EdgiOS|OPiOS|Opera)/i.test(userAgent);
199
- return isSafariEngine && !isOtherBrowser;
200
- }
201
- function playDialogEnterAnimation(dialog) {
202
- if (window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) {
203
- return;
204
- }
205
- const isMobile = window.matchMedia?.("(max-width: 639px)").matches;
206
- const animationName = dialog.classList.contains("dialog-no-scale-animation") ? "pds-dialog-fade-enter" : isMobile ? "pds-dialog-enter-mobile" : "pds-dialog-enter";
207
- dialog.style.animation = "none";
208
- void dialog.offsetWidth;
209
- dialog.style.animation = `${animationName} var(--transition-normal) ease`;
210
- dialog.addEventListener("animationend", () => {
211
- dialog.style.animation = "";
212
- }, { once: true });
213
- }
214
- function shouldUseLiquidGlass(options = {}) {
215
- return options?.liquidGlassEffects === true;
216
- }
217
- async function ask(message, options = {}) {
218
- const defaults = {
219
- title: "Confirm",
220
- type: "confirm",
221
- // 'alert', 'confirm', 'custom'
222
- buttons: {
223
- ok: { name: "OK", primary: true },
224
- cancel: { name: "Cancel", cancel: true }
225
- }
226
- };
227
- options = { ...defaults, ...options };
228
- const buttonConfigs = options.buttons && typeof options.buttons === "object" ? options.buttons : defaults.buttons;
229
- const resolveActionMeta = (actionCode) => {
230
- if (actionCode == null) {
231
- return {
232
- actionCode: "dismiss",
233
- actionKind: "dismiss",
234
- button: null
235
- };
236
- }
237
- const button = buttonConfigs?.[actionCode] ?? null;
238
- const actionKind = actionCode === "ok" ? "ok" : actionCode === "dismiss" ? "dismiss" : button?.cancel || actionCode === "cancel" ? "cancel" : "custom";
239
- return {
240
- actionCode,
241
- actionKind,
242
- button
243
- };
244
- };
245
- const normalizeBeforeCloseResult = (result) => {
246
- if (typeof result === "undefined" || result === null || result === true) {
247
- return { allow: true };
248
- }
249
- if (result === false) {
250
- return { allow: false };
251
- }
252
- if (typeof result === "object") {
253
- const hasResult = Object.prototype.hasOwnProperty.call(result, "result") || Object.prototype.hasOwnProperty.call(result, "value");
254
- return {
255
- allow: result.allow !== false,
256
- hasResult,
257
- result: Object.prototype.hasOwnProperty.call(result, "result") ? result.result : result.value
258
- };
259
- }
260
- return { allow: Boolean(result) };
261
- };
262
- return new Promise((resolve) => {
263
- let settled = false;
264
- const settle = (value, dialog2, { shouldClose = true } = {}) => {
265
- if (settled)
266
- return;
267
- settled = true;
268
- resolve(value);
269
- if (!shouldClose || !dialog2?.open) {
270
- return;
271
- }
272
- try {
273
- dialog2.close();
274
- } catch (error) {
275
- PDS.log("warn", "ask: dialog.close() failed", error);
276
- }
277
- };
278
- const runBeforeClose = async (context) => {
279
- if (context.actionKind !== "ok" || typeof options.beforeClose !== "function") {
280
- return { allow: true };
281
- }
282
- try {
283
- const beforeCloseResult = await options.beforeClose(context);
284
- return normalizeBeforeCloseResult(beforeCloseResult);
285
- } catch (error) {
286
- PDS.log("error", "ask.beforeClose: validation failed", error);
287
- return { allow: false };
288
- }
289
- };
290
- const resolveDefaultResult = ({ actionKind, form }) => {
291
- if (actionKind === "ok") {
292
- if (options.useForm && form) {
293
- return new FormData(form);
294
- }
295
- return true;
296
- }
297
- return false;
298
- };
299
- const attemptResolve = async ({
300
- actionCode,
301
- form,
302
- submitter,
303
- originalEvent,
304
- bypassValidation = false,
305
- shouldClose = true
306
- }) => {
307
- if (settled)
308
- return;
309
- const { actionKind, button } = resolveActionMeta(actionCode);
310
- const activeForm = form || dialog.querySelector("form") || null;
311
- if (options.useForm && actionKind === "ok" && activeForm && !bypassValidation) {
312
- const valid = validateDialogFormTree(activeForm);
313
- if (!valid) {
314
- return;
315
- }
316
- }
317
- const defaultResult = resolveDefaultResult({
318
- actionKind,
319
- form: activeForm
320
- });
321
- const guard = await runBeforeClose({
322
- actionCode,
323
- actionKind,
324
- dialog,
325
- form: activeForm,
326
- formData: options.useForm && actionKind === "ok" && activeForm ? defaultResult : null,
327
- submitter,
328
- originalEvent,
329
- options,
330
- button,
331
- defaultResult
332
- });
333
- if (!guard.allow) {
334
- return;
335
- }
336
- const result = guard.hasResult ? guard.result : defaultResult;
337
- settle(result, dialog, { shouldClose });
338
- };
339
- const dialog = document.createElement("dialog");
340
- if (isSafariBrowser()) {
341
- dialog.classList.add("dialog-no-scale-animation");
342
- }
343
- if (shouldUseLiquidGlass(options))
344
- dialog.classList.add("liquid-glass");
345
- if (options.size) {
346
- dialog.classList.add(`dialog-${options.size}`);
347
- }
348
- if (options.type) {
349
- dialog.classList.add(`dialog-${options.type}`);
350
- }
351
- if (options.class) {
352
- if (Array.isArray(options.class)) {
353
- dialog.classList.add(...options.class);
354
- } else {
355
- dialog.classList.add(options.class);
356
- }
357
- }
358
- if (options.maxHeight) {
359
- dialog.style.setProperty("--dialog-max-height", options.maxHeight);
360
- }
361
- const buttons = Object.entries(buttonConfigs).map(([code, obj]) => {
362
- const btnClass = obj.primary ? "btn-primary btn-sm" : "btn-outline btn-sm";
363
- const btnType = obj.cancel ? "button" : "submit";
364
- const formNoValidate = obj.formNoValidate ? " formnovalidate" : "";
365
- return `<button type="${btnType}" class="${btnClass}" value="${code}"${formNoValidate}>${obj.name}</button>`;
366
- });
367
- if (options.useForm) {
368
- const tempContainer = document.createElement("div");
369
- appendMessageContent(tempContainer, message);
370
- const form = tempContainer.querySelector("form");
371
- if (form) {
372
- dialog.innerHTML = /*html*/
373
- `
1
+ function M(i){let e=Array.isArray(i?.strings)?i.strings:[],u=Array.isArray(i?.values)?i.values:[],m=new Set,A=[],$=/(\s)(\.[\w-]+)=\s*$/,s=/(\s)(@[\w-]+)=\s*$/,o=/(\s)(\?[\w-]+)=\s*$/,d=/(\s)([\w:-]+)=\s*$/;for(let r=0;r<e.length;r+=1){let t=e[r]??"";if(r<u.length){let n=`pds-val-${r}`,c=t.match($),l=t.match(s),p=t.match(o),w=t.match(d);if(c){let y=c[2].slice(1);t=t.replace($,`$1data-pds-bind-${r}="prop:${y}:${n}"`),m.add(r)}else if(l){let y=l[2].slice(1);t=t.replace(s,`$1data-pds-bind-${r}="event:${y}:${n}"`),m.add(r)}else if(p){let y=p[2].slice(1);t=t.replace(o,`$1data-pds-bind-${r}="boolean:${y}:${n}"`),m.add(r)}else if(w){let y=w[2];t=t.replace(d,`$1data-pds-bind-${r}="attr:${y}:${n}"`),m.add(r)}}A.push(t),r<u.length&&!m.has(r)&&A.push(`<!--pds-val-${r}-->`)}let f=document.createElement("template");f.innerHTML=A.join("");let g=(r,t)=>{let n=r.parentNode;if(!n)return;if(t==null){n.removeChild(r);return}let c=l=>{if(l!=null){if(l instanceof Node){n.insertBefore(l,r);return}if(Array.isArray(l)){l.forEach(p=>c(p));return}n.insertBefore(document.createTextNode(String(l)),r)}};c(t),n.removeChild(r)},h=document.createTreeWalker(f.content,NodeFilter.SHOW_COMMENT),a=[];for(;h.nextNode();){let r=h.currentNode;r?.nodeValue?.startsWith("pds-val-")&&a.push(r)}return a.forEach(r=>{let t=Number(r.nodeValue.replace("pds-val-",""));g(r,u[t])}),f.content.querySelectorAll("*").forEach(r=>{[...r.attributes].forEach(t=>{if(!t.name.startsWith("data-pds-bind-"))return;let n=t.value.indexOf(":"),c=t.value.lastIndexOf(":");if(n<=0||c<=n){r.removeAttribute(t.name);return}let l=t.value.slice(0,n),p=t.value.slice(n+1,c),w=t.value.slice(c+1),y=Number(String(w).replace("pds-val-","")),b=u[y];if(!p||!Number.isInteger(y)){r.removeAttribute(t.name);return}l==="prop"?r[p]=b:l==="event"?(typeof b=="function"||b&&typeof b.handleEvent=="function")&&r.addEventListener(p,b):l==="boolean"?b?r.setAttribute(p,""):r.removeAttribute(p):l==="attr"&&(b==null||b===!1?r.removeAttribute(p):r.setAttribute(p,String(b))),r.removeAttribute(t.name)})}),f.content}var T=class extends EventTarget{constructor(){super(),this.mode=null,this.compiled=null,this.log=()=>{},this.logHandler=null}},F="__PURE_DS_PDS_SINGLETON__",N=typeof globalThis<"u"?globalThis:window,x=N?.[F],v=x&&typeof x.addEventListener=="function"?x:new T;N&&(N[F]=v);typeof v.log!="function"&&(v.log=(i="log",e,...u)=>{if(typeof console>"u")return;let m=typeof console[i]=="function"?console[i].bind(console):typeof console.log=="function"?console.log.bind(console):null;m&&(u.length>0?m(e,...u):m(e))});typeof v.logHandler!="function"&&(v.logHandler=null);function L(i,e){if(e==null)return;if(typeof e=="object"&&Array.isArray(e.strings)&&Array.isArray(e.values)){i.appendChild(M(e));return}if(e instanceof Node){i.appendChild(e);return}if(Array.isArray(e)){e.forEach(m=>L(i,m));return}let u=typeof e=="string"?e:String(e);i.appendChild(document.createTextNode(u))}function P(i){if(!i)return!0;let e=!0,u=o=>{if(!o||typeof o!="object")return"<unknown>";let d=o.tagName?String(o.tagName).toLowerCase():"node",f=o.id?`#${o.id}`:"",g=typeof o.getAttribute=="function"?o.getAttribute("name"):null,h=g?`[name="${g}"]`:"";return`${d}${f}${h}`},m=(o,d)=>{if(!o||typeof o.querySelectorAll!="function")return;let f=Array.from(o.querySelectorAll(":invalid"));if(!f.length)return;let g=f.map(h=>{let a=typeof h.validationMessage=="string"?h.validationMessage:"";return`${u(h)}${a?` \u2014 ${a}`:""}`});v.log("warn",`ask.validateDialogFormTree: invalid controls in ${d}:`,g)},A=(o,d)=>{try{let f=typeof o.reportValidity=="function"?o.reportValidity():o.checkValidity?.()??!0;return f||m(o,d),f}catch(f){return v.log("error",`ask.validateDialogFormTree: validation threw in ${d}`,f),!1}};e=A(i,"host dialog form")&&e;let $=Array.from(i.querySelectorAll("form"));for(let o of $){if(o===i)continue;e=A(o,`nested light DOM form ${u(o)}`)&&e}let s=Array.from(i.querySelectorAll("*"));for(let o of s){let d=o?.shadowRoot;if(!d)continue;let f=Array.from(d.querySelectorAll("form"));for(let g of f)e=A(g,`shadow form under ${u(o)}`)&&e}return e}function V(){let i=navigator.userAgent,e=/Safari/i.test(i),u=/(Chrome|Chromium|CriOS|FxiOS|EdgiOS|OPiOS|Opera)/i.test(i);return e&&!u}function k(i){if(window.matchMedia?.("(prefers-reduced-motion: reduce)").matches)return;let e=window.matchMedia?.("(max-width: 639px)").matches,u=i.classList.contains("dialog-no-scale-animation")?"pds-dialog-fade-enter":e?"pds-dialog-enter-mobile":"pds-dialog-enter";i.style.animation="none",i.offsetWidth,i.style.animation=`${u} var(--transition-normal) ease`,i.addEventListener("animationend",()=>{i.style.animation=""},{once:!0})}function D(i={}){return i?.liquidGlassEffects===!0}async function j(i,e={}){let u={title:"Confirm",type:"confirm",buttons:{ok:{name:"OK",primary:!0},cancel:{name:"Cancel",cancel:!0}}};e={...u,...e};let m=e.buttons&&typeof e.buttons=="object"?e.buttons:u.buttons,A=s=>{if(s==null)return{actionCode:"dismiss",actionKind:"dismiss",button:null};let o=m?.[s]??null,d=s==="ok"?"ok":s==="dismiss"?"dismiss":o?.cancel||s==="cancel"?"cancel":"custom";return{actionCode:s,actionKind:d,button:o}},$=s=>{if(typeof s>"u"||s===null||s===!0)return{allow:!0};if(s===!1)return{allow:!1};if(typeof s=="object"){let o=Object.prototype.hasOwnProperty.call(s,"result")||Object.prototype.hasOwnProperty.call(s,"value");return{allow:s.allow!==!1,hasResult:o,result:Object.prototype.hasOwnProperty.call(s,"result")?s.result:s.value}}return{allow:!!s}};return new Promise(s=>{let o=!1,d=(t,n,{shouldClose:c=!0}={})=>{if(!o&&(o=!0,s(t),!(!c||!n?.open)))try{n.close()}catch(l){v.log("warn","ask: dialog.close() failed",l)}},f=async t=>{if(t.actionKind!=="ok"||typeof e.beforeClose!="function")return{allow:!0};try{let n=await e.beforeClose(t);return $(n)}catch(n){return v.log("error","ask.beforeClose: validation failed",n),{allow:!1}}},g=({actionKind:t,form:n})=>t==="ok"?e.useForm&&n?new FormData(n):!0:!1,h=async({actionCode:t,form:n,submitter:c,originalEvent:l,bypassValidation:p=!1,shouldClose:w=!0})=>{if(o)return;let{actionKind:y,button:b}=A(t),S=n||a.querySelector("form")||null;if(e.useForm&&y==="ok"&&S&&!p&&!P(S))return;let E=g({actionKind:y,form:S}),O=await f({actionCode:t,actionKind:y,dialog:a,form:S,formData:e.useForm&&y==="ok"&&S?E:null,submitter:c,originalEvent:l,options:e,button:b,defaultResult:E});if(!O.allow)return;let q=O.hasResult?O.result:E;d(q,a,{shouldClose:w})},a=document.createElement("dialog");V()&&a.classList.add("dialog-no-scale-animation"),D(e)&&a.classList.add("liquid-glass"),e.size&&a.classList.add(`dialog-${e.size}`),e.type&&a.classList.add(`dialog-${e.type}`),e.class&&(Array.isArray(e.class)?a.classList.add(...e.class):a.classList.add(e.class)),e.maxHeight&&a.style.setProperty("--dialog-max-height",e.maxHeight);let C=Object.entries(m).map(([t,n])=>{let c=n.primary?"btn-primary btn-sm":"btn-outline btn-sm",l=n.cancel?"button":"submit",p=n.formNoValidate?" formnovalidate":"";return`<button type="${l}" class="${c}" value="${t}"${p}>${n.name}</button>`});if(e.useForm){let t=document.createElement("div");L(t,i);let n=t.querySelector("form");if(n){a.innerHTML=`
374
2
  <header>
375
- <h2>${options.title}</h2>
3
+ <h2>${e.title}</h2>
376
4
  </header>
377
- `;
378
- const article = document.createElement("article");
379
- article.className = "dialog-body";
380
- while (form.firstChild) {
381
- article.appendChild(form.firstChild);
382
- }
383
- form.appendChild(article);
384
- const footer = document.createElement("footer");
385
- footer.innerHTML = buttons.join("");
386
- form.appendChild(footer);
387
- dialog.appendChild(form);
388
- } else {
389
- dialog.innerHTML = /*html*/
390
- `
5
+ `;let c=document.createElement("article");for(c.className="dialog-body";n.firstChild;)c.appendChild(n.firstChild);n.appendChild(c);let l=document.createElement("footer");l.innerHTML=C.join(""),n.appendChild(l),a.appendChild(n)}else a.innerHTML=`
391
6
  <header>
392
- <h2>${options.title}</h2>
7
+ <h2>${e.title}</h2>
393
8
  </header>
394
9
  <article id="msg-container"></article>
395
10
  <footer>
396
- ${buttons.join("")}
11
+ ${C.join("")}
397
12
  </footer>
398
- `;
399
- const article = dialog.querySelector("#msg-container");
400
- article.appendChild(tempContainer);
401
- }
402
- } else {
403
- dialog.innerHTML = /*html*/
404
- `
13
+ `,a.querySelector("#msg-container").appendChild(t)}else{a.innerHTML=`
405
14
  <form method="dialog">
406
15
  <header>
407
- <h2>${options.title}</h2>
16
+ <h2>${e.title}</h2>
408
17
  </header>
409
18
 
410
19
  <article id="msg-container"></article>
411
20
 
412
21
  <footer>
413
- ${buttons.join("")}
22
+ ${C.join("")}
414
23
  </footer>
415
24
  </form>
416
- `;
417
- const article = dialog.querySelector("#msg-container");
418
- appendMessageContent(article, message);
419
- }
420
- dialog.addEventListener("click", (e) => {
421
- const btn = e.target.closest('button[value="cancel"]');
422
- if (btn) {
423
- attemptResolve({
424
- actionCode: "cancel",
425
- form: dialog.querySelector("form"),
426
- submitter: btn,
427
- originalEvent: e
428
- });
429
- }
430
- });
431
- const setupFormListener = () => {
432
- const form = dialog.querySelector("form");
433
- if (form) {
434
- if (form.dataset.askSubmitBound === "true") {
435
- return;
436
- }
437
- form.dataset.askSubmitBound = "true";
438
- form.addEventListener("submit", (event) => {
439
- event.preventDefault();
440
- const submitValue = event.submitter?.value ?? (options.useForm ? "ok" : void 0);
441
- const bypassValidation = Boolean(event.submitter?.hasAttribute("formnovalidate"));
442
- attemptResolve({
443
- actionCode: submitValue,
444
- form,
445
- submitter: event.submitter,
446
- originalEvent: event,
447
- bypassValidation
448
- });
449
- });
450
- } else {
451
- requestAnimationFrame(setupFormListener);
452
- }
453
- };
454
- dialog.addEventListener("cancel", (event) => {
455
- event.preventDefault();
456
- attemptResolve({
457
- actionCode: "dismiss",
458
- form: dialog.querySelector("form"),
459
- originalEvent: event
460
- });
461
- });
462
- dialog.addEventListener("close", () => {
463
- if (!settled) {
464
- settle(false, dialog, { shouldClose: false });
465
- }
466
- setTimeout(() => dialog.remove(), 200);
467
- });
468
- document.body.appendChild(dialog);
469
- requestAnimationFrame(setupFormListener);
470
- if (typeof options.rendered === "function") {
471
- options.rendered(dialog);
472
- }
473
- dialog.showModal();
474
- requestAnimationFrame(() => playDialogEnterAnimation(dialog));
475
- });
476
- }
477
- export {
478
- ask
479
- };
480
- //# sourceMappingURL=pds-ask.js.map
25
+ `;let t=a.querySelector("#msg-container");L(t,i)}a.addEventListener("click",t=>{let n=t.target.closest('button[value="cancel"]');n&&h({actionCode:"cancel",form:a.querySelector("form"),submitter:n,originalEvent:t})});let r=()=>{let t=a.querySelector("form");if(t){if(t.dataset.askSubmitBound==="true")return;t.dataset.askSubmitBound="true",t.addEventListener("submit",n=>{n.preventDefault();let c=n.submitter?.value??(e.useForm?"ok":void 0),l=!!n.submitter?.hasAttribute("formnovalidate");h({actionCode:c,form:t,submitter:n.submitter,originalEvent:n,bypassValidation:l})})}else requestAnimationFrame(r)};a.addEventListener("cancel",t=>{t.preventDefault(),h({actionCode:"dismiss",form:a.querySelector("form"),originalEvent:t})}),a.addEventListener("close",()=>{o||d(!1,a,{shouldClose:!1}),setTimeout(()=>a.remove(),200)}),document.body.appendChild(a),requestAnimationFrame(r),typeof e.rendered=="function"&&e.rendered(a),a.showModal(),requestAnimationFrame(()=>k(a))})}export{j as ask};