tuidroid 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 +674 -0
- package/README.md +181 -2
- package/dist/arrange/Mover.svelte +42 -0
- package/dist/arrange/Mover.svelte.d.ts +29 -0
- package/dist/arrange/PutAway.svelte +48 -0
- package/dist/arrange/PutAway.svelte.d.ts +30 -0
- package/dist/arrange/arrangement.svelte.d.ts +27 -0
- package/dist/arrange/arrangement.svelte.js +44 -0
- package/dist/arrange/order.d.ts +7 -0
- package/dist/arrange/order.js +20 -0
- package/dist/calendar/Calendar.svelte +328 -0
- package/dist/calendar/Calendar.svelte.d.ts +28 -0
- package/dist/calendar/MonthPicker.svelte +41 -0
- package/dist/calendar/MonthPicker.svelte.d.ts +10 -0
- package/dist/calendar/YearPicker.svelte +61 -0
- package/dist/calendar/YearPicker.svelte.d.ts +11 -0
- package/dist/calendar/dates.d.ts +23 -0
- package/dist/calendar/dates.js +54 -0
- package/dist/charts/BarChart.svelte +98 -0
- package/dist/charts/BarChart.svelte.d.ts +28 -0
- package/dist/charts/ChartFrame.svelte +133 -0
- package/dist/charts/ChartFrame.svelte.d.ts +21 -0
- package/dist/charts/ColumnChart.svelte +79 -0
- package/dist/charts/ColumnChart.svelte.d.ts +20 -0
- package/dist/charts/HeatGrid.svelte +110 -0
- package/dist/charts/HeatGrid.svelte.d.ts +22 -0
- package/dist/charts/LineChart.svelte +132 -0
- package/dist/charts/LineChart.svelte.d.ts +29 -0
- package/dist/charts/StripChart.svelte +80 -0
- package/dist/charts/StripChart.svelte.d.ts +27 -0
- package/dist/charts/scale.d.ts +17 -0
- package/dist/charts/scale.js +35 -0
- package/dist/controls/AccentStepper.svelte +24 -0
- package/dist/controls/AccentStepper.svelte.d.ts +8 -0
- package/dist/controls/Button.svelte +264 -0
- package/dist/controls/Button.svelte.d.ts +26 -0
- package/dist/controls/Cycle.svelte +27 -0
- package/dist/controls/Cycle.svelte.d.ts +31 -0
- package/dist/controls/NumberStepper.svelte +28 -0
- package/dist/controls/NumberStepper.svelte.d.ts +12 -0
- package/dist/controls/OptionStepper.svelte +42 -0
- package/dist/controls/OptionStepper.svelte.d.ts +34 -0
- package/dist/controls/Segmented.svelte +72 -0
- package/dist/controls/Segmented.svelte.d.ts +35 -0
- package/dist/controls/SettingRow.svelte +59 -0
- package/dist/controls/SettingRow.svelte.d.ts +11 -0
- package/dist/controls/Stepper.svelte +151 -0
- package/dist/controls/Stepper.svelte.d.ts +17 -0
- package/dist/controls/TextInput.svelte +176 -0
- package/dist/controls/TextInput.svelte.d.ts +12 -0
- package/dist/controls/Toggle.svelte +22 -0
- package/dist/controls/Toggle.svelte.d.ts +9 -0
- package/dist/data/BarRows.svelte +75 -0
- package/dist/data/BarRows.svelte.d.ts +15 -0
- package/dist/data/CellBar.svelte +55 -0
- package/dist/data/CellBar.svelte.d.ts +13 -0
- package/dist/data/Delta.svelte +28 -0
- package/dist/data/Delta.svelte.d.ts +11 -0
- package/dist/data/Hatch.svelte +9 -0
- package/dist/data/Hatch.svelte.d.ts +8 -0
- package/dist/data/KeyValues.svelte +56 -0
- package/dist/data/KeyValues.svelte.d.ts +14 -0
- package/dist/data/Legend.svelte +64 -0
- package/dist/data/Legend.svelte.d.ts +15 -0
- package/dist/data/Meter.svelte +46 -0
- package/dist/data/Meter.svelte.d.ts +9 -0
- package/dist/data/StackedBar.svelte +64 -0
- package/dist/data/StackedBar.svelte.d.ts +14 -0
- package/dist/data/Swatch.svelte +56 -0
- package/dist/data/Swatch.svelte.d.ts +11 -0
- package/dist/data/Table.svelte +86 -0
- package/dist/data/Table.svelte.d.ts +16 -0
- package/dist/data/Value.svelte +32 -0
- package/dist/data/Value.svelte.d.ts +12 -0
- package/dist/data/cells.d.ts +27 -0
- package/dist/data/cells.js +41 -0
- package/dist/data/fit.d.ts +10 -0
- package/dist/data/fit.js +35 -0
- package/dist/gestures/drag.d.ts +28 -0
- package/dist/gestures/drag.js +110 -0
- package/dist/gestures/hold.d.ts +7 -0
- package/dist/gestures/hold.js +59 -0
- package/dist/gestures/pick.d.ts +5 -0
- package/dist/gestures/pick.js +60 -0
- package/dist/haptics.d.ts +5 -0
- package/dist/haptics.js +16 -0
- package/dist/icons/Icon.svelte +52 -0
- package/dist/icons/Icon.svelte.d.ts +17 -0
- package/dist/icons/material.d.ts +68 -0
- package/dist/icons/material.js +69 -0
- package/dist/index.d.ts +75 -0
- package/dist/index.js +91 -0
- package/dist/layout/Alert.svelte +46 -0
- package/dist/layout/Alert.svelte.d.ts +12 -0
- package/dist/layout/Block.svelte +166 -0
- package/dist/layout/Block.svelte.d.ts +22 -0
- package/dist/layout/Panes.svelte +41 -0
- package/dist/layout/Panes.svelte.d.ts +9 -0
- package/dist/layout/Rows.svelte +37 -0
- package/dist/layout/Rows.svelte.d.ts +8 -0
- package/dist/layout/Split.svelte +18 -0
- package/dist/layout/Split.svelte.d.ts +4 -0
- package/dist/layout/Stage.svelte +59 -0
- package/dist/layout/Stage.svelte.d.ts +10 -0
- package/dist/layout/Unfold.svelte +25 -0
- package/dist/layout/Unfold.svelte.d.ts +9 -0
- package/dist/lists/ListItem.svelte +75 -0
- package/dist/lists/ListItem.svelte.d.ts +13 -0
- package/dist/lists/SwipeRow.svelte +158 -0
- package/dist/lists/SwipeRow.svelte.d.ts +21 -0
- package/dist/lists/UndoRow.svelte +37 -0
- package/dist/lists/UndoRow.svelte.d.ts +10 -0
- package/dist/motion/FlipCard.svelte +197 -0
- package/dist/motion/FlipCard.svelte.d.ts +34 -0
- package/dist/motion/Hero.svelte +59 -0
- package/dist/motion/Hero.svelte.d.ts +9 -0
- package/dist/motion/ShuffleText.svelte +42 -0
- package/dist/motion/ShuffleText.svelte.d.ts +13 -0
- package/dist/motion/TypeText.svelte +68 -0
- package/dist/motion/TypeText.svelte.d.ts +11 -0
- package/dist/motion/shuffle.d.ts +24 -0
- package/dist/motion/shuffle.js +58 -0
- package/dist/motion/still.d.ts +2 -0
- package/dist/motion/still.js +7 -0
- package/dist/motion/sweep.d.ts +14 -0
- package/dist/motion/sweep.js +59 -0
- package/dist/motion/typing.d.ts +9 -0
- package/dist/motion/typing.js +19 -0
- package/dist/motion/unfold.d.ts +4 -0
- package/dist/motion/unfold.js +13 -0
- package/dist/nav/Hang.svelte +194 -0
- package/dist/nav/Hang.svelte.d.ts +15 -0
- package/dist/nav/Pager.svelte +89 -0
- package/dist/nav/Pager.svelte.d.ts +43 -0
- package/dist/nav/Pane.svelte +93 -0
- package/dist/nav/Pane.svelte.d.ts +15 -0
- package/dist/nav/Shell.svelte +40 -0
- package/dist/nav/Shell.svelte.d.ts +34 -0
- package/dist/nav/TabBar.svelte +139 -0
- package/dist/nav/TabBar.svelte.d.ts +15 -0
- package/dist/styles/base.css +87 -0
- package/dist/styles/tokens.css +253 -0
- package/dist/text/Fields.svelte +28 -0
- package/dist/text/Fields.svelte.d.ts +8 -0
- package/dist/text/fields.d.ts +6 -0
- package/dist/text/fields.js +16 -0
- package/dist/theme/FlavourButton.svelte +55 -0
- package/dist/theme/FlavourButton.svelte.d.ts +13 -0
- package/dist/theme/Theme.svelte +48 -0
- package/dist/theme/Theme.svelte.d.ts +15 -0
- package/dist/theme/palette.d.ts +23 -0
- package/dist/theme/palette.js +55 -0
- package/dist/theme/reveal.d.ts +10 -0
- package/dist/theme/reveal.js +92 -0
- package/dist/theme/theme.d.ts +15 -0
- package/dist/theme/theme.js +21 -0
- package/package.json +72 -4
package/README.md
CHANGED
|
@@ -1,3 +1,182 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tuidroid
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Svelte 5 components drawn like a terminal: line boxes, word buttons and text-cell charts, in [Catppuccin](https://catppuccin.com).
|
|
4
|
+
|
|
5
|
+
[Showcase](https://nouritsu.codeberg.page/tuidroid/) · [](https://codeberg.org/nouritsu/tuidroid/actions)
|
|
6
|
+
|
|
7
|
+
## Use
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install tuidroid
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Needs Svelte 5.59+. GPL-3.0-or-later: an app that bundles it must be GPL-compatible.
|
|
14
|
+
|
|
15
|
+
```svelte
|
|
16
|
+
<script>
|
|
17
|
+
import 'tuidroid/tokens.css' // palette and tokens, once
|
|
18
|
+
import 'tuidroid/base.css' // optional: the page and plain elements
|
|
19
|
+
import { Block, Button } from 'tuidroid'
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<Block title="Hello">
|
|
23
|
+
<Button primary>Go</Button>
|
|
24
|
+
</Block>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
- **Flavour**: `data-theme="latte|frappe|macchiato|mocha"` on any element; Mocha by default.
|
|
28
|
+
- **Accent**: `--tui-accent: var(--ctp-peach)`.
|
|
29
|
+
- **Motion**: follows reduced motion; `data-motion="off|on"` overrides it.
|
|
30
|
+
- **Restyle**: set any `--tui-*` token. Everything sits in the `tuidroid` layer, so your CSS wins.
|
|
31
|
+
|
|
32
|
+
## Components
|
|
33
|
+
|
|
34
|
+
### Theme
|
|
35
|
+
|
|
36
|
+
| Element | What it is |
|
|
37
|
+
| --------------- | ----------------------------------------------- |
|
|
38
|
+
| `Theme` | A subtree in its own flavour, accent and motion |
|
|
39
|
+
| `FlavourButton` | Steps the flavour, with a circle reveal |
|
|
40
|
+
|
|
41
|
+
### Layout
|
|
42
|
+
|
|
43
|
+
| Element | What it is |
|
|
44
|
+
| -------- | ---------------------------------------------------------- |
|
|
45
|
+
| `Block` | Rounded box with titles and buttons set into its border |
|
|
46
|
+
| `Split` | A rule across a Block |
|
|
47
|
+
| `Panes` | A column of Blocks, optionally scrolling |
|
|
48
|
+
| `Unfold` | Opens below its Block, pushing the rest down |
|
|
49
|
+
| `Stage` | A screen in three rows; the middle never moves |
|
|
50
|
+
| `Alert` | A message pinned above the bottom edge |
|
|
51
|
+
| `Rows` | Lines up settings' labels, values and controls in a column |
|
|
52
|
+
|
|
53
|
+
### Controls
|
|
54
|
+
|
|
55
|
+
| Element | What it is |
|
|
56
|
+
| --------------- | -------------------------------------------------------------- |
|
|
57
|
+
| `Button` | Box, word, glyph, edge, gate or link; can confirm on 2nd press |
|
|
58
|
+
| `Toggle` | On or off, as a word |
|
|
59
|
+
| `Cycle` | A word that steps through its options |
|
|
60
|
+
| `Segmented` | A few choices as bare words |
|
|
61
|
+
| `Stepper` | `< value >`; hold to repeat, drag to scrub |
|
|
62
|
+
| `NumberStepper` | A Stepper over a number range |
|
|
63
|
+
| `OptionStepper` | A Stepper over a list |
|
|
64
|
+
| `AccentStepper` | One of Catppuccin's 14 accents |
|
|
65
|
+
| `TextInput` | Text field with an icon and inline completion |
|
|
66
|
+
| `SettingRow` | A setting's name, value, control and hint |
|
|
67
|
+
|
|
68
|
+
### Text and motion
|
|
69
|
+
|
|
70
|
+
| Element | What it is |
|
|
71
|
+
| ------------- | ---------------------------------------------------- |
|
|
72
|
+
| `ShuffleText` | Text that scrambles into its new value |
|
|
73
|
+
| `TypeText` | Text typed out behind a block cursor |
|
|
74
|
+
| `Hero` | The screen's main word, fitted to the width |
|
|
75
|
+
| `FlipCard` | A Block that turns over behind a scan line |
|
|
76
|
+
| `Fields` | A status line of fixed-width fields |
|
|
77
|
+
| `Icon` | An icon drawn as a character; Material set or a path |
|
|
78
|
+
|
|
79
|
+
### Data
|
|
80
|
+
|
|
81
|
+
| Element | What it is |
|
|
82
|
+
| ------------ | ---------------------------------------- |
|
|
83
|
+
| `Value` | A live value, bold in the accent or tone |
|
|
84
|
+
| `Delta` | ▲ or ▼ against the previous value |
|
|
85
|
+
| `Swatch` | A square of colour at text size |
|
|
86
|
+
| `Legend` | Swatches and names for a chart |
|
|
87
|
+
| `Hatch` | Diagonal-line SVG fill for a near miss |
|
|
88
|
+
| `CellBar` | A share as `█░` text cells |
|
|
89
|
+
| `StackedBar` | Parts of a whole in one line of cells |
|
|
90
|
+
| `BarRows` | Labelled text bars, one per row |
|
|
91
|
+
| `Meter` | A thin smooth bar for a share |
|
|
92
|
+
| `KeyValues` | Records with notes at the right edge |
|
|
93
|
+
| `Table` | A table without lines |
|
|
94
|
+
|
|
95
|
+
### Charts
|
|
96
|
+
|
|
97
|
+
All read by tap or sideways drag.
|
|
98
|
+
|
|
99
|
+
| Element | What it is |
|
|
100
|
+
| ------------- | ---------------------------------------------- |
|
|
101
|
+
| `ChartFrame` | The SVG every chart draws on |
|
|
102
|
+
| `BarChart` | Stacked bars over time, with a goal mark |
|
|
103
|
+
| `ColumnChart` | A few labelled columns |
|
|
104
|
+
| `LineChart` | Points with a trend line and guides |
|
|
105
|
+
| `HeatGrid` | Days in weeks, coloured by how much |
|
|
106
|
+
| `StripChart` | A row per day, spans from midnight to midnight |
|
|
107
|
+
|
|
108
|
+
### Calendar
|
|
109
|
+
|
|
110
|
+
| Element | What it is |
|
|
111
|
+
| ------------- | -------------------------------- |
|
|
112
|
+
| `Calendar` | A month grid; swipe for the next |
|
|
113
|
+
| `MonthPicker` | The twelve months as words |
|
|
114
|
+
| `YearPicker` | `< 2026 >` with jumps |
|
|
115
|
+
|
|
116
|
+
### Lists
|
|
117
|
+
|
|
118
|
+
| Element | What it is |
|
|
119
|
+
| ---------- | ------------------------------------------ |
|
|
120
|
+
| `ListItem` | An entry: title, actions and a colour mark |
|
|
121
|
+
| `SwipeRow` | Swipe sideways to uncover an action |
|
|
122
|
+
| `UndoRow` | What a deleted entry leaves, with undo |
|
|
123
|
+
|
|
124
|
+
### Navigation
|
|
125
|
+
|
|
126
|
+
| Element | What it is |
|
|
127
|
+
| -------- | ----------------------------------------------- |
|
|
128
|
+
| `Shell` | A phone app's frame: pages and tabs |
|
|
129
|
+
| `Pager` | Pages side by side, swiped between |
|
|
130
|
+
| `TabBar` | Tabs along the bottom, ratatui style |
|
|
131
|
+
| `Hang` | A pane that pushes the page from above or below |
|
|
132
|
+
| `Pane` | A Block as a dialog, with Close and an action |
|
|
133
|
+
|
|
134
|
+
### Arranging
|
|
135
|
+
|
|
136
|
+
| Element | What it is |
|
|
137
|
+
| ------------- | ------------------------------------------- |
|
|
138
|
+
| `Arrangement` | A column's order and the blocks put away |
|
|
139
|
+
| `Mover` | `˄ ˅ ✕` in a Block's edge |
|
|
140
|
+
| `PutAway` | The blocks put away, each one to bring back |
|
|
141
|
+
|
|
142
|
+
### Helpers
|
|
143
|
+
|
|
144
|
+
| Export | What it is |
|
|
145
|
+
| ------------------------------------ | ------------------------------------------- |
|
|
146
|
+
| `drag`, `hold`, `pick` | Swipes, hold-to-repeat, chart picking |
|
|
147
|
+
| `unfold`, `sweepIn`, `runShuffle` | Transitions behind the components |
|
|
148
|
+
| `still` | Whether motion is held still |
|
|
149
|
+
| `tick`, `buzz`, `setHaptics` | Vibration feedback |
|
|
150
|
+
| `pad`, `dashed` | Fixed-width field text |
|
|
151
|
+
| `monthRows`, `isoWeek`, `dayKey` | Calendar arithmetic |
|
|
152
|
+
| `niceScale`, `progressCells`, `fit` | Chart axes, cell bars, characters per width |
|
|
153
|
+
| `FLAVOURS`, `ACCENTS`, `ctp`, `tone` | Palette names and their CSS |
|
|
154
|
+
| `moveIn`, `toOrder` | Ordering for arranged things |
|
|
155
|
+
|
|
156
|
+
## Develop
|
|
157
|
+
|
|
158
|
+
```sh
|
|
159
|
+
direnv allow # or: nix develop --no-pure-eval
|
|
160
|
+
npm run dev # showcase on localhost:5173
|
|
161
|
+
npm test # unit tests in Node, components in Chromium
|
|
162
|
+
npm run check # svelte-check
|
|
163
|
+
nix fmt # format
|
|
164
|
+
nix flake check --no-pure-eval # all checks
|
|
165
|
+
nix build # result/site and result/dist
|
|
166
|
+
nix run # serve the built showcase
|
|
167
|
+
nix run .#publish -- --dry-run # what npm would get
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
Release: bump `version` in `package.json`, then push a tag `v<version>`. CI checks it and publishes to npm.
|
|
171
|
+
|
|
172
|
+
| Path | What it is |
|
|
173
|
+
| --------------------- | ------------------------------------------------------------------- |
|
|
174
|
+
| `src/lib/` | The library, a folder per group |
|
|
175
|
+
| `src/routes/` | The showcase |
|
|
176
|
+
| `src/tests/` | Component test harnesses |
|
|
177
|
+
| `nix/` | The package, its checks and the formatters |
|
|
178
|
+
| `.forgejo/workflows/` | CI: checks on `main` and PRs, Pages from `main`, npm from `v*` tags |
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
GPL-3.0-or-later. Palette from Catppuccin (MIT); icons from Material Icons (Apache-2.0).
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends string">
|
|
2
|
+
import Button from '../controls/Button.svelte'
|
|
3
|
+
import type { Arrangement } from './arrangement.svelte'
|
|
4
|
+
|
|
5
|
+
// A block's moves while its column is arranged, set into its top edge (a Block's
|
|
6
|
+
// headingRight): ˄ and ˅ move it past its neighbours, ✕ puts it away. `name` is the
|
|
7
|
+
// block's, for a screen reader.
|
|
8
|
+
let { arrangement, id, name }: { arrangement: Arrangement<T>; id: T; name: string } = $props()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<span class="tui-mover">
|
|
12
|
+
<Button
|
|
13
|
+
variant="glyph"
|
|
14
|
+
icon="keyboard_arrow_up"
|
|
15
|
+
aria-label="Move {name} up"
|
|
16
|
+
disabled={!arrangement.canMove(id, -1)}
|
|
17
|
+
onclick={() => arrangement.move(id, -1)}
|
|
18
|
+
/>
|
|
19
|
+
<Button
|
|
20
|
+
variant="glyph"
|
|
21
|
+
icon="keyboard_arrow_down"
|
|
22
|
+
aria-label="Move {name} down"
|
|
23
|
+
disabled={!arrangement.canMove(id, 1)}
|
|
24
|
+
onclick={() => arrangement.move(id, 1)}
|
|
25
|
+
/>
|
|
26
|
+
<Button variant="glyph" icon="close" quit aria-label="Put {name} away" onclick={() => arrangement.hide(id)} />
|
|
27
|
+
</span>
|
|
28
|
+
|
|
29
|
+
<style>
|
|
30
|
+
@layer tuidroid {
|
|
31
|
+
/* Glyphs on the border line, their tap areas reaching above and below it. */
|
|
32
|
+
.tui-mover {
|
|
33
|
+
display: inline-flex;
|
|
34
|
+
margin: -0.45em -0.6ch;
|
|
35
|
+
|
|
36
|
+
& :global(.tui-button.glyph) {
|
|
37
|
+
min-width: 2em;
|
|
38
|
+
font-size: 1em;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Arrangement } from './arrangement.svelte';
|
|
2
|
+
declare function $$render<T extends string>(): {
|
|
3
|
+
props: {
|
|
4
|
+
arrangement: Arrangement<T>;
|
|
5
|
+
id: T;
|
|
6
|
+
name: string;
|
|
7
|
+
};
|
|
8
|
+
exports: {};
|
|
9
|
+
bindings: "";
|
|
10
|
+
slots: {};
|
|
11
|
+
events: {};
|
|
12
|
+
};
|
|
13
|
+
declare class __sveltets_Render<T extends string> {
|
|
14
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
15
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
16
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
17
|
+
bindings(): "";
|
|
18
|
+
exports(): {};
|
|
19
|
+
}
|
|
20
|
+
interface $$IsomorphicComponent {
|
|
21
|
+
new <T extends string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
22
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
23
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
24
|
+
<T extends string>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
25
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
26
|
+
}
|
|
27
|
+
declare const Mover: $$IsomorphicComponent;
|
|
28
|
+
type Mover<T extends string> = InstanceType<typeof Mover<T>>;
|
|
29
|
+
export default Mover;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends string">
|
|
2
|
+
import Button from '../controls/Button.svelte'
|
|
3
|
+
import Block from '../layout/Block.svelte'
|
|
4
|
+
import type { Arrangement } from './arrangement.svelte'
|
|
5
|
+
|
|
6
|
+
// The blocks put away while arranging, each a [ + name ] word that brings it back, with
|
|
7
|
+
// ↺ Defaults (every block back, in the first order) and ✓ Done (arranging ends) in the
|
|
8
|
+
// bottom edge. Unfold it below the block that starts arranging.
|
|
9
|
+
interface Props {
|
|
10
|
+
arrangement: Arrangement<T>
|
|
11
|
+
names: Record<T, string>
|
|
12
|
+
title?: string
|
|
13
|
+
empty?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let { arrangement, names, title = 'Put away', empty = 'Nothing put away. ✕ on a block puts it here.' }: Props = $props()
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<Block {title} icon="visibility_off">
|
|
20
|
+
{#if arrangement.hidden.length}
|
|
21
|
+
<div class="words">
|
|
22
|
+
{#each arrangement.hidden as id (id)}<Button variant="word" icon="add" onclick={() => arrangement.show(id)}>{names[id]}</Button
|
|
23
|
+
>{/each}
|
|
24
|
+
</div>
|
|
25
|
+
{:else}
|
|
26
|
+
<p class="empty">{empty}</p>
|
|
27
|
+
{/if}
|
|
28
|
+
{#snippet actions()}
|
|
29
|
+
<Button variant="edge" icon="restart_alt" disabled={!arrangement.changed} onclick={() => arrangement.reset()}>Defaults</Button>
|
|
30
|
+
<Button variant="edge" icon="check" primary onclick={() => (arrangement.arranging = false)}>Done</Button>
|
|
31
|
+
{/snippet}
|
|
32
|
+
</Block>
|
|
33
|
+
|
|
34
|
+
<style>
|
|
35
|
+
@layer tuidroid {
|
|
36
|
+
.words {
|
|
37
|
+
display: flex;
|
|
38
|
+
flex-wrap: wrap;
|
|
39
|
+
gap: 0 2ch;
|
|
40
|
+
margin-left: -0.3ch;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.empty {
|
|
44
|
+
margin: 0.2em 0;
|
|
45
|
+
color: var(--tui-muted);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
</style>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Arrangement } from './arrangement.svelte';
|
|
2
|
+
declare function $$render<T extends string>(): {
|
|
3
|
+
props: {
|
|
4
|
+
arrangement: Arrangement<T>;
|
|
5
|
+
names: Record<T, string>;
|
|
6
|
+
title?: string;
|
|
7
|
+
empty?: string;
|
|
8
|
+
};
|
|
9
|
+
exports: {};
|
|
10
|
+
bindings: "";
|
|
11
|
+
slots: {};
|
|
12
|
+
events: {};
|
|
13
|
+
};
|
|
14
|
+
declare class __sveltets_Render<T extends string> {
|
|
15
|
+
props(): ReturnType<typeof $$render<T>>['props'];
|
|
16
|
+
events(): ReturnType<typeof $$render<T>>['events'];
|
|
17
|
+
slots(): ReturnType<typeof $$render<T>>['slots'];
|
|
18
|
+
bindings(): "";
|
|
19
|
+
exports(): {};
|
|
20
|
+
}
|
|
21
|
+
interface $$IsomorphicComponent {
|
|
22
|
+
new <T extends string>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<T>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<T>['props']>, ReturnType<__sveltets_Render<T>['events']>, ReturnType<__sveltets_Render<T>['slots']>> & {
|
|
23
|
+
$$bindings?: ReturnType<__sveltets_Render<T>['bindings']>;
|
|
24
|
+
} & ReturnType<__sveltets_Render<T>['exports']>;
|
|
25
|
+
<T extends string>(internal: unknown, props: ReturnType<__sveltets_Render<T>['props']> & {}): ReturnType<__sveltets_Render<T>['exports']>;
|
|
26
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
27
|
+
}
|
|
28
|
+
declare const PutAway: $$IsomorphicComponent;
|
|
29
|
+
type PutAway<T extends string> = InstanceType<typeof PutAway<T>>;
|
|
30
|
+
export default PutAway;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface SavedArrangement<T> {
|
|
2
|
+
order: T[];
|
|
3
|
+
hidden: T[];
|
|
4
|
+
}
|
|
5
|
+
export declare class Arrangement<T extends string> {
|
|
6
|
+
readonly defaults: readonly T[];
|
|
7
|
+
order: T[];
|
|
8
|
+
hidden: T[];
|
|
9
|
+
arranging: boolean;
|
|
10
|
+
/** The blocks shown, in order. */
|
|
11
|
+
readonly shown: T[];
|
|
12
|
+
/** Whether anything differs from the defaults: what Reset would undo. */
|
|
13
|
+
readonly changed: boolean;
|
|
14
|
+
/** `saved` is read as it comes (from storage, a backup): what is not one of `defaults` goes. */
|
|
15
|
+
constructor(defaults: readonly T[], saved?: {
|
|
16
|
+
order?: unknown;
|
|
17
|
+
hidden?: unknown;
|
|
18
|
+
});
|
|
19
|
+
/** Swaps `id` with the next one shown either way; the put-away ones keep out of the way. */
|
|
20
|
+
move(id: T, by: -1 | 1): void;
|
|
21
|
+
canMove(id: T, by: -1 | 1): boolean;
|
|
22
|
+
hide(id: T): void;
|
|
23
|
+
show(id: T): void;
|
|
24
|
+
/** Every block back, in the first order. */
|
|
25
|
+
reset(): void;
|
|
26
|
+
get saved(): SavedArrangement<T>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// What a column of blocks is arranged as: their order, the ones put away, and whether the
|
|
2
|
+
// user is arranging now. Mover sets ˄ ˅ ✕ into a block's edge to change it; PutAway brings
|
|
3
|
+
// them back. Keep `saved` to restore it next time.
|
|
4
|
+
import { moveIn, toOrder, toSubset } from './order';
|
|
5
|
+
export class Arrangement {
|
|
6
|
+
defaults;
|
|
7
|
+
order = $state([]);
|
|
8
|
+
hidden = $state([]);
|
|
9
|
+
arranging = $state(false);
|
|
10
|
+
/** The blocks shown, in order. */
|
|
11
|
+
shown = $derived(this.order.filter((id) => !this.hidden.includes(id)));
|
|
12
|
+
/** Whether anything differs from the defaults: what Reset would undo. */
|
|
13
|
+
changed = $derived(this.hidden.length > 0 || this.order.some((id, i) => id !== this.defaults[i]));
|
|
14
|
+
/** `saved` is read as it comes (from storage, a backup): what is not one of `defaults` goes. */
|
|
15
|
+
constructor(defaults, saved) {
|
|
16
|
+
this.defaults = defaults;
|
|
17
|
+
this.order = toOrder(saved?.order, defaults);
|
|
18
|
+
this.hidden = toSubset(saved?.hidden, defaults);
|
|
19
|
+
}
|
|
20
|
+
/** Swaps `id` with the next one shown either way; the put-away ones keep out of the way. */
|
|
21
|
+
move(id, by) {
|
|
22
|
+
const next = moveIn(this.shown, id, by);
|
|
23
|
+
this.order = [...next, ...this.order.filter((p) => !next.includes(p))];
|
|
24
|
+
}
|
|
25
|
+
canMove(id, by) {
|
|
26
|
+
const at = this.shown.indexOf(id);
|
|
27
|
+
return at >= 0 && at + by >= 0 && at + by < this.shown.length;
|
|
28
|
+
}
|
|
29
|
+
hide(id) {
|
|
30
|
+
if (!this.hidden.includes(id))
|
|
31
|
+
this.hidden = [...this.hidden, id];
|
|
32
|
+
}
|
|
33
|
+
show(id) {
|
|
34
|
+
this.hidden = this.hidden.filter((h) => h !== id);
|
|
35
|
+
}
|
|
36
|
+
/** Every block back, in the first order. */
|
|
37
|
+
reset() {
|
|
38
|
+
this.order = [...this.defaults];
|
|
39
|
+
this.hidden = [];
|
|
40
|
+
}
|
|
41
|
+
get saved() {
|
|
42
|
+
return { order: [...this.order], hidden: [...this.hidden] };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Moves `id` one place along `order`, towards the start for -1; at an end it stays. */
|
|
2
|
+
export declare function moveIn<T>(order: readonly T[], id: T, by: -1 | 1): T[];
|
|
3
|
+
/** `v` as an order of every one of `all`: the known ones in their saved order, then any it
|
|
4
|
+
* lacks (one a later version added) in their default place at the end. */
|
|
5
|
+
export declare function toOrder<T>(v: unknown, all: readonly T[]): T[];
|
|
6
|
+
/** `v` as a set of the ones in `allowed`, without repeats, in `allowed`'s order. */
|
|
7
|
+
export declare const toSubset: <T>(v: unknown, allowed: readonly T[]) => T[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Orders of things the user lays out (a page's blocks, an app's tabs): plain functions, so
|
|
2
|
+
// saved orders can be checked with them too.
|
|
3
|
+
/** Moves `id` one place along `order`, towards the start for -1; at an end it stays. */
|
|
4
|
+
export function moveIn(order, id, by) {
|
|
5
|
+
const from = order.indexOf(id);
|
|
6
|
+
const to = from + by;
|
|
7
|
+
if (from < 0 || to < 0 || to >= order.length)
|
|
8
|
+
return [...order];
|
|
9
|
+
const next = [...order];
|
|
10
|
+
[next[from], next[to]] = [next[to], next[from]];
|
|
11
|
+
return next;
|
|
12
|
+
}
|
|
13
|
+
/** `v` as an order of every one of `all`: the known ones in their saved order, then any it
|
|
14
|
+
* lacks (one a later version added) in their default place at the end. */
|
|
15
|
+
export function toOrder(v, all) {
|
|
16
|
+
const saved = Array.isArray(v) ? v.filter((x, i) => all.includes(x) && v.indexOf(x) === i) : [];
|
|
17
|
+
return [...saved, ...all.filter((x) => !saved.includes(x))];
|
|
18
|
+
}
|
|
19
|
+
/** `v` as a set of the ones in `allowed`, without repeats, in `allowed`'s order. */
|
|
20
|
+
export const toSubset = (v, allowed) => (Array.isArray(v) ? allowed.filter((x) => v.includes(x)) : []);
|