@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.
Files changed (81) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +31 -0
  3. package/dist/modules/controller.accept.d.ts +12 -0
  4. package/dist/modules/controller.accept.js +26 -0
  5. package/dist/modules/controller.audio.d.ts +11 -0
  6. package/dist/modules/controller.audio.js +10 -0
  7. package/dist/modules/controller.bg.d.ts +14 -0
  8. package/dist/modules/controller.bg.js +12 -0
  9. package/dist/modules/controller.d.ts +15 -0
  10. package/dist/modules/controller.grid.d.ts +20 -0
  11. package/dist/modules/controller.grid.js +25 -0
  12. package/dist/modules/controller.js +16 -0
  13. package/dist/modules/controller.pages.d.ts +12 -0
  14. package/dist/modules/controller.pages.items.d.ts +27 -0
  15. package/dist/modules/controller.pages.items.js +29 -0
  16. package/dist/modules/controller.pages.js +17 -0
  17. package/dist/modules/controller.preload.d.ts +28 -0
  18. package/dist/modules/controller.preload.js +29 -0
  19. package/dist/modules/controller.tabs.d.ts +33 -0
  20. package/dist/modules/controller.tabs.js +29 -0
  21. package/dist/modules/gallery.d.ts +10 -0
  22. package/dist/modules/gallery.js +14 -0
  23. package/dist/modules/hide.controls.d.ts +8 -0
  24. package/dist/modules/hide.controls.js +7 -0
  25. package/dist/modules/hide.state.d.ts +6 -0
  26. package/dist/modules/hide.state.js +5 -0
  27. package/dist/modules/view.d.ts +10 -0
  28. package/dist/modules/view.js +9 -0
  29. package/dist/types.d.ts +29 -0
  30. package/dist/types.js +1 -0
  31. package/dist/utils/gallery.d.ts +21 -0
  32. package/dist/utils/gallery.js +2 -0
  33. package/dist/view/components/GalleryClose.d.ts +2 -0
  34. package/dist/view/components/GalleryClose.js +3 -0
  35. package/dist/view/components/GalleryControls.d.ts +7 -0
  36. package/dist/view/components/GalleryControls.js +10 -0
  37. package/dist/view/components/GalleryItems.d.ts +7 -0
  38. package/dist/view/components/GalleryItems.js +22 -0
  39. package/dist/view/components/GalleryPages.d.ts +7 -0
  40. package/dist/view/components/GalleryPages.js +6 -0
  41. package/dist/view/components/index.d.ts +4 -0
  42. package/dist/view/components/index.js +4 -0
  43. package/dist/view/index.d.ts +3 -0
  44. package/dist/view/index.js +9 -0
  45. package/package.json +75 -4
  46. package/src/index.ts +35 -0
  47. package/src/modules/controller.accept.ts +41 -0
  48. package/src/modules/controller.audio.ts +16 -0
  49. package/src/modules/controller.bg.ts +25 -0
  50. package/src/modules/controller.grid.ts +41 -0
  51. package/src/modules/controller.pages.items.ts +47 -0
  52. package/src/modules/controller.pages.ts +28 -0
  53. package/src/modules/controller.preload.ts +48 -0
  54. package/src/modules/controller.tabs.ts +49 -0
  55. package/src/modules/controller.ts +28 -0
  56. package/src/modules/gallery.ts +25 -0
  57. package/src/modules/hide.controls.ts +17 -0
  58. package/src/modules/hide.state.ts +9 -0
  59. package/src/modules/view.ts +17 -0
  60. package/src/tests/accept.test.ts +98 -0
  61. package/src/tests/audio.test.ts +86 -0
  62. package/src/tests/controller.bg.test.ts +84 -0
  63. package/src/tests/gallery.test.ts +49 -0
  64. package/src/tests/grid.test.ts +189 -0
  65. package/src/tests/hide.controls.test.ts +55 -0
  66. package/src/tests/hide.state.test.ts +27 -0
  67. package/src/tests/pages.items.test.ts +48 -0
  68. package/src/tests/pages.test.ts +98 -0
  69. package/src/tests/preload.test.ts +75 -0
  70. package/src/tests/setup.ts +67 -0
  71. package/src/tests/tabs.test.ts +101 -0
  72. package/src/types.ts +42 -0
  73. package/src/utils/gallery.ts +26 -0
  74. package/src/view/components/GalleryClose.tsx +12 -0
  75. package/src/view/components/GalleryControls.tsx +26 -0
  76. package/src/view/components/GalleryItems.tsx +51 -0
  77. package/src/view/components/GalleryPages.tsx +24 -0
  78. package/src/view/components/index.ts +4 -0
  79. package/src/view/index.tsx +67 -0
  80. package/tsconfig.json +10 -0
  81. package/README.md +0 -3
@@ -0,0 +1,98 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { GalleryControllerPages } from "../modules/controller.pages.js";
6
+
7
+ import { createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("GalleryControllerPages", () => {
10
+ beforeEach(() => {
11
+ registerGalleryPluginVne();
12
+ });
13
+
14
+ it("PAGE_SET updates pageIndex and applyPage emits GRID_UPDATE_ITEMS", async () => {
15
+ const { module, observer } = createGalleryTestModule(GalleryControllerPages);
16
+ const pages = module as GalleryControllerPages;
17
+
18
+ pages.updateState({ pageIndex: 0, pagesCount: 3, tab: "cg" });
19
+
20
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
21
+ const gridUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
22
+ const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
23
+
24
+ await observer.emit(SUBSCRIBE_EVENTS.PAGE_SET, { pageIndex: 1 });
25
+
26
+ expect(stateUpdate).toHaveBeenCalledWith({ pageIndex: 1 });
27
+ expect(stateUpdate).toHaveBeenCalledWith({ gridIndex: 1, gridsCount: 3 });
28
+ expect(gridUpdate).toHaveBeenCalledOnce();
29
+ expect(updateFast).toHaveBeenCalledOnce();
30
+ });
31
+
32
+ it("PAGE_SET is a no-op when page equals pageIndex", async () => {
33
+ const { module, observer } = createGalleryTestModule(GalleryControllerPages);
34
+ const pages = module as GalleryControllerPages;
35
+
36
+ pages.updateState({ pageIndex: 1, pagesCount: 3 });
37
+
38
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
39
+ const gridUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
40
+
41
+ await observer.emit(SUBSCRIBE_EVENTS.PAGE_SET, { pageIndex: 1 });
42
+
43
+ expect(stateUpdate).not.toHaveBeenCalled();
44
+ expect(gridUpdate).not.toHaveBeenCalled();
45
+ });
46
+
47
+ it("GRID_NEXT advances page when not on last", async () => {
48
+ const { module, observer } = createGalleryTestModule(GalleryControllerPages);
49
+ const pages = module as GalleryControllerPages;
50
+
51
+ pages.updateState({ pageIndex: 0, pagesCount: 3, tab: "cg" });
52
+
53
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
54
+
55
+ await observer.emit(SUBSCRIBE_EVENTS.GRID_NEXT);
56
+
57
+ expect(stateUpdate).toHaveBeenCalledWith({ pageIndex: 1 });
58
+ });
59
+
60
+ it("GRID_NEXT is a no-op on last page", async () => {
61
+ const { module, observer } = createGalleryTestModule(GalleryControllerPages);
62
+ const pages = module as GalleryControllerPages;
63
+
64
+ pages.updateState({ pageIndex: 2, pagesCount: 3 });
65
+
66
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
67
+
68
+ await observer.emit(SUBSCRIBE_EVENTS.GRID_NEXT);
69
+
70
+ expect(stateUpdate).not.toHaveBeenCalled();
71
+ });
72
+
73
+ it("GRID_PREV goes back when not on first page", async () => {
74
+ const { module, observer } = createGalleryTestModule(GalleryControllerPages);
75
+ const pages = module as GalleryControllerPages;
76
+
77
+ pages.updateState({ pageIndex: 2, pagesCount: 3, tab: "cg" });
78
+
79
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
80
+
81
+ await observer.emit(SUBSCRIBE_EVENTS.GRID_PREV);
82
+
83
+ expect(stateUpdate).toHaveBeenCalledWith({ pageIndex: 1 });
84
+ });
85
+
86
+ it("GRID_PREV is a no-op on first page", async () => {
87
+ const { module, observer } = createGalleryTestModule(GalleryControllerPages);
88
+ const pages = module as GalleryControllerPages;
89
+
90
+ pages.updateState({ pageIndex: 0, pagesCount: 3 });
91
+
92
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
93
+
94
+ await observer.emit(SUBSCRIBE_EVENTS.GRID_PREV);
95
+
96
+ expect(stateUpdate).not.toHaveBeenCalled();
97
+ });
98
+ });
@@ -0,0 +1,75 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as MEMORY_EVENTS } from "@vnejs/contracts.core.memory";
6
+
7
+ import { GalleryControllerPreload } from "../modules/controller.preload.js";
8
+
9
+ import { createGalleryTestModule, PARAMS, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ const makeEntry = (name: string) => ({ check: name, mediaType: "gallery", name, fullName: name });
12
+
13
+ describe("GalleryControllerPreload", () => {
14
+ beforeEach(() => {
15
+ registerGalleryPluginVne();
16
+ });
17
+
18
+ const withTabs = (module: GalleryControllerPreload) => {
19
+ module.PARAMS.GALLERY.TABS = {
20
+ cg: {
21
+ locKey: "tabs.cg",
22
+ content: Array.from({ length: PARAMS.ROWS * PARAMS.COLUMNS * 2 }, (_, i) => makeEntry(`cg${i}`)),
23
+ },
24
+ scenes: {
25
+ locKey: "tabs.scenes",
26
+ content: [makeEntry("scene0"), makeEntry("scene1")],
27
+ },
28
+ };
29
+ };
30
+
31
+ it("PRELOAD emits PAGE_ITEMS_GET for first page of first tab", async () => {
32
+ const { module, observer } = createGalleryTestModule(GalleryControllerPreload);
33
+ const preload = module as GalleryControllerPreload;
34
+ withTabs(preload);
35
+
36
+ const pageItemsGet = spyEvent(observer, SUBSCRIBE_EVENTS.PAGE_ITEMS_GET);
37
+
38
+ await observer.emit(SUBSCRIBE_EVENTS.PRELOAD);
39
+
40
+ expect(pageItemsGet).toHaveBeenCalledTimes(PARAMS.ROWS * PARAMS.COLUMNS);
41
+ expect(pageItemsGet).toHaveBeenCalledWith(makeEntry("cg0"));
42
+ expect(pageItemsGet).not.toHaveBeenCalledWith(makeEntry(`cg${PARAMS.ROWS * PARAMS.COLUMNS}`));
43
+ });
44
+
45
+ it("MEMORY.CLEARED is a no-op when not shown", async () => {
46
+ const { module, observer } = createGalleryTestModule(GalleryControllerPreload);
47
+ const preload = module as GalleryControllerPreload;
48
+ withTabs(preload);
49
+ preload.updateState({ isShow: false, tab: "cg", pageIndex: 0 });
50
+
51
+ const pageItemsGet = spyEvent(observer, SUBSCRIBE_EVENTS.PAGE_ITEMS_GET);
52
+
53
+ await observer.emit(MEMORY_EVENTS.CLEARED);
54
+
55
+ expect(pageItemsGet).not.toHaveBeenCalled();
56
+ });
57
+
58
+ it("MEMORY.CLEARED preloads current, neighbor pages and other tabs page 0", async () => {
59
+ const { module, observer } = createGalleryTestModule(GalleryControllerPreload);
60
+ const preload = module as GalleryControllerPreload;
61
+ withTabs(preload);
62
+ preload.updateState({ isShow: true, tab: "cg", pageIndex: 0 });
63
+
64
+ const pageItemsGet = spyEvent(observer, SUBSCRIBE_EVENTS.PAGE_ITEMS_GET);
65
+
66
+ await observer.emit(MEMORY_EVENTS.CLEARED);
67
+
68
+ const pageSize = PARAMS.ROWS * PARAMS.COLUMNS;
69
+ // current page (9) + next page (9) + scenes page 0 (2)
70
+ expect(pageItemsGet).toHaveBeenCalledTimes(pageSize + pageSize + 2);
71
+ expect(pageItemsGet).toHaveBeenCalledWith(makeEntry("cg0"));
72
+ expect(pageItemsGet).toHaveBeenCalledWith(makeEntry(`cg${pageSize}`));
73
+ expect(pageItemsGet).toHaveBeenCalledWith(makeEntry("scene0"));
74
+ });
75
+ });
@@ -0,0 +1,67 @@
1
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
2
+
3
+ import { SUBSCRIBE_EVENTS as AUDIO_EVENTS, PLUGIN_NAME as AUDIO } from "@vnejs/contracts.audio";
4
+ import { SETTINGS_KEYS as MUSIC_SETTINGS, PLUGIN_NAME as MUSIC } from "@vnejs/contracts.audio.music";
5
+ import { CONSTANTS as LAYER_CONST, PLUGIN_NAME as LAYER, SETTINGS_KEYS as LAYER_SETTINGS } from "@vnejs/contracts.canvas.layer";
6
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gallery";
7
+ import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
8
+ import { SUBSCRIBE_EVENTS as STORAGE_EVENTS } from "@vnejs/contracts.core.storage";
9
+
10
+ export const registerGalleryPluginVne = () => {
11
+ registerCoreVne();
12
+ registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
13
+ registerVnePlugin(LAYER, { constants: LAYER_CONST, settings: LAYER_SETTINGS });
14
+ registerVnePlugin(AUDIO, { events: AUDIO_EVENTS });
15
+ registerVnePlugin(MUSIC, { settings: MUSIC_SETTINGS });
16
+ registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
17
+ };
18
+
19
+ export const createGalleryTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
20
+ ModuleClass: T,
21
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
22
+ ) => {
23
+ const storage = new Map<string, unknown>();
24
+
25
+ const result = baseCreateTestModule(ModuleClass, {
26
+ state: {
27
+ gallery: { isShow: false },
28
+ ...(options.state ?? {}),
29
+ },
30
+ shared: {
31
+ settings: { [MUSIC_SETTINGS.VOLUME]: 100, [LAYER_SETTINGS.QUALITY]: LAYER_CONST.QUALITIES.FHD },
32
+ ...(options.shared ?? {}),
33
+ },
34
+ ...options,
35
+ });
36
+
37
+ stubEvent(result.observer, STORAGE_EVENTS.GET, ({ key }: { key?: string } = {}) => storage.get(key ?? ""));
38
+ stubSilentEvent(result.observer, STORAGE_EVENTS.SET, ({ key, value }: { key?: string; value?: unknown } = {}) => {
39
+ storage.set(key ?? "", value);
40
+ });
41
+ stubSilentEvent(result.observer, STORAGE_EVENTS.RM_ALL, () => storage.clear());
42
+ stubSilentEvent(result.observer, AUDIO_EVENTS.PLAY);
43
+ stubSilentEvent(result.observer, AUDIO_EVENTS.STOP);
44
+ stubSilentEvent(result.observer, AUDIO_EVENTS.GLOBAL_PAUSE);
45
+ stubSilentEvent(result.observer, AUDIO_EVENTS.GLOBAL_RESUME);
46
+ stubSilentEvent(result.observer, AUDIO_EVENTS.MEDIA_LOAD);
47
+ stubSilentEvent(result.observer, AUDIO_EVENTS.VOLUME);
48
+ stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
49
+ stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
50
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.ACCEPT);
51
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
52
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
53
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.GRID_NEXT);
54
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.GRID_PREV);
55
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.GRID_CLEAR);
56
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
57
+ stubEvent(result.observer, SUBSCRIBE_EVENTS.PAGE_ITEMS_GET, async (payload) => ({
58
+ isOpened: false,
59
+ fullName: (payload as { fullName?: string })?.fullName ?? "",
60
+ mediaType: (payload as { mediaType?: string })?.mediaType ?? "",
61
+ }));
62
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.CHECK);
63
+
64
+ return { ...result, storage };
65
+ };
66
+
67
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, STORAGE_EVENTS, AUDIO_EVENTS, CONTROLS_EVENTS };
@@ -0,0 +1,101 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { GalleryControllerTabs } from "../modules/controller.tabs.js";
6
+
7
+ import { CONTROLS_EVENTS, createGalleryTestModule, registerGalleryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("GalleryControllerTabs", () => {
10
+ beforeEach(() => {
11
+ registerGalleryPluginVne();
12
+ });
13
+
14
+ const withTabs = (module: GalleryControllerTabs) => {
15
+ module.PARAMS.GALLERY.TABS = {
16
+ cg: { locKey: "tabs.cg", content: [] },
17
+ scenes: { locKey: "tabs.scenes", content: [] },
18
+ };
19
+ module.TABS = module.PARAMS.GALLERY.TABS;
20
+ };
21
+
22
+ it("SHOW sets first tab and pushes TAB controls", async () => {
23
+ const { module, observer } = createGalleryTestModule(GalleryControllerTabs);
24
+ withTabs(module as GalleryControllerTabs);
25
+
26
+ const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
27
+
28
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
29
+
30
+ expect((module as GalleryControllerTabs).state.tab).toBe("cg");
31
+ expect(push).toHaveBeenCalledExactlyOnceWith(
32
+ expect.objectContaining({
33
+ key: "gallery.controller.tabs",
34
+ checkNext: true,
35
+ index: (module as GalleryControllerTabs).PARAMS.GALLERY.ZINDEX + 1,
36
+ }),
37
+ );
38
+ });
39
+
40
+ it("SHOW uses tab from payload when provided", async () => {
41
+ const { module, observer } = createGalleryTestModule(GalleryControllerTabs);
42
+ withTabs(module as GalleryControllerTabs);
43
+
44
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW, { tab: "scenes" });
45
+
46
+ expect((module as GalleryControllerTabs).state.tab).toBe("scenes");
47
+ });
48
+
49
+ it("HIDE pops TAB controls", async () => {
50
+ const { module, observer } = createGalleryTestModule(GalleryControllerTabs);
51
+ withTabs(module as GalleryControllerTabs);
52
+
53
+ const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
54
+
55
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
56
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
57
+
58
+ expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gallery.controller.tabs" });
59
+ });
60
+
61
+ it("TAB_SET syncs tab", async () => {
62
+ const { module, observer } = createGalleryTestModule(GalleryControllerTabs);
63
+ withTabs(module as GalleryControllerTabs);
64
+
65
+ await observer.emit(SUBSCRIBE_EVENTS.TAB_SET, { tab: "scenes" });
66
+
67
+ expect((module as GalleryControllerTabs).state.tab).toBe("scenes");
68
+ });
69
+
70
+ it("TAB_SET onTabSet emits GRID_CLEAR and GRID_UPDATE_ITEMS", async () => {
71
+ const { module, observer } = createGalleryTestModule(GalleryControllerTabs);
72
+ withTabs(module as GalleryControllerTabs);
73
+ (module as GalleryControllerTabs).updateState({ tab: "cg" });
74
+
75
+ const gridClear = spyEvent(observer, SUBSCRIBE_EVENTS.GRID_CLEAR);
76
+ const gridUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.GRID_UPDATE_ITEMS);
77
+
78
+ await observer.emit(SUBSCRIBE_EVENTS.TAB_SET, { tab: "scenes" });
79
+
80
+ expect(gridClear).toHaveBeenCalledOnce();
81
+ expect(gridUpdate).toHaveBeenCalledOnce();
82
+ });
83
+
84
+ it("onNextTab / onPrevTab cycle tabs and emit TAB_SET", async () => {
85
+ const { module, observer } = createGalleryTestModule(GalleryControllerTabs);
86
+ withTabs(module as GalleryControllerTabs);
87
+
88
+ (module as GalleryControllerTabs).updateState({ tab: "cg" });
89
+
90
+ const tabSet = spyEvent(observer, SUBSCRIBE_EVENTS.TAB_SET);
91
+
92
+ (module as GalleryControllerTabs).onNextTab();
93
+ expect(tabSet).toHaveBeenLastCalledWith({ tab: "scenes" });
94
+
95
+ (module as GalleryControllerTabs).onNextTab();
96
+ expect(tabSet).toHaveBeenLastCalledWith({ tab: "cg" });
97
+
98
+ (module as GalleryControllerTabs).onPrevTab();
99
+ expect(tabSet).toHaveBeenLastCalledWith({ tab: "scenes" });
100
+ });
101
+ });
package/src/types.ts ADDED
@@ -0,0 +1,42 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+
3
+ import type { PluginName as AudioPluginName, SubscribeEvents as AudioSubscribeEvents } from "@vnejs/contracts.audio";
4
+ import type { PluginName as MusicPluginName, SettingsKeys as MusicSettingsKeys } from "@vnejs/contracts.audio.music";
5
+ import type { SettingsKeys as LayerSettingsKeys, PluginName as LayerPluginName } from "@vnejs/contracts.canvas.layer";
6
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.gallery";
7
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
8
+ import type { PluginName as MemoryPluginName, SubscribeEvents as MemorySubscribeEvents } from "@vnejs/contracts.core.memory";
9
+ import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
10
+ import type { PluginName as StoragePluginName, SubscribeEvents as StorageSubscribeEvents } from "@vnejs/contracts.core.storage";
11
+ import type { PluginName as SystemPluginName, SubscribeEvents as SystemSubscribeEvents } from "@vnejs/contracts.core.system";
12
+
13
+ import type { GalleryCurrentItem } from "./utils/gallery.js";
14
+
15
+ export type GalleryPluginEvents = ModuleComponentsEvents &
16
+ Record<PluginName, SubscribeEvents> &
17
+ Record<AudioPluginName, AudioSubscribeEvents> &
18
+ Record<StoragePluginName, StorageSubscribeEvents> &
19
+ Record<MemoryPluginName, MemorySubscribeEvents> &
20
+ Record<StatePluginName, StateSubscribeEvents> &
21
+ Record<SystemPluginName, SystemSubscribeEvents>;
22
+
23
+ export type GalleryPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
24
+
25
+ export type GalleryPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys> & Record<MusicPluginName, MusicSettingsKeys>;
26
+
27
+ export type GalleryPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
28
+
29
+ export type GalleryPluginState = {
30
+ isShow: boolean;
31
+ isForce: boolean;
32
+ locs?: Record<string, string>;
33
+ bgSrc?: string;
34
+ tab?: string;
35
+ pageIndex?: number;
36
+ pagesCount?: number;
37
+ gridRow?: number | null;
38
+ gridColumn?: number | null;
39
+ gridItems?: GalleryCurrentItem[];
40
+ gridIndex?: number;
41
+ gridsCount?: number;
42
+ };
@@ -0,0 +1,26 @@
1
+ import type { Module } from "@vnejs/module";
2
+
3
+ import type { GalleryCurrentVariant } from "@vnejs/contracts.controllers.screens.gallery";
4
+
5
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings, GalleryPluginState } from "../types.js";
6
+
7
+ export type GalleryCurrentItem = {
8
+ isStub?: boolean;
9
+ isOpened?: boolean;
10
+ layerChildType?: string;
11
+ fullName?: string;
12
+ src?: string;
13
+ mediaType?: string;
14
+ variants?: GalleryCurrentVariant[];
15
+ };
16
+
17
+ export type GalleryViewContext = {
18
+ emit: Module<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState>["emit"];
19
+ EVENTS: GalleryPluginEvents;
20
+ PARAMS: GalleryPluginParams;
21
+ };
22
+
23
+ export const normalizeGalleryOverlays = (overlays: Record<string, string | number> = {}) =>
24
+ Object.fromEntries(Object.entries(overlays).map(([key, value]) => [key, String(value)]));
25
+
26
+ export const toGalleryMediaName = (name = "", layerChildType?: string) => (layerChildType ? `${layerChildType}/${name}` : name);
@@ -0,0 +1,12 @@
1
+ import { PositionBox, Svg } from "@vnejs/uis.react";
2
+
3
+ import type { GalleryViewContext } from "../../utils/gallery.js";
4
+
5
+ export const GalleryClose = ({ emit, EVENTS, PARAMS }: GalleryViewContext) => (
6
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.close.position}>
7
+ <Svg.Cross
8
+ {...PARAMS.GALLERY.VIEW_PROPS.close.svg}
9
+ onClick={() => void emit(EVENTS.GALLERY.HIDE)}
10
+ />
11
+ </PositionBox>
12
+ );
@@ -0,0 +1,26 @@
1
+ import { PositionBox, TextControls } from "@vnejs/uis.react";
2
+
3
+ import type { GalleryViewContext } from "../../utils/gallery.js";
4
+
5
+ type GalleryControlsProps = GalleryViewContext & {
6
+ locs: Record<string, string>;
7
+ tab: string;
8
+ };
9
+
10
+ export const GalleryControls = ({ locs, tab, emit, EVENTS, PARAMS }: GalleryControlsProps) => {
11
+ const texts = Object.keys(PARAMS.GALLERY.TABS).map((key) => ({ text: locs[PARAMS.GALLERY.TABS[key].locKey], value: key }));
12
+ const selectedIndex = Object.keys(PARAMS.GALLERY.TABS).findIndex((key) => key === tab);
13
+
14
+ return (
15
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.controls.position}>
16
+ <TextControls
17
+ {...PARAMS.GALLERY.VIEW_PROPS.controls.controls}
18
+ selectedIndex={selectedIndex}
19
+ texts={texts}
20
+ onClick={(tab?: unknown) => {
21
+ if (typeof tab === "string") void emit(EVENTS.GALLERY.TAB_SET, { tab });
22
+ }}
23
+ />
24
+ </PositionBox>
25
+ );
26
+ };
@@ -0,0 +1,51 @@
1
+ import { Flex, PositionBox, WrapWithContent } from "@vnejs/uis.react";
2
+
3
+ import type { GalleryCurrentItem, GalleryViewContext } from "../../utils/gallery.js";
4
+
5
+ type GalleryItemsProps = GalleryViewContext & {
6
+ gridItems?: GalleryCurrentItem[];
7
+ selectedIndex?: number;
8
+ };
9
+
10
+ export const GalleryItems = ({ gridItems = [], selectedIndex = -1, emit, EVENTS, PARAMS }: GalleryItemsProps) => {
11
+ const onSlotClick = (index?: unknown) => {
12
+ const itemIndex = Number(index);
13
+ const item = gridItems[itemIndex];
14
+
15
+ void emit(EVENTS.GALLERY.CHOOSE, {
16
+ index: itemIndex,
17
+ fullName: item?.fullName,
18
+ mediaType: item?.mediaType,
19
+ layerChildType: item?.layerChildType,
20
+ isOpened: item?.isOpened,
21
+ variants: item?.variants,
22
+ });
23
+ };
24
+
25
+ return (
26
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.items.position}>
27
+ <Flex {...PARAMS.GALLERY.VIEW_PROPS.items.flex}>
28
+ {gridItems.map((item, i) => {
29
+ if (item.isStub)
30
+ return (
31
+ <div
32
+ {...PARAMS.GALLERY.VIEW_PROPS.items.stub}
33
+ key={i}
34
+ />
35
+ );
36
+
37
+ return (
38
+ <WrapWithContent
39
+ {...PARAMS.GALLERY.VIEW_PROPS.items.item}
40
+ key={item.isOpened ? item.src : i}
41
+ value={i}
42
+ imageSrc={item.isOpened ? item.src : undefined}
43
+ isSelected={selectedIndex === i}
44
+ onClick={item.isOpened ? onSlotClick : undefined}
45
+ />
46
+ );
47
+ })}
48
+ </Flex>
49
+ </PositionBox>
50
+ );
51
+ };
@@ -0,0 +1,24 @@
1
+ import { PageSelector, PositionBox } from "@vnejs/uis.react";
2
+
3
+ import type { GalleryViewContext } from "../../utils/gallery.js";
4
+
5
+ type GalleryPagesProps = GalleryViewContext & {
6
+ pagesCount?: number;
7
+ pageIndex?: number;
8
+ };
9
+
10
+ export const GalleryPages = ({ pagesCount = 0, pageIndex = 0, emit, EVENTS, PARAMS }: GalleryPagesProps) => {
11
+ const setPage = (nextPageIndex: number) => void emit(EVENTS.GALLERY.PAGE_SET, { pageIndex: nextPageIndex });
12
+
13
+ return (
14
+ <PositionBox {...PARAMS.GALLERY.VIEW_PROPS.pages.position}>
15
+ <PageSelector
16
+ onPrevPage={() => setPage(pageIndex - 1)}
17
+ onNextPage={() => setPage(pageIndex + 1)}
18
+ pagesCount={pagesCount}
19
+ page={pageIndex + 1}
20
+ pagesMinCount={1}
21
+ />
22
+ </PositionBox>
23
+ );
24
+ };
@@ -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,67 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+
3
+ import { Screen, createRenderFunc, useStoreState } from "@vnejs/uis.react";
4
+
5
+ import type { ReactComponentProps } from "@vnejs/uis.react";
6
+
7
+ import type { GalleryPluginConstants, GalleryPluginEvents, GalleryPluginParams, GalleryPluginSettings } from "../types.js";
8
+ import type { GalleryPluginState } from "../types.js";
9
+
10
+ import { GalleryClose, GalleryControls, GalleryItems, GalleryPages } from "./components/index.js";
11
+
12
+ type GalleryComponentProps = ReactComponentProps<GalleryPluginEvents, GalleryPluginConstants, GalleryPluginSettings, GalleryPluginParams, GalleryPluginState>;
13
+
14
+ const Gallery = ({ store, onMount, PARAMS, emit, EVENTS }: GalleryComponentProps) => {
15
+ const {
16
+ isShow = false,
17
+ isForce = false,
18
+ locs = {},
19
+ bgSrc = "",
20
+ tab = "",
21
+ gridItems = [],
22
+ pagesCount,
23
+ gridColumn = null,
24
+ gridRow = null,
25
+ pageIndex,
26
+ } = useStoreState<GalleryPluginState>(store, onMount);
27
+
28
+ const selectedIndex = gridColumn !== null && gridRow !== null ? gridColumn + gridRow * PARAMS.GALLERY.COLUMNS : -1;
29
+
30
+ return (
31
+ <Screen
32
+ {...PARAMS.GALLERY.VIEW_PROPS.screen}
33
+ isShow={isShow}
34
+ isForce={isForce}
35
+ bgSrc={bgSrc}
36
+ >
37
+ <GalleryControls
38
+ emit={emit}
39
+ EVENTS={EVENTS}
40
+ PARAMS={PARAMS}
41
+ tab={tab}
42
+ locs={locs}
43
+ />
44
+ <GalleryPages
45
+ emit={emit}
46
+ EVENTS={EVENTS}
47
+ PARAMS={PARAMS}
48
+ pagesCount={pagesCount}
49
+ pageIndex={pageIndex}
50
+ />
51
+ <GalleryItems
52
+ emit={emit}
53
+ EVENTS={EVENTS}
54
+ PARAMS={PARAMS}
55
+ gridItems={gridItems}
56
+ selectedIndex={selectedIndex}
57
+ />
58
+ <GalleryClose
59
+ emit={emit}
60
+ EVENTS={EVENTS}
61
+ PARAMS={PARAMS}
62
+ />
63
+ </Screen>
64
+ );
65
+ };
66
+
67
+ 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", "src/tests"]
10
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.