@rowsncolumns/spreadsheet 10.14.0 → 10.17.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.
Files changed (104) hide show
  1. package/dist/cjs/api/editor-formula.d.ts +40 -0
  2. package/dist/cjs/api/editor-formula.d.ts.map +1 -0
  3. package/dist/cjs/api/editor-formula.js +87 -0
  4. package/dist/cjs/atoms/cell-input-context.atom.d.ts.map +1 -1
  5. package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts +22 -8
  6. package/dist/cjs/components/autocorrect-options-smart-tag/index.d.ts.map +1 -1
  7. package/dist/cjs/components/autocorrect-options-smart-tag/index.js +107 -22
  8. package/dist/cjs/components/canvas-grid/index.d.ts.map +1 -1
  9. package/dist/cjs/components/canvas-grid/index.js +114 -22
  10. package/dist/cjs/components/canvas-grid/typings.d.ts +8 -0
  11. package/dist/cjs/components/canvas-grid/typings.d.ts.map +1 -1
  12. package/dist/cjs/components/cell-input/cell-input.d.ts.map +1 -1
  13. package/dist/cjs/components/cell-input/cell-input.js +3 -1
  14. package/dist/cjs/components/embeds/embed-draggable.d.ts.map +1 -1
  15. package/dist/cjs/components/embeds/embed-draggable.js +42 -18
  16. package/dist/cjs/components/embeds/object-focus.d.ts +16 -3
  17. package/dist/cjs/components/embeds/object-focus.d.ts.map +1 -1
  18. package/dist/cjs/components/embeds/object-focus.js +62 -6
  19. package/dist/cjs/components/outline-gutter/index.d.ts +11 -3
  20. package/dist/cjs/components/outline-gutter/index.d.ts.map +1 -1
  21. package/dist/cjs/components/outline-gutter/index.js +11 -6
  22. package/dist/cjs/components/selection/index.d.ts +1 -1
  23. package/dist/cjs/components/selection/index.d.ts.map +1 -1
  24. package/dist/cjs/components/selection/index.js +2 -2
  25. package/dist/cjs/components/selection/types.d.ts +2 -0
  26. package/dist/cjs/components/selection/types.d.ts.map +1 -1
  27. package/dist/cjs/hooks/object-spec-schema.generated.d.ts.map +1 -1
  28. package/dist/cjs/hooks/object-spec-schema.generated.js +16 -0
  29. package/dist/cjs/hooks/use-editable.d.ts.map +1 -1
  30. package/dist/cjs/hooks/use-editable.js +5 -1
  31. package/dist/cjs/hooks/use-editor-change.d.ts.map +1 -1
  32. package/dist/cjs/hooks/use-editor-change.js +3 -1
  33. package/dist/cjs/hooks/use-embeds-charts.d.ts.map +1 -1
  34. package/dist/cjs/hooks/use-embeds-charts.js +32 -16
  35. package/dist/cjs/hooks/use-flash-fill-suggestion.d.ts.map +1 -1
  36. package/dist/cjs/hooks/use-flash-fill-suggestion.js +15 -4
  37. package/dist/cjs/hooks/use-grid-children.d.ts +7 -1
  38. package/dist/cjs/hooks/use-grid-children.d.ts.map +1 -1
  39. package/dist/cjs/hooks/use-grid-children.js +8 -2
  40. package/dist/cjs/hooks/use-header-actions.d.ts +11 -1
  41. package/dist/cjs/hooks/use-header-actions.d.ts.map +1 -1
  42. package/dist/cjs/hooks/use-header-actions.js +16 -6
  43. package/dist/cjs/hooks/use-move-columns-rows.d.ts +7 -1
  44. package/dist/cjs/hooks/use-move-columns-rows.d.ts.map +1 -1
  45. package/dist/cjs/hooks/use-move-columns-rows.js +12 -10
  46. package/dist/cjs/hooks/use-selection-renderer.d.ts.map +1 -1
  47. package/dist/cjs/hooks/use-selection-renderer.js +18 -4
  48. package/dist/cjs/release-date.js +1 -1
  49. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  50. package/dist/cjs/types.d.ts +17 -0
  51. package/dist/cjs/types.d.ts.map +1 -1
  52. package/dist/esm/api/editor-formula.d.ts +40 -0
  53. package/dist/esm/api/editor-formula.d.ts.map +1 -0
  54. package/dist/esm/api/editor-formula.js +76 -0
  55. package/dist/esm/atoms/cell-input-context.atom.d.ts.map +1 -1
  56. package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts +22 -8
  57. package/dist/esm/components/autocorrect-options-smart-tag/index.d.ts.map +1 -1
  58. package/dist/esm/components/autocorrect-options-smart-tag/index.js +103 -22
  59. package/dist/esm/components/canvas-grid/index.d.ts.map +1 -1
  60. package/dist/esm/components/canvas-grid/index.js +111 -23
  61. package/dist/esm/components/canvas-grid/typings.d.ts +8 -0
  62. package/dist/esm/components/canvas-grid/typings.d.ts.map +1 -1
  63. package/dist/esm/components/cell-input/cell-input.d.ts.map +1 -1
  64. package/dist/esm/components/cell-input/cell-input.js +4 -2
  65. package/dist/esm/components/embeds/embed-draggable.d.ts.map +1 -1
  66. package/dist/esm/components/embeds/embed-draggable.js +41 -20
  67. package/dist/esm/components/embeds/object-focus.d.ts +16 -3
  68. package/dist/esm/components/embeds/object-focus.d.ts.map +1 -1
  69. package/dist/esm/components/embeds/object-focus.js +38 -2
  70. package/dist/esm/components/outline-gutter/index.d.ts +11 -3
  71. package/dist/esm/components/outline-gutter/index.d.ts.map +1 -1
  72. package/dist/esm/components/outline-gutter/index.js +11 -6
  73. package/dist/esm/components/selection/index.d.ts +1 -1
  74. package/dist/esm/components/selection/index.d.ts.map +1 -1
  75. package/dist/esm/components/selection/index.js +2 -2
  76. package/dist/esm/components/selection/types.d.ts +2 -0
  77. package/dist/esm/components/selection/types.d.ts.map +1 -1
  78. package/dist/esm/hooks/object-spec-schema.generated.d.ts.map +1 -1
  79. package/dist/esm/hooks/object-spec-schema.generated.js +16 -0
  80. package/dist/esm/hooks/use-editable.d.ts.map +1 -1
  81. package/dist/esm/hooks/use-editable.js +6 -2
  82. package/dist/esm/hooks/use-editor-change.d.ts.map +1 -1
  83. package/dist/esm/hooks/use-editor-change.js +4 -2
  84. package/dist/esm/hooks/use-embeds-charts.d.ts.map +1 -1
  85. package/dist/esm/hooks/use-embeds-charts.js +32 -16
  86. package/dist/esm/hooks/use-flash-fill-suggestion.d.ts.map +1 -1
  87. package/dist/esm/hooks/use-flash-fill-suggestion.js +15 -4
  88. package/dist/esm/hooks/use-grid-children.d.ts +7 -1
  89. package/dist/esm/hooks/use-grid-children.d.ts.map +1 -1
  90. package/dist/esm/hooks/use-grid-children.js +7 -1
  91. package/dist/esm/hooks/use-header-actions.d.ts +11 -1
  92. package/dist/esm/hooks/use-header-actions.d.ts.map +1 -1
  93. package/dist/esm/hooks/use-header-actions.js +12 -2
  94. package/dist/esm/hooks/use-move-columns-rows.d.ts +7 -1
  95. package/dist/esm/hooks/use-move-columns-rows.d.ts.map +1 -1
  96. package/dist/esm/hooks/use-move-columns-rows.js +11 -7
  97. package/dist/esm/hooks/use-selection-renderer.d.ts.map +1 -1
  98. package/dist/esm/hooks/use-selection-renderer.js +18 -4
  99. package/dist/esm/release-date.js +1 -1
  100. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  101. package/dist/esm/types.d.ts +17 -0
  102. package/dist/esm/types.d.ts.map +1 -1
  103. package/dist/spreadsheet.min.css +1 -1
  104. package/package.json +3 -3
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The cell editor's own reading of the text being typed (demo-app-monorepo#57258): the engine takes
3
+ * a sign typed in front of a number literal as that number (rowsncolumns/spreadsheet#1666,
4
+ * rnc-cellmodel `is_a_formula_in`), so the editor does not colour it, offer function hints or pick
5
+ * references with the arrow keys while it is typed.
6
+ */
7
+ /** The marks a locale writes numbers with: its decimal mark and its thousands separator. */
8
+ export type NumberSeparators = {
9
+ decimal: string;
10
+ group: string;
11
+ };
12
+ /**
13
+ * The number marks of a locale, from CLDR as the engine reads them (ICU there, `Intl` here): de-DE
14
+ * `1.234,5`, fr-FR `1 234,5` (a narrow no-break space), de-CH `1'234.5`. Without a locale, or one
15
+ * `Intl` does not know: en-US.
16
+ */
17
+ export declare const numberSeparatorsOf: (locale?: {
18
+ id?: string;
19
+ } | null) => NumberSeparators;
20
+ /**
21
+ * A `+` / `-` right in front of a number literal that the engine takes as that number
22
+ * (rnc-cellmodel `is_a_formula_in`, rowsncolumns/spreadsheet#1666): a percent, a number ending in
23
+ * `€`, or a mixed fraction (`-3%`, `+3%`, `-1,234.5%`, `-.5%`, `-0 1/2`, `-5€`, `-3,5%` in de-DE).
24
+ * A date or a time after the sign (`-1/2`, `-3 PM`, `-12:30`), a bracket or a second sign (`-(3)`,
25
+ * `--3%`), a `%` after an exponent (`-1e5%`) and anything that is not a number (`+A1`,
26
+ * `-SUM(A1)`) are not. Kept to what that rule accepts: the editor never calls something a number
27
+ * that the engine will store as a formula.
28
+ */
29
+ export declare const isSignedNumberLiteral: (text: string, separators?: NumberSeparators) => boolean;
30
+ /**
31
+ * Whether the cell editor treats the text being typed as a formula: its syntax colouring, its
32
+ * function hints and autocomplete, and arrow keys picking references. The same as
33
+ * {@link isAFormula}, except that a sign in front of a number literal (`-3%`) is that number, as
34
+ * the engine stores it. `isAFormula` itself is unchanged: it classifies entries on the commit
35
+ * paths, which follow the engine.
36
+ */
37
+ export declare const isAFormulaWhileEditing: (text: unknown, locale?: {
38
+ id?: string;
39
+ } | null) => boolean;
40
+ //# sourceMappingURL=editor-formula.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editor-formula.d.ts","sourceRoot":"","sources":["../../../api/editor-formula.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AAEH,4FAA4F;AAC5F,MAAM,MAAM,gBAAgB,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAMlE;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,KAC9B,gBAiBF,CAAC;AAkCF;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAChC,MAAM,MAAM,EACZ,aAAY,gBAAmC,KAC9C,OAAsE,CAAC;AAE1E;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GACjC,MAAM,OAAO,EACb,SAAS;IAAE,EAAE,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,KAC9B,OAIF,CAAC"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAFormulaWhileEditing = exports.isSignedNumberLiteral = exports.numberSeparatorsOf = void 0;
4
+ var utils_1 = require("@rowsncolumns/utils");
5
+ var EN_US_SEPARATORS = { decimal: ".", group: "," };
6
+ var separatorsByLocale = new Map();
7
+ /**
8
+ * The number marks of a locale, from CLDR as the engine reads them (ICU there, `Intl` here): de-DE
9
+ * `1.234,5`, fr-FR `1 234,5` (a narrow no-break space), de-CH `1'234.5`. Without a locale, or one
10
+ * `Intl` does not know: en-US.
11
+ */
12
+ var numberSeparatorsOf = function (locale) {
13
+ var _a, _b, _c, _d;
14
+ var tag = locale === null || locale === void 0 ? void 0 : locale.id;
15
+ if (!tag)
16
+ return EN_US_SEPARATORS;
17
+ var separators = separatorsByLocale.get(tag);
18
+ if (!separators) {
19
+ try {
20
+ var parts = new Intl.NumberFormat(tag, { useGrouping: true }).formatToParts(1234567.5);
21
+ separators = {
22
+ decimal: (_b = (_a = parts.find(function (part) { return part.type === "decimal"; })) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ".",
23
+ group: (_d = (_c = parts.find(function (part) { return part.type === "group"; })) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : ",",
24
+ };
25
+ }
26
+ catch (_e) {
27
+ separators = EN_US_SEPARATORS;
28
+ }
29
+ separatorsByLocale.set(tag, separators);
30
+ }
31
+ return separators;
32
+ };
33
+ exports.numberSeparatorsOf = numberSeparatorsOf;
34
+ var escapeRegExp = function (text) { return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); };
35
+ var signedNumberLiteralPatterns = new Map();
36
+ /**
37
+ * The literals of rowsncolumns/spreadsheet#1666's entry table, and nothing wider: a whole number
38
+ * (thousands-grouped or not) with decimal digits after the mark, or decimals alone, ending in `%`
39
+ * or `€`; or a mixed fraction as the engine reads one (`\d{1,15} +\d{1,3}/\d{1,3}`, a non-zero
40
+ * denominator). A plain or scientific number after a sign is not a formula already.
41
+ */
42
+ var signedNumberLiteralPattern = function (_a) {
43
+ var decimal = _a.decimal, group = _a.group;
44
+ var key = "".concat(decimal).concat(group);
45
+ var pattern = signedNumberLiteralPatterns.get(key);
46
+ if (!pattern) {
47
+ var d = escapeRegExp(decimal);
48
+ // Groups only with `,` or `.`: a space or an apostrophe as the thousands mark (fr-FR, de-CH)
49
+ // is written differently across CLDR versions and keyboards, so a grouped number there keeps
50
+ // the formula reading rather than risk calling a number what the engine does not.
51
+ var whole = group === "," || group === "."
52
+ ? "(?:\\d{1,3}(?:".concat(escapeRegExp(group), "\\d{3})+|\\d+)")
53
+ : "\\d+";
54
+ var number = "(?:".concat(whole, "(?:").concat(d, "\\d+)?|").concat(d, "\\d+)");
55
+ pattern = new RegExp("^[+-](?:".concat(number, "(?:%|\u20AC)|\\d{1,15} +\\d{1,3}/(?!0+$)\\d{1,3})$"), "u");
56
+ signedNumberLiteralPatterns.set(key, pattern);
57
+ }
58
+ return pattern;
59
+ };
60
+ /**
61
+ * A `+` / `-` right in front of a number literal that the engine takes as that number
62
+ * (rnc-cellmodel `is_a_formula_in`, rowsncolumns/spreadsheet#1666): a percent, a number ending in
63
+ * `€`, or a mixed fraction (`-3%`, `+3%`, `-1,234.5%`, `-.5%`, `-0 1/2`, `-5€`, `-3,5%` in de-DE).
64
+ * A date or a time after the sign (`-1/2`, `-3 PM`, `-12:30`), a bracket or a second sign (`-(3)`,
65
+ * `--3%`), a `%` after an exponent (`-1e5%`) and anything that is not a number (`+A1`,
66
+ * `-SUM(A1)`) are not. Kept to what that rule accepts: the editor never calls something a number
67
+ * that the engine will store as a formula.
68
+ */
69
+ var isSignedNumberLiteral = function (text, separators) {
70
+ if (separators === void 0) { separators = EN_US_SEPARATORS; }
71
+ return signedNumberLiteralPattern(separators).test(text.trimEnd());
72
+ };
73
+ exports.isSignedNumberLiteral = isSignedNumberLiteral;
74
+ /**
75
+ * Whether the cell editor treats the text being typed as a formula: its syntax colouring, its
76
+ * function hints and autocomplete, and arrow keys picking references. The same as
77
+ * {@link isAFormula}, except that a sign in front of a number literal (`-3%`) is that number, as
78
+ * the engine stores it. `isAFormula` itself is unchanged: it classifies entries on the commit
79
+ * paths, which follow the engine.
80
+ */
81
+ var isAFormulaWhileEditing = function (text, locale) {
82
+ if (!(0, utils_1.isAFormula)(text))
83
+ return false;
84
+ var textStr = String(text);
85
+ return !(0, exports.isSignedNumberLiteral)(textStr, (0, exports.numberSeparatorsOf)(locale));
86
+ };
87
+ exports.isAFormulaWhileEditing = isAFormulaWhileEditing;
@@ -1 +1 @@
1
- {"version":3,"file":"cell-input-context.atom.d.ts","sourceRoot":"","sources":["../../../atoms/cell-input-context.atom.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,mBAAmB;;;;oBACu63F,CAAC;qBAAwB,CAAC;;;;;;;;;;;CADl53F,CAAC"}
1
+ {"version":3,"file":"cell-input-context.atom.d.ts","sourceRoot":"","sources":["../../../atoms/cell-input-context.atom.ts"],"names":[],"mappings":"AAoCA,eAAO,MAAM,mBAAmB;;;;oBAC874F,CAAC;qBAAwB,CAAC;;;;;;;;;;;CADz64F,CAAC"}
@@ -1,8 +1,19 @@
1
1
  import React from "react";
2
2
  import type { CalculatedColumnFillKind, CalculatedColumnOption } from "../../api/calculated-column-fill";
3
3
  import type { TableAutoExpansionOption } from "../../api/table-auto-expansion";
4
+ /**
5
+ * Where the button hangs from its cell. `outside`: just outside the bottom-right corner, over the
6
+ * next row (Excel for Mac). When a split bar runs along the cell's bottom or right edge, that
7
+ * corner is in no pane, so the pane showing the cell keeps the button inside itself: `above-bar`
8
+ * (the bar under the cell: beside the cell, its bottom on the bar), `left-of-bar` (the bar right
9
+ * of the cell: under the cell, its right on the bar), `inside` (both: in the cell's corner).
10
+ */
11
+ export type AutoCorrectPlacement = "outside" | "above-bar" | "left-of-bar" | "inside";
4
12
  export type AutoCorrectOptionsSmartTagProps = {
5
- /** Position/size of the cell the tag belongs to; the tag sits beside its top-right corner. */
13
+ /**
14
+ * Position/size of the cell the tag belongs to; the tag hangs just outside its bottom-right
15
+ * corner, over the next row (where Excel for Mac puts it).
16
+ */
6
17
  x: number;
7
18
  y: number;
8
19
  width: number;
@@ -21,17 +32,20 @@ export type AutoCorrectOptionsSmartTagProps = {
21
32
  canStop: boolean;
22
33
  };
23
34
  onChooseCalculatedColumnOption?(option: CalculatedColumnOption): void;
35
+ /** Where the button hangs from the cell; `outside` by default. */
36
+ placement?: AutoCorrectPlacement;
24
37
  };
25
38
  /**
26
- * Excel's AutoCorrect Options smart tag beside the cell an edit grew a table from, or typed a
27
- * table column's formula into — ONE button, carrying the entries of both when one edit did both
28
- * (a formula typed in the column right of a table): "Undo Table AutoExpansion" / "Stop
29
- * Automatically Expanding Tables", and "Undo Calculated Column" (or "Overwrite all cells in this
30
- * column with this formula") / "Stop automatically creating calculated columns". An entry the
31
- * host cannot carry out is not offered; with none left, no button.
39
+ * Excel's AutoCorrect Options smart tag, hanging from the bottom-right corner of the cell an edit
40
+ * grew a table from, or typed a table column's formula into — ONE button, carrying the entries of
41
+ * both when one edit did both (a formula typed in the column right of a table): "Undo Table
42
+ * AutoExpansion" / "Stop Automatically Expanding Tables", and "Undo Calculated Column" (or
43
+ * "Overwrite all cells in this column with this formula") / "Stop automatically creating
44
+ * calculated columns". An entry the host cannot carry out is not offered; with none left, no
45
+ * button.
32
46
  */
33
47
  export declare const AutoCorrectOptionsSmartTag: {
34
- ({ x, y, width, tableAutoExpansion, onChooseTableAutoExpansionOption, calculatedColumn, onChooseCalculatedColumnOption, }: AutoCorrectOptionsSmartTagProps): React.JSX.Element | null;
48
+ ({ x, y, width, height, tableAutoExpansion, onChooseTableAutoExpansionOption, calculatedColumn, onChooseCalculatedColumnOption, placement, }: AutoCorrectOptionsSmartTagProps): React.JSX.Element | null;
35
49
  displayName: string;
36
50
  };
37
51
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/autocorrect-options-smart-tag/index.tsx"],"names":[],"mappings":"AASA,OAAO,KAAmB,MAAM,OAAO,CAAC;AAExC,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE/E,MAAM,MAAM,+BAA+B,GAAG;IAC5C,8FAA8F;IAC9F,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,kBAAkB,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAC5D,gCAAgC,CAAC,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAC1E,yGAAyG;IACzG,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,wBAAwB,CAAC;QAC/B,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,OAAO,CAAC;QACtB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,8BAA8B,CAAC,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAAC;CACvE,CAAC;AAWF;;;;;;;GAOG;AACH,eAAO,MAAM,0BAA0B;+HAQpC,+BAA+B;;CAyGjC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/autocorrect-options-smart-tag/index.tsx"],"names":[],"mappings":"AASA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,GAC5B,SAAS,GACT,WAAW,GACX,aAAa,GACb,QAAQ,CAAC;AA+Eb,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;;OAGG;IACH,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,+EAA+E;IAC/E,kBAAkB,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAC5D,gCAAgC,CAAC,CAAC,MAAM,EAAE,wBAAwB,GAAG,IAAI,CAAC;IAC1E,yGAAyG;IACzG,gBAAgB,CAAC,EAAE;QACjB,IAAI,EAAE,wBAAwB,CAAC;QAC/B,OAAO,EAAE,OAAO,CAAC;QACjB,YAAY,EAAE,OAAO,CAAC;QACtB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,8BAA8B,CAAC,CAAC,MAAM,EAAE,sBAAsB,GAAG,IAAI,CAAC;IACtE,kEAAkE;IAClE,SAAS,CAAC,EAAE,oBAAoB,CAAC;CAClC,CAAC;AAgCF;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B;kJAUpC,+BAA+B;;CA+HjC,CAAC"}
@@ -4,20 +4,100 @@ exports.AutoCorrectOptionsSmartTag = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var ui_1 = require("@rowsncolumns/ui");
6
6
  var react_1 = tslib_1.__importStar(require("react"));
7
- /** Excel's AutoCorrect Options lightning bolt. */
8
- var LightningIcon = function () { return (react_1.default.createElement("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true" },
9
- react_1.default.createElement("path", { d: "M13 2 4 14h6l-1 8 9-12h-6l1-8z" }))); };
7
+ var placementStyle = function (placement, _a) {
8
+ var x = _a.x, y = _a.y, width = _a.width, height = _a.height;
9
+ var beside = placement === "outside" || placement === "above-bar";
10
+ var below = placement === "outside" || placement === "left-of-bar";
11
+ return {
12
+ left: beside ? x + width + 2 : x + width,
13
+ top: y + height,
14
+ transform: beside && below
15
+ ? undefined
16
+ : "translate(".concat(beside ? "0" : "-100%", ", ").concat(below ? "0" : "-100%", ")"),
17
+ };
18
+ };
19
+ /** The nearest ancestor that clips its content: the pane the button is drawn in. */
20
+ var clipOf = function (node) {
21
+ var _a;
22
+ var view = node.ownerDocument.defaultView;
23
+ for (var el = node.parentElement; el; el = el.parentElement) {
24
+ var overflow = (_a = view === null || view === void 0 ? void 0 : view.getComputedStyle(el).overflow) !== null && _a !== void 0 ? _a : "";
25
+ if (overflow && overflow !== "visible")
26
+ return el;
27
+ }
28
+ return null;
29
+ };
30
+ var THRESHOLDS = Array.from({ length: 25 }, function (_, i) { return i / 24; });
31
+ /**
32
+ * Keeps the button whole inside the pane it is drawn in: an invisible box at the button's own
33
+ * place is watched against the pane (an `IntersectionObserver`, so a pane scrolling the cell toward
34
+ * its edge is seen too), and the button is moved back inside by as much as that box sticks out —
35
+ * a cell one row above a split bar or the window's edge, where hanging below the cell would cut
36
+ * the button. Without `IntersectionObserver` (jsdom) the button stays at its place.
37
+ */
38
+ var useKeepInsidePane = function (deps) {
39
+ var sentinelRef = (0, react_1.useRef)(null);
40
+ var _a = tslib_1.__read((0, react_1.useState)({ x: 0, y: 0 }), 2), shift = _a[0], setShift = _a[1];
41
+ (0, react_1.useEffect)(function () {
42
+ var _a;
43
+ var sentinel = sentinelRef.current;
44
+ var IO = (_a = sentinel === null || sentinel === void 0 ? void 0 : sentinel.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.IntersectionObserver;
45
+ if (!sentinel || !IO)
46
+ return;
47
+ var root = clipOf(sentinel);
48
+ if (!root)
49
+ return;
50
+ var observer = new IO(function (entries) {
51
+ var _a;
52
+ var entry = entries[entries.length - 1];
53
+ var box = entry.boundingClientRect;
54
+ var bounds = (_a = entry.rootBounds) !== null && _a !== void 0 ? _a : root.getBoundingClientRect();
55
+ var x = box.right > bounds.right
56
+ ? bounds.right - box.right
57
+ : box.left < bounds.left
58
+ ? bounds.left - box.left
59
+ : 0;
60
+ var y = box.bottom > bounds.bottom
61
+ ? bounds.bottom - box.bottom
62
+ : box.top < bounds.top
63
+ ? bounds.top - box.top
64
+ : 0;
65
+ setShift(function (prev) { return (prev.x === x && prev.y === y ? prev : { x: x, y: y }); });
66
+ }, { root: root, threshold: THRESHOLDS });
67
+ observer.observe(sentinel);
68
+ return function () { return observer.disconnect(); };
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ }, deps);
71
+ return { sentinelRef: sentinelRef, shift: shift };
72
+ };
73
+ /**
74
+ * The AutoCorrect Options glyph: a letter "A" with a lightning bolt at its shoulder, and a ▾ for
75
+ * the menu the button opens — the same reading as Excel's button, drawn here from scratch. Every
76
+ * mark is a path (no font), so it reads the same at 1× on every system.
77
+ */
78
+ var AutoCorrectGlyph = function () { return (react_1.default.createElement("svg", { width: "20", height: "14", viewBox: "0 0 20 14", "aria-hidden": "true", "data-testid": "autocorrect-options-glyph" },
79
+ react_1.default.createElement("path", { d: "M1.2 13 5 2.2 8.8 13M2.6 9.4h4.8", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinejoin: "round" }),
80
+ react_1.default.createElement("path", { d: "M12.6 0.6 9.2 6.2h2.3l-1 4.4 4.1-6.1h-2.3l1.5-3.9z", fill: "#E8A317" }),
81
+ react_1.default.createElement("path", { d: "M15.6 7h4l-2 2.6z", fill: "currentColor" }))); };
10
82
  /**
11
- * Excel's AutoCorrect Options smart tag beside the cell an edit grew a table from, or typed a
12
- * table column's formula into — ONE button, carrying the entries of both when one edit did both
13
- * (a formula typed in the column right of a table): "Undo Table AutoExpansion" / "Stop
14
- * Automatically Expanding Tables", and "Undo Calculated Column" (or "Overwrite all cells in this
15
- * column with this formula") / "Stop automatically creating calculated columns". An entry the
16
- * host cannot carry out is not offered; with none left, no button.
83
+ * Excel's AutoCorrect Options smart tag, hanging from the bottom-right corner of the cell an edit
84
+ * grew a table from, or typed a table column's formula into — ONE button, carrying the entries of
85
+ * both when one edit did both (a formula typed in the column right of a table): "Undo Table
86
+ * AutoExpansion" / "Stop Automatically Expanding Tables", and "Undo Calculated Column" (or
87
+ * "Overwrite all cells in this column with this formula") / "Stop automatically creating
88
+ * calculated columns". An entry the host cannot carry out is not offered; with none left, no
89
+ * button.
17
90
  */
18
91
  var AutoCorrectOptionsSmartTag = function (_a) {
19
- var x = _a.x, y = _a.y, width = _a.width, tableAutoExpansion = _a.tableAutoExpansion, onChooseTableAutoExpansionOption = _a.onChooseTableAutoExpansionOption, calculatedColumn = _a.calculatedColumn, onChooseCalculatedColumnOption = _a.onChooseCalculatedColumnOption;
20
- var _b = tslib_1.__read((0, react_1.useState)(false), 2), open = _b[0], setOpen = _b[1];
92
+ var x = _a.x, y = _a.y, width = _a.width, height = _a.height, tableAutoExpansion = _a.tableAutoExpansion, onChooseTableAutoExpansionOption = _a.onChooseTableAutoExpansionOption, calculatedColumn = _a.calculatedColumn, onChooseCalculatedColumnOption = _a.onChooseCalculatedColumnOption, _b = _a.placement, placement = _b === void 0 ? "outside" : _b;
93
+ var _c = tslib_1.__read((0, react_1.useState)(false), 2), open = _c[0], setOpen = _c[1];
94
+ var _d = useKeepInsidePane([
95
+ placement,
96
+ x,
97
+ y,
98
+ width,
99
+ height,
100
+ ]), sentinelRef = _d.sentinelRef, shift = _d.shift;
21
101
  var tableEntries = tableAutoExpansion && onChooseTableAutoExpansionOption
22
102
  ? tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read((tableAutoExpansion.canUndo
23
103
  ? [
@@ -45,7 +125,8 @@ var AutoCorrectOptionsSmartTag = function (_a) {
45
125
  onSelect: function () { return onChooseCalculatedColumnOption("undo"); },
46
126
  },
47
127
  ]
48
- : [])), false), tslib_1.__read((calculatedColumn.kind !== "filled" && calculatedColumn.canOverwrite
128
+ : [])), false), tslib_1.__read((calculatedColumn.kind !== "filled" &&
129
+ calculatedColumn.canOverwrite
49
130
  ? [
50
131
  {
51
132
  key: "column-overwrite",
@@ -69,16 +150,20 @@ var AutoCorrectOptionsSmartTag = function (_a) {
69
150
  tableEntries.length ? "table-auto-expansion" : undefined,
70
151
  columnEntries.length ? "calculated-column" : undefined,
71
152
  ].filter(Boolean);
72
- return (react_1.default.createElement("div", { className: "absolute pointer-events-auto flex items-start justify-start", style: { left: x + width + 2, top: y }, onMouseDown: function (e) { return e.stopPropagation(); }, "data-testid": "autocorrect-options", "data-autocorrect": kinds.join(" ") },
73
- react_1.default.createElement(ui_1.DropdownMenu, { modal: false, open: open, onOpenChange: setOpen },
74
- react_1.default.createElement(ui_1.DropdownMenuTrigger, { asChild: true },
75
- react_1.default.createElement(ui_1.IconButton, { tooltip: "AutoCorrect Options", "aria-label": "AutoCorrect Options", className: "shadow-sm bg-rnc-background border-rnc-border border border-solid rounded-md" },
76
- react_1.default.createElement(LightningIcon, null))),
77
- react_1.default.createElement(ui_1.DropdownMenuPortal, null,
78
- react_1.default.createElement(ui_1.DropdownMenuContent, { align: "start", onCloseAutoFocus: function (event) { return event.preventDefault(); } },
79
- tableEntries.map(function (entry) { return (react_1.default.createElement(ui_1.DropdownMenuItem, { key: entry.key, onSelect: entry.onSelect }, entry.label)); }),
80
- tableEntries.length && columnEntries.length ? (react_1.default.createElement(ui_1.DropdownMenuSeparator, null)) : null,
81
- columnEntries.map(function (entry) { return (react_1.default.createElement(ui_1.DropdownMenuItem, { key: entry.key, onSelect: entry.onSelect }, entry.label)); }))))));
153
+ return (react_1.default.createElement("div", { className: "absolute pointer-events-auto flex items-start justify-start", style: placementStyle(placement, { x: x, y: y, width: width, height: height }), onMouseDown: function (e) { return e.stopPropagation(); }, "data-testid": "autocorrect-options", "data-autocorrect": kinds.join(" "), "data-placement": placement },
154
+ react_1.default.createElement("div", { ref: sentinelRef, "aria-hidden": "true", className: "absolute inset-0 invisible pointer-events-none" }),
155
+ react_1.default.createElement("div", { style: shift.x || shift.y
156
+ ? { transform: "translate(".concat(shift.x, "px, ").concat(shift.y, "px)") }
157
+ : undefined },
158
+ react_1.default.createElement(ui_1.DropdownMenu, { modal: false, open: open, onOpenChange: setOpen },
159
+ react_1.default.createElement(ui_1.DropdownMenuTrigger, { asChild: true },
160
+ react_1.default.createElement(ui_1.IconButton, { tooltip: "AutoCorrect Options", "aria-label": "AutoCorrect Options", className: "shadow-sm bg-rnc-background border-rnc-border border border-solid rounded-md" },
161
+ react_1.default.createElement(AutoCorrectGlyph, null))),
162
+ react_1.default.createElement(ui_1.DropdownMenuPortal, null,
163
+ react_1.default.createElement(ui_1.DropdownMenuContent, { align: "start", onCloseAutoFocus: function (event) { return event.preventDefault(); } },
164
+ tableEntries.map(function (entry) { return (react_1.default.createElement(ui_1.DropdownMenuItem, { key: entry.key, onSelect: entry.onSelect }, entry.label)); }),
165
+ tableEntries.length && columnEntries.length ? (react_1.default.createElement(ui_1.DropdownMenuSeparator, null)) : null,
166
+ columnEntries.map(function (entry) { return (react_1.default.createElement(ui_1.DropdownMenuItem, { key: entry.key, onSelect: entry.onSelect }, entry.label)); })))))));
82
167
  };
83
168
  exports.AutoCorrectOptionsSmartTag = AutoCorrectOptionsSmartTag;
84
169
  exports.AutoCorrectOptionsSmartTag.displayName = "AutoCorrectOptionsSmartTag";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AA4Qf,OAAO,KAAK,EAGV,QAAQ,EAYT,MAAM,aAAa,CAAC;AA4CrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAigPnB,eAAO,MAAM,UAAU,EAA4C,CACjE,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,EAEvB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACvB,wBAAwB,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;CAAE,KAChE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../components/canvas-grid/index.tsx"],"names":[],"mappings":"AAqEA,OAAO,KASN,MAAM,OAAO,CAAC;AAiRf,OAAO,KAAK,EAGV,QAAQ,EAYT,MAAM,aAAa,CAAC;AA4CrB,OAAO,KAAK,EACV,wBAAwB,EACxB,iBAAiB,EACjB,eAAe,EAEhB,MAAM,WAAW,CAAC;AAknPnB,eAAO,MAAM,UAAU,EAA4C,CACjE,CAAC,SAAS,QAAQ,CAAC,GAAG,CAAC,EAEvB,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GACvB,wBAAwB,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAA;CAAE,KAChE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC"}