@ktbsh/ui 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/README.md +165 -0
- package/dist/custom-elements.json +1427 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +12 -0
- package/dist/react/alert.d.ts +20 -0
- package/dist/react/alert.js +30 -0
- package/dist/react/badge.d.ts +17 -0
- package/dist/react/badge.js +30 -0
- package/dist/react/box.d.ts +22 -0
- package/dist/react/box.js +30 -0
- package/dist/react/breadcrumb.d.ts +17 -0
- package/dist/react/breadcrumb.js +30 -0
- package/dist/react/button.d.ts +20 -0
- package/dist/react/button.js +30 -0
- package/dist/react/checkbox.d.ts +22 -0
- package/dist/react/checkbox.js +30 -0
- package/dist/react/container.d.ts +18 -0
- package/dist/react/container.js +30 -0
- package/dist/react/field.d.ts +20 -0
- package/dist/react/field.js +30 -0
- package/dist/react/heading.d.ts +19 -0
- package/dist/react/heading.js +30 -0
- package/dist/react/input.d.ts +25 -0
- package/dist/react/input.js +30 -0
- package/dist/react/label.d.ts +18 -0
- package/dist/react/label.js +30 -0
- package/dist/react/link.d.ts +21 -0
- package/dist/react/link.js +30 -0
- package/dist/react/modal.d.ts +18 -0
- package/dist/react/modal.js +30 -0
- package/dist/react/nav.d.ts +17 -0
- package/dist/react/nav.js +30 -0
- package/dist/react/pagination.d.ts +19 -0
- package/dist/react/pagination.js +30 -0
- package/dist/react/progress.d.ts +19 -0
- package/dist/react/progress.js +30 -0
- package/dist/react/radio.d.ts +22 -0
- package/dist/react/radio.js +30 -0
- package/dist/react/select.d.ts +22 -0
- package/dist/react/select.js +30 -0
- package/dist/react/skeleton.d.ts +19 -0
- package/dist/react/skeleton.js +30 -0
- package/dist/react/spinner.d.ts +18 -0
- package/dist/react/spinner.js +30 -0
- package/dist/react/stack.d.ts +21 -0
- package/dist/react/stack.js +30 -0
- package/dist/react/switch.d.ts +21 -0
- package/dist/react/switch.js +30 -0
- package/dist/react/tab-panel.d.ts +18 -0
- package/dist/react/tab-panel.js +30 -0
- package/dist/react/tab.d.ts +19 -0
- package/dist/react/tab.js +30 -0
- package/dist/react/tabs.d.ts +17 -0
- package/dist/react/tabs.js +30 -0
- package/dist/react/text.d.ts +19 -0
- package/dist/react/text.js +30 -0
- package/dist/react/textarea.d.ts +24 -0
- package/dist/react/textarea.js +30 -0
- package/dist/react/toast.d.ts +19 -0
- package/dist/react/toast.js +30 -0
- package/dist/themes/dark.css +52 -0
- package/dist/themes/light.css +53 -0
- package/dist/tokens/index.d.ts +7 -0
- package/dist/tokens/index.js +7 -0
- package/dist/tokens/semantic.d.ts +209 -0
- package/dist/tokens/semantic.js +102 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.js +2 -0
- package/dist/vanilla/alert.d.ts +2 -0
- package/dist/vanilla/alert.js +134 -0
- package/dist/vanilla/alert.src.js +257 -0
- package/dist/vanilla/badge.d.ts +2 -0
- package/dist/vanilla/badge.js +89 -0
- package/dist/vanilla/badge.src.js +212 -0
- package/dist/vanilla/box.d.ts +2 -0
- package/dist/vanilla/box.js +100 -0
- package/dist/vanilla/box.src.js +270 -0
- package/dist/vanilla/breadcrumb.d.ts +2 -0
- package/dist/vanilla/breadcrumb.js +93 -0
- package/dist/vanilla/breadcrumb.src.js +255 -0
- package/dist/vanilla/button.d.ts +2 -0
- package/dist/vanilla/button.js +135 -0
- package/dist/vanilla/button.src.js +260 -0
- package/dist/vanilla/checkbox.d.ts +2 -0
- package/dist/vanilla/checkbox.js +96 -0
- package/dist/vanilla/checkbox.src.js +296 -0
- package/dist/vanilla/container.d.ts +2 -0
- package/dist/vanilla/container.js +79 -0
- package/dist/vanilla/container.src.js +222 -0
- package/dist/vanilla/field.d.ts +2 -0
- package/dist/vanilla/field.js +113 -0
- package/dist/vanilla/field.src.js +278 -0
- package/dist/vanilla/heading.d.ts +2 -0
- package/dist/vanilla/heading.js +75 -0
- package/dist/vanilla/heading.src.js +241 -0
- package/dist/vanilla/input.d.ts +2 -0
- package/dist/vanilla/input.js +121 -0
- package/dist/vanilla/input.src.js +326 -0
- package/dist/vanilla/label.d.ts +2 -0
- package/dist/vanilla/label.js +75 -0
- package/dist/vanilla/label.src.js +232 -0
- package/dist/vanilla/link.d.ts +2 -0
- package/dist/vanilla/link.js +96 -0
- package/dist/vanilla/link.src.js +272 -0
- package/dist/vanilla/modal.d.ts +2 -0
- package/dist/vanilla/modal.js +125 -0
- package/dist/vanilla/modal.src.js +251 -0
- package/dist/vanilla/nav.d.ts +2 -0
- package/dist/vanilla/nav.js +94 -0
- package/dist/vanilla/nav.src.js +214 -0
- package/dist/vanilla/pagination.d.ts +2 -0
- package/dist/vanilla/pagination.js +114 -0
- package/dist/vanilla/pagination.src.js +262 -0
- package/dist/vanilla/progress.d.ts +2 -0
- package/dist/vanilla/progress.js +108 -0
- package/dist/vanilla/progress.src.js +244 -0
- package/dist/vanilla/radio.d.ts +2 -0
- package/dist/vanilla/radio.js +104 -0
- package/dist/vanilla/radio.src.js +326 -0
- package/dist/vanilla/select.d.ts +2 -0
- package/dist/vanilla/select.js +104 -0
- package/dist/vanilla/select.src.js +332 -0
- package/dist/vanilla/skeleton.d.ts +2 -0
- package/dist/vanilla/skeleton.js +99 -0
- package/dist/vanilla/skeleton.src.js +240 -0
- package/dist/vanilla/spinner.d.ts +2 -0
- package/dist/vanilla/spinner.js +108 -0
- package/dist/vanilla/spinner.src.js +222 -0
- package/dist/vanilla/stack.d.ts +2 -0
- package/dist/vanilla/stack.js +83 -0
- package/dist/vanilla/stack.src.js +259 -0
- package/dist/vanilla/switch.d.ts +2 -0
- package/dist/vanilla/switch.js +166 -0
- package/dist/vanilla/switch.src.js +299 -0
- package/dist/vanilla/tab-panel.d.ts +2 -0
- package/dist/vanilla/tab-panel.js +80 -0
- package/dist/vanilla/tab-panel.src.js +227 -0
- package/dist/vanilla/tab.d.ts +2 -0
- package/dist/vanilla/tab.js +99 -0
- package/dist/vanilla/tab.src.js +253 -0
- package/dist/vanilla/tabs.d.ts +2 -0
- package/dist/vanilla/tabs.js +66 -0
- package/dist/vanilla/tabs.src.js +237 -0
- package/dist/vanilla/text.d.ts +2 -0
- package/dist/vanilla/text.js +74 -0
- package/dist/vanilla/text.src.js +232 -0
- package/dist/vanilla/textarea.d.ts +2 -0
- package/dist/vanilla/textarea.js +97 -0
- package/dist/vanilla/textarea.src.js +316 -0
- package/dist/vanilla/toast.d.ts +2 -0
- package/dist/vanilla/toast.js +120 -0
- package/dist/vanilla/toast.src.js +245 -0
- package/package.json +111 -0
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
|
|
2
|
+
import { render, html } from 'uhtml';
|
|
3
|
+
|
|
4
|
+
const sheet = new CSSStyleSheet();
|
|
5
|
+
sheet.replaceSync(":host {\n--kb-color-bg-canvas: #ffffff;\n--kb-color-bg-surface: #f6f8fa;\n--kb-color-bg-subtle: #eef1f4;\n--kb-color-bg-inverse: #1f2328;\n--kb-color-fg-default: #1f2328;\n--kb-color-fg-muted: #656d76;\n--kb-color-fg-subtle: #8c959f;\n--kb-color-fg-on-accent: #ffffff;\n--kb-color-fg-on-inverse: #ffffff;\n--kb-color-border-default: #d0d7de;\n--kb-color-border-muted: #e6ebf0;\n--kb-color-border-focus: #0969da;\n--kb-color-accent-default: #0969da;\n--kb-color-accent-hover: #0860ca;\n--kb-color-accent-subtle: #ddf4ff;\n--kb-color-danger-default: #cf222e;\n--kb-color-danger-subtle: #ffebe9;\n--kb-color-success-default: #1a7f37;\n--kb-color-success-subtle: #dafbe1;\n--kb-color-warning-default: #9a6700;\n--kb-color-warning-subtle: #fff8c5;\n--kb-space-2xs: 2px;\n--kb-space-xs: 4px;\n--kb-space-sm: 8px;\n--kb-space-md: 16px;\n--kb-space-lg: 24px;\n--kb-space-xl: 32px;\n--kb-space-2xl: 48px;\n--kb-radius-sm: 4px;\n--kb-radius-md: 8px;\n--kb-radius-lg: 12px;\n--kb-radius-full: 9999px;\n--kb-font-family-sans: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n--kb-font-size-sm: 0.875rem;\n--kb-font-size-md: 1rem;\n--kb-font-size-lg: 1.125rem;\n--kb-font-size-xl: 1.25rem;\n--kb-font-weight-regular: 400;\n--kb-font-weight-medium: 500;\n--kb-font-weight-semibold: 600;\n--kb-line-height-tight: 1.25;\n--kb-line-height-normal: 1.5;\n--kb-shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);\n--kb-shadow-md: 0 4px 12px rgba(31, 35, 40, 0.1);\n--kb-focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);\n}\n\n\n :host {\n display: inline-flex;\n vertical-align: middle;\n font-family: var(--kb-font-family-sans);\n font-size: var(--kb-font-size-md);\n color: var(--kb-color-fg-default);\n --kitbash-switch-w: 2.75rem;\n --kitbash-switch-h: 1.5rem;\n --kitbash-switch-pad: 2px;\n --kitbash-switch-thumb: calc(\n var(--kitbash-switch-h) - 2 * var(--kitbash-switch-pad)\n );\n --kitbash-switch-track: var(--kb-color-bg-subtle);\n --kitbash-switch-track-on: var(--kb-color-accent-default);\n --kitbash-switch-knob: #ffffff;\n }\n .label-wrap {\n display: inline-flex;\n align-items: center;\n gap: var(--kb-space-sm);\n cursor: pointer;\n user-select: none;\n }\n .switch {\n position: relative;\n display: inline-block;\n width: var(--kitbash-switch-w);\n height: var(--kitbash-switch-h);\n flex-shrink: 0;\n }\n input {\n position: absolute;\n inset: 0;\n z-index: 2;\n width: 100%;\n height: 100%;\n margin: 0;\n opacity: 0;\n cursor: pointer;\n }\n input:disabled {\n cursor: not-allowed;\n }\n .track {\n position: absolute;\n inset: 0;\n z-index: 0;\n box-sizing: border-box;\n border-radius: 999px;\n background: var(--kitbash-switch-track);\n border: 1px solid var(--kb-color-border-default);\n transition: background 0.15s ease, border-color 0.15s ease;\n pointer-events: none;\n }\n .thumb {\n position: absolute;\n z-index: 1;\n top: var(--kitbash-switch-pad);\n left: var(--kitbash-switch-pad);\n width: var(--kitbash-switch-thumb);\n height: var(--kitbash-switch-thumb);\n border-radius: 999px;\n background: var(--kitbash-switch-knob);\n box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);\n transition: transform 0.15s ease;\n pointer-events: none;\n }\n input:checked + .track {\n background: var(--kitbash-switch-track-on);\n border-color: var(--kitbash-switch-track-on);\n }\n input:checked + .track .thumb {\n transform: translateX(\n calc(\n var(--kitbash-switch-w) - var(--kitbash-switch-thumb) - 2 *\n var(--kitbash-switch-pad)\n )\n );\n }\n input:focus-visible + .track {\n box-shadow: var(--kb-focus-ring);\n }\n input:disabled + .track {\n opacity: 0.55;\n }\n input[aria-invalid=\"true\"] + .track {\n border-color: var(--kb-color-danger-default);\n }\n .label {\n line-height: var(--kb-line-height-normal);\n }\n @media (prefers-reduced-motion: reduce) {\n .track,\n .thumb {\n transition: none;\n }\n }\n ");
|
|
6
|
+
|
|
7
|
+
export class KitbashSwitch extends HTMLElement {
|
|
8
|
+
static formAssociated = true;
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ["name","value","checked","disabled","invalid"];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get propTypes() {
|
|
14
|
+
return {"name":"String","value":"String","checked":"Boolean","disabled":"Boolean","invalid":"Boolean"};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get name() {
|
|
19
|
+
return this._props['name'];
|
|
20
|
+
}
|
|
21
|
+
set name(val) {
|
|
22
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
23
|
+
// (caller already knows the value they set).
|
|
24
|
+
this._assignProp('name', val);
|
|
25
|
+
this.update();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get value() {
|
|
29
|
+
return this._props['value'];
|
|
30
|
+
}
|
|
31
|
+
set value(val) {
|
|
32
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
33
|
+
// (caller already knows the value they set).
|
|
34
|
+
this._assignProp('value', val);
|
|
35
|
+
this.update();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get checked() {
|
|
39
|
+
return this._props['checked'];
|
|
40
|
+
}
|
|
41
|
+
set checked(val) {
|
|
42
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
43
|
+
// (caller already knows the value they set).
|
|
44
|
+
this._assignProp('checked', val);
|
|
45
|
+
this.update();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get disabled() {
|
|
49
|
+
return this._props['disabled'];
|
|
50
|
+
}
|
|
51
|
+
set disabled(val) {
|
|
52
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
53
|
+
// (caller already knows the value they set).
|
|
54
|
+
this._assignProp('disabled', val);
|
|
55
|
+
this.update();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get invalid() {
|
|
59
|
+
return this._props['invalid'];
|
|
60
|
+
}
|
|
61
|
+
set invalid(val) {
|
|
62
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
63
|
+
// (caller already knows the value they set).
|
|
64
|
+
this._assignProp('invalid', val);
|
|
65
|
+
this.update();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
constructor() {
|
|
70
|
+
super();
|
|
71
|
+
this.attachShadow({ mode: 'open', delegatesFocus: true });
|
|
72
|
+
this._internals = this.attachInternals();
|
|
73
|
+
this.shadowRoot.adoptedStyleSheets = [sheet];
|
|
74
|
+
|
|
75
|
+
this._defaults = {"name":"","value":"on","checked":false,"disabled":false,"invalid":false};
|
|
76
|
+
|
|
77
|
+
this._state = {};
|
|
78
|
+
this._props = { ...this._defaults };
|
|
79
|
+
this._eventHandlers = { 'click': function(e) {
|
|
80
|
+
const host = e.currentTarget;
|
|
81
|
+
if (e.composedPath()[0] !== host)
|
|
82
|
+
return;
|
|
83
|
+
const input = host.shadowRoot?.querySelector("input");
|
|
84
|
+
if (!input || input.disabled)
|
|
85
|
+
return;
|
|
86
|
+
input.click();
|
|
87
|
+
}, 'change input': function(e, { commit }) {
|
|
88
|
+
const target = e.target;
|
|
89
|
+
commit({
|
|
90
|
+
props: { checked: target.checked }
|
|
91
|
+
});
|
|
92
|
+
} };
|
|
93
|
+
this._eventCleanup = [];
|
|
94
|
+
this._renderFn = function({ props, html }) {
|
|
95
|
+
return html`
|
|
96
|
+
<label part="switch-container" class="label-wrap">
|
|
97
|
+
<span class="switch" part="switch-wrap">
|
|
98
|
+
<input
|
|
99
|
+
part="switch-input"
|
|
100
|
+
type="checkbox"
|
|
101
|
+
role="switch"
|
|
102
|
+
name=${props.name}
|
|
103
|
+
value=${props.value}
|
|
104
|
+
.checked=${props.checked}
|
|
105
|
+
?disabled=${props.disabled}
|
|
106
|
+
aria-invalid=${props.invalid ? "true" : "false"}
|
|
107
|
+
/>
|
|
108
|
+
<span class="track" part="switch-track" aria-hidden="true">
|
|
109
|
+
<span class="thumb" part="switch-thumb"></span>
|
|
110
|
+
</span>
|
|
111
|
+
</span>
|
|
112
|
+
<span class="label" part="switch-label"><slot></slot></span>
|
|
113
|
+
</label>
|
|
114
|
+
`;
|
|
115
|
+
};
|
|
116
|
+
this._reflecting = false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
connectedCallback() {
|
|
120
|
+
// Initial attribute values are parsed by attributeChangedCallback before connectedCallback fires
|
|
121
|
+
this.update();
|
|
122
|
+
if (this.value !== undefined) this._internals.setFormValue(this.value == null ? null : String(this.value));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
disconnectedCallback() {
|
|
126
|
+
this.cleanupEvents();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
130
|
+
// Skip when we caused the attribute write ourselves (avoids double update)
|
|
131
|
+
if (this._reflecting) return;
|
|
132
|
+
if (oldValue === newValue) return;
|
|
133
|
+
|
|
134
|
+
const type = this.constructor.propTypes[name];
|
|
135
|
+
|
|
136
|
+
let parsedValue = newValue;
|
|
137
|
+
if (newValue === null || newValue === undefined) {
|
|
138
|
+
parsedValue = this._defaults[name];
|
|
139
|
+
} else if (type === 'Number' && newValue !== '') {
|
|
140
|
+
// Match property coercion: empty string is not Number('') → 0
|
|
141
|
+
parsedValue = Number(newValue);
|
|
142
|
+
} else if (type === 'Boolean') {
|
|
143
|
+
parsedValue = newValue !== null && newValue !== 'false';
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
this._props[name] = parsedValue;
|
|
147
|
+
if (name === 'value' && this._internals) this._internals.setFormValue(parsedValue == null ? null : String(parsedValue));
|
|
148
|
+
this.update();
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Coerce + reflect a single prop; no re-render (caller decides). */
|
|
152
|
+
_assignProp(key, val) {
|
|
153
|
+
const type = this.constructor.propTypes[key];
|
|
154
|
+
let next = val;
|
|
155
|
+
if (type === 'Boolean') {
|
|
156
|
+
next = val === true || val === '';
|
|
157
|
+
} else if (type === 'Number' && val !== null && val !== undefined && val !== '') {
|
|
158
|
+
next = Number(val);
|
|
159
|
+
}
|
|
160
|
+
this._props[key] = next;
|
|
161
|
+
|
|
162
|
+
// Only reflect primitives — objects/arrays stay as properties (no [object Object] attrs)
|
|
163
|
+
const isPrimitive =
|
|
164
|
+
next === null ||
|
|
165
|
+
next === undefined ||
|
|
166
|
+
typeof next === 'string' ||
|
|
167
|
+
typeof next === 'number' ||
|
|
168
|
+
typeof next === 'boolean';
|
|
169
|
+
|
|
170
|
+
this._reflecting = true;
|
|
171
|
+
try {
|
|
172
|
+
if (type === 'Boolean') {
|
|
173
|
+
if (next) this.setAttribute(key, '');
|
|
174
|
+
else this.removeAttribute(key);
|
|
175
|
+
} else if (!isPrimitive) {
|
|
176
|
+
// property-only; drop stale attribute if any
|
|
177
|
+
this.removeAttribute(key);
|
|
178
|
+
} else if (next === null || next === undefined) {
|
|
179
|
+
this.removeAttribute(key);
|
|
180
|
+
} else {
|
|
181
|
+
this.setAttribute(key, String(next));
|
|
182
|
+
}
|
|
183
|
+
} finally {
|
|
184
|
+
this._reflecting = false;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (key === 'value' && this._internals) {
|
|
188
|
+
this._internals.setFormValue(next == null ? null : String(next));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
_emitChange() {
|
|
193
|
+
// Shallow-copy both bags so listeners cannot mutate internal state/props via event.detail
|
|
194
|
+
this.dispatchEvent(new CustomEvent('kitbash-change', {
|
|
195
|
+
detail: {
|
|
196
|
+
state: { ...this._state },
|
|
197
|
+
props: { ...this._props },
|
|
198
|
+
},
|
|
199
|
+
bubbles: true,
|
|
200
|
+
composed: true
|
|
201
|
+
}));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Batch props and/or state: one uhtml update, one kitbash-change.
|
|
206
|
+
* Prefer this in event handlers (e.g. controlled inputs).
|
|
207
|
+
*/
|
|
208
|
+
commit(patch) {
|
|
209
|
+
const p = patch || {};
|
|
210
|
+
if (p.props) {
|
|
211
|
+
const allowed = this.constructor.propTypes || {};
|
|
212
|
+
for (const key of Object.keys(p.props)) {
|
|
213
|
+
// Only declared props — ignore typos / stray keys
|
|
214
|
+
if (!Object.prototype.hasOwnProperty.call(allowed, key)) continue;
|
|
215
|
+
this._assignProp(key, p.props[key]);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (p.state) {
|
|
219
|
+
this._state = { ...this._state, ...p.state };
|
|
220
|
+
}
|
|
221
|
+
this.update();
|
|
222
|
+
this._emitChange();
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
setState(newState) {
|
|
226
|
+
this.commit({ state: newState });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
setProps(nextProps) {
|
|
230
|
+
this.commit({ props: nextProps });
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
_handlerCtx() {
|
|
234
|
+
// Snapshots so handlers/render cannot mutate internal bags by accident
|
|
235
|
+
return {
|
|
236
|
+
props: { ...this._props },
|
|
237
|
+
state: { ...this._state },
|
|
238
|
+
setState: this.setState.bind(this),
|
|
239
|
+
setProps: this.setProps.bind(this),
|
|
240
|
+
commit: this.commit.bind(this),
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
cleanupEvents() {
|
|
245
|
+
this._eventCleanup.forEach(cleanup => cleanup());
|
|
246
|
+
this._eventCleanup = [];
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
update() {
|
|
250
|
+
// Run the uhtml DOM diffing render cycle
|
|
251
|
+
render(this.shadowRoot, this._renderFn({
|
|
252
|
+
...this._handlerCtx(),
|
|
253
|
+
html
|
|
254
|
+
}));
|
|
255
|
+
this.cleanupEvents();
|
|
256
|
+
this.bindEvents();
|
|
257
|
+
this.syncFormState();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
syncFormState() {
|
|
262
|
+
const flags = {};
|
|
263
|
+
let msg = '';
|
|
264
|
+
if (this._props.invalid) {
|
|
265
|
+
flags.customError = true;
|
|
266
|
+
msg = 'Invalid field.';
|
|
267
|
+
} else if (this._props.required && !this._props.value) {
|
|
268
|
+
flags.valueMissing = true;
|
|
269
|
+
msg = 'This field is required.';
|
|
270
|
+
}
|
|
271
|
+
if (Object.keys(flags).length > 0) {
|
|
272
|
+
this._internals.setValidity(flags, msg);
|
|
273
|
+
} else {
|
|
274
|
+
this._internals.setValidity({});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
bindEvents() {
|
|
280
|
+
Object.keys(this._eventHandlers).forEach(eventSelector => {
|
|
281
|
+
const parts = eventSelector.split(' ');
|
|
282
|
+
const eventName = parts[0];
|
|
283
|
+
const selector = parts.slice(1).join(' ');
|
|
284
|
+
|
|
285
|
+
const targets = selector ? this.shadowRoot.querySelectorAll(selector) : [this];
|
|
286
|
+
targets.forEach(target => {
|
|
287
|
+
const handler = (e) => {
|
|
288
|
+
this._eventHandlers[eventSelector](e, this._handlerCtx());
|
|
289
|
+
};
|
|
290
|
+
target.addEventListener(eventName, handler);
|
|
291
|
+
this._eventCleanup.push(() => target.removeEventListener(eventName, handler));
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!customElements.get('kitbash-switch')) {
|
|
298
|
+
customElements.define('kitbash-switch', KitbashSwitch);
|
|
299
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var d=(_,U,B,Y,I)=>{let W=B.length,J=U.length,z=W,O=0,$=0,X=null;while(O<J||$<z)if(J===O){let Q=z<W?$?Y(B[$-1],-0).nextSibling:Y(B[z],0):I;while($<z)_.insertBefore(Y(B[$++],1),Q)}else if(z===$)while(O<J){if(!X||!X.has(U[O]))_.removeChild(Y(U[O],-1));O++}else if(U[O]===B[$])O++,$++;else if(U[J-1]===B[z-1])J--,z--;else if(U[O]===B[z-1]&&B[$]===U[J-1]){let Q=Y(U[--J],-0).nextSibling;_.insertBefore(Y(B[$++],1),Y(U[O++],-0).nextSibling),_.insertBefore(Y(B[--z],1),Q),U[J]=B[z]}else{if(!X){X=new Map;let Q=$;while(Q<z)X.set(B[Q],Q++)}if(X.has(U[O])){let Q=X.get(U[O]);if($<Q&&Q<z){let Z=O,K=1;while(++Z<J&&Z<z&&X.get(U[Z])===Q+K)K++;if(K>Q-$){let D=Y(U[O],0);while($<Q)_.insertBefore(Y(B[$++],1),D)}else _.replaceChild(Y(B[$++],1),Y(U[O++],-1))}else O++}else _.removeChild(Y(U[O++],-1))}return B};var{isArray:E}=Array,{getPrototypeOf:R1,getOwnPropertyDescriptor:D1}=Object;var i="http://www.w3.org/2000/svg",q=[],N=()=>document.createRange(),M=(_,U,B)=>{return _.set(U,B),B},m=(_,U)=>{let B;do B=D1(_,U);while(!B&&(_=R1(_)));return B},o=(_,U)=>U.reduceRight(M1,_),M1=(_,U)=>_.childNodes[U];var s=1;var r=8;var l=11;var{setPrototypeOf:T1}=Object,n=(_)=>{function U(B){return T1(B,new.target.prototype)}return U.prototype=_.prototype,U};var T,V=(_,U,B)=>{if(!T)T=N();if(B)T.setStartAfter(_);else T.setStartBefore(_);return T.setEndAfter(U),T.deleteContents(),_};var x=({firstChild:_,lastChild:U},B)=>V(_,U,B),t=!1,j=(_,U)=>t&&_.nodeType===l?1/U<0?U?x(_,!0):_.lastChild:U?_.valueOf():_.firstChild:_,a=(_)=>document.createComment(_);class w extends n(DocumentFragment){#U=a("<>");#B=a("</>");#_=q;constructor(_){super(_);this.replaceChildren(...[this.#U,..._.childNodes,this.#B]),t=!0}get firstChild(){return this.#U}get lastChild(){return this.#B}get parentNode(){return this.#U.parentNode}remove(){x(this,!1)}replaceWith(_){x(this,!0).replaceWith(_)}valueOf(){let{parentNode:_}=this;if(_===this){if(this.#_===q)this.#_=[...this.childNodes]}else{if(_){let{firstChild:U,lastChild:B}=this;this.#_=[U];while(U!==B)this.#_.push(U=U.nextSibling)}this.replaceChildren(...this.#_)}return this}}var e=(_,U,B)=>_.setAttribute(U,B),F=(_,U)=>_.removeAttribute(U),H1=(_,U)=>{for(let B in U){let Y=U[B],I=B==="role"?B:`aria-${B}`;if(Y==null)F(_,I);else e(_,I,Y)}return U},C,F1=(_,U,B)=>{if(B=B.slice(1),!C)C=new WeakMap;let Y=C.get(_)||M(C,_,{}),I=Y[B];if(I&&I[0])_.removeEventListener(B,...I);if(I=E(U)?U:[U,!1],Y[B]=I,I[0])_.addEventListener(B,...I);return U};var G=(_,U)=>{let{t:B,n:Y}=_,I=!1;switch(typeof U){case"object":if(U!==null){(Y||B).replaceWith(_.n=U.valueOf());break}case"undefined":I=!0;default:if(B.data=I?"":U,Y)_.n=null,Y.replaceWith(B);break}return U},P1=(_,U)=>f(_,U,U==null?"class":"className"),A1=(_,U)=>{let{dataset:B}=_;for(let Y in U)if(U[Y]==null)delete B[Y];else B[Y]=U[Y];return U},k=(_,U,B)=>_[B]=U,E1=(_,U,B)=>k(_,U,B.slice(1)),f=(_,U,B)=>U==null?(F(_,B),U):k(_,U,B),_1=(_,U)=>(typeof U==="function"?U(_):U.current=_,U),y=(_,U,B)=>(U==null?F(_,B):e(_,B,U),U),N1=(_,U)=>U==null?f(_,U,"style"):k(_.style,U,"cssText"),V1=(_,U,B)=>(_.toggleAttribute(B.slice(1),U),U),R=(_,U,B)=>{let{length:Y}=U;if(_.data=`[${Y}]`,Y)return d(_.parentNode,B,U,j,_);switch(B.length){case 1:B[0].remove();case 0:break;default:V(j(B[0],0),j(B.at(-1),-0),!1);break}return q},U1=new Map([["aria",H1],["class",P1],["data",A1],["ref",_1],["style",N1]]),B1=(_,U,B)=>{switch(U[0]){case".":return E1;case"?":return V1;case"@":return F1;default:return B||"ownerSVGElement"in _?U==="ref"?_1:y:U1.get(U)||(U in _?U.startsWith("on")?k:m(_,U)?.set?f:y:y)}},Y1=(_,U)=>(_.textContent=U==null?"":U,U);var H=(_,U,B)=>({a:_,b:U,c:B}),z1=(_,U)=>({b:_,c:U}),I1=(_,U,B,Y)=>({v:q,u:_,t:U,n:B,c:Y}),L=()=>H(null,null,q);var b=(_)=>(U,B)=>{let{a:Y,b:I,c:W}=_(U,B),J=document.importNode(Y,!0),z=q;if(I!==q){z=[];for(let O,$,X=0;X<I.length;X++){let{a:Q,b:Z,c:K}=I[X],D=Q===$?O:O=o(J,$=Q);z[X]=I1(Z,D,K,Z===R?[]:Z===G?L():null)}}return z1(W?J.firstChild:new w(J),z)};var J1=/^(?:plaintext|script|style|textarea|title|xmp)$/i,O1=/^(?:area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;var j1=/<([a-zA-Z0-9]+[a-zA-Z0-9:._-]*)([^>]*?)(\/?)>/g,C1=/([^\s\\>"'=]+)\s*=\s*(['"]?)\x01/g,k1=/[\x01\x02]/g,Q1=(_,U,B)=>{let Y=0;return _.join("\x01").trim().replace(j1,(I,W,J,z)=>`<${W}${J.replace(C1,"\x02=$2$1").trimEnd()}${z?B||O1.test(W)?" /":`></${W}`:""}>`).replace(k1,(I)=>I==="\x01"?`<!--${U+Y++}-->`:U+Y++)};var S=document.createElement("template"),g,h,W1=(_,U)=>{if(U){if(!g)g=document.createElementNS(i,"svg"),h=N(),h.selectNodeContents(g);return h.createContextualFragment(_)}S.innerHTML=_;let{content:B}=S;return S=S.cloneNode(!1),B};var c=(_)=>{let U=[],B;while(B=_.parentNode)U.push(U.indexOf.call(B.childNodes,_)),_=B;return U},X1=()=>document.createTextNode(""),S1=(_,U,B)=>{let Y=W1(Q1(_,P,B),B),{length:I}=_,W=q;if(I>1){let O=[],$=document.createTreeWalker(Y,129),X=0,Q=`${P}${X++}`;W=[];while(X<I){let Z=$.nextNode();if(Z.nodeType===r){if(Z.data===Q){let K=E(U[X-1])?R:G;if(K===G)O.push(Z);W.push(H(c(Z),K,null)),Q=`${P}${X++}`}}else{let K;while(Z.hasAttribute(Q)){if(!K)K=c(Z);let D=Z.getAttribute(Q);W.push(H(K,B1(Z,D,B),D)),F(Z,Q),Q=`${P}${X++}`}if(!B&&J1.test(Z.localName)&&Z.textContent.trim()===`<!--${Q}-->`)W.push(H(K||c(Z),Y1,null)),Q=`${P}${X++}`}}for(X=0;X<O.length;X++)O[X].replaceWith(X1())}let{childNodes:J}=Y,{length:z}=J;if(z<1)z=1,Y.appendChild(X1());else if(z===1&&I!==1&&J[0].nodeType!==s)z=0;return M($1,_,H(Y,W,z===1))},$1=new WeakMap,P="isµ",v=(_)=>(U,B)=>$1.get(U)||S1(U,B,_);var x1=b(v(!1)),w1=b(v(!0)),p=(_,{s:U,t:B,v:Y})=>{if(_.a!==B){let{b:I,c:W}=(U?w1:x1)(B,Y);_.a=B,_.b=I,_.c=W}for(let{c:I}=_,W=0;W<I.length;W++){let J=Y[W],z=I[W];switch(z.u){case R:z.v=R(z.t,y1(z.c,J),z.v);break;case G:let O=J instanceof A?p(z.c||(z.c=L()),J):(z.c=null,J);if(O!==z.v)z.v=G(z,O);break;default:if(J!==z.v)z.v=z.u(z.t,J,z.n,z.v);break}}return _.b},y1=(_,U)=>{let B=0,{length:Y}=U;if(Y<_.length)_.splice(Y);for(;B<Y;B++){let I=U[B];if(I instanceof A)U[B]=p(_[B]||(_[B]=L()),I);else _[B]=null}return U};class A{constructor(_,U,B){this.s=_,this.t=U,this.v=B}toDOM(_=L()){return p(_,this)}}var Z1=new WeakMap,u=(_,U)=>{let B=Z1.get(_)||M(Z1,_,L()),{b:Y}=B;if(Y!==(typeof U==="function"?U():U).toDOM(B))_.replaceChildren(B.b.valueOf());return _};/*! (c) Andrea Giammarchi - MIT */var K1=(_)=>(U,...B)=>new A(_,U,B),q1=K1(!1),C_=K1(!0);var G1=new CSSStyleSheet;G1.replaceSync(`:host {
|
|
2
|
+
--kb-color-bg-canvas: #ffffff;
|
|
3
|
+
--kb-color-bg-surface: #f6f8fa;
|
|
4
|
+
--kb-color-bg-subtle: #eef1f4;
|
|
5
|
+
--kb-color-bg-inverse: #1f2328;
|
|
6
|
+
--kb-color-fg-default: #1f2328;
|
|
7
|
+
--kb-color-fg-muted: #656d76;
|
|
8
|
+
--kb-color-fg-subtle: #8c959f;
|
|
9
|
+
--kb-color-fg-on-accent: #ffffff;
|
|
10
|
+
--kb-color-fg-on-inverse: #ffffff;
|
|
11
|
+
--kb-color-border-default: #d0d7de;
|
|
12
|
+
--kb-color-border-muted: #e6ebf0;
|
|
13
|
+
--kb-color-border-focus: #0969da;
|
|
14
|
+
--kb-color-accent-default: #0969da;
|
|
15
|
+
--kb-color-accent-hover: #0860ca;
|
|
16
|
+
--kb-color-accent-subtle: #ddf4ff;
|
|
17
|
+
--kb-color-danger-default: #cf222e;
|
|
18
|
+
--kb-color-danger-subtle: #ffebe9;
|
|
19
|
+
--kb-color-success-default: #1a7f37;
|
|
20
|
+
--kb-color-success-subtle: #dafbe1;
|
|
21
|
+
--kb-color-warning-default: #9a6700;
|
|
22
|
+
--kb-color-warning-subtle: #fff8c5;
|
|
23
|
+
--kb-space-2xs: 2px;
|
|
24
|
+
--kb-space-xs: 4px;
|
|
25
|
+
--kb-space-sm: 8px;
|
|
26
|
+
--kb-space-md: 16px;
|
|
27
|
+
--kb-space-lg: 24px;
|
|
28
|
+
--kb-space-xl: 32px;
|
|
29
|
+
--kb-space-2xl: 48px;
|
|
30
|
+
--kb-radius-sm: 4px;
|
|
31
|
+
--kb-radius-md: 8px;
|
|
32
|
+
--kb-radius-lg: 12px;
|
|
33
|
+
--kb-radius-full: 9999px;
|
|
34
|
+
--kb-font-family-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
35
|
+
--kb-font-size-sm: 0.875rem;
|
|
36
|
+
--kb-font-size-md: 1rem;
|
|
37
|
+
--kb-font-size-lg: 1.125rem;
|
|
38
|
+
--kb-font-size-xl: 1.25rem;
|
|
39
|
+
--kb-font-weight-regular: 400;
|
|
40
|
+
--kb-font-weight-medium: 500;
|
|
41
|
+
--kb-font-weight-semibold: 600;
|
|
42
|
+
--kb-line-height-tight: 1.25;
|
|
43
|
+
--kb-line-height-normal: 1.5;
|
|
44
|
+
--kb-shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);
|
|
45
|
+
--kb-shadow-md: 0 4px 12px rgba(31, 35, 40, 0.1);
|
|
46
|
+
--kb-focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
:host {
|
|
51
|
+
display: block;
|
|
52
|
+
font-family: var(--kb-font-family-sans);
|
|
53
|
+
color: var(--kb-color-fg-default);
|
|
54
|
+
}
|
|
55
|
+
:host(:not([open])) {
|
|
56
|
+
display: none;
|
|
57
|
+
}
|
|
58
|
+
.panel {
|
|
59
|
+
padding: var(--kb-space-md) 0;
|
|
60
|
+
font-size: var(--kb-font-size-md);
|
|
61
|
+
line-height: var(--kb-line-height-normal);
|
|
62
|
+
}
|
|
63
|
+
.panel:focus {
|
|
64
|
+
outline: none;
|
|
65
|
+
}
|
|
66
|
+
.panel:focus-visible {
|
|
67
|
+
box-shadow: var(--kb-focus-ring);
|
|
68
|
+
border-radius: var(--kb-radius-sm);
|
|
69
|
+
}
|
|
70
|
+
`);class L1 extends HTMLElement{static get observedAttributes(){return["value","open"]}static get propTypes(){return{value:"String",open:"Boolean"}}get value(){return this._props.value}set value(_){this._assignProp("value",_),this.update()}get open(){return this._props.open}set open(_){this._assignProp("open",_),this.update()}constructor(){super();this.attachShadow({mode:"open",delegatesFocus:!1}),this.shadowRoot.adoptedStyleSheets=[G1],this._defaults={value:"",open:!1},this._state={},this._props={...this._defaults},this._eventHandlers={},this._eventCleanup=[],this._renderFn=function({props:_,html:U}){return U`
|
|
71
|
+
<div
|
|
72
|
+
part="tab-panel-root"
|
|
73
|
+
class="panel"
|
|
74
|
+
role="tabpanel"
|
|
75
|
+
tabindex="0"
|
|
76
|
+
data-value=${typeof _.value==="string"?_.value:""}
|
|
77
|
+
>
|
|
78
|
+
<slot></slot>
|
|
79
|
+
</div>
|
|
80
|
+
`},this._reflecting=!1}connectedCallback(){this.update()}disconnectedCallback(){this.cleanupEvents()}attributeChangedCallback(_,U,B){if(this._reflecting)return;if(U===B)return;let Y=this.constructor.propTypes[_],I=B;if(B===null||B===void 0)I=this._defaults[_];else if(Y==="Number"&&B!=="")I=Number(B);else if(Y==="Boolean")I=B!==null&&B!=="false";this._props[_]=I,this.update()}_assignProp(_,U){let B=this.constructor.propTypes[_],Y=U;if(B==="Boolean")Y=U===!0||U==="";else if(B==="Number"&&U!==null&&U!==void 0&&U!=="")Y=Number(U);this._props[_]=Y;let I=Y===null||Y===void 0||typeof Y==="string"||typeof Y==="number"||typeof Y==="boolean";this._reflecting=!0;try{if(B==="Boolean")if(Y)this.setAttribute(_,"");else this.removeAttribute(_);else if(!I)this.removeAttribute(_);else if(Y===null||Y===void 0)this.removeAttribute(_);else this.setAttribute(_,String(Y))}finally{this._reflecting=!1}}_emitChange(){this.dispatchEvent(new CustomEvent("kitbash-change",{detail:{state:{...this._state},props:{...this._props}},bubbles:!0,composed:!0}))}commit(_){let U=_||{};if(U.props){let B=this.constructor.propTypes||{};for(let Y of Object.keys(U.props)){if(!Object.prototype.hasOwnProperty.call(B,Y))continue;this._assignProp(Y,U.props[Y])}}if(U.state)this._state={...this._state,...U.state};this.update(),this._emitChange()}setState(_){this.commit({state:_})}setProps(_){this.commit({props:_})}_handlerCtx(){return{props:{...this._props},state:{...this._state},setState:this.setState.bind(this),setProps:this.setProps.bind(this),commit:this.commit.bind(this)}}cleanupEvents(){this._eventCleanup.forEach((_)=>_()),this._eventCleanup=[]}update(){u(this.shadowRoot,this._renderFn({...this._handlerCtx(),html:q1})),this.cleanupEvents(),this.bindEvents()}bindEvents(){Object.keys(this._eventHandlers).forEach((_)=>{let U=_.split(" "),B=U[0],Y=U.slice(1).join(" ");(Y?this.shadowRoot.querySelectorAll(Y):[this]).forEach((W)=>{let J=(z)=>{this._eventHandlers[_](z,this._handlerCtx())};W.addEventListener(B,J),this._eventCleanup.push(()=>W.removeEventListener(B,J))})})}}if(!customElements.get("kitbash-tab-panel"))customElements.define("kitbash-tab-panel",L1);export{L1 as KitbashTabPanel};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
|
|
2
|
+
import { render, html } from 'uhtml';
|
|
3
|
+
|
|
4
|
+
const sheet = new CSSStyleSheet();
|
|
5
|
+
sheet.replaceSync(":host {\n--kb-color-bg-canvas: #ffffff;\n--kb-color-bg-surface: #f6f8fa;\n--kb-color-bg-subtle: #eef1f4;\n--kb-color-bg-inverse: #1f2328;\n--kb-color-fg-default: #1f2328;\n--kb-color-fg-muted: #656d76;\n--kb-color-fg-subtle: #8c959f;\n--kb-color-fg-on-accent: #ffffff;\n--kb-color-fg-on-inverse: #ffffff;\n--kb-color-border-default: #d0d7de;\n--kb-color-border-muted: #e6ebf0;\n--kb-color-border-focus: #0969da;\n--kb-color-accent-default: #0969da;\n--kb-color-accent-hover: #0860ca;\n--kb-color-accent-subtle: #ddf4ff;\n--kb-color-danger-default: #cf222e;\n--kb-color-danger-subtle: #ffebe9;\n--kb-color-success-default: #1a7f37;\n--kb-color-success-subtle: #dafbe1;\n--kb-color-warning-default: #9a6700;\n--kb-color-warning-subtle: #fff8c5;\n--kb-space-2xs: 2px;\n--kb-space-xs: 4px;\n--kb-space-sm: 8px;\n--kb-space-md: 16px;\n--kb-space-lg: 24px;\n--kb-space-xl: 32px;\n--kb-space-2xl: 48px;\n--kb-radius-sm: 4px;\n--kb-radius-md: 8px;\n--kb-radius-lg: 12px;\n--kb-radius-full: 9999px;\n--kb-font-family-sans: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, \"Helvetica Neue\", Arial, sans-serif;\n--kb-font-size-sm: 0.875rem;\n--kb-font-size-md: 1rem;\n--kb-font-size-lg: 1.125rem;\n--kb-font-size-xl: 1.25rem;\n--kb-font-weight-regular: 400;\n--kb-font-weight-medium: 500;\n--kb-font-weight-semibold: 600;\n--kb-line-height-tight: 1.25;\n--kb-line-height-normal: 1.5;\n--kb-shadow-sm: 0 1px 2px rgba(31, 35, 40, 0.08);\n--kb-shadow-md: 0 4px 12px rgba(31, 35, 40, 0.1);\n--kb-focus-ring: 0 0 0 3px rgba(9, 105, 218, 0.35);\n}\n\n\n :host {\n display: block;\n font-family: var(--kb-font-family-sans);\n color: var(--kb-color-fg-default);\n }\n :host(:not([open])) {\n display: none;\n }\n .panel {\n padding: var(--kb-space-md) 0;\n font-size: var(--kb-font-size-md);\n line-height: var(--kb-line-height-normal);\n }\n .panel:focus {\n outline: none;\n }\n .panel:focus-visible {\n box-shadow: var(--kb-focus-ring);\n border-radius: var(--kb-radius-sm);\n }\n ");
|
|
6
|
+
|
|
7
|
+
export class KitbashTabPanel extends HTMLElement {
|
|
8
|
+
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ["value","open"];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static get propTypes() {
|
|
14
|
+
return {"value":"String","open":"Boolean"};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
get value() {
|
|
19
|
+
return this._props['value'];
|
|
20
|
+
}
|
|
21
|
+
set value(val) {
|
|
22
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
23
|
+
// (caller already knows the value they set).
|
|
24
|
+
this._assignProp('value', val);
|
|
25
|
+
this.update();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get open() {
|
|
29
|
+
return this._props['open'];
|
|
30
|
+
}
|
|
31
|
+
set open(val) {
|
|
32
|
+
// External / framework property writes: re-render, do not emit kitbash-change
|
|
33
|
+
// (caller already knows the value they set).
|
|
34
|
+
this._assignProp('open', val);
|
|
35
|
+
this.update();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
constructor() {
|
|
40
|
+
super();
|
|
41
|
+
this.attachShadow({ mode: 'open', delegatesFocus: false });
|
|
42
|
+
|
|
43
|
+
this.shadowRoot.adoptedStyleSheets = [sheet];
|
|
44
|
+
|
|
45
|
+
this._defaults = {"value":"","open":false};
|
|
46
|
+
|
|
47
|
+
this._state = {};
|
|
48
|
+
this._props = { ...this._defaults };
|
|
49
|
+
this._eventHandlers = {};
|
|
50
|
+
this._eventCleanup = [];
|
|
51
|
+
this._renderFn = function({ props, html }) {
|
|
52
|
+
return html`
|
|
53
|
+
<div
|
|
54
|
+
part="tab-panel-root"
|
|
55
|
+
class="panel"
|
|
56
|
+
role="tabpanel"
|
|
57
|
+
tabindex="0"
|
|
58
|
+
data-value=${typeof props.value === "string" ? props.value : ""}
|
|
59
|
+
>
|
|
60
|
+
<slot></slot>
|
|
61
|
+
</div>
|
|
62
|
+
`;
|
|
63
|
+
};
|
|
64
|
+
this._reflecting = false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
connectedCallback() {
|
|
68
|
+
// Initial attribute values are parsed by attributeChangedCallback before connectedCallback fires
|
|
69
|
+
this.update();
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
this.cleanupEvents();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
attributeChangedCallback(name, oldValue, newValue) {
|
|
78
|
+
// Skip when we caused the attribute write ourselves (avoids double update)
|
|
79
|
+
if (this._reflecting) return;
|
|
80
|
+
if (oldValue === newValue) return;
|
|
81
|
+
|
|
82
|
+
const type = this.constructor.propTypes[name];
|
|
83
|
+
|
|
84
|
+
let parsedValue = newValue;
|
|
85
|
+
if (newValue === null || newValue === undefined) {
|
|
86
|
+
parsedValue = this._defaults[name];
|
|
87
|
+
} else if (type === 'Number' && newValue !== '') {
|
|
88
|
+
// Match property coercion: empty string is not Number('') → 0
|
|
89
|
+
parsedValue = Number(newValue);
|
|
90
|
+
} else if (type === 'Boolean') {
|
|
91
|
+
parsedValue = newValue !== null && newValue !== 'false';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this._props[name] = parsedValue;
|
|
95
|
+
|
|
96
|
+
this.update();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Coerce + reflect a single prop; no re-render (caller decides). */
|
|
100
|
+
_assignProp(key, val) {
|
|
101
|
+
const type = this.constructor.propTypes[key];
|
|
102
|
+
let next = val;
|
|
103
|
+
if (type === 'Boolean') {
|
|
104
|
+
next = val === true || val === '';
|
|
105
|
+
} else if (type === 'Number' && val !== null && val !== undefined && val !== '') {
|
|
106
|
+
next = Number(val);
|
|
107
|
+
}
|
|
108
|
+
this._props[key] = next;
|
|
109
|
+
|
|
110
|
+
// Only reflect primitives — objects/arrays stay as properties (no [object Object] attrs)
|
|
111
|
+
const isPrimitive =
|
|
112
|
+
next === null ||
|
|
113
|
+
next === undefined ||
|
|
114
|
+
typeof next === 'string' ||
|
|
115
|
+
typeof next === 'number' ||
|
|
116
|
+
typeof next === 'boolean';
|
|
117
|
+
|
|
118
|
+
this._reflecting = true;
|
|
119
|
+
try {
|
|
120
|
+
if (type === 'Boolean') {
|
|
121
|
+
if (next) this.setAttribute(key, '');
|
|
122
|
+
else this.removeAttribute(key);
|
|
123
|
+
} else if (!isPrimitive) {
|
|
124
|
+
// property-only; drop stale attribute if any
|
|
125
|
+
this.removeAttribute(key);
|
|
126
|
+
} else if (next === null || next === undefined) {
|
|
127
|
+
this.removeAttribute(key);
|
|
128
|
+
} else {
|
|
129
|
+
this.setAttribute(key, String(next));
|
|
130
|
+
}
|
|
131
|
+
} finally {
|
|
132
|
+
this._reflecting = false;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
_emitChange() {
|
|
138
|
+
// Shallow-copy both bags so listeners cannot mutate internal state/props via event.detail
|
|
139
|
+
this.dispatchEvent(new CustomEvent('kitbash-change', {
|
|
140
|
+
detail: {
|
|
141
|
+
state: { ...this._state },
|
|
142
|
+
props: { ...this._props },
|
|
143
|
+
},
|
|
144
|
+
bubbles: true,
|
|
145
|
+
composed: true
|
|
146
|
+
}));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Batch props and/or state: one uhtml update, one kitbash-change.
|
|
151
|
+
* Prefer this in event handlers (e.g. controlled inputs).
|
|
152
|
+
*/
|
|
153
|
+
commit(patch) {
|
|
154
|
+
const p = patch || {};
|
|
155
|
+
if (p.props) {
|
|
156
|
+
const allowed = this.constructor.propTypes || {};
|
|
157
|
+
for (const key of Object.keys(p.props)) {
|
|
158
|
+
// Only declared props — ignore typos / stray keys
|
|
159
|
+
if (!Object.prototype.hasOwnProperty.call(allowed, key)) continue;
|
|
160
|
+
this._assignProp(key, p.props[key]);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (p.state) {
|
|
164
|
+
this._state = { ...this._state, ...p.state };
|
|
165
|
+
}
|
|
166
|
+
this.update();
|
|
167
|
+
this._emitChange();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
setState(newState) {
|
|
171
|
+
this.commit({ state: newState });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
setProps(nextProps) {
|
|
175
|
+
this.commit({ props: nextProps });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
_handlerCtx() {
|
|
179
|
+
// Snapshots so handlers/render cannot mutate internal bags by accident
|
|
180
|
+
return {
|
|
181
|
+
props: { ...this._props },
|
|
182
|
+
state: { ...this._state },
|
|
183
|
+
setState: this.setState.bind(this),
|
|
184
|
+
setProps: this.setProps.bind(this),
|
|
185
|
+
commit: this.commit.bind(this),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
cleanupEvents() {
|
|
190
|
+
this._eventCleanup.forEach(cleanup => cleanup());
|
|
191
|
+
this._eventCleanup = [];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
update() {
|
|
195
|
+
// Run the uhtml DOM diffing render cycle
|
|
196
|
+
render(this.shadowRoot, this._renderFn({
|
|
197
|
+
...this._handlerCtx(),
|
|
198
|
+
html
|
|
199
|
+
}));
|
|
200
|
+
this.cleanupEvents();
|
|
201
|
+
this.bindEvents();
|
|
202
|
+
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
bindEvents() {
|
|
208
|
+
Object.keys(this._eventHandlers).forEach(eventSelector => {
|
|
209
|
+
const parts = eventSelector.split(' ');
|
|
210
|
+
const eventName = parts[0];
|
|
211
|
+
const selector = parts.slice(1).join(' ');
|
|
212
|
+
|
|
213
|
+
const targets = selector ? this.shadowRoot.querySelectorAll(selector) : [this];
|
|
214
|
+
targets.forEach(target => {
|
|
215
|
+
const handler = (e) => {
|
|
216
|
+
this._eventHandlers[eventSelector](e, this._handlerCtx());
|
|
217
|
+
};
|
|
218
|
+
target.addEventListener(eventName, handler);
|
|
219
|
+
this._eventCleanup.push(() => target.removeEventListener(eventName, handler));
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (!customElements.get('kitbash-tab-panel')) {
|
|
226
|
+
customElements.define('kitbash-tab-panel', KitbashTabPanel);
|
|
227
|
+
}
|