@t007/dialog 0.0.27 → 0.0.28

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.
@@ -124,17 +124,18 @@
124
124
  window.T007_DIALOG_CSS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/dialog@latest/dist/index.min.css`;
125
125
  }
126
126
 
127
- // ../utils/dist/chunk-YDARUYLO.js
128
- function initOutsideClick(el, { enabled = false, onOutsideClick = NOOP, outOnClick = true, outOnEscape = true, outOnFocusOut = false, allowInputs = false, root = window, scoped = true, capture = true } = NIL) {
127
+ // ../utils/dist/chunk-LBDWVTYF.js
128
+ function initOutsideClick(el, { enabled = false, onOutside = NOOP, outOnClick = true, outOnEscape = true, outOnFocusOut = false, allowBounds = false, allowInputs = false, root = window, scoped = true, capture = true } = NIL) {
129
129
  const stacks = t007._outsiders_stacks ??= /* @__PURE__ */ new WeakMap(), existing = (t007._outsiders ??= /* @__PURE__ */ new WeakMap()).get(el);
130
130
  if (!enabled || existing) return existing ? existing : void 0;
131
131
  scoped = scoped && root instanceof HTMLElement, root = scoped ? root : root === document ? document : window;
132
- const stack = stacks.get(root) ?? [], onScopedOut = (e, t, p = e.touches?.[0] || e, rect = el.getBoundingClientRect()) => {
133
- if (stack.at(-1) !== el || p.clientX >= rect.left && p.clientX <= rect.right && p.clientY >= rect.top && p.clientY <= rect.bottom) return false;
134
- return (!scoped ? true : root.contains(t)) && onOutsideClick(e);
135
- }, handleClick = ((e) => outOnClick && !(allowInputs && isInteractive(e.target)) && onScopedOut(e, e.target)), handleEscape = ((e) => outOnEscape && e.key === "Escape" && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && stack.at(-1) === el && onOutsideClick(e)), handleFocusOut = (e) => outOnFocusOut && !el.contains(e.relatedTarget) && onScopedOut(e, e.relatedTarget);
132
+ const stack = stacks.get(root) ?? [], onScopedOut = (e, t, p = e.touches?.[0] || e, rect = allowBounds ? el.getBoundingClientRect() : null) => {
133
+ if (stack.at(-1) !== el || (allowBounds ? p.clientX >= rect.left && p.clientX <= rect.right && p.clientY >= rect.top && p.clientY <= rect.bottom : el.contains(t))) return false;
134
+ return (!scoped ? true : root.contains(t)) && onOutside(e);
135
+ }, handleClick = ((e) => outOnClick && !(allowInputs && isInteractive(e.target)) && onScopedOut(e, e.target)), handleEscape = ((e) => outOnEscape && e.key === "Escape" && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.metaKey && stack.at(-1) === el && onOutside(e)), handleFocusOut = (e) => outOnFocusOut && !el.contains(e.relatedTarget) && onScopedOut(e, e.relatedTarget);
136
136
  root.addEventListener("mousedown", handleClick, capture), root.addEventListener("touchstart", handleClick, { passive: true, capture });
137
- root.addEventListener("keydown", handleEscape, capture), el.addEventListener("focusout", handleFocusOut, capture);
137
+ root.addEventListener("keydown", handleEscape, capture);
138
+ el.addEventListener("focusout", handleFocusOut, capture);
138
139
  if (!stack.includes(el)) stack.push(el), stacks.set(root, stack);
139
140
  const destroy = () => {
140
141
  root.removeEventListener("mousedown", handleClick, capture), root.removeEventListener("touchstart", handleClick, capture);
@@ -166,7 +167,7 @@
166
167
  first.addEventListener("focus", (e) => el.contains(e.relatedTarget) ? edgeFocus(true) : resetFocus(), capture), el.prepend(first);
167
168
  last.addEventListener("focus", (e) => el.contains(e.relatedTarget) ? edgeFocus() : resetFocus(-1), capture), el.append(last);
168
169
  root.addEventListener("focusin", handleFocusIn, capture);
169
- if (!el.querySelector(":focus")) !initial ? setTimeout(resetFocus) : setTimeout(() => (initial.classList.add(ringClassName), initial.focus(), initial.addEventListener("blur", handleInitialBlur, capture)));
170
+ if (initial || !el.contains(focused)) !initial ? setTimeout(resetFocus) : setTimeout(() => (initial.classList.add(ringClassName), initial.focus(), initial.addEventListener("blur", handleInitialBlur, capture)));
170
171
  if (!stack.includes(el)) stack.push(el), stacks.set(root, stack);
171
172
  const destroy = () => {
172
173
  focused?.isConnected && focused.focus(), first.remove(), last.remove();
@@ -363,10 +364,10 @@
363
364
  this.resolve = resolve;
364
365
  t007.dialogs.set(this.id = id ?? uid("t007_dialog_"), this);
365
366
  this.rootElement = root?.isConnected ? root : document.body, this.rootScoped = this.rootElement !== document.body, this.scoped = this.rootScoped && scoped;
366
- this.rootElement.append(this.dialog = createEl("dialog", { closedBy: by || (this.rootScoped ? "none" : "any"), className: `t007-dialog${this.rootScoped ? " t007-dialog-scoped" : ""}`, id: this.id }), this.rootScoped ? this.backdrop = createEl("div", { className: "t007-dialog-backdrop", id: `${this.id}_backdrop` }) : null);
367
+ this.rootElement.append(this.dialog = createEl("dialog", { closedBy: by || (this.rootScoped ? "none" : "any"), className: `t007-dialog${this.rootScoped ? " t007-dialog-scoped" : ""}`, id: this.id }), this.rootScoped ? this.backdrop = createEl("div", { className: "t007-dialog-backdrop", id: `${this.id}_backdrop` }) : "");
367
368
  this.dialog.addEventListener("cancel", this.cancel);
368
369
  initArrowNavigation(this.dialog, { enabled: true, rovingTab: false });
369
- this.rootScoped && !by && initOutsideClick(this.dialog, { enabled: true, onOutsideClick: this.cancel, root: this.rootElement, scoped: this.scoped });
370
+ this.rootScoped && !by && initOutsideClick(this.dialog, { enabled: true, onOutside: this.cancel, root: this.rootElement, scoped: this.scoped });
370
371
  }
371
372
  show() {
372
373
  this.dialog[this.rootScoped ? "show" : "showModal"]();
@@ -394,7 +395,7 @@
394
395
  <div class="t007-dialog-question">${message}</div>
395
396
  </div>
396
397
  <div class="t007-dialog-bottom-section">
397
- <button type="button" data-autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
398
+ <button type="button" autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
398
399
  </div>
399
400
  `;
400
401
  this.dialog.querySelector(".t007-dialog-confirm-button").addEventListener("click", this.confirm);
@@ -411,7 +412,7 @@
411
412
  <div class="t007-dialog-question">${question}</div>
412
413
  </div>
413
414
  <div class="t007-dialog-bottom-section">
414
- <button type="button" data-autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
415
+ <button type="button" autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
415
416
  <button type="button" data-arrow-item class="t007-dialog-cancel-button">${options.cancelText || "Cancel"}</button>
416
417
  </div>
417
418
  `;
@@ -425,7 +426,7 @@
425
426
  super(resolve, options), this.render(question, defaultValue, options);
426
427
  }
427
428
  async render(question, defaultValue, options) {
428
- options = { ...options, value: defaultValue };
429
+ options = { autofocus: true, ...options, value: defaultValue };
429
430
  await loadResource(window.T007_INPUT_JS_SRC, "script");
430
431
  this.dialog.innerHTML = `
431
432
  <form class="t007-input-form" ${t007.field ? "novalidate" : ""}>
package/dist/index.js CHANGED
@@ -7,10 +7,10 @@ var T007_Dialog = class {
7
7
  this.resolve = resolve;
8
8
  t007.dialogs.set(this.id = id ?? uid("t007_dialog_"), this);
9
9
  this.rootElement = root?.isConnected ? root : document.body, this.rootScoped = this.rootElement !== document.body, this.scoped = this.rootScoped && scoped;
10
- this.rootElement.append(this.dialog = createEl("dialog", { closedBy: by || (this.rootScoped ? "none" : "any"), className: `t007-dialog${this.rootScoped ? " t007-dialog-scoped" : ""}`, id: this.id }), this.rootScoped ? this.backdrop = createEl("div", { className: "t007-dialog-backdrop", id: `${this.id}_backdrop` }) : null);
10
+ this.rootElement.append(this.dialog = createEl("dialog", { closedBy: by || (this.rootScoped ? "none" : "any"), className: `t007-dialog${this.rootScoped ? " t007-dialog-scoped" : ""}`, id: this.id }), this.rootScoped ? this.backdrop = createEl("div", { className: "t007-dialog-backdrop", id: `${this.id}_backdrop` }) : "");
11
11
  this.dialog.addEventListener("cancel", this.cancel);
12
12
  initArrowNavigation(this.dialog, { enabled: true, rovingTab: false });
13
- this.rootScoped && !by && initOutsideClick(this.dialog, { enabled: true, onOutsideClick: this.cancel, root: this.rootElement, scoped: this.scoped });
13
+ this.rootScoped && !by && initOutsideClick(this.dialog, { enabled: true, onOutside: this.cancel, root: this.rootElement, scoped: this.scoped });
14
14
  }
15
15
  show() {
16
16
  this.dialog[this.rootScoped ? "show" : "showModal"]();
@@ -38,7 +38,7 @@ var T007_Alert_Dialog = class extends T007_Dialog {
38
38
  <div class="t007-dialog-question">${message}</div>
39
39
  </div>
40
40
  <div class="t007-dialog-bottom-section">
41
- <button type="button" data-autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
41
+ <button type="button" autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
42
42
  </div>
43
43
  `;
44
44
  this.dialog.querySelector(".t007-dialog-confirm-button").addEventListener("click", this.confirm);
@@ -55,7 +55,7 @@ var T007_Confirm_Dialog = class extends T007_Dialog {
55
55
  <div class="t007-dialog-question">${question}</div>
56
56
  </div>
57
57
  <div class="t007-dialog-bottom-section">
58
- <button type="button" data-autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
58
+ <button type="button" autofocus data-arrow-item class="t007-dialog-confirm-button">${options.confirmText || "OK"}</button>
59
59
  <button type="button" data-arrow-item class="t007-dialog-cancel-button">${options.cancelText || "Cancel"}</button>
60
60
  </div>
61
61
  `;
@@ -69,7 +69,7 @@ var T007_Prompt_Dialog = class extends T007_Dialog {
69
69
  super(resolve, options), this.render(question, defaultValue, options);
70
70
  }
71
71
  async render(question, defaultValue, options) {
72
- options = { ...options, value: defaultValue };
72
+ options = { autofocus: true, ...options, value: defaultValue };
73
73
  await loadResource(window.T007_INPUT_JS_SRC, "script");
74
74
  this.dialog.innerHTML = `
75
75
  <form class="t007-input-form" ${t007.field ? "novalidate" : ""}>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t007/dialog",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "A lightweight, pure JS dialog system.",
5
5
  "author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
6
6
  "license": "MIT",
@@ -56,7 +56,7 @@
56
56
  "accessible"
57
57
  ],
58
58
  "dependencies": {
59
- "@t007/utils": "^0.0.30"
59
+ "@t007/utils": "^0.0.31"
60
60
  },
61
61
  "devDependencies": {
62
62
  "esbuild-sass-plugin": "^3.7.0"