@cascivo/elements 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -2
- package/dist/base-B5z3ufCR.js +1 -0
- package/dist/chips-Cg27QTfm.js +1 -0
- package/dist/combobox.d.ts +82 -0
- package/dist/combobox.js +1 -0
- package/dist/command-menu.d.ts +62 -0
- package/dist/command-menu.js +1 -0
- package/dist/custom-elements.json +924 -0
- package/dist/data-table.d.ts +70 -0
- package/dist/data-table.js +1 -0
- package/dist/date-picker.d.ts +83 -0
- package/dist/date-picker.js +1 -0
- package/dist/dialog.d.ts +58 -0
- package/dist/dialog.js +1 -0
- package/dist/drawer.d.ts +61 -0
- package/dist/drawer.js +1 -0
- package/dist/elements.css +16 -0
- package/dist/form.d.ts +14 -0
- package/dist/form.js +1 -0
- package/dist/htmx.d.ts +1 -0
- package/dist/htmx.js +1 -0
- package/dist/menu.d.ts +51 -0
- package/dist/menu.js +1 -0
- package/dist/messages-Bhd7waiI.js +1 -0
- package/dist/multi-select.d.ts +80 -0
- package/dist/multi-select.js +1 -0
- package/dist/tabs.d.ts +51 -0
- package/dist/tabs.js +1 -0
- package/dist/tags-input.d.ts +77 -0
- package/dist/tags-input.js +1 -0
- package/dist/theme.d.ts +58 -0
- package/dist/theme.js +1 -0
- package/dist/toaster.d.ts +38 -0
- package/dist/toaster.js +1 -0
- package/dist/tooltip.d.ts +54 -0
- package/dist/tooltip.js +1 -0
- package/package.json +130 -3
- package/readme.body.md +95 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) cascivo contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,124 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- generated by scripts/readme/generate.ts — edit readme.body.md, not this file -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<div align="center">
|
|
4
|
+
<a href="https://cascivo.com"><img src="https://cascivo.com/logo-mark-img-accent.svg" width="72" height="72" alt="cascivo logo"></a>
|
|
5
|
+
<h1>@cascivo/elements</h1>
|
|
6
|
+
<p><strong>Light-DOM custom elements (cv-menu, cv-tabs, cv-combobox, cv-date-picker, cv-dialog, cv-toaster, cv-form) and the htmx glue that enhance cascivo's server-rendered markup: no React, behaviour on @cascivo/core/pure</strong></p>
|
|
7
|
+
|
|
8
|
+
[](https://www.npmjs.com/package/@cascivo/elements)
|
|
9
|
+
[](https://www.npmjs.com/package/@cascivo/elements)
|
|
10
|
+
[](https://github.com/cascivo/cascivo/blob/main/LICENSE)
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
[npm](https://www.npmjs.com/package/@cascivo/elements) · [cascivo.com](https://cascivo.com) · [Docs](https://cascivo.com/docs) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/cascivo/cascivo)
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## What
|
|
19
|
+
|
|
20
|
+
Light-DOM custom elements that enhance the server-rendered [`@cascivo/css`](../css/README.md) markup (the
|
|
21
|
+
`cv-<unit>-<part>` classes that `cascivo-html` and `cascivo-server` emit): `<cv-menu>`, `<cv-tabs>`,
|
|
22
|
+
`<cv-form>`, `<cv-combobox>`, `<cv-date-picker>`, `<cv-dialog>` and `<cv-toaster>`. No React. Without JS the
|
|
23
|
+
markup still works; with JS the elements add the keyboard, focus and ARIA behaviour on top of
|
|
24
|
+
`@cascivo/core/pure` signals. Guide: [USING-CASCIVO-SERVER.md](../../docs/USING-CASCIVO-SERVER.md); markup contract:
|
|
25
|
+
[CONTRACT.md](../../docs/CONTRACT.md).
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
Importing an element module does **not** register it: each module exports `define()`, which is idempotent
|
|
30
|
+
(`customElements.define` only when the tag is unknown). `@cascivo/elements/htmx` is the exception, it wires
|
|
31
|
+
the document when imported.
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
// web/src/elements.ts (the starter's file)
|
|
35
|
+
import '@cascivo/elements/elements.css'
|
|
36
|
+
import { define as menu } from '@cascivo/elements/menu'
|
|
37
|
+
import { define as tabs } from '@cascivo/elements/tabs'
|
|
38
|
+
import '@cascivo/elements/htmx'
|
|
39
|
+
|
|
40
|
+
for (const define of [menu, tabs]) define()
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
One entry per element, no barrel, so a page ships only what it uses.
|
|
44
|
+
|
|
45
|
+
| Export | What |
|
|
46
|
+
| -------------------------- | ------------------------------------------------------------------------------------- |
|
|
47
|
+
| `/menu` `/tabs` `/form` | `define()` for `cv-menu` (fires `cv-select`), `cv-tabs`, `cv-form` |
|
|
48
|
+
| `/combobox` `/date-picker` | `define()` for the form-associated `cv-combobox`, `cv-date-picker` |
|
|
49
|
+
| `/dialog` `/toaster` | `define()` for `cv-dialog` (`cv-open`, `cv-close`), `cv-toaster` (`cv-toast-dismiss`) |
|
|
50
|
+
| `/htmx` | the glue below; no `define()` |
|
|
51
|
+
| `/elements.css` | the component CSS those elements style, in `@layer cascivo.component` |
|
|
52
|
+
| `/custom-elements.json` | Custom Elements Manifest (tags, attributes, events) |
|
|
53
|
+
|
|
54
|
+
## Markup
|
|
55
|
+
|
|
56
|
+
The element wraps the markup the server renders; this is the shape `<cv-tabs>` enhances (the server picks the
|
|
57
|
+
selected tab, the element projects it and adds roving focus):
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<cv-tabs id="demo">
|
|
61
|
+
<div class="cv-tabs-tabs">
|
|
62
|
+
<div role="tablist" class="cv-tabs-list" aria-label="Sections">
|
|
63
|
+
<button
|
|
64
|
+
type="button"
|
|
65
|
+
role="tab"
|
|
66
|
+
id="t-a"
|
|
67
|
+
aria-selected="true"
|
|
68
|
+
aria-controls="p-a"
|
|
69
|
+
data-value="a"
|
|
70
|
+
>
|
|
71
|
+
A
|
|
72
|
+
</button>
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
role="tab"
|
|
76
|
+
id="t-b"
|
|
77
|
+
aria-selected="false"
|
|
78
|
+
aria-controls="p-b"
|
|
79
|
+
data-value="b"
|
|
80
|
+
>
|
|
81
|
+
B
|
|
82
|
+
</button>
|
|
83
|
+
</div>
|
|
84
|
+
<div role="tabpanel" id="p-a" aria-labelledby="t-a">A body</div>
|
|
85
|
+
<div role="tabpanel" id="p-b" aria-labelledby="t-b" hidden>B body</div>
|
|
86
|
+
</div>
|
|
87
|
+
</cv-tabs>
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Arrow, Home and End move focus and activate; `activation="manual"` makes arrows move focus only. The element
|
|
91
|
+
fires `cv-value-change` with `detail.value` (the tab's `data-value`, else its id). Every element's attributes
|
|
92
|
+
and events are listed in `custom-elements.json`.
|
|
93
|
+
|
|
94
|
+
## htmx glue
|
|
95
|
+
|
|
96
|
+
`import '@cascivo/elements/htmx'` runs `install()` once per document (no htmx import; it listens to DOM
|
|
97
|
+
events). It does only this:
|
|
98
|
+
|
|
99
|
+
- After `htmx:afterSettle`, if focus fell to `<body>`, it returns focus to the previously focused id, else the
|
|
100
|
+
first focusable element in the swap target, else the target, else `<main>`.
|
|
101
|
+
- `cv-dialog-close` (for example from `HX-Trigger`) closes the enclosing `<cv-dialog>`, or every open one.
|
|
102
|
+
- `cv-toast` (`HX-Trigger: {"cv-toast": [{"kind": "...", "message": "..."}]}`) calls `.add()` on the page's
|
|
103
|
+
`<cv-toaster>`; entries without a string `message` are ignored.
|
|
104
|
+
- When a global `Idiomorph` exists, the focused field keeps its typed value across a morph and a morph does
|
|
105
|
+
not strip an open `<dialog>`'s `open` attribute.
|
|
106
|
+
|
|
107
|
+
## Budget
|
|
108
|
+
|
|
109
|
+
Each element is at most 3 KB gzip and a page's cascivo JS (elements plus glue, htmx counted separately) at
|
|
110
|
+
most 15 KB; see [JavaScript budgets](../../docs/USING-CASCIVO-SERVER.md#javascript-budgets). Messages are
|
|
111
|
+
declared in `src/messages.ts` under the same keys as `@cascivo/i18n`'s `builtin`, so an adopter's
|
|
112
|
+
`defineCatalog` translates them without pulling the whole catalog in.
|
|
113
|
+
|
|
114
|
+
## Install
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
pnpm add @cascivo/elements
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
[cascivo.com](https://cascivo.com) · [Docs](https://cascivo.com/docs) · [Storybook](https://storybook.cascivo.com) · [GitHub](https://github.com/cascivo/cascivo) · AI agents: read [`llms.txt`](https://cascivo.com/llms.txt) (install steps + component index, plain text) or use [`@cascivo/mcp`](https://github.com/cascivo/cascivo/tree/main/packages/mcp) and [`registry.json`](https://github.com/cascivo/cascivo/blob/main/registry.json) · MIT
|
|
123
|
+
|
|
124
|
+
<div align="center"><a href="https://cascivo.com"><img src="https://cascivo.com/logo-mark-img.svg" width="28" height="28" alt="cascivo"></a></div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){return e}function t(e,t,n){return e.states[t]?.on?.[n]??t}var n=Symbol.for(`preact-signals`);function r(){if(l>1){l--;return}let e,t=!1;for((function(){let e=c;for(c=void 0;e!==void 0;)e.S.v===e.v&&(e.S.i=e.i),e=e.o})();o!==void 0;){let n=o;for(o=void 0,u++;n!==void 0;){let r=n.u;if(n.u=void 0,n.f&=-3,!(8&n.f)&&_(n))try{n.c()}catch(n){t||=(e=n,!0)}n=r}}if(u=0,l--,t)throw e}function i(e){if(l>0)return e();f=++d,l++;try{return e()}finally{r()}}var a,o;function s(e){let t=a;a=void 0;try{return e()}finally{a=t}}var c,l=0,u=0,d=0,f=0,p=0;function m(e){if(a===void 0)return;let t=e.n;if(t===void 0||t.t!==a)return t={i:0,S:e,p:a.s,n:void 0,t:a,e:void 0,x:void 0,r:t},a.s!==void 0&&(a.s.n=t),a.s=t,e.n=t,32&a.f&&e.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=a.s,t.n=void 0,a.s.n=t,a.s=t),t}function h(e,t){this.v=e,this.i=0,this.n=void 0,this.t=void 0,this.l=0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}h.prototype.brand=n,h.prototype.h=function(){return!0},h.prototype.S=function(e){let t=this.t;t!==e&&e.e===void 0&&(e.x=t,this.t=e,t===void 0?s(()=>{var e;(e=this.W)==null||e.call(this)}):t.e=e)},h.prototype.U=function(e){if(this.t!==void 0){let t=e.e,n=e.x;t!==void 0&&(t.x=n,e.e=void 0),n!==void 0&&(n.e=t,e.x=void 0),e===this.t&&(this.t=n,n===void 0&&s(()=>{var e;(e=this.Z)==null||e.call(this)}))}},h.prototype.subscribe=function(e){return T(()=>{let t=this.value;s(()=>e(t))},{name:`sub`})},h.prototype.valueOf=function(){return this.value},h.prototype.toString=function(){return this.value+``},h.prototype.toJSON=function(){return this.value},h.prototype.peek=function(){return s(()=>this.value)},Object.defineProperty(h.prototype,"value",{get(){let e=m(this);return e!==void 0&&(e.i=this.i),this.v},set(e){if(e!==this.v){if(u>100)throw Error(`Cycle detected`);(function(e){l!==0&&u===0&&e.l!==f&&(e.l=f,c={S:e,v:e.v,i:e.i,o:c})})(this),this.v=e,this.i++,p++,l++;try{for(let e=this.t;e!==void 0;e=e.x)e.t.N()}finally{r()}}}});function g(e,t){return new h(e,t)}function _(e){for(let t=e.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function v(e){for(let t=e.s;t!==void 0;t=t.n){let n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){e.s=t;break}}}function y(e){let t,n=e.s;for(;n!==void 0;){let e=n.p;n.i===-1?(n.S.U(n),e!==void 0&&(e.n=n.n),n.n!==void 0&&(n.n.p=e)):t=n,n.S.n=n.r,n.r!==void 0&&(n.r=void 0),n=e}e.s=t}function b(e,t){h.call(this,void 0,t),this.x=e,this.s=void 0,this.g=p-1,this.f=4}b.prototype=new h,b.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===p))return!0;if(this.g=p,this.f|=1,this.i>0&&!_(this))return this.f&=-2,!0;let e=a;try{v(this),a=this;let e=this.x();(16&this.f||this.v!==e||this.i===0)&&(this.v=e,this.f&=-17,this.i++)}catch(e){this.v=e,this.f|=16,this.i++}return a=e,y(this),this.f&=-2,!0},b.prototype.S=function(e){if(this.t===void 0){this.f|=36;for(let e=this.s;e!==void 0;e=e.n)e.S.S(e)}h.prototype.S.call(this,e)},b.prototype.U=function(e){if(this.t!==void 0&&(h.prototype.U.call(this,e),this.t===void 0)){this.f&=-33;for(let e=this.s;e!==void 0;e=e.n)e.S.U(e)}},b.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(let e=this.t;e!==void 0;e=e.x)e.t.N()}},Object.defineProperty(b.prototype,"value",{get(){if(1&this.f)throw Error(`Cycle detected`);let e=m(this);if(this.h(),e!==void 0&&(e.i=this.i),16&this.f)throw this.v;return this.v}});function x(e){let t=e.m;if(e.m=void 0,typeof t==`function`){l++;let n=a;a=void 0;try{t()}catch(t){throw e.f&=-2,e.f|=8,S(e),t}finally{a=n,r()}}}function S(e){for(let t=e.s;t!==void 0;t=t.n)t.S.U(t);e.x=void 0,e.s=void 0,x(e)}function C(e){if(a!==this)throw Error(`Out-of-order effect`);y(this),a=e,this.f&=-2,8&this.f&&S(this),r()}function w(e,t){this.x=e,this.m=void 0,this.s=void 0,this.u=void 0,this.f=32,this.name=t?.name}w.prototype.c=function(){let e=this.S();try{if(8&this.f||this.x===void 0)return;let e=this.x();typeof e==`function`&&(this.m=e)}finally{e()}},w.prototype.S=function(){if(1&this.f)throw Error(`Cycle detected`);this.f|=1,this.f&=-9,x(this),v(this),l++;let e=a;return a=this,C.bind(this,e)},w.prototype.N=function(){2&this.f||(this.f|=2,this.u=o,o=this)},w.prototype.d=function(){this.f|=8,1&this.f||S(this)},w.prototype.dispose=function(){this.d()};function T(e,t){let n=new w(e,t);try{n.c()}catch(e){throw n.d(),e}let r=n.d.bind(n);return r[Symbol.dispose]=r,r}var E=0;function D(e,t,n){e&&(n===null?e.hasAttribute(t)&&e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n))}var O=e=>e.target,k=class extends HTMLElement{uid=``;#e=[];connectedCallback(){this.uid||=this.id||`cv${++E}`;let e=new MutationObserver(()=>this.render());e.observe(this,{attributes:!0,childList:!0,subtree:!0}),this.#e=[T(()=>this.render()),()=>e.disconnect()]}disconnectedCallback(){for(let e of this.#e)e();this.#e=[]}emit(e,t){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:t}))}$(e){return this.querySelector(e)}$$(e){return Array.from(this.querySelectorAll(e))}},A=e({initial:`closed`,states:{closed:{on:{OPEN:`open`}},open:{on:{CLOSE:`closed`}}}}),j=class extends k{static formAssociated=!0;state=g(A.initial);current=g(void 0);internals;constructor(){super(),this.internals=this.attachInternals();for(let e of[`input`,`change`])this.addEventListener(e,e=>e.target!==this&&e.stopPropagation());this.addEventListener(`focusout`,e=>{this.contains(e.relatedTarget)||queueMicrotask(()=>!this.contains(document.activeElement)&&this.close(!1))})}connectedCallback(){this.uid||this.setValue(this.getAttribute(`value`)??``,!0),super.connectedCallback()}get value(){return this.current.value??``}set value(e){this.setValue(e,!0)}get name(){return this.getAttribute(`name`)}get form(){return this.internals.form}get isOpen(){return this.state.value===`open`}formResetCallback(){this.value=this.getAttribute(`value`)??``}send(e){this.state.value=t(A,this.state.peek(),e)}close(e=!0){this.send(`CLOSE`),e&&this.$(`[role="combobox"]`)?.focus()}setValue(e,t=!1){let n=e||void 0;this.current.value=n,this.internals.setFormValue(e),!t&&(this.emit(`cv-value-change`,{value:n}),this.dispatchEvent(new Event(`input`,{bubbles:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0})))}renderField(e,t,n,r,i,a){let o=this.hasAttribute(`disabled`)?``:null;for(let n of[e,a])D(n,`aria-controls`,t),D(n,`aria-expanded`,String(this.isOpen)),D(n,`disabled`,o);D(e,`placeholder`,this.getAttribute(`placeholder`)??r),D(e,`aria-required`,this.hasAttribute(`required`)?`true`:null),D(this.$(`[class$="-wrapper"]`),`data-state`,this.isOpen?`open`:`closed`),D(e,`value`,n),e.value!==n&&(e.value=n),this.hasAttribute(`required`)&&this.current.value===void 0?this.internals.setValidity({valueMissing:!0},i,e):this.internals.setValidity({})}};function M(e,t){customElements.get(e)||customElements.define(e,t)}export{O as a,e as c,D as i,t as l,j as n,i as o,M as r,g as s,k as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,s as t,t as n}from"./base-B5z3ufCR.js";import{i as r,o as i}from"./messages-Bhd7waiI.js";var a=class extends n{static formAssociated=!0;values=t([]);internals=this.attachInternals();#e;constructor(){super();for(let e of[`input`,`change`])this.addEventListener(e,e=>e.target!==this&&e.stopPropagation())}connectedCallback(){this.#e??=this.values.value=this.initial(),super.connectedCallback()}get value(){return this.values.value}set value(e){this.commit(e,!0)}get name(){return this.getAttribute(`name`)}get form(){return this.internals.form}formResetCallback(){this.commit(this.#e??[],!0)}commit(e,t=!1){this.values.value=e,!t&&(this.emit(`cv-value-change`,{value:e}),this.dispatchEvent(new Event(`input`,{bubbles:!0})),this.dispatchEvent(new Event(`change`,{bubbles:!0})))}sync(e){let t=this.getAttribute(`name`),n=this.values.value,a=null;if(t){a=new FormData;for(let e of n)a.append(t,e)}this.internals.setFormValue(a),this.hasAttribute(`required`)&&!n.length?this.internals.setValidity({valueMissing:!0},i(r.valueMissing),e??void 0):this.internals.setValidity({})}},o=(e,t)=>{let n=document.createElement(e);return n.className=t,n};function s(t,n,r,i){let a=[...t.children].filter(e=>e.classList.contains(i.chip)),s=r.map(([e])=>a.find(t=>t.dataset.value===e));a.forEach(e=>s.includes(e)||e.remove());let c=s.find(Boolean)??n;r.forEach(([n,r],a)=>{let l=s[a];if(!l){l=o(`span`,i.chip),l.dataset.value=n;let e=o(`button`,i.remove);if(e.setAttribute(`type`,`button`),i.glyph){let t=o(`span`,``);t.setAttribute(`aria-hidden`,`true`),t.textContent=i.glyph,e.append(t)}l.append(i.label?o(`span`,i.label):``,e)}let u=i.label?l.firstElementChild:l.firstChild;u.textContent!==r&&(u.textContent=r);let d=l.lastElementChild;e(d,`aria-label`,i.text.replace(`{label}`,r)),e(d,`disabled`,i.off?``:null),l===c?c=l.nextElementSibling:t.insertBefore(l,c)})}export{s as n,a as t};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
declare const BRAND_SYMBOL: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* The base class for plain and computed signals.
|
|
4
|
+
*/
|
|
5
|
+
declare class Signal<T = any> {
|
|
6
|
+
constructor(value?: T, options?: SignalOptions<T>);
|
|
7
|
+
subscribe(fn: (value: T) => void): () => void;
|
|
8
|
+
name?: string;
|
|
9
|
+
valueOf(): T;
|
|
10
|
+
toString(): string;
|
|
11
|
+
toJSON(): T;
|
|
12
|
+
peek(): T;
|
|
13
|
+
brand: typeof BRAND_SYMBOL;
|
|
14
|
+
get value(): T;
|
|
15
|
+
set value(value: T);
|
|
16
|
+
}
|
|
17
|
+
interface SignalOptions<T = any> {
|
|
18
|
+
watched?: (this: Signal<T>) => void;
|
|
19
|
+
unwatched?: (this: Signal<T>) => void;
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Light-DOM base: state lives in signals on the instance; `render()` projects it onto
|
|
24
|
+
* whatever markup is currently inside the element. It reruns on every signal change (effect)
|
|
25
|
+
* and on every DOM change (MutationObserver), so an htmx/idiomorph morph that resets
|
|
26
|
+
* attributes or replaces children is repaired on the next microtask and the element keeps
|
|
27
|
+
* its state, provided it keeps its `id` (idiomorph then reuses the node).
|
|
28
|
+
*/
|
|
29
|
+
declare abstract class CvElement extends HTMLElement {
|
|
30
|
+
#private;
|
|
31
|
+
protected uid: string;
|
|
32
|
+
connectedCallback(): void;
|
|
33
|
+
disconnectedCallback(): void;
|
|
34
|
+
protected abstract render(): void;
|
|
35
|
+
protected emit(type: string, detail?: unknown): void;
|
|
36
|
+
protected $<T extends Element = HTMLElement>(selector: string): T | null;
|
|
37
|
+
protected $$<T extends Element = HTMLElement>(selector: string): T[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Shared by the two form-associated elements: popup FSM, value property, form value,
|
|
41
|
+
* events, reset and dismissal. The `value` attribute is the initial value (like
|
|
42
|
+
* `<input value>`); the live value is the `value` property, so a morph that rewrites the
|
|
43
|
+
* attribute does not clobber what the user picked.
|
|
44
|
+
*/
|
|
45
|
+
declare abstract class CvFormElement extends CvElement {
|
|
46
|
+
static formAssociated: boolean;
|
|
47
|
+
readonly state: Signal<"closed" | "open">;
|
|
48
|
+
readonly current: Signal<string | undefined>;
|
|
49
|
+
protected internals: ElementInternals;
|
|
50
|
+
constructor();
|
|
51
|
+
connectedCallback(): void;
|
|
52
|
+
get value(): string;
|
|
53
|
+
set value(v: string);
|
|
54
|
+
get name(): string | null;
|
|
55
|
+
get form(): HTMLFormElement | null;
|
|
56
|
+
get isOpen(): boolean;
|
|
57
|
+
formResetCallback(): void;
|
|
58
|
+
protected send(event: 'OPEN' | 'CLOSE'): void;
|
|
59
|
+
protected close(focus?: boolean): void;
|
|
60
|
+
/** Set the value; unless `quiet`, fire `cv-value-change` + native `input`/`change`. */
|
|
61
|
+
protected setValue(v: string, quiet?: boolean): void;
|
|
62
|
+
/**
|
|
63
|
+
* The parts both fields share: ARIA wiring and disabled (on the input and an optional
|
|
64
|
+
* popup button), the visible text, validity.
|
|
65
|
+
*/
|
|
66
|
+
protected renderField(input: HTMLInputElement, controls: string, text: string, placeholder: string, valueMissing: string, button?: Element | null): void;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* `<cv-combobox>`: the editable (searchable) `Combobox`, form-associated. Options are the
|
|
70
|
+
* `[role="option"][data-value]` rows already in the markup; typing filters them (`hidden`).
|
|
71
|
+
* Keyboard per the APG editable combobox with list autocomplete.
|
|
72
|
+
*/
|
|
73
|
+
export declare class CvCombobox extends CvFormElement {
|
|
74
|
+
#private;
|
|
75
|
+
readonly query: Signal<string>;
|
|
76
|
+
/** Index into `#options()` (all rows, DOM order); -1 for none. */
|
|
77
|
+
readonly active: Signal<number>;
|
|
78
|
+
constructor();
|
|
79
|
+
protected close(focus?: boolean): void;
|
|
80
|
+
protected render(): void;
|
|
81
|
+
}
|
|
82
|
+
export declare function define(): void;
|
package/dist/combobox.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,n,o as r,r as i,s as a}from"./base-B5z3ufCR.js";import{i as o,n as s,o as c}from"./messages-Bhd7waiI.js";var l=class extends n{query=a(``);active=a(-1);constructor(){super(),this.addEventListener(`keydown`,e=>this.#o(e)),this.addEventListener(`input`,t=>{let n=e(t);n instanceof HTMLInputElement&&r(()=>{this.query.value=n.value,this.send(`OPEN`),this.active.value=this.#n()[0]??-1})}),this.addEventListener(`mousedown`,t=>{e(t).closest(`[role="option"]`)&&t.preventDefault()}),this.addEventListener(`click`,t=>{let n=e(t),r=n.closest(`[role="option"]`);if(r)return this.#i(this.#e().indexOf(r));n.closest(`[role="combobox"]`)&&!this.isOpen&&this.#r()})}#e(){return this.$$(`[role="option"]`)}#t(e){return!!e&&e.getAttribute(`aria-disabled`)!==`true`}#n(){let e=this.query.peek().trim().toLowerCase();return this.#e().flatMap((t,n)=>this.#t(t)&&(t.textContent??``).toLowerCase().includes(e)?[n]:[])}#r(e=!1){if(this.hasAttribute(`disabled`))return;let t=this.#n(),n=this.#e().findIndex(e=>e.dataset.value===this.current.peek());r(()=>{this.active.value=t.includes(n)?n:(e?t.at(-1):t[0])??-1,this.send(`OPEN`)})}close(e=!0){r(()=>{this.query.value=``,this.active.value=-1,super.close(e)})}#i(e){let t=this.#e()[e];if(!this.#t(t))return;let n=t.dataset.value??``;this.close(),n!==this.value&&this.setValue(n)}#a(e){let t=this.#n();if(t.length===0)return;let n=t.indexOf(this.active.peek()),r=n===-1?e>0?0:-1:n+e;this.active.value=t.at(r%t.length)??-1}#o(t){if(!e(t).closest(`[role="combobox"]`)||this.hasAttribute(`disabled`))return;let n=this.isOpen,r=t.altKey?`Alt${t.key}`:t.key;switch(r){case`AltArrowDown`:t.preventDefault(),n||this.#r();return;case`AltArrowUp`:t.preventDefault(),n&&this.close();return;case`ArrowDown`:case`ArrowUp`:t.preventDefault(),n?this.#a(r===`ArrowDown`?1:-1):this.#r(r===`ArrowUp`);return;case`Enter`:if(!n)return;t.preventDefault(),this.active.peek()>=0&&this.#i(this.active.peek());return;case`Escape`:if(!n)return;t.preventDefault(),t.stopPropagation(),this.close();return;case`Tab`:n&&this.close(!1)}}render(){let e=this.$(`[role="combobox"]`),n=this.$(`[role="listbox"]`);if(!e||!n)return;let r=this.isOpen,i=this.query.value.trim().toLowerCase(),a=this.active.value,l=this.current.value,u=this.#e(),d=n.id||`${this.uid}-listbox`,f=0,p=``;u.forEach((e,n)=>{let r=e.textContent?.trim()??``,o=r.toLowerCase().includes(i);o&&f++,e.dataset.value===l&&(p=r),t(e,`id`,e.id||`${this.uid}-option-${n}`),t(e,`aria-selected`,String(e.dataset.value===l)),t(e,`data-state`,n===a?`active`:null),t(e,`hidden`,o?null:``)});let m=r?u[a]:void 0;m?.scrollIntoView?.({block:`nearest`}),t(n,`id`,d),!n.hasAttribute(`aria-label`)&&!n.hasAttribute(`aria-labelledby`)&&t(n,`aria-labelledby`,this.$(`label`)?.id||null),t(e,`aria-activedescendant`,m?.id??null);let h=r?this.query.value:p;this.renderField(e,d,h,c(s.placeholder),c(o.valueMissing)),t(this.$(`.cv-combobox-popup`),`data-state`,r?`open`:`closed`);let g=this.$(`.cv-combobox-empty`);t(g,`hidden`,f===0?null:``),g&&g.textContent!==c(s.empty)&&(g.textContent=c(s.empty));let _=this.$(`[aria-live]`),v=r?c(s.resultCount,{count:String(f)}):``;_&&_.textContent!==v&&(_.textContent=v)}};function u(){i(`cv-combobox`,l)}export{l as CvCombobox,u as define};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
declare const BRAND_SYMBOL: unique symbol;
|
|
2
|
+
/**
|
|
3
|
+
* The base class for plain and computed signals.
|
|
4
|
+
*/
|
|
5
|
+
declare class Signal<T = any> {
|
|
6
|
+
constructor(value?: T, options?: SignalOptions<T>);
|
|
7
|
+
subscribe(fn: (value: T) => void): () => void;
|
|
8
|
+
name?: string;
|
|
9
|
+
valueOf(): T;
|
|
10
|
+
toString(): string;
|
|
11
|
+
toJSON(): T;
|
|
12
|
+
peek(): T;
|
|
13
|
+
brand: typeof BRAND_SYMBOL;
|
|
14
|
+
get value(): T;
|
|
15
|
+
set value(value: T);
|
|
16
|
+
}
|
|
17
|
+
interface SignalOptions<T = any> {
|
|
18
|
+
watched?: (this: Signal<T>) => void;
|
|
19
|
+
unwatched?: (this: Signal<T>) => void;
|
|
20
|
+
name?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Light-DOM base: state lives in signals on the instance; `render()` projects it onto
|
|
24
|
+
* whatever markup is currently inside the element. It reruns on every signal change (effect)
|
|
25
|
+
* and on every DOM change (MutationObserver), so an htmx/idiomorph morph that resets
|
|
26
|
+
* attributes or replaces children is repaired on the next microtask and the element keeps
|
|
27
|
+
* its state, provided it keeps its `id` (idiomorph then reuses the node).
|
|
28
|
+
*/
|
|
29
|
+
declare abstract class CvElement extends HTMLElement {
|
|
30
|
+
#private;
|
|
31
|
+
protected uid: string;
|
|
32
|
+
connectedCallback(): void;
|
|
33
|
+
disconnectedCallback(): void;
|
|
34
|
+
protected abstract render(): void;
|
|
35
|
+
protected emit(type: string, detail?: unknown): void;
|
|
36
|
+
protected $<T extends Element = HTMLElement>(selector: string): T | null;
|
|
37
|
+
protected $$<T extends Element = HTMLElement>(selector: string): T[];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `<cv-command-menu>`: enhances the markup `CommandMenu` renders (a `<dialog>` holding an
|
|
41
|
+
* `input[role=combobox]`, a `[role=listbox]` of `[role=option]` rows and optionally an
|
|
42
|
+
* `.cv-command-menu-empty` / `[data-cv-command-empty]` element). Opens on `shortcut` (default
|
|
43
|
+
* `mod+k`) or `[data-cv-command-open]`; the input filters rows (`data-search`, else their text)
|
|
44
|
+
* by hiding them; focus stays in the input and the active row is `aria-activedescendant`.
|
|
45
|
+
* Enter clicks the active row, so an anchor or `hx-get` row works natively; every activation
|
|
46
|
+
* also fires `cv-select` (`detail.value` = `data-value`, else its text) and closes.
|
|
47
|
+
* Fires `cv-open` / `cv-close`.
|
|
48
|
+
*/
|
|
49
|
+
export declare class CvCommandMenu extends CvElement {
|
|
50
|
+
#private;
|
|
51
|
+
readonly state: Signal<boolean>;
|
|
52
|
+
readonly query: Signal<string>;
|
|
53
|
+
readonly active: Signal<number>;
|
|
54
|
+
constructor();
|
|
55
|
+
get open(): boolean;
|
|
56
|
+
show(): void;
|
|
57
|
+
close(): void;
|
|
58
|
+
connectedCallback(): void;
|
|
59
|
+
disconnectedCallback(): void;
|
|
60
|
+
protected render(): void;
|
|
61
|
+
}
|
|
62
|
+
export declare function define(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,r as n,s as r,t as i}from"./base-B5z3ufCR.js";var a=`[role="option"]`,o=`[data-cv-command-open]`,s=e=>e.getAttribute(`aria-disabled`)===`true`;function c(e,t){let n=e.toLowerCase().split(`+`),r=n.pop(),i=e=>n.includes(e);return t.key.toLowerCase()===r&&(i(`mod`)?t.metaKey||t.ctrlKey:t.metaKey===i(`meta`)&&t.ctrlKey===i(`ctrl`))&&t.shiftKey===i(`shift`)&&t.altKey===i(`alt`)}var l=class extends i{state=r(!1);query=r(``);active=r(0);#e;constructor(){super(),this.addEventListener(`input`,t=>{this.query.value=e(t).value,this.active.value=0}),this.addEventListener(`click`,t=>{let n=e(t),r=n.closest(a);r&&!s(r)?(this.emit(`cv-select`,{value:r.dataset.value??r.textContent?.trim()??``}),this.close()):n.localName===`dialog`&&this.close()}),this.addEventListener(`mouseover`,t=>{let n=e(t).closest(a),r=n?this.#r().indexOf(n):-1;r>=0&&(this.active.value=r)}),this.addEventListener(`keydown`,e=>{let t=this.#r(),n=this.active.peek(),r=n=>{e.preventDefault(),this.active.value=t.length?(n+t.length)%t.length:0};e.key===`ArrowDown`?r(n+1):e.key===`ArrowUp`?r(n-1):e.key===`Home`?r(0):e.key===`End`?r(-1):e.key===`Enter`&&t[n]?(e.preventDefault(),t[n].click()):e.key===`Escape`&&(e.preventDefault(),this.close())}),this.addEventListener(`close`,()=>this.#t(),!0),this.addEventListener(`cancel`,()=>this.#t(),!0)}get open(){return this.state.value}show(){if(this.state.peek())return;let e=this.$(`input`);e&&(e.value=``),this.query.value=``,this.active.value=0,this.state.value=!0,this.emit(`cv-open`)}close(){this.#t()}#t(){return this.state.peek()?(this.state.value=!1,this.emit(`cv-close`),!0):!1}connectedCallback(){super.connectedCallback(),this.#e?.();let t=e=>{c(this.getAttribute(`shortcut`)??`mod+k`,e)&&(e.preventDefault(),this.state.peek()?this.close():this.show())},n=t=>{e(t).closest(o)&&this.show()};document.addEventListener(`keydown`,t),document.addEventListener(`click`,n),this.#e=()=>{document.removeEventListener(`keydown`,t),document.removeEventListener(`click`,n)}}disconnectedCallback(){super.disconnectedCallback(),this.#e?.(),this.#e=void 0}#n(e){let t=(e.dataset.search??e.textContent??``).toLowerCase();return this.query.value.toLowerCase().split(/\s+/).filter(Boolean).every(e=>t.includes(e))}#r(){return this.$$(a).filter(e=>!s(e)&&this.#n(e))}render(){let e=this.$(`dialog`),n=this.$(`input`);if(!e||!n)return;let r=this.state.value,i=this.#r(),o=i[Math.min(this.active.value,i.length-1)],s=this.$$(a);s.forEach((e,n)=>{t(e,`id`,e.id||`${this.uid}-o${n}`),t(e,`hidden`,this.#n(e)?null:``),t(e,`aria-selected`,String(e===o))});let c=this.$(`[role="listbox"]`);t(n,`role`,`combobox`),t(n,`aria-autocomplete`,`list`),t(n,`aria-expanded`,String(r)),t(n,`aria-controls`,c?.id||null),t(n,`aria-activedescendant`,o?.id??null),t(this.$(`[data-cv-command-empty], [class$="-empty"]`),`hidden`,s.some(e=>this.#n(e))?``:null),r!==e.open&&(r?typeof e.showModal==`function`?e.showModal():e.setAttribute(`open`,``):typeof e.close==`function`?e.close():e.removeAttribute(`open`),r&&n.focus())}};function u(){n(`cv-command-menu`,l)}export{l as CvCommandMenu,u as define};
|