solely 0.5.3 → 0.5.5
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/dist/components/commands/drawer/index.cjs +1 -1
- package/dist/components/commands/drawer/index.js +1 -1
- package/dist/components/commands/drawer/types.d.ts +2 -0
- package/dist/components/commands/index.cjs +1 -1
- package/dist/components/commands/index.d.ts +2 -2
- package/dist/components/commands/index.js +1 -1
- package/dist/components/commands/message/index.cjs +1 -1
- package/dist/components/commands/message/index.js +1 -1
- package/dist/components/commands/message/types.d.ts +2 -0
- package/dist/components/commands/modal/index.cjs +1 -1
- package/dist/components/commands/modal/index.js +1 -1
- package/dist/components/commands/modal/types.d.ts +2 -0
- package/dist/components/commands/popconfirm/index.cjs +1 -1
- package/dist/components/commands/popconfirm/index.d.ts +3 -4
- package/dist/components/commands/popconfirm/index.js +1 -1
- package/dist/components/commands/popconfirm/types.d.ts +10 -0
- package/dist/components/commands/tooltip/index.cjs +1 -1
- package/dist/components/commands/tooltip/index.d.ts +13 -0
- package/dist/components/commands/tooltip/index.js +1 -1
- package/dist/components/commands/tooltip/types.d.ts +2 -0
- package/dist/components/commands/utils.cjs +1 -1
- package/dist/components/commands/utils.d.ts +6 -0
- package/dist/components/commands/utils.js +1 -1
- package/dist/components/elements/button/index.cjs +1 -1
- package/dist/components/elements/button/index.js +1 -1
- package/dist/components/elements/card/index.cjs +1 -1
- package/dist/components/elements/card/index.js +1 -1
- package/dist/components/elements/card/types.d.ts +1 -1
- package/dist/components/elements/input/index.cjs +1 -1
- package/dist/components/elements/input/index.js +1 -1
- package/dist/components/elements/pagination/index.cjs +1 -1
- package/dist/components/elements/pagination/index.js +1 -1
- package/dist/components/elements/pagination/types.d.ts +1 -1
- package/dist/components/elements/steps/index.cjs +1 -1
- package/dist/components/elements/steps/index.js +1 -1
- package/dist/components/elements/steps/types.d.ts +1 -1
- package/dist/components/elements/table/index.cjs +1 -1
- package/dist/components/elements/table/index.js +1 -1
- package/dist/components/elements/table/types.d.ts +1 -1
- package/dist/components/elements/tabs/index.cjs +1 -1
- package/dist/components/elements/tabs/index.js +1 -1
- package/dist/components/elements/tabs/types.d.ts +1 -1
- package/dist/components/index.cjs +1 -1
- package/dist/components/index.js +1 -1
- package/dist/router/core.cjs +1 -1
- package/dist/router/core.d.ts +1 -0
- package/dist/router/core.js +1 -1
- package/dist/router/router-link.cjs +1 -1
- package/dist/router/router-link.d.ts +5 -0
- package/dist/router/router-link.js +1 -1
- package/dist/runtime/component/base-element.cjs +1 -1
- package/dist/runtime/component/base-element.js +1 -1
- package/dist/runtime/reactivity/observe.cjs +1 -1
- package/dist/runtime/reactivity/observe.js +1 -1
- package/dist/runtime/reactivity/watch.cjs +1 -1
- package/dist/runtime/reactivity/watch.js +1 -1
- package/dist/shared/env.cjs +1 -1
- package/dist/shared/env.js +1 -1
- package/dist/shared/url.cjs +1 -1
- package/dist/shared/url.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),l={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},n=[],s=new Set;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),l={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},n=[],s=new Set;async function o(t){var l;if(!s.has(t)){s.add(t);try{const s=n.findIndex(e=>e.id===t);if(-1===s)return;const o=n[s],i=o.element.querySelector(".solely-drawer-mask"),a=o.element.querySelector(".solely-drawer");i&&i.classList.add("is-closing"),a&&a.classList.add("is-closing"),await e.addClosingAnimation(o.element,e.ANIMATION_DURATION.NORMAL),null==(l=o.cleanup)||l.call(o);const r=n.findIndex(e=>e.id===t);-1!==r&&(n[r].element.remove(),n.splice(r,1)),0===n.length&&document.body.classList.remove("solely-drawer-open")}finally{s.delete(t)}}}const i={open:function(s){const i=e.generateId();e.injectStyle("solely-drawer-styles",t.default);const a=s.placement||"right",r=s.width??l.width,c=s.height??l.height,d=s.mask??l.mask,y=s.maskClosable??l.maskClosable,m=s.closable??l.closable,p=e.createElement("div",{className:"solely-drawer-wrap"}),h=e.observeTheme(()=>p),f=s.cloneElement??!0,u=[];if(!1!==d){const t=e.createElement("div",{className:"solely-drawer-mask"});if(y){const e=()=>{var e;o(i),null==(e=s.onClose)||e.call(s)};t.addEventListener("click",e),u.push({element:t,type:"click",handler:e})}p.appendChild(t)}const w=e.createElement("div",{className:`solely-drawer solely-drawer--${a}${s.className?` ${s.className}`:""}`,styles:s.style});if("left"===a||"right"===a?w.style.width="number"==typeof r?`${r}px`:r:w.style.height="number"==typeof c?`${c}px`:c,s.title||!1!==m){const t=e.createElement("div",{className:"solely-drawer__header"});if(s.title){const l=e.createElement("h3",{className:"solely-drawer__title"});"string"==typeof s.title?l.textContent=s.title:s.title instanceof HTMLElement&&l.appendChild(f?s.title.cloneNode(!0):s.title),t.appendChild(l)}if(!1!==m){const l=e.createElement("button",{className:"solely-drawer__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}}),n=()=>{var e;o(i),null==(e=s.onClose)||e.call(s)};l.addEventListener("click",n),u.push({element:l,type:"click",handler:n}),t.appendChild(l)}w.appendChild(t)}const g=e.createElement("div",{className:"solely-drawer__body",styles:s.bodyStyle});return"string"==typeof s.content?g.textContent=s.content||"":s.content instanceof HTMLElement&&g.appendChild(f?s.content.cloneNode(!0):s.content),w.appendChild(g),p.appendChild(w),document.body.appendChild(p),document.body.classList.add("solely-drawer-open"),n.push({id:i,element:p,options:s,cleanup:()=>{u.forEach(({element:e,type:t,handler:l})=>{e.removeEventListener(t,l)}),h()}}),{close:()=>{var e;o(i),null==(e=s.onClose)||e.call(s)},update:t=>{const l=t.cloneElement??f;if(void 0!==t.title){const n=p.querySelector(".solely-drawer__title");if(n)n.innerHTML="","string"==typeof t.title?n.textContent=t.title:t.title instanceof HTMLElement&&n.appendChild(l?t.title.cloneNode(!0):t.title);else if(t.title){const n=e.createElement("div",{className:"solely-drawer__header"}),s=e.createElement("h3",{className:"solely-drawer__title"});"string"==typeof t.title?s.textContent=t.title:t.title instanceof HTMLElement&&s.appendChild(l?t.title.cloneNode(!0):t.title),n.appendChild(s);const o=p.querySelector(".solely-drawer");null==o||o.insertBefore(n,o.firstChild)}}if(void 0!==t.content){const e=p.querySelector(".solely-drawer__body");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(l?t.content.cloneNode(!0):t.content))}const n=p.querySelector(".solely-drawer");if(n){const e=t.placement||s.placement||"right";void 0===t.width||"left"!==e&&"right"!==e||(n.style.width="number"==typeof t.width?`${t.width}px`:t.width),void 0===t.height||"top"!==e&&"bottom"!==e||(n.style.height="number"==typeof t.height?`${t.height}px`:t.height)}if(void 0!==t.className&&n){const e=s.placement||"right";n.className=`solely-drawer solely-drawer--${e} ${t.className}`.trim()}if(void 0!==t.style&&n&&Object.assign(n.style,t.style),void 0!==t.bodyStyle){const e=p.querySelector(".solely-drawer__body");e&&Object.assign(e.style,t.bodyStyle)}}}},config:function(e){Object.assign(l,e)},destroy:async function(){const e=[...n].reverse();for(const t of e)await o(t.id)}};exports.Drawer=i;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as e,
|
|
1
|
+
import{createElement as e,observeTheme as t,addClosingAnimation as l,ANIMATION_DURATION as n,injectStyle as s,generateId as o}from"../utils.js";import i from"./style.css.js";const a={width:378,height:378,mask:!0,maskClosable:!0,closable:!0},d=[],c=new Set;async function r(e){var t;if(!c.has(e)){c.add(e);try{const s=d.findIndex(t=>t.id===e);if(-1===s)return;const o=d[s],i=o.element.querySelector(".solely-drawer-mask"),a=o.element.querySelector(".solely-drawer");i&&i.classList.add("is-closing"),a&&a.classList.add("is-closing"),await l(o.element,n.NORMAL),null==(t=o.cleanup)||t.call(o);const c=d.findIndex(t=>t.id===e);-1!==c&&(d[c].element.remove(),d.splice(c,1)),0===d.length&&document.body.classList.remove("solely-drawer-open")}finally{c.delete(e)}}}const y={open:function(l){const n=o();s("solely-drawer-styles",i);const c=l.placement||"right",y=l.width??a.width,p=l.height??a.height,h=l.mask??a.mask,m=l.maskClosable??a.maskClosable,f=l.closable??a.closable,w=e("div",{className:"solely-drawer-wrap"}),u=t(()=>w),b=l.cloneElement??!0,g=[];if(!1!==h){const t=e("div",{className:"solely-drawer-mask"});if(m){const e=()=>{var e;r(n),null==(e=l.onClose)||e.call(l)};t.addEventListener("click",e),g.push({element:t,type:"click",handler:e})}w.appendChild(t)}const C=e("div",{className:`solely-drawer solely-drawer--${c}${l.className?` ${l.className}`:""}`,styles:l.style});if("left"===c||"right"===c?C.style.width="number"==typeof y?`${y}px`:y:C.style.height="number"==typeof p?`${p}px`:p,l.title||!1!==f){const t=e("div",{className:"solely-drawer__header"});if(l.title){const n=e("h3",{className:"solely-drawer__title"});"string"==typeof l.title?n.textContent=l.title:l.title instanceof HTMLElement&&n.appendChild(b?l.title.cloneNode(!0):l.title),t.appendChild(n)}if(!1!==f){const s=e("button",{className:"solely-drawer__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}}),o=()=>{var e;r(n),null==(e=l.onClose)||e.call(l)};s.addEventListener("click",o),g.push({element:s,type:"click",handler:o}),t.appendChild(s)}C.appendChild(t)}const v=e("div",{className:"solely-drawer__body",styles:l.bodyStyle});return"string"==typeof l.content?v.textContent=l.content||"":l.content instanceof HTMLElement&&v.appendChild(b?l.content.cloneNode(!0):l.content),C.appendChild(v),w.appendChild(C),document.body.appendChild(w),document.body.classList.add("solely-drawer-open"),d.push({id:n,element:w,options:l,cleanup:()=>{g.forEach(({element:e,type:t,handler:l})=>{e.removeEventListener(t,l)}),u()}}),{close:()=>{var e;r(n),null==(e=l.onClose)||e.call(l)},update:t=>{const n=t.cloneElement??b;if(void 0!==t.title){const l=w.querySelector(".solely-drawer__title");if(l)l.innerHTML="","string"==typeof t.title?l.textContent=t.title:t.title instanceof HTMLElement&&l.appendChild(n?t.title.cloneNode(!0):t.title);else if(t.title){const l=e("div",{className:"solely-drawer__header"}),s=e("h3",{className:"solely-drawer__title"});"string"==typeof t.title?s.textContent=t.title:t.title instanceof HTMLElement&&s.appendChild(n?t.title.cloneNode(!0):t.title),l.appendChild(s);const o=w.querySelector(".solely-drawer");null==o||o.insertBefore(l,o.firstChild)}}if(void 0!==t.content){const e=w.querySelector(".solely-drawer__body");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(n?t.content.cloneNode(!0):t.content))}const s=w.querySelector(".solely-drawer");if(s){const e=t.placement||l.placement||"right";void 0===t.width||"left"!==e&&"right"!==e||(s.style.width="number"==typeof t.width?`${t.width}px`:t.width),void 0===t.height||"top"!==e&&"bottom"!==e||(s.style.height="number"==typeof t.height?`${t.height}px`:t.height)}if(void 0!==t.className&&s){const e=l.placement||"right";s.className=`solely-drawer solely-drawer--${e} ${t.className}`.trim()}if(void 0!==t.style&&s&&Object.assign(s.style,t.style),void 0!==t.bodyStyle){const e=w.querySelector(".solely-drawer__body");e&&Object.assign(e.style,t.bodyStyle)}}}},config:function(e){Object.assign(a,e)},destroy:async function(){const e=[...d].reverse();for(const t of e)await r(t.id)}};export{y as Drawer};
|
|
@@ -27,6 +27,8 @@ export interface DrawerOptions {
|
|
|
27
27
|
style?: Partial<CSSStyleDeclaration>;
|
|
28
28
|
/** 抽屉内容的样式 */
|
|
29
29
|
bodyStyle?: Partial<CSSStyleDeclaration>;
|
|
30
|
+
/** 是否克隆传入的 HTMLElement 内容(默认 true) */
|
|
31
|
+
cloneElement?: boolean;
|
|
30
32
|
}
|
|
31
33
|
export interface DrawerInstance {
|
|
32
34
|
/** 关闭抽屉 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./message/index.cjs"),r=require("./modal/index.cjs"),o=require("./tooltip/index.cjs"),t=require("./drawer/index.cjs"),s=require("./popconfirm/index.cjs"),i=require("./utils.cjs");exports.Message=e.Message,exports.Modal=r.Modal,exports.Tooltip=o.Tooltip,exports.Drawer=t.Drawer,exports.Popconfirm=s.Popconfirm,exports.ANIMATION_DURATION=i.ANIMATION_DURATION,exports.Z_INDEX=i.Z_INDEX,exports.addClosingAnimation=i.addClosingAnimation,exports.calculatePosition=i.calculatePosition,exports.createElement=i.createElement,exports.generateId=i.generateId,exports.injectStyle=i.injectStyle,exports.removeStyle=i.removeStyle,exports.safeAsyncCallback=i.safeAsyncCallback;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./message/index.cjs"),r=require("./modal/index.cjs"),o=require("./tooltip/index.cjs"),t=require("./drawer/index.cjs"),s=require("./popconfirm/index.cjs"),i=require("./utils.cjs");exports.Message=e.Message,exports.Modal=r.Modal,exports.Tooltip=o.Tooltip,exports.Drawer=t.Drawer,exports.Popconfirm=s.Popconfirm,exports.ANIMATION_DURATION=i.ANIMATION_DURATION,exports.Z_INDEX=i.Z_INDEX,exports.addClosingAnimation=i.addClosingAnimation,exports.calculatePosition=i.calculatePosition,exports.createElement=i.createElement,exports.generateId=i.generateId,exports.injectStyle=i.injectStyle,exports.observeTheme=i.observeTheme,exports.removeStyle=i.removeStyle,exports.safeAsyncCallback=i.safeAsyncCallback;
|
|
@@ -10,6 +10,6 @@ export type { MessageOptions, MessageInstance, MessageConfig, MessageType, Messa
|
|
|
10
10
|
export type { ModalOptions, ModalInstance, ModalConfig, ModalType, ModalButton } from './modal/types';
|
|
11
11
|
export type { TooltipOptions, TooltipInstance, TooltipConfig, TooltipPlacement, TooltipTrigger } from './tooltip/types';
|
|
12
12
|
export type { DrawerOptions, DrawerInstance, DrawerConfig, DrawerPlacement } from './drawer/types';
|
|
13
|
-
export type { PopconfirmOptions, PopconfirmInstance, PopconfirmConfig, PopconfirmPlacement } from './popconfirm/types';
|
|
14
|
-
export { generateId, injectStyle, removeStyle, createElement, calculatePosition, safeAsyncCallback, addClosingAnimation, ANIMATION_DURATION, Z_INDEX, } from './utils';
|
|
13
|
+
export type { PopconfirmOptions, PopconfirmInstance, PopconfirmResult, PopconfirmConfig, PopconfirmPlacement, } from './popconfirm/types';
|
|
14
|
+
export { generateId, injectStyle, removeStyle, createElement, calculatePosition, safeAsyncCallback, addClosingAnimation, observeTheme, ANIMATION_DURATION, Z_INDEX, } from './utils';
|
|
15
15
|
export type { PositionResult, Placement } from './utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Message as o}from"./message/index.js";import{Modal as r}from"./modal/index.js";import{Tooltip as m}from"./tooltip/index.js";import{Drawer as i}from"./drawer/index.js";import{Popconfirm as p}from"./popconfirm/index.js";import{ANIMATION_DURATION as t,Z_INDEX as e,addClosingAnimation as s,calculatePosition as d,createElement as f,generateId as j,injectStyle as n,
|
|
1
|
+
import{Message as o}from"./message/index.js";import{Modal as r}from"./modal/index.js";import{Tooltip as m}from"./tooltip/index.js";import{Drawer as i}from"./drawer/index.js";import{Popconfirm as p}from"./popconfirm/index.js";import{ANIMATION_DURATION as t,Z_INDEX as e,addClosingAnimation as s,calculatePosition as d,createElement as f,generateId as j,injectStyle as n,observeTheme as x,removeStyle as a,safeAsyncCallback as l}from"./utils.js";export{t as ANIMATION_DURATION,i as Drawer,o as Message,r as Modal,p as Popconfirm,m as Tooltip,e as Z_INDEX,s as addClosingAnimation,d as calculatePosition,f as createElement,j as generateId,n as injectStyle,x as observeTheme,a as removeStyle,l as safeAsyncCallback};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let o
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let o;const s=new Set,i=[],l={info:"ℹ",success:"✓",warning:"⚠",error:"✕",loading:e.createElement("span",{className:"solely-message__loading-spinner"})},a=new Map;function r(t,n){const o=e.createElement("span",{className:`solely-message__icon solely-message__icon--${n}`});return"string"==typeof t?o.textContent=t:o.appendChild(t.cloneNode(!0)),o}async function c(t){var n;if(!s.has(t)){s.add(t);try{const s=i.findIndex(e=>e.id===t);if(-1===s)return;const r=i[s];r.timer&&(clearTimeout(r.timer),r.timer=void 0),await e.addClosingAnimation(r.element,e.ANIMATION_DURATION.NORMAL),r.element.remove();const c=i.findIndex(e=>e.id===t);-1!==c&&i.splice(c,1);try{null==(n=r.onClose)||n.call(r)}catch(l){console.error("[Solely Message] onClose callback error:",l)}o&&clearTimeout(o),o=window.setTimeout(()=>{0===i.length&&a.forEach((e,t)=>{0===e.element.childElementCount&&(e.element.remove(),e.cleanupTheme(),a.delete(t))}),o=void 0},300)}finally{s.delete(t)}}}function p(o){const s=e.generateId(),p=o.placement||n.placement,d=function(o=n.placement){const s=o;if(a.has(s))return a.get(s).element;const i=e.createElement("div",{className:"solely-message-container"}),l={position:"fixed",display:"flex",flexDirection:"column",gap:`${n.gap}px`,pointerEvents:"none",zIndex:String(e.Z_INDEX.TOAST)};switch(o){case"top":l.top=`${n.top}px`,l.left="50%",l.transform="translateX(-50%)";break;case"topLeft":l.top=`${n.top}px`,l.left=`${n.left}px`,l.alignItems="flex-start";break;case"topRight":l.top=`${n.top}px`,l.right=`${n.right}px`,l.alignItems="flex-end";break;case"bottom":l.bottom=`${n.bottom}px`,l.left="50%",l.transform="translateX(-50%)";break;case"bottomLeft":l.bottom=`${n.bottom}px`,l.left=`${n.left}px`,l.alignItems="flex-start";break;case"bottomRight":l.bottom=`${n.bottom}px`,l.right=`${n.right}px`,l.alignItems="flex-end";break;case"left":l.top="50%",l.left=`${n.left}px`,l.transform="translateY(-50%)",l.alignItems="flex-start";break;case"right":l.top="50%",l.right=`${n.right}px`,l.transform="translateY(-50%)",l.alignItems="flex-end"}Object.assign(i.style,l),document.body.appendChild(i),e.injectStyle("solely-message-styles",t.default);const r=e.observeTheme(()=>i);return a.set(s,{element:i,cleanupTheme:r}),i}(p),m=i.filter(e=>e.placement===p);if(m.length>=n.maxCount){const e=m[0];e&&c(e.id)}const f=function(t,n){const o=t.type||"info",s=!1!==t.showIcon,i=t.cloneElement??!0,a=e.createElement("div",{className:`solely-message solely-message--${o}${t.className?` ${t.className}`:""}`,styles:t.style});if(a.setAttribute("role","error"===o||"warning"===o?"alert":"status"),a.setAttribute("aria-live","error"===o||"warning"===o?"assertive":"polite"),s){const e=t.icon?r(t.icon,o):r(l[o],o);a.appendChild(e)}const p=e.createElement("span",{className:"solely-message__content"}),d=e.createElement("span",{className:"solely-message__text"});if("string"==typeof t.content?d.textContent=t.content:t.content instanceof HTMLElement&&d.appendChild(i?t.content.cloneNode(!0):t.content),p.appendChild(d),t.description){const n=e.createElement("span",{className:"solely-message__description"});"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(i?t.description.cloneNode(!0):t.description),p.appendChild(n)}if(a.appendChild(p),t.closable){const t=e.createElement("button",{className:"solely-message__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}});t.onclick=()=>c(n),a.appendChild(t)}return a}(o,s);d.appendChild(f);const g={id:s,element:f,onClose:o.onClose,placement:p},u=o.duration??n.duration;return u>0&&(g.timer=window.setTimeout(()=>{c(s)},u)),i.push(g),{close:()=>c(s),update:t=>{if("string"==typeof t||t instanceof HTMLElement){const e=f.querySelector(".solely-message__text");return void(e&&(e.innerHTML="","string"==typeof t?e.textContent=t:t instanceof HTMLElement&&e.appendChild(t.cloneNode(!0))))}if(void 0!==t.content){const e=f.querySelector(".solely-message__text");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(t.content.cloneNode(!0)))}if(void 0!==t.description){let n=f.querySelector(".solely-message__description");if(!n&&t.description){n=e.createElement("span",{className:"solely-message__description"}),"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0));const o=f.querySelector(".solely-message__content");null==o||o.appendChild(n)}else n&&(t.description?(n.innerHTML="","string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0))):n.remove())}}}}const d={open:p,info:function(e,t){return p({content:e,type:"info",..."number"==typeof t?{duration:t}:t})},success:function(e,t){return p({content:e,type:"success",..."number"==typeof t?{duration:t}:t})},warning:function(e,t){return p({content:e,type:"warning",..."number"==typeof t?{duration:t}:t})},error:function(e,t){return p({content:e,type:"error",..."number"==typeof t?{duration:t}:t})},loading:function(e,t){return p(void 0===t?{content:e,type:"loading",duration:0,closable:!0}:"number"==typeof t?{content:e,type:"loading",duration:t,closable:!0}:{content:e,type:"loading",duration:0,closable:!0,...t})},config:function(e){Object.assign(n,e),a.forEach((t,n)=>{const o=t.element;void 0!==e.top&&["top","topLeft","topRight"].includes(n)&&(o.style.top=`${e.top}px`),void 0!==e.bottom&&["bottom","bottomLeft","bottomRight"].includes(n)&&(o.style.bottom=`${e.bottom}px`),void 0!==e.left&&["topLeft","bottomLeft","left"].includes(n)&&(o.style.left=`${e.left}px`),void 0!==e.right&&["topRight","bottomRight","right"].includes(n)&&(o.style.right=`${e.right}px`),void 0!==e.gap&&(o.style.gap=`${e.gap}px`)})},destroy:async function(){o&&(clearTimeout(o),o=void 0);const e=[...i];await Promise.all(e.map(e=>c(e.id)))}};exports.Message=d;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as
|
|
1
|
+
import{createElement as e,addClosingAnimation as t,ANIMATION_DURATION as n,Z_INDEX as o,observeTheme as s,generateId as i,injectStyle as l}from"../utils.js";import a from"./style.css.js";const r={duration:3e3,maxCount:5,gap:8,top:24,bottom:24,left:24,right:24,placement:"top"};let c;const p=new Set,d=[],m={info:"ℹ",success:"✓",warning:"⚠",error:"✕",loading:e("span",{className:"solely-message__loading-spinner"})},f=new Map;function g(t,n){const o=e("span",{className:`solely-message__icon solely-message__icon--${n}`});return"string"==typeof t?o.textContent=t:o.appendChild(t.cloneNode(!0)),o}async function u(e){var o;if(!p.has(e)){p.add(e);try{const i=d.findIndex(t=>t.id===e);if(-1===i)return;const l=d[i];l.timer&&(clearTimeout(l.timer),l.timer=void 0),await t(l.element,n.NORMAL),l.element.remove();const a=d.findIndex(t=>t.id===e);-1!==a&&d.splice(a,1);try{null==(o=l.onClose)||o.call(l)}catch(s){console.error("[Solely Message] onClose callback error:",s)}c&&clearTimeout(c),c=window.setTimeout(()=>{0===d.length&&f.forEach((e,t)=>{0===e.element.childElementCount&&(e.element.remove(),e.cleanupTheme(),f.delete(t))}),c=void 0},300)}finally{p.delete(e)}}}function y(t){const n=i(),c=t.placement||r.placement,p=function(t=r.placement){const n=t;if(f.has(n))return f.get(n).element;const i=e("div",{className:"solely-message-container"}),c={position:"fixed",display:"flex",flexDirection:"column",gap:`${r.gap}px`,pointerEvents:"none",zIndex:String(o.TOAST)};switch(t){case"top":c.top=`${r.top}px`,c.left="50%",c.transform="translateX(-50%)";break;case"topLeft":c.top=`${r.top}px`,c.left=`${r.left}px`,c.alignItems="flex-start";break;case"topRight":c.top=`${r.top}px`,c.right=`${r.right}px`,c.alignItems="flex-end";break;case"bottom":c.bottom=`${r.bottom}px`,c.left="50%",c.transform="translateX(-50%)";break;case"bottomLeft":c.bottom=`${r.bottom}px`,c.left=`${r.left}px`,c.alignItems="flex-start";break;case"bottomRight":c.bottom=`${r.bottom}px`,c.right=`${r.right}px`,c.alignItems="flex-end";break;case"left":c.top="50%",c.left=`${r.left}px`,c.transform="translateY(-50%)",c.alignItems="flex-start";break;case"right":c.top="50%",c.right=`${r.right}px`,c.transform="translateY(-50%)",c.alignItems="flex-end"}Object.assign(i.style,c),document.body.appendChild(i),l("solely-message-styles",a);const p=s(()=>i);return f.set(n,{element:i,cleanupTheme:p}),i}(c),y=d.filter(e=>e.placement===c);if(y.length>=r.maxCount){const e=y[0];e&&u(e.id)}const h=function(t,n){const o=t.type||"info",s=!1!==t.showIcon,i=t.cloneElement??!0,l=e("div",{className:`solely-message solely-message--${o}${t.className?` ${t.className}`:""}`,styles:t.style});if(l.setAttribute("role","error"===o||"warning"===o?"alert":"status"),l.setAttribute("aria-live","error"===o||"warning"===o?"assertive":"polite"),s){const e=t.icon?g(t.icon,o):g(m[o],o);l.appendChild(e)}const a=e("span",{className:"solely-message__content"}),r=e("span",{className:"solely-message__text"});if("string"==typeof t.content?r.textContent=t.content:t.content instanceof HTMLElement&&r.appendChild(i?t.content.cloneNode(!0):t.content),a.appendChild(r),t.description){const n=e("span",{className:"solely-message__description"});"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(i?t.description.cloneNode(!0):t.description),a.appendChild(n)}if(l.appendChild(a),t.closable){const t=e("button",{className:"solely-message__close",textContent:"×",attrs:{type:"button","aria-label":"关闭"}});t.onclick=()=>u(n),l.appendChild(t)}return l}(t,n);p.appendChild(h);const x={id:n,element:h,onClose:t.onClose,placement:c},b=t.duration??r.duration;return b>0&&(x.timer=window.setTimeout(()=>{u(n)},b)),d.push(x),{close:()=>u(n),update:t=>{if("string"==typeof t||t instanceof HTMLElement){const e=h.querySelector(".solely-message__text");return void(e&&(e.innerHTML="","string"==typeof t?e.textContent=t:t instanceof HTMLElement&&e.appendChild(t.cloneNode(!0))))}if(void 0!==t.content){const e=h.querySelector(".solely-message__text");e&&(e.innerHTML="","string"==typeof t.content?e.textContent=t.content:t.content instanceof HTMLElement&&e.appendChild(t.content.cloneNode(!0)))}if(void 0!==t.description){let n=h.querySelector(".solely-message__description");if(!n&&t.description){n=e("span",{className:"solely-message__description"}),"string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0));const o=h.querySelector(".solely-message__content");null==o||o.appendChild(n)}else n&&(t.description?(n.innerHTML="","string"==typeof t.description?n.textContent=t.description:t.description instanceof HTMLElement&&n.appendChild(t.description.cloneNode(!0))):n.remove())}}}}const h={open:y,info:function(e,t){return y({content:e,type:"info",..."number"==typeof t?{duration:t}:t})},success:function(e,t){return y({content:e,type:"success",..."number"==typeof t?{duration:t}:t})},warning:function(e,t){return y({content:e,type:"warning",..."number"==typeof t?{duration:t}:t})},error:function(e,t){return y({content:e,type:"error",..."number"==typeof t?{duration:t}:t})},loading:function(e,t){return y(void 0===t?{content:e,type:"loading",duration:0,closable:!0}:"number"==typeof t?{content:e,type:"loading",duration:t,closable:!0}:{content:e,type:"loading",duration:0,closable:!0,...t})},config:function(e){Object.assign(r,e),f.forEach((t,n)=>{const o=t.element;void 0!==e.top&&["top","topLeft","topRight"].includes(n)&&(o.style.top=`${e.top}px`),void 0!==e.bottom&&["bottom","bottomLeft","bottomRight"].includes(n)&&(o.style.bottom=`${e.bottom}px`),void 0!==e.left&&["topLeft","bottomLeft","left"].includes(n)&&(o.style.left=`${e.left}px`),void 0!==e.right&&["topRight","bottomRight","right"].includes(n)&&(o.style.right=`${e.right}px`),void 0!==e.gap&&(o.style.gap=`${e.gap}px`)})},destroy:async function(){c&&(clearTimeout(c),c=void 0);const e=[...d];await Promise.all(e.map(e=>u(e.id)))}};export{h as Message};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={width:520,mask:!0,maskClosable:!1,okText:"确定",cancelText:"取消"},l=[],o=new Set
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),n={width:520,mask:!0,maskClosable:!1,okText:"确定",cancelText:"取消"},l=[],o=new Set,s={info:"ℹ",success:"✓",warning:"⚠",error:"✕",confirm:"?"};async function a(t){var n;if(!o.has(t)){o.add(t);try{const o=l.findIndex(e=>e.id===t);if(-1===o)return;const s=l[o],a=s.element.querySelector(".solely-modal-mask"),c=s.element.querySelector(".solely-modal");a&&a.classList.add("is-closing"),c&&c.classList.add("is-closing"),await e.addClosingAnimation(s.element,e.ANIMATION_DURATION.NORMAL),null==(n=s.cleanup)||n.call(s);const i=l.findIndex(e=>e.id===t);-1!==i&&(l[i].element.remove(),l.splice(i,1))}finally{o.delete(t)}}}async function c(){if(0===l.length)return;const e=l[l.length-1];await a(e.id)}function i(t,n,l,o=!1){const s=e.createElement("button",{className:`solely-modal__btn solely-modal__btn--${"default"===n?"default":n}`,attrs:{type:"button"}});return"string"==typeof t?s.textContent=t:t instanceof HTMLElement&&s.appendChild(o?t.cloneNode(!0):t),s.onclick=()=>e.safeAsyncCallback(l),s}function d(o){const c=e.generateId();e.injectStyle("solely-modal-styles",t.default);const d=o.type||"info",r=o.width??n.width,m=o.showCancel??"confirm"===d,p=o.maskClosable??n.maskClosable,y=e.createElement("div",{className:"solely-modal-wrap",attrs:{tabIndex:"-1",part:"wrap"}}),f=e.observeTheme(()=>y),u=[];if(!1!==o.mask){const t=e.createElement("div",{className:"solely-modal-mask"});if(p){const e=()=>{var e;a(c),null==(e=o.onCancel)||e.call(o)};t.onclick=e,u.push({element:t,type:"click",handler:e})}y.appendChild(t)}const h=e.createElement("div",{className:"solely-modal"+(o.className?` ${o.className}`:""),styles:{...o.style,width:"number"==typeof r?`${r}px`:r}}),C=e.createElement("div",{className:"solely-modal__header"}),b=e.createElement("h3",{className:"solely-modal__title"});if("string"==typeof o.title)b.textContent=o.title||"";else if(o.title instanceof HTMLElement){const e=o.cloneElement??!1;b.appendChild(e?o.title.cloneNode(!0):o.title)}if(C.appendChild(b),!1!==o.closable){const t=e.createElement("button",{className:"solely-modal__close",textContent:"×",attrs:{type:"button","aria-label":"关闭",part:"close"}}),n=()=>{var e;a(c),null==(e=o.onClose)||e.call(o)};t.onclick=n,u.push({element:t,type:"click",handler:n}),C.appendChild(t)}h.appendChild(C);const E=e.createElement("div",{className:"solely-modal__body"}),_=e.createElement("div",{className:"solely-modal__content-wrapper"});if(!1!==o.showIcon){const t=e.createElement("span",{className:`solely-modal__icon solely-modal__icon--${d}`,textContent:s[d]});_.appendChild(t)}const N=e.createElement("div",{className:"solely-modal__content"});if("string"==typeof o.content)N.textContent=o.content||"";else if(o.content instanceof HTMLElement){const e=o.cloneElement??!1;N.appendChild(e?o.content.cloneNode(!0):o.content)}_.appendChild(N),E.appendChild(_),h.appendChild(E);const w=e.createElement("div",{className:"solely-modal__footer"});if(o.buttons&&o.buttons.length>0)o.buttons.forEach(t=>{const n=i(t.text,t.type||"default",async()=>{await e.safeAsyncCallback(()=>t.onClick())},o.cloneElement);t.style&&Object.assign(n.style,t.style),w.appendChild(n)});else{if(m){const e=i(o.cancelText||n.cancelText,"default",()=>{var e;a(c),null==(e=o.onCancel)||e.call(o)},o.cloneElement);w.appendChild(e)}const t=i(o.okText||n.okText,o.okType||"primary",async()=>{const t=o.onConfirm||o.onOk;t&&!1===await e.safeAsyncCallback(()=>t())||a(c)},o.cloneElement);w.appendChild(t)}h.appendChild(w),y.appendChild(h),document.body.appendChild(y),l.push({id:c,element:y,instance:null,cleanup:()=>{u.forEach(({element:e,type:t,handler:n})=>{e.removeEventListener(t,n)}),f()}});const v={close:()=>{var e;a(c),null==(e=o.onClose)||e.call(o)},update:e=>{if(void 0!==e.title){const t=y.querySelector(".solely-modal__title");if(t)if(t.innerHTML="","string"==typeof e.title)t.textContent=e.title;else if(e.title instanceof HTMLElement){const n=e.cloneElement??!1;t.appendChild(n?e.title.cloneNode(!0):e.title)}}if(void 0!==e.content){const t=y.querySelector(".solely-modal__content");if(t)if(t.innerHTML="","string"==typeof e.content)t.textContent=e.content;else if(e.content instanceof HTMLElement){const n=e.cloneElement??!1;t.appendChild(n?e.content.cloneNode(!0):e.content)}}if(void 0!==e.width){const t=y.querySelector(".solely-modal");t&&(t.style.width="number"==typeof e.width?`${e.width}px`:e.width)}if(void 0!==e.className){const t=y.querySelector(".solely-modal");t&&(t.className=`solely-modal ${e.className}`.trim())}if(void 0!==e.style){const t=y.querySelector(".solely-modal");t&&Object.assign(t.style,e.style)}}},g=l.find(e=>e.id===c);return g&&(g.instance=v),v}const r={open:d,confirm:function(e){return d({...e,type:"confirm",showCancel:!0})},info:function(e){return d({...e,type:"info"})},success:function(e){return d({...e,type:"success"})},error:function(e){return d({...e,type:"error"})},warning:function(e){return d({...e,type:"warning"})},config:function(e){Object.assign(n,e)},destroy:async function(){for(;l.length>0;)await c()}};exports.Modal=r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as e,
|
|
1
|
+
import{createElement as e,observeTheme as t,safeAsyncCallback as n,injectStyle as l,addClosingAnimation as o,ANIMATION_DURATION as s,generateId as a}from"../utils.js";import c from"./style.css.js";const i={width:520,mask:!0,maskClosable:!1,okText:"确定",cancelText:"取消"},d=[],r=new Set,m={info:"ℹ",success:"✓",warning:"⚠",error:"✕",confirm:"?"};async function p(e){var t;if(!r.has(e)){r.add(e);try{const n=d.findIndex(t=>t.id===e);if(-1===n)return;const l=d[n],a=l.element.querySelector(".solely-modal-mask"),c=l.element.querySelector(".solely-modal");a&&a.classList.add("is-closing"),c&&c.classList.add("is-closing"),await o(l.element,s.NORMAL),null==(t=l.cleanup)||t.call(l);const i=d.findIndex(t=>t.id===e);-1!==i&&(d[i].element.remove(),d.splice(i,1))}finally{r.delete(e)}}}async function y(){if(0===d.length)return;const e=d[d.length-1];await p(e.id)}function f(t,l,o,s=!1){const a=e("button",{className:`solely-modal__btn solely-modal__btn--${"default"===l?"default":l}`,attrs:{type:"button"}});return"string"==typeof t?a.textContent=t:t instanceof HTMLElement&&a.appendChild(s?t.cloneNode(!0):t),a.onclick=()=>n(o),a}function u(o){const s=a();l("solely-modal-styles",c);const r=o.type||"info",y=o.width??i.width,u=o.showCancel??"confirm"===r,h=o.maskClosable??i.maskClosable,C=e("div",{className:"solely-modal-wrap",attrs:{tabIndex:"-1",part:"wrap"}}),_=t(()=>C),w=[];if(!1!==o.mask){const t=e("div",{className:"solely-modal-mask"});if(h){const e=()=>{var e;p(s),null==(e=o.onCancel)||e.call(o)};t.onclick=e,w.push({element:t,type:"click",handler:e})}C.appendChild(t)}const N=e("div",{className:"solely-modal"+(o.className?` ${o.className}`:""),styles:{...o.style,width:"number"==typeof y?`${y}px`:y}}),b=e("div",{className:"solely-modal__header"}),v=e("h3",{className:"solely-modal__title"});if("string"==typeof o.title)v.textContent=o.title||"";else if(o.title instanceof HTMLElement){const e=o.cloneElement??!1;v.appendChild(e?o.title.cloneNode(!0):o.title)}if(b.appendChild(v),!1!==o.closable){const t=e("button",{className:"solely-modal__close",textContent:"×",attrs:{type:"button","aria-label":"关闭",part:"close"}}),n=()=>{var e;p(s),null==(e=o.onClose)||e.call(o)};t.onclick=n,w.push({element:t,type:"click",handler:n}),b.appendChild(t)}N.appendChild(b);const x=e("div",{className:"solely-modal__body"}),g=e("div",{className:"solely-modal__content-wrapper"});if(!1!==o.showIcon){const t=e("span",{className:`solely-modal__icon solely-modal__icon--${r}`,textContent:m[r]});g.appendChild(t)}const k=e("div",{className:"solely-modal__content"});if("string"==typeof o.content)k.textContent=o.content||"";else if(o.content instanceof HTMLElement){const e=o.cloneElement??!1;k.appendChild(e?o.content.cloneNode(!0):o.content)}g.appendChild(k),x.appendChild(g),N.appendChild(x);const E=e("div",{className:"solely-modal__footer"});if(o.buttons&&o.buttons.length>0)o.buttons.forEach(e=>{const t=f(e.text,e.type||"default",async()=>{await n(()=>e.onClick())},o.cloneElement);e.style&&Object.assign(t.style,e.style),E.appendChild(t)});else{if(u){const e=f(o.cancelText||i.cancelText,"default",()=>{var e;p(s),null==(e=o.onCancel)||e.call(o)},o.cloneElement);E.appendChild(e)}const e=f(o.okText||i.okText,o.okType||"primary",async()=>{const e=o.onConfirm||o.onOk;e&&!1===await n(()=>e())||p(s)},o.cloneElement);E.appendChild(e)}N.appendChild(E),C.appendChild(N),document.body.appendChild(C),d.push({id:s,element:C,instance:null,cleanup:()=>{w.forEach(({element:e,type:t,handler:n})=>{e.removeEventListener(t,n)}),_()}});const T={close:()=>{var e;p(s),null==(e=o.onClose)||e.call(o)},update:e=>{if(void 0!==e.title){const t=C.querySelector(".solely-modal__title");if(t)if(t.innerHTML="","string"==typeof e.title)t.textContent=e.title;else if(e.title instanceof HTMLElement){const n=e.cloneElement??!1;t.appendChild(n?e.title.cloneNode(!0):e.title)}}if(void 0!==e.content){const t=C.querySelector(".solely-modal__content");if(t)if(t.innerHTML="","string"==typeof e.content)t.textContent=e.content;else if(e.content instanceof HTMLElement){const n=e.cloneElement??!1;t.appendChild(n?e.content.cloneNode(!0):e.content)}}if(void 0!==e.width){const t=C.querySelector(".solely-modal");t&&(t.style.width="number"==typeof e.width?`${e.width}px`:e.width)}if(void 0!==e.className){const t=C.querySelector(".solely-modal");t&&(t.className=`solely-modal ${e.className}`.trim())}if(void 0!==e.style){const t=C.querySelector(".solely-modal");t&&Object.assign(t.style,e.style)}}},L=d.find(e=>e.id===s);return L&&(L.instance=T),T}const h={open:u,confirm:function(e){return u({...e,type:"confirm",showCancel:!0})},info:function(e){return u({...e,type:"info"})},success:function(e){return u({...e,type:"success"})},error:function(e){return u({...e,type:"error"})},warning:function(e){return u({...e,type:"warning"})},config:function(e){Object.assign(i,e)},destroy:async function(){for(;d.length>0;)await y()}};export{h as Modal};
|
|
@@ -40,6 +40,8 @@ export interface ModalOptions {
|
|
|
40
40
|
/** 自定义按钮数组(如果提供,将忽略 okText/cancelText/showCancel) */
|
|
41
41
|
buttons?: ModalButton[];
|
|
42
42
|
/** 确定按钮回调 - 返回 false 阻止关闭,返回 HTMLElement 或数据作为结果 */
|
|
43
|
+
onConfirm?: () => void | false | HTMLElement | Record<string, unknown> | Promise<void | false | HTMLElement | Record<string, unknown>>;
|
|
44
|
+
/** @deprecated 请使用 onConfirm,此别名仅为向后兼容保留 */
|
|
43
45
|
onOk?: () => void | false | HTMLElement | Record<string, unknown> | Promise<void | false | HTMLElement | Record<string, unknown>>;
|
|
44
46
|
/** 取消按钮回调 */
|
|
45
47
|
onCancel?: () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),n=require("./style.css.cjs"),t={okText:"确定",cancelText:"取消",okType:"primary",showCancel:!0,placement:"top"};let o=null;const l=new WeakSet;function c(){o&&(o.cleanup(),o.element.remove(),o=null)}function s(){if(!o)return;const{element:n,cleanup:t}=o,l=n.querySelector(".solely-popconfirm");l&&l.classList.add("is-closing"),o=null,e.addClosingAnimation(n,e.ANIMATION_DURATION.FAST).then(()=>{t(),n.remove()})}function r(e,n,t){void 0!==n&&("string"==typeof n?e.textContent=n:n instanceof HTMLElement&&e.appendChild(t?n.cloneNode(!0):n))}function i(e){return{...e,then:n=>Promise.resolve(n(e))}}function a(l,a){if(o&&o.target===l)return c(),i({close:()=>{},destroy:()=>{}});c();const p=e.generateId();e.injectStyle("solely-popconfirm-styles",n.default);const d=a.placement??t.placement,m=a.okType??t.okType,u=a.showCancel??t.showCancel,y=a.cloneElement??!0,f=e.createElement("div",{className:"solely-popconfirm-overlay"}),v=e.observeTheme(()=>f),_=[`solely-popconfirm solely-popconfirm--${d}`,a.className].filter(Boolean).join(" "),E=e.createElement("div",{className:_,styles:a.style}),h=e.createElement("div",{className:"solely-popconfirm__content"});if(!1!==a.showIcon){const n=e.createElement("span",{className:"solely-popconfirm__icon",textContent:"⚠"});h.appendChild(n)}const C=e.createElement("div",{className:"solely-popconfirm__text"}),k=e.createElement("div",{className:"solely-popconfirm__title"});if(r(k,a.title,y),C.appendChild(k),a.description){const n=e.createElement("div",{className:"solely-popconfirm__description"});r(n,a.description,y),C.appendChild(n)}h.appendChild(C);const T=e.createElement("div",{className:"solely-popconfirm__buttons"}),b=()=>{var e;s(),null==(e=a.onCancel)||e.call(a)};if(u){const n=e.createElement("button",{className:"solely-popconfirm__btn solely-popconfirm__btn--cancel",attrs:{type:"button"}});r(n,a.cancelText??t.cancelText,y),n.onclick=b,T.appendChild(n)}const w=["solely-popconfirm__btn solely-popconfirm__btn--ok","danger"===m?"solely-popconfirm__btn--danger":""].filter(Boolean).join(" "),N=e.createElement("button",{className:w,attrs:{type:"button"}});r(N,a.okText??t.okText,y),N.onclick=()=>{var e;s(),null==(e=a.onConfirm)||e.call(a)},T.appendChild(N);const g=e.createElement("div",{className:"solely-popconfirm__arrow"});E.appendChild(g),E.appendChild(h),E.appendChild(T),f.appendChild(E),document.body.appendChild(f);const x=e.calculatePosition(l,E,d);E.style.top=`${x.top}px`,E.style.left=`${x.left}px`,void 0!==x.arrowLeft&&(g.style.left=`${x.arrowLeft}px`),void 0!==x.arrowTop&&(g.style.top=`${x.arrowTop}px`);const L=e=>{e.target===f&&b()},j=e=>{"Escape"===e.key&&(b(),document.removeEventListener("keydown",j))};f.addEventListener("click",L),document.addEventListener("keydown",j);const S=()=>{document.removeEventListener("keydown",j),f.removeEventListener("click",L),v()};return o={id:p,target:l,element:f,cleanup:S},i({close:()=>{o&&o.element===f&&(S(),s())},destroy:()=>{o&&o.element===f&&(S(),s())}})}const p={show:a,bind:function(e,n){if(l.has(e))return{close:()=>{},destroy:()=>{}};l.add(e);let t=null;const s=l=>{l.stopPropagation(),o?(c(),t=null):t=a(e,n)},r=n=>{if(!o)return;const l=n.target;o.element.contains(l)||e.contains(l)||(c(),t=null)};return e.addEventListener("click",s),document.addEventListener("mousedown",r),{close:()=>{null==t||t.close(),t=null},destroy:()=>{l.delete(e),e.removeEventListener("click",s),document.removeEventListener("mousedown",r),null==t||t.destroy(),t=null}}},config:function(e){Object.assign(t,e)},destroy:()=>{s()}};exports.Popconfirm=p;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { PopconfirmOptions, PopconfirmInstance, PopconfirmPlacement, PopconfirmConfig } from './types';
|
|
2
|
-
declare function
|
|
3
|
-
declare function show(target: HTMLElement, options: PopconfirmOptions): Promise<PopconfirmInstance>;
|
|
1
|
+
import { PopconfirmOptions, PopconfirmInstance, PopconfirmResult, PopconfirmPlacement, PopconfirmConfig } from './types';
|
|
2
|
+
declare function show(target: HTMLElement, options: PopconfirmOptions): PopconfirmResult;
|
|
4
3
|
declare function bind(target: HTMLElement, options: Omit<PopconfirmOptions, 'placement'> & {
|
|
5
4
|
placement?: PopconfirmPlacement;
|
|
6
5
|
}): PopconfirmInstance;
|
|
@@ -9,6 +8,6 @@ export declare const Popconfirm: {
|
|
|
9
8
|
show: typeof show;
|
|
10
9
|
bind: typeof bind;
|
|
11
10
|
config: typeof config;
|
|
12
|
-
destroy:
|
|
11
|
+
destroy: () => void;
|
|
13
12
|
};
|
|
14
13
|
export default Popconfirm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createElement as e,calculatePosition as
|
|
1
|
+
import{createElement as e,observeTheme as n,calculatePosition as o,injectStyle as t,addClosingAnimation as l,ANIMATION_DURATION as s,generateId as c}from"../utils.js";import i from"./style.css.js";const r={okText:"确定",cancelText:"取消",okType:"primary",showCancel:!0,placement:"top"};let p=null;const a=new WeakSet;function d(){p&&(p.cleanup(),p.element.remove(),p=null)}function m(){if(!p)return;const{element:e,cleanup:n}=p,o=e.querySelector(".solely-popconfirm");o&&o.classList.add("is-closing"),p=null,l(e,s.FAST).then(()=>{n(),e.remove()})}function y(e,n,o){void 0!==n&&("string"==typeof n?e.textContent=n:n instanceof HTMLElement&&e.appendChild(o?n.cloneNode(!0):n))}function f(e){return{...e,then:n=>Promise.resolve(n(e))}}function u(l,s){if(p&&p.target===l)return d(),f({close:()=>{},destroy:()=>{}});d();const a=c();t("solely-popconfirm-styles",i);const u=s.placement??r.placement,v=s.okType??r.okType,_=s.showCancel??r.showCancel,h=s.cloneElement??!0,C=e("div",{className:"solely-popconfirm-overlay"}),k=n(()=>C),w=[`solely-popconfirm solely-popconfirm--${u}`,s.className].filter(Boolean).join(" "),x=e("div",{className:w,styles:s.style}),b=e("div",{className:"solely-popconfirm__content"});if(!1!==s.showIcon){const n=e("span",{className:"solely-popconfirm__icon",textContent:"⚠"});b.appendChild(n)}const L=e("div",{className:"solely-popconfirm__text"}),N=e("div",{className:"solely-popconfirm__title"});if(y(N,s.title,h),L.appendChild(N),s.description){const n=e("div",{className:"solely-popconfirm__description"});y(n,s.description,h),L.appendChild(n)}b.appendChild(L);const T=e("div",{className:"solely-popconfirm__buttons"}),E=()=>{var e;m(),null==(e=s.onCancel)||e.call(s)};if(_){const n=e("button",{className:"solely-popconfirm__btn solely-popconfirm__btn--cancel",attrs:{type:"button"}});y(n,s.cancelText??r.cancelText,h),n.onclick=E,T.appendChild(n)}const g=["solely-popconfirm__btn solely-popconfirm__btn--ok","danger"===v?"solely-popconfirm__btn--danger":""].filter(Boolean).join(" "),j=e("button",{className:g,attrs:{type:"button"}});y(j,s.okText??r.okText,h),j.onclick=()=>{var e;m(),null==(e=s.onConfirm)||e.call(s)},T.appendChild(j);const $=e("div",{className:"solely-popconfirm__arrow"});x.appendChild($),x.appendChild(b),x.appendChild(T),C.appendChild(x),document.body.appendChild(C);const S=o(l,x,u);x.style.top=`${S.top}px`,x.style.left=`${S.left}px`,void 0!==S.arrowLeft&&($.style.left=`${S.arrowLeft}px`),void 0!==S.arrowTop&&($.style.top=`${S.arrowTop}px`);const B=e=>{e.target===C&&E()},P=e=>{"Escape"===e.key&&(E(),document.removeEventListener("keydown",P))};C.addEventListener("click",B),document.addEventListener("keydown",P);const q=()=>{document.removeEventListener("keydown",P),C.removeEventListener("click",B),k()};return p={id:a,target:l,element:C,cleanup:q},f({close:()=>{p&&p.element===C&&(q(),m())},destroy:()=>{p&&p.element===C&&(q(),m())}})}const v={show:u,bind:function(e,n){if(a.has(e))return{close:()=>{},destroy:()=>{}};a.add(e);let o=null;const t=t=>{t.stopPropagation(),p?(d(),o=null):o=u(e,n)},l=n=>{if(!p)return;const t=n.target;p.element.contains(t)||e.contains(t)||(d(),o=null)};return e.addEventListener("click",t),document.addEventListener("mousedown",l),{close:()=>{null==o||o.close(),o=null},destroy:()=>{a.delete(e),e.removeEventListener("click",t),document.removeEventListener("mousedown",l),null==o||o.destroy(),o=null}}},config:function(e){Object.assign(r,e)},destroy:()=>{m()}};export{v as Popconfirm};
|
|
@@ -27,11 +27,21 @@ export interface PopconfirmOptions {
|
|
|
27
27
|
className?: string;
|
|
28
28
|
/** 自定义样式 */
|
|
29
29
|
style?: Partial<CSSStyleDeclaration>;
|
|
30
|
+
/** 是否克隆传入的 HTMLElement 内容(默认 true) */
|
|
31
|
+
cloneElement?: boolean;
|
|
30
32
|
}
|
|
31
33
|
export interface PopconfirmInstance {
|
|
34
|
+
/** 关闭确认框(与 Modal/Drawer 的 close 保持一致) */
|
|
35
|
+
close: () => void;
|
|
32
36
|
/** 销毁确认框 */
|
|
33
37
|
destroy: () => void;
|
|
34
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* show 方法的返回值类型。
|
|
41
|
+
* 既是 PopconfirmInstance(支持同步使用),又是 PromiseLike<PopconfirmInstance>(兼容 await/.then)。
|
|
42
|
+
* 这是为了向后兼容历史版本中 show 返回 Promise 的用法。
|
|
43
|
+
*/
|
|
44
|
+
export type PopconfirmResult = PopconfirmInstance & PromiseLike<PopconfirmInstance>;
|
|
35
45
|
export interface PopconfirmConfig {
|
|
36
46
|
/** 默认确认按钮文字 */
|
|
37
47
|
okText: string | HTMLElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),o={placement:"top",trigger:"hover",duration:3e3,singleton:!0},n=[],
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../utils.cjs"),t=require("./style.css.cjs"),o={placement:"top",trigger:"hover",duration:3e3,singleton:!0},n=[],l=new WeakSet;function r(e,t,o,n=8){const l=e.getBoundingClientRect(),r=t.offsetWidth||250,s=t.offsetHeight||100;let i,c,a=0,d=0;switch(o){case"top":a=l.top-s-n,d=l.left+(l.width-r)/2,i=r/2-4;break;case"topLeft":a=l.top-s-n,d=l.left,i=16;break;case"topRight":a=l.top-s-n,d=l.right-r,i=r-24;break;case"bottom":a=l.bottom+n,d=l.left+(l.width-r)/2,i=r/2-4;break;case"bottomLeft":a=l.bottom+n,d=l.left,i=16;break;case"bottomRight":a=l.bottom+n,d=l.right-r,i=r-24;break;case"left":a=l.top+(l.height-s)/2,d=l.left-r-n,c=s/2-4;break;case"leftTop":a=l.top,d=l.left-r-n,c=16;break;case"leftBottom":a=l.bottom-s,d=l.left-r-n,c=s-24;break;case"right":a=l.top+(l.height-s)/2,d=l.right+n,c=s/2-4;break;case"rightTop":a=l.top,d=l.right+n,c=16;break;case"rightBottom":a=l.bottom-s,d=l.right+n,c=s-24}return a=Math.max(8,Math.min(a,window.innerHeight-s-8)),d=Math.max(8,Math.min(d,window.innerWidth-r-8)),{top:a,left:d,arrowLeft:i,arrowTop:c}}let s=null,i=!1;function c(){s||(s=requestAnimationFrame(()=>{s=null,n.forEach(e=>{const t=e.element;if(!t||!e.target)return;const o=t.querySelector(".solely-tooltip__arrow"),n=r(e.target,t,e.placement);t.style.top=`${n.top}px`,t.style.left=`${n.left}px`,o&&(void 0!==n.arrowLeft&&(o.style.left=`${n.arrowLeft}px`,o.style.top=""),void 0!==n.arrowTop&&(o.style.top=`${n.arrowTop}px`,o.style.left=""))})}))}function a(){i&&(i=!1,window.removeEventListener("resize",c),s&&(cancelAnimationFrame(s),s=null))}async function d(e,t){const o=n.findIndex(t=>t.id===e);if(-1===o)return;const l=n[o];l.element.classList.add("is-closing"),l.element.remove(),l.cleanupTheme(),l.scrollParents.forEach(e=>e.removeEventListener("scroll",c)),n.splice(o,1),0===n.length&&a(),null==t||t()}function m(){if(0===n.length)return;const e=new Set;n.forEach(t=>{t.scrollParents.forEach(t=>e.add(t)),t.element.classList.add("is-closing"),t.element.remove(),t.cleanupTheme()}),e.forEach(e=>e.removeEventListener("scroll",c)),n.length=0,a()}function p(l,s){var a;const d=e.generateId();e.injectStyle("solely-tooltip-styles",t.default);const p=s.placement??o.placement,u=s.cloneElement??!0,f=n.findIndex(e=>e.target===l);if(-1!==f){const e=n[f];e.element.remove(),e.cleanupTheme(),e.scrollParents.forEach(e=>e.removeEventListener("scroll",c)),n.splice(f,1)}o.singleton&&n.length>0&&m();const h=e.createElement("div",{className:`solely-tooltip solely-tooltip--${p}${s.className?` ${s.className}`:""}`,styles:{...s.style,...s.color?{backgroundColor:s.color}:{}}}),v=e.observeTheme(()=>h),g=e.createElement("div",{className:"solely-tooltip__content"});s.content&&("string"==typeof s.content?g.textContent=s.content:s.content instanceof HTMLElement&&g.appendChild(u?s.content.cloneNode(!0):s.content)),h.appendChild(g);const b=e.createElement("div",{className:"solely-tooltip__arrow"});s.color&&(b.style.backgroundColor=s.color),h.appendChild(b),document.body.appendChild(h),requestAnimationFrame(()=>{const e=r(l,h,p);h.style.top=`${e.top}px`,h.style.left=`${e.left}px`,void 0!==e.arrowLeft&&(b.style.left=`${e.arrowLeft}px`),void 0!==e.arrowTop&&(b.style.top=`${e.arrowTop}px`)});const y=function(e){const t=[];let o=e.parentElement;for(;o&&o!==document.body;){const e=getComputedStyle(o);"auto"!==e.overflow&&"scroll"!==e.overflow&&"auto"!==e.overflowY&&"scroll"!==e.overflowY||t.push(o),o=o.parentElement}return t}(l);return y.forEach(e=>e.addEventListener("scroll",c)),i||0===n.length||(i=!0,window.addEventListener("resize",c)),n.push({id:d,element:h,target:l,placement:p,scrollParents:y,cleanupTheme:v}),null==(a=s.onVisibleChange)||a.call(s,!0),d}function u(e,t){const n=p(e,t),l=t.duration??o.duration;l>0&&setTimeout(()=>d(n),l)}const f={bind:function(e,t){if(l.has(e))return{show:()=>{},hide:()=>{},destroy:()=>{}};l.add(e);const n=t.trigger??o.trigger;let r=t.visible??t.defaultVisible??!1,s=null;const i=()=>{r||(r=!0,s=p(e,t))},c=()=>{if(!r||null===s)return;r=!1;const e=s;s=null,d(e,()=>{var e;null==(e=t.onVisibleChange)||e.call(t,!1)})},a=e=>{e.stopPropagation(),r?c():i()},m=t=>{r&&(e.contains(t.target)||c())};return"hover"===n?(e.addEventListener("mouseenter",i),e.addEventListener("mouseleave",c)):"click"===n?(e.addEventListener("click",a),document.addEventListener("click",m)):"focus"===n&&(e.addEventListener("focus",i),e.addEventListener("blur",c)),r&&(s=p(e,t)),{show:i,hide:c,destroy:()=>{c(),l.delete(e),"hover"===n?(e.removeEventListener("mouseenter",i),e.removeEventListener("mouseleave",c)):"click"===n?(e.removeEventListener("click",a),document.removeEventListener("click",m)):"focus"===n&&(e.removeEventListener("focus",i),e.removeEventListener("blur",c))}}},showOnce:u,show:u,hide:async function(e){m(),null==e||e()},destroy:m,config:function(e){Object.assign(o,e)}};exports.Tooltip=f;
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { TooltipOptions, TooltipInstance, TooltipConfig } from './types';
|
|
2
|
+
declare function hideAllTooltipsSync(): void;
|
|
2
3
|
declare function hideAllTooltips(callback?: () => void): Promise<void>;
|
|
3
4
|
declare function bind(target: HTMLElement, options: TooltipOptions): TooltipInstance;
|
|
5
|
+
/**
|
|
6
|
+
* 一次性显示 Tooltip(自动隐藏)
|
|
7
|
+
* 如需手动控制显隐,请使用 bind() 方法
|
|
8
|
+
*/
|
|
4
9
|
declare function showOnce(target: HTMLElement, options: TooltipOptions & {
|
|
5
10
|
duration?: number;
|
|
6
11
|
}): void;
|
|
7
12
|
declare function config(options: Partial<TooltipConfig>): void;
|
|
8
13
|
export declare const Tooltip: {
|
|
14
|
+
/** 绑定到目标元素,返回可手动控制的实例 */
|
|
9
15
|
bind: typeof bind;
|
|
16
|
+
/** 一次性显示(自动隐藏)。如需手动控制请用 bind() */
|
|
17
|
+
showOnce: typeof showOnce;
|
|
18
|
+
/** @deprecated show 的别名,仅为向后兼容保留,请使用 showOnce */
|
|
10
19
|
show: typeof showOnce;
|
|
20
|
+
/** 隐藏所有 Tooltip */
|
|
11
21
|
hide: typeof hideAllTooltips;
|
|
22
|
+
/** 销毁所有 Tooltip */
|
|
23
|
+
destroy: typeof hideAllTooltipsSync;
|
|
24
|
+
/** 配置全局默认值 */
|
|
12
25
|
config: typeof config;
|
|
13
26
|
};
|
|
14
27
|
export default Tooltip;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{generateId as e,createElement as t,injectStyle as
|
|
1
|
+
import{generateId as e,createElement as t,observeTheme as o,injectStyle as n}from"../utils.js";import l from"./style.css.js";const r={placement:"top",trigger:"hover",duration:3e3,singleton:!0},s=[],i=new WeakSet;function c(e,t,o,n=8){const l=e.getBoundingClientRect(),r=t.offsetWidth||250,s=t.offsetHeight||100;let i,c,a=0,d=0;switch(o){case"top":a=l.top-s-n,d=l.left+(l.width-r)/2,i=r/2-4;break;case"topLeft":a=l.top-s-n,d=l.left,i=16;break;case"topRight":a=l.top-s-n,d=l.right-r,i=r-24;break;case"bottom":a=l.bottom+n,d=l.left+(l.width-r)/2,i=r/2-4;break;case"bottomLeft":a=l.bottom+n,d=l.left,i=16;break;case"bottomRight":a=l.bottom+n,d=l.right-r,i=r-24;break;case"left":a=l.top+(l.height-s)/2,d=l.left-r-n,c=s/2-4;break;case"leftTop":a=l.top,d=l.left-r-n,c=16;break;case"leftBottom":a=l.bottom-s,d=l.left-r-n,c=s-24;break;case"right":a=l.top+(l.height-s)/2,d=l.right+n,c=s/2-4;break;case"rightTop":a=l.top,d=l.right+n,c=16;break;case"rightBottom":a=l.bottom-s,d=l.right+n,c=s-24}return a=Math.max(8,Math.min(a,window.innerHeight-s-8)),d=Math.max(8,Math.min(d,window.innerWidth-r-8)),{top:a,left:d,arrowLeft:i,arrowTop:c}}let a=null,d=!1;function m(){a||(a=requestAnimationFrame(()=>{a=null,s.forEach(e=>{const t=e.element;if(!t||!e.target)return;const o=t.querySelector(".solely-tooltip__arrow"),n=c(e.target,t,e.placement);t.style.top=`${n.top}px`,t.style.left=`${n.left}px`,o&&(void 0!==n.arrowLeft&&(o.style.left=`${n.arrowLeft}px`,o.style.top=""),void 0!==n.arrowTop&&(o.style.top=`${n.arrowTop}px`,o.style.left=""))})}))}function f(){d&&(d=!1,window.removeEventListener("resize",m),a&&(cancelAnimationFrame(a),a=null))}async function p(e,t){const o=s.findIndex(t=>t.id===e);if(-1===o)return;const n=s[o];n.element.classList.add("is-closing"),n.element.remove(),n.cleanupTheme(),n.scrollParents.forEach(e=>e.removeEventListener("scroll",m)),s.splice(o,1),0===s.length&&f(),null==t||t()}function u(){if(0===s.length)return;const e=new Set;s.forEach(t=>{t.scrollParents.forEach(t=>e.add(t)),t.element.classList.add("is-closing"),t.element.remove(),t.cleanupTheme()}),e.forEach(e=>e.removeEventListener("scroll",m)),s.length=0,f()}function h(i,a){var f;const p=e();n("solely-tooltip-styles",l);const h=a.placement??r.placement,v=a.cloneElement??!0,g=s.findIndex(e=>e.target===i);if(-1!==g){const e=s[g];e.element.remove(),e.cleanupTheme(),e.scrollParents.forEach(e=>e.removeEventListener("scroll",m)),s.splice(g,1)}r.singleton&&s.length>0&&u();const w=t("div",{className:`solely-tooltip solely-tooltip--${h}${a.className?` ${a.className}`:""}`,styles:{...a.style,...a.color?{backgroundColor:a.color}:{}}}),b=o(()=>w),y=t("div",{className:"solely-tooltip__content"});a.content&&("string"==typeof a.content?y.textContent=a.content:a.content instanceof HTMLElement&&y.appendChild(v?a.content.cloneNode(!0):a.content)),w.appendChild(y);const E=t("div",{className:"solely-tooltip__arrow"});a.color&&(E.style.backgroundColor=a.color),w.appendChild(E),document.body.appendChild(w),requestAnimationFrame(()=>{const e=c(i,w,h);w.style.top=`${e.top}px`,w.style.left=`${e.left}px`,void 0!==e.arrowLeft&&(E.style.left=`${e.arrowLeft}px`),void 0!==e.arrowTop&&(E.style.top=`${e.arrowTop}px`)});const L=function(e){const t=[];let o=e.parentElement;for(;o&&o!==document.body;){const e=getComputedStyle(o);"auto"!==e.overflow&&"scroll"!==e.overflow&&"auto"!==e.overflowY&&"scroll"!==e.overflowY||t.push(o),o=o.parentElement}return t}(i);return L.forEach(e=>e.addEventListener("scroll",m)),d||0===s.length||(d=!0,window.addEventListener("resize",m)),s.push({id:p,element:w,target:i,placement:h,scrollParents:L,cleanupTheme:b}),null==(f=a.onVisibleChange)||f.call(a,!0),p}function v(e,t){const o=h(e,t),n=t.duration??r.duration;n>0&&setTimeout(()=>p(o),n)}const g={bind:function(e,t){if(i.has(e))return{show:()=>{},hide:()=>{},destroy:()=>{}};i.add(e);const o=t.trigger??r.trigger;let n=t.visible??t.defaultVisible??!1,l=null;const s=()=>{n||(n=!0,l=h(e,t))},c=()=>{if(!n||null===l)return;n=!1;const e=l;l=null,p(e,()=>{var e;null==(e=t.onVisibleChange)||e.call(t,!1)})},a=e=>{e.stopPropagation(),n?c():s()},d=t=>{n&&(e.contains(t.target)||c())};return"hover"===o?(e.addEventListener("mouseenter",s),e.addEventListener("mouseleave",c)):"click"===o?(e.addEventListener("click",a),document.addEventListener("click",d)):"focus"===o&&(e.addEventListener("focus",s),e.addEventListener("blur",c)),n&&(l=h(e,t)),{show:s,hide:c,destroy:()=>{c(),i.delete(e),"hover"===o?(e.removeEventListener("mouseenter",s),e.removeEventListener("mouseleave",c)):"click"===o?(e.removeEventListener("click",a),document.removeEventListener("click",d)):"focus"===o&&(e.removeEventListener("focus",s),e.removeEventListener("blur",c))}}},showOnce:v,show:v,hide:async function(e){u(),null==e||e()},destroy:u,config:function(e){Object.assign(r,e)}};export{g as Tooltip};
|
|
@@ -21,6 +21,8 @@ export interface TooltipOptions {
|
|
|
21
21
|
style?: Partial<CSSStyleDeclaration>;
|
|
22
22
|
/** 浮层渲染节点 */
|
|
23
23
|
getPopupContainer?: () => HTMLElement;
|
|
24
|
+
/** 是否克隆传入的 HTMLElement 内容(默认 true) */
|
|
25
|
+
cloneElement?: boolean;
|
|
24
26
|
}
|
|
25
27
|
export interface TooltipInstance {
|
|
26
28
|
/** 显示提示 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={FAST:200,NORMAL:300,SLOW:500};let e=0;exports.ANIMATION_DURATION=t,exports.Z_INDEX={TOOLTIP:1070,POPOVER:1060,MODAL:1050,TOAST:1100},exports.addClosingAnimation=function(e,o=t.NORMAL){return new Promise(t=>{e.classList.add("is-closing"),setTimeout(()=>t(),o)})},exports.calculatePosition=function(t,e,o="top",n=8){const r=t.getBoundingClientRect(),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={FAST:200,NORMAL:300,SLOW:500};let e=0,o=null;const n=new Set;exports.ANIMATION_DURATION=t,exports.Z_INDEX={TOOLTIP:1070,POPOVER:1060,MODAL:1050,TOAST:1100},exports.addClosingAnimation=function(e,o=t.NORMAL){return new Promise(t=>{e.classList.add("is-closing"),setTimeout(()=>t(),o)})},exports.calculatePosition=function(t,e,o="top",n=8){const r=t.getBoundingClientRect(),a=(null==e?void 0:e.offsetWidth)??250,s=(null==e?void 0:e.offsetHeight)??100,i=window.pageYOffset||document.documentElement.scrollTop,c=window.pageXOffset||document.documentElement.scrollLeft;let l,m,u=0,d=0;switch(o){case"top":u=r.top+i-s-n,d=r.left+c+(r.width-a)/2,l=a/2-4;break;case"topLeft":u=r.top+i-s-n,d=r.left+c,l=16;break;case"topRight":u=r.top+i-s-n,d=r.right+c-a,l=a-24;break;case"bottom":u=r.bottom+i+n,d=r.left+c+(r.width-a)/2,l=a/2-4;break;case"bottomLeft":u=r.bottom+i+n,d=r.left+c,l=16;break;case"bottomRight":u=r.bottom+i+n,d=r.right+c-a,l=a-24;break;case"left":u=r.top+i+(r.height-s)/2,d=r.left+c-a-n,m=s/2-4;break;case"leftTop":u=r.top+i,d=r.left+c-a-n,m=16;break;case"leftBottom":u=r.bottom+i-s,d=r.left+c-a-n,m=s-24;break;case"right":u=r.top+i+(r.height-s)/2,d=r.right+c+n,m=s/2-4;break;case"rightTop":u=r.top+i,d=r.right+c+n,m=16;break;case"rightBottom":u=r.bottom+i-s,d=r.right+c+n,m=s-24}return u=Math.max(8,Math.min(u,window.innerHeight+i-s-8)),d=Math.max(8,Math.min(d,window.innerWidth+c-a-8)),{top:u,left:d,arrowLeft:l,arrowTop:m}},exports.createElement=function(t,e){const o=document.createElement(t);return(null==e?void 0:e.className)&&(o.className=e.className),void 0!==(null==e?void 0:e.textContent)&&(o.textContent=e.textContent),(null==e?void 0:e.styles)&&Object.assign(o.style,e.styles),(null==e?void 0:e.attrs)&&Object.entries(e.attrs).forEach(([t,e])=>{o.setAttribute(t,e)}),o},exports.generateId=function(){return e=(e+1)%Number.MAX_SAFE_INTEGER,e},exports.injectStyle=function(t,e){if(document.getElementById(t))return;const o=document.createElement("style");o.id=t,o.textContent=e,document.head.appendChild(o)},exports.observeTheme=function(t){const e=()=>{const e=t();if(!e)return;const o=Array.isArray(e)?e:[e],n=document.documentElement.getAttribute("data-theme");o.forEach(t=>{n?t.setAttribute("data-theme",n):t.removeAttribute("data-theme")})};return e(),n.add(e),o||(o=new MutationObserver(()=>{n.forEach(t=>t())}),o.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]})),()=>{n.delete(e),0===n.size&&o&&(o.disconnect(),o=null)}},exports.removeStyle=function(t){const e=document.getElementById(t);e&&e.remove()},exports.safeAsyncCallback=async function(t,e){try{return await t()}catch(o){return console.error("[Solely Commands] Async callback error:",o),void(null==e||e())}};
|
|
@@ -38,3 +38,9 @@ export declare function safeAsyncCallback<T>(callback: () => T | Promise<T>, fal
|
|
|
38
38
|
* 添加关闭动画(使用 .is-closing 类)
|
|
39
39
|
*/
|
|
40
40
|
export declare function addClosingAnimation(element: HTMLElement, duration?: number): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* 观察主题变化并同步到指定元素
|
|
43
|
+
* @param getElements 返回需要同步主题的元素(单个、数组或 null)
|
|
44
|
+
* @returns 清理函数(取消观察)
|
|
45
|
+
*/
|
|
46
|
+
export declare function observeTheme(getElements: () => HTMLElement | HTMLElement[] | null): () => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t={FAST:200,NORMAL:300,SLOW:500},e={TOOLTIP:1070,POPOVER:1060,MODAL:1050,TOAST:1100};let o=0;function n(){return o=(o+1)%Number.MAX_SAFE_INTEGER,o}function r(t,e){if(document.getElementById(t))return;const o=document.createElement("style");o.id=t,o.textContent=e,document.head.appendChild(o)}function a(t){const e=document.getElementById(t);e&&e.remove()}function i(t,e){const o=document.createElement(t);return(null==e?void 0:e.className)&&(o.className=e.className),void 0!==(null==e?void 0:e.textContent)&&(o.textContent=e.textContent),(null==e?void 0:e.styles)&&Object.assign(o.style,e.styles),(null==e?void 0:e.attrs)&&Object.entries(e.attrs).forEach(([t,e])=>{o.setAttribute(t,e)}),o}function c(t,e,o="top",n=8){const r=t.getBoundingClientRect(),a=(null==e?void 0:e.offsetWidth)??250,i=(null==e?void 0:e.offsetHeight)??100,c=window.pageYOffset||document.documentElement.scrollTop,
|
|
1
|
+
const t={FAST:200,NORMAL:300,SLOW:500},e={TOOLTIP:1070,POPOVER:1060,MODAL:1050,TOAST:1100};let o=0;function n(){return o=(o+1)%Number.MAX_SAFE_INTEGER,o}function r(t,e){if(document.getElementById(t))return;const o=document.createElement("style");o.id=t,o.textContent=e,document.head.appendChild(o)}function a(t){const e=document.getElementById(t);e&&e.remove()}function i(t,e){const o=document.createElement(t);return(null==e?void 0:e.className)&&(o.className=e.className),void 0!==(null==e?void 0:e.textContent)&&(o.textContent=e.textContent),(null==e?void 0:e.styles)&&Object.assign(o.style,e.styles),(null==e?void 0:e.attrs)&&Object.entries(e.attrs).forEach(([t,e])=>{o.setAttribute(t,e)}),o}function c(t,e,o="top",n=8){const r=t.getBoundingClientRect(),a=(null==e?void 0:e.offsetWidth)??250,i=(null==e?void 0:e.offsetHeight)??100,c=window.pageYOffset||document.documentElement.scrollTop,s=window.pageXOffset||document.documentElement.scrollLeft;let l,m,u=0,d=0;switch(o){case"top":u=r.top+c-i-n,d=r.left+s+(r.width-a)/2,l=a/2-4;break;case"topLeft":u=r.top+c-i-n,d=r.left+s,l=16;break;case"topRight":u=r.top+c-i-n,d=r.right+s-a,l=a-24;break;case"bottom":u=r.bottom+c+n,d=r.left+s+(r.width-a)/2,l=a/2-4;break;case"bottomLeft":u=r.bottom+c+n,d=r.left+s,l=16;break;case"bottomRight":u=r.bottom+c+n,d=r.right+s-a,l=a-24;break;case"left":u=r.top+c+(r.height-i)/2,d=r.left+s-a-n,m=i/2-4;break;case"leftTop":u=r.top+c,d=r.left+s-a-n,m=16;break;case"leftBottom":u=r.bottom+c-i,d=r.left+s-a-n,m=i-24;break;case"right":u=r.top+c+(r.height-i)/2,d=r.right+s+n,m=i/2-4;break;case"rightTop":u=r.top+c,d=r.right+s+n,m=16;break;case"rightBottom":u=r.bottom+c-i,d=r.right+s+n,m=i-24}return u=Math.max(8,Math.min(u,window.innerHeight+c-i-8)),d=Math.max(8,Math.min(d,window.innerWidth+s-a-8)),{top:u,left:d,arrowLeft:l,arrowTop:m}}async function s(t,e){try{return await t()}catch(o){return console.error("[Solely Commands] Async callback error:",o),void(null==e||e())}}function l(e,o=t.NORMAL){return new Promise(t=>{e.classList.add("is-closing"),setTimeout(()=>t(),o)})}let m=null;const u=new Set;function d(t){const e=()=>{const e=t();if(!e)return;const o=Array.isArray(e)?e:[e],n=document.documentElement.getAttribute("data-theme");o.forEach(t=>{n?t.setAttribute("data-theme",n):t.removeAttribute("data-theme")})};return e(),u.add(e),m||(m=new MutationObserver(()=>{u.forEach(t=>t())}),m.observe(document.documentElement,{attributes:!0,attributeFilter:["data-theme"]})),()=>{u.delete(e),0===u.size&&m&&(m.disconnect(),m=null)}}export{t as ANIMATION_DURATION,e as Z_INDEX,l as addClosingAnimation,c as calculatePosition,i as createElement,n as generateId,r as injectStyle,d as observeTheme,a as removeStyle,s as safeAsyncCallback};
|