haori-bootstrap 0.4.0 → 0.5.0
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 +36 -7
- package/README.md +37 -8
- package/dist/collapse_persist.d.ts +1 -1
- package/dist/haori-bootstrap.iife.js +2 -2
- package/dist/haori-bootstrap.iife.js.map +1 -1
- package/dist/haori-bootstrap.js +345 -345
- package/dist/haori-bootstrap.js.map +1 -1
- package/dist/index.d.ts +1 -1
- 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
|
+
Version: 0.5.0
|
|
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.
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/haori@0.19.0/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.
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/haori-bootstrap@0.5.0/dist/haori-bootstrap.iife.js"></script>
|
|
47
47
|
```
|
|
48
48
|
|
|
49
49
|
IIFE 版は、window.Haori と window.bootstrap が利用可能な場合に自動で有効化されます。
|
|
@@ -117,11 +117,11 @@ install({
|
|
|
117
117
|
|
|
118
118
|
## collapse 開閉状態の永続化
|
|
119
119
|
|
|
120
|
-
Bootstrap collapse 要素に `data-haori-
|
|
120
|
+
Bootstrap collapse 要素に `data-haori-persist="キー名"` を付与すると、開閉状態を sessionStorage に保存し、ページ再訪時に復元します。
|
|
121
121
|
|
|
122
122
|
```html
|
|
123
123
|
<button data-bs-toggle="collapse" data-bs-target="#sideMenu">メニュー</button>
|
|
124
|
-
<div class="collapse" id="sideMenu" data-haori-
|
|
124
|
+
<div class="collapse" id="sideMenu" data-haori-persist="side-menu">
|
|
125
125
|
...
|
|
126
126
|
</div>
|
|
127
127
|
```
|
|
@@ -133,6 +133,35 @@ Bootstrap collapse 要素に `data-haori-bootstrap-persist="キー名"` を付
|
|
|
133
133
|
- ストレージが使えない環境(プライベートモード等)では黙って無効化し、例外は送出しません。
|
|
134
134
|
- `uninstall()` で監視を解除します。
|
|
135
135
|
|
|
136
|
+
## e2e 向け安定セレクタ
|
|
137
|
+
|
|
138
|
+
`dialog` / `confirm` / `toast` が描画する要素には、文言・ロケールに依存しない安定した識別属性を付与しています。Playwright などの e2e テストでは、表示文言やボタン名ではなくこれらの属性でセレクタを組むことを推奨します(文言変更やロケール差で壊れません)。
|
|
139
|
+
|
|
140
|
+
| 要素 | 属性 | 値 |
|
|
141
|
+
| ---- | ---- | ---- |
|
|
142
|
+
| トーストルート | `data-haori-toast` | `"true"` |
|
|
143
|
+
| トーストのレベル | `data-haori-toast-level` | `"success"` \| `"warning"` \| `"error"` \| `"info"` |
|
|
144
|
+
| トーストの閉じるボタン | `data-haori-toast-dismiss` | `"true"` |
|
|
145
|
+
| トーストコンテナ | `data-haori-toast-container` | `"true"` |
|
|
146
|
+
| 情報ダイアログのルート | `data-haori-dialog` | `"true"` |
|
|
147
|
+
| 情報ダイアログの OK ボタン | `data-haori-dialog-ok` | `"true"` |
|
|
148
|
+
| 確認ダイアログのルート | `data-haori-confirm` | `"true"` |
|
|
149
|
+
| 確認ダイアログの OK ボタン | `data-haori-confirm-ok` | `"true"` |
|
|
150
|
+
| 確認ダイアログのキャンセルボタン | `data-haori-confirm-cancel` | `"true"` |
|
|
151
|
+
| ダイアログのタイトル | `data-haori-dialog-title` | `"true"` |
|
|
152
|
+
| 管理対象メッセージのコンテナ | `data-haori-message-container` | `"true"` |
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
// 例: 文言に依存せず確認ダイアログを操作する
|
|
156
|
+
await page.locator('[data-haori-confirm-ok="true"]').click();
|
|
157
|
+
|
|
158
|
+
// 例: トーストのレベルを検証する
|
|
159
|
+
await expect(page.locator('[data-haori-toast="true"]').last())
|
|
160
|
+
.toHaveAttribute('data-haori-toast-level', 'success');
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
> 上記属性は安定した公開契約として維持します。情報ダイアログ (`data-haori-dialog`) と確認ダイアログ (`data-haori-confirm`) はルート属性で区別できます。
|
|
164
|
+
|
|
136
165
|
## Build & Publish
|
|
137
166
|
|
|
138
167
|
ローカル確認手順:
|
|
@@ -157,12 +186,12 @@ push 後に、そのタグから GitHub Release を published にします。公
|
|
|
157
186
|
次回 patch リリースの例:
|
|
158
187
|
|
|
159
188
|
```bash
|
|
160
|
-
# version が 0.
|
|
189
|
+
# version が 0.5.1 になる
|
|
161
190
|
npm version patch
|
|
162
191
|
git push origin main --follow-tags
|
|
163
192
|
```
|
|
164
193
|
|
|
165
|
-
その後、push 済みタグの GitHub Release を作成して published にします。例として次回は `0.
|
|
194
|
+
その後、push 済みタグの GitHub Release を作成して published にします。例として次回は `0.5.1` タグになります。
|
|
166
195
|
|
|
167
196
|
自動公開:
|
|
168
197
|
|
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
|
+
Version: 0.5.0
|
|
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.
|
|
44
|
+
<script src="https://cdn.jsdelivr.net/npm/haori@0.19.0/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.
|
|
46
|
+
<script src="https://cdn.jsdelivr.net/npm/haori-bootstrap@0.5.0/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.
|
|
@@ -117,11 +117,11 @@ Existing Procedure flows can keep using data-click-* and data-click-*-message at
|
|
|
117
117
|
|
|
118
118
|
## Persisting collapse state
|
|
119
119
|
|
|
120
|
-
Add `data-haori-
|
|
120
|
+
Add `data-haori-persist="key"` to a Bootstrap collapse element to persist its open/closed state in `sessionStorage` and restore it on the next visit.
|
|
121
121
|
|
|
122
122
|
```html
|
|
123
123
|
<button data-bs-toggle="collapse" data-bs-target="#sideMenu">Menu</button>
|
|
124
|
-
<div class="collapse" id="sideMenu" data-haori-
|
|
124
|
+
<div class="collapse" id="sideMenu" data-haori-persist="side-menu">
|
|
125
125
|
...
|
|
126
126
|
</div>
|
|
127
127
|
```
|
|
@@ -133,6 +133,35 @@ Add `data-haori-bootstrap-persist="key"` to a Bootstrap collapse element to pers
|
|
|
133
133
|
- When storage is unavailable (e.g. private mode) the feature silently disables itself and never throws.
|
|
134
134
|
- `uninstall()` removes the listeners and observer.
|
|
135
135
|
|
|
136
|
+
## Stable selectors for e2e
|
|
137
|
+
|
|
138
|
+
The elements rendered by `dialog` / `confirm` / `toast` carry stable identifier attributes that do not depend on wording or locale. In e2e tests (e.g. Playwright), prefer building selectors from these attributes instead of visible text or button names — they survive copy changes and localization.
|
|
139
|
+
|
|
140
|
+
| Element | Attribute | Value |
|
|
141
|
+
| ---- | ---- | ---- |
|
|
142
|
+
| Toast root | `data-haori-toast` | `"true"` |
|
|
143
|
+
| Toast level | `data-haori-toast-level` | `"success"` \| `"warning"` \| `"error"` \| `"info"` |
|
|
144
|
+
| Toast dismiss button | `data-haori-toast-dismiss` | `"true"` |
|
|
145
|
+
| Toast container | `data-haori-toast-container` | `"true"` |
|
|
146
|
+
| Info dialog root | `data-haori-dialog` | `"true"` |
|
|
147
|
+
| Info dialog OK button | `data-haori-dialog-ok` | `"true"` |
|
|
148
|
+
| Confirm dialog root | `data-haori-confirm` | `"true"` |
|
|
149
|
+
| Confirm dialog OK button | `data-haori-confirm-ok` | `"true"` |
|
|
150
|
+
| Confirm dialog cancel button | `data-haori-confirm-cancel` | `"true"` |
|
|
151
|
+
| Dialog title | `data-haori-dialog-title` | `"true"` |
|
|
152
|
+
| Managed message container | `data-haori-message-container` | `"true"` |
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
// Operate the confirm dialog without depending on wording
|
|
156
|
+
await page.locator('[data-haori-confirm-ok="true"]').click();
|
|
157
|
+
|
|
158
|
+
// Assert the toast level
|
|
159
|
+
await expect(page.locator('[data-haori-toast="true"]').last())
|
|
160
|
+
.toHaveAttribute('data-haori-toast-level', 'success');
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
> These attributes are maintained as a stable public contract. Info dialogs (`data-haori-dialog`) and confirm dialogs (`data-haori-confirm`) are distinguished by their root attribute.
|
|
164
|
+
|
|
136
165
|
## Build & Publish
|
|
137
166
|
|
|
138
167
|
Local verification:
|
|
@@ -154,15 +183,15 @@ git push origin main --follow-tags
|
|
|
154
183
|
|
|
155
184
|
After pushing, publish a GitHub Release from the generated version tag. The release workflow then publishes the package and uploads `dist.zip` automatically.
|
|
156
185
|
|
|
157
|
-
Example next patch release after `0.
|
|
186
|
+
Example next patch release after `0.5.0`:
|
|
158
187
|
|
|
159
188
|
```bash
|
|
160
|
-
# version becomes 0.
|
|
189
|
+
# version becomes 0.5.1
|
|
161
190
|
npm version patch
|
|
162
191
|
git push origin main --follow-tags
|
|
163
192
|
```
|
|
164
193
|
|
|
165
|
-
Create and publish the GitHub Release for the pushed tag such as `0.
|
|
194
|
+
Create and publish the GitHub Release for the pushed tag such as `0.5.1`.
|
|
166
195
|
|
|
167
196
|
Release automation:
|
|
168
197
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Bootstrap collapse の開閉状態を sessionStorage へ永続化する。
|
|
3
3
|
*
|
|
4
|
-
* `data-haori-
|
|
4
|
+
* `data-haori-persist="キー名"` を collapse 要素(`.collapse`)に付与すると、
|
|
5
5
|
* `shown.bs.collapse` / `hidden.bs.collapse` を監視して開閉状態を保存し、ページ再訪時や
|
|
6
6
|
* `data-import` で後から挿入されたフラグメントにも保存済みの状態を復元する。
|
|
7
7
|
*
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var HaoriBootstrap=(function(p){"use strict";function G(e){return typeof e=="function"}function V(e){return G(e?.Modal)?e?.Modal:void 0}function j(e){return G(e?.Toast)?e?.Toast:void 0}function N(e){return!!V(e)}function Ce(e){return!!j(e)}function k(e,t,o){const n=V(o);if(n)return typeof n.getOrCreateInstance=="function"?n.getOrCreateInstance(e,t):new n(e,t)}function we(e,t,o){const n=j(o);if(n)return typeof n.getOrCreateInstance=="function"?n.getOrCreateInstance(e,t):new n(e,t)}const Se="data-haori-bootstrap-dialog",w="data-haori-bootstrap-action",ye="data-haori-bootstrap-dialog-title";let Me=0;function K(){return{backdrop:"static",keyboard:!1}}function J(e,t){if(t.dialogContainerSelector){const o=e.querySelector(t.dialogContainerSelector);if(o)return o}return e.body}function X(e,t,o,n){const r=e.createElement("div");r.className="modal fade",r.tabIndex=-1,r.setAttribute(Se,"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",n){const u=`haori-dialog-title-${++Me}`,g=e.createElement("div");g.className="modal-header";const L=e.createElement("h5");L.className="modal-title",L.id=u,L.setAttribute(ye,"true"),L.textContent=n,g.appendChild(L),c.appendChild(g),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=t,a.appendChild(d);const l=e.createElement("div");if(l.className="modal-footer",o){const u=e.createElement("button");u.type="button",u.className="btn btn-secondary",u.setAttribute(w,"cancel"),u.textContent="Cancel",l.appendChild(u)}const b=e.createElement("button");return b.type="button",b.className="btn btn-primary",b.setAttribute(w,"ok"),b.textContent="OK",l.appendChild(b),c.append(a,l),i.appendChild(c),r.appendChild(i),r}function Ie(e,t){const o=globalThis.document,n=X(o,e,!1,t.dialogTitle);J(o,t).appendChild(n);const r=k(n,K(),t.bootstrap);return r?new Promise((i,c)=>{const a=()=>{n.removeEventListener("hidden.bs.modal",d),n.remove(),r.dispose?.(),i()},d=()=>{a()};n.querySelector(`[${w}="ok"]`)?.addEventListener("click",()=>{r.hide()},{once:!0}),n.addEventListener("hidden.bs.modal",d,{once:!0});try{r.show()}catch(b){n.removeEventListener("hidden.bs.modal",d),n.remove(),r.dispose?.(),c(b)}}):(n.remove(),Promise.reject(new Error("Bootstrap Modal is unavailable.")))}function Le(e,t){const o=globalThis.document,n=X(o,e,!0,t.dialogTitle);J(o,t).appendChild(n);const r=k(n,K(),t.bootstrap);return r?new Promise((i,c)=>{let a=!1;const d=()=>{n.removeEventListener("hidden.bs.modal",l),n.remove(),r.dispose?.(),i(a)},l=()=>{d()},b=n.querySelector(`[${w}="ok"]`),u=n.querySelector(`[${w}="cancel"]`);b?.addEventListener("click",()=>{a=!0,r.hide()},{once:!0}),u?.addEventListener("click",()=>{a=!1,r.hide()},{once:!0}),n.addEventListener("hidden.bs.modal",l,{once:!0});try{r.show()}catch(g){n.removeEventListener("hidden.bs.modal",l),n.remove(),r.dispose?.(),c(g)}}):(n.remove(),Promise.reject(new Error("Bootstrap Modal is unavailable.")))}const h="data-haori-bootstrap-owned",m="data-haori-bootstrap-message-container",A="data-haori-bootstrap-invalid-target",S="data-haori-bootstrap-valid-target";function y(e){return e instanceof HTMLInputElement&&(e.type==="checkbox"||e.type==="radio")}function E(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(t=>t instanceof HTMLElement&&t.getAttribute(m)==="true")}function Q(e,t){const o=e.createElement("div");return o.setAttribute(h,"true"),o.textContent=t,o}function Y(e){return H(e)}function I(e){if(e.name){const t=e.form??e.ownerDocument,o=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e.name):e.name.replace(/(["\\])/g,"\\$1"),n=Array.from(t.querySelectorAll(`input[type="radio"][name="${o}"]`));if(n.length>0)return n}return[e]}function Ne(e){const[t,...o]=e;if(!t)return;let n=t;for(;n;){if(o.every(r=>n?.contains(r)))return n;n=n.parentElement}}function O(e){const o=I(e).map(n=>n.closest(".form-check")).filter(n=>n instanceof HTMLElement);if(o.length>1){const n=Ne(o);if(n&&!o.includes(n))return n}return B(e)}function B(e){const t=e.closest(".form-check");return t instanceof HTMLElement?t:void 0}function Z(e){const t=e.nextElementSibling;if(t instanceof HTMLElement&&t.getAttribute(m)==="true")return t;const o=document.createElement("div");return o.className="invalid-feedback d-block",o.setAttribute(h,"true"),o.setAttribute(m,"true"),e.insertAdjacentElement("afterend",o),o}function ke(e){const t=E(e)?O(e):B(e);if(!t)return Z(e);const o=H(t);if(o)return o;const n=document.createElement("div");return n.className="invalid-feedback d-block",n.setAttribute(h,"true"),n.setAttribute(m,"true"),t.appendChild(n),n}function He(e){const t=Y(e);if(t)return t;const o=document.createElement("div");return o.className="alert alert-danger",o.setAttribute("role","alert"),o.setAttribute(h,"true"),o.setAttribute(m,"true"),e.insertAdjacentElement("afterbegin",o),o}function v(e){e.getAttribute(A)==="true"&&(e.classList.remove("is-invalid"),e.removeAttribute(A))}function T(e){e.getAttribute(S)==="true"&&(e.classList.remove("is-valid"),e.removeAttribute(S))}function ee(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 R(e){return e==="success"?"valid-feedback d-block":"invalid-feedback d-block"}function te(e){(E(e)?I(e):[e]).forEach(o=>{o.classList.add("is-invalid"),o.setAttribute(A,"true")})}function Be(e){(E(e)?I(e):[e]).forEach(o=>{v(o)})}function oe(e,t){const o=e.nextElementSibling;if(o instanceof HTMLElement&&o.getAttribute(m)==="true")return o.className=R(t),o;const n=document.createElement("div");return n.className=R(t),n.setAttribute(h,"true"),n.setAttribute(m,"true"),e.insertAdjacentElement("afterend",n),n}function Re(e,t){const o=E(e)?O(e):B(e);if(!o)return oe(e,t);const n=H(o);if(n)return n.className=R(t),n;const r=document.createElement("div");return r.className=R(t),r.setAttribute(h,"true"),r.setAttribute(m,"true"),o.appendChild(r),r}function Pe(e,t){const o=Y(e);if(o)return o.className=ee(t),o;const n=document.createElement("div");return n.className=ee(t),n.setAttribute("role","alert"),n.setAttribute(h,"true"),n.setAttribute(m,"true"),e.insertAdjacentElement("afterbegin",n),n}function De(e,t){return(y(e)?ke(e):M(e)?Z(e):He(e)).appendChild(Q(document,t)),y(e)?te(e):M(e)&&(e.classList.add("is-invalid"),e.setAttribute(A,"true")),Promise.resolve()}function _e(e,t,o){if((y(e)?Re(e,o):M(e)?oe(e,o):Pe(e,o)).appendChild(Q(document,t)),y(e)){const r=E(e)?I(e):[e];o==="success"?r.forEach(i=>{v(i),i.classList.add("is-valid"),i.setAttribute(S,"true")}):!o||o==="error"?(r.forEach(i=>T(i)),te(e)):r.forEach(i=>{T(i),v(i)})}else M(e)&&(o==="success"?(v(e),e.classList.add("is-valid"),e.setAttribute(S,"true")):!o||o==="error"?(T(e),e.classList.add("is-invalid"),e.setAttribute(A,"true")):(T(e),v(e)));return Promise.resolve()}function xe(e){if(y(e)){const r=E(e)?O(e):B(e);(r?H(r):void 0)?.remove(),Be(e),(E(e)?I(e):[e]).forEach(a=>T(a))}else if(M(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(`[${A}="true"]`).forEach(r=>{v(r)}),e.querySelectorAll(`[${S}="true"]`).forEach(r=>{T(r)}),Promise.resolve()}function ne(e){e.classList.contains("modal")||e.classList.add("modal"),e.tabIndex<0&&(e.tabIndex=-1),e.hasAttribute("aria-hidden")||e.setAttribute("aria-hidden","true")}function $e(e,t){ne(e);const o=k(e,void 0,t.bootstrap);return o?(o.show(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}function qe(e,t){ne(e);const o=k(e,void 0,t.bootstrap);return o?(o.hide(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}const re="data-haori-bootstrap-toast-container",Oe="data-haori-bootstrap-toast",Ue="data-haori-bootstrap-toast-accent",Fe="data-haori-bootstrap-toast-dismiss",ie={"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 ze(e){switch(e){case"success":return{accentClassName:"bg-success"};case"warning":return{accentClassName:"bg-warning"};case"error":return{accentClassName:"bg-danger"};default:return{accentClassName:"bg-info"}}}function We(e,t){if(t.toastContainerSelector){const o=e.querySelector(t.toastContainerSelector);if(o)return o}return e.body}function Ge(e,t){const o=We(e,t),n=ie[t.toastPosition??"bottom-end"],r=o.querySelector(`[${re}="true"]`);if(r){const c=Object.values(ie).flatMap(a=>a.split(" "));return r.classList.remove(...c),r.classList.add(...n.split(" ")),r}const i=e.createElement("div");return i.className=`toast-container position-fixed ${n} p-3`,i.setAttribute(re,"true"),o.appendChild(i),i}function Ve(e,t,o){const n=globalThis.document,r=ze(t),i=n.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(Oe,"true");const c=n.createElement("div");c.className="d-flex align-items-stretch";const a=n.createElement("div");a.className=`flex-shrink-0 rounded-start ${r.accentClassName}`,a.style.width="0.375rem",a.setAttribute(Ue,"true");const d=n.createElement("div");d.className="toast-body",d.style.whiteSpace="pre-line",d.textContent=e;const l=n.createElement("button");l.type="button",l.className="btn-close me-2 m-auto flex-shrink-0",l.setAttribute("aria-label","Close"),l.setAttribute(Fe,"true"),c.appendChild(a),c.appendChild(d),c.appendChild(l),i.appendChild(c),Ge(n,o).appendChild(i);const b=o.toastDelay!==void 0?{delay:o.toastDelay}:void 0,u=we(i,b,o.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(g){return i.remove(),u.dispose?.(),Promise.reject(g)}}let f={options:{fallbackToNative:!0}};function C(e){return e.replace(/\\n/g,`
|
|
2
|
-
`)}function
|
|
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 V(e){return W(e?.Toast)?e?.Toast:void 0}function L(e){return!!G(e)}function Se(e){return!!V(e)}function N(e,t,n){const o=G(n);if(o)return typeof o.getOrCreateInstance=="function"?o.getOrCreateInstance(e,t):new o(e,t)}function ye(e,t,n){const o=V(n);if(o)return typeof o.getOrCreateInstance=="function"?o.getOrCreateInstance(e,t):new o(e,t)}const Ie="data-haori-dialog",Me="data-haori-confirm",Le="data-haori-dialog-title",K="data-haori-dialog-ok",j="data-haori-confirm-ok",J="data-haori-confirm-cancel";let Ne=0;function X(){return{backdrop:"static",keyboard:!1}}function Q(e,t){if(t.dialogContainerSelector){const n=e.querySelector(t.dialogContainerSelector);if(n)return n}return e.body}function Y(e,t,n,o){const r=e.createElement("div");r.className="modal fade",r.tabIndex=-1,r.setAttribute(n?Me:Ie,"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-${++Ne}`,A=e.createElement("div");A.className="modal-header";const M=e.createElement("h5");M.className="modal-title",M.id=u,M.setAttribute(Le,"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=t,a.appendChild(d);const l=e.createElement("div");if(l.className="modal-footer",n){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(n?j:K,"true"),b.textContent="OK",l.appendChild(b),c.append(a,l),i.appendChild(c),r.appendChild(i),r}function He(e,t){const n=globalThis.document,o=Y(n,e,!1,t.dialogTitle);Q(n,t).appendChild(o);const r=N(o,X(),t.bootstrap);return r?new Promise((i,c)=>{const a=()=>{o.removeEventListener("hidden.bs.modal",d),o.remove(),r.dispose?.(),i()},d=()=>{a()};o.querySelector(`[${K}]`)?.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 ke(e,t){const n=globalThis.document,o=Y(n,e,!0,t.dialogTitle);Q(n,t).appendChild(o);const r=N(o,X(),t.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(`[${j}]`),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(t=>t instanceof HTMLElement&&t.getAttribute(m)==="true")}function Z(e,t){const n=e.createElement("div");return n.setAttribute(p,"true"),n.textContent=t,n}function ee(e){return H(e)}function I(e){if(e.name){const t=e.form??e.ownerDocument,n=typeof CSS<"u"&&typeof CSS.escape=="function"?CSS.escape(e.name):e.name.replace(/(["\\])/g,"\\$1"),o=Array.from(t.querySelectorAll(`input[type="radio"][name="${n}"]`));if(o.length>0)return o}return[e]}function Be(e){const[t,...n]=e;if(!t)return;let o=t;for(;o;){if(n.every(r=>o?.contains(r)))return o;o=o.parentElement}}function $(e){const n=I(e).map(o=>o.closest(".form-check")).filter(o=>o instanceof HTMLElement);if(n.length>1){const o=Be(n);if(o&&!n.includes(o))return o}return k(e)}function k(e){const t=e.closest(".form-check");return t instanceof HTMLElement?t:void 0}function te(e){const t=e.nextElementSibling;if(t instanceof HTMLElement&&t.getAttribute(m)==="true")return t;const n=document.createElement("div");return n.className="invalid-feedback d-block",n.setAttribute(p,"true"),n.setAttribute(m,"true"),e.insertAdjacentElement("afterend",n),n}function Re(e){const t=E(e)?$(e):k(e);if(!t)return te(e);const n=H(t);if(n)return n;const o=document.createElement("div");return o.className="invalid-feedback d-block",o.setAttribute(p,"true"),o.setAttribute(m,"true"),t.appendChild(o),o}function _e(e){const t=ee(e);if(t)return t;const n=document.createElement("div");return n.className="alert alert-danger",n.setAttribute("role","alert"),n.setAttribute(p,"true"),n.setAttribute(m,"true"),e.insertAdjacentElement("afterbegin",n),n}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(n=>{n.classList.add("is-invalid"),n.setAttribute(g,"true")})}function Pe(e){(E(e)?I(e):[e]).forEach(n=>{v(n)})}function re(e,t){const n=e.nextElementSibling;if(n instanceof HTMLElement&&n.getAttribute(m)==="true")return n.className=B(t),n;const o=document.createElement("div");return o.className=B(t),o.setAttribute(p,"true"),o.setAttribute(m,"true"),e.insertAdjacentElement("afterend",o),o}function De(e,t){const n=E(e)?$(e):k(e);if(!n)return re(e,t);const o=H(n);if(o)return o.className=B(t),o;const r=document.createElement("div");return r.className=B(t),r.setAttribute(p,"true"),r.setAttribute(m,"true"),n.appendChild(r),r}function xe(e,t){const n=ee(e);if(n)return n.className=ne(t),n;const o=document.createElement("div");return o.className=ne(t),o.setAttribute("role","alert"),o.setAttribute(p,"true"),o.setAttribute(m,"true"),e.insertAdjacentElement("afterbegin",o),o}function Oe(e,t){return(S(e)?Re(e):y(e)?te(e):_e(e)).appendChild(Z(document,t)),S(e)?oe(e):y(e)&&(e.classList.add("is-invalid"),e.setAttribute(g,"true")),Promise.resolve()}function $e(e,t,n){if((S(e)?De(e,n):y(e)?re(e,n):xe(e,n)).appendChild(Z(document,t)),S(e)){const r=E(e)?I(e):[e];n==="success"?r.forEach(i=>{v(i),i.classList.add("is-valid"),i.setAttribute(w,"true")}):!n||n==="error"?(r.forEach(i=>T(i)),oe(e)):r.forEach(i=>{T(i),v(i)})}else y(e)&&(n==="success"?(v(e),e.classList.add("is-valid"),e.setAttribute(w,"true")):!n||n==="error"?(T(e),e.classList.add("is-invalid"),e.setAttribute(g,"true")):(T(e),v(e)));return Promise.resolve()}function Ue(e){if(S(e)){const r=E(e)?$(e):k(e);(r?H(r):void 0)?.remove(),Pe(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 ie(e){e.classList.contains("modal")||e.classList.add("modal"),e.tabIndex<0&&(e.tabIndex=-1),e.hasAttribute("aria-hidden")||e.setAttribute("aria-hidden","true")}function qe(e,t){ie(e);const n=N(e,void 0,t.bootstrap);return n?(n.show(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}function Fe(e,t){ie(e);const n=N(e,void 0,t.bootstrap);return n?(n.hide(),Promise.resolve()):Promise.reject(new Error("Bootstrap Modal is unavailable."))}const se="data-haori-toast-container",ze="data-haori-toast",We="data-haori-toast-level",Ge="data-haori-toast-accent",Ve="data-haori-toast-dismiss",ae={"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,t){if(t.toastContainerSelector){const n=e.querySelector(t.toastContainerSelector);if(n)return n}return e.body}function Je(e,t){const n=je(e,t),o=ae[t.toastPosition??"bottom-end"],r=n.querySelector(`[${se}="true"]`);if(r){const c=Object.values(ae).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(se,"true"),n.appendChild(i),i}function Xe(e,t,n){const o=globalThis.document,r=Ke(t),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(ze,"true"),i.setAttribute(We,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(Ge,"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),Je(o,n).appendChild(i);const b=n.toastDelay!==void 0?{delay:n.toastDelay}:void 0,u=ye(i,b,n.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 ce(){return globalThis.window}function U(e){return Promise.resolve(e).then(()=>{})}function R(e){const t=f.originalHaori?.[e];return typeof t=="function"?t:void 0}function _(e){console.warn(`[haori-bootstrap] ${e} skipped because Bootstrap support is unavailable.`)}function le(e){const t=C(e),n=R("dialog");if(n)return U(n(t));const o=ce();return f.options.fallbackToNative&&typeof o?.alert=="function"?(o.alert(t),Promise.resolve()):(_("dialog"),Promise.resolve())}function ue(e){const t=C(e),n=R("confirm");if(n)return Promise.resolve(n(t)).then(r=>!!r);const o=ce();return f.options.fallbackToNative&&typeof o?.confirm=="function"?Promise.resolve(o.confirm(t)):(_("confirm"),Promise.resolve(!1))}function de(e,t){const n=C(e),o=R("toast");return o?U(o(n,t)):(_("toast"),Promise.resolve())}function P(e,t){const n=R(e);return n?U(n(t)):(_(e),Promise.resolve())}function Qe(e){f=e}class fe{static dialog(t){const n=C(t);return L(f.options.bootstrap)?He(n,f.options).catch(()=>le(n)):le(n)}static confirm(t){const n=C(t);return L(f.options.bootstrap)?ke(n,f.options).catch(()=>ue(n)):ue(n)}static toast(t,n){const o=C(t);return Se(f.options.bootstrap)?Xe(o,n,f.options).catch(()=>de(o,n)):de(o,n)}static openDialog(t){return L(f.options.bootstrap)?qe(t,f.options).catch(()=>P("openDialog",t)):P("openDialog",t)}static closeDialog(t){return L(f.options.bootstrap)?Fe(t,f.options).catch(()=>P("closeDialog",t)):P("closeDialog",t)}static addErrorMessage(t,n){return Oe(t,n)}static addMessage(t,n,o){return $e(t,n,o)}static clearMessages(t){return Ue(t)}}const Ye="haori-bootstrap:collapse:",D="data-haori-persist";let x=!1,O,q;function me(e){return Ye+e}function Ze(e){try{const t=window.sessionStorage.getItem(me(e));return t==="shown"||t==="hidden"?t:void 0}catch{return}}function et(e,t){try{window.sessionStorage.setItem(me(e),t)}catch{}}function be(e,t){const n=e.id,o=[`[data-bs-toggle="collapse"][data-bs-target="#${n}"]`];if(n&&o.push(`[data-bs-toggle="collapse"][href="#${n}"]`),!n)return;e.ownerDocument.querySelectorAll(o.join(",")).forEach(i=>{i.setAttribute("aria-expanded",t?"true":"false"),i.classList.toggle("collapsed",!t)})}function he(e){const t=e.getAttribute(D);if(!t)return;const n=Ze(t);if(!n)return;const o=e.classList.contains("show");n==="shown"&&!o?(e.classList.add("show"),be(e,!0)):n==="hidden"&&o&&(e.classList.remove("show"),be(e,!1))}function pe(e){e instanceof HTMLElement&&e.hasAttribute(D)&&he(e),e.querySelectorAll(`[${D}]`).forEach(he)}function Ee(e,t){const n=e.target;if(!(n instanceof HTMLElement))return;const o=n.getAttribute(D);o&&et(o,t)}const ve=e=>Ee(e,"shown"),Te=e=>Ee(e,"hidden");function tt(e=document){if(x)return;x=!0,q=e,e.addEventListener("shown.bs.collapse",ve),e.addEventListener("hidden.bs.collapse",Te);const t=()=>{pe(e),O=new MutationObserver(n=>{for(const o of n)o.addedNodes.forEach(r=>{r instanceof HTMLElement&&pe(r)})}),e.body&&O.observe(e.body,{childList:!0,subtree:!0})};e.body?t():e.addEventListener("DOMContentLoaded",t,{once:!0})}function nt(e=q??document){x&&(x=!1,e.removeEventListener("shown.bs.collapse",ve),e.removeEventListener("hidden.bs.collapse",Te),O?.disconnect(),O=void 0,q=void 0)}const F={fallbackToNative:!0},Ae=new Set(["dialog","confirm","toast","openDialog","closeDialog","addErrorMessage","addMessage","clearMessages"]);function ot(e){const t=fe;return new Proxy(e,{get(n,o,r){return typeof o=="string"&&Ae.has(o)?t[o]:Reflect.get(n,o,r)},has(n,o){return typeof o=="string"&&Ae.has(o)?!0:Reflect.has(n,o)}})}const s={installed:!1,options:F};function z(){return globalThis.window}function rt(e,t){return{bootstrap:e.bootstrap??t?.bootstrap,fallbackToNative:e.fallbackToNative??F.fallbackToNative,runtime:e.runtime??s.options.runtime??t?.Haori?.runtime,toastContainerSelector:e.toastContainerSelector??s.options.toastContainerSelector,dialogContainerSelector:e.dialogContainerSelector??s.options.dialogContainerSelector,dialogTitle:e.dialogTitle??s.options.dialogTitle,toastPosition:e.toastPosition??s.options.toastPosition,toastDelay:e.toastDelay??s.options.toastDelay}}function ge(e=z()){return!!(e?.Haori&&e.bootstrap)}function Ce(e={}){const t=z();if(!t?.Haori)throw new Error("window.Haori is required before calling install().");if(s.originalHaori||(s.originalHaori=t.Haori,s.originalRuntime=t.Haori.runtime),s.options=rt(e,t),s.options.runtime){const n=s.originalHaori??t.Haori;typeof n.setRuntime=="function"?n.setRuntime(s.options.runtime):console.warn("[haori-bootstrap] Haori.setRuntime が利用できません。runtime 設定は無視されます。")}Qe({originalHaori:s.originalHaori,options:s.options}),t.Haori=ot(s.originalHaori),tt(),s.installed=!0}function it(){const e=z();if(!e||!s.originalHaori)return;const t=s.originalHaori;typeof t.setRuntime=="function"?t.setRuntime(s.originalRuntime):t.runtime=s.originalRuntime,e.Haori=s.originalHaori,nt(),s.installed=!1,s.originalHaori=void 0,s.originalRuntime=void 0,s.options=F}function st(){return s.installed}const we="__haoriJsBootstrapAutoEnabled__";function at(){return globalThis.window}function ct(e){return!!e[we]}function lt(e){e[we]=!0}function ut(){const e=at();if(!(!e||ct(e))){if(!ge(e)){console.warn("[haori-bootstrap] Auto-enable skipped because window.Haori or window.bootstrap is missing.");return}try{Ce({bootstrap:e.bootstrap}),lt(e)}catch(t){console.warn("[haori-bootstrap] Auto-enable failed.",t)}}}ut();const dt="0.5.0";return h.BootstrapHaori=fe,h.hasAutoEnablePrerequisites=ge,h.install=Ce,h.isInstalled=st,h.uninstall=it,h.version=dt,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"}),h})({});
|
|
3
3
|
//# sourceMappingURL=haori-bootstrap.iife.js.map
|