haori-bootstrap 0.5.21 → 0.5.23
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/README.ja.md +11 -6
- package/README.md +12 -7
- package/dist/haori-bootstrap.iife.js +2 -2
- package/dist/haori-bootstrap.iife.js.map +1 -1
- package/dist/haori-bootstrap.js +338 -314
- package/dist/haori-bootstrap.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/modal.d.ts +18 -0
- package/dist/types.d.ts +8 -0
- package/package.json +1 -1
package/README.ja.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Haori.js Bootstrap は、Haori.js 向けの Bootstrap ベース UI 拡張ライブラリです。
|
|
4
4
|
|
|
5
|
-
Version: 0.5.
|
|
5
|
+
Version: 0.5.23
|
|
6
6
|
|
|
7
7
|
## 概要
|
|
8
8
|
|
|
@@ -41,9 +41,9 @@ npm install haori-bootstrap
|
|
|
41
41
|
rel="stylesheet"
|
|
42
42
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css"
|
|
43
43
|
/>
|
|
44
|
-
<script src="https://cdn.jsdelivr.net/npm/haori@0.41.
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/haori@0.41.2/dist/haori.iife.js"></script>
|
|
45
45
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
|
|
46
|
-
<script src="https://cdn.jsdelivr.net/npm/haori-bootstrap@0.5.
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/haori-bootstrap@0.5.23/dist/haori-bootstrap.iife.js"></script>
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
IIFE 版は、window.Haori と window.bootstrap が利用可能な場合に自動で有効化されます。
|
|
@@ -75,7 +75,7 @@ install({
|
|
|
75
75
|
| confirm(message) | 確認ダイアログ | Promise<boolean> |
|
|
76
76
|
| toast(message, level) | トースト通知 | Promise<void> |
|
|
77
77
|
| openDialog(element) | 対象の Modal を開く(`.modal` 自身またはその子孫を渡す。非 `.modal` の場合は祖先方向で最も近い `.modal` に解決)。表示前に対象 Modal 配下の管理メッセージと `is-invalid` / `is-valid` 状態をクリアするため、再表示時はクリーンな状態で開く。 | Promise<void> |
|
|
78
|
-
| closeDialog(element) | 対象の Modal を閉じる(`.modal` 自身またはその子孫を渡す。非 `.modal` の場合は祖先方向で最も近い `.modal`
|
|
78
|
+
| closeDialog(element) | 対象の Modal を閉じる(`.modal` 自身またはその子孫を渡す。非 `.modal` の場合は祖先方向で最も近い `.modal` に解決)。表示アニメーション中に呼んだ場合は、表示完了を待ってから閉じる | Promise<void> |
|
|
79
79
|
| addErrorMessage(target, message) | 管理対象エラーメッセージの追加 | Promise<void> |
|
|
80
80
|
| addMessage(target, message, level?) | レベル付き管理対象メッセージを追加(`'error'` \| `'success'` \| `'warning'` \| `'info'`)。再呼び出し時は Bootstrap 検証クラス(`is-invalid` / `is-valid`)も切り替わります。 | Promise<void> |
|
|
81
81
|
| clearMessages(parentOrTarget) | 管理対象メッセージのみ削除 | Promise<void> |
|
|
@@ -88,6 +88,11 @@ install({
|
|
|
88
88
|
| ---- | ---- | ---- | ---- |
|
|
89
89
|
| toastPosition | `'top-start' \| 'top-center' \| 'top-end' \| 'bottom-start' \| 'bottom-center' \| 'bottom-end'` | `'bottom-end'` | トーストコンテナの表示位置。変更は次のトースト表示時に反映されます。 |
|
|
90
90
|
| toastDelay | `number` | Bootstrap デフォルト (5000ms) | トースト通知の自動非表示までの時間 (ms)。 |
|
|
91
|
+
| dialogTitle | `string` | 未指定(ヘッダーなし) | dialog / confirm のヘッダーに表示するタイトル。 |
|
|
92
|
+
| dialogOkLabel | `string` | `'OK'` | dialog / confirm の OK ボタンの文言。 |
|
|
93
|
+
| dialogCancelLabel | `string` | `'Cancel'` | confirm のキャンセルボタンの文言。 |
|
|
94
|
+
|
|
95
|
+
ボタンの識別属性(`data-haori-confirm-ok` / `data-haori-confirm-cancel` / `data-haori-dialog-ok`)は文言を変えても変わりません。文言で要素を探していない限り、既存のセレクターはそのまま動きます。
|
|
91
96
|
|
|
92
97
|
## Procedure 連携例
|
|
93
98
|
|
|
@@ -215,12 +220,12 @@ push 後に、そのタグから GitHub Release を published にします。公
|
|
|
215
220
|
次回 patch リリースの例:
|
|
216
221
|
|
|
217
222
|
```bash
|
|
218
|
-
# version が 0.5.
|
|
223
|
+
# version が 0.5.24 になる
|
|
219
224
|
npm version patch
|
|
220
225
|
git push origin main --follow-tags
|
|
221
226
|
```
|
|
222
227
|
|
|
223
|
-
その後、push 済みタグの GitHub Release を作成して published にします。例として次回は `0.5.
|
|
228
|
+
その後、push 済みタグの GitHub Release を作成して published にします。例として次回は `0.5.24` タグになります。
|
|
224
229
|
|
|
225
230
|
自動公開:
|
|
226
231
|
|
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Haori.js Bootstrap is a Bootstrap-based UI extension library for Haori.js.
|
|
4
4
|
|
|
5
|
-
Version: 0.5.
|
|
5
|
+
Version: 0.5.23
|
|
6
6
|
|
|
7
7
|
## Overview
|
|
8
8
|
|
|
@@ -41,9 +41,9 @@ Load dependencies in this order for browser direct loading:
|
|
|
41
41
|
rel="stylesheet"
|
|
42
42
|
href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css"
|
|
43
43
|
/>
|
|
44
|
-
<script src="https://cdn.jsdelivr.net/npm/haori@0.41.
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/haori@0.41.2/dist/haori.iife.js"></script>
|
|
45
45
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/js/bootstrap.bundle.min.js"></script>
|
|
46
|
-
<script src="https://cdn.jsdelivr.net/npm/haori-bootstrap@0.5.
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/haori-bootstrap@0.5.23/dist/haori-bootstrap.iife.js"></script>
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
The IIFE build auto-enables when both window.Haori and window.bootstrap are available.
|
|
@@ -75,7 +75,7 @@ install({
|
|
|
75
75
|
| confirm(message) | Confirmation dialog | Promise<boolean> |
|
|
76
76
|
| toast(message, level) | Toast notification | Promise<void> |
|
|
77
77
|
| openDialog(element) | Open the target's modal (pass the `.modal` itself or a descendant; a non-`.modal` element resolves to its nearest ancestor `.modal`). Managed messages and `is-invalid` / `is-valid` state under the modal are cleared before it is shown, so a reopened form starts clean. | Promise<void> |
|
|
78
|
-
| closeDialog(element) | Close the target's modal (pass the `.modal` itself or a descendant; a non-`.modal` element resolves to its nearest ancestor `.modal`) | Promise<void> |
|
|
78
|
+
| closeDialog(element) | Close the target's modal (pass the `.modal` itself or a descendant; a non-`.modal` element resolves to its nearest ancestor `.modal`). When called during the show animation, it waits for the animation to finish and then closes | Promise<void> |
|
|
79
79
|
| addErrorMessage(target, message) | Append managed error messages | Promise<void> |
|
|
80
80
|
| addMessage(target, message, level?) | Append a level-aware managed message (`'error'` \| `'success'` \| `'warning'` \| `'info'`). Switches Bootstrap validation classes (`is-invalid` / `is-valid`) on re-call. | Promise<void> |
|
|
81
81
|
| clearMessages(parentOrTarget) | Remove only managed messages | Promise<void> |
|
|
@@ -88,6 +88,11 @@ install({
|
|
|
88
88
|
| ---- | ---- | ---- | ---- |
|
|
89
89
|
| toastPosition | `'top-start' \| 'top-center' \| 'top-end' \| 'bottom-start' \| 'bottom-center' \| 'bottom-end'` | `'bottom-end'` | Toast container position. The new position takes effect the next time a toast is shown. |
|
|
90
90
|
| toastDelay | `number` | Bootstrap default (5000ms) | Auto-hide delay in milliseconds for toast notifications. |
|
|
91
|
+
| dialogTitle | `string` | none (no header) | Header title shown by dialog and confirm. |
|
|
92
|
+
| dialogOkLabel | `string` | `'OK'` | Label of the OK button in dialog and confirm. |
|
|
93
|
+
| dialogCancelLabel | `string` | `'Cancel'` | Label of the cancel button in confirm. |
|
|
94
|
+
|
|
95
|
+
The identifying attributes (`data-haori-confirm-ok`, `data-haori-confirm-cancel`, `data-haori-dialog-ok`) do not change with the label, so selectors keep working.
|
|
91
96
|
|
|
92
97
|
## Procedure Integration Example
|
|
93
98
|
|
|
@@ -212,15 +217,15 @@ git push origin main --follow-tags
|
|
|
212
217
|
|
|
213
218
|
After pushing, publish a GitHub Release from the generated version tag. The release workflow then publishes the package and uploads `dist.zip` automatically.
|
|
214
219
|
|
|
215
|
-
Example next patch release after `0.5.
|
|
220
|
+
Example next patch release after `0.5.23`:
|
|
216
221
|
|
|
217
222
|
```bash
|
|
218
|
-
# version becomes 0.5.
|
|
223
|
+
# version becomes 0.5.24
|
|
219
224
|
npm version patch
|
|
220
225
|
git push origin main --follow-tags
|
|
221
226
|
```
|
|
222
227
|
|
|
223
|
-
Create and publish the GitHub Release for the pushed tag such as `0.5.
|
|
228
|
+
Create and publish the GitHub Release for the pushed tag such as `0.5.24`.
|
|
224
229
|
|
|
225
230
|
Release automation:
|
|
226
231
|
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var HaoriBootstrap=(function(h){"use strict";function W(e){return typeof e=="function"}function G(e){return W(e?.Modal)?e?.Modal:void 0}function j(e){return W(e?.Toast)?e?.Toast:void 0}function L(e){return!!G(e)}function Ie(e){return!!j(e)}function N(e,n,t){const o=G(t);if(o)return typeof o.getOrCreateInstance=="function"?o.getOrCreateInstance(e,n):new o(e,n)}function Me(e,n,t){const o=j(t);if(o)return typeof o.getOrCreateInstance=="function"?o.getOrCreateInstance(e,n):new o(e,n)}const Le="data-haori-dialog",Ne="data-haori-confirm",He="data-haori-dialog-title",V="data-haori-dialog-ok",K="data-haori-confirm-ok",J="data-haori-confirm-cancel";let ke=0;function X(){return{backdrop:"static",keyboard:!1}}function Q(e,n){if(n.dialogContainerSelector){const t=e.querySelector(n.dialogContainerSelector);if(t)return t}return e.body}function Y(e,n,t,o){const r=e.createElement("div");r.className="modal fade",r.tabIndex=-1,r.setAttribute(t?Ne:Le,"true"),r.setAttribute("aria-hidden","true");const i=e.createElement("div");i.className="modal-dialog modal-dialog-centered";const c=e.createElement("div");if(c.className="modal-content",o){const u=`haori-dialog-title-${++ke}`,A=e.createElement("div");A.className="modal-header";const M=e.createElement("h5");M.className="modal-title",M.id=u,M.setAttribute(He,"true"),M.textContent=o,A.appendChild(M),c.appendChild(A),r.setAttribute("aria-labelledby",u)}const a=e.createElement("div");a.className="modal-body";const d=e.createElement("p");d.className="mb-0",d.style.whiteSpace="pre-line",d.textContent=n,a.appendChild(d);const l=e.createElement("div");if(l.className="modal-footer",t){const u=e.createElement("button");u.type="button",u.className="btn btn-secondary",u.setAttribute(J,"true"),u.textContent="Cancel",l.appendChild(u)}const b=e.createElement("button");return b.type="button",b.className="btn btn-primary",b.setAttribute(t?K:V,"true"),b.textContent="OK",l.appendChild(b),c.append(a,l),i.appendChild(c),r.appendChild(i),r}function Be(e,n){const t=globalThis.document,o=Y(t,e,!1,n.dialogTitle);Q(t,n).appendChild(o);const r=N(o,X(),n.bootstrap);return r?new Promise((i,c)=>{const a=()=>{o.removeEventListener("hidden.bs.modal",d),o.remove(),r.dispose?.(),i()},d=()=>{a()};o.querySelector(`[${V}]`)?.addEventListener("click",()=>{r.hide()},{once:!0}),o.addEventListener("hidden.bs.modal",d,{once:!0});try{r.show()}catch(b){o.removeEventListener("hidden.bs.modal",d),o.remove(),r.dispose?.(),c(b)}}):(o.remove(),Promise.reject(new Error("Bootstrap Modal is unavailable.")))}function Re(e,n){const t=globalThis.document,o=Y(t,e,!0,n.dialogTitle);Q(t,n).appendChild(o);const r=N(o,X(),n.bootstrap);return r?new Promise((i,c)=>{let a=!1;const d=()=>{o.removeEventListener("hidden.bs.modal",l),o.remove(),r.dispose?.(),i(a)},l=()=>{d()},b=o.querySelector(`[${K}]`),u=o.querySelector(`[${J}]`);b?.addEventListener("click",()=>{a=!0,r.hide()},{once:!0}),u?.addEventListener("click",()=>{a=!1,r.hide()},{once:!0}),o.addEventListener("hidden.bs.modal",l,{once:!0});try{r.show()}catch(A){o.removeEventListener("hidden.bs.modal",l),o.remove(),r.dispose?.(),c(A)}}):(o.remove(),Promise.reject(new Error("Bootstrap Modal is unavailable.")))}const p="data-haori-owned",m="data-haori-message-container",g="data-haori-invalid-target",w="data-haori-valid-target";function S(e){return e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")}function E(e){return e instanceof HTMLInputElement&&e.type==="radio"}function y(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function H(e){return Array.from(e.children).find(n=>n instanceof HTMLElement&&n.getAttribute(m)==="true")}function Z(e,n){const t=e.createElement("div");return t.setAttribute(p,"true"),t.textContent=n,t}function ee(e){return H(e)}function I(e){if(e.name){const n=e.form??e.ownerDocument,t=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e.name):e.name.replace(/(["\\])/g,"\\$1"),o=Array.from(n.querySelectorAll(`input[type="radio"][name="${t}"]`));if(o.length>0)return o}return[e]}function Pe(e){const[n,...t]=e;if(!n)return;let o=n;for(;o;){if(t.every(r=>o?.contains(r)))return o;o=o.parentElement}}function $(e){const t=I(e).map(o=>o.closest(".form-check")).filter(o=>o instanceof HTMLElement);if(t.length>1){const o=Pe(t);if(o&&!t.includes(o))return o}return k(e)}function k(e){const n=e.closest(".form-check");return n instanceof HTMLElement?n:void 0}function te(e){const n=e.nextElementSibling;if(n instanceof HTMLElement&&n.getAttribute(m)==="true")return n;const t=document.createElement("div");return t.className="invalid-feedback d-block",t.setAttribute(p,"true"),t.setAttribute(m,"true"),e.insertAdjacentElement("afterend",t),t}function _e(e){const n=E(e)?$(e):k(e);if(!n)return te(e);const t=H(n);if(t)return t;const o=document.createElement("div");return o.className="invalid-feedback d-block",o.setAttribute(p,"true"),o.setAttribute(m,"true"),n.appendChild(o),o}function De(e){const n=ee(e);if(n)return n;const t=document.createElement("div");return t.className="alert alert-danger",t.setAttribute("role","alert"),t.setAttribute(p,"true"),t.setAttribute(m,"true"),e.insertAdjacentElement("afterbegin",t),t}function v(e){e.getAttribute(g)==="true"&&(e.classList.remove("is-invalid"),e.removeAttribute(g))}function T(e){e.getAttribute(w)==="true"&&(e.classList.remove("is-valid"),e.removeAttribute(w))}function ne(e){switch(e){case"success":return"alert alert-success";case"warning":return"alert alert-warning";case"info":return"alert alert-info";default:return"alert alert-danger"}}function B(e){return e==="success"?"valid-feedback d-block":"invalid-feedback d-block"}function oe(e){(E(e)?I(e):[e]).forEach(t=>{t.classList.add("is-invalid"),t.setAttribute(g,"true")})}function xe(e){(E(e)?I(e):[e]).forEach(t=>{v(t)})}function re(e,n){const t=e.nextElementSibling;if(t instanceof HTMLElement&&t.getAttribute(m)==="true")return t.className=B(n),t;const o=document.createElement("div");return o.className=B(n),o.setAttribute(p,"true"),o.setAttribute(m,"true"),e.insertAdjacentElement("afterend",o),o}function Oe(e,n){const t=E(e)?$(e):k(e);if(!t)return re(e,n);const o=H(t);if(o)return o.className=B(n),o;const r=document.createElement("div");return r.className=B(n),r.setAttribute(p,"true"),r.setAttribute(m,"true"),t.appendChild(r),r}function $e(e,n){const t=ee(e);if(t)return t.className=ne(n),t;const o=document.createElement("div");return o.className=ne(n),o.setAttribute("role","alert"),o.setAttribute(p,"true"),o.setAttribute(m,"true"),e.insertAdjacentElement("afterbegin",o),o}function Ue(e,n){return(S(e)?_e(e):y(e)?te(e):De(e)).appendChild(Z(document,n)),S(e)?oe(e):y(e)&&(e.classList.add("is-invalid"),e.setAttribute(g,"true")),Promise.resolve()}function qe(e,n,t){if((S(e)?Oe(e,t):y(e)?re(e,t):$e(e,t)).appendChild(Z(document,n)),S(e)){const r=E(e)?I(e):[e];t==="success"?r.forEach(i=>{v(i),i.classList.add("is-valid"),i.setAttribute(w,"true")}):!t||t==="error"?(r.forEach(i=>T(i)),oe(e)):r.forEach(i=>{T(i),v(i)})}else y(e)&&(t==="success"?(v(e),e.classList.add("is-valid"),e.setAttribute(w,"true")):!t||t==="error"?(T(e),e.classList.add("is-invalid"),e.setAttribute(g,"true")):(T(e),v(e)));return Promise.resolve()}function ie(e){if(S(e)){const r=E(e)?$(e):k(e);(r?H(r):void 0)?.remove(),xe(e),(E(e)?I(e):[e]).forEach(a=>T(a))}else if(y(e)){const r=e.nextElementSibling;r instanceof HTMLElement&&r.getAttribute(m)==="true"&&r.remove(),v(e),T(e)}return e.querySelectorAll(`[${m}="true"]`).forEach(r=>{r.remove()}),e.querySelectorAll(`[${g}="true"]`).forEach(r=>{v(r)}),e.querySelectorAll(`[${w}="true"]`).forEach(r=>{T(r)}),Promise.resolve()}function se(e){return e.classList.contains("modal")?e:e.closest(".modal")}function ae(e){e.tabIndex<0&&(e.tabIndex=-1),e.hasAttribute("aria-hidden")||e.setAttribute("aria-hidden","true")}function Fe(e,n){const t=se(e);if(!t)return Promise.reject(new Error('No ancestor ".modal" element was found for the target.'));ae(t),ie(t);const o=N(t,void 0,n.bootstrap);return o?(o.show(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}function ze(e,n){const t=se(e);if(!t)return Promise.reject(new Error('No ancestor ".modal" element was found for the target.'));ae(t);const o=N(t,void 0,n.bootstrap);return o?(o.hide(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}const ce="data-haori-toast-container",We="data-haori-toast",Ge="data-haori-toast-level",je="data-haori-toast-accent",Ve="data-haori-toast-dismiss",le={"top-start":"top-0 start-0","top-center":"top-0 start-50 translate-middle-x","top-end":"top-0 end-0","bottom-start":"bottom-0 start-0","bottom-center":"bottom-0 start-50 translate-middle-x","bottom-end":"bottom-0 end-0"};function Ke(e){switch(e){case"success":return{accentClassName:"bg-success",level:"success"};case"warning":return{accentClassName:"bg-warning",level:"warning"};case"error":return{accentClassName:"bg-danger",level:"error"};default:return{accentClassName:"bg-info",level:"info"}}}function Je(e,n){if(n.toastContainerSelector){const t=e.querySelector(n.toastContainerSelector);if(t)return t}return e.body}function Xe(e,n){const t=Je(e,n),o=le[n.toastPosition??"bottom-end"],r=t.querySelector(`[${ce}="true"]`);if(r){const c=Object.values(le).flatMap(a=>a.split(" "));return r.classList.remove(...c),r.classList.add(...o.split(" ")),r}const i=e.createElement("div");return i.className=`toast-container position-fixed ${o} p-3`,i.setAttribute(ce,"true"),t.appendChild(i),i}function Qe(e,n,t){const o=globalThis.document,r=Ke(n),i=o.createElement("div");i.className="toast border bg-body text-body shadow-sm",i.setAttribute("role","status"),i.setAttribute("aria-live","polite"),i.setAttribute("aria-atomic","true"),i.setAttribute(We,"true"),i.setAttribute(Ge,r.level);const c=o.createElement("div");c.className="d-flex align-items-stretch";const a=o.createElement("div");a.className=`flex-shrink-0 rounded-start ${r.accentClassName}`,a.style.width="0.375rem",a.setAttribute(je,"true");const d=o.createElement("div");d.className="toast-body",d.style.whiteSpace="pre-line",d.textContent=e;const l=o.createElement("button");l.type="button",l.className="btn-close me-2 m-auto flex-shrink-0",l.setAttribute("aria-label","Close"),l.setAttribute(Ve,"true"),c.appendChild(a),c.appendChild(d),c.appendChild(l),i.appendChild(c),Xe(o,t).appendChild(i);const b=t.toastDelay!==void 0?{delay:t.toastDelay}:void 0,u=Me(i,b,t.bootstrap);if(!u)return i.remove(),Promise.reject(new Error("Bootstrap Toast is unavailable."));l.addEventListener("click",()=>{u.hide?.()}),i.addEventListener("hidden.bs.toast",()=>{i.remove(),u.dispose?.()},{once:!0});try{return u.show(),Promise.resolve()}catch(A){return i.remove(),u.dispose?.(),Promise.reject(A)}}let f={options:{fallbackToNative:!0}};function C(e){return e.replace(/\\n/g,`
|
|
2
|
-
`)}function
|
|
1
|
+
var HaoriBootstrap=(function(E){"use strict";function V(e){return typeof e=="function"}function J(e){return V(e?.Modal)?e?.Modal:void 0}function X(e){return V(e?.Toast)?e?.Toast:void 0}function N(e){return!!J(e)}function Be(e){return!!X(e)}function k(e,n,t){const o=J(t);if(o)return typeof o.getOrCreateInstance=="function"?o.getOrCreateInstance(e,n):new o(e,n)}function _e(e,n,t){const o=X(t);if(o)return typeof o.getOrCreateInstance=="function"?o.getOrCreateInstance(e,n):new o(e,n)}const Pe="data-haori-dialog",De="data-haori-confirm",xe="data-haori-dialog-title",Q="data-haori-dialog-ok",Y="data-haori-confirm-ok",Z="data-haori-confirm-cancel",Oe="OK",qe="Cancel";let Ue=0;function ee(){return{backdrop:"static",keyboard:!1}}function te(e,n){if(n.dialogContainerSelector){const t=e.querySelector(n.dialogContainerSelector);if(t)return t}return e.body}function ne(e,n,t,o){const r=o.dialogTitle,s=e.createElement("div");s.className="modal fade",s.tabIndex=-1,s.setAttribute(t?De:Pe,"true"),s.setAttribute("aria-hidden","true");const c=e.createElement("div");c.className="modal-dialog modal-dialog-centered";const a=e.createElement("div");if(a.className="modal-content",r){const b=`haori-dialog-title-${++Ue}`,y=e.createElement("div");y.className="modal-header";const A=e.createElement("h5");A.className="modal-title",A.id=b,A.setAttribute(xe,"true"),A.textContent=r,y.appendChild(A),a.appendChild(y),s.setAttribute("aria-labelledby",b)}const f=e.createElement("div");f.className="modal-body";const l=e.createElement("p");l.className="mb-0",l.style.whiteSpace="pre-line",l.textContent=n,f.appendChild(l);const m=e.createElement("div");if(m.className="modal-footer",t){const b=e.createElement("button");b.type="button",b.className="btn btn-secondary",b.setAttribute(Z,"true"),b.textContent=o.dialogCancelLabel??qe,m.appendChild(b)}const d=e.createElement("button");return d.type="button",d.className="btn btn-primary",d.setAttribute(t?Y:Q,"true"),d.textContent=o.dialogOkLabel??Oe,m.appendChild(d),a.append(f,m),c.appendChild(a),s.appendChild(c),s}function oe(e){let n=!1,t=!1;return{requestClose:o=>{n||(n=!0,o?.(),t&&e.hide())},handleShown:()=>{t=!0,n&&e.hide()}}}function $e(e,n){const t=globalThis.document,o=ne(t,e,!1,n);te(t,n).appendChild(o);const r=k(o,ee(),n.bootstrap);return r?new Promise((s,c)=>{const a=()=>{o.removeEventListener("shown.bs.modal",m),o.removeEventListener("hidden.bs.modal",f),o.remove(),r.dispose?.(),s()},f=()=>{a()},l=oe(r),m=l.handleShown;o.querySelector(`[${Q}]`)?.addEventListener("click",()=>{l.requestClose()}),o.addEventListener("shown.bs.modal",m),o.addEventListener("hidden.bs.modal",f,{once:!0});try{r.show()}catch(b){o.removeEventListener("shown.bs.modal",m),o.removeEventListener("hidden.bs.modal",f),o.remove(),r.dispose?.(),c(b)}}):(o.remove(),Promise.reject(new Error("Bootstrap Modal is unavailable.")))}function Fe(e,n){const t=globalThis.document,o=ne(t,e,!0,n);te(t,n).appendChild(o);const r=k(o,ee(),n.bootstrap);return r?new Promise((s,c)=>{let a=!1;const f=()=>{o.removeEventListener("shown.bs.modal",d),o.removeEventListener("hidden.bs.modal",l),o.remove(),r.dispose?.(),s(a)},l=()=>{f()},m=oe(r),d=m.handleShown,b=o.querySelector(`[${Y}]`),y=o.querySelector(`[${Z}]`);b?.addEventListener("click",()=>{m.requestClose(()=>{a=!0})}),y?.addEventListener("click",()=>{m.requestClose(()=>{a=!1})}),o.addEventListener("shown.bs.modal",d),o.addEventListener("hidden.bs.modal",l,{once:!0});try{r.show()}catch(A){o.removeEventListener("shown.bs.modal",d),o.removeEventListener("hidden.bs.modal",l),o.remove(),r.dispose?.(),c(A)}}):(o.remove(),Promise.reject(new Error("Bootstrap Modal is unavailable.")))}const v="data-haori-owned",h="data-haori-message-container",w="data-haori-invalid-target",L="data-haori-valid-target";function S(e){return e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")}function p(e){return e instanceof HTMLInputElement&&e.type==="radio"}function M(e){return e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement}function H(e){return Array.from(e.children).find(n=>n instanceof HTMLElement&&n.getAttribute(h)==="true")}function re(e,n){const t=e.createElement("div");return t.setAttribute(v,"true"),t.textContent=n,t}function se(e){return H(e)}function I(e){if(e.name){const n=e.form??e.ownerDocument,t=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e.name):e.name.replace(/(["\\])/g,"\\$1"),o=Array.from(n.querySelectorAll(`input[type="radio"][name="${t}"]`));if(o.length>0)return o}return[e]}function ze(e){const[n,...t]=e;if(!n)return;let o=n;for(;o;){if(t.every(r=>o?.contains(r)))return o;o=o.parentElement}}function $(e){const t=I(e).map(o=>o.closest(".form-check")).filter(o=>o instanceof HTMLElement);if(t.length>1){const o=ze(t);if(o&&!t.includes(o))return o}return R(e)}function R(e){const n=e.closest(".form-check");return n instanceof HTMLElement?n:void 0}function ie(e){const n=e.nextElementSibling;if(n instanceof HTMLElement&&n.getAttribute(h)==="true")return n;const t=document.createElement("div");return t.className="invalid-feedback d-block",t.setAttribute(v,"true"),t.setAttribute(h,"true"),e.insertAdjacentElement("afterend",t),t}function We(e){const n=p(e)?$(e):R(e);if(!n)return ie(e);const t=H(n);if(t)return t;const o=document.createElement("div");return o.className="invalid-feedback d-block",o.setAttribute(v,"true"),o.setAttribute(h,"true"),n.appendChild(o),o}function Ge(e){const n=se(e);if(n)return n;const t=document.createElement("div");return t.className="alert alert-danger",t.setAttribute("role","alert"),t.setAttribute(v,"true"),t.setAttribute(h,"true"),e.insertAdjacentElement("afterbegin",t),t}function T(e){e.getAttribute(w)==="true"&&(e.classList.remove("is-invalid"),e.removeAttribute(w))}function g(e){e.getAttribute(L)==="true"&&(e.classList.remove("is-valid"),e.removeAttribute(L))}function ae(e){switch(e){case"success":return"alert alert-success";case"warning":return"alert alert-warning";case"info":return"alert alert-info";default:return"alert alert-danger"}}function B(e){return e==="success"?"valid-feedback d-block":"invalid-feedback d-block"}function le(e){(p(e)?I(e):[e]).forEach(t=>{t.classList.add("is-invalid"),t.setAttribute(w,"true")})}function je(e){(p(e)?I(e):[e]).forEach(t=>{T(t)})}function ce(e,n){const t=e.nextElementSibling;if(t instanceof HTMLElement&&t.getAttribute(h)==="true")return t.className=B(n),t;const o=document.createElement("div");return o.className=B(n),o.setAttribute(v,"true"),o.setAttribute(h,"true"),e.insertAdjacentElement("afterend",o),o}function Ke(e,n){const t=p(e)?$(e):R(e);if(!t)return ce(e,n);const o=H(t);if(o)return o.className=B(n),o;const r=document.createElement("div");return r.className=B(n),r.setAttribute(v,"true"),r.setAttribute(h,"true"),t.appendChild(r),r}function Ve(e,n){const t=se(e);if(t)return t.className=ae(n),t;const o=document.createElement("div");return o.className=ae(n),o.setAttribute("role","alert"),o.setAttribute(v,"true"),o.setAttribute(h,"true"),e.insertAdjacentElement("afterbegin",o),o}function Je(e,n){return(S(e)?We(e):M(e)?ie(e):Ge(e)).appendChild(re(document,n)),S(e)?le(e):M(e)&&(e.classList.add("is-invalid"),e.setAttribute(w,"true")),Promise.resolve()}function Xe(e,n,t){if((S(e)?Ke(e,t):M(e)?ce(e,t):Ve(e,t)).appendChild(re(document,n)),S(e)){const r=p(e)?I(e):[e];t==="success"?r.forEach(s=>{T(s),s.classList.add("is-valid"),s.setAttribute(L,"true")}):!t||t==="error"?(r.forEach(s=>g(s)),le(e)):r.forEach(s=>{g(s),T(s)})}else M(e)&&(t==="success"?(T(e),e.classList.add("is-valid"),e.setAttribute(L,"true")):!t||t==="error"?(g(e),e.classList.add("is-invalid"),e.setAttribute(w,"true")):(g(e),T(e)));return Promise.resolve()}function de(e){if(S(e)){const r=p(e)?$(e):R(e);(r?H(r):void 0)?.remove(),je(e),(p(e)?I(e):[e]).forEach(a=>g(a))}else if(M(e)){const r=e.nextElementSibling;r instanceof HTMLElement&&r.getAttribute(h)==="true"&&r.remove(),T(e),g(e)}return e.querySelectorAll(`[${h}="true"]`).forEach(r=>{r.remove()}),e.querySelectorAll(`[${w}="true"]`).forEach(r=>{T(r)}),e.querySelectorAll(`[${L}="true"]`).forEach(r=>{g(r)}),Promise.resolve()}const F=new WeakSet;let _=!1,z;const ue=e=>{e.target instanceof HTMLElement&&F.add(e.target)},fe=e=>{e.target instanceof HTMLElement&&F.delete(e.target)};function Qe(e=document){_||(_=!0,z=e,e.addEventListener("show.bs.modal",ue),e.addEventListener("shown.bs.modal",fe))}function Ye(e=z??document){_&&(_=!1,e.removeEventListener("show.bs.modal",ue),e.removeEventListener("shown.bs.modal",fe),z=void 0)}function me(e){return e.classList.contains("modal")?e:e.closest(".modal")}function be(e){e.tabIndex<0&&(e.tabIndex=-1),e.hasAttribute("aria-hidden")||e.setAttribute("aria-hidden","true")}function Ze(e,n){const t=me(e);if(!t)return Promise.reject(new Error('No ancestor ".modal" element was found for the target.'));be(t),de(t);const o=k(t,void 0,n.bootstrap);return o?(o.show(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}function et(e,n){const t=me(e);if(!t)return Promise.reject(new Error('No ancestor ".modal" element was found for the target.'));be(t);const o=k(t,void 0,n.bootstrap);return o?F.has(t)?(t.addEventListener("shown.bs.modal",()=>{o.hide()},{once:!0}),Promise.resolve()):(o.hide(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}const he="data-haori-toast-container",tt="data-haori-toast",nt="data-haori-toast-level",ot="data-haori-toast-accent",rt="data-haori-toast-dismiss",Ee={"top-start":"top-0 start-0","top-center":"top-0 start-50 translate-middle-x","top-end":"top-0 end-0","bottom-start":"bottom-0 start-0","bottom-center":"bottom-0 start-50 translate-middle-x","bottom-end":"bottom-0 end-0"};function st(e){switch(e){case"success":return{accentClassName:"bg-success",level:"success"};case"warning":return{accentClassName:"bg-warning",level:"warning"};case"error":return{accentClassName:"bg-danger",level:"error"};default:return{accentClassName:"bg-info",level:"info"}}}function it(e,n){if(n.toastContainerSelector){const t=e.querySelector(n.toastContainerSelector);if(t)return t}return e.body}function at(e,n){const t=it(e,n),o=Ee[n.toastPosition??"bottom-end"],r=t.querySelector(`[${he}="true"]`);if(r){const c=Object.values(Ee).flatMap(a=>a.split(" "));return r.classList.remove(...c),r.classList.add(...o.split(" ")),r}const s=e.createElement("div");return s.className=`toast-container position-fixed ${o} p-3`,s.setAttribute(he,"true"),t.appendChild(s),s}function lt(e,n,t){const o=globalThis.document,r=st(n),s=o.createElement("div");s.className="toast border bg-body text-body shadow-sm",s.setAttribute("role","status"),s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","true"),s.setAttribute(tt,"true"),s.setAttribute(nt,r.level);const c=o.createElement("div");c.className="d-flex align-items-stretch";const a=o.createElement("div");a.className=`flex-shrink-0 rounded-start ${r.accentClassName}`,a.style.width="0.375rem",a.setAttribute(ot,"true");const f=o.createElement("div");f.className="toast-body",f.style.whiteSpace="pre-line",f.textContent=e;const l=o.createElement("button");l.type="button",l.className="btn-close me-2 m-auto flex-shrink-0",l.setAttribute("aria-label","Close"),l.setAttribute(rt,"true"),c.appendChild(a),c.appendChild(f),c.appendChild(l),s.appendChild(c),at(o,t).appendChild(s);const m=t.toastDelay!==void 0?{delay:t.toastDelay}:void 0,d=_e(s,m,t.bootstrap);if(!d)return s.remove(),Promise.reject(new Error("Bootstrap Toast is unavailable."));l.addEventListener("click",()=>{d.hide?.()}),s.addEventListener("hidden.bs.toast",()=>{s.remove(),d.dispose?.()},{once:!0});try{return d.show(),Promise.resolve()}catch(b){return s.remove(),d.dispose?.(),Promise.reject(b)}}let u={options:{fallbackToNative:!0}};function C(e){return e.replace(/\\n/g,`
|
|
2
|
+
`)}function ve(){return globalThis.window}function W(e){return Promise.resolve(e).then(()=>{})}function P(e){const n=u.originalHaori?.[e];return typeof n=="function"?n:void 0}function D(e){console.warn(`[haori-bootstrap] ${e} skipped because Bootstrap support is unavailable.`)}function pe(e){const n=C(e),t=P("dialog");if(t)return W(t(n));const o=ve();return u.options.fallbackToNative&&typeof o?.alert=="function"?(o.alert(n),Promise.resolve()):(D("dialog"),Promise.resolve())}function Te(e){const n=C(e),t=P("confirm");if(t)return Promise.resolve(t(n)).then(r=>!!r);const o=ve();return u.options.fallbackToNative&&typeof o?.confirm=="function"?Promise.resolve(o.confirm(n)):(D("confirm"),Promise.resolve(!1))}function ge(e,n){const t=C(e),o=P("toast");return o?W(o(t,n)):(D("toast"),Promise.resolve())}function x(e,n){const t=P(e);return t?W(t(n)):(D(e),Promise.resolve())}function ct(e){u=e}class Ae{static dialog(n){const t=C(n);return N(u.options.bootstrap)?$e(t,u.options).catch(()=>pe(t)):pe(t)}static confirm(n){const t=C(n);return N(u.options.bootstrap)?Fe(t,u.options).catch(()=>Te(t)):Te(t)}static toast(n,t){const o=C(n);return Be(u.options.bootstrap)?lt(o,t,u.options).catch(()=>ge(o,t)):ge(o,t)}static openDialog(n){return N(u.options.bootstrap)?Ze(n,u.options).catch(()=>x("openDialog",n)):x("openDialog",n)}static closeDialog(n){return N(u.options.bootstrap)?et(n,u.options).catch(()=>x("closeDialog",n)):x("closeDialog",n)}static addErrorMessage(n,t){return Je(n,t)}static addMessage(n,t,o){return Xe(n,t,o)}static clearMessages(n){return de(n)}}const dt="haori-bootstrap:collapse:",O="data-haori-persist";let q=!1,U,G;function we(e){return dt+e}function ut(e){try{const n=window.sessionStorage.getItem(we(e));return n==="shown"||n==="hidden"?n:void 0}catch{return}}function ft(e,n){try{window.sessionStorage.setItem(we(e),n)}catch{}}function Ce(e,n){const t=e.id,o=[`[data-bs-toggle="collapse"][data-bs-target="#${t}"]`];if(t&&o.push(`[data-bs-toggle="collapse"][href="#${t}"]`),!t)return;e.ownerDocument.querySelectorAll(o.join(",")).forEach(s=>{s.setAttribute("aria-expanded",n?"true":"false"),s.classList.toggle("collapsed",!n)})}function Le(e){const n=e.getAttribute(O);if(!n)return;const t=ut(n);if(!t)return;const o=e.classList.contains("show");t==="shown"&&!o?(e.classList.add("show"),Ce(e,!0)):t==="hidden"&&o&&(e.classList.remove("show"),Ce(e,!1))}function Se(e){e instanceof HTMLElement&&e.hasAttribute(O)&&Le(e),e.querySelectorAll(`[${O}]`).forEach(Le)}function Me(e,n){const t=e.target;if(!(t instanceof HTMLElement))return;const o=t.getAttribute(O);o&&ft(o,n)}const Ie=e=>Me(e,"shown"),ye=e=>Me(e,"hidden");function mt(e=document){if(q)return;q=!0,G=e,e.addEventListener("shown.bs.collapse",Ie),e.addEventListener("hidden.bs.collapse",ye);const n=()=>{Se(e),U=new MutationObserver(t=>{for(const o of t)o.addedNodes.forEach(r=>{r instanceof HTMLElement&&Se(r)})}),e.body&&U.observe(e.body,{childList:!0,subtree:!0})};e.body?n():e.addEventListener("DOMContentLoaded",n,{once:!0})}function bt(e=G??document){q&&(q=!1,e.removeEventListener("shown.bs.collapse",Ie),e.removeEventListener("hidden.bs.collapse",ye),U?.disconnect(),U=void 0,G=void 0)}const j={fallbackToNative:!0},Ne=new Set(["dialog","confirm","toast","openDialog","closeDialog","addErrorMessage","addMessage","clearMessages"]);function ht(e){const n=Ae;return new Proxy(e,{get(t,o,r){return typeof o=="string"&&Ne.has(o)?n[o]:Reflect.get(t,o,r)},has(t,o){return typeof o=="string"&&Ne.has(o)?!0:Reflect.has(t,o)}})}const i={installed:!1,options:j};function K(){return globalThis.window}function Et(e,n){return{bootstrap:e.bootstrap??n?.bootstrap,fallbackToNative:e.fallbackToNative??j.fallbackToNative,runtime:e.runtime??i.options.runtime??n?.Haori?.runtime,toastContainerSelector:e.toastContainerSelector??i.options.toastContainerSelector,dialogContainerSelector:e.dialogContainerSelector??i.options.dialogContainerSelector,dialogTitle:e.dialogTitle??i.options.dialogTitle,dialogOkLabel:e.dialogOkLabel??i.options.dialogOkLabel,dialogCancelLabel:e.dialogCancelLabel??i.options.dialogCancelLabel,toastPosition:e.toastPosition??i.options.toastPosition,toastDelay:e.toastDelay??i.options.toastDelay}}function ke(e=K()){return!!(e?.Haori&&e.bootstrap)}function He(e={}){const n=K();if(!n?.Haori)throw new Error("window.Haori is required before calling install().");if(i.originalHaori||(i.originalHaori=n.Haori,i.originalRuntime=n.Haori.runtime),i.options=Et(e,n),i.options.runtime){const t=i.originalHaori??n.Haori;typeof t.setRuntime=="function"?t.setRuntime(i.options.runtime):console.warn("[haori-bootstrap] Haori.setRuntime が利用できません。runtime 設定は無視されます。")}ct({originalHaori:i.originalHaori,options:i.options}),n.Haori=ht(i.originalHaori),mt(),Qe(),i.installed=!0}function vt(){const e=K();if(!e||!i.originalHaori)return;const n=i.originalHaori;typeof n.setRuntime=="function"?n.setRuntime(i.originalRuntime):n.runtime=i.originalRuntime,e.Haori=i.originalHaori,bt(),Ye(),i.installed=!1,i.originalHaori=void 0,i.originalRuntime=void 0,i.options=j}function pt(){return i.installed}const Re="__haoriJsBootstrapAutoEnabled__";function Tt(){return globalThis.window}function gt(e){return!!e[Re]}function At(e){e[Re]=!0}function wt(){const e=Tt();if(!(!e||gt(e))){if(!ke(e)){console.warn("[haori-bootstrap] Auto-enable skipped because window.Haori or window.bootstrap is missing.");return}try{He({bootstrap:e.bootstrap}),At(e)}catch(n){console.warn("[haori-bootstrap] Auto-enable failed.",n)}}}wt();const Ct="0.5.23";return E.BootstrapHaori=Ae,E.hasAutoEnablePrerequisites=ke,E.install=He,E.isInstalled=pt,E.uninstall=vt,E.version=Ct,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"}),E})({});
|
|
3
3
|
//# sourceMappingURL=haori-bootstrap.iife.js.map
|