@vnejs/module.controller.arrows.grid 0.2.2 → 0.2.4

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
@@ -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 EVENT_STATE_UPDATE: string;
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,13 +25,16 @@ 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;
32
31
  getCurrentGridIndex: () => number;
33
32
  getGridsCount: () => number;
34
33
  getGridItemsCount: (gridItems?: unknown[]) => number;
34
+ onArrowUp: () => void | Promise<void>;
35
+ onArrowRight: () => void | Promise<void>;
36
+ onArrowBottom: () => void | Promise<void>;
37
+ onArrowLeft: () => void | Promise<void>;
35
38
  subscribe: () => void;
36
39
  getDefaultState: () => TState;
37
40
  getGridItems: () => Promise<unknown[]>;
package/dist/index.js CHANGED
@@ -2,10 +2,10 @@ import { ModuleCore } from "@vnejs/module.core";
2
2
  export class ModuleControllerArrowsGrid extends ModuleCore {
3
3
  EVENT_GRID_UPDATE_ITEMS;
4
4
  CONTROLS = {
5
- [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.decRow(),
6
- [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.incColumn(),
7
- [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.incRow(),
8
- [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => void this.decColumn(),
5
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.onArrowUp(),
6
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.onArrowRight(),
7
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.onArrowBottom(),
8
+ [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => void this.onArrowLeft(),
9
9
  };
10
10
  gridRow = null;
11
11
  gridColumn = null;
@@ -14,25 +14,29 @@ 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;
21
+ onArrowUp = () => void this.decRow();
22
+ onArrowRight = () => void this.incColumn();
23
+ onArrowBottom = () => void this.incRow();
24
+ onArrowLeft = () => void this.decColumn();
22
25
  subscribe = () => {
23
- this.on(this.EVENT_SHOW, this.onShow);
24
- this.on(this.EVENT_HIDE, this.onHide);
25
- this.on(this.EVENT_STATE_UPDATE, this.onStateUpdate);
26
+ const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
27
+ this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
28
+ this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
29
+ this.on(this.EVENT_UPDATE_STATE, this.onStateUpdate);
26
30
  this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
27
31
  if (this.EVENT_GRID_UPDATE_ITEMS)
28
32
  this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
29
33
  };
30
- getDefaultState = () => ({});
34
+ getDefaultState = () => ({ isShow: false });
31
35
  getGridItems = async () => [];
32
36
  onGridClear = () => {
33
37
  this.gridRow = null;
34
38
  this.gridColumn = null;
35
- return this.emit(this.EVENT_STATE_UPDATE, {
39
+ return this.emit(this.EVENT_UPDATE_STATE, {
36
40
  gridRow: null,
37
41
  gridColumn: null,
38
42
  });
@@ -40,7 +44,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
40
44
  onGridUpdateItems = async () => {
41
45
  const gridItems = await this.getGridItems();
42
46
  this.cachedItemsCount = this.getGridItemsCount(gridItems);
43
- await this.emit(this.EVENT_STATE_UPDATE, { gridItems });
47
+ await this.emit(this.EVENT_UPDATE_STATE, { gridItems });
44
48
  this.snapSelectionToGrid();
45
49
  };
46
50
  findNearestValidCell = (row, column) => {
@@ -80,9 +84,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
80
84
  this.emitPosition();
81
85
  };
82
86
  onShow = () => {
83
- if (this.isShow)
84
- return;
85
- this.isShow = true;
87
+ this.updateState({ isShow: true });
86
88
  this.gridRow = null;
87
89
  this.gridColumn = null;
88
90
  return this.emit(this.EVENTS.CONTROLS.PUSH, {
@@ -93,9 +95,9 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
93
95
  });
94
96
  };
95
97
  onHide = () => {
96
- if (!this.isShow)
98
+ if (!this.state.isShow)
97
99
  return;
98
- this.isShow = false;
100
+ this.updateState({ isShow: false });
99
101
  this.gridRow = null;
100
102
  this.gridColumn = null;
101
103
  return this.emit(this.EVENTS.CONTROLS.POP, { key: this.name });
@@ -128,7 +130,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
128
130
  hasNextGrid = () => this.getCurrentGridIndex() + 1 < this.getGridsCount();
129
131
  hasPrevGrid = () => this.getCurrentGridIndex() > 0;
130
132
  emitPosition = () => {
131
- this.emit(this.EVENT_STATE_UPDATE, {
133
+ this.emit(this.EVENT_UPDATE_STATE, {
132
134
  gridRow: this.gridRow,
133
135
  gridColumn: this.gridColumn,
134
136
  });
@@ -139,7 +141,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
139
141
  return;
140
142
  this.gridRow = nextRow;
141
143
  this.gridColumn = nextColumn;
142
- this.emit(this.EVENT_STATE_UPDATE, {
144
+ this.emit(this.EVENT_UPDATE_STATE, {
143
145
  gridRow: this.gridRow,
144
146
  gridColumn: this.gridColumn,
145
147
  });
@@ -150,7 +152,7 @@ export class ModuleControllerArrowsGrid extends ModuleCore {
150
152
  return;
151
153
  this.gridRow = nextRow;
152
154
  this.gridColumn = nextColumn;
153
- this.emit(this.EVENT_STATE_UPDATE, {
155
+ this.emit(this.EVENT_UPDATE_STATE, {
154
156
  gridRow: this.gridRow,
155
157
  gridColumn: this.gridColumn,
156
158
  });
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/module.controller.arrows.grid",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
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 EVENT_STATE_UPDATE: string;
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;
@@ -38,10 +38,10 @@ export abstract class ModuleControllerArrowsGrid<
38
38
  abstract CONTROLS_ZINDEX: number;
39
39
 
40
40
  CONTROLS = {
41
- [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.decRow(),
42
- [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.incColumn(),
43
- [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.incRow(),
44
- [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => void this.decColumn(),
41
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.onArrowUp(),
42
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.onArrowRight(),
43
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.onArrowBottom(),
44
+ [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => void this.onArrowLeft(),
45
45
  };
46
46
 
47
47
  gridRow: number | null = null;
@@ -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
 
@@ -65,15 +63,22 @@ export abstract class ModuleControllerArrowsGrid<
65
63
 
66
64
  getGridItemsCount = (gridItems: unknown[] = []) => gridItems.filter((item) => !(item as { isStub?: boolean } | null | undefined)?.isStub).length;
67
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
+
68
71
  subscribe = () => {
69
- this.on(this.EVENT_SHOW, this.onShow);
70
- this.on(this.EVENT_HIDE, this.onHide);
71
- this.on(this.EVENT_STATE_UPDATE, this.onStateUpdate);
72
+ const { SHOW, HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
73
+
74
+ this.on(this.EVENT_SHOW, this.onShow, { priority: SHOW.CONTROLS });
75
+ this.on(this.EVENT_HIDE, this.onHide, { priority: HIDE.CONTROLS });
76
+ this.on(this.EVENT_UPDATE_STATE, this.onStateUpdate);
72
77
  this.on(this.EVENT_GRID_CLEAR, this.onGridClear);
73
78
  if (this.EVENT_GRID_UPDATE_ITEMS) this.on(this.EVENT_GRID_UPDATE_ITEMS, this.onGridUpdateItems);
74
79
  };
75
80
 
76
- getDefaultState = (): TState => ({}) as TState;
81
+ getDefaultState = (): TState => ({ isShow: false }) as TState;
77
82
 
78
83
  getGridItems = async (): Promise<unknown[]> => [];
79
84
 
@@ -81,7 +86,7 @@ export abstract class ModuleControllerArrowsGrid<
81
86
  this.gridRow = null;
82
87
  this.gridColumn = null;
83
88
 
84
- return this.emit(this.EVENT_STATE_UPDATE, {
89
+ return this.emit(this.EVENT_UPDATE_STATE, {
85
90
  gridRow: null,
86
91
  gridColumn: null,
87
92
  } satisfies Partial<ModuleControllerArrowsGridState>);
@@ -91,7 +96,7 @@ export abstract class ModuleControllerArrowsGrid<
91
96
  const gridItems = await this.getGridItems();
92
97
  this.cachedItemsCount = this.getGridItemsCount(gridItems);
93
98
 
94
- await this.emit(this.EVENT_STATE_UPDATE, { gridItems } satisfies Partial<ModuleControllerArrowsGridState>);
99
+ await this.emit(this.EVENT_UPDATE_STATE, { gridItems } satisfies Partial<ModuleControllerArrowsGridState>);
95
100
  this.snapSelectionToGrid();
96
101
  };
97
102
 
@@ -136,9 +141,7 @@ export abstract class ModuleControllerArrowsGrid<
136
141
  };
137
142
 
138
143
  onShow = () => {
139
- if (this.isShow) return;
140
-
141
- this.isShow = true;
144
+ this.updateState({ isShow: true } as Partial<TState>);
142
145
  this.gridRow = null;
143
146
  this.gridColumn = null;
144
147
 
@@ -151,9 +154,9 @@ export abstract class ModuleControllerArrowsGrid<
151
154
  };
152
155
 
153
156
  onHide = () => {
154
- if (!this.isShow) return;
157
+ if (!this.state.isShow) return;
155
158
 
156
- this.isShow = false;
159
+ this.updateState({ isShow: false } as Partial<TState>);
157
160
  this.gridRow = null;
158
161
  this.gridColumn = null;
159
162
 
@@ -189,7 +192,7 @@ export abstract class ModuleControllerArrowsGrid<
189
192
  hasPrevGrid = () => this.getCurrentGridIndex() > 0;
190
193
 
191
194
  emitPosition = () => {
192
- this.emit(this.EVENT_STATE_UPDATE, {
195
+ this.emit(this.EVENT_UPDATE_STATE, {
193
196
  gridRow: this.gridRow,
194
197
  gridColumn: this.gridColumn,
195
198
  } satisfies Partial<ModuleControllerArrowsGridState>);
@@ -201,7 +204,7 @@ export abstract class ModuleControllerArrowsGrid<
201
204
 
202
205
  this.gridRow = nextRow;
203
206
  this.gridColumn = nextColumn;
204
- this.emit(this.EVENT_STATE_UPDATE, {
207
+ this.emit(this.EVENT_UPDATE_STATE, {
205
208
  gridRow: this.gridRow,
206
209
  gridColumn: this.gridColumn,
207
210
  } satisfies Partial<ModuleControllerArrowsGridState>);
@@ -213,7 +216,7 @@ export abstract class ModuleControllerArrowsGrid<
213
216
 
214
217
  this.gridRow = nextRow;
215
218
  this.gridColumn = nextColumn;
216
- this.emit(this.EVENT_STATE_UPDATE, {
219
+ this.emit(this.EVENT_UPDATE_STATE, {
217
220
  gridRow: this.gridRow,
218
221
  gridColumn: this.gridColumn,
219
222
  } 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;