@silvery/examples 0.17.3 → 0.17.5
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/dist/UPNG-ShUlaTDh.mjs +5074 -0
- package/dist/__vite-browser-external-2447137e-Bopa5BFR.mjs +4 -0
- package/dist/_banner-A70_y2Vi.mjs +43 -0
- package/dist/ansi-0VXlUmNn.mjs +16397 -0
- package/dist/apng-B0gRaDVT.mjs +3 -0
- package/dist/apng-BTRDTfDW.mjs +68 -0
- package/dist/apps/aichat/index.mjs +1298 -0
- package/dist/apps/app-todo.mjs +138 -0
- package/dist/apps/async-data.mjs +203 -0
- package/dist/apps/cli-wizard.mjs +338 -0
- package/dist/apps/clipboard.mjs +197 -0
- package/dist/apps/components.mjs +863 -0
- package/dist/apps/data-explorer.mjs +482 -0
- package/dist/apps/dev-tools.mjs +396 -0
- package/dist/apps/explorer.mjs +697 -0
- package/dist/apps/gallery.mjs +765 -0
- package/dist/apps/inline-bench.mjs +115 -0
- package/dist/apps/kanban.mjs +279 -0
- package/dist/apps/layout-ref.mjs +186 -0
- package/dist/apps/outline.mjs +202 -0
- package/dist/apps/paste-demo.mjs +188 -0
- package/dist/apps/scroll.mjs +85 -0
- package/dist/apps/search-filter.mjs +286 -0
- package/dist/apps/selection.mjs +354 -0
- package/dist/apps/spatial-focus-demo.mjs +387 -0
- package/dist/apps/task-list.mjs +257 -0
- package/dist/apps/terminal-caps-demo.mjs +314 -0
- package/dist/apps/terminal.mjs +871 -0
- package/dist/apps/text-selection-demo.mjs +253 -0
- package/dist/apps/textarea.mjs +177 -0
- package/dist/apps/theme.mjs +660 -0
- package/dist/apps/transform.mjs +214 -0
- package/dist/apps/virtual-10k.mjs +421 -0
- package/dist/assets/resvgjs.darwin-arm64-BtufyGW1.node +0 -0
- package/dist/backends-Dj-11kZF.mjs +1179 -0
- package/dist/backends-U3QwStfO.mjs +3 -0
- package/dist/{cli.mjs → bin/cli.mjs} +15 -19
- package/dist/chunk-BSw8zbkd.mjs +37 -0
- package/dist/components/counter.mjs +47 -0
- package/dist/components/hello.mjs +30 -0
- package/dist/components/progress-bar.mjs +58 -0
- package/dist/components/select-list.mjs +84 -0
- package/dist/components/spinner.mjs +56 -0
- package/dist/components/text-input.mjs +61 -0
- package/dist/components/virtual-list.mjs +50 -0
- package/dist/flexily-zero-adapter-ByVzLTFP.mjs +3374 -0
- package/dist/gif-B6NGH5gs.mjs +3 -0
- package/dist/gif-CfkOF-iG.mjs +71 -0
- package/dist/gifenc-BI4ihP_T.mjs +728 -0
- package/dist/key-mapping-5oYQdAQE.mjs +3 -0
- package/dist/key-mapping-D4LR1go6.mjs +130 -0
- package/dist/layout/dashboard.mjs +1203 -0
- package/dist/layout/live-resize.mjs +302 -0
- package/dist/layout/overflow.mjs +69 -0
- package/dist/layout/text-layout.mjs +334 -0
- package/dist/node-nsrAOjH4.mjs +1083 -0
- package/dist/plugins-CT0DdV_E.mjs +3056 -0
- package/dist/resvg-js-Cnk2o49d.mjs +201 -0
- package/dist/src-9ZhfQyzD.mjs +814 -0
- package/dist/src-CUUOuRH6.mjs +5322 -0
- package/dist/src-jO3Zuzjj.mjs +23538 -0
- package/dist/usingCtx-CsEf0xO3.mjs +57 -0
- package/dist/yoga-adapter-BSQHuMV9.mjs +237 -0
- package/package.json +21 -14
- package/_banner.tsx +0 -60
- package/apps/aichat/components.tsx +0 -469
- package/apps/aichat/index.tsx +0 -220
- package/apps/aichat/script.ts +0 -460
- package/apps/aichat/state.ts +0 -325
- package/apps/aichat/types.ts +0 -19
- package/apps/app-todo.tsx +0 -201
- package/apps/async-data.tsx +0 -196
- package/apps/cli-wizard.tsx +0 -332
- package/apps/clipboard.tsx +0 -183
- package/apps/components.tsx +0 -658
- package/apps/data-explorer.tsx +0 -490
- package/apps/dev-tools.tsx +0 -395
- package/apps/explorer.tsx +0 -731
- package/apps/gallery.tsx +0 -653
- package/apps/inline-bench.tsx +0 -138
- package/apps/kanban.tsx +0 -265
- package/apps/layout-ref.tsx +0 -173
- package/apps/outline.tsx +0 -160
- package/apps/panes/index.tsx +0 -203
- package/apps/paste-demo.tsx +0 -185
- package/apps/scroll.tsx +0 -80
- package/apps/search-filter.tsx +0 -240
- package/apps/selection.tsx +0 -346
- package/apps/spatial-focus-demo.tsx +0 -372
- package/apps/task-list.tsx +0 -271
- package/apps/terminal-caps-demo.tsx +0 -317
- package/apps/terminal.tsx +0 -784
- package/apps/text-selection-demo.tsx +0 -193
- package/apps/textarea.tsx +0 -155
- package/apps/theme.tsx +0 -515
- package/apps/transform.tsx +0 -229
- package/apps/virtual-10k.tsx +0 -405
- package/apps/vterm-demo/index.tsx +0 -216
- package/components/counter.tsx +0 -49
- package/components/hello.tsx +0 -38
- package/components/progress-bar.tsx +0 -52
- package/components/select-list.tsx +0 -54
- package/components/spinner.tsx +0 -44
- package/components/text-input.tsx +0 -61
- package/components/virtual-list.tsx +0 -56
- package/dist/cli.d.mts +0 -1
- package/dist/cli.mjs.map +0 -1
- package/layout/dashboard.tsx +0 -953
- package/layout/live-resize.tsx +0 -282
- package/layout/overflow.tsx +0 -51
- package/layout/text-layout.tsx +0 -283
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { D as TerminalBuffer, N as init_buffer, i as outputPhase, r as createOutputPhase } from "../ansi-0VXlUmNn.mjs";
|
|
2
|
+
//#region apps/inline-bench.tsx
|
|
3
|
+
init_buffer();
|
|
4
|
+
const RUNS = 500;
|
|
5
|
+
function fillBuffer(buf, rows, prefix = "") {
|
|
6
|
+
for (let y = 0; y < rows; y++) {
|
|
7
|
+
const text = `${prefix}Item ${y}: Content line with some styling and longer text here`;
|
|
8
|
+
for (let x = 0; x < Math.min(text.length, buf.width); x++) buf.setCell(x, y, { char: text[x] });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
function benchmarkOutputPhase(name, width, height, contentRows, changedCells, forceFullRender) {
|
|
12
|
+
const timings = [];
|
|
13
|
+
const bytes = [];
|
|
14
|
+
for (let i = 0; i < RUNS; i++) {
|
|
15
|
+
const prev = new TerminalBuffer(width, height);
|
|
16
|
+
fillBuffer(prev, contentRows);
|
|
17
|
+
const next = new TerminalBuffer(width, height);
|
|
18
|
+
fillBuffer(next, contentRows);
|
|
19
|
+
for (let c = 0; c < changedCells; c++) {
|
|
20
|
+
const row = Math.floor(c / Math.max(changedCells, 1) * contentRows);
|
|
21
|
+
const col = c % Math.min(10, width);
|
|
22
|
+
next.setCell(col, row, { char: "X" });
|
|
23
|
+
}
|
|
24
|
+
if (forceFullRender) {
|
|
25
|
+
outputPhase(null, prev, "inline", 0, height);
|
|
26
|
+
const t0 = performance.now();
|
|
27
|
+
const output = outputPhase(prev, next, "inline", 0, height);
|
|
28
|
+
const t1 = performance.now();
|
|
29
|
+
timings.push(t1 - t0);
|
|
30
|
+
bytes.push(output.length);
|
|
31
|
+
} else {
|
|
32
|
+
const render = createOutputPhase({});
|
|
33
|
+
render(null, prev, "inline", 0, height);
|
|
34
|
+
const t0 = performance.now();
|
|
35
|
+
const output = render(prev, next, "inline", 0, height);
|
|
36
|
+
const t1 = performance.now();
|
|
37
|
+
timings.push(t1 - t0);
|
|
38
|
+
bytes.push(output.length);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
timings.sort((a, b) => a - b);
|
|
42
|
+
bytes.sort((a, b) => a - b);
|
|
43
|
+
return {
|
|
44
|
+
name,
|
|
45
|
+
timings,
|
|
46
|
+
bytes
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function printResult(r) {
|
|
50
|
+
const p50t = r.timings[Math.floor(r.timings.length * .5)];
|
|
51
|
+
const p95t = r.timings[Math.floor(r.timings.length * .95)];
|
|
52
|
+
const p50b = r.bytes[Math.floor(r.bytes.length * .5)];
|
|
53
|
+
const avgB = r.bytes.reduce((a, b) => a + b, 0) / r.bytes.length;
|
|
54
|
+
console.log(` ${r.name.padEnd(40)} p50=${p50t.toFixed(3).padStart(7)}ms p95=${p95t.toFixed(3).padStart(7)}ms bytes=${Math.round(p50b).toString().padStart(6)} (avg ${Math.round(avgB)})`);
|
|
55
|
+
}
|
|
56
|
+
function printComparison(full, incr) {
|
|
57
|
+
const fullP50b = full.bytes[Math.floor(full.bytes.length * .5)];
|
|
58
|
+
const incrP50b = incr.bytes[Math.floor(incr.bytes.length * .5)];
|
|
59
|
+
const fullP50t = full.timings[Math.floor(full.timings.length * .5)];
|
|
60
|
+
const incrP50t = incr.timings[Math.floor(incr.timings.length * .5)];
|
|
61
|
+
const byteRatio = fullP50b / Math.max(incrP50b, 1);
|
|
62
|
+
const timeRatio = fullP50t / Math.max(incrP50t, .001);
|
|
63
|
+
console.log(` ${"→ savings".padEnd(40)} time=${timeRatio.toFixed(1)}x faster bytes=${byteRatio.toFixed(0)}x fewer (${fullP50b} → ${incrP50b})`);
|
|
64
|
+
}
|
|
65
|
+
async function main() {
|
|
66
|
+
console.log(`\n═══ Inline Output Phase: Full vs Incremental (${RUNS} runs) ═══\n`);
|
|
67
|
+
for (const cfg of [
|
|
68
|
+
{
|
|
69
|
+
label: "10 rows, 1 change",
|
|
70
|
+
w: 80,
|
|
71
|
+
h: 20,
|
|
72
|
+
rows: 10,
|
|
73
|
+
changes: 1
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: "30 rows, 1 change",
|
|
77
|
+
w: 120,
|
|
78
|
+
h: 40,
|
|
79
|
+
rows: 30,
|
|
80
|
+
changes: 1
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
label: "50 rows, 1 change",
|
|
84
|
+
w: 120,
|
|
85
|
+
h: 60,
|
|
86
|
+
rows: 50,
|
|
87
|
+
changes: 1
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
label: "50 rows, 3 changes",
|
|
91
|
+
w: 120,
|
|
92
|
+
h: 60,
|
|
93
|
+
rows: 50,
|
|
94
|
+
changes: 3
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
label: "50 rows, 10 changes",
|
|
98
|
+
w: 120,
|
|
99
|
+
h: 60,
|
|
100
|
+
rows: 50,
|
|
101
|
+
changes: 10
|
|
102
|
+
}
|
|
103
|
+
]) {
|
|
104
|
+
console.log(`--- ${cfg.label} ---`);
|
|
105
|
+
const full = benchmarkOutputPhase(`full render`, cfg.w, cfg.h, cfg.rows, cfg.changes, true);
|
|
106
|
+
const incr = benchmarkOutputPhase(`incremental`, cfg.w, cfg.h, cfg.rows, cfg.changes, false);
|
|
107
|
+
printResult(full);
|
|
108
|
+
printResult(incr);
|
|
109
|
+
printComparison(full, incr);
|
|
110
|
+
console.log();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (import.meta.main) await main();
|
|
114
|
+
//#endregion
|
|
115
|
+
export { main };
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { t as _usingCtx } from "../usingCtx-CsEf0xO3.mjs";
|
|
2
|
+
import { t as ExampleBanner } from "../_banner-A70_y2Vi.mjs";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Box, Text, createTerm, render, useApp, useInput } from "silvery";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region apps/kanban.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Kanban Board Example
|
|
9
|
+
*
|
|
10
|
+
* A 3-column kanban board demonstrating:
|
|
11
|
+
* - Todo, In Progress, Done columns
|
|
12
|
+
* - Move items between columns with arrow keys
|
|
13
|
+
* - Each column uses native overflow="scroll" for scrolling
|
|
14
|
+
* - Flexbox layout for proportional sizing
|
|
15
|
+
*/
|
|
16
|
+
const meta = {
|
|
17
|
+
name: "Kanban Board",
|
|
18
|
+
description: "3-column kanban with card movement and independent scroll",
|
|
19
|
+
demo: true,
|
|
20
|
+
features: [
|
|
21
|
+
"Box flexDirection",
|
|
22
|
+
"useInput",
|
|
23
|
+
"backgroundColor",
|
|
24
|
+
"multi-column layout"
|
|
25
|
+
]
|
|
26
|
+
};
|
|
27
|
+
const initialColumns = [
|
|
28
|
+
{
|
|
29
|
+
id: "todo",
|
|
30
|
+
title: "To Do",
|
|
31
|
+
cards: [
|
|
32
|
+
{
|
|
33
|
+
id: 1,
|
|
34
|
+
title: "Design new landing page",
|
|
35
|
+
tags: ["design"]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: 2,
|
|
39
|
+
title: "Write API documentation",
|
|
40
|
+
tags: ["docs"]
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 3,
|
|
44
|
+
title: "Set up monitoring",
|
|
45
|
+
tags: ["devops"]
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
id: 4,
|
|
49
|
+
title: "Create onboarding flow",
|
|
50
|
+
tags: ["ux"]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
id: 5,
|
|
54
|
+
title: "Database optimization",
|
|
55
|
+
tags: ["backend"]
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: 6,
|
|
59
|
+
title: "Mobile responsive fixes",
|
|
60
|
+
tags: ["frontend"]
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
id: 7,
|
|
64
|
+
title: "Add dark mode",
|
|
65
|
+
tags: ["frontend", "ux"]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
id: 8,
|
|
69
|
+
title: "Implement caching",
|
|
70
|
+
tags: ["backend"]
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
id: "inProgress",
|
|
76
|
+
title: "In Progress",
|
|
77
|
+
cards: [
|
|
78
|
+
{
|
|
79
|
+
id: 9,
|
|
80
|
+
title: "User authentication",
|
|
81
|
+
tags: ["backend", "security"]
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
id: 10,
|
|
85
|
+
title: "Dashboard redesign",
|
|
86
|
+
tags: ["frontend", "design"]
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
id: 11,
|
|
90
|
+
title: "API rate limiting",
|
|
91
|
+
tags: ["backend"]
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: "done",
|
|
97
|
+
title: "Done",
|
|
98
|
+
cards: [
|
|
99
|
+
{
|
|
100
|
+
id: 12,
|
|
101
|
+
title: "Project setup",
|
|
102
|
+
tags: ["devops"]
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
id: 13,
|
|
106
|
+
title: "CI/CD pipeline",
|
|
107
|
+
tags: ["devops"]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
id: 14,
|
|
111
|
+
title: "Initial wireframes",
|
|
112
|
+
tags: ["design"]
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
id: 15,
|
|
116
|
+
title: "Database schema",
|
|
117
|
+
tags: ["backend"]
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
];
|
|
122
|
+
const tagColors = {
|
|
123
|
+
frontend: "$info",
|
|
124
|
+
backend: "$accent",
|
|
125
|
+
design: "$warning",
|
|
126
|
+
devops: "$success",
|
|
127
|
+
docs: "$primary",
|
|
128
|
+
ux: "$muted",
|
|
129
|
+
security: "$error"
|
|
130
|
+
};
|
|
131
|
+
function Tag({ name }) {
|
|
132
|
+
return /* @__PURE__ */ jsxs(Text, {
|
|
133
|
+
color: tagColors[name] ?? "$muted",
|
|
134
|
+
dim: true,
|
|
135
|
+
children: ["#", name]
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function CardComponent({ card, isSelected }) {
|
|
139
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
140
|
+
flexDirection: "column",
|
|
141
|
+
borderStyle: "round",
|
|
142
|
+
borderColor: isSelected ? "$primary" : "$border",
|
|
143
|
+
children: [isSelected ? /* @__PURE__ */ jsx(Box, {
|
|
144
|
+
backgroundColor: "$primary",
|
|
145
|
+
paddingX: 1,
|
|
146
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
147
|
+
color: "$primary-fg",
|
|
148
|
+
bold: true,
|
|
149
|
+
wrap: "truncate",
|
|
150
|
+
children: card.title
|
|
151
|
+
})
|
|
152
|
+
}) : /* @__PURE__ */ jsx(Box, {
|
|
153
|
+
paddingX: 1,
|
|
154
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
155
|
+
wrap: "truncate",
|
|
156
|
+
children: card.title
|
|
157
|
+
})
|
|
158
|
+
}), /* @__PURE__ */ jsx(Box, {
|
|
159
|
+
gap: 1,
|
|
160
|
+
paddingX: 1,
|
|
161
|
+
children: card.tags.map((tag) => /* @__PURE__ */ jsx(Tag, { name: tag }, tag))
|
|
162
|
+
})]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
function ColumnComponent({ column, isSelected, selectedCardIndex }) {
|
|
166
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
167
|
+
flexDirection: "column",
|
|
168
|
+
flexGrow: 1,
|
|
169
|
+
flexBasis: 0,
|
|
170
|
+
borderStyle: "single",
|
|
171
|
+
borderColor: isSelected ? "$primary" : "$border",
|
|
172
|
+
children: [/* @__PURE__ */ jsxs(Box, {
|
|
173
|
+
backgroundColor: isSelected ? "$primary" : void 0,
|
|
174
|
+
paddingX: 1,
|
|
175
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
176
|
+
bold: true,
|
|
177
|
+
color: isSelected ? "$primary-fg" : "$text",
|
|
178
|
+
children: column.title
|
|
179
|
+
}), /* @__PURE__ */ jsxs(Text, {
|
|
180
|
+
color: isSelected ? "$primary-fg" : "$muted",
|
|
181
|
+
children: [
|
|
182
|
+
" (",
|
|
183
|
+
column.cards.length,
|
|
184
|
+
")"
|
|
185
|
+
]
|
|
186
|
+
})]
|
|
187
|
+
}), /* @__PURE__ */ jsxs(Box, {
|
|
188
|
+
flexDirection: "column",
|
|
189
|
+
paddingX: 1,
|
|
190
|
+
overflow: "scroll",
|
|
191
|
+
scrollTo: isSelected ? selectedCardIndex : void 0,
|
|
192
|
+
flexGrow: 1,
|
|
193
|
+
children: [column.cards.map((card, cardIndex) => /* @__PURE__ */ jsx(CardComponent, {
|
|
194
|
+
card,
|
|
195
|
+
isSelected: isSelected && cardIndex === selectedCardIndex
|
|
196
|
+
}, card.id)), column.cards.length === 0 && /* @__PURE__ */ jsx(Text, {
|
|
197
|
+
dim: true,
|
|
198
|
+
italic: true,
|
|
199
|
+
children: "No cards"
|
|
200
|
+
})]
|
|
201
|
+
})]
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
function KanbanBoard() {
|
|
205
|
+
const { exit } = useApp();
|
|
206
|
+
const [columns, setColumns] = useState(initialColumns);
|
|
207
|
+
const [selectedColumn, setSelectedColumn] = useState(0);
|
|
208
|
+
const [selectedCard, setSelectedCard] = useState(0);
|
|
209
|
+
const currentColumnCards = columns[selectedColumn]?.cards ?? [];
|
|
210
|
+
const boundedSelectedCard = Math.min(selectedCard, Math.max(0, currentColumnCards.length - 1));
|
|
211
|
+
useInput((input, key) => {
|
|
212
|
+
if (input === "q" || key.escape) exit();
|
|
213
|
+
if (key.leftArrow || input === "h") {
|
|
214
|
+
setSelectedColumn((prev) => Math.max(0, prev - 1));
|
|
215
|
+
setSelectedCard(0);
|
|
216
|
+
}
|
|
217
|
+
if (key.rightArrow || input === "l") {
|
|
218
|
+
setSelectedColumn((prev) => Math.min(columns.length - 1, prev + 1));
|
|
219
|
+
setSelectedCard(0);
|
|
220
|
+
}
|
|
221
|
+
if (key.upArrow || input === "k") setSelectedCard((prev) => Math.max(0, prev - 1));
|
|
222
|
+
if (key.downArrow || input === "j") setSelectedCard((prev) => Math.min(currentColumnCards.length - 1, prev + 1));
|
|
223
|
+
if (input === "<" || input === ",") moveCard(-1);
|
|
224
|
+
if (input === ">" || input === ".") moveCard(1);
|
|
225
|
+
});
|
|
226
|
+
function moveCard(direction) {
|
|
227
|
+
const targetColumnIndex = selectedColumn + direction;
|
|
228
|
+
if (targetColumnIndex < 0 || targetColumnIndex >= columns.length) return;
|
|
229
|
+
if (currentColumnCards.length === 0) return;
|
|
230
|
+
const cardToMove = currentColumnCards[boundedSelectedCard];
|
|
231
|
+
if (!cardToMove) return;
|
|
232
|
+
setColumns((prev) => {
|
|
233
|
+
const next = prev.map((col) => ({
|
|
234
|
+
...col,
|
|
235
|
+
cards: [...col.cards]
|
|
236
|
+
}));
|
|
237
|
+
next[selectedColumn].cards.splice(boundedSelectedCard, 1);
|
|
238
|
+
next[targetColumnIndex].cards.push(cardToMove);
|
|
239
|
+
return next;
|
|
240
|
+
});
|
|
241
|
+
setSelectedColumn(targetColumnIndex);
|
|
242
|
+
setSelectedCard(columns[targetColumnIndex].cards.length);
|
|
243
|
+
}
|
|
244
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
245
|
+
flexDirection: "column",
|
|
246
|
+
padding: 1,
|
|
247
|
+
height: "100%",
|
|
248
|
+
children: /* @__PURE__ */ jsx(Box, {
|
|
249
|
+
flexGrow: 1,
|
|
250
|
+
flexDirection: "row",
|
|
251
|
+
gap: 1,
|
|
252
|
+
overflow: "hidden",
|
|
253
|
+
children: columns.map((column, colIndex) => /* @__PURE__ */ jsx(ColumnComponent, {
|
|
254
|
+
column,
|
|
255
|
+
isSelected: colIndex === selectedColumn,
|
|
256
|
+
selectedCardIndex: colIndex === selectedColumn ? boundedSelectedCard : -1
|
|
257
|
+
}, column.id))
|
|
258
|
+
})
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
async function main() {
|
|
262
|
+
try {
|
|
263
|
+
var _usingCtx$1 = _usingCtx();
|
|
264
|
+
const term = _usingCtx$1.u(createTerm());
|
|
265
|
+
const { waitUntilExit } = await render(/* @__PURE__ */ jsx(ExampleBanner, {
|
|
266
|
+
meta,
|
|
267
|
+
controls: "h/l column j/k card </> move Esc/q quit",
|
|
268
|
+
children: /* @__PURE__ */ jsx(KanbanBoard, {})
|
|
269
|
+
}), term);
|
|
270
|
+
await waitUntilExit();
|
|
271
|
+
} catch (_) {
|
|
272
|
+
_usingCtx$1.e = _;
|
|
273
|
+
} finally {
|
|
274
|
+
_usingCtx$1.d();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (import.meta.main) await main();
|
|
278
|
+
//#endregion
|
|
279
|
+
export { KanbanBoard, main, meta };
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { t as _usingCtx } from "../usingCtx-CsEf0xO3.mjs";
|
|
2
|
+
import { t as ExampleBanner } from "../_banner-A70_y2Vi.mjs";
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { Box, H1, Kbd, Muted, Text, createTerm, render, useApp, useInput } from "silvery";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
//#region apps/layout-ref.tsx
|
|
7
|
+
/**
|
|
8
|
+
* Layout Ref Example
|
|
9
|
+
*
|
|
10
|
+
* Demonstrates imperative access to layout information:
|
|
11
|
+
* - forwardRef on Box and Text components
|
|
12
|
+
* - BoxHandle for accessing layout info imperatively
|
|
13
|
+
* - onLayout callback for responding to size changes
|
|
14
|
+
*/
|
|
15
|
+
const meta = {
|
|
16
|
+
name: "Layout Ref",
|
|
17
|
+
description: "useBoxRect + useScrollRect for imperative layout measurement",
|
|
18
|
+
features: [
|
|
19
|
+
"forwardRef",
|
|
20
|
+
"BoxHandle",
|
|
21
|
+
"onLayout",
|
|
22
|
+
"getBoxRect()"
|
|
23
|
+
]
|
|
24
|
+
};
|
|
25
|
+
function ResizablePane({ title, color, onLayoutChange }) {
|
|
26
|
+
return /* @__PURE__ */ jsx(Box, {
|
|
27
|
+
ref: useRef(null),
|
|
28
|
+
flexGrow: 1,
|
|
29
|
+
borderStyle: "round",
|
|
30
|
+
borderColor: color,
|
|
31
|
+
padding: 1,
|
|
32
|
+
onLayout: (layout) => onLayoutChange(layout),
|
|
33
|
+
children: /* @__PURE__ */ jsx(H1, {
|
|
34
|
+
color,
|
|
35
|
+
children: title
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function ImperativeAccessDemo() {
|
|
40
|
+
const boxRef = useRef(null);
|
|
41
|
+
const [info, setInfo] = useState("Click 'i' to inspect");
|
|
42
|
+
const inspect = () => {
|
|
43
|
+
if (!boxRef.current) {
|
|
44
|
+
setInfo("No ref attached");
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const content = boxRef.current.getBoxRect();
|
|
48
|
+
const screen = boxRef.current.getScrollRect();
|
|
49
|
+
const node = boxRef.current.getNode();
|
|
50
|
+
setInfo(`Content: ${content?.width}x${content?.height} at (${content?.x},${content?.y})\nScreen: ${screen?.width}x${screen?.height} at (${screen?.x},${screen?.y})\nNode: ${node ? "available" : "null"}`);
|
|
51
|
+
};
|
|
52
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
53
|
+
ref: boxRef,
|
|
54
|
+
flexDirection: "column",
|
|
55
|
+
borderStyle: "double",
|
|
56
|
+
borderColor: "$accent",
|
|
57
|
+
padding: 1,
|
|
58
|
+
children: [
|
|
59
|
+
/* @__PURE__ */ jsx(H1, {
|
|
60
|
+
color: "$accent",
|
|
61
|
+
children: "Imperative Access (BoxHandle)"
|
|
62
|
+
}),
|
|
63
|
+
/* @__PURE__ */ jsx(Muted, { children: "Press 'i' to inspect this box" }),
|
|
64
|
+
/* @__PURE__ */ jsx(Box, {
|
|
65
|
+
marginTop: 1,
|
|
66
|
+
children: /* @__PURE__ */ jsx(Text, { children: info })
|
|
67
|
+
}),
|
|
68
|
+
/* @__PURE__ */ jsx(InspectTrigger, { onInspect: inspect })
|
|
69
|
+
]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function InspectTrigger({ onInspect }) {
|
|
73
|
+
useInput((input) => {
|
|
74
|
+
if (input === "i") onInspect();
|
|
75
|
+
});
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
function LayoutRefApp() {
|
|
79
|
+
const { exit } = useApp();
|
|
80
|
+
const [layouts, setLayouts] = useState({});
|
|
81
|
+
useInput((input, key) => {
|
|
82
|
+
if (input === "q" || key.escape) exit();
|
|
83
|
+
});
|
|
84
|
+
const handleLayoutChange = (pane) => (info) => {
|
|
85
|
+
setLayouts((prev) => ({
|
|
86
|
+
...prev,
|
|
87
|
+
[pane]: info
|
|
88
|
+
}));
|
|
89
|
+
};
|
|
90
|
+
return /* @__PURE__ */ jsxs(Box, {
|
|
91
|
+
flexDirection: "column",
|
|
92
|
+
padding: 1,
|
|
93
|
+
children: [
|
|
94
|
+
/* @__PURE__ */ jsxs(Box, {
|
|
95
|
+
flexDirection: "row",
|
|
96
|
+
gap: 1,
|
|
97
|
+
height: 8,
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx(ResizablePane, {
|
|
100
|
+
title: "Pane A",
|
|
101
|
+
color: "$success",
|
|
102
|
+
onLayoutChange: handleLayoutChange("a")
|
|
103
|
+
}),
|
|
104
|
+
/* @__PURE__ */ jsx(ResizablePane, {
|
|
105
|
+
title: "Pane B",
|
|
106
|
+
color: "$info",
|
|
107
|
+
onLayoutChange: handleLayoutChange("b")
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ jsx(ResizablePane, {
|
|
110
|
+
title: "Pane C",
|
|
111
|
+
color: "$primary",
|
|
112
|
+
onLayoutChange: handleLayoutChange("c")
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
}),
|
|
116
|
+
/* @__PURE__ */ jsx(Box, {
|
|
117
|
+
marginTop: 1,
|
|
118
|
+
borderStyle: "single",
|
|
119
|
+
borderColor: "$border",
|
|
120
|
+
padding: 1,
|
|
121
|
+
children: /* @__PURE__ */ jsxs(Box, {
|
|
122
|
+
flexDirection: "column",
|
|
123
|
+
children: [
|
|
124
|
+
/* @__PURE__ */ jsx(Text, {
|
|
125
|
+
bold: true,
|
|
126
|
+
dim: true,
|
|
127
|
+
children: "onLayout Results:"
|
|
128
|
+
}),
|
|
129
|
+
Object.entries(layouts).map(([pane, info]) => /* @__PURE__ */ jsxs(Text, {
|
|
130
|
+
dim: true,
|
|
131
|
+
children: [
|
|
132
|
+
"Pane ",
|
|
133
|
+
pane.toUpperCase(),
|
|
134
|
+
": ",
|
|
135
|
+
info.width,
|
|
136
|
+
"x",
|
|
137
|
+
info.height,
|
|
138
|
+
" at (",
|
|
139
|
+
info.x,
|
|
140
|
+
",",
|
|
141
|
+
info.y,
|
|
142
|
+
")"
|
|
143
|
+
]
|
|
144
|
+
}, pane)),
|
|
145
|
+
Object.keys(layouts).length === 0 && /* @__PURE__ */ jsx(Text, {
|
|
146
|
+
dim: true,
|
|
147
|
+
italic: true,
|
|
148
|
+
children: "Waiting for layout..."
|
|
149
|
+
})
|
|
150
|
+
]
|
|
151
|
+
})
|
|
152
|
+
}),
|
|
153
|
+
/* @__PURE__ */ jsx(Box, {
|
|
154
|
+
flexGrow: 1,
|
|
155
|
+
marginTop: 1,
|
|
156
|
+
children: /* @__PURE__ */ jsx(ImperativeAccessDemo, {})
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsxs(Muted, { children: [
|
|
159
|
+
" ",
|
|
160
|
+
/* @__PURE__ */ jsx(Kbd, { children: "i" }),
|
|
161
|
+
" inspect ",
|
|
162
|
+
/* @__PURE__ */ jsx(Kbd, { children: "Esc/q" }),
|
|
163
|
+
" quit"
|
|
164
|
+
] })
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
async function main() {
|
|
169
|
+
try {
|
|
170
|
+
var _usingCtx$1 = _usingCtx();
|
|
171
|
+
const term = _usingCtx$1.u(createTerm());
|
|
172
|
+
const { waitUntilExit } = await render(/* @__PURE__ */ jsx(ExampleBanner, {
|
|
173
|
+
meta,
|
|
174
|
+
controls: "i inspect Esc/q quit",
|
|
175
|
+
children: /* @__PURE__ */ jsx(LayoutRefApp, {})
|
|
176
|
+
}), term);
|
|
177
|
+
await waitUntilExit();
|
|
178
|
+
} catch (_) {
|
|
179
|
+
_usingCtx$1.e = _;
|
|
180
|
+
} finally {
|
|
181
|
+
_usingCtx$1.d();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (import.meta.main) await main();
|
|
185
|
+
//#endregion
|
|
186
|
+
export { LayoutRefApp, main, meta };
|