@gridsheet/preact-core 2.0.0-rc.0 → 2.0.0-rc.2

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 ADDED
@@ -0,0 +1,79 @@
1
+ # @gridsheet/preact-core
2
+
3
+ Spreadsheet component for Preact
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @gridsheet/preact-core
9
+ ```
10
+
11
+ ## Peer Dependencies
12
+
13
+ This package requires the following peer dependencies:
14
+
15
+ - `preact` ^10.26.6
16
+ - `dayjs` ^1.11.13
17
+
18
+ ## Usage
19
+
20
+ ### Basic Preact Component
21
+
22
+ ```tsx
23
+ import { GridSheet } from '@gridsheet/preact-core';
24
+
25
+ // Your Preact component
26
+ function App() {
27
+ return (
28
+ <GridSheet />
29
+ );
30
+ }
31
+
32
+ render(<App />, document.getElementById('app'));
33
+ ```
34
+
35
+ ### Vanilla JavaScript Integration
36
+
37
+ ```javascript
38
+ import { GridSheet, h, render } from '@gridsheet/preact-core';
39
+
40
+ // Create a container element
41
+ const container = document.getElementById('gridsheet');
42
+
43
+ // Render GridSheet directly
44
+ render(
45
+ h(GridSheet, {
46
+ initialCells: {
47
+ A1: { value: 'Hello' },
48
+ B1: { value: 'Vanilla JS', style: { backgroundColor: '#448888'} },
49
+ A2: { value: 123 },
50
+ B2: { value: 456 },
51
+ C10: { value: '=SUM(A2:B2)' },
52
+ },
53
+ options: {
54
+ mode: 'dark',
55
+ },
56
+ sheetName: 'Sheet1'
57
+ }),
58
+ container
59
+ );
60
+ ```
61
+
62
+ ## Exports
63
+
64
+ This package exports all the core GridSheet functionality along with Preact compatibility layer. It includes:
65
+
66
+ - All React compatibility exports from `preact/compat`
67
+ - Core GridSheet components and utilities
68
+ - Preact-specific exports (`h`, `render`)
69
+
70
+ ## Development
71
+
72
+ ```bash
73
+ # Build the package
74
+ pnpm build
75
+ ```
76
+
77
+ ## License
78
+
79
+ Apache-2.0
@@ -1,3 +1,3 @@
1
1
  import { Props } from '../types';
2
- export declare function GridSheet({ initialCells, sheetName, tableRef, options, className, style, hubReactive: initialHubReactive, }: Props): JSX.Element;
2
+ export declare function GridSheet({ initialCells, sheetName, tableRef, storeRef, options, className, style, hub: initialHub, }: Props): JSX.Element;
3
3
  //# sourceMappingURL=GridSheet.d.ts.map
@@ -1,8 +1,11 @@
1
- import { FC } from 'react';
2
- import { OptionsType } from '../types';
1
+ import { FC, MutableRefObject } from 'react';
2
+ import { OptionsType, StoreRef } from '../types';
3
3
  type StoreInitializerProps = OptionsType & {
4
4
  sheetName?: string;
5
+ storeRef?: MutableRefObject<StoreRef | null>;
5
6
  };
7
+ export declare const createStoreRef: () => import('react').RefObject<StoreRef | null>;
8
+ export declare const useStoreRef: () => MutableRefObject<StoreRef | null>;
6
9
  export declare const StoreObserver: FC<StoreInitializerProps>;
7
10
  export {};
8
11
  //# sourceMappingURL=StoreObserver.d.ts.map
@@ -2,7 +2,8 @@ import { TableRef } from '../types';
2
2
  type Props = {
3
3
  tableRef: React.MutableRefObject<TableRef | null> | undefined;
4
4
  };
5
- export declare const createTableRef: () => import('react').MutableRefObject<TableRef | null>;
5
+ export declare const createTableRef: () => import('react').RefObject<TableRef | null>;
6
+ export declare const useTableRef: () => import('react').MutableRefObject<TableRef | null>;
6
7
  export declare const Tabular: ({ tableRef }: Props) => JSX.Element | null;
7
8
  export {};
8
9
  //# sourceMappingURL=Tabular.d.ts.map
@@ -1,8 +1,22 @@
1
1
  import { Table } from '../lib/table';
2
- import { PointType } from '../types';
2
+ import { Id, PointType } from '../types';
3
3
  type EvaluateProps = {
4
4
  table: Table;
5
5
  };
6
+ export type IdentifyProps = {
7
+ table: Table;
8
+ slideY?: number;
9
+ slideX?: number;
10
+ dependency: string;
11
+ idMap?: {
12
+ [id: string]: string;
13
+ };
14
+ };
15
+ export type DisplayProps = {
16
+ table: Table;
17
+ slideY?: number;
18
+ slideX?: number;
19
+ };
6
20
  export declare class FormulaError {
7
21
  code: string;
8
22
  message: string;
@@ -26,24 +40,24 @@ export declare class RefEntity extends Entity<string> {
26
40
  constructor(value: string);
27
41
  stringify(): string;
28
42
  evaluate({ table }: EvaluateProps): Table;
29
- id(table: Table, paths: string[], slideY?: number, slideX?: number): string;
43
+ identify({ table, dependency, slideY, slideX }: IdentifyProps): string;
30
44
  }
31
45
  export declare class RangeEntity extends Entity<string> {
32
46
  stringify(): string;
33
47
  evaluate({ table }: EvaluateProps): Table;
34
- idRange(table: Table, paths: string[], slideY?: number, slideX?: number): string;
48
+ identify({ table, dependency, slideY, slideX }: IdentifyProps): string;
35
49
  }
36
50
  export declare class IdEntity extends Entity<string> {
37
51
  private parse;
38
52
  evaluate({ table }: EvaluateProps): Table;
39
- ref(table: Table, slideY?: number, slideX?: number): string;
40
- slide(table: Table, slideY?: number, slideX?: number): string;
53
+ display({ table, slideY, slideX }: DisplayProps): string;
54
+ identify({ table, dependency, slideX, slideY }: IdentifyProps): string;
41
55
  }
42
56
  export declare class IdRangeEntity extends Entity<string> {
43
57
  private parse;
44
58
  evaluate({ table }: EvaluateProps): Table;
45
- range(table: Table, slideY?: number, slideX?: number): string;
46
- slide(table: Table, slideY?: number, slideX?: number): string | undefined;
59
+ display({ table, slideY, slideX }: DisplayProps): string;
60
+ identify({ table, dependency, slideY, slideX }: IdentifyProps): string | undefined;
47
61
  }
48
62
  export declare class FunctionEntity {
49
63
  args: Expression[];
@@ -67,6 +81,9 @@ export declare class Token {
67
81
  }
68
82
  type LexerOption = {
69
83
  origin?: PointType;
84
+ idMap?: {
85
+ [id: Id]: Id;
86
+ };
70
87
  };
71
88
  export declare class Lexer {
72
89
  private index;
@@ -74,6 +91,7 @@ export declare class Lexer {
74
91
  tokens: Token[];
75
92
  foreign: boolean;
76
93
  private origin?;
94
+ private idMap;
77
95
  constructor(formula: string, options?: LexerOption);
78
96
  private isWhiteSpace;
79
97
  private next;
@@ -82,11 +100,12 @@ export declare class Lexer {
82
100
  getTokenIndexByCharPosition(pos: number): [number, boolean];
83
101
  getTokenPositionRange(index: number, slide?: number): [number, number];
84
102
  stringify(): string;
85
- stringifyToId(table: Table, slideY?: number, slideX?: number): [string, string[]];
86
- stringifyToRef(table: Table): string;
103
+ identify(props: IdentifyProps): string;
104
+ display({ table }: DisplayProps): string;
87
105
  tokenize(): void;
88
106
  private skipSpaces;
89
107
  private getString;
108
+ private resolveIdRange;
90
109
  }
91
110
  export declare class Parser {
92
111
  index: number;
@@ -96,13 +115,7 @@ export declare class Parser {
96
115
  build(): Expression | undefined;
97
116
  private parse;
98
117
  }
99
- export declare const identifyFormula: ({ value, table, originPath, slideY, slideX, }: {
100
- value: any;
101
- table: Table;
102
- originPath: string;
103
- slideY?: number;
104
- slideX?: number;
105
- }) => any;
118
+ export declare const identifyFormula: (value: any, { idMap, ...props }: IdentifyProps) => any;
106
119
  export declare const stripSheetName: (sheetName: string) => string;
107
120
  export declare function splitRef(ref: string): {
108
121
  sheetName: string | undefined;
@@ -4,9 +4,12 @@ export declare const lt: (left: any, right: any) => boolean;
4
4
  export declare const lte: (left: any, right: any) => boolean;
5
5
  export declare const eq: (left: any, right: any) => boolean;
6
6
  export declare const ne: (left: any, right: any) => boolean;
7
- export declare const ensureNumber: (value: any, alternative?: number) => number;
7
+ export type EnsureNumberOptions = {
8
+ alternative?: number;
9
+ ignore?: boolean;
10
+ };
11
+ export declare const ensureNumber: (value: any, options?: EnsureNumberOptions) => number;
8
12
  export declare const ensureString: (value: any) => string;
9
13
  export declare const ensureBoolean: (value: any, alternative?: boolean) => boolean;
10
- export declare const stripTable: (value: any, y?: number, x?: number) => any;
11
14
  export declare const check: (value: any, condition: string) => boolean;
12
15
  //# sourceMappingURL=__utils.d.ts.map
@@ -8,6 +8,6 @@ export declare class AddFunction extends BaseFunction {
8
8
  description: string;
9
9
  }[];
10
10
  protected validate(): void;
11
- protected main(v1: number | Date | TimeDelta, v2: number | Date | TimeDelta): number | Date | TimeDelta;
11
+ protected main(v1: number | Date | TimeDelta, v2: number | Date | TimeDelta): number | Date;
12
12
  }
13
13
  //# sourceMappingURL=add.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { Table } from '../../lib/table';
2
+ import { BaseFunction } from './__base';
3
+ export declare class IndexFunction extends BaseFunction {
4
+ example: string;
5
+ helpText: string[];
6
+ helpArgs: ({
7
+ name: string;
8
+ description: string;
9
+ optional?: undefined;
10
+ } | {
11
+ name: string;
12
+ description: string;
13
+ optional: boolean;
14
+ })[];
15
+ protected validate(): void;
16
+ protected main(table: Table, y?: number, x?: number): Table;
17
+ }
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ import { Table } from '../../lib/table';
2
+ import { BaseFunction } from './__base';
3
+ export declare class MatchFunction extends BaseFunction {
4
+ example: string;
5
+ helpText: string[];
6
+ helpArgs: ({
7
+ name: string;
8
+ description: string;
9
+ optional?: undefined;
10
+ } | {
11
+ name: string;
12
+ description: string;
13
+ optional: boolean;
14
+ })[];
15
+ protected validate(): void;
16
+ protected main(searchKey: any, range: Table, searchType?: number): number;
17
+ }
18
+ //# sourceMappingURL=match.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=match.test.d.ts.map
@@ -1,16 +1,19 @@
1
1
  import { Table } from '../lib/table';
2
- import { MatrixType, PointType } from '../types';
3
- type SolveFormulaType = {
2
+ import { MatrixType, PointType, RefEvaluation } from '../types';
3
+ type SolveFormulaProps = {
4
4
  value: any;
5
5
  table: Table;
6
6
  raise?: boolean;
7
- evaluates?: boolean | null;
8
- origin?: PointType;
7
+ refEvaluation?: RefEvaluation;
8
+ origin: PointType;
9
9
  };
10
- export declare const solveFormula: ({ value, table, raise, evaluates, origin }: SolveFormulaType) => any;
11
- export declare const solveTable: ({ table, raise }: {
10
+ export declare const solveFormula: ({ value, table, raise, refEvaluation, origin }: SolveFormulaProps) => any;
11
+ type SolveTableProps = {
12
12
  table: Table;
13
13
  raise?: boolean;
14
- }) => MatrixType;
14
+ refEvaluation?: RefEvaluation;
15
+ };
16
+ export declare const solveTable: ({ table, raise }: SolveTableProps) => MatrixType;
17
+ export declare const stripTable: (value: any, y?: number, x?: number, raise?: boolean) => any;
15
18
  export {};
16
19
  //# sourceMappingURL=solver.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { GridSheet } from './components/GridSheet';
2
- export { createTableRef } from './components/Tabular';
2
+ export { useTableRef, createTableRef } from './components/Tabular';
3
+ export { useStoreRef, createStoreRef } from './components/StoreObserver';
3
4
  export { Renderer } from './renderers/core';
4
5
  export type { RendererMixinType, RendererCallProps, RenderProps } from './renderers/core';
5
6
  export { Parser } from './parsers/core';
@@ -9,18 +10,22 @@ export { TimeDelta } from './lib/time';
9
10
  export { x2c, c2x, y2r, r2y, p2a, a2p } from './lib/converters';
10
11
  export { updateTable } from './store/actions';
11
12
  export { PluginBase, useInitialPluginContext, usePluginContext } from './components/PluginBase';
12
- export type { MatrixType, CellType, FeedbackType, OptionsType, WriterType, CellsByAddressType, CellsByIdType, ModeType, HeadersType, HistoryType, StoreType, PointType, AreaType, ZoneType, Props, TableRef, HubPatchType, } from './types';
13
- export type { HubReactiveType } from './lib/hub';
14
- export { Hub, useHubReactive, createHubReactive } from './lib/hub';
13
+ export type { MatrixType, CellType, FeedbackType, OptionsType, WriterType, CellsByAddressType, CellsByIdType, ModeType, HeadersType, HistoryType, StoreType, PointType, AreaType, ZoneType, Props, TableRef, } from './types';
14
+ export type { HubType, WireProps, TransmitProps } from './lib/hub';
15
+ export { Wire, useHub, createHub } from './lib/hub';
15
16
  export type { Dispatcher } from './store';
16
17
  export { ThousandSeparatorRendererMixin } from './renderers/thousand_separator';
17
18
  export { CheckboxRendererMixin } from './renderers/checkbox';
18
19
  export { BaseFunction } from './formula/functions/__base';
20
+ export { FormulaError } from './formula/evaluator';
19
21
  export { Table } from './lib/table';
20
22
  export { Policy } from './policy/core';
21
23
  export type { PolicyType, PolicyOption, PolicyMixinType } from './policy/core';
22
24
  export * as operations from './lib/operation';
23
25
  export { DEFAULT_HISTORY_LIMIT } from './constants';
26
+ export { userActions } from './store/actions';
27
+ export { clip } from './lib/clipboard';
28
+ export { makeBorder } from './styles/utils';
24
29
  //# sourceMappingURL=index.d.ts.map
25
30
  export { h, render } from "preact";
26
31
  export {