@vnejs/module.controller.arrows.grid 0.2.1 → 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 +4 -4
- package/dist/index.js +14 -9
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/index.ts +16 -10
- 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;
|
|
@@ -34,15 +34,15 @@ export declare abstract class ModuleControllerArrowsGrid<TEvents extends ModuleC
|
|
|
34
34
|
subscribe: () => void;
|
|
35
35
|
getDefaultState: () => TState;
|
|
36
36
|
getGridItems: () => Promise<unknown[]>;
|
|
37
|
-
onGridClear: () => Promise<
|
|
37
|
+
onGridClear: () => Promise<import("@vnejs/shared").EmitResults<string>> | undefined;
|
|
38
38
|
onGridUpdateItems: () => Promise<void>;
|
|
39
39
|
findNearestValidCell: (row: number, column: number) => {
|
|
40
40
|
row: number;
|
|
41
41
|
column: number;
|
|
42
42
|
} | null;
|
|
43
43
|
snapSelectionToGrid: () => void;
|
|
44
|
-
onShow: () => Promise<
|
|
45
|
-
onHide: () => Promise<
|
|
44
|
+
onShow: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:push">> | undefined;
|
|
45
|
+
onHide: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:pop">> | undefined;
|
|
46
46
|
onStateUpdate: (payload?: Partial<TState>) => void;
|
|
47
47
|
initRowAndColumns: () => void;
|
|
48
48
|
isCellInGrid: (row: number, column: number) => boolean;
|
package/dist/index.js
CHANGED
|
@@ -19,19 +19,20 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
19
19
|
getGridsCount = () => this.cachedGridsCount;
|
|
20
20
|
getGridItemsCount = (gridItems = []) => gridItems.filter((item) => !item?.isStub).length;
|
|
21
21
|
subscribe = () => {
|
|
22
|
-
|
|
23
|
-
this.on(this.
|
|
24
|
-
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);
|
|
25
26
|
this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
|
|
26
27
|
if (this.EVENT_GRID_UPDATE_ITEMS)
|
|
27
28
|
this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
|
|
28
29
|
};
|
|
29
|
-
getDefaultState = () => ({});
|
|
30
|
+
getDefaultState = () => ({ isShow: false });
|
|
30
31
|
getGridItems = async () => [];
|
|
31
32
|
onGridClear = () => {
|
|
32
33
|
this.gridRow = null;
|
|
33
34
|
this.gridColumn = null;
|
|
34
|
-
return this.emit(this.
|
|
35
|
+
return this.emit(this.EVENT_UPDATE_STATE, {
|
|
35
36
|
gridRow: null,
|
|
36
37
|
gridColumn: null,
|
|
37
38
|
});
|
|
@@ -39,7 +40,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
39
40
|
onGridUpdateItems = async () => {
|
|
40
41
|
const gridItems = await this.getGridItems();
|
|
41
42
|
this.cachedItemsCount = this.getGridItemsCount(gridItems);
|
|
42
|
-
await this.emit(this.
|
|
43
|
+
await this.emit(this.EVENT_UPDATE_STATE, { gridItems });
|
|
43
44
|
this.snapSelectionToGrid();
|
|
44
45
|
};
|
|
45
46
|
findNearestValidCell = (row, column) => {
|
|
@@ -79,6 +80,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
79
80
|
this.emitPosition();
|
|
80
81
|
};
|
|
81
82
|
onShow = () => {
|
|
83
|
+
this.updateState({ isShow: true });
|
|
82
84
|
this.gridRow = null;
|
|
83
85
|
this.gridColumn = null;
|
|
84
86
|
return this.emit(this.EVENTS.CONTROLS.PUSH, {
|
|
@@ -89,6 +91,9 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
89
91
|
});
|
|
90
92
|
};
|
|
91
93
|
onHide = () => {
|
|
94
|
+
if (!this.state.isShow)
|
|
95
|
+
return;
|
|
96
|
+
this.updateState({ isShow: false });
|
|
92
97
|
this.gridRow = null;
|
|
93
98
|
this.gridColumn = null;
|
|
94
99
|
return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
|
|
@@ -121,7 +126,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
121
126
|
hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
|
|
122
127
|
hasPrevGrid = () => this.getCurrentGridIndex() > 0;
|
|
123
128
|
emitPosition = () => {
|
|
124
|
-
this.emit(this.
|
|
129
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
125
130
|
gridRow: this.gridRow,
|
|
126
131
|
gridColumn: this.gridColumn,
|
|
127
132
|
});
|
|
@@ -132,7 +137,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
132
137
|
return;
|
|
133
138
|
this.gridRow = nextRow;
|
|
134
139
|
this.gridColumn = nextColumn;
|
|
135
|
-
this.emit(this.
|
|
140
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
136
141
|
gridRow: this.gridRow,
|
|
137
142
|
gridColumn: this.gridColumn,
|
|
138
143
|
});
|
|
@@ -143,7 +148,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
|
|
|
143
148
|
return;
|
|
144
149
|
this.gridRow = nextRow;
|
|
145
150
|
this.gridColumn = nextColumn;
|
|
146
|
-
this.emit(this.
|
|
151
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
147
152
|
gridRow: this.gridRow,
|
|
148
153
|
gridColumn: this.gridColumn,
|
|
149
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;
|
|
@@ -64,14 +64,16 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
64
64
|
getGridItemsCount = (gridItems: unknown[] = []) => gridItems.filter((item) => !(item as { isStub?: boolean } | null | undefined)?.isStub).length;
|
|
65
65
|
|
|
66
66
|
subscribe = () => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
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);
|
|
70
72
|
this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
|
|
71
73
|
if (this.EVENT_GRID_UPDATE_ITEMS) this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
|
|
72
74
|
};
|
|
73
75
|
|
|
74
|
-
getDefaultState = (): TState => ({}) as TState;
|
|
76
|
+
getDefaultState = (): TState => ({ isShow: false }) as TState;
|
|
75
77
|
|
|
76
78
|
getGridItems = async (): Promise<unknown[]> => [];
|
|
77
79
|
|
|
@@ -79,7 +81,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
79
81
|
this.gridRow = null;
|
|
80
82
|
this.gridColumn = null;
|
|
81
83
|
|
|
82
|
-
return this.emit(this.
|
|
84
|
+
return this.emit(this.EVENT_UPDATE_STATE, {
|
|
83
85
|
gridRow: null,
|
|
84
86
|
gridColumn: null,
|
|
85
87
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
|
@@ -89,7 +91,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
89
91
|
const gridItems = await this.getGridItems();
|
|
90
92
|
this.cachedItemsCount = this.getGridItemsCount(gridItems);
|
|
91
93
|
|
|
92
|
-
await this.emit(this.
|
|
94
|
+
await this.emit(this.EVENT_UPDATE_STATE, { gridItems } satisfies Partial<ModuleControllerArrowsGridState>);
|
|
93
95
|
this.snapSelectionToGrid();
|
|
94
96
|
};
|
|
95
97
|
|
|
@@ -134,6 +136,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
134
136
|
};
|
|
135
137
|
|
|
136
138
|
onShow = () => {
|
|
139
|
+
this.updateState({ isShow: true } as Partial<TState>);
|
|
137
140
|
this.gridRow = null;
|
|
138
141
|
this.gridColumn = null;
|
|
139
142
|
|
|
@@ -146,6 +149,9 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
146
149
|
};
|
|
147
150
|
|
|
148
151
|
onHide = () => {
|
|
152
|
+
if (!this.state.isShow) return;
|
|
153
|
+
|
|
154
|
+
this.updateState({ isShow: false } as Partial<TState>);
|
|
149
155
|
this.gridRow = null;
|
|
150
156
|
this.gridColumn = null;
|
|
151
157
|
|
|
@@ -181,7 +187,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
181
187
|
hasPrevGrid = () => this.getCurrentGridIndex() > 0;
|
|
182
188
|
|
|
183
189
|
emitPosition = () => {
|
|
184
|
-
this.emit(this.
|
|
190
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
185
191
|
gridRow: this.gridRow,
|
|
186
192
|
gridColumn: this.gridColumn,
|
|
187
193
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
|
@@ -193,7 +199,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
193
199
|
|
|
194
200
|
this.gridRow = nextRow;
|
|
195
201
|
this.gridColumn = nextColumn;
|
|
196
|
-
this.emit(this.
|
|
202
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
197
203
|
gridRow: this.gridRow,
|
|
198
204
|
gridColumn: this.gridColumn,
|
|
199
205
|
} satisfies Partial<ModuleControllerArrowsGridState>);
|
|
@@ -205,7 +211,7 @@ export abstract class ModuleControllerArrowsGrid<
|
|
|
205
211
|
|
|
206
212
|
this.gridRow = nextRow;
|
|
207
213
|
this.gridColumn = nextColumn;
|
|
208
|
-
this.emit(this.
|
|
214
|
+
this.emit(this.EVENT_UPDATE_STATE, {
|
|
209
215
|
gridRow: this.gridRow,
|
|
210
216
|
gridColumn: this.gridColumn,
|
|
211
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;
|