@trama-ui/react-native 0.0.0-stage → 0.7.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 +21 -0
- package/README.md +198 -2
- package/dist/accordion.d.ts +29 -0
- package/dist/accordion.js +137 -0
- package/dist/alert.d.ts +30 -0
- package/dist/alert.js +95 -0
- package/dist/avatar.d.ts +36 -0
- package/dist/avatar.js +91 -0
- package/dist/bars.d.ts +44 -0
- package/dist/bars.js +74 -0
- package/dist/button.d.ts +30 -0
- package/dist/button.js +90 -0
- package/dist/calendar.d.ts +71 -0
- package/dist/calendar.js +276 -0
- package/dist/card.d.ts +41 -0
- package/dist/card.js +139 -0
- package/dist/choices.d.ts +87 -0
- package/dist/choices.js +228 -0
- package/dist/collections.d.ts +131 -0
- package/dist/collections.js +230 -0
- package/dist/color-code.d.ts +37 -0
- package/dist/color-code.js +158 -0
- package/dist/compositions.d.ts +110 -0
- package/dist/compositions.js +190 -0
- package/dist/controls.d.ts +85 -0
- package/dist/controls.js +221 -0
- package/dist/drag-drop.d.ts +65 -0
- package/dist/drag-drop.js +482 -0
- package/dist/feedback.d.ts +30 -0
- package/dist/feedback.js +81 -0
- package/dist/file-upload.d.ts +67 -0
- package/dist/file-upload.js +251 -0
- package/dist/generated/icons.d.ts +1037 -0
- package/dist/generated/icons.js +3 -0
- package/dist/generated/tokens.d.ts +64 -0
- package/dist/generated/tokens.js +65 -0
- package/dist/icon.d.ts +31 -0
- package/dist/icon.js +28 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +43 -0
- package/dist/input.d.ts +43 -0
- package/dist/input.js +115 -0
- package/dist/interactive-layout.d.ts +26 -0
- package/dist/interactive-layout.js +117 -0
- package/dist/internal/content.d.ts +17 -0
- package/dist/internal/content.js +24 -0
- package/dist/internal/drag-geometry.d.ts +16 -0
- package/dist/internal/drag-geometry.js +25 -0
- package/dist/internal/keyboard.d.ts +20 -0
- package/dist/internal/keyboard.js +101 -0
- package/dist/internal/motion.d.ts +1 -0
- package/dist/internal/motion.js +24 -0
- package/dist/internal/number-format.d.ts +4 -0
- package/dist/internal/number-format.js +25 -0
- package/dist/internal/pointer-capture.d.ts +1 -0
- package/dist/internal/pointer-capture.js +16 -0
- package/dist/internal/state.d.ts +6 -0
- package/dist/internal/state.js +28 -0
- package/dist/internal/system-drag.d.ts +48 -0
- package/dist/internal/system-drag.js +93 -0
- package/dist/internal/table-drag.d.ts +56 -0
- package/dist/internal/table-drag.js +237 -0
- package/dist/internal/table-editing.d.ts +49 -0
- package/dist/internal/table-editing.js +278 -0
- package/dist/internal/table-editor.d.ts +11 -0
- package/dist/internal/table-editor.js +31 -0
- package/dist/internal/table-grid.d.ts +44 -0
- package/dist/internal/table-grid.js +153 -0
- package/dist/internal/table-model.d.ts +132 -0
- package/dist/internal/table-model.js +231 -0
- package/dist/internal/table-source.d.ts +9 -0
- package/dist/internal/table-source.js +80 -0
- package/dist/internal/tour-target.d.ts +23 -0
- package/dist/internal/tour-target.js +81 -0
- package/dist/keyboard.d.ts +14 -0
- package/dist/keyboard.js +27 -0
- package/dist/layout.d.ts +35 -0
- package/dist/layout.js +77 -0
- package/dist/loader.d.ts +18 -0
- package/dist/loader.js +79 -0
- package/dist/localization.d.ts +106 -0
- package/dist/localization.js +310 -0
- package/dist/media.d.ts +35 -0
- package/dist/media.js +96 -0
- package/dist/menus.d.ts +103 -0
- package/dist/menus.js +422 -0
- package/dist/navigation.d.ts +111 -0
- package/dist/navigation.js +255 -0
- package/dist/overlays.d.ts +97 -0
- package/dist/overlays.js +364 -0
- package/dist/pill.d.ts +33 -0
- package/dist/pill.js +90 -0
- package/dist/progress.d.ts +27 -0
- package/dist/progress.js +154 -0
- package/dist/responsive.d.ts +15 -0
- package/dist/responsive.js +27 -0
- package/dist/select.d.ts +74 -0
- package/dist/select.js +181 -0
- package/dist/separator.d.ts +13 -0
- package/dist/separator.js +34 -0
- package/dist/switch.d.ts +26 -0
- package/dist/switch.js +69 -0
- package/dist/table.d.ts +122 -0
- package/dist/table.js +928 -0
- package/dist/text-fields.d.ts +39 -0
- package/dist/text-fields.js +134 -0
- package/dist/theme.d.ts +47 -0
- package/dist/theme.js +71 -0
- package/dist/transient.d.ts +80 -0
- package/dist/transient.js +273 -0
- package/package.json +50 -4
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export function tableGridSpans(rowCount, columnPins, rowEnds, requested) {
|
|
2
|
+
const width = columnPins.length;
|
|
3
|
+
const owners = new Map();
|
|
4
|
+
const rowSpans = new Map();
|
|
5
|
+
const anchors = [];
|
|
6
|
+
function count(value) {
|
|
7
|
+
return value !== undefined && Number.isFinite(value) ? Math.max(1, Math.floor(value)) : 1;
|
|
8
|
+
}
|
|
9
|
+
for (let row = 0; row < rowCount; row++) {
|
|
10
|
+
for (let column = 0; column < width; column++) {
|
|
11
|
+
if (owners.has(row * width + column))
|
|
12
|
+
continue;
|
|
13
|
+
const request = requested({ row, column });
|
|
14
|
+
let endColumn = column + 1;
|
|
15
|
+
const widthLimit = Math.min(width, column + count(request.columns));
|
|
16
|
+
while (endColumn < widthLimit &&
|
|
17
|
+
columnPins[endColumn] === columnPins[column] &&
|
|
18
|
+
!owners.has(row * width + endColumn))
|
|
19
|
+
endColumn++;
|
|
20
|
+
let endRow = row + 1;
|
|
21
|
+
const heightLimit = Math.min(rowCount, rowEnds[row] ?? rowCount, row + count(request.rows));
|
|
22
|
+
while (endRow < heightLimit) {
|
|
23
|
+
let clear = true;
|
|
24
|
+
for (let x = column; x < endColumn; x++) {
|
|
25
|
+
if (owners.has(endRow * width + x)) {
|
|
26
|
+
clear = false;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (!clear)
|
|
31
|
+
break;
|
|
32
|
+
endRow++;
|
|
33
|
+
}
|
|
34
|
+
if (endColumn === column + 1 && endRow === row + 1)
|
|
35
|
+
continue;
|
|
36
|
+
const span = { row, column, rows: endRow - row, columns: endColumn - column };
|
|
37
|
+
anchors.push(span);
|
|
38
|
+
for (let y = row; y < endRow; y++) {
|
|
39
|
+
let cells = rowSpans.get(y);
|
|
40
|
+
if (!cells) {
|
|
41
|
+
cells = new Map();
|
|
42
|
+
rowSpans.set(y, cells);
|
|
43
|
+
}
|
|
44
|
+
for (let x = column; x < endColumn; x++) {
|
|
45
|
+
owners.set(y * width + x, span);
|
|
46
|
+
cells.set(x, span);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
close(bounds) {
|
|
53
|
+
return closeGridBounds(bounds, anchors);
|
|
54
|
+
},
|
|
55
|
+
owner(point) {
|
|
56
|
+
return owners.get(point.row * width + point.column) ?? { ...point, rows: 1, columns: 1 };
|
|
57
|
+
},
|
|
58
|
+
row(index) {
|
|
59
|
+
return rowSpans.get(index);
|
|
60
|
+
},
|
|
61
|
+
rowEnd(index) {
|
|
62
|
+
let end = index + 1;
|
|
63
|
+
for (const span of rowSpans.get(index)?.values() ?? [])
|
|
64
|
+
end = Math.max(end, span.row + span.rows);
|
|
65
|
+
return end;
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function closeGridBounds(bounds, anchors) {
|
|
70
|
+
const result = { ...bounds };
|
|
71
|
+
let grew = true;
|
|
72
|
+
while (grew) {
|
|
73
|
+
grew = false;
|
|
74
|
+
for (const span of anchors) {
|
|
75
|
+
if (!gridSpanIntersects(span, result))
|
|
76
|
+
continue;
|
|
77
|
+
const { top, bottom, start, end } = result;
|
|
78
|
+
result.top = Math.min(top, span.row);
|
|
79
|
+
result.bottom = Math.max(bottom, span.row + span.rows - 1);
|
|
80
|
+
result.start = Math.min(start, span.column);
|
|
81
|
+
result.end = Math.max(end, span.column + span.columns - 1);
|
|
82
|
+
grew ||= top !== result.top || bottom !== result.bottom || start !== result.start || end !== result.end;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
export function gridTravel(event, point, current, bounds) {
|
|
88
|
+
if (!bounds.rows || !bounds.columns || event.altKey || event.isComposing)
|
|
89
|
+
return null;
|
|
90
|
+
let { row, column } = point;
|
|
91
|
+
const modified = event.ctrlKey || event.metaKey;
|
|
92
|
+
switch (event.key) {
|
|
93
|
+
case 'ArrowLeft':
|
|
94
|
+
case 'ArrowRight':
|
|
95
|
+
if (modified)
|
|
96
|
+
return null;
|
|
97
|
+
column = (event.key === 'ArrowRight') !== bounds.rtl ? current.column + current.columns : current.column - 1;
|
|
98
|
+
break;
|
|
99
|
+
case 'ArrowUp':
|
|
100
|
+
if (modified)
|
|
101
|
+
return null;
|
|
102
|
+
row = current.row - 1;
|
|
103
|
+
break;
|
|
104
|
+
case 'ArrowDown':
|
|
105
|
+
if (modified)
|
|
106
|
+
return null;
|
|
107
|
+
row = current.row + current.rows;
|
|
108
|
+
break;
|
|
109
|
+
case 'Home':
|
|
110
|
+
column = 0;
|
|
111
|
+
if (modified)
|
|
112
|
+
row = 0;
|
|
113
|
+
break;
|
|
114
|
+
case 'End':
|
|
115
|
+
column = bounds.columns - 1;
|
|
116
|
+
if (modified)
|
|
117
|
+
row = bounds.rows - 1;
|
|
118
|
+
break;
|
|
119
|
+
case 'PageUp':
|
|
120
|
+
case 'PageDown':
|
|
121
|
+
if (modified)
|
|
122
|
+
return null;
|
|
123
|
+
row += Math.max(1, bounds.pageRows) * (event.key === 'PageDown' ? 1 : -1);
|
|
124
|
+
break;
|
|
125
|
+
default:
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
row: Math.min(bounds.rows - 1, Math.max(0, row)),
|
|
130
|
+
column: Math.min(bounds.columns - 1, Math.max(0, column)),
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export function gridSpanIntersects(span, bounds) {
|
|
134
|
+
return (span.row <= bounds.bottom &&
|
|
135
|
+
span.row + span.rows - 1 >= bounds.top &&
|
|
136
|
+
span.column <= bounds.end &&
|
|
137
|
+
span.column + span.columns - 1 >= bounds.start);
|
|
138
|
+
}
|
|
139
|
+
export function gridColumnAt(x, width, scroll, offsets, pinnedStart, pinnedEnd, rtl) {
|
|
140
|
+
const logical = Math.max(0, Math.min(width - 0.01, rtl ? width - x : x));
|
|
141
|
+
const content = offsets[offsets.length - 1];
|
|
142
|
+
const point = logical < pinnedStart ? logical : logical >= width - pinnedEnd ? content - width + logical : logical + scroll;
|
|
143
|
+
let low = 0;
|
|
144
|
+
let high = offsets.length - 1;
|
|
145
|
+
while (low + 1 < high) {
|
|
146
|
+
const middle = Math.floor((low + high) / 2);
|
|
147
|
+
if (offsets[middle] <= point)
|
|
148
|
+
low = middle;
|
|
149
|
+
else
|
|
150
|
+
high = middle;
|
|
151
|
+
}
|
|
152
|
+
return low;
|
|
153
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { TramaNativeMessages } from '../localization.js';
|
|
3
|
+
export type TableRowId = string | number;
|
|
4
|
+
export type TableValue = string | number | boolean | null | undefined;
|
|
5
|
+
export interface TableSort {
|
|
6
|
+
key: string;
|
|
7
|
+
direction: 'ascending' | 'descending';
|
|
8
|
+
}
|
|
9
|
+
export interface TableCellAddress {
|
|
10
|
+
rowId: TableRowId;
|
|
11
|
+
columnId: string;
|
|
12
|
+
}
|
|
13
|
+
export interface TableCellRange {
|
|
14
|
+
anchor: TableCellAddress;
|
|
15
|
+
focus: TableCellAddress;
|
|
16
|
+
}
|
|
17
|
+
export interface TableCellChange extends TableCellAddress {
|
|
18
|
+
previous: TableValue;
|
|
19
|
+
value: TableValue;
|
|
20
|
+
}
|
|
21
|
+
export interface TableRowsChange {
|
|
22
|
+
reason: 'edit' | 'paste' | 'fill' | 'undo' | 'redo';
|
|
23
|
+
changes: readonly TableCellChange[];
|
|
24
|
+
}
|
|
25
|
+
export interface TableCellEditor<Row> {
|
|
26
|
+
type?: 'text' | 'number' | 'boolean' | 'select' | 'date' | 'time';
|
|
27
|
+
required?: boolean;
|
|
28
|
+
min?: number;
|
|
29
|
+
max?: number;
|
|
30
|
+
maxLength?: number;
|
|
31
|
+
options?: readonly {
|
|
32
|
+
value: string;
|
|
33
|
+
label: string;
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
}[];
|
|
36
|
+
validate?: (value: TableValue, row: Row) => string | undefined;
|
|
37
|
+
render?: (field: {
|
|
38
|
+
row: Row;
|
|
39
|
+
value: TableValue;
|
|
40
|
+
label: string;
|
|
41
|
+
error?: string;
|
|
42
|
+
setValue(value: TableValue): void;
|
|
43
|
+
}) => ReactNode;
|
|
44
|
+
}
|
|
45
|
+
export interface TableColumnDefinition<Row> {
|
|
46
|
+
id: string;
|
|
47
|
+
heading: string;
|
|
48
|
+
group?: string;
|
|
49
|
+
width?: number;
|
|
50
|
+
minWidth?: number;
|
|
51
|
+
maxWidth?: number;
|
|
52
|
+
pinned?: 'start' | 'end';
|
|
53
|
+
sortable?: boolean;
|
|
54
|
+
resizable?: boolean;
|
|
55
|
+
value?: (row: Row) => TableValue;
|
|
56
|
+
compare?: (first: TableValue, second: TableValue) => number;
|
|
57
|
+
editable?: boolean | ((row: Row) => boolean);
|
|
58
|
+
editor?: TableCellEditor<Row>;
|
|
59
|
+
setValue?: (row: Row, value: TableValue) => Row;
|
|
60
|
+
renderCell?: (row: Row) => ReactNode;
|
|
61
|
+
colSpan?: (row: Row) => number;
|
|
62
|
+
rowSpan?: (row: Row) => number;
|
|
63
|
+
renderHeader?: (state: {
|
|
64
|
+
sort: TableSort | null;
|
|
65
|
+
sorting: readonly TableSort[];
|
|
66
|
+
column: TableColumnDefinition<Row>;
|
|
67
|
+
}) => ReactNode;
|
|
68
|
+
}
|
|
69
|
+
export interface TableClipboard {
|
|
70
|
+
readText?: () => string | Promise<string>;
|
|
71
|
+
writeText?: (value: string) => void | Promise<void>;
|
|
72
|
+
}
|
|
73
|
+
export interface TableExportOptions {
|
|
74
|
+
format?: 'csv' | 'tsv' | 'json';
|
|
75
|
+
rows?: 'all' | 'filtered' | 'page' | 'selected';
|
|
76
|
+
includeHeaders?: boolean;
|
|
77
|
+
escapeFormulas?: boolean;
|
|
78
|
+
}
|
|
79
|
+
export interface TableQuery {
|
|
80
|
+
page: number;
|
|
81
|
+
pageSize: number;
|
|
82
|
+
filter: string;
|
|
83
|
+
sorting: readonly TableSort[];
|
|
84
|
+
signal: AbortSignal;
|
|
85
|
+
}
|
|
86
|
+
export type TableDataSource<Row> = (query: TableQuery) => Promise<{
|
|
87
|
+
rows: readonly Row[];
|
|
88
|
+
totalItems: number;
|
|
89
|
+
}>;
|
|
90
|
+
export declare function getTableValue<Row>(row: Row, column: TableColumnDefinition<Row>): TableValue;
|
|
91
|
+
export declare function canEditTableCell<Row>(row: Row, column: TableColumnDefinition<Row>): boolean;
|
|
92
|
+
type Validation = Pick<TramaNativeMessages, 'enterValue' | 'enterNumber' | 'minNumber' | 'maxNumber' | 'maxLength' | 'chooseOption' | 'chooseDate' | 'enterTime' | 'tableBooleanValue'>;
|
|
93
|
+
type TableCellResult = {
|
|
94
|
+
value: TableValue;
|
|
95
|
+
error?: undefined;
|
|
96
|
+
} | {
|
|
97
|
+
error: string;
|
|
98
|
+
};
|
|
99
|
+
export declare function validateTableCell<Row>(raw: TableValue, column: TableColumnDefinition<Row>, row: Row, messages: Validation, numeric?: {
|
|
100
|
+
format: Intl.NumberFormat;
|
|
101
|
+
parse(text: string, exponent?: boolean): number | undefined;
|
|
102
|
+
}): TableCellResult;
|
|
103
|
+
export declare function sameTableCell(a: TableCellAddress, b: TableCellAddress): boolean;
|
|
104
|
+
export declare function tableRangeBounds<Row>(range: TableCellRange | null, ids: readonly TableRowId[], columns: readonly TableColumnDefinition<Row>[]): {
|
|
105
|
+
top: number;
|
|
106
|
+
bottom: number;
|
|
107
|
+
start: number;
|
|
108
|
+
end: number;
|
|
109
|
+
} | null;
|
|
110
|
+
export declare function formatTableFields(rows: readonly (readonly TableValue[])[], delimiter?: string, escapeFormulas?: boolean): string;
|
|
111
|
+
export declare function parseTableFields(input: string): string[][] | null;
|
|
112
|
+
export type TableLayoutCell = {
|
|
113
|
+
key: string;
|
|
114
|
+
width: number;
|
|
115
|
+
pin?: 'start' | 'end';
|
|
116
|
+
};
|
|
117
|
+
export type TableLayoutSlot = {
|
|
118
|
+
index: number;
|
|
119
|
+
span?: number;
|
|
120
|
+
} | {
|
|
121
|
+
key: string;
|
|
122
|
+
width: number;
|
|
123
|
+
};
|
|
124
|
+
export declare function tableColumnOffsets(cells: readonly TableLayoutCell[]): number[];
|
|
125
|
+
export declare function tableColumnWindow(offsets: readonly number[], left: number, width: number, overscan: number): {
|
|
126
|
+
start: number;
|
|
127
|
+
end: number;
|
|
128
|
+
};
|
|
129
|
+
export declare function tableColumnSlots(cells: readonly TableLayoutCell[], offsets: readonly number[], start: number, end: number, retained: number): TableLayoutSlot[];
|
|
130
|
+
export declare function tableSpanningSlots(slots: readonly TableLayoutSlot[], cells: readonly TableLayoutCell[], offsets: readonly number[], spans: ReadonlyMap<number, number>): TableLayoutSlot[];
|
|
131
|
+
export declare function tableVisibleColumns<Row>(definitions: readonly TableColumnDefinition<Row>[], order: readonly string[], hidden: readonly string[]): TableColumnDefinition<Row>[];
|
|
132
|
+
export {};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { parseDate } from '@internationalized/date';
|
|
2
|
+
import { numberInputFormat } from './number-format.js';
|
|
3
|
+
export function getTableValue(row, column) {
|
|
4
|
+
if (column.value)
|
|
5
|
+
return column.value(row);
|
|
6
|
+
const value = row && typeof row === 'object' && column.id in row
|
|
7
|
+
? row[column.id]
|
|
8
|
+
: undefined;
|
|
9
|
+
return value == null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'
|
|
10
|
+
? value
|
|
11
|
+
: undefined;
|
|
12
|
+
}
|
|
13
|
+
export function canEditTableCell(row, column) {
|
|
14
|
+
if (!(column.setValue || (!column.value && row && typeof row === 'object' && !Array.isArray(row))))
|
|
15
|
+
return false;
|
|
16
|
+
return typeof column.editable === 'function' ? column.editable(row) : (column.editable ?? Boolean(column.editor));
|
|
17
|
+
}
|
|
18
|
+
const defaultNumberInput = numberInputFormat('en');
|
|
19
|
+
export function validateTableCell(raw, column, row, messages, numeric = defaultNumberInput) {
|
|
20
|
+
const editor = column.editor ?? {};
|
|
21
|
+
const type = editor.type ?? 'text';
|
|
22
|
+
const text = raw == null ? '' : String(raw);
|
|
23
|
+
const trimmed = text.trim();
|
|
24
|
+
let value = raw;
|
|
25
|
+
if (!trimmed) {
|
|
26
|
+
if (editor.required)
|
|
27
|
+
return { error: messages.enterValue };
|
|
28
|
+
value = type === 'number' || type === 'boolean' ? null : type === 'text' ? text : '';
|
|
29
|
+
}
|
|
30
|
+
else if (type === 'number') {
|
|
31
|
+
const parsed = numeric.parse(trimmed, true);
|
|
32
|
+
if (parsed === undefined)
|
|
33
|
+
return { error: messages.enterNumber };
|
|
34
|
+
value = parsed;
|
|
35
|
+
if (editor.min !== undefined && value < editor.min)
|
|
36
|
+
return { error: messages.minNumber(editor.min) };
|
|
37
|
+
if (editor.max !== undefined && value > editor.max)
|
|
38
|
+
return { error: messages.maxNumber(editor.max) };
|
|
39
|
+
}
|
|
40
|
+
else if (type === 'boolean') {
|
|
41
|
+
if (!/^(?:true|false|1|0)$/iu.test(trimmed))
|
|
42
|
+
return { error: messages.tableBooleanValue };
|
|
43
|
+
value = /^(?:true|1)$/iu.test(trimmed);
|
|
44
|
+
}
|
|
45
|
+
else if (type === 'select') {
|
|
46
|
+
const option = editor.options?.find((option) => !option.disabled && (option.value === text || option.label === text));
|
|
47
|
+
if (!option)
|
|
48
|
+
return { error: messages.chooseOption };
|
|
49
|
+
value = option.value;
|
|
50
|
+
}
|
|
51
|
+
else if (type === 'date') {
|
|
52
|
+
try {
|
|
53
|
+
if (parseDate(trimmed).toString() !== trimmed)
|
|
54
|
+
return { error: messages.chooseDate };
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
return { error: messages.chooseDate };
|
|
58
|
+
}
|
|
59
|
+
value = trimmed;
|
|
60
|
+
}
|
|
61
|
+
else if (type === 'time') {
|
|
62
|
+
if (!/^(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d)?$/u.test(trimmed))
|
|
63
|
+
return { error: messages.enterTime };
|
|
64
|
+
value = trimmed;
|
|
65
|
+
}
|
|
66
|
+
else if (!editor.render) {
|
|
67
|
+
if (editor.maxLength !== undefined && text.length > editor.maxLength)
|
|
68
|
+
return { error: messages.maxLength(editor.maxLength) };
|
|
69
|
+
value = text;
|
|
70
|
+
}
|
|
71
|
+
const error = editor.validate?.(value, row)?.trim();
|
|
72
|
+
return error ? { error } : { value };
|
|
73
|
+
}
|
|
74
|
+
export function sameTableCell(a, b) {
|
|
75
|
+
return a.rowId === b.rowId && a.columnId === b.columnId;
|
|
76
|
+
}
|
|
77
|
+
export function tableRangeBounds(range, ids, columns) {
|
|
78
|
+
if (!range)
|
|
79
|
+
return null;
|
|
80
|
+
const a = ids.indexOf(range.anchor.rowId);
|
|
81
|
+
const b = ids.indexOf(range.focus.rowId);
|
|
82
|
+
const x = columns.findIndex((column) => column.id === range.anchor.columnId);
|
|
83
|
+
const y = columns.findIndex((column) => column.id === range.focus.columnId);
|
|
84
|
+
if (a < 0 || b < 0 || x < 0 || y < 0)
|
|
85
|
+
return null;
|
|
86
|
+
return { top: Math.min(a, b), bottom: Math.max(a, b), start: Math.min(x, y), end: Math.max(x, y) };
|
|
87
|
+
}
|
|
88
|
+
export function formatTableFields(rows, delimiter = '\t', escapeFormulas = false) {
|
|
89
|
+
return rows
|
|
90
|
+
.map((row) => row
|
|
91
|
+
.map((field) => {
|
|
92
|
+
let text = String(field ?? '');
|
|
93
|
+
if (escapeFormulas && typeof field === 'string' && /^[\s\uFEFF]*[=+@\-]/u.test(text))
|
|
94
|
+
text = "'" + text;
|
|
95
|
+
return /["\t,\r\n]/u.test(text) ? '"' + text.replaceAll('"', '""') + '"' : text;
|
|
96
|
+
})
|
|
97
|
+
.join(delimiter))
|
|
98
|
+
.join('\r\n');
|
|
99
|
+
}
|
|
100
|
+
export function parseTableFields(input) {
|
|
101
|
+
const matrix = [];
|
|
102
|
+
let row = [];
|
|
103
|
+
let field = '';
|
|
104
|
+
let quoted = false;
|
|
105
|
+
let closed = false;
|
|
106
|
+
for (let index = 0; index < input.length; index++) {
|
|
107
|
+
const character = input[index];
|
|
108
|
+
if (quoted) {
|
|
109
|
+
if (character !== '"')
|
|
110
|
+
field += character;
|
|
111
|
+
else if (input[index + 1] === '"') {
|
|
112
|
+
field += '"';
|
|
113
|
+
index++;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
quoted = false;
|
|
117
|
+
closed = true;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (character === '\t' || character === '\n' || character === '\r') {
|
|
121
|
+
row.push(field);
|
|
122
|
+
field = '';
|
|
123
|
+
closed = false;
|
|
124
|
+
if (character !== '\t') {
|
|
125
|
+
matrix.push(row);
|
|
126
|
+
row = [];
|
|
127
|
+
if (character === '\r' && input[index + 1] === '\n')
|
|
128
|
+
index++;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (closed)
|
|
132
|
+
return null;
|
|
133
|
+
else if (!field && character === '"')
|
|
134
|
+
quoted = true;
|
|
135
|
+
else
|
|
136
|
+
field += character;
|
|
137
|
+
}
|
|
138
|
+
if (quoted)
|
|
139
|
+
return null;
|
|
140
|
+
if (row.length || field || closed || !matrix.length)
|
|
141
|
+
matrix.push([...row, field]);
|
|
142
|
+
return matrix;
|
|
143
|
+
}
|
|
144
|
+
export function tableColumnOffsets(cells) {
|
|
145
|
+
const offsets = [0];
|
|
146
|
+
for (const cell of cells)
|
|
147
|
+
offsets.push(offsets[offsets.length - 1] + cell.width);
|
|
148
|
+
return offsets;
|
|
149
|
+
}
|
|
150
|
+
export function tableColumnWindow(offsets, left, width, overscan) {
|
|
151
|
+
const last = offsets.length - 1;
|
|
152
|
+
function find(offset) {
|
|
153
|
+
let lower = 0;
|
|
154
|
+
let upper = last;
|
|
155
|
+
while (lower < upper) {
|
|
156
|
+
const mid = Math.floor((lower + upper) / 2);
|
|
157
|
+
if (offsets[mid + 1] <= offset)
|
|
158
|
+
lower = mid + 1;
|
|
159
|
+
else
|
|
160
|
+
upper = mid;
|
|
161
|
+
}
|
|
162
|
+
return lower;
|
|
163
|
+
}
|
|
164
|
+
return { start: Math.max(0, find(left) - overscan), end: Math.min(last, find(left + width) + 1 + overscan) };
|
|
165
|
+
}
|
|
166
|
+
export function tableColumnSlots(cells, offsets, start, end, retained) {
|
|
167
|
+
const slots = [];
|
|
168
|
+
let skipped = -1;
|
|
169
|
+
for (let index = 0; index <= cells.length; index++) {
|
|
170
|
+
const cell = cells[index];
|
|
171
|
+
if (cell && !cell.pin && index !== retained && (index < start || index >= end)) {
|
|
172
|
+
if (skipped === -1)
|
|
173
|
+
skipped = index;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
if (skipped >= 0) {
|
|
177
|
+
slots.push({ key: 'space-' + skipped, width: offsets[index] - offsets[skipped] });
|
|
178
|
+
skipped = -1;
|
|
179
|
+
}
|
|
180
|
+
if (cell)
|
|
181
|
+
slots.push({ index });
|
|
182
|
+
}
|
|
183
|
+
return slots;
|
|
184
|
+
}
|
|
185
|
+
export function tableSpanningSlots(slots, cells, offsets, spans) {
|
|
186
|
+
const visible = new Set(slots.flatMap((slot) => ('index' in slot ? [slot.index] : [])));
|
|
187
|
+
const result = [];
|
|
188
|
+
let gap = -1;
|
|
189
|
+
for (let index = 0; index <= cells.length;) {
|
|
190
|
+
const span = spans.get(index) ?? 1;
|
|
191
|
+
let display = false;
|
|
192
|
+
for (let column = index; column < index + span; column++) {
|
|
193
|
+
if (visible.has(column)) {
|
|
194
|
+
display = true;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (index < cells.length && !display) {
|
|
199
|
+
if (gap === -1)
|
|
200
|
+
gap = index;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
if (gap >= 0) {
|
|
204
|
+
result.push({ key: 'space-' + gap, width: offsets[index] - offsets[gap] });
|
|
205
|
+
gap = -1;
|
|
206
|
+
}
|
|
207
|
+
if (index < cells.length)
|
|
208
|
+
result.push({ index, span });
|
|
209
|
+
}
|
|
210
|
+
index += span;
|
|
211
|
+
}
|
|
212
|
+
return result;
|
|
213
|
+
}
|
|
214
|
+
export function tableVisibleColumns(definitions, order, hidden) {
|
|
215
|
+
const excluded = new Set(hidden);
|
|
216
|
+
const remaining = new Map(definitions.filter((column) => !excluded.has(column.id)).map((column) => [column.id, column]));
|
|
217
|
+
const visible = [];
|
|
218
|
+
for (const id of order) {
|
|
219
|
+
const column = remaining.get(id);
|
|
220
|
+
if (column) {
|
|
221
|
+
visible.push(column);
|
|
222
|
+
remaining.delete(id);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
visible.push(...remaining.values());
|
|
226
|
+
return [
|
|
227
|
+
...visible.filter((column) => column.pinned === 'start'),
|
|
228
|
+
...visible.filter((column) => !column.pinned),
|
|
229
|
+
...visible.filter((column) => column.pinned === 'end'),
|
|
230
|
+
];
|
|
231
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { TableDataSource, TableQuery } from './table-model.js';
|
|
2
|
+
export declare function useTableSource<Row>(source: TableDataSource<Row> | undefined, request: Omit<TableQuery, 'signal'>, cache: boolean, onError?: (error: unknown) => void): {
|
|
3
|
+
rows: readonly Row[];
|
|
4
|
+
totalItems: number | undefined;
|
|
5
|
+
loading: boolean;
|
|
6
|
+
failed: boolean;
|
|
7
|
+
refresh(): void;
|
|
8
|
+
updateRows(rows: readonly Row[]): boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
const emptyRows = [];
|
|
3
|
+
export function useTableSource(source, request, cache, onError) {
|
|
4
|
+
const { page, pageSize, filter } = request;
|
|
5
|
+
const sortKey = JSON.stringify(request.sorting);
|
|
6
|
+
const key = JSON.stringify([page, pageSize, filter, sortKey]);
|
|
7
|
+
const [version, setVersion] = useState(0);
|
|
8
|
+
const [result, setResult] = useState();
|
|
9
|
+
const errorCallback = useRef(onError);
|
|
10
|
+
errorCallback.current = onError;
|
|
11
|
+
const pages = useRef({ values: new Map() });
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
if (pages.current.source !== source)
|
|
14
|
+
pages.current = { source, values: new Map() };
|
|
15
|
+
if (!source)
|
|
16
|
+
return;
|
|
17
|
+
const stored = cache && pages.current.values.get(key);
|
|
18
|
+
if (stored) {
|
|
19
|
+
setResult({ source, key, version, page: stored });
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
void Promise.resolve()
|
|
24
|
+
.then(() => controller.signal.aborted
|
|
25
|
+
? undefined
|
|
26
|
+
: source({
|
|
27
|
+
page,
|
|
28
|
+
pageSize,
|
|
29
|
+
filter,
|
|
30
|
+
sorting: JSON.parse(sortKey),
|
|
31
|
+
signal: controller.signal,
|
|
32
|
+
}))
|
|
33
|
+
.then((next) => {
|
|
34
|
+
if (controller.signal.aborted || !next)
|
|
35
|
+
return;
|
|
36
|
+
const loaded = {
|
|
37
|
+
rows: next.rows,
|
|
38
|
+
totalItems: Number.isFinite(next.totalItems) ? Math.max(0, Math.floor(next.totalItems)) : 0,
|
|
39
|
+
};
|
|
40
|
+
if (cache) {
|
|
41
|
+
const values = pages.current.values;
|
|
42
|
+
if (values.size >= 12) {
|
|
43
|
+
const first = values.keys().next();
|
|
44
|
+
if (!first.done)
|
|
45
|
+
values.delete(first.value);
|
|
46
|
+
}
|
|
47
|
+
values.set(key, loaded);
|
|
48
|
+
}
|
|
49
|
+
setResult({ source, key, version, page: loaded });
|
|
50
|
+
})
|
|
51
|
+
.catch((error) => {
|
|
52
|
+
if (!controller.signal.aborted) {
|
|
53
|
+
setResult({ source, key, version, failed: true });
|
|
54
|
+
errorCallback.current?.(error);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return () => controller.abort();
|
|
58
|
+
}, [source, key, version, cache, page, pageSize, filter, sortKey]);
|
|
59
|
+
const matching = result && result.source === source && result.key === key && result.version === version ? result : undefined;
|
|
60
|
+
return {
|
|
61
|
+
rows: matching?.page?.rows ?? emptyRows,
|
|
62
|
+
totalItems: result?.source === source ? result?.page?.totalItems : undefined,
|
|
63
|
+
loading: Boolean(source && !matching),
|
|
64
|
+
failed: Boolean(matching?.failed),
|
|
65
|
+
refresh() {
|
|
66
|
+
pages.current.values.clear();
|
|
67
|
+
setVersion((previous) => previous + 1);
|
|
68
|
+
},
|
|
69
|
+
updateRows(rows) {
|
|
70
|
+
if (!matching?.page)
|
|
71
|
+
return false;
|
|
72
|
+
pages.current.values.clear();
|
|
73
|
+
const page = { ...matching.page, rows };
|
|
74
|
+
if (cache)
|
|
75
|
+
pages.current.values.set(key, page);
|
|
76
|
+
setResult({ ...matching, page });
|
|
77
|
+
return true;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ComponentRef, type RefObject } from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
type NativeView = ComponentRef<typeof View>;
|
|
4
|
+
export type TourTarget = Pick<NativeView, 'measureInWindow'>;
|
|
5
|
+
type Box = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
export interface TourTargetOptions {
|
|
12
|
+
value: string;
|
|
13
|
+
target?: RefObject<TourTarget | null>;
|
|
14
|
+
prepareTarget?: (signal: AbortSignal) => void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare function useTourTarget(step: TourTargetOptions | undefined, active: boolean, onMissing?: (value: string) => void): Box | undefined;
|
|
17
|
+
export declare function TourMask({ target, gap, color, testID }: {
|
|
18
|
+
target: Box;
|
|
19
|
+
gap: number;
|
|
20
|
+
color: string;
|
|
21
|
+
testID?: string;
|
|
22
|
+
}): import("react").JSX.Element;
|
|
23
|
+
export {};
|