@vnejs/plugins.controllers.screens.gallery 0.0.0-stage → 0.2.26
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 +1 -0
- package/dist/index.js +31 -0
- package/dist/modules/controller.accept.d.ts +12 -0
- package/dist/modules/controller.accept.js +26 -0
- package/dist/modules/controller.audio.d.ts +11 -0
- package/dist/modules/controller.audio.js +10 -0
- package/dist/modules/controller.bg.d.ts +14 -0
- package/dist/modules/controller.bg.js +12 -0
- package/dist/modules/controller.d.ts +15 -0
- package/dist/modules/controller.grid.d.ts +20 -0
- package/dist/modules/controller.grid.js +25 -0
- package/dist/modules/controller.js +16 -0
- package/dist/modules/controller.pages.d.ts +12 -0
- package/dist/modules/controller.pages.items.d.ts +27 -0
- package/dist/modules/controller.pages.items.js +29 -0
- package/dist/modules/controller.pages.js +17 -0
- package/dist/modules/controller.preload.d.ts +28 -0
- package/dist/modules/controller.preload.js +29 -0
- package/dist/modules/controller.tabs.d.ts +33 -0
- package/dist/modules/controller.tabs.js +29 -0
- package/dist/modules/gallery.d.ts +10 -0
- package/dist/modules/gallery.js +14 -0
- package/dist/modules/hide.controls.d.ts +8 -0
- package/dist/modules/hide.controls.js +7 -0
- package/dist/modules/hide.state.d.ts +6 -0
- package/dist/modules/hide.state.js +5 -0
- package/dist/modules/view.d.ts +10 -0
- package/dist/modules/view.js +9 -0
- package/dist/types.d.ts +29 -0
- package/dist/types.js +1 -0
- package/dist/utils/gallery.d.ts +21 -0
- package/dist/utils/gallery.js +2 -0
- package/dist/view/components/GalleryClose.d.ts +2 -0
- package/dist/view/components/GalleryClose.js +3 -0
- package/dist/view/components/GalleryControls.d.ts +7 -0
- package/dist/view/components/GalleryControls.js +10 -0
- package/dist/view/components/GalleryItems.d.ts +7 -0
- package/dist/view/components/GalleryItems.js +22 -0
- package/dist/view/components/GalleryPages.d.ts +7 -0
- package/dist/view/components/GalleryPages.js +6 -0
- package/dist/view/components/index.d.ts +4 -0
- package/dist/view/components/index.js +4 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +9 -0
- package/package.json +75 -4
- package/src/index.ts +35 -0
- package/src/modules/controller.accept.ts +41 -0
- package/src/modules/controller.audio.ts +16 -0
- package/src/modules/controller.bg.ts +25 -0
- package/src/modules/controller.grid.ts +41 -0
- package/src/modules/controller.pages.items.ts +47 -0
- package/src/modules/controller.pages.ts +28 -0
- package/src/modules/controller.preload.ts +48 -0
- package/src/modules/controller.tabs.ts +49 -0
- package/src/modules/controller.ts +28 -0
- package/src/modules/gallery.ts +25 -0
- package/src/modules/hide.controls.ts +17 -0
- package/src/modules/hide.state.ts +9 -0
- package/src/modules/view.ts +17 -0
- package/src/tests/accept.test.ts +98 -0
- package/src/tests/audio.test.ts +86 -0
- package/src/tests/controller.bg.test.ts +84 -0
- package/src/tests/gallery.test.ts +49 -0
- package/src/tests/grid.test.ts +189 -0
- package/src/tests/hide.controls.test.ts +55 -0
- package/src/tests/hide.state.test.ts +27 -0
- package/src/tests/pages.items.test.ts +48 -0
- package/src/tests/pages.test.ts +98 -0
- package/src/tests/preload.test.ts +75 -0
- package/src/tests/setup.ts +67 -0
- package/src/tests/tabs.test.ts +101 -0
- package/src/types.ts +42 -0
- package/src/utils/gallery.ts +26 -0
- package/src/view/components/GalleryClose.tsx +12 -0
- package/src/view/components/GalleryControls.tsx +26 -0
- package/src/view/components/GalleryItems.tsx +51 -0
- package/src/view/components/GalleryPages.tsx +24 -0
- package/src/view/components/index.ts +4 -0
- package/src/view/index.tsx +67 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "react";
|
|
3
|
+
import { Flex, PositionBox, WrapWithContent } from "@vnejs/uis.react";
|
|
4
|
+
export const GalleryItems = ({ gridItems = [], selectedIndex = -1, emit, EVENTS, PARAMS }) => {
|
|
5
|
+
const onSlotClick = (index) => {
|
|
6
|
+
const itemIndex = Number(index);
|
|
7
|
+
const item = gridItems[itemIndex];
|
|
8
|
+
void emit(EVENTS.GALLERY.CHOOSE, {
|
|
9
|
+
index: itemIndex,
|
|
10
|
+
fullName: item?.fullName,
|
|
11
|
+
mediaType: item?.mediaType,
|
|
12
|
+
layerChildType: item?.layerChildType,
|
|
13
|
+
isOpened: item?.isOpened,
|
|
14
|
+
variants: item?.variants,
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
return (_jsx(PositionBox, { ...PARAMS.GALLERY.VIEW_PROPS.items.position, children: _jsx(Flex, { ...PARAMS.GALLERY.VIEW_PROPS.items.flex, children: gridItems.map((item, i) => {
|
|
18
|
+
if (item.isStub)
|
|
19
|
+
return (_createElement("div", { ...PARAMS.GALLERY.VIEW_PROPS.items.stub, key: i }));
|
|
20
|
+
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 }));
|
|
21
|
+
}) }) }));
|
|
22
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GalleryViewContext } from "../../utils/gallery.js";
|
|
2
|
+
type GalleryPagesProps = GalleryViewContext & {
|
|
3
|
+
pagesCount?: number;
|
|
4
|
+
pageIndex?: number;
|
|
5
|
+
};
|
|
6
|
+
export declare const GalleryPages: ({ pagesCount, pageIndex, emit, EVENTS, PARAMS }: GalleryPagesProps) => import("react").JSX.Element;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { PageSelector, PositionBox } from "@vnejs/uis.react";
|
|
3
|
+
export const GalleryPages = ({ pagesCount = 0, pageIndex = 0, emit, EVENTS, PARAMS }) => {
|
|
4
|
+
const setPage = (nextPageIndex) => void emit(EVENTS.GALLERY.PAGE_SET, { pageIndex: nextPageIndex });
|
|
5
|
+
return (_jsx(PositionBox, { ...PARAMS.GALLERY.VIEW_PROPS.pages.position, children: _jsx(PageSelector, { onPrevPage: () => setPage(pageIndex - 1), onNextPage: () => setPage(pageIndex + 1), pagesCount: pagesCount, page: pageIndex + 1, pagesMinCount: 1 }) }));
|
|
6
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Screen, createRenderFunc, 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 = "", tab = "", gridItems = [], pagesCount, gridColumn = null, gridRow = null, pageIndex, } = useStoreState(store, onMount);
|
|
6
|
+
const selectedIndex = gridColumn !== null && gridRow !== null ? gridColumn + gridRow * PARAMS.GALLERY.COLUMNS : -1;
|
|
7
|
+
return (_jsxs(Screen, { ...PARAMS.GALLERY.VIEW_PROPS.screen, isShow: isShow, isForce: isForce, bgSrc: bgSrc, children: [_jsx(GalleryControls, { emit: emit, EVENTS: EVENTS, PARAMS: PARAMS, tab: tab, locs: locs }), _jsx(GalleryPages, { emit: emit, EVENTS: EVENTS, PARAMS: PARAMS, pagesCount: pagesCount, pageIndex: pageIndex }), _jsx(GalleryItems, { emit: emit, EVENTS: EVENTS, PARAMS: PARAMS, gridItems: gridItems, selectedIndex: selectedIndex }), _jsx(GalleryClose, { emit: emit, EVENTS: EVENTS, PARAMS: PARAMS })] }));
|
|
8
|
+
};
|
|
9
|
+
export const render = createRenderFunc(Gallery);
|
package/package.json
CHANGED
|
@@ -1,6 +1,77 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.controllers.screens.gallery",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.26",
|
|
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
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
23
|
+
"publish:major:plugin": "npm run publish:major",
|
|
24
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
25
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
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"
|
|
29
|
+
},
|
|
30
|
+
"author": "",
|
|
31
|
+
"license": "ISC",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/contracts.controllers.screens.gallery": "~0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.2.0",
|
|
37
|
+
"@vnejs/module.core": "~0.2.0",
|
|
38
|
+
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.controller.audio": "~0.2.0",
|
|
40
|
+
"@vnejs/module.controller.tabs": "~0.2.0",
|
|
41
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
42
|
+
"@vnejs/module.controller.arrows.grid": "~0.2.0",
|
|
43
|
+
"@vnejs/module.controller.bg": "~0.2.0",
|
|
44
|
+
"@vnejs/module.controller.pages": "~0.2.0",
|
|
45
|
+
"@vnejs/module.controller.hide.on.controls": "~0.2.0",
|
|
46
|
+
"@vnejs/module.controller.hide.on.state": "~0.2.0",
|
|
47
|
+
"@vnejs/contracts.audio": "~0.2.0",
|
|
48
|
+
"@vnejs/contracts.audio.music": "~0.2.0",
|
|
49
|
+
"@vnejs/contracts.canvas.layer": "~0.2.0",
|
|
50
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
51
|
+
"@vnejs/registry": "~0.2.0",
|
|
52
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
56
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
57
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
58
|
+
"@vnejs/contracts.audio": "~0.2.0",
|
|
59
|
+
"@vnejs/contracts.audio.music": "~0.2.0",
|
|
60
|
+
"@vnejs/contracts.canvas.layer": "~0.2.0",
|
|
61
|
+
"@vnejs/contracts.controls": "~0.2.0",
|
|
62
|
+
"@vnejs/contracts.controllers.screens.gallery": "~0.2.0",
|
|
63
|
+
"@vnejs/helpers": "~0.2.0",
|
|
64
|
+
"@vnejs/module.core": "~0.2.0",
|
|
65
|
+
"@vnejs/module.components": "~0.2.0",
|
|
66
|
+
"@vnejs/module.controller.audio": "~0.2.0",
|
|
67
|
+
"@vnejs/module.controller.tabs": "~0.2.0",
|
|
68
|
+
"@vnejs/module.controller.accept": "~0.2.0",
|
|
69
|
+
"@vnejs/module.controller.arrows.grid": "~0.2.0",
|
|
70
|
+
"@vnejs/module.controller.bg": "~0.2.0",
|
|
71
|
+
"@vnejs/module.controller.pages": "~0.2.0",
|
|
72
|
+
"@vnejs/module.controller.hide.on.controls": "~0.2.0",
|
|
73
|
+
"@vnejs/module.controller.hide.on.state": "~0.2.0",
|
|
74
|
+
"@vnejs/registry": "~0.2.0",
|
|
75
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
76
|
+
}
|
|
77
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.screens.gallery";
|
|
2
|
+
|
|
3
|
+
import { regPlugin } from "@vnejs/registry";
|
|
4
|
+
|
|
5
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gallery";
|
|
6
|
+
|
|
7
|
+
import { GalleryControllerAccept } from "./modules/controller.accept.js";
|
|
8
|
+
import { GalleryControllerAudio } from "./modules/controller.audio.js";
|
|
9
|
+
import { GalleryControllerBg } from "./modules/controller.bg.js";
|
|
10
|
+
import { GalleryControllerGrid } from "./modules/controller.grid.js";
|
|
11
|
+
import { GalleryController } from "./modules/controller.js";
|
|
12
|
+
import { GalleryControllerPagesItems } from "./modules/controller.pages.items.js";
|
|
13
|
+
import { GalleryControllerPages } from "./modules/controller.pages.js";
|
|
14
|
+
import { GalleryControllerPreload } from "./modules/controller.preload.js";
|
|
15
|
+
import { GalleryControllerTabs } from "./modules/controller.tabs.js";
|
|
16
|
+
import { Gallery } from "./modules/gallery.js";
|
|
17
|
+
import { GalleryHideControls } from "./modules/hide.controls.js";
|
|
18
|
+
import { GalleryHideState } from "./modules/hide.state.js";
|
|
19
|
+
import { GalleryView } from "./modules/view.js";
|
|
20
|
+
|
|
21
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
|
|
22
|
+
GalleryControllerAudio,
|
|
23
|
+
GalleryController,
|
|
24
|
+
GalleryControllerAccept,
|
|
25
|
+
GalleryControllerBg,
|
|
26
|
+
GalleryControllerGrid,
|
|
27
|
+
GalleryControllerPages,
|
|
28
|
+
GalleryControllerPagesItems,
|
|
29
|
+
GalleryControllerPreload,
|
|
30
|
+
GalleryHideControls,
|
|
31
|
+
GalleryHideState,
|
|
32
|
+
GalleryControllerTabs,
|
|
33
|
+
Gallery,
|
|
34
|
+
GalleryView,
|
|
35
|
+
]);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
|
|
2
|
+
|
|
3
|
+
import type { GalleryChoosePayload } from "@vnejs/contracts.controllers.screens.gallery";
|
|
4
|
+
|
|
5
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
6
|
+
import type { GalleryPluginState } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export class GalleryControllerAccept extends ModuleControllerAccept<
|
|
9
|
+
GalleryPluginEvents,
|
|
10
|
+
GalleryPluginConstants,
|
|
11
|
+
GalleryPluginSettings,
|
|
12
|
+
GalleryPluginParams,
|
|
13
|
+
GalleryPluginState
|
|
14
|
+
> {
|
|
15
|
+
name = "gallery.controller.accept";
|
|
16
|
+
|
|
17
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
18
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
19
|
+
EVENT_ACCEPT = this.EVENTS.GALLERY.ACCEPT;
|
|
20
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY.UPDATE_STATE;
|
|
21
|
+
|
|
22
|
+
CONTROLS_ZINDEX = this.PARAMS.GALLERY.ZINDEX;
|
|
23
|
+
|
|
24
|
+
onAccept = () => {
|
|
25
|
+
const { gridRow, gridColumn, gridItems } = this.state;
|
|
26
|
+
if (gridRow == null || gridColumn == null) return;
|
|
27
|
+
|
|
28
|
+
const index = gridColumn + gridRow * this.PARAMS.GALLERY.COLUMNS;
|
|
29
|
+
const item = gridItems?.[index];
|
|
30
|
+
if (!item || item.isStub || !item.isOpened) return;
|
|
31
|
+
|
|
32
|
+
void this.emit(this.EVENTS.GALLERY.CHOOSE, {
|
|
33
|
+
index,
|
|
34
|
+
fullName: item.fullName,
|
|
35
|
+
mediaType: item.mediaType,
|
|
36
|
+
layerChildType: item.layerChildType,
|
|
37
|
+
isOpened: item.isOpened,
|
|
38
|
+
variants: item.variants,
|
|
39
|
+
} satisfies GalleryChoosePayload);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ModuleControllerAudio } from "@vnejs/module.controller.audio";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class GalleryControllerAudio extends ModuleControllerAudio<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams> {
|
|
6
|
+
name = "gallery.controller.audio";
|
|
7
|
+
|
|
8
|
+
AUDIO_NAME = this.PARAMS.GALLERY.AUDIO_NAME;
|
|
9
|
+
AUDIO_START_DURATION = this.PARAMS.GALLERY.TRANSITION;
|
|
10
|
+
|
|
11
|
+
VOLUME_SETTING = this.SETTINGS.MUSIC.VOLUME;
|
|
12
|
+
|
|
13
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
14
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
15
|
+
EVENT_LOAD = this.EVENTS.GALLERY.PRELOAD;
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModuleControllerBg } from "@vnejs/module.controller.bg";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
import type { GalleryPluginState } from "../types.js";
|
|
5
|
+
export class GalleryControllerBg extends ModuleControllerBg<
|
|
6
|
+
GalleryPluginEvents,
|
|
7
|
+
GalleryPluginConstants,
|
|
8
|
+
GalleryPluginSettings,
|
|
9
|
+
GalleryPluginParams,
|
|
10
|
+
GalleryPluginState
|
|
11
|
+
> {
|
|
12
|
+
name = "gallery.controller.bg";
|
|
13
|
+
|
|
14
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
15
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
16
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY.UPDATE_STATE;
|
|
17
|
+
EVENT_UPDATE_FAST = this.EVENTS.GALLERY.UPDATE_FAST;
|
|
18
|
+
EVENT_PRELOAD = this.EVENTS.GALLERY.PRELOAD;
|
|
19
|
+
|
|
20
|
+
BGNAME = this.PARAMS.GALLERY.BACKGROUND;
|
|
21
|
+
|
|
22
|
+
QUALITY_SETTING = this.SETTINGS.LAYER.QUALITY;
|
|
23
|
+
|
|
24
|
+
IS_MEMORY_CLEARED_UPDATE_ENABLED = true;
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ModuleControllerArrowsGrid } from "@vnejs/module.controller.arrows.grid";
|
|
2
|
+
|
|
3
|
+
import type { GalleryCurrentItem } from "../utils/gallery.js";
|
|
4
|
+
|
|
5
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
6
|
+
import type { GalleryPluginState } from "../types.js";
|
|
7
|
+
export class GalleryControllerGrid extends ModuleControllerArrowsGrid<
|
|
8
|
+
GalleryPluginEvents,
|
|
9
|
+
GalleryPluginConstants,
|
|
10
|
+
GalleryPluginSettings,
|
|
11
|
+
GalleryPluginParams,
|
|
12
|
+
GalleryPluginState
|
|
13
|
+
> {
|
|
14
|
+
name = "gallery.controller.grid";
|
|
15
|
+
|
|
16
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
17
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
18
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY.UPDATE_STATE;
|
|
19
|
+
EVENT_UPDATE_FAST = this.EVENTS.GALLERY.UPDATE_FAST;
|
|
20
|
+
EVENT_GRID_NEXT = this.EVENTS.GALLERY.GRID_NEXT;
|
|
21
|
+
EVENT_GRID_PREV = this.EVENTS.GALLERY.GRID_PREV;
|
|
22
|
+
EVENT_GRID_CLEAR = this.EVENTS.GALLERY.GRID_CLEAR;
|
|
23
|
+
EVENT_GRID_UPDATE_ITEMS = this.EVENTS.GALLERY.GRID_UPDATE_ITEMS;
|
|
24
|
+
|
|
25
|
+
CONTROLS_ZINDEX = this.PARAMS.GALLERY.ZINDEX;
|
|
26
|
+
|
|
27
|
+
isDisableGridChangeVertical = true;
|
|
28
|
+
|
|
29
|
+
getMaxRows = () => this.PARAMS.GALLERY.ROWS;
|
|
30
|
+
getMaxColumns = () => this.PARAMS.GALLERY.COLUMNS;
|
|
31
|
+
getGridItems = async () => {
|
|
32
|
+
const { gridIndex = 0, tab = "" } = this.state;
|
|
33
|
+
const itemsOnPage = this.getMaxRows() * this.getMaxColumns();
|
|
34
|
+
const content = this.PARAMS.GALLERY.TABS[tab]?.content.slice(gridIndex * itemsOnPage, (gridIndex + 1) * itemsOnPage) ?? [];
|
|
35
|
+
|
|
36
|
+
const items = (await Promise.all(content.map((entry) => this.emitOne(this.EVENTS.GALLERY.PAGE_ITEMS_GET, entry)))) as GalleryCurrentItem[];
|
|
37
|
+
while (items.length < itemsOnPage) items.push({ isStub: true });
|
|
38
|
+
|
|
39
|
+
return items;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { MediaLoadPayload } from "@vnejs/module.components";
|
|
4
|
+
|
|
5
|
+
import type { GalleryMapTabContentPayload } from "@vnejs/contracts.controllers.screens.gallery";
|
|
6
|
+
|
|
7
|
+
import { normalizeGalleryOverlays, toGalleryMediaName } from "../utils/gallery.js";
|
|
8
|
+
|
|
9
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
10
|
+
|
|
11
|
+
export class GalleryControllerPagesItems extends ModuleCore<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams> {
|
|
12
|
+
name = "gallery.controller.pages.items";
|
|
13
|
+
|
|
14
|
+
subscribe = () => {
|
|
15
|
+
this.on(this.EVENTS.GALLERY.PAGE_ITEMS_GET, this.onPageItemsGet);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
onPageItemsGet = async (payload: GalleryMapTabContentPayload = {} as GalleryMapTabContentPayload) => {
|
|
19
|
+
const { check, mediaType, layerChildType, name, fullName, variations = [] } = payload;
|
|
20
|
+
|
|
21
|
+
const checkKey = toGalleryMediaName(check, layerChildType);
|
|
22
|
+
const isOpened = Boolean(await this.emitOne(this.EVENTS.GALLERY.CHECK, { key: checkKey }));
|
|
23
|
+
const mediaName = toGalleryMediaName(name, layerChildType);
|
|
24
|
+
const src = isOpened ? (await this.loadImageMedia(mediaName, mediaType, this.shared.settings[this.SETTINGS.LAYER.QUALITY])).src : "";
|
|
25
|
+
|
|
26
|
+
const variationVariants = await Promise.all(
|
|
27
|
+
variations.map(async ({ check: variationCheck, layerChildType: variationLayerChildType, name: variationName, overlays }) => {
|
|
28
|
+
const variationCheckKey = toGalleryMediaName(variationCheck ?? check, variationLayerChildType ?? layerChildType);
|
|
29
|
+
const isOpened = Boolean(await this.emitOne(this.EVENTS.GALLERY.CHECK, { key: variationCheckKey }));
|
|
30
|
+
|
|
31
|
+
return { layerChildType: variationLayerChildType, name: variationName, overlays: normalizeGalleryOverlays(overlays), isOpened };
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
const variants = variationVariants.length ? variationVariants : [{ isOpened, layerChildType, name: fullName }];
|
|
35
|
+
|
|
36
|
+
return { isOpened, layerChildType, fullName, src, mediaType, variants };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
loadImageMedia = (name: string, mediaType: string, quality: string | number): Promise<HTMLImageElement> =>
|
|
40
|
+
this.emitOne(this.EVENTS.MEDIA.LOAD, {
|
|
41
|
+
type: this.CONST.MEDIA.TYPES.IMAGE,
|
|
42
|
+
priority: this.CONST.MEDIA.PRIORITIES.HIGH,
|
|
43
|
+
quality,
|
|
44
|
+
name,
|
|
45
|
+
mediaType,
|
|
46
|
+
} satisfies MediaLoadPayload) as Promise<HTMLImageElement>;
|
|
47
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ModuleControllerPages } from "@vnejs/module.controller.pages";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
import type { GalleryPluginState } from "../types.js";
|
|
5
|
+
export class GalleryControllerPages extends ModuleControllerPages<
|
|
6
|
+
GalleryPluginEvents,
|
|
7
|
+
GalleryPluginConstants,
|
|
8
|
+
GalleryPluginSettings,
|
|
9
|
+
GalleryPluginParams,
|
|
10
|
+
GalleryPluginState
|
|
11
|
+
> {
|
|
12
|
+
name = "gallery.controller.pages";
|
|
13
|
+
|
|
14
|
+
EVENT_PAGE_SET = this.EVENTS.GALLERY.PAGE_SET;
|
|
15
|
+
EVENT_PAGE_NEXT = this.EVENTS.GALLERY.GRID_NEXT;
|
|
16
|
+
EVENT_PAGE_PREV = this.EVENTS.GALLERY.GRID_PREV;
|
|
17
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY.UPDATE_STATE;
|
|
18
|
+
EVENT_UPDATE_FAST = this.EVENTS.GALLERY.UPDATE_FAST;
|
|
19
|
+
|
|
20
|
+
applyPage = async () => {
|
|
21
|
+
await this.emit(this.EVENT_UPDATE_STATE, {
|
|
22
|
+
gridIndex: this.state.pageIndex ?? 0,
|
|
23
|
+
gridsCount: this.state.pagesCount ?? 0,
|
|
24
|
+
} satisfies Partial<GalleryPluginState>);
|
|
25
|
+
await this.emit(this.EVENTS.GALLERY.GRID_UPDATE_ITEMS);
|
|
26
|
+
this.emit(this.EVENTS.MEMORY.CLEAR);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { GalleryMapTabContentPayload } from "@vnejs/contracts.controllers.screens.gallery";
|
|
4
|
+
|
|
5
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
6
|
+
import type { GalleryPluginState } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export class GalleryControllerPreload extends ModuleCore<
|
|
9
|
+
GalleryPluginEvents,
|
|
10
|
+
GalleryPluginConstants,
|
|
11
|
+
GalleryPluginSettings,
|
|
12
|
+
GalleryPluginParams,
|
|
13
|
+
GalleryPluginState
|
|
14
|
+
> {
|
|
15
|
+
name = "gallery.controller.preload";
|
|
16
|
+
|
|
17
|
+
subscribe = () => {
|
|
18
|
+
this.on(this.EVENTS.GALLERY.PRELOAD, this.onPreload);
|
|
19
|
+
this.on(this.EVENTS.GALLERY.UPDATE_STATE, this.updateState);
|
|
20
|
+
this.on(this.EVENTS.MEMORY.CLEARED, this.onMemoryCleared);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
onPreload = () => Promise.all(this.getItemsInfo(Object.keys(this.PARAMS.GALLERY.TABS)[0], 0).map(this.preloadItem));
|
|
24
|
+
|
|
25
|
+
onMemoryCleared = () => {
|
|
26
|
+
if (!this.state.isShow) return;
|
|
27
|
+
|
|
28
|
+
const { pageIndex = 0, tab = "" } = this.state;
|
|
29
|
+
|
|
30
|
+
const promises = [...this.getItemsInfo(tab, pageIndex).map(this.preloadItem)];
|
|
31
|
+
|
|
32
|
+
if (pageIndex > 0) promises.push(...this.getItemsInfo(tab, pageIndex - 1).map(this.preloadItem));
|
|
33
|
+
if (pageIndex + 1 < this.getMaxPagesCount(tab)) promises.push(...this.getItemsInfo(tab, pageIndex + 1).map(this.preloadItem));
|
|
34
|
+
|
|
35
|
+
Object.keys(this.PARAMS.GALLERY.TABS).forEach((otherTab) => otherTab !== tab && promises.push(...this.getItemsInfo(otherTab, 0).map(this.preloadItem)));
|
|
36
|
+
|
|
37
|
+
return Promise.all(promises);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
preloadItem = (entry: GalleryMapTabContentPayload) => this.emitOne(this.EVENTS.GALLERY.PAGE_ITEMS_GET, entry) as Promise<unknown>;
|
|
41
|
+
|
|
42
|
+
getItemsOnPage = () => this.PARAMS.GALLERY.ROWS * this.PARAMS.GALLERY.COLUMNS;
|
|
43
|
+
getMaxPagesCount = (tab: string) => Math.ceil((this.PARAMS.GALLERY.TABS[tab]?.content.length ?? 0) / this.getItemsOnPage());
|
|
44
|
+
getItemsInfo = (tab: string, page: number) => {
|
|
45
|
+
const itemsOnPage = this.getItemsOnPage();
|
|
46
|
+
return this.PARAMS.GALLERY.TABS[tab].content.slice(page * itemsOnPage, (page + 1) * itemsOnPage);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ModuleControllerTabs } from "@vnejs/module.controller.tabs";
|
|
2
|
+
|
|
3
|
+
import type { ModuleControllerTabsTabSetPayload } from "@vnejs/module.controller.tabs";
|
|
4
|
+
|
|
5
|
+
import type { GalleryTabSetPayload } from "@vnejs/contracts.controllers.screens.gallery";
|
|
6
|
+
|
|
7
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
8
|
+
import type { GalleryPluginState } from "../types.js";
|
|
9
|
+
|
|
10
|
+
export class GalleryControllerTabs extends ModuleControllerTabs<
|
|
11
|
+
GalleryPluginEvents,
|
|
12
|
+
GalleryPluginConstants,
|
|
13
|
+
GalleryPluginSettings,
|
|
14
|
+
GalleryPluginParams,
|
|
15
|
+
GalleryPluginState
|
|
16
|
+
> {
|
|
17
|
+
name = "gallery.controller.tabs";
|
|
18
|
+
|
|
19
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
20
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
21
|
+
EVENT_TAB_SET = this.EVENTS.GALLERY.TAB_SET;
|
|
22
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY.UPDATE_STATE;
|
|
23
|
+
|
|
24
|
+
CONTROLS_ZINDEX = this.PARAMS.GALLERY.ZINDEX;
|
|
25
|
+
|
|
26
|
+
TABS = this.PARAMS.GALLERY.TABS;
|
|
27
|
+
|
|
28
|
+
onTabSet = async (payload: ModuleControllerTabsTabSetPayload = {}) => {
|
|
29
|
+
const { isUpdateView = true } = payload as GalleryTabSetPayload;
|
|
30
|
+
const tab = this.state.tab!;
|
|
31
|
+
const itemsOnPage = this.PARAMS.GALLERY.ROWS * this.PARAMS.GALLERY.COLUMNS;
|
|
32
|
+
const gridsCount = Math.ceil((this.PARAMS.GALLERY.TABS[tab]?.content.length ?? 0) / itemsOnPage);
|
|
33
|
+
|
|
34
|
+
await this.emit(this.EVENTS.GALLERY.UPDATE_STATE, {
|
|
35
|
+
tab,
|
|
36
|
+
pageIndex: 0,
|
|
37
|
+
pagesCount: gridsCount,
|
|
38
|
+
gridIndex: 0,
|
|
39
|
+
gridsCount,
|
|
40
|
+
} satisfies Partial<GalleryPluginState>);
|
|
41
|
+
await this.emit(this.EVENTS.GALLERY.GRID_CLEAR);
|
|
42
|
+
await this.emit(this.EVENTS.GALLERY.GRID_UPDATE_ITEMS);
|
|
43
|
+
|
|
44
|
+
if (!isUpdateView) return;
|
|
45
|
+
|
|
46
|
+
await this.emit(this.EVENTS.GALLERY.UPDATE_FAST);
|
|
47
|
+
this.emit(this.EVENTS.MEMORY.CLEAR);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
import type { GalleryPluginState } from "../types.js";
|
|
5
|
+
export class GalleryController extends ModuleController<
|
|
6
|
+
GalleryPluginEvents,
|
|
7
|
+
GalleryPluginConstants,
|
|
8
|
+
GalleryPluginSettings,
|
|
9
|
+
GalleryPluginParams,
|
|
10
|
+
GalleryPluginState
|
|
11
|
+
> {
|
|
12
|
+
name = "gallery.controller";
|
|
13
|
+
|
|
14
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GALLERY.UPDATE;
|
|
15
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY.UPDATE_STATE;
|
|
16
|
+
EVENT_UPDATE_FAST = this.EVENTS.GALLERY.UPDATE_FAST;
|
|
17
|
+
EVENT_UPDATE_FORCE = this.EVENTS.GALLERY.UPDATE_FORCE;
|
|
18
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
19
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
20
|
+
|
|
21
|
+
CONTROLS = {};
|
|
22
|
+
CONTROLS_INDEX = this.PARAMS.GALLERY.ZINDEX;
|
|
23
|
+
|
|
24
|
+
onShowBefore = async () => {
|
|
25
|
+
const tab = Object.keys(this.PARAMS.GALLERY.TABS)[0];
|
|
26
|
+
await this.emit(this.EVENTS.GALLERY.TAB_SET, { tab, isForce: true, isUpdateView: false });
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { GalleryCheckPayload, GalleryOpenPayload } from "@vnejs/contracts.controllers.screens.gallery";
|
|
4
|
+
|
|
5
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
6
|
+
|
|
7
|
+
const STORAGE_VALUE = 1;
|
|
8
|
+
|
|
9
|
+
const isEqualStorageValueFunc = (value: unknown) => value === STORAGE_VALUE;
|
|
10
|
+
|
|
11
|
+
export class Gallery extends ModuleCore<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams> {
|
|
12
|
+
name = "gallery";
|
|
13
|
+
|
|
14
|
+
subscribe = () => {
|
|
15
|
+
this.on(this.EVENTS.GALLERY.OPEN, this.onOpen);
|
|
16
|
+
this.on(this.EVENTS.GALLERY.CHECK, this.onCheck);
|
|
17
|
+
this.on(this.EVENTS.GALLERY.CLEAR, this.onClear);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
onOpen = ({ key }: GalleryOpenPayload = {}) => this.emit(this.EVENTS.STORAGE.SET, { module: this.name, key, value: STORAGE_VALUE });
|
|
21
|
+
|
|
22
|
+
onCheck = ({ key }: GalleryCheckPayload = {}) => this.emitOne(this.EVENTS.STORAGE.GET, { module: this.name, key })!.then(isEqualStorageValueFunc);
|
|
23
|
+
|
|
24
|
+
onClear = () => this.emit(this.EVENTS.STORAGE.RM_ALL, { module: this.name });
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class GalleryHideControls extends ModuleControllerHideOnControls<
|
|
6
|
+
GalleryPluginEvents,
|
|
7
|
+
GalleryPluginConstants,
|
|
8
|
+
GalleryPluginSettings,
|
|
9
|
+
GalleryPluginParams
|
|
10
|
+
> {
|
|
11
|
+
name = "gallery.hide.controls";
|
|
12
|
+
|
|
13
|
+
EVENT_SHOW = this.EVENTS.GALLERY.SHOW;
|
|
14
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
15
|
+
|
|
16
|
+
CONTROLS_ZINDEX = this.PARAMS.GALLERY.ZINDEX;
|
|
17
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class GalleryHideState extends ModuleControllerHideOnState<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams> {
|
|
6
|
+
name = "gallery.hide.state";
|
|
7
|
+
|
|
8
|
+
EVENT_HIDE = this.EVENTS.GALLERY.HIDE;
|
|
9
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
|
|
4
|
+
import type { GalleryPluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
import { render } from "../view/index.js";
|
|
7
|
+
export class GalleryView extends ModuleView<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState> {
|
|
8
|
+
name = "gallery.view";
|
|
9
|
+
|
|
10
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GALLERY.UPDATE;
|
|
11
|
+
|
|
12
|
+
LOC_LABEL = this.PARAMS.GALLERY.LOC_LABEL;
|
|
13
|
+
|
|
14
|
+
TRANSITION = this.PARAMS.GALLERY.TRANSITION;
|
|
15
|
+
|
|
16
|
+
renderFunc = render;
|
|
17
|
+
}
|