sodialog 0.1.13 → 0.1.14
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.md +52 -0
- package/dist/favicon.ico +0 -0
- package/dist/logo.ico +0 -0
- package/dist/sodialog.css +1 -1
- package/dist/sodialog.es.js +514 -194
- package/dist/sodialog.umd.js +1 -1
- package/dist/types/lib.d.ts +71 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,6 +34,18 @@ openOffcanvas({
|
|
|
34
34
|
animation: 'slide',
|
|
35
35
|
content: '<p>这是 Offcanvas</p>',
|
|
36
36
|
})
|
|
37
|
+
|
|
38
|
+
// Toast
|
|
39
|
+
import { toast } from 'sodialog'
|
|
40
|
+
|
|
41
|
+
toast({
|
|
42
|
+
title: '保存成功',
|
|
43
|
+
content: '配置已更新',
|
|
44
|
+
placement: 'top-end',
|
|
45
|
+
variant: 'success',
|
|
46
|
+
duration: 2500,
|
|
47
|
+
maxVisible: 3,
|
|
48
|
+
})
|
|
37
49
|
```
|
|
38
50
|
|
|
39
51
|
## API
|
|
@@ -143,6 +155,35 @@ openOffcanvas({ title: 'Bottom', placement: 'bottom', animation: 'zoom', content
|
|
|
143
155
|
|
|
144
156
|
通用入口,`options.kind` 可为 `modal` 或 `offcanvas`。
|
|
145
157
|
|
|
158
|
+
### `toast(options)` / `SoToast.show(options)`
|
|
159
|
+
|
|
160
|
+
- `content: string | Node`
|
|
161
|
+
- `title?: string`
|
|
162
|
+
- `placement?: 'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end'`(默认 `top-end`)
|
|
163
|
+
- `variant?: 'default' | 'info' | 'success' | 'warning' | 'danger'`(默认 `default`)
|
|
164
|
+
- `duration?: number | false`(默认 `3000`,`false` 表示不自动消失)
|
|
165
|
+
- `showProgress?: boolean`(默认 `true`,显示自动消失倒计时进度条)
|
|
166
|
+
- `maxVisible?: number`(默认 `3`,按同位置队列生效)
|
|
167
|
+
- `closable?: boolean`(默认 `true`)
|
|
168
|
+
- `pauseOnHover?: boolean`(默认 `true`)
|
|
169
|
+
- `pauseOnWindowBlur?: boolean`(默认 `false`,切换窗口时暂停倒计时)
|
|
170
|
+
- `duplicateStrategy?: 'update' | 'ignore' | 'restart-timer' | 'stack'`(默认 `update`)
|
|
171
|
+
- `onShown?: (handle) => void`
|
|
172
|
+
- `onClose?: (reason, handle) => void`
|
|
173
|
+
|
|
174
|
+
队列与控制:
|
|
175
|
+
|
|
176
|
+
- 超过 `maxVisible` 的消息会进入队列,前面的 toast 关闭后自动补位
|
|
177
|
+
- 相同 `id` 再次调用会按 `duplicateStrategy` 处理
|
|
178
|
+
- `update`: 更新内容与配置;若 `placement` 改变会迁移到新位置
|
|
179
|
+
- `ignore`: 保留已有 toast,忽略本次重复调用
|
|
180
|
+
- `restart-timer`: 更新并强制重启倒计时
|
|
181
|
+
- `stack`: 自动生成新 id,保留已有 toast 并叠加新 toast
|
|
182
|
+
- 返回 `handle`,支持 `close / update / pause / resume`
|
|
183
|
+
- 可用 `SoToast.clear(placement?)` 清空指定位置或全部 toast
|
|
184
|
+
- 可用 `SoToast.closeAll()` 清空全部 toast
|
|
185
|
+
- 便捷方法:`SoToast.success/error/info/warning`
|
|
186
|
+
|
|
146
187
|
## 开发
|
|
147
188
|
|
|
148
189
|
```bash
|
|
@@ -152,6 +193,17 @@ npm run build
|
|
|
152
193
|
npm run docs:changelog
|
|
153
194
|
```
|
|
154
195
|
|
|
196
|
+
## GitHub Pages 首页
|
|
197
|
+
|
|
198
|
+
本仓库已将文档主页入口放在 `index.html + src/main.ts`,用于展示开发文档与使用说明。
|
|
199
|
+
|
|
200
|
+
- 本地构建主页:`npm run build:demo`
|
|
201
|
+
- 产物目录:`dist-pages/`
|
|
202
|
+
- 线上部署:`.github/workflows/pages.yml`(推送到 `master` 自动部署)
|
|
203
|
+
- 仓库设置:`Settings -> Pages -> Source` 选择 `GitHub Actions`
|
|
204
|
+
|
|
205
|
+
默认线上地址:`https://sohophp.github.io/sodialog/`
|
|
206
|
+
|
|
155
207
|
## 文档体系
|
|
156
208
|
|
|
157
209
|
- `README.md`:使用方式、API、发布流程总览
|
package/dist/favicon.ico
ADDED
|
Binary file
|
package/dist/logo.ico
ADDED
|
Binary file
|
package/dist/sodialog.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.sod-dialog{border:0;padding:0;margin:auto;background:transparent;max-width:none;max-height:none;overflow:visible}.sod-dialog::backdrop{background:#0000007f}.sod-panel{box-sizing:border-box;background:#fff;color:#212529;border-radius:.5rem;box-shadow:0 .5rem 1rem #00000040;min-width:min(520px,calc(100vw - 2rem));max-width:min(520px,calc(100vw - 2rem))}.sod-modal .sod-panel{position:relative;margin:0}.sod-modal[open]{width:100vw;height:100vh;display:flex;justify-content:center;align-items:center}.sod-modal[open].sod-modal-viewport-scroll{align-items:flex-start;overflow:auto;padding:1rem 0}.sod-modal .sod-panel.sod-modal-pos-center{align-self:center}.sod-modal .sod-panel.sod-modal-pos-top{align-self:flex-start;margin-top:1rem}.sod-modal .sod-panel.sod-modal-pos-bottom{align-self:flex-end;margin-bottom:1rem}.sod-modal .sod-panel.sod-modal-autofit{min-width:0;width:auto;height:auto;max-width:calc(100vw - 2rem);max-height:calc(100vh - 2rem);display:flex;flex-direction:column}.sod-modal .sod-panel.sod-modal-draggable{touch-action:none}.sod-modal .sod-panel.sod-is-dragging{animation:none!important;transition:none!important}.sod-modal .sod-panel .sod-drag-handle{cursor:move;-webkit-user-select:none;user-select:none}.sod-modal .sod-panel .sod-drag-handle.is-dragging{cursor:grabbing}.sod-modal .sod-panel.sod-modal-anim-fade{animation:sod-fade-in .18s ease-out}.sod-modal .sod-panel.sod-modal-anim-fade.is-closing{animation:sod-fade-out .18s ease-in forwards}.sod-modal .sod-panel.sod-modal-anim-zoom{animation:sod-modal-zoom-in .18s ease-out}.sod-modal .sod-panel.sod-modal-anim-zoom.is-closing{animation:sod-modal-zoom-out .18s ease-in forwards}.sod-modal .sod-panel.sod-modal-anim-slide{animation:sod-modal-slide-in .18s ease-out}.sod-modal .sod-panel.sod-modal-anim-slide.is-closing{animation:sod-modal-slide-out .18s ease-in forwards}.sod-header{display:flex;align-items:center;justify-content:space-between;padding:1rem 1rem .75rem;border-bottom:1px solid #dee2e6}.sod-title{margin:0;font-size:1.1rem}.sod-close{border:0;background:transparent;color:#6c757d;font-size:1.5rem;line-height:1;cursor:pointer}.sod-body{box-sizing:border-box;padding:1rem;overflow-wrap:anywhere;word-break:break-word}.sod-body>*{max-width:100%}.sod-body input,.sod-body select,.sod-body textarea,.sod-body button{max-width:100%;box-sizing:border-box}.sod-body img,.sod-body video,.sod-body canvas,.sod-body iframe,.sod-body table{max-width:100%}.sod-modal .sod-panel.sod-modal-autofit .sod-body{flex:1 1 auto;min-height:0}.sod-body p{margin:0 0 .5rem}.sod-body ul{margin:.5rem 0 0;padding-left:1.2rem}.sod-footer{padding:.75rem 1rem 1rem;border-top:1px solid #dee2e6;display:flex;justify-content:flex-end;gap:.5rem}.sod-footer[data-align=start]{justify-content:flex-start}.sod-footer[data-align=center]{justify-content:center}.sod-footer[data-align=between]{justify-content:space-between}.sod-btn{display:inline-flex;align-items:center;justify-content:center;border-radius:.375rem;border:1px solid transparent;padding:.5rem 1rem;font-size:.95rem;font-weight:500;cursor:pointer;transition:all .15s ease-in-out}.sod-btn:focus-visible{outline:2px solid #86b7fe;outline-offset:1px}.sod-btn-primary{background:#0d6efd;color:#fff;border-color:#0d6efd}.sod-btn-primary:hover{background:#0b5ed7;border-color:#0a58ca}.sod-btn-outline{background:transparent;color:#6c757d;border-color:#6c757d}.sod-btn-outline:hover{color:#fff;background:#6c757d}.sod-btn-danger{background:#dc3545;color:#fff;border-color:#dc3545}.sod-btn-danger:hover{background:#bb2d3b;border-color:#b02a37}.sod-btn-success{background:#198754;color:#fff;border-color:#198754}.sod-btn-success:hover{background:#157347;border-color:#146c43}.sod-btn-ghost{background:transparent;color:#495057;border-color:transparent}.sod-btn-ghost:hover{background:#e9ecef}.sod-btn-link{background:transparent;color:#0d6efd;border-color:transparent;text-decoration:underline;text-underline-offset:2px}.sod-btn-link:hover{color:#0a58ca}.sod-offcanvas[open]{width:100vw;height:100vh}.sod-offcanvas .sod-panel{position:fixed;margin:0;min-width:0;max-width:none;border-radius:0;width:min(360px,90vw);height:100vh}.sod-offcanvas .sod-panel.sod-placement-start{left:0;top:0}.sod-offcanvas .sod-panel.sod-placement-end{right:0;top:0}.sod-offcanvas .sod-panel.sod-placement-top{top:0;left:0;width:100vw;height:300px}.sod-offcanvas .sod-panel.sod-placement-bottom{bottom:0;left:0;width:100vw;height:300px}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-start{animation:sod-slide-in-start .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-start.is-closing{animation:sod-slide-out-start .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-end{animation:sod-slide-in-end .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-end.is-closing{animation:sod-slide-out-end .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-top{animation:sod-slide-in-top .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-top.is-closing{animation:sod-slide-out-top .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-bottom{animation:sod-slide-in-bottom .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-bottom.is-closing{animation:sod-slide-out-bottom .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-fade{animation:sod-fade-in .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-fade.is-closing{animation:sod-fade-out .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-zoom{animation:sod-zoom-in .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-zoom.is-closing{animation:sod-zoom-out .18s ease-in forwards}@keyframes sod-modal-zoom-in{0%{opacity:0;transform:scale(.96)}to{opacity:1;transform:scale(1)}}@keyframes sod-modal-zoom-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.96)}}@keyframes sod-modal-slide-in{0%{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:translateY(0)}}@keyframes sod-modal-slide-out{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-12px)}}@keyframes sod-slide-in-start{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes sod-slide-out-start{0%{transform:translate(0)}to{transform:translate(-100%)}}@keyframes sod-slide-in-end{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes sod-slide-out-end{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes sod-slide-in-top{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes sod-slide-out-top{0%{transform:translateY(0)}to{transform:translateY(-100%)}}@keyframes sod-slide-in-bottom{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes sod-slide-out-bottom{0%{transform:translateY(0)}to{transform:translateY(100%)}}@keyframes sod-fade-in{0%{opacity:0}to{opacity:1}}@keyframes sod-fade-out{0%{opacity:1}to{opacity:0}}@keyframes sod-zoom-in{0%{opacity:0;transform:scale(.96)}to{opacity:1;transform:scale(1)}}@keyframes sod-zoom-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.96)}}
|
|
1
|
+
.sod-dialog{border:0;padding:0;margin:auto;background:transparent;max-width:none;max-height:none;overflow:visible}.sod-dialog::backdrop{background:#0000007f}.sod-panel{box-sizing:border-box;background:#fff;color:#212529;border-radius:.5rem;box-shadow:0 .5rem 1rem #00000040;min-width:min(520px,calc(100vw - 2rem));max-width:min(520px,calc(100vw - 2rem))}.sod-modal .sod-panel{position:relative;margin:0}.sod-modal[open]{width:100vw;height:100vh;display:flex;justify-content:center;align-items:center}.sod-modal[open].sod-modal-viewport-scroll{align-items:flex-start;overflow:auto;padding:1rem 0}.sod-modal .sod-panel.sod-modal-pos-center{align-self:center}.sod-modal .sod-panel.sod-modal-pos-top{align-self:flex-start;margin-top:1rem}.sod-modal .sod-panel.sod-modal-pos-bottom{align-self:flex-end;margin-bottom:1rem}.sod-modal .sod-panel.sod-modal-autofit{min-width:0;width:auto;height:auto;max-width:calc(100vw - 2rem);max-height:calc(100vh - 2rem);display:flex;flex-direction:column}.sod-modal .sod-panel.sod-modal-draggable{touch-action:none}.sod-modal .sod-panel.sod-is-dragging{animation:none!important;transition:none!important}.sod-modal .sod-panel .sod-drag-handle{cursor:move;-webkit-user-select:none;user-select:none}.sod-modal .sod-panel .sod-drag-handle.is-dragging{cursor:grabbing}.sod-modal .sod-panel.sod-modal-anim-fade{animation:sod-fade-in .18s ease-out}.sod-modal .sod-panel.sod-modal-anim-fade.is-closing{animation:sod-fade-out .18s ease-in forwards}.sod-modal .sod-panel.sod-modal-anim-zoom{animation:sod-modal-zoom-in .18s ease-out}.sod-modal .sod-panel.sod-modal-anim-zoom.is-closing{animation:sod-modal-zoom-out .18s ease-in forwards}.sod-modal .sod-panel.sod-modal-anim-slide{animation:sod-modal-slide-in .18s ease-out}.sod-modal .sod-panel.sod-modal-anim-slide.is-closing{animation:sod-modal-slide-out .18s ease-in forwards}.sod-header{display:flex;align-items:center;justify-content:space-between;padding:1rem 1rem .75rem;border-bottom:1px solid #dee2e6}.sod-title{margin:0;font-size:1.1rem}.sod-close{border:0;background:transparent;color:#6c757d;font-size:1.5rem;line-height:1;cursor:pointer}.sod-body{box-sizing:border-box;padding:1rem;overflow-wrap:anywhere;word-break:break-word}.sod-body>*{max-width:100%}.sod-body input,.sod-body select,.sod-body textarea,.sod-body button{max-width:100%;box-sizing:border-box}.sod-body img,.sod-body video,.sod-body canvas,.sod-body iframe,.sod-body table{max-width:100%}.sod-modal .sod-panel.sod-modal-autofit .sod-body{flex:1 1 auto;min-height:0}.sod-body p{margin:0 0 .5rem}.sod-body ul{margin:.5rem 0 0;padding-left:1.2rem}.sod-footer{padding:.75rem 1rem 1rem;border-top:1px solid #dee2e6;display:flex;justify-content:flex-end;gap:.5rem}.sod-footer[data-align=start]{justify-content:flex-start}.sod-footer[data-align=center]{justify-content:center}.sod-footer[data-align=between]{justify-content:space-between}.sod-btn{display:inline-flex;align-items:center;justify-content:center;border-radius:.375rem;border:1px solid transparent;padding:.5rem 1rem;font-size:.95rem;font-weight:500;cursor:pointer;transition:all .15s ease-in-out}.sod-btn:focus-visible{outline:2px solid #86b7fe;outline-offset:1px}.sod-btn-primary{background:#0d6efd;color:#fff;border-color:#0d6efd}.sod-btn-primary:hover{background:#0b5ed7;border-color:#0a58ca}.sod-btn-outline{background:transparent;color:#6c757d;border-color:#6c757d}.sod-btn-outline:hover{color:#fff;background:#6c757d}.sod-btn-danger{background:#dc3545;color:#fff;border-color:#dc3545}.sod-btn-danger:hover{background:#bb2d3b;border-color:#b02a37}.sod-btn-success{background:#198754;color:#fff;border-color:#198754}.sod-btn-success:hover{background:#157347;border-color:#146c43}.sod-btn-ghost{background:transparent;color:#495057;border-color:transparent}.sod-btn-ghost:hover{background:#e9ecef}.sod-btn-link{background:transparent;color:#0d6efd;border-color:transparent;text-decoration:underline;text-underline-offset:2px}.sod-btn-link:hover{color:#0a58ca}.sod-offcanvas[open]{width:100vw;height:100vh}.sod-offcanvas .sod-panel{position:fixed;margin:0;min-width:0;max-width:none;border-radius:0;width:min(360px,90vw);height:100vh}.sod-offcanvas .sod-panel.sod-placement-start{left:0;top:0}.sod-offcanvas .sod-panel.sod-placement-end{right:0;top:0}.sod-offcanvas .sod-panel.sod-placement-top{top:0;left:0;width:100vw;height:300px}.sod-offcanvas .sod-panel.sod-placement-bottom{bottom:0;left:0;width:100vw;height:300px}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-start{animation:sod-slide-in-start .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-start.is-closing{animation:sod-slide-out-start .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-end{animation:sod-slide-in-end .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-end.is-closing{animation:sod-slide-out-end .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-top{animation:sod-slide-in-top .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-top.is-closing{animation:sod-slide-out-top .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-bottom{animation:sod-slide-in-bottom .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-slide.sod-placement-bottom.is-closing{animation:sod-slide-out-bottom .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-fade{animation:sod-fade-in .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-fade.is-closing{animation:sod-fade-out .18s ease-in forwards}.sod-offcanvas .sod-panel.sod-anim-zoom{animation:sod-zoom-in .18s ease-out}.sod-offcanvas .sod-panel.sod-anim-zoom.is-closing{animation:sod-zoom-out .18s ease-in forwards}@keyframes sod-modal-zoom-in{0%{opacity:0;transform:scale(.96)}to{opacity:1;transform:scale(1)}}@keyframes sod-modal-zoom-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.96)}}@keyframes sod-modal-slide-in{0%{opacity:0;transform:translateY(-16px)}to{opacity:1;transform:translateY(0)}}@keyframes sod-modal-slide-out{0%{opacity:1;transform:translateY(0)}to{opacity:0;transform:translateY(-12px)}}@keyframes sod-slide-in-start{0%{transform:translate(-100%)}to{transform:translate(0)}}@keyframes sod-slide-out-start{0%{transform:translate(0)}to{transform:translate(-100%)}}@keyframes sod-slide-in-end{0%{transform:translate(100%)}to{transform:translate(0)}}@keyframes sod-slide-out-end{0%{transform:translate(0)}to{transform:translate(100%)}}@keyframes sod-slide-in-top{0%{transform:translateY(-100%)}to{transform:translateY(0)}}@keyframes sod-slide-out-top{0%{transform:translateY(0)}to{transform:translateY(-100%)}}@keyframes sod-slide-in-bottom{0%{transform:translateY(100%)}to{transform:translateY(0)}}@keyframes sod-slide-out-bottom{0%{transform:translateY(0)}to{transform:translateY(100%)}}@keyframes sod-fade-in{0%{opacity:0}to{opacity:1}}@keyframes sod-fade-out{0%{opacity:1}to{opacity:0}}@keyframes sod-zoom-in{0%{opacity:0;transform:scale(.96)}to{opacity:1;transform:scale(1)}}.sod-toast-layer{position:fixed;z-index:1200;display:flex;flex-direction:column;gap:.5rem;width:min(360px,calc(100vw - 1.5rem));pointer-events:none}.sod-toast-layer-top-start{top:.75rem;left:.75rem;align-items:flex-start}.sod-toast-layer-top-center{top:.75rem;left:50%;transform:translate(-50%);align-items:center}.sod-toast-layer-top-end{top:.75rem;right:.75rem;align-items:flex-end}.sod-toast-layer-bottom-start{bottom:.75rem;left:.75rem;align-items:flex-start}.sod-toast-layer-bottom-center{bottom:.75rem;left:50%;transform:translate(-50%);align-items:center}.sod-toast-layer-bottom-end{bottom:.75rem;right:.75rem;align-items:flex-end}.sod-toast{--sod-toast-accent: #6c757d;pointer-events:auto;width:100%;box-sizing:border-box;border-radius:.5rem;border:1px solid #dee2e6;background:#fff;color:#212529;box-shadow:0 .5rem 1rem #0000002e;overflow:hidden;animation:sod-toast-enter .18s ease-out}.sod-toast.is-closing{animation:sod-toast-exit .18s ease-in forwards}.sod-toast-header{display:flex;align-items:center;justify-content:space-between;gap:.5rem;padding:.5rem .75rem 0}.sod-toast-title{font-size:.92rem;font-weight:700}.sod-toast-close{border:0;background:transparent;color:#6c757d;font-size:1.15rem;line-height:1;cursor:pointer;padding:0}.sod-toast-body{padding:.55rem .75rem .75rem;font-size:.92rem;line-height:1.45;overflow-wrap:anywhere;word-break:break-word}.sod-toast-progress{width:100%;height:3px;background:var(--sod-toast-accent);opacity:.9;transform-origin:left center;animation:sod-toast-progress-countdown 3s linear forwards}.sod-toast-default{--sod-toast-accent: #6c757d;border-left:4px solid #6c757d}.sod-toast-info{--sod-toast-accent: #0dcaf0;border-left:4px solid #0dcaf0}.sod-toast-success{--sod-toast-accent: #198754;border-left:4px solid #198754}.sod-toast-warning{--sod-toast-accent: #ffc107;border-left:4px solid #ffc107}.sod-toast-danger{--sod-toast-accent: #dc3545;border-left:4px solid #dc3545}@keyframes sod-toast-enter{0%{opacity:0;transform:translateY(-8px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes sod-toast-exit{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.96)}}@keyframes sod-toast-progress-countdown{0%{transform:scaleX(1)}to{transform:scaleX(0)}}@keyframes sod-zoom-out{0%{opacity:1;transform:scale(1)}to{opacity:0;transform:scale(.96)}}
|
package/dist/sodialog.es.js
CHANGED
|
@@ -1,157 +1,157 @@
|
|
|
1
|
-
function
|
|
1
|
+
function W(n, e) {
|
|
2
2
|
if (typeof e == "string") {
|
|
3
|
-
|
|
3
|
+
n.innerHTML = e;
|
|
4
4
|
return;
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
n.append(e);
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function B(n, e = "hide") {
|
|
9
9
|
if (e === "destroy") {
|
|
10
|
-
|
|
10
|
+
n.dataset.sodDestroy = "true", n.open && n.close(), n.remove();
|
|
11
11
|
return;
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
n.open && n.close();
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
return
|
|
15
|
+
function $(n, e) {
|
|
16
|
+
return n.action ? n.action : n.role === "confirm" ? e : n.role === "cancel" ? "hide" : "none";
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
return
|
|
18
|
+
function N(n) {
|
|
19
|
+
return n === "danger" ? "sod-btn-danger" : n === "success" ? "sod-btn-success" : n === "ghost" ? "sod-btn-ghost" : n === "link" ? "sod-btn-link" : n === "outline" ? "sod-btn-outline" : "sod-btn-primary";
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
const
|
|
23
|
-
|
|
21
|
+
function F(n, e) {
|
|
22
|
+
const t = Array.isArray(e) ? e.length > 0 ? e : ["header"] : [e ?? "header"], s = [], i = (o) => {
|
|
23
|
+
o && (s.includes(o) || s.push(o));
|
|
24
24
|
};
|
|
25
|
-
for (const
|
|
26
|
-
if (
|
|
27
|
-
|
|
25
|
+
for (const o of t) {
|
|
26
|
+
if (o === "panel") {
|
|
27
|
+
i(n);
|
|
28
28
|
continue;
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
30
|
+
if (o === "header") {
|
|
31
|
+
i(n.querySelector(".sod-header"));
|
|
32
32
|
continue;
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
35
|
-
|
|
34
|
+
if (o === "title") {
|
|
35
|
+
i(n.querySelector(".sod-title"));
|
|
36
36
|
continue;
|
|
37
37
|
}
|
|
38
|
-
if (
|
|
39
|
-
|
|
38
|
+
if (o === "body") {
|
|
39
|
+
i(n.querySelector(".sod-body"));
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
n.querySelectorAll(o).forEach((r) => {
|
|
43
|
+
i(r);
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
|
-
return
|
|
46
|
+
return s.length === 0 && i(n.querySelector(".sod-header")), s;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
48
|
+
function k(n, e) {
|
|
49
|
+
const t = F(n, e);
|
|
50
|
+
if (t.length === 0)
|
|
51
51
|
return;
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
n.classList.add("sod-modal-draggable"), t.forEach((m) => {
|
|
53
|
+
m.classList.add("sod-drag-handle");
|
|
54
54
|
});
|
|
55
|
-
let
|
|
56
|
-
const
|
|
57
|
-
const
|
|
55
|
+
let s = !1, i = 0, o = 0, r = null, d = null, h = 0, a = 0, f = 0;
|
|
56
|
+
const v = document.body.style.userSelect, E = (m, u) => {
|
|
57
|
+
const y = n.getBoundingClientRect(), p = Math.max(0, window.innerWidth - y.width), S = Math.max(0, window.innerHeight - y.height), A = Math.min(0, window.innerWidth - y.width), b = Math.min(0, window.innerHeight - y.height);
|
|
58
58
|
return {
|
|
59
|
-
left: Math.min(
|
|
60
|
-
top: Math.min(
|
|
59
|
+
left: Math.min(p, Math.max(A, m)),
|
|
60
|
+
top: Math.min(S, Math.max(b, u))
|
|
61
61
|
};
|
|
62
|
-
},
|
|
63
|
-
if (!
|
|
62
|
+
}, R = (m) => {
|
|
63
|
+
if (!s)
|
|
64
64
|
return;
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
const u = E(m.clientX - i, m.clientY - o);
|
|
66
|
+
a = u.left, f = u.top, h === 0 && (h = window.requestAnimationFrame(() => {
|
|
67
|
+
h = 0, n.style.inset = "auto", n.style.left = `${a}px`, n.style.top = `${f}px`, n.style.right = "auto", n.style.bottom = "auto", n.style.margin = "0", n.style.transform = "none";
|
|
68
68
|
}));
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}),
|
|
69
|
+
}, x = () => {
|
|
70
|
+
s = !1, t.forEach((m) => {
|
|
71
|
+
m.classList.remove("is-dragging");
|
|
72
|
+
}), n.classList.remove("sod-is-dragging"), n.style.willChange = "", document.body.style.userSelect = v, h !== 0 && (window.cancelAnimationFrame(h), h = 0), r !== null && d !== null && d.hasPointerCapture && d.hasPointerCapture(r) && d.releasePointerCapture(r), r = null, d = null, window.removeEventListener("pointermove", R), window.removeEventListener("pointerup", x), window.removeEventListener("pointercancel", x);
|
|
73
73
|
};
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
74
|
+
t.forEach((m) => {
|
|
75
|
+
m.addEventListener("pointerdown", (u) => {
|
|
76
|
+
if (u.button !== 0 || u.target?.closest("button, input, select, textarea, a"))
|
|
77
77
|
return;
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
78
|
+
u.preventDefault(), n.classList.add("sod-is-dragging"), n.style.animation = "none", n.style.transition = "none", n.style.transform = "none";
|
|
79
|
+
const p = n.getBoundingClientRect();
|
|
80
|
+
i = u.clientX - p.left, o = u.clientY - p.top, s = !0, r = u.pointerId, d = m, m.setPointerCapture(u.pointerId), n.style.position = "fixed", n.style.left = `${p.left}px`, n.style.top = `${p.top}px`, n.style.width = `${Math.round(p.width)}px`, n.style.height = `${Math.round(p.height)}px`, n.style.inset = "auto", n.style.right = "auto", n.style.bottom = "auto", n.style.margin = "0", n.style.willChange = "left, top", m.classList.add("is-dragging"), document.body.style.userSelect = "none", window.addEventListener("pointermove", R), window.addEventListener("pointerup", x), window.addEventListener("pointercancel", x);
|
|
81
81
|
});
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
|
-
function
|
|
85
|
-
const
|
|
86
|
-
let
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
84
|
+
function D(n, e, t, s, i, o) {
|
|
85
|
+
const d = Math.max(1, o?.hybridSwitchRatio ?? 1.35), h = o?.refitOnContentChange ?? !0, a = Math.max(120, o?.autoFitMinWidth ?? 280), f = Math.max(100, o?.autoFitMinHeight ?? 160), v = o?.scrollMode ? o.scrollMode : o?.autoFitUseScrollbar === !1 ? "viewport" : "body";
|
|
86
|
+
let E = 0;
|
|
87
|
+
const R = (b, M, L) => Math.min(L, Math.max(M, b)), x = () => {
|
|
88
|
+
if (E = 0, !n.isConnected || !n.open)
|
|
89
89
|
return;
|
|
90
|
-
const
|
|
91
|
-
e.style.width = "auto", e.style.height = "auto", e.style.maxHeight = "none",
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
const
|
|
95
|
-
e.style.width = `${
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
} else if (
|
|
99
|
-
if (
|
|
100
|
-
const
|
|
101
|
-
e.style.width = `${
|
|
90
|
+
const b = Math.max(a, window.innerWidth - 32), M = Math.max(f, window.innerHeight - 32);
|
|
91
|
+
e.style.width = "auto", e.style.height = "auto", e.style.maxHeight = "none", s.style.maxHeight = "none", s.style.overflowY = "visible", s.style.overflowX = "visible";
|
|
92
|
+
const L = Math.ceil(e.scrollWidth), l = Math.ceil(e.scrollHeight), c = L > b, g = l > M;
|
|
93
|
+
if (v === "body") {
|
|
94
|
+
const w = R(L, a, b), O = R(l, f, M);
|
|
95
|
+
e.style.width = `${w}px`, e.style.maxWidth = `${b}px`, e.style.height = `${O}px`, e.style.maxHeight = `${M}px`;
|
|
96
|
+
const H = t.offsetHeight, T = i.offsetHeight, I = Math.max(64, O - H - T);
|
|
97
|
+
g ? (s.style.maxHeight = `${I}px`, s.style.overflowY = "auto") : (s.style.maxHeight = "none", s.style.overflowY = "hidden"), s.style.overflowX = c ? "auto" : "hidden", n.classList.remove("sod-modal-viewport-scroll");
|
|
98
|
+
} else if (v === "hybrid")
|
|
99
|
+
if (l > M * d) {
|
|
100
|
+
const O = Math.max(L, a), H = Math.max(l, f);
|
|
101
|
+
e.style.width = `${O}px`, e.style.maxWidth = "none", e.style.height = `${H}px`, e.style.maxHeight = "none", s.style.maxHeight = "none", s.style.overflowY = "visible", s.style.overflowX = "visible", n.classList.add("sod-modal-viewport-scroll");
|
|
102
102
|
} else {
|
|
103
|
-
const
|
|
104
|
-
e.style.width = `${
|
|
105
|
-
const
|
|
106
|
-
|
|
103
|
+
const O = R(L, a, b), H = R(l, f, M);
|
|
104
|
+
e.style.width = `${O}px`, e.style.maxWidth = `${b}px`, e.style.height = `${H}px`, e.style.maxHeight = `${M}px`;
|
|
105
|
+
const T = t.offsetHeight, I = i.offsetHeight, C = Math.max(64, H - T - I);
|
|
106
|
+
g ? (s.style.maxHeight = `${C}px`, s.style.overflowY = "auto") : (s.style.maxHeight = "none", s.style.overflowY = "hidden"), s.style.overflowX = c ? "auto" : "hidden", n.classList.remove("sod-modal-viewport-scroll");
|
|
107
107
|
}
|
|
108
|
-
else if (
|
|
109
|
-
const
|
|
110
|
-
e.style.width = `${
|
|
108
|
+
else if (v === "viewport") {
|
|
109
|
+
const w = Math.max(L, a), O = Math.max(l, f);
|
|
110
|
+
e.style.width = `${w}px`, e.style.maxWidth = "none", e.style.height = `${O}px`, e.style.maxHeight = "none", s.style.maxHeight = "none", s.style.overflowY = "visible", s.style.overflowX = "visible", O > M ? n.classList.add("sod-modal-viewport-scroll") : n.classList.remove("sod-modal-viewport-scroll");
|
|
111
111
|
} else {
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
const
|
|
115
|
-
e.style.width = `${
|
|
112
|
+
const w = c ? Math.max(L, a) : R(L, a, b);
|
|
113
|
+
if (c || g) {
|
|
114
|
+
const O = Math.max(l, f);
|
|
115
|
+
e.style.width = `${w}px`, e.style.maxWidth = "none", e.style.height = `${O}px`, e.style.maxHeight = "none", s.style.maxHeight = "none", s.style.overflowY = "visible", s.style.overflowX = "visible", n.classList.add("sod-modal-viewport-scroll");
|
|
116
116
|
} else
|
|
117
|
-
e.style.width = `${
|
|
117
|
+
e.style.width = `${w}px`, e.style.maxWidth = `${b}px`, e.style.height = "auto", e.style.maxHeight = "none", s.style.maxHeight = "none", s.style.overflowY = "visible", s.style.overflowX = "visible", n.classList.remove("sod-modal-viewport-scroll");
|
|
118
118
|
}
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
}),
|
|
124
|
-
|
|
125
|
-
}),
|
|
126
|
-
|
|
127
|
-
},
|
|
128
|
-
|
|
119
|
+
}, m = () => {
|
|
120
|
+
E === 0 && (E = window.requestAnimationFrame(x));
|
|
121
|
+
}, u = new ResizeObserver(() => {
|
|
122
|
+
m();
|
|
123
|
+
}), y = new MutationObserver(() => {
|
|
124
|
+
m();
|
|
125
|
+
}), p = () => {
|
|
126
|
+
m();
|
|
127
|
+
}, S = () => {
|
|
128
|
+
m();
|
|
129
129
|
};
|
|
130
|
-
|
|
130
|
+
n.addEventListener("sod:refit", S), u.observe(s), u.observe(t), u.observe(i), h && (y.observe(s, {
|
|
131
131
|
subtree: !0,
|
|
132
132
|
childList: !0,
|
|
133
133
|
characterData: !0,
|
|
134
134
|
attributes: !0
|
|
135
|
-
}),
|
|
136
|
-
const
|
|
137
|
-
|
|
135
|
+
}), s.addEventListener("load", p, !0), s.addEventListener("error", p, !0));
|
|
136
|
+
const A = () => {
|
|
137
|
+
m();
|
|
138
138
|
};
|
|
139
|
-
return window.addEventListener("resize",
|
|
140
|
-
|
|
139
|
+
return window.addEventListener("resize", A), m(), () => {
|
|
140
|
+
E !== 0 && (window.cancelAnimationFrame(E), E = 0), u.disconnect(), y.disconnect(), window.removeEventListener("resize", A), n.removeEventListener("sod:refit", S), s.removeEventListener("load", p, !0), s.removeEventListener("error", p, !0), n.classList.remove("sod-modal-viewport-scroll"), s.style.maxHeight = "", s.style.overflowY = "", s.style.overflowX = "";
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
|
-
class
|
|
143
|
+
class P {
|
|
144
144
|
static modalRegistry = /* @__PURE__ */ new Map();
|
|
145
145
|
static handleRegistry = /* @__PURE__ */ new WeakMap();
|
|
146
146
|
static modalIdSeed = 0;
|
|
147
147
|
static createAutoModalId() {
|
|
148
148
|
return this.modalIdSeed += 1, `sod-modal-${this.modalIdSeed}`;
|
|
149
149
|
}
|
|
150
|
-
static revealExisting(e,
|
|
150
|
+
static revealExisting(e, t) {
|
|
151
151
|
if (!e.isConnected)
|
|
152
152
|
return {
|
|
153
153
|
dialog: e,
|
|
154
|
-
close: () =>
|
|
154
|
+
close: () => B(e),
|
|
155
155
|
refit: () => e.dispatchEvent(new Event("sod:refit")),
|
|
156
156
|
setFooterButtons: () => {
|
|
157
157
|
},
|
|
@@ -160,12 +160,12 @@ class B {
|
|
|
160
160
|
},
|
|
161
161
|
id: e.dataset.sodId
|
|
162
162
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
const
|
|
166
|
-
return
|
|
163
|
+
const s = e.querySelector(".sod-panel");
|
|
164
|
+
s?.classList.remove("is-closing"), document.body.append(e), e.open || (t ? e.showModal() : e.show()), e.dispatchEvent(new Event("sod:refit")), s?.focus();
|
|
165
|
+
const i = this.handleRegistry.get(e);
|
|
166
|
+
return i ? i() : {
|
|
167
167
|
dialog: e,
|
|
168
|
-
close: () =>
|
|
168
|
+
close: () => B(e),
|
|
169
169
|
refit: () => e.dispatchEvent(new Event("sod:refit")),
|
|
170
170
|
setFooterButtons: () => {
|
|
171
171
|
},
|
|
@@ -176,51 +176,51 @@ class B {
|
|
|
176
176
|
};
|
|
177
177
|
}
|
|
178
178
|
static open(e) {
|
|
179
|
-
const
|
|
180
|
-
let
|
|
181
|
-
if (
|
|
182
|
-
const
|
|
183
|
-
if (
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
const
|
|
179
|
+
const t = e.kind ?? "modal", s = "useModal" in e ? e.useModal ?? !0 : !0, i = t === "modal" ? e : void 0, o = t === "modal" && ("autoFitSize" in e ? e.autoFitSize !== !1 : !0);
|
|
180
|
+
let r, d = !1, h = e.confirmAction ?? "hide";
|
|
181
|
+
if (t === "modal") {
|
|
182
|
+
const l = "id" in e && e.id?.trim() ? e.id.trim() : void 0;
|
|
183
|
+
if (d = !!l, r = l ?? this.createAutoModalId(), e.confirmAction === void 0 && d && (h = "destroy"), l) {
|
|
184
|
+
const c = this.modalRegistry.get(r);
|
|
185
|
+
if (c && c.isConnected) {
|
|
186
|
+
const g = this.revealExisting(c, s);
|
|
187
187
|
if (e.onAction) {
|
|
188
|
-
const
|
|
189
|
-
|
|
188
|
+
const w = g.onAction(e.onAction);
|
|
189
|
+
c.addEventListener("close", w, { once: !0 });
|
|
190
190
|
}
|
|
191
|
-
return "onReused" in e && e.onReused?.(
|
|
191
|
+
return "onReused" in e && e.onReused?.(g), g;
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
this.modalRegistry.delete(
|
|
194
|
+
this.modalRegistry.delete(r);
|
|
195
195
|
}
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
202
|
-
const
|
|
203
|
-
|
|
196
|
+
const a = document.createElement("dialog");
|
|
197
|
+
a.className = `sod-dialog sod-${t}`;
|
|
198
|
+
const f = [];
|
|
199
|
+
r && (a.dataset.sodId = r, d && (a.dataset.sodPersistent = "true"));
|
|
200
|
+
const v = document.createElement("section");
|
|
201
|
+
if (v.className = "sod-panel", v.tabIndex = -1, t === "offcanvas") {
|
|
202
|
+
const l = "placement" in e ? e.placement ?? "end" : "end", c = "animation" in e ? e.animation ?? "slide" : "slide";
|
|
203
|
+
v.classList.add(`sod-placement-${l}`), v.classList.add(`sod-anim-${c}`);
|
|
204
204
|
} else {
|
|
205
|
-
const
|
|
206
|
-
|
|
205
|
+
const l = "position" in e ? e.position ?? "center" : "center", c = "animation" in e ? e.animation ?? "fade" : "fade";
|
|
206
|
+
v.classList.add(`sod-modal-pos-${l}`), v.classList.add(`sod-modal-anim-${c}`), o && v.classList.add("sod-modal-autofit");
|
|
207
207
|
}
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
const
|
|
211
|
-
|
|
212
|
-
const
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
const
|
|
217
|
-
|
|
218
|
-
const
|
|
219
|
-
e.onAction &&
|
|
220
|
-
const
|
|
221
|
-
|
|
208
|
+
const E = document.createElement("header");
|
|
209
|
+
E.className = "sod-header";
|
|
210
|
+
const R = document.createElement("h2");
|
|
211
|
+
R.className = "sod-title", R.textContent = e.title;
|
|
212
|
+
const x = document.createElement("button");
|
|
213
|
+
x.type = "button", x.className = "sod-close", x.setAttribute("aria-label", "Close"), x.textContent = "×", x.addEventListener("click", () => B(a)), E.append(R, x);
|
|
214
|
+
const m = document.createElement("div");
|
|
215
|
+
m.className = "sod-body", W(m, e.content);
|
|
216
|
+
const u = document.createElement("footer");
|
|
217
|
+
u.className = "sod-footer", u.dataset.align = e.footerAlign ?? "end";
|
|
218
|
+
const y = /* @__PURE__ */ new Set();
|
|
219
|
+
e.onAction && y.add(e.onAction);
|
|
220
|
+
const p = (l) => (y.add(l), () => {
|
|
221
|
+
y.delete(l);
|
|
222
222
|
});
|
|
223
|
-
let
|
|
223
|
+
let S = e.footerButtons ? [...e.footerButtons] : [
|
|
224
224
|
{
|
|
225
225
|
id: "cancel",
|
|
226
226
|
label: e.cancelText ?? "取消",
|
|
@@ -234,66 +234,66 @@ class B {
|
|
|
234
234
|
variant: "primary"
|
|
235
235
|
}
|
|
236
236
|
];
|
|
237
|
-
const
|
|
238
|
-
dialog:
|
|
239
|
-
close: () =>
|
|
240
|
-
refit: () =>
|
|
241
|
-
setFooterButtons: (
|
|
242
|
-
|
|
237
|
+
const A = () => ({
|
|
238
|
+
dialog: a,
|
|
239
|
+
close: () => B(a),
|
|
240
|
+
refit: () => a.dispatchEvent(new Event("sod:refit")),
|
|
241
|
+
setFooterButtons: (l) => {
|
|
242
|
+
S = [...l], M(), a.dispatchEvent(new Event("sod:refit"));
|
|
243
243
|
},
|
|
244
|
-
updateFooterButton: (
|
|
245
|
-
const
|
|
246
|
-
return
|
|
244
|
+
updateFooterButton: (l, c) => {
|
|
245
|
+
const g = S.findIndex((w) => w.id === l);
|
|
246
|
+
return g < 0 ? !1 : (S[g] = { ...S[g], ...c }, M(), a.dispatchEvent(new Event("sod:refit")), !0);
|
|
247
247
|
},
|
|
248
|
-
onAction: (
|
|
249
|
-
id:
|
|
250
|
-
}),
|
|
251
|
-
if (typeof
|
|
252
|
-
|
|
248
|
+
onAction: (l) => p(l),
|
|
249
|
+
id: r
|
|
250
|
+
}), b = (l, c) => {
|
|
251
|
+
if (typeof c == "string") {
|
|
252
|
+
l.textContent = c;
|
|
253
253
|
return;
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
},
|
|
257
|
-
if (
|
|
258
|
-
|
|
255
|
+
l.append(c);
|
|
256
|
+
}, M = () => {
|
|
257
|
+
if (u.replaceChildren(), e.hideFooter || S.length === 0) {
|
|
258
|
+
u.hidden = !0;
|
|
259
259
|
return;
|
|
260
260
|
}
|
|
261
|
-
|
|
262
|
-
for (const
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}),
|
|
261
|
+
u.hidden = !1;
|
|
262
|
+
for (const l of S) {
|
|
263
|
+
const c = document.createElement("button");
|
|
264
|
+
c.type = "button", c.className = `sod-btn ${N(l.variant)}`, l.className?.trim() && (c.className = `${c.className} ${l.className.trim()}`), l.id?.trim() && (c.dataset.action = l.id.trim()), l.disabled && (c.disabled = !0), l.attrs && Object.entries(l.attrs).forEach(([g, w]) => {
|
|
265
|
+
c.setAttribute(g, w);
|
|
266
|
+
}), b(c, l.label), c.addEventListener("click", (g) => {
|
|
267
267
|
(async () => {
|
|
268
|
-
const
|
|
269
|
-
action:
|
|
270
|
-
button:
|
|
271
|
-
buttonElement:
|
|
272
|
-
dialog:
|
|
273
|
-
event:
|
|
274
|
-
handle:
|
|
268
|
+
const w = A(), H = {
|
|
269
|
+
action: l.id ?? l.role ?? "custom",
|
|
270
|
+
button: l,
|
|
271
|
+
buttonElement: c,
|
|
272
|
+
dialog: a,
|
|
273
|
+
event: g,
|
|
274
|
+
handle: w
|
|
275
275
|
};
|
|
276
|
-
if (await
|
|
276
|
+
if (await l.onClick?.(H) === !1)
|
|
277
277
|
return;
|
|
278
|
-
|
|
279
|
-
|
|
278
|
+
l.role === "cancel" && e.onCancel?.(), l.role === "confirm" && e.onConfirm?.(), y.forEach((C) => {
|
|
279
|
+
C(H);
|
|
280
280
|
});
|
|
281
|
-
const
|
|
282
|
-
|
|
281
|
+
const I = $(l, h);
|
|
282
|
+
I === "hide" && B(a, "hide"), I === "destroy" && B(a, "destroy");
|
|
283
283
|
})();
|
|
284
|
-
}),
|
|
284
|
+
}), u.append(c);
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}), (e.closeOnEsc ?? !0) ||
|
|
290
|
-
|
|
291
|
-
}),
|
|
292
|
-
const
|
|
293
|
-
(!
|
|
294
|
-
}), document.body.append(
|
|
295
|
-
const
|
|
296
|
-
return
|
|
287
|
+
M(), v.append(E, m, u), o && f.push(D(a, v, E, m, u, i)), t === "modal" && "draggable" in e && e.draggable && k(v, e.dragHandle), a.append(v), (e.closeOnBackdrop ?? !0) && a.addEventListener("click", (l) => {
|
|
288
|
+
l.target === a && B(a);
|
|
289
|
+
}), (e.closeOnEsc ?? !0) || a.addEventListener("cancel", (l) => {
|
|
290
|
+
l.preventDefault();
|
|
291
|
+
}), a.addEventListener("close", () => {
|
|
292
|
+
const l = a.dataset.sodPersistent === "true", c = a.dataset.sodDestroy === "true";
|
|
293
|
+
(!l || c) && (f.forEach((g) => g()), y.clear(), a.remove(), r && this.modalRegistry.delete(r), this.handleRegistry.delete(a), delete a.dataset.sodDestroy);
|
|
294
|
+
}), document.body.append(a), s ? a.showModal() : a.show(), a.dispatchEvent(new Event("sod:refit")), r && this.modalRegistry.set(r, a), this.handleRegistry.set(a, A);
|
|
295
|
+
const L = A();
|
|
296
|
+
return t === "modal" && "onCreated" in e && e.onCreated?.(L), L;
|
|
297
297
|
}
|
|
298
298
|
static openModal(e) {
|
|
299
299
|
return this.open({ ...e, kind: "modal" });
|
|
@@ -302,14 +302,334 @@ class B {
|
|
|
302
302
|
return this.open({ ...e, kind: "offcanvas" });
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
|
-
|
|
306
|
-
|
|
305
|
+
class V {
|
|
306
|
+
static placementState = /* @__PURE__ */ new Map();
|
|
307
|
+
static recordById = /* @__PURE__ */ new Map();
|
|
308
|
+
static idSeed = 0;
|
|
309
|
+
static defaults = {
|
|
310
|
+
placement: "top-end",
|
|
311
|
+
variant: "default",
|
|
312
|
+
duration: 3e3,
|
|
313
|
+
showProgress: !0,
|
|
314
|
+
closable: !0,
|
|
315
|
+
pauseOnHover: !0,
|
|
316
|
+
pauseOnWindowBlur: !1,
|
|
317
|
+
duplicateStrategy: "update",
|
|
318
|
+
newestOnTop: !0,
|
|
319
|
+
maxVisible: 3
|
|
320
|
+
};
|
|
321
|
+
static normalizeOptions(e) {
|
|
322
|
+
const t = e.duration === !1 ? !1 : Math.max(0, e.duration ?? this.defaults.duration);
|
|
323
|
+
return {
|
|
324
|
+
placement: e.placement ?? this.defaults.placement,
|
|
325
|
+
variant: e.variant ?? this.defaults.variant,
|
|
326
|
+
duration: t,
|
|
327
|
+
showProgress: e.showProgress ?? this.defaults.showProgress,
|
|
328
|
+
closable: e.closable ?? this.defaults.closable,
|
|
329
|
+
pauseOnHover: e.pauseOnHover ?? this.defaults.pauseOnHover,
|
|
330
|
+
pauseOnWindowBlur: e.pauseOnWindowBlur ?? this.defaults.pauseOnWindowBlur,
|
|
331
|
+
duplicateStrategy: e.duplicateStrategy ?? this.defaults.duplicateStrategy,
|
|
332
|
+
newestOnTop: e.newestOnTop ?? this.defaults.newestOnTop,
|
|
333
|
+
maxVisible: Math.max(1, e.maxVisible ?? this.defaults.maxVisible),
|
|
334
|
+
title: e.title,
|
|
335
|
+
content: e.content,
|
|
336
|
+
className: e.className,
|
|
337
|
+
attrs: e.attrs,
|
|
338
|
+
onShown: e.onShown,
|
|
339
|
+
onClose: e.onClose
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
static createAutoToastId() {
|
|
343
|
+
return this.idSeed += 1, `sot-toast-${this.idSeed}`;
|
|
344
|
+
}
|
|
345
|
+
static createStackedToastId(e) {
|
|
346
|
+
let t = 1, s = `${e}-${t}`;
|
|
347
|
+
for (; this.recordById.has(s); )
|
|
348
|
+
t += 1, s = `${e}-${t}`;
|
|
349
|
+
return s;
|
|
350
|
+
}
|
|
351
|
+
static resolveRole(e) {
|
|
352
|
+
return e === "danger" ? "alert" : "status";
|
|
353
|
+
}
|
|
354
|
+
static getPlacementState(e) {
|
|
355
|
+
const t = this.placementState.get(e);
|
|
356
|
+
if (t)
|
|
357
|
+
return t;
|
|
358
|
+
const s = document.createElement("div");
|
|
359
|
+
s.className = `sod-toast-layer sod-toast-layer-${e}`, s.setAttribute("aria-live", "polite"), s.setAttribute("aria-atomic", "false"), document.body.append(s);
|
|
360
|
+
const i = {
|
|
361
|
+
container: s,
|
|
362
|
+
active: [],
|
|
363
|
+
pending: []
|
|
364
|
+
};
|
|
365
|
+
return this.placementState.set(e, i), i;
|
|
366
|
+
}
|
|
367
|
+
static createToastElement(e) {
|
|
368
|
+
const { options: t } = e, s = document.createElement("article");
|
|
369
|
+
s.className = `sod-toast sod-toast-${t.variant}`, t.className?.trim() && (s.className = `${s.className} ${t.className.trim()}`), s.dataset.toastId = e.id, s.setAttribute("role", this.resolveRole(t.variant)), t.attrs && Object.entries(t.attrs).forEach(([a, f]) => {
|
|
370
|
+
s.setAttribute(a, f);
|
|
371
|
+
});
|
|
372
|
+
const i = document.createElement("header");
|
|
373
|
+
i.className = "sod-toast-header";
|
|
374
|
+
let o = null;
|
|
375
|
+
t.title?.trim() && (o = document.createElement("strong"), o.className = "sod-toast-title", o.textContent = t.title, i.append(o));
|
|
376
|
+
let r = null;
|
|
377
|
+
t.closable && (r = document.createElement("button"), r.type = "button", r.className = "sod-toast-close", r.setAttribute("aria-label", "Close"), r.textContent = "×", r.addEventListener("click", () => {
|
|
378
|
+
this.closeRecord(e, "close-button");
|
|
379
|
+
}), i.append(r)), i.childElementCount > 0 && s.append(i);
|
|
380
|
+
const d = document.createElement("div");
|
|
381
|
+
d.className = "sod-toast-body", W(d, t.content), s.append(d);
|
|
382
|
+
let h = null;
|
|
383
|
+
if (t.showProgress && (h = document.createElement("div"), h.className = "sod-toast-progress", s.append(h)), t.pauseOnHover) {
|
|
384
|
+
const a = () => this.pauseRecord(e), f = () => this.resumeRecord(e);
|
|
385
|
+
s.addEventListener("mouseenter", a), s.addEventListener("mouseleave", f), e.cleanupListeners.push(() => {
|
|
386
|
+
s.removeEventListener("mouseenter", a), s.removeEventListener("mouseleave", f);
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
if (t.pauseOnWindowBlur) {
|
|
390
|
+
const a = () => {
|
|
391
|
+
e.paused || e.status !== "active" || (e.pausedByWindowBlur = !0, this.pauseRecord(e));
|
|
392
|
+
}, f = () => {
|
|
393
|
+
e.pausedByWindowBlur && (e.pausedByWindowBlur = !1, this.resumeRecord(e));
|
|
394
|
+
};
|
|
395
|
+
window.addEventListener("blur", a), window.addEventListener("focus", f), e.cleanupListeners.push(() => {
|
|
396
|
+
window.removeEventListener("blur", a), window.removeEventListener("focus", f);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
e.element = s, e.bodyElement = d, e.titleElement = o, e.closeButton = r, e.progressElement = h;
|
|
400
|
+
}
|
|
401
|
+
static resetProgressAnimation(e, t) {
|
|
402
|
+
!e.progressElement || !e.options.showProgress || (e.progressElement.style.display = "block", e.progressElement.style.animation = "none", e.progressElement.style.animationPlayState = "running", e.progressElement.offsetWidth, e.progressElement.style.animation = `sod-toast-progress-countdown ${Math.max(1, t)}ms linear forwards`);
|
|
403
|
+
}
|
|
404
|
+
static hideProgress(e) {
|
|
405
|
+
e.progressElement && (e.progressElement.style.display = "none", e.progressElement.style.animation = "none");
|
|
406
|
+
}
|
|
407
|
+
static isRecordActive(e, t) {
|
|
408
|
+
return e.active.includes(t);
|
|
409
|
+
}
|
|
410
|
+
static isRecordPending(e, t) {
|
|
411
|
+
return e.pending.includes(t);
|
|
412
|
+
}
|
|
413
|
+
static mountRecord(e, t) {
|
|
414
|
+
t.status = "active", t.options.newestOnTop ? e.container.prepend(t.element) : e.container.append(t.element), e.active.push(t), this.startRecordTimer(t), t.options.onShown?.(t.handle);
|
|
415
|
+
}
|
|
416
|
+
static queueRecord(e, t) {
|
|
417
|
+
t.status = "pending", e.pending.push(t);
|
|
418
|
+
}
|
|
419
|
+
static startRecordTimer(e) {
|
|
420
|
+
if (this.clearRecordTimer(e), e.options.duration === !1) {
|
|
421
|
+
e.remainingMs = !1, e.startedAt = null, this.hideProgress(e);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
const t = Math.max(0, e.remainingMs === !1 ? e.options.duration : e.remainingMs);
|
|
425
|
+
if (t === 0) {
|
|
426
|
+
this.closeRecord(e, "timeout");
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
e.startedAt = Date.now(), e.remainingMs = t, this.resetProgressAnimation(e, t), e.timerId = window.setTimeout(() => {
|
|
430
|
+
e.timerId = null, this.closeRecord(e, "timeout");
|
|
431
|
+
}, t);
|
|
432
|
+
}
|
|
433
|
+
static clearRecordTimer(e) {
|
|
434
|
+
e.timerId !== null && (window.clearTimeout(e.timerId), e.timerId = null);
|
|
435
|
+
}
|
|
436
|
+
static pauseRecord(e) {
|
|
437
|
+
if (e.paused || e.status !== "active" || e.options.duration === !1)
|
|
438
|
+
return;
|
|
439
|
+
const t = e.startedAt ?? Date.now(), s = Math.max(0, Date.now() - t), i = e.remainingMs === !1 ? e.options.duration : e.remainingMs;
|
|
440
|
+
e.remainingMs = Math.max(0, i - s), e.startedAt = null, e.paused = !0, e.progressElement && (e.progressElement.style.animationPlayState = "paused"), this.clearRecordTimer(e);
|
|
441
|
+
}
|
|
442
|
+
static resumeRecord(e) {
|
|
443
|
+
!e.paused || e.status !== "active" || (e.paused = !1, e.progressElement && (e.progressElement.style.animationPlayState = "running"), this.startRecordTimer(e));
|
|
444
|
+
}
|
|
445
|
+
static rebuildRecordElement(e) {
|
|
446
|
+
const t = e.element, s = t.parentElement;
|
|
447
|
+
e.cleanupListeners.forEach((i) => i()), e.cleanupListeners = [], t.remove(), this.createToastElement(e), s && e.status === "active" && (e.options.newestOnTop ? s.prepend(e.element) : s.append(e.element), this.startRecordTimer(e));
|
|
448
|
+
}
|
|
449
|
+
static moveRecordToPlacement(e, t) {
|
|
450
|
+
const s = e.options.placement;
|
|
451
|
+
if (s === t)
|
|
452
|
+
return;
|
|
453
|
+
const i = this.placementState.get(s), o = this.getPlacementState(t), r = !!(i && this.removeFromArray(i.active, e)), d = !!(i && this.removeFromArray(i.pending, e));
|
|
454
|
+
if (e.options.placement = t, this.clearRecordTimer(e), d && !r) {
|
|
455
|
+
this.queueRecord(o, e), this.drainQueue(o, t), i && this.drainQueue(i, s);
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
o.active.length < e.options.maxVisible ? this.mountRecord(o, e) : this.queueRecord(o, e), i && this.drainQueue(i, s);
|
|
459
|
+
}
|
|
460
|
+
static updateRecord(e, t) {
|
|
461
|
+
if (t.title !== void 0) {
|
|
462
|
+
const i = t.title.trim();
|
|
463
|
+
if (e.options.title = i.length > 0 ? i : void 0, e.options.title)
|
|
464
|
+
if (e.titleElement)
|
|
465
|
+
e.titleElement.textContent = e.options.title;
|
|
466
|
+
else {
|
|
467
|
+
const o = e.element.querySelector(".sod-toast-header");
|
|
468
|
+
if (o) {
|
|
469
|
+
const r = document.createElement("strong");
|
|
470
|
+
r.className = "sod-toast-title", r.textContent = e.options.title, o.prepend(r), e.titleElement = r;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
else e.titleElement && (e.titleElement.remove(), e.titleElement = null);
|
|
474
|
+
}
|
|
475
|
+
t.content !== void 0 && (e.options.content = t.content, e.bodyElement.replaceChildren(), W(e.bodyElement, t.content)), t.variant !== void 0 && (e.options.variant = t.variant, e.element.classList.remove("sod-toast-default", "sod-toast-info", "sod-toast-success", "sod-toast-warning", "sod-toast-danger"), e.element.classList.add(`sod-toast-${t.variant}`), e.element.setAttribute("role", this.resolveRole(t.variant))), t.duration !== void 0 && (e.options.duration = t.duration === !1 ? !1 : Math.max(0, t.duration), e.remainingMs = e.options.duration === !1 ? !1 : e.options.duration, e.paused = !1, e.status === "active" && this.startRecordTimer(e)), t.maxVisible !== void 0 && (e.options.maxVisible = Math.max(1, t.maxVisible)), t.newestOnTop !== void 0 && (e.options.newestOnTop = t.newestOnTop);
|
|
476
|
+
let s = !1;
|
|
477
|
+
t.closable !== void 0 && t.closable !== e.options.closable && (e.options.closable = t.closable, s = !0), t.pauseOnHover !== void 0 && t.pauseOnHover !== e.options.pauseOnHover && (e.options.pauseOnHover = t.pauseOnHover, s = !0), t.pauseOnWindowBlur !== void 0 && t.pauseOnWindowBlur !== e.options.pauseOnWindowBlur && (e.options.pauseOnWindowBlur = t.pauseOnWindowBlur, s = !0), t.duplicateStrategy !== void 0 && (e.options.duplicateStrategy = t.duplicateStrategy), t.showProgress !== void 0 && t.showProgress !== e.options.showProgress && (e.options.showProgress = t.showProgress, s = !0), t.className !== void 0 && (e.options.className = t.className, s = !0), t.attrs !== void 0 && (e.options.attrs = t.attrs, s = !0), s && this.rebuildRecordElement(e), t.placement && t.placement !== e.options.placement && this.moveRecordToPlacement(e, t.placement);
|
|
478
|
+
}
|
|
479
|
+
static removeStateContainerIfEmpty(e) {
|
|
480
|
+
const t = this.placementState.get(e);
|
|
481
|
+
t && (t.active.length > 0 || t.pending.length > 0 || (t.container.remove(), this.placementState.delete(e)));
|
|
482
|
+
}
|
|
483
|
+
static drainQueue(e, t) {
|
|
484
|
+
let s = !0;
|
|
485
|
+
for (; s && e.pending.length > 0; ) {
|
|
486
|
+
const i = e.pending[0];
|
|
487
|
+
if (e.active.length >= i.options.maxVisible) {
|
|
488
|
+
s = !1;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
e.pending.shift(), this.mountRecord(e, i);
|
|
492
|
+
}
|
|
493
|
+
this.removeStateContainerIfEmpty(t);
|
|
494
|
+
}
|
|
495
|
+
static removeFromArray(e, t) {
|
|
496
|
+
const s = e.indexOf(t);
|
|
497
|
+
return s < 0 ? !1 : (e.splice(s, 1), !0);
|
|
498
|
+
}
|
|
499
|
+
static finalizeClose(e, t) {
|
|
500
|
+
if (e.status === "closed")
|
|
501
|
+
return;
|
|
502
|
+
const s = e.options.placement, i = this.placementState.get(s);
|
|
503
|
+
this.clearRecordTimer(e), e.cleanupListeners.forEach((o) => o()), e.cleanupListeners = [], e.element.remove(), e.status = "closed", i && (this.removeFromArray(i.active, e), this.removeFromArray(i.pending, e)), this.recordById.delete(e.id), e.options.onClose?.(t, e.handle), i ? this.drainQueue(i, s) : this.removeStateContainerIfEmpty(s);
|
|
504
|
+
}
|
|
505
|
+
static closeRecord(e, t) {
|
|
506
|
+
if (e.status === "closed" || e.status === "closing")
|
|
507
|
+
return;
|
|
508
|
+
const s = e.options.placement, i = this.placementState.get(s);
|
|
509
|
+
if (!!(i && this.isRecordPending(i, e) && !this.isRecordActive(i, e))) {
|
|
510
|
+
this.finalizeClose(e, t);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
e.status = "closing", this.clearRecordTimer(e), e.element.classList.add("is-closing");
|
|
514
|
+
let r = !1;
|
|
515
|
+
const d = () => {
|
|
516
|
+
r || (r = !0, this.finalizeClose(e, t));
|
|
517
|
+
}, h = (a) => {
|
|
518
|
+
a.target === e.element && (e.element.removeEventListener("animationend", h), d());
|
|
519
|
+
};
|
|
520
|
+
e.element.addEventListener("animationend", h), window.setTimeout(() => {
|
|
521
|
+
e.element.removeEventListener("animationend", h), d();
|
|
522
|
+
}, 220);
|
|
523
|
+
}
|
|
524
|
+
static createHandle(e) {
|
|
525
|
+
return {
|
|
526
|
+
id: e.id,
|
|
527
|
+
get element() {
|
|
528
|
+
return e.element;
|
|
529
|
+
},
|
|
530
|
+
close: (t = "programmatic") => {
|
|
531
|
+
this.closeRecord(e, t);
|
|
532
|
+
},
|
|
533
|
+
update: (t) => {
|
|
534
|
+
this.updateRecord(e, t);
|
|
535
|
+
},
|
|
536
|
+
pause: () => {
|
|
537
|
+
this.pauseRecord(e);
|
|
538
|
+
},
|
|
539
|
+
resume: () => {
|
|
540
|
+
this.resumeRecord(e);
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
static show(e) {
|
|
545
|
+
const s = e.id?.trim() || this.createAutoToastId(), i = this.normalizeOptions(e), o = this.recordById.get(s);
|
|
546
|
+
if (o) {
|
|
547
|
+
const a = i.duplicateStrategy;
|
|
548
|
+
if (a === "ignore")
|
|
549
|
+
return o.handle;
|
|
550
|
+
if (a === "stack") {
|
|
551
|
+
const f = this.createStackedToastId(s);
|
|
552
|
+
return this.show({ ...e, id: f, duplicateStrategy: "update" });
|
|
553
|
+
}
|
|
554
|
+
return this.updateRecord(o, {
|
|
555
|
+
title: e.title,
|
|
556
|
+
content: e.content,
|
|
557
|
+
variant: e.variant,
|
|
558
|
+
duration: a === "restart-timer" ? e.duration === void 0 ? o.options.duration : i.duration : e.duration === void 0 ? void 0 : i.duration,
|
|
559
|
+
placement: e.placement,
|
|
560
|
+
closable: e.closable,
|
|
561
|
+
pauseOnHover: e.pauseOnHover,
|
|
562
|
+
pauseOnWindowBlur: e.pauseOnWindowBlur,
|
|
563
|
+
duplicateStrategy: e.duplicateStrategy,
|
|
564
|
+
newestOnTop: e.newestOnTop,
|
|
565
|
+
maxVisible: e.maxVisible,
|
|
566
|
+
showProgress: e.showProgress,
|
|
567
|
+
className: e.className,
|
|
568
|
+
attrs: e.attrs
|
|
569
|
+
}), o.options.onClose = i.onClose, o.options.onShown = i.onShown, o.handle;
|
|
570
|
+
}
|
|
571
|
+
const d = {
|
|
572
|
+
id: s,
|
|
573
|
+
options: i,
|
|
574
|
+
element: document.createElement("article"),
|
|
575
|
+
status: "pending",
|
|
576
|
+
timerId: null,
|
|
577
|
+
remainingMs: i.duration,
|
|
578
|
+
startedAt: null,
|
|
579
|
+
paused: !1,
|
|
580
|
+
pausedByWindowBlur: !1,
|
|
581
|
+
closeButton: null,
|
|
582
|
+
progressElement: null,
|
|
583
|
+
bodyElement: document.createElement("div"),
|
|
584
|
+
titleElement: null,
|
|
585
|
+
cleanupListeners: [],
|
|
586
|
+
handle: void 0
|
|
587
|
+
};
|
|
588
|
+
d.handle = this.createHandle(d), this.createToastElement(d), this.recordById.set(s, d);
|
|
589
|
+
const h = this.getPlacementState(i.placement);
|
|
590
|
+
return h.active.length < i.maxVisible ? this.mountRecord(h, d) : this.queueRecord(h, d), d.handle;
|
|
591
|
+
}
|
|
592
|
+
static clear(e) {
|
|
593
|
+
(e ? [e] : Array.from(this.placementState.keys())).forEach((s) => {
|
|
594
|
+
const i = this.placementState.get(s);
|
|
595
|
+
if (!i)
|
|
596
|
+
return;
|
|
597
|
+
const o = [...i.active];
|
|
598
|
+
[...i.pending].forEach((d) => this.closeRecord(d, "container-clear")), o.forEach((d) => this.closeRecord(d, "container-clear"));
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
static configure(e) {
|
|
602
|
+
e.placement && (this.defaults.placement = e.placement), e.variant && (this.defaults.variant = e.variant), e.duration !== void 0 && (this.defaults.duration = e.duration === !1 ? 3e3 : Math.max(0, e.duration)), e.showProgress !== void 0 && (this.defaults.showProgress = e.showProgress), e.closable !== void 0 && (this.defaults.closable = e.closable), e.pauseOnHover !== void 0 && (this.defaults.pauseOnHover = e.pauseOnHover), e.pauseOnWindowBlur !== void 0 && (this.defaults.pauseOnWindowBlur = e.pauseOnWindowBlur), e.duplicateStrategy !== void 0 && (this.defaults.duplicateStrategy = e.duplicateStrategy), e.newestOnTop !== void 0 && (this.defaults.newestOnTop = e.newestOnTop), e.maxVisible !== void 0 && (this.defaults.maxVisible = Math.max(1, e.maxVisible));
|
|
603
|
+
}
|
|
604
|
+
static success(e, t = {}) {
|
|
605
|
+
return this.show({ ...t, content: e, variant: "success" });
|
|
606
|
+
}
|
|
607
|
+
static error(e, t = {}) {
|
|
608
|
+
return this.show({ ...t, content: e, variant: "danger" });
|
|
609
|
+
}
|
|
610
|
+
static info(e, t = {}) {
|
|
611
|
+
return this.show({ ...t, content: e, variant: "info" });
|
|
612
|
+
}
|
|
613
|
+
static warning(e, t = {}) {
|
|
614
|
+
return this.show({ ...t, content: e, variant: "warning" });
|
|
615
|
+
}
|
|
616
|
+
static closeAll() {
|
|
617
|
+
this.clear();
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
function q(n) {
|
|
621
|
+
return P.openModal(n);
|
|
622
|
+
}
|
|
623
|
+
function z(n) {
|
|
624
|
+
return P.openOffcanvas(n);
|
|
307
625
|
}
|
|
308
|
-
function
|
|
309
|
-
return
|
|
626
|
+
function Y(n) {
|
|
627
|
+
return V.show(n);
|
|
310
628
|
}
|
|
311
629
|
export {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
630
|
+
P as SoDialog,
|
|
631
|
+
V as SoToast,
|
|
632
|
+
q as openModal,
|
|
633
|
+
z as openOffcanvas,
|
|
634
|
+
Y as toast
|
|
315
635
|
};
|
package/dist/sodialog.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(C,W){typeof exports=="object"&&typeof module<"u"?W(exports):typeof define=="function"&&define.amd?define(["exports"],W):(C=typeof globalThis<"u"?globalThis:C||self,W(C.SoDialog={}))})(this,(function(C){"use strict";function W(t,e){if(typeof e=="string"){t.innerHTML=e;return}t.append(e)}function F(t,e="hide"){if(e==="destroy"){t.dataset.sodDestroy="true",t.open&&t.close(),t.remove();return}t.open&&t.close()}function k(t,e){return t.action?t.action:t.role==="confirm"?e:t.role==="cancel"?"hide":"none"}function N(t){return t==="danger"?"sod-btn-danger":t==="success"?"sod-btn-success":t==="ghost"?"sod-btn-ghost":t==="link"?"sod-btn-link":t==="outline"?"sod-btn-outline":"sod-btn-primary"}function P(t,e){const c=Array.isArray(e)?e.length>0?e:["header"]:[e??"header"],s=[],f=d=>{d&&(s.includes(d)||s.push(d))};for(const d of c){if(d==="panel"){f(t);continue}if(d==="header"){f(t.querySelector(".sod-header"));continue}if(d==="title"){f(t.querySelector(".sod-title"));continue}if(d==="body"){f(t.querySelector(".sod-body"));continue}t.querySelectorAll(d).forEach(l=>{f(l)})}return s.length===0&&f(t.querySelector(".sod-header")),s}function T(t,e){const c=P(t,e);if(c.length===0)return;t.classList.add("sod-modal-draggable"),c.forEach(a=>{a.classList.add("sod-drag-handle")});let s=!1,f=0,d=0,l=null,M=null,$=0,o=0,L=0;const u=document.body.style.userSelect,y=(a,r)=>{const g=t.getBoundingClientRect(),m=Math.max(0,window.innerWidth-g.width),A=Math.max(0,window.innerHeight-g.height),S=Math.min(0,window.innerWidth-g.width),x=Math.min(0,window.innerHeight-g.height);return{left:Math.min(m,Math.max(S,a)),top:Math.min(A,Math.max(x,r))}},p=a=>{if(!s)return;const r=y(a.clientX-f,a.clientY-d);o=r.left,L=r.top,$===0&&($=window.requestAnimationFrame(()=>{$=0,t.style.inset="auto",t.style.left=`${o}px`,t.style.top=`${L}px`,t.style.right="auto",t.style.bottom="auto",t.style.margin="0",t.style.transform="none"}))},w=()=>{s=!1,c.forEach(a=>{a.classList.remove("is-dragging")}),t.classList.remove("sod-is-dragging"),t.style.willChange="",document.body.style.userSelect=u,$!==0&&(window.cancelAnimationFrame($),$=0),l!==null&&M!==null&&M.hasPointerCapture&&M.hasPointerCapture(l)&&M.releasePointerCapture(l),l=null,M=null,window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",w),window.removeEventListener("pointercancel",w)};c.forEach(a=>{a.addEventListener("pointerdown",r=>{if(r.button!==0||r.target?.closest("button, input, select, textarea, a"))return;r.preventDefault(),t.classList.add("sod-is-dragging"),t.style.animation="none",t.style.transition="none",t.style.transform="none";const m=t.getBoundingClientRect();f=r.clientX-m.left,d=r.clientY-m.top,s=!0,l=r.pointerId,M=a,a.setPointerCapture(r.pointerId),t.style.position="fixed",t.style.left=`${m.left}px`,t.style.top=`${m.top}px`,t.style.width=`${Math.round(m.width)}px`,t.style.height=`${Math.round(m.height)}px`,t.style.inset="auto",t.style.right="auto",t.style.bottom="auto",t.style.margin="0",t.style.willChange="left, top",a.classList.add("is-dragging"),document.body.style.userSelect="none",window.addEventListener("pointermove",p),window.addEventListener("pointerup",w),window.addEventListener("pointercancel",w)})})}function Y(t,e,c,s,f,d){const M=Math.max(1,d?.hybridSwitchRatio??1.35),$=d?.refitOnContentChange??!0,o=Math.max(120,d?.autoFitMinWidth??280),L=Math.max(100,d?.autoFitMinHeight??160),u=d?.scrollMode?d.scrollMode:d?.autoFitUseScrollbar===!1?"viewport":"body";let y=0;const p=(x,E,H)=>Math.min(H,Math.max(E,x)),w=()=>{if(y=0,!t.isConnected||!t.open)return;const x=Math.max(o,window.innerWidth-32),E=Math.max(L,window.innerHeight-32);e.style.width="auto",e.style.height="auto",e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible";const H=Math.ceil(e.scrollWidth),n=Math.ceil(e.scrollHeight),i=H>x,h=n>E;if(u==="body"){const v=p(H,o,x),b=p(n,L,E);e.style.width=`${v}px`,e.style.maxWidth=`${x}px`,e.style.height=`${b}px`,e.style.maxHeight=`${E}px`;const I=c.offsetHeight,O=f.offsetHeight,R=Math.max(64,b-I-O);h?(s.style.maxHeight=`${R}px`,s.style.overflowY="auto"):(s.style.maxHeight="none",s.style.overflowY="hidden"),s.style.overflowX=i?"auto":"hidden",t.classList.remove("sod-modal-viewport-scroll")}else if(u==="hybrid")if(n>E*M){const b=Math.max(H,o),I=Math.max(n,L);e.style.width=`${b}px`,e.style.maxWidth="none",e.style.height=`${I}px`,e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",t.classList.add("sod-modal-viewport-scroll")}else{const b=p(H,o,x),I=p(n,L,E);e.style.width=`${b}px`,e.style.maxWidth=`${x}px`,e.style.height=`${I}px`,e.style.maxHeight=`${E}px`;const O=c.offsetHeight,R=f.offsetHeight,B=Math.max(64,I-O-R);h?(s.style.maxHeight=`${B}px`,s.style.overflowY="auto"):(s.style.maxHeight="none",s.style.overflowY="hidden"),s.style.overflowX=i?"auto":"hidden",t.classList.remove("sod-modal-viewport-scroll")}else if(u==="viewport"){const v=Math.max(H,o),b=Math.max(n,L);e.style.width=`${v}px`,e.style.maxWidth="none",e.style.height=`${b}px`,e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",b>E?t.classList.add("sod-modal-viewport-scroll"):t.classList.remove("sod-modal-viewport-scroll")}else{const v=i?Math.max(H,o):p(H,o,x);if(i||h){const b=Math.max(n,L);e.style.width=`${v}px`,e.style.maxWidth="none",e.style.height=`${b}px`,e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",t.classList.add("sod-modal-viewport-scroll")}else e.style.width=`${v}px`,e.style.maxWidth=`${x}px`,e.style.height="auto",e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",t.classList.remove("sod-modal-viewport-scroll")}},a=()=>{y===0&&(y=window.requestAnimationFrame(w))},r=new ResizeObserver(()=>{a()}),g=new MutationObserver(()=>{a()}),m=()=>{a()},A=()=>{a()};t.addEventListener("sod:refit",A),r.observe(s),r.observe(c),r.observe(f),$&&(g.observe(s,{subtree:!0,childList:!0,characterData:!0,attributes:!0}),s.addEventListener("load",m,!0),s.addEventListener("error",m,!0));const S=()=>{a()};return window.addEventListener("resize",S),a(),()=>{y!==0&&(window.cancelAnimationFrame(y),y=0),r.disconnect(),g.disconnect(),window.removeEventListener("resize",S),t.removeEventListener("sod:refit",A),s.removeEventListener("load",m,!0),s.removeEventListener("error",m,!0),t.classList.remove("sod-modal-viewport-scroll"),s.style.maxHeight="",s.style.overflowY="",s.style.overflowX=""}}class D{static modalRegistry=new Map;static handleRegistry=new WeakMap;static modalIdSeed=0;static createAutoModalId(){return this.modalIdSeed+=1,`sod-modal-${this.modalIdSeed}`}static revealExisting(e,c){if(!e.isConnected)return{dialog:e,close:()=>F(e),refit:()=>e.dispatchEvent(new Event("sod:refit")),setFooterButtons:()=>{},updateFooterButton:()=>!1,onAction:()=>()=>{},id:e.dataset.sodId};const s=e.querySelector(".sod-panel");s?.classList.remove("is-closing"),document.body.append(e),e.open||(c?e.showModal():e.show()),e.dispatchEvent(new Event("sod:refit")),s?.focus();const f=this.handleRegistry.get(e);return f?f():{dialog:e,close:()=>F(e),refit:()=>e.dispatchEvent(new Event("sod:refit")),setFooterButtons:()=>{},updateFooterButton:()=>!1,onAction:()=>()=>{},id:e.dataset.sodId}}static open(e){const c=e.kind??"modal",s="useModal"in e?e.useModal??!0:!0,f=c==="modal"?e:void 0,d=c==="modal"&&("autoFitSize"in e?e.autoFitSize!==!1:!0);let l,M=!1,$=e.confirmAction??"hide";if(c==="modal"){const n="id"in e&&e.id?.trim()?e.id.trim():void 0;if(M=!!n,l=n??this.createAutoModalId(),e.confirmAction===void 0&&M&&($="destroy"),n){const i=this.modalRegistry.get(l);if(i&&i.isConnected){const h=this.revealExisting(i,s);if(e.onAction){const v=h.onAction(e.onAction);i.addEventListener("close",v,{once:!0})}return"onReused"in e&&e.onReused?.(h),h}}this.modalRegistry.delete(l)}const o=document.createElement("dialog");o.className=`sod-dialog sod-${c}`;const L=[];l&&(o.dataset.sodId=l,M&&(o.dataset.sodPersistent="true"));const u=document.createElement("section");if(u.className="sod-panel",u.tabIndex=-1,c==="offcanvas"){const n="placement"in e?e.placement??"end":"end",i="animation"in e?e.animation??"slide":"slide";u.classList.add(`sod-placement-${n}`),u.classList.add(`sod-anim-${i}`)}else{const n="position"in e?e.position??"center":"center",i="animation"in e?e.animation??"fade":"fade";u.classList.add(`sod-modal-pos-${n}`),u.classList.add(`sod-modal-anim-${i}`),d&&u.classList.add("sod-modal-autofit")}const y=document.createElement("header");y.className="sod-header";const p=document.createElement("h2");p.className="sod-title",p.textContent=e.title;const w=document.createElement("button");w.type="button",w.className="sod-close",w.setAttribute("aria-label","Close"),w.textContent="×",w.addEventListener("click",()=>F(o)),y.append(p,w);const a=document.createElement("div");a.className="sod-body",W(a,e.content);const r=document.createElement("footer");r.className="sod-footer",r.dataset.align=e.footerAlign??"end";const g=new Set;e.onAction&&g.add(e.onAction);const m=n=>(g.add(n),()=>{g.delete(n)});let A=e.footerButtons?[...e.footerButtons]:[{id:"cancel",label:e.cancelText??"取消",role:"cancel",variant:"outline"},{id:"confirm",label:e.confirmText??"确认",role:"confirm",variant:"primary"}];const S=()=>({dialog:o,close:()=>F(o),refit:()=>o.dispatchEvent(new Event("sod:refit")),setFooterButtons:n=>{A=[...n],E(),o.dispatchEvent(new Event("sod:refit"))},updateFooterButton:(n,i)=>{const h=A.findIndex(v=>v.id===n);return h<0?!1:(A[h]={...A[h],...i},E(),o.dispatchEvent(new Event("sod:refit")),!0)},onAction:n=>m(n),id:l}),x=(n,i)=>{if(typeof i=="string"){n.textContent=i;return}n.append(i)},E=()=>{if(r.replaceChildren(),e.hideFooter||A.length===0){r.hidden=!0;return}r.hidden=!1;for(const n of A){const i=document.createElement("button");i.type="button",i.className=`sod-btn ${N(n.variant)}`,n.className?.trim()&&(i.className=`${i.className} ${n.className.trim()}`),n.id?.trim()&&(i.dataset.action=n.id.trim()),n.disabled&&(i.disabled=!0),n.attrs&&Object.entries(n.attrs).forEach(([h,v])=>{i.setAttribute(h,v)}),x(i,n.label),i.addEventListener("click",h=>{(async()=>{const v=S(),I={action:n.id??n.role??"custom",button:n,buttonElement:i,dialog:o,event:h,handle:v};if(await n.onClick?.(I)===!1)return;n.role==="cancel"&&e.onCancel?.(),n.role==="confirm"&&e.onConfirm?.(),g.forEach(B=>{B(I)});const R=k(n,$);R==="hide"&&F(o,"hide"),R==="destroy"&&F(o,"destroy")})()}),r.append(i)}};E(),u.append(y,a,r),d&&L.push(Y(o,u,y,a,r,f)),c==="modal"&&"draggable"in e&&e.draggable&&T(u,e.dragHandle),o.append(u),(e.closeOnBackdrop??!0)&&o.addEventListener("click",n=>{n.target===o&&F(o)}),(e.closeOnEsc??!0)||o.addEventListener("cancel",n=>{n.preventDefault()}),o.addEventListener("close",()=>{const n=o.dataset.sodPersistent==="true",i=o.dataset.sodDestroy==="true";(!n||i)&&(L.forEach(h=>h()),g.clear(),o.remove(),l&&this.modalRegistry.delete(l),this.handleRegistry.delete(o),delete o.dataset.sodDestroy)}),document.body.append(o),s?o.showModal():o.show(),o.dispatchEvent(new Event("sod:refit")),l&&this.modalRegistry.set(l,o),this.handleRegistry.set(o,S);const H=S();return c==="modal"&&"onCreated"in e&&e.onCreated?.(H),H}static openModal(e){return this.open({...e,kind:"modal"})}static openOffcanvas(e){return this.open({...e,kind:"offcanvas"})}}function X(t){return D.openModal(t)}function q(t){return D.openOffcanvas(t)}C.SoDialog=D,C.openModal=X,C.openOffcanvas=q,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})}));
|
|
1
|
+
(function(H,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(H=typeof globalThis<"u"?globalThis:H||self,B(H.SoDialog={}))})(this,(function(H){"use strict";function B(n,e){if(typeof e=="string"){n.innerHTML=e;return}n.append(e)}function I(n,e="hide"){if(e==="destroy"){n.dataset.sodDestroy="true",n.open&&n.close(),n.remove();return}n.open&&n.close()}function F(n,e){return n.action?n.action:n.role==="confirm"?e:n.role==="cancel"?"hide":"none"}function k(n){return n==="danger"?"sod-btn-danger":n==="success"?"sod-btn-success":n==="ghost"?"sod-btn-ghost":n==="link"?"sod-btn-link":n==="outline"?"sod-btn-outline":"sod-btn-primary"}function D(n,e){const t=Array.isArray(e)?e.length>0?e:["header"]:[e??"header"],s=[],i=o=>{o&&(s.includes(o)||s.push(o))};for(const o of t){if(o==="panel"){i(n);continue}if(o==="header"){i(n.querySelector(".sod-header"));continue}if(o==="title"){i(n.querySelector(".sod-title"));continue}if(o==="body"){i(n.querySelector(".sod-body"));continue}n.querySelectorAll(o).forEach(r=>{i(r)})}return s.length===0&&i(n.querySelector(".sod-header")),s}function V(n,e){const t=D(n,e);if(t.length===0)return;n.classList.add("sod-modal-draggable"),t.forEach(m=>{m.classList.add("sod-drag-handle")});let s=!1,i=0,o=0,r=null,d=null,h=0,a=0,f=0;const v=document.body.style.userSelect,E=(m,u)=>{const y=n.getBoundingClientRect(),p=Math.max(0,window.innerWidth-y.width),O=Math.max(0,window.innerHeight-y.height),T=Math.min(0,window.innerWidth-y.width),b=Math.min(0,window.innerHeight-y.height);return{left:Math.min(p,Math.max(T,m)),top:Math.min(O,Math.max(b,u))}},R=m=>{if(!s)return;const u=E(m.clientX-i,m.clientY-o);a=u.left,f=u.top,h===0&&(h=window.requestAnimationFrame(()=>{h=0,n.style.inset="auto",n.style.left=`${a}px`,n.style.top=`${f}px`,n.style.right="auto",n.style.bottom="auto",n.style.margin="0",n.style.transform="none"}))},x=()=>{s=!1,t.forEach(m=>{m.classList.remove("is-dragging")}),n.classList.remove("sod-is-dragging"),n.style.willChange="",document.body.style.userSelect=v,h!==0&&(window.cancelAnimationFrame(h),h=0),r!==null&&d!==null&&d.hasPointerCapture&&d.hasPointerCapture(r)&&d.releasePointerCapture(r),r=null,d=null,window.removeEventListener("pointermove",R),window.removeEventListener("pointerup",x),window.removeEventListener("pointercancel",x)};t.forEach(m=>{m.addEventListener("pointerdown",u=>{if(u.button!==0||u.target?.closest("button, input, select, textarea, a"))return;u.preventDefault(),n.classList.add("sod-is-dragging"),n.style.animation="none",n.style.transition="none",n.style.transform="none";const p=n.getBoundingClientRect();i=u.clientX-p.left,o=u.clientY-p.top,s=!0,r=u.pointerId,d=m,m.setPointerCapture(u.pointerId),n.style.position="fixed",n.style.left=`${p.left}px`,n.style.top=`${p.top}px`,n.style.width=`${Math.round(p.width)}px`,n.style.height=`${Math.round(p.height)}px`,n.style.inset="auto",n.style.right="auto",n.style.bottom="auto",n.style.margin="0",n.style.willChange="left, top",m.classList.add("is-dragging"),document.body.style.userSelect="none",window.addEventListener("pointermove",R),window.addEventListener("pointerup",x),window.addEventListener("pointercancel",x)})})}function q(n,e,t,s,i,o){const d=Math.max(1,o?.hybridSwitchRatio??1.35),h=o?.refitOnContentChange??!0,a=Math.max(120,o?.autoFitMinWidth??280),f=Math.max(100,o?.autoFitMinHeight??160),v=o?.scrollMode?o.scrollMode:o?.autoFitUseScrollbar===!1?"viewport":"body";let E=0;const R=(b,M,L)=>Math.min(L,Math.max(M,b)),x=()=>{if(E=0,!n.isConnected||!n.open)return;const b=Math.max(a,window.innerWidth-32),M=Math.max(f,window.innerHeight-32);e.style.width="auto",e.style.height="auto",e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible";const L=Math.ceil(e.scrollWidth),l=Math.ceil(e.scrollHeight),c=L>b,g=l>M;if(v==="body"){const w=R(L,a,b),S=R(l,f,M);e.style.width=`${w}px`,e.style.maxWidth=`${b}px`,e.style.height=`${S}px`,e.style.maxHeight=`${M}px`;const A=t.offsetHeight,P=i.offsetHeight,C=Math.max(64,S-A-P);g?(s.style.maxHeight=`${C}px`,s.style.overflowY="auto"):(s.style.maxHeight="none",s.style.overflowY="hidden"),s.style.overflowX=c?"auto":"hidden",n.classList.remove("sod-modal-viewport-scroll")}else if(v==="hybrid")if(l>M*d){const S=Math.max(L,a),A=Math.max(l,f);e.style.width=`${S}px`,e.style.maxWidth="none",e.style.height=`${A}px`,e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",n.classList.add("sod-modal-viewport-scroll")}else{const S=R(L,a,b),A=R(l,f,M);e.style.width=`${S}px`,e.style.maxWidth=`${b}px`,e.style.height=`${A}px`,e.style.maxHeight=`${M}px`;const P=t.offsetHeight,C=i.offsetHeight,$=Math.max(64,A-P-C);g?(s.style.maxHeight=`${$}px`,s.style.overflowY="auto"):(s.style.maxHeight="none",s.style.overflowY="hidden"),s.style.overflowX=c?"auto":"hidden",n.classList.remove("sod-modal-viewport-scroll")}else if(v==="viewport"){const w=Math.max(L,a),S=Math.max(l,f);e.style.width=`${w}px`,e.style.maxWidth="none",e.style.height=`${S}px`,e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",S>M?n.classList.add("sod-modal-viewport-scroll"):n.classList.remove("sod-modal-viewport-scroll")}else{const w=c?Math.max(L,a):R(L,a,b);if(c||g){const S=Math.max(l,f);e.style.width=`${w}px`,e.style.maxWidth="none",e.style.height=`${S}px`,e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",n.classList.add("sod-modal-viewport-scroll")}else e.style.width=`${w}px`,e.style.maxWidth=`${b}px`,e.style.height="auto",e.style.maxHeight="none",s.style.maxHeight="none",s.style.overflowY="visible",s.style.overflowX="visible",n.classList.remove("sod-modal-viewport-scroll")}},m=()=>{E===0&&(E=window.requestAnimationFrame(x))},u=new ResizeObserver(()=>{m()}),y=new MutationObserver(()=>{m()}),p=()=>{m()},O=()=>{m()};n.addEventListener("sod:refit",O),u.observe(s),u.observe(t),u.observe(i),h&&(y.observe(s,{subtree:!0,childList:!0,characterData:!0,attributes:!0}),s.addEventListener("load",p,!0),s.addEventListener("error",p,!0));const T=()=>{m()};return window.addEventListener("resize",T),m(),()=>{E!==0&&(window.cancelAnimationFrame(E),E=0),u.disconnect(),y.disconnect(),window.removeEventListener("resize",T),n.removeEventListener("sod:refit",O),s.removeEventListener("load",p,!0),s.removeEventListener("error",p,!0),n.classList.remove("sod-modal-viewport-scroll"),s.style.maxHeight="",s.style.overflowY="",s.style.overflowX=""}}class W{static modalRegistry=new Map;static handleRegistry=new WeakMap;static modalIdSeed=0;static createAutoModalId(){return this.modalIdSeed+=1,`sod-modal-${this.modalIdSeed}`}static revealExisting(e,t){if(!e.isConnected)return{dialog:e,close:()=>I(e),refit:()=>e.dispatchEvent(new Event("sod:refit")),setFooterButtons:()=>{},updateFooterButton:()=>!1,onAction:()=>()=>{},id:e.dataset.sodId};const s=e.querySelector(".sod-panel");s?.classList.remove("is-closing"),document.body.append(e),e.open||(t?e.showModal():e.show()),e.dispatchEvent(new Event("sod:refit")),s?.focus();const i=this.handleRegistry.get(e);return i?i():{dialog:e,close:()=>I(e),refit:()=>e.dispatchEvent(new Event("sod:refit")),setFooterButtons:()=>{},updateFooterButton:()=>!1,onAction:()=>()=>{},id:e.dataset.sodId}}static open(e){const t=e.kind??"modal",s="useModal"in e?e.useModal??!0:!0,i=t==="modal"?e:void 0,o=t==="modal"&&("autoFitSize"in e?e.autoFitSize!==!1:!0);let r,d=!1,h=e.confirmAction??"hide";if(t==="modal"){const l="id"in e&&e.id?.trim()?e.id.trim():void 0;if(d=!!l,r=l??this.createAutoModalId(),e.confirmAction===void 0&&d&&(h="destroy"),l){const c=this.modalRegistry.get(r);if(c&&c.isConnected){const g=this.revealExisting(c,s);if(e.onAction){const w=g.onAction(e.onAction);c.addEventListener("close",w,{once:!0})}return"onReused"in e&&e.onReused?.(g),g}}this.modalRegistry.delete(r)}const a=document.createElement("dialog");a.className=`sod-dialog sod-${t}`;const f=[];r&&(a.dataset.sodId=r,d&&(a.dataset.sodPersistent="true"));const v=document.createElement("section");if(v.className="sod-panel",v.tabIndex=-1,t==="offcanvas"){const l="placement"in e?e.placement??"end":"end",c="animation"in e?e.animation??"slide":"slide";v.classList.add(`sod-placement-${l}`),v.classList.add(`sod-anim-${c}`)}else{const l="position"in e?e.position??"center":"center",c="animation"in e?e.animation??"fade":"fade";v.classList.add(`sod-modal-pos-${l}`),v.classList.add(`sod-modal-anim-${c}`),o&&v.classList.add("sod-modal-autofit")}const E=document.createElement("header");E.className="sod-header";const R=document.createElement("h2");R.className="sod-title",R.textContent=e.title;const x=document.createElement("button");x.type="button",x.className="sod-close",x.setAttribute("aria-label","Close"),x.textContent="×",x.addEventListener("click",()=>I(a)),E.append(R,x);const m=document.createElement("div");m.className="sod-body",B(m,e.content);const u=document.createElement("footer");u.className="sod-footer",u.dataset.align=e.footerAlign??"end";const y=new Set;e.onAction&&y.add(e.onAction);const p=l=>(y.add(l),()=>{y.delete(l)});let O=e.footerButtons?[...e.footerButtons]:[{id:"cancel",label:e.cancelText??"取消",role:"cancel",variant:"outline"},{id:"confirm",label:e.confirmText??"确认",role:"confirm",variant:"primary"}];const T=()=>({dialog:a,close:()=>I(a),refit:()=>a.dispatchEvent(new Event("sod:refit")),setFooterButtons:l=>{O=[...l],M(),a.dispatchEvent(new Event("sod:refit"))},updateFooterButton:(l,c)=>{const g=O.findIndex(w=>w.id===l);return g<0?!1:(O[g]={...O[g],...c},M(),a.dispatchEvent(new Event("sod:refit")),!0)},onAction:l=>p(l),id:r}),b=(l,c)=>{if(typeof c=="string"){l.textContent=c;return}l.append(c)},M=()=>{if(u.replaceChildren(),e.hideFooter||O.length===0){u.hidden=!0;return}u.hidden=!1;for(const l of O){const c=document.createElement("button");c.type="button",c.className=`sod-btn ${k(l.variant)}`,l.className?.trim()&&(c.className=`${c.className} ${l.className.trim()}`),l.id?.trim()&&(c.dataset.action=l.id.trim()),l.disabled&&(c.disabled=!0),l.attrs&&Object.entries(l.attrs).forEach(([g,w])=>{c.setAttribute(g,w)}),b(c,l.label),c.addEventListener("click",g=>{(async()=>{const w=T(),A={action:l.id??l.role??"custom",button:l,buttonElement:c,dialog:a,event:g,handle:w};if(await l.onClick?.(A)===!1)return;l.role==="cancel"&&e.onCancel?.(),l.role==="confirm"&&e.onConfirm?.(),y.forEach($=>{$(A)});const C=F(l,h);C==="hide"&&I(a,"hide"),C==="destroy"&&I(a,"destroy")})()}),u.append(c)}};M(),v.append(E,m,u),o&&f.push(q(a,v,E,m,u,i)),t==="modal"&&"draggable"in e&&e.draggable&&V(v,e.dragHandle),a.append(v),(e.closeOnBackdrop??!0)&&a.addEventListener("click",l=>{l.target===a&&I(a)}),(e.closeOnEsc??!0)||a.addEventListener("cancel",l=>{l.preventDefault()}),a.addEventListener("close",()=>{const l=a.dataset.sodPersistent==="true",c=a.dataset.sodDestroy==="true";(!l||c)&&(f.forEach(g=>g()),y.clear(),a.remove(),r&&this.modalRegistry.delete(r),this.handleRegistry.delete(a),delete a.dataset.sodDestroy)}),document.body.append(a),s?a.showModal():a.show(),a.dispatchEvent(new Event("sod:refit")),r&&this.modalRegistry.set(r,a),this.handleRegistry.set(a,T);const L=T();return t==="modal"&&"onCreated"in e&&e.onCreated?.(L),L}static openModal(e){return this.open({...e,kind:"modal"})}static openOffcanvas(e){return this.open({...e,kind:"offcanvas"})}}class N{static placementState=new Map;static recordById=new Map;static idSeed=0;static defaults={placement:"top-end",variant:"default",duration:3e3,showProgress:!0,closable:!0,pauseOnHover:!0,pauseOnWindowBlur:!1,duplicateStrategy:"update",newestOnTop:!0,maxVisible:3};static normalizeOptions(e){const t=e.duration===!1?!1:Math.max(0,e.duration??this.defaults.duration);return{placement:e.placement??this.defaults.placement,variant:e.variant??this.defaults.variant,duration:t,showProgress:e.showProgress??this.defaults.showProgress,closable:e.closable??this.defaults.closable,pauseOnHover:e.pauseOnHover??this.defaults.pauseOnHover,pauseOnWindowBlur:e.pauseOnWindowBlur??this.defaults.pauseOnWindowBlur,duplicateStrategy:e.duplicateStrategy??this.defaults.duplicateStrategy,newestOnTop:e.newestOnTop??this.defaults.newestOnTop,maxVisible:Math.max(1,e.maxVisible??this.defaults.maxVisible),title:e.title,content:e.content,className:e.className,attrs:e.attrs,onShown:e.onShown,onClose:e.onClose}}static createAutoToastId(){return this.idSeed+=1,`sot-toast-${this.idSeed}`}static createStackedToastId(e){let t=1,s=`${e}-${t}`;for(;this.recordById.has(s);)t+=1,s=`${e}-${t}`;return s}static resolveRole(e){return e==="danger"?"alert":"status"}static getPlacementState(e){const t=this.placementState.get(e);if(t)return t;const s=document.createElement("div");s.className=`sod-toast-layer sod-toast-layer-${e}`,s.setAttribute("aria-live","polite"),s.setAttribute("aria-atomic","false"),document.body.append(s);const i={container:s,active:[],pending:[]};return this.placementState.set(e,i),i}static createToastElement(e){const{options:t}=e,s=document.createElement("article");s.className=`sod-toast sod-toast-${t.variant}`,t.className?.trim()&&(s.className=`${s.className} ${t.className.trim()}`),s.dataset.toastId=e.id,s.setAttribute("role",this.resolveRole(t.variant)),t.attrs&&Object.entries(t.attrs).forEach(([a,f])=>{s.setAttribute(a,f)});const i=document.createElement("header");i.className="sod-toast-header";let o=null;t.title?.trim()&&(o=document.createElement("strong"),o.className="sod-toast-title",o.textContent=t.title,i.append(o));let r=null;t.closable&&(r=document.createElement("button"),r.type="button",r.className="sod-toast-close",r.setAttribute("aria-label","Close"),r.textContent="×",r.addEventListener("click",()=>{this.closeRecord(e,"close-button")}),i.append(r)),i.childElementCount>0&&s.append(i);const d=document.createElement("div");d.className="sod-toast-body",B(d,t.content),s.append(d);let h=null;if(t.showProgress&&(h=document.createElement("div"),h.className="sod-toast-progress",s.append(h)),t.pauseOnHover){const a=()=>this.pauseRecord(e),f=()=>this.resumeRecord(e);s.addEventListener("mouseenter",a),s.addEventListener("mouseleave",f),e.cleanupListeners.push(()=>{s.removeEventListener("mouseenter",a),s.removeEventListener("mouseleave",f)})}if(t.pauseOnWindowBlur){const a=()=>{e.paused||e.status!=="active"||(e.pausedByWindowBlur=!0,this.pauseRecord(e))},f=()=>{e.pausedByWindowBlur&&(e.pausedByWindowBlur=!1,this.resumeRecord(e))};window.addEventListener("blur",a),window.addEventListener("focus",f),e.cleanupListeners.push(()=>{window.removeEventListener("blur",a),window.removeEventListener("focus",f)})}e.element=s,e.bodyElement=d,e.titleElement=o,e.closeButton=r,e.progressElement=h}static resetProgressAnimation(e,t){!e.progressElement||!e.options.showProgress||(e.progressElement.style.display="block",e.progressElement.style.animation="none",e.progressElement.style.animationPlayState="running",e.progressElement.offsetWidth,e.progressElement.style.animation=`sod-toast-progress-countdown ${Math.max(1,t)}ms linear forwards`)}static hideProgress(e){e.progressElement&&(e.progressElement.style.display="none",e.progressElement.style.animation="none")}static isRecordActive(e,t){return e.active.includes(t)}static isRecordPending(e,t){return e.pending.includes(t)}static mountRecord(e,t){t.status="active",t.options.newestOnTop?e.container.prepend(t.element):e.container.append(t.element),e.active.push(t),this.startRecordTimer(t),t.options.onShown?.(t.handle)}static queueRecord(e,t){t.status="pending",e.pending.push(t)}static startRecordTimer(e){if(this.clearRecordTimer(e),e.options.duration===!1){e.remainingMs=!1,e.startedAt=null,this.hideProgress(e);return}const t=Math.max(0,e.remainingMs===!1?e.options.duration:e.remainingMs);if(t===0){this.closeRecord(e,"timeout");return}e.startedAt=Date.now(),e.remainingMs=t,this.resetProgressAnimation(e,t),e.timerId=window.setTimeout(()=>{e.timerId=null,this.closeRecord(e,"timeout")},t)}static clearRecordTimer(e){e.timerId!==null&&(window.clearTimeout(e.timerId),e.timerId=null)}static pauseRecord(e){if(e.paused||e.status!=="active"||e.options.duration===!1)return;const t=e.startedAt??Date.now(),s=Math.max(0,Date.now()-t),i=e.remainingMs===!1?e.options.duration:e.remainingMs;e.remainingMs=Math.max(0,i-s),e.startedAt=null,e.paused=!0,e.progressElement&&(e.progressElement.style.animationPlayState="paused"),this.clearRecordTimer(e)}static resumeRecord(e){!e.paused||e.status!=="active"||(e.paused=!1,e.progressElement&&(e.progressElement.style.animationPlayState="running"),this.startRecordTimer(e))}static rebuildRecordElement(e){const t=e.element,s=t.parentElement;e.cleanupListeners.forEach(i=>i()),e.cleanupListeners=[],t.remove(),this.createToastElement(e),s&&e.status==="active"&&(e.options.newestOnTop?s.prepend(e.element):s.append(e.element),this.startRecordTimer(e))}static moveRecordToPlacement(e,t){const s=e.options.placement;if(s===t)return;const i=this.placementState.get(s),o=this.getPlacementState(t),r=!!(i&&this.removeFromArray(i.active,e)),d=!!(i&&this.removeFromArray(i.pending,e));if(e.options.placement=t,this.clearRecordTimer(e),d&&!r){this.queueRecord(o,e),this.drainQueue(o,t),i&&this.drainQueue(i,s);return}o.active.length<e.options.maxVisible?this.mountRecord(o,e):this.queueRecord(o,e),i&&this.drainQueue(i,s)}static updateRecord(e,t){if(t.title!==void 0){const i=t.title.trim();if(e.options.title=i.length>0?i:void 0,e.options.title)if(e.titleElement)e.titleElement.textContent=e.options.title;else{const o=e.element.querySelector(".sod-toast-header");if(o){const r=document.createElement("strong");r.className="sod-toast-title",r.textContent=e.options.title,o.prepend(r),e.titleElement=r}}else e.titleElement&&(e.titleElement.remove(),e.titleElement=null)}t.content!==void 0&&(e.options.content=t.content,e.bodyElement.replaceChildren(),B(e.bodyElement,t.content)),t.variant!==void 0&&(e.options.variant=t.variant,e.element.classList.remove("sod-toast-default","sod-toast-info","sod-toast-success","sod-toast-warning","sod-toast-danger"),e.element.classList.add(`sod-toast-${t.variant}`),e.element.setAttribute("role",this.resolveRole(t.variant))),t.duration!==void 0&&(e.options.duration=t.duration===!1?!1:Math.max(0,t.duration),e.remainingMs=e.options.duration===!1?!1:e.options.duration,e.paused=!1,e.status==="active"&&this.startRecordTimer(e)),t.maxVisible!==void 0&&(e.options.maxVisible=Math.max(1,t.maxVisible)),t.newestOnTop!==void 0&&(e.options.newestOnTop=t.newestOnTop);let s=!1;t.closable!==void 0&&t.closable!==e.options.closable&&(e.options.closable=t.closable,s=!0),t.pauseOnHover!==void 0&&t.pauseOnHover!==e.options.pauseOnHover&&(e.options.pauseOnHover=t.pauseOnHover,s=!0),t.pauseOnWindowBlur!==void 0&&t.pauseOnWindowBlur!==e.options.pauseOnWindowBlur&&(e.options.pauseOnWindowBlur=t.pauseOnWindowBlur,s=!0),t.duplicateStrategy!==void 0&&(e.options.duplicateStrategy=t.duplicateStrategy),t.showProgress!==void 0&&t.showProgress!==e.options.showProgress&&(e.options.showProgress=t.showProgress,s=!0),t.className!==void 0&&(e.options.className=t.className,s=!0),t.attrs!==void 0&&(e.options.attrs=t.attrs,s=!0),s&&this.rebuildRecordElement(e),t.placement&&t.placement!==e.options.placement&&this.moveRecordToPlacement(e,t.placement)}static removeStateContainerIfEmpty(e){const t=this.placementState.get(e);t&&(t.active.length>0||t.pending.length>0||(t.container.remove(),this.placementState.delete(e)))}static drainQueue(e,t){let s=!0;for(;s&&e.pending.length>0;){const i=e.pending[0];if(e.active.length>=i.options.maxVisible){s=!1;continue}e.pending.shift(),this.mountRecord(e,i)}this.removeStateContainerIfEmpty(t)}static removeFromArray(e,t){const s=e.indexOf(t);return s<0?!1:(e.splice(s,1),!0)}static finalizeClose(e,t){if(e.status==="closed")return;const s=e.options.placement,i=this.placementState.get(s);this.clearRecordTimer(e),e.cleanupListeners.forEach(o=>o()),e.cleanupListeners=[],e.element.remove(),e.status="closed",i&&(this.removeFromArray(i.active,e),this.removeFromArray(i.pending,e)),this.recordById.delete(e.id),e.options.onClose?.(t,e.handle),i?this.drainQueue(i,s):this.removeStateContainerIfEmpty(s)}static closeRecord(e,t){if(e.status==="closed"||e.status==="closing")return;const s=e.options.placement,i=this.placementState.get(s);if(!!(i&&this.isRecordPending(i,e)&&!this.isRecordActive(i,e))){this.finalizeClose(e,t);return}e.status="closing",this.clearRecordTimer(e),e.element.classList.add("is-closing");let r=!1;const d=()=>{r||(r=!0,this.finalizeClose(e,t))},h=a=>{a.target===e.element&&(e.element.removeEventListener("animationend",h),d())};e.element.addEventListener("animationend",h),window.setTimeout(()=>{e.element.removeEventListener("animationend",h),d()},220)}static createHandle(e){return{id:e.id,get element(){return e.element},close:(t="programmatic")=>{this.closeRecord(e,t)},update:t=>{this.updateRecord(e,t)},pause:()=>{this.pauseRecord(e)},resume:()=>{this.resumeRecord(e)}}}static show(e){const s=e.id?.trim()||this.createAutoToastId(),i=this.normalizeOptions(e),o=this.recordById.get(s);if(o){const a=i.duplicateStrategy;if(a==="ignore")return o.handle;if(a==="stack"){const f=this.createStackedToastId(s);return this.show({...e,id:f,duplicateStrategy:"update"})}return this.updateRecord(o,{title:e.title,content:e.content,variant:e.variant,duration:a==="restart-timer"?e.duration===void 0?o.options.duration:i.duration:e.duration===void 0?void 0:i.duration,placement:e.placement,closable:e.closable,pauseOnHover:e.pauseOnHover,pauseOnWindowBlur:e.pauseOnWindowBlur,duplicateStrategy:e.duplicateStrategy,newestOnTop:e.newestOnTop,maxVisible:e.maxVisible,showProgress:e.showProgress,className:e.className,attrs:e.attrs}),o.options.onClose=i.onClose,o.options.onShown=i.onShown,o.handle}const d={id:s,options:i,element:document.createElement("article"),status:"pending",timerId:null,remainingMs:i.duration,startedAt:null,paused:!1,pausedByWindowBlur:!1,closeButton:null,progressElement:null,bodyElement:document.createElement("div"),titleElement:null,cleanupListeners:[],handle:void 0};d.handle=this.createHandle(d),this.createToastElement(d),this.recordById.set(s,d);const h=this.getPlacementState(i.placement);return h.active.length<i.maxVisible?this.mountRecord(h,d):this.queueRecord(h,d),d.handle}static clear(e){(e?[e]:Array.from(this.placementState.keys())).forEach(s=>{const i=this.placementState.get(s);if(!i)return;const o=[...i.active];[...i.pending].forEach(d=>this.closeRecord(d,"container-clear")),o.forEach(d=>this.closeRecord(d,"container-clear"))})}static configure(e){e.placement&&(this.defaults.placement=e.placement),e.variant&&(this.defaults.variant=e.variant),e.duration!==void 0&&(this.defaults.duration=e.duration===!1?3e3:Math.max(0,e.duration)),e.showProgress!==void 0&&(this.defaults.showProgress=e.showProgress),e.closable!==void 0&&(this.defaults.closable=e.closable),e.pauseOnHover!==void 0&&(this.defaults.pauseOnHover=e.pauseOnHover),e.pauseOnWindowBlur!==void 0&&(this.defaults.pauseOnWindowBlur=e.pauseOnWindowBlur),e.duplicateStrategy!==void 0&&(this.defaults.duplicateStrategy=e.duplicateStrategy),e.newestOnTop!==void 0&&(this.defaults.newestOnTop=e.newestOnTop),e.maxVisible!==void 0&&(this.defaults.maxVisible=Math.max(1,e.maxVisible))}static success(e,t={}){return this.show({...t,content:e,variant:"success"})}static error(e,t={}){return this.show({...t,content:e,variant:"danger"})}static info(e,t={}){return this.show({...t,content:e,variant:"info"})}static warning(e,t={}){return this.show({...t,content:e,variant:"warning"})}static closeAll(){this.clear()}}function z(n){return W.openModal(n)}function Y(n){return W.openOffcanvas(n)}function X(n){return N.show(n)}H.SoDialog=W,H.SoToast=N,H.openModal=z,H.openOffcanvas=Y,H.toast=X,Object.defineProperty(H,Symbol.toStringTag,{value:"Module"})}));
|
package/dist/types/lib.d.ts
CHANGED
|
@@ -10,6 +10,10 @@ export type SoModalScrollMode = 'body' | 'viewport' | 'none' | 'hybrid';
|
|
|
10
10
|
export type SoFooterButtonVariant = 'primary' | 'outline' | 'danger' | 'success' | 'ghost' | 'link';
|
|
11
11
|
export type SoFooterAlign = 'start' | 'center' | 'end' | 'between';
|
|
12
12
|
export type SoFooterButtonAction = 'none' | 'hide' | 'destroy';
|
|
13
|
+
export type SoToastPlacement = 'top-start' | 'top-center' | 'top-end' | 'bottom-start' | 'bottom-center' | 'bottom-end';
|
|
14
|
+
export type SoToastVariant = 'default' | 'info' | 'success' | 'warning' | 'danger';
|
|
15
|
+
export type SoToastCloseReason = 'timeout' | 'manual' | 'close-button' | 'container-clear' | 'programmatic';
|
|
16
|
+
export type SoToastDuplicateStrategy = 'update' | 'ignore' | 'restart-timer' | 'stack';
|
|
13
17
|
export interface SoDialogFooterButton {
|
|
14
18
|
id?: string;
|
|
15
19
|
label: string | Node;
|
|
@@ -78,6 +82,33 @@ export interface SoDialogFooterActionContext {
|
|
|
78
82
|
handle: SoDialogHandle;
|
|
79
83
|
}
|
|
80
84
|
export type SoDialogActionListener = (context: SoDialogFooterActionContext) => void;
|
|
85
|
+
export interface SoToastOptions {
|
|
86
|
+
id?: string;
|
|
87
|
+
title?: string;
|
|
88
|
+
content: string | Node;
|
|
89
|
+
placement?: SoToastPlacement;
|
|
90
|
+
variant?: SoToastVariant;
|
|
91
|
+
duration?: number | false;
|
|
92
|
+
showProgress?: boolean;
|
|
93
|
+
closable?: boolean;
|
|
94
|
+
pauseOnHover?: boolean;
|
|
95
|
+
pauseOnWindowBlur?: boolean;
|
|
96
|
+
duplicateStrategy?: SoToastDuplicateStrategy;
|
|
97
|
+
newestOnTop?: boolean;
|
|
98
|
+
maxVisible?: number;
|
|
99
|
+
className?: string;
|
|
100
|
+
attrs?: Record<string, string>;
|
|
101
|
+
onShown?: (handle: SoToastHandle) => void;
|
|
102
|
+
onClose?: (reason: SoToastCloseReason, handle: SoToastHandle) => void;
|
|
103
|
+
}
|
|
104
|
+
export interface SoToastHandle {
|
|
105
|
+
id: string;
|
|
106
|
+
element: HTMLElement;
|
|
107
|
+
close: (reason?: Exclude<SoToastCloseReason, 'timeout' | 'close-button'>) => void;
|
|
108
|
+
update: (patch: Partial<Pick<SoToastOptions, 'title' | 'content' | 'variant' | 'duration'>>) => void;
|
|
109
|
+
pause: () => void;
|
|
110
|
+
resume: () => void;
|
|
111
|
+
}
|
|
81
112
|
export declare class SoDialog {
|
|
82
113
|
private static modalRegistry;
|
|
83
114
|
private static handleRegistry;
|
|
@@ -88,5 +119,45 @@ export declare class SoDialog {
|
|
|
88
119
|
static openModal(options: SoDialogModalOptions): SoDialogHandle;
|
|
89
120
|
static openOffcanvas(options: Omit<SoDialogOffcanvasOptions, 'kind'>): SoDialogHandle;
|
|
90
121
|
}
|
|
122
|
+
export declare class SoToast {
|
|
123
|
+
private static placementState;
|
|
124
|
+
private static recordById;
|
|
125
|
+
private static idSeed;
|
|
126
|
+
private static defaults;
|
|
127
|
+
private static normalizeOptions;
|
|
128
|
+
private static createAutoToastId;
|
|
129
|
+
private static createStackedToastId;
|
|
130
|
+
private static resolveRole;
|
|
131
|
+
private static getPlacementState;
|
|
132
|
+
private static createToastElement;
|
|
133
|
+
private static resetProgressAnimation;
|
|
134
|
+
private static hideProgress;
|
|
135
|
+
private static isRecordActive;
|
|
136
|
+
private static isRecordPending;
|
|
137
|
+
private static mountRecord;
|
|
138
|
+
private static queueRecord;
|
|
139
|
+
private static startRecordTimer;
|
|
140
|
+
private static clearRecordTimer;
|
|
141
|
+
private static pauseRecord;
|
|
142
|
+
private static resumeRecord;
|
|
143
|
+
private static rebuildRecordElement;
|
|
144
|
+
private static moveRecordToPlacement;
|
|
145
|
+
private static updateRecord;
|
|
146
|
+
private static removeStateContainerIfEmpty;
|
|
147
|
+
private static drainQueue;
|
|
148
|
+
private static removeFromArray;
|
|
149
|
+
private static finalizeClose;
|
|
150
|
+
private static closeRecord;
|
|
151
|
+
private static createHandle;
|
|
152
|
+
static show(options: SoToastOptions): SoToastHandle;
|
|
153
|
+
static clear(placement?: SoToastPlacement): void;
|
|
154
|
+
static configure(defaults: Partial<SoToastOptions>): void;
|
|
155
|
+
static success(content: string | Node, options?: Omit<SoToastOptions, 'content' | 'variant'>): SoToastHandle;
|
|
156
|
+
static error(content: string | Node, options?: Omit<SoToastOptions, 'content' | 'variant'>): SoToastHandle;
|
|
157
|
+
static info(content: string | Node, options?: Omit<SoToastOptions, 'content' | 'variant'>): SoToastHandle;
|
|
158
|
+
static warning(content: string | Node, options?: Omit<SoToastOptions, 'content' | 'variant'>): SoToastHandle;
|
|
159
|
+
static closeAll(): void;
|
|
160
|
+
}
|
|
91
161
|
export declare function openModal(options: SoDialogModalOptions): SoDialogHandle;
|
|
92
162
|
export declare function openOffcanvas(options: Omit<SoDialogOffcanvasOptions, 'kind'>): SoDialogHandle;
|
|
163
|
+
export declare function toast(options: SoToastOptions): SoToastHandle;
|