@vnejs/module.controller.arrows.grid 0.2.2 → 0.2.3
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.d.ts +1 -2
- package/dist/index.js +13 -15
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +15 -17
- package/src/types.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare abstract class ModuleControllerArrowsGrid<TEvents extends ModuleC
|
|
|
5
5
|
abstract name: string;
|
|
6
6
|
abstract EVENT_SHOW: string;
|
|
7
7
|
abstract EVENT_HIDE: string;
|
|
8
|
-
abstract
|
|
8
|
+
abstract EVENT_UPDATE_STATE: string;
|
|
9
9
|
abstract EVENT_UPDATE_FAST: string;
|
|
10
10
|
abstract EVENT_GRID_NEXT: string;
|
|
11
11
|
abstract EVENT_GRID_PREV: string;
|
|
@@ -25,7 +25,6 @@ export declare abstract class ModuleControllerArrowsGrid<TEvents extends ModuleC
|
|
|
25
25
|
cachedGridIndex: number;
|
|
26
26
|
cachedGridsCount: number;
|
|
27
27
|
cachedItemsCount: number | null;
|
|
28
|
-
isShow: boolean;
|
|
29
28
|
abstract getMaxRows: () => number;
|
|
30
29
|
abstract getMaxColumns: () => number;
|
|
31
30
|
getItemsCount: () => number;
|
package/dist/index.js
CHANGED
|
@@ -14,25 +14,25 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
14
14
|
cachedGridIndex = 0;
|
|
15
15
|
cachedGridsCount = 1;
|
|
16
16
|
cachedItemsCount = null;
|
|
17
|
-
isShow = false;
|
|
18
17
|
getItemsCount = () => this.cachedItemsCount ?? this.getMaxRows() * this.getMaxColumns();
|
|
19
18
|
getCurrentGridIndex = () => this.cachedGridIndex;
|
|
20
19
|
getGridsCount = () => this.cachedGridsCount;
|
|
21
20
|
getGridItemsCount = (gridItems = []) => gridItems.filter((item) => !item?.isStub).length;
|
|
22
21
|
subscribe = () => {
|
|
23
|
-
|
|
24
|
-
this.on(this.
|
|
25
|
-
this.on(this.
|
|
22
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
23
|
+
this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
|
|
24
|
+
this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
|
|
25
|
+
this.on(this.EVENT_UPDATE_STATE, this.onStateUpdate);
|
|
26
26
|
this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
|
|
27
27
|
if (this.EVENT_GRID_UPDATE_ITEMS)
|
|
28
28
|
this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
|
|
29
29
|
};
|
|
30
|
-
getDefaultState = () => ({});
|
|
30
|
+
getDefaultState = () => ({ isShow: false });
|
|
31
31
|
getGridItems = async () => [];
|
|
32
32
|
onGridClear = () => {
|
|
33
33
|
this.gridRow = null;
|
|
34
34
|
this.gridColumn = null;
|
|
35
|
-
return this.emit(this.
|
|
35
|
+
return this.emit(this.EVENT_UPDATE_STATE, {
|
|
36
36
|
gridRow: null,
|
|
37
37
|
gridColumn: null,
|
|
38
38
|
});
|
|
@@ -40,7 +40,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
40
40
|
onGridUpdateItems = async () => {
|
|
41
41
|
const gridItems = await this.getGridItems();
|
|
42
42
|
this.cachedItemsCount = this.getGridItemsCount(gridItems);
|
|
43
|
-
await this.emit(this.
|
|
43
|
+
await this.emit(this.EVENT_UPDATE_STATE, { gridItems });
|
|
44
44
|
this.snapSelectionToGrid();
|
|
45
45
|
};
|
|
46
46
|
findNearestValidCell = (row, column) => {
|
|
@@ -80,9 +80,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
80
80
|
this.emitPosition();
|
|
81
81
|
};
|
|
82
82
|
onShow = () => {
|
|
83
|
-
|
|
84
|
-
return;
|
|
85
|
-
this.isShow = true;
|
|
83
|
+
this.updateState({ isShow: true });
|
|
86
84
|
this.gridRow = null;
|
|
87
85
|
this.gridColumn = null;
|
|
88
86
|
return this.emit(this.EVENTS.CONTROLS.PUSH, {
|
|
@@ -93,9 +91,9 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
93
91
|
});
|
|
94
92
|
};
|
|
95
93
|
onHide = () => {
|
|
96
|
-
if (!this.isShow)
|
|
94
|
+
if (!this.state.isShow)
|
|
97
95
|
return;
|
|
98
|
-
this.isShow
|
|
96
|
+
this.updateState({ isShow: false });
|
|
99
97
|
this.gridRow = null;
|
|
100
98
|
this.gridColumn = null;
|
|
101
99
|
return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
|
|
@@ -128,7 +126,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
128
126
|
hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
|
|
129
127
|
hasPrevGrid = () => this.getCurrentGridIndex() > 0;
|
|
130
128
|
emitPosition = () => {
|
|
131
|
-
this.emit(this.
|
|
129
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
132
130
|
gridRow: this.gridRow,
|
|
133
131
|
gridColumn: this.gridColumn,
|
|
134
132
|
});
|
|
@@ -139,7 +137,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
139
137
|
return;
|
|
140
138
|
this.gridRow = nextRow;
|
|
141
139
|
this.gridColumn = nextColumn;
|
|
142
|
-
this.emit(this.
|
|
140
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
143
141
|
gridRow: this.gridRow,
|
|
144
142
|
gridColumn: this.gridColumn,
|
|
145
143
|
});
|
|
@@ -150,7 +148,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
150
148
|
return;
|
|
151
149
|
this.gridRow = nextRow;
|
|
152
150
|
this.gridColumn = nextColumn;
|
|
153
|
-
this.emit(this.
|
|
151
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
154
152
|
gridRow: this.gridRow,
|
|
155
153
|
gridColumn: this.gridColumn,
|
|
156
154
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export type ModuleControllerArrowsGridConstants = ModuleCoreConstants & Record<C
|
|
|
5
5
|
export type ModuleControllerArrowsGridSettings = ModuleCoreSettings;
|
|
6
6
|
export type ModuleControllerArrowsGridParams = ModuleCoreParams;
|
|
7
7
|
export type ModuleControllerArrowsGridState = {
|
|
8
|
+
isShow: boolean;
|
|
8
9
|
gridRow?: number | null;
|
|
9
10
|
gridColumn?: number | null;
|
|
10
11
|
gridIndex?: number;
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -28,7 +28,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
28
28
|
|
|
29
29
|
abstract EVENT_SHOW: string;
|
|
30
30
|
abstract EVENT_HIDE: string;
|
|
31
|
-
abstract
|
|
31
|
+
abstract EVENT_UPDATE_STATE: string;
|
|
32
32
|
abstract EVENT_UPDATE_FAST: string;
|
|
33
33
|
abstract EVENT_GRID_NEXT: string;
|
|
34
34
|
abstract EVENT_GRID_PREV: string;
|
|
@@ -54,8 +54,6 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
54
54
|
cachedGridsCount = 1;
|
|
55
55
|
cachedItemsCount: number | null = null;
|
|
56
56
|
|
|
57
|
-
isShow = false;
|
|
58
|
-
|
|
59
57
|
abstract getMaxRows: () => number;
|
|
60
58
|
abstract getMaxColumns: () => number;
|
|
61
59
|
|
|
@@ -66,14 +64,16 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
66
64
|
getGridItemsCount = (gridItems: unknown[] = []) => gridItems.filter((item) => !(item as { isStub?: boolean } | null | undefined)?.isStub).length;
|
|
67
65
|
|
|
68
66
|
subscribe = () => {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.on(this.
|
|
67
|
+
const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
68
|
+
|
|
69
|
+
this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
|
|
70
|
+
this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
|
|
71
|
+
this.on(this.EVENT_UPDATE_STATE, this.onStateUpdate);
|
|
72
72
|
this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
|
|
73
73
|
if (this.EVENT_GRID_UPDATE_ITEMS) this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
|
|
74
74
|
};
|
|
75
75
|
|
|
76
|
-
getDefaultState = (): TState => ({}) as TState;
|
|
76
|
+
getDefaultState = (): TState => ({ isShow: false }) as TState;
|
|
77
77
|
|
|
78
78
|
getGridItems = async (): Promise<unknown[]> => [];
|
|
79
79
|
|
|
@@ -81,7 +81,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
81
81
|
this.gridRow = null;
|
|
82
82
|
this.gridColumn = null;
|
|
83
83
|
|
|
84
|
-
return this.emit(this.
|
|
84
|
+
return this.emit(this.EVENT_UPDATE_STATE, {
|
|
85
85
|
gridRow: null,
|
|
86
86
|
gridColumn: null,
|
|
87
87
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
|
@@ -91,7 +91,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
91
91
|
const gridItems = await this.getGridItems();
|
|
92
92
|
this.cachedItemsCount = this.getGridItemsCount(gridItems);
|
|
93
93
|
|
|
94
|
-
await this.emit(this.
|
|
94
|
+
await this.emit(this.EVENT_UPDATE_STATE, { gridItems } satisfies Partial<ModuleControllerArrowsGridState>);
|
|
95
95
|
this.snapSelectionToGrid();
|
|
96
96
|
};
|
|
97
97
|
|
|
@@ -136,9 +136,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
136
136
|
};
|
|
137
137
|
|
|
138
138
|
onShow = () => {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.isShow = true;
|
|
139
|
+
this.updateState({ isShow: true } as Partial<TState>);
|
|
142
140
|
this.gridRow = null;
|
|
143
141
|
this.gridColumn = null;
|
|
144
142
|
|
|
@@ -151,9 +149,9 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
151
149
|
};
|
|
152
150
|
|
|
153
151
|
onHide = () => {
|
|
154
|
-
if (!this.isShow) return;
|
|
152
|
+
if (!this.state.isShow) return;
|
|
155
153
|
|
|
156
|
-
this.isShow
|
|
154
|
+
this.updateState({ isShow: false } as Partial<TState>);
|
|
157
155
|
this.gridRow = null;
|
|
158
156
|
this.gridColumn = null;
|
|
159
157
|
|
|
@@ -189,7 +187,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
189
187
|
hasPrevGrid = () => this.getCurrentGridIndex() > 0;
|
|
190
188
|
|
|
191
189
|
emitPosition = () => {
|
|
192
|
-
this.emit(this.
|
|
190
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
193
191
|
gridRow: this.gridRow,
|
|
194
192
|
gridColumn: this.gridColumn,
|
|
195
193
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
|
@@ -201,7 +199,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
201
199
|
|
|
202
200
|
this.gridRow = nextRow;
|
|
203
201
|
this.gridColumn = nextColumn;
|
|
204
|
-
this.emit(this.
|
|
202
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
205
203
|
gridRow: this.gridRow,
|
|
206
204
|
gridColumn: this.gridColumn,
|
|
207
205
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
|
@@ -213,7 +211,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
213
211
|
|
|
214
212
|
this.gridRow = nextRow;
|
|
215
213
|
this.gridColumn = nextColumn;
|
|
216
|
-
this.emit(this.
|
|
214
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
217
215
|
gridRow: this.gridRow,
|
|
218
216
|
gridColumn: this.gridColumn,
|
|
219
217
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
package/src/types.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type ModuleControllerArrowsGridSettings = ModuleCoreSettings;
|
|
|
10
10
|
export type ModuleControllerArrowsGridParams = ModuleCoreParams;
|
|
11
11
|
|
|
12
12
|
export type ModuleControllerArrowsGridState = {
|
|
13
|
+
isShow: boolean;
|
|
13
14
|
gridRow?: number | null;
|
|
14
15
|
gridColumn?: number | null;
|
|
15
16
|
gridIndex?: number;
|