@rowsncolumns/utils 9.2.37 → 9.2.39
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/cell-data-helpers.d.ts +22 -1
- package/dist/cjs/cell-data-helpers.d.ts.map +1 -1
- package/dist/cjs/cell-data-helpers.js +29 -1
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/keyboard.d.ts +28 -0
- package/dist/cjs/keyboard.d.ts.map +1 -0
- package/dist/cjs/keyboard.js +67 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/cell-data-helpers.d.ts +22 -1
- package/dist/esm/cell-data-helpers.d.ts.map +1 -1
- package/dist/esm/cell-data-helpers.js +25 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/keyboard.d.ts +28 -0
- package/dist/esm/keyboard.d.ts.map +1 -0
- package/dist/esm/keyboard.js +62 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Note: These functions use generic types to avoid circular dependencies
|
|
6
6
|
*/
|
|
7
|
-
import type { CellData, CellFormat, StyleReference } from "@rowsncolumns/common-types";
|
|
7
|
+
import type { CellData, CellFormat, DataValidationRule, HorizontalAlign, StyleReference } from "@rowsncolumns/common-types";
|
|
8
8
|
export declare const getCellUserEnteredValue: <T extends CellData>(cell?: T | null) => T["ue"];
|
|
9
9
|
export declare const getCellEffectiveValue: <T extends CellData>(cell?: T | null) => T["ev"];
|
|
10
10
|
export declare const getCellUserEnteredFormat: <T extends CellData>(cell?: T | null) => T["uf"];
|
|
@@ -16,4 +16,25 @@ export declare const getExtendedValueString: (extValue?: Record<string, any> | n
|
|
|
16
16
|
export declare const getExtendedValueBool: (extValue?: Record<string, any> | null) => boolean | undefined;
|
|
17
17
|
export declare const getExtendedValueFormula: (extValue?: Record<string, any> | null) => string | undefined;
|
|
18
18
|
export declare const getExtendedValueError: (extValue?: Record<string, any> | null) => any | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Horizontal alignment the grid paints for a cell that has no explicit
|
|
21
|
+
* `horizontalAlignment` (Excel / Google Sheets "General"): errors,
|
|
22
|
+
* user-entered booleans and checkbox cells centre, numeric effective values
|
|
23
|
+
* right, everything else falls back to the renderer default (left, returned
|
|
24
|
+
* here as `undefined`).
|
|
25
|
+
*
|
|
26
|
+
* A checkbox cell centres regardless of its VALUE: a blank checkbox (no `ue`
|
|
27
|
+
* at all) and a windowed host whose lean read reconstructs the boolean as
|
|
28
|
+
* text both miss the `bv` probe, so the BOOLEAN data-validation rule decides.
|
|
29
|
+
*
|
|
30
|
+
* Shared by the CanvasGrid renderer and the state hooks'
|
|
31
|
+
* `getDefaultHorizontalAlignment(sheetId, rowIndex, columnIndex)` so a toolbar
|
|
32
|
+
* alignment selector reports the alignment the grid actually draws.
|
|
33
|
+
*/
|
|
34
|
+
export declare const resolveDefaultHorizontalAlignment: ({ errorValue, userEnteredValue, effectiveValue, dataValidation, }: {
|
|
35
|
+
errorValue: unknown;
|
|
36
|
+
userEnteredValue: Record<string, any> | null | undefined;
|
|
37
|
+
effectiveValue: Record<string, any> | null | undefined;
|
|
38
|
+
dataValidation: Pick<DataValidationRule, "condition"> | null | undefined;
|
|
39
|
+
}) => HorizontalAlign | undefined;
|
|
19
40
|
//# sourceMappingURL=cell-data-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-data-helpers.d.ts","sourceRoot":"","sources":["../../cell-data-helpers.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,QAAQ,EACR,UAAU,EACV,cAAc,EACf,MAAM,4BAA4B,CAAC;AAEpC,eAAO,MAAM,uBAAuB,GAAI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AAC,GAAG,IAAI,KACpC,OAAO,GAAG,SAEZ,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KACpC,MAAM,GAAG,SAEX,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KACpC,GAAG,GAAG,SAER,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,GAAI,mEAK/C;IACD,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACzD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACvD,cAAc,EAAE,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1E,KAAG,eAAe,GAAG,SASrB,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Note: These functions use generic types to avoid circular dependencies
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.getExtendedValueError = exports.getExtendedValueFormula = exports.getExtendedValueBool = exports.getExtendedValueString = exports.getExtendedValueNumber = exports.getStyleId = exports.getCellFormattedValue = exports.getCellEffectiveFormat = exports.getCellUserEnteredFormat = exports.getCellEffectiveValue = exports.getCellUserEnteredValue = void 0;
|
|
9
|
+
exports.resolveDefaultHorizontalAlignment = exports.getExtendedValueError = exports.getExtendedValueFormula = exports.getExtendedValueBool = exports.getExtendedValueString = exports.getExtendedValueNumber = exports.getStyleId = exports.getCellFormattedValue = exports.getCellEffectiveFormat = exports.getCellUserEnteredFormat = exports.getCellEffectiveValue = exports.getCellUserEnteredValue = void 0;
|
|
10
10
|
var getCellUserEnteredValue = function (cell) {
|
|
11
11
|
var _a;
|
|
12
12
|
return (_a = cell === null || cell === void 0 ? void 0 : cell.ue) !== null && _a !== void 0 ? _a : cell === null || cell === void 0 ? void 0 : cell.userEnteredValue;
|
|
@@ -62,3 +62,31 @@ var getExtendedValueError = function (extValue) {
|
|
|
62
62
|
return (_a = extValue === null || extValue === void 0 ? void 0 : extValue.ev) !== null && _a !== void 0 ? _a : extValue === null || extValue === void 0 ? void 0 : extValue.errorValue;
|
|
63
63
|
};
|
|
64
64
|
exports.getExtendedValueError = getExtendedValueError;
|
|
65
|
+
/**
|
|
66
|
+
* Horizontal alignment the grid paints for a cell that has no explicit
|
|
67
|
+
* `horizontalAlignment` (Excel / Google Sheets "General"): errors,
|
|
68
|
+
* user-entered booleans and checkbox cells centre, numeric effective values
|
|
69
|
+
* right, everything else falls back to the renderer default (left, returned
|
|
70
|
+
* here as `undefined`).
|
|
71
|
+
*
|
|
72
|
+
* A checkbox cell centres regardless of its VALUE: a blank checkbox (no `ue`
|
|
73
|
+
* at all) and a windowed host whose lean read reconstructs the boolean as
|
|
74
|
+
* text both miss the `bv` probe, so the BOOLEAN data-validation rule decides.
|
|
75
|
+
*
|
|
76
|
+
* Shared by the CanvasGrid renderer and the state hooks'
|
|
77
|
+
* `getDefaultHorizontalAlignment(sheetId, rowIndex, columnIndex)` so a toolbar
|
|
78
|
+
* alignment selector reports the alignment the grid actually draws.
|
|
79
|
+
*/
|
|
80
|
+
var resolveDefaultHorizontalAlignment = function (_a) {
|
|
81
|
+
var _b;
|
|
82
|
+
var errorValue = _a.errorValue, userEnteredValue = _a.userEnteredValue, effectiveValue = _a.effectiveValue, dataValidation = _a.dataValidation;
|
|
83
|
+
var isBoolean = (0, exports.getExtendedValueBool)(userEnteredValue) !== undefined;
|
|
84
|
+
var isCheckbox = ((_b = dataValidation === null || dataValidation === void 0 ? void 0 : dataValidation.condition) === null || _b === void 0 ? void 0 : _b.type) === "BOOLEAN";
|
|
85
|
+
if (errorValue || isBoolean || isCheckbox) {
|
|
86
|
+
return "center";
|
|
87
|
+
}
|
|
88
|
+
return (0, exports.getExtendedValueNumber)(effectiveValue) !== undefined
|
|
89
|
+
? "right"
|
|
90
|
+
: undefined;
|
|
91
|
+
};
|
|
92
|
+
exports.resolveDefaultHorizontalAlignment = resolveDefaultHorizontalAlignment;
|
package/dist/cjs/index.d.ts
CHANGED
package/dist/cjs/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,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"}
|
|
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,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"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,3 +24,4 @@ tslib_1.__exportStar(require("./conditional-format"), exports);
|
|
|
24
24
|
tslib_1.__exportStar(require("./data-validation"), exports);
|
|
25
25
|
tslib_1.__exportStar(require("./content-hash"), exports);
|
|
26
26
|
tslib_1.__exportStar(require("./shared-string-canonical"), exports);
|
|
27
|
+
tslib_1.__exportStar(require("./keyboard"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type HotkeyEventLike = {
|
|
2
|
+
key: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Map a physical key code (`KeyboardEvent.code`) to the character that key
|
|
7
|
+
* produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
|
|
8
|
+
* Returns undefined for codes that are not a letter, digit or punctuation key.
|
|
9
|
+
* @param code
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const hotkeyKeyFromCode: (code: string | undefined) => string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Layout-independent key to match keyboard shortcuts against.
|
|
15
|
+
*
|
|
16
|
+
* - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
|
|
17
|
+
* keep the shortcut printed on their keys (Excel / Google Sheets parity)
|
|
18
|
+
* and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
|
|
19
|
+
* - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
|
|
20
|
+
* Hebrew, or a macOS Option dead character such as `†`), the character is
|
|
21
|
+
* derived from the physical key instead: `event.code` `KeyB` → `b`.
|
|
22
|
+
* - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
|
|
23
|
+
* @param event
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare const getHotkeyKey: (event: HotkeyEventLike) => string;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../keyboard.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAqBF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,GAAG,SAAS,uBAWzD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,eAAe,WAYlD,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getHotkeyKey = exports.hotkeyKeyFromCode = void 0;
|
|
4
|
+
var PUNCTUATION_BY_CODE = {
|
|
5
|
+
Backquote: "`",
|
|
6
|
+
Backslash: "\\",
|
|
7
|
+
BracketLeft: "[",
|
|
8
|
+
BracketRight: "]",
|
|
9
|
+
Comma: ",",
|
|
10
|
+
Equal: "=",
|
|
11
|
+
Minus: "-",
|
|
12
|
+
Period: ".",
|
|
13
|
+
Quote: "'",
|
|
14
|
+
Semicolon: ";",
|
|
15
|
+
Slash: "/",
|
|
16
|
+
};
|
|
17
|
+
var isPrintableAscii = function (key) {
|
|
18
|
+
var charCode = key.charCodeAt(0);
|
|
19
|
+
return charCode >= 0x20 && charCode <= 0x7e;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Map a physical key code (`KeyboardEvent.code`) to the character that key
|
|
23
|
+
* produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
|
|
24
|
+
* Returns undefined for codes that are not a letter, digit or punctuation key.
|
|
25
|
+
* @param code
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
var hotkeyKeyFromCode = function (code) {
|
|
29
|
+
if (!code) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
if (/^Key[A-Z]$/.test(code)) {
|
|
33
|
+
return code.charAt(3).toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
if (/^Digit[0-9]$/.test(code)) {
|
|
36
|
+
return code.charAt(5);
|
|
37
|
+
}
|
|
38
|
+
return PUNCTUATION_BY_CODE[code];
|
|
39
|
+
};
|
|
40
|
+
exports.hotkeyKeyFromCode = hotkeyKeyFromCode;
|
|
41
|
+
/**
|
|
42
|
+
* Layout-independent key to match keyboard shortcuts against.
|
|
43
|
+
*
|
|
44
|
+
* - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
|
|
45
|
+
* keep the shortcut printed on their keys (Excel / Google Sheets parity)
|
|
46
|
+
* and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
|
|
47
|
+
* - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
|
|
48
|
+
* Hebrew, or a macOS Option dead character such as `†`), the character is
|
|
49
|
+
* derived from the physical key instead: `event.code` `KeyB` → `b`.
|
|
50
|
+
* - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
|
|
51
|
+
* @param event
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
var getHotkeyKey = function (event) {
|
|
55
|
+
var key = event.key, code = event.code;
|
|
56
|
+
if (key.length === 1) {
|
|
57
|
+
if (isPrintableAscii(key)) {
|
|
58
|
+
return key.toLowerCase();
|
|
59
|
+
}
|
|
60
|
+
var keyFromCode = (0, exports.hotkeyKeyFromCode)(code);
|
|
61
|
+
if (keyFromCode !== undefined) {
|
|
62
|
+
return keyFromCode;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return key;
|
|
66
|
+
};
|
|
67
|
+
exports.getHotkeyKey = getHotkeyKey;
|
|
@@ -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","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.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","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Note: These functions use generic types to avoid circular dependencies
|
|
6
6
|
*/
|
|
7
|
-
import type { CellData, CellFormat, StyleReference } from "@rowsncolumns/common-types";
|
|
7
|
+
import type { CellData, CellFormat, DataValidationRule, HorizontalAlign, StyleReference } from "@rowsncolumns/common-types";
|
|
8
8
|
export declare const getCellUserEnteredValue: <T extends CellData>(cell?: T | null) => T["ue"];
|
|
9
9
|
export declare const getCellEffectiveValue: <T extends CellData>(cell?: T | null) => T["ev"];
|
|
10
10
|
export declare const getCellUserEnteredFormat: <T extends CellData>(cell?: T | null) => T["uf"];
|
|
@@ -16,4 +16,25 @@ export declare const getExtendedValueString: (extValue?: Record<string, any> | n
|
|
|
16
16
|
export declare const getExtendedValueBool: (extValue?: Record<string, any> | null) => boolean | undefined;
|
|
17
17
|
export declare const getExtendedValueFormula: (extValue?: Record<string, any> | null) => string | undefined;
|
|
18
18
|
export declare const getExtendedValueError: (extValue?: Record<string, any> | null) => any | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Horizontal alignment the grid paints for a cell that has no explicit
|
|
21
|
+
* `horizontalAlignment` (Excel / Google Sheets "General"): errors,
|
|
22
|
+
* user-entered booleans and checkbox cells centre, numeric effective values
|
|
23
|
+
* right, everything else falls back to the renderer default (left, returned
|
|
24
|
+
* here as `undefined`).
|
|
25
|
+
*
|
|
26
|
+
* A checkbox cell centres regardless of its VALUE: a blank checkbox (no `ue`
|
|
27
|
+
* at all) and a windowed host whose lean read reconstructs the boolean as
|
|
28
|
+
* text both miss the `bv` probe, so the BOOLEAN data-validation rule decides.
|
|
29
|
+
*
|
|
30
|
+
* Shared by the CanvasGrid renderer and the state hooks'
|
|
31
|
+
* `getDefaultHorizontalAlignment(sheetId, rowIndex, columnIndex)` so a toolbar
|
|
32
|
+
* alignment selector reports the alignment the grid actually draws.
|
|
33
|
+
*/
|
|
34
|
+
export declare const resolveDefaultHorizontalAlignment: ({ errorValue, userEnteredValue, effectiveValue, dataValidation, }: {
|
|
35
|
+
errorValue: unknown;
|
|
36
|
+
userEnteredValue: Record<string, any> | null | undefined;
|
|
37
|
+
effectiveValue: Record<string, any> | null | undefined;
|
|
38
|
+
dataValidation: Pick<DataValidationRule, "condition"> | null | undefined;
|
|
39
|
+
}) => HorizontalAlign | undefined;
|
|
19
40
|
//# sourceMappingURL=cell-data-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cell-data-helpers.d.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MAAM,sBAAsB,GACjC,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KACpC,MAAM,GAAG,SAEX,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAC/B,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KACpC,OAAO,GAAG,SAEZ,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAClC,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KACpC,MAAM,GAAG,SAEX,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAChC,WAAW,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KACpC,GAAG,GAAG,SAER,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iCAAiC,GAAI,mEAK/C;IACD,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACzD,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IACvD,cAAc,EAAE,IAAI,CAAC,kBAAkB,EAAE,WAAW,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;CAC1E,KAAG,eAAe,GAAG,SASrB,CAAC"}
|
|
@@ -37,3 +37,28 @@ export const getExtendedValueFormula = (extValue) => {
|
|
|
37
37
|
export const getExtendedValueError = (extValue) => {
|
|
38
38
|
return extValue?.ev ?? extValue?.errorValue;
|
|
39
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Horizontal alignment the grid paints for a cell that has no explicit
|
|
42
|
+
* `horizontalAlignment` (Excel / Google Sheets "General"): errors,
|
|
43
|
+
* user-entered booleans and checkbox cells centre, numeric effective values
|
|
44
|
+
* right, everything else falls back to the renderer default (left, returned
|
|
45
|
+
* here as `undefined`).
|
|
46
|
+
*
|
|
47
|
+
* A checkbox cell centres regardless of its VALUE: a blank checkbox (no `ue`
|
|
48
|
+
* at all) and a windowed host whose lean read reconstructs the boolean as
|
|
49
|
+
* text both miss the `bv` probe, so the BOOLEAN data-validation rule decides.
|
|
50
|
+
*
|
|
51
|
+
* Shared by the CanvasGrid renderer and the state hooks'
|
|
52
|
+
* `getDefaultHorizontalAlignment(sheetId, rowIndex, columnIndex)` so a toolbar
|
|
53
|
+
* alignment selector reports the alignment the grid actually draws.
|
|
54
|
+
*/
|
|
55
|
+
export const resolveDefaultHorizontalAlignment = ({ errorValue, userEnteredValue, effectiveValue, dataValidation, }) => {
|
|
56
|
+
const isBoolean = getExtendedValueBool(userEnteredValue) !== undefined;
|
|
57
|
+
const isCheckbox = dataValidation?.condition?.type === "BOOLEAN";
|
|
58
|
+
if (errorValue || isBoolean || isCheckbox) {
|
|
59
|
+
return "center";
|
|
60
|
+
}
|
|
61
|
+
return getExtendedValueNumber(effectiveValue) !== undefined
|
|
62
|
+
? "right"
|
|
63
|
+
: undefined;
|
|
64
|
+
};
|
package/dist/esm/index.d.ts
CHANGED
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,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"}
|
|
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,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"}
|
package/dist/esm/index.js
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
type HotkeyEventLike = {
|
|
2
|
+
key: string;
|
|
3
|
+
code?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Map a physical key code (`KeyboardEvent.code`) to the character that key
|
|
7
|
+
* produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
|
|
8
|
+
* Returns undefined for codes that are not a letter, digit or punctuation key.
|
|
9
|
+
* @param code
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
export declare const hotkeyKeyFromCode: (code: string | undefined) => string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Layout-independent key to match keyboard shortcuts against.
|
|
15
|
+
*
|
|
16
|
+
* - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
|
|
17
|
+
* keep the shortcut printed on their keys (Excel / Google Sheets parity)
|
|
18
|
+
* and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
|
|
19
|
+
* - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
|
|
20
|
+
* Hebrew, or a macOS Option dead character such as `†`), the character is
|
|
21
|
+
* derived from the physical key instead: `event.code` `KeyB` → `b`.
|
|
22
|
+
* - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
|
|
23
|
+
* @param event
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare const getHotkeyKey: (event: HotkeyEventLike) => string;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=keyboard.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../keyboard.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAqBF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,GAAG,SAAS,uBAWzD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,eAAe,WAYlD,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const PUNCTUATION_BY_CODE = {
|
|
2
|
+
Backquote: "`",
|
|
3
|
+
Backslash: "\\",
|
|
4
|
+
BracketLeft: "[",
|
|
5
|
+
BracketRight: "]",
|
|
6
|
+
Comma: ",",
|
|
7
|
+
Equal: "=",
|
|
8
|
+
Minus: "-",
|
|
9
|
+
Period: ".",
|
|
10
|
+
Quote: "'",
|
|
11
|
+
Semicolon: ";",
|
|
12
|
+
Slash: "/",
|
|
13
|
+
};
|
|
14
|
+
const isPrintableAscii = (key) => {
|
|
15
|
+
const charCode = key.charCodeAt(0);
|
|
16
|
+
return charCode >= 0x20 && charCode <= 0x7e;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Map a physical key code (`KeyboardEvent.code`) to the character that key
|
|
20
|
+
* produces on a US layout: `KeyB` → `b`, `Digit1` → `1`, `Semicolon` → `;`.
|
|
21
|
+
* Returns undefined for codes that are not a letter, digit or punctuation key.
|
|
22
|
+
* @param code
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export const hotkeyKeyFromCode = (code) => {
|
|
26
|
+
if (!code) {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
if (/^Key[A-Z]$/.test(code)) {
|
|
30
|
+
return code.charAt(3).toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
if (/^Digit[0-9]$/.test(code)) {
|
|
33
|
+
return code.charAt(5);
|
|
34
|
+
}
|
|
35
|
+
return PUNCTUATION_BY_CODE[code];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Layout-independent key to match keyboard shortcuts against.
|
|
39
|
+
*
|
|
40
|
+
* - A printable ASCII `event.key` wins, lowercased, so Dvorak/AZERTY users
|
|
41
|
+
* keep the shortcut printed on their keys (Excel / Google Sheets parity)
|
|
42
|
+
* and Shift no longer changes the letter (`Ctrl+Shift+X` → `x`).
|
|
43
|
+
* - When the layout produces a non-ASCII character (Cyrillic `и`, Greek `β`,
|
|
44
|
+
* Hebrew, or a macOS Option dead character such as `†`), the character is
|
|
45
|
+
* derived from the physical key instead: `event.code` `KeyB` → `b`.
|
|
46
|
+
* - Named keys (`Enter`, `Escape`, `F4`, `ArrowUp`, …) are returned as-is.
|
|
47
|
+
* @param event
|
|
48
|
+
* @returns
|
|
49
|
+
*/
|
|
50
|
+
export const getHotkeyKey = (event) => {
|
|
51
|
+
const { key, code } = event;
|
|
52
|
+
if (key.length === 1) {
|
|
53
|
+
if (isPrintableAscii(key)) {
|
|
54
|
+
return key.toLowerCase();
|
|
55
|
+
}
|
|
56
|
+
const keyFromCode = hotkeyKeyFromCode(code);
|
|
57
|
+
if (keyFromCode !== undefined) {
|
|
58
|
+
return keyFromCode;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return key;
|
|
62
|
+
};
|
|
@@ -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","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.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","../../formatter.ts","../../formula-refs.ts","../../formula.ts","../../index.ts","../../keyboard.ts","../../locale.ts","../../log.ts","../../memoize.ts","../../numbers.ts","../../selection.ts","../../shared-string-canonical.ts","../../sort.ts","../../string.ts","../../table-styles.ts","../../typeguards.ts","../../uuid.ts","../../vitest.config.ts"],"version":"5.8.3"}
|