@data-slot/dialog 0.2.165 → 0.2.167
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 +9 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -264,6 +264,15 @@ element.dispatchEvent(
|
|
|
264
264
|
|
|
265
265
|
Use `{ open: boolean }` instead.
|
|
266
266
|
|
|
267
|
+
## Controller destruction
|
|
268
|
+
|
|
269
|
+
`destroy()` permanently disposes the controller and hides any open surface without
|
|
270
|
+
emitting an additional change event. Repeated destruction is safe; methods on the
|
|
271
|
+
old controller become no-ops. Create a new controller on the same root to rebind it.
|
|
272
|
+
|
|
273
|
+
Destruction restores prior focus, falling back to a surviving trigger if the prior
|
|
274
|
+
target was removed. Destroying an unopened modal does not move focus.
|
|
275
|
+
|
|
267
276
|
## License
|
|
268
277
|
|
|
269
278
|
MIT
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=`@data-slot/dialog
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@data-slot/core`);const t=`@data-slot/dialog`;function n(n,r={}){let i=(0,e.reuseRootBinding)(n,t,`[@data-slot/dialog] createDialog() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(i)return i;let a=r.defaultOpen??(0,e.getDataBool)(n,`defaultOpen`)??!1,o=r.onOpenChange,s=r.closeOnClickOutside??(0,e.getDataBool)(n,`closeOnClickOutside`)??!0,c=r.closeOnEscape??(0,e.getDataBool)(n,`closeOnEscape`)??!0,l=r.lockScroll??(0,e.getDataBool)(n,`lockScroll`)??!0,u=r.alertDialog??(0,e.getDataBool)(n,`alertDialog`)??!1,d=(0,e.getPart)(n,`dialog-trigger`),f=(0,e.getPart)(n,`dialog-portal`),p=(0,e.getPart)(n,`dialog-overlay`),m=(0,e.getPart)(n,`dialog-content`),h=(0,e.getPart)(n,`dialog-title`),g=(0,e.getPart)(n,`dialog-description`);if(!m)throw Error(`Dialog requires dialog-content slot`);if(!p)throw Error(`Dialog requires dialog-overlay slot`);let _=!1,v=(0,e.createTerminalLifecycle)(),y=null,b=[],x=f?(0,e.createPortalLifecycle)({content:f,root:n}):null,S=!1,C=()=>{v.trackFinalRaf(()=>{y&&(document.contains(y)?(0,e.focusElement)(y):d&&document.contains(d)&&(0,e.focusElement)(d)),y=null})};(0,e.ensureId)(m,`dialog-content`),m.setAttribute(`role`,u?`alertdialog`:`dialog`),(0,e.setAria)(m,`modal`,!0),(0,e.linkLabelledBy)(m,h,g),p.setAttribute(`role`,`presentation`),p.setAttribute(`aria-hidden`,`true`),p.tabIndex=-1,d&&(d.setAttribute(`aria-haspopup`,`dialog`),d.setAttribute(`aria-controls`,m.id),(0,e.setAria)(d,`expanded`,!1));let w=!1,T=()=>{m.hasAttribute(`tabindex`)||(m.tabIndex=-1,w=!0)},E=()=>{w&&=(m.removeAttribute(`tabindex`),!1)},D=()=>{let t=(0,e.getAutofocusOrFirstFocusable)(m);if(t)return t.focus();T(),m.focus()},O=()=>{x?.mount()},k=()=>{v.trackRaf(()=>{y&&document.contains(y)&&typeof y.focus==`function`?(0,e.focusElement)(y):d&&document.contains(d)&&(0,e.focusElement)(d),y=null})},A=e=>{if(n.setAttribute(`data-state`,e),f&&f.setAttribute(`data-state`,e),p.setAttribute(`data-state`,e),m.setAttribute(`data-state`,e),e===`open`){n.setAttribute(`data-open`,``),f?.setAttribute(`data-open`,``),p.setAttribute(`data-open`,``),m.setAttribute(`data-open`,``),n.removeAttribute(`data-closed`),f?.removeAttribute(`data-closed`),p.removeAttribute(`data-closed`),m.removeAttribute(`data-closed`);return}n.setAttribute(`data-closed`,``),f?.setAttribute(`data-closed`,``),p.setAttribute(`data-closed`,``),m.setAttribute(`data-closed`,``),n.removeAttribute(`data-open`),f?.removeAttribute(`data-open`),p.removeAttribute(`data-open`),m.removeAttribute(`data-open`)},j=0,M=0,N=0,P=0,F=(e,t)=>{v.isDestroyed||_||t!==j||(e.hidden=!0,M=Math.max(0,M-1),M===0&&(E(),k()))},I=(0,e.createPresenceLifecycle)({element:p,onExitComplete:()=>F(p,N)}),L=(0,e.createPresenceLifecycle)({element:m,onExitComplete:()=>F(m,P)}),R=(t,r=!1)=>{v.isDestroyed||_===t&&!r||(t?(j+=1,M=0,O(),y=document.activeElement,B.open(),l&&!S&&((0,e.lockScroll)(),S=!0)):(j+=1,M=2,N=j,P=j,B.close(),S&&=((0,e.unlockScroll)(),!1)),_=t,d&&(0,e.setAria)(d,`expanded`,_),t?(p.hidden=!1,m.hidden=!1,A(`open`),I.enter(),L.enter()):(A(`closed`),I.exit(),L.exit()),(0,e.emit)(n,`dialog:change`,{open:_}),o?.(_),t&&v.trackRaf(()=>D()))},z=t=>{if(t.key!==`Tab`)return;let n=(0,e.getTabbables)(m);if(n.length===0){t.preventDefault(),T(),m.focus();return}let r=n[0],i=n[n.length-1],a=m.ownerDocument.activeElement;if(!n.includes(a)){t.preventDefault(),(t.shiftKey?i:r).focus();return}if(r===i){t.preventDefault();return}t.shiftKey?a===r&&(t.preventDefault(),i.focus()):a===i&&(t.preventDefault(),r.focus())},B=(0,e.createModalStackItem)({content:m,overlay:p,onTabKeydown:z,cssVarPrefix:`dialog`});m.hidden=!0,p.hidden=!0,A(`closed`),d&&b.push((0,e.on)(d,`click`,()=>R(!_))),b.push((0,e.on)(m,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&m.contains(n)&&R(!1)})),s&&b.push((0,e.on)(p,`click`,e=>{e.button===0&&e.target===p&&_&&R(!1)})),b.push((0,e.createDismissLayer)({root:n,isOpen:()=>_,onDismiss:()=>R(!1),closeOnClickOutside:!1,closeOnEscape:c}));let V={open:()=>{v.isDestroyed||R(!0)},close:()=>{v.isDestroyed||R(!1)},toggle:()=>{v.isDestroyed||R(!_)},get isOpen(){return _},destroy:()=>{v.destroy()},_handleKeydown:z,_content:m,_overlay:p};return(0,e.registerModalTerminalResources)(v,{cleanups:b,modalStack:B,presence:[I,L],portal:x,beforeDestroy:C,reset:()=>{j+=1,M=0,_=!1,A(`closed`),p.hidden=!0,m.hidden=!0,d&&(0,e.setAria)(d,`expanded`,!1)},releaseScrollLock:()=>{S&&=((0,e.unlockScroll)(),!1)},cleanup:E,unbind:()=>(0,e.clearRootBinding)(n,t,V)}),b.push((0,e.onRoot)(n,`dialog:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&R(n)})),(0,e.setRootBinding)(n,t,V),a&&R(!0),V}function r(r=document){let i=[];for(let a of(0,e.getRoots)(r,`dialog`))(0,e.hasRootBinding)(a,t)||i.push(n(a));return i}exports.create=r,exports.createDialog=n;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{clearRootBinding as e,createDismissLayer as t,createModalStackItem as n,createPortalLifecycle as r,createPresenceLifecycle as i,emit as
|
|
1
|
+
import{clearRootBinding as e,createDismissLayer as t,createModalStackItem as n,createPortalLifecycle as r,createPresenceLifecycle as i,createTerminalLifecycle as ee,emit as te,ensureId as ne,focusElement as a,getAutofocusOrFirstFocusable as o,getDataBool as s,getPart as c,getRoots as l,getTabbables as u,hasRootBinding as d,linkLabelledBy as f,lockScroll as p,on as m,onRoot as re,registerModalTerminalResources as ie,reuseRootBinding as ae,setAria as h,setRootBinding as oe,unlockScroll as g}from"@data-slot/core";const _=`@data-slot/dialog`;function v(l,d={}){let v=ae(l,_,`[@data-slot/dialog] createDialog() called more than once for the same root. Returning the existing controller. Destroy it before rebinding with new options.`);if(v)return v;let y=d.defaultOpen??s(l,`defaultOpen`)??!1,b=d.onOpenChange,x=d.closeOnClickOutside??s(l,`closeOnClickOutside`)??!0,S=d.closeOnEscape??s(l,`closeOnEscape`)??!0,C=d.lockScroll??s(l,`lockScroll`)??!0,w=d.alertDialog??s(l,`alertDialog`)??!1,T=c(l,`dialog-trigger`),E=c(l,`dialog-portal`),D=c(l,`dialog-overlay`),O=c(l,`dialog-content`),se=c(l,`dialog-title`),ce=c(l,`dialog-description`);if(!O)throw Error(`Dialog requires dialog-content slot`);if(!D)throw Error(`Dialog requires dialog-overlay slot`);let k=!1,A=ee(),j=null,M=[],N=E?r({content:E,root:l}):null,P=!1,F=()=>{A.trackFinalRaf(()=>{j&&(document.contains(j)?a(j):T&&document.contains(T)&&a(T)),j=null})};ne(O,`dialog-content`),O.setAttribute(`role`,w?`alertdialog`:`dialog`),h(O,`modal`,!0),f(O,se,ce),D.setAttribute(`role`,`presentation`),D.setAttribute(`aria-hidden`,`true`),D.tabIndex=-1,T&&(T.setAttribute(`aria-haspopup`,`dialog`),T.setAttribute(`aria-controls`,O.id),h(T,`expanded`,!1));let I=!1,L=()=>{O.hasAttribute(`tabindex`)||(O.tabIndex=-1,I=!0)},R=()=>{I&&=(O.removeAttribute(`tabindex`),!1)},z=()=>{let e=o(O);if(e)return e.focus();L(),O.focus()},B=()=>{N?.mount()},V=()=>{A.trackRaf(()=>{j&&document.contains(j)&&typeof j.focus==`function`?a(j):T&&document.contains(T)&&a(T),j=null})},H=e=>{if(l.setAttribute(`data-state`,e),E&&E.setAttribute(`data-state`,e),D.setAttribute(`data-state`,e),O.setAttribute(`data-state`,e),e===`open`){l.setAttribute(`data-open`,``),E?.setAttribute(`data-open`,``),D.setAttribute(`data-open`,``),O.setAttribute(`data-open`,``),l.removeAttribute(`data-closed`),E?.removeAttribute(`data-closed`),D.removeAttribute(`data-closed`),O.removeAttribute(`data-closed`);return}l.setAttribute(`data-closed`,``),E?.setAttribute(`data-closed`,``),D.setAttribute(`data-closed`,``),O.setAttribute(`data-closed`,``),l.removeAttribute(`data-open`),E?.removeAttribute(`data-open`),D.removeAttribute(`data-open`),O.removeAttribute(`data-open`)},U=0,W=0,G=0,K=0,q=(e,t)=>{A.isDestroyed||k||t!==U||(e.hidden=!0,W=Math.max(0,W-1),W===0&&(R(),V()))},J=i({element:D,onExitComplete:()=>q(D,G)}),Y=i({element:O,onExitComplete:()=>q(O,K)}),X=(e,t=!1)=>{A.isDestroyed||k===e&&!t||(e?(U+=1,W=0,B(),j=document.activeElement,Q.open(),C&&!P&&(p(),P=!0)):(U+=1,W=2,G=U,K=U,Q.close(),P&&=(g(),!1)),k=e,T&&h(T,`expanded`,k),e?(D.hidden=!1,O.hidden=!1,H(`open`),J.enter(),Y.enter()):(H(`closed`),J.exit(),Y.exit()),te(l,`dialog:change`,{open:k}),b?.(k),e&&A.trackRaf(()=>z()))},Z=e=>{if(e.key!==`Tab`)return;let t=u(O);if(t.length===0){e.preventDefault(),L(),O.focus();return}let n=t[0],r=t[t.length-1],i=O.ownerDocument.activeElement;if(!t.includes(i)){e.preventDefault(),(e.shiftKey?r:n).focus();return}if(n===r){e.preventDefault();return}e.shiftKey?i===n&&(e.preventDefault(),r.focus()):i===r&&(e.preventDefault(),n.focus())},Q=n({content:O,overlay:D,onTabKeydown:Z,cssVarPrefix:`dialog`});O.hidden=!0,D.hidden=!0,H(`closed`),T&&M.push(m(T,`click`,()=>X(!k))),M.push(m(O,`click`,e=>{let t=e.target;if(!t)return;let n=t.closest?.(`[data-slot="dialog-close"]`);n&&O.contains(n)&&X(!1)})),x&&M.push(m(D,`click`,e=>{e.button===0&&e.target===D&&k&&X(!1)})),M.push(t({root:l,isOpen:()=>k,onDismiss:()=>X(!1),closeOnClickOutside:!1,closeOnEscape:S}));let $={open:()=>{A.isDestroyed||X(!0)},close:()=>{A.isDestroyed||X(!1)},toggle:()=>{A.isDestroyed||X(!k)},get isOpen(){return k},destroy:()=>{A.destroy()},_handleKeydown:Z,_content:O,_overlay:D};return ie(A,{cleanups:M,modalStack:Q,presence:[J,Y],portal:N,beforeDestroy:F,reset:()=>{U+=1,W=0,k=!1,H(`closed`),D.hidden=!0,O.hidden=!0,T&&h(T,`expanded`,!1)},releaseScrollLock:()=>{P&&=(g(),!1)},cleanup:R,unbind:()=>e(l,_,$)}),M.push(re(l,`dialog:set`,e=>{let t=e.detail,n;t?.open===void 0?t?.value!==void 0&&(n=t.value):n=t.open,typeof n==`boolean`&&X(n)})),oe(l,_,$),y&&X(!0),$}function y(e=document){let t=[];for(let n of l(e,`dialog`))d(n,_)||t.push(v(n));return t}export{y as create,v as createDialog};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@data-slot/dialog",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.167",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -35,6 +35,6 @@
|
|
|
35
35
|
],
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@data-slot/core": "0.2.
|
|
38
|
+
"@data-slot/core": "0.2.167"
|
|
39
39
|
}
|
|
40
40
|
}
|