@vnejs/module.controller.arrows.grid 0.2.6 → 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,24 +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
- onHideCleanup: () => Promise<import("@vnejs/shared").EmitResults<string> | undefined>;
50
- onStateUpdate: (payload?: Partial<TState>) => void;
51
52
  initRowAndColumns: () => void;
52
53
  isCellInGrid: (row: number, column: number) => boolean;
53
54
  hasNextGrid: () => boolean;
54
55
  hasPrevGrid: () => boolean;
55
- emitPosition: () => void;
56
56
  goNextGrid: (nextRow: number, nextColumn: number) => void;
57
57
  goPrevGrid: (nextRow: number, nextColumn: number) => void;
58
58
  setCell: (row: number, column: number) => void;
package/dist/index.js CHANGED
@@ -14,14 +14,6 @@ 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 });
@@ -32,7 +24,41 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
32
24
  if (this.EVENT_GRID_UPDATE_ITEMS)
33
25
  this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
34
26
  };
35
- 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
+ };
36
62
  onGridClear = () => {
37
63
  this.gridRow = null;
38
64
  this.gridColumn = null;
@@ -47,6 +73,22 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
47
73
  await this.emit(this.EVENT_UPDATE_STATE, { gridItems });
48
74
  this.snapSelectionToGrid();
49
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 () => [];
50
92
  findNearestValidCell = (row, column) => {
51
93
  const maxColumns = this.getMaxColumns();
52
94
  const itemsCount = this.getItemsCount();
@@ -83,41 +125,6 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
83
125
  this.gridColumn = nearest.column;
84
126
  this.emitPosition();
85
127
  };
86
- onShow = () => {
87
- this.gridRow = null;
88
- this.gridColumn = null;
89
- return this.emit(this.EVENTS.CONTROLS.PUSH, {
90
- key: this.name,
91
- controls: this.CONTROLS,
92
- index: this.CONTROLS_ZINDEX + 1,
93
- checkNext: true,
94
- });
95
- };
96
- onHide = () => {
97
- this.gridRow = null;
98
- this.gridColumn = null;
99
- return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
100
- };
101
- onHideCleanup = async () => {
102
- this.gridRow = null;
103
- this.gridColumn = null;
104
- const unset = { gridRow: undefined, gridColumn: undefined };
105
- await this.emit(this.EVENT_UPDATE_STATE, unset);
106
- return this.emit(this.EVENT_UPDATE_FAST);
107
- };
108
- onStateUpdate = (payload = {}) => {
109
- this.updateState(payload);
110
- if (payload.gridIndex !== undefined)
111
- this.cachedGridIndex = payload.gridIndex;
112
- if (payload.gridsCount !== undefined)
113
- this.cachedGridsCount = payload.gridsCount;
114
- if (payload.gridItems !== undefined)
115
- this.cachedItemsCount = this.getGridItemsCount(payload.gridItems);
116
- if ("gridRow" in payload)
117
- this.gridRow = payload.gridRow ?? null;
118
- if ("gridColumn" in payload)
119
- this.gridColumn = payload.gridColumn ?? null;
120
- };
121
128
  initRowAndColumns = () => {
122
129
  this.gridRow = 0;
123
130
  this.gridColumn = 0;
@@ -132,13 +139,6 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
132
139
  };
133
140
  hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
134
141
  hasPrevGrid = () => this.getCurrentGridIndex() > 0;
135
- emitPosition = () => {
136
- this.emit(this.EVENT_UPDATE_STATE, {
137
- gridRow: this.gridRow,
138
- gridColumn: this.gridColumn,
139
- });
140
- this.emit(this.EVENT_UPDATE_FAST);
141
- };
142
142
  goNextGrid = (nextRow, nextColumn) => {
143
143
  if (!this.hasNextGrid())
144
144
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/module.controller.arrows.grid",
3
- "version": "0.2.6",
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,28 +45,12 @@ 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
 
@@ -79,7 +62,46 @@ export abstract class ModuleControllerArrowsGrid<
79
62
  if (this.EVENT_GRID_UPDATE_ITEMS) this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
80
63
  };
81
64
 
82
- 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
+ };
83
105
 
84
106
  onGridClear = () => {
85
107
  this.gridRow = null;
@@ -99,6 +121,25 @@ export abstract class ModuleControllerArrowsGrid<
99
121
  this.snapSelectionToGrid();
100
122
  };
101
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[]> => [];
102
143
  findNearestValidCell = (row: number, column: number) => {
103
144
  const maxColumns = this.getMaxColumns();
104
145
  const itemsCount = this.getItemsCount();
@@ -121,7 +162,6 @@ export abstract class ModuleControllerArrowsGrid<
121
162
 
122
163
  return { row: bestRow, column: bestColumn };
123
164
  };
124
-
125
165
  snapSelectionToGrid = () => {
126
166
  if (this.gridRow === null || this.gridColumn === null) return;
127
167
  if (this.isCellInGrid(this.gridRow, this.gridColumn)) return;
@@ -138,54 +178,11 @@ export abstract class ModuleControllerArrowsGrid<
138
178
  this.gridColumn = nearest.column;
139
179
  this.emitPosition();
140
180
  };
141
-
142
- onShow = () => {
143
- this.gridRow = null;
144
- this.gridColumn = null;
145
-
146
- return this.emit(this.EVENTS.CONTROLS.PUSH, {
147
- key: this.name,
148
- controls: this.CONTROLS,
149
- index: this.CONTROLS_ZINDEX + 1,
150
- checkNext: true,
151
- } satisfies ControlsPushPayload);
152
- };
153
-
154
- onHide = () => {
155
- this.gridRow = null;
156
- this.gridColumn = null;
157
-
158
- return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name } satisfies ControlsPopPayload);
159
- };
160
-
161
- onHideCleanup = async () => {
162
- this.gridRow = null;
163
- this.gridColumn = null;
164
-
165
- const unset = { gridRow: undefined, gridColumn: undefined } satisfies Partial<ModuleControllerArrowsGridState>;
166
-
167
- await this.emit(this.EVENT_UPDATE_STATE, unset);
168
-
169
- return this.emit(this.EVENT_UPDATE_FAST);
170
- };
171
-
172
- onStateUpdate = (payload: Partial<TState> = {} as Partial<TState>) => {
173
- this.updateState(payload);
174
-
175
- if (payload.gridIndex !== undefined) this.cachedGridIndex = payload.gridIndex;
176
- if (payload.gridsCount !== undefined) this.cachedGridsCount = payload.gridsCount;
177
- if (payload.gridItems !== undefined) this.cachedItemsCount = this.getGridItemsCount(payload.gridItems);
178
-
179
- if ("gridRow" in payload) this.gridRow = payload.gridRow ?? null;
180
- if ("gridColumn" in payload) this.gridColumn = payload.gridColumn ?? null;
181
- };
182
-
183
181
  initRowAndColumns = () => {
184
182
  this.gridRow = 0;
185
183
  this.gridColumn = 0;
186
184
  this.emitPosition();
187
185
  };
188
-
189
186
  isCellInGrid = (row: number, column: number) => {
190
187
  const maxRows = this.getMaxRows();
191
188
  const maxColumns = this.getMaxColumns();
@@ -193,18 +190,8 @@ export abstract class ModuleControllerArrowsGrid<
193
190
 
194
191
  return row * maxColumns + column < this.getItemsCount();
195
192
  };
196
-
197
193
  hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
198
194
  hasPrevGrid = () => this.getCurrentGridIndex() > 0;
199
-
200
- emitPosition = () => {
201
- this.emit(this.EVENT_UPDATE_STATE, {
202
- gridRow: this.gridRow,
203
- gridColumn: this.gridColumn,
204
- } satisfies Partial<ModuleControllerArrowsGridState>);
205
- this.emit(this.EVENT_UPDATE_FAST);
206
- };
207
-
208
195
  goNextGrid = (nextRow: number, nextColumn: number) => {
209
196
  if (!this.hasNextGrid()) return;
210
197
 
@@ -216,7 +203,6 @@ export abstract class ModuleControllerArrowsGrid<
216
203
  } satisfies Partial<ModuleControllerArrowsGridState>);
217
204
  this.emit(this.EVENT_GRID_NEXT);
218
205
  };
219
-
220
206
  goPrevGrid = (nextRow: number, nextColumn: number) => {
221
207
  if (!this.hasPrevGrid()) return;
222
208
 
@@ -228,7 +214,6 @@ export abstract class ModuleControllerArrowsGrid<
228
214
  } satisfies Partial<ModuleControllerArrowsGridState>);
229
215
  this.emit(this.EVENT_GRID_PREV);
230
216
  };
231
-
232
217
  setCell = (row: number, column: number) => {
233
218
  if (!this.isCellInGrid(row, column)) return;
234
219
 
@@ -236,7 +221,6 @@ export abstract class ModuleControllerArrowsGrid<
236
221
  this.gridColumn = column;
237
222
  this.emitPosition();
238
223
  };
239
-
240
224
  incRow = () => {
241
225
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
242
226
 
@@ -247,7 +231,6 @@ export abstract class ModuleControllerArrowsGrid<
247
231
 
248
232
  return this.goNextGrid(0, this.gridColumn);
249
233
  };
250
-
251
234
  decRow = () => {
252
235
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
253
236
 
@@ -258,7 +241,6 @@ export abstract class ModuleControllerArrowsGrid<
258
241
 
259
242
  return this.goPrevGrid(this.getMaxRows() - 1, this.gridColumn);
260
243
  };
261
-
262
244
  incColumn = () => {
263
245
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
264
246
 
@@ -269,7 +251,6 @@ export abstract class ModuleControllerArrowsGrid<
269
251
 
270
252
  return this.goNextGrid(this.gridRow, 0);
271
253
  };
272
-
273
254
  decColumn = () => {
274
255
  if (this.gridRow === null || this.gridColumn === null) return this.initRowAndColumns();
275
256