@zaly/tui 0.0.4
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 +21 -0
- package/README.md +59 -0
- package/assets/schemas/theme.schema.json +899 -0
- package/assets/themes/LICENSE-tokyonight.txt +201 -0
- package/assets/themes/NOTICES.md +69 -0
- package/assets/themes/ayu-dark.json +119 -0
- package/assets/themes/catppuccin-frappe.json +124 -0
- package/assets/themes/catppuccin-latte.json +124 -0
- package/assets/themes/catppuccin-macchiato.json +124 -0
- package/assets/themes/catppuccin-mocha.json +124 -0
- package/assets/themes/dracula-soft.json +119 -0
- package/assets/themes/dracula.json +119 -0
- package/assets/themes/everforest-dark.json +118 -0
- package/assets/themes/everforest-light.json +118 -0
- package/assets/themes/github-dark.json +123 -0
- package/assets/themes/github-light.json +123 -0
- package/assets/themes/gruvbox-dark-medium.json +112 -0
- package/assets/themes/kanagawa-dragon.json +115 -0
- package/assets/themes/kanagawa-wave.json +115 -0
- package/assets/themes/material-theme-palenight.json +114 -0
- package/assets/themes/min-dark.json +55 -0
- package/assets/themes/min-light.json +59 -0
- package/assets/themes/monokai.json +116 -0
- package/assets/themes/night-owl.json +116 -0
- package/assets/themes/nord.json +101 -0
- package/assets/themes/one-dark-pro.json +110 -0
- package/assets/themes/one-light.json +108 -0
- package/assets/themes/poimandres.json +123 -0
- package/assets/themes/rose-pine.json +98 -0
- package/assets/themes/solarized-dark.json +116 -0
- package/assets/themes/solarized-light.json +116 -0
- package/assets/themes/synthwave-84.json +100 -0
- package/assets/themes/tokyonight-day.json +157 -0
- package/assets/themes/tokyonight-moon.json +157 -0
- package/assets/themes/tokyonight-night.json +157 -0
- package/assets/themes/tokyonight-storm.json +157 -0
- package/assets/themes/vesper.json +103 -0
- package/assets/themes/vitesse-dark.json +126 -0
- package/assets/themes/vitesse-light.json +126 -0
- package/dist/ansi-Clq0ozyA.mjs +206 -0
- package/dist/ansi-Clq0ozyA.mjs.map +1 -0
- package/dist/ansi.d.mts +48 -0
- package/dist/ansi.d.mts.map +1 -0
- package/dist/ansi.mjs +2 -0
- package/dist/autocomplete-Dfw-yQDa.d.mts +100 -0
- package/dist/autocomplete-Dfw-yQDa.d.mts.map +1 -0
- package/dist/box-DyaByEiG.mjs +386 -0
- package/dist/box-DyaByEiG.mjs.map +1 -0
- package/dist/builder-D49ECBEf.mjs +385 -0
- package/dist/builder-D49ECBEf.mjs.map +1 -0
- package/dist/callbacks-CNjGNxVw.mjs +279 -0
- package/dist/callbacks-CNjGNxVw.mjs.map +1 -0
- package/dist/client-D6C_uczF.mjs +142 -0
- package/dist/client-D6C_uczF.mjs.map +1 -0
- package/dist/clipboard.d.mts +104 -0
- package/dist/clipboard.d.mts.map +1 -0
- package/dist/clipboard.mjs +404 -0
- package/dist/clipboard.mjs.map +1 -0
- package/dist/flex-Bguo-fUe.mjs +202 -0
- package/dist/flex-Bguo-fUe.mjs.map +1 -0
- package/dist/image-Cm5T-uw-.mjs +108 -0
- package/dist/image-Cm5T-uw-.mjs.map +1 -0
- package/dist/image.d.mts +123 -0
- package/dist/image.d.mts.map +1 -0
- package/dist/image.mjs +2 -0
- package/dist/index.d.mts +64 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +222 -0
- package/dist/index.mjs.map +1 -0
- package/dist/input-B5Vy-iaa.d.mts +141 -0
- package/dist/input-B5Vy-iaa.d.mts.map +1 -0
- package/dist/inspect-D1d9t-ni.mjs +101 -0
- package/dist/inspect-D1d9t-ni.mjs.map +1 -0
- package/dist/inspect-D6FW_QUo.d.mts +67 -0
- package/dist/inspect-D6FW_QUo.d.mts.map +1 -0
- package/dist/kitty-JbCJC0iQ.mjs +673 -0
- package/dist/kitty-JbCJC0iQ.mjs.map +1 -0
- package/dist/markdown.d.mts +24 -0
- package/dist/markdown.d.mts.map +1 -0
- package/dist/markdown.mjs +2 -0
- package/dist/md.bun.d.mts +14 -0
- package/dist/md.bun.d.mts.map +1 -0
- package/dist/md.bun.mjs +28 -0
- package/dist/md.bun.mjs.map +1 -0
- package/dist/md.node.d.mts +14 -0
- package/dist/md.node.d.mts.map +1 -0
- package/dist/md.node.mjs +126 -0
- package/dist/md.node.mjs.map +1 -0
- package/dist/node-BZ7f6HzU.mjs +316 -0
- package/dist/node-BZ7f6HzU.mjs.map +1 -0
- package/dist/picker-D8OLb6kZ.d.mts +36 -0
- package/dist/picker-D8OLb6kZ.d.mts.map +1 -0
- package/dist/picker-ndVVt6qF.mjs +621 -0
- package/dist/picker-ndVVt6qF.mjs.map +1 -0
- package/dist/queries-DH3bj74K.d.mts +1963 -0
- package/dist/queries-DH3bj74K.d.mts.map +1 -0
- package/dist/reactive-f7NpAi69.mjs +623 -0
- package/dist/reactive-f7NpAi69.mjs.map +1 -0
- package/dist/registry-U654j61Y.mjs +356 -0
- package/dist/registry-U654j61Y.mjs.map +1 -0
- package/dist/render-DxVLqqB9.mjs +74 -0
- package/dist/render-DxVLqqB9.mjs.map +1 -0
- package/dist/renderer-CdLCkJB-.mjs +42 -0
- package/dist/renderer-CdLCkJB-.mjs.map +1 -0
- package/dist/renderer-CxL4xbkl.mjs +2644 -0
- package/dist/renderer-CxL4xbkl.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/search-FvGnswRl.d.mts +49 -0
- package/dist/search-FvGnswRl.d.mts.map +1 -0
- package/dist/select-CbmAZdpt.d.mts +116 -0
- package/dist/select-CbmAZdpt.d.mts.map +1 -0
- package/dist/services/logger.d.mts +2 -0
- package/dist/services/logger.mjs +71 -0
- package/dist/services/logger.mjs.map +1 -0
- package/dist/services/notifier.d.mts +17 -0
- package/dist/services/notifier.d.mts.map +1 -0
- package/dist/services/notifier.mjs +71 -0
- package/dist/services/notifier.mjs.map +1 -0
- package/dist/services/picker.d.mts +36 -0
- package/dist/services/picker.d.mts.map +1 -0
- package/dist/services/picker.mjs +137 -0
- package/dist/services/picker.mjs.map +1 -0
- package/dist/services/prompt.d.mts +30 -0
- package/dist/services/prompt.d.mts.map +1 -0
- package/dist/services/prompt.mjs +83 -0
- package/dist/services/prompt.mjs.map +1 -0
- package/dist/shiki-BrjVUkeh.mjs +423 -0
- package/dist/shiki-BrjVUkeh.mjs.map +1 -0
- package/dist/size-D8JogYLy.mjs +34 -0
- package/dist/size-D8JogYLy.mjs.map +1 -0
- package/dist/style.d.mts +10 -0
- package/dist/style.d.mts.map +1 -0
- package/dist/style.mjs +4 -0
- package/dist/text.d.mts +33 -0
- package/dist/text.d.mts.map +1 -0
- package/dist/text.mjs +111 -0
- package/dist/text.mjs.map +1 -0
- package/dist/theme.config-CU3B50HN.mjs +832 -0
- package/dist/theme.config-CU3B50HN.mjs.map +1 -0
- package/dist/themes.d.mts +113 -0
- package/dist/themes.d.mts.map +1 -0
- package/dist/themes.mjs +2 -0
- package/dist/tree-C28QOVIK.d.mts +23 -0
- package/dist/tree-C28QOVIK.d.mts.map +1 -0
- package/dist/types-B9Eh7k2v.d.mts +212 -0
- package/dist/types-B9Eh7k2v.d.mts.map +1 -0
- package/dist/types-D3jk1rtk.d.mts +140 -0
- package/dist/types-D3jk1rtk.d.mts.map +1 -0
- package/dist/utils-3M4D_AXZ.mjs +40 -0
- package/dist/utils-3M4D_AXZ.mjs.map +1 -0
- package/dist/widgets/autocomplete.d.mts +2 -0
- package/dist/widgets/autocomplete.mjs +165 -0
- package/dist/widgets/autocomplete.mjs.map +1 -0
- package/dist/widgets/box.d.mts +2 -0
- package/dist/widgets/box.mjs +2 -0
- package/dist/widgets/code.d.mts +48 -0
- package/dist/widgets/code.d.mts.map +1 -0
- package/dist/widgets/code.mjs +59 -0
- package/dist/widgets/code.mjs.map +1 -0
- package/dist/widgets/completions/actions.d.mts +41 -0
- package/dist/widgets/completions/actions.d.mts.map +1 -0
- package/dist/widgets/completions/actions.mjs +48 -0
- package/dist/widgets/completions/actions.mjs.map +1 -0
- package/dist/widgets/completions/files.d.mts +29 -0
- package/dist/widgets/completions/files.d.mts.map +1 -0
- package/dist/widgets/completions/files.mjs +42 -0
- package/dist/widgets/completions/files.mjs.map +1 -0
- package/dist/widgets/completions/github.d.mts +64 -0
- package/dist/widgets/completions/github.d.mts.map +1 -0
- package/dist/widgets/completions/github.mjs +137 -0
- package/dist/widgets/completions/github.mjs.map +1 -0
- package/dist/widgets/completions/index.d.mts +4 -0
- package/dist/widgets/completions/index.mjs +4 -0
- package/dist/widgets/diff.d.mts +57 -0
- package/dist/widgets/diff.d.mts.map +1 -0
- package/dist/widgets/diff.mjs +199 -0
- package/dist/widgets/diff.mjs.map +1 -0
- package/dist/widgets/divider.d.mts +11 -0
- package/dist/widgets/divider.d.mts.map +1 -0
- package/dist/widgets/divider.mjs +9 -0
- package/dist/widgets/divider.mjs.map +1 -0
- package/dist/widgets/image.d.mts +37 -0
- package/dist/widgets/image.d.mts.map +1 -0
- package/dist/widgets/image.mjs +77 -0
- package/dist/widgets/image.mjs.map +1 -0
- package/dist/widgets/input.d.mts +2 -0
- package/dist/widgets/input.mjs +497 -0
- package/dist/widgets/input.mjs.map +1 -0
- package/dist/widgets/log.d.mts +2 -0
- package/dist/widgets/log.mjs +130 -0
- package/dist/widgets/log.mjs.map +1 -0
- package/dist/widgets/markdown.d.mts +45 -0
- package/dist/widgets/markdown.d.mts.map +1 -0
- package/dist/widgets/markdown.mjs +124 -0
- package/dist/widgets/markdown.mjs.map +1 -0
- package/dist/widgets/overlay.d.mts +2 -0
- package/dist/widgets/overlay.mjs +18 -0
- package/dist/widgets/overlay.mjs.map +1 -0
- package/dist/widgets/picker.d.mts +2 -0
- package/dist/widgets/picker.mjs +2 -0
- package/dist/widgets/progress.d.mts +48 -0
- package/dist/widgets/progress.d.mts.map +1 -0
- package/dist/widgets/progress.mjs +48 -0
- package/dist/widgets/progress.mjs.map +1 -0
- package/dist/widgets/select.d.mts +2 -0
- package/dist/widgets/select.mjs +195 -0
- package/dist/widgets/select.mjs.map +1 -0
- package/dist/widgets/show.d.mts +55 -0
- package/dist/widgets/show.d.mts.map +1 -0
- package/dist/widgets/show.mjs +85 -0
- package/dist/widgets/show.mjs.map +1 -0
- package/dist/widgets/spinner.d.mts +65 -0
- package/dist/widgets/spinner.d.mts.map +1 -0
- package/dist/widgets/spinner.mjs +147 -0
- package/dist/widgets/spinner.mjs.map +1 -0
- package/dist/widgets/text.d.mts +2 -0
- package/dist/widgets/text.mjs +32 -0
- package/dist/widgets/text.mjs.map +1 -0
- package/dist/widgets/tree.d.mts +2 -0
- package/dist/widgets/tree.mjs +73 -0
- package/dist/widgets/tree.mjs.map +1 -0
- package/dist/widgets/widget.d.mts +49 -0
- package/dist/widgets/widget.d.mts.map +1 -0
- package/dist/widgets/widget.mjs +40 -0
- package/dist/widgets/widget.mjs.map +1 -0
- package/dist/worker-DjHuQSbY.mjs +27 -0
- package/dist/worker-DjHuQSbY.mjs.map +1 -0
- package/package.json +117 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { S as unwrap, h as memo } from "../reactive-f7NpAi69.mjs";
|
|
2
|
+
import { widget } from "./widget.mjs";
|
|
3
|
+
import { select } from "./select.mjs";
|
|
4
|
+
import { stringWidth } from "@zaly/shared/ansi";
|
|
5
|
+
//#region src/widgets/tree.ts
|
|
6
|
+
const icons = {
|
|
7
|
+
last: "╰─",
|
|
8
|
+
middle: "├─",
|
|
9
|
+
vertical: "│ "
|
|
10
|
+
};
|
|
11
|
+
var Tree = class {
|
|
12
|
+
root;
|
|
13
|
+
nodes = /* @__PURE__ */ new Map();
|
|
14
|
+
items = [];
|
|
15
|
+
constructor(root) {
|
|
16
|
+
this.root = root;
|
|
17
|
+
this.#build(root, void 0, true);
|
|
18
|
+
}
|
|
19
|
+
#build(item, parent, last) {
|
|
20
|
+
this.nodes.set(item, {
|
|
21
|
+
last,
|
|
22
|
+
parent
|
|
23
|
+
});
|
|
24
|
+
this.items.push(item);
|
|
25
|
+
const children = item.children ?? [];
|
|
26
|
+
for (let c = 0; c < children.length; c++) {
|
|
27
|
+
const child = children[c];
|
|
28
|
+
this.#build(child, item, c === children.length - 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
node(item) {
|
|
32
|
+
return this.nodes.get(item);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const tree = widget((props) => {
|
|
36
|
+
const builder = memo(() => new Tree(unwrap(props.tree)));
|
|
37
|
+
const items = memo(() => props.root === true ? builder().items : builder().items.slice(1));
|
|
38
|
+
const activeFn = typeof props.active === "function" ? props.active : (i) => i === props.active;
|
|
39
|
+
const active = props.active ? items().findIndex((i) => activeFn(i)) : -1;
|
|
40
|
+
const ret = select({
|
|
41
|
+
...props,
|
|
42
|
+
active: active === -1 ? 0 : active,
|
|
43
|
+
items
|
|
44
|
+
});
|
|
45
|
+
ret.extendRenderer((prev) => (item, ctx) => {
|
|
46
|
+
const t = builder();
|
|
47
|
+
const path = [];
|
|
48
|
+
const s = ctx.style;
|
|
49
|
+
const itemNode = t.node(item);
|
|
50
|
+
let n = t.node(item);
|
|
51
|
+
while (n?.parent) {
|
|
52
|
+
if (props.root !== true && n.parent === props.tree) break;
|
|
53
|
+
let icon = "";
|
|
54
|
+
if (n !== itemNode) icon = n.last ? " " : icons.vertical;
|
|
55
|
+
else icon = n.last ? icons.last : icons.middle;
|
|
56
|
+
path.unshift(icon);
|
|
57
|
+
n = t.node(n.parent);
|
|
58
|
+
}
|
|
59
|
+
const prefix = path.join("");
|
|
60
|
+
const prefixWidth = stringWidth(prefix);
|
|
61
|
+
const text = prev(item, {
|
|
62
|
+
...ctx,
|
|
63
|
+
prefixWidth,
|
|
64
|
+
width: ctx.width - prefixWidth
|
|
65
|
+
}).replace(/\s/g, " ");
|
|
66
|
+
return `${s.gutter(prefix)}${text}`;
|
|
67
|
+
});
|
|
68
|
+
return Object.assign(ret, { items });
|
|
69
|
+
});
|
|
70
|
+
//#endregion
|
|
71
|
+
export { tree };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=tree.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tree.mjs","names":["#build"],"sources":["../../src/widgets/tree.ts"],"sourcesContent":["import type { Reactive } from \"../core/reactive.ts\"\nimport type { Option, Select, SelectState } from \"./select.ts\"\n\nimport { stringWidth } from \"@zaly/shared/ansi\"\nimport { memo, unwrap } from \"../core/reactive.ts\"\nimport { select } from \"./select.ts\"\nimport { widget } from \"./widget.ts\"\n\nexport type TreeItem<T extends Option = Option> = T & {\n children?: TreeItem<T>[]\n icon?: string\n}\n\nexport type TreeProps<T extends TreeItem = TreeItem> = Omit<SelectState<T>, \"items\" | \"active\"> & {\n tree: Reactive<T>\n /** If true, the root node will be rendered and selectable. Defaults to false. */\n root?: boolean\n active?: T | ((item: T) => boolean)\n}\n\nconst icons = {\n // last: \"└─\",\n last: \"╰─\",\n middle: \"├─\",\n vertical: \"│ \",\n}\n\nexport type TreeNode<T extends TreeItem> = {\n last?: boolean\n parent?: T\n}\n\nclass Tree<T extends TreeItem> {\n nodes = new Map<T, TreeNode<T>>()\n items: T[] = []\n\n constructor(public root: T) {\n this.#build(root, undefined, true)\n }\n\n #build(item: T, parent?: T, last?: boolean) {\n this.nodes.set(item, { last, parent })\n this.items.push(item)\n const children = item.children ?? []\n for (let c = 0; c < children.length; c++) {\n const child = children[c] as T\n this.#build(child, item, c === children.length - 1)\n }\n }\n\n node(item: T) {\n return this.nodes.get(item)\n }\n}\n\nexport const tree = widget(\n <T extends TreeItem>(props: TreeProps<T>): Select<T> & { items: Reactive<T[]> } => {\n const builder = memo(() => new Tree(unwrap(props.tree)))\n const items = memo(() => (props.root === true ? builder().items : builder().items.slice(1)))\n\n const activeFn =\n typeof props.active === \"function\" ? props.active : (i: T) => i === props.active\n const active = props.active ? items().findIndex((i) => activeFn(i)) : -1\n\n const ret = select({ ...props, active: active === -1 ? 0 : active, items })\n\n ret.extendRenderer((prev) => (item, ctx) => {\n const t = builder()\n const path: string[] = []\n const s = ctx.style\n const itemNode = t.node(item)\n let n = t.node(item)\n while (n?.parent) {\n if (props.root !== true && n.parent === props.tree) break\n let icon = \"\"\n if (n !== itemNode) icon = n.last ? \" \" : icons.vertical\n else icon = n.last ? icons.last : icons.middle\n path.unshift(icon)\n n = t.node(n.parent)\n }\n const prefix = path.join(\"\")\n const prefixWidth = stringWidth(prefix)\n const text = prev(item, { ...ctx, prefixWidth, width: ctx.width - prefixWidth }).replace(\n /\\s/g,\n \" \"\n )\n return `${s.gutter(prefix)}${text}`\n })\n\n return Object.assign(ret, { items })\n }\n)\n"],"mappings":";;;;;AAoBA,MAAM,QAAQ;CAEZ,MAAM;CACN,QAAQ;CACR,UAAU;AACZ;AAOA,IAAM,OAAN,MAA+B;CAIV;CAHnB,wBAAQ,IAAI,IAAoB;CAChC,QAAa,CAAC;CAEd,YAAY,MAAgB;EAAT,KAAA,OAAA;EACjB,KAAKA,OAAO,MAAM,KAAA,GAAW,IAAI;CACnC;CAEA,OAAO,MAAS,QAAY,MAAgB;EAC1C,KAAK,MAAM,IAAI,MAAM;GAAE;GAAM;EAAO,CAAC;EACrC,KAAK,MAAM,KAAK,IAAI;EACpB,MAAM,WAAW,KAAK,YAAY,CAAC;EACnC,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK;GACxC,MAAM,QAAQ,SAAS;GACvB,KAAKA,OAAO,OAAO,MAAM,MAAM,SAAS,SAAS,CAAC;EACpD;CACF;CAEA,KAAK,MAAS;EACZ,OAAO,KAAK,MAAM,IAAI,IAAI;CAC5B;AACF;AAEA,MAAa,OAAO,QACG,UAA8D;CACjF,MAAM,UAAU,WAAW,IAAI,KAAK,OAAO,MAAM,IAAI,CAAC,CAAC;CACvD,MAAM,QAAQ,WAAY,MAAM,SAAS,OAAO,QAAQ,CAAC,CAAC,QAAQ,QAAQ,CAAC,CAAC,MAAM,MAAM,CAAC,CAAE;CAE3F,MAAM,WACJ,OAAO,MAAM,WAAW,aAAa,MAAM,UAAU,MAAS,MAAM,MAAM;CAC5E,MAAM,SAAS,MAAM,SAAS,MAAM,CAAC,CAAC,WAAW,MAAM,SAAS,CAAC,CAAC,IAAI;CAEtE,MAAM,MAAM,OAAO;EAAE,GAAG;EAAO,QAAQ,WAAW,KAAK,IAAI;EAAQ;CAAM,CAAC;CAE1E,IAAI,gBAAgB,UAAU,MAAM,QAAQ;EAC1C,MAAM,IAAI,QAAQ;EAClB,MAAM,OAAiB,CAAC;EACxB,MAAM,IAAI,IAAI;EACd,MAAM,WAAW,EAAE,KAAK,IAAI;EAC5B,IAAI,IAAI,EAAE,KAAK,IAAI;EACnB,OAAO,GAAG,QAAQ;GAChB,IAAI,MAAM,SAAS,QAAQ,EAAE,WAAW,MAAM,MAAM;GACpD,IAAI,OAAO;GACX,IAAI,MAAM,UAAU,OAAO,EAAE,OAAO,OAAO,MAAM;QAC5C,OAAO,EAAE,OAAO,MAAM,OAAO,MAAM;GACxC,KAAK,QAAQ,IAAI;GACjB,IAAI,EAAE,KAAK,EAAE,MAAM;EACrB;EACA,MAAM,SAAS,KAAK,KAAK,EAAE;EAC3B,MAAM,cAAc,YAAY,MAAM;EACtC,MAAM,OAAO,KAAK,MAAM;GAAE,GAAG;GAAK;GAAa,OAAO,IAAI,QAAQ;EAAY,CAAC,CAAC,CAAC,QAC/E,OACA,GACF;EACA,OAAO,GAAG,EAAE,OAAO,MAAM,IAAI;CAC/B,CAAC;CAED,OAAO,OAAO,OAAO,KAAK,EAAE,MAAM,CAAC;AACrC,CACF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { p as Node } from "../queries-DH3bj74K.mjs";
|
|
2
|
+
//#region src/widgets/widget.d.ts
|
|
3
|
+
type Props = Record<string, unknown>;
|
|
4
|
+
/**
|
|
5
|
+
* A widget factory: takes some args, returns a `Node`.
|
|
6
|
+
*
|
|
7
|
+
* The default `A = never[]` makes the *bare* `Widget` the universal
|
|
8
|
+
* "any widget" type — the `(...args: never[]) => Node` idiom. Every
|
|
9
|
+
* concrete factory (zero-arg, `state + ...children`, single-props) is
|
|
10
|
+
* assignable to it, so it works both as the `widget()` constraint and
|
|
11
|
+
* as a stored value type (`details?: Widget`, invoked zero-arg). Supply
|
|
12
|
+
* `A` explicitly for a precise signature: `Widget<[State<LogState>]>`.
|
|
13
|
+
*/
|
|
14
|
+
type Widget<A extends unknown[] = never[], N extends Node = Node> = (...args: A) => N;
|
|
15
|
+
/**
|
|
16
|
+
* Type helper for declaring widgets — runtime identity, just `return fn`.
|
|
17
|
+
*
|
|
18
|
+
* Three things it earns:
|
|
19
|
+
* 1. Inference at the declaration site: TS infers `S` from the function
|
|
20
|
+
* parameter and enforces it on every call site.
|
|
21
|
+
* 2. A consistent grep target: every component reads as
|
|
22
|
+
* `export const foo = widget((props) => …)`.
|
|
23
|
+
* 3. A future seam for instrumentation, lifecycle wrappers, devtools.
|
|
24
|
+
*
|
|
25
|
+
* The factory body runs **once** at construction. Reactive content lives
|
|
26
|
+
* in leaf thunks (`text(({ style }) => …)`), not by re-running the body
|
|
27
|
+
* — this is the Solid model, not React's. `ctx` is therefore unavailable
|
|
28
|
+
* inside the factory; reach for it inside leaf thunks where it belongs.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const status = widget((props: { level: "ok" | "warn"; msg: string }) =>
|
|
32
|
+
* text(({ style }) => `${style.bold[props.level]("●")} ${style.dim(props.msg)}`),
|
|
33
|
+
* )
|
|
34
|
+
*
|
|
35
|
+
* status({ level: "ok", msg: "all systems nominal" })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
/**
|
|
39
|
+
* Call-site args derived from `S`:
|
|
40
|
+
* - If `S` declares `children`, `children` is injected from rest args;
|
|
41
|
+
* state at the call site has `children` omitted, then `...children`.
|
|
42
|
+
* - Otherwise, no rest is allowed.
|
|
43
|
+
* - Either way, the state arg is optional when every field of the
|
|
44
|
+
* resolved state is optional (so bare `widget()` works).
|
|
45
|
+
*/
|
|
46
|
+
declare function widget<T extends Widget>(fn: T): T;
|
|
47
|
+
//#endregion
|
|
48
|
+
export { Props, Widget, widget };
|
|
49
|
+
//# sourceMappingURL=widget.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.d.mts","names":[],"sources":["../../src/widgets/widget.ts"],"mappings":";;KAIY,QAAQ;;;;;;;;;;;KAYR,OAAO,+BAA+B,UAAU,OAAO,YAAY,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAkC3E,OAAO,UAAU,QAAQ,IAAI,IAAI"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { o as createNode } from "../reactive-f7NpAi69.mjs";
|
|
2
|
+
//#region src/widgets/widget.ts
|
|
3
|
+
/**
|
|
4
|
+
* Type helper for declaring widgets — runtime identity, just `return fn`.
|
|
5
|
+
*
|
|
6
|
+
* Three things it earns:
|
|
7
|
+
* 1. Inference at the declaration site: TS infers `S` from the function
|
|
8
|
+
* parameter and enforces it on every call site.
|
|
9
|
+
* 2. A consistent grep target: every component reads as
|
|
10
|
+
* `export const foo = widget((props) => …)`.
|
|
11
|
+
* 3. A future seam for instrumentation, lifecycle wrappers, devtools.
|
|
12
|
+
*
|
|
13
|
+
* The factory body runs **once** at construction. Reactive content lives
|
|
14
|
+
* in leaf thunks (`text(({ style }) => …)`), not by re-running the body
|
|
15
|
+
* — this is the Solid model, not React's. `ctx` is therefore unavailable
|
|
16
|
+
* inside the factory; reach for it inside leaf thunks where it belongs.
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* const status = widget((props: { level: "ok" | "warn"; msg: string }) =>
|
|
20
|
+
* text(({ style }) => `${style.bold[props.level]("●")} ${style.dim(props.msg)}`),
|
|
21
|
+
* )
|
|
22
|
+
*
|
|
23
|
+
* status({ level: "ok", msg: "all systems nominal" })
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
/**
|
|
27
|
+
* Call-site args derived from `S`:
|
|
28
|
+
* - If `S` declares `children`, `children` is injected from rest args;
|
|
29
|
+
* state at the call site has `children` omitted, then `...children`.
|
|
30
|
+
* - Otherwise, no rest is allowed.
|
|
31
|
+
* - Either way, the state arg is optional when every field of the
|
|
32
|
+
* resolved state is optional (so bare `widget()` works).
|
|
33
|
+
*/
|
|
34
|
+
function widget(fn) {
|
|
35
|
+
return ((...args) => createNode(() => fn(...args)));
|
|
36
|
+
}
|
|
37
|
+
//#endregion
|
|
38
|
+
export { widget };
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=widget.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget.mjs","names":[],"sources":["../../src/widgets/widget.ts"],"sourcesContent":["import type { Node } from \"../core/node.ts\"\n\nimport { createNode } from \"../core/reactive.ts\"\n\nexport type Props = Record<string, unknown>\n\n/**\n * A widget factory: takes some args, returns a `Node`.\n *\n * The default `A = never[]` makes the *bare* `Widget` the universal\n * \"any widget\" type — the `(...args: never[]) => Node` idiom. Every\n * concrete factory (zero-arg, `state + ...children`, single-props) is\n * assignable to it, so it works both as the `widget()` constraint and\n * as a stored value type (`details?: Widget`, invoked zero-arg). Supply\n * `A` explicitly for a precise signature: `Widget<[State<LogState>]>`.\n */\nexport type Widget<A extends unknown[] = never[], N extends Node = Node> = (...args: A) => N\n\n/**\n * Type helper for declaring widgets — runtime identity, just `return fn`.\n *\n * Three things it earns:\n * 1. Inference at the declaration site: TS infers `S` from the function\n * parameter and enforces it on every call site.\n * 2. A consistent grep target: every component reads as\n * `export const foo = widget((props) => …)`.\n * 3. A future seam for instrumentation, lifecycle wrappers, devtools.\n *\n * The factory body runs **once** at construction. Reactive content lives\n * in leaf thunks (`text(({ style }) => …)`), not by re-running the body\n * — this is the Solid model, not React's. `ctx` is therefore unavailable\n * inside the factory; reach for it inside leaf thunks where it belongs.\n *\n * ```ts\n * const status = widget((props: { level: \"ok\" | \"warn\"; msg: string }) =>\n * text(({ style }) => `${style.bold[props.level](\"●\")} ${style.dim(props.msg)}`),\n * )\n *\n * status({ level: \"ok\", msg: \"all systems nominal\" })\n * ```\n */\n/**\n * Call-site args derived from `S`:\n * - If `S` declares `children`, `children` is injected from rest args;\n * state at the call site has `children` omitted, then `...children`.\n * - Otherwise, no rest is allowed.\n * - Either way, the state arg is optional when every field of the\n * resolved state is optional (so bare `widget()` works).\n */\n\nexport function widget<T extends Widget>(fn: T): T {\n return ((...args: Parameters<T>) => createNode(() => fn(...args))) as T\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,SAAgB,OAAyB,IAAU;CACjD,SAAS,GAAG,SAAwB,iBAAiB,GAAG,GAAG,IAAI,CAAC;AAClE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//#region src/shiki/worker.ts
|
|
2
|
+
async function createWorker(scriptURL) {
|
|
3
|
+
if (typeof globalThis.Worker === "function") {
|
|
4
|
+
const w = new Worker(scriptURL, { type: "module" });
|
|
5
|
+
w.unref?.();
|
|
6
|
+
return {
|
|
7
|
+
on: (event, handler) => {
|
|
8
|
+
if (event === "error") w.addEventListener(event, (e) => void handler(e.error ?? new Error(e.message)));
|
|
9
|
+
else w.addEventListener(event, (e) => void handler(e.data));
|
|
10
|
+
},
|
|
11
|
+
postMessage: (message) => w.postMessage(message),
|
|
12
|
+
terminate: () => w.terminate()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
const { Worker: NodeWorker } = await import("node:worker_threads");
|
|
16
|
+
const worker = new NodeWorker(scriptURL);
|
|
17
|
+
worker.unref();
|
|
18
|
+
return {
|
|
19
|
+
on: (event, handler) => worker.on(event, (e) => void handler(e)),
|
|
20
|
+
postMessage: (message) => worker.postMessage(message),
|
|
21
|
+
terminate: () => void worker.terminate()
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createWorker };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=worker-DjHuQSbY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker-DjHuQSbY.mjs","names":[],"sources":["../src/shiki/worker.ts"],"sourcesContent":["// oxlint-disable typescript/method-signature-style unicorn/require-post-message-target-origin\nimport type { MaybePromise } from \"@zaly/shared\"\n\nexport const workerHost = {\n onMessage: (handler: (message: any) => MaybePromise): void => {\n if (typeof globalThis.addEventListener === \"function\") {\n globalThis.addEventListener(\"message\", (event: MessageEvent) => void handler(event.data))\n return\n }\n void import(\"node:worker_threads\").then(({ parentPort }) => {\n parentPort?.on(\"message\", (message) => void handler(message))\n })\n },\n\n postMessage: (message: unknown): void => {\n if (typeof globalThis.postMessage === \"function\") {\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n globalThis.postMessage(message)\n return\n }\n void import(\"node:worker_threads\").then(({ parentPort }) => {\n // oxlint-disable-next-line unicorn/require-post-message-target-origin\n parentPort?.postMessage(message)\n })\n },\n}\n\nexport type WorkerInstance<In = unknown, Out = unknown> = {\n on(event: \"message\", handler: (message: Out) => MaybePromise): void\n on(event: \"error\", handler: (error: Error) => MaybePromise): void\n postMessage(message: In): void\n terminate(): void\n}\n\nexport async function createWorker<In = unknown, Out = unknown>(\n scriptURL: string | URL\n): Promise<WorkerInstance<In, Out>> {\n if (typeof globalThis.Worker === \"function\") {\n const w = new Worker(scriptURL, { type: \"module\" })\n // oxlint-disable-next-line typescript/no-unnecessary-condition\n w.unref?.()\n return {\n on: (event, handler) => {\n if (event === \"error\")\n w.addEventListener(event, (e) => void handler(e.error ?? new Error(e.message)))\n else w.addEventListener(event, (e) => void handler(e.data))\n },\n postMessage: (message) => w.postMessage(message),\n terminate: () => w.terminate(),\n }\n }\n const { Worker: NodeWorker } = await import(\"node:worker_threads\")\n const worker = new NodeWorker(scriptURL)\n worker.unref()\n return {\n on: (event, handler) => worker.on(event, (e) => void handler(e)),\n postMessage: (message) => worker.postMessage(message),\n terminate: () => void worker.terminate(),\n }\n}\n"],"mappings":";AAkCA,eAAsB,aACpB,WACkC;CAClC,IAAI,OAAO,WAAW,WAAW,YAAY;EAC3C,MAAM,IAAI,IAAI,OAAO,WAAW,EAAE,MAAM,SAAS,CAAC;EAElD,EAAE,QAAQ;EACV,OAAO;GACL,KAAK,OAAO,YAAY;IACtB,IAAI,UAAU,SACZ,EAAE,iBAAiB,QAAQ,MAAM,KAAK,QAAQ,EAAE,SAAS,IAAI,MAAM,EAAE,OAAO,CAAC,CAAC;SAC3E,EAAE,iBAAiB,QAAQ,MAAM,KAAK,QAAQ,EAAE,IAAI,CAAC;GAC5D;GACA,cAAc,YAAY,EAAE,YAAY,OAAO;GAC/C,iBAAiB,EAAE,UAAU;EAC/B;CACF;CACA,MAAM,EAAE,QAAQ,eAAe,MAAM,OAAO;CAC5C,MAAM,SAAS,IAAI,WAAW,SAAS;CACvC,OAAO,MAAM;CACb,OAAO;EACL,KAAK,OAAO,YAAY,OAAO,GAAG,QAAQ,MAAM,KAAK,QAAQ,CAAC,CAAC;EAC/D,cAAc,YAAY,OAAO,YAAY,OAAO;EACpD,iBAAiB,KAAK,OAAO,UAAU;CACzC;AACF"}
|
package/package.json
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@zaly/tui",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Terminal UI framework used by zaly.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"ansi",
|
|
7
|
+
"cli",
|
|
8
|
+
"terminal",
|
|
9
|
+
"tui",
|
|
10
|
+
"widgets"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://github.com/folke/zaly/tree/main/packages/tui#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/folke/zaly/issues"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/folke/zaly.git",
|
|
20
|
+
"directory": "packages/tui"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist/**/*",
|
|
24
|
+
"assets/**/*"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"imports": {
|
|
28
|
+
"#ansi": {
|
|
29
|
+
"bun": "./dist/ansi.bun.mjs",
|
|
30
|
+
"default": "./dist/ansi.node.mjs"
|
|
31
|
+
},
|
|
32
|
+
"#md": {
|
|
33
|
+
"bun": "./dist/md.bun.mjs",
|
|
34
|
+
"default": "./dist/md.node.mjs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"exports": {
|
|
38
|
+
".": "./dist/index.mjs",
|
|
39
|
+
"./ansi": "./dist/ansi.mjs",
|
|
40
|
+
"./clipboard": "./dist/clipboard.mjs",
|
|
41
|
+
"./image": "./dist/image.mjs",
|
|
42
|
+
"./markdown": "./dist/markdown.mjs",
|
|
43
|
+
"./services/logger": "./dist/services/logger.mjs",
|
|
44
|
+
"./services/notifier": "./dist/services/notifier.mjs",
|
|
45
|
+
"./services/picker": "./dist/services/picker.mjs",
|
|
46
|
+
"./services/prompt": "./dist/services/prompt.mjs",
|
|
47
|
+
"./style": "./dist/style.mjs",
|
|
48
|
+
"./text": "./dist/text.mjs",
|
|
49
|
+
"./themes": "./dist/themes.mjs",
|
|
50
|
+
"./widgets/autocomplete": "./dist/widgets/autocomplete.mjs",
|
|
51
|
+
"./widgets/box": "./dist/widgets/box.mjs",
|
|
52
|
+
"./widgets/code": "./dist/widgets/code.mjs",
|
|
53
|
+
"./widgets/completions": "./dist/widgets/completions/index.mjs",
|
|
54
|
+
"./widgets/completions/actions": "./dist/widgets/completions/actions.mjs",
|
|
55
|
+
"./widgets/completions/files": "./dist/widgets/completions/files.mjs",
|
|
56
|
+
"./widgets/completions/github": "./dist/widgets/completions/github.mjs",
|
|
57
|
+
"./widgets/diff": "./dist/widgets/diff.mjs",
|
|
58
|
+
"./widgets/divider": "./dist/widgets/divider.mjs",
|
|
59
|
+
"./widgets/image": "./dist/widgets/image.mjs",
|
|
60
|
+
"./widgets/input": "./dist/widgets/input.mjs",
|
|
61
|
+
"./widgets/log": "./dist/widgets/log.mjs",
|
|
62
|
+
"./widgets/markdown": "./dist/widgets/markdown.mjs",
|
|
63
|
+
"./widgets/overlay": "./dist/widgets/overlay.mjs",
|
|
64
|
+
"./widgets/picker": "./dist/widgets/picker.mjs",
|
|
65
|
+
"./widgets/progress": "./dist/widgets/progress.mjs",
|
|
66
|
+
"./widgets/select": "./dist/widgets/select.mjs",
|
|
67
|
+
"./widgets/show": "./dist/widgets/show.mjs",
|
|
68
|
+
"./widgets/spinner": "./dist/widgets/spinner.mjs",
|
|
69
|
+
"./widgets/text": "./dist/widgets/text.mjs",
|
|
70
|
+
"./widgets/tree": "./dist/widgets/tree.mjs",
|
|
71
|
+
"./widgets/widget": "./dist/widgets/widget.mjs",
|
|
72
|
+
"./package.json": "./package.json"
|
|
73
|
+
},
|
|
74
|
+
"publishConfig": {
|
|
75
|
+
"access": "public"
|
|
76
|
+
},
|
|
77
|
+
"dependencies": {
|
|
78
|
+
"diff": "^9.0.0",
|
|
79
|
+
"marked": "^18.0.6",
|
|
80
|
+
"pathe": "^2.0.3",
|
|
81
|
+
"shiki": "^4.3.1",
|
|
82
|
+
"@zaly/shared": "0.0.3"
|
|
83
|
+
},
|
|
84
|
+
"devDependencies": {
|
|
85
|
+
"@typia/transform": "^12.1.1",
|
|
86
|
+
"ghostty-web": "^0.4.0",
|
|
87
|
+
"mitata": "^1.0.34",
|
|
88
|
+
"slice-ansi": "^9.0.0",
|
|
89
|
+
"string-width": "^8.2.2",
|
|
90
|
+
"typia": "^13.0.2",
|
|
91
|
+
"wrap-ansi": "^10.0.0"
|
|
92
|
+
},
|
|
93
|
+
"optionalDependencies": {
|
|
94
|
+
"sharp": "^0.35.3"
|
|
95
|
+
},
|
|
96
|
+
"engines": {
|
|
97
|
+
"bun": ">=1.2",
|
|
98
|
+
"node": ">=24"
|
|
99
|
+
},
|
|
100
|
+
"inlinedDependencies": {
|
|
101
|
+
"typia": "13.0.2"
|
|
102
|
+
},
|
|
103
|
+
"scripts": {
|
|
104
|
+
"bench": "z bench",
|
|
105
|
+
"build": "z build",
|
|
106
|
+
"build:themes-1-shiki": "bun scripts/themes-shiki.ts",
|
|
107
|
+
"build:themes-2-nvim": "exit 0; nvim -l scripts/themes-nvim.lua",
|
|
108
|
+
"build:themes-3-tokyonight": "bun scripts/themes-tokyonight.ts",
|
|
109
|
+
"build:themes-4-builtin": "bun scripts/themes-builtin.ts && oxfmt src/themes/builtin.ts",
|
|
110
|
+
"docs:api": "typedoc",
|
|
111
|
+
"docs:build": "bun run docs:api && vitepress build docs",
|
|
112
|
+
"docs:dev": "bun run docs:api && vitepress dev docs",
|
|
113
|
+
"docs:preview": "vitepress preview docs",
|
|
114
|
+
"lint": "z lint",
|
|
115
|
+
"test": "z test"
|
|
116
|
+
}
|
|
117
|
+
}
|