@vnejs/plugins.views.screens.gallery 0.1.5 → 0.1.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.
Files changed (49) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +7 -0
  3. package/dist/modules/controller.d.ts +61 -0
  4. package/dist/modules/controller.js +144 -0
  5. package/dist/modules/gallery.d.ts +10 -0
  6. package/dist/modules/gallery.js +14 -0
  7. package/dist/modules/view.d.ts +11 -0
  8. package/dist/modules/view.js +10 -0
  9. package/dist/types.d.ts +12 -0
  10. package/dist/types.js +1 -0
  11. package/dist/utils/gallery.d.ts +43 -0
  12. package/dist/utils/gallery.js +1 -0
  13. package/dist/view/components/GalleryClose.d.ts +2 -0
  14. package/dist/view/components/GalleryClose.js +8 -0
  15. package/dist/view/components/GalleryControls.d.ts +7 -0
  16. package/dist/view/components/GalleryControls.js +10 -0
  17. package/dist/view/components/GalleryItems.d.ts +7 -0
  18. package/dist/view/components/GalleryItems.js +13 -0
  19. package/dist/view/components/GalleryPages.d.ts +7 -0
  20. package/dist/view/components/GalleryPages.js +9 -0
  21. package/dist/view/components/index.d.ts +4 -0
  22. package/dist/view/components/index.js +4 -0
  23. package/dist/view/index.d.ts +3 -0
  24. package/dist/view/index.js +14 -0
  25. package/package.json +40 -6
  26. package/src/index.ts +10 -0
  27. package/{modules/controller.js → src/modules/controller.ts} +64 -43
  28. package/src/modules/gallery.ts +22 -0
  29. package/src/modules/view.ts +22 -0
  30. package/src/types.ts +21 -0
  31. package/src/utils/gallery.ts +54 -0
  32. package/src/view/components/GalleryClose.tsx +17 -0
  33. package/src/view/components/GalleryControls.tsx +31 -0
  34. package/src/view/components/GalleryItems.tsx +44 -0
  35. package/src/view/components/GalleryPages.tsx +26 -0
  36. package/src/view/components/index.ts +4 -0
  37. package/src/view/index.tsx +49 -0
  38. package/tsconfig.json +10 -0
  39. package/const/events.js +0 -13
  40. package/const/params.js +0 -32
  41. package/index.js +0 -10
  42. package/modules/gallery.js +0 -19
  43. package/modules/view.js +0 -14
  44. package/view/components/GalleryClose.jsx +0 -15
  45. package/view/components/GalleryControls.jsx +0 -18
  46. package/view/components/GalleryItems.jsx +0 -37
  47. package/view/components/GalleryPages.jsx +0 -16
  48. package/view/components/index.js +0 -4
  49. package/view/index.jsx +0 -33
@@ -1,15 +1,32 @@
1
1
  import { ModuleController } from "@vnejs/module.components";
2
2
 
3
- export class GalleryController extends ModuleController {
3
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
4
+ import type {
5
+ GalleryChoosePayload,
6
+ GalleryCurrentItem,
7
+ GalleryMapTabContentPayload,
8
+ GalleryPageSetPayload,
9
+ GalleryPluginState,
10
+ GalleryTypeSetPayload,
11
+ } from "../utils/gallery.js";
12
+
13
+ export class GalleryController extends ModuleController<
14
+ GalleryPluginEvents,
15
+ GalleryPluginConstants,
16
+ GalleryPluginSettings,
17
+ GalleryPluginParams,
18
+ GalleryPluginState
19
+ > {
4
20
  name = "gallery.controller";
5
21
 
6
22
  updateEvent = this.EVENTS.GALLERY.UPDATE;
7
23
 
8
24
  bgName = this.PARAMS.GALLERY.BACKGROUND;
9
25
 
10
- maxPagesCount = {};
26
+ maxPagesCount: Record<string, number> = {};
27
+ itemsOnPage!: number;
11
28
 
12
- emitHide = () => this.emit(this.EVENTS.GALLERY.HIDE);
29
+ emitHide = () => void this.emit(this.EVENTS.GALLERY.HIDE);
13
30
 
14
31
  initRowAndColumns = () => this.updateStateAndViewFast({ currentRow: 0, currentColumn: 0 });
15
32
  incRow = () => {
@@ -17,11 +34,11 @@ export class GalleryController extends ModuleController {
17
34
 
18
35
  const maxRows = this.PARAMS.GALLERY.ROWS;
19
36
 
20
- if (this.state.currentRow + 1 < maxRows) {
21
- this.updateStateAndView({ currentRow: this.state.currentRow + 1 });
22
- } else if (this.state.currentPage + 1 < this.state.pages) {
37
+ if ((this.state.currentRow ?? 0) + 1 < maxRows) {
38
+ this.updateStateAndView({ currentRow: this.state.currentRow! + 1 });
39
+ } else if (this.state.currentPage! + 1 < this.state.pages!) {
23
40
  this.updateState({ currentRow: 0 });
24
- this.updatePageAndType(this.state.currentPage + 1, false, true);
41
+ this.updatePageAndType(this.state.currentPage! + 1, false, true);
25
42
  }
26
43
  };
27
44
  decRow = () => {
@@ -30,10 +47,10 @@ export class GalleryController extends ModuleController {
30
47
  const maxRows = this.PARAMS.GALLERY.ROWS;
31
48
 
32
49
  if (this.state.currentRow !== 0) {
33
- this.updateStateAndView({ currentRow: this.state.currentRow - 1 });
34
- } else if (this.state.currentPage > 0) {
50
+ this.updateStateAndView({ currentRow: this.state.currentRow! - 1 });
51
+ } else if (this.state.currentPage! > 0) {
35
52
  this.updateState({ currentRow: maxRows - 1 });
36
- this.updatePageAndType(this.state.currentPage - 1, false, true);
53
+ this.updatePageAndType(this.state.currentPage! - 1, false, true);
37
54
  }
38
55
  };
39
56
  incColumn = () => {
@@ -41,11 +58,11 @@ export class GalleryController extends ModuleController {
41
58
 
42
59
  const maxColumns = this.PARAMS.GALLERY.COLUMNS;
43
60
 
44
- if (this.state.currentColumn + 1 < maxColumns) {
45
- this.updateStateAndView({ currentColumn: this.state.currentColumn + 1 });
46
- } else if (this.state.currentPage + 1 < this.state.pages) {
61
+ if ((this.state.currentColumn ?? 0) + 1 < maxColumns) {
62
+ this.updateStateAndView({ currentColumn: this.state.currentColumn! + 1 });
63
+ } else if (this.state.currentPage! + 1 < this.state.pages!) {
47
64
  this.updateState({ currentColumn: 0 });
48
- this.updatePageAndType(this.state.currentPage + 1, false, true);
65
+ this.updatePageAndType(this.state.currentPage! + 1, false, true);
49
66
  }
50
67
  };
51
68
  decColumn = () => {
@@ -54,40 +71,43 @@ export class GalleryController extends ModuleController {
54
71
  const maxColumns = this.PARAMS.GALLERY.COLUMNS;
55
72
 
56
73
  if (this.state.currentColumn !== 0) {
57
- this.updateStateAndView({ currentColumn: this.state.currentColumn - 1 });
58
- } else if (this.state.currentPage > 0) {
74
+ this.updateStateAndView({ currentColumn: this.state.currentColumn! - 1 });
75
+ } else if (this.state.currentPage! > 0) {
59
76
  this.updateState({ currentColumn: maxColumns - 1 });
60
- this.updatePageAndType(this.state.currentPage - 1, false, true);
77
+ this.updatePageAndType(this.state.currentPage! - 1, false, true);
61
78
  }
62
79
  };
63
- accept = () => this.emit(this.EVENTS.GALLERY.CHOOSE, { index: this.state.currentColumn + this.state.currentRow * this.PARAMS.GALLERY.COLUMNS });
80
+ accept = () =>
81
+ void this.emit(this.EVENTS.GALLERY.CHOOSE, {
82
+ index: this.state.currentColumn! + this.state.currentRow! * this.PARAMS.GALLERY.COLUMNS,
83
+ } satisfies GalleryChoosePayload);
64
84
  onPrevTab = () => {
65
85
  const keys = Object.keys(this.PARAMS.GALLERY.TABS);
66
86
  const currentTypeIndex = keys.findIndex((key) => key === this.state.currentType);
67
87
  const type = currentTypeIndex === 0 ? keys[keys.length - 1] : keys[(currentTypeIndex - 1) % keys.length];
68
88
 
69
- this.emit(this.EVENTS.GALLERY.TYPE_SET, { type });
89
+ void this.emit(this.EVENTS.GALLERY.TYPE_SET, { type } satisfies GalleryTypeSetPayload);
70
90
  };
71
91
  onNextTab = () => {
72
92
  const keys = Object.keys(this.PARAMS.GALLERY.TABS);
73
93
  const currentTypeIndex = keys.findIndex((key) => key === this.state.currentType);
74
94
  const type = currentTypeIndex === keys.length - 1 ? keys[0] : keys[(currentTypeIndex + 1) % keys.length];
75
95
 
76
- this.emit(this.EVENTS.GALLERY.TYPE_SET, { type });
96
+ void this.emit(this.EVENTS.GALLERY.TYPE_SET, { type } satisfies GalleryTypeSetPayload);
77
97
  };
78
98
 
79
99
  controls = {
80
- [this.CONST.CONTROLS.BUTTONS.BACK]: this.emitHide,
81
- [this.CONST.CONTROLS.BUTTONS.MENU]: this.emitHide,
82
- [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: this.emitHide,
83
- [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: this.decRow,
84
- [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: this.incColumn,
85
- [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: this.incRow,
86
- [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: this.decColumn,
87
- [this.CONST.CONTROLS.BUTTONS.TAB_PREV]: this.onPrevTab,
88
- [this.CONST.CONTROLS.BUTTONS.TAB_NEXT]: this.onNextTab,
89
- [this.CONST.CONTROLS.BUTTONS.ACCEPT]: this.accept,
90
- [this.CONST.CONTROLS.BUTTONS.INTERACT]: this.accept,
100
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emitHide(),
101
+ [this.CONST.CONTROLS.BUTTONS.MENU]: () => void this.emitHide(),
102
+ [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: () => void this.emitHide(),
103
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.decRow(),
104
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.incColumn(),
105
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.incRow(),
106
+ [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => void this.decColumn(),
107
+ [this.CONST.CONTROLS.BUTTONS.TAB_PREV]: () => void this.onPrevTab(),
108
+ [this.CONST.CONTROLS.BUTTONS.TAB_NEXT]: () => void this.onNextTab(),
109
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.accept(),
110
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.accept(),
91
111
  };
92
112
  controlsIndex = this.PARAMS.GALLERY.ZINDEX;
93
113
 
@@ -118,13 +138,13 @@ export class GalleryController extends ModuleController {
118
138
  afterHide = () => this.setDefaultState();
119
139
 
120
140
  onStarted = () => Object.keys(this.PARAMS.GALLERY.TABS).forEach(this.calcMaxPageCount);
121
- onPreload = () => Promise.all([this.loadBgMedia(), this.getItemsInfo(Object.keys(this.PARAMS.GALLERY.TABS)[0], 0).map(this.mapTabContent)]);
141
+ onPreload = () => Promise.all([this.loadBgMedia(), ...this.getItemsInfo(Object.keys(this.PARAMS.GALLERY.TABS)[0], 0).map(this.mapTabContent)]);
122
142
  onMemoryCleared = () => {
123
143
  if (!this.state.isShow) return;
124
144
 
125
145
  const { currentPage = 0, currentType = "" } = this.state;
126
146
 
127
- const promises = [this.loadBgMedia(), ...this.getItemsInfo(currentType, currentPage).map(this.mapTabContent)];
147
+ const promises: Promise<unknown>[] = [this.loadBgMedia(), ...this.getItemsInfo(currentType, currentPage).map(this.mapTabContent)];
128
148
 
129
149
  if (currentPage > 0) promises.push(...this.getItemsInfo(currentType, currentPage - 1).map(this.mapTabContent));
130
150
  if (currentPage + 1 < this.maxPagesCount[currentType]) promises.push(...this.getItemsInfo(currentType, currentPage + 1).map(this.mapTabContent));
@@ -134,32 +154,33 @@ export class GalleryController extends ModuleController {
134
154
  return Promise.all(promises);
135
155
  };
136
156
 
137
- onPageSet = ({ page } = {}) => page !== this.state.currentPage && this.updatePageAndType(page);
138
- onTypeSet = ({ type } = {}) => type !== this.state.currentType && this.updatePageAndType(0, type);
157
+ onPageSet = ({ page }: GalleryPageSetPayload = {}) => page !== this.state.currentPage && this.updatePageAndType(page);
158
+ onTypeSet = ({ type }: GalleryTypeSetPayload = {}) => type !== this.state.currentType && this.updatePageAndType(0, type);
139
159
 
140
- updatePageAndType = async (page, type, isUpdateView = true) => {
160
+ updatePageAndType = async (page?: number, type?: string | false, isUpdateView = true) => {
141
161
  this.updateState({ currentPage: page });
142
162
  if (type) this.updateState({ currentType: type, pages: this.maxPagesCount[type], currentColumn: null, currentRow: null });
143
163
 
144
- const currentItems = await Promise.all(this.getItemsInfo(this.state.currentType, this.state.currentPage).map(this.mapTabContent));
164
+ const currentItems = await Promise.all(this.getItemsInfo(this.state.currentType!, this.state.currentPage!).map(this.mapTabContent));
145
165
 
146
- while (currentItems.length < this.itemsOnPage) currentItems.push({ isStub: true });
147
- this.updateState({ currentItems });
166
+ const items: GalleryCurrentItem[] = [...currentItems];
167
+ while (items.length < this.itemsOnPage) items.push({ isStub: true });
168
+ this.updateState({ currentItems: items });
148
169
  if (isUpdateView) await this.updateViewFast();
149
170
 
150
171
  this.emit(this.EVENTS.MEMORY.CLEAR);
151
172
  };
152
173
 
153
- mapTabContent = async ({ check, mediaType, name, fullName } = {}) => {
154
- const isOpened = await this.emitOne(this.EVENTS.GALLERY.CHECK, { key: check });
174
+ mapTabContent = async ({ check, mediaType, name, fullName }: GalleryMapTabContentPayload = { check: "", mediaType: "", name: "", fullName: "" }) => {
175
+ const isOpened = Boolean(await this.emitOne(this.EVENTS.GALLERY.CHECK, { key: check }));
155
176
  const src = isOpened ? (await this.loadImageMedia(name, mediaType, this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src : "";
156
177
 
157
178
  return { isOpened, fullName, src, mediaType };
158
179
  };
159
180
 
160
- getItemsInfo = (type, page) => this.PARAMS.GALLERY.TABS[type].content.slice(page * this.itemsOnPage, (page + 1) * this.itemsOnPage);
181
+ getItemsInfo = (type: string, page: number) => this.PARAMS.GALLERY.TABS[type].content.slice(page * this.itemsOnPage, (page + 1) * this.itemsOnPage);
161
182
 
162
- calcMaxPageCount = (type) => {
183
+ calcMaxPageCount = (type: string) => {
163
184
  this.maxPagesCount[type] = Math.ceil(this.PARAMS.GALLERY.TABS[type].content.length / this.itemsOnPage);
164
185
  };
165
186
  }
@@ -0,0 +1,22 @@
1
+ import { Module } from "@vnejs/module";
2
+
3
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
4
+ import type { GalleryCheckPayload, GalleryOpenPayload } from "../utils/gallery.js";
5
+
6
+ const STORAGE_VALUE = 1;
7
+
8
+ const isEqualStorageValueFunc = (value: unknown) => value === STORAGE_VALUE;
9
+
10
+ export class Gallery extends Module<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams> {
11
+ name = "gallery";
12
+
13
+ subscribe = () => {
14
+ this.on(this.EVENTS.GALLERY.OPEN, this.onOpen);
15
+ this.on(this.EVENTS.GALLERY.CHECK, this.onCheck);
16
+ this.on(this.EVENTS.GALLERY.CLEAR, this.onClear);
17
+ };
18
+
19
+ onOpen = ({ key }: GalleryOpenPayload = {}) => this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
20
+ onCheck = ({ key }: GalleryCheckPayload = {}) => this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key })!.then(isEqualStorageValueFunc);
21
+ onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
22
+ }
@@ -0,0 +1,22 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import { render } from "../view/index.js";
4
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
5
+ import type { GalleryPluginState } from "../utils/gallery.js";
6
+
7
+ export class GalleryView extends ModuleView<
8
+ GalleryPluginEvents,
9
+ GalleryPluginConstants,
10
+ GalleryPluginSettings,
11
+ GalleryPluginParams,
12
+ GalleryPluginState
13
+ > {
14
+ name = "gallery.view";
15
+
16
+ locLabel = this.PARAMS.GALLERY.LOC_LABEL;
17
+ animationTime = this.PARAMS.GALLERY.TRANSITION;
18
+ updateEvent = this.EVENTS.GALLERY.UPDATE;
19
+
20
+ renderFunc = render;
21
+ updateHandler = this.onUpdateStoreComponent;
22
+ }
package/src/types.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { SettingsKeys as LayerSettingsKeys, PluginName as LayerPluginName } from "@vnejs/plugins.canvas.layer.contract";
3
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/plugins.controls.contract";
4
+ import type { PluginName as MemoryPluginName, SubscribeEvents as MemorySubscribeEvents } from "@vnejs/plugins.core.memory.contract";
5
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/plugins.core.state.contract";
6
+ import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/plugins.core.storage.contract";
7
+ import type { PluginName as SystemPluginName, SubscribeEvents as SystemSubscribeEvents } from "@vnejs/plugins.core.system.contract";
8
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/plugins.views.screens.gallery.contract";
9
+
10
+ export type GalleryPluginEvents = ModuleComponentsEvents &
11
+ Record<PluginName, SubscribeEvents> &
12
+ Record<StoragePluginName, StorageSubscribeEvents> &
13
+ Record<MemoryPluginName, MemorySubscribeEvents> &
14
+ Record<StatePluginName, StateSubscribeEvents> &
15
+ Record<SystemPluginName, SystemSubscribeEvents>;
16
+
17
+ export type GalleryPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
18
+
19
+ export type GalleryPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys>;
20
+
21
+ export type GalleryPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
@@ -0,0 +1,54 @@
1
+ import type { Module } from "@vnejs/module";
2
+
3
+ import type { GalleryTabContent } from "@vnejs/plugins.views.screens.gallery.contract";
4
+
5
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
6
+
7
+ export type GalleryCurrentItem = {
8
+ isStub?: boolean;
9
+ isOpened?: boolean;
10
+ fullName?: string;
11
+ src?: string;
12
+ mediaType?: string;
13
+ };
14
+
15
+ export type GalleryPluginState = {
16
+ isShow: boolean;
17
+ isForce: boolean;
18
+ locs?: Record<string, string>;
19
+ bgSrc?: string;
20
+ currentType?: string;
21
+ currentPage?: number;
22
+ pages?: number;
23
+ currentRow?: number | null;
24
+ currentColumn?: number | null;
25
+ currentItems?: GalleryCurrentItem[];
26
+ };
27
+
28
+ export type GalleryViewContext = {
29
+ emit: Module<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState>["emit"];
30
+ EVENTS: GalleryPluginEvents;
31
+ PARAMS: GalleryPluginParams;
32
+ };
33
+
34
+ export type GalleryOpenPayload = {
35
+ key?: string;
36
+ };
37
+
38
+ export type GalleryCheckPayload = {
39
+ key?: string;
40
+ };
41
+
42
+ export type GalleryPageSetPayload = {
43
+ page?: number;
44
+ };
45
+
46
+ export type GalleryTypeSetPayload = {
47
+ type?: string;
48
+ };
49
+
50
+ export type GalleryChoosePayload = {
51
+ index?: number;
52
+ };
53
+
54
+ export type GalleryMapTabContentPayload = GalleryTabContent;
@@ -0,0 +1,17 @@
1
+ import { useCallback, useMemo } from "react";
2
+
3
+ import { PositionBox, Svg } from "@vnejs/uis.react";
4
+
5
+ import type { GalleryViewContext } from "../../utils/gallery.js";
6
+
7
+ export const GalleryClose = ({ emit, EVENTS, PARAMS }: GalleryViewContext) => {
8
+ const onClick = useCallback(() => void emit(EVENTS.GALLERY.HIDE), [emit, EVENTS.GALLERY.HIDE]);
9
+
10
+ const propsSvg = useMemo(() => ({ ...PARAMS.GALLERY.VIEW_PROPS.close.svg, onClick }), [PARAMS.GALLERY.VIEW_PROPS.close.svg, onClick]);
11
+
12
+ return (
13
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.close.position}>
14
+ <Svg.Cross {...propsSvg} />
15
+ </PositionBox>
16
+ );
17
+ };
@@ -0,0 +1,31 @@
1
+ import { useCallback, useMemo } from "react";
2
+
3
+ import { PositionBox, TextControls } from "@vnejs/uis.react";
4
+
5
+ import type { GalleryViewContext } from "../../utils/gallery.js";
6
+
7
+ type GalleryControlsProps = GalleryViewContext & {
8
+ locs: Record<string, string>;
9
+ currentType: string;
10
+ };
11
+
12
+ export const GalleryControls = ({ locs, currentType, emit, EVENTS, PARAMS }: GalleryControlsProps) => {
13
+ const texts = useMemo(
14
+ () => Object.keys(PARAMS.GALLERY.TABS).map((key) => ({ text: locs[PARAMS.GALLERY.TABS[key].locKey], value: key })),
15
+ [locs, PARAMS.GALLERY.TABS],
16
+ );
17
+ const selectedIndex = useMemo(() => Object.keys(PARAMS.GALLERY.TABS).findIndex((key) => key === currentType), [currentType, PARAMS.GALLERY.TABS]);
18
+
19
+ const onClick = useCallback((type?: unknown) => void emit(EVENTS.GALLERY.TYPE_SET, { type }), [emit, EVENTS.GALLERY.TYPE_SET]);
20
+
21
+ const propsControls = useMemo(
22
+ () => ({ ...PARAMS.GALLERY.VIEW_PROPS.controls.controls, selectedIndex, texts, onClick }),
23
+ [PARAMS.GALLERY.VIEW_PROPS.controls.controls, selectedIndex, texts, onClick],
24
+ );
25
+
26
+ return (
27
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.controls.position}>
28
+ <TextControls {...propsControls} />
29
+ </PositionBox>
30
+ );
31
+ };
@@ -0,0 +1,44 @@
1
+ import { useCallback } from "react";
2
+
3
+ import { Flex, PositionBox, WrapWithContent } from "@vnejs/uis.react";
4
+
5
+ import type { GalleryCurrentItem, GalleryViewContext } from "../../utils/gallery.js";
6
+
7
+ type GalleryItemsProps = GalleryViewContext & {
8
+ currentItems?: GalleryCurrentItem[];
9
+ selectedIndex?: number;
10
+ };
11
+
12
+ export const GalleryItems = ({ currentItems = [], selectedIndex = -1, emit, EVENTS, PARAMS }: GalleryItemsProps) => {
13
+ const onSlotClick = useCallback((index?: unknown) => void emit(EVENTS.GALLERY.CHOOSE, { index: Number(index) }), [emit, EVENTS.GALLERY.CHOOSE]);
14
+
15
+ const renderSlot = useCallback(
16
+ (item: GalleryCurrentItem, i: number) => {
17
+ if (item.isStub)
18
+ return (
19
+ <div
20
+ {...PARAMS.GALLERY.VIEW_PROPS.items.stub}
21
+ key={i}
22
+ />
23
+ );
24
+
25
+ return (
26
+ <WrapWithContent
27
+ {...PARAMS.GALLERY.VIEW_PROPS.items.item}
28
+ key={item.isOpened ? item.src : i}
29
+ value={i}
30
+ imageSrc={item.isOpened ? item.src : undefined}
31
+ isSelected={selectedIndex === i}
32
+ onClick={item.isOpened ? onSlotClick : undefined}
33
+ />
34
+ );
35
+ },
36
+ [PARAMS.GALLERY.VIEW_PROPS.items, onSlotClick, selectedIndex],
37
+ );
38
+
39
+ return (
40
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.items.position}>
41
+ <Flex {...PARAMS.GALLERY.VIEW_PROPS.items.flex}>{currentItems.map(renderSlot)}</Flex>
42
+ </PositionBox>
43
+ );
44
+ };
@@ -0,0 +1,26 @@
1
+ import { useCallback, useMemo } from "react";
2
+
3
+ import { PageSelector, PositionBox } from "@vnejs/uis.react";
4
+
5
+ import type { GalleryViewContext } from "../../utils/gallery.js";
6
+
7
+ type GalleryPagesProps = GalleryViewContext & {
8
+ pagesCount?: number;
9
+ currentPage?: number;
10
+ };
11
+
12
+ export const GalleryPages = ({ pagesCount, currentPage, emit, EVENTS, PARAMS }: GalleryPagesProps) => {
13
+ const onPrevPage = useCallback(() => void emit(EVENTS.GALLERY.PAGE_SET, { page: currentPage! - 1 }), [emit, EVENTS.GALLERY.PAGE_SET, currentPage]);
14
+ const onNextPage = useCallback(() => void emit(EVENTS.GALLERY.PAGE_SET, { page: currentPage! + 1 }), [emit, EVENTS.GALLERY.PAGE_SET, currentPage]);
15
+
16
+ const propsSelector = useMemo(
17
+ () => ({ onPrevPage, onNextPage, pagesCount: pagesCount ?? 0, page: currentPage! + 1, pagesMinCount: 1 }),
18
+ [onPrevPage, onNextPage, pagesCount, currentPage],
19
+ );
20
+
21
+ return (
22
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.pages.position}>
23
+ <PageSelector {...propsSelector} />
24
+ </PositionBox>
25
+ );
26
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./GalleryClose.js";
2
+ export * from "./GalleryControls.js";
3
+ export * from "./GalleryItems.js";
4
+ export * from "./GalleryPages.js";
@@ -0,0 +1,49 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { ReactComponentProps } from "@vnejs/uis.react";
3
+ import { Screen, createRenderFunc, useMemo, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
6
+ import type { GalleryPluginState, GalleryViewContext } from "../utils/gallery.js";
7
+ import { GalleryClose, GalleryControls, GalleryItems, GalleryPages } from "./components/index.js";
8
+
9
+ type GalleryComponentProps = ReactComponentProps<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState>;
10
+
11
+ const Gallery = ({ store, onMount, PARAMS, emit, EVENTS }: GalleryComponentProps) => {
12
+ const {
13
+ isShow = false,
14
+ isForce = false,
15
+ locs = {},
16
+ bgSrc = "",
17
+ currentType = "",
18
+ currentItems = [],
19
+ pages,
20
+ currentColumn = null,
21
+ currentRow = null,
22
+ currentPage,
23
+ } = useStoreState<GalleryPluginState>(store, onMount);
24
+
25
+ const selectedIndex = currentColumn !== null && currentRow !== null ? currentColumn + currentRow * 3 : -1;
26
+
27
+ const viewProps = useMemo<GalleryViewContext>(() => ({ emit, EVENTS, PARAMS }), [emit, EVENTS, PARAMS]);
28
+ const propsScreen = useMemo(
29
+ () => ({ ...PARAMS.GALLERY.VIEW_PROPS.screen, isShow, isForce, bgSrc }),
30
+ [isShow, isForce, bgSrc, PARAMS.GALLERY.VIEW_PROPS.screen],
31
+ );
32
+ const propsControls = useMemo(() => ({ ...viewProps, currentType, locs }), [viewProps, currentType, locs]);
33
+ const propsPages = useMemo(() => ({ ...viewProps, pagesCount: pages, currentPage }), [viewProps, pages, currentPage]);
34
+ const propsItems = useMemo(
35
+ () => ({ ...viewProps, currentItems, currentType, selectedIndex, locs }),
36
+ [viewProps, currentItems, currentType, selectedIndex, locs],
37
+ );
38
+
39
+ return (
40
+ <Screen {...propsScreen}>
41
+ <GalleryControls {...propsControls} />
42
+ <GalleryPages {...propsPages} />
43
+ <GalleryItems {...propsItems} />
44
+ <GalleryClose {...viewProps} />
45
+ </Screen>
46
+ );
47
+ };
48
+
49
+ export const render: ViewRenderFunc<GalleryPluginState> = createRenderFunc(Gallery);
package/tsconfig.json ADDED
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "jsx": "react-jsx"
7
+ },
8
+ "include": ["src/**/*.ts", "src/**/*.tsx"],
9
+ "exclude": ["dist", "node_modules"]
10
+ }
package/const/events.js DELETED
@@ -1,13 +0,0 @@
1
- export const SUBSCRIBE_EVENTS = {
2
- OPEN: "vne:gallery:open",
3
- CHECK: "vne:gallery:check",
4
- CLEAR: "vne:gallery:clear",
5
-
6
- SHOW: "vne:gallery:show",
7
- HIDE: "vne:gallery:hide",
8
- PAGE_SET: "vne:gallery:page_set",
9
- TYPE_SET: "vne:gallery:type_set",
10
- UPDATE: "vne:gallery:update",
11
- PRELOAD: "vne:gallery:preload",
12
- CHOOSE: "vne:gallery:choose",
13
- };
package/const/params.js DELETED
@@ -1,32 +0,0 @@
1
- export const TABS = {};
2
-
3
- export const BACKGROUND = "save";
4
-
5
- export const TRANSITION = 300;
6
- export const ZINDEX = 4000;
7
-
8
- export const LOC_LABEL = "gallery";
9
-
10
- const [ITEM_WIDTH, ITEM_HEIGHT, ITEM_GAP] = [800, 450, 120];
11
-
12
- export const VIEW_PROPS = {
13
- screen: { withBackgroundDark: true, zIndex: ZINDEX, transition: TRANSITION },
14
- close: {
15
- position: { right: 120, top: 90 },
16
- svg: { size: 60 },
17
- },
18
- controls: {
19
- position: { top: 240, left: 120 },
20
- controls: { flexDirection: "column", flexGap: 60, textSize: 96 },
21
- },
22
- items: {
23
- position: { top: 240, right: 120 },
24
- flex: { gap: ITEM_GAP, withWrap: true, width: 2 * ITEM_GAP + 3 * ITEM_WIDTH },
25
- stub: { width: ITEM_WIDTH, height: ITEM_HEIGHT },
26
- item: { width: ITEM_WIDTH, height: ITEM_HEIGHT, withHover: true },
27
- },
28
- pages: { position: { bottom: 120, right: 120 } },
29
- };
30
-
31
- export const ROWS = 3;
32
- export const COLUMNS = 3;
package/index.js DELETED
@@ -1,10 +0,0 @@
1
- import { regPlugin } from "@vnejs/shared";
2
-
3
- import { SUBSCRIBE_EVENTS } from "./const/events";
4
- import * as params from "./const/params";
5
-
6
- import { GalleryController } from "./modules/controller";
7
- import { Gallery } from "./modules/gallery";
8
- import { GalleryView } from "./modules/view";
9
-
10
- regPlugin("GALLERY", { params, events: SUBSCRIBE_EVENTS }, [GalleryController, Gallery, GalleryView]);
@@ -1,19 +0,0 @@
1
- import { Module } from "@vnejs/module";
2
-
3
- const STORAGE_VALUE = 1;
4
-
5
- const isEqualStorageValueFunc = (value) => value === STORAGE_VALUE;
6
-
7
- export class Gallery extends Module {
8
- name = "gallery";
9
-
10
- subscribe = () => {
11
- this.on(this.EVENTS.GALLERY.OPEN, this.onOpen);
12
- this.on(this.EVENTS.GALLERY.CHECK, this.onCheck);
13
- this.on(this.EVENTS.GALLERY.CLEAR, this.onClear);
14
- };
15
-
16
- onOpen = ({ key } = {}) => this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
17
- onCheck = ({ key } = {}) => this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key }).then(isEqualStorageValueFunc);
18
- onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
19
- }
package/modules/view.js DELETED
@@ -1,14 +0,0 @@
1
- import { ModuleView } from "@vnejs/module.components";
2
-
3
- import { render } from "../view";
4
-
5
- export class GalleryView extends ModuleView {
6
- name = "gallery.view";
7
-
8
- locLabel = this.PARAMS.GALLERY.LOC_LABEL;
9
- animationTime = this.PARAMS.GALLERY.TRANSITION;
10
- updateEvent = this.EVENTS.GALLERY.UPDATE;
11
-
12
- renderFunc = render;
13
- updateHandler = this.onUpdateStoreComponent;
14
- }
@@ -1,15 +0,0 @@
1
- import { useCallback, useMemo } from "react";
2
-
3
- import { PositionBox, Svg } from "@vnejs/uis.react";
4
-
5
- export const GalleryClose = (props) => {
6
- const onClick = useCallback(() => props.emit(props.EVENTS.GALLERY.HIDE));
7
-
8
- const propsSvg = useMemo(() => ({ ...props.PARAMS.GALLERY.VIEW_PROPS.close.svg, onClick }), []);
9
-
10
- return (
11
- <PositionBox {...props.PARAMS.GALLERY.VIEW_PROPS.close.position}>
12
- <Svg.Cross {...propsSvg} />
13
- </PositionBox>
14
- );
15
- };
@@ -1,18 +0,0 @@
1
- import { useCallback, useMemo } from "react";
2
-
3
- import { PositionBox, TextControls } from "@vnejs/uis.react";
4
-
5
- export const GalleryControls = ({ locs, currentType, ...props } = {}) => {
6
- const texts = useMemo(() => Object.keys(props.PARAMS.GALLERY.TABS).map((key) => ({ text: locs[props.PARAMS.GALLERY.TABS[key].locKey], value: key })), [locs]);
7
- const selectedIndex = useMemo(() => Object.keys(props.PARAMS.GALLERY.TABS).findIndex((key) => key === currentType), [currentType]);
8
-
9
- const onClick = useCallback((type) => props.emit(props.EVENTS.GALLERY.TYPE_SET, { type }), []);
10
-
11
- const propsControls = useMemo(() => ({ ...props.PARAMS.GALLERY.VIEW_PROPS.controls.controls, selectedIndex, texts, onClick }), [selectedIndex, texts]);
12
-
13
- return (
14
- <PositionBox {...props.PARAMS.GALLERY.VIEW_PROPS.controls.position}>
15
- <TextControls {...propsControls} />
16
- </PositionBox>
17
- );
18
- };