@vnejs/plugins.controllers.screens.gallery.full 0.0.0-stage → 0.2.18
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 +2 -0
- package/dist/index.js +22 -0
- package/dist/modules/bridge.d.ts +8 -0
- package/dist/modules/bridge.js +13 -0
- package/dist/modules/controller.arrows.d.ts +12 -0
- package/dist/modules/controller.arrows.js +11 -0
- package/dist/modules/controller.d.ts +16 -0
- package/dist/modules/controller.js +24 -0
- package/dist/modules/hide.controls.d.ts +8 -0
- package/dist/modules/hide.controls.js +7 -0
- package/dist/modules/load.d.ts +9 -0
- package/dist/modules/load.js +17 -0
- package/dist/modules/load.src.d.ts +11 -0
- package/dist/modules/load.src.js +27 -0
- package/dist/modules/variation.d.ts +12 -0
- package/dist/modules/variation.js +12 -0
- package/dist/modules/view.d.ts +9 -0
- package/dist/modules/view.js +8 -0
- package/dist/types.d.ts +23 -0
- package/dist/types.js +1 -0
- package/dist/utils/gallery.full.d.ts +16 -0
- package/dist/utils/gallery.full.js +21 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +10 -0
- package/package.json +63 -4
- package/src/index.ts +26 -0
- package/src/modules/bridge.ts +21 -0
- package/src/modules/controller.arrows.ts +22 -0
- package/src/modules/controller.ts +43 -0
- package/src/modules/hide.controls.ts +17 -0
- package/src/modules/load.src.ts +50 -0
- package/src/modules/load.ts +33 -0
- package/src/modules/variation.ts +24 -0
- package/src/modules/view.ts +21 -0
- package/src/tests/arrows.test.ts +60 -0
- package/src/tests/bridge.test.ts +32 -0
- package/src/tests/controller.test.ts +46 -0
- package/src/tests/hide.controls.test.ts +55 -0
- package/src/tests/load.src.test.ts +49 -0
- package/src/tests/load.test.ts +49 -0
- package/src/tests/setup.ts +56 -0
- package/src/tests/variation.test.ts +69 -0
- package/src/types.ts +38 -0
- package/src/utils/gallery.full.ts +45 -0
- package/src/view/index.tsx +68 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ModuleControllerPages } from "@vnejs/module.controller.pages";
|
|
2
|
+
|
|
3
|
+
import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
|
|
4
|
+
import type { GalleryFullPluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
export class GalleryFullViewVariation extends ModuleControllerPages<
|
|
7
|
+
GalleryFullPluginEvents,
|
|
8
|
+
GalleryFullPluginConstants,
|
|
9
|
+
GalleryFullPluginSettings,
|
|
10
|
+
GalleryFullPluginParams,
|
|
11
|
+
GalleryFullPluginState
|
|
12
|
+
> {
|
|
13
|
+
name = "gallery.full.view.variation";
|
|
14
|
+
|
|
15
|
+
EVENT_PAGE_SET = this.EVENTS.GALLERY_FULL_VIEW.PAGE_SET;
|
|
16
|
+
EVENT_PAGE_NEXT = this.EVENTS.GALLERY_FULL_VIEW.NEXT;
|
|
17
|
+
EVENT_PAGE_PREV = this.EVENTS.GALLERY_FULL_VIEW.PREV;
|
|
18
|
+
EVENT_UPDATE_STATE = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_STATE;
|
|
19
|
+
EVENT_UPDATE_FAST = this.EVENTS.GALLERY_FULL_VIEW.UPDATE_FAST;
|
|
20
|
+
|
|
21
|
+
applyPage = async () => {
|
|
22
|
+
await this.emit(this.EVENTS.GALLERY_FULL_VIEW.LOAD, { pageIndex: this.state.pageIndex ?? 0 });
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
|
|
4
|
+
import type { GalleryFullPluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
import { render } from "../view/index.js";
|
|
7
|
+
export class GalleryFullView extends ModuleView<
|
|
8
|
+
GalleryFullPluginEvents,
|
|
9
|
+
GalleryFullPluginConstants,
|
|
10
|
+
GalleryFullPluginSettings,
|
|
11
|
+
GalleryFullPluginParams,
|
|
12
|
+
GalleryFullPluginState
|
|
13
|
+
> {
|
|
14
|
+
name = "gallery.full.view";
|
|
15
|
+
|
|
16
|
+
EVENT_UPDATE_VIEW = this.EVENTS.GALLERY_FULL_VIEW.UPDATE;
|
|
17
|
+
|
|
18
|
+
TRANSITION = this.PARAMS.GALLERY_FULL_VIEW.TRANSITION;
|
|
19
|
+
|
|
20
|
+
renderFunc = render;
|
|
21
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryFullViewControllerArrows } from "../modules/controller.arrows.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGalleryFullTestModule, registerGalleryFullPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryFullViewControllerArrows", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryFullPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes arrow controls above the controller layer", async () => {
|
|
15
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewControllerArrows);
|
|
16
|
+
const arrows = module as GalleryFullViewControllerArrows;
|
|
17
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
20
|
+
|
|
21
|
+
expect(arrows.currentItem).toBeNull();
|
|
22
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
23
|
+
expect.objectContaining({
|
|
24
|
+
key: "gallery.full.view.controller.arrows",
|
|
25
|
+
checkNext: true,
|
|
26
|
+
index: arrows.PARAMS.GALLERY_FULL_VIEW.ZINDEX + 1,
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(arrows.CONST.CONTROLS.BUTTONS.ARROW_LEFT);
|
|
30
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(arrows.CONST.CONTROLS.BUTTONS.ARROW_RIGHT);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("HIDE pops arrow controls", async () => {
|
|
34
|
+
const { observer } = createGalleryFullTestModule(GalleryFullViewControllerArrows);
|
|
35
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
36
|
+
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
38
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
39
|
+
|
|
40
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gallery.full.view.controller.arrows" });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("onArrowLeft emits PREV", async () => {
|
|
44
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewControllerArrows);
|
|
45
|
+
const prev = spyEvent(observer, SUBSCRIBE_EVENTS.PREV);
|
|
46
|
+
|
|
47
|
+
await (module as GalleryFullViewControllerArrows).onArrowLeft();
|
|
48
|
+
|
|
49
|
+
expect(prev).toHaveBeenCalledOnce();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("onArrowRight emits NEXT", async () => {
|
|
53
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewControllerArrows);
|
|
54
|
+
const next = spyEvent(observer, SUBSCRIBE_EVENTS.NEXT);
|
|
55
|
+
|
|
56
|
+
await (module as GalleryFullViewControllerArrows).onArrowRight();
|
|
57
|
+
|
|
58
|
+
expect(next).toHaveBeenCalledOnce();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryFullViewBridge } from "../modules/bridge.js";
|
|
6
|
+
|
|
7
|
+
import { createGalleryFullTestModule, GALLERY_EVENTS, registerGalleryFullPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryFullViewBridge", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryFullPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("GALLERY.CHOOSE with isOpened true emits SHOW", async () => {
|
|
15
|
+
const { observer } = createGalleryFullTestModule(GalleryFullViewBridge);
|
|
16
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
17
|
+
const payload = { index: 0, isOpened: true, fullName: "img1", mediaType: "gallery" };
|
|
18
|
+
|
|
19
|
+
await observer.emit(GALLERY_EVENTS.CHOOSE, payload);
|
|
20
|
+
|
|
21
|
+
expect(show).toHaveBeenCalledExactlyOnceWith(payload);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("GALLERY.CHOOSE with isOpened false does not emit SHOW", async () => {
|
|
25
|
+
const { observer } = createGalleryFullTestModule(GalleryFullViewBridge);
|
|
26
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
27
|
+
|
|
28
|
+
await observer.emit(GALLERY_EVENTS.CHOOSE, { index: 0, isOpened: false, fullName: "img1", mediaType: "gallery" });
|
|
29
|
+
|
|
30
|
+
expect(show).not.toHaveBeenCalled();
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryFullViewController } from "../modules/controller.js";
|
|
6
|
+
|
|
7
|
+
import { createGalleryFullTestModule, registerGalleryFullPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryFullViewController", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryFullPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW writes item context to UPDATE_STATE and emits LOAD", async () => {
|
|
15
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewController);
|
|
16
|
+
const updateState = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
17
|
+
const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
20
|
+
|
|
21
|
+
expect(updateState).toHaveBeenCalledWith({
|
|
22
|
+
itemFullName: "img1",
|
|
23
|
+
itemMediaType: "gallery",
|
|
24
|
+
itemLayerChildType: "",
|
|
25
|
+
variants: [{ isOpened: false, layerChildType: undefined, name: "img1" }],
|
|
26
|
+
});
|
|
27
|
+
expect(load).toHaveBeenCalledExactlyOnceWith({ pageIndex: 0 });
|
|
28
|
+
expect((module as GalleryFullViewController).state.itemFullName).toBe("img1");
|
|
29
|
+
expect((module as GalleryFullViewController).state.variants).toEqual([{ isOpened: false, layerChildType: undefined, name: "img1" }]);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("HIDE clears item context via UPDATE_STATE", async () => {
|
|
33
|
+
const { observer } = createGalleryFullTestModule(GalleryFullViewController);
|
|
34
|
+
const updateState = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
35
|
+
|
|
36
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
38
|
+
|
|
39
|
+
expect(updateState).toHaveBeenCalledWith({
|
|
40
|
+
itemFullName: "",
|
|
41
|
+
itemMediaType: "",
|
|
42
|
+
itemLayerChildType: "",
|
|
43
|
+
variants: [],
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryFullViewHideControls } from "../modules/hide.controls.js";
|
|
6
|
+
|
|
7
|
+
import { CONTROLS_EVENTS, createGalleryFullTestModule, registerGalleryFullPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryFullViewHideControls", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryFullPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("SHOW pushes BACK, MENU and GAMEMENU controls", async () => {
|
|
15
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewHideControls);
|
|
16
|
+
const hide = module as GalleryFullViewHideControls;
|
|
17
|
+
const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
|
|
18
|
+
|
|
19
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
20
|
+
|
|
21
|
+
expect(push).toHaveBeenCalledExactlyOnceWith(
|
|
22
|
+
expect.objectContaining({
|
|
23
|
+
key: "gallery.full.view.hide.controls",
|
|
24
|
+
checkNext: true,
|
|
25
|
+
index: hide.PARAMS.GALLERY_FULL_VIEW.ZINDEX + 1,
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.BACK);
|
|
29
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.MENU);
|
|
30
|
+
expect(push.mock.calls[0][0].controls).toHaveProperty(hide.CONST.CONTROLS.BUTTONS.GAMEMENU);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("HIDE pops hide.controls", async () => {
|
|
34
|
+
const { observer } = createGalleryFullTestModule(GalleryFullViewHideControls);
|
|
35
|
+
const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
|
|
36
|
+
|
|
37
|
+
await observer.emit(SUBSCRIBE_EVENTS.SHOW);
|
|
38
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
39
|
+
|
|
40
|
+
expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "gallery.full.view.hide.controls" });
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("BACK, MENU and GAMEMENU emit GALLERY_FULL_VIEW.HIDE", async () => {
|
|
44
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewHideControls);
|
|
45
|
+
const hide = module as GalleryFullViewHideControls;
|
|
46
|
+
const hideEvent = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
47
|
+
|
|
48
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.BACK]();
|
|
49
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.MENU]();
|
|
50
|
+
hide.CONTROLS[hide.CONST.CONTROLS.BUTTONS.GAMEMENU]();
|
|
51
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
52
|
+
|
|
53
|
+
expect(hideEvent).toHaveBeenCalledTimes(3);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
|
|
6
|
+
|
|
7
|
+
import { GalleryFullViewLoadSrc } from "../modules/load.src.js";
|
|
8
|
+
|
|
9
|
+
import { createGalleryFullTestModule, LAYER_BG_EVENTS, registerGalleryFullPluginVne } from "./setup.js";
|
|
10
|
+
|
|
11
|
+
describe("GalleryFullViewLoadSrc", () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registerGalleryFullPluginVne();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("onLoadSrc loads media by variant name", async () => {
|
|
17
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewLoadSrc);
|
|
18
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
19
|
+
|
|
20
|
+
(module as GalleryFullViewLoadSrc).updateState({ itemMediaType: "gallery" });
|
|
21
|
+
|
|
22
|
+
await expect((module as GalleryFullViewLoadSrc).onLoadSrc({ name: "img1" })).resolves.toBe("full.png");
|
|
23
|
+
expect(mediaLoad).toHaveBeenCalledOnce();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("onLoadSrc falls back to itemFullName from state", async () => {
|
|
27
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewLoadSrc);
|
|
28
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
29
|
+
|
|
30
|
+
(module as GalleryFullViewLoadSrc).updateState({
|
|
31
|
+
itemFullName: "img1",
|
|
32
|
+
itemMediaType: "gallery",
|
|
33
|
+
itemLayerChildType: "cg",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
await expect((module as GalleryFullViewLoadSrc).onLoadSrc({})).resolves.toBe("full.png");
|
|
37
|
+
expect(mediaLoad).toHaveBeenCalledWith(expect.objectContaining({ name: "cg/img1", mediaType: "gallery" }));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("onLoadSrc asks LAYER_BG.SRC_GET for a background variant", async () => {
|
|
41
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewLoadSrc);
|
|
42
|
+
const srcGet = spyEvent(observer, LAYER_BG_EVENTS.SRC_GET);
|
|
43
|
+
const mediaLoad = spyEvent(observer, MEDIA_EVENTS.LOAD);
|
|
44
|
+
|
|
45
|
+
await expect((module as GalleryFullViewLoadSrc).onLoadSrc({ name: "room", layerChildType: "bg", overlays: { night: "1" } })).resolves.toBe("bg.png");
|
|
46
|
+
expect(srcGet).toHaveBeenCalledExactlyOnceWith({ name: "room", args: { overlays: { night: "1" } } });
|
|
47
|
+
expect(mediaLoad).not.toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryFullViewLoad } from "../modules/load.js";
|
|
6
|
+
|
|
7
|
+
import { createGalleryFullTestModule, registerGalleryFullPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryFullViewLoad", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryFullPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("onLoad does not emit LOAD_SRC for a locked variant", async () => {
|
|
15
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewLoad);
|
|
16
|
+
const loadSrc = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD_SRC);
|
|
17
|
+
const updateState = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
18
|
+
|
|
19
|
+
(module as GalleryFullViewLoad).updateState({ variants: [{ isOpened: false, name: "secret" }] });
|
|
20
|
+
await (module as GalleryFullViewLoad).onLoad({ pageIndex: 0 });
|
|
21
|
+
|
|
22
|
+
expect(loadSrc).not.toHaveBeenCalled();
|
|
23
|
+
expect(updateState).toHaveBeenCalledExactlyOnceWith({
|
|
24
|
+
pageIndex: 0,
|
|
25
|
+
pagesCount: 1,
|
|
26
|
+
withBackgroundBlur: true,
|
|
27
|
+
imageSrc: "",
|
|
28
|
+
isAllSrcRendered: false,
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("onLoad emits LOAD_SRC for an opened variant", async () => {
|
|
33
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewLoad);
|
|
34
|
+
const loadSrc = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD_SRC);
|
|
35
|
+
const updateState = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
36
|
+
|
|
37
|
+
(module as GalleryFullViewLoad).updateState({ variants: [{ isOpened: true, name: "img1" }] });
|
|
38
|
+
await (module as GalleryFullViewLoad).onLoad({ pageIndex: 0 });
|
|
39
|
+
|
|
40
|
+
expect(loadSrc).toHaveBeenCalledExactlyOnceWith({ isOpened: true, name: "img1" });
|
|
41
|
+
expect(updateState).toHaveBeenCalledExactlyOnceWith({
|
|
42
|
+
pageIndex: 0,
|
|
43
|
+
pagesCount: 1,
|
|
44
|
+
withBackgroundBlur: false,
|
|
45
|
+
imageSrc: "full.png",
|
|
46
|
+
isAllSrcRendered: false,
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { SourcesSet } from "@vnejs/sources-set";
|
|
2
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
|
|
3
|
+
|
|
4
|
+
import { CONSTANTS as LAYER_BG_CONST, PLUGIN_NAME as LAYER_BG, SUBSCRIBE_EVENTS as LAYER_BG_EVENTS } from "@vnejs/contracts.canvas.child.bg";
|
|
5
|
+
import { CONSTANTS as LAYER_CONST, PLUGIN_NAME as LAYER, SETTINGS_KEYS as LAYER_SETTINGS } from "@vnejs/contracts.canvas.layer";
|
|
6
|
+
import { PARAMS as GALLERY_PARAMS, PLUGIN_NAME as GALLERY, SUBSCRIBE_EVENTS as GALLERY_EVENTS } from "@vnejs/contracts.controllers.screens.gallery";
|
|
7
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.gallery.full";
|
|
8
|
+
import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
|
|
9
|
+
import { SUBSCRIBE_EVENTS as MEDIA_EVENTS } from "@vnejs/contracts.core.media";
|
|
10
|
+
|
|
11
|
+
export const registerGalleryFullPluginVne = () => {
|
|
12
|
+
registerCoreVne();
|
|
13
|
+
registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
|
|
14
|
+
registerVnePlugin(LAYER, { constants: LAYER_CONST, settings: LAYER_SETTINGS });
|
|
15
|
+
registerVnePlugin(LAYER_BG, { constants: LAYER_BG_CONST, events: LAYER_BG_EVENTS });
|
|
16
|
+
registerVnePlugin(GALLERY, { events: GALLERY_EVENTS, params: GALLERY_PARAMS });
|
|
17
|
+
registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const createGalleryFullTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
21
|
+
ModuleClass: T,
|
|
22
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
23
|
+
) => {
|
|
24
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
25
|
+
state: {
|
|
26
|
+
"gallery.controller": { currentItems: [{ fullName: "img1", mediaType: "gallery" }] },
|
|
27
|
+
"gallery.full.view.controller": { bgSrc: "", isShow: false },
|
|
28
|
+
...(options.state ?? {}),
|
|
29
|
+
},
|
|
30
|
+
shared: {
|
|
31
|
+
settings: { [LAYER_SETTINGS.QUALITY]: LAYER_CONST.QUALITIES.FHD },
|
|
32
|
+
viewForceAnimationSources: new SourcesSet(),
|
|
33
|
+
...(options.shared ?? {}),
|
|
34
|
+
},
|
|
35
|
+
...options,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
stubEvent(result.observer, MEDIA_EVENTS.LOAD, () => ({ src: "full.png" }));
|
|
39
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
|
|
40
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
|
|
41
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
|
|
42
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.LOAD);
|
|
43
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.NEXT);
|
|
44
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.PREV);
|
|
45
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.PAGE_SET);
|
|
46
|
+
stubEvent(result.observer, SUBSCRIBE_EVENTS.LOAD_SRC, () => "full.png");
|
|
47
|
+
stubEvent(result.observer, LAYER_BG_EVENTS.SRC_GET, () => "bg.png");
|
|
48
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
|
|
49
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
50
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.PUSH);
|
|
51
|
+
stubSilentEvent(result.observer, CONTROLS_EVENTS.POP);
|
|
52
|
+
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export { SUBSCRIBE_EVENTS, GALLERY_EVENTS, PARAMS, PLUGIN_NAME, CONTROLS_EVENTS, LAYER_BG_EVENTS };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { GalleryFullViewVariation } from "../modules/variation.js";
|
|
6
|
+
|
|
7
|
+
import { createGalleryFullTestModule, registerGalleryFullPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("GalleryFullViewVariation", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerGalleryFullPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("PREV emits LOAD previous variation and UPDATE_FAST", async () => {
|
|
15
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewVariation);
|
|
16
|
+
const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
|
|
17
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
18
|
+
|
|
19
|
+
(module as GalleryFullViewVariation).updateState({ pageIndex: 1, pagesCount: 3 });
|
|
20
|
+
await observer.emit(SUBSCRIBE_EVENTS.PREV);
|
|
21
|
+
|
|
22
|
+
expect(load).toHaveBeenCalledExactlyOnceWith({ pageIndex: 0 });
|
|
23
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("NEXT emits LOAD next variation and UPDATE_FAST", async () => {
|
|
27
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewVariation);
|
|
28
|
+
const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
|
|
29
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
30
|
+
|
|
31
|
+
(module as GalleryFullViewVariation).updateState({ pageIndex: 0, pagesCount: 3 });
|
|
32
|
+
await observer.emit(SUBSCRIBE_EVENTS.NEXT);
|
|
33
|
+
|
|
34
|
+
expect(load).toHaveBeenCalledExactlyOnceWith({ pageIndex: 1 });
|
|
35
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("PREV does nothing on the first variation", async () => {
|
|
39
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewVariation);
|
|
40
|
+
const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
|
|
41
|
+
|
|
42
|
+
(module as GalleryFullViewVariation).updateState({ pageIndex: 0, pagesCount: 3 });
|
|
43
|
+
await observer.emit(SUBSCRIBE_EVENTS.PREV);
|
|
44
|
+
|
|
45
|
+
expect(load).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("NEXT does nothing on the last variation", async () => {
|
|
49
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewVariation);
|
|
50
|
+
const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
|
|
51
|
+
|
|
52
|
+
(module as GalleryFullViewVariation).updateState({ pageIndex: 2, pagesCount: 3 });
|
|
53
|
+
await observer.emit(SUBSCRIBE_EVENTS.NEXT);
|
|
54
|
+
|
|
55
|
+
expect(load).not.toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("PAGE_SET loads the given page", async () => {
|
|
59
|
+
const { module, observer } = createGalleryFullTestModule(GalleryFullViewVariation);
|
|
60
|
+
const load = spyEvent(observer, SUBSCRIBE_EVENTS.LOAD);
|
|
61
|
+
const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
|
|
62
|
+
|
|
63
|
+
(module as GalleryFullViewVariation).updateState({ pageIndex: 0, pagesCount: 3 });
|
|
64
|
+
await observer.emit(SUBSCRIBE_EVENTS.PAGE_SET, { pageIndex: 2 });
|
|
65
|
+
|
|
66
|
+
expect(load).toHaveBeenCalledExactlyOnceWith({ pageIndex: 2 });
|
|
67
|
+
expect(updateFast).toHaveBeenCalledOnce();
|
|
68
|
+
});
|
|
69
|
+
});
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
Constants as LayerBgConstants,
|
|
5
|
+
PluginName as LayerBgPluginName,
|
|
6
|
+
SubscribeEvents as LayerBgSubscribeEvents,
|
|
7
|
+
} from "@vnejs/contracts.canvas.child.bg";
|
|
8
|
+
import type { SettingsKeys as LayerSettingsKeys, PluginName as LayerPluginName } from "@vnejs/contracts.canvas.layer";
|
|
9
|
+
import type { PluginName as GalleryPluginName, SubscribeEvents as GallerySubscribeEvents } from "@vnejs/contracts.controllers.screens.gallery";
|
|
10
|
+
import type { GalleryFullImageSrcItem, GalleryFullVariant, Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.gallery.full";
|
|
11
|
+
import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
|
|
12
|
+
|
|
13
|
+
export type GalleryFullPluginEvents = ModuleComponentsEvents &
|
|
14
|
+
Record<PluginName, SubscribeEvents> &
|
|
15
|
+
Record<GalleryPluginName, GallerySubscribeEvents> &
|
|
16
|
+
Record<LayerBgPluginName, LayerBgSubscribeEvents>;
|
|
17
|
+
|
|
18
|
+
export type GalleryFullPluginConstants = ModuleComponentsConstants &
|
|
19
|
+
Record<ControlsPluginName, ControlsConstants> &
|
|
20
|
+
Record<LayerBgPluginName, LayerBgConstants>;
|
|
21
|
+
|
|
22
|
+
export type GalleryFullPluginSettings = ModuleComponentsSettings & Record<LayerPluginName, LayerSettingsKeys>;
|
|
23
|
+
|
|
24
|
+
export type GalleryFullPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
25
|
+
|
|
26
|
+
export type GalleryFullPluginState = {
|
|
27
|
+
isShow: boolean;
|
|
28
|
+
isForce: boolean;
|
|
29
|
+
imageSrc?: string | GalleryFullImageSrcItem[];
|
|
30
|
+
isAllSrcRendered?: boolean;
|
|
31
|
+
withBackgroundBlur?: boolean;
|
|
32
|
+
pageIndex?: number;
|
|
33
|
+
pagesCount?: number;
|
|
34
|
+
itemFullName?: string;
|
|
35
|
+
itemMediaType?: string;
|
|
36
|
+
itemLayerChildType?: string;
|
|
37
|
+
variants?: GalleryFullVariant[];
|
|
38
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { GalleryFullImageSrcItem, GalleryFullShowPayload, GalleryFullVariant } from "@vnejs/contracts.controllers.screens.gallery.full";
|
|
2
|
+
|
|
3
|
+
export type { GalleryFullImageSrcItem };
|
|
4
|
+
|
|
5
|
+
export type GalleryControllerGlobalItem = {
|
|
6
|
+
fullName?: string;
|
|
7
|
+
mediaType?: string;
|
|
8
|
+
layerChildType?: string;
|
|
9
|
+
isOpened?: boolean;
|
|
10
|
+
variants?: GalleryFullVariant[];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type GalleryControllerGlobalState = {
|
|
14
|
+
currentItems?: GalleryControllerGlobalItem[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const toGalleryMediaName = (name = "", layerChildType?: string) => (layerChildType ? `${layerChildType}/${name}` : name);
|
|
18
|
+
|
|
19
|
+
export const getItemFromPayload = (
|
|
20
|
+
{ index = 0, fullName, mediaType, layerChildType, isOpened, variants }: GalleryFullShowPayload = {},
|
|
21
|
+
galleryState?: unknown,
|
|
22
|
+
): GalleryControllerGlobalItem => {
|
|
23
|
+
if (fullName || mediaType || variants?.length) return { fullName, mediaType, layerChildType, isOpened, variants };
|
|
24
|
+
|
|
25
|
+
return (galleryState as GalleryControllerGlobalState | undefined)?.currentItems?.[index] ?? {};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const getItemVariants = (item: GalleryControllerGlobalItem = {}): GalleryFullVariant[] => {
|
|
29
|
+
if (item.variants?.length) return item.variants;
|
|
30
|
+
|
|
31
|
+
const { isOpened = false, layerChildType, fullName } = item;
|
|
32
|
+
|
|
33
|
+
return fullName || item.mediaType ? [{ isOpened, layerChildType, name: fullName }] : [];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const toImageSrc = (src: unknown): string | GalleryFullImageSrcItem[] => {
|
|
37
|
+
if (typeof src === "string") return src;
|
|
38
|
+
if (Array.isArray(src)) {
|
|
39
|
+
const items = src.map((item) => ({ url: item.url, duration: 0, transition: 0 }));
|
|
40
|
+
|
|
41
|
+
return items.length === 1 ? items[0].url : items;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return "";
|
|
45
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { Image, PageSelector, PositionBox, Screen, Svg, createRenderFunc, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import type { GalleryFullPluginConstants, GalleryFullPluginEvents, GalleryFullPluginParams, GalleryFullPluginSettings } from "../types.js";
|
|
8
|
+
import type { GalleryFullPluginState } from "../types.js";
|
|
9
|
+
type GalleryFullComponentProps = ReactComponentProps<
|
|
10
|
+
GalleryFullPluginEvents,
|
|
11
|
+
GalleryFullPluginConstants,
|
|
12
|
+
GalleryFullPluginSettings,
|
|
13
|
+
GalleryFullPluginParams,
|
|
14
|
+
GalleryFullPluginState
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
const LOCKED_FILTER = "blur(var(--vne-screen-blur))";
|
|
18
|
+
|
|
19
|
+
const GalleryFull = ({ store, onMount, PARAMS, emit, EVENTS }: GalleryFullComponentProps) => {
|
|
20
|
+
const {
|
|
21
|
+
isShow = false,
|
|
22
|
+
imageSrc = "",
|
|
23
|
+
isAllSrcRendered = false,
|
|
24
|
+
withBackgroundBlur = false,
|
|
25
|
+
pageIndex = 0,
|
|
26
|
+
pagesCount = 0,
|
|
27
|
+
} = useStoreState<GalleryFullPluginState>(store, onMount);
|
|
28
|
+
|
|
29
|
+
const propsView = PARAMS.GALLERY_FULL_VIEW.VIEW_PROPS;
|
|
30
|
+
const showPages = pagesCount > 1;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Screen
|
|
34
|
+
{...propsView.screen}
|
|
35
|
+
isShow={isShow}
|
|
36
|
+
isDisableAutoread={isShow}
|
|
37
|
+
>
|
|
38
|
+
<Image
|
|
39
|
+
{...propsView.image}
|
|
40
|
+
src={imageSrc}
|
|
41
|
+
isAllSrcRendered={isAllSrcRendered}
|
|
42
|
+
isSwitchDisabled={true}
|
|
43
|
+
transition={propsView.image.transition}
|
|
44
|
+
filter={withBackgroundBlur ? LOCKED_FILTER : undefined}
|
|
45
|
+
/>
|
|
46
|
+
<PositionBox {...propsView.close.position}>
|
|
47
|
+
<Svg.Cross
|
|
48
|
+
{...propsView.close.props}
|
|
49
|
+
onClick={() => void emit(EVENTS.GALLERY_FULL_VIEW.HIDE)}
|
|
50
|
+
/>
|
|
51
|
+
</PositionBox>
|
|
52
|
+
<PositionBox
|
|
53
|
+
{...propsView.pages.position}
|
|
54
|
+
isNotRender={!showPages}
|
|
55
|
+
>
|
|
56
|
+
<PageSelector
|
|
57
|
+
onPrevPage={() => void emit(EVENTS.GALLERY_FULL_VIEW.PREV)}
|
|
58
|
+
onNextPage={() => void emit(EVENTS.GALLERY_FULL_VIEW.NEXT)}
|
|
59
|
+
pagesCount={pagesCount}
|
|
60
|
+
page={pageIndex + 1}
|
|
61
|
+
pagesMinCount={1}
|
|
62
|
+
/>
|
|
63
|
+
</PositionBox>
|
|
64
|
+
</Screen>
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const render: ViewRenderFunc<GalleryFullPluginState> = createRenderFunc(GalleryFull);
|
package/tsconfig.json
ADDED
package/README.md
DELETED