@cascivo/elements 0.0.0-stage → 0.0.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
|
@@ -0,0 +1,80 @@
|
|
|
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 `cv-multi-select` and `cv-tags-input`: a form-associated element whose value is a
|
|
41
|
+
* list. It does not extend `CvFormElement` because that holds one string; here the form value
|
|
42
|
+
* is a `FormData` with one entry per item, so a plain `<form>` submits `name=a&name=b`.
|
|
43
|
+
*/
|
|
44
|
+
declare abstract class CvChips extends CvElement {
|
|
45
|
+
#private;
|
|
46
|
+
static formAssociated: boolean;
|
|
47
|
+
readonly values: Signal<string[]>;
|
|
48
|
+
protected internals: ElementInternals;
|
|
49
|
+
constructor();
|
|
50
|
+
/** The value the server rendered; also what a form reset restores. */
|
|
51
|
+
protected abstract initial(): string[];
|
|
52
|
+
connectedCallback(): void;
|
|
53
|
+
get value(): string[];
|
|
54
|
+
set value(v: string[]);
|
|
55
|
+
get name(): string | null;
|
|
56
|
+
get form(): HTMLFormElement | null;
|
|
57
|
+
formResetCallback(): void;
|
|
58
|
+
/** Replace the value; unless `quiet`, fire `cv-value-change` + native `input`/`change`. */
|
|
59
|
+
protected commit(v: string[], quiet?: boolean): void;
|
|
60
|
+
/** Project the value onto the form (`name` entries) and `required` validity. */
|
|
61
|
+
protected sync(anchor: HTMLElement | null | undefined): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `<cv-multi-select>`: the `MultiSelect` markup (chips + trigger + `popover` panel with a
|
|
65
|
+
* search box and a `[role=listbox][aria-multiselectable]` of `[role=option]` rows, `data-value`
|
|
66
|
+
* else text), form-associated: submits one `name` entry per value. Attributes: `name`,
|
|
67
|
+
* `required`, `disabled`, `placeholder`, `selected-label` (`{count} selected`), `remove-label`
|
|
68
|
+
* (`Remove {label}`). Typing filters, Backspace on an empty search drops the last chip.
|
|
69
|
+
*/
|
|
70
|
+
export declare class CvMultiSelect extends CvChips {
|
|
71
|
+
#private;
|
|
72
|
+
readonly open: Signal<boolean>;
|
|
73
|
+
readonly query: Signal<string>;
|
|
74
|
+
/** Index into the rows (DOM order); -1 for none. */
|
|
75
|
+
readonly active: Signal<number>;
|
|
76
|
+
constructor();
|
|
77
|
+
protected initial(): string[];
|
|
78
|
+
protected render(): void;
|
|
79
|
+
}
|
|
80
|
+
export declare function define(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,o as n,r,s as i}from"./base-B5z3ufCR.js";import{n as a,t as o}from"./chips-Cg27QTfm.js";var s=`.cv-multi-select-`,c=`[role="option"]`,l=class extends o{open=i(!1);query=i(``);active=i(-1);#e;constructor(){super(),this.addEventListener(`pointerdown`,t=>{e(t).closest(`${s}trigger`)&&(this.#e=this.open.peek())}),this.addEventListener(`click`,t=>{let n=e(t),r=n.closest(c),i=n.closest(`${s}chip-remove`)?.parentElement;if(!this.hasAttribute(`disabled`)){if(i)this.commit(this.values.peek().filter(e=>e!==i.dataset.value));else if(n.closest(`${s}clear`))this.commit([]);else if(n.closest(`${s}select-all`)){let e=this.#t().filter(e=>this.#r(e)).map(e=>this.#n(e));this.commit(e.every(e=>this.values.peek().includes(e))?[]:e)}else if(r)this.#a(r);else if(n.closest(`${s}trigger`)){let e=!(this.#e??this.open.peek());this.#e=void 0,e?this.#o():this.#s()}}}),this.addEventListener(`input`,t=>{let r=e(t);r.matches(`${s}search`)&&n(()=>{this.query.value=r.value,this.active.value=this.#i()[0]??-1})}),this.addEventListener(`mousedown`,t=>e(t).closest(c)&&t.preventDefault()),this.addEventListener(`toggle`,e=>e.newState===`closed`&&this.#s(!1),!0),this.addEventListener(`keydown`,e=>this.#c(e))}initial(){return this.#t().filter(e=>e.getAttribute(`aria-selected`)===`true`).map(e=>this.#n(e))}#t(){return this.$$(c)}#n(e){return e.dataset.value??e.textContent?.trim()??``}#r(e){return!!e&&e.getAttribute(`aria-disabled`)!==`true`}#i(){let e=this.query.peek().trim().toLowerCase();return this.#t().flatMap((t,n)=>this.#r(t)&&(t.textContent??``).toLowerCase().includes(e)?[n]:[])}#a(e){if(!this.#r(e))return;let t=this.#n(e),n=this.values.peek();this.commit(n.includes(t)?n.filter(e=>e!==t):[...n,t])}#o(){this.hasAttribute(`disabled`)||(n(()=>{this.active.value=this.#i()[0]??-1,this.open.value=!0}),queueMicrotask(()=>(this.$(`${s}search`)??this.$(`[role="listbox"]`))?.focus()))}#s(e=!0){n(()=>{this.open.value=!1,this.query.value=``,this.active.value=-1}),e&&this.$(`${s}trigger`)?.focus()}#c(t){let n=e(t),r=this.$(`${s}field`)?.dataset.display===`chips`,i=n instanceof HTMLInputElement&&n.value!==``;if(t.key===`Backspace`){let e=this.values.peek();if(r&&!i&&e.length&&!this.hasAttribute(`disabled`)){if(!n.closest(`${s}trigger, ${s}search`))return;t.preventDefault(),this.commit(e.slice(0,-1))}}else if(n.closest(`${s}trigger`))(t.key===`ArrowDown`||t.key===`ArrowUp`)&&(t.preventDefault(),this.#o());else if(n.closest(`${s}panel`)&&this.open.peek()){let e=this.#i(),r=e.indexOf(this.active.peek()),i=n=>{t.preventDefault(),this.active.value=e.at(n%(e.length||1))??-1},a=this.#t()[this.active.peek()];switch(t.key){case`ArrowDown`:return i(r+1);case`ArrowUp`:return i(r<0?-1:r-1);case`Home`:return i(0);case`End`:return i(-1);case`Enter`:return n.matches(`${s}select-all`)?void 0:(t.preventDefault(),this.#a(a));case` `:return n.matches(`input`)||!a?void 0:(t.preventDefault(),this.#a(a));case`Escape`:return t.preventDefault(),t.stopPropagation(),this.#s();case`Tab`:return this.#s(!1)}}}render(){let e=this.$(`${s}trigger`),n=this.$(`${s}panel`),r=this.$(`[role="listbox"]`);if(!e||!n||!r)return;let i=this.hasAttribute(`disabled`),o=this.open.value&&!i,c=this.query.value.trim().toLowerCase(),l=this.active.value,u=this.values.value,d=this.#t(),f=this.$(`${s}search`),p=0,m={};d.forEach((e,n)=>{let r=e.textContent?.trim()??``,i=this.#n(e),a=r.toLowerCase().includes(c);p+=+a,m[i]=r,t(e,`id`,e.id||`${this.uid}-option-${n}`),t(e,`aria-selected`,String(u.includes(i))),t(e,`data-selected`,u.includes(i)?``:null),t(e,`data-active`,o&&n===l?``:null),t(e,`hidden`,a?null:``)});let h=n.id||`${this.uid}-panel`,g=r.id||`${this.uid}-listbox`,_=`--${this.uid}-anchor`;t(n,`id`,h),t(n,`popover`,`auto`),t(n,`data-state`,o?`open`:`closed`),t(r,`id`,g),t(r,`aria-multiselectable`,`true`),t(e,`aria-haspopup`,`listbox`),t(e,`aria-controls`,h),t(e,`aria-expanded`,String(o)),t(e,`disabled`,i?``:null),t(f??r,`aria-activedescendant`,o&&d[l]?.id||null),f&&(t(f,`aria-expanded`,String(o)),t(f,`aria-controls`,g),t(f,`aria-autocomplete`,`list`),f.value!==this.query.value&&(f.value=this.query.value));let v=this.$(`${s}wrapper`);v?.dataset.state!==`error`&&t(v,`data-state`,o?`open`:`closed`),e.style.getPropertyValue(`anchor-name`)!==_&&(e.style.setProperty(`anchor-name`,_),n.style.setProperty(`position-anchor`,_)),t(this.$(`${s}status`),`hidden`,p?``:null);let y=d.filter(e=>this.#r(e));t(this.$(`${s}select-all`),`aria-pressed`,String(y.length>0&&y.every(e=>u.includes(this.#n(e)))));let b=this.$(`${s}clear`);t(b,`hidden`,u.length?null:``),t(b,`disabled`,i?``:null);let x=this.$(`${s}field`),S=x?.dataset.display===`chips`;x&&S&&a(x,e,u.map(e=>[e,m[e]??e]),{chip:`cv-multi-select-chip`,label:`cv-multi-select-chip-label`,remove:`cv-multi-select-chip-remove`,text:this.getAttribute(`remove-label`)??`Remove {label}`,off:i});let C=this.$(`${s}trigger-label`),w=u.length?(this.getAttribute(`selected-label`)??`{count} selected`).replace(`{count}`,String(u.length)):this.getAttribute(`placeholder`)??`Select options`,T=S&&u.length&&C?.querySelector(`${s}sr-only`)||C;T&&T.textContent!==w&&(T.textContent=w),this.sync(e),typeof n.showPopover==`function`&&n.matches(`:popover-open`)!==o&&(o?n.showPopover():n.hidePopover())}};function u(){r(`cv-multi-select`,l)}export{l as CvMultiSelect,u as define};
|
package/dist/tabs.d.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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-tabs>`: enhances the markup `Tabs` renders (a `[role="tablist"]` of `[role="tab"]`
|
|
41
|
+
* controlling `[role="tabpanel"]` rows). Arrow/Home/End roving focus (APG); the arrow keys
|
|
42
|
+
* activate too unless `activation="manual"`. Fires `cv-value-change` (`detail.value` = the
|
|
43
|
+
* tab's `data-value`, else its id).
|
|
44
|
+
*/
|
|
45
|
+
export declare class CvTabs extends CvElement {
|
|
46
|
+
#private;
|
|
47
|
+
readonly current: Signal<string | undefined>;
|
|
48
|
+
constructor();
|
|
49
|
+
protected render(): void;
|
|
50
|
+
}
|
|
51
|
+
export declare function define(): void;
|
package/dist/tabs.js
ADDED
|
@@ -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="tab"]`,o=`${a}:not([disabled]):not([aria-disabled="true"])`,s=e=>e.dataset.value??e.id,c=class extends i{current=r(void 0);constructor(){super(),this.addEventListener(`click`,t=>{let n=e(t).closest(o);n&&this.#e(n)&&this.#n(n)}),this.addEventListener(`keydown`,t=>{let n=this.#t(o),r=n.indexOf(e(t)),i=getComputedStyle(this).direction===`rtl`?-1:1,a={ArrowRight:r+i,ArrowLeft:r-i,Home:0,End:-1}[t.key],s=n[((a??0)+n.length)%n.length];r<0||a===void 0||!s||(t.preventDefault(),s.focus(),this.getAttribute(`activation`)!==`manual`&&this.#n(s))})}#e(e){return e.closest(`cv-tabs`)===this}#t(e){return this.$$(e).filter(e=>this.#e(e))}#n(e){e.getAttribute(`aria-selected`)!==`true`&&(this.current.value=s(e),this.emit(`cv-value-change`,{value:this.current.value}))}render(){let e=this.#t(a),n=this.current.value,r=e.find(e=>s(e)===n)??e.find(e=>e.getAttribute(`aria-selected`)===`true`)??e[0],i=this.#t(`[role="tabpanel"]`);for(let n of e){let e=n===r?`active`:`inactive`;t(n,`aria-selected`,String(n===r)),t(n,`data-state`,e),t(n,`tabindex`,n===r?`0`:`-1`);let a=i.find(e=>e.id===n.getAttribute(`aria-controls`));t(a,`data-state`,e),t(a,`hidden`,n===r?null:``)}}};function l(){n(`cv-tabs`,c)}export{c as CvTabs,l as define};
|
|
@@ -0,0 +1,77 @@
|
|
|
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 `cv-multi-select` and `cv-tags-input`: a form-associated element whose value is a
|
|
41
|
+
* list. It does not extend `CvFormElement` because that holds one string; here the form value
|
|
42
|
+
* is a `FormData` with one entry per item, so a plain `<form>` submits `name=a&name=b`.
|
|
43
|
+
*/
|
|
44
|
+
declare abstract class CvChips extends CvElement {
|
|
45
|
+
#private;
|
|
46
|
+
static formAssociated: boolean;
|
|
47
|
+
readonly values: Signal<string[]>;
|
|
48
|
+
protected internals: ElementInternals;
|
|
49
|
+
constructor();
|
|
50
|
+
/** The value the server rendered; also what a form reset restores. */
|
|
51
|
+
protected abstract initial(): string[];
|
|
52
|
+
connectedCallback(): void;
|
|
53
|
+
get value(): string[];
|
|
54
|
+
set value(v: string[]);
|
|
55
|
+
get name(): string | null;
|
|
56
|
+
get form(): HTMLFormElement | null;
|
|
57
|
+
formResetCallback(): void;
|
|
58
|
+
/** Replace the value; unless `quiet`, fire `cv-value-change` + native `input`/`change`. */
|
|
59
|
+
protected commit(v: string[], quiet?: boolean): void;
|
|
60
|
+
/** Project the value onto the form (`name` entries) and `required` validity. */
|
|
61
|
+
protected sync(anchor: HTMLElement | null | undefined): void;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `<cv-tags-input>`: the `TagsInput` markup (a `.cv-tags-input-wrapper` of
|
|
65
|
+
* `.cv-tags-input-tag` spans and one `<input>`), form-associated: submits one `name` entry
|
|
66
|
+
* per tag. Enter or comma adds, Backspace on an empty field removes the last tag, a paste
|
|
67
|
+
* with separators (comma, semicolon, newline, tab) adds each piece, blur adds the pending
|
|
68
|
+
* text. Attributes: `name`, `required`, `disabled`, `max`, `placeholder` (shown while there
|
|
69
|
+
* are no tags), `remove-label` (`Remove {label}`).
|
|
70
|
+
*/
|
|
71
|
+
export declare class CvTagsInput extends CvChips {
|
|
72
|
+
#private;
|
|
73
|
+
constructor();
|
|
74
|
+
protected initial(): string[];
|
|
75
|
+
protected render(): void;
|
|
76
|
+
}
|
|
77
|
+
export declare function define(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,r as n}from"./base-B5z3ufCR.js";import{n as r,t as i}from"./chips-Cg27QTfm.js";var a=`cv-tags-input-tag`,o=`cv-tags-input-dismiss`,s=class extends i{constructor(){super(),this.addEventListener(`click`,t=>{let n=e(t),r=n.closest(`.${o}`)?.parentElement;this.hasAttribute(`disabled`)||(r&&this.commit(this.values.peek().filter(e=>e!==r.dataset.value)),n.closest(`input`)||this.#e()?.focus())}),this.addEventListener(`keydown`,e=>{let t=this.#e();e.target===t&&t&&(e.key===`Enter`||e.key===`,`?(e.preventDefault(),this.#t([t.value])):e.key===`Backspace`&&!t.value&&this.commit(this.values.peek().slice(0,-1)))}),this.addEventListener(`paste`,e=>{let t=e.clipboardData?.getData(`text`)??``;e.target===this.#e()&&/[,;\n\t]/.test(t)&&(e.preventDefault(),this.#t(t.split(/[,;\n\t]/)))}),this.addEventListener(`focusout`,e=>{let t=this.#e();e.target===t&&t?.value&&this.#t([t.value])})}initial(){return this.$$(`.${a}`).map(e=>e.dataset.value??e.firstChild?.textContent?.trim()??``)}#e(){return this.$(`input`)}#t(e){let t=this.#e();t&&(t.value=``);let n=Number(this.getAttribute(`max`)??1/0),r=[...this.values.peek()];for(let t of e){let e=t.trim();e&&!r.includes(e)&&r.length<n&&r.push(e)}r.length!==this.values.peek().length&&this.commit(r)}render(){let e=this.#e();if(!e)return;let n=this.hasAttribute(`disabled`),i=this.values.value;t(e,`disabled`,n?``:null),t(e,`aria-required`,this.hasAttribute(`required`)?`true`:null);let s=this.getAttribute(`placeholder`);s!==null&&t(e,`placeholder`,i.length?null:s);let c=e.parentElement;c&&(t(c,`data-disabled`,n?``:null),r(c,e,i.map(e=>[e,e]),{chip:a,remove:o,glyph:`×`,text:this.getAttribute(`remove-label`)??`Remove {label}`,off:n})),this.sync(e)}};function c(){n(`cv-tags-input`,s)}export{s as CvTagsInput,c as define};
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
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-theme>`: runtime theme (or density) switcher around a `<select>` or a set of
|
|
41
|
+
* `[data-cv-theme-value]` buttons (`aria-pressed` marks the current one). Writes the choice to
|
|
42
|
+
* an attribute on `<html>` (`attribute`, default `data-theme`, the one every theme CSS and the
|
|
43
|
+
* no-flash `theme_script()` use) and persists it to `localStorage` (`storage-key`, default
|
|
44
|
+
* `cascade-theme`) in the versioned envelope `{"v":1,"value":…}` that script reads, so a
|
|
45
|
+
* reload never flashes. A bare string written by older code is read too. On connect it
|
|
46
|
+
* restores the stored value, else keeps what `<html>` already carries, else the control's own.
|
|
47
|
+
* For density use `attribute="data-density" storage-key="cascade-density"`.
|
|
48
|
+
* Fires `cv-theme-change` (`detail.value`) when the user picks.
|
|
49
|
+
*/
|
|
50
|
+
export declare class CvTheme extends CvElement {
|
|
51
|
+
#private;
|
|
52
|
+
readonly value: Signal<string | undefined>;
|
|
53
|
+
constructor();
|
|
54
|
+
pick(value: string): void;
|
|
55
|
+
connectedCallback(): void;
|
|
56
|
+
protected render(): void;
|
|
57
|
+
}
|
|
58
|
+
export declare function define(): void;
|
package/dist/theme.js
ADDED
|
@@ -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=`[data-cv-theme-value]`,o=class extends i{value=r(void 0);constructor(){super(),this.addEventListener(`change`,t=>{let n=e(t);n instanceof HTMLSelectElement&&this.pick(n.value)}),this.addEventListener(`click`,t=>{let n=e(t).closest(a);n&&this.pick(n.dataset.cvThemeValue??``)})}get#e(){return this.getAttribute(`attribute`)??`data-theme`}get#t(){return this.getAttribute(`storage-key`)??`cascade-theme`}pick(e){if(e){try{localStorage.setItem(this.#t,JSON.stringify({v:1,value:e}))}catch{}e!==this.value.peek()&&(this.value.value=e,this.emit(`cv-theme-change`,{value:e}))}}connectedCallback(){if(this.value.peek()===void 0){let e;try{let t=localStorage.getItem(this.#t);if(t){e=t;try{let n=JSON.parse(t);n&&typeof n==`object`&&`value`in n&&(e=String(n.value))}catch{}}}catch{}this.value.value=e||document.documentElement.getAttribute(this.#e)||this.$(`select`)?.value||this.$(`${a}[aria-pressed="true"]`)?.getAttribute(`data-cv-theme-value`)||void 0}super.connectedCallback()}render(){let e=this.value.value;if(e===void 0)return;t(document.documentElement,this.#e,e);let n=this.$(`select`);n&&n.value!==e&&(n.value=e);for(let n of this.$$(a))t(n,`aria-pressed`,String(n.getAttribute(`data-cv-theme-value`)===e))}};function s(){n(`cv-theme`,o)}export{o as CvTheme,s as define};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Light-DOM base: state lives in signals on the instance; `render()` projects it onto
|
|
3
|
+
* whatever markup is currently inside the element. It reruns on every signal change (effect)
|
|
4
|
+
* and on every DOM change (MutationObserver), so an htmx/idiomorph morph that resets
|
|
5
|
+
* attributes or replaces children is repaired on the next microtask and the element keeps
|
|
6
|
+
* its state, provided it keeps its `id` (idiomorph then reuses the node).
|
|
7
|
+
*/
|
|
8
|
+
declare abstract class CvElement extends HTMLElement {
|
|
9
|
+
#private;
|
|
10
|
+
protected uid: string;
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
disconnectedCallback(): void;
|
|
13
|
+
protected abstract render(): void;
|
|
14
|
+
protected emit(type: string, detail?: unknown): void;
|
|
15
|
+
protected $<T extends Element = HTMLElement>(selector: string): T | null;
|
|
16
|
+
protected $$<T extends Element = HTMLElement>(selector: string): T[];
|
|
17
|
+
}
|
|
18
|
+
export interface ToastInput {
|
|
19
|
+
kind?: string;
|
|
20
|
+
message: string;
|
|
21
|
+
title?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* `<cv-toaster id="cv-toaster">`: the live region B1's `View::toast` fills (OOB
|
|
25
|
+
* `beforeend:#cv-toaster`) or notifies (`cv-toast` event, wired by the htmx glue to `.add()`).
|
|
26
|
+
* Toasts are `.cv-toast-toast` rows (`role=status`, `alert` for destructive). Each dismisses
|
|
27
|
+
* itself after `duration` ms (default 5000; 0 keeps them); hover or focus anywhere in the
|
|
28
|
+
* region pauses every timer; the close button or Escape dismisses now. Without the script
|
|
29
|
+
* the server-rendered toasts simply stay (no-JS flash fallback). Fires `cv-toast-dismiss`.
|
|
30
|
+
*/
|
|
31
|
+
export declare class CvToaster extends CvElement {
|
|
32
|
+
#private;
|
|
33
|
+
constructor();
|
|
34
|
+
/** Append a toast built from data (the `cv-toast` trigger path); text only, never HTML. */
|
|
35
|
+
add({ kind, message, title }: ToastInput): void;
|
|
36
|
+
protected render(): void;
|
|
37
|
+
}
|
|
38
|
+
export declare function define(): void;
|
package/dist/toaster.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,i as t,r as n,t as r}from"./base-B5z3ufCR.js";import{a as i,o as a}from"./messages-Bhd7waiI.js";var o=`cv-toast-`,s={info:`default`,danger:`destructive`},c={success:`✓`,warning:`!`,destructive:`✕`},l=class extends r{#e=/* @__PURE__ */ new WeakMap;#t=/* @__PURE__ */ new Set;#n=!1;#r=null;constructor(){super();let t=e=>{this.#n=e;for(let e of this.#t)this.#o(e)};this.addEventListener(`pointerenter`,()=>t(!0)),this.addEventListener(`pointerleave`,()=>t(this.matches(`:focus-within`))),this.addEventListener(`focusin`,e=>{let n=e.relatedTarget;n&&!this.contains(n)&&(this.#r=n),t(!0)}),this.addEventListener(`focusout`,e=>{this.contains(e.relatedTarget)||t(this.matches(`:hover`))}),this.addEventListener(`click`,t=>{let n=e(t).closest(`.${o}close`)?.closest(`.${o}toast`);n&&this.#i(n)}),this.addEventListener(`keydown`,t=>{let n=e(t).closest(`.${o}toast`);t.key===`Escape`&&n&&this.#i(n)})}add({kind:e=`info`,message:t,title:n}){let r=s[e]??e,i=(e,t,n)=>{let r=document.createElement(e);return r.className=o+t,n!==void 0&&(r.textContent=n),r},a=i(`div`,`toast`);a.setAttribute(`role`,r===`destructive`?`alert`:`status`),a.dataset.variant=r;let l=c[r];if(l){let e=i(`span`,`icon`,l);e.setAttribute(`aria-hidden`,`true`),a.append(e)}let u=i(`div`,`body`);u.append(i(`div`,`title`,n??t)),n&&u.append(i(`div`,`description`,t));let d=i(`button`,`close`,`×`);d.setAttribute(`type`,`button`),a.append(u,d),this.append(a)}#i(e){this.#a(e);let t=e.nextElementSibling?.querySelector(`.${o}close`),n=e.contains(document.activeElement);if(e.replaceWith(),this.emit(`cv-toast-dismiss`),!n)return;let r=this.#r?.isConnected?this.#r:null,i=t??this.$(`.${o}close`)??r??document.querySelector(`main`);i instanceof HTMLElement&&(i.tabIndex<0&&!i.matches(`button,a[href],input`)&&(i.tabIndex=-1),i.focus())}#a(e){clearTimeout(this.#e.get(e)?.id),this.#e.delete(e),this.#t.delete(e)}#o(e){let t=this.#e.get(e);if(t){if(clearTimeout(t.id),this.#n){t.since&&(t.left-=Date.now()-t.since),t.since=0;return}t.since=Date.now(),t.id=window.setTimeout(()=>this.#i(e),Math.max(t.left,0))}}render(){t(this,`role`,`region`),this.matches(`[aria-label]`)||t(this,`aria-label`,a(i.region));let e=Number(this.getAttribute(`duration`)??5e3),n=new Set(this.$$(`.${o}toast`));for(let e of this.#t)n.has(e)||this.#a(e);for(let r of n){t(r,`data-state`,`visible`);let n=r.querySelector(`.${o}close`);n&&!n.hasAttribute(`aria-label`)&&t(n,`aria-label`,a(i.dismiss)),!this.#t.has(r)&&(this.#t.add(r),!(e<=0)&&(this.#e.set(r,{left:e,since:0,id:0}),this.#o(r)))}}};function u(){n(`cv-toaster`,l)}export{l as CvToaster,u as define};
|
|
@@ -0,0 +1,54 @@
|
|
|
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-tooltip>`: enhances the markup `Tooltip` renders (a trigger and a
|
|
41
|
+
* `[role=tooltip][popover=manual]` sibling). Hover or keyboard focus on the trigger shows it
|
|
42
|
+
* after `delay` ms (default 200); leave, blur or Escape hides it at once. The trigger gets
|
|
43
|
+
* `aria-describedby` while it is visible. The tooltip never takes focus or pointer events.
|
|
44
|
+
* CSS alone cannot do this: a `popover=manual` panel needs `showPopover()`, and the delay and
|
|
45
|
+
* Escape (WCAG 1.4.13 dismissable) need script.
|
|
46
|
+
*/
|
|
47
|
+
export declare class CvTooltip extends CvElement {
|
|
48
|
+
#private;
|
|
49
|
+
readonly visible: Signal<boolean>;
|
|
50
|
+
constructor();
|
|
51
|
+
disconnectedCallback(): void;
|
|
52
|
+
protected render(): void;
|
|
53
|
+
}
|
|
54
|
+
export declare function define(): void;
|
package/dist/tooltip.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,r as t,s as n,t as r}from"./base-B5z3ufCR.js";var i=class extends r{visible=n(!1);#e;constructor(){super();let e=()=>{clearTimeout(this.#e);let e=Number(this.getAttribute(`delay`)??200);this.#e=setTimeout(()=>this.visible.value=!0,e)},t=()=>{clearTimeout(this.#e),this.visible.value=!1};this.addEventListener(`mouseover`,e),this.addEventListener(`mouseout`,e=>{this.contains(e.relatedTarget)||t()}),this.addEventListener(`focusin`,e),this.addEventListener(`focusout`,t),this.addEventListener(`keydown`,e=>e.key===`Escape`&&t())}disconnectedCallback(){super.disconnectedCallback(),clearTimeout(this.#e)}render(){let t=this.$(`[role="tooltip"]`);if(!t)return;let n=this.visible.value,r=Array.from(this.querySelectorAll(`*`)).find(e=>e!==t&&!t.contains(e)&&!e.contains(t));e(t,`id`,t.id||`${this.uid}-tip`),e(t,`popover`,`manual`),e(t,`data-state`,n?`visible`:`hidden`),e(r,`aria-describedby`,n?t.id:null),typeof t.showPopover==`function`&&t.matches(`:popover-open`)!==n&&(n?t.showPopover():t.hidePopover())}};function a(){t(`cv-tooltip`,i)}export{i as CvTooltip,a as define};
|
package/package.json
CHANGED
|
@@ -1,6 +1,133 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cascivo/elements",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "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",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"cascivo",
|
|
8
|
+
"custom-elements",
|
|
9
|
+
"design-system",
|
|
10
|
+
"htmx",
|
|
11
|
+
"light-dom",
|
|
12
|
+
"web-components"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/cascivo/cascivo/tree/main/packages/elements#readme",
|
|
15
|
+
"bugs": "https://github.com/cascivo/cascivo/issues",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"author": "urbanisierung",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/cascivo/cascivo.git",
|
|
21
|
+
"directory": "packages/elements"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"sideEffects": [
|
|
28
|
+
"./dist/htmx.js"
|
|
29
|
+
],
|
|
30
|
+
"exports": {
|
|
31
|
+
"./package.json": "./package.json",
|
|
32
|
+
"./menu": {
|
|
33
|
+
"types": "./dist/menu.d.ts",
|
|
34
|
+
"import": "./dist/menu.js",
|
|
35
|
+
"default": "./dist/menu.js"
|
|
36
|
+
},
|
|
37
|
+
"./tabs": {
|
|
38
|
+
"types": "./dist/tabs.d.ts",
|
|
39
|
+
"import": "./dist/tabs.js",
|
|
40
|
+
"default": "./dist/tabs.js"
|
|
41
|
+
},
|
|
42
|
+
"./form": {
|
|
43
|
+
"types": "./dist/form.d.ts",
|
|
44
|
+
"import": "./dist/form.js",
|
|
45
|
+
"default": "./dist/form.js"
|
|
46
|
+
},
|
|
47
|
+
"./combobox": {
|
|
48
|
+
"types": "./dist/combobox.d.ts",
|
|
49
|
+
"import": "./dist/combobox.js",
|
|
50
|
+
"default": "./dist/combobox.js"
|
|
51
|
+
},
|
|
52
|
+
"./date-picker": {
|
|
53
|
+
"types": "./dist/date-picker.d.ts",
|
|
54
|
+
"import": "./dist/date-picker.js",
|
|
55
|
+
"default": "./dist/date-picker.js"
|
|
56
|
+
},
|
|
57
|
+
"./dialog": {
|
|
58
|
+
"types": "./dist/dialog.d.ts",
|
|
59
|
+
"import": "./dist/dialog.js",
|
|
60
|
+
"default": "./dist/dialog.js"
|
|
61
|
+
},
|
|
62
|
+
"./toaster": {
|
|
63
|
+
"types": "./dist/toaster.d.ts",
|
|
64
|
+
"import": "./dist/toaster.js",
|
|
65
|
+
"default": "./dist/toaster.js"
|
|
66
|
+
},
|
|
67
|
+
"./data-table": {
|
|
68
|
+
"types": "./dist/data-table.d.ts",
|
|
69
|
+
"import": "./dist/data-table.js",
|
|
70
|
+
"default": "./dist/data-table.js"
|
|
71
|
+
},
|
|
72
|
+
"./drawer": {
|
|
73
|
+
"types": "./dist/drawer.d.ts",
|
|
74
|
+
"import": "./dist/drawer.js",
|
|
75
|
+
"default": "./dist/drawer.js"
|
|
76
|
+
},
|
|
77
|
+
"./command-menu": {
|
|
78
|
+
"types": "./dist/command-menu.d.ts",
|
|
79
|
+
"import": "./dist/command-menu.js",
|
|
80
|
+
"default": "./dist/command-menu.js"
|
|
81
|
+
},
|
|
82
|
+
"./theme": {
|
|
83
|
+
"types": "./dist/theme.d.ts",
|
|
84
|
+
"import": "./dist/theme.js",
|
|
85
|
+
"default": "./dist/theme.js"
|
|
86
|
+
},
|
|
87
|
+
"./tooltip": {
|
|
88
|
+
"types": "./dist/tooltip.d.ts",
|
|
89
|
+
"import": "./dist/tooltip.js",
|
|
90
|
+
"default": "./dist/tooltip.js"
|
|
91
|
+
},
|
|
92
|
+
"./multi-select": {
|
|
93
|
+
"types": "./dist/multi-select.d.ts",
|
|
94
|
+
"import": "./dist/multi-select.js",
|
|
95
|
+
"default": "./dist/multi-select.js"
|
|
96
|
+
},
|
|
97
|
+
"./tags-input": {
|
|
98
|
+
"types": "./dist/tags-input.d.ts",
|
|
99
|
+
"import": "./dist/tags-input.js",
|
|
100
|
+
"default": "./dist/tags-input.js"
|
|
101
|
+
},
|
|
102
|
+
"./htmx": {
|
|
103
|
+
"types": "./dist/htmx.d.ts",
|
|
104
|
+
"import": "./dist/htmx.js",
|
|
105
|
+
"default": "./dist/htmx.js"
|
|
106
|
+
},
|
|
107
|
+
"./elements.css": "./dist/elements.css",
|
|
108
|
+
"./custom-elements.json": "./dist/custom-elements.json"
|
|
109
|
+
},
|
|
110
|
+
"publishConfig": {
|
|
111
|
+
"access": "public",
|
|
112
|
+
"provenance": true
|
|
113
|
+
},
|
|
114
|
+
"devDependencies": {
|
|
115
|
+
"@cascivo/core": "1.11.0",
|
|
116
|
+
"@cascivo/css": "0.0.0",
|
|
117
|
+
"@cascivo/i18n": "1.11.0",
|
|
118
|
+
"@preact/signals-core": "^1.14.3",
|
|
119
|
+
"@types/node": "^25",
|
|
120
|
+
"axe-core": "4.11.4",
|
|
121
|
+
"idiomorph": "^0.8.0",
|
|
122
|
+
"jsdom": "^29",
|
|
123
|
+
"playwright": "^1.61.0",
|
|
124
|
+
"typescript": "^5",
|
|
125
|
+
"vite-plus": "^1.0.0"
|
|
126
|
+
},
|
|
127
|
+
"customElements": "./dist/custom-elements.json",
|
|
128
|
+
"scripts": {
|
|
129
|
+
"build": "vp build && node --experimental-strip-types scripts/build-assets.ts && node ../../scripts/build/flatten-dts.mjs menu=src/menu.ts tabs=src/tabs.ts form=src/form.ts combobox=src/combobox.ts date-picker=src/date-picker.ts dialog=src/dialog.ts toaster=src/toaster.ts data-table=src/data-table.ts drawer=src/drawer.ts command-menu=src/command-menu.ts theme=src/theme.ts tooltip=src/tooltip.ts multi-select=src/multi-select.ts tags-input=src/tags-input.ts htmx=src/htmx.ts && node ../../scripts/build/check-types-flat.mjs",
|
|
130
|
+
"check": "tsc --noEmit",
|
|
131
|
+
"test": "vp test"
|
|
132
|
+
}
|
|
6
133
|
}
|
package/readme.body.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
## What
|
|
2
|
+
|
|
3
|
+
Light-DOM custom elements that enhance the server-rendered [`@cascivo/css`](../css/README.md) markup (the
|
|
4
|
+
`cv-<unit>-<part>` classes that `cascivo-html` and `cascivo-server` emit): `<cv-menu>`, `<cv-tabs>`,
|
|
5
|
+
`<cv-form>`, `<cv-combobox>`, `<cv-date-picker>`, `<cv-dialog>` and `<cv-toaster>`. No React. Without JS the
|
|
6
|
+
markup still works; with JS the elements add the keyboard, focus and ARIA behaviour on top of
|
|
7
|
+
`@cascivo/core/pure` signals. Guide: [USING-CASCIVO-SERVER.md](../../docs/USING-CASCIVO-SERVER.md); markup contract:
|
|
8
|
+
[CONTRACT.md](../../docs/CONTRACT.md).
|
|
9
|
+
|
|
10
|
+
## Usage
|
|
11
|
+
|
|
12
|
+
Importing an element module does **not** register it: each module exports `define()`, which is idempotent
|
|
13
|
+
(`customElements.define` only when the tag is unknown). `@cascivo/elements/htmx` is the exception, it wires
|
|
14
|
+
the document when imported.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
// web/src/elements.ts (the starter's file)
|
|
18
|
+
import '@cascivo/elements/elements.css'
|
|
19
|
+
import { define as menu } from '@cascivo/elements/menu'
|
|
20
|
+
import { define as tabs } from '@cascivo/elements/tabs'
|
|
21
|
+
import '@cascivo/elements/htmx'
|
|
22
|
+
|
|
23
|
+
for (const define of [menu, tabs]) define()
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
One entry per element, no barrel, so a page ships only what it uses.
|
|
27
|
+
|
|
28
|
+
| Export | What |
|
|
29
|
+
| -------------------------- | ------------------------------------------------------------------------------------- |
|
|
30
|
+
| `/menu` `/tabs` `/form` | `define()` for `cv-menu` (fires `cv-select`), `cv-tabs`, `cv-form` |
|
|
31
|
+
| `/combobox` `/date-picker` | `define()` for the form-associated `cv-combobox`, `cv-date-picker` |
|
|
32
|
+
| `/dialog` `/toaster` | `define()` for `cv-dialog` (`cv-open`, `cv-close`), `cv-toaster` (`cv-toast-dismiss`) |
|
|
33
|
+
| `/htmx` | the glue below; no `define()` |
|
|
34
|
+
| `/elements.css` | the component CSS those elements style, in `@layer cascivo.component` |
|
|
35
|
+
| `/custom-elements.json` | Custom Elements Manifest (tags, attributes, events) |
|
|
36
|
+
|
|
37
|
+
## Markup
|
|
38
|
+
|
|
39
|
+
The element wraps the markup the server renders; this is the shape `<cv-tabs>` enhances (the server picks the
|
|
40
|
+
selected tab, the element projects it and adds roving focus):
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<cv-tabs id="demo">
|
|
44
|
+
<div class="cv-tabs-tabs">
|
|
45
|
+
<div role="tablist" class="cv-tabs-list" aria-label="Sections">
|
|
46
|
+
<button
|
|
47
|
+
type="button"
|
|
48
|
+
role="tab"
|
|
49
|
+
id="t-a"
|
|
50
|
+
aria-selected="true"
|
|
51
|
+
aria-controls="p-a"
|
|
52
|
+
data-value="a"
|
|
53
|
+
>
|
|
54
|
+
A
|
|
55
|
+
</button>
|
|
56
|
+
<button
|
|
57
|
+
type="button"
|
|
58
|
+
role="tab"
|
|
59
|
+
id="t-b"
|
|
60
|
+
aria-selected="false"
|
|
61
|
+
aria-controls="p-b"
|
|
62
|
+
data-value="b"
|
|
63
|
+
>
|
|
64
|
+
B
|
|
65
|
+
</button>
|
|
66
|
+
</div>
|
|
67
|
+
<div role="tabpanel" id="p-a" aria-labelledby="t-a">A body</div>
|
|
68
|
+
<div role="tabpanel" id="p-b" aria-labelledby="t-b" hidden>B body</div>
|
|
69
|
+
</div>
|
|
70
|
+
</cv-tabs>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Arrow, Home and End move focus and activate; `activation="manual"` makes arrows move focus only. The element
|
|
74
|
+
fires `cv-value-change` with `detail.value` (the tab's `data-value`, else its id). Every element's attributes
|
|
75
|
+
and events are listed in `custom-elements.json`.
|
|
76
|
+
|
|
77
|
+
## htmx glue
|
|
78
|
+
|
|
79
|
+
`import '@cascivo/elements/htmx'` runs `install()` once per document (no htmx import; it listens to DOM
|
|
80
|
+
events). It does only this:
|
|
81
|
+
|
|
82
|
+
- After `htmx:afterSettle`, if focus fell to `<body>`, it returns focus to the previously focused id, else the
|
|
83
|
+
first focusable element in the swap target, else the target, else `<main>`.
|
|
84
|
+
- `cv-dialog-close` (for example from `HX-Trigger`) closes the enclosing `<cv-dialog>`, or every open one.
|
|
85
|
+
- `cv-toast` (`HX-Trigger: {"cv-toast": [{"kind": "...", "message": "..."}]}`) calls `.add()` on the page's
|
|
86
|
+
`<cv-toaster>`; entries without a string `message` are ignored.
|
|
87
|
+
- When a global `Idiomorph` exists, the focused field keeps its typed value across a morph and a morph does
|
|
88
|
+
not strip an open `<dialog>`'s `open` attribute.
|
|
89
|
+
|
|
90
|
+
## Budget
|
|
91
|
+
|
|
92
|
+
Each element is at most 3 KB gzip and a page's cascivo JS (elements plus glue, htmx counted separately) at
|
|
93
|
+
most 15 KB; see [JavaScript budgets](../../docs/USING-CASCIVO-SERVER.md#javascript-budgets). Messages are
|
|
94
|
+
declared in `src/messages.ts` under the same keys as `@cascivo/i18n`'s `builtin`, so an adopter's
|
|
95
|
+
`defineCatalog` translates them without pulling the whole catalog in.
|