@nouxwell/tabula-core 0.4.0 → 0.5.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/dist/columns.d.ts +15 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +1132 -936
- package/dist/index.js.map +1 -1
- package/dist/table.d.ts +102 -2
- package/dist/templates.d.ts +6 -1
- package/dist/validation.d.ts +7 -1
- package/package.json +1 -1
package/dist/table.d.ts
CHANGED
|
@@ -18,6 +18,16 @@ export interface TableExportOptions {
|
|
|
18
18
|
readonly settings: ValueSettings;
|
|
19
19
|
/** What the first row holds: the columns' labels, their keys, or nothing. Labels by default. */
|
|
20
20
|
readonly header?: "label" | "key" | "none";
|
|
21
|
+
/**
|
|
22
|
+
* Columns of the host's own, written as text before or after the fields' (after by default), such
|
|
23
|
+
* as each row's number or its issues. Nothing reads them back as a value.
|
|
24
|
+
*/
|
|
25
|
+
readonly extra?: readonly ExtraColumn[];
|
|
26
|
+
}
|
|
27
|
+
export interface ExtraColumn {
|
|
28
|
+
readonly header: string;
|
|
29
|
+
readonly text: (rowId: RowId) => string;
|
|
30
|
+
readonly at?: "start" | "end";
|
|
21
31
|
}
|
|
22
32
|
export declare function exportTable(options: TableExportOptions): string[][];
|
|
23
33
|
/** The delimiter a spreadsheet in the sheet's language expects: `;` where the comma is the decimal mark. */
|
|
@@ -30,24 +40,35 @@ export interface TableImportOptions {
|
|
|
30
40
|
* leaves a column out.
|
|
31
41
|
*/
|
|
32
42
|
readonly columns?: Readonly<Record<number, string | null>>;
|
|
43
|
+
/**
|
|
44
|
+
* The column that finds each row in the sheet, for `matchRows`, by its position: its text is kept
|
|
45
|
+
* in `keys`, and it brings no value.
|
|
46
|
+
*/
|
|
47
|
+
readonly key?: number | null;
|
|
33
48
|
}
|
|
34
49
|
/**
|
|
35
50
|
* What became of a column. `unknown`: no field has its header. `duplicate`: an earlier column went
|
|
36
51
|
* to the same field. `read_only`: its field is not typed into, such as one shown for reference or
|
|
37
|
-
* worked out by a formula. `skipped`: left out on purpose.
|
|
52
|
+
* worked out by a formula. `skipped`: left out on purpose. `key`: it finds the rows (`key`).
|
|
38
53
|
*/
|
|
39
|
-
export type ColumnStatus = "matched" | "unknown" | "duplicate" | "read_only" | "skipped";
|
|
54
|
+
export type ColumnStatus = "matched" | "unknown" | "duplicate" | "read_only" | "skipped" | "key";
|
|
40
55
|
export interface ColumnMatch {
|
|
41
56
|
readonly index: number;
|
|
42
57
|
readonly header: string;
|
|
43
58
|
/** The field the column went to; null unless it was `matched`. */
|
|
44
59
|
readonly field: string | null;
|
|
45
60
|
readonly status: ColumnStatus;
|
|
61
|
+
/** Its first few values that are not empty, as written: what a column is told by. */
|
|
62
|
+
readonly samples: readonly string[];
|
|
63
|
+
/** Its cells whose text is not a value of its field's type. */
|
|
64
|
+
readonly unreadable: number;
|
|
46
65
|
}
|
|
47
66
|
export interface TableImport {
|
|
48
67
|
readonly columns: readonly ColumnMatch[];
|
|
49
68
|
/** For `RowStore.appendRows`: new rows, ids to be made. Empty lines are left out. */
|
|
50
69
|
readonly rows: RowInit[];
|
|
70
|
+
/** With `key`, that column's text in each row, trimmed, in the order of `rows`; empty otherwise. */
|
|
71
|
+
readonly keys: readonly string[];
|
|
51
72
|
/** Required fields no column brought: every row lacks them, and will say so. */
|
|
52
73
|
readonly missing: readonly string[];
|
|
53
74
|
/**
|
|
@@ -61,3 +82,82 @@ export interface TableImport {
|
|
|
61
82
|
* Each cell is read as what a user typed into the field would be.
|
|
62
83
|
*/
|
|
63
84
|
export declare function importTable(table: readonly (readonly string[])[], options: TableImportOptions): TableImport;
|
|
85
|
+
/**
|
|
86
|
+
* Why a column is suggested for a field. `remembered`: the host said this header went there before.
|
|
87
|
+
* `name`: the header is the field's label or key. `similar`: the header shares a word with the
|
|
88
|
+
* label, "Fiyat" with "Yeni fiyat". `values`: the column's values read as that field's and as no
|
|
89
|
+
* other's, "TRY" and "USD" as a currency's options.
|
|
90
|
+
*/
|
|
91
|
+
export type SuggestionReason = "remembered" | "name" | "similar" | "values";
|
|
92
|
+
export interface ColumnSuggestion {
|
|
93
|
+
/** The field the column would go to; null to leave it out. */
|
|
94
|
+
readonly field: string | null;
|
|
95
|
+
readonly reason: SuggestionReason | null;
|
|
96
|
+
}
|
|
97
|
+
export interface SuggestOptions {
|
|
98
|
+
readonly schema: ModuleSchema;
|
|
99
|
+
readonly settings: ValueSettings;
|
|
100
|
+
/**
|
|
101
|
+
* Where headers went before, by `headerKey`: a field's key, or null for a column left out. Kept by
|
|
102
|
+
* the host, such as from the user's last import.
|
|
103
|
+
*/
|
|
104
|
+
readonly remembered?: Readonly<Record<string, string | null>>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Where each column of a table would go, and why, for an import the user then looks over: what the
|
|
108
|
+
* host remembered, then the header as a field's name, then a word the two share, then values only
|
|
109
|
+
* one field reads. Only fields typed into are suggested, each for one column at most; a column
|
|
110
|
+
* nothing fits is left out.
|
|
111
|
+
*/
|
|
112
|
+
export declare function suggestColumns(table: readonly (readonly string[])[], options: SuggestOptions): ColumnSuggestion[];
|
|
113
|
+
/** A header as `SuggestOptions.remembered` keeps it: trimmed and lower-cased, in Turkish. */
|
|
114
|
+
export declare function headerKey(header: string): string;
|
|
115
|
+
export interface MatchSuggestion {
|
|
116
|
+
/** The table's column that finds the rows, by position. */
|
|
117
|
+
readonly column: number;
|
|
118
|
+
/** The field of the sheet it finds them by. */
|
|
119
|
+
readonly field: string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The column most likely to find a table's rows in the sheet, and the field it finds them by: the
|
|
123
|
+
* column whose values most often stand in some row's text, whole-number or lookup field, such as a
|
|
124
|
+
* product code. Null when none finds half of the values it holds.
|
|
125
|
+
*/
|
|
126
|
+
export declare function suggestMatch(table: readonly (readonly string[])[], store: RowStore, options: {
|
|
127
|
+
readonly schema: ModuleSchema;
|
|
128
|
+
readonly settings: ValueSettings;
|
|
129
|
+
}): MatchSuggestion | null;
|
|
130
|
+
/**
|
|
131
|
+
* The rows of the sheet each key finds: those whose `field` holds what the key's text reads as,
|
|
132
|
+
* compared as a backend is sent them, so "1.001" finds 1001, and text without regard to case or the
|
|
133
|
+
* spaces around it. A key that finds none gives an empty list; one that finds several, all of them.
|
|
134
|
+
*/
|
|
135
|
+
export declare function matchRows(store: RowStore, field: FieldSchema, keys: readonly string[], settings: ValueSettings): RowId[][];
|
|
136
|
+
/** The origin an import's change carries in the store and in the undo history. */
|
|
137
|
+
export declare const IMPORT_ORIGIN = "import";
|
|
138
|
+
export interface ImportApplyOptions {
|
|
139
|
+
/**
|
|
140
|
+
* For each row of the import, the rows of the sheet it is written into, as `matchRows` found
|
|
141
|
+
* them: the values the file brought, an empty cell emptying the cell it lands in. Left out, every
|
|
142
|
+
* row is added.
|
|
143
|
+
*/
|
|
144
|
+
readonly matches?: readonly (readonly RowId[])[];
|
|
145
|
+
/** With `matches`, what becomes of a row that found none: added at the end, or left out. */
|
|
146
|
+
readonly unmatched?: "add" | "skip";
|
|
147
|
+
/** Rows not to be written into, such as those the backend has processed. */
|
|
148
|
+
readonly locked?: (rowId: RowId) => boolean;
|
|
149
|
+
readonly origin?: string;
|
|
150
|
+
}
|
|
151
|
+
export interface ImportApplied {
|
|
152
|
+
/** The rows added at the end, in order. */
|
|
153
|
+
readonly added: readonly RowId[];
|
|
154
|
+
/** How many rows of the sheet were written into. */
|
|
155
|
+
readonly updated: number;
|
|
156
|
+
/** Rows of the file left out: finding none with `unmatched: "skip"`, or only rows locked. */
|
|
157
|
+
readonly skipped: number;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* An import put into the sheet as one change, taken back with one Ctrl+Z: rows written into where
|
|
161
|
+
* `matches` found them, the others added at the end with the schema's defaults, or left out.
|
|
162
|
+
*/
|
|
163
|
+
export declare function applyImport(store: RowStore, schema: ModuleSchema, imported: TableImport, options?: ImportApplyOptions): ImportApplied;
|
package/dist/templates.d.ts
CHANGED
|
@@ -49,7 +49,12 @@ export interface GridTemplate {
|
|
|
49
49
|
readonly checks: readonly CheckInput[];
|
|
50
50
|
/** Colour rules added after the schema's own, written as a schema's; see `StyleRule`. */
|
|
51
51
|
readonly styles: readonly StyleRuleInput[];
|
|
52
|
-
/**
|
|
52
|
+
/**
|
|
53
|
+
* How the sheet opens: the columns, widths, filters and sort, under each user's own views. Its
|
|
54
|
+
* column formats are not only where the sheet starts: they lie under each user's own whatever view
|
|
55
|
+
* is open, so every user of the template sees them (`mergeColumnFormats`, the grid's
|
|
56
|
+
* `defaultFormats`).
|
|
57
|
+
*/
|
|
53
58
|
readonly view: ViewState | null;
|
|
54
59
|
}
|
|
55
60
|
/** One thing wrong with a template, and where: `fields.newPrice.rules[0]`, `columns[1].key`. */
|
package/dist/validation.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RowId, RowStore } from "./rows.js";
|
|
2
2
|
import type { FieldSchema, ModuleSchema } from "./schema.js";
|
|
3
|
-
import type
|
|
3
|
+
import { type CellValue } from "./value.js";
|
|
4
4
|
import { type ValueProblemCode } from "./values/read.js";
|
|
5
5
|
import { type ValueSettings } from "./values/settings.js";
|
|
6
6
|
/**
|
|
@@ -80,6 +80,12 @@ export interface IssueSet {
|
|
|
80
80
|
* The schema's row checks are checked for the row a change touched, and only those that read the
|
|
81
81
|
* field it changed. Their issues land on the cell each check is about, as errors or as warnings.
|
|
82
82
|
*/
|
|
83
|
+
/**
|
|
84
|
+
* Whether a row holds nothing anyone gave it: every field empty or at its default, a formula's
|
|
85
|
+
* aside. Such a row, a new one nobody typed into or a pasted block's empty line, is neither checked
|
|
86
|
+
* nor sent; it is still the user's, kept with the draft until they delete it.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isBlankRow(schema: ModuleSchema, get: (key: string) => CellValue): boolean;
|
|
83
89
|
export declare class SheetValidator implements IssueSet {
|
|
84
90
|
#private;
|
|
85
91
|
constructor(schema: ModuleSchema, store: RowStore, settings?: ValueSettings);
|