@openartifactsai/ui 0.0.0-stage → 0.23.0-rc.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 +202 -0
- package/NOTICE +5 -0
- package/README.md +5 -2
- package/package.json +82 -4
- package/src/button.d.ts +30 -0
- package/src/button.js +29 -0
- package/src/clicks.d.ts +63 -0
- package/src/clicks.js +75 -0
- package/src/cn.d.ts +3 -0
- package/src/cn.js +5 -0
- package/src/color-picker.d.ts +98 -0
- package/src/color-picker.js +395 -0
- package/src/color.d.ts +150 -0
- package/src/color.js +543 -0
- package/src/crash-boundary.d.ts +29 -0
- package/src/crash-boundary.js +32 -0
- package/src/data/google-fonts.json +1775 -0
- package/src/drag-cover.d.ts +48 -0
- package/src/drag-cover.js +41 -0
- package/src/effect-editors.d.ts +48 -0
- package/src/effect-editors.js +230 -0
- package/src/effects.d.ts +118 -0
- package/src/effects.js +425 -0
- package/src/escape-to-popup.d.ts +53 -0
- package/src/escape-to-popup.js +78 -0
- package/src/field-announce.d.ts +28 -0
- package/src/field-announce.js +43 -0
- package/src/fields.d.ts +176 -0
- package/src/fields.js +377 -0
- package/src/focusables.d.ts +50 -0
- package/src/focusables.js +61 -0
- package/src/font-picker.d.ts +62 -0
- package/src/font-picker.js +242 -0
- package/src/fonts.d.ts +121 -0
- package/src/fonts.js +273 -0
- package/src/history-diff.d.ts +64 -0
- package/src/history-diff.js +151 -0
- package/src/history.d.ts +95 -0
- package/src/history.js +160 -0
- package/src/index.d.ts +38 -0
- package/src/index.js +38 -0
- package/src/key-chord.d.ts +74 -0
- package/src/key-chord.js +228 -0
- package/src/keys.d.ts +142 -0
- package/src/keys.js +172 -0
- package/src/layout.d.ts +74 -0
- package/src/layout.js +173 -0
- package/src/link-card-view.d.ts +97 -0
- package/src/link-card-view.js +175 -0
- package/src/link-card.d.ts +136 -0
- package/src/link-card.js +158 -0
- package/src/menu-shortcuts.d.ts +31 -0
- package/src/menu-shortcuts.js +91 -0
- package/src/menu.d.ts +120 -0
- package/src/menu.js +100 -0
- package/src/number-entry.d.ts +140 -0
- package/src/number-entry.js +202 -0
- package/src/number-limits.d.ts +2 -0
- package/src/number-limits.js +2 -0
- package/src/number-wheel.d.ts +29 -0
- package/src/number-wheel.js +27 -0
- package/src/numbers.d.ts +28 -0
- package/src/numbers.js +124 -0
- package/src/overlays.d.ts +71 -0
- package/src/overlays.js +131 -0
- package/src/pressed.d.ts +5 -0
- package/src/pressed.js +10 -0
- package/src/scroll.d.ts +24 -0
- package/src/scroll.js +111 -0
- package/src/scrub-number-field.d.ts +79 -0
- package/src/scrub-number-field.js +254 -0
- package/src/select-announce.d.ts +50 -0
- package/src/select-announce.js +71 -0
- package/src/slider-session.d.ts +43 -0
- package/src/slider-session.js +39 -0
- package/src/styles.css +96 -0
- package/src/tab-strip-layout.d.ts +76 -0
- package/src/tab-strip-layout.js +111 -0
- package/src/tab-strip.d.ts +73 -0
- package/src/tab-strip.js +498 -0
- package/src/text-area-view.d.ts +35 -0
- package/src/text-area-view.js +142 -0
- package/src/text-area.d.ts +38 -0
- package/src/text-area.js +51 -0
- package/src/theme.css +34 -0
- package/src/toast-fit.d.ts +21 -0
- package/src/toast-fit.js +30 -0
- package/src/toast-tone.d.ts +27 -0
- package/src/toast-tone.js +22 -0
- package/src/tooltip.d.ts +23 -0
- package/src/tooltip.js +18 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The arithmetic of {@link TabStrip} (`tab-strip.tsx`), apart from the page so it can be tested on its own: which tabs
|
|
3
|
+
* fit in the row and what room the ones whose title is cut are given, where a dragged tab is drawn and lands, where a tab picked from
|
|
4
|
+
* the list of those that do not fit goes, and what each Close item of a tab's menu closes.
|
|
5
|
+
*/
|
|
6
|
+
/** Which tabs fit in the row. */
|
|
7
|
+
export function fitTabs(input) {
|
|
8
|
+
const { ids, fixed, widths, needs, gap, avail, more, activeId } = input;
|
|
9
|
+
const fit = { hidden: new Set(), stretch: new Map(), clipped: new Set(), start: 0 };
|
|
10
|
+
const total = widths.reduce((sum, w) => sum + w, 0) + gap * Math.max(0, ids.length - 1);
|
|
11
|
+
if (total > avail + 0.5) {
|
|
12
|
+
const moving = ids.map((_, i) => i).filter((i) => !fixed[i]);
|
|
13
|
+
const fixedWidth = ids.reduce((sum, _, i) => (fixed[i] ? sum + widths[i] + gap : sum), 0);
|
|
14
|
+
const space = avail - more - fixedWidth;
|
|
15
|
+
const span = (from, to) => {
|
|
16
|
+
let w = gap * (to - from);
|
|
17
|
+
for (let k = from; k <= to; k++)
|
|
18
|
+
w += widths[moving[k]];
|
|
19
|
+
return w;
|
|
20
|
+
};
|
|
21
|
+
const count = moving.length;
|
|
22
|
+
const front = moving.findIndex((i) => ids[i] === activeId);
|
|
23
|
+
let first = Math.min(Math.max(0, input.start), Math.max(0, count - 1));
|
|
24
|
+
if (front >= 0) {
|
|
25
|
+
if (front < first)
|
|
26
|
+
first = front;
|
|
27
|
+
else
|
|
28
|
+
while (first < front && span(first, front) > space)
|
|
29
|
+
first++;
|
|
30
|
+
}
|
|
31
|
+
let last = first;
|
|
32
|
+
while (last + 1 < count && span(first, last + 1) <= space)
|
|
33
|
+
last++;
|
|
34
|
+
// Closing tabs at the end leaves room: the tabs before come back into it.
|
|
35
|
+
if (last === count - 1)
|
|
36
|
+
while (first > 0 && span(first - 1, last) <= space)
|
|
37
|
+
first--;
|
|
38
|
+
fit.start = first;
|
|
39
|
+
moving.forEach((i, k) => (k < first || k > last) && fit.hidden.add(ids[i]));
|
|
40
|
+
// What is left over goes to the tabs shown whose title is cut, the ones that need least first.
|
|
41
|
+
let spare = count ? Math.floor(space - span(first, last)) : 0;
|
|
42
|
+
const wants = moving
|
|
43
|
+
.slice(first, last + 1)
|
|
44
|
+
.map((i) => ({ id: ids[i], px: Math.ceil(needs[i]) }))
|
|
45
|
+
.filter((want) => want.px > 1)
|
|
46
|
+
.sort((a, b) => a.px - b.px);
|
|
47
|
+
wants.forEach((want, k) => {
|
|
48
|
+
const give = Math.max(0, Math.min(want.px, Math.floor(spare / (wants.length - k))));
|
|
49
|
+
spare -= give;
|
|
50
|
+
if (give > 0)
|
|
51
|
+
fit.stretch.set(want.id, give);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
ids.forEach((id, i) => needs[i] - (fit.stretch.get(id) ?? 0) > 1 && fit.clipped.add(id));
|
|
55
|
+
return fit;
|
|
56
|
+
}
|
|
57
|
+
/** Whether two fits show the same thing. */
|
|
58
|
+
export const sameFit = (a, b) => fitKey(a) === fitKey(b);
|
|
59
|
+
const fitKey = (fit) => [[...fit.hidden].join(','), [...fit.stretch].map(([id, px]) => `${id}=${px}`).join(','), [...fit.clipped].join(',')].join('|');
|
|
60
|
+
/** The order with `id` moved to `to`. */
|
|
61
|
+
export function moveTo(order, id, to) {
|
|
62
|
+
const next = order.filter((x) => x !== id);
|
|
63
|
+
next.splice(Math.max(0, Math.min(to, next.length)), 0, id);
|
|
64
|
+
return next;
|
|
65
|
+
}
|
|
66
|
+
/** Room left between the dragged tab and the row's ends. */
|
|
67
|
+
export const DRAG_EDGE_PX = 4;
|
|
68
|
+
/** Where the dragged tab is drawn: under the pointer, held inside the row and right of the fixed tabs. */
|
|
69
|
+
export function dragLeft(drag) {
|
|
70
|
+
return Math.min(Math.max(drag.left, drag.rowLeft + DRAG_EDGE_PX, drag.fixedEnd), drag.rowRight - DRAG_EDGE_PX - drag.width);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The order while a tab is dragged. It goes after every other tab of the row it has passed: one whose middle its own
|
|
74
|
+
* middle (held inside the row) has passed, or, when it covers the other tab whole, one laid out after its place. Held
|
|
75
|
+
* against the fixed tabs, it goes first. `row` is the tabs shown that can move, in order; `boxOf` says where another
|
|
76
|
+
* tab is laid out.
|
|
77
|
+
*/
|
|
78
|
+
export function dragOrder(order, row, id, drag, boxOf) {
|
|
79
|
+
const right = drag.left + drag.width;
|
|
80
|
+
const middle = Math.min(Math.max(drag.left + drag.width / 2, drag.rowLeft + DRAG_EDGE_PX), drag.rowRight - DRAG_EDGE_PX);
|
|
81
|
+
let passed = 0;
|
|
82
|
+
for (const other of row) {
|
|
83
|
+
const box = other === id ? undefined : boxOf(other);
|
|
84
|
+
if (!box)
|
|
85
|
+
continue;
|
|
86
|
+
const covers = drag.left < box.left && right > box.left + box.width;
|
|
87
|
+
if (covers ? box.left > drag.slot : middle > box.left + box.width / 2)
|
|
88
|
+
passed++;
|
|
89
|
+
}
|
|
90
|
+
if (dragLeft(drag) <= drag.fixedEnd + 1)
|
|
91
|
+
passed = 0;
|
|
92
|
+
return moveTo(order, id, order.indexOf(row[0]) + passed);
|
|
93
|
+
}
|
|
94
|
+
/** Where a tab picked from the list goes: next to the last tab shown. Null when it stays where it is. */
|
|
95
|
+
export function pickedPlace(order, id, lastShown) {
|
|
96
|
+
const last = lastShown === undefined ? -1 : order.indexOf(lastShown);
|
|
97
|
+
const from = order.indexOf(id);
|
|
98
|
+
if (last < 0 || from < 0)
|
|
99
|
+
return null;
|
|
100
|
+
const to = from < last + 1 ? last : last + 1;
|
|
101
|
+
return to === from ? null : to;
|
|
102
|
+
}
|
|
103
|
+
/** What the Close items of a tab's menu close: the others, the ones to its right, all (closable ones only). */
|
|
104
|
+
export function closeGroups(order, closable, id) {
|
|
105
|
+
const all = order.filter(closable);
|
|
106
|
+
return {
|
|
107
|
+
others: all.filter((x) => x !== id),
|
|
108
|
+
right: order.slice(order.indexOf(id) + 1).filter(closable),
|
|
109
|
+
all,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface TabStripTab {
|
|
3
|
+
id: string;
|
|
4
|
+
title: string;
|
|
5
|
+
/** Drawn left of the title. */
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
/** The second line of the tab's row in the list of tabs that do not fit (its type, say). */
|
|
8
|
+
detail?: string;
|
|
9
|
+
/** Stays first: never dragged, closed or put in the list. */
|
|
10
|
+
fixed?: boolean;
|
|
11
|
+
/** Has a close button and the Close items of the menu. Default: not fixed. */
|
|
12
|
+
closable?: boolean;
|
|
13
|
+
/** Something is not saved: a dot where × is, until the pointer is over the tab. */
|
|
14
|
+
marked?: boolean;
|
|
15
|
+
markLabel?: string;
|
|
16
|
+
/** Drawn after the title (what the tab is doing). */
|
|
17
|
+
extra?: ReactNode;
|
|
18
|
+
/** The tab's tooltip. Default: its title. */
|
|
19
|
+
tooltip?: string;
|
|
20
|
+
/** `data-*` attributes put on the tab. */
|
|
21
|
+
attrs?: Record<`data-${string}`, string | undefined>;
|
|
22
|
+
}
|
|
23
|
+
/** A menu's line: an item, a rule between groups, or the name of the group under it. */
|
|
24
|
+
export type TabStripMenuItem = {
|
|
25
|
+
key: string;
|
|
26
|
+
label: string;
|
|
27
|
+
/** Drawn left of the label. */
|
|
28
|
+
icon?: ReactNode;
|
|
29
|
+
/** Said in the item's tooltip after its label. */
|
|
30
|
+
detail?: string;
|
|
31
|
+
testId?: string;
|
|
32
|
+
/** `data-*` attributes put on the item. */
|
|
33
|
+
attrs?: Record<`data-${string}`, string | undefined>;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
onSelect(): void;
|
|
36
|
+
} | 'separator' | {
|
|
37
|
+
heading: string;
|
|
38
|
+
};
|
|
39
|
+
export interface TabStripWords {
|
|
40
|
+
/** The row's name for screen readers. */
|
|
41
|
+
label: string;
|
|
42
|
+
newTab: string;
|
|
43
|
+
moreTabs: string;
|
|
44
|
+
/** × of a tab. */
|
|
45
|
+
close(title: string): string;
|
|
46
|
+
/** A tab's menu, for screen readers. */
|
|
47
|
+
menu(title: string): string;
|
|
48
|
+
closeTab: string;
|
|
49
|
+
closeOthers: string;
|
|
50
|
+
closeRight: string;
|
|
51
|
+
closeAll: string;
|
|
52
|
+
}
|
|
53
|
+
export interface TabStripProps {
|
|
54
|
+
tabs: TabStripTab[];
|
|
55
|
+
activeId: string;
|
|
56
|
+
words: TabStripWords;
|
|
57
|
+
onSelect(id: string): void;
|
|
58
|
+
/** Close these tabs (one, or several from the menu), in order. */
|
|
59
|
+
onClose(ids: string[]): void;
|
|
60
|
+
/** Put the tab at `index` of `tabs` (fixed tabs counted). */
|
|
61
|
+
onReorder(id: string, index: number): void;
|
|
62
|
+
/** + after the tabs (none without it, or without `newMenu`): what a click on it does. */
|
|
63
|
+
onNew?(): void;
|
|
64
|
+
/** What + offers instead: a click opens a menu of these under it. */
|
|
65
|
+
newMenu?: TabStripMenuItem[];
|
|
66
|
+
newTestId?: string;
|
|
67
|
+
/** Items above the Close items of a tab's menu. */
|
|
68
|
+
menuItems?(tab: TabStripTab): TabStripMenuItem[];
|
|
69
|
+
/** A menu or the list opened or closed (it may be drawn over something the owner has to hide). */
|
|
70
|
+
onPopupChange?(open: boolean): void;
|
|
71
|
+
className?: string;
|
|
72
|
+
}
|
|
73
|
+
export declare function TabStrip(props: TabStripProps): import("react/jsx-runtime").JSX.Element;
|