@bigpixelrocket/uiok 0.2.1 → 0.2.3

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.
Files changed (64) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/dist/button/TextLink.d.ts +27 -0
  3. package/dist/button/TextLink.js +15 -0
  4. package/dist/button/button.css +48 -0
  5. package/dist/button/index.d.ts +2 -1
  6. package/dist/button/index.js +2 -1
  7. package/dist/charts/Line.logic.d.ts +15 -1
  8. package/dist/charts/Line.logic.js +37 -4
  9. package/dist/charts/LineChart.d.ts +42 -2
  10. package/dist/charts/LineChart.js +41 -9
  11. package/dist/charts/Scatter.logic.js +7 -2
  12. package/dist/charts/charts.css +35 -5
  13. package/dist/charts/index.d.ts +1 -1
  14. package/dist/dialog/ConfirmDialog.d.ts +7 -1
  15. package/dist/dialog/ConfirmDialog.js +9 -4
  16. package/dist/dialog/DialogLists.d.ts +8 -1
  17. package/dist/dialog/DialogLists.js +3 -2
  18. package/dist/field/field.css +110 -2
  19. package/dist/filter/filter.css +16 -0
  20. package/dist/grid/DataGrid.d.ts +10 -2
  21. package/dist/grid/DataGrid.js +47 -13
  22. package/dist/grid/DataGrid.logic.d.ts +16 -0
  23. package/dist/grid/DataGrid.logic.js +28 -0
  24. package/dist/grid/grid.css +128 -4
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +1 -0
  27. package/dist/labels/UiokLabels.d.ts +3 -0
  28. package/dist/labels/UiokLabels.js +3 -1
  29. package/dist/labels/index.d.ts +1 -0
  30. package/dist/labels/index.js +1 -0
  31. package/dist/labels/keys.js +2 -0
  32. package/dist/labels/paneTabs.d.ts +27 -0
  33. package/dist/labels/paneTabs.js +10 -0
  34. package/dist/labels/selectAll.d.ts +4 -1
  35. package/dist/labels/selectAll.js +1 -1
  36. package/dist/legend/KeyLegendStrip.d.ts +9 -1
  37. package/dist/legend/KeyLegendStrip.js +119 -5
  38. package/dist/legend/legend.css +52 -0
  39. package/dist/listing/Listing.d.ts +23 -5
  40. package/dist/listing/Listing.js +11 -8
  41. package/dist/listing/listing.css +106 -3
  42. package/dist/pane/PaneActions.d.ts +3 -1
  43. package/dist/pane/PaneActions.js +6 -5
  44. package/dist/pane/PaneTabs.d.ts +92 -0
  45. package/dist/pane/PaneTabs.js +326 -0
  46. package/dist/pane/PaneTabs.logic.d.ts +97 -0
  47. package/dist/pane/PaneTabs.logic.js +158 -0
  48. package/dist/pane/index.d.ts +5 -1
  49. package/dist/pane/index.js +5 -1
  50. package/dist/pane/panetabs.css +408 -0
  51. package/dist/pane/useTabDrag.d.ts +49 -0
  52. package/dist/pane/useTabDrag.js +306 -0
  53. package/dist/segmented/SegmentedChoice.d.ts +8 -1
  54. package/dist/segmented/SegmentedChoice.js +7 -4
  55. package/dist/styles.css +8 -0
  56. package/dist/surface/GroupSwatch.d.ts +22 -0
  57. package/dist/surface/GroupSwatch.js +15 -0
  58. package/dist/surface/Tag.d.ts +26 -0
  59. package/dist/surface/Tag.js +12 -0
  60. package/dist/surface/index.d.ts +7 -0
  61. package/dist/surface/index.js +7 -0
  62. package/dist/surface/surface.css +116 -1
  63. package/dist/themes/tokens.js +13 -1
  64. package/package.json +1 -1
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The rules a pane's tab strip draws by, as pure functions: which tabs are
3
+ * picked to close or move together, which tabs a crowded strip folds away
4
+ * and how many in one step, how narrow a tab's label may get, and where a
5
+ * dragged tab lands. A host keeps its tab state with the pick helpers;
6
+ * `PaneTabs` uses the rest.
7
+ */
8
+ /**
9
+ * The tabs picked on a strip beside the one in front. They belong to the
10
+ * tab in front when they were picked, and lapse once another tab comes to
11
+ * the front. A host keeps them in memory; they are never worth saving.
12
+ */
13
+ export interface TabPicks {
14
+ /** The tab in front when the picks were made. */
15
+ readonly front: string;
16
+ /** The picked tabs other than the one in front, in the order they were picked. */
17
+ readonly ids: readonly string[];
18
+ }
19
+ /**
20
+ * The tabs a strip's picks stand for, in strip order: the tab in front,
21
+ * always, and every pick that still stands.
22
+ */
23
+ export declare function pickedTabs(order: readonly string[], frontId: string, picks: TabPicks | null): readonly string[];
24
+ /**
25
+ * A Command press on the tab `id`: picks it, or drops it when it was
26
+ * picked. The tab in front is always among the picks and is never dropped,
27
+ * so a press on it changes nothing. Null once nothing beside the tab in
28
+ * front is picked.
29
+ */
30
+ export declare function togglePick(order: readonly string[], frontId: string, picks: TabPicks | null, id: string): TabPicks | null;
31
+ /**
32
+ * A Shift press on the tab `id`: picks the run of tabs from the one in
33
+ * front to it, both ends included, in place of the picks before. Null for a
34
+ * press on the tab in front, or on a tab not in `order`.
35
+ */
36
+ export declare function pickRun(order: readonly string[], frontId: string, id: string): TabPicks | null;
37
+ /**
38
+ * The strip's order with the tabs `carried` drawn together around `held`,
39
+ * the tab under the pointer, as a drag of picked tabs lifts them: the ones
40
+ * before it close up just before it and the ones after it just after, in
41
+ * their order, and every other tab keeps its order.
42
+ */
43
+ export declare function gatherTabs(order: readonly string[], carried: readonly string[], held: string): readonly string[];
44
+ /**
45
+ * The fewest characters a tab's label keeps, its ellipses counted, split
46
+ * into the context (its slash not counted) and the name: eight characters
47
+ * of the name and three of the context, or all of a shorter one. The
48
+ * context shrinks to its floor before the name loses a character: the name
49
+ * is what the eye looks for, and the context only tells two tabs apart.
50
+ */
51
+ export declare function tabLabelFloor(label: {
52
+ readonly name: string;
53
+ readonly context?: string;
54
+ }): {
55
+ readonly context: number;
56
+ readonly name: number;
57
+ };
58
+ /** What `foldOrder` reads of a tab. */
59
+ export interface FoldableTab {
60
+ readonly id: string;
61
+ readonly pinned?: boolean;
62
+ readonly following?: boolean;
63
+ }
64
+ /**
65
+ * The order in which a crowded strip folds its tabs into the count:
66
+ * farthest from the tab in front first and, of two as far, the later one.
67
+ * The tab in front, pinned tabs, and the following tab never fold, so they
68
+ * are left out.
69
+ */
70
+ export declare function foldOrder(tabs: readonly FoldableTab[], frontId: string): readonly string[];
71
+ /**
72
+ * How many more tabs a crowded strip folds in one step. `deficit` is how far
73
+ * the tabs on show run past their room, `widths` the foldable tabs still on
74
+ * show in fold order, and `gap` the space between two tabs. Folding one tab
75
+ * per layout pass would take a pass per tab, and a strip can hold more tabs
76
+ * than React allows passes in a row. A deficit folds at least one tab, and
77
+ * one that no tab covers folds them all.
78
+ */
79
+ export declare function foldsNeeded(deficit: number, widths: readonly number[], gap: number): number;
80
+ /** A tab on show in a strip, as a drag measures it. */
81
+ export interface TabBox {
82
+ readonly id: string;
83
+ readonly left: number;
84
+ readonly width: number;
85
+ }
86
+ /**
87
+ * The strip's order while a tab is dragged along it. `held` is the dragged
88
+ * tab where the pointer has it, `boxes` the other tabs on show where the
89
+ * layout has them, and `order` every tab, folded ones included. A neighbour
90
+ * steps aside once the tab coming toward it covers half of it; one the tab
91
+ * is moving away from stays put, so a tab resting on the line between two
92
+ * places cannot flicker between them. Folded tabs keep their places: a tab
93
+ * that crosses no neighbour returns `order` itself, and one that crosses
94
+ * lands beside the last neighbour it passed. `direction` is the sign of the
95
+ * pointer's last move.
96
+ */
97
+ export declare function draggedTabOrder(order: readonly string[], held: TabBox, boxes: readonly TabBox[], direction: number): readonly string[];
@@ -0,0 +1,158 @@
1
+ /**
2
+ * The rules a pane's tab strip draws by, as pure functions: which tabs are
3
+ * picked to close or move together, which tabs a crowded strip folds away
4
+ * and how many in one step, how narrow a tab's label may get, and where a
5
+ * dragged tab lands. A host keeps its tab state with the pick helpers;
6
+ * `PaneTabs` uses the rest.
7
+ */
8
+ /** The picks that still stand: those made under the tab in front now, on tabs still in `order`. */
9
+ const livePicks = (order, frontId, picks) => picks === null || picks.front !== frontId
10
+ ? []
11
+ : picks.ids.filter((id) => id !== frontId && order.includes(id));
12
+ /**
13
+ * The tabs a strip's picks stand for, in strip order: the tab in front,
14
+ * always, and every pick that still stands.
15
+ */
16
+ export function pickedTabs(order, frontId, picks) {
17
+ const live = livePicks(order, frontId, picks);
18
+ return order.filter((id) => id === frontId || live.includes(id));
19
+ }
20
+ /**
21
+ * A Command press on the tab `id`: picks it, or drops it when it was
22
+ * picked. The tab in front is always among the picks and is never dropped,
23
+ * so a press on it changes nothing. Null once nothing beside the tab in
24
+ * front is picked.
25
+ */
26
+ export function togglePick(order, frontId, picks, id) {
27
+ const live = livePicks(order, frontId, picks);
28
+ const ids = id === frontId || !order.includes(id)
29
+ ? live
30
+ : live.includes(id)
31
+ ? live.filter((other) => other !== id)
32
+ : [...live, id];
33
+ return ids.length === 0 ? null : { front: frontId, ids };
34
+ }
35
+ /**
36
+ * A Shift press on the tab `id`: picks the run of tabs from the one in
37
+ * front to it, both ends included, in place of the picks before. Null for a
38
+ * press on the tab in front, or on a tab not in `order`.
39
+ */
40
+ export function pickRun(order, frontId, id) {
41
+ const from = order.indexOf(frontId);
42
+ const to = order.indexOf(id);
43
+ if (from < 0 || to < 0 || from === to) {
44
+ return null;
45
+ }
46
+ return {
47
+ front: frontId,
48
+ ids: order
49
+ .slice(Math.min(from, to), Math.max(from, to) + 1)
50
+ .filter((other) => other !== frontId)
51
+ };
52
+ }
53
+ /**
54
+ * The strip's order with the tabs `carried` drawn together around `held`,
55
+ * the tab under the pointer, as a drag of picked tabs lifts them: the ones
56
+ * before it close up just before it and the ones after it just after, in
57
+ * their order, and every other tab keeps its order.
58
+ */
59
+ export function gatherTabs(order, carried, held) {
60
+ const block = order.filter((id) => id === held || carried.includes(id));
61
+ const rest = order.filter((id) => id === held || !carried.includes(id));
62
+ const at = rest.indexOf(held);
63
+ return at < 0 ? order : [...rest.slice(0, at), ...block, ...rest.slice(at + 1)];
64
+ }
65
+ /** The characters of its name a tab keeps before it folds away instead of shrinking further. */
66
+ const NAME_FLOOR = 8;
67
+ /** The characters of its context a tab keeps before its name starts to shrink. */
68
+ const CONTEXT_FLOOR = 3;
69
+ /** How many characters a part cut to `floor` takes: all of a shorter one, else `floor` and its ellipsis. */
70
+ const kept = (text, floor) => {
71
+ const length = [...text].length;
72
+ return length <= floor ? length : floor + 1;
73
+ };
74
+ /**
75
+ * The fewest characters a tab's label keeps, its ellipses counted, split
76
+ * into the context (its slash not counted) and the name: eight characters
77
+ * of the name and three of the context, or all of a shorter one. The
78
+ * context shrinks to its floor before the name loses a character: the name
79
+ * is what the eye looks for, and the context only tells two tabs apart.
80
+ */
81
+ export function tabLabelFloor(label) {
82
+ return {
83
+ context: label.context === undefined ? 0 : kept(label.context, CONTEXT_FLOOR),
84
+ name: kept(label.name, NAME_FLOOR)
85
+ };
86
+ }
87
+ /**
88
+ * The order in which a crowded strip folds its tabs into the count:
89
+ * farthest from the tab in front first and, of two as far, the later one.
90
+ * The tab in front, pinned tabs, and the following tab never fold, so they
91
+ * are left out.
92
+ */
93
+ export function foldOrder(tabs, frontId) {
94
+ const frontAt = tabs.findIndex((tab) => tab.id === frontId);
95
+ return tabs
96
+ .map((tab, index) => ({ tab, index, distance: Math.abs(index - frontAt) }))
97
+ .filter(({ tab }) => tab.id !== frontId && tab.pinned !== true && tab.following !== true)
98
+ .sort((a, b) => b.distance - a.distance || b.index - a.index)
99
+ .map(({ tab }) => tab.id);
100
+ }
101
+ /**
102
+ * How many more tabs a crowded strip folds in one step. `deficit` is how far
103
+ * the tabs on show run past their room, `widths` the foldable tabs still on
104
+ * show in fold order, and `gap` the space between two tabs. Folding one tab
105
+ * per layout pass would take a pass per tab, and a strip can hold more tabs
106
+ * than React allows passes in a row. A deficit folds at least one tab, and
107
+ * one that no tab covers folds them all.
108
+ */
109
+ export function foldsNeeded(deficit, widths, gap) {
110
+ let freed = 0;
111
+ let count = 0;
112
+ for (const width of widths) {
113
+ if (freed >= deficit) {
114
+ break;
115
+ }
116
+ freed += width + gap;
117
+ count += 1;
118
+ }
119
+ return count;
120
+ }
121
+ /**
122
+ * The strip's order while a tab is dragged along it. `held` is the dragged
123
+ * tab where the pointer has it, `boxes` the other tabs on show where the
124
+ * layout has them, and `order` every tab, folded ones included. A neighbour
125
+ * steps aside once the tab coming toward it covers half of it; one the tab
126
+ * is moving away from stays put, so a tab resting on the line between two
127
+ * places cannot flicker between them. Folded tabs keep their places: a tab
128
+ * that crosses no neighbour returns `order` itself, and one that crosses
129
+ * lands beside the last neighbour it passed. `direction` is the sign of the
130
+ * pointer's last move.
131
+ */
132
+ export function draggedTabOrder(order, held, boxes, direction) {
133
+ const mine = order.indexOf(held.id);
134
+ const rest = order.filter((id) => id !== held.id);
135
+ const shown = rest.filter((id) => boxes.some((box) => box.id === id));
136
+ const right = held.left + held.width;
137
+ const passed = shown.filter((id) => {
138
+ const box = boxes.find((candidate) => candidate.id === id);
139
+ if (box === undefined) {
140
+ return false;
141
+ }
142
+ const centre = box.left + box.width / 2;
143
+ return order.indexOf(id) < mine
144
+ ? !(direction < 0 && held.left < centre)
145
+ : direction > 0 && right > centre;
146
+ }).length;
147
+ const stayed = shown.filter((id) => order.indexOf(id) < mine).length;
148
+ // Nothing crossed: the tab keeps its place among the folded tabs too.
149
+ if (passed === stayed) {
150
+ return order;
151
+ }
152
+ // Past a neighbour, the tab lands beside it: folded tabs on the far side
153
+ // of that neighbour stay where they were.
154
+ const at = passed > stayed
155
+ ? rest.indexOf(shown[passed - 1]) + 1
156
+ : rest.indexOf(shown[passed]);
157
+ return [...rest.slice(0, at), held.id, ...rest.slice(at)];
158
+ }
@@ -3,11 +3,15 @@
3
3
  * compact controls inside them, in listing rows, and in a toolbar that
4
4
  * fits its tools to one line (`useToolbarFit`), and the keyboard of a
5
5
  * sidebar beside a page (`usePaneKeys`) with the pure key mapping and DOM
6
- * readers it is built on. Styled by the listing look under `.listing-root`.
6
+ * readers it is built on, and the tab strip a pane hangs from (`PaneTabs`)
7
+ * with the pure rules it and its host keep tab state by. Styled by the
8
+ * listing look under `.listing-root`.
7
9
  */
8
10
  export { InRowContext, QuietAction, RowIconAction, RowLinkLookContext, useInRow, type ControlVerb, type LinkLook, type QuietActionProps, type RowIconActionProps } from './PaneActions.js';
9
11
  export { PanePathBar, PaneStatus, PathFact, type PaneCrumb, type PanePathBarProps, type PaneStatusProps, type PathFactProps } from './PaneFrame.js';
10
12
  export { isTabStop, nextTabStop, pageRows, paneRow, paneRows, showRow, tabStops, verbControl, type SidebarTabStops, type TabStop } from './PaneKeys.js';
11
13
  export { movedIndex, NO_MAIN_VERBS, paneKeyAction, sameVerbs, type MainVerbs, type PaneKeyAction, type PaneKeyOptions, type PaneKeyStroke, type PaneMove } from './PaneKeys.logic.js';
14
+ export { PaneTabs, type PaneTabItem, type PaneTabsProps } from './PaneTabs.js';
15
+ export { draggedTabOrder, foldOrder, foldsNeeded, gatherTabs, pickedTabs, pickRun, tabLabelFloor, togglePick, type FoldableTab, type TabBox, type TabPicks } from './PaneTabs.logic.js';
12
16
  export { useToolbarFit } from './useToolbarFit.js';
13
17
  export { usePaneKeys, type Pane, type PaneKeys, type PaneKeysOptions } from './usePaneKeys.js';
@@ -3,11 +3,15 @@
3
3
  * compact controls inside them, in listing rows, and in a toolbar that
4
4
  * fits its tools to one line (`useToolbarFit`), and the keyboard of a
5
5
  * sidebar beside a page (`usePaneKeys`) with the pure key mapping and DOM
6
- * readers it is built on. Styled by the listing look under `.listing-root`.
6
+ * readers it is built on, and the tab strip a pane hangs from (`PaneTabs`)
7
+ * with the pure rules it and its host keep tab state by. Styled by the
8
+ * listing look under `.listing-root`.
7
9
  */
8
10
  export { InRowContext, QuietAction, RowIconAction, RowLinkLookContext, useInRow } from './PaneActions.js';
9
11
  export { PanePathBar, PaneStatus, PathFact } from './PaneFrame.js';
10
12
  export { isTabStop, nextTabStop, pageRows, paneRow, paneRows, showRow, tabStops, verbControl } from './PaneKeys.js';
11
13
  export { movedIndex, NO_MAIN_VERBS, paneKeyAction, sameVerbs } from './PaneKeys.logic.js';
14
+ export { PaneTabs } from './PaneTabs.js';
15
+ export { draggedTabOrder, foldOrder, foldsNeeded, gatherTabs, pickedTabs, pickRun, tabLabelFloor, togglePick } from './PaneTabs.logic.js';
12
16
  export { useToolbarFit } from './useToolbarFit.js';
13
17
  export { usePaneKeys } from './usePaneKeys.js';