@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,178 @@
|
|
|
1
|
+
import { css, html, nothing } from "lit";
|
|
2
|
+
import { live } from "lit/directives/live.js";
|
|
3
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
4
|
+
import { UiElement } from "../element.js";
|
|
5
|
+
import { DEFAULT_STRINGS } from "../strings.js";
|
|
6
|
+
import { tok } from "../theme.js";
|
|
7
|
+
import { baseStyles, COMMIT, emit, focusWithin, keepFocus } from "./shared.js";
|
|
8
|
+
export const FONT_ROW_PX = 28;
|
|
9
|
+
export const FONT_LIST_PX = 240;
|
|
10
|
+
export const FONT_VIRTUAL_PAST = 100;
|
|
11
|
+
const OVERSCAN = 6;
|
|
12
|
+
export function weightFor(f, current) {
|
|
13
|
+
if (current !== null && f.weights.includes(current))
|
|
14
|
+
return current;
|
|
15
|
+
return f.weights.includes(400) ? 400 : (f.weights[0] ?? 400);
|
|
16
|
+
}
|
|
17
|
+
export class FontPicker extends UiElement {
|
|
18
|
+
static styles = [
|
|
19
|
+
baseStyles,
|
|
20
|
+
css `
|
|
21
|
+
:host{display: flex;flex-direction: column;gap: 6px;width: 220px;}.search{height: ${tok("control")};padding: 0 8px;border: 1px solid ${tok("border")};border-radius: calc(${tok("radius")} - 4px);background: ${tok("bg")};font: inherit;color: inherit;outline: none;}.search:focus{border-color: ${tok("accent")};}.list{position: relative;overflow-y: auto;outline: none;}.row{display: flex;align-items: center;height: ${FONT_ROW_PX}px;
|
|
22
|
+
padding: 0 8px;
|
|
23
|
+
border-radius: calc(${tok("radius")} - 4px);
|
|
24
|
+
white-space: nowrap;
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
text-overflow: ellipsis;
|
|
27
|
+
cursor: pointer;
|
|
28
|
+
}
|
|
29
|
+
.virtual .row {
|
|
30
|
+
position: absolute;
|
|
31
|
+
left: 0;
|
|
32
|
+
right: 0;
|
|
33
|
+
}
|
|
34
|
+
.row:hover,
|
|
35
|
+
.row.active {
|
|
36
|
+
background: ${tok("hover")};
|
|
37
|
+
}
|
|
38
|
+
.row[aria-selected="true"] {
|
|
39
|
+
color: ${tok("accent")};
|
|
40
|
+
}
|
|
41
|
+
.empty {
|
|
42
|
+
padding: 8px;
|
|
43
|
+
color: ${tok("muted")};
|
|
44
|
+
}
|
|
45
|
+
`,
|
|
46
|
+
];
|
|
47
|
+
static properties = { fonts: { attribute: false }, value: {}, weight: { type: Number }, mixed: { type: Boolean } };
|
|
48
|
+
#query = "";
|
|
49
|
+
#active = -1;
|
|
50
|
+
#scrollTop = 0;
|
|
51
|
+
constructor() {
|
|
52
|
+
super();
|
|
53
|
+
this.fonts = [];
|
|
54
|
+
this.value = null;
|
|
55
|
+
this.weight = null;
|
|
56
|
+
this.mixed = false;
|
|
57
|
+
}
|
|
58
|
+
get results() {
|
|
59
|
+
return this.#matching(this.fonts);
|
|
60
|
+
}
|
|
61
|
+
#matching(fonts) {
|
|
62
|
+
const q = this.#query.trim().toLowerCase();
|
|
63
|
+
if (!q)
|
|
64
|
+
return fonts;
|
|
65
|
+
return fonts.filter((f) => f.family.toLowerCase().includes(q) || (f.label ?? "").toLowerCase().includes(q));
|
|
66
|
+
}
|
|
67
|
+
willUpdate(changed) {
|
|
68
|
+
const shown = this.mixed ? undefined : this.fonts.find((f) => f.family === this.value);
|
|
69
|
+
const select = shown?.weights.length ? null : this.renderRoot?.querySelector("daas-select[part=weight]");
|
|
70
|
+
if (select && focusWithin(select))
|
|
71
|
+
this.renderRoot.querySelector(".search")?.focus({ preventScroll: true });
|
|
72
|
+
if (!changed.has("fonts"))
|
|
73
|
+
return;
|
|
74
|
+
const before = changed.get("fonts");
|
|
75
|
+
const family = before ? this.#matching(before)[this.#active]?.family : undefined;
|
|
76
|
+
const list = this.results;
|
|
77
|
+
this.#active = family === undefined ? -1 : list.findIndex((f) => f.family === family);
|
|
78
|
+
const end = Math.max(0, list.length * FONT_ROW_PX - FONT_LIST_PX);
|
|
79
|
+
if (this.#scrollTop > end) {
|
|
80
|
+
this.#scrollTop = end;
|
|
81
|
+
const el = this.renderRoot.querySelector(".list");
|
|
82
|
+
if (el)
|
|
83
|
+
el.scrollTop = end;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
#pick(f) {
|
|
87
|
+
const weight = weightFor(f, this.weight);
|
|
88
|
+
if (!this.mixed && f.family === this.value && weight === this.weight)
|
|
89
|
+
return;
|
|
90
|
+
emit(this, COMMIT, { family: f.family, weight });
|
|
91
|
+
}
|
|
92
|
+
#keys(e) {
|
|
93
|
+
const list = this.results;
|
|
94
|
+
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
if (list.length === 0)
|
|
97
|
+
return;
|
|
98
|
+
this.#active = e.key === "ArrowDown" ? Math.min(list.length - 1, this.#active + 1) : Math.max(0, this.#active - 1);
|
|
99
|
+
this.#reveal(this.#active);
|
|
100
|
+
this.requestUpdate();
|
|
101
|
+
}
|
|
102
|
+
else if (e.key === "Enter") {
|
|
103
|
+
const f = list[this.#active] ?? (list.length === 1 ? list[0] : undefined);
|
|
104
|
+
if (!f)
|
|
105
|
+
return;
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
this.#pick(f);
|
|
108
|
+
}
|
|
109
|
+
else if (e.key === "Escape" && this.#query) {
|
|
110
|
+
e.preventDefault();
|
|
111
|
+
e.stopPropagation();
|
|
112
|
+
this.#query = "";
|
|
113
|
+
this.#active = -1;
|
|
114
|
+
this.requestUpdate();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
#reveal(i) {
|
|
118
|
+
const list = this.renderRoot.querySelector(".list");
|
|
119
|
+
if (!list)
|
|
120
|
+
return;
|
|
121
|
+
const top = i * FONT_ROW_PX;
|
|
122
|
+
if (top < list.scrollTop)
|
|
123
|
+
list.scrollTop = top;
|
|
124
|
+
else if (top + FONT_ROW_PX > list.scrollTop + FONT_LIST_PX)
|
|
125
|
+
list.scrollTop = top + FONT_ROW_PX - FONT_LIST_PX;
|
|
126
|
+
this.#scrollTop = list.scrollTop;
|
|
127
|
+
}
|
|
128
|
+
#weightLabel(w) {
|
|
129
|
+
const key = `weight.${w}`;
|
|
130
|
+
return key in DEFAULT_STRINGS ? this.t(key) : String(w);
|
|
131
|
+
}
|
|
132
|
+
#row(f, i, total, virtual) {
|
|
133
|
+
return html `<div class="row ${i === this.#active ? "active" : ""}" part="option" role="option" id="opt-${i}" aria-selected=${!this.mixed && f.family === this.value ? "true" : "false"} aria-setsize=${virtual ? total : nothing} aria-posinset=${virtual ? i + 1 : nothing} style=${virtual ? styleMap({ top: `${i * FONT_ROW_PX}px` }) : nothing} @pointerdown=${keepFocus} @mousedown=${keepFocus} @click=${() => this.#pick(f)} >
|
|
134
|
+
${f.label ?? f.family}
|
|
135
|
+
</div>`;
|
|
136
|
+
}
|
|
137
|
+
render() {
|
|
138
|
+
const list = this.results;
|
|
139
|
+
const virtual = list.length > FONT_VIRTUAL_PAST;
|
|
140
|
+
let rows;
|
|
141
|
+
if (virtual) {
|
|
142
|
+
const first = Math.max(0, Math.floor(this.#scrollTop / FONT_ROW_PX) - OVERSCAN);
|
|
143
|
+
const last = Math.min(list.length, Math.ceil((this.#scrollTop + FONT_LIST_PX) / FONT_ROW_PX) + OVERSCAN);
|
|
144
|
+
const shown = list.slice(first, last).map((f, k) => this.#row(f, first + k, list.length, true));
|
|
145
|
+
const a = this.#active;
|
|
146
|
+
const kept = list[a];
|
|
147
|
+
if (kept && a < first)
|
|
148
|
+
shown.unshift(this.#row(kept, a, list.length, true));
|
|
149
|
+
else if (kept && a >= last)
|
|
150
|
+
shown.push(this.#row(kept, a, list.length, true));
|
|
151
|
+
rows = html `<div style=${styleMap({ height: `${list.length * FONT_ROW_PX}px` })}>${shown}</div>`;
|
|
152
|
+
}
|
|
153
|
+
else
|
|
154
|
+
rows = list.map((f, i) => this.#row(f, i, list.length, false));
|
|
155
|
+
const family = this.mixed ? undefined : this.fonts.find((f) => f.family === this.value);
|
|
156
|
+
return html `<input class="search" part="search" type="search" role="combobox" aria-expanded="true" aria-controls="list" aria-autocomplete="list" aria-activedescendant=${this.#active >= 0 ? `opt-${this.#active}` : nothing} aria-label=${this.t("font.search")} placeholder=${this.t("font.search")} autocomplete="off" spellcheck="false" .value=${live(this.#query)} @input=${(e) => {
|
|
157
|
+
this.#query = e.target.value;
|
|
158
|
+
this.#active = this.results.length > 0 ? 0 : -1;
|
|
159
|
+
this.#scrollTop = 0;
|
|
160
|
+
const el = this.renderRoot.querySelector(".list");
|
|
161
|
+
if (el)
|
|
162
|
+
el.scrollTop = 0;
|
|
163
|
+
this.requestUpdate();
|
|
164
|
+
}} @keydown=${(e) => this.#keys(e)} />
|
|
165
|
+
<div id="list" class="list ${virtual ? "virtual" : ""}" part="list" role="listbox" aria-label=${this.t("font.families")} style=${styleMap({ height: `${FONT_LIST_PX}px` })} @scroll=${(e) => {
|
|
166
|
+
this.#scrollTop = e.target.scrollTop;
|
|
167
|
+
this.requestUpdate();
|
|
168
|
+
}} >
|
|
169
|
+
${list.length === 0 ? html `<div class="empty">${this.t("value.none")}</div>` : rows}
|
|
170
|
+
</div>
|
|
171
|
+
${family && family.weights.length > 0
|
|
172
|
+
? html `<daas-select part="weight" label=${this.t("font.weight")} .options=${family.weights.map((w) => ({ value: String(w), label: this.#weightLabel(w) }))} .value=${this.weight === null ? null : String(this.weight)} @daas-commit=${(e) => {
|
|
173
|
+
e.stopPropagation();
|
|
174
|
+
emit(this, COMMIT, { family: family.family, weight: Number(e.detail) });
|
|
175
|
+
}} ></daas-select>`
|
|
176
|
+
: nothing}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { IconButton, SegmentedControl, ToggleButton } from "./buttons.js";
|
|
2
|
+
import { FontPicker } from "./font-picker.js";
|
|
3
|
+
import { NumberField } from "./number-field.js";
|
|
4
|
+
import { Menu, Popover, Select } from "./popover.js";
|
|
5
|
+
import { ColorArea, Slider } from "./slider.js";
|
|
6
|
+
import { Swatch } from "./swatch.js";
|
|
7
|
+
export { IconButton, ToggleButton, SegmentedControl, type Segment } from "./buttons.js";
|
|
8
|
+
export { NumberField, parseNumber, formatNumber } from "./number-field.js";
|
|
9
|
+
export { Slider, ColorArea, checkerUnder, type AreaValue } from "./slider.js";
|
|
10
|
+
export { Popover, Menu, Select, OPEN, CLOSE, type MenuItem, type MenuEntry, type SelectOption } from "./popover.js";
|
|
11
|
+
export { Swatch, swatchBackground } from "./swatch.js";
|
|
12
|
+
export { FontPicker, weightFor, type FontChoice } from "./font-picker.js";
|
|
13
|
+
export { PREVIEW, COMMIT, CANCEL } from "./shared.js";
|
|
14
|
+
export { hasPopoverApi, place, type Placement, type PlaceOptions } from "./place.js";
|
|
15
|
+
export declare const CONTROL_TAGS: {
|
|
16
|
+
readonly "daas-icon-button": typeof IconButton;
|
|
17
|
+
readonly "daas-toggle-button": typeof ToggleButton;
|
|
18
|
+
readonly "daas-segmented": typeof SegmentedControl;
|
|
19
|
+
readonly "daas-number-field": typeof NumberField;
|
|
20
|
+
readonly "daas-slider": typeof Slider;
|
|
21
|
+
readonly "daas-color-area": typeof ColorArea;
|
|
22
|
+
readonly "daas-popover": typeof Popover;
|
|
23
|
+
readonly "daas-menu": typeof Menu;
|
|
24
|
+
readonly "daas-select": typeof Select;
|
|
25
|
+
readonly "daas-swatch": typeof Swatch;
|
|
26
|
+
readonly "daas-font-picker": typeof FontPicker;
|
|
27
|
+
};
|
|
28
|
+
export declare function defineControls(): void;
|
|
29
|
+
declare global {
|
|
30
|
+
interface HTMLElementTagNameMap {
|
|
31
|
+
"daas-icon-button": IconButton;
|
|
32
|
+
"daas-toggle-button": ToggleButton;
|
|
33
|
+
"daas-segmented": SegmentedControl;
|
|
34
|
+
"daas-number-field": NumberField;
|
|
35
|
+
"daas-slider": Slider;
|
|
36
|
+
"daas-color-area": ColorArea;
|
|
37
|
+
"daas-popover": Popover;
|
|
38
|
+
"daas-menu": Menu;
|
|
39
|
+
"daas-select": Select;
|
|
40
|
+
"daas-swatch": Swatch;
|
|
41
|
+
"daas-font-picker": FontPicker;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { IconButton, SegmentedControl, ToggleButton } from "./buttons.js";
|
|
2
|
+
import { FontPicker } from "./font-picker.js";
|
|
3
|
+
import { NumberField } from "./number-field.js";
|
|
4
|
+
import { Menu, Popover, Select } from "./popover.js";
|
|
5
|
+
import { ColorArea, Slider } from "./slider.js";
|
|
6
|
+
import { Swatch } from "./swatch.js";
|
|
7
|
+
export { IconButton, ToggleButton, SegmentedControl } from "./buttons.js";
|
|
8
|
+
export { NumberField, parseNumber, formatNumber } from "./number-field.js";
|
|
9
|
+
export { Slider, ColorArea, checkerUnder } from "./slider.js";
|
|
10
|
+
export { Popover, Menu, Select, OPEN, CLOSE } from "./popover.js";
|
|
11
|
+
export { Swatch, swatchBackground } from "./swatch.js";
|
|
12
|
+
export { FontPicker, weightFor } from "./font-picker.js";
|
|
13
|
+
export { PREVIEW, COMMIT, CANCEL } from "./shared.js";
|
|
14
|
+
export { hasPopoverApi, place } from "./place.js";
|
|
15
|
+
export const CONTROL_TAGS = {
|
|
16
|
+
"daas-icon-button": IconButton,
|
|
17
|
+
"daas-toggle-button": ToggleButton,
|
|
18
|
+
"daas-segmented": SegmentedControl,
|
|
19
|
+
"daas-number-field": NumberField,
|
|
20
|
+
"daas-slider": Slider,
|
|
21
|
+
"daas-color-area": ColorArea,
|
|
22
|
+
"daas-popover": Popover,
|
|
23
|
+
"daas-menu": Menu,
|
|
24
|
+
"daas-select": Select,
|
|
25
|
+
"daas-swatch": Swatch,
|
|
26
|
+
"daas-font-picker": FontPicker,
|
|
27
|
+
};
|
|
28
|
+
export function defineControls() {
|
|
29
|
+
for (const [tag, cls] of Object.entries(CONTROL_TAGS))
|
|
30
|
+
if (!customElements.get(tag))
|
|
31
|
+
customElements.define(tag, cls);
|
|
32
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type PropertyDeclarations, type TemplateResult } from "lit";
|
|
2
|
+
import { UiElement } from "../element.js";
|
|
3
|
+
import type { IconName } from "../icons/index.js";
|
|
4
|
+
export declare function parseNumber(text: string, unit?: string): number | null;
|
|
5
|
+
export declare const formatNumber: (v: number, precision?: number) => string;
|
|
6
|
+
export declare abstract class TypedField extends UiElement {
|
|
7
|
+
static styles: import("lit").CSSResult[];
|
|
8
|
+
static properties: PropertyDeclarations;
|
|
9
|
+
mixed: boolean;
|
|
10
|
+
name: string;
|
|
11
|
+
disabled: boolean;
|
|
12
|
+
protected draft: string | null;
|
|
13
|
+
constructor();
|
|
14
|
+
abstract commitDraft(): unknown;
|
|
15
|
+
discardDraft(): boolean;
|
|
16
|
+
protected takeDraft(): string | null;
|
|
17
|
+
protected onKey(e: KeyboardEvent): void;
|
|
18
|
+
protected input(text: string, placeholder: string, label: string, mode?: string, busy?: boolean): TemplateResult;
|
|
19
|
+
}
|
|
20
|
+
export declare class NumberField extends TypedField {
|
|
21
|
+
#private;
|
|
22
|
+
static properties: {
|
|
23
|
+
value: {
|
|
24
|
+
type: NumberConstructor;
|
|
25
|
+
};
|
|
26
|
+
min: {
|
|
27
|
+
type: NumberConstructor;
|
|
28
|
+
};
|
|
29
|
+
max: {
|
|
30
|
+
type: NumberConstructor;
|
|
31
|
+
};
|
|
32
|
+
step: {
|
|
33
|
+
type: NumberConstructor;
|
|
34
|
+
};
|
|
35
|
+
precision: {
|
|
36
|
+
type: NumberConstructor;
|
|
37
|
+
};
|
|
38
|
+
unit: {};
|
|
39
|
+
label: {};
|
|
40
|
+
labelIcon: {
|
|
41
|
+
attribute: string;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
value: number | null;
|
|
45
|
+
min: number;
|
|
46
|
+
max: number;
|
|
47
|
+
step: number;
|
|
48
|
+
precision: number;
|
|
49
|
+
unit: string;
|
|
50
|
+
label: string;
|
|
51
|
+
labelIcon: IconName | undefined;
|
|
52
|
+
constructor();
|
|
53
|
+
disconnectedCallback(): void;
|
|
54
|
+
requestUpdate(...args: Parameters<UiElement["requestUpdate"]>): void;
|
|
55
|
+
get scrubbing(): boolean;
|
|
56
|
+
get draftValue(): number | null;
|
|
57
|
+
commitDraft(): number | null;
|
|
58
|
+
protected onKey(e: KeyboardEvent): void;
|
|
59
|
+
protected render(): TemplateResult<1>;
|
|
60
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { css, html, nothing } from "lit";
|
|
2
|
+
import { live } from "lit/directives/live.js";
|
|
3
|
+
import { UiElement } from "../element.js";
|
|
4
|
+
import { tok } from "../theme.js";
|
|
5
|
+
import { baseStyles, CANCEL, clamp, COMMIT, decimalsOf, Drag, emit, PREVIEW } from "./shared.js";
|
|
6
|
+
export function parseNumber(text, unit = "") {
|
|
7
|
+
const m = /^\s*([-+]?(?:\d+(?:[.,]\d*)?|[.,]\d+))\s*(\S*)\s*$/.exec(text);
|
|
8
|
+
if (!m)
|
|
9
|
+
return null;
|
|
10
|
+
const u = m[2];
|
|
11
|
+
if (u !== "" && u.toLowerCase() !== unit.toLowerCase())
|
|
12
|
+
return null;
|
|
13
|
+
const n = Number(m[1].replace(",", "."));
|
|
14
|
+
return Number.isFinite(n) ? n : null;
|
|
15
|
+
}
|
|
16
|
+
export const formatNumber = (v, precision = 2) => String(Number(v.toFixed(precision)));
|
|
17
|
+
export class TypedField extends UiElement {
|
|
18
|
+
static styles = [
|
|
19
|
+
baseStyles,
|
|
20
|
+
css `
|
|
21
|
+
:host{display: inline-flex;min-width: 0;}.field{display: flex;align-items: center;width: 100%;height: ${tok("control")};border: 1px solid transparent;border-radius: calc(${tok("radius")} - 4px);background: ${tok("bg2")};}.field:hover{border-color: ${tok("border")};}.field:focus-within{border-color: ${tok("accent")};}.label{display: inline-flex;align-items: center;justify-content: center;min-width: 22px;height: 100%;padding: 0 2px 0 6px;color: ${tok("muted")};cursor: ew-resize;user-select: none;touch-action: none;}input{flex: 1;min-width: 0;height: 100%;padding: 0 6px;border: 0;background: none;font: inherit;color: inherit;outline: none;}input::placeholder{color: ${tok("muted")};}.unit{padding-right: 6px;color: ${tok("muted")};}:host([disabled]){opacity: 0.45;pointer-events: none;}`,
|
|
22
|
+
];
|
|
23
|
+
static properties = { mixed: { type: Boolean }, name: {}, disabled: { type: Boolean, reflect: true } };
|
|
24
|
+
draft = null;
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
this.mixed = false;
|
|
28
|
+
this.name = "";
|
|
29
|
+
this.disabled = false;
|
|
30
|
+
}
|
|
31
|
+
discardDraft() {
|
|
32
|
+
return this.takeDraft() !== null;
|
|
33
|
+
}
|
|
34
|
+
takeDraft() {
|
|
35
|
+
const draft = this.draft;
|
|
36
|
+
this.draft = null;
|
|
37
|
+
if (draft !== null)
|
|
38
|
+
this.requestUpdate();
|
|
39
|
+
return draft;
|
|
40
|
+
}
|
|
41
|
+
onKey(e) {
|
|
42
|
+
if (e.key === "Enter") {
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
this.commitDraft();
|
|
45
|
+
}
|
|
46
|
+
else if (e.key === "Escape" && this.draft !== null) {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
this.draft = null;
|
|
50
|
+
this.requestUpdate();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
input(text, placeholder, label, mode, busy) {
|
|
54
|
+
return html `<input part="input" type="text" inputmode=${mode ?? nothing} autocomplete="off" spellcheck="false" aria-label=${label || nothing} aria-busy=${busy ? "true" : nothing} placeholder=${placeholder} .value=${live(this.draft ?? text)} ?disabled=${this.disabled} @input=${(e) => (this.draft = e.target.value)} @keydown=${(e) => this.onKey(e)} @focus=${(e) => e.target.select()} @blur=${() => this.commitDraft()} />`;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export class NumberField extends TypedField {
|
|
58
|
+
static properties = {
|
|
59
|
+
value: { type: Number },
|
|
60
|
+
min: { type: Number },
|
|
61
|
+
max: { type: Number },
|
|
62
|
+
step: { type: Number },
|
|
63
|
+
precision: { type: Number },
|
|
64
|
+
unit: {},
|
|
65
|
+
label: {},
|
|
66
|
+
labelIcon: { attribute: "label-icon" },
|
|
67
|
+
};
|
|
68
|
+
#scrubFrom = 0;
|
|
69
|
+
#scrubMixed = false;
|
|
70
|
+
#scrubX = 0;
|
|
71
|
+
#previewed = null;
|
|
72
|
+
#drag = new Drag({
|
|
73
|
+
move: (e) => this.#scrubMove(e),
|
|
74
|
+
commit: (moved) => this.#scrubEnd(moved),
|
|
75
|
+
cancel: () => this.#scrubCancel(),
|
|
76
|
+
});
|
|
77
|
+
constructor() {
|
|
78
|
+
super();
|
|
79
|
+
this.value = null;
|
|
80
|
+
this.min = -Infinity;
|
|
81
|
+
this.max = Infinity;
|
|
82
|
+
this.step = 1;
|
|
83
|
+
this.precision = 2;
|
|
84
|
+
this.unit = "";
|
|
85
|
+
this.label = "";
|
|
86
|
+
}
|
|
87
|
+
disconnectedCallback() {
|
|
88
|
+
super.disconnectedCallback();
|
|
89
|
+
this.#drag.cancel();
|
|
90
|
+
}
|
|
91
|
+
requestUpdate(...args) {
|
|
92
|
+
super.requestUpdate(...args);
|
|
93
|
+
if (args[0] === "disabled" && this.disabled)
|
|
94
|
+
this.#drag.cancel();
|
|
95
|
+
}
|
|
96
|
+
get scrubbing() {
|
|
97
|
+
return this.#drag.active;
|
|
98
|
+
}
|
|
99
|
+
get draftValue() {
|
|
100
|
+
return this.draft === null ? null : parseNumber(this.draft, this.unit);
|
|
101
|
+
}
|
|
102
|
+
#clampRound(v) {
|
|
103
|
+
return clamp(Number(v.toFixed(Math.min(20, Math.max(decimalsOf(this.step), this.precision)))), this.min, this.max);
|
|
104
|
+
}
|
|
105
|
+
#commit(v) {
|
|
106
|
+
if (this.mixed || v !== this.value)
|
|
107
|
+
emit(this, COMMIT, v);
|
|
108
|
+
}
|
|
109
|
+
commitDraft() {
|
|
110
|
+
const draft = this.takeDraft();
|
|
111
|
+
if (draft === null)
|
|
112
|
+
return null;
|
|
113
|
+
const typed = parseNumber(draft, this.unit);
|
|
114
|
+
if (typed === null)
|
|
115
|
+
return null;
|
|
116
|
+
const v = this.#clampRound(typed);
|
|
117
|
+
this.#commit(v);
|
|
118
|
+
return v;
|
|
119
|
+
}
|
|
120
|
+
onKey(e) {
|
|
121
|
+
if (this.#drag.active) {
|
|
122
|
+
if (e.key === "Tab")
|
|
123
|
+
return;
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
if (e.key === "Escape") {
|
|
126
|
+
e.stopPropagation();
|
|
127
|
+
this.#drag.cancel();
|
|
128
|
+
}
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (e.key !== "ArrowUp" && e.key !== "ArrowDown")
|
|
132
|
+
return super.onKey(e);
|
|
133
|
+
e.preventDefault();
|
|
134
|
+
const typed = this.draft === null ? null : parseNumber(this.draft, this.unit);
|
|
135
|
+
const base = typed ?? this.value ?? 0;
|
|
136
|
+
const delta = (e.key === "ArrowUp" ? 1 : -1) * this.step * (e.shiftKey ? 10 : 1);
|
|
137
|
+
this.draft = null;
|
|
138
|
+
this.#commit(this.#clampRound(base + delta));
|
|
139
|
+
this.requestUpdate();
|
|
140
|
+
}
|
|
141
|
+
#scrubStart(e) {
|
|
142
|
+
if (this.disabled || !this.#drag.start(e, e.currentTarget, this.ui))
|
|
143
|
+
return;
|
|
144
|
+
const typed = this.commitDraft();
|
|
145
|
+
this.#scrubFrom = typed ?? this.value ?? 0;
|
|
146
|
+
this.#scrubMixed = typed === null && this.mixed;
|
|
147
|
+
this.#scrubX = e.clientX;
|
|
148
|
+
this.#previewed = null;
|
|
149
|
+
}
|
|
150
|
+
#scrubMove(e) {
|
|
151
|
+
const steps = Math.round(e.clientX - this.#scrubX) * (e.shiftKey ? 10 : 1);
|
|
152
|
+
const v = this.#clampRound(this.#scrubFrom + steps * this.step);
|
|
153
|
+
if (v === this.#previewed || (this.#previewed === null && v === this.#scrubFrom && !this.#scrubMixed))
|
|
154
|
+
return;
|
|
155
|
+
this.#previewed = v;
|
|
156
|
+
emit(this, PREVIEW, v);
|
|
157
|
+
this.requestUpdate();
|
|
158
|
+
}
|
|
159
|
+
#scrubEnd(moved) {
|
|
160
|
+
const v = this.#previewed;
|
|
161
|
+
this.#previewed = null;
|
|
162
|
+
if (v !== null) {
|
|
163
|
+
if (v === this.#scrubFrom && !this.#scrubMixed)
|
|
164
|
+
emit(this, CANCEL);
|
|
165
|
+
else
|
|
166
|
+
emit(this, COMMIT, v);
|
|
167
|
+
}
|
|
168
|
+
else if (!moved)
|
|
169
|
+
this.renderRoot.querySelector("input")?.focus();
|
|
170
|
+
this.requestUpdate();
|
|
171
|
+
}
|
|
172
|
+
#scrubCancel() {
|
|
173
|
+
const had = this.#previewed !== null;
|
|
174
|
+
this.#previewed = null;
|
|
175
|
+
if (had)
|
|
176
|
+
emit(this, CANCEL);
|
|
177
|
+
this.requestUpdate();
|
|
178
|
+
}
|
|
179
|
+
render() {
|
|
180
|
+
const shown = this.#previewed ?? (this.mixed ? null : this.value);
|
|
181
|
+
const text = shown === null || !Number.isFinite(shown) ? "" : formatNumber(shown, this.precision);
|
|
182
|
+
const label = this.labelIcon ? this.drawIcon(this.labelIcon, 14) : this.label;
|
|
183
|
+
return html `<div class="field" part="field">
|
|
184
|
+
${label
|
|
185
|
+
? html `<span class="label" part="label" aria-hidden="true" @pointerdown=${(e) => this.#scrubStart(e)} @mousedown=${(e) => e.preventDefault()}>${label}</span>`
|
|
186
|
+
: nothing}
|
|
187
|
+
${this.input(text, this.mixed && this.#previewed === null ? this.t("value.mixed") : "", this.name || this.label, "decimal")}${this.unit ? html `<span class="unit" part="unit">${this.unit}</span>` : nothing}
|
|
188
|
+
</div>`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Placement } from "@floating-ui/dom";
|
|
2
|
+
export type { Placement };
|
|
3
|
+
export declare const hasPopoverApi: (el: HTMLElement) => boolean;
|
|
4
|
+
export interface PlaceOptions {
|
|
5
|
+
placement?: Placement;
|
|
6
|
+
gap?: number;
|
|
7
|
+
fitHeight?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function place(anchor: Element, floating: HTMLElement, opts?: PlaceOptions): () => void;
|
|
10
|
+
export declare function observeMove(el: Element, onMove: () => void): () => void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { autoUpdate, computePosition, flip, offset, shift, size } from "@floating-ui/dom";
|
|
2
|
+
export const hasPopoverApi = (el) => typeof el.showPopover === "function";
|
|
3
|
+
const EDGE_PADDING = 8;
|
|
4
|
+
export function place(anchor, floating, opts = {}) {
|
|
5
|
+
const update = () => {
|
|
6
|
+
const doc = floating.ownerDocument.documentElement;
|
|
7
|
+
const topLayer = floating.matches(":popover-open");
|
|
8
|
+
const boundary = topLayer ? { x: 0, y: 0, width: doc.clientWidth, height: doc.clientHeight } : "clippingAncestors";
|
|
9
|
+
void computePosition(anchor, floating, {
|
|
10
|
+
strategy: "fixed",
|
|
11
|
+
placement: opts.placement ?? "bottom-start",
|
|
12
|
+
middleware: [
|
|
13
|
+
offset(opts.gap ?? 6),
|
|
14
|
+
flip({ boundary, padding: EDGE_PADDING }),
|
|
15
|
+
shift({ boundary, padding: EDGE_PADDING }),
|
|
16
|
+
...(opts.fitHeight
|
|
17
|
+
? [size({ boundary, padding: EDGE_PADDING, apply: ({ availableHeight }) => void floating.style.setProperty("max-height", `${Math.max(64, Math.floor(availableHeight))}px`) })]
|
|
18
|
+
: []),
|
|
19
|
+
],
|
|
20
|
+
}).then(({ x, y }) => {
|
|
21
|
+
floating.style.left = `${x}px`;
|
|
22
|
+
floating.style.top = `${y}px`;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const stopResize = autoUpdate(anchor, floating, update, { ancestorScroll: false, ancestorResize: false, elementResize: true, layoutShift: false });
|
|
26
|
+
const stopMove = observeMove(anchor, update);
|
|
27
|
+
return () => {
|
|
28
|
+
stopResize();
|
|
29
|
+
stopMove();
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const sameRect = (a, b) => a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
33
|
+
export function observeMove(el, onMove) {
|
|
34
|
+
let io = null;
|
|
35
|
+
let retry;
|
|
36
|
+
const stop = () => {
|
|
37
|
+
clearTimeout(retry);
|
|
38
|
+
io?.disconnect();
|
|
39
|
+
io = null;
|
|
40
|
+
};
|
|
41
|
+
const watch = (notify, threshold = 1) => {
|
|
42
|
+
stop();
|
|
43
|
+
const at = el.getBoundingClientRect();
|
|
44
|
+
if (notify)
|
|
45
|
+
onMove();
|
|
46
|
+
if (!at.width || !at.height || typeof IntersectionObserver !== "function")
|
|
47
|
+
return;
|
|
48
|
+
const doc = el.ownerDocument.documentElement;
|
|
49
|
+
const cut = (v) => `${-Math.floor(v)}px`;
|
|
50
|
+
const rootMargin = [cut(at.top), cut(doc.clientWidth - at.right), cut(doc.clientHeight - at.bottom), cut(at.left)].join(" ");
|
|
51
|
+
let first = true;
|
|
52
|
+
const seen = (entries) => {
|
|
53
|
+
const ratio = entries[0]?.intersectionRatio ?? 0;
|
|
54
|
+
if (!sameRect(at, el.getBoundingClientRect()))
|
|
55
|
+
return watch(true);
|
|
56
|
+
if (ratio !== threshold) {
|
|
57
|
+
if (!first)
|
|
58
|
+
return watch(true);
|
|
59
|
+
if (ratio === 0)
|
|
60
|
+
retry = setTimeout(() => watch(true, 1e-7), 1000);
|
|
61
|
+
else
|
|
62
|
+
watch(true, ratio);
|
|
63
|
+
}
|
|
64
|
+
first = false;
|
|
65
|
+
};
|
|
66
|
+
const options = { rootMargin, threshold: Math.max(0, Math.min(1, threshold)) || 1 };
|
|
67
|
+
try {
|
|
68
|
+
io = new IntersectionObserver(seen, { ...options, root: el.ownerDocument });
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
io = new IntersectionObserver(seen, options);
|
|
72
|
+
}
|
|
73
|
+
io.observe(el);
|
|
74
|
+
};
|
|
75
|
+
watch(false);
|
|
76
|
+
return stop;
|
|
77
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { UiElement } from "../element.js";
|
|
2
|
+
import type { IconName } from "../icons/index.js";
|
|
3
|
+
import { type Placement } from "./place.js";
|
|
4
|
+
export declare const OPEN = "daas-open";
|
|
5
|
+
export declare const CLOSE = "daas-close";
|
|
6
|
+
export declare class Popover extends UiElement {
|
|
7
|
+
#private;
|
|
8
|
+
static styles: import("lit").CSSResult[];
|
|
9
|
+
static properties: {
|
|
10
|
+
placement: {};
|
|
11
|
+
};
|
|
12
|
+
placement: Placement;
|
|
13
|
+
constructor();
|
|
14
|
+
get keepOpenOn(): ((e: PointerEvent) => boolean) | null;
|
|
15
|
+
set keepOpenOn(fn: ((e: PointerEvent) => boolean) | null);
|
|
16
|
+
connectedCallback(): void;
|
|
17
|
+
disconnectedCallback(): void;
|
|
18
|
+
get open(): boolean;
|
|
19
|
+
get opener(): Element | null;
|
|
20
|
+
show(anchor: Element): void;
|
|
21
|
+
reanchor(anchor: Element): void;
|
|
22
|
+
hide(): void;
|
|
23
|
+
toggle(anchor: Element): void;
|
|
24
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
25
|
+
}
|
|
26
|
+
export interface MenuItem {
|
|
27
|
+
value: string;
|
|
28
|
+
label: string;
|
|
29
|
+
icon?: IconName;
|
|
30
|
+
shortcut?: string;
|
|
31
|
+
checked?: boolean;
|
|
32
|
+
disabled?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export type MenuEntry = MenuItem | "separator";
|
|
35
|
+
export declare class Menu extends UiElement {
|
|
36
|
+
#private;
|
|
37
|
+
static styles: import("lit").CSSResult[];
|
|
38
|
+
static properties: {
|
|
39
|
+
items: {
|
|
40
|
+
attribute: boolean;
|
|
41
|
+
};
|
|
42
|
+
label: {};
|
|
43
|
+
placement: {};
|
|
44
|
+
};
|
|
45
|
+
items: readonly MenuEntry[];
|
|
46
|
+
label: string;
|
|
47
|
+
placement: Placement;
|
|
48
|
+
constructor();
|
|
49
|
+
get open(): boolean;
|
|
50
|
+
show(anchor: HTMLElement, focus?: "checked" | "first" | "last"): Promise<void>;
|
|
51
|
+
hide(returnFocus?: boolean): void;
|
|
52
|
+
toggle(anchor: HTMLElement): void;
|
|
53
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
54
|
+
}
|
|
55
|
+
export interface SelectOption {
|
|
56
|
+
value: string;
|
|
57
|
+
label: string;
|
|
58
|
+
icon?: IconName;
|
|
59
|
+
}
|
|
60
|
+
export declare class Select extends UiElement {
|
|
61
|
+
#private;
|
|
62
|
+
static styles: import("lit").CSSResult[];
|
|
63
|
+
static properties: {
|
|
64
|
+
options: {
|
|
65
|
+
attribute: boolean;
|
|
66
|
+
};
|
|
67
|
+
value: {};
|
|
68
|
+
mixed: {
|
|
69
|
+
type: BooleanConstructor;
|
|
70
|
+
};
|
|
71
|
+
label: {};
|
|
72
|
+
disabled: {
|
|
73
|
+
type: BooleanConstructor;
|
|
74
|
+
reflect: boolean;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
options: readonly SelectOption[];
|
|
78
|
+
value: string | null;
|
|
79
|
+
mixed: boolean;
|
|
80
|
+
label: string;
|
|
81
|
+
disabled: boolean;
|
|
82
|
+
constructor();
|
|
83
|
+
protected render(): import("lit").TemplateResult<1>;
|
|
84
|
+
}
|