logisheets-formula-editor 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.js CHANGED
@@ -13884,7 +13884,10 @@ function Rd(s, e) {
13884
13884
  return Md.some((m) => g[m] !== i[m]);
13885
13885
  }
13886
13886
  return {
13887
- focus: () => o == null ? void 0 : o.focus(),
13887
+ // preventScroll: the in-cell editor may be parked off-screen while a
13888
+ // cross-sheet formula reference is being picked; refocusing it to keep
13889
+ // Enter working must not scroll the page to it.
13890
+ focus: () => o == null ? void 0 : o.contentDOM.focus({ preventScroll: !0 }),
13888
13891
  blur: () => o == null ? void 0 : o.contentDOM.blur(),
13889
13892
  getValue: () => (o == null ? void 0 : o.state.doc.toString()) ?? "",
13890
13893
  setValue: (g) => {
@@ -1 +1 @@
1
- {"version":3,"file":"editor.d.ts","sourceRoot":"","sources":["../src/lib/editor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EACH,UAAU,EAQb,MAAM,kBAAkB,CAAA;AAUzB,OAAO,KAAK,EAER,mBAAmB,EACnB,eAAe,EACf,mBAAmB,EACtB,MAAM,SAAS,CAAA;AAsUhB;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACjC,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,8DAA8D;IAC9D,qBAAqB,CAAC,EAAE,OAAO,GAAG,KAAK,CAAA;IACvC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAChC,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IAClC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IACrB,4DAA4D;I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;IAC5B;;;;;OAKG;IACH,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,oBAAoB,CAAC,GAAG,IAAI,CAAA;IACxD,OAAO,IAAI,IAAI,CAAA;CAClB;AAcD;;;GAGG;AACH,wBAAgB,mBAAmB,CAC/B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,oBAAoB,GAC9B,mBAAmB,CAierB"}
package/dist/engine.d.ts CHANGED
@@ -7,6 +7,8 @@ export interface FormulaWorkbook {
7
7
  export interface EngineFormulaServices {
8
8
  getWorkbook(): FormulaWorkbook;
9
9
  checkFormula(formula: string): Promise<boolean>;
10
+ /** Sheet name for a given index — used to build cross-sheet references. */
11
+ getSheetNameByIdx(idx: number): string;
10
12
  }
11
13
  export interface EngineFormulaSourceOptions {
12
14
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/lib/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EACR,OAAO,EAEP,eAAe,EACf,mBAAmB,EACtB,MAAM,SAAS,CAAA;AAGhB,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC5B,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAC9D;AAED,6DAA6D;AAC7D,MAAM,WAAW,qBAAqB;IAClC,WAAW,IAAI,eAAe,CAAA;IAC9B,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,0BAA0B;IACvC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAA;IACpC;;;OAGG;IACH,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,KAAK,IAAI,CAAA;CACtD;AAED,0DAA0D;AAC1D,MAAM,WAAW,mBAAmB;IAChC,eAAe,EAAE,mBAAmB,CAAA;IACpC,YAAY,EAAE,CA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rB"}
package/dist/inline.d.ts CHANGED
@@ -1,6 +1,41 @@
1
1
  import { EngineFormulaServices } from './engine';
2
2
  import { FormulaEditorConfig, FormulaFunction } from './types';
3
3
  import { Grid, SelectedData, Session } from 'logisheets-engine';
4
+ /**
5
+ * A single in-progress formula edit, registered with a {@link FormulaCoordinator}
6
+ * so OTHER views can feed it references (Excel "point mode" across sheets/views).
7
+ */
8
+ export interface FormulaEditEntry {
9
+ /** Stable id of the view that owns this edit. */
10
+ readonly viewId: string;
11
+ /** Sheet index the cell being edited lives on. */
12
+ getEditSheetIdx(): number;
13
+ /** Display reference of the edited cell, e.g. "Sheet1!B2". */
14
+ getCellRef(): string;
15
+ /** Current (live) formula text. */
16
+ getText(): string;
17
+ /** Insert a reference for a selection made in `sourceSheetIdx`. */
18
+ insertExternalRef(sourceSheetIdx: number, data: SelectedData): void;
19
+ /** Refocus the editor (e.g. after a sheet tab grabbed focus) so Enter
20
+ * keeps committing. */
21
+ focus(): void;
22
+ /** Commit / cancel the edit (for the cross-sheet reminder's buttons). */
23
+ commit(): void;
24
+ cancel(): void;
25
+ }
26
+ /**
27
+ * App-provided coordinator that tracks the one active formula edit across all
28
+ * views, so any view's cell click routes a reference to it instead of
29
+ * committing, and sheet tabs / other canvases know not to steal focus.
30
+ */
31
+ export interface FormulaCoordinator {
32
+ setActive(entry: FormulaEditEntry): void;
33
+ clear(entry: FormulaEditEntry): void;
34
+ getActive(): FormulaEditEntry | null;
35
+ isFormulaEditing(): boolean;
36
+ /** Notify that the active entry's live text changed (for the reminder). */
37
+ notifyChange?(entry: FormulaEditEntry): void;
38
+ }
4
39
  export interface InlineCellEditorOptions {
5
40
  /** Element the editor + highlight overlays mount into (the view's canvas
6
41
  * container; also the positioning origin and refocus target). */
@@ -10,8 +45,10 @@ export interface InlineCellEditorOptions {
10
45
  eventSource: Pick<Session, 'on' | 'off'>;
11
46
  /** Engine data service — `getWorkbook()` + `checkFormula()`. */
12
47
  dataService: EngineFormulaServices;
13
- /** This view's sheet index. */
14
- sheetIdx: number;
48
+ /** Stable id of the view that owns this editor (cross-view routing). */
49
+ viewId: string;
50
+ /** This view's CURRENT sheet index (read fresh; changes as tabs switch). */
51
+ getViewSheetIdx: () => number;
15
52
  /** Current sheet name (read fresh; used for local cell-ref coloring). */
16
53
  getSheetName: () => string;
17
54
  /** Commit a cell value (the host's input/ops layer). The return value is
@@ -19,6 +56,11 @@ export interface InlineCellEditorOptions {
19
56
  inputCell: (sheetIdx: number, row: number, col: number, text: string) => unknown;
20
57
  /** Move the view's selection (e.g. after committing). */
21
58
  setSelection: (data: SelectedData) => void;
59
+ /** Switch the view to a sheet — used to return to the edited cell's sheet
60
+ * after committing a formula built from another sheet. */
61
+ setViewSheet?: (sheetIdx: number) => void;
62
+ /** Cross-view formula-edit coordinator (Excel point mode across views). */
63
+ coordinator?: FormulaCoordinator;
22
64
  /** Initial grid; keep updated via {@link InlineCellEditorHandle.setGrid}. */
23
65
  grid?: Grid | null;
24
66
  /** Header panel offsets (engine config leftTopWidth/Height). Default 32/24. */
@@ -1 +1 @@
1
- {"version":3,"file":"inline.d.ts","sourceRoot":"","sources":["../src/lib/inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,OAAO,EAA4B,KAAK,qBAAqB,EAAC,MAAM,UAAU,CAAA;AAG9E,OAAO,EAAkB,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAC,MAAM,SAAS,CAAA;AAQvF,OAAO,KAAK,EACR,IAAI,EACJ,YAAY,EACZ,OAAO,EAEV,MAAM,mBAAmB,CAAA;AAE1B,MAAM,WAAW,uBAAuB;IACpC;sEACkE;IAClE,SAAS,EAAE,WAAW,CAAA;IACtB;2EACuE;IACvE,WAAW,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,GAAG,KAAK,CAAC,CAAA;IACxC,gEAAgE;IAChE,WAAW,EAAE,qBAAqB,CAAA;IAClC,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAA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AAe,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC5C,4EAA4E;IAC5E,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAA;CAChC;AAED,MAAM,WAAW,sBAAsB;IACnC;8EAC0E;IAC1E,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAA;IAChC,SAAS,IAAI,OAAO,CAAA;IACpB,gBAAgB,IAAI,OAAO,CAAA;IAC3B,OAAO,IAAI,IAAI,CAAA;CAClB;AAcD,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,uBAAuB,GACjC,sBAAsB,CAyXxB"}
package/dist/inline.js CHANGED
@@ -1,164 +1,211 @@
1
- import { getCellRefColor as Q, createFormulaEditor as Z, measureText as tt } from "./core.js";
2
- import { createEngineFormulaSource as et } from "./engine.js";
3
- import { b as it } from "./functions-Cxg5fTo6.js";
4
- import { getReferenceHighlightRects as ot, getReferenceString as nt, isCellInGridWindow as rt, getCellRect as B, buildSelectedDataFromCell as lt } from "logisheets-engine";
5
- const st = '13px Consolas, Monaco, "Courier New", monospace';
6
- function dt(P) {
1
+ import { getCellRefColor as fe, createFormulaEditor as ue, measureText as ae } from "./core.js";
2
+ import { createEngineFormulaSource as de } from "./engine.js";
3
+ import { b as ge } from "./functions-Cxg5fTo6.js";
4
+ import { getReferenceHighlightRects as he, isCellInGridWindow as xe, getCellRect as J, getReferenceString as K, qualifyReference as L, buildSelectedDataFromCell as Q } from "logisheets-engine";
5
+ const pe = '13px Consolas, Monaco, "Courier New", monospace';
6
+ function Ee(k) {
7
7
  const {
8
- container: w,
9
- eventSource: a,
10
- dataService: G,
11
- sheetIdx: $,
12
- getSheetName: z,
13
- inputCell: q,
14
- setSelection: N,
15
- origin: u = { x: 32, y: 24 },
16
- canEdit: A = () => !0,
17
- formulaFunctions: I = it,
18
- getHighlightColor: O = Q,
19
- editorConfig: V,
20
- onInvalidFormula: f,
21
- onEditingChange: d,
22
- onContentChanged: g
23
- } = P;
24
- let l = P.grid ?? null, c = !1, e = null, s = null, E = [], r = null, m = !1, p = "", C = "", n = null;
25
- const S = [], R = et(G, {
26
- formulaFunctions: I,
27
- onCellRefs: (t) => {
28
- E = t, k();
8
+ container: I,
9
+ eventSource: h,
10
+ dataService: B,
11
+ viewId: Z,
12
+ getViewSheetIdx: b,
13
+ getSheetName: D,
14
+ inputCell: ee,
15
+ setSelection: P,
16
+ setViewSheet: $,
17
+ coordinator: o,
18
+ origin: x = { x: 32, y: 24 },
19
+ canEdit: te = () => !0,
20
+ formulaFunctions: ie = ge,
21
+ getHighlightColor: ne = fe,
22
+ editorConfig: oe,
23
+ onInvalidFormula: p,
24
+ onEditingChange: m,
25
+ onContentChanged: f
26
+ } = k;
27
+ let u = k.grid ?? null, a = !1, t = null, l = null, N = [], r = null, R = !1, d = "", T = "", g = !1, s = null;
28
+ const z = [], W = de(B, {
29
+ formulaFunctions: ie,
30
+ onCellRefs: (e) => {
31
+ N = e, U();
29
32
  }
30
33
  });
31
- function T() {
32
- return c && p.trim().startsWith("=");
33
- }
34
- function W() {
35
- const t = w.querySelector("canvas");
36
- t == null || t.focus({ preventScroll: !0 });
34
+ function v() {
35
+ return a && d.trim().startsWith("=");
37
36
  }
38
37
  function H() {
39
- for (const t of S) t.remove();
40
- S.length = 0;
38
+ const e = I.querySelector("canvas");
39
+ e == null || e.focus({ preventScroll: !0 });
40
+ }
41
+ function M() {
42
+ for (const e of z) e.remove();
43
+ z.length = 0;
41
44
  }
42
- function k() {
43
- if (H(), !l) return;
44
- const t = ot(E, l, z(), {
45
- originX: u.x,
46
- originY: u.y
45
+ function U() {
46
+ if (M(), !u) return;
47
+ const e = he(N, u, D(), {
48
+ originX: x.x,
49
+ originY: x.y
47
50
  });
48
- for (const i of t) {
49
- const o = document.createElement("div");
50
- o.style.cssText = `position:absolute;pointer-events:none;opacity:0.3;z-index:0;left:${i.x}px;top:${i.y}px;width:${i.width}px;height:${i.height}px;background-color:${O(i.colorIndex)};`, w.appendChild(o), S.push(o);
51
+ for (const i of e) {
52
+ const n = document.createElement("div");
53
+ n.style.cssText = `position:absolute;pointer-events:none;opacity:0.3;z-index:0;left:${i.x}px;top:${i.y}px;width:${i.width}px;height:${i.height}px;background-color:${ne(i.colorIndex)};`, I.appendChild(n), z.push(n);
51
54
  }
52
55
  }
53
- function D() {
54
- !n || !e || (n.style.left = `${e.position.x}px`, n.style.top = `${e.position.y}px`, n.style.height = `${e.position.height}px`);
56
+ function X() {
57
+ !s || !t || (s.style.left = `${t.position.x}px`, s.style.top = `${t.position.y}px`, s.style.height = `${t.position.height}px`);
55
58
  }
56
- function M(t) {
57
- if (!n || !e) return;
58
- const i = tt(t, st) + 20;
59
- n.style.width = `${Math.max(e.position.width, i)}px`;
59
+ function Y(e) {
60
+ if (!s || !t) return;
61
+ const i = ae(e, pe) + 20;
62
+ s.style.width = `${Math.max(t.position.width, i)}px`;
60
63
  }
61
- function _(t) {
62
- p = t, M(t), m || (r = null), m = !1;
64
+ function se(e) {
65
+ d = e, Y(e), R || (r = null), R = !1, G();
63
66
  }
64
- function j(t) {
65
- if (!s) return;
66
- const i = s.getCursorPosition();
67
- m = !0, r ? s.replaceRange(
67
+ function le(e) {
68
+ if (!l) return;
69
+ const i = l.getCursorPosition();
70
+ R = !0, r ? l.replaceRange(
68
71
  r.startPos,
69
72
  r.startPos + r.text.length,
70
- t
71
- ) : s.insertText(t), r = { text: t, startPos: (r == null ? void 0 : r.startPos) ?? i };
73
+ e
74
+ ) : l.insertText(e), r = { text: e, startPos: (r == null ? void 0 : r.startPos) ?? i };
75
+ }
76
+ function q(e, i) {
77
+ if (!t) return;
78
+ const n = K(i);
79
+ if (!n) return;
80
+ const c = e === t.sheetIdx ? n : L(
81
+ n,
82
+ B.getSheetNameByIdx(e)
83
+ );
84
+ c !== T && (T = c, le(c));
72
85
  }
73
- function J() {
74
- s == null || s.destroy(), s = null, n == null || n.remove(), n = null;
86
+ const w = {
87
+ viewId: Z,
88
+ getEditSheetIdx: () => (t == null ? void 0 : t.sheetIdx) ?? -1,
89
+ getCellRef: () => {
90
+ if (!t) return "";
91
+ const e = K(
92
+ Q(t.row, t.col, "none")
93
+ );
94
+ return L(e, t.sheetName);
95
+ },
96
+ getText: () => d,
97
+ insertExternalRef: (e, i) => q(e, i),
98
+ focus: () => l == null ? void 0 : l.focus(),
99
+ commit: () => F(d, !0),
100
+ cancel: () => O()
101
+ };
102
+ function G() {
103
+ var i;
104
+ const e = v();
105
+ e && !g ? (g = !0, o == null || o.setActive(w)) : !e && g && (g = !1, o == null || o.clear(w)), g && ((i = o == null ? void 0 : o.notifyChange) == null || i.call(o, w));
75
106
  }
76
- function y() {
77
- c = !1, e = null, E = [], r = null, m = !1, p = "", C = "", J(), H(), d == null || d(!1);
107
+ function re() {
108
+ l == null || l.destroy(), l = null, s == null || s.remove(), s = null;
78
109
  }
79
- function K(t, i, o, h = "end") {
80
- if (!l || !A($, t, i, l)) return;
81
- c && y();
82
- const b = B(l, t, i, {
83
- originX: u.x,
84
- originY: u.y,
110
+ function C() {
111
+ g && (g = !1, o == null || o.clear(w)), a = !1, t = null, N = [], r = null, R = !1, d = "", T = "", re(), M(), m == null || m(!1);
112
+ }
113
+ function ce(e, i, n, c = "end") {
114
+ if (!u) return;
115
+ const y = b();
116
+ if (!te(y, e, i, u)) return;
117
+ a && C();
118
+ const E = J(u, e, i, {
119
+ originX: x.x,
120
+ originY: x.y,
85
121
  defaultWidth: 100,
86
122
  defaultHeight: 25
87
123
  });
88
- p = o, e = { sheetName: z(), row: t, col: i, position: b }, c = !0, d == null || d(!0), n = document.createElement("div"), n.style.cssText = "position:absolute;display:flex;align-items:center;box-sizing:border-box;z-index:1000;background:#fff;overflow:hidden;border:1px solid #4a90d9;box-shadow:0 1px 4px rgba(0,0,0,0.18);", w.appendChild(n);
89
- const x = document.createElement("div");
90
- x.style.width = "100%", x.style.boxSizing = "border-box", n.appendChild(x), D(), M(o), s = Z(x, {
91
- getDisplayUnits: R.getDisplayUnits,
92
- formulaFunctions: R.formulaFunctions,
93
- sheetName: e.sheetName,
94
- defaultValue: o,
95
- initialCursorPosition: h,
124
+ d = n, t = { sheetName: D(), sheetIdx: y, row: e, col: i, position: E }, a = !0, m == null || m(!0), s = document.createElement("div"), s.style.cssText = "position:absolute;display:flex;align-items:center;box-sizing:border-box;z-index:1000;background:#fff;overflow:hidden;border:1px solid #4a90d9;box-shadow:0 1px 4px rgba(0,0,0,0.18);", I.appendChild(s);
125
+ const S = document.createElement("div");
126
+ S.style.width = "100%", S.style.boxSizing = "border-box", s.appendChild(S), X(), Y(n), l = ue(S, {
127
+ getDisplayUnits: W.getDisplayUnits,
128
+ formulaFunctions: W.formulaFunctions,
129
+ sheetName: t.sheetName,
130
+ defaultValue: n,
131
+ initialCursorPosition: c,
96
132
  config: {
97
133
  fontSize: 12,
98
134
  lineHeight: 1.2,
99
135
  autoFocus: !0,
100
136
  placeholder: "",
101
137
  showBorder: !1,
102
- ...V
138
+ ...oe
103
139
  },
104
140
  style: { width: "100%", boxSizing: "border-box" },
105
- onChange: _,
106
- onBlur: (F) => v(F, !1),
107
- onSubmit: (F) => v(F, !0),
108
- onCancel: L
109
- });
141
+ onChange: se,
142
+ // While picking references for a formula (point mode), losing focus
143
+ // — clicking a sheet tab, another view, the reminder — must NOT
144
+ // commit (Excel behavior); only Enter / the reminder button do.
145
+ // Plain-text edits still commit on blur.
146
+ onBlur: (A) => {
147
+ v() || F(A, !1);
148
+ },
149
+ onSubmit: (A) => F(A, !0),
150
+ onCancel: O
151
+ }), G();
110
152
  }
111
- async function v(t, i = !0) {
112
- if (!e) return;
113
- const o = t.trim();
114
- if (o.startsWith("=") && !await R.checkFormula(o)) {
115
- f == null || f();
153
+ async function F(e, i = !0) {
154
+ if (!t) return;
155
+ const { row: n, col: c, sheetIdx: y } = t, E = e.trim();
156
+ if (E.startsWith("=") && !await W.checkFormula(E)) {
157
+ p == null || p();
116
158
  return;
117
159
  }
118
- const { row: h, col: b } = e;
119
- await q($, h, b, o), i && N(lt(h, b, "none")), y(), g == null || g(), W();
160
+ await ee(y, n, c, E), i && (b() !== y && ($ == null || $(y)), P(Q(n, c, "none"))), C(), f == null || f(), H();
120
161
  }
121
- function L() {
122
- y(), W();
162
+ function O() {
163
+ C(), H();
123
164
  }
124
- const U = async (t) => {
125
- await Promise.resolve(), K(t.row, t.col, t.initialText);
126
- }, X = (t) => {
165
+ const V = async (e) => {
166
+ await Promise.resolve(), ce(e.row, e.col, e.initialText);
167
+ }, _ = (e) => {
127
168
  var i;
128
- if (T()) {
129
- const o = nt(t);
130
- o && o !== C && (C = o, j(o));
169
+ if (v()) {
170
+ q(b(), e);
131
171
  return;
132
172
  }
133
- if (c && e && ((i = t.data) == null ? void 0 : i.ty) === "cellRange") {
134
- const { startRow: o, startCol: h } = t.data.d;
135
- (o !== e.row || h !== e.col) && v(p, !1);
173
+ if (!a) {
174
+ const n = o == null ? void 0 : o.getActive();
175
+ if (n && n !== w) {
176
+ n.insertExternalRef(b(), e), P(e), f == null || f();
177
+ return;
178
+ }
179
+ }
180
+ if (a && t && ((i = e.data) == null ? void 0 : i.ty) === "cellRange") {
181
+ const { startRow: n, startCol: c } = e.data.d;
182
+ (n !== t.row || c !== t.col) && F(d, !1);
136
183
  }
137
- N(t), g == null || g();
138
- }, Y = () => f == null ? void 0 : f();
139
- return a.on("startEdit", U), a.on("selectionChange", X), a.on("invalidFormula", Y), {
140
- setGrid(t) {
141
- if (l = t, c && e && l) {
142
- if (!rt(l, e.row, e.col))
143
- e.position.x = -9999, e.position.y = -9999;
184
+ P(e), f == null || f();
185
+ }, j = () => p == null ? void 0 : p();
186
+ return h.on("startEdit", V), h.on("selectionChange", _), h.on("invalidFormula", j), {
187
+ setGrid(e) {
188
+ if (u = e, a && t && u) {
189
+ if (b() !== t.sheetIdx || !xe(u, t.row, t.col))
190
+ t.position.x = -9999, t.position.y = -9999;
144
191
  else {
145
- const { x: i, y: o } = B(l, e.row, e.col, {
146
- originX: u.x,
147
- originY: u.y
192
+ const { x: i, y: n } = J(u, t.row, t.col, {
193
+ originX: x.x,
194
+ originY: x.y
148
195
  });
149
- e.position.x = i, e.position.y = o;
196
+ t.position.x = i, t.position.y = n;
150
197
  }
151
- D();
198
+ X();
152
199
  }
153
- k();
200
+ U();
154
201
  },
155
- isEditing: () => c,
156
- isEditingFormula: T,
202
+ isEditing: () => a,
203
+ isEditingFormula: v,
157
204
  destroy() {
158
- a.off("startEdit", U), a.off("selectionChange", X), a.off("invalidFormula", Y), y();
205
+ h.off("startEdit", V), h.off("selectionChange", _), h.off("invalidFormula", j), C();
159
206
  }
160
207
  };
161
208
  }
162
209
  export {
163
- dt as createInlineCellEditor
210
+ Ee as createInlineCellEditor
164
211
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "logisheets-formula-editor",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",