@rowsncolumns/utils 9.3.0 → 9.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/cjs/index.d.ts +5 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +5 -0
- package/dist/cjs/rich-text-html.d.ts +82 -0
- package/dist/cjs/rich-text-html.d.ts.map +1 -0
- package/dist/cjs/rich-text-html.js +601 -0
- package/dist/cjs/rich-text-links.d.ts +23 -0
- package/dist/cjs/rich-text-links.d.ts.map +1 -0
- package/dist/cjs/rich-text-links.js +48 -0
- package/dist/cjs/sparkline-groups.d.ts +102 -0
- package/dist/cjs/sparkline-groups.d.ts.map +1 -0
- package/dist/cjs/sparkline-groups.js +452 -0
- package/dist/cjs/string.d.ts +15 -0
- package/dist/cjs/string.d.ts.map +1 -1
- package/dist/cjs/string.js +46 -1
- package/dist/cjs/table-names.d.ts +55 -0
- package/dist/cjs/table-names.d.ts.map +1 -0
- package/dist/cjs/table-names.js +189 -0
- package/dist/cjs/table-styles.d.ts +9 -0
- package/dist/cjs/table-styles.d.ts.map +1 -1
- package/dist/cjs/table-styles.js +53 -1
- package/dist/cjs/table-totals.d.ts +31 -0
- package/dist/cjs/table-totals.d.ts.map +1 -0
- package/dist/cjs/table-totals.js +84 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +5 -0
- package/dist/esm/rich-text-html.d.ts +82 -0
- package/dist/esm/rich-text-html.d.ts.map +1 -0
- package/dist/esm/rich-text-html.js +520 -0
- package/dist/esm/rich-text-links.d.ts +23 -0
- package/dist/esm/rich-text-links.d.ts.map +1 -0
- package/dist/esm/rich-text-links.js +31 -0
- package/dist/esm/sparkline-groups.d.ts +102 -0
- package/dist/esm/sparkline-groups.d.ts.map +1 -0
- package/dist/esm/sparkline-groups.js +387 -0
- package/dist/esm/string.d.ts +15 -0
- package/dist/esm/string.d.ts.map +1 -1
- package/dist/esm/string.js +43 -0
- package/dist/esm/table-names.d.ts +55 -0
- package/dist/esm/table-names.d.ts.map +1 -0
- package/dist/esm/table-names.js +129 -0
- package/dist/esm/table-styles.d.ts +9 -0
- package/dist/esm/table-styles.d.ts.map +1 -1
- package/dist/esm/table-styles.js +34 -1
- package/dist/esm/table-totals.d.ts +31 -0
- package/dist/esm/table-totals.d.ts.map +1 -0
- package/dist/esm/table-totals.js +68 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's rules for a table name (Table Design → Table Name / "Rename an Excel table"):
|
|
3
|
+
*
|
|
4
|
+
* - starts with a letter, an underscore (`_`) or a backslash (`\`);
|
|
5
|
+
* - the rest is letters, digits, periods (`.`) and underscores — no spaces;
|
|
6
|
+
* - is not a cell reference (`A1`, `R1C1`, `XFD1048576`) and not the lone `C` / `R` shortcuts;
|
|
7
|
+
* - is at most 255 characters;
|
|
8
|
+
* - is unique across the workbook, compared case-insensitively — against the other tables AND the
|
|
9
|
+
* defined names (Excel refuses a table named like an existing defined name, and a defined name
|
|
10
|
+
* spelled like an existing table).
|
|
11
|
+
*
|
|
12
|
+
* Both engines create and rename tables through these checks (the rnc store mirrors them in Rust and
|
|
13
|
+
* surfaces the same messages through its `rejections` channel), and the table editor's validation
|
|
14
|
+
* schema shows the same text under the name field.
|
|
15
|
+
*/
|
|
16
|
+
export declare const TABLE_NAME_MAX_LENGTH = 255;
|
|
17
|
+
export declare const TABLE_NAME_REQUIRED_MESSAGE = "Enter a table name.";
|
|
18
|
+
export declare const TABLE_NAME_TOO_LONG_MESSAGE = "Table names can't be longer than 255 characters.";
|
|
19
|
+
export declare const TABLE_NAME_SPACES_MESSAGE = "Table names can't contain spaces.";
|
|
20
|
+
export declare const TABLE_NAME_LEADING_CHAR_MESSAGE = "Table names must start with a letter, an underscore (_) or a backslash (\\).";
|
|
21
|
+
export declare const TABLE_NAME_INVALID_CHAR_MESSAGE = "Table names can only contain letters, numbers, periods (.) and underscores (_).";
|
|
22
|
+
export declare const TABLE_NAME_CELL_REFERENCE_MESSAGE = "Table names can't be a cell reference such as A1 or R1C1.";
|
|
23
|
+
export declare const tableNameDuplicateMessage: (existing: string) => string;
|
|
24
|
+
export declare const tableNameDefinedNameMessage: (existing: string) => string;
|
|
25
|
+
/** `create-table` with an `id` an existing table already holds is refused on both engines (#668 T-56). */
|
|
26
|
+
export declare const tableIdDuplicateMessage: (id: string | number) => string;
|
|
27
|
+
export declare const definedNameTableNameMessage: (existing: string) => string;
|
|
28
|
+
/** True when `name` reads as a cell reference in either A1 or R1C1 notation. */
|
|
29
|
+
export declare const isCellReferenceLikeName: (name: string) => boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The reason `name` is not an acceptable table name, or `undefined` when it is. `existingNames` are
|
|
32
|
+
* the OTHER tables' names in the workbook (leave the table being renamed out of it) and
|
|
33
|
+
* `existingDefinedNames` the workbook's defined names; duplicates against either are detected
|
|
34
|
+
* case-insensitively, the way Excel compares names.
|
|
35
|
+
*/
|
|
36
|
+
export declare const validateTableName: (name: string, existingNames?: Iterable<string> | null, existingDefinedNames?: Iterable<string> | null) => string | undefined;
|
|
37
|
+
export declare const isValidTableName: (name: string, existingNames?: Iterable<string> | null, existingDefinedNames?: Iterable<string> | null) => boolean;
|
|
38
|
+
/**
|
|
39
|
+
* The reason a defined name `name` cannot be created or renamed to — it is spelled like one of
|
|
40
|
+
* `tableNames` (case-insensitive) — or `undefined` when no table holds it. Excel keeps tables and
|
|
41
|
+
* defined names in one namespace.
|
|
42
|
+
*/
|
|
43
|
+
export declare const validateDefinedNameAgainstTables: (name: string, tableNames?: Iterable<string> | null) => string | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The default name for a new table: `Table1`, `Table2`, … — the LOWEST number no existing table
|
|
46
|
+
* uses (case-insensitive), so a deleted table's number is reissued and the result never collides.
|
|
47
|
+
* `format` localises the pattern (`(n) => \`Tabelle${n}\``).
|
|
48
|
+
*/
|
|
49
|
+
export declare const getNextTableName: (existingNames: Iterable<string>, format?: (index: number) => string) => string;
|
|
50
|
+
/**
|
|
51
|
+
* The name for a copy of table `base`: `Sales2`, `Sales3`, … — the LOWEST number no existing table
|
|
52
|
+
* uses (case-insensitive), the way Excel names the table on a duplicated sheet.
|
|
53
|
+
*/
|
|
54
|
+
export declare const getNextTableCopyName: (base: string, existingNames: Iterable<string>) => string;
|
|
55
|
+
//# sourceMappingURL=table-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-names.d.ts","sourceRoot":"","sources":["../../table-names.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAYzC,eAAO,MAAM,2BAA2B,wBAAwB,CAAC;AACjE,eAAO,MAAM,2BAA2B,qDAA0E,CAAC;AACnH,eAAO,MAAM,yBAAyB,sCAAsC,CAAC;AAC7E,eAAO,MAAM,+BAA+B,iFACoC,CAAC;AACjF,eAAO,MAAM,+BAA+B,oFACuC,CAAC;AACpF,eAAO,MAAM,iCAAiC,8DACe,CAAC;AAC9D,eAAO,MAAM,yBAAyB,GAAI,UAAU,MAAM,WACkC,CAAC;AAC7F,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,WACmD,CAAC;AAChH,0GAA0G;AAC1G,eAAO,MAAM,uBAAuB,GAAI,IAAI,MAAM,GAAG,MAAM,WACK,CAAC;AACjE,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,WACkD,CAAC;AAmB/G,gFAAgF;AAChF,eAAO,MAAM,uBAAuB,GAAI,MAAM,MAAM,KAAG,OAGzB,CAAC;AAE/B;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,MAAM,MAAM,EACZ,gBAAgB,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,EACvC,uBAAuB,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,KAC7C,MAAM,GAAG,SA4BX,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAC3B,MAAM,MAAM,EACZ,gBAAgB,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,EACvC,uBAAuB,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,KAC7C,OACyE,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,gCAAgC,GAC3C,MAAM,MAAM,EACZ,aAAa,QAAQ,CAAC,MAAM,CAAC,GAAG,IAAI,KACnC,MAAM,GAAG,SAGX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAC3B,eAAe,QAAQ,CAAC,MAAM,CAAC,EAC/B,SAAQ,CAAC,KAAK,EAAE,MAAM,KAAK,MAAmC,KAC7D,MAUF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAC/B,MAAM,MAAM,EACZ,eAAe,QAAQ,CAAC,MAAM,CAAC,KAC9B,MAUF,CAAC"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getNextTableCopyName = exports.getNextTableName = exports.validateDefinedNameAgainstTables = exports.isValidTableName = exports.validateTableName = exports.isCellReferenceLikeName = exports.definedNameTableNameMessage = exports.tableIdDuplicateMessage = exports.tableNameDefinedNameMessage = exports.tableNameDuplicateMessage = exports.TABLE_NAME_CELL_REFERENCE_MESSAGE = exports.TABLE_NAME_INVALID_CHAR_MESSAGE = exports.TABLE_NAME_LEADING_CHAR_MESSAGE = exports.TABLE_NAME_SPACES_MESSAGE = exports.TABLE_NAME_TOO_LONG_MESSAGE = exports.TABLE_NAME_REQUIRED_MESSAGE = exports.TABLE_NAME_MAX_LENGTH = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Excel's rules for a table name (Table Design → Table Name / "Rename an Excel table"):
|
|
7
|
+
*
|
|
8
|
+
* - starts with a letter, an underscore (`_`) or a backslash (`\`);
|
|
9
|
+
* - the rest is letters, digits, periods (`.`) and underscores — no spaces;
|
|
10
|
+
* - is not a cell reference (`A1`, `R1C1`, `XFD1048576`) and not the lone `C` / `R` shortcuts;
|
|
11
|
+
* - is at most 255 characters;
|
|
12
|
+
* - is unique across the workbook, compared case-insensitively — against the other tables AND the
|
|
13
|
+
* defined names (Excel refuses a table named like an existing defined name, and a defined name
|
|
14
|
+
* spelled like an existing table).
|
|
15
|
+
*
|
|
16
|
+
* Both engines create and rename tables through these checks (the rnc store mirrors them in Rust and
|
|
17
|
+
* surfaces the same messages through its `rejections` channel), and the table editor's validation
|
|
18
|
+
* schema shows the same text under the name field.
|
|
19
|
+
*/
|
|
20
|
+
exports.TABLE_NAME_MAX_LENGTH = 255;
|
|
21
|
+
// Built with `RegExp` (not literals) so the `u` flag survives the CJS build's ES5 target.
|
|
22
|
+
var LEADING_CHAR = new RegExp("^[\\p{L}_\\\\]", "u");
|
|
23
|
+
var BODY_CHARS = new RegExp("^[\\p{L}\\p{N}._]*$", "u");
|
|
24
|
+
/** `A1`-style — up to three ASCII column letters then a row number. */
|
|
25
|
+
var A1_REFERENCE = /^[A-Za-z]{1,3}\d+$/;
|
|
26
|
+
/** `R1C1`-style — `R`/`C` each followed by an optional index (`RC`, `R1C`, `R1C1`). */
|
|
27
|
+
var R1C1_REFERENCE = /^[Rr]\d*[Cc]\d*$/;
|
|
28
|
+
/** `C` and `R` alone select the active cell's column / row in the Name Box. */
|
|
29
|
+
var RESERVED_SHORTCUT = /^[CcRr]$/;
|
|
30
|
+
exports.TABLE_NAME_REQUIRED_MESSAGE = "Enter a table name.";
|
|
31
|
+
exports.TABLE_NAME_TOO_LONG_MESSAGE = "Table names can't be longer than ".concat(exports.TABLE_NAME_MAX_LENGTH, " characters.");
|
|
32
|
+
exports.TABLE_NAME_SPACES_MESSAGE = "Table names can't contain spaces.";
|
|
33
|
+
exports.TABLE_NAME_LEADING_CHAR_MESSAGE = "Table names must start with a letter, an underscore (_) or a backslash (\\).";
|
|
34
|
+
exports.TABLE_NAME_INVALID_CHAR_MESSAGE = "Table names can only contain letters, numbers, periods (.) and underscores (_).";
|
|
35
|
+
exports.TABLE_NAME_CELL_REFERENCE_MESSAGE = "Table names can't be a cell reference such as A1 or R1C1.";
|
|
36
|
+
var tableNameDuplicateMessage = function (existing) {
|
|
37
|
+
return "A table named \"".concat(existing, "\" already exists in this workbook. Table names must be unique.");
|
|
38
|
+
};
|
|
39
|
+
exports.tableNameDuplicateMessage = tableNameDuplicateMessage;
|
|
40
|
+
var tableNameDefinedNameMessage = function (existing) {
|
|
41
|
+
return "A defined name \"".concat(existing, "\" already exists in this workbook. Table names and defined names must be unique.");
|
|
42
|
+
};
|
|
43
|
+
exports.tableNameDefinedNameMessage = tableNameDefinedNameMessage;
|
|
44
|
+
/** `create-table` with an `id` an existing table already holds is refused on both engines (#668 T-56). */
|
|
45
|
+
var tableIdDuplicateMessage = function (id) {
|
|
46
|
+
return "A table with the id \"".concat(id, "\" already exists in this workbook.");
|
|
47
|
+
};
|
|
48
|
+
exports.tableIdDuplicateMessage = tableIdDuplicateMessage;
|
|
49
|
+
var definedNameTableNameMessage = function (existing) {
|
|
50
|
+
return "A table named \"".concat(existing, "\" already exists in this workbook. Table names and defined names must be unique.");
|
|
51
|
+
};
|
|
52
|
+
exports.definedNameTableNameMessage = definedNameTableNameMessage;
|
|
53
|
+
/** The entry of `names` that equals `name` case-insensitively, the way Excel compares names. */
|
|
54
|
+
var findNameCollision = function (name, names) {
|
|
55
|
+
var e_1, _a;
|
|
56
|
+
if (!names) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
var lower = name.toLowerCase();
|
|
60
|
+
try {
|
|
61
|
+
for (var names_1 = tslib_1.__values(names), names_1_1 = names_1.next(); !names_1_1.done; names_1_1 = names_1.next()) {
|
|
62
|
+
var existing = names_1_1.value;
|
|
63
|
+
if (existing.toLowerCase() === lower) {
|
|
64
|
+
return existing;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
69
|
+
finally {
|
|
70
|
+
try {
|
|
71
|
+
if (names_1_1 && !names_1_1.done && (_a = names_1.return)) _a.call(names_1);
|
|
72
|
+
}
|
|
73
|
+
finally { if (e_1) throw e_1.error; }
|
|
74
|
+
}
|
|
75
|
+
return undefined;
|
|
76
|
+
};
|
|
77
|
+
/** True when `name` reads as a cell reference in either A1 or R1C1 notation. */
|
|
78
|
+
var isCellReferenceLikeName = function (name) {
|
|
79
|
+
return A1_REFERENCE.test(name) ||
|
|
80
|
+
R1C1_REFERENCE.test(name) ||
|
|
81
|
+
RESERVED_SHORTCUT.test(name);
|
|
82
|
+
};
|
|
83
|
+
exports.isCellReferenceLikeName = isCellReferenceLikeName;
|
|
84
|
+
/**
|
|
85
|
+
* The reason `name` is not an acceptable table name, or `undefined` when it is. `existingNames` are
|
|
86
|
+
* the OTHER tables' names in the workbook (leave the table being renamed out of it) and
|
|
87
|
+
* `existingDefinedNames` the workbook's defined names; duplicates against either are detected
|
|
88
|
+
* case-insensitively, the way Excel compares names.
|
|
89
|
+
*/
|
|
90
|
+
var validateTableName = function (name, existingNames, existingDefinedNames) {
|
|
91
|
+
if (!name) {
|
|
92
|
+
return exports.TABLE_NAME_REQUIRED_MESSAGE;
|
|
93
|
+
}
|
|
94
|
+
if (name.length > exports.TABLE_NAME_MAX_LENGTH) {
|
|
95
|
+
return exports.TABLE_NAME_TOO_LONG_MESSAGE;
|
|
96
|
+
}
|
|
97
|
+
if (/\s/.test(name)) {
|
|
98
|
+
return exports.TABLE_NAME_SPACES_MESSAGE;
|
|
99
|
+
}
|
|
100
|
+
if (!LEADING_CHAR.test(name)) {
|
|
101
|
+
return exports.TABLE_NAME_LEADING_CHAR_MESSAGE;
|
|
102
|
+
}
|
|
103
|
+
if (!BODY_CHARS.test(name.slice(1))) {
|
|
104
|
+
return exports.TABLE_NAME_INVALID_CHAR_MESSAGE;
|
|
105
|
+
}
|
|
106
|
+
if ((0, exports.isCellReferenceLikeName)(name)) {
|
|
107
|
+
return exports.TABLE_NAME_CELL_REFERENCE_MESSAGE;
|
|
108
|
+
}
|
|
109
|
+
var duplicate = findNameCollision(name, existingNames);
|
|
110
|
+
if (duplicate !== undefined) {
|
|
111
|
+
return (0, exports.tableNameDuplicateMessage)(duplicate);
|
|
112
|
+
}
|
|
113
|
+
var definedName = findNameCollision(name, existingDefinedNames);
|
|
114
|
+
if (definedName !== undefined) {
|
|
115
|
+
return (0, exports.tableNameDefinedNameMessage)(definedName);
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
};
|
|
119
|
+
exports.validateTableName = validateTableName;
|
|
120
|
+
var isValidTableName = function (name, existingNames, existingDefinedNames) {
|
|
121
|
+
return (0, exports.validateTableName)(name, existingNames, existingDefinedNames) === undefined;
|
|
122
|
+
};
|
|
123
|
+
exports.isValidTableName = isValidTableName;
|
|
124
|
+
/**
|
|
125
|
+
* The reason a defined name `name` cannot be created or renamed to — it is spelled like one of
|
|
126
|
+
* `tableNames` (case-insensitive) — or `undefined` when no table holds it. Excel keeps tables and
|
|
127
|
+
* defined names in one namespace.
|
|
128
|
+
*/
|
|
129
|
+
var validateDefinedNameAgainstTables = function (name, tableNames) {
|
|
130
|
+
var table = findNameCollision(name, tableNames);
|
|
131
|
+
return table === undefined ? undefined : (0, exports.definedNameTableNameMessage)(table);
|
|
132
|
+
};
|
|
133
|
+
exports.validateDefinedNameAgainstTables = validateDefinedNameAgainstTables;
|
|
134
|
+
/**
|
|
135
|
+
* The default name for a new table: `Table1`, `Table2`, … — the LOWEST number no existing table
|
|
136
|
+
* uses (case-insensitive), so a deleted table's number is reissued and the result never collides.
|
|
137
|
+
* `format` localises the pattern (`(n) => \`Tabelle${n}\``).
|
|
138
|
+
*/
|
|
139
|
+
var getNextTableName = function (existingNames, format) {
|
|
140
|
+
var e_2, _a;
|
|
141
|
+
if (format === void 0) { format = function (index) { return "Table".concat(index); }; }
|
|
142
|
+
var taken = new Set();
|
|
143
|
+
try {
|
|
144
|
+
for (var existingNames_1 = tslib_1.__values(existingNames), existingNames_1_1 = existingNames_1.next(); !existingNames_1_1.done; existingNames_1_1 = existingNames_1.next()) {
|
|
145
|
+
var name_1 = existingNames_1_1.value;
|
|
146
|
+
taken.add(name_1.toLowerCase());
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
150
|
+
finally {
|
|
151
|
+
try {
|
|
152
|
+
if (existingNames_1_1 && !existingNames_1_1.done && (_a = existingNames_1.return)) _a.call(existingNames_1);
|
|
153
|
+
}
|
|
154
|
+
finally { if (e_2) throw e_2.error; }
|
|
155
|
+
}
|
|
156
|
+
var index = 1;
|
|
157
|
+
while (taken.has(format(index).toLowerCase())) {
|
|
158
|
+
index++;
|
|
159
|
+
}
|
|
160
|
+
return format(index);
|
|
161
|
+
};
|
|
162
|
+
exports.getNextTableName = getNextTableName;
|
|
163
|
+
/**
|
|
164
|
+
* The name for a copy of table `base`: `Sales2`, `Sales3`, … — the LOWEST number no existing table
|
|
165
|
+
* uses (case-insensitive), the way Excel names the table on a duplicated sheet.
|
|
166
|
+
*/
|
|
167
|
+
var getNextTableCopyName = function (base, existingNames) {
|
|
168
|
+
var e_3, _a;
|
|
169
|
+
var taken = new Set();
|
|
170
|
+
try {
|
|
171
|
+
for (var existingNames_2 = tslib_1.__values(existingNames), existingNames_2_1 = existingNames_2.next(); !existingNames_2_1.done; existingNames_2_1 = existingNames_2.next()) {
|
|
172
|
+
var name_2 = existingNames_2_1.value;
|
|
173
|
+
taken.add(name_2.toLowerCase());
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
177
|
+
finally {
|
|
178
|
+
try {
|
|
179
|
+
if (existingNames_2_1 && !existingNames_2_1.done && (_a = existingNames_2.return)) _a.call(existingNames_2);
|
|
180
|
+
}
|
|
181
|
+
finally { if (e_3) throw e_3.error; }
|
|
182
|
+
}
|
|
183
|
+
var index = 2;
|
|
184
|
+
while (taken.has("".concat(base).concat(index).toLowerCase())) {
|
|
185
|
+
index++;
|
|
186
|
+
}
|
|
187
|
+
return "".concat(base).concat(index);
|
|
188
|
+
};
|
|
189
|
+
exports.getNextTableCopyName = getNextTableCopyName;
|
|
@@ -32,6 +32,15 @@ export type BandingProperties = {
|
|
|
32
32
|
secondBandBorder?: Maybe<Borders>;
|
|
33
33
|
totalRowColor?: Maybe<Color>;
|
|
34
34
|
totalRowBorder?: Maybe<Borders>;
|
|
35
|
+
/**
|
|
36
|
+
* Fill of the table's first / last column when the table shows them (`TableView.showFirstColumn`
|
|
37
|
+
* / `showLastColumn` — Excel's Table Design → First Column / Last Column). Every built-in style
|
|
38
|
+
* emphasises those columns in bold; only the Dark styles add a fill.
|
|
39
|
+
*/
|
|
40
|
+
firstColumnColor?: Maybe<Color>;
|
|
41
|
+
lastColumnColor?: Maybe<Color>;
|
|
42
|
+
/** Excel's `totalRow` style element bolds the totals row. */
|
|
43
|
+
totalRowBold?: Maybe<boolean>;
|
|
35
44
|
};
|
|
36
45
|
export type BandedDefinition = {
|
|
37
46
|
rowProperties?: Maybe<BandingProperties>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table-styles.d.ts","sourceRoot":"","sources":["../../table-styles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAG5C,MAAM,MAAM,UAAU,GAAG;IACvB,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACtB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B,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,oBAAoB,GACpB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,iBAAiB,GACjB,kBAAkB,GAClB,kBAAkB,CAAC;AAEvB,KAAK,eAAe,GAAG;IACrB,KAAK,EAAE,UAAU;IACjB,mBAAmB,EAAE,MAAM,GAAG,SAAS;IACvC,cAAc,EAAE,MAAM,GAAG,SAAS;IAClC,cAAc,EAAE,gBAAgB,GAAG,SAAS;CAC7C,CAAC;AAKF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAC/B,gBAAgB,OAAO,GAAG,SAAS,EACnC,mBAAmB,OAAO,GAAG,SAAS,KACrC,GAAG,CAAC,MAAM,EAAE,eAAe,EAAE,CAoX/B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,YAAY,UAAU,EACtB,gBAAgB,OAAO,GAAG,SAAS,EACnC,mBAAmB,OAAO,GAAG,SAAS,KACrC,gBAAgB,GAAG,SAcrB,CAAC"}
|
package/dist/cjs/table-styles.js
CHANGED
|
@@ -12,10 +12,12 @@ var colorIndexes = [1, 4, 5, 6, 7, 8, 9];
|
|
|
12
12
|
* Get table border styles map with all table themes and their banded definitions
|
|
13
13
|
*/
|
|
14
14
|
var getTableBorderStyles = function (showRowStripes, showColumnStripes) {
|
|
15
|
+
var e_1, _a, e_2, _b;
|
|
16
|
+
var _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
15
17
|
var runningLightIndex = 1;
|
|
16
18
|
var runningMediumIndex = 1;
|
|
17
19
|
var runningDarkIndex = 1;
|
|
18
|
-
|
|
20
|
+
var styles = new Map([
|
|
19
21
|
[
|
|
20
22
|
"Light",
|
|
21
23
|
tslib_1.__spreadArray(tslib_1.__spreadArray(tslib_1.__spreadArray([
|
|
@@ -280,6 +282,10 @@ var getTableBorderStyles = function (showRowStripes, showColumnStripes) {
|
|
|
280
282
|
tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(colorIndexes.map(function (value) {
|
|
281
283
|
var firstTint = value - 1 === 0 ? 0.25 : -0.25;
|
|
282
284
|
var secondTint = value - 1 === 0 ? 0.5 : 0;
|
|
285
|
+
var edgeColumnColor = {
|
|
286
|
+
theme: value,
|
|
287
|
+
tint: value - 1 === 0 ? 0.15 : -0.5,
|
|
288
|
+
};
|
|
283
289
|
return [
|
|
284
290
|
("TableStyleDark" + runningDarkIndex++),
|
|
285
291
|
firstTint,
|
|
@@ -295,6 +301,8 @@ var getTableBorderStyles = function (showRowStripes, showColumnStripes) {
|
|
|
295
301
|
theme: value,
|
|
296
302
|
tint: secondTint,
|
|
297
303
|
},
|
|
304
|
+
firstColumnColor: edgeColumnColor,
|
|
305
|
+
lastColumnColor: edgeColumnColor,
|
|
298
306
|
},
|
|
299
307
|
columnProperties: showColumnStripes
|
|
300
308
|
? {
|
|
@@ -309,6 +317,10 @@ var getTableBorderStyles = function (showRowStripes, showColumnStripes) {
|
|
|
309
317
|
})), false), tslib_1.__read([1, 5, 7, 9].map(function (value) {
|
|
310
318
|
var firstTint = value - 1 === 0 ? -0.35 : 0.6;
|
|
311
319
|
var secondTint = value - 1 === 0 ? -0.15 : 0.8;
|
|
320
|
+
var edgeColumnColor = {
|
|
321
|
+
theme: value - 1,
|
|
322
|
+
tint: value - 1 === 0 ? -0.5 : 0.4,
|
|
323
|
+
};
|
|
312
324
|
return [
|
|
313
325
|
("TableStyleDark" + runningDarkIndex++),
|
|
314
326
|
firstTint,
|
|
@@ -324,6 +336,8 @@ var getTableBorderStyles = function (showRowStripes, showColumnStripes) {
|
|
|
324
336
|
theme: value - 1,
|
|
325
337
|
tint: secondTint,
|
|
326
338
|
},
|
|
339
|
+
firstColumnColor: edgeColumnColor,
|
|
340
|
+
lastColumnColor: edgeColumnColor,
|
|
327
341
|
},
|
|
328
342
|
columnProperties: showColumnStripes
|
|
329
343
|
? {
|
|
@@ -338,6 +352,44 @@ var getTableBorderStyles = function (showRowStripes, showColumnStripes) {
|
|
|
338
352
|
})), false),
|
|
339
353
|
],
|
|
340
354
|
]);
|
|
355
|
+
try {
|
|
356
|
+
// Excel's built-in table styles bold the totals row and rule it with a double top border in
|
|
357
|
+
// the style's accent colour — the header border's colour, else the header fill's, else the
|
|
358
|
+
// stripe border's.
|
|
359
|
+
for (var _m = tslib_1.__values(styles.values()), _o = _m.next(); !_o.done; _o = _m.next()) {
|
|
360
|
+
var entries = _o.value;
|
|
361
|
+
try {
|
|
362
|
+
for (var entries_1 = (e_2 = void 0, tslib_1.__values(entries)), entries_1_1 = entries_1.next(); !entries_1_1.done; entries_1_1 = entries_1.next()) {
|
|
363
|
+
var _p = tslib_1.__read(entries_1_1.value, 4), bandDefinition = _p[3];
|
|
364
|
+
var rows = bandDefinition === null || bandDefinition === void 0 ? void 0 : bandDefinition.rowProperties;
|
|
365
|
+
if (!rows)
|
|
366
|
+
continue;
|
|
367
|
+
rows.totalRowBold = true;
|
|
368
|
+
var accent = (_j = (_h = (_e = (_d = (_c = rows.headerBorder) === null || _c === void 0 ? void 0 : _c.top) === null || _d === void 0 ? void 0 : _d.color) !== null && _e !== void 0 ? _e : (_g = (_f = rows.headerBorder) === null || _f === void 0 ? void 0 : _f.bottom) === null || _g === void 0 ? void 0 : _g.color) !== null && _h !== void 0 ? _h : rows.headerColor) !== null && _j !== void 0 ? _j : (_l = (_k = rows.firstBandBorder) === null || _k === void 0 ? void 0 : _k.bottom) === null || _l === void 0 ? void 0 : _l.color;
|
|
369
|
+
if (accent && !rows.totalRowBorder) {
|
|
370
|
+
rows.totalRowBorder = {
|
|
371
|
+
top: { width: 1, style: "double", color: accent },
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
377
|
+
finally {
|
|
378
|
+
try {
|
|
379
|
+
if (entries_1_1 && !entries_1_1.done && (_b = entries_1.return)) _b.call(entries_1);
|
|
380
|
+
}
|
|
381
|
+
finally { if (e_2) throw e_2.error; }
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
386
|
+
finally {
|
|
387
|
+
try {
|
|
388
|
+
if (_o && !_o.done && (_a = _m.return)) _a.call(_m);
|
|
389
|
+
}
|
|
390
|
+
finally { if (e_1) throw e_1.error; }
|
|
391
|
+
}
|
|
392
|
+
return styles;
|
|
341
393
|
};
|
|
342
394
|
exports.getTableBorderStyles = getTableBorderStyles;
|
|
343
395
|
/**
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Excel's table totals row: the `totalsRowFunction` values a `<tableColumn>` carries
|
|
3
|
+
* (ECMA-376 `ST_TotalsRowFunction`), the hidden-row-aware `SUBTOTAL` number each one
|
|
4
|
+
* writes into the totals cell, and the structured-reference formula for it.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TOTALS_ROW_FUNCTIONS: readonly ["none", "average", "count", "countNums", "max", "min", "sum", "stdDev", "var", "custom"];
|
|
7
|
+
export type TotalsRowFunction = (typeof TOTALS_ROW_FUNCTIONS)[number];
|
|
8
|
+
/**
|
|
9
|
+
* `SUBTOTAL` function numbers of the 101–111 family (ignore rows hidden by a filter),
|
|
10
|
+
* as Excel writes them into a totals-row cell. `none` and `custom` have none.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TOTALS_ROW_FUNCTION_SUBTOTAL: Readonly<Partial<Record<TotalsRowFunction, number>>>;
|
|
13
|
+
export declare const isTotalsRowFunction: (value: unknown) => value is TotalsRowFunction;
|
|
14
|
+
/**
|
|
15
|
+
* Escape a column name for use inside a structured reference: `[`, `]`, `#`
|
|
16
|
+
* and `'` are prefixed with `'`, as Excel does (`Sales[Amount '[est']]`).
|
|
17
|
+
*/
|
|
18
|
+
export declare const escapeStructuredColumnName: (name: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* The totals-row formula for `fn` over a table column, qualified with the table
|
|
21
|
+
* name so it evaluates from any engine and matches what Excel writes:
|
|
22
|
+
* `=SUBTOTAL(109,Sales[Amount])`. `undefined` for `none` / `custom`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const getTotalsRowFormula: (fn: TotalsRowFunction, tableName: string, columnName: string) => string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Recognise the aggregation a totals-row formula uses. Both the hidden-row-aware
|
|
27
|
+
* (1xx) and plain (1–11) `SUBTOTAL` numbers map to the same function; anything
|
|
28
|
+
* else is `none`.
|
|
29
|
+
*/
|
|
30
|
+
export declare const getTotalsRowFunctionFromFormula: (formula: string | null | undefined) => TotalsRowFunction;
|
|
31
|
+
//# sourceMappingURL=table-totals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table-totals.d.ts","sourceRoot":"","sources":["../../table-totals.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,oGAWvB,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE;;;GAGG;AACH,eAAO,MAAM,4BAA4B,EAAE,QAAQ,CACjD,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,MAAM,CAAC,CAAC,CAU3C,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,OAAO,OAAO,KACb,KAAK,IAAI,iBAEiD,CAAC;AAE9D;;;GAGG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM,MAAM,WACnB,CAAC;AAErC;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAC9B,IAAI,iBAAiB,EACrB,WAAW,MAAM,EACjB,YAAY,MAAM,KACjB,MAAM,GAAG,SAQX,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAC1C,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,KACjC,iBAcF,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTotalsRowFunctionFromFormula = exports.getTotalsRowFormula = exports.escapeStructuredColumnName = exports.isTotalsRowFunction = exports.TOTALS_ROW_FUNCTION_SUBTOTAL = exports.TOTALS_ROW_FUNCTIONS = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Excel's table totals row: the `totalsRowFunction` values a `<tableColumn>` carries
|
|
7
|
+
* (ECMA-376 `ST_TotalsRowFunction`), the hidden-row-aware `SUBTOTAL` number each one
|
|
8
|
+
* writes into the totals cell, and the structured-reference formula for it.
|
|
9
|
+
*/
|
|
10
|
+
exports.TOTALS_ROW_FUNCTIONS = [
|
|
11
|
+
"none",
|
|
12
|
+
"average",
|
|
13
|
+
"count",
|
|
14
|
+
"countNums",
|
|
15
|
+
"max",
|
|
16
|
+
"min",
|
|
17
|
+
"sum",
|
|
18
|
+
"stdDev",
|
|
19
|
+
"var",
|
|
20
|
+
"custom",
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* `SUBTOTAL` function numbers of the 101–111 family (ignore rows hidden by a filter),
|
|
24
|
+
* as Excel writes them into a totals-row cell. `none` and `custom` have none.
|
|
25
|
+
*/
|
|
26
|
+
exports.TOTALS_ROW_FUNCTION_SUBTOTAL = {
|
|
27
|
+
average: 101,
|
|
28
|
+
countNums: 102,
|
|
29
|
+
count: 103,
|
|
30
|
+
max: 104,
|
|
31
|
+
min: 105,
|
|
32
|
+
stdDev: 107,
|
|
33
|
+
sum: 109,
|
|
34
|
+
var: 110,
|
|
35
|
+
};
|
|
36
|
+
var isTotalsRowFunction = function (value) {
|
|
37
|
+
return typeof value === "string" &&
|
|
38
|
+
exports.TOTALS_ROW_FUNCTIONS.includes(value);
|
|
39
|
+
};
|
|
40
|
+
exports.isTotalsRowFunction = isTotalsRowFunction;
|
|
41
|
+
/**
|
|
42
|
+
* Escape a column name for use inside a structured reference: `[`, `]`, `#`
|
|
43
|
+
* and `'` are prefixed with `'`, as Excel does (`Sales[Amount '[est']]`).
|
|
44
|
+
*/
|
|
45
|
+
var escapeStructuredColumnName = function (name) {
|
|
46
|
+
return name.replace(/(['\[\]#])/g, "'$1");
|
|
47
|
+
};
|
|
48
|
+
exports.escapeStructuredColumnName = escapeStructuredColumnName;
|
|
49
|
+
/**
|
|
50
|
+
* The totals-row formula for `fn` over a table column, qualified with the table
|
|
51
|
+
* name so it evaluates from any engine and matches what Excel writes:
|
|
52
|
+
* `=SUBTOTAL(109,Sales[Amount])`. `undefined` for `none` / `custom`.
|
|
53
|
+
*/
|
|
54
|
+
var getTotalsRowFormula = function (fn, tableName, columnName) {
|
|
55
|
+
var subtotal = exports.TOTALS_ROW_FUNCTION_SUBTOTAL[fn];
|
|
56
|
+
if (subtotal === undefined) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
return "=SUBTOTAL(".concat(subtotal, ",").concat(tableName, "[").concat((0, exports.escapeStructuredColumnName)(columnName), "])");
|
|
60
|
+
};
|
|
61
|
+
exports.getTotalsRowFormula = getTotalsRowFormula;
|
|
62
|
+
/**
|
|
63
|
+
* Recognise the aggregation a totals-row formula uses. Both the hidden-row-aware
|
|
64
|
+
* (1xx) and plain (1–11) `SUBTOTAL` numbers map to the same function; anything
|
|
65
|
+
* else is `none`.
|
|
66
|
+
*/
|
|
67
|
+
var getTotalsRowFunctionFromFormula = function (formula) {
|
|
68
|
+
var _a;
|
|
69
|
+
if (!formula) {
|
|
70
|
+
return "none";
|
|
71
|
+
}
|
|
72
|
+
var match = /^\s*=\s*SUBTOTAL\s*\(\s*(\d{1,3})\s*,/i.exec(formula);
|
|
73
|
+
if (!match) {
|
|
74
|
+
return "none";
|
|
75
|
+
}
|
|
76
|
+
var number = Number(match[1]);
|
|
77
|
+
var normalized = number > 100 ? number - 100 : number;
|
|
78
|
+
var found = Object.entries(exports.TOTALS_ROW_FUNCTION_SUBTOTAL).find(function (_a) {
|
|
79
|
+
var _b = tslib_1.__read(_a, 2), subtotal = _b[1];
|
|
80
|
+
return subtotal - 100 === normalized;
|
|
81
|
+
});
|
|
82
|
+
return (_a = found === null || found === void 0 ? void 0 : found[0]) !== null && _a !== void 0 ? _a : "none";
|
|
83
|
+
};
|
|
84
|
+
exports.getTotalsRowFunctionFromFormula = getTotalsRowFunctionFromFormula;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-span.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["../../array.ts","../../cell-data-helpers.ts","../../color.ts","../../colors.ts","../../conditional-format.ts","../../content-hash.ts","../../data-validation.ts","../../date.ts","../../dom.ts","../../excel-number-format.ts","../../formatter.ts","../../formula-locale.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../rich-text-html.ts","../../rich-text-links.ts","../../selection.ts","../../shared-string-canonical.ts","../../sheet-span.ts","../../sort.ts","../../sparkline-groups.ts","../../string.ts","../../table-names.ts","../../table-styles.ts","../../table-totals.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts","../../formula-locale/formula-locale-data.generated.ts"],"version":"5.8.3"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -25,4 +25,9 @@ export * from "./shared-string-canonical";
|
|
|
25
25
|
export * from "./keyboard";
|
|
26
26
|
export * from "./sheet-span";
|
|
27
27
|
export * from "./formula-locale";
|
|
28
|
+
export * from "./table-names";
|
|
29
|
+
export * from "./table-totals";
|
|
30
|
+
export * from "./sparkline-groups";
|
|
31
|
+
export * from "./rich-text-html";
|
|
32
|
+
export * from "./rich-text-links";
|
|
28
33
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AACtB,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -25,3 +25,8 @@ export * from "./shared-string-canonical";
|
|
|
25
25
|
export * from "./keyboard";
|
|
26
26
|
export * from "./sheet-span";
|
|
27
27
|
export * from "./formula-locale";
|
|
28
|
+
export * from "./table-names";
|
|
29
|
+
export * from "./table-totals";
|
|
30
|
+
export * from "./sparkline-groups";
|
|
31
|
+
export * from "./rich-text-html";
|
|
32
|
+
export * from "./rich-text-links";
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { TextFormat, TextFormatRun } from "@rowsncolumns/common-types";
|
|
2
|
+
/**
|
|
3
|
+
* Clipboard HTML → the engine's native rich-text shape.
|
|
4
|
+
*
|
|
5
|
+
* Google Sheets and Excel both put a cell's mixed formatting into `text/html`
|
|
6
|
+
* — Google as `<span style="…">` / `<a href>` runs inside a `<td>` (wrapped in
|
|
7
|
+
* `<google-sheets-html-origin>`), Excel as `<b>` / `<font color>` /
|
|
8
|
+
* `<font class="fontN">` (class rules in `<head><style>`) / `<span style>` /
|
|
9
|
+
* `<a href>` inside a `<td>`. This module is the ONE converter every paste
|
|
10
|
+
* target uses (the grid's cell paste in `spreadsheet-state/api/parse-html`,
|
|
11
|
+
* the formula bar and the in-cell editor in `ui/editor-pm`), so a rich cell
|
|
12
|
+
* lands identically wherever it is pasted:
|
|
13
|
+
*
|
|
14
|
+
* - `text` — the full text, whitespace normalized like `extractTextContent`
|
|
15
|
+
* (source-newlines collapse to a space, `<br>` / block boundaries become
|
|
16
|
+
* `\n`, outer whitespace trimmed).
|
|
17
|
+
* - `runs` — `TextFormatRun`s RELATIVE to `baseFormat` (only the properties a
|
|
18
|
+
* segment changes), adjacent equal segments merged, empty formats dropped —
|
|
19
|
+
* the same normal form `extractTextFormatRuns` produces from the editor.
|
|
20
|
+
* `undefined` when the text is uniformly formatted (then `baseFormat`
|
|
21
|
+
* already says everything).
|
|
22
|
+
* - `links` — every `<a href>` in document order, as `[start, end)` spans.
|
|
23
|
+
* A link is also carried on its run as `format.link` (Google Sheets keeps
|
|
24
|
+
* several links per cell), and the engines promote the first run link to the
|
|
25
|
+
* cell-level `hyperlink` on commit (Excel keeps one link per cell).
|
|
26
|
+
* - `hyperlink` — the cell-level link: an anchor wrapping the whole text
|
|
27
|
+
* (Excel), else the first link.
|
|
28
|
+
* - `baseFormat` — the container's own formatting (the `<td>` class / inline
|
|
29
|
+
* style), i.e. the CELL-level text format of the source cell.
|
|
30
|
+
*
|
|
31
|
+
* Styles are read from the inline `style`, the tag semantics and
|
|
32
|
+
* `getComputedStyle` (the element must be mounted — see
|
|
33
|
+
* {@link mountClipboardHtml}) so Excel's class-based `<font class="fontN">`
|
|
34
|
+
* runs resolve. `<a>` elements read inline styles only: a browser's UA sheet
|
|
35
|
+
* would otherwise paint every pasted link `-webkit-link` blue.
|
|
36
|
+
*/
|
|
37
|
+
export type RichTextLink = {
|
|
38
|
+
startIndex: number;
|
|
39
|
+
endIndex: number;
|
|
40
|
+
uri: string;
|
|
41
|
+
};
|
|
42
|
+
export type ParsedRichText = {
|
|
43
|
+
text: string;
|
|
44
|
+
runs: TextFormatRun[] | undefined;
|
|
45
|
+
links: RichTextLink[];
|
|
46
|
+
hyperlink: string | undefined;
|
|
47
|
+
baseFormat: TextFormat;
|
|
48
|
+
/** Mixed formatting or at least one link — the reasons to prefer runs over flat text. */
|
|
49
|
+
isRich: boolean;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Parse an HTML clipboard payload into a hidden, mounted sandbox so
|
|
53
|
+
* `getComputedStyle` resolves the payload's own `<style>` rules (Excel's
|
|
54
|
+
* `.fontN` / `.xlNN` classes). Callers must `cleanup()` when done.
|
|
55
|
+
*/
|
|
56
|
+
export declare const mountClipboardHtml: (clipboardValue: string) => {
|
|
57
|
+
root: HTMLDivElement;
|
|
58
|
+
cleanup: () => void;
|
|
59
|
+
};
|
|
60
|
+
export declare const cssColorToHex: (value: string | null | undefined) => string | undefined;
|
|
61
|
+
/** CSS font-size → points. `pt` verbatim, `px` at 96dpi, `em`/`rem` on a 16px base. */
|
|
62
|
+
export declare const cssFontSizeToPt: (value: string | null | undefined) => number | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* Convert a mounted element (a clipboard `<td>`, or the sandbox wrapper for
|
|
65
|
+
* table-less HTML) into the engine's rich-text shape. See the module doc.
|
|
66
|
+
*/
|
|
67
|
+
export declare const htmlElementToRichText: (root: HTMLElement) => ParsedRichText;
|
|
68
|
+
/**
|
|
69
|
+
* The element a single-cell clipboard payload's text lives in: the lone
|
|
70
|
+
* `<td>`/`<th>` of a one-cell table (Excel / Google Sheets), or the mounted
|
|
71
|
+
* wrapper for table-less HTML. `undefined` for a multi-cell table — that is a
|
|
72
|
+
* grid paste, not a rich-text one.
|
|
73
|
+
*/
|
|
74
|
+
export declare const findSingleClipboardCell: (root: HTMLElement) => HTMLElement | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* One-shot helper for the editor targets: mount the clipboard HTML, convert
|
|
77
|
+
* the single cell it carries, clean up. `undefined` when the payload is a
|
|
78
|
+
* multi-cell table or carries no formatting/links worth keeping (the caller
|
|
79
|
+
* then falls back to its plain-text handling).
|
|
80
|
+
*/
|
|
81
|
+
export declare const clipboardHtmlToRichText: (html: string) => ParsedRichText | undefined;
|
|
82
|
+
//# sourceMappingURL=rich-text-html.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rich-text-html.d.ts","sourceRoot":"","sources":["../../rich-text-html.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAK5E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,MAAM,MAAM,YAAY,GAAG;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,aAAa,EAAE,GAAG,SAAS,CAAC;IAClC,KAAK,EAAE,YAAY,EAAE,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,UAAU,CAAC;IACvB,yFAAyF;IACzF,MAAM,EAAE,OAAO,CAAC;CACjB,CAAC;AAgGF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,gBAAgB,MAAM;;;CAmBxD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,OAAO,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,MAAM,GAAG,SAkBX,CAAC;AAEF,uFAAuF;AACvF,eAAO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