logisheets-formula-editor 1.1.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/README.md +192 -0
- package/dist/FormulaEditor.d.ts +17 -0
- package/dist/FormulaEditor.d.ts.map +1 -0
- package/dist/builtin-functions.json.d.ts +1510 -0
- package/dist/core.d.ts +18 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +13946 -0
- package/dist/editor.d.ts +57 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/engine.d.ts +34 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +23 -0
- package/dist/functions-Cxg5fTo6.js +1510 -0
- package/dist/functions.d.ts +3 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +94 -0
- package/dist/inline.d.ts +53 -0
- package/dist/inline.d.ts.map +1 -0
- package/dist/inline.js +164 -0
- package/dist/types.d.ts +159 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils.d.ts +43 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +62 -0
package/dist/editor.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { EditorView } from '@codemirror/view';
|
|
2
|
+
import { FormulaEditorConfig, FormulaFunction, GetDisplayUnitsFunc } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for {@link createFormulaEditor}. These mirror the React component's
|
|
5
|
+
* props minus the React-only bits — the React `style` prop maps to `style`
|
|
6
|
+
* here (applied to the host element).
|
|
7
|
+
*/
|
|
8
|
+
export interface FormulaEditorOptions {
|
|
9
|
+
/** Initial value (with leading '='). */
|
|
10
|
+
value?: string;
|
|
11
|
+
/** Initial value when `value` is not given. */
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
/** Where to place the cursor on creation (default: 'end'). */
|
|
14
|
+
initialCursorPosition?: 'start' | 'end';
|
|
15
|
+
onChange?: (value: string) => void;
|
|
16
|
+
onBlur?: (value: string) => void;
|
|
17
|
+
onSubmit?: (value: string) => void;
|
|
18
|
+
onCancel?: () => void;
|
|
19
|
+
/** Fetch token / cell-ref info from the host (required). */
|
|
20
|
+
getDisplayUnits: GetDisplayUnitsFunc;
|
|
21
|
+
/** Functions offered by autocomplete + signature help. */
|
|
22
|
+
formulaFunctions?: FormulaFunction[];
|
|
23
|
+
/** Current sheet name (for local cell-ref coloring). */
|
|
24
|
+
sheetName?: string;
|
|
25
|
+
config?: FormulaEditorConfig;
|
|
26
|
+
/** Extra class(es) added to the host element. */
|
|
27
|
+
className?: string;
|
|
28
|
+
/** Extra inline styles merged onto the host element. */
|
|
29
|
+
style?: Partial<CSSStyleDeclaration>;
|
|
30
|
+
}
|
|
31
|
+
/** Imperative handle returned by {@link createFormulaEditor}. */
|
|
32
|
+
export interface FormulaEditorHandle {
|
|
33
|
+
focus(): void;
|
|
34
|
+
blur(): void;
|
|
35
|
+
getValue(): string;
|
|
36
|
+
setValue(value: string): void;
|
|
37
|
+
/** Insert text at the current cursor position. */
|
|
38
|
+
insertText(text: string): void;
|
|
39
|
+
/** Replace a range — useful for swapping a previously-inserted ref. */
|
|
40
|
+
replaceRange(from: number, to: number, text: string): void;
|
|
41
|
+
getCursorPosition(): number;
|
|
42
|
+
getView(): EditorView | null;
|
|
43
|
+
/**
|
|
44
|
+
* Update live options without recreating the editor. Callback / function-
|
|
45
|
+
* list / sheet-name changes apply immediately; a changed `config` rebuilds
|
|
46
|
+
* the view (preserving text + cursor); a changed controlled `value` is
|
|
47
|
+
* dispatched into the document.
|
|
48
|
+
*/
|
|
49
|
+
updateOptions(opts: Partial<FormulaEditorOptions>): void;
|
|
50
|
+
destroy(): void;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a formula editor mounted into `parent`. Returns an imperative handle;
|
|
54
|
+
* call `destroy()` when done.
|
|
55
|
+
*/
|
|
56
|
+
export declare function createFormulaEditor(parent: HTMLElement, options: FormulaEditorOptions): FormulaEditorHandle;
|
|
57
|
+
//# sourceMappingURL=editor.d.ts.map
|
|
@@ -0,0 +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;IAC5D,eAAe,EAAE,mBAAmB,CAAA;IACpC,0DAA0D;IAC1D,gBAAgB,CAAC,EAAE,eAAe,EAAE,CAAA;IACpC,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,mBAAmB,CAAA;IAC5B,iDAAiD;IACjD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wDAAwD;IACxD,KAAK,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAA;CACvC;AAED,iEAAiE;AACjE,MAAM,WAAW,mBAAmB;IAChC,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,IAAI,IAAI,CAAA;IACZ,QAAQ,IAAI,MAAM,CAAA;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,kDAAkD;IAClD,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,uEAAuE;IACvE,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1D,iBAAiB,IAAI,MAAM,CAAA;IAC3B,OAAO,IAAI,UAAU,GAAG,IAAI,CAAA;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,CA8drB"}
|
package/dist/engine.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CellRef, FormulaFunction, GetDisplayUnitsFunc } from './types';
|
|
2
|
+
/** The slice of a workbook client the source needs. */
|
|
3
|
+
export interface FormulaWorkbook {
|
|
4
|
+
getDisplayUnitsOfFormula(formula: string): Promise<unknown>;
|
|
5
|
+
}
|
|
6
|
+
/** The slice of an engine `DataService` the source needs. */
|
|
7
|
+
export interface EngineFormulaServices {
|
|
8
|
+
getWorkbook(): FormulaWorkbook;
|
|
9
|
+
checkFormula(formula: string): Promise<boolean>;
|
|
10
|
+
}
|
|
11
|
+
export interface EngineFormulaSourceOptions {
|
|
12
|
+
/**
|
|
13
|
+
* Functions for autocomplete + signature help. Defaults to the bundled
|
|
14
|
+
* {@link builtinFormulaFunctions}; pass a localized list to override.
|
|
15
|
+
*/
|
|
16
|
+
formulaFunctions?: FormulaFunction[];
|
|
17
|
+
/**
|
|
18
|
+
* Called with the parsed cell references each time display units are
|
|
19
|
+
* fetched — wire this to your reference-highlight overlay.
|
|
20
|
+
*/
|
|
21
|
+
onCellRefs?: (cellRefs: readonly CellRef[]) => void;
|
|
22
|
+
}
|
|
23
|
+
/** Props the editor consumes, derived from the engine. */
|
|
24
|
+
export interface EngineFormulaSource {
|
|
25
|
+
getDisplayUnits: GetDisplayUnitsFunc;
|
|
26
|
+
checkFormula: (formula: string) => Promise<boolean>;
|
|
27
|
+
formulaFunctions: FormulaFunction[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Build the editor's data props from an engine `DataService`. Spread the result
|
|
31
|
+
* into `createFormulaEditor` / `<FormulaEditor>`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createEngineFormulaSource(services: EngineFormulaServices, options?: EngineFormulaSourceOptions): EngineFormulaSource;
|
|
34
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +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,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;IACnD,gBAAgB,EAAE,eAAe,EAAE,CAAA;CACtC;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACrC,QAAQ,EAAE,qBAAqB,EAC/B,OAAO,GAAE,0BAA+B,GACzC,mBAAmB,CA8BrB"}
|
package/dist/engine.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { b as f } from "./functions-Cxg5fTo6.js";
|
|
2
|
+
function o(c, e = {}) {
|
|
3
|
+
const a = e.formulaFunctions ?? f;
|
|
4
|
+
return {
|
|
5
|
+
getDisplayUnits: async (t) => {
|
|
6
|
+
var l, n;
|
|
7
|
+
try {
|
|
8
|
+
const r = await c.getWorkbook().getDisplayUnitsOfFormula(t);
|
|
9
|
+
if (r && typeof r == "object" && "tokenUnits" in r) {
|
|
10
|
+
const u = r;
|
|
11
|
+
return (l = e.onCellRefs) == null || l.call(e, u.cellRefs), u;
|
|
12
|
+
}
|
|
13
|
+
} catch {
|
|
14
|
+
}
|
|
15
|
+
(n = e.onCellRefs) == null || n.call(e, []);
|
|
16
|
+
},
|
|
17
|
+
checkFormula: (t) => c.checkFormula(t),
|
|
18
|
+
formulaFunctions: a
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {
|
|
22
|
+
o as createEngineFormulaSource
|
|
23
|
+
};
|