@daasboard/ui 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 +5 -0
- package/README.md +6 -2
- package/dist/LICENSE-lucide.txt +43 -0
- package/dist/color/color.d.ts +34 -0
- package/dist/color/color.js +106 -0
- package/dist/color/edit.d.ts +34 -0
- package/dist/color/edit.js +40 -0
- package/dist/color/gradient.d.ts +39 -0
- package/dist/color/gradient.js +129 -0
- package/dist/color/index.d.ts +3 -0
- package/dist/color/index.js +3 -0
- package/dist/controls/buttons.d.ts +54 -0
- package/dist/controls/buttons.js +95 -0
- package/dist/controls/font-picker.d.ts +35 -0
- package/dist/controls/font-picker.js +178 -0
- package/dist/controls/index.d.ts +43 -0
- package/dist/controls/index.js +32 -0
- package/dist/controls/number-field.d.ts +60 -0
- package/dist/controls/number-field.js +190 -0
- package/dist/controls/place.d.ts +10 -0
- package/dist/controls/place.js +77 -0
- package/dist/controls/popover.d.ts +84 -0
- package/dist/controls/popover.js +366 -0
- package/dist/controls/shared.d.ts +30 -0
- package/dist/controls/shared.js +134 -0
- package/dist/controls/slider.d.ts +82 -0
- package/dist/controls/slider.js +241 -0
- package/dist/controls/swatch.d.ts +25 -0
- package/dist/controls/swatch.js +38 -0
- package/dist/controls/tooltip.d.ts +19 -0
- package/dist/controls/tooltip.js +84 -0
- package/dist/controls/typed.d.ts +28 -0
- package/dist/controls/typed.js +126 -0
- package/dist/element.d.ts +40 -0
- package/dist/element.js +78 -0
- package/dist/host.d.ts +99 -0
- package/dist/host.js +1 -0
- package/dist/icons/index.d.ts +7 -0
- package/dist/icons/index.js +31 -0
- package/dist/icons/lucide.d.ts +851 -0
- package/dist/icons/lucide.js +90 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +16 -0
- package/dist/keys.d.ts +30 -0
- package/dist/keys.js +122 -0
- package/dist/mount.d.ts +11 -0
- package/dist/mount.js +96 -0
- package/dist/options.d.ts +152 -0
- package/dist/options.js +78 -0
- package/dist/palette.d.ts +6 -0
- package/dist/palette.js +9 -0
- package/dist/picker/handles.d.ts +7 -0
- package/dist/picker/handles.js +8 -0
- package/dist/picker/index.d.ts +21 -0
- package/dist/picker/index.js +20 -0
- package/dist/picker/palette.d.ts +8 -0
- package/dist/picker/palette.js +14 -0
- package/dist/picker/picker.d.ts +63 -0
- package/dist/picker/picker.js +561 -0
- package/dist/picker/solid-editor.d.ts +60 -0
- package/dist/picker/solid-editor.js +330 -0
- package/dist/picker/stop-bar.d.ts +27 -0
- package/dist/picker/stop-bar.js +140 -0
- package/dist/prefs.d.ts +6 -0
- package/dist/prefs.js +34 -0
- package/dist/recents.d.ts +9 -0
- package/dist/recents.js +140 -0
- package/dist/root.d.ts +31 -0
- package/dist/root.js +526 -0
- package/dist/scheduler.d.ts +21 -0
- package/dist/scheduler.js +132 -0
- package/dist/strings.d.ts +284 -0
- package/dist/strings.js +287 -0
- package/dist/surface.d.ts +27 -0
- package/dist/surface.js +8 -0
- package/dist/surfaces/context-menu/index.d.ts +2 -0
- package/dist/surfaces/context-menu/index.js +2 -0
- package/dist/surfaces/context-menu/items.d.ts +14 -0
- package/dist/surfaces/context-menu/items.js +38 -0
- package/dist/surfaces/context-menu/menu.d.ts +16 -0
- package/dist/surfaces/context-menu/menu.js +135 -0
- package/dist/surfaces/pane/index.d.ts +16 -0
- package/dist/surfaces/pane/index.js +19 -0
- package/dist/surfaces/pane/model.d.ts +41 -0
- package/dist/surfaces/pane/model.js +139 -0
- package/dist/surfaces/pane/outlet.d.ts +16 -0
- package/dist/surfaces/pane/outlet.js +20 -0
- package/dist/surfaces/pane/pane.d.ts +40 -0
- package/dist/surfaces/pane/pane.js +1429 -0
- package/dist/surfaces/pane/placement.d.ts +11 -0
- package/dist/surfaces/pane/placement.js +62 -0
- package/dist/surfaces/pane/text-field.d.ts +16 -0
- package/dist/surfaces/pane/text-field.js +20 -0
- package/dist/surfaces/selection-toolbar/index.d.ts +2 -0
- package/dist/surfaces/selection-toolbar/index.js +2 -0
- package/dist/surfaces/selection-toolbar/items.d.ts +37 -0
- package/dist/surfaces/selection-toolbar/items.js +183 -0
- package/dist/surfaces/selection-toolbar/toolbar.d.ts +27 -0
- package/dist/surfaces/selection-toolbar/toolbar.js +956 -0
- package/dist/surfaces/tools/index.d.ts +2 -0
- package/dist/surfaces/tools/index.js +2 -0
- package/dist/surfaces/tools/keys.d.ts +11 -0
- package/dist/surfaces/tools/keys.js +21 -0
- package/dist/surfaces/tools/model.d.ts +48 -0
- package/dist/surfaces/tools/model.js +155 -0
- package/dist/surfaces/tools/toolbar.d.ts +27 -0
- package/dist/surfaces/tools/toolbar.js +502 -0
- package/dist/theme.d.ts +26 -0
- package/dist/theme.js +47 -0
- package/package.json +31 -3
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
var _a;
|
|
2
|
+
import { css, html, nothing } from "lit";
|
|
3
|
+
import { CONTEXT, UiElement } from "../element.js";
|
|
4
|
+
import { tok } from "../theme.js";
|
|
5
|
+
import { hasPopoverApi, place } from "./place.js";
|
|
6
|
+
import { baseStyles, cancelDragsWithin, COMMIT, emit, focusWithin, keepFocus, within } from "./shared.js";
|
|
7
|
+
const PRESS_TO_CLICK_MS = 1000;
|
|
8
|
+
export const OPEN = "daas-open";
|
|
9
|
+
export const CLOSE = "daas-close";
|
|
10
|
+
export class Popover extends UiElement {
|
|
11
|
+
static styles = [
|
|
12
|
+
baseStyles,
|
|
13
|
+
css `
|
|
14
|
+
:host{position: fixed;inset: auto;margin: 0;padding: 4px;min-width: 120px;border: 1px solid ${tok("border")};border-radius: ${tok("radius")};background: ${tok("bg")};color: ${tok("fg")};box-shadow: ${tok("shadow")};overflow: auto;}:host(:not([data-open])){display: none;}:host([data-open]){display: block;}:host([data-fallback]){z-index: 2147483647;}`,
|
|
15
|
+
];
|
|
16
|
+
static properties = { placement: {} };
|
|
17
|
+
#anchor = null;
|
|
18
|
+
#stopPlacing = null;
|
|
19
|
+
#stopWatching = null;
|
|
20
|
+
#anchorPressedAt = -Infinity;
|
|
21
|
+
#keepOpenOn = null;
|
|
22
|
+
#switching = false;
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
this.placement = "bottom-start";
|
|
26
|
+
}
|
|
27
|
+
get keepOpenOn() {
|
|
28
|
+
return this.#keepOpenOn;
|
|
29
|
+
}
|
|
30
|
+
set keepOpenOn(fn) {
|
|
31
|
+
if (fn === this.#keepOpenOn)
|
|
32
|
+
return;
|
|
33
|
+
this.#keepOpenOn = fn;
|
|
34
|
+
this.#applyMode();
|
|
35
|
+
if (this.open)
|
|
36
|
+
this.#watch();
|
|
37
|
+
}
|
|
38
|
+
#applyMode() {
|
|
39
|
+
const mode = this.#keepOpenOn ? "manual" : "auto";
|
|
40
|
+
if (!this.isConnected || this.getAttribute("popover") === mode)
|
|
41
|
+
return;
|
|
42
|
+
const showing = hasPopoverApi(this) && this.matches(":popover-open");
|
|
43
|
+
if (showing && !this.open)
|
|
44
|
+
return;
|
|
45
|
+
if (!showing)
|
|
46
|
+
return this.setAttribute("popover", mode);
|
|
47
|
+
this.#switching = true;
|
|
48
|
+
try {
|
|
49
|
+
this.hidePopover();
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
this.#switching = false;
|
|
53
|
+
}
|
|
54
|
+
this.setAttribute("popover", mode);
|
|
55
|
+
try {
|
|
56
|
+
this.showPopover(this.#anchor ? { source: this.#anchor } : undefined);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
this.toggleAttribute("data-fallback", true);
|
|
60
|
+
this.#watch();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
connectedCallback() {
|
|
64
|
+
super.connectedCallback();
|
|
65
|
+
if (!this.hasAttribute("popover"))
|
|
66
|
+
this.setAttribute("popover", this.#keepOpenOn ? "manual" : "auto");
|
|
67
|
+
else
|
|
68
|
+
this.#applyMode();
|
|
69
|
+
this.addEventListener("beforetoggle", this.#onBeforeToggle);
|
|
70
|
+
this.addEventListener("keydown", this.#onKey);
|
|
71
|
+
this.addEventListener("focusout", this.#onFocusOut);
|
|
72
|
+
}
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
this.hide();
|
|
75
|
+
this.#anchor?.removeEventListener("pointerdown", this.#onAnchorDown, true);
|
|
76
|
+
this.removeEventListener("beforetoggle", this.#onBeforeToggle);
|
|
77
|
+
this.removeEventListener("keydown", this.#onKey);
|
|
78
|
+
this.removeEventListener("focusout", this.#onFocusOut);
|
|
79
|
+
super.disconnectedCallback();
|
|
80
|
+
}
|
|
81
|
+
get open() {
|
|
82
|
+
return this.hasAttribute("data-open");
|
|
83
|
+
}
|
|
84
|
+
get opener() {
|
|
85
|
+
return this.#anchor;
|
|
86
|
+
}
|
|
87
|
+
show(anchor) {
|
|
88
|
+
if (this.open)
|
|
89
|
+
return;
|
|
90
|
+
this.#anchor?.removeEventListener("pointerdown", this.#onAnchorDown, true);
|
|
91
|
+
this.#anchor = anchor;
|
|
92
|
+
this.#anchorPressedAt = -Infinity;
|
|
93
|
+
anchor.addEventListener("pointerdown", this.#onAnchorDown, true);
|
|
94
|
+
this.#applyMode();
|
|
95
|
+
this.toggleAttribute("data-open", true);
|
|
96
|
+
let topLayer = false;
|
|
97
|
+
if (hasPopoverApi(this)) {
|
|
98
|
+
try {
|
|
99
|
+
this.showPopover({ source: anchor });
|
|
100
|
+
topLayer = true;
|
|
101
|
+
}
|
|
102
|
+
catch {
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (!topLayer)
|
|
106
|
+
this.toggleAttribute("data-fallback", true);
|
|
107
|
+
this.#watch();
|
|
108
|
+
this.#stopPlacing = place(anchor, this, { placement: this.placement, fitHeight: true });
|
|
109
|
+
this.dispatchEvent(new CustomEvent(OPEN, { bubbles: true }));
|
|
110
|
+
}
|
|
111
|
+
reanchor(anchor) {
|
|
112
|
+
if (!this.open || anchor === this.#anchor)
|
|
113
|
+
return;
|
|
114
|
+
this.#anchor?.removeEventListener("pointerdown", this.#onAnchorDown, true);
|
|
115
|
+
this.#anchor = anchor;
|
|
116
|
+
anchor.addEventListener("pointerdown", this.#onAnchorDown, true);
|
|
117
|
+
this.#stopPlacing?.();
|
|
118
|
+
this.#stopPlacing = place(anchor, this, { placement: this.placement, fitHeight: true });
|
|
119
|
+
}
|
|
120
|
+
hide() {
|
|
121
|
+
if (!this.open)
|
|
122
|
+
return;
|
|
123
|
+
if (this.matches(":popover-open"))
|
|
124
|
+
this.hidePopover();
|
|
125
|
+
if (this.open)
|
|
126
|
+
this.#closed();
|
|
127
|
+
}
|
|
128
|
+
toggle(anchor) {
|
|
129
|
+
if (this.open)
|
|
130
|
+
return this.hide();
|
|
131
|
+
const closedByThisPress = anchor === this.#anchor && performance.now() - this.#anchorPressedAt < PRESS_TO_CLICK_MS;
|
|
132
|
+
this.#anchorPressedAt = -Infinity;
|
|
133
|
+
if (!closedByThisPress)
|
|
134
|
+
this.show(anchor);
|
|
135
|
+
}
|
|
136
|
+
#onAnchorDown = () => {
|
|
137
|
+
if (this.open)
|
|
138
|
+
this.#anchorPressedAt = performance.now();
|
|
139
|
+
};
|
|
140
|
+
#onBeforeToggle = (e) => {
|
|
141
|
+
if (e.newState === "closed" && this.open && !this.#switching)
|
|
142
|
+
this.#closed();
|
|
143
|
+
};
|
|
144
|
+
#onKey = (e) => {
|
|
145
|
+
if (e.key === "Escape" && (this.hasAttribute("data-fallback") || this.#keepOpenOn) && !e.defaultPrevented) {
|
|
146
|
+
e.preventDefault();
|
|
147
|
+
this.hide();
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
#onFocusOut = (e) => {
|
|
151
|
+
const to = e.relatedTarget;
|
|
152
|
+
if (this.open && to && !within(this, to))
|
|
153
|
+
this.hide();
|
|
154
|
+
};
|
|
155
|
+
#watch() {
|
|
156
|
+
this.#stopWatching?.();
|
|
157
|
+
this.#stopWatching = null;
|
|
158
|
+
const container = this.ui?.container;
|
|
159
|
+
if (!this.open || !container || !(this.#keepOpenOn || this.hasAttribute("data-fallback")))
|
|
160
|
+
return;
|
|
161
|
+
const onDown = (e) => {
|
|
162
|
+
if (this.#keepOpenOn && e.button !== 0)
|
|
163
|
+
return;
|
|
164
|
+
const path = e.composedPath();
|
|
165
|
+
if (path.includes(this) || (this.#anchor && path.includes(this.#anchor)) || this.#keepOpenOn?.(e))
|
|
166
|
+
return;
|
|
167
|
+
this.hide();
|
|
168
|
+
};
|
|
169
|
+
const inUi = (e) => e.composedPath().some((n) => !!n[CONTEXT]);
|
|
170
|
+
const down = (e) => {
|
|
171
|
+
if (!this.#keepOpenOn || inUi(e))
|
|
172
|
+
onDown(e);
|
|
173
|
+
};
|
|
174
|
+
const up = (e) => {
|
|
175
|
+
if (this.#keepOpenOn && !inUi(e))
|
|
176
|
+
onDown(e);
|
|
177
|
+
};
|
|
178
|
+
const root = this.#keepOpenOn ? this.#root() : null;
|
|
179
|
+
const watched = root && !within(container, root) ? [container, root] : [container];
|
|
180
|
+
for (const el of watched) {
|
|
181
|
+
el.addEventListener("pointerdown", down, true);
|
|
182
|
+
el.addEventListener("pointerdown", up);
|
|
183
|
+
}
|
|
184
|
+
this.#stopWatching = () => watched.forEach((el) => {
|
|
185
|
+
el.removeEventListener("pointerdown", down, true);
|
|
186
|
+
el.removeEventListener("pointerdown", up);
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
#root() {
|
|
190
|
+
for (let n = this.parentNode; n; n = n.parentNode ?? n.host ?? null) {
|
|
191
|
+
if (n[CONTEXT])
|
|
192
|
+
return n;
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
#closed() {
|
|
197
|
+
cancelDragsWithin(this);
|
|
198
|
+
this.removeAttribute("data-open");
|
|
199
|
+
this.removeAttribute("data-fallback");
|
|
200
|
+
this.#stopPlacing?.();
|
|
201
|
+
this.#stopPlacing = null;
|
|
202
|
+
this.#stopWatching?.();
|
|
203
|
+
this.#stopWatching = null;
|
|
204
|
+
this.dispatchEvent(new CustomEvent(CLOSE, { bubbles: true }));
|
|
205
|
+
if (!focusWithin(this))
|
|
206
|
+
return;
|
|
207
|
+
const opener = this.#anchor;
|
|
208
|
+
const parent = this.#openParent();
|
|
209
|
+
if (parent && opener instanceof HTMLElement && within(parent, opener))
|
|
210
|
+
opener.focus({ preventScroll: true });
|
|
211
|
+
if (focusWithin(this))
|
|
212
|
+
this.ui?.returnFocus();
|
|
213
|
+
}
|
|
214
|
+
#openParent() {
|
|
215
|
+
for (let n = this.parentNode; n; n = n.parentNode ?? n.host ?? null) {
|
|
216
|
+
if (n instanceof _a && n.open)
|
|
217
|
+
return n;
|
|
218
|
+
}
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
render() {
|
|
222
|
+
return html `<slot></slot>`;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
_a = Popover;
|
|
226
|
+
const itemStyles = css `
|
|
227
|
+
[role="menu"]{display: flex;flex-direction: column;outline: none;}.item{display: flex;align-items: center;gap: 8px;min-height: 28px;padding: 0 10px 0 6px;border-radius: calc(${tok("radius")} - 4px);text-align: left;white-space: nowrap;}.item:hover:not(:disabled),
|
|
228
|
+
.item:focus{background: ${tok("hover")};}.check{display: inline-flex;width: 14px;color: ${tok("accent")};}.label{flex: 1;}.shortcut{color: ${tok("muted")};padding-left: 16px;}.sep{height: 1px;margin: 4px 2px;background: ${tok("border")};}`;
|
|
229
|
+
export class Menu extends UiElement {
|
|
230
|
+
static styles = [baseStyles, itemStyles];
|
|
231
|
+
static properties = { items: { attribute: false }, label: {}, placement: {} };
|
|
232
|
+
#focused = false;
|
|
233
|
+
constructor() {
|
|
234
|
+
super();
|
|
235
|
+
this.items = [];
|
|
236
|
+
this.label = "";
|
|
237
|
+
this.placement = "bottom-start";
|
|
238
|
+
}
|
|
239
|
+
get open() {
|
|
240
|
+
return this.#popover()?.open ?? false;
|
|
241
|
+
}
|
|
242
|
+
async show(anchor, focus = "checked") {
|
|
243
|
+
if (!this.hasUpdated)
|
|
244
|
+
await this.updateComplete;
|
|
245
|
+
const pop = this.#popover();
|
|
246
|
+
if (!pop)
|
|
247
|
+
return;
|
|
248
|
+
pop.show(anchor);
|
|
249
|
+
this.#focusItem(focus);
|
|
250
|
+
}
|
|
251
|
+
hide(returnFocus = false) {
|
|
252
|
+
const pop = this.#popover();
|
|
253
|
+
const anchor = pop?.opener;
|
|
254
|
+
pop?.hide();
|
|
255
|
+
if (returnFocus)
|
|
256
|
+
anchor?.focus();
|
|
257
|
+
}
|
|
258
|
+
toggle(anchor) {
|
|
259
|
+
const pop = this.#popover();
|
|
260
|
+
if (!pop)
|
|
261
|
+
return;
|
|
262
|
+
if (pop.open)
|
|
263
|
+
return this.hide();
|
|
264
|
+
pop.toggle(anchor);
|
|
265
|
+
if (pop.open)
|
|
266
|
+
this.#focusItem("checked");
|
|
267
|
+
}
|
|
268
|
+
#focusItem(focus) {
|
|
269
|
+
const items = this.#buttons();
|
|
270
|
+
const checked = items.findIndex((b) => b.getAttribute("aria-checked") === "true");
|
|
271
|
+
const at = focus === "last" ? items.length - 1 : focus === "checked" && checked >= 0 ? checked : 0;
|
|
272
|
+
items[at]?.focus();
|
|
273
|
+
}
|
|
274
|
+
#popover() {
|
|
275
|
+
return this.renderRoot?.querySelector("daas-popover") ?? null;
|
|
276
|
+
}
|
|
277
|
+
#buttons() {
|
|
278
|
+
return [...this.renderRoot.querySelectorAll("button.item:not(:disabled)")];
|
|
279
|
+
}
|
|
280
|
+
#pick(item) {
|
|
281
|
+
if (item.disabled)
|
|
282
|
+
return;
|
|
283
|
+
const focusInside = this.#focused;
|
|
284
|
+
emit(this, COMMIT, item.value);
|
|
285
|
+
this.hide(focusInside);
|
|
286
|
+
}
|
|
287
|
+
#keys(e) {
|
|
288
|
+
const items = this.#buttons();
|
|
289
|
+
const at = items.indexOf(e.target);
|
|
290
|
+
const move = (to) => {
|
|
291
|
+
e.preventDefault();
|
|
292
|
+
items[(to + items.length) % items.length]?.focus();
|
|
293
|
+
};
|
|
294
|
+
switch (e.key) {
|
|
295
|
+
case "ArrowDown":
|
|
296
|
+
return move(at + 1);
|
|
297
|
+
case "ArrowUp":
|
|
298
|
+
return move(at < 0 ? items.length - 1 : at - 1);
|
|
299
|
+
case "Home":
|
|
300
|
+
return move(0);
|
|
301
|
+
case "End":
|
|
302
|
+
return move(items.length - 1);
|
|
303
|
+
case "Escape":
|
|
304
|
+
e.preventDefault();
|
|
305
|
+
e.stopPropagation();
|
|
306
|
+
return this.hide(true);
|
|
307
|
+
case "Tab":
|
|
308
|
+
return this.hide();
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
render() {
|
|
312
|
+
const relay = (e) => this.dispatchEvent(new CustomEvent(e.type, { bubbles: true }));
|
|
313
|
+
return html `<daas-popover part="popover" placement=${this.placement} @daas-open=${relay} @daas-close=${relay}>
|
|
314
|
+
<div role="menu" aria-label=${this.label || nothing} @keydown=${(e) => this.#keys(e)} @focusin=${() => (this.#focused = true)} @focusout=${(e) => (this.#focused = !!e.relatedTarget && this.shadowRoot.contains(e.relatedTarget))} >
|
|
315
|
+
${this.items.map((it) => it === "separator"
|
|
316
|
+
? html `<div class="sep" role="separator"></div>`
|
|
317
|
+
: html `<button class="item" part="item" role=${it.checked === undefined ? "menuitem" : "menuitemradio"} aria-checked=${it.checked === undefined ? nothing : String(it.checked)} aria-keyshortcuts=${this.shortcutAria(it.shortcut) || nothing} tabindex="-1" ?disabled=${it.disabled} @mousedown=${keepFocus} @pointerenter=${(e) => e.currentTarget.focus()} @click=${() => this.#pick(it)} >
|
|
318
|
+
${it.checked !== undefined ? html `<span class="check">${it.checked ? this.drawIcon("check", 14) : nothing}</span>` : nothing}
|
|
319
|
+
${it.icon ? this.drawIcon(it.icon) : nothing}<span class="label">${it.label}</span>${it.shortcut ? html `<span class="shortcut">${this.shortcutText(it.shortcut)}</span>` : nothing}
|
|
320
|
+
</button>`)}
|
|
321
|
+
</div>
|
|
322
|
+
</daas-popover>`;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
export class Select extends UiElement {
|
|
326
|
+
static styles = [
|
|
327
|
+
baseStyles,
|
|
328
|
+
css `
|
|
329
|
+
:host{display: inline-flex;min-width: 0;}.trigger{display: flex;align-items: center;gap: 4px;width: 100%;height: ${tok("control")};padding: 0 6px 0 8px;border: 1px solid ${tok("border")};border-radius: calc(${tok("radius")} - 4px);background: ${tok("bg")};}.trigger:hover:not(:disabled){border-color: ${tok("borderStrong")};}.value{flex: 1;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;text-align: left;}.value.mixed{color: ${tok("muted")};}`,
|
|
330
|
+
];
|
|
331
|
+
static properties = { options: { attribute: false }, value: {}, mixed: { type: Boolean }, label: {}, disabled: { type: Boolean, reflect: true } };
|
|
332
|
+
constructor() {
|
|
333
|
+
super();
|
|
334
|
+
this.options = [];
|
|
335
|
+
this.value = null;
|
|
336
|
+
this.mixed = false;
|
|
337
|
+
this.label = "";
|
|
338
|
+
this.disabled = false;
|
|
339
|
+
}
|
|
340
|
+
#menu() {
|
|
341
|
+
return this.renderRoot.querySelector("daas-menu");
|
|
342
|
+
}
|
|
343
|
+
#trigger() {
|
|
344
|
+
return this.renderRoot.querySelector(".trigger");
|
|
345
|
+
}
|
|
346
|
+
#keys(e) {
|
|
347
|
+
if (e.key !== "ArrowDown" && e.key !== "ArrowUp")
|
|
348
|
+
return;
|
|
349
|
+
e.preventDefault();
|
|
350
|
+
void this.#menu()?.show(this.#trigger(), e.key === "ArrowUp" ? "last" : "checked");
|
|
351
|
+
this.requestUpdate();
|
|
352
|
+
}
|
|
353
|
+
render() {
|
|
354
|
+
const current = this.options.find((o) => o.value === this.value);
|
|
355
|
+
const open = this.#menu()?.open ?? false;
|
|
356
|
+
return html `<button class="trigger" part="trigger" aria-haspopup="menu" aria-expanded=${open ? "true" : "false"} aria-label=${this.label || nothing} ?disabled=${this.disabled} @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${() => {
|
|
357
|
+
this.#menu()?.toggle(this.#trigger());
|
|
358
|
+
this.requestUpdate();
|
|
359
|
+
}} @keydown=${(e) => this.#keys(e)} >
|
|
360
|
+
${current?.icon && !this.mixed ? this.drawIcon(current.icon, 14) : nothing}<span class="value ${this.mixed ? "mixed" : ""}">${this.mixed ? this.t("value.mixed") : (current?.label ?? "")}</span >${this.drawIcon("chevron-down", 14)}</button ><daas-menu .items=${this.options.map((o) => ({ ...o, checked: !this.mixed && o.value === this.value }))} label=${this.label} @daas-commit=${(e) => {
|
|
361
|
+
e.stopPropagation();
|
|
362
|
+
if (this.mixed || e.detail !== this.value)
|
|
363
|
+
emit(this, COMMIT, e.detail);
|
|
364
|
+
}} @daas-close=${() => this.requestUpdate()} @daas-open=${() => this.requestUpdate()} ></daas-menu>`;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { UiContext } from "../element.js";
|
|
2
|
+
export declare const PREVIEW = "daas-preview";
|
|
3
|
+
export declare const COMMIT = "daas-commit";
|
|
4
|
+
export declare const CANCEL = "daas-cancel";
|
|
5
|
+
export declare function emit(el: HTMLElement, type: typeof PREVIEW | typeof COMMIT | typeof CANCEL, value?: unknown): void;
|
|
6
|
+
export declare const keepFocus: (e: Event) => void;
|
|
7
|
+
export declare const clamp: (v: number, lo: number, hi: number) => number;
|
|
8
|
+
export declare function decimalsOf(step: number): number;
|
|
9
|
+
export declare const roundTo: (v: number, step: number) => number;
|
|
10
|
+
export interface DragCallbacks {
|
|
11
|
+
move(e: PointerEvent): void;
|
|
12
|
+
commit(moved: boolean): void;
|
|
13
|
+
cancel(): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function within(ancestor: Node, node: Node | null): boolean;
|
|
16
|
+
export declare function focused(doc: Document | null): Element | null;
|
|
17
|
+
export declare const focusWithin: (node: Node) => boolean;
|
|
18
|
+
export declare function cancelDragsWithin(node: Node): void;
|
|
19
|
+
export declare function draggingWithin(node: Node): Element | null;
|
|
20
|
+
export declare class Drag {
|
|
21
|
+
#private;
|
|
22
|
+
private readonly cb;
|
|
23
|
+
constructor(cb: DragCallbacks);
|
|
24
|
+
get active(): boolean;
|
|
25
|
+
get target(): Element | null;
|
|
26
|
+
start(e: PointerEvent, target: Element, ctx: UiContext | null): boolean;
|
|
27
|
+
inside(node: Node): boolean;
|
|
28
|
+
cancel(): void;
|
|
29
|
+
}
|
|
30
|
+
export declare const baseStyles: import("lit").CSSResult;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
import { tok } from "../theme.js";
|
|
3
|
+
export const PREVIEW = "daas-preview";
|
|
4
|
+
export const COMMIT = "daas-commit";
|
|
5
|
+
export const CANCEL = "daas-cancel";
|
|
6
|
+
export function emit(el, type, value) {
|
|
7
|
+
el.dispatchEvent(new CustomEvent(type, { detail: value, bubbles: true }));
|
|
8
|
+
}
|
|
9
|
+
export const keepFocus = (e) => e.preventDefault();
|
|
10
|
+
export const clamp = (v, lo, hi) => (v < lo ? lo : v > hi ? hi : v);
|
|
11
|
+
export function decimalsOf(step) {
|
|
12
|
+
if (!Number.isFinite(step) || step <= 0)
|
|
13
|
+
return 0;
|
|
14
|
+
const s = String(step);
|
|
15
|
+
if (s.includes("e-"))
|
|
16
|
+
return Number(s.split("e-")[1]);
|
|
17
|
+
return s.includes(".") ? s.length - s.indexOf(".") - 1 : 0;
|
|
18
|
+
}
|
|
19
|
+
export const roundTo = (v, step) => Number(v.toFixed(Math.min(20, decimalsOf(step))));
|
|
20
|
+
export function within(ancestor, node) {
|
|
21
|
+
for (let n = node; n; n = n.parentNode ?? n.host ?? null)
|
|
22
|
+
if (n === ancestor)
|
|
23
|
+
return true;
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
export function focused(doc) {
|
|
27
|
+
try {
|
|
28
|
+
let active = doc?.activeElement ?? null;
|
|
29
|
+
while (active?.shadowRoot?.activeElement)
|
|
30
|
+
active = active.shadowRoot.activeElement;
|
|
31
|
+
return active;
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export const focusWithin = (node) => within(node, focused(node.ownerDocument));
|
|
38
|
+
const running = new Set();
|
|
39
|
+
export function cancelDragsWithin(node) {
|
|
40
|
+
for (const drag of [...running])
|
|
41
|
+
if (drag.inside(node))
|
|
42
|
+
drag.cancel();
|
|
43
|
+
}
|
|
44
|
+
export function draggingWithin(node) {
|
|
45
|
+
for (const drag of running)
|
|
46
|
+
if (drag.inside(node))
|
|
47
|
+
return drag.target;
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
export class Drag {
|
|
51
|
+
cb;
|
|
52
|
+
#pointer = null;
|
|
53
|
+
#target = null;
|
|
54
|
+
#moved = false;
|
|
55
|
+
#endRoot = null;
|
|
56
|
+
constructor(cb) {
|
|
57
|
+
this.cb = cb;
|
|
58
|
+
}
|
|
59
|
+
get active() {
|
|
60
|
+
return this.#pointer !== null;
|
|
61
|
+
}
|
|
62
|
+
get target() {
|
|
63
|
+
return this.#target;
|
|
64
|
+
}
|
|
65
|
+
start(e, target, ctx) {
|
|
66
|
+
if (e.button !== 0 || this.active)
|
|
67
|
+
return false;
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
this.#pointer = e.pointerId;
|
|
70
|
+
this.#target = target;
|
|
71
|
+
this.#moved = false;
|
|
72
|
+
try {
|
|
73
|
+
target.setPointerCapture(e.pointerId);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
}
|
|
77
|
+
target.addEventListener("pointermove", this.#onMove);
|
|
78
|
+
target.addEventListener("pointerup", this.#onUp);
|
|
79
|
+
target.addEventListener("pointercancel", this.#onLost);
|
|
80
|
+
target.addEventListener("lostpointercapture", this.#onLost);
|
|
81
|
+
running.add(this);
|
|
82
|
+
this.#endRoot = ctx?.beginDrag(() => this.cancel()) ?? null;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
inside(node) {
|
|
86
|
+
return within(node, this.#target);
|
|
87
|
+
}
|
|
88
|
+
cancel() {
|
|
89
|
+
if (!this.active)
|
|
90
|
+
return;
|
|
91
|
+
this.#finish();
|
|
92
|
+
this.cb.cancel();
|
|
93
|
+
}
|
|
94
|
+
#onMove = (e) => {
|
|
95
|
+
if (e.pointerId !== this.#pointer)
|
|
96
|
+
return;
|
|
97
|
+
this.#moved = true;
|
|
98
|
+
this.cb.move(e);
|
|
99
|
+
};
|
|
100
|
+
#onUp = (e) => {
|
|
101
|
+
if (e.pointerId !== this.#pointer)
|
|
102
|
+
return;
|
|
103
|
+
const moved = this.#moved;
|
|
104
|
+
this.#finish();
|
|
105
|
+
this.cb.commit(moved);
|
|
106
|
+
};
|
|
107
|
+
#onLost = (e) => {
|
|
108
|
+
if (e.pointerId === this.#pointer)
|
|
109
|
+
this.cancel();
|
|
110
|
+
};
|
|
111
|
+
#finish() {
|
|
112
|
+
const target = this.#target;
|
|
113
|
+
const pointer = this.#pointer;
|
|
114
|
+
this.#pointer = null;
|
|
115
|
+
this.#target = null;
|
|
116
|
+
running.delete(this);
|
|
117
|
+
target.removeEventListener("pointermove", this.#onMove);
|
|
118
|
+
target.removeEventListener("pointerup", this.#onUp);
|
|
119
|
+
target.removeEventListener("pointercancel", this.#onLost);
|
|
120
|
+
target.removeEventListener("lostpointercapture", this.#onLost);
|
|
121
|
+
try {
|
|
122
|
+
if (target.hasPointerCapture(pointer))
|
|
123
|
+
target.releasePointerCapture(pointer);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
}
|
|
127
|
+
this.#endRoot?.();
|
|
128
|
+
this.#endRoot = null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
export const baseStyles = css `
|
|
132
|
+
:host{box-sizing: border-box;font-family: ${tok("font")};font-size: 12px;line-height: 16px;color: ${tok("fg")};}*,
|
|
133
|
+
*::before,
|
|
134
|
+
*::after{box-sizing: inherit;}button{font: inherit;color: inherit;margin: 0;padding: 0;border: 0;background: none;cursor: pointer;}button:disabled{cursor: default;opacity: 0.45;}:focus{outline: none;}:focus-visible{outline: 2px solid ${tok("accent")};outline-offset: 1px;}.icon{display: block;flex: none;}`;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { UiElement } from "../element.js";
|
|
2
|
+
export declare const checkerUnder: (background: string) => string;
|
|
3
|
+
export declare class Slider extends UiElement {
|
|
4
|
+
#private;
|
|
5
|
+
static styles: import("lit").CSSResult[];
|
|
6
|
+
static properties: {
|
|
7
|
+
value: {
|
|
8
|
+
type: NumberConstructor;
|
|
9
|
+
};
|
|
10
|
+
min: {
|
|
11
|
+
type: NumberConstructor;
|
|
12
|
+
};
|
|
13
|
+
max: {
|
|
14
|
+
type: NumberConstructor;
|
|
15
|
+
};
|
|
16
|
+
step: {
|
|
17
|
+
type: NumberConstructor;
|
|
18
|
+
};
|
|
19
|
+
label: {};
|
|
20
|
+
valueText: {
|
|
21
|
+
attribute: boolean;
|
|
22
|
+
};
|
|
23
|
+
track: {};
|
|
24
|
+
mixed: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
};
|
|
27
|
+
disabled: {
|
|
28
|
+
type: BooleanConstructor;
|
|
29
|
+
reflect: boolean;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
value: number;
|
|
33
|
+
min: number;
|
|
34
|
+
max: number;
|
|
35
|
+
step: number;
|
|
36
|
+
label: string;
|
|
37
|
+
valueText: ((v: number) => string) | undefined;
|
|
38
|
+
track: string | undefined;
|
|
39
|
+
mixed: boolean;
|
|
40
|
+
disabled: boolean;
|
|
41
|
+
constructor();
|
|
42
|
+
disconnectedCallback(): void;
|
|
43
|
+
requestUpdate(...args: Parameters<UiElement["requestUpdate"]>): void;
|
|
44
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
45
|
+
}
|
|
46
|
+
export interface AreaValue {
|
|
47
|
+
x: number;
|
|
48
|
+
y: number;
|
|
49
|
+
}
|
|
50
|
+
export declare class ColorArea extends UiElement {
|
|
51
|
+
#private;
|
|
52
|
+
static styles: import("lit").CSSResult[];
|
|
53
|
+
static properties: {
|
|
54
|
+
hue: {
|
|
55
|
+
type: NumberConstructor;
|
|
56
|
+
};
|
|
57
|
+
x: {
|
|
58
|
+
type: NumberConstructor;
|
|
59
|
+
};
|
|
60
|
+
y: {
|
|
61
|
+
type: NumberConstructor;
|
|
62
|
+
};
|
|
63
|
+
label: {};
|
|
64
|
+
mixed: {
|
|
65
|
+
type: BooleanConstructor;
|
|
66
|
+
};
|
|
67
|
+
disabled: {
|
|
68
|
+
type: BooleanConstructor;
|
|
69
|
+
reflect: boolean;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
hue: number;
|
|
73
|
+
x: number;
|
|
74
|
+
y: number;
|
|
75
|
+
label: string;
|
|
76
|
+
mixed: boolean;
|
|
77
|
+
disabled: boolean;
|
|
78
|
+
constructor();
|
|
79
|
+
disconnectedCallback(): void;
|
|
80
|
+
requestUpdate(...args: Parameters<UiElement["requestUpdate"]>): void;
|
|
81
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
82
|
+
}
|