@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,2 @@
|
|
|
1
|
+
export { ToolsToolbar, TOOLS_TAG, ZOOM_SHORTCUTS, defineToolsToolbar } from "./toolbar.js";
|
|
2
|
+
export { DEFAULT_TOOLBAR_TOOLS, toolbarGroups, resolveToolbarOptions, overflowCount, creationKind, creationColorStyle, toolbarColorKey, CreationColorMemory, type ToolbarGroup, type ToolbarSlot, type ToolEntry, type ResolvedToolbarOptions, type OverflowOptions } from "./model.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { UiHost, ZoomLevel } from "../../host.js";
|
|
2
|
+
import type { ResolvedOptions } from "../../options.js";
|
|
3
|
+
export declare const ZOOM_SHORTCUTS: {
|
|
4
|
+
readonly zoomIn: "Mod+=";
|
|
5
|
+
readonly zoomOut: "Mod+-";
|
|
6
|
+
readonly zoomReset: "Mod+0";
|
|
7
|
+
readonly zoomFit: "Shift+1";
|
|
8
|
+
readonly zoomSelection: "Shift+2";
|
|
9
|
+
};
|
|
10
|
+
export declare const ZOOM_LEVELS: Readonly<Record<keyof typeof ZOOM_SHORTCUTS, ZoomLevel>>;
|
|
11
|
+
export declare function handleZoomKey(e: KeyboardEvent, options: ResolvedOptions, host: UiHost, mac: boolean): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { matchesChord, parseChord } from "../../keys.js";
|
|
2
|
+
export const ZOOM_SHORTCUTS = {
|
|
3
|
+
zoomIn: "Mod+=", zoomOut: "Mod+-", zoomReset: "Mod+0", zoomFit: "Shift+1", zoomSelection: "Shift+2",
|
|
4
|
+
};
|
|
5
|
+
export const ZOOM_LEVELS = {
|
|
6
|
+
zoomIn: "in", zoomOut: "out", zoomReset: 1, zoomFit: "fit", zoomSelection: "selection",
|
|
7
|
+
};
|
|
8
|
+
export function handleZoomKey(e, options, host, mac) {
|
|
9
|
+
if (options.toolbar === false || options.toolbar.zoom === false || e.defaultPrevented || e.isComposing || e.keyCode === 229 || e.key === "Process")
|
|
10
|
+
return false;
|
|
11
|
+
for (const command of Object.keys(ZOOM_SHORTCUTS)) {
|
|
12
|
+
const text = command in options.shortcuts ? options.shortcuts[command] : ZOOM_SHORTCUTS[command];
|
|
13
|
+
const chord = text ? parseChord(text, mac) : null;
|
|
14
|
+
if (!chord || !matchesChord(chord, e))
|
|
15
|
+
continue;
|
|
16
|
+
host.camera.zoomTo(ZOOM_LEVELS[command]);
|
|
17
|
+
e.preventDefault();
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type CreateKind, type Style, type ToolManager, type ToolName } from "@daasboard/editor";
|
|
2
|
+
import type { CustomTool, ToolbarOptions, ToolbarToolName } from "../../options.js";
|
|
3
|
+
import type { PrefsStore } from "../../prefs.js";
|
|
4
|
+
export type ToolEntry = ToolbarToolName | CustomTool;
|
|
5
|
+
export interface ToolbarSlot {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly tools: readonly ToolEntry[];
|
|
8
|
+
}
|
|
9
|
+
export interface ToolbarGroup {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly slots: readonly ToolbarSlot[];
|
|
12
|
+
}
|
|
13
|
+
export declare const DEFAULT_TOOLBAR_TOOLS: NonNullable<ToolbarOptions["tools"]>;
|
|
14
|
+
export declare function toolbarGroups(tools?: ToolbarOptions["tools"], readOnly?: boolean): ToolbarGroup[];
|
|
15
|
+
export interface ResolvedToolbarOptions {
|
|
16
|
+
readonly placement: NonNullable<ToolbarOptions["placement"]>;
|
|
17
|
+
readonly vertical: boolean;
|
|
18
|
+
readonly overflow: boolean;
|
|
19
|
+
readonly zoom: boolean;
|
|
20
|
+
readonly rememberToolStyles: boolean;
|
|
21
|
+
readonly quickActions: {
|
|
22
|
+
readonly toolOptions: boolean;
|
|
23
|
+
readonly touch: boolean;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare function resolveToolbarOptions(options: ToolbarOptions): ResolvedToolbarOptions;
|
|
27
|
+
export interface OverflowOptions {
|
|
28
|
+
gap?: number;
|
|
29
|
+
fixed?: number;
|
|
30
|
+
more?: number;
|
|
31
|
+
enabled?: boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare function overflowCount(widths: readonly number[], available: number, options?: OverflowOptions): number;
|
|
34
|
+
export declare function creationKind(tool: ToolName): CreateKind | null;
|
|
35
|
+
export declare function creationColorStyle(kind: CreateKind, color: string): Style;
|
|
36
|
+
export declare function toolbarColorKey(kind: CreateKind): string;
|
|
37
|
+
type CreationStyles = Pick<ToolManager, "creationStyle" | "setCreationStyle">;
|
|
38
|
+
export declare class CreationColorMemory {
|
|
39
|
+
#private;
|
|
40
|
+
constructor(prefs: PrefsStore, remember?: boolean);
|
|
41
|
+
get prefs(): PrefsStore;
|
|
42
|
+
get remember(): boolean;
|
|
43
|
+
configure(prefs: PrefsStore, remember: boolean): boolean;
|
|
44
|
+
restore(tools: CreationStyles): void;
|
|
45
|
+
color(tool: ToolName): string | null;
|
|
46
|
+
set(tool: ToolName, value: string, tools: CreationStyles): boolean;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { CREATE_KINDS, isPresetName, PRESET_NAMES, TOOL_NAMES } from "@daasboard/editor";
|
|
2
|
+
import { normalizeHex } from "../../color/color.js";
|
|
3
|
+
export const DEFAULT_TOOLBAR_TOOLS = [
|
|
4
|
+
{ tools: ["select", "hand"] },
|
|
5
|
+
"|",
|
|
6
|
+
"rect", "ellipse", { tools: PRESET_NAMES },
|
|
7
|
+
"|",
|
|
8
|
+
"text", "image",
|
|
9
|
+
"|",
|
|
10
|
+
"sticky",
|
|
11
|
+
"|",
|
|
12
|
+
"connector",
|
|
13
|
+
"|",
|
|
14
|
+
{ tools: ["frame", "section"] },
|
|
15
|
+
];
|
|
16
|
+
export function toolbarGroups(tools = DEFAULT_TOOLBAR_TOOLS, readOnly = false) {
|
|
17
|
+
const groups = [];
|
|
18
|
+
let slots = [];
|
|
19
|
+
let groupIndex = 0;
|
|
20
|
+
const finish = () => {
|
|
21
|
+
if (slots.length)
|
|
22
|
+
groups.push({ id: `group-${groupIndex}`, slots });
|
|
23
|
+
slots = [];
|
|
24
|
+
groupIndex++;
|
|
25
|
+
};
|
|
26
|
+
const allowed = (tool) => {
|
|
27
|
+
if (typeof tool !== "string")
|
|
28
|
+
return !readOnly;
|
|
29
|
+
return (tool === "image" || TOOL_NAMES.includes(tool)) && (!readOnly || tool === "select" || tool === "hand");
|
|
30
|
+
};
|
|
31
|
+
for (const [index, entry] of tools.entries()) {
|
|
32
|
+
if (entry === "|") {
|
|
33
|
+
finish();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const entries = typeof entry === "object" && "tools" in entry ? entry.tools : [entry];
|
|
37
|
+
const kept = entries.filter(allowed);
|
|
38
|
+
if (kept.length)
|
|
39
|
+
slots.push({ id: `slot-${index}`, tools: kept });
|
|
40
|
+
}
|
|
41
|
+
finish();
|
|
42
|
+
return groups;
|
|
43
|
+
}
|
|
44
|
+
export function resolveToolbarOptions(options) {
|
|
45
|
+
const placement = options.placement ?? "bottom";
|
|
46
|
+
const quick = options.quickActions;
|
|
47
|
+
return {
|
|
48
|
+
placement,
|
|
49
|
+
vertical: placement === "left" || placement === "right",
|
|
50
|
+
overflow: options.overflow ?? true,
|
|
51
|
+
zoom: options.zoom ?? true,
|
|
52
|
+
rememberToolStyles: options.rememberToolStyles ?? true,
|
|
53
|
+
quickActions: {
|
|
54
|
+
toolOptions: quick !== false && (typeof quick !== "object" || quick.toolOptions !== false),
|
|
55
|
+
touch: quick !== false && (typeof quick !== "object" || quick.touch !== false),
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function overflowCount(widths, available, options = {}) {
|
|
60
|
+
if (options.enabled === false || widths.length === 0)
|
|
61
|
+
return widths.length;
|
|
62
|
+
const nonnegative = (value) => Number.isFinite(value) ? Math.max(0, value) : 0;
|
|
63
|
+
const gap = nonnegative(options.gap ?? 4);
|
|
64
|
+
const fixed = nonnegative(options.fixed ?? 0);
|
|
65
|
+
const more = nonnegative(options.more ?? 0);
|
|
66
|
+
const room = available === Infinity ? Infinity : nonnegative(available);
|
|
67
|
+
let used = 0, visible = 0;
|
|
68
|
+
for (let i = 0; i < widths.length; i++) {
|
|
69
|
+
used += nonnegative(widths[i]);
|
|
70
|
+
if (fixed + used + more + gap * (i + 1) <= room)
|
|
71
|
+
visible = i + 1;
|
|
72
|
+
}
|
|
73
|
+
return fixed + used + gap * (widths.length - 1) <= room ? widths.length : visible;
|
|
74
|
+
}
|
|
75
|
+
export function creationKind(tool) {
|
|
76
|
+
return tool === "select" || tool === "hand" ? null : isPresetName(tool) ? "path" : tool;
|
|
77
|
+
}
|
|
78
|
+
export function creationColorStyle(kind, color) {
|
|
79
|
+
return { [creationColorKey(kind)]: color };
|
|
80
|
+
}
|
|
81
|
+
const creationColorKey = (kind) => kind === "text" ? "color" : kind === "connector" ? "stroke" : "fill";
|
|
82
|
+
export function toolbarColorKey(kind) {
|
|
83
|
+
return `toolbar.color.${kind}`;
|
|
84
|
+
}
|
|
85
|
+
export class CreationColorMemory {
|
|
86
|
+
#colors = new Map();
|
|
87
|
+
#prefs;
|
|
88
|
+
#remember;
|
|
89
|
+
#changedViewer = false;
|
|
90
|
+
constructor(prefs, remember = true) {
|
|
91
|
+
this.#prefs = prefs;
|
|
92
|
+
this.#remember = remember;
|
|
93
|
+
}
|
|
94
|
+
get prefs() { return this.#prefs; }
|
|
95
|
+
get remember() { return this.#remember; }
|
|
96
|
+
configure(prefs, remember) {
|
|
97
|
+
const changedStore = prefs !== this.#prefs;
|
|
98
|
+
this.#changedViewer ||= changedStore;
|
|
99
|
+
const restore = remember && (this.#changedViewer || !this.#remember);
|
|
100
|
+
this.#prefs = prefs;
|
|
101
|
+
this.#remember = remember;
|
|
102
|
+
return restore;
|
|
103
|
+
}
|
|
104
|
+
restore(tools) {
|
|
105
|
+
if (!this.remember)
|
|
106
|
+
return;
|
|
107
|
+
if (this.#changedViewer) {
|
|
108
|
+
for (const kind of this.#colors.keys()) {
|
|
109
|
+
const style = { ...tools.creationStyle(kind) };
|
|
110
|
+
delete style[creationColorKey(kind)];
|
|
111
|
+
tools.setCreationStyle(kind, Object.keys(style).length ? style : undefined);
|
|
112
|
+
}
|
|
113
|
+
this.#colors.clear();
|
|
114
|
+
this.#changedViewer = false;
|
|
115
|
+
}
|
|
116
|
+
for (const kind of CREATE_KINDS) {
|
|
117
|
+
if (this.#colors.has(kind))
|
|
118
|
+
continue;
|
|
119
|
+
let value;
|
|
120
|
+
try {
|
|
121
|
+
value = this.prefs.get(toolbarColorKey(kind));
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (typeof value !== "string" || !/^#[\da-f]{6}(?:[\da-f]{2})?$/i.test(value))
|
|
127
|
+
continue;
|
|
128
|
+
const color = normalizeHex(value);
|
|
129
|
+
if (!color)
|
|
130
|
+
continue;
|
|
131
|
+
this.#colors.set(kind, color);
|
|
132
|
+
tools.setCreationStyle(kind, { ...tools.creationStyle(kind), [creationColorKey(kind)]: color });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
color(tool) {
|
|
136
|
+
const kind = creationKind(tool);
|
|
137
|
+
return kind ? (this.#colors.get(kind) ?? null) : null;
|
|
138
|
+
}
|
|
139
|
+
set(tool, value, tools) {
|
|
140
|
+
const kind = creationKind(tool);
|
|
141
|
+
const color = normalizeHex(value);
|
|
142
|
+
if (!kind || !color)
|
|
143
|
+
return false;
|
|
144
|
+
this.#colors.set(kind, color);
|
|
145
|
+
tools.setCreationStyle(kind, { ...tools.creationStyle(kind), [creationColorKey(kind)]: color });
|
|
146
|
+
if (this.remember) {
|
|
147
|
+
try {
|
|
148
|
+
this.prefs.set(toolbarColorKey(kind), color);
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { nothing, type PropertyValues, type TemplateResult } from "lit";
|
|
2
|
+
import { type ToolName } from "@daasboard/editor";
|
|
3
|
+
import { UiSurface } from "../../surface.js";
|
|
4
|
+
export { ZOOM_SHORTCUTS } from "./keys.js";
|
|
5
|
+
import { type ToolEntry } from "./model.js";
|
|
6
|
+
export declare const TOOLS_TAG = "daas-tools-toolbar";
|
|
7
|
+
export declare class ToolsToolbar extends UiSurface {
|
|
8
|
+
#private;
|
|
9
|
+
static styles: import("lit").CSSResult[];
|
|
10
|
+
keyHandler: ((e: KeyboardEvent) => boolean) | null;
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
disconnectedCallback(): void;
|
|
13
|
+
setCreationColor(tool: ToolName, color: string): boolean;
|
|
14
|
+
handleKey(e: KeyboardEvent): boolean;
|
|
15
|
+
requestUpdate(...args: Parameters<UiSurface["requestUpdate"]>): void;
|
|
16
|
+
protected shouldUpdate(_changed: PropertyValues): boolean;
|
|
17
|
+
protected willUpdate(): void;
|
|
18
|
+
recordToolUse(tool: ToolEntry, slot?: string | null): void;
|
|
19
|
+
protected render(): typeof nothing | TemplateResult<1>;
|
|
20
|
+
protected updated(): void;
|
|
21
|
+
}
|
|
22
|
+
export declare function defineToolsToolbar(): void;
|
|
23
|
+
declare global {
|
|
24
|
+
interface HTMLElementTagNameMap {
|
|
25
|
+
"daas-tools-toolbar": ToolsToolbar;
|
|
26
|
+
}
|
|
27
|
+
}
|