@primitiv-ui/web 0.1.53 → 0.1.55
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 +69 -4
- package/dist/cdn/accordion.js +1 -1
- package/dist/cdn/chunks/chunk-EDLRMP2K.js +1 -0
- package/dist/cdn/chunks/chunk-HXGMU6SD.js +1 -0
- package/dist/cdn/chunks/chunk-PKW6AKXD.js +1 -0
- package/dist/cdn/chunks/chunk-QVNDDONZ.js +1 -0
- package/dist/cdn/collapsible.js +1 -1
- package/dist/cdn/modal.js +1 -0
- package/dist/cdn/popover.js +1 -0
- package/dist/cdn/tabs.js +1 -1
- package/dist/custom-elements.json +749 -0
- package/dist/define/index.d.ts +2 -0
- package/dist/define/index.js +2 -0
- package/dist/define/modal.d.ts +1 -0
- package/dist/define/modal.js +11 -0
- package/dist/define/popover.d.ts +1 -0
- package/dist/define/popover.js +11 -0
- package/dist/frameworks/events.d.ts +8 -0
- package/dist/frameworks/react.d.ts +25 -2
- package/dist/frameworks/svelte.d.ts +22 -1
- package/dist/frameworks/vue.d.ts +22 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/modal/ModalController.d.ts +58 -0
- package/dist/modal/ModalController.js +91 -0
- package/dist/modal/elements.d.ts +86 -0
- package/dist/modal/elements.js +235 -0
- package/dist/modal/index.d.ts +2 -0
- package/dist/modal/index.js +2 -0
- package/dist/popover/PopoverController.d.ts +55 -0
- package/dist/popover/PopoverController.js +100 -0
- package/dist/popover/elements.d.ts +98 -0
- package/dist/popover/elements.js +230 -0
- package/dist/popover/index.d.ts +2 -0
- package/dist/popover/index.js +2 -0
- package/dist/primitiv-web.js +1 -1
- package/dist/tags.d.ts +15 -0
- package/package.json +18 -2
- package/dist/cdn/chunks/chunk-WVI5UEAW.js +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@ framework and no runtime dependencies beyond
|
|
|
6
6
|
server-rendered stack (HTMX, Rails, Django, Laravel, Spring …), and inside
|
|
7
7
|
React, Vue, Angular or any other framework.
|
|
8
8
|
|
|
9
|
-
> **Status: published.** Tabs, Accordion and
|
|
9
|
+
> **Status: published.** Tabs, Accordion, Collapsible, Modal and Popover so far. See
|
|
10
10
|
> [RFC 0033](../../docs/rfcs/0033-web-components.md) for the design.
|
|
11
11
|
|
|
12
12
|
## Components
|
|
@@ -16,6 +16,8 @@ React, Vue, Angular or any other framework.
|
|
|
16
16
|
| Tabs | `primitiv-tabs`, `-list`, `-trigger`, `-content` | `primitiv-tabs-change` | 0.1.42 |
|
|
17
17
|
| Accordion | `primitiv-accordion`, `-item`, `-trigger`, `-content`, `-trigger-icon` | `primitiv-accordion-change` | 0.1.44 |
|
|
18
18
|
| Collapsible | `primitiv-collapsible`, `-trigger`, `-content`, `-trigger-icon` | `primitiv-collapsible-change` | 0.1.47 |
|
|
19
|
+
| Modal | `primitiv-modal`, `-trigger`, `-content`, `-title`, `-description`, `-close` | `primitiv-modal-change` | 0.1.54 |
|
|
20
|
+
| Popover | `primitiv-popover`, `-trigger`, `-anchor`, `-content`, `-title`, `-description`, `-close` | `primitiv-popover-change` | 0.1.55 |
|
|
19
21
|
|
|
20
22
|
## Use it
|
|
21
23
|
|
|
@@ -47,9 +49,10 @@ Each `dist/cdn/<component>.js` imports the code components share from
|
|
|
47
49
|
downloads it once. `dist/primitiv-web.js` is the alternative: every element in
|
|
48
50
|
one file. Per-component files ship from 0.1.43.
|
|
49
51
|
|
|
50
|
-
The main entry (`@primitiv-ui/web`, `/tabs`, `/accordion`, `/collapsible
|
|
51
|
-
exports the classes and `defineTabs(registry?)` /
|
|
52
|
-
`
|
|
52
|
+
The main entry (`@primitiv-ui/web`, `/tabs`, `/accordion`, `/collapsible`,
|
|
53
|
+
`/modal`, `/popover`) exports the classes and `defineTabs(registry?)` /
|
|
54
|
+
`defineAccordion(registry?)` / `defineCollapsible(registry?)` /
|
|
55
|
+
`defineModal(registry?)` / `definePopover(registry?)` with **no side effects**.
|
|
53
56
|
|
|
54
57
|
**Render `hidden` on inactive panels yourself.** Until the module loads, CSS
|
|
55
58
|
cannot tell which panel is active, so markup that omits it shows every panel.
|
|
@@ -118,6 +121,68 @@ on a panel as it becomes active, for lazy loading.
|
|
|
118
121
|
open }`) and `primitiv-collapsible-show` on the panel as it opens. Render
|
|
119
122
|
`hidden` on a closed panel yourself, as for Tabs.
|
|
120
123
|
|
|
124
|
+
### Modal
|
|
125
|
+
|
|
126
|
+
```html
|
|
127
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@primitiv-ui/web@<version>/dist/cdn/modal.js"></script>
|
|
128
|
+
|
|
129
|
+
<primitiv-modal>
|
|
130
|
+
<primitiv-modal-trigger><button type="button">Edit profile</button></primitiv-modal-trigger>
|
|
131
|
+
<primitiv-modal-content>
|
|
132
|
+
<dialog>
|
|
133
|
+
<primitiv-modal-title><h2>Edit profile</h2></primitiv-modal-title>
|
|
134
|
+
<primitiv-modal-description><p>Changes apply to every workspace.</p></primitiv-modal-description>
|
|
135
|
+
<primitiv-modal-close><button type="button">Done</button></primitiv-modal-close>
|
|
136
|
+
</dialog>
|
|
137
|
+
</primitiv-modal-content>
|
|
138
|
+
</primitiv-modal>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
- **It is a native `<dialog>`, opened with `showModal()`**: the browser supplies
|
|
142
|
+
the top layer, the `::backdrop` and the inert page. The element adds the
|
|
143
|
+
Tab wrap, closing on Escape and on a backdrop press, and the ARIA wiring —
|
|
144
|
+
`aria-haspopup`, `aria-expanded` and `aria-controls` on the trigger's button,
|
|
145
|
+
`aria-labelledby` / `aria-describedby` from the title's heading and the
|
|
146
|
+
description's paragraph. Focus returns to the trigger on close.
|
|
147
|
+
- **`open` on the root is the state**, reflected as the user opens and dismisses
|
|
148
|
+
it; the `open` property reads and sets it, and setting it is not announced.
|
|
149
|
+
Leave `open` off the `<dialog>` itself — the root opens it modally, and
|
|
150
|
+
reopens modally one that arrives with it (a history snapshot).
|
|
151
|
+
- **Several triggers and close buttons** are fine. There is no overlay element:
|
|
152
|
+
style `::backdrop`.
|
|
153
|
+
- **Listen with `primitiv-modal-change`** (bubbles, cancelable, `detail: { open
|
|
154
|
+
}`), fired before every user-driven change — trigger, close, Escape, a backdrop
|
|
155
|
+
press, a `<form method="dialog">` — so `preventDefault()` keeps a dirty form
|
|
156
|
+
open.
|
|
157
|
+
|
|
158
|
+
### Popover
|
|
159
|
+
|
|
160
|
+
```html
|
|
161
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@primitiv-ui/web@<version>/dist/cdn/popover.js"></script>
|
|
162
|
+
|
|
163
|
+
<primitiv-popover>
|
|
164
|
+
<primitiv-popover-trigger><button type="button">Share</button></primitiv-popover-trigger>
|
|
165
|
+
<primitiv-popover-content popover="auto">
|
|
166
|
+
<primitiv-popover-title><h2>Share this page</h2></primitiv-popover-title>
|
|
167
|
+
<primitiv-popover-description><p>Anyone with the link can view it.</p></primitiv-popover-description>
|
|
168
|
+
<primitiv-popover-close><button type="button">Done</button></primitiv-popover-close>
|
|
169
|
+
</primitiv-popover-content>
|
|
170
|
+
</primitiv-popover>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
- **It is a native `popover="auto"` panel**: the browser supplies the top layer
|
|
174
|
+
and light dismiss. The element adds `role="dialog"` and the trigger's ARIA,
|
|
175
|
+
moves focus into the panel on open, and closes it on Escape with focus back on
|
|
176
|
+
the trigger. Write `popover="auto"` yourself so the panel is hidden before the
|
|
177
|
+
script loads.
|
|
178
|
+
- **No anchor wiring.** The panel is shown with its trigger as its source (or
|
|
179
|
+
the element inside `<primitiv-popover-anchor>`), which makes it the implicit
|
|
180
|
+
anchor, so CSS anchor positioning (`position-area`) places it with no
|
|
181
|
+
`anchor-name` / `position-anchor` pair.
|
|
182
|
+
- **`open` on the root is the state**; the `open` property reads and sets it.
|
|
183
|
+
**Listen with `primitiv-popover-change`** (bubbles, cancelable, `detail: {
|
|
184
|
+
open }`), fired before every user-driven change, a light dismiss included.
|
|
185
|
+
|
|
121
186
|
**TypeScript** — opt into the tag map so DOM queries return the element classes:
|
|
122
187
|
`import type {} from "@primitiv-ui/web/tags"` (npm only).
|
|
123
188
|
|
package/dist/cdn/accordion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as b,
|
|
1
|
+
import{a as b,b as R,c as H}from"./chunks/chunk-HXGMU6SD.js";import{a as S}from"./chunks/chunk-EDLRMP2K.js";import{a as h,b as r,c as v,d as O,e as f,f as C}from"./chunks/chunk-QVNDDONZ.js";function K(e,t){return e.disabled.has(t)?null:e.expanded.includes(t)?e.expanded.filter(n=>n!==t):e.multiple?[...e.expanded,t]:[t]}function M(e,t,n){let d=R({orientation:e.orientation,dir:e.dir,homeEnd:!0,activate:!0})[n];if(d==="activate")return e.disabled.has(t)?null:{focus:null,toggle:t};let l=e.values.filter(a=>!e.disabled.has(a)),s=H({action:d,navigable:l,currentKey:t});return s&&{focus:s.target,toggle:null}}var m=class extends S{#t;constructor(t,n){super(t),this.#t=n}#e(t){let{expanded:n,multiple:d}=this.#t.state(),l=K({disabled:this.disabled(),expanded:n,multiple:d},t);l!==null&&this.#t.change(l)}onTriggerClick(t){this.#e(t.value)}onTriggerKeydown(t,n){let{expanded:d,multiple:l,orientation:s,dir:a}=this.#t.state(),u=this.ordered(),p=u.map(([,i])=>i.value),o=M({values:p,disabled:this.disabled(),expanded:d,multiple:l,orientation:s,dir:a},t.value,n.key);o&&(n.preventDefault(),o.toggle!==null&&this.#e(o.toggle),o.focus!==null&&u[p.indexOf(o.focus)][0].focus())}};var I="primitiv-accordion",g="primitiv-accordion-item",w="primitiv-accordion-trigger",L="primitiv-accordion-content",k="primitiv-accordion-trigger-icon";function z(e){return(e??"").split(/\s+/).filter(Boolean)}function N(e){return e.childElementCount===1?e.firstElementChild:(v(e,`<${w}> needs exactly one element child (a <button>) to decorate.`),null)}var y=class extends C{#t=new Set;#e=!1;controller=new m(this,this.#i());reconcileOn=["value","disabled","orientation","force-mount"];get value(){return z(this.getAttribute("value"))}set value(t){this.setAttribute("value",typeof t=="string"?t:t.join(" "))}#i(){return{state:()=>({expanded:this.value,multiple:this.hasAttribute("multiple"),orientation:this.#o(),dir:this.direction()}),change:t=>{this.announce("primitiv-accordion-change",{value:t})&&(this.value=t)}}}#o(){return this.getAttribute("orientation")==="horizontal"?"horizontal":"vertical"}reconcile(){let t=new Set(this.value),n=this.rootId();r(this,"data-orientation",this.#o());let d=[];for(let l of this.parts(g)){let s=l.getAttribute("value");if(s===null){v(l,`<${g}> needs a value, which pairs it with the root's value.`);continue}let a=t.has(s),u=a?"open":"closed",[p]=f(l,w,g),[o]=f(l,L,g),i=p?N(p):null;if(i){let c=p.hasAttribute("disabled");d.push({value:s,element:i,disabled:c}),i.id||(i.id=b(n,"heading",s)),r(i,"aria-expanded",String(a)),r(i,"aria-disabled",String(c)),r(i,"data-disabled",String(c)),r(i,"data-state",u)}if(o){o.id||(o.id=b(n,"panel",s));let c=o.hasAttribute("force-mount");o.hasAttribute("role")||o.setAttribute("role","region"),r(o,"aria-labelledby",i?i.id:null),r(o,"hidden",a||c?null:""),r(o,"aria-hidden",a?null:"true"),r(o,"data-state",u),this.#e&&a&&!this.#t.has(s)&&o.dispatchEvent(new CustomEvent("primitiv-accordion-show",{bubbles:!0}))}i&&r(i,"aria-controls",o?o.id:null);for(let c of f(l,k,g))r(c,"aria-hidden","true"),r(c,"data-state",u)}this.controller.setTriggers(d),this.#t=t,this.#e=!0}},x=class extends h{},A=class extends h{},T=class extends h{},E=class extends h{};function D(e=globalThis.customElements){O(e,[[I,y],[g,x],[w,A],[L,T],[k,E]])}D();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var n=class{#r;#e=new Map;#t=null;constructor(e){this.#r=e}registerTrigger(e,t,r={}){this.#e.set(t,{value:e,disabled:r.disabled??!1})}setTriggers(e){this.#e.clear();for(let{value:t,element:r,disabled:i}of e)this.registerTrigger(t,r,{disabled:i})}unregisterTrigger(e){this.#e.delete(e)}connect(){if(this.#t)return;this.#t=new AbortController;let{signal:e}=this.#t;this.#r.addEventListener("click",t=>this.#i(t,this.onTriggerClick),{signal:e}),this.#r.addEventListener("keydown",t=>this.#i(t,this.onTriggerKeydown),{signal:e})}disconnect(){this.#t?.abort(),this.#t=null}ordered(){return[...this.#e].sort(([e],[t])=>e.compareDocumentPosition(t)&Node.DOCUMENT_POSITION_FOLLOWING?-1:1)}disabled(){let e=new Set;for(let t of this.#e.values())t.disabled&&e.add(t.value);return e}#i(e,t){for(let[r,i]of this.#e)if(r.contains(e.target))return t.call(this,i,e)}};export{n as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function c(r,e,n){return`${r}-${e}-${n}`}function l({orientation:r,dir:e,homeEnd:n=!1,activate:o=!1}){let t={};if(r==="horizontal"||r==="both"){let i=e==="rtl"?"ArrowLeft":"ArrowRight",a=e==="rtl"?"ArrowRight":"ArrowLeft";t[i]="next",t[a]="prev"}return(r==="vertical"||r==="both")&&(t.ArrowDown="next",t.ArrowUp="prev"),n&&(t.Home="first",t.End="last"),o&&(t.Enter="activate",t[" "]="activate"),t}function g({action:r,navigable:e,currentKey:n}){let o=e.length;if(o===0)return null;switch(r){case"activate":return{target:n};case"first":return{target:e[0]};case"last":return{target:e[o-1]};case void 0:return null;case"next":case"prev":{let t=e.indexOf(n);if(t===-1)return null;let i=r==="next"?1:o-1;return{target:e[(t+i)%o]}}}}export{c as a,l as b,g as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])",'[tabindex]:not([tabindex="-1"])'].join(",");export{t as a};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var i=globalThis.HTMLElement??class{};function d(e,t,n){e.getAttribute(t)!==n&&(n===null?e.removeAttribute(t):e.setAttribute(t,n))}var o=new WeakSet;function a(e,t){o.has(e)||(o.add(e),console.error(t,e))}function u(e,t){if(e)for(let[n,r]of t)e.get(n)||e.define(n,r)}function s(e,t,n){return[...e.querySelectorAll(t)].filter(r=>r.closest(n)===e)}var l=0,c=class extends i{#t;#e=new MutationObserver(()=>this.reconcile());connectedCallback(){this.controller.connect(),this.#e.observe(this,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[...this.reconcileOn]}),this.reconcile()}disconnectedCallback(){this.controller.disconnect(),this.#e.disconnect()}rootId(){return this.id||(this.#t??=`${this.localName}-${++l}`)}direction(){return this.matches(":dir(rtl)")?"rtl":"ltr"}parts(t){return s(this,t,this.localName)}announce(t,n){return this.dispatchEvent(new CustomEvent(t,{bubbles:!0,cancelable:!0,detail:n}))}};export{i as a,d as b,a as c,u as d,s as e,c as f};
|
package/dist/cdn/collapsible.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{a as E}from"./chunks/chunk-EDLRMP2K.js";import{a as p,b as l,c as C,d as x,f as T}from"./chunks/chunk-QVNDDONZ.js";function c(e){return e.disabled?null:!e.open}function v(e,t){if(t!=="Enter"&&t!==" ")return null;let o=c(e);return o===null?null:{open:o}}var d=class extends E{#e;constructor(t,o){super(t),this.#e=o}onTriggerClick(t){let o=c({open:this.#e.state().open,disabled:t.disabled});o!==null&&this.#e.change(o)}onTriggerKeydown(t,o){let r=v({open:this.#e.state().open,disabled:t.disabled},o.key);r&&(o.preventDefault(),this.#e.change(r.open))}};var N="primitiv-collapsible",f="primitiv-collapsible-trigger",H="primitiv-collapsible-content",w="primitiv-collapsible-trigger-icon",R="--primitiv-collapsible-collapsed-height";function S(e){return e.childElementCount===1?e.firstElementChild:(C(e,`<${f}> needs exactly one element child (a <button>) to decorate.`),null)}function K(e){return Number.isNaN(Number(e))?e:`${e}px`}function L(e,t,o){e.style.getPropertyValue(t)!==o&&(e.style.setProperty(t,o),e.getAttribute("style")===""&&e.removeAttribute("style"))}var u=class extends T{#e;controller=new d(this,this.#t());reconcileOn=["open","disabled","force-mount","collapsed-height"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#t(){return{state:()=>({open:this.open}),change:t=>{this.announce("primitiv-collapsible-change",{open:t})&&(this.open=t)}}}reconcile(){let t=this.open,o=t?"open":"closed",r=this.hasAttribute("disabled"),m=this.rootId();l(this,"data-state",o),l(this,"data-disabled",String(r));let[y]=this.parts(f),[n]=this.parts(H),i=y?S(y):null;if(i&&(i.id||(i.id=`${m}-trigger`),l(i,"aria-expanded",String(t)),l(i,"aria-disabled",r?"true":null),l(i,"data-disabled",String(r)),l(i,"data-state",o)),n){n.id||(n.id=`${m}-content`);let s=n.getAttribute("collapsed-height"),a=s!==null,A=a||n.hasAttribute("force-mount");l(n,"hidden",t||A?null:""),l(n,"aria-hidden",t||a?null:"true"),l(n,"data-state",o),l(n,"data-disabled",String(r)),l(n,"data-clamped",a?"true":null),L(n,R,a?K(s):""),t&&this.#e===!1&&n.dispatchEvent(new CustomEvent("primitiv-collapsible-show",{bubbles:!0}))}i&&l(i,"aria-controls",n?n.id:null);for(let s of this.parts(w))l(s,"aria-hidden","true"),l(s,"data-state",o);this.controller.setTriggers(i?[{value:"trigger",element:i,disabled:r}]:[]),this.#e=t}},b=class extends p{},h=class extends p{},g=class extends p{};function O(e=globalThis.customElements){x(e,[[N,u],[f,b],[H,h],[w,g]])}O();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as H}from"./chunks/chunk-PKW6AKXD.js";import{a as l,b as i,c as h,d as M,f as L}from"./chunks/chunk-QVNDDONZ.js";function C({key:n,shiftKey:t,active:e,count:o}){if(n!=="Tab")return null;if(o===0)return{focus:null};let r=o-1;return!t&&e===r?{focus:0}:t&&e===0?{focus:r}:null}function O(n,t){return t.x<n.left||t.x>n.right||t.y<n.top||t.y>n.bottom}var d=class{#e;#t;#n=null;constructor(t,e){this.#e=t,this.#t=e}connect(){if(this.#n)return;this.#n=new AbortController;let{signal:t}=this.#n,e=this.#e;e.addEventListener("close",()=>this.#t.change(!1),{signal:t}),e.addEventListener("cancel",o=>this.#i(o),{signal:t}),e.addEventListener("pointerdown",o=>this.#o(o),{signal:t}),e.addEventListener("keydown",o=>this.#s(o),{signal:t})}disconnect(){this.#n?.abort(),this.#n=null}sync(){let{open:t}=this.#t.state();t&&!this.#e.open?this.#e.showModal():!t&&this.#e.open&&this.#e.close()}#i(t){this.#t.escapeKeyDown?.(t);let e=t.defaultPrevented;t.preventDefault(),e||this.#t.change(!1)}#o(t){let e={x:t.clientX,y:t.clientY};O(this.#e.getBoundingClientRect(),e)&&(this.#t.pointerDownOutside?.(t),t.defaultPrevented||this.#t.change(!1))}#s(t){if(!this.#e.open)return;let e=[...this.#e.querySelectorAll(H)],o=C({key:t.key,shiftKey:t.shiftKey,active:e.indexOf(document.activeElement),count:e.length});o&&(t.preventDefault(),o.focus!==null&&e[o.focus].focus())}};var k="primitiv-modal",w="primitiv-modal-trigger",v="primitiv-modal-content",D="primitiv-modal-title",R="primitiv-modal-description",A="primitiv-modal-close";function p(n,t){return n.childElementCount===1?n.firstElementChild:(h(n,`<${n.localName}> needs exactly one element child (${t}) to decorate.`),null)}function K(n){let t=n.firstElementChild;return n.childElementCount===1&&t instanceof HTMLDialogElement?t:(h(n,`<${v}> needs exactly one <dialog> child to decorate.`),null)}var f=class extends L{#e=null;#t=null;#n=[];#i=[];#o=null;controller={connect:()=>this.#a(),disconnect:()=>this.#c()};reconcileOn=["open"];get open(){return this.hasAttribute("open")}set open(t){this.toggleAttribute("open",t)}#s(){return{state:()=>({open:this.open}),change:t=>this.#l(t)}}#l(t){t!==this.open&&(this.announce("primitiv-modal-change",{open:t})?this.open=t:this.#t?.sync())}#a(){this.#o=new AbortController,this.addEventListener("click",t=>this.#d(t),{signal:this.#o.signal}),this.#t?.connect()}#c(){this.#o.abort(),this.#o=null,this.#t?.disconnect(),this.#e&&i(this.#e,"open",null)}#d(t){let e=t.target;this.#n.some(o=>o.contains(e))?this.#l(!0):this.#i.some(o=>o.contains(e))&&this.#l(!1)}#u(t){t!==this.#e&&(this.#t?.disconnect(),t&&i(t,"open",null),this.#e=t,this.#t=t?new d(t,this.#s()):null,this.#t?.connect())}reconcile(){let t=this.open,e=t?"open":"closed",o=this.rootId();i(this,"data-state",e);let[r]=this.parts(v),s=r?K(r):null,[T]=this.parts(D),a=T?p(T,"a heading"):null,[x]=this.parts(R),c=x?p(x,"a <p>"):null;a&&!a.id&&(a.id=`${o}-title`),c&&!c.id&&(c.id=`${o}-description`),s&&(s.id||(s.id=`${o}-content`),i(s,"data-state",e),i(s,"aria-labelledby",a?a.id:null),i(s,"aria-describedby",c?c.id:null)),this.#n=this.#r(w);for(let u of this.#n)i(u,"aria-haspopup","dialog"),i(u,"aria-expanded",String(t)),i(u,"aria-controls",s?s.id:null);this.#i=this.#r(A),this.#u(s),this.#t?.sync()}#r(t){return this.parts(t).flatMap(e=>p(e,"a <button>")??[])}},m=class extends l{},b=class extends l{},E=class extends l{},g=class extends l{},y=class extends l{};function S(n=globalThis.customElements){M(n,[[k,f],[w,m],[v,b],[D,E],[R,g],[A,y]])}S();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as M}from"./chunks/chunk-PKW6AKXD.js";import{a as r,b as n,c as x,d as L,f as H}from"./chunks/chunk-QVNDDONZ.js";function C(o){return o==="Escape"?{open:!1}:null}function w({open:o,nativeLightDismiss:e,inTrigger:t,inPopover:i}){return o&&!e&&!t&&!i}var p=class{#o;#e;#t=null;#s=!1;constructor(e,t){this.#o=e,this.#e=t}connect(){if(this.#t)return;this.#t=new AbortController;let{signal:e}=this.#t;this.#o.addEventListener("toggle",t=>this.#i(t),{signal:e}),this.#o.addEventListener("keydown",t=>this.#n(t),{signal:e}),document.addEventListener("click",t=>this.#r(t),{signal:e})}disconnect(){this.#t?.abort(),this.#t=null,this.#s=!1}sync(){let{open:e}=this.#e.state();if(e&&!this.#s){this.#s=!0;let t=this.#e.source?.();t?this.#o.showPopover({source:t}):this.#o.showPopover(),(this.#o.querySelector(M)??this.#o).focus()}else if(!e&&this.#s){this.#s=!1;try{this.#o.hidePopover()}catch{}}}#i(e){e.newState==="closed"&&(this.#s=!1,this.#e.change(!1))}#n(e){e.defaultPrevented||!C(e.key)||(e.preventDefault(),this.#e.change(!1),this.#e.trigger()?.focus())}#r(e){let t=e.target;w({open:this.#e.state().open,nativeLightDismiss:"popover"in HTMLElement.prototype,inTrigger:this.#e.trigger()?.contains(t)??!1,inPopover:t.closest("[popover]")!==null})&&this.#e.change(!1)}};var D="primitiv-popover",P="primitiv-popover-trigger",O="primitiv-popover-anchor",A="primitiv-popover-content",R="primitiv-popover-title",S="primitiv-popover-description",k="primitiv-popover-close";function c(o,e){return o.childElementCount===1?o.firstElementChild:(x(o,`<${o.localName}> needs exactly one element child (${e}) to decorate.`),null)}var h=class extends H{#o=null;#e=null;#t=null;#s=null;#i=[];#n=null;controller={connect:()=>this.#a(),disconnect:()=>this.#c()};reconcileOn=["open"];get open(){return this.hasAttribute("open")}set open(e){this.toggleAttribute("open",e)}#r(){return{state:()=>({open:this.open}),change:e=>this.#l(e),trigger:()=>this.#t,source:()=>this.#s??this.#t}}#l(e){e!==this.open&&(this.announce("primitiv-popover-change",{open:e})?this.open=e:queueMicrotask(()=>this.#e?.sync()))}#a(){this.#n=new AbortController,this.addEventListener("click",e=>this.#p(e),{signal:this.#n.signal}),this.#e?.connect()}#c(){this.#n.abort(),this.#n=null,this.#e?.disconnect()}#p(e){let t=e.target;this.#t?.contains(t)?this.#l(!this.open):this.#i.some(i=>i.contains(t))&&this.#l(!1)}#h(e){e!==this.#o&&(this.#e?.disconnect(),this.#o=e,this.#e=e?new p(e,this.#r()):null,this.#e?.connect())}reconcile(){let e=this.open,t=e?"open":"closed",i=this.rootId();n(this,"data-state",t);let[s=null]=this.parts(A),[E]=this.parts(P),[b]=this.parts(O),[y]=this.parts(R),[T]=this.parts(S);this.#t=E?c(E,"a <button>"):null,this.#s=b?c(b,"the element to anchor to"):null;let l=y?c(y,"a heading"):null,a=T?c(T,"a <p>"):null;l&&!l.id&&(l.id=`${i}-title`),a&&!a.id&&(a.id=`${i}-description`),s&&(s.id||(s.id=`${i}-content`),n(s,"role","dialog"),s.hasAttribute("popover")||s.setAttribute("popover","auto"),n(s,"tabindex","-1"),n(s,"data-state",t),n(s,"aria-labelledby",l?l.id:null),n(s,"aria-describedby",a?a.id:null)),this.#t&&(n(this.#t,"aria-haspopup","dialog"),n(this.#t,"aria-expanded",String(e)),n(this.#t,"aria-controls",s?s.id:null)),this.#i=this.parts(k).flatMap(N=>c(N,"a <button>")??[]),this.#h(s),this.#e?.sync()}},d=class extends r{},u=class extends r{},v=class extends r{},g=class extends r{},f=class extends r{},m=class extends r{};function I(o=globalThis.customElements){L(o,[[D,h],[P,d],[O,u],[A,v],[R,g],[S,f],[k,m]])}I();
|
package/dist/cdn/tabs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as f,b as R,c as w}from"./chunks/chunk-HXGMU6SD.js";import{a as H}from"./chunks/chunk-EDLRMP2K.js";import{a as v,b as n,c as A,d as O,f as C}from"./chunks/chunk-QVNDDONZ.js";function S(i){return i.active??i.values[0]}function g(i,e){return i.disabled.has(e)||i.active===e?null:e}function K(i,e,o){let s=R({orientation:i.orientation,dir:i.dir,homeEnd:!0,activate:!0})[o],l=w({action:s,navigable:i.values,currentKey:e});if(!l)return null;let d=l.target,u=i.activationMode==="automatic"||s==="activate";return{focus:d,activate:u?g(i,d):null}}var p=class extends H{#t;constructor(e,o){super(e),this.#t=o}onTriggerClick(e){let{active:o}=this.#t.state(),s=g({disabled:this.disabled(),active:o},e.value);if(s!==null){let l=this.ordered().map(([,d])=>d.value);this.#t.activate(s,l.indexOf(s))}}onTriggerKeydown(e,o){let{active:s,orientation:l,dir:d,activationMode:u}=this.#t.state(),b=this.ordered(),a=b.map(([,r])=>r.value),t=K({values:a,disabled:this.disabled(),active:s,orientation:l,dir:d,activationMode:u},e.value,o.key);t&&(o.preventDefault(),t.activate!==null&&this.#t.activate(t.activate,a.indexOf(t.activate)),b[a.indexOf(t.focus)][0].focus())}};var D="primitiv-tabs",k="primitiv-tabs-list",x="primitiv-tabs-trigger",I="primitiv-tabs-content";function z(i){let e=i.getAttribute("value");return i.childElementCount===1&&e!==null?{tab:i.firstElementChild,value:e}:(A(i,`<${x}> needs a value and exactly one element child (a <button>, an <a href> or a router link) to decorate.`),null)}var m=class extends C{#t;#e=!1;controller=new p(this,this.#a());reconcileOn=["value","disabled","label","orientation"];get value(){return this.getAttribute("value")??void 0}set value(e){this.setAttribute("value",e)}#a(){return{state:()=>({active:this.value,orientation:this.#i(),dir:this.direction(),activationMode:this.#n()}),activate:(e,o)=>{this.announce("primitiv-tabs-change",{value:e,index:o})&&(this.value=e)}}}#n(){let e=this.getAttribute("activation-mode");return e==="manual"?e:"automatic"}#i(){return this.getAttribute("orientation")==="vertical"?"vertical":"horizontal"}reconcile(){let e=this.#i(),o=this.value,s=this.rootId();n(this,"data-orientation",e);for(let a of this.parts(k)){n(a,"role","tablist"),n(a,"aria-orientation",e),n(a,"data-orientation",e);let t=a.getAttribute("label");t!==null&&n(a,"aria-label",t)}let l=new Map;for(let a of this.parts(I)){let t=a.getAttribute("value");t!==null&&l.set(t,a)}let d=this.parts(x).flatMap(a=>{let t=z(a);return t?[{trigger:a,...t}]:[]}),u=S({values:d.map(a=>a.value),active:o});this.controller.setTriggers(d.map(({trigger:a,tab:t,value:r})=>({value:r,element:t,disabled:a.hasAttribute("disabled")})));for(let{trigger:a,tab:t,value:r}of d){let c=l.get(r),M=r===o,E=a.hasAttribute("disabled");t.id||(t.id=f(s,"trigger",r)),c&&!c.id&&(c.id=f(s,"panel",r)),n(t,"role","tab"),n(t,"aria-selected",String(M)),n(t,"aria-controls",c?c.id:null),n(t,"tabindex",r===u?"0":"-1"),n(t,"aria-disabled",E?"true":null),n(t,"data-disabled",E?"":null),n(t,"data-state",M?"active":"inactive"),n(t,"data-orientation",e),c&&n(c,"aria-labelledby",t.id)}for(let[a,t]of l){let r=a===o;n(t,"role","tabpanel"),n(t,"tabindex","0"),n(t,"hidden",r?null:""),n(t,"data-state",r?"active":"inactive"),n(t,"data-orientation",e)}let b=l.get(o);this.#e&&o!==this.#t&&b&&b.dispatchEvent(new CustomEvent("primitiv-tabs-show",{bubbles:!0})),this.#t=o,this.#e=!0}},h=class extends v{},T=class extends v{},y=class extends v{};function L(i=globalThis.customElements){O(i,[[D,m],[k,h],[x,T],[I,y]])}L();
|