logisheets-engine 1.0.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 (38) hide show
  1. package/README.md +85 -0
  2. package/dist/assets/logisheets_wasm_server_bg.wasm +0 -0
  3. package/dist/assets/worker-DtAa7uxj.js +4205 -0
  4. package/dist/logisheets-engine.css +1 -0
  5. package/dist/logisheets-engine.es.js +14095 -0
  6. package/dist/logisheets-engine.umd.js +1 -0
  7. package/dist/types/lib/adapters/index.d.ts +5 -0
  8. package/dist/types/lib/adapters/react.d.ts +88 -0
  9. package/dist/types/lib/block/enum_set_manager.d.ts +118 -0
  10. package/dist/types/lib/block/field_manager.d.ts +236 -0
  11. package/dist/types/lib/block/index.d.ts +7 -0
  12. package/dist/types/lib/block/manager.d.ts +25 -0
  13. package/dist/types/lib/block/value_formula.d.ts +47 -0
  14. package/dist/types/lib/clients/index.d.ts +3 -0
  15. package/dist/types/lib/clients/offscreen.d.ts +23 -0
  16. package/dist/types/lib/clients/service.d.ts +48 -0
  17. package/dist/types/lib/clients/workbook.d.ts +184 -0
  18. package/dist/types/lib/components/contextMenuTypes.d.ts +39 -0
  19. package/dist/types/lib/components/index.d.ts +8 -0
  20. package/dist/types/lib/components/utils.d.ts +33 -0
  21. package/dist/types/lib/engine.d.ts +242 -0
  22. package/dist/types/lib/global.d.ts +36 -0
  23. package/dist/types/lib/index.d.ts +15 -0
  24. package/dist/types/lib/license/index.d.ts +26 -0
  25. package/dist/types/lib/worker/border_helper.d.ts +24 -0
  26. package/dist/types/lib/worker/index.d.ts +3 -0
  27. package/dist/types/lib/worker/license.d.ts +27 -0
  28. package/dist/types/lib/worker/offscreen.worker.d.ts +35 -0
  29. package/dist/types/lib/worker/painter.d.ts +23 -0
  30. package/dist/types/lib/worker/pool.d.ts +26 -0
  31. package/dist/types/lib/worker/render.d.ts +24 -0
  32. package/dist/types/lib/worker/standable.d.ts +119 -0
  33. package/dist/types/lib/worker/types.d.ts +122 -0
  34. package/dist/types/lib/worker/view_manager.d.ts +59 -0
  35. package/dist/types/lib/worker/workbook.worker.d.ts +163 -0
  36. package/dist/types/lib/worker/worker.d.ts +5 -0
  37. package/dist/types/types/index.d.ts +115 -0
  38. package/package.json +40 -0
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Framework adapters for logisheets-engine.
3
+ * Provides compatibility layers for React and other frameworks.
4
+ */
5
+ export { convertCanvasPropsToAdapterProps, type SpreadsheetAdapterProps, type CanvasAdapterProps, type UseSpreadsheetConfig, type UseSpreadsheetReturn, } from "./react";
@@ -0,0 +1,88 @@
1
+ /**
2
+ * React adapter for logisheets-engine Svelte components.
3
+ * This module provides React wrappers around the Svelte components,
4
+ * allowing seamless integration with LogiSheets React application.
5
+ */
6
+ import type { SelectedData, SheetInfo, CellLayout } from "logisheets-web";
7
+ import type { Grid, EngineConfig } from "$types/index";
8
+ import type { ContextMenuItem, ContextMenuContext } from "../components/contextMenuTypes";
9
+ /**
10
+ * Props for the React Spreadsheet component adapter.
11
+ * These mirror the Svelte component props but follow React conventions.
12
+ */
13
+ export interface SpreadsheetAdapterProps {
14
+ /** Currently selected data */
15
+ selectedData?: SelectedData;
16
+ /** Active sheet index */
17
+ activeSheet?: number;
18
+ /** Cell layouts for custom rendering */
19
+ cellLayouts?: CellLayout[];
20
+ /** Engine configuration */
21
+ config?: Partial<EngineConfig>;
22
+ /** Show sheet tabs at bottom */
23
+ showSheetTabs?: boolean;
24
+ /** Show scrollbars */
25
+ showScrollbars?: boolean;
26
+ /** Custom context menu items */
27
+ contextMenuItems?: ContextMenuItem[];
28
+ /** Callback when selection changes */
29
+ onSelectedDataChange?: (data: SelectedData) => void;
30
+ /** Callback when active sheet changes */
31
+ onActiveSheetChange?: (sheet: number) => void;
32
+ /** Callback when grid updates */
33
+ onGridChange?: (grid: Grid | null) => void;
34
+ /** Callback when sheets list changes */
35
+ onSheetsChange?: (sheets: readonly SheetInfo[]) => void;
36
+ /** Callback when context menu item is clicked */
37
+ onContextMenuItemClick?: (item: ContextMenuItem, context: ContextMenuContext | null) => void;
38
+ }
39
+ /**
40
+ * LogiSheets-compatible props that follow the existing LogiSheets naming conventions.
41
+ * Use this interface when migrating from LogiSheets Canvas component.
42
+ */
43
+ export interface CanvasAdapterProps {
44
+ selectedData: SelectedData;
45
+ selectedData$: (e: SelectedData) => void;
46
+ activeSheet: number;
47
+ activeSheet$: (s: number) => void;
48
+ selectedDataContentChanged$: (e: object) => void;
49
+ grid: Grid | null;
50
+ setGrid: (grid: Grid | null) => void;
51
+ cellLayouts: CellLayout[];
52
+ }
53
+ /**
54
+ * Convert LogiSheets-style props to engine adapter props.
55
+ * This helps when migrating from the existing LogiSheets Canvas component.
56
+ */
57
+ export declare function convertCanvasPropsToAdapterProps(props: CanvasAdapterProps): SpreadsheetAdapterProps;
58
+ /**
59
+ * Hook configuration for creating a React-integrated spreadsheet instance.
60
+ * This can be used with custom React hooks to manage spreadsheet state.
61
+ */
62
+ export interface UseSpreadsheetConfig {
63
+ /** Initial selected data */
64
+ initialSelectedData?: SelectedData;
65
+ /** Initial active sheet index */
66
+ initialActiveSheet?: number;
67
+ /** Engine configuration */
68
+ config?: Partial<EngineConfig>;
69
+ }
70
+ /**
71
+ * Return type for useSpreadsheet hook (to be implemented in React wrapper package)
72
+ */
73
+ export interface UseSpreadsheetReturn {
74
+ /** Current selected data */
75
+ selectedData: SelectedData;
76
+ /** Set selected data */
77
+ setSelectedData: (data: SelectedData) => void;
78
+ /** Current active sheet */
79
+ activeSheet: number;
80
+ /** Set active sheet */
81
+ setActiveSheet: (sheet: number) => void;
82
+ /** Current grid */
83
+ grid: Grid | null;
84
+ /** Current sheets list */
85
+ sheets: readonly SheetInfo[];
86
+ /** Props to spread on the Spreadsheet component */
87
+ spreadsheetProps: SpreadsheetAdapterProps;
88
+ }
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Represents a single variant in an enum
3
+ */
4
+ export interface EnumVariant {
5
+ /** Unique identifier for this variant */
6
+ id: string;
7
+ /** The string value of this variant (must be unique within the enum) */
8
+ value: string;
9
+ /** Color associated with this variant (hex color code) */
10
+ color: string;
11
+ }
12
+ /**
13
+ * Represents a complete enum definition
14
+ */
15
+ export interface EnumInfo {
16
+ /** Unique identifier for this enum */
17
+ id: string;
18
+ /** Name of the enum */
19
+ name: string;
20
+ /** Description of the enum */
21
+ description?: string;
22
+ /** List of variants in this enum */
23
+ variants: EnumVariant[];
24
+ }
25
+ /**
26
+ * Manager for all enum sets in the application
27
+ * Ensures uniqueness of variant values within each enum
28
+ */
29
+ export declare class EnumSetManager {
30
+ constructor();
31
+ private enums;
32
+ /**
33
+ * Get an enum by its ID
34
+ * @param id The unique identifier of the enum
35
+ * @returns The EnumInfo if found, undefined otherwise
36
+ */
37
+ get(id: string): EnumInfo | undefined;
38
+ /**
39
+ * Get all registered enums
40
+ * @returns Array of all EnumInfo objects
41
+ */
42
+ getAll(): EnumInfo[];
43
+ /**
44
+ * Check if an enum exists
45
+ * @param id The unique identifier of the enum
46
+ * @returns true if the enum exists, false otherwise
47
+ */
48
+ has(id: string): boolean;
49
+ /**
50
+ * Register a new enum or update an existing one
51
+ * @param id The unique identifier for this enum
52
+ * @param name The name of the enum
53
+ * @param variants The list of variants
54
+ * @param description Optional description
55
+ * @throws Error if variant values are not unique within the enum
56
+ * @returns The created/updated EnumInfo
57
+ */
58
+ set(id: string, name: string, variants: EnumVariant[], description?: string): EnumInfo;
59
+ /**
60
+ * Update an existing enum
61
+ * @param id The unique identifier of the enum
62
+ */
63
+ update(id: string, info: EnumInfo): EnumInfo;
64
+ /**
65
+ * Add a variant to an existing enum
66
+ * @param enumId The ID of the enum
67
+ * @param variant The variant to add
68
+ * @throws Error if enum doesn't exist or variant value already exists
69
+ * @returns The updated EnumInfo
70
+ */
71
+ addVariant(enumId: string, variant: EnumVariant): EnumInfo;
72
+ /**
73
+ * Remove a variant from an enum
74
+ * @param enumId The ID of the enum
75
+ * @param variantId The ID of the variant to remove
76
+ * @throws Error if enum doesn't exist
77
+ * @returns The updated EnumInfo
78
+ */
79
+ removeVariant(enumId: string, variantId: string): EnumInfo;
80
+ /**
81
+ * Delete an enum
82
+ * @param id The unique identifier of the enum to delete
83
+ * @returns true if the enum was deleted, false if it didn't exist
84
+ */
85
+ delete(id: string): boolean;
86
+ /**
87
+ * Clear all enums
88
+ */
89
+ clear(): void;
90
+ /**
91
+ * Get the number of registered enums
92
+ * @returns The count of enums
93
+ */
94
+ count(): number;
95
+ /**
96
+ * Find enums by name (case-insensitive partial match)
97
+ * @param query The search query
98
+ * @returns Array of matching EnumInfo objects
99
+ */
100
+ search(query: string): EnumInfo[];
101
+ /**
102
+ * Validate that all variant values are unique within the list
103
+ * @param variants The list of variants to validate
104
+ * @throws Error if duplicate values are found
105
+ */
106
+ private validateVariantUniqueness;
107
+ /**
108
+ * Export all enums as JSON
109
+ * @returns JSON string representation of all enums
110
+ */
111
+ toJSON(): string;
112
+ /**
113
+ * Import enums from JSON
114
+ * @param json JSON string representation of enums
115
+ * @throws Error if JSON is invalid
116
+ */
117
+ fromJSON(json: string): void;
118
+ }
@@ -0,0 +1,236 @@
1
+ /**
2
+ * Represents a field's type and configuration
3
+ */
4
+ export type FieldTypeEnum = {
5
+ type: "enum";
6
+ id: string;
7
+ } | {
8
+ type: "multiSelect";
9
+ id: string;
10
+ } | {
11
+ type: "datetime";
12
+ formatter: string;
13
+ } | {
14
+ type: "boolean";
15
+ } | {
16
+ type: "string";
17
+ validation: string;
18
+ } | {
19
+ type: "number";
20
+ validation: string;
21
+ formatter: string;
22
+ } | {
23
+ type: "image";
24
+ }
25
+ /**
26
+ * Reference to another block's field. The dropdown options are pulled
27
+ * dynamically from the target block at render time. The validation
28
+ * formula carries an existence check so dangling refs surface as a
29
+ * warning indicator.
30
+ */
31
+ | {
32
+ type: "fieldRef";
33
+ sheetId: number;
34
+ blockId: number;
35
+ fieldName: string;
36
+ validation: string;
37
+ }
38
+ /**
39
+ * Reference to another block's field, picking multiple values. Storage
40
+ * is a comma-separated string in the cell. Renderer parses the string
41
+ * into a list and shows a multi-select dropdown sourced from the same
42
+ * (sheetId, blockId, fieldName) target as `fieldRef`. v1 does not
43
+ * auto-inject existence validation — dangling refs are not surfaced.
44
+ */
45
+ | {
46
+ type: "multiSelectRef";
47
+ sheetId: number;
48
+ blockId: number;
49
+ fieldName: string;
50
+ validation: string;
51
+ };
52
+ /**
53
+ * Represents a complete field definition
54
+ */
55
+ export interface FieldInfo {
56
+ /** Unique identifier for this field (cannot be changed or reused) */
57
+ id: string;
58
+ /** Sheet ID this field belongs to */
59
+ sheetId: number;
60
+ /** Block ID this field belongs to */
61
+ blockId: number;
62
+ /**
63
+ * Block-schema ref name (the `refName` passed to `bindFormSchema`).
64
+ * Optional because fields may be created before the schema is bound;
65
+ * the host fills this in once the bind happens.
66
+ */
67
+ refName?: string;
68
+ /** Name of the field */
69
+ name: string;
70
+ /** Type of the field */
71
+ type: FieldTypeEnum;
72
+ /** Optional description */
73
+ description?: string;
74
+ /** Whether this field is required */
75
+ required: boolean;
76
+ /**
77
+ * Whether this field's values must be unique within the block.
78
+ * Used by the composer to enumerate eligible target fields when
79
+ * configuring a `fieldRef` cell. The actual duplicate check is
80
+ * enforced by an auto-injected COUNTIF validation formula.
81
+ */
82
+ unique: boolean;
83
+ /** Default value */
84
+ defaultValue?: string;
85
+ /**
86
+ * Optional value-formula template for this field. When set, every row
87
+ * of the block carries a derived formula in this column rather than a
88
+ * free-form user value. Placeholders:
89
+ *
90
+ * `#FIELD("name")` → absolute A1 reference to the same row's cell
91
+ * in the named sibling field.
92
+ * `#KEY` → this row's key value, quoted as a string
93
+ * literal.
94
+ *
95
+ * Templated fields are constraints, not defaults — `userEditable` is
96
+ * forced to `false` by {@link FieldManager.create} when a template is
97
+ * present (the UI offers no edit affordance). Use
98
+ * {@link expandFieldFormula} to substitute the placeholders against a
99
+ * concrete row before writing into a cell.
100
+ */
101
+ valueFormula?: string;
102
+ /**
103
+ * Field-level write permission for the player (non-owner caller).
104
+ * Two shapes:
105
+ *
106
+ * - `boolean` — static decision evaluated synchronously by the host
107
+ * UI guard. `false` permanently locks the field's cells against
108
+ * player edits; `true` always allows.
109
+ * - `string` — a formula evaluated per cell. Same placeholders as
110
+ * `valueFormula` (`#FIELD("name")`, `#KEY`) plus `#PLACEHOLDER`
111
+ * (the cell being checked). At widget mount the host installs
112
+ * this formula onto a per-cell `UserEditable` shadow ephemeral
113
+ * (via `getShadowCellId({kind: 'userEditable'})` +
114
+ * `EphemeralCellInput`) — same machinery validation cells use —
115
+ * then subscribes to the shadow value and toggles the widget's
116
+ * read-only state accordingly.
117
+ * - `undefined` — fall back to block-owner rules (default behavior):
118
+ * only the owner of the block can write; if the block has no
119
+ * owner, anyone can write.
120
+ *
121
+ * The engine itself doesn't enforce this flag — boolean is host-UI
122
+ * only, and the string path piggy-backs on the engine's generic
123
+ * ephemeral-cell evaluator without any schema-side knowledge of
124
+ * "user editable" as a concept. The block owner is unaffected by
125
+ * either form; owners always retain write access.
126
+ */
127
+ userEditable?: boolean | string;
128
+ }
129
+ /**
130
+ * Manager for all fields in the application
131
+ * Ensures field IDs are unique and immutable
132
+ */
133
+ export declare class FieldManager {
134
+ private fields;
135
+ private _counter;
136
+ /**
137
+ * Generate a unique field ID
138
+ * @returns A unique field ID that will never be reused
139
+ */
140
+ private generateFieldId;
141
+ /**
142
+ * Create a new field
143
+ * @param sheetId The sheet ID
144
+ * @param blockId The block ID
145
+ * @param fieldData Field configuration (without id)
146
+ * @returns The created FieldInfo with generated ID
147
+ */
148
+ create(sheetId: number, blockId: number, fieldData: Omit<FieldInfo, "id" | "sheetId" | "blockId">): FieldInfo;
149
+ /**
150
+ * Get a field by its composite key
151
+ * @param fieldId The field ID
152
+ * @returns The FieldInfo if found, undefined otherwise
153
+ */
154
+ get(fieldId: string): FieldInfo | undefined;
155
+ /**
156
+ * Get all fields for a specific sheet and block
157
+ * @param sheetId The sheet ID
158
+ * @param blockId The block ID
159
+ * @returns Array of all FieldInfo objects for the block
160
+ */
161
+ getByBlock(sheetId: number, blockId: number): FieldInfo[];
162
+ /**
163
+ * Get all fields for a specific sheet
164
+ * @param sheetId The sheet ID
165
+ * @returns Array of all FieldInfo objects for the sheet
166
+ */
167
+ getBySheet(sheetId: number): FieldInfo[];
168
+ /**
169
+ * Get all fields
170
+ * @returns Array of all FieldInfo objects
171
+ */
172
+ getAll(): FieldInfo[];
173
+ /**
174
+ * Check if a field exists
175
+ * @param fieldId The field ID
176
+ * @returns true if the field exists, false otherwise
177
+ */
178
+ has(fieldId: string): boolean;
179
+ /**
180
+ * Update a field (ID cannot be changed)
181
+ * @param fieldId The field ID
182
+ * @param updates Partial field updates
183
+ * @returns The updated FieldInfo, or undefined if field not found
184
+ * @throws Error if attempting to change the field ID
185
+ */
186
+ update(fieldId: string, updates: Partial<Omit<FieldInfo, "id" | "sheetId" | "blockId">>): FieldInfo | undefined;
187
+ /**
188
+ * Set the schema ref-name on every field of a block. Call this right
189
+ * after the corresponding `bindFormSchema` payload — the host knows
190
+ * the refName at bind time, the field manager doesn't, so we stamp it
191
+ * onto every field belonging to the block.
192
+ */
193
+ setBlockRefName(sheetId: number, blockId: number, refName: string): void;
194
+ /**
195
+ * Delete a field
196
+ * @param fieldId The field ID
197
+ * @returns true if the field was deleted, false if it didn't exist
198
+ * @note The field ID will never be reused even after deletion
199
+ */
200
+ delete(fieldId: string): boolean;
201
+ /**
202
+ * Delete all fields for a specific block
203
+ * @param sheetId The sheet ID
204
+ * @param blockId The block ID
205
+ * @returns Number of fields deleted
206
+ */
207
+ deleteBlock(sheetId: number, blockId: number): number;
208
+ /**
209
+ * Delete all fields for a specific sheet
210
+ * @param sheetId The sheet ID
211
+ * @returns Number of fields deleted
212
+ */
213
+ deleteSheet(sheetId: number): number;
214
+ /**
215
+ * Clear all fields
216
+ * @note Field IDs remain reserved to prevent reuse
217
+ */
218
+ clear(): void;
219
+ /**
220
+ * Get the total number of fields
221
+ * @returns The count of fields
222
+ */
223
+ count(): number;
224
+ /**
225
+ * Search fields by name (case-insensitive partial match)
226
+ * @param query The search query
227
+ * @returns Array of matching FieldInfo objects
228
+ */
229
+ search(query: string): FieldInfo[];
230
+ /**
231
+ * Import fields from JSON
232
+ * @param json JSON string representation of fields
233
+ * @throws Error if JSON is invalid
234
+ */
235
+ fromJSON(json: string): void;
236
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Block management module - handles field definitions and enum sets for blocks.
3
+ */
4
+ export { BlockManager, LOGISHEETS_BUILTIN_CRAFT_ID, FIELD_AND_VALIDATION_TAG, } from "./manager";
5
+ export { EnumSetManager, type EnumInfo, type EnumVariant, } from "./enum_set_manager";
6
+ export { FieldManager, type FieldInfo, type FieldTypeEnum, } from "./field_manager";
7
+ export { expandFieldFormula, colIdxToLetters } from "./value_formula";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * BlockManager - manages block fields and enum sets for the spreadsheet engine.
3
+ * This is used to define custom field types and validations for blocks.
4
+ */
5
+ import type { BlockField } from "logisheets-web";
6
+ import { EnumSetManager } from "./enum_set_manager";
7
+ import { FieldManager } from "./field_manager";
8
+ import type { WorkbookClient } from "../clients/workbook";
9
+ export declare const LOGISHEETS_BUILTIN_CRAFT_ID = "logisheets";
10
+ export declare const FIELD_AND_VALIDATION_TAG = 80;
11
+ /**
12
+ * BlockManager is used to load and manage block-related data,
13
+ * including field definitions and enum sets.
14
+ *
15
+ * Block IDs, block ranges and craft URLs are supposed to be stored in the workbook file.
16
+ * And when the application starts, it will fetch the craft manifest from the URL, register it and bind the blocks.
17
+ */
18
+ export declare class BlockManager {
19
+ private readonly _workbookClient?;
20
+ constructor(_workbookClient?: WorkbookClient | undefined);
21
+ enumSetManager: EnumSetManager;
22
+ fieldManager: FieldManager;
23
+ getPersistentData(blockFields: readonly BlockField[]): string;
24
+ parseAppData(data: string): void;
25
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Field-level value-formula substitution.
3
+ *
4
+ * A field carries a `valueFormula` template on its FieldInfo. Templates
5
+ * use two placeholders:
6
+ *
7
+ * `#FIELD("name")` → absolute A1 reference to the same row's cell in
8
+ * the sibling field named `name`.
9
+ * `#KEY` → the row's key value, quoted as a string literal.
10
+ *
11
+ * Substitution is host-side: callers (block-composer's row-add path,
12
+ * block-interface's +Add Row handler, or any craft programmatically
13
+ * inserting rows) call {@link expandFieldFormula} to produce a concrete
14
+ * Excel formula, then write it via `blockInput` / `cellInput`.
15
+ *
16
+ * The engine itself sees only the resulting plain formula — A1 refs and
17
+ * BLOCKREF calls behave normally. Constraint enforcement (templated
18
+ * fields are uneditable) is handled by FieldManager + the block-interface
19
+ * widgets.
20
+ */
21
+ /** 0-based column index → Excel column letters: 0→A, 25→Z, 26→AA, … */
22
+ export declare function colIdxToLetters(col: number): string;
23
+ /**
24
+ * Substitute `#FIELD("name")` and `#KEY` placeholders in `template`
25
+ * against a concrete row of a block.
26
+ *
27
+ * - `fields` is the ordered list of field names occupying the block's
28
+ * columns (left-to-right). The Nth entry corresponds to absolute col
29
+ * `colStart + N`.
30
+ * - `sheetRowZero` is the 0-based absolute sheet row of this row.
31
+ * - `colStart` is the 0-based absolute sheet col of the block's first
32
+ * field (typically `BlockInfo.colStart`).
33
+ * - `key` is the row's key value as a string. The host substitutes it
34
+ * as a literal (with `"` doubled per Excel string escaping rules).
35
+ * Passing `""` is allowed when the key isn't known yet — `#KEY`
36
+ * becomes the empty string literal `""`.
37
+ *
38
+ * Throws if the template references a `#FIELD("X")` where `X` isn't in
39
+ * `fields`.
40
+ */
41
+ export declare function expandFieldFormula(params: {
42
+ template: string;
43
+ fields: readonly string[];
44
+ sheetRowZero: number;
45
+ colStart: number;
46
+ key: string;
47
+ }): string;
@@ -0,0 +1,3 @@
1
+ export { WorkbookClient } from "./workbook";
2
+ export { OffscreenClient } from "./offscreen";
3
+ export { DataService } from "./service";
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Offscreen Client - communicates with the worker for rendering operations.
3
+ */
4
+ import type { Grid, AppropriateHeight } from "$types/index";
5
+ import type { ErrorMessage } from "logisheets-web";
6
+ type Resp<T> = Promise<T | ErrorMessage>;
7
+ export declare class OffscreenClient {
8
+ private _worker;
9
+ private _resolvers;
10
+ private _rid;
11
+ constructor(worker: Worker);
12
+ init(canvas: OffscreenCanvas, dpr: number): Resp<void>;
13
+ render(sheetId: number, anchorX: number, anchorY: number): Resp<Grid>;
14
+ getAppropriateHeights(sheetId: number, anchorX: number, anchorY: number): Resp<readonly AppropriateHeight[]>;
15
+ resize(width: number, height: number, dpr: number): Resp<Grid>;
16
+ setLicense(apiKey: string, domain: string): Resp<{
17
+ valid: boolean;
18
+ reason?: string;
19
+ }>;
20
+ clearLicense(): void;
21
+ private _call;
22
+ }
23
+ export {};
@@ -0,0 +1,48 @@
1
+ /**
2
+ * DataService - main service for interacting with the spreadsheet engine.
3
+ * Combines WorkbookClient and OffscreenClient functionality.
4
+ */
5
+ import type { SheetInfo, SheetDimension, MergeCell, Transaction, ErrorMessage } from "logisheets-web";
6
+ import { Cell } from "logisheets-web";
7
+ import { WorkbookClient } from "./workbook";
8
+ import type { Grid } from "$types/index";
9
+ type Resp<T> = Promise<T | ErrorMessage>;
10
+ export declare class DataService {
11
+ private _workbook;
12
+ private _offscreen;
13
+ private _sheetInfos;
14
+ private _sheetIdx;
15
+ private _sheetId;
16
+ private _sheetUpdateCallback;
17
+ private _lastRender;
18
+ constructor(worker: Worker);
19
+ private _init;
20
+ render(sheetId: number, anchorX: number, anchorY: number): Resp<Grid>;
21
+ resize(width: number, height: number, dpr: number): Resp<Grid>;
22
+ initOffscreen(canvas: OffscreenCanvas): Resp<void>;
23
+ setLicense(apiKey: string): Resp<{
24
+ valid: boolean;
25
+ reason?: string;
26
+ }>;
27
+ clearLicense(): void;
28
+ loadWorkbook(buf: Uint8Array, name: string): Resp<Grid>;
29
+ setCurrentSheetIdx(idx: number): void;
30
+ getCurrentSheetIdx(): number;
31
+ getCurrentSheetId(): number;
32
+ getCurrentSheetName(): string;
33
+ getCacheAllSheetInfo(): readonly SheetInfo[];
34
+ getSheetDimension(sheetIdx: number): Resp<SheetDimension>;
35
+ getCellInfo(sheetIdx: number, row: number, col: number): Resp<Cell>;
36
+ getMergedCells(sheetIdx: number, targetStartRow: number, targetStartCol: number, targetEndRow: number, targetEndCol: number): Resp<readonly MergeCell[]>;
37
+ getAvailableBlockId(sheetIdx: number): Resp<number>;
38
+ checkFormula(formula: string): Promise<boolean>;
39
+ handleTransaction(transaction: Transaction, temp?: boolean): Resp<void>;
40
+ handleTransactionAndAdjustRowHeights(transaction: Transaction, onlyIncrease?: boolean, fromRowIdx?: number, toRowIdx?: number): Resp<void>;
41
+ undo(): Resp<void>;
42
+ redo(): Resp<void>;
43
+ getWorkbook(): WorkbookClient;
44
+ registerSheetUpdatedCallback(f: () => void): void;
45
+ registerCellUpdatedCallback(f: () => void, callbackId?: number): void;
46
+ registerHeaderUpdatedCallback(f: (sheetIdxes: readonly number[]) => void): void;
47
+ }
48
+ export {};