@stonecrop/atable 0.2.63 → 0.2.64

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/index.js CHANGED
@@ -1,16 +1,19 @@
1
+ import { createPinia } from 'pinia';
1
2
  import ACell from '@/components/ACell.vue';
2
3
  import AExpansionRow from '@/components/AExpansionRow.vue';
3
4
  import ARow from '@/components/ARow.vue';
4
5
  import ATable from '@/components/ATable.vue';
5
6
  import ATableHeader from '@/components/ATableHeader.vue';
6
7
  import ATableModal from '@/components/ATableModal.vue';
7
- import TableDataStore from './components';
8
+ export { createTableStore } from '@/stores/table';
8
9
  /**
9
10
  * Install all ATable components
10
11
  * @param app - Vue app instance
11
12
  * @public
12
13
  */
13
14
  function install(app /* options */) {
15
+ const pinia = createPinia();
16
+ app.use(pinia);
14
17
  app.component('ACell', ACell);
15
18
  app.component('AExpansionRow', AExpansionRow);
16
19
  app.component('ARow', ARow);
@@ -18,4 +21,4 @@ function install(app /* options */) {
18
21
  app.component('ATableHeader', ATableHeader);
19
22
  app.component('ATableModal', ATableModal);
20
23
  }
21
- export { install, ACell, AExpansionRow, ARow, ATable, ATableHeader, ATableModal, TableDataStore };
24
+ export { install, ACell, AExpansionRow, ARow, ATable, ATableHeader, ATableModal };
@@ -5,7 +5,7 @@ import ARow from '@/components/ARow.vue';
5
5
  import ATable from '@/components/ATable.vue';
6
6
  import ATableHeader from '@/components/ATableHeader.vue';
7
7
  import ATableModal from '@/components/ATableModal.vue';
8
- import TableDataStore from './components';
8
+ export { createTableStore } from '@/stores/table';
9
9
  export type { CellContext, TableColumn, TableConfig, TableDisplay, TableRow, TableModal } from '@/types';
10
10
  /**
11
11
  * Install all ATable components
@@ -13,5 +13,5 @@ export type { CellContext, TableColumn, TableConfig, TableDisplay, TableRow, Tab
13
13
  * @public
14
14
  */
15
15
  declare function install(app: App): void;
16
- export { install, ACell, AExpansionRow, ARow, ATable, ATableHeader, ATableModal, TableDataStore };
16
+ export { install, ACell, AExpansionRow, ARow, ATable, ATableHeader, ATableModal };
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,OAAO,KAAK,MAAM,wBAAwB,CAAA;AAC1C,OAAO,aAAa,MAAM,gCAAgC,CAAA;AAC1D,OAAO,IAAI,MAAM,uBAAuB,CAAA;AACxC,OAAO,MAAM,MAAM,yBAAyB,CAAA;AAC5C,OAAO,YAAY,MAAM,+BAA+B,CAAA;AACxD,OAAO,WAAW,MAAM,8BAA8B,CAAA;AACtD,OAAO,cAAc,MAAM,cAAc,CAAA;AACzC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAExG;;;;GAIG;AACH,iBAAS,OAAO,CAAC,GAAG,EAAE,GAAG,QAOxB;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,OAAO,KAAK,MAAM,wBAAwB,CAAA;AAC1C,OAAO,aAAa,MAAM,gCAAgC,CAAA;AAC1D,OAAO,IAAI,MAAM,uBAAuB,CAAA;AACxC,OAAO,MAAM,MAAM,yBAAyB,CAAA;AAC5C,OAAO,YAAY,MAAM,+BAA+B,CAAA;AACxD,OAAO,WAAW,MAAM,8BAA8B,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAExG;;;;GAIG;AACH,iBAAS,OAAO,CAAC,GAAG,EAAE,GAAG,QAUxB;AAED,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,CAAA"}
@@ -0,0 +1,320 @@
1
+ import { type CSSProperties } from 'vue';
2
+ import type { CellContext, TableColumn, TableConfig, TableDisplay, TableModal, TableRow } from '@/types';
3
+ export declare const createTableStore: (initData: {
4
+ columns: TableColumn[];
5
+ rows: TableRow[];
6
+ id?: string;
7
+ config?: TableConfig;
8
+ table?: {
9
+ [key: string]: any;
10
+ };
11
+ display?: TableDisplay[];
12
+ modal?: TableModal;
13
+ }) => import("pinia").Store<`table-${string}`, Pick<{
14
+ columns: import("vue").Ref<{
15
+ name: string;
16
+ align?: CanvasTextAlign;
17
+ edit?: boolean;
18
+ label?: string;
19
+ type?: string;
20
+ width?: string;
21
+ pinned?: boolean;
22
+ cellComponent?: string;
23
+ cellComponentProps?: Record<string, any>;
24
+ modalComponent?: string | ((context?: CellContext) => string);
25
+ modalComponentExtraProps?: Record<string, any>;
26
+ format?: string | ((value: any, context?: CellContext) => string);
27
+ mask?: (value: any) => any;
28
+ }[], TableColumn[] | {
29
+ name: string;
30
+ align?: CanvasTextAlign;
31
+ edit?: boolean;
32
+ label?: string;
33
+ type?: string;
34
+ width?: string;
35
+ pinned?: boolean;
36
+ cellComponent?: string;
37
+ cellComponentProps?: Record<string, any>;
38
+ modalComponent?: string | ((context?: CellContext) => string);
39
+ modalComponentExtraProps?: Record<string, any>;
40
+ format?: string | ((value: any, context?: CellContext) => string);
41
+ mask?: (value: any) => any;
42
+ }[]>;
43
+ rows: import("vue").Ref<{
44
+ [x: string]: any;
45
+ indent?: number;
46
+ parent?: number;
47
+ }[], TableRow[] | {
48
+ [x: string]: any;
49
+ indent?: number;
50
+ parent?: number;
51
+ }[]>;
52
+ config: import("vue").Ref<{
53
+ view?: "uncounted" | "list" | "list-expansion" | "tree";
54
+ fullWidth?: boolean;
55
+ }, TableConfig | {
56
+ view?: "uncounted" | "list" | "list-expansion" | "tree";
57
+ fullWidth?: boolean;
58
+ }>;
59
+ table: import("vue").Ref<{}, {}>;
60
+ display: import("vue").Ref<{
61
+ childrenOpen?: boolean;
62
+ expanded?: boolean;
63
+ indent?: number;
64
+ isParent?: boolean;
65
+ isRoot?: boolean;
66
+ open?: boolean;
67
+ parent?: number;
68
+ rowModified?: boolean;
69
+ }[], TableDisplay[] | {
70
+ childrenOpen?: boolean;
71
+ expanded?: boolean;
72
+ indent?: number;
73
+ isParent?: boolean;
74
+ isRoot?: boolean;
75
+ open?: boolean;
76
+ parent?: number;
77
+ rowModified?: boolean;
78
+ }[]>;
79
+ modal: import("vue").Ref<{
80
+ colIndex?: number;
81
+ event?: string;
82
+ left?: number;
83
+ parent?: HTMLElement;
84
+ rowIndex?: number;
85
+ top?: number;
86
+ visible?: boolean;
87
+ width?: string;
88
+ component?: string;
89
+ componentProps?: Record<string, any>;
90
+ }, TableModal | {
91
+ colIndex?: number;
92
+ event?: string;
93
+ left?: number;
94
+ parent?: HTMLElement;
95
+ rowIndex?: number;
96
+ top?: number;
97
+ visible?: boolean;
98
+ width?: string;
99
+ component?: string;
100
+ componentProps?: Record<string, any>;
101
+ }>;
102
+ hasPinnedColumns: import("vue").ComputedRef<boolean>;
103
+ numberedRowWidth: import("vue").ComputedRef<string>;
104
+ zeroColumn: import("vue").ComputedRef<boolean>;
105
+ closeModal: (event: MouseEvent) => void;
106
+ getCellData: <T = any>(colIndex: number, rowIndex: number) => T;
107
+ getCellDisplayValue: (colIndex: number, rowIndex: number) => any;
108
+ getFormattedValue: (colIndex: number, rowIndex: number, value: any) => any;
109
+ getHeaderCellStyle: (column: TableColumn) => CSSProperties;
110
+ getIndent: (colIndex: number, indentLevel?: number) => string;
111
+ getRowExpandSymbol: (rowIndex: number) => "" | "-" | "+";
112
+ isRowVisible: (rowIndex: number) => boolean;
113
+ setCellData: (colIndex: number, rowIndex: number, value: any) => void;
114
+ toggleRowExpand: (rowIndex: number) => void;
115
+ }, "columns" | "rows" | "config" | "table" | "display" | "modal">, Pick<{
116
+ columns: import("vue").Ref<{
117
+ name: string;
118
+ align?: CanvasTextAlign;
119
+ edit?: boolean;
120
+ label?: string;
121
+ type?: string;
122
+ width?: string;
123
+ pinned?: boolean;
124
+ cellComponent?: string;
125
+ cellComponentProps?: Record<string, any>;
126
+ modalComponent?: string | ((context?: CellContext) => string);
127
+ modalComponentExtraProps?: Record<string, any>;
128
+ format?: string | ((value: any, context?: CellContext) => string);
129
+ mask?: (value: any) => any;
130
+ }[], TableColumn[] | {
131
+ name: string;
132
+ align?: CanvasTextAlign;
133
+ edit?: boolean;
134
+ label?: string;
135
+ type?: string;
136
+ width?: string;
137
+ pinned?: boolean;
138
+ cellComponent?: string;
139
+ cellComponentProps?: Record<string, any>;
140
+ modalComponent?: string | ((context?: CellContext) => string);
141
+ modalComponentExtraProps?: Record<string, any>;
142
+ format?: string | ((value: any, context?: CellContext) => string);
143
+ mask?: (value: any) => any;
144
+ }[]>;
145
+ rows: import("vue").Ref<{
146
+ [x: string]: any;
147
+ indent?: number;
148
+ parent?: number;
149
+ }[], TableRow[] | {
150
+ [x: string]: any;
151
+ indent?: number;
152
+ parent?: number;
153
+ }[]>;
154
+ config: import("vue").Ref<{
155
+ view?: "uncounted" | "list" | "list-expansion" | "tree";
156
+ fullWidth?: boolean;
157
+ }, TableConfig | {
158
+ view?: "uncounted" | "list" | "list-expansion" | "tree";
159
+ fullWidth?: boolean;
160
+ }>;
161
+ table: import("vue").Ref<{}, {}>;
162
+ display: import("vue").Ref<{
163
+ childrenOpen?: boolean;
164
+ expanded?: boolean;
165
+ indent?: number;
166
+ isParent?: boolean;
167
+ isRoot?: boolean;
168
+ open?: boolean;
169
+ parent?: number;
170
+ rowModified?: boolean;
171
+ }[], TableDisplay[] | {
172
+ childrenOpen?: boolean;
173
+ expanded?: boolean;
174
+ indent?: number;
175
+ isParent?: boolean;
176
+ isRoot?: boolean;
177
+ open?: boolean;
178
+ parent?: number;
179
+ rowModified?: boolean;
180
+ }[]>;
181
+ modal: import("vue").Ref<{
182
+ colIndex?: number;
183
+ event?: string;
184
+ left?: number;
185
+ parent?: HTMLElement;
186
+ rowIndex?: number;
187
+ top?: number;
188
+ visible?: boolean;
189
+ width?: string;
190
+ component?: string;
191
+ componentProps?: Record<string, any>;
192
+ }, TableModal | {
193
+ colIndex?: number;
194
+ event?: string;
195
+ left?: number;
196
+ parent?: HTMLElement;
197
+ rowIndex?: number;
198
+ top?: number;
199
+ visible?: boolean;
200
+ width?: string;
201
+ component?: string;
202
+ componentProps?: Record<string, any>;
203
+ }>;
204
+ hasPinnedColumns: import("vue").ComputedRef<boolean>;
205
+ numberedRowWidth: import("vue").ComputedRef<string>;
206
+ zeroColumn: import("vue").ComputedRef<boolean>;
207
+ closeModal: (event: MouseEvent) => void;
208
+ getCellData: <T = any>(colIndex: number, rowIndex: number) => T;
209
+ getCellDisplayValue: (colIndex: number, rowIndex: number) => any;
210
+ getFormattedValue: (colIndex: number, rowIndex: number, value: any) => any;
211
+ getHeaderCellStyle: (column: TableColumn) => CSSProperties;
212
+ getIndent: (colIndex: number, indentLevel?: number) => string;
213
+ getRowExpandSymbol: (rowIndex: number) => "" | "-" | "+";
214
+ isRowVisible: (rowIndex: number) => boolean;
215
+ setCellData: (colIndex: number, rowIndex: number, value: any) => void;
216
+ toggleRowExpand: (rowIndex: number) => void;
217
+ }, "hasPinnedColumns" | "numberedRowWidth" | "zeroColumn">, Pick<{
218
+ columns: import("vue").Ref<{
219
+ name: string;
220
+ align?: CanvasTextAlign;
221
+ edit?: boolean;
222
+ label?: string;
223
+ type?: string;
224
+ width?: string;
225
+ pinned?: boolean;
226
+ cellComponent?: string;
227
+ cellComponentProps?: Record<string, any>;
228
+ modalComponent?: string | ((context?: CellContext) => string);
229
+ modalComponentExtraProps?: Record<string, any>;
230
+ format?: string | ((value: any, context?: CellContext) => string);
231
+ mask?: (value: any) => any;
232
+ }[], TableColumn[] | {
233
+ name: string;
234
+ align?: CanvasTextAlign;
235
+ edit?: boolean;
236
+ label?: string;
237
+ type?: string;
238
+ width?: string;
239
+ pinned?: boolean;
240
+ cellComponent?: string;
241
+ cellComponentProps?: Record<string, any>;
242
+ modalComponent?: string | ((context?: CellContext) => string);
243
+ modalComponentExtraProps?: Record<string, any>;
244
+ format?: string | ((value: any, context?: CellContext) => string);
245
+ mask?: (value: any) => any;
246
+ }[]>;
247
+ rows: import("vue").Ref<{
248
+ [x: string]: any;
249
+ indent?: number;
250
+ parent?: number;
251
+ }[], TableRow[] | {
252
+ [x: string]: any;
253
+ indent?: number;
254
+ parent?: number;
255
+ }[]>;
256
+ config: import("vue").Ref<{
257
+ view?: "uncounted" | "list" | "list-expansion" | "tree";
258
+ fullWidth?: boolean;
259
+ }, TableConfig | {
260
+ view?: "uncounted" | "list" | "list-expansion" | "tree";
261
+ fullWidth?: boolean;
262
+ }>;
263
+ table: import("vue").Ref<{}, {}>;
264
+ display: import("vue").Ref<{
265
+ childrenOpen?: boolean;
266
+ expanded?: boolean;
267
+ indent?: number;
268
+ isParent?: boolean;
269
+ isRoot?: boolean;
270
+ open?: boolean;
271
+ parent?: number;
272
+ rowModified?: boolean;
273
+ }[], TableDisplay[] | {
274
+ childrenOpen?: boolean;
275
+ expanded?: boolean;
276
+ indent?: number;
277
+ isParent?: boolean;
278
+ isRoot?: boolean;
279
+ open?: boolean;
280
+ parent?: number;
281
+ rowModified?: boolean;
282
+ }[]>;
283
+ modal: import("vue").Ref<{
284
+ colIndex?: number;
285
+ event?: string;
286
+ left?: number;
287
+ parent?: HTMLElement;
288
+ rowIndex?: number;
289
+ top?: number;
290
+ visible?: boolean;
291
+ width?: string;
292
+ component?: string;
293
+ componentProps?: Record<string, any>;
294
+ }, TableModal | {
295
+ colIndex?: number;
296
+ event?: string;
297
+ left?: number;
298
+ parent?: HTMLElement;
299
+ rowIndex?: number;
300
+ top?: number;
301
+ visible?: boolean;
302
+ width?: string;
303
+ component?: string;
304
+ componentProps?: Record<string, any>;
305
+ }>;
306
+ hasPinnedColumns: import("vue").ComputedRef<boolean>;
307
+ numberedRowWidth: import("vue").ComputedRef<string>;
308
+ zeroColumn: import("vue").ComputedRef<boolean>;
309
+ closeModal: (event: MouseEvent) => void;
310
+ getCellData: <T = any>(colIndex: number, rowIndex: number) => T;
311
+ getCellDisplayValue: (colIndex: number, rowIndex: number) => any;
312
+ getFormattedValue: (colIndex: number, rowIndex: number, value: any) => any;
313
+ getHeaderCellStyle: (column: TableColumn) => CSSProperties;
314
+ getIndent: (colIndex: number, indentLevel?: number) => string;
315
+ getRowExpandSymbol: (rowIndex: number) => "" | "-" | "+";
316
+ isRowVisible: (rowIndex: number) => boolean;
317
+ setCellData: (colIndex: number, rowIndex: number, value: any) => void;
318
+ toggleRowExpand: (rowIndex: number) => void;
319
+ }, "closeModal" | "getCellData" | "getCellDisplayValue" | "getFormattedValue" | "getHeaderCellStyle" | "getIndent" | "getRowExpandSymbol" | "isRowVisible" | "setCellData" | "toggleRowExpand">>;
320
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/stores/table.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,KAAK,CAAA;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAExG,eAAO,MAAM,gBAAgB,aAAc;IAC1C,OAAO,EAAE,WAAW,EAAE,CAAA;IACtB,IAAI,EAAE,QAAQ,EAAE,CAAA;IAChB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,KAAK,CAAC,EAAE;QAAE,CAAC,GAAG,EA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AAM,YAAY,MAAM;kCAK1B,MAAM,YAAY,MAAM,SAAS,GAAG;iCA3CrC,WAAW,KAAG,aAAa;0BA0ElC,MAAM,gBAAgB,MAAM;mCAhEnB,MAAM;6BAJZ,MAAM;4BAlBP,MAAM,YAAY,MAAM,SAAS,GAAG;gCAkChC,MAAM;gMAyF1C,CAAA"}
@@ -1,4 +1,3 @@
1
- import TableDataStore from '@/components';
2
1
  export type TableColumn = {
3
2
  name: string;
4
3
  align?: CanvasTextAlign;
@@ -17,7 +16,9 @@ export type TableColumn = {
17
16
  export type CellContext = {
18
17
  row: TableRow;
19
18
  column: TableColumn;
20
- table: TableDataStore['table'];
19
+ table: {
20
+ [key: string]: any;
21
+ };
21
22
  };
22
23
  export type TableConfig = {
23
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,cAAc,CAAA;AAEzC,MAAM,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,MAAM,CAAA;IAEZ,KAAK,CAAC,EAAE,eAAe,CAAA;IACvB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACxC,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,EAAE,WAAW,KAAK,MAAM,CAAC,CAAA;IAC7D,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAE9C,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,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AAA;IACvD,SAAS,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG;IAC1B,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,WAAW,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CACpC,CAAA"}
@@ -0,0 +1,174 @@
1
+ import { defineStore } from 'pinia';
2
+ import { computed, ref } from 'vue';
3
+ export const createTableStore = (initData) => {
4
+ const id = initData.id || crypto.randomUUID();
5
+ const createStore = defineStore(`table-${id}`, () => {
6
+ // util functions
7
+ const createTableObject = () => {
8
+ const table = {};
9
+ for (const [colIndex, column] of columns.value.entries()) {
10
+ for (const [rowIndex, row] of rows.value.entries()) {
11
+ table[`${colIndex}:${rowIndex}`] = row[column.name];
12
+ }
13
+ }
14
+ return table;
15
+ };
16
+ const createDisplayObject = (display) => {
17
+ const defaultDisplay = [Object.assign({}, { rowModified: false })];
18
+ // TODO: (typing) what is the type of `display` here?
19
+ if (display) {
20
+ if ('0:0' in display) {
21
+ return display;
22
+ }
23
+ // else if ('default' in display) {
24
+ // // TODO: (typing) what is the possible input here for 'default'?
25
+ // defaultDisplay = display.default
26
+ // }
27
+ }
28
+ // TODO: (typing) is this type correct for the parent set?
29
+ const parents = new Set();
30
+ for (let rowIndex = rows.value.length - 1; rowIndex >= 0; rowIndex--) {
31
+ const row = rows.value[rowIndex];
32
+ if (row.parent) {
33
+ parents.add(row.parent);
34
+ }
35
+ defaultDisplay[rowIndex] = {
36
+ childrenOpen: false,
37
+ expanded: false,
38
+ indent: row.indent || null,
39
+ isParent: parents.has(rowIndex),
40
+ isRoot: row.parent === null || row.parent === undefined,
41
+ rowModified: false,
42
+ open: row.parent === null || row.parent === undefined,
43
+ parent: row.parent,
44
+ };
45
+ }
46
+ return defaultDisplay;
47
+ };
48
+ // state
49
+ const columns = ref(initData.columns);
50
+ const rows = ref(initData.rows);
51
+ const config = ref(initData.config || {});
52
+ const table = ref(initData.table || createTableObject());
53
+ const display = ref(createDisplayObject(initData.display));
54
+ const modal = ref(initData.modal || { visible: false });
55
+ // getters
56
+ const hasPinnedColumns = computed(() => columns.value.some(col => col.pinned));
57
+ const numberedRowWidth = computed(() => {
58
+ const indent = Math.ceil(rows.value.length / 100 + 1);
59
+ return `${indent}ch`;
60
+ });
61
+ const zeroColumn = computed(() => ['list', 'tree', 'list-expansion'].includes(config.value.view));
62
+ // actions
63
+ const getCellData = (colIndex, rowIndex) => table.value[`${colIndex}:${rowIndex}`];
64
+ const setCellData = (colIndex, rowIndex, value) => {
65
+ const index = `${colIndex}:${rowIndex}`;
66
+ const col = columns.value[colIndex];
67
+ if (table.value[index] !== value) {
68
+ display.value[rowIndex].rowModified = true;
69
+ }
70
+ table.value[index] = value;
71
+ rows.value[rowIndex][col.name] = value;
72
+ };
73
+ const getHeaderCellStyle = (column) => ({
74
+ minWidth: column.width || '40ch',
75
+ textAlign: column.align || 'center',
76
+ width: config.value.fullWidth ? 'auto' : null,
77
+ });
78
+ const isRowVisible = (rowIndex) => {
79
+ return config.value.view !== 'tree' || display.value[rowIndex].isRoot || display.value[rowIndex].open;
80
+ };
81
+ const getRowExpandSymbol = (rowIndex) => {
82
+ if (config.value.view !== 'tree') {
83
+ return '';
84
+ }
85
+ if (display.value[rowIndex].isRoot || display.value[rowIndex].isParent) {
86
+ return display.value[rowIndex].childrenOpen ? '-' : '+';
87
+ }
88
+ return '';
89
+ };
90
+ const toggleRowExpand = (rowIndex) => {
91
+ if (config.value.view === 'tree') {
92
+ display.value[rowIndex].childrenOpen = !display.value[rowIndex].childrenOpen;
93
+ for (let index = rows.value.length - 1; index >= 0; index--) {
94
+ if (display.value[index].parent === rowIndex) {
95
+ display.value[index].open = !display.value[index].open;
96
+ if (display.value[index].childrenOpen) {
97
+ toggleRowExpand(index);
98
+ }
99
+ }
100
+ }
101
+ }
102
+ else if (config.value.view === 'list-expansion') {
103
+ display.value[rowIndex].expanded = !display.value[rowIndex].expanded;
104
+ }
105
+ };
106
+ const getCellDisplayValue = (colIndex, rowIndex) => {
107
+ const cellData = getCellData(colIndex, rowIndex);
108
+ return getFormattedValue(colIndex, rowIndex, cellData);
109
+ };
110
+ const getFormattedValue = (colIndex, rowIndex, value) => {
111
+ const column = columns.value[colIndex];
112
+ const row = rows.value[rowIndex];
113
+ const format = column.format;
114
+ if (!format) {
115
+ return value;
116
+ }
117
+ if (typeof format === 'function') {
118
+ return format(value, { table: table.value, row, column });
119
+ }
120
+ else if (typeof format === 'string') {
121
+ // parse format function from string
122
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
123
+ const formatFn = Function(`"use strict";return (${format})`)();
124
+ return formatFn(value, { table: table.value, row, column });
125
+ }
126
+ return value;
127
+ };
128
+ const closeModal = (event) => {
129
+ if (!(event.target instanceof Node)) {
130
+ // if the target is not a node, it's probably a custom click event to Document or Window
131
+ // err on the side of closing the modal in that case
132
+ if (modal.value.visible)
133
+ modal.value.visible = false;
134
+ }
135
+ else if (!modal.value.parent?.contains(event.target)) {
136
+ if (modal.value.visible)
137
+ modal.value.visible = false;
138
+ }
139
+ };
140
+ const getIndent = (colIndex, indentLevel) => {
141
+ if (indentLevel && colIndex === 0 && indentLevel > 0) {
142
+ return `${indentLevel}ch`;
143
+ }
144
+ else {
145
+ return 'inherit';
146
+ }
147
+ };
148
+ return {
149
+ // state
150
+ columns,
151
+ rows,
152
+ config,
153
+ table,
154
+ display,
155
+ modal,
156
+ // getters
157
+ hasPinnedColumns,
158
+ numberedRowWidth,
159
+ zeroColumn,
160
+ // actions
161
+ closeModal,
162
+ getCellData,
163
+ getCellDisplayValue,
164
+ getFormattedValue,
165
+ getHeaderCellStyle,
166
+ getIndent,
167
+ getRowExpandSymbol,
168
+ isRowVisible,
169
+ setCellData,
170
+ toggleRowExpand,
171
+ };
172
+ });
173
+ return createStore();
174
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stonecrop/atable",
3
- "version": "0.2.63",
3
+ "version": "0.2.64",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "author": {
@@ -36,9 +36,10 @@
36
36
  "dependencies": {
37
37
  "@vueuse/components": "^10.11.0",
38
38
  "@vueuse/core": "^11.1.0",
39
- "vue": "^3.5.6",
40
- "@stonecrop/themes": "0.2.63",
41
- "@stonecrop/utilities": "0.2.63"
39
+ "pinia": "^2.3.0",
40
+ "vue": "^3.5.11",
41
+ "@stonecrop/themes": "0.2.64",
42
+ "@stonecrop/utilities": "0.2.64"
42
43
  },
43
44
  "devDependencies": {
44
45
  "@microsoft/api-documenter": "^7.25.3",