tinky-table 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.
@@ -0,0 +1,190 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Border character mappings for different table styles.
4
+ * @module tinky-table/utils/border
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getBorderChars = getBorderChars;
8
+ exports.renderSeparator = renderSeparator;
9
+ /**
10
+ * Border characters for the 'single' style (thin lines).
11
+ */
12
+ var SINGLE_BORDER = {
13
+ top: "─",
14
+ bottom: "─",
15
+ left: "│",
16
+ right: "│",
17
+ topLeft: "┌",
18
+ topRight: "┐",
19
+ bottomLeft: "└",
20
+ bottomRight: "┘",
21
+ cross: "┼",
22
+ topCross: "┬",
23
+ bottomCross: "┴",
24
+ leftCross: "├",
25
+ rightCross: "┤",
26
+ horizontal: "─",
27
+ vertical: "│",
28
+ };
29
+ /**
30
+ * Border characters for the 'double' style (double lines).
31
+ */
32
+ var DOUBLE_BORDER = {
33
+ top: "═",
34
+ bottom: "═",
35
+ left: "║",
36
+ right: "║",
37
+ topLeft: "╔",
38
+ topRight: "╗",
39
+ bottomLeft: "╚",
40
+ bottomRight: "╝",
41
+ cross: "╬",
42
+ topCross: "╦",
43
+ bottomCross: "╩",
44
+ leftCross: "╠",
45
+ rightCross: "╣",
46
+ horizontal: "═",
47
+ vertical: "║",
48
+ };
49
+ /**
50
+ * Border characters for the 'round' style (rounded corners).
51
+ */
52
+ var ROUND_BORDER = {
53
+ top: "─",
54
+ bottom: "─",
55
+ left: "│",
56
+ right: "│",
57
+ topLeft: "╭",
58
+ topRight: "╮",
59
+ bottomLeft: "╰",
60
+ bottomRight: "╯",
61
+ cross: "┼",
62
+ topCross: "┬",
63
+ bottomCross: "┴",
64
+ leftCross: "├",
65
+ rightCross: "┤",
66
+ horizontal: "─",
67
+ vertical: "│",
68
+ };
69
+ /**
70
+ * Border characters for the 'bold' style (thick lines).
71
+ */
72
+ var BOLD_BORDER = {
73
+ top: "━",
74
+ bottom: "━",
75
+ left: "┃",
76
+ right: "┃",
77
+ topLeft: "┏",
78
+ topRight: "┓",
79
+ bottomLeft: "┗",
80
+ bottomRight: "┛",
81
+ cross: "╋",
82
+ topCross: "┳",
83
+ bottomCross: "┻",
84
+ leftCross: "┣",
85
+ rightCross: "┫",
86
+ horizontal: "━",
87
+ vertical: "┃",
88
+ };
89
+ /**
90
+ * Border characters for the 'classic' style (ASCII only).
91
+ */
92
+ var CLASSIC_BORDER = {
93
+ top: "-",
94
+ bottom: "-",
95
+ left: "|",
96
+ right: "|",
97
+ topLeft: "+",
98
+ topRight: "+",
99
+ bottomLeft: "+",
100
+ bottomRight: "+",
101
+ cross: "+",
102
+ topCross: "+",
103
+ bottomCross: "+",
104
+ leftCross: "+",
105
+ rightCross: "+",
106
+ horizontal: "-",
107
+ vertical: "|",
108
+ };
109
+ /**
110
+ * Empty border (no visible border characters).
111
+ */
112
+ var NO_BORDER = {
113
+ top: " ",
114
+ bottom: " ",
115
+ left: " ",
116
+ right: " ",
117
+ topLeft: " ",
118
+ topRight: " ",
119
+ bottomLeft: " ",
120
+ bottomRight: " ",
121
+ cross: " ",
122
+ topCross: " ",
123
+ bottomCross: " ",
124
+ leftCross: " ",
125
+ rightCross: " ",
126
+ horizontal: " ",
127
+ vertical: " ",
128
+ };
129
+ /**
130
+ * Map of border styles to their character sets.
131
+ */
132
+ var BORDER_STYLES = {
133
+ single: SINGLE_BORDER,
134
+ double: DOUBLE_BORDER,
135
+ round: ROUND_BORDER,
136
+ bold: BOLD_BORDER,
137
+ singleDouble: SINGLE_BORDER, // Use single for now
138
+ doubleSingle: DOUBLE_BORDER, // Use double for now
139
+ classic: CLASSIC_BORDER,
140
+ none: NO_BORDER,
141
+ };
142
+ /**
143
+ * Gets the border characters for a given table border style.
144
+ *
145
+ * @param style - The border style name
146
+ * @returns The corresponding border character set
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const chars = getBorderChars('single');
151
+ * console.log(chars.topLeft); // '┌'
152
+ * ```
153
+ */
154
+ function getBorderChars(style) {
155
+ var _a;
156
+ return (_a = BORDER_STYLES[style]) !== null && _a !== void 0 ? _a : SINGLE_BORDER;
157
+ }
158
+ /**
159
+ * Renders a horizontal separator line for the table.
160
+ *
161
+ * @param columnWidths - Array of column widths
162
+ * @param chars - Border character set
163
+ * @param position - Position of the separator ('top' | 'middle' | 'bottom')
164
+ * @returns The formatted separator string
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * const sep = renderSeparator([10, 15, 8], chars, 'top');
169
+ * // Returns: '┌──────────┬───────────────┬────────┐'
170
+ * ```
171
+ */
172
+ function renderSeparator(columnWidths, chars, position) {
173
+ var leftChar = position === "top"
174
+ ? chars.topLeft
175
+ : position === "bottom"
176
+ ? chars.bottomLeft
177
+ : chars.leftCross;
178
+ var rightChar = position === "top"
179
+ ? chars.topRight
180
+ : position === "bottom"
181
+ ? chars.bottomRight
182
+ : chars.rightCross;
183
+ var crossChar = position === "top"
184
+ ? chars.topCross
185
+ : position === "bottom"
186
+ ? chars.bottomCross
187
+ : chars.cross;
188
+ var segments = columnWidths.map(function (width) { return chars.horizontal.repeat(width); });
189
+ return leftChar + segments.join(crossChar) + rightChar;
190
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @fileoverview Column width utilities for tinky-table.
3
+ * @module tinky-table/utils/column-width
4
+ *
5
+ * Provides utilities for converting column definitions to grid template format.
6
+ */
7
+ import { type ColumnDef, type RowData } from "../types.js";
8
+ /**
9
+ * Grid template value type compatible with tinky's gridTemplateColumns.
10
+ * Uses taffy-layout's TrackSizingFunction format.
11
+ */
12
+ export type GridTemplateValue = number | {
13
+ min: number | "auto";
14
+ max: number | `${number}fr` | "auto";
15
+ };
16
+ /**
17
+ * Converts column width definitions to grid template format.
18
+ *
19
+ * Maps ColumnDef widths to taffy-layout's GridTemplateComponent:
20
+ * - `number` → fixed size
21
+ * - `'auto'` → fr(1) (flexible)
22
+ * - `'${number}%'` → percentage as fr units
23
+ *
24
+ * @template T - Row data type
25
+ * @param columns - Column definitions
26
+ * @returns Array of values for use with gridTemplateColumns
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const template = columnsToGridTemplate([
31
+ * { key: 'name', width: 20 },
32
+ * { key: 'email', width: 'auto' },
33
+ * { key: 'age', width: 10 }
34
+ * ]);
35
+ * // Returns: [20, fr(1), 10]
36
+ * ```
37
+ */
38
+ export declare function columnsToGridTemplate<T extends RowData>(columns: ColumnDef<T>[]): GridTemplateValue[];
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ /**
3
+ * @fileoverview Column width utilities for tinky-table.
4
+ * @module tinky-table/utils/column-width
5
+ *
6
+ * Provides utilities for converting column definitions to grid template format.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.columnsToGridTemplate = columnsToGridTemplate;
10
+ /**
11
+ * Creates a fractional unit value for grid templates.
12
+ *
13
+ * @param value - The fr value (e.g., 1 for 1fr)
14
+ * @returns A TrackSizingFunction object
15
+ */
16
+ function fr(value) {
17
+ return { min: "auto", max: "".concat(value, "fr") };
18
+ }
19
+ /**
20
+ * Converts column width definitions to grid template format.
21
+ *
22
+ * Maps ColumnDef widths to taffy-layout's GridTemplateComponent:
23
+ * - `number` → fixed size
24
+ * - `'auto'` → fr(1) (flexible)
25
+ * - `'${number}%'` → percentage as fr units
26
+ *
27
+ * @template T - Row data type
28
+ * @param columns - Column definitions
29
+ * @returns Array of values for use with gridTemplateColumns
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const template = columnsToGridTemplate([
34
+ * { key: 'name', width: 20 },
35
+ * { key: 'email', width: 'auto' },
36
+ * { key: 'age', width: 10 }
37
+ * ]);
38
+ * // Returns: [20, fr(1), 10]
39
+ * ```
40
+ */
41
+ function columnsToGridTemplate(columns) {
42
+ return columns.map(function (col) {
43
+ var _a;
44
+ var width = (_a = col.width) !== null && _a !== void 0 ? _a : "auto";
45
+ if (typeof width === "number") {
46
+ return width;
47
+ }
48
+ if (width === "auto") {
49
+ // Use fr(1) for flexible columns
50
+ return fr(1);
51
+ }
52
+ if (typeof width === "string" && width.endsWith("%")) {
53
+ // For percentage, use fr with the percentage value as relative weight
54
+ var percent = parseInt(width, 10);
55
+ return fr(percent);
56
+ }
57
+ return fr(1);
58
+ });
59
+ }
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "tinky-table",
3
+ "version": "0.1.0",
4
+ "description": "A feature-rich, customizable Table component for tinky applications",
5
+ "keywords": [
6
+ "tinky",
7
+ "table",
8
+ "react",
9
+ "cli",
10
+ "terminal",
11
+ "component",
12
+ "datagrid",
13
+ "ui"
14
+ ],
15
+ "homepage": "https://github.com/ByteLandTechnology/tinky-table#readme",
16
+ "bugs": {
17
+ "url": "https://github.com/ByteLandTechnology/tinky-table/issues"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/ByteLandTechnology/tinky-table.git"
22
+ },
23
+ "license": "MIT",
24
+ "author": {
25
+ "name": "ByteLandTechnology"
26
+ },
27
+ "type": "module",
28
+ "main": "./lib/index.js",
29
+ "scripts": {
30
+ "test": "bun test",
31
+ "build": "tsc && npm run docs",
32
+ "lint": "eslint src tests",
33
+ "prepublish": "npm run build",
34
+ "prepare": "husky",
35
+ "docs": "typedoc --plugin typedoc-plugin-markdown --disableSources --out docs/api && prettier --write docs/api"
36
+ },
37
+ "files": [
38
+ "./bin/*",
39
+ "./lib/*"
40
+ ],
41
+ "typings": "./lib/index.d.ts",
42
+ "peerDependencies": {
43
+ "tinky": "^1.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@commitlint/cli": "^20.3.0",
47
+ "@commitlint/config-conventional": "^20.3.0",
48
+ "@semantic-release/changelog": "^6.0.3",
49
+ "@semantic-release/git": "^10.0.1",
50
+ "@semantic-release/github": "^12.0.0",
51
+ "@semantic-release/npm": "^13.1.3",
52
+ "@types/bun": "^1.3.6",
53
+ "eslint": "^9.39.2",
54
+ "eslint-plugin-react": "^7.37.5",
55
+ "husky": "^9.1.7",
56
+ "jiti": "^2.6.1",
57
+ "lint-staged": "^16.2.7",
58
+ "prettier": "^3.7.4",
59
+ "typedoc": "^0.28.16",
60
+ "typedoc-plugin-markdown": "^4.9.0",
61
+ "typescript-eslint": "^8.53.0"
62
+ },
63
+ "commitlint": {
64
+ "extends": [
65
+ "@commitlint/config-conventional"
66
+ ]
67
+ },
68
+ "lint-staged": {
69
+ "*.{js,ts,jsx,tsx,json,md,yaml,yml}": "prettier --write"
70
+ }
71
+ }