@vnejs/module.controller.arrows.grid 0.2.5 → 0.2.7

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 CHANGED
@@ -25,6 +25,14 @@ export declare abstract class ModuleControllerArrowsGrid<TEvents extends ModuleC
25
25
  cachedGridIndex: number;
26
26
  cachedGridsCount: number;
27
27
  cachedItemsCount: number | null;
28
+ subscribe: () => void;
29
+ onShow: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:push">> | undefined;
30
+ onHide: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:pop">> | undefined;
31
+ onHideCleanup: () => Promise<import("@vnejs/shared").EmitResults<string> | undefined>;
32
+ onStateUpdate: (payload?: Partial<TState>) => void;
33
+ onGridClear: () => Promise<import("@vnejs/shared").EmitResults<string>> | undefined;
34
+ onGridUpdateItems: () => Promise<void>;
35
+ emitPosition: () => void;
28
36
  abstract getMaxRows: () => number;
29
37
  abstract getMaxColumns: () => number;
30
38
  getItemsCount: () => number;
@@ -35,23 +43,16 @@ export declare abstract class ModuleControllerArrowsGrid<TEvents extends ModuleC
35
43
  onArrowRight: () => void | Promise<void>;
36
44
  onArrowBottom: () => void | Promise<void>;
37
45
  onArrowLeft: () => void | Promise<void>;
38
- subscribe: () => void;
39
46
  getGridItems: () => Promise<unknown[]>;
40
- onGridClear: () => Promise<import("@vnejs/shared").EmitResults<string>> | undefined;
41
- onGridUpdateItems: () => Promise<void>;
42
47
  findNearestValidCell: (row: number, column: number) => {
43
48
  row: number;
44
49
  column: number;
45
50
  } | null;
46
51
  snapSelectionToGrid: () => void;
47
- onShow: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:push">> | undefined;
48
- onHide: () => Promise<import("@vnejs/shared").EmitResults<"vne:controls:pop">> | undefined;
49
- onStateUpdate: (payload?: Partial<TState>) => void;
50
52
  initRowAndColumns: () => void;
51
53
  isCellInGrid: (row: number, column: number) => boolean;
52
54
  hasNextGrid: () => boolean;
53
55
  hasPrevGrid: () => boolean;
54
- emitPosition: () => void;
55
56
  goNextGrid: (nextRow: number, nextColumn: number) => void;
56
57
  goPrevGrid: (nextRow: number, nextColumn: number) => void;
57
58
  setCell: (row: number, column: number) => void;
package/dist/index.js CHANGED
@@ -14,24 +14,51 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
14
14
  cachedGridIndex = 0;
15
15
  cachedGridsCount = 1;
16
16
  cachedItemsCount = null;
17
- getItemsCount = () => this.cachedItemsCount ?? this.getMaxRows() * this.getMaxColumns();
18
- getCurrentGridIndex = () => this.cachedGridIndex;
19
- getGridsCount = () => this.cachedGridsCount;
20
- getGridItemsCount = (gridItems = []) => gridItems.filter((item) => !item?.isStub).length;
21
- onArrowUp = () => void this.decRow();
22
- onArrowRight = () => void this.incColumn();
23
- onArrowBottom = () => void this.incRow();
24
- onArrowLeft = () => void this.decColumn();
25
17
  subscribe = () => {
26
18
  const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
27
19
  this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
28
20
  this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
21
+ this.on(this.EVENT_HIDE, this.onHideCleanup, { priority: HIDE.CLEANUP });
29
22
  this.on(this.EVENT_UPDATE_STATE, this.onStateUpdate);
30
23
  this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
31
24
  if (this.EVENT_GRID_UPDATE_ITEMS)
32
25
  this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
33
26
  };
34
- getGridItems = async () => [];
27
+ onShow = () => {
28
+ this.gridRow = null;
29
+ this.gridColumn = null;
30
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
31
+ key: this.name,
32
+ controls: this.CONTROLS,
33
+ index: this.CONTROLS_ZINDEX + 1,
34
+ checkNext: true,
35
+ });
36
+ };
37
+ onHide = () => {
38
+ this.gridRow = null;
39
+ this.gridColumn = null;
40
+ return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
41
+ };
42
+ onHideCleanup = async () => {
43
+ this.gridRow = null;
44
+ this.gridColumn = null;
45
+ const unset = { gridRow: undefined, gridColumn: undefined };
46
+ await this.emit(this.EVENT_UPDATE_STATE, unset);
47
+ return this.emit(this.EVENT_UPDATE_FAST);
48
+ };
49
+ onStateUpdate = (payload = {}) => {
50
+ this.updateState(payload);
51
+ if (payload.gridIndex !== undefined)
52
+ this.cachedGridIndex = payload.gridIndex;
53
+ if (payload.gridsCount !== undefined)
54
+ this.cachedGridsCount = payload.gridsCount;
55
+ if (payload.gridItems !== undefined)
56
+ this.cachedItemsCount = this.getGridItemsCount(payload.gridItems);
57
+ if ("gridRow" in payload)
58
+ this.gridRow = payload.gridRow ?? null;
59
+ if ("gridColumn" in payload)
60
+ this.gridColumn = payload.gridColumn ?? null;
61
+ };
35
62
  onGridClear = () => {
36
63
  this.gridRow = null;
37
64
  this.gridColumn = null;
@@ -46,6 +73,22 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
46
73
  await this.emit(this.EVENT_UPDATE_STATE, { gridItems });
47
74
  this.snapSelectionToGrid();
48
75
  };
76
+ emitPosition = () => {
77
+ this.emit(this.EVENT_UPDATE_STATE, {
78
+ gridRow: this.gridRow,
79
+ gridColumn: this.gridColumn,
80
+ });
81
+ this.emit(this.EVENT_UPDATE_FAST);
82
+ };
83
+ getItemsCount = () => this.cachedItemsCount ?? this.getMaxRows() * this.getMaxColumns();
84
+ getCurrentGridIndex = () => this.cachedGridIndex;
85
+ getGridsCount = () => this.cachedGridsCount;
86
+ getGridItemsCount = (gridItems = []) => gridItems.filter((item) => !item?.isStub).length;
87
+ onArrowUp = () => void this.decRow();
88
+ onArrowRight = () => void this.incColumn();
89
+ onArrowBottom = () => void this.incRow();
90
+ onArrowLeft = () => void this.decColumn();
91
+ getGridItems = async () => [];
49
92
  findNearestValidCell = (row, column) => {
50
93
  const maxColumns = this.getMaxColumns();
51
94
  const itemsCount = this.getItemsCount();
@@ -82,34 +125,6 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
82
125
  this.gridColumn = nearest.column;
83
126
  this.emitPosition();
84
127
  };
85
- onShow = () => {
86
- this.gridRow = null;
87
- this.gridColumn = null;
88
- return this.emit(this.EVENTS.CONTROLS.PUSH, {
89
- key: this.name,
90
- controls: this.CONTROLS,
91
- index: this.CONTROLS_ZINDEX + 1,
92
- checkNext: true,
93
- });
94
- };
95
- onHide = () => {
96
- this.gridRow = null;
97
- this.gridColumn = null;
98
- return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
99
- };
100
- onStateUpdate = (payload = {}) => {
101
- this.updateState(payload);
102
- if (payload.gridIndex !== undefined)
103
- this.cachedGridIndex = payload.gridIndex;
104
- if (payload.gridsCount !== undefined)
105
- this.cachedGridsCount = payload.gridsCount;
106
- if (payload.gridItems !== undefined)
107
- this.cachedItemsCount = this.getGridItemsCount(payload.gridItems);
108
- if ("gridRow" in payload)
109
- this.gridRow = payload.gridRow ?? null;
110
- if ("gridColumn" in payload)
111
- this.gridColumn = payload.gridColumn ?? null;
112
- };
113
128
  initRowAndColumns = () => {
114
129
  this.gridRow = 0;
115
130
  this.gridColumn = 0;
@@ -124,13 +139,6 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
124
139
  };
125
140
  hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
126
141
  hasPrevGrid = () => this.getCurrentGridIndex() > 0;
127
- emitPosition = () => {
128
- this.emit(this.EVENT_UPDATE_STATE, {
129
- gridRow: this.gridRow,
130
- gridColumn: this.gridColumn,
131
- });
132
- this.emit(this.EVENT_UPDATE_FAST);
133
- };
134
142
  goNextGrid = (nextRow, nextColumn) => {
135
143
  if (!this.hasNextGrid())
136
144
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/module.controller.arrows.grid",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -36,7 +36,6 @@ export abstract class ModuleControllerArrowsGrid<
36
36
  EVENT_GRID_UPDATE_ITEMS?: string;
37
37
 
38
38
  abstract CONTROLS_ZINDEX: number;
39
-
40
39
  CONTROLS = {
41
40
  [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.onArrowUp(),
42
41
  [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.onArrowRight(),
@@ -46,39 +45,63 @@ export abstract class ModuleControllerArrowsGrid<
46
45
 
47
46
  gridRow: number | null = null;
48
47
  gridColumn: number | null = null;
49
-
50
48
  isDisableGridChangeHorizontal = false;
51
49
  isDisableGridChangeVertical = false;
52
-
53
50
  cachedGridIndex = 0;
54
51
  cachedGridsCount = 1;
55
52
  cachedItemsCount: number | null = null;
56
53
 
57
- abstract getMaxRows: () => number;
58
- abstract getMaxColumns: () => number;
59
-
60
- getItemsCount = () => this.cachedItemsCount ?? this.getMaxRows() * this.getMaxColumns();
61
- getCurrentGridIndex = () => this.cachedGridIndex;
62
- getGridsCount = () => this.cachedGridsCount;
63
-
64
- getGridItemsCount = (gridItems: unknown[] = []) => gridItems.filter((item) => !(item as { isStub?: boolean } | null | undefined)?.isStub).length;
65
-
66
- onArrowUp = (): void | Promise<void> => void this.decRow();
67
- onArrowRight = (): void | Promise<void> => void this.incColumn();
68
- onArrowBottom = (): void | Promise<void> => void this.incRow();
69
- onArrowLeft = (): void | Promise<void> => void this.decColumn();
70
-
71
54
  subscribe = () => {
72
55
  const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
73
56
 
74
57
  this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
75
58
  this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
59
+ this.on(this.EVENT_HIDE, this.onHideCleanup, { priority: HIDE.CLEANUP });
76
60
  this.on(this.EVENT_UPDATE_STATE, this.onStateUpdate);
77
61
  this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
78
62
  if (this.EVENT_GRID_UPDATE_ITEMS) this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
79
63
  };
80
64
 
81
- getGridItems = async (): Promise<unknown[]> => [];
65
+ onShow = () => {
66
+ this.gridRow = null;
67
+ this.gridColumn = null;
68
+
69
+ return this.emit(this.EVENTS.CONTROLS.PUSH, {
70
+ key: this.name,
71
+ controls: this.CONTROLS,
72
+ index: this.CONTROLS_ZINDEX + 1,
73
+ checkNext: true,
74
+ } satisfies ControlsPushPayload);
75
+ };
76
+
77
+ onHide = () => {
78
+ this.gridRow = null;
79
+ this.gridColumn = null;
80
+
81
+ return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name } satisfies ControlsPopPayload);
82
+ };
83
+
84
+ onHideCleanup = async () => {
85
+ this.gridRow = null;
86
+ this.gridColumn = null;
87
+
88
+ const unset = { gridRow: undefined, gridColumn: undefined } satisfies Partial<ModuleControllerArrowsGridState>;
89
+
90
+ await this.emit(this.EVENT_UPDATE_STATE, unset);
91
+
92
+ return this.emit(this.EVENT_UPDATE_FAST);
93
+ };
94
+
95
+ onStateUpdate = (payload: Partial<TState> = {} as Partial<TState>) => {
96
+ this.updateState(payload);
97
+
98
+ if (payload.gridIndex !== undefined) this.cachedGridIndex = payload.gridIndex;
99
+ if (payload.gridsCount !== undefined) this.cachedGridsCount = payload.gridsCount;
100
+ if (payload.gridItems !== undefined) this.cachedItemsCount = this.getGridItemsCount(payload.gridItems);
101
+
102
+ if ("gridRow" in payload) this.gridRow = payload.gridRow ?? null;
103
+ if ("gridColumn" in payload) this.gridColumn = payload.gridColumn ?? null;
104
+ };
82
105
 
83
106
  onGridClear = () => {
84
107
  this.gridRow = null;
@@ -98,6 +121,25 @@ export abstract class ModuleControllerArrowsGrid<
98
121
  this.snapSelectionToGrid();
99
122
  };
100
123
 
124
+ emitPosition = () => {
125
+ this.emit(this.EVENT_UPDATE_STATE, {
126
+ gridRow: this.gridRow,
127
+ gridColumn: this.gridColumn,
128
+ } satisfies Partial<ModuleControllerArrowsGridState>);
129
+ this.emit(this.EVENT_UPDATE_FAST);
130
+ };
131
+
132
+ abstract getMaxRows: () => number;
133
+ abstract getMaxColumns: () => number;
134
+ getItemsCount = () => this.cachedItemsCount ?? this.getMaxRows() * this.getMaxColumns();
135
+ getCurrentGridIndex = () => this.cachedGridIndex;
136
+ getGridsCount = () => this.cachedGridsCount;
137
+ getGridItemsCount = (gridItems: unknown[] = []) => gridItems.filter((item) => !(item as { isStub?: boolean } | null | undefined)?.isStub).length;
138
+ onArrowUp = (): void | Promise<void> => void this.decRow();
139
+ onArrowRight = (): void | Promise<void> => void this.incColumn();
140
+ onArrowBottom = (): void | Promise<void> => void this.incRow();
141
+ onArrowLeft = (): void | Promise<void> => void this.decColumn();
142
+ getGridItems = async (): Promise<unknown[]> => [];
101
143
  findNearestValidCell = (row: number, column: number) => {
102
144
  const maxColumns = this.getMaxColumns();
103
145
  const itemsCount = this.getItemsCount();
@@ -120,7 +162,6 @@ export abstract class ModuleControllerArrowsGrid<
120
162
 
121
163
  return { row: bestRow, column: bestColumn };
122
164
  };
123
-
124
165
  snapSelectionToGrid = () => {
125
166
  if (this.gridRow === null || this.gridColumn === null) return;
126
167
  if (this.isCellInGrid(this.gridRow, this.gridColumn)) return;
@@ -137,43 +178,11 @@ export abstract class ModuleControllerArrowsGrid<
137
178
  this.gridColumn = nearest.column;
138
179
  this.emitPosition();
139
180
  };
140
-
141
- onShow = () => {
142
- this.gridRow = null;
143
- this.gridColumn = null;
144
-
145
- return this.emit(this.EVENTS.CONTROLS.PUSH, {
146
- key: this.name,
147
- controls: this.CONTROLS,
148
- index: this.CONTROLS_ZINDEX + 1,
149
- checkNext: true,
150
- } satisfies ControlsPushPayload);
151
- };
152
-
153
- onHide = () => {
154
- this.gridRow = null;
155
- this.gridColumn = null;
156
-
157
- return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name } satisfies ControlsPopPayload);
158
- };
159
-
160
- onStateUpdate = (payload: Partial<TState> = {} as Partial<TState>) => {
161
- this.updateState(payload);
162
-
163
- if (payload.gridIndex !== undefined) this.cachedGridIndex = payload.gridIndex;
164
- if (payload.gridsCount !== undefined) this.cachedGridsCount = payload.gridsCount;
165
- if (payload.gridItems !== undefined) this.cachedItemsCount = this.getGridItemsCount(payload.gridItems);
166
-
167
- if ("gridRow" in payload) this.gridRow = payload.gridRow ?? null;
168
- if ("gridColumn" in payload) this.gridColumn = payload.gridColumn ?? null;
169
- };
170
-
171
181
  initRowAndColumns = () => {
172
182
  this.gridRow = 0;
173
183
  this.gridColumn = 0;
174
184
  this.emitPosition();
175
185
  };
176
-
177
186
  isCellInGrid = (row: number, column: number) => {
178
187
  const maxRows = this.getMaxRows();
179
188
  const maxColumns = this.getMaxColumns();
@@ -181,18 +190,8 @@ export abstract class ModuleControllerArrowsGrid<
181
190
 
182
191
  return row * maxColumns + column < this.getItemsCount();
183
192
  };
184
-
185
193
  hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
186
194
  hasPrevGrid = () => this.getCurrentGridIndex() > 0;
187
-
188
- emitPosition = () => {
189
- this.emit(this.EVENT_UPDATE_STATE, {
190
- gridRow: this.gridRow,
191
- gridColumn: this.gridColumn,
192
- } satisfies Partial<ModuleControllerArrowsGridState>);
193
- this.emit(this.EVENT_UPDATE_FAST);
194
- };
195
-
196
195
  goNextGrid = (nextRow: number, nextColumn: number) => {
197
196
  if (!this.hasNextGrid()) return;
198
197
 
@@ -204,7 +203,6 @@ export abstract class ModuleControllerArrowsGrid<
204
203
  } satisfies Partial<ModuleControllerArrowsGridState>);
205
204
  this.emit(this.EVENT_GRID_NEXT);
206
205
  };
207
-
208
206
  goPrevGrid = (nextRow: number, nextColumn: number) => {
209
207
  if (!this.hasPrevGrid()) return;
210
208
 
@@ -216,7 +214,6 @@ export abstract class ModuleControllerArrowsGrid<
216
214
  } satisfies Partial<ModuleControllerArrowsGridState>);
217
215
  this.emit(this.EVENT_GRID_PREV);
218
216
  };
219
-
220
217
  setCell = (row: number, column: number) => {
221
218
  if (!this.isCellInGrid(row, column)) return;
222
219
 
@@ -224,7 +221,6 @@ export abstract class ModuleControllerArrowsGrid<
224
221
  this.gridColumn = column;
225
222
  this.emitPosition();
226
223
  };
227
-
228
224
  incRow = () => {
229
225
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
230
226
 
@@ -235,7 +231,6 @@ export abstract class ModuleControllerArrowsGrid<
235
231
 
236
232
  return this.goNextGrid(0, this.gridColumn);
237
233
  };
238
-
239
234
  decRow = () => {
240
235
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
241
236
 
@@ -246,7 +241,6 @@ export abstract class ModuleControllerArrowsGrid<
246
241
 
247
242
  return this.goPrevGrid(this.getMaxRows() - 1, this.gridColumn);
248
243
  };
249
-
250
244
  incColumn = () => {
251
245
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
252
246
 
@@ -257,7 +251,6 @@ export abstract class ModuleControllerArrowsGrid<
257
251
 
258
252
  return this.goNextGrid(this.gridRow, 0);
259
253
  };
260
-
261
254
  decColumn = () => {
262
255
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
263
256