@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
@@ -0,0 +1 @@
1
+ import "@vnejs/plugins.views.screens.gallery.contract";
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import "@vnejs/plugins.views.screens.gallery.contract";
2
+ import { regPlugin } from "@vnejs/shared";
3
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.screens.gallery.contract";
4
+ import { GalleryController } from "./modules/controller.js";
5
+ import { Gallery } from "./modules/gallery.js";
6
+ import { GalleryView } from "./modules/view.js";
7
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [GalleryController, Gallery, GalleryView]);
@@ -0,0 +1,61 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
3
+ import type { GalleryMapTabContentPayload, GalleryPageSetPayload, GalleryPluginState, GalleryTypeSetPayload } from "../utils/gallery.js";
4
+ export declare class GalleryController extends ModuleController<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState> {
5
+ name: string;
6
+ updateEvent: "vne:gallery:update";
7
+ bgName: "save";
8
+ maxPagesCount: Record<string, number>;
9
+ itemsOnPage: number;
10
+ emitHide: () => undefined;
11
+ initRowAndColumns: () => Promise<unknown[]> | undefined;
12
+ incRow: () => Promise<unknown[]> | undefined;
13
+ decRow: () => Promise<unknown[]> | undefined;
14
+ incColumn: () => Promise<unknown[]> | undefined;
15
+ decColumn: () => Promise<unknown[]> | undefined;
16
+ accept: () => undefined;
17
+ onPrevTab: () => void;
18
+ onNextTab: () => void;
19
+ controls: {
20
+ abstract_back: () => undefined;
21
+ abstract_menu: () => undefined;
22
+ abstract_gamemenu: () => undefined;
23
+ abstract_arrow_up: () => undefined;
24
+ abstract_arrow_right: () => undefined;
25
+ abstract_arrow_bottom: () => undefined;
26
+ abstract_arrow_left: () => undefined;
27
+ abstract_tab_prev: () => undefined;
28
+ abstract_tab_next: () => undefined;
29
+ abstract_accept: () => undefined;
30
+ abstract_interact: () => undefined;
31
+ };
32
+ controlsIndex: number;
33
+ subscribe: () => void;
34
+ init: () => void;
35
+ beforeShow: () => Promise<void>;
36
+ afterHide: () => void;
37
+ onStarted: () => void;
38
+ onPreload: () => Promise<[HTMLImageElement, ...{
39
+ isOpened: boolean;
40
+ fullName: string;
41
+ src: string;
42
+ mediaType: string;
43
+ }[]]>;
44
+ onMemoryCleared: () => Promise<unknown[]> | undefined;
45
+ onPageSet: ({ page }?: GalleryPageSetPayload) => false | Promise<void>;
46
+ onTypeSet: ({ type }?: GalleryTypeSetPayload) => false | Promise<void>;
47
+ updatePageAndType: (page?: number, type?: string | false, isUpdateView?: boolean) => Promise<void>;
48
+ mapTabContent: ({ check, mediaType, name, fullName }?: GalleryMapTabContentPayload) => Promise<{
49
+ isOpened: boolean;
50
+ fullName: string;
51
+ src: string;
52
+ mediaType: string;
53
+ }>;
54
+ getItemsInfo: (type: string, page: number) => {
55
+ check: string;
56
+ mediaType: string;
57
+ name: string;
58
+ fullName: string;
59
+ }[];
60
+ calcMaxPageCount: (type: string) => void;
61
+ }
@@ -0,0 +1,144 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ export class GalleryController extends ModuleController {
3
+ name = "gallery.controller";
4
+ updateEvent = this.EVENTS.GALLERY.UPDATE;
5
+ bgName = this.PARAMS.GALLERY.BACKGROUND;
6
+ maxPagesCount = {};
7
+ itemsOnPage;
8
+ emitHide = () => void this.emit(this.EVENTS.GALLERY.HIDE);
9
+ initRowAndColumns = () => this.updateStateAndViewFast({ currentRow: 0, currentColumn: 0 });
10
+ incRow = () => {
11
+ if (this.state.currentRow === null || this.state.currentColumn === null)
12
+ return this.initRowAndColumns();
13
+ const maxRows = this.PARAMS.GALLERY.ROWS;
14
+ if ((this.state.currentRow ?? 0) + 1 < maxRows) {
15
+ this.updateStateAndView({ currentRow: this.state.currentRow + 1 });
16
+ }
17
+ else if (this.state.currentPage + 1 < this.state.pages) {
18
+ this.updateState({ currentRow: 0 });
19
+ this.updatePageAndType(this.state.currentPage + 1, false, true);
20
+ }
21
+ };
22
+ decRow = () => {
23
+ if (this.state.currentRow === null || this.state.currentColumn === null)
24
+ return this.initRowAndColumns();
25
+ const maxRows = this.PARAMS.GALLERY.ROWS;
26
+ if (this.state.currentRow !== 0) {
27
+ this.updateStateAndView({ currentRow: this.state.currentRow - 1 });
28
+ }
29
+ else if (this.state.currentPage > 0) {
30
+ this.updateState({ currentRow: maxRows - 1 });
31
+ this.updatePageAndType(this.state.currentPage - 1, false, true);
32
+ }
33
+ };
34
+ incColumn = () => {
35
+ if (this.state.currentRow === null || this.state.currentColumn === null)
36
+ return this.initRowAndColumns();
37
+ const maxColumns = this.PARAMS.GALLERY.COLUMNS;
38
+ if ((this.state.currentColumn ?? 0) + 1 < maxColumns) {
39
+ this.updateStateAndView({ currentColumn: this.state.currentColumn + 1 });
40
+ }
41
+ else if (this.state.currentPage + 1 < this.state.pages) {
42
+ this.updateState({ currentColumn: 0 });
43
+ this.updatePageAndType(this.state.currentPage + 1, false, true);
44
+ }
45
+ };
46
+ decColumn = () => {
47
+ if (this.state.currentRow === null || this.state.currentColumn === null)
48
+ return this.initRowAndColumns();
49
+ const maxColumns = this.PARAMS.GALLERY.COLUMNS;
50
+ if (this.state.currentColumn !== 0) {
51
+ this.updateStateAndView({ currentColumn: this.state.currentColumn - 1 });
52
+ }
53
+ else if (this.state.currentPage > 0) {
54
+ this.updateState({ currentColumn: maxColumns - 1 });
55
+ this.updatePageAndType(this.state.currentPage - 1, false, true);
56
+ }
57
+ };
58
+ accept = () => void this.emit(this.EVENTS.GALLERY.CHOOSE, {
59
+ index: this.state.currentColumn + this.state.currentRow * this.PARAMS.GALLERY.COLUMNS,
60
+ });
61
+ onPrevTab = () => {
62
+ const keys = Object.keys(this.PARAMS.GALLERY.TABS);
63
+ const currentTypeIndex = keys.findIndex((key) => key === this.state.currentType);
64
+ const type = currentTypeIndex === 0 ? keys[keys.length - 1] : keys[(currentTypeIndex - 1) % keys.length];
65
+ void this.emit(this.EVENTS.GALLERY.TYPE_SET, { type });
66
+ };
67
+ onNextTab = () => {
68
+ const keys = Object.keys(this.PARAMS.GALLERY.TABS);
69
+ const currentTypeIndex = keys.findIndex((key) => key === this.state.currentType);
70
+ const type = currentTypeIndex === keys.length - 1 ? keys[0] : keys[(currentTypeIndex + 1) % keys.length];
71
+ void this.emit(this.EVENTS.GALLERY.TYPE_SET, { type });
72
+ };
73
+ controls = {
74
+ [this.CONST.CONTROLS.BUTTONS.BACK]: () => void this.emitHide(),
75
+ [this.CONST.CONTROLS.BUTTONS.MENU]: () => void this.emitHide(),
76
+ [this.CONST.CONTROLS.BUTTONS.GAMEMENU]: () => void this.emitHide(),
77
+ [this.CONST.CONTROLS.BUTTONS.ARROW_UP]: () => void this.decRow(),
78
+ [this.CONST.CONTROLS.BUTTONS.ARROW_RIGHT]: () => void this.incColumn(),
79
+ [this.CONST.CONTROLS.BUTTONS.ARROW_BOTTOM]: () => void this.incRow(),
80
+ [this.CONST.CONTROLS.BUTTONS.ARROW_LEFT]: () => void this.decColumn(),
81
+ [this.CONST.CONTROLS.BUTTONS.TAB_PREV]: () => void this.onPrevTab(),
82
+ [this.CONST.CONTROLS.BUTTONS.TAB_NEXT]: () => void this.onNextTab(),
83
+ [this.CONST.CONTROLS.BUTTONS.ACCEPT]: () => void this.accept(),
84
+ [this.CONST.CONTROLS.BUTTONS.INTERACT]: () => void this.accept(),
85
+ };
86
+ controlsIndex = this.PARAMS.GALLERY.ZINDEX;
87
+ subscribe = () => {
88
+ this.on(this.EVENTS.GALLERY.SHOW, this.onShow);
89
+ this.on(this.EVENTS.GALLERY.HIDE, this.onHide);
90
+ this.on(this.EVENTS.GALLERY.PAGE_SET, this.onPageSet);
91
+ this.on(this.EVENTS.GALLERY.TYPE_SET, this.onTypeSet);
92
+ this.on(this.EVENTS.GALLERY.PRELOAD, this.onPreload);
93
+ this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
94
+ this.on(this.EVENTS.STATE.CLEAR, this.onHide);
95
+ this.on(this.EVENTS.SYSTEM.STARTED, this.onStarted);
96
+ };
97
+ init = () => {
98
+ this.itemsOnPage = this.PARAMS.GALLERY.ROWS * this.PARAMS.GALLERY.COLUMNS;
99
+ this.updateState({ currentType: Object.keys(this.PARAMS.GALLERY.TABS)[0], currentPage: 0 });
100
+ };
101
+ beforeShow = async () => {
102
+ this.updateState({ bgSrc: (await this.loadBgMedia()).src, currentRow: null, currentColumn: null });
103
+ return this.updatePageAndType(0, Object.keys(this.PARAMS.GALLERY.TABS)[0], false);
104
+ };
105
+ afterHide = () => this.setDefaultState();
106
+ onStarted = () => Object.keys(this.PARAMS.GALLERY.TABS).forEach(this.calcMaxPageCount);
107
+ onPreload = () => Promise.all([this.loadBgMedia(), ...this.getItemsInfo(Object.keys(this.PARAMS.GALLERY.TABS)[0], 0).map(this.mapTabContent)]);
108
+ onMemoryCleared = () => {
109
+ if (!this.state.isShow)
110
+ return;
111
+ const { currentPage = 0, currentType = "" } = this.state;
112
+ const promises = [this.loadBgMedia(), ...this.getItemsInfo(currentType, currentPage).map(this.mapTabContent)];
113
+ if (currentPage > 0)
114
+ promises.push(...this.getItemsInfo(currentType, currentPage - 1).map(this.mapTabContent));
115
+ if (currentPage + 1 < this.maxPagesCount[currentType])
116
+ promises.push(...this.getItemsInfo(currentType, currentPage + 1).map(this.mapTabContent));
117
+ Object.keys(this.PARAMS.GALLERY.TABS).forEach((type) => type !== currentType && promises.push(...this.getItemsInfo(type, 0).map(this.mapTabContent)));
118
+ return Promise.all(promises);
119
+ };
120
+ onPageSet = ({ page } = {}) => page !== this.state.currentPage && this.updatePageAndType(page);
121
+ onTypeSet = ({ type } = {}) => type !== this.state.currentType && this.updatePageAndType(0, type);
122
+ updatePageAndType = async (page, type, isUpdateView = true) => {
123
+ this.updateState({ currentPage: page });
124
+ if (type)
125
+ this.updateState({ currentType: type, pages: this.maxPagesCount[type], currentColumn: null, currentRow: null });
126
+ const currentItems = await Promise.all(this.getItemsInfo(this.state.currentType, this.state.currentPage).map(this.mapTabContent));
127
+ const items = [...currentItems];
128
+ while (items.length < this.itemsOnPage)
129
+ items.push({ isStub: true });
130
+ this.updateState({ currentItems: items });
131
+ if (isUpdateView)
132
+ await this.updateViewFast();
133
+ this.emit(this.EVENTS.MEMORY.CLEAR);
134
+ };
135
+ mapTabContent = async ({ check, mediaType, name, fullName } = { check: "", mediaType: "", name: "", fullName: "" }) => {
136
+ const isOpened = Boolean(await this.emitOne(this.EVENTS.GALLERY.CHECK, { key: check }));
137
+ const src = isOpened ? (await this.loadImageMedia(name, mediaType, this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src : "";
138
+ return { isOpened, fullName, src, mediaType };
139
+ };
140
+ getItemsInfo = (type, page) => this.PARAMS.GALLERY.TABS[type].content.slice(page * this.itemsOnPage, (page + 1) * this.itemsOnPage);
141
+ calcMaxPageCount = (type) => {
142
+ this.maxPagesCount[type] = Math.ceil(this.PARAMS.GALLERY.TABS[type].content.length / this.itemsOnPage);
143
+ };
144
+ }
@@ -0,0 +1,10 @@
1
+ import { Module } from "@vnejs/module";
2
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
3
+ import type { GalleryCheckPayload, GalleryOpenPayload } from "../utils/gallery.js";
4
+ export declare class Gallery extends Module<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onOpen: ({ key }?: GalleryOpenPayload) => Promise<unknown[]> | undefined;
8
+ onCheck: ({ key }?: GalleryCheckPayload) => Promise<boolean>;
9
+ onClear: () => Promise<unknown[]> | undefined;
10
+ }
@@ -0,0 +1,14 @@
1
+ import { Module } from "@vnejs/module";
2
+ const STORAGE_VALUE = 1;
3
+ const isEqualStorageValueFunc = (value) => value === STORAGE_VALUE;
4
+ export class Gallery extends Module {
5
+ name = "gallery";
6
+ subscribe = () => {
7
+ this.on(this.EVENTS.GALLERY.OPEN, this.onOpen);
8
+ this.on(this.EVENTS.GALLERY.CHECK, this.onCheck);
9
+ this.on(this.EVENTS.GALLERY.CLEAR, this.onClear);
10
+ };
11
+ onOpen = ({ key } = {}) => this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
12
+ onCheck = ({ key } = {}) => this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key }).then(isEqualStorageValueFunc);
13
+ onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
14
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
3
+ import type { GalleryPluginState } from "../utils/gallery.js";
4
+ export declare class GalleryView extends ModuleView<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState> {
5
+ name: string;
6
+ locLabel: string;
7
+ animationTime: number;
8
+ updateEvent: "vne:gallery:update";
9
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<GalleryPluginState>;
10
+ updateHandler: (state?: GalleryPluginState | undefined) => Promise<void>;
11
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class GalleryView extends ModuleView {
4
+ name = "gallery.view";
5
+ locLabel = this.PARAMS.GALLERY.LOC_LABEL;
6
+ animationTime = this.PARAMS.GALLERY.TRANSITION;
7
+ updateEvent = this.EVENTS.GALLERY.UPDATE;
8
+ renderFunc = render;
9
+ updateHandler = this.onUpdateStoreComponent;
10
+ }
@@ -0,0 +1,12 @@
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
+ export type GalleryPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<StoragePluginName, StorageSubscribeEvents> & Record<MemoryPluginName, MemorySubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<SystemPluginName, SystemSubscribeEvents>;
10
+ export type GalleryPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
11
+ export type GalleryPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys>;
12
+ export type GalleryPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ import type { Module } from "@vnejs/module";
2
+ import type { GalleryTabContent } from "@vnejs/plugins.views.screens.gallery.contract";
3
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
4
+ export type GalleryCurrentItem = {
5
+ isStub?: boolean;
6
+ isOpened?: boolean;
7
+ fullName?: string;
8
+ src?: string;
9
+ mediaType?: string;
10
+ };
11
+ export type GalleryPluginState = {
12
+ isShow: boolean;
13
+ isForce: boolean;
14
+ locs?: Record<string, string>;
15
+ bgSrc?: string;
16
+ currentType?: string;
17
+ currentPage?: number;
18
+ pages?: number;
19
+ currentRow?: number | null;
20
+ currentColumn?: number | null;
21
+ currentItems?: GalleryCurrentItem[];
22
+ };
23
+ export type GalleryViewContext = {
24
+ emit: Module<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState>["emit"];
25
+ EVENTS: GalleryPluginEvents;
26
+ PARAMS: GalleryPluginParams;
27
+ };
28
+ export type GalleryOpenPayload = {
29
+ key?: string;
30
+ };
31
+ export type GalleryCheckPayload = {
32
+ key?: string;
33
+ };
34
+ export type GalleryPageSetPayload = {
35
+ page?: number;
36
+ };
37
+ export type GalleryTypeSetPayload = {
38
+ type?: string;
39
+ };
40
+ export type GalleryChoosePayload = {
41
+ index?: number;
42
+ };
43
+ export type GalleryMapTabContentPayload = GalleryTabContent;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { GalleryViewContext } from "../../utils/gallery.js";
2
+ export declare const GalleryClose: ({ emit, EVENTS, PARAMS }: GalleryViewContext) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from "react";
3
+ import { PositionBox, Svg } from "@vnejs/uis.react";
4
+ export const GalleryClose = ({ emit, EVENTS, PARAMS }) => {
5
+ const onClick = useCallback(() => void emit(EVENTS.GALLERY.HIDE), [emit, EVENTS.GALLERY.HIDE]);
6
+ const propsSvg = useMemo(() => ({ ...PARAMS.GALLERY.VIEW_PROPS.close.svg, onClick }), [PARAMS.GALLERY.VIEW_PROPS.close.svg, onClick]);
7
+ return (_jsx(PositionBox, { ...PARAMS.GALLERY.VIEW_PROPS.close.position, children: _jsx(Svg.Cross, { ...propsSvg }) }));
8
+ };
@@ -0,0 +1,7 @@
1
+ import type { GalleryViewContext } from "../../utils/gallery.js";
2
+ type GalleryControlsProps = GalleryViewContext & {
3
+ locs: Record<string, string>;
4
+ currentType: string;
5
+ };
6
+ export declare const GalleryControls: ({ locs, currentType, emit, EVENTS, PARAMS }: GalleryControlsProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from "react";
3
+ import { PositionBox, TextControls } from "@vnejs/uis.react";
4
+ export const GalleryControls = ({ locs, currentType, emit, EVENTS, PARAMS }) => {
5
+ const texts = useMemo(() => Object.keys(PARAMS.GALLERY.TABS).map((key) => ({ text: locs[PARAMS.GALLERY.TABS[key].locKey], value: key })), [locs, PARAMS.GALLERY.TABS]);
6
+ const selectedIndex = useMemo(() => Object.keys(PARAMS.GALLERY.TABS).findIndex((key) => key === currentType), [currentType, PARAMS.GALLERY.TABS]);
7
+ const onClick = useCallback((type) => void emit(EVENTS.GALLERY.TYPE_SET, { type }), [emit, EVENTS.GALLERY.TYPE_SET]);
8
+ const propsControls = useMemo(() => ({ ...PARAMS.GALLERY.VIEW_PROPS.controls.controls, selectedIndex, texts, onClick }), [PARAMS.GALLERY.VIEW_PROPS.controls.controls, selectedIndex, texts, onClick]);
9
+ return (_jsx(PositionBox, { ...PARAMS.GALLERY.VIEW_PROPS.controls.position, children: _jsx(TextControls, { ...propsControls }) }));
10
+ };
@@ -0,0 +1,7 @@
1
+ import type { GalleryCurrentItem, GalleryViewContext } from "../../utils/gallery.js";
2
+ type GalleryItemsProps = GalleryViewContext & {
3
+ currentItems?: GalleryCurrentItem[];
4
+ selectedIndex?: number;
5
+ };
6
+ export declare const GalleryItems: ({ currentItems, selectedIndex, emit, EVENTS, PARAMS }: GalleryItemsProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { useCallback } from "react";
4
+ import { Flex, PositionBox, WrapWithContent } from "@vnejs/uis.react";
5
+ export const GalleryItems = ({ currentItems = [], selectedIndex = -1, emit, EVENTS, PARAMS }) => {
6
+ const onSlotClick = useCallback((index) => void emit(EVENTS.GALLERY.CHOOSE, { index: Number(index) }), [emit, EVENTS.GALLERY.CHOOSE]);
7
+ const renderSlot = useCallback((item, i) => {
8
+ if (item.isStub)
9
+ return (_createElement("div", { ...PARAMS.GALLERY.VIEW_PROPS.items.stub, key: i }));
10
+ return (_createElement(WrapWithContent, { ...PARAMS.GALLERY.VIEW_PROPS.items.item, key: item.isOpened ? item.src : i, value: i, imageSrc: item.isOpened ? item.src : undefined, isSelected: selectedIndex === i, onClick: item.isOpened ? onSlotClick : undefined }));
11
+ }, [PARAMS.GALLERY.VIEW_PROPS.items, onSlotClick, selectedIndex]);
12
+ return (_jsx(PositionBox, { ...PARAMS.GALLERY.VIEW_PROPS.items.position, children: _jsx(Flex, { ...PARAMS.GALLERY.VIEW_PROPS.items.flex, children: currentItems.map(renderSlot) }) }));
13
+ };
@@ -0,0 +1,7 @@
1
+ import type { GalleryViewContext } from "../../utils/gallery.js";
2
+ type GalleryPagesProps = GalleryViewContext & {
3
+ pagesCount?: number;
4
+ currentPage?: number;
5
+ };
6
+ export declare const GalleryPages: ({ pagesCount, currentPage, emit, EVENTS, PARAMS }: GalleryPagesProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useCallback, useMemo } from "react";
3
+ import { PageSelector, PositionBox } from "@vnejs/uis.react";
4
+ export const GalleryPages = ({ pagesCount, currentPage, emit, EVENTS, PARAMS }) => {
5
+ const onPrevPage = useCallback(() => void emit(EVENTS.GALLERY.PAGE_SET, { page: currentPage - 1 }), [emit, EVENTS.GALLERY.PAGE_SET, currentPage]);
6
+ const onNextPage = useCallback(() => void emit(EVENTS.GALLERY.PAGE_SET, { page: currentPage + 1 }), [emit, EVENTS.GALLERY.PAGE_SET, currentPage]);
7
+ const propsSelector = useMemo(() => ({ onPrevPage, onNextPage, pagesCount: pagesCount ?? 0, page: currentPage + 1, pagesMinCount: 1 }), [onPrevPage, onNextPage, pagesCount, currentPage]);
8
+ return (_jsx(PositionBox, { ...PARAMS.GALLERY.VIEW_PROPS.pages.position, children: _jsx(PageSelector, { ...propsSelector }) }));
9
+ };
@@ -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,4 @@
1
+ export * from "./GalleryClose.js";
2
+ export * from "./GalleryControls.js";
3
+ export * from "./GalleryItems.js";
4
+ export * from "./GalleryPages.js";
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { GalleryPluginState } from "../utils/gallery.js";
3
+ export declare const render: ViewRenderFunc<GalleryPluginState>;
@@ -0,0 +1,14 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Screen, createRenderFunc, useMemo, useStoreState } from "@vnejs/uis.react";
3
+ import { GalleryClose, GalleryControls, GalleryItems, GalleryPages } from "./components/index.js";
4
+ const Gallery = ({ store, onMount, PARAMS, emit, EVENTS }) => {
5
+ const { isShow = false, isForce = false, locs = {}, bgSrc = "", currentType = "", currentItems = [], pages, currentColumn = null, currentRow = null, currentPage, } = useStoreState(store, onMount);
6
+ const selectedIndex = currentColumn !== null && currentRow !== null ? currentColumn + currentRow * 3 : -1;
7
+ const viewProps = useMemo(() => ({ emit, EVENTS, PARAMS }), [emit, EVENTS, PARAMS]);
8
+ const propsScreen = useMemo(() => ({ ...PARAMS.GALLERY.VIEW_PROPS.screen, isShow, isForce, bgSrc }), [isShow, isForce, bgSrc, PARAMS.GALLERY.VIEW_PROPS.screen]);
9
+ const propsControls = useMemo(() => ({ ...viewProps, currentType, locs }), [viewProps, currentType, locs]);
10
+ const propsPages = useMemo(() => ({ ...viewProps, pagesCount: pages, currentPage }), [viewProps, pages, currentPage]);
11
+ const propsItems = useMemo(() => ({ ...viewProps, currentItems, currentType, selectedIndex, locs }), [viewProps, currentItems, currentType, selectedIndex, locs]);
12
+ return (_jsxs(Screen, { ...propsScreen, children: [_jsx(GalleryControls, { ...propsControls }), _jsx(GalleryPages, { ...propsPages }), _jsx(GalleryItems, { ...propsItems }), _jsx(GalleryClose, { ...viewProps })] }));
13
+ };
14
+ export const render = createRenderFunc(Gallery);
package/package.json CHANGED
@@ -1,17 +1,51 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.views.screens.gallery",
3
- "version": "0.1.5",
4
- "main": "index.js",
3
+ "version": "0.1.7",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "require": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "src",
18
+ "tsconfig.json"
19
+ ],
5
20
  "scripts": {
6
21
  "test": "echo \"Error: no test specified\" && exit 1",
22
+ "build": "npx @vnejs/monorepo package",
7
23
  "publish:major:plugin": "npm run publish:major",
8
24
  "publish:minor:plugin": "npm run publish:minor",
9
25
  "publish:patch:plugin": "npm run publish:patch",
10
- "publish:major": "npm version major && npm publish --access public",
11
- "publish:minor": "npm version minor && npm publish --access public",
12
- "publish:patch": "npm version patch && npm publish --access public"
26
+ "publish:major": "npx @vnejs/monorepo publish major --access public",
27
+ "publish:minor": "npx @vnejs/monorepo publish minor --access public",
28
+ "publish:patch": "npx @vnejs/monorepo publish patch --access public"
13
29
  },
14
30
  "author": "",
15
31
  "license": "ISC",
16
- "description": ""
32
+ "dependencies": {
33
+ "@vnejs/plugins.views.screens.gallery.contract": "~0.0.1"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/helpers": "~0.1.0",
37
+ "@vnejs/module": "~0.0.1",
38
+ "@vnejs/module.components": "~0.0.1",
39
+ "@vnejs/plugins.canvas.layer.contract": "~0.0.1",
40
+ "@vnejs/plugins.controls.contract": "~0.0.1",
41
+ "@vnejs/plugins.core.memory.contract": "~0.0.1",
42
+ "@vnejs/plugins.core.state.contract": "~0.0.1",
43
+ "@vnejs/plugins.core.storage.contract": "~0.0.1",
44
+ "@vnejs/plugins.core.system.contract": "~0.0.1",
45
+ "@vnejs/shared": "~0.0.9",
46
+ "@vnejs/uis.react": "~0.1.0"
47
+ },
48
+ "devDependencies": {
49
+ "@vnejs/configs.ts-common": "~0.0.1"
50
+ }
17
51
  }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ import "@vnejs/plugins.views.screens.gallery.contract";
2
+
3
+ import { regPlugin } from "@vnejs/shared";
4
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/plugins.views.screens.gallery.contract";
5
+
6
+ import { GalleryController } from "./modules/controller.js";
7
+ import { Gallery } from "./modules/gallery.js";
8
+ import { GalleryView } from "./modules/view.js";
9
+
10
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [GalleryController, Gallery, GalleryView]);