@rowsncolumns/spreadsheet-state 29.2.0 → 29.3.2
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/api/border.d.ts +1 -1
- package/dist/cjs/api/border.d.ts.map +1 -1
- package/dist/cjs/commands.d.ts +36 -3
- package/dist/cjs/commands.d.ts.map +1 -1
- package/dist/cjs/components/editors/cell-format/alignment-tab.d.ts +27 -0
- package/dist/cjs/components/editors/cell-format/alignment-tab.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/alignment-tab.js +83 -0
- package/dist/cjs/components/editors/cell-format/border-edges.d.ts +42 -0
- package/dist/cjs/components/editors/cell-format/border-edges.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/border-edges.js +118 -0
- package/dist/cjs/components/editors/cell-format/border-tab.d.ts +21 -0
- package/dist/cjs/components/editors/cell-format/border-tab.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/border-tab.js +123 -0
- package/dist/cjs/components/editors/cell-format/fill-tab.d.ts +14 -0
- package/dist/cjs/components/editors/cell-format/fill-tab.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/fill-tab.js +54 -0
- package/dist/cjs/components/editors/cell-format/font-tab.d.ts +18 -0
- package/dist/cjs/components/editors/cell-format/font-tab.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/font-tab.js +99 -0
- package/dist/cjs/components/editors/cell-format/list-box.d.ts +35 -0
- package/dist/cjs/components/editors/cell-format/list-box.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/list-box.js +37 -0
- package/dist/cjs/components/editors/cell-format/number-formats.d.ts +90 -0
- package/dist/cjs/components/editors/cell-format/number-formats.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/number-formats.js +403 -0
- package/dist/cjs/components/editors/cell-format/number-tab.d.ts +12 -0
- package/dist/cjs/components/editors/cell-format/number-tab.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/number-tab.js +194 -0
- package/dist/cjs/components/editors/cell-format/protection-tab.d.ts +13 -0
- package/dist/cjs/components/editors/cell-format/protection-tab.d.ts.map +1 -0
- package/dist/cjs/components/editors/cell-format/protection-tab.js +13 -0
- package/dist/cjs/components/editors/cell-format-editor.d.ts +31 -3
- package/dist/cjs/components/editors/cell-format-editor.d.ts.map +1 -1
- package/dist/cjs/components/editors/cell-format-editor.js +182 -636
- package/dist/cjs/components/editors/conditional-format-data-bar-options.d.ts +16 -0
- package/dist/cjs/components/editors/conditional-format-data-bar-options.d.ts.map +1 -0
- package/dist/cjs/components/editors/conditional-format-data-bar-options.js +166 -0
- package/dist/cjs/components/editors/conditional-format-editor.d.ts +7 -1
- package/dist/cjs/components/editors/conditional-format-editor.d.ts.map +1 -1
- package/dist/cjs/components/editors/conditional-format-editor.js +51 -9
- package/dist/cjs/components/editors/conditional-format-icon-set-options.d.ts +17 -0
- package/dist/cjs/components/editors/conditional-format-icon-set-options.d.ts.map +1 -0
- package/dist/cjs/components/editors/conditional-format-icon-set-options.js +163 -0
- package/dist/cjs/components/editors/conditional-format-rule-editor.d.ts +9 -0
- package/dist/cjs/components/editors/conditional-format-rule-editor.d.ts.map +1 -1
- package/dist/cjs/components/editors/conditional-format-rule-editor.js +97 -125
- package/dist/cjs/components/editors/sheet-filter.d.ts +20 -9
- package/dist/cjs/components/editors/sheet-filter.d.ts.map +1 -1
- package/dist/cjs/components/editors/sheet-filter.js +44 -12
- package/dist/cjs/hooks/use-conditional-formatting-rules.d.ts +2 -0
- package/dist/cjs/hooks/use-conditional-formatting-rules.d.ts.map +1 -1
- package/dist/cjs/hooks/use-conditional-formatting-rules.js +22 -1
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts +2 -0
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/cjs/hooks/use-spreadsheet-state.js +4 -2
- package/dist/cjs/interface/change-border.d.ts.map +1 -1
- package/dist/cjs/interface/change-border.js +8 -1
- package/dist/cjs/interface/conditional-formatting-rules.d.ts +11 -1
- package/dist/cjs/interface/conditional-formatting-rules.d.ts.map +1 -1
- package/dist/cjs/interface/conditional-formatting-rules.js +44 -1
- package/dist/cjs/sheet-cell.d.ts +8 -0
- package/dist/cjs/sheet-cell.d.ts.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/api/border.d.ts +1 -1
- package/dist/esm/api/border.d.ts.map +1 -1
- package/dist/esm/commands.d.ts +36 -3
- package/dist/esm/commands.d.ts.map +1 -1
- package/dist/esm/components/editors/cell-format/alignment-tab.d.ts +27 -0
- package/dist/esm/components/editors/cell-format/alignment-tab.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/alignment-tab.js +81 -0
- package/dist/esm/components/editors/cell-format/border-edges.d.ts +42 -0
- package/dist/esm/components/editors/cell-format/border-edges.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/border-edges.js +79 -0
- package/dist/esm/components/editors/cell-format/border-tab.d.ts +21 -0
- package/dist/esm/components/editors/cell-format/border-tab.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/border-tab.js +103 -0
- package/dist/esm/components/editors/cell-format/fill-tab.d.ts +14 -0
- package/dist/esm/components/editors/cell-format/fill-tab.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/fill-tab.js +49 -0
- package/dist/esm/components/editors/cell-format/font-tab.d.ts +18 -0
- package/dist/esm/components/editors/cell-format/font-tab.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/font-tab.js +88 -0
- package/dist/esm/components/editors/cell-format/list-box.d.ts +35 -0
- package/dist/esm/components/editors/cell-format/list-box.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/list-box.js +30 -0
- package/dist/esm/components/editors/cell-format/number-formats.d.ts +90 -0
- package/dist/esm/components/editors/cell-format/number-formats.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/number-formats.js +383 -0
- package/dist/esm/components/editors/cell-format/number-tab.d.ts +12 -0
- package/dist/esm/components/editors/cell-format/number-tab.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/number-tab.js +165 -0
- package/dist/esm/components/editors/cell-format/protection-tab.d.ts +13 -0
- package/dist/esm/components/editors/cell-format/protection-tab.d.ts.map +1 -0
- package/dist/esm/components/editors/cell-format/protection-tab.js +9 -0
- package/dist/esm/components/editors/cell-format-editor.d.ts +31 -3
- package/dist/esm/components/editors/cell-format-editor.d.ts.map +1 -1
- package/dist/esm/components/editors/cell-format-editor.js +148 -615
- package/dist/esm/components/editors/conditional-format-data-bar-options.d.ts +16 -0
- package/dist/esm/components/editors/conditional-format-data-bar-options.d.ts.map +1 -0
- package/dist/esm/components/editors/conditional-format-data-bar-options.js +145 -0
- package/dist/esm/components/editors/conditional-format-editor.d.ts +7 -1
- package/dist/esm/components/editors/conditional-format-editor.d.ts.map +1 -1
- package/dist/esm/components/editors/conditional-format-editor.js +39 -8
- package/dist/esm/components/editors/conditional-format-icon-set-options.d.ts +17 -0
- package/dist/esm/components/editors/conditional-format-icon-set-options.d.ts.map +1 -0
- package/dist/esm/components/editors/conditional-format-icon-set-options.js +139 -0
- package/dist/esm/components/editors/conditional-format-rule-editor.d.ts +9 -0
- package/dist/esm/components/editors/conditional-format-rule-editor.d.ts.map +1 -1
- package/dist/esm/components/editors/conditional-format-rule-editor.js +60 -85
- package/dist/esm/components/editors/sheet-filter.d.ts +20 -9
- package/dist/esm/components/editors/sheet-filter.d.ts.map +1 -1
- package/dist/esm/components/editors/sheet-filter.js +31 -11
- package/dist/esm/hooks/use-conditional-formatting-rules.d.ts +2 -0
- package/dist/esm/hooks/use-conditional-formatting-rules.d.ts.map +1 -1
- package/dist/esm/hooks/use-conditional-formatting-rules.js +19 -1
- package/dist/esm/hooks/use-spreadsheet-state.d.ts +2 -0
- package/dist/esm/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/esm/hooks/use-spreadsheet-state.js +4 -2
- package/dist/esm/interface/change-border.d.ts.map +1 -1
- package/dist/esm/interface/change-border.js +8 -1
- package/dist/esm/interface/conditional-formatting-rules.d.ts +11 -1
- package/dist/esm/interface/conditional-formatting-rules.d.ts.map +1 -1
- package/dist/esm/interface/conditional-formatting-rules.js +29 -1
- package/dist/esm/sheet-cell.d.ts +8 -0
- package/dist/esm/sheet-cell.d.ts.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
/** Excel's category list, in Excel's order. */
|
|
2
|
+
export var NUMBER_CATEGORIES = [
|
|
3
|
+
{
|
|
4
|
+
id: "general",
|
|
5
|
+
name: "General",
|
|
6
|
+
type: "GENERAL",
|
|
7
|
+
description: "General format cells have no specific number format.",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
id: "number",
|
|
11
|
+
name: "Number",
|
|
12
|
+
type: "NUMBER",
|
|
13
|
+
description: "Number is used for general display of numbers. Currency and Accounting offer specialized formatting for monetary value.",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
id: "currency",
|
|
17
|
+
name: "Currency",
|
|
18
|
+
type: "CURRENCY",
|
|
19
|
+
description: "Currency formats are used for general monetary values. Use Accounting formats to align decimal points in a column.",
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
id: "accounting",
|
|
23
|
+
name: "Accounting",
|
|
24
|
+
type: "ACCOUNTING",
|
|
25
|
+
description: "Accounting formats line up the currency symbols and decimal points in a column.",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
id: "date",
|
|
29
|
+
name: "Date",
|
|
30
|
+
type: "DATE",
|
|
31
|
+
description: "Date formats display date and time serial numbers as date values.",
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
id: "time",
|
|
35
|
+
name: "Time",
|
|
36
|
+
type: "DATE_TIME",
|
|
37
|
+
description: "Time formats display date and time serial numbers as time values.",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: "percentage",
|
|
41
|
+
name: "Percentage",
|
|
42
|
+
type: "PERCENT",
|
|
43
|
+
description: "Percentage formats multiply the cell value by 100 and display the result with a percent symbol.",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "fraction",
|
|
47
|
+
name: "Fraction",
|
|
48
|
+
type: "FRACTION",
|
|
49
|
+
description: "Fraction formats display a number as a fraction.",
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "scientific",
|
|
53
|
+
name: "Scientific",
|
|
54
|
+
type: "SCIENTIFIC",
|
|
55
|
+
description: "Scientific formats display a number in exponential notation.",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "text",
|
|
59
|
+
name: "Text",
|
|
60
|
+
type: "TEXT",
|
|
61
|
+
description: "Text format cells are treated as text even when a number is in the cell. The cell is displayed exactly as entered.",
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "special",
|
|
65
|
+
name: "Special",
|
|
66
|
+
type: "SPECIAL",
|
|
67
|
+
description: "Special formats are useful for tracking list and database values.",
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
id: "custom",
|
|
71
|
+
name: "Custom",
|
|
72
|
+
type: "NUMBER",
|
|
73
|
+
description: "Type the number format code, using one of the existing codes as a starting point.",
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
export var NEGATIVE_STYLES = [
|
|
77
|
+
"minus",
|
|
78
|
+
"red",
|
|
79
|
+
"parens",
|
|
80
|
+
"redParens",
|
|
81
|
+
];
|
|
82
|
+
var digits = function (decimals, thousands) {
|
|
83
|
+
var d = Math.max(0, Math.min(30, Math.floor(decimals)));
|
|
84
|
+
var base = thousands ? "#,##0" : "0";
|
|
85
|
+
return d > 0 ? "".concat(base, ".").concat("0".repeat(d)) : base;
|
|
86
|
+
};
|
|
87
|
+
/** `prefix` wraps a currency symbol in quotes so it never reads as a code. */
|
|
88
|
+
var symbolPrefix = function (symbol) {
|
|
89
|
+
return symbol ? "\"".concat(symbol.replace(/"/g, ""), "\"") : "";
|
|
90
|
+
};
|
|
91
|
+
var withNegative = function (positive, style) {
|
|
92
|
+
switch (style) {
|
|
93
|
+
case "red":
|
|
94
|
+
return "".concat(positive, ";[Red]").concat(positive);
|
|
95
|
+
case "parens":
|
|
96
|
+
return "".concat(positive, "_);(").concat(positive, ")");
|
|
97
|
+
case "redParens":
|
|
98
|
+
return "".concat(positive, "_);[Red](").concat(positive, ")");
|
|
99
|
+
default:
|
|
100
|
+
return positive;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
/** Number: decimal places, 1000 separator, negative numbers. */
|
|
104
|
+
export var buildNumberPattern = function (_a) {
|
|
105
|
+
var decimals = _a.decimals, thousands = _a.thousands, negative = _a.negative;
|
|
106
|
+
return withNegative(digits(decimals, thousands), negative);
|
|
107
|
+
};
|
|
108
|
+
/** Currency: decimal places, symbol, negative numbers. */
|
|
109
|
+
export var buildCurrencyPattern = function (_a) {
|
|
110
|
+
var decimals = _a.decimals, symbol = _a.symbol, negative = _a.negative;
|
|
111
|
+
return withNegative("".concat(symbolPrefix(symbol)).concat(digits(decimals, true)), negative);
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Accounting: decimal places and symbol. The symbol sits at the left edge
|
|
115
|
+
* (`* ` repeats the space to fill the cell), zero shows a dash, and the `_(`
|
|
116
|
+
* / `_)` paddings line the decimal points up across positive and negative.
|
|
117
|
+
*/
|
|
118
|
+
export var buildAccountingPattern = function (_a) {
|
|
119
|
+
var decimals = _a.decimals, symbol = _a.symbol;
|
|
120
|
+
var d = Math.max(0, Math.min(30, Math.floor(decimals)));
|
|
121
|
+
var num = digits(d, true);
|
|
122
|
+
var sym = symbolPrefix(symbol);
|
|
123
|
+
var zero = d > 0 ? "\"-\"".concat("?".repeat(d)) : "\"-\"";
|
|
124
|
+
return "_(".concat(sym, "* ").concat(num, "_);_(").concat(sym, "* \\(").concat(num, "\\);_(").concat(sym, "* ").concat(zero, "_);_(@_)");
|
|
125
|
+
};
|
|
126
|
+
export var buildPercentPattern = function (decimals) {
|
|
127
|
+
return "".concat(digits(decimals, false), "%");
|
|
128
|
+
};
|
|
129
|
+
export var buildScientificPattern = function (decimals) {
|
|
130
|
+
return "".concat(digits(decimals, false), "E+00");
|
|
131
|
+
};
|
|
132
|
+
/** Excel's Currency / Accounting symbol list (a representative subset). */
|
|
133
|
+
export var CURRENCY_SYMBOLS = [
|
|
134
|
+
{ symbol: "", label: "None" },
|
|
135
|
+
{ symbol: "$", label: "$" },
|
|
136
|
+
{ symbol: "€", label: "€ Euro" },
|
|
137
|
+
{ symbol: "£", label: "£ English (United Kingdom)" },
|
|
138
|
+
{ symbol: "¥", label: "¥ Japanese" },
|
|
139
|
+
{ symbol: "₹", label: "₹ English (India)" },
|
|
140
|
+
{ symbol: "CHF", label: "CHF Swiss" },
|
|
141
|
+
{ symbol: "kr", label: "kr Swedish" },
|
|
142
|
+
{ symbol: "R$", label: "R$ Portuguese (Brazil)" },
|
|
143
|
+
{ symbol: "₩", label: "₩ Korean" },
|
|
144
|
+
];
|
|
145
|
+
export var FRACTION_TYPES = [
|
|
146
|
+
{ label: "Up to one digit (1/4)", pattern: "# ?/?" },
|
|
147
|
+
{ label: "Up to two digits (21/25)", pattern: "# ??/??" },
|
|
148
|
+
{ label: "Up to three digits (312/943)", pattern: "# ???/???" },
|
|
149
|
+
{ label: "As halves (1/2)", pattern: "# ?/2" },
|
|
150
|
+
{ label: "As quarters (2/4)", pattern: "# ?/4" },
|
|
151
|
+
{ label: "As eighths (4/8)", pattern: "# ?/8" },
|
|
152
|
+
{ label: "As sixteenths (8/16)", pattern: "# ??/16" },
|
|
153
|
+
{ label: "As tenths (3/10)", pattern: "# ?/10" },
|
|
154
|
+
{ label: "As hundredths (30/100)", pattern: "# ??/100" },
|
|
155
|
+
];
|
|
156
|
+
/** Excel's Special types for English (United States). */
|
|
157
|
+
export var SPECIAL_TYPES = [
|
|
158
|
+
{ label: "Zip Code", pattern: "00000" },
|
|
159
|
+
{ label: "Zip Code + 4", pattern: "00000-0000" },
|
|
160
|
+
{ label: "Phone Number", pattern: "[<=9999999]###-####;(###) ###-####" },
|
|
161
|
+
{ label: "Social Security Number", pattern: "000-00-0000" },
|
|
162
|
+
];
|
|
163
|
+
export var FORMAT_LOCALES = [
|
|
164
|
+
{ tag: "en-US", label: "English (United States)", lcid: "409", dayFirst: false },
|
|
165
|
+
{ tag: "en-GB", label: "English (United Kingdom)", lcid: "809", dayFirst: true },
|
|
166
|
+
{ tag: "en-IN", label: "English (India)", lcid: "4009", dayFirst: true },
|
|
167
|
+
{ tag: "en-AU", label: "English (Australia)", lcid: "C09", dayFirst: true },
|
|
168
|
+
{ tag: "en-CA", label: "English (Canada)", lcid: "1009", dayFirst: true },
|
|
169
|
+
{ tag: "fr-FR", label: "French (France)", lcid: "40C", dayFirst: true },
|
|
170
|
+
{ tag: "de-DE", label: "German (Germany)", lcid: "407", dayFirst: true },
|
|
171
|
+
{ tag: "es-ES", label: "Spanish (Spain)", lcid: "C0A", dayFirst: true },
|
|
172
|
+
{ tag: "it-IT", label: "Italian (Italy)", lcid: "410", dayFirst: true },
|
|
173
|
+
{ tag: "ja-JP", label: "Japanese", lcid: "411", dayFirst: false },
|
|
174
|
+
{ tag: "zh-CN", label: "Chinese (PRC)", lcid: "804", dayFirst: false },
|
|
175
|
+
];
|
|
176
|
+
export var findFormatLocale = function (tag) {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
return (_b = (_a = FORMAT_LOCALES.find(function (l) { return l.tag === tag; })) !== null && _a !== void 0 ? _a : FORMAT_LOCALES.find(function (l) { return tag && l.tag.split("-")[0] === tag.split("-")[0]; })) !== null && _b !== void 0 ? _b : FORMAT_LOCALES[0];
|
|
179
|
+
};
|
|
180
|
+
/** Excel's Date types for English (United States). */
|
|
181
|
+
var DATE_TYPES_US = [
|
|
182
|
+
"m/d/yyyy",
|
|
183
|
+
"dddd, mmmm d, yyyy",
|
|
184
|
+
"m/d;@",
|
|
185
|
+
"m/d/yy;@",
|
|
186
|
+
"mm/dd/yy;@",
|
|
187
|
+
"d-mmm;@",
|
|
188
|
+
"d-mmm-yy;@",
|
|
189
|
+
"dd-mmm-yy;@",
|
|
190
|
+
"mmm-yy;@",
|
|
191
|
+
"mmmm-yy;@",
|
|
192
|
+
"mmmm d, yyyy;@",
|
|
193
|
+
"m/d/yy h:mm AM/PM;@",
|
|
194
|
+
"m/d/yy h:mm;@",
|
|
195
|
+
"mmmmm;@",
|
|
196
|
+
"mmmmm-yy;@",
|
|
197
|
+
"m/d/yyyy;@",
|
|
198
|
+
"d-mmm-yyyy;@",
|
|
199
|
+
];
|
|
200
|
+
/** Excel's Time types for English (United States). */
|
|
201
|
+
var TIME_TYPES_US = [
|
|
202
|
+
"h:mm:ss AM/PM",
|
|
203
|
+
"h:mm;@",
|
|
204
|
+
"h:mm AM/PM;@",
|
|
205
|
+
"h:mm:ss;@",
|
|
206
|
+
"h:mm:ss AM/PM;@",
|
|
207
|
+
"mm:ss.0;@",
|
|
208
|
+
"[h]:mm:ss;@",
|
|
209
|
+
"m/d/yy h:mm AM/PM;@",
|
|
210
|
+
"m/d/yy h:mm;@",
|
|
211
|
+
];
|
|
212
|
+
/** A month-first numeric date code reordered day-first (`m/d/yy` → `d/m/yy`). */
|
|
213
|
+
var dayFirst = function (pattern) {
|
|
214
|
+
return pattern.replace(/\b(m{1,2})\/(d{1,2})\b/g, "$2/$1");
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* The Date / Time types for a locale. The default locale's codes are written
|
|
218
|
+
* bare (they follow the workbook); another locale's carry Excel's
|
|
219
|
+
* `[$-lcid]` prefix so the cell keeps that locale's names and order.
|
|
220
|
+
*/
|
|
221
|
+
export var getDateTimeTypes = function (kind, locale, defaultLocale) {
|
|
222
|
+
var base = kind === "date" ? DATE_TYPES_US : TIME_TYPES_US;
|
|
223
|
+
var ordered = locale.dayFirst ? base.map(dayFirst) : base;
|
|
224
|
+
if (locale.tag === defaultLocale.tag)
|
|
225
|
+
return ordered;
|
|
226
|
+
return ordered.map(function (p) { return "[$-".concat(locale.lcid, "]").concat(p); });
|
|
227
|
+
};
|
|
228
|
+
var LOCALE_PREFIX = /^\[\$-([0-9A-Fa-f]+)\]/;
|
|
229
|
+
/** The locale a format code's `[$-lcid]` prefix names, if any. */
|
|
230
|
+
export var getPatternLocale = function (pattern) {
|
|
231
|
+
var _a, _b;
|
|
232
|
+
var lcid = (_b = (_a = pattern === null || pattern === void 0 ? void 0 : pattern.match(LOCALE_PREFIX)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.toUpperCase();
|
|
233
|
+
return lcid
|
|
234
|
+
? FORMAT_LOCALES.find(function (l) { return l.lcid.toUpperCase() === lcid; })
|
|
235
|
+
: undefined;
|
|
236
|
+
};
|
|
237
|
+
/** The pieces the Number / Currency options read back off a code. */
|
|
238
|
+
export var parseNumericPattern = function (pattern) {
|
|
239
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
240
|
+
var p = pattern !== null && pattern !== void 0 ? pattern : "";
|
|
241
|
+
var first = (_a = p.split(";")[0]) !== null && _a !== void 0 ? _a : "";
|
|
242
|
+
var decimals = (_d = (_c = (_b = first.match(/\.(0+)/)) === null || _b === void 0 ? void 0 : _b[1]) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0;
|
|
243
|
+
var thousands = /#,##0/.test(first);
|
|
244
|
+
var sections = p.split(";");
|
|
245
|
+
var second = (_e = sections[1]) !== null && _e !== void 0 ? _e : "";
|
|
246
|
+
var negative = !second
|
|
247
|
+
? "minus"
|
|
248
|
+
: second.includes("[Red]")
|
|
249
|
+
? second.includes("(")
|
|
250
|
+
? "redParens"
|
|
251
|
+
: "red"
|
|
252
|
+
: second.includes("(")
|
|
253
|
+
? "parens"
|
|
254
|
+
: "minus";
|
|
255
|
+
var symbol = (_g = (_f = first.match(/"([^"]+)"/)) === null || _f === void 0 ? void 0 : _f[1]) !== null && _g !== void 0 ? _g : "";
|
|
256
|
+
return { decimals: decimals, thousands: thousands, negative: negative, symbol: symbol };
|
|
257
|
+
};
|
|
258
|
+
/** Which category a cell's number format opens the Number tab on. */
|
|
259
|
+
export var detectCategory = function (format) {
|
|
260
|
+
var _a;
|
|
261
|
+
var pattern = (_a = format === null || format === void 0 ? void 0 : format.pattern) !== null && _a !== void 0 ? _a : "";
|
|
262
|
+
if (SPECIAL_TYPES.some(function (t) { return t.pattern === pattern; }))
|
|
263
|
+
return "special";
|
|
264
|
+
switch (format === null || format === void 0 ? void 0 : format.type) {
|
|
265
|
+
case undefined:
|
|
266
|
+
case "GENERAL":
|
|
267
|
+
return pattern && pattern !== "General" ? "custom" : "general";
|
|
268
|
+
case "NUMBER":
|
|
269
|
+
return "number";
|
|
270
|
+
case "CURRENCY":
|
|
271
|
+
return pattern.startsWith("_(") ? "accounting" : "currency";
|
|
272
|
+
case "ACCOUNTING":
|
|
273
|
+
return "accounting";
|
|
274
|
+
case "DATE":
|
|
275
|
+
return "date";
|
|
276
|
+
case "TIME":
|
|
277
|
+
case "DATE_TIME":
|
|
278
|
+
return "time";
|
|
279
|
+
case "PERCENT":
|
|
280
|
+
return "percentage";
|
|
281
|
+
case "FRACTION":
|
|
282
|
+
return "fraction";
|
|
283
|
+
case "SCIENTIFIC":
|
|
284
|
+
return "scientific";
|
|
285
|
+
case "TEXT":
|
|
286
|
+
return "text";
|
|
287
|
+
case "SPECIAL":
|
|
288
|
+
return "special";
|
|
289
|
+
default:
|
|
290
|
+
return "custom";
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
/** The format a category gets when it is first picked (Excel's defaults). */
|
|
294
|
+
export var defaultFormatForCategory = function (id, _a) {
|
|
295
|
+
var currencySymbol = _a.currencySymbol, locale = _a.locale, defaultLocale = _a.defaultLocale;
|
|
296
|
+
switch (id) {
|
|
297
|
+
case "general":
|
|
298
|
+
return null;
|
|
299
|
+
case "number":
|
|
300
|
+
return {
|
|
301
|
+
type: "NUMBER",
|
|
302
|
+
pattern: buildNumberPattern({
|
|
303
|
+
decimals: 2,
|
|
304
|
+
thousands: false,
|
|
305
|
+
negative: "minus",
|
|
306
|
+
}),
|
|
307
|
+
};
|
|
308
|
+
case "currency":
|
|
309
|
+
return {
|
|
310
|
+
type: "CURRENCY",
|
|
311
|
+
pattern: buildCurrencyPattern({
|
|
312
|
+
decimals: 2,
|
|
313
|
+
symbol: currencySymbol,
|
|
314
|
+
negative: "minus",
|
|
315
|
+
}),
|
|
316
|
+
};
|
|
317
|
+
case "accounting":
|
|
318
|
+
return {
|
|
319
|
+
type: "ACCOUNTING",
|
|
320
|
+
pattern: buildAccountingPattern({ decimals: 2, symbol: currencySymbol }),
|
|
321
|
+
};
|
|
322
|
+
case "date":
|
|
323
|
+
return {
|
|
324
|
+
type: "DATE",
|
|
325
|
+
pattern: getDateTimeTypes("date", locale, defaultLocale)[0],
|
|
326
|
+
};
|
|
327
|
+
case "time":
|
|
328
|
+
return {
|
|
329
|
+
type: "DATE_TIME",
|
|
330
|
+
pattern: getDateTimeTypes("time", locale, defaultLocale)[0],
|
|
331
|
+
};
|
|
332
|
+
case "percentage":
|
|
333
|
+
return { type: "PERCENT", pattern: buildPercentPattern(2) };
|
|
334
|
+
case "fraction":
|
|
335
|
+
return { type: "FRACTION", pattern: FRACTION_TYPES[0].pattern };
|
|
336
|
+
case "scientific":
|
|
337
|
+
return { type: "SCIENTIFIC", pattern: buildScientificPattern(2) };
|
|
338
|
+
case "text":
|
|
339
|
+
return { type: "TEXT", pattern: "@" };
|
|
340
|
+
case "special":
|
|
341
|
+
return { type: "SPECIAL", pattern: SPECIAL_TYPES[0].pattern };
|
|
342
|
+
case "custom":
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
/** Excel's Custom type list (the built-in codes). */
|
|
347
|
+
export var CUSTOM_PATTERNS = [
|
|
348
|
+
"General",
|
|
349
|
+
"0",
|
|
350
|
+
"0.00",
|
|
351
|
+
"#,##0",
|
|
352
|
+
"#,##0.00",
|
|
353
|
+
"#,##0_);(#,##0)",
|
|
354
|
+
"#,##0_);[Red](#,##0)",
|
|
355
|
+
"#,##0.00_);(#,##0.00)",
|
|
356
|
+
"#,##0.00_);[Red](#,##0.00)",
|
|
357
|
+
'"$"#,##0_);("$"#,##0)',
|
|
358
|
+
'"$"#,##0_);[Red]("$"#,##0)',
|
|
359
|
+
'"$"#,##0.00_);("$"#,##0.00)',
|
|
360
|
+
'"$"#,##0.00_);[Red]("$"#,##0.00)',
|
|
361
|
+
"0%",
|
|
362
|
+
"0.00%",
|
|
363
|
+
"0.00E+00",
|
|
364
|
+
"##0.0E+0",
|
|
365
|
+
"# ?/?",
|
|
366
|
+
"# ??/??",
|
|
367
|
+
"m/d/yyyy",
|
|
368
|
+
"d-mmm-yy",
|
|
369
|
+
"d-mmm",
|
|
370
|
+
"mmm-yy",
|
|
371
|
+
"h:mm AM/PM",
|
|
372
|
+
"h:mm:ss AM/PM",
|
|
373
|
+
"h:mm",
|
|
374
|
+
"h:mm:ss",
|
|
375
|
+
"m/d/yyyy h:mm",
|
|
376
|
+
"mm:ss",
|
|
377
|
+
"mm:ss.0",
|
|
378
|
+
"@",
|
|
379
|
+
"[h]:mm:ss",
|
|
380
|
+
'_("$"* #,##0_);_("$"* \\(#,##0\\);_("$"* "-"_);_(@_)',
|
|
381
|
+
'_(* #,##0_);_(* \\(#,##0\\);_(* "-"_);_(@_)',
|
|
382
|
+
'_("$"* #,##0.00_);_("$"* \\(#,##0.00\\);_("$"* "-"??_);_(@_)',
|
|
383
|
+
'_(* #,##0.00_);_(* \\(#,##0.00\\);_(* "-"??_);_(@_)',
|
|
384
|
+
];
|
|
385
|
+
/** The NumberFormatType a typed custom code is closest to. */
|
|
386
|
+
export var inferTypeFromPattern = function (pattern) {
|
|
387
|
+
var p = pattern.replace(/"[^"]*"/g, "").replace(/\[[^\]]*\]/g, "");
|
|
388
|
+
if (!pattern || pattern === "General")
|
|
389
|
+
return "GENERAL";
|
|
390
|
+
if (p === "@")
|
|
391
|
+
return "TEXT";
|
|
392
|
+
if (/[yd]/i.test(p) || /m{3,}/i.test(p))
|
|
393
|
+
return "DATE";
|
|
394
|
+
if (/[hs]/i.test(p) || /AM\/PM/i.test(p))
|
|
395
|
+
return "DATE_TIME";
|
|
396
|
+
if (/E[+-]/i.test(p))
|
|
397
|
+
return "SCIENTIFIC";
|
|
398
|
+
if (p.includes("%"))
|
|
399
|
+
return "PERCENT";
|
|
400
|
+
if (/\?\/[?\d]/.test(p))
|
|
401
|
+
return "FRACTION";
|
|
402
|
+
return "NUMBER";
|
|
403
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NumberFormat } from "@rowsncolumns/spreadsheet";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export type NumberTabProps = {
|
|
4
|
+
numberFormat: NumberFormat | null | undefined;
|
|
5
|
+
onChange(numberFormat: NumberFormat | null): void;
|
|
6
|
+
sampleValue: unknown;
|
|
7
|
+
locale?: string;
|
|
8
|
+
currencySymbol: string;
|
|
9
|
+
};
|
|
10
|
+
/** Format Cells → Number. */
|
|
11
|
+
export declare const NumberTab: ({ numberFormat, onChange, sampleValue, locale, currencySymbol, }: NumberTabProps) => React.JSX.Element;
|
|
12
|
+
//# sourceMappingURL=number-tab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-tab.d.ts","sourceRoot":"","sources":["../../../../../components/editors/cell-format/number-tab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,KAA4B,MAAM,OAAO,CAAC;AA6CjD,MAAM,MAAM,cAAc,GAAG;IAC3B,YAAY,EAAE,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC;IAC9C,QAAQ,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,GAAG,IAAI,CAAC;IAClD,WAAW,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,6BAA6B;AAC7B,eAAO,MAAM,SAAS,GAAI,kEAMvB,cAAc,sBAiThB,CAAC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { __assign, __read } from "tslib";
|
|
2
|
+
import { Input } from "@rowsncolumns/ui";
|
|
3
|
+
import { ssfFormat, ssfFormatColor } from "@rowsncolumns/utils";
|
|
4
|
+
import React, { useMemo, useState } from "react";
|
|
5
|
+
import { CheckboxField, ListBox, SelectField } from "./list-box";
|
|
6
|
+
import { buildAccountingPattern, buildCurrencyPattern, buildNumberPattern, buildPercentPattern, buildScientificPattern, CURRENCY_SYMBOLS, CUSTOM_PATTERNS, defaultFormatForCategory, detectCategory, findFormatLocale, FORMAT_LOCALES, FRACTION_TYPES, getDateTimeTypes, getPatternLocale, inferTypeFromPattern, NEGATIVE_STYLES, NUMBER_CATEGORIES, parseNumericPattern, SPECIAL_TYPES, } from "./number-formats";
|
|
7
|
+
var SAMPLE_NEGATIVE = -1234.1;
|
|
8
|
+
var render = function (pattern, value) {
|
|
9
|
+
try {
|
|
10
|
+
return ssfFormat(pattern, value) || " ";
|
|
11
|
+
}
|
|
12
|
+
catch (_a) {
|
|
13
|
+
return " ";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var colorOf = function (pattern, value) {
|
|
17
|
+
try {
|
|
18
|
+
return ssfFormatColor(pattern, value);
|
|
19
|
+
}
|
|
20
|
+
catch (_a) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/** Format Cells → Number. */
|
|
25
|
+
export var NumberTab = function (_a) {
|
|
26
|
+
var _b;
|
|
27
|
+
var numberFormat = _a.numberFormat, onChange = _a.onChange, sampleValue = _a.sampleValue, locale = _a.locale, currencySymbol = _a.currencySymbol;
|
|
28
|
+
var defaultLocale = findFormatLocale(locale);
|
|
29
|
+
var _c = __read(useState(function () {
|
|
30
|
+
return detectCategory(numberFormat);
|
|
31
|
+
}), 2), category = _c[0], setCategory = _c[1];
|
|
32
|
+
var _d = __read(useState(function () { var _a; return (_a = getPatternLocale(numberFormat === null || numberFormat === void 0 ? void 0 : numberFormat.pattern)) !== null && _a !== void 0 ? _a : defaultLocale; }), 2), formatLocale = _d[0], setFormatLocale = _d[1];
|
|
33
|
+
var pattern = (_b = numberFormat === null || numberFormat === void 0 ? void 0 : numberFormat.pattern) !== null && _b !== void 0 ? _b : "General";
|
|
34
|
+
var parsed = parseNumericPattern(numberFormat === null || numberFormat === void 0 ? void 0 : numberFormat.pattern);
|
|
35
|
+
var definition = NUMBER_CATEGORIES.find(function (c) { return c.id === category; });
|
|
36
|
+
var sample = render(pattern, sampleValue);
|
|
37
|
+
var pickCategory = function (id) {
|
|
38
|
+
setCategory(id);
|
|
39
|
+
if (id === "custom")
|
|
40
|
+
return;
|
|
41
|
+
onChange(defaultFormatForCategory(id, {
|
|
42
|
+
currencySymbol: currencySymbol,
|
|
43
|
+
locale: formatLocale,
|
|
44
|
+
defaultLocale: defaultLocale,
|
|
45
|
+
}));
|
|
46
|
+
};
|
|
47
|
+
var dateTimeTypes = useMemo(function () {
|
|
48
|
+
return category === "date" || category === "time"
|
|
49
|
+
? getDateTimeTypes(category, formatLocale, defaultLocale)
|
|
50
|
+
: [];
|
|
51
|
+
}, [category, formatLocale, defaultLocale]);
|
|
52
|
+
var decimalsField = function (onDecimals) { return (React.createElement("label", { className: "flex flex-col gap-1 font-system text-sm" },
|
|
53
|
+
"Decimal places",
|
|
54
|
+
React.createElement(Input, { "aria-label": "Decimal places", type: "number", min: 0, max: 30, className: "text-xs", value: parsed.decimals, onChange: function (event) {
|
|
55
|
+
var n = parseInt(event.target.value, 10);
|
|
56
|
+
if (Number.isFinite(n))
|
|
57
|
+
onDecimals(Math.max(0, Math.min(30, n)));
|
|
58
|
+
} }))); };
|
|
59
|
+
var symbolField = function (onSymbol) { return (React.createElement(SelectField, { label: "Symbol", value: parsed.symbol, options: CURRENCY_SYMBOLS.map(function (s) { return ({ value: s.symbol, label: s.label }); }), onChange: onSymbol })); };
|
|
60
|
+
var negativeList = function (build, selected) { return (React.createElement("div", { className: "flex flex-col gap-1" },
|
|
61
|
+
React.createElement("span", { className: "font-system text-sm" }, "Negative numbers"),
|
|
62
|
+
React.createElement(ListBox, { label: "Negative numbers", value: selected, items: NEGATIVE_STYLES.map(function (style) {
|
|
63
|
+
var p = build(style);
|
|
64
|
+
return {
|
|
65
|
+
value: style,
|
|
66
|
+
label: (React.createElement("span", { style: { color: colorOf(p, SAMPLE_NEGATIVE) } }, render(p, SAMPLE_NEGATIVE))),
|
|
67
|
+
};
|
|
68
|
+
}), onChange: function (style) { var _a; return onChange({ type: (_a = numberFormat === null || numberFormat === void 0 ? void 0 : numberFormat.type) !== null && _a !== void 0 ? _a : "NUMBER", pattern: build(style) }); } }))); };
|
|
69
|
+
var localeField = (React.createElement(SelectField, { label: "Locale (location)", value: formatLocale.tag, options: FORMAT_LOCALES.map(function (l) { return ({ value: l.tag, label: l.label }); }), onChange: function (tag) {
|
|
70
|
+
var next = findFormatLocale(tag);
|
|
71
|
+
setFormatLocale(next);
|
|
72
|
+
if (category === "date" || category === "time") {
|
|
73
|
+
onChange({
|
|
74
|
+
type: category === "date" ? "DATE" : "DATE_TIME",
|
|
75
|
+
pattern: getDateTimeTypes(category, next, defaultLocale)[0],
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
} }));
|
|
79
|
+
var options = null;
|
|
80
|
+
switch (category) {
|
|
81
|
+
case "number":
|
|
82
|
+
options = (React.createElement(React.Fragment, null,
|
|
83
|
+
decimalsField(function (decimals) {
|
|
84
|
+
return onChange({
|
|
85
|
+
type: "NUMBER",
|
|
86
|
+
pattern: buildNumberPattern(__assign(__assign({}, parsed), { decimals: decimals })),
|
|
87
|
+
});
|
|
88
|
+
}),
|
|
89
|
+
React.createElement(CheckboxField, { label: "Use 1000 Separator (,)", checked: parsed.thousands, onChange: function (thousands) {
|
|
90
|
+
return onChange({
|
|
91
|
+
type: "NUMBER",
|
|
92
|
+
pattern: buildNumberPattern(__assign(__assign({}, parsed), { thousands: thousands })),
|
|
93
|
+
});
|
|
94
|
+
} }),
|
|
95
|
+
negativeList(function (negative) { return buildNumberPattern(__assign(__assign({}, parsed), { negative: negative })); }, parsed.negative)));
|
|
96
|
+
break;
|
|
97
|
+
case "currency":
|
|
98
|
+
options = (React.createElement(React.Fragment, null,
|
|
99
|
+
decimalsField(function (decimals) {
|
|
100
|
+
return onChange({
|
|
101
|
+
type: "CURRENCY",
|
|
102
|
+
pattern: buildCurrencyPattern(__assign(__assign({}, parsed), { decimals: decimals })),
|
|
103
|
+
});
|
|
104
|
+
}),
|
|
105
|
+
symbolField(function (symbol) {
|
|
106
|
+
return onChange({
|
|
107
|
+
type: "CURRENCY",
|
|
108
|
+
pattern: buildCurrencyPattern(__assign(__assign({}, parsed), { symbol: symbol })),
|
|
109
|
+
});
|
|
110
|
+
}),
|
|
111
|
+
negativeList(function (negative) { return buildCurrencyPattern(__assign(__assign({}, parsed), { negative: negative })); }, parsed.negative)));
|
|
112
|
+
break;
|
|
113
|
+
case "accounting":
|
|
114
|
+
options = (React.createElement(React.Fragment, null,
|
|
115
|
+
decimalsField(function (decimals) {
|
|
116
|
+
return onChange({
|
|
117
|
+
type: "ACCOUNTING",
|
|
118
|
+
pattern: buildAccountingPattern(__assign(__assign({}, parsed), { decimals: decimals })),
|
|
119
|
+
});
|
|
120
|
+
}),
|
|
121
|
+
symbolField(function (symbol) {
|
|
122
|
+
return onChange({
|
|
123
|
+
type: "ACCOUNTING",
|
|
124
|
+
pattern: buildAccountingPattern(__assign(__assign({}, parsed), { symbol: symbol })),
|
|
125
|
+
});
|
|
126
|
+
})));
|
|
127
|
+
break;
|
|
128
|
+
case "percentage":
|
|
129
|
+
options = decimalsField(function (decimals) {
|
|
130
|
+
return onChange({ type: "PERCENT", pattern: buildPercentPattern(decimals) });
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
case "scientific":
|
|
134
|
+
options = decimalsField(function (decimals) {
|
|
135
|
+
return onChange({ type: "SCIENTIFIC", pattern: buildScientificPattern(decimals) });
|
|
136
|
+
});
|
|
137
|
+
break;
|
|
138
|
+
case "date":
|
|
139
|
+
case "time":
|
|
140
|
+
options = (React.createElement(React.Fragment, null,
|
|
141
|
+
React.createElement("div", { className: "flex flex-col gap-1" },
|
|
142
|
+
React.createElement("span", { className: "font-system text-sm" }, "Type"),
|
|
143
|
+
React.createElement(ListBox, { label: "Type", value: pattern, items: dateTimeTypes.map(function (p) { return ({
|
|
144
|
+
value: p,
|
|
145
|
+
label: render(p, sampleDate()),
|
|
146
|
+
}); }), onChange: function (p) {
|
|
147
|
+
return onChange({
|
|
148
|
+
type: category === "date" ? "DATE" : "DATE_TIME",
|
|
149
|
+
pattern: p,
|
|
150
|
+
});
|
|
151
|
+
} })),
|
|
152
|
+
localeField));
|
|
153
|
+
break;
|
|
154
|
+
case "fraction":
|
|
155
|
+
options = (React.createElement("div", { className: "flex flex-col gap-1" },
|
|
156
|
+
React.createElement("span", { className: "font-system text-sm" }, "Type"),
|
|
157
|
+
React.createElement(ListBox, { label: "Type", value: pattern, items: FRACTION_TYPES.map(function (t) { return ({ value: t.pattern, label: t.label }); }), onChange: function (p) { return onChange({ type: "FRACTION", pattern: p }); } })));
|
|
158
|
+
break;
|
|
159
|
+
case "special":
|
|
160
|
+
options = (React.createElement(React.Fragment, null,
|
|
161
|
+
React.createElement("div", { className: "flex flex-col gap-1" },
|
|
162
|
+
React.createElement("span", { className: "font-system text-sm" }, "Type"),
|
|
163
|
+
React.createElement(ListBox, { label: "Type", value: pattern, items: SPECIAL_TYPES.map(function (t) { return ({ value: t.pattern, label: t.label }); }), onChange: function (p) { return onChange({ type: "SPECIAL", pattern: p }); } })),
|
|
164
|
+
React.createElement(SelectField, { label: "Locale (location)", value: "en-US", options: [{ value: "en-US", label: "English (United States)" }], onChange: function () { return undefined; } })));
|
|
165
|
+
break;
|
|
166
|
+
case "custom":
|
|
167
|
+
options = (React.createElement("div", { className: "flex flex-col gap-1" },
|
|
168
|
+
React.createElement("label", { className: "flex flex-col gap-1 font-system text-sm" },
|
|
169
|
+
"Type",
|
|
170
|
+
React.createElement(Input, { "aria-label": "Custom format code", type: "text", className: "text-xs", value: pattern, onChange: function (event) {
|
|
171
|
+
return onChange({
|
|
172
|
+
type: inferTypeFromPattern(event.target.value),
|
|
173
|
+
pattern: event.target.value,
|
|
174
|
+
});
|
|
175
|
+
} })),
|
|
176
|
+
React.createElement(ListBox, { label: "Custom formats", value: pattern, items: CUSTOM_PATTERNS.map(function (p) { return ({ value: p, label: p }); }), onChange: function (p) {
|
|
177
|
+
return onChange(p === "General" ? null : { type: inferTypeFromPattern(p), pattern: p });
|
|
178
|
+
} })));
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
return (React.createElement("div", { className: "grid grid-cols-[140px_1fr] gap-3" },
|
|
182
|
+
React.createElement("div", { className: "flex flex-col gap-1" },
|
|
183
|
+
React.createElement("span", { className: "font-system text-sm" }, "Category"),
|
|
184
|
+
React.createElement(ListBox, { label: "Category", value: category, items: NUMBER_CATEGORIES.map(function (c) { return ({ value: c.id, label: c.name }); }), onChange: pickCategory, className: "max-h-[260px]" })),
|
|
185
|
+
React.createElement("div", { className: "flex flex-col gap-2" },
|
|
186
|
+
React.createElement("div", { className: "flex flex-col gap-1" },
|
|
187
|
+
React.createElement("span", { className: "font-system text-sm" }, "Sample"),
|
|
188
|
+
React.createElement("div", { "data-testid": "number-sample", className: "rounded-sm bg-rnc-muted p-1 px-2 text-rnc-foreground", style: { color: colorOf(pattern, sampleValue) } }, sample)),
|
|
189
|
+
options,
|
|
190
|
+
React.createElement("p", { className: "font-system text-xs text-rnc-muted-foreground" }, definition === null || definition === void 0 ? void 0 : definition.description))));
|
|
191
|
+
};
|
|
192
|
+
// Excel previews date and time types on the active cell's value when it is a
|
|
193
|
+
// date; a fixed date keeps the list stable otherwise.
|
|
194
|
+
var sampleDate = function () { return new Date(2012, 2, 14, 13, 30, 55); };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export type CellProtectionDraft = {
|
|
3
|
+
locked: boolean;
|
|
4
|
+
hidden: boolean;
|
|
5
|
+
};
|
|
6
|
+
/** Excel's note under the Protection tab's checkboxes. */
|
|
7
|
+
export declare const PROTECTION_NOTE = "Locking cells or hiding formulas has no effect until you protect the worksheet (Review tab, Protect group, Protect Sheet button).";
|
|
8
|
+
/** Format Cells → Protection: Locked (default on) and Hidden. */
|
|
9
|
+
export declare const ProtectionTab: ({ protection, onChange, }: {
|
|
10
|
+
protection: CellProtectionDraft;
|
|
11
|
+
onChange(protection: CellProtectionDraft): void;
|
|
12
|
+
}) => React.JSX.Element;
|
|
13
|
+
//# sourceMappingURL=protection-tab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protection-tab.d.ts","sourceRoot":"","sources":["../../../../../components/editors/cell-format/protection-tab.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,mBAAmB,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvE,0DAA0D;AAC1D,eAAO,MAAM,eAAe,sIACyG,CAAC;AAEtI,iEAAiE;AACjE,eAAO,MAAM,aAAa,GAAI,2BAG3B;IACD,UAAU,EAAE,mBAAmB,CAAC;IAChC,QAAQ,CAAC,UAAU,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACjD,sBAcA,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { __assign } from "tslib";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { CheckboxField } from "./list-box";
|
|
4
|
+
/** Excel's note under the Protection tab's checkboxes. */
|
|
5
|
+
export var PROTECTION_NOTE = "Locking cells or hiding formulas has no effect until you protect the worksheet (Review tab, Protect group, Protect Sheet button).";
|
|
6
|
+
/** Format Cells → Protection: Locked (default on) and Hidden. */
|
|
7
|
+
export var ProtectionTab = function (_a) {
|
|
8
|
+
var protection = _a.protection, onChange = _a.onChange;
|
|
9
|
+
return (React.createElement("div", { className: "flex flex-col gap-2" },
|
|
10
|
+
React.createElement(CheckboxField, { label: "Locked", checked: protection.locked, onChange: function (locked) { return onChange(__assign(__assign({}, protection), { locked: locked })); } }),
|
|
11
|
+
React.createElement(CheckboxField, { label: "Hidden", checked: protection.hidden, onChange: function (hidden) { return onChange(__assign(__assign({}, protection), { hidden: hidden })); } }),
|
|
12
|
+
React.createElement("p", { className: "font-system text-xs text-rnc-muted-foreground" }, PROTECTION_NOTE)));
|
|
13
|
+
};
|