@vnejs/plugins.controllers.screens.history 0.0.0-stage → 0.2.22

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 (52) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js +20 -0
  3. package/dist/modules/controller.accept.d.ts +12 -0
  4. package/dist/modules/controller.accept.js +14 -0
  5. package/dist/modules/controller.arrows.d.ts +11 -0
  6. package/dist/modules/controller.arrows.js +10 -0
  7. package/dist/modules/controller.click.d.ts +8 -0
  8. package/dist/modules/controller.click.js +15 -0
  9. package/dist/modules/controller.d.ts +17 -0
  10. package/dist/modules/controller.js +29 -0
  11. package/dist/modules/hide.controls.d.ts +8 -0
  12. package/dist/modules/hide.controls.js +7 -0
  13. package/dist/modules/hide.state.d.ts +7 -0
  14. package/dist/modules/hide.state.js +6 -0
  15. package/dist/modules/view.d.ts +10 -0
  16. package/dist/modules/view.js +9 -0
  17. package/dist/types.d.ts +20 -0
  18. package/dist/types.js +1 -0
  19. package/dist/utils/history.d.ts +7 -0
  20. package/dist/utils/history.js +1 -0
  21. package/dist/view/components/HistoryClose.d.ts +2 -0
  22. package/dist/view/components/HistoryClose.js +3 -0
  23. package/dist/view/components/HistoryLines.d.ts +12 -0
  24. package/dist/view/components/HistoryLines.js +43 -0
  25. package/dist/view/components/index.d.ts +2 -0
  26. package/dist/view/components/index.js +2 -0
  27. package/dist/view/index.d.ts +3 -0
  28. package/dist/view/index.js +8 -0
  29. package/package.json +65 -4
  30. package/src/index.ts +24 -0
  31. package/src/modules/controller.accept.ts +28 -0
  32. package/src/modules/controller.arrows.ts +23 -0
  33. package/src/modules/controller.click.ts +23 -0
  34. package/src/modules/controller.ts +49 -0
  35. package/src/modules/hide.controls.ts +17 -0
  36. package/src/modules/hide.state.ts +11 -0
  37. package/src/modules/view.ts +17 -0
  38. package/src/tests/accept.test.ts +72 -0
  39. package/src/tests/arrows.test.ts +88 -0
  40. package/src/tests/controller.click.test.ts +35 -0
  41. package/src/tests/hide.controls.test.ts +57 -0
  42. package/src/tests/hide.state.test.ts +25 -0
  43. package/src/tests/history.test.ts +45 -0
  44. package/src/tests/setup.ts +46 -0
  45. package/src/types.ts +29 -0
  46. package/src/utils/history.ts +9 -0
  47. package/src/view/components/HistoryClose.tsx +12 -0
  48. package/src/view/components/HistoryLines.tsx +84 -0
  49. package/src/view/components/index.ts +2 -0
  50. package/src/view/index.tsx +51 -0
  51. package/tsconfig.json +10 -0
  52. package/README.md +0 -3
@@ -0,0 +1,2 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import "@vnejs/contracts.controllers.screens.history";
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import "@vnejs/contracts.controllers.screens.history";
3
+ import { regPlugin } from "@vnejs/registry";
4
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.history";
5
+ import { HistoryViewControllerAccept } from "./modules/controller.accept.js";
6
+ import { HistoryViewControllerArrows } from "./modules/controller.arrows.js";
7
+ import { HistoryViewControllerClick } from "./modules/controller.click.js";
8
+ import { HistoryViewController } from "./modules/controller.js";
9
+ import { HistoryViewHideControls } from "./modules/hide.controls.js";
10
+ import { HistoryViewHideState } from "./modules/hide.state.js";
11
+ import { HistoryView } from "./modules/view.js";
12
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
13
+ HistoryViewController,
14
+ HistoryViewControllerAccept,
15
+ HistoryViewControllerArrows,
16
+ HistoryViewControllerClick,
17
+ HistoryViewHideControls,
18
+ HistoryViewHideState,
19
+ HistoryView,
20
+ ]);
@@ -0,0 +1,12 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
3
+ import type { HistoryPluginState } from "../types.js";
4
+ export declare class HistoryViewControllerAccept extends ModuleControllerAccept<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState> {
5
+ name: string;
6
+ EVENT_SHOW: "vne:history_view:show";
7
+ EVENT_HIDE: "vne:history_view:hide";
8
+ EVENT_ACCEPT: "vne:history_view:accept";
9
+ EVENT_UPDATE_STATE: "vne:history_view:update_state";
10
+ CONTROLS_ZINDEX: number;
11
+ onAccept: () => void;
12
+ }
@@ -0,0 +1,14 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+ export class HistoryViewControllerAccept extends ModuleControllerAccept {
3
+ name = "history.view.controller.accept";
4
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
6
+ EVENT_ACCEPT = this.EVENTS.HISTORY_VIEW.ACCEPT;
7
+ EVENT_UPDATE_STATE = this.EVENTS.HISTORY_VIEW.UPDATE_STATE;
8
+ CONTROLS_ZINDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
9
+ onAccept = () => {
10
+ if (this.state.currentArrowVerticalItem === null || this.state.currentArrowVerticalItem === undefined)
11
+ return;
12
+ this.emit(this.EVENTS.HISTORY_VIEW.CLICK, { uid: this.globalState.history.history[this.state.currentArrowVerticalItem].uid });
13
+ };
14
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
3
+ export declare class HistoryViewControllerArrows extends ModuleControllerArrowsVertical<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams> {
4
+ name: string;
5
+ EVENT_SHOW: "vne:history_view:show";
6
+ EVENT_HIDE: "vne:history_view:hide";
7
+ EVENT_UPDATE_STATE: "vne:history_view:update_state";
8
+ EVENT_UPDATE_FAST: "vne:history_view:update_fast";
9
+ CONTROLS_ZINDEX: number;
10
+ getMaxCurrentItem: () => number;
11
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+ export class HistoryViewControllerArrows extends ModuleControllerArrowsVertical {
3
+ name = "history.view.controller.arrows";
4
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.HISTORY_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.HISTORY_VIEW.UPDATE_FAST;
8
+ CONTROLS_ZINDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
9
+ getMaxCurrentItem = () => (this.globalState.history?.history ?? []).length - 1;
10
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { HistoryClickPayload } from "@vnejs/contracts.controllers.screens.history";
3
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
4
+ export declare class HistoryViewControllerClick extends ModuleCore<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams> {
5
+ name: string;
6
+ subscribe: () => void;
7
+ onClick: ({ uid }?: HistoryClickPayload) => Promise<import("@vnejs/registry").EmitResults<"vne:history:load"> | undefined>;
8
+ }
@@ -0,0 +1,15 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ export class HistoryViewControllerClick extends ModuleCore {
3
+ name = "history.view.controller.click";
4
+ subscribe = () => {
5
+ this.on(this.EVENTS.HISTORY_VIEW.CLICK, this.onClick);
6
+ };
7
+ onClick = async ({ uid } = {}) => {
8
+ if (uid == null)
9
+ return;
10
+ const keys = (await this.emitOne(this.EVENTS.HISTORY.KEYS)) ?? [];
11
+ if (!keys.includes(uid))
12
+ return;
13
+ return this.emit(this.EVENTS.HISTORY.LOAD, { uid });
14
+ };
15
+ }
@@ -0,0 +1,17 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ import type { HistoryEntry } from "@vnejs/contracts.scenario.history";
3
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
4
+ import type { HistoryPluginState } from "../types.js";
5
+ export declare class HistoryViewController extends ModuleController<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState> {
6
+ name: string;
7
+ EVENT_UPDATE_VIEW: "vne:history_view:update";
8
+ EVENT_UPDATE_STATE: "vne:history_view:update_state";
9
+ EVENT_UPDATE_FAST: "vne:history_view:update_fast";
10
+ EVENT_UPDATE_FORCE: "vne:history_view:update_force";
11
+ EVENT_SHOW: "vne:history_view:show";
12
+ EVENT_HIDE: "vne:history_view:hide";
13
+ CONTROLS: {};
14
+ CONTROLS_INDEX: number;
15
+ onShowBefore: () => Promise<void>;
16
+ getHistoryText: ({ label, text, args, uid, locKey }: HistoryEntry) => Promise<string>;
17
+ }
@@ -0,0 +1,29 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+ const MARK_REG = /\{.*?\}/g;
3
+ export class HistoryViewController extends ModuleController {
4
+ name = "history.view.controller";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.HISTORY_VIEW.UPDATE;
6
+ EVENT_UPDATE_STATE = this.EVENTS.HISTORY_VIEW.UPDATE_STATE;
7
+ EVENT_UPDATE_FAST = this.EVENTS.HISTORY_VIEW.UPDATE_FAST;
8
+ EVENT_UPDATE_FORCE = this.EVENTS.HISTORY_VIEW.UPDATE_FORCE;
9
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
10
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
11
+ CONTROLS = {};
12
+ CONTROLS_INDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
13
+ onShowBefore = async () => {
14
+ const history = this.globalState.history.history;
15
+ this.updateState({
16
+ historyLocs: await Promise.all(history.map(this.getHistoryText)),
17
+ historyKeys: (await this.emitOne(this.EVENTS.HISTORY.KEYS)) ?? [],
18
+ history,
19
+ });
20
+ };
21
+ getHistoryText = async ({ label, text, args, uid, locKey }) => {
22
+ const state = (await this.emitOne(this.EVENTS.HISTORY.GET, { uid })) ?? undefined;
23
+ const replaceArg = locKey
24
+ ? { label: this.PARAMS.HISTORY_VIEW.LOC_LABEL, text: locKey, args, state, group: this.PARAMS.LOCS.GROUPS.VIEWS }
25
+ : { label, text, args, state };
26
+ const resolved = (await this.emitOne(this.EVENTS.TEXT.REPLACE, replaceArg)) ?? "";
27
+ return resolved.replace(MARK_REG, "");
28
+ };
29
+ }
@@ -0,0 +1,8 @@
1
+ import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
2
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
3
+ export declare class HistoryViewHideControls extends ModuleControllerHideOnControls<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams> {
4
+ name: string;
5
+ EVENT_SHOW: "vne:history_view:show";
6
+ EVENT_HIDE: "vne:history_view:hide";
7
+ CONTROLS_ZINDEX: number;
8
+ }
@@ -0,0 +1,7 @@
1
+ import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
2
+ export class HistoryViewHideControls extends ModuleControllerHideOnControls {
3
+ name = "history.view.hide.controls";
4
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
5
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
6
+ CONTROLS_ZINDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
3
+ export declare class HistoryViewHideState extends ModuleControllerHideOnState<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams> {
4
+ name: string;
5
+ EVENT_HIDE: "vne:history_view:hide";
6
+ IS_STATE_CLEAR_ENABLED: boolean;
7
+ }
@@ -0,0 +1,6 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+ export class HistoryViewHideState extends ModuleControllerHideOnState {
3
+ name = "history.view.hide.state";
4
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
5
+ IS_STATE_CLEAR_ENABLED = false;
6
+ }
@@ -0,0 +1,10 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
3
+ import type { HistoryPluginState } from "../types.js";
4
+ export declare class HistoryView extends ModuleView<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState> {
5
+ name: string;
6
+ EVENT_UPDATE_VIEW: "vne:history_view:update";
7
+ LOC_LABEL: string;
8
+ TRANSITION: number;
9
+ renderFunc: import("@vnejs/module.components").ViewRenderFunc<HistoryPluginState>;
10
+ }
@@ -0,0 +1,9 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+ import { render } from "../view/index.js";
3
+ export class HistoryView extends ModuleView {
4
+ name = "history.view";
5
+ EVENT_UPDATE_VIEW = this.EVENTS.HISTORY_VIEW.UPDATE;
6
+ LOC_LABEL = this.PARAMS.HISTORY_VIEW.LOC_LABEL;
7
+ TRANSITION = this.PARAMS.HISTORY_VIEW.TRANSITION;
8
+ renderFunc = render;
9
+ }
@@ -0,0 +1,20 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.history";
3
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
4
+ import type { HistoryEntry, PluginName as HistoryPluginName, SubscribeEvents as HistorySubscribeEvents } from "@vnejs/contracts.scenario.history";
5
+ import type { Params as TextParams, PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
6
+ import type { Params as LocsParams, PluginName as LocsPluginName } from "@vnejs/contracts.text.locs";
7
+ export type HistoryPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<HistoryPluginName, HistorySubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
8
+ export type HistoryPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
9
+ export type HistoryPluginSettings = ModuleComponentsSettings;
10
+ export type HistoryPluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<TextPluginName, TextParams> & Record<LocsPluginName, LocsParams>;
11
+ export type HistoryPluginState = {
12
+ isShow: boolean;
13
+ isForce: boolean;
14
+ locs?: Record<string, string>;
15
+ history?: HistoryEntry[];
16
+ historyLocs?: string[];
17
+ historyKeys?: string[];
18
+ currentItem?: number | null;
19
+ currentArrowVerticalItem?: number | null;
20
+ };
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { Module } from "@vnejs/module";
2
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings, HistoryPluginState } from "../types.js";
3
+ export type HistoryViewContext = {
4
+ emit: Module<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState>["emit"];
5
+ EVENTS: HistoryPluginEvents;
6
+ PARAMS: HistoryPluginParams;
7
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { HistoryViewContext } from "../../utils/history.js";
2
+ export declare const HistoryClose: ({ emit, EVENTS, PARAMS }: HistoryViewContext) => import("react").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { PositionBox, Svg } from "@vnejs/uis.react";
3
+ export const HistoryClose = ({ emit, EVENTS, PARAMS }) => (_jsx(PositionBox, { ...PARAMS.HISTORY_VIEW.VIEW_PROPS.close.position, children: _jsx(Svg.Cross, { ...PARAMS.HISTORY_VIEW.VIEW_PROPS.close.svg, onClick: () => void emit(EVENTS.HISTORY_VIEW.HIDE) }) }));
@@ -0,0 +1,12 @@
1
+ import type { HistoryEntry } from "@vnejs/contracts.scenario.history";
2
+ import type { HistoryViewContext } from "../../utils/history.js";
3
+ type HistoryLinesProps = HistoryViewContext & {
4
+ isShow?: boolean;
5
+ history?: HistoryEntry[];
6
+ currentItem?: number | null;
7
+ historyLocs?: string[];
8
+ historyKeys?: (string | null | undefined)[];
9
+ locs?: Record<string, string>;
10
+ };
11
+ export declare const HistoryLines: ({ isShow, history, currentItem, historyLocs, historyKeys, locs, emit, EVENTS, PARAMS, }: HistoryLinesProps) => import("react").JSX.Element;
12
+ export {};
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import { PositionBox, Text, TextControls } from "@vnejs/uis.react";
4
+ const scrollToBottom = (scrollbarWrapRef) => {
5
+ if (!scrollbarWrapRef.current)
6
+ return requestAnimationFrame(() => scrollToBottom(scrollbarWrapRef));
7
+ if (scrollbarWrapRef.current.clientHeight === scrollbarWrapRef.current.scrollHeight || scrollbarWrapRef.current.scrollTop !== 0)
8
+ return;
9
+ scrollbarWrapRef.current.scrollTop = 9999999;
10
+ requestAnimationFrame(() => scrollToBottom(scrollbarWrapRef));
11
+ };
12
+ export const HistoryLines = ({ isShow = false, history = [], currentItem = null, historyLocs = [], historyKeys = [], locs = {}, emit, EVENTS, PARAMS, }) => {
13
+ const scrollbarWrapRef = useRef(null);
14
+ const onClick = (uid) => {
15
+ if (typeof uid === "string" && historyKeys.includes(uid))
16
+ void emit(EVENTS.HISTORY_VIEW.CLICK, { uid });
17
+ };
18
+ const texts = history.map(({ text, uid, speaker, speakerInfo }, i) => {
19
+ const speakers = PARAMS.TEXT.SPEAKERS_INFO;
20
+ const { speakerColor = "white" } = (speakers[speaker || ""] || speakers.default || {});
21
+ const speakerKey = speaker ?? "";
22
+ const meet = speakerInfo?.meet ?? 0;
23
+ const defaultSpeakerName = PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
24
+ const speakerName = locs[`speaker.${speakerKey}.${meet}`] ??
25
+ locs[`speaker.${speakerKey}`] ??
26
+ speakers[speakerKey]?.displayName ??
27
+ (speakerKey !== defaultSpeakerName ? speakerKey : undefined);
28
+ return {
29
+ text: (historyLocs && historyLocs[i]) || text,
30
+ value: uid,
31
+ textPrefix: speakerName ? `${speakerName}: ` : undefined,
32
+ colorPrefix: speakerColor,
33
+ weightPrefix: Text.WEIGHT.BOLD,
34
+ isHoverable: Boolean(historyKeys.find((key) => key === uid)),
35
+ };
36
+ });
37
+ useEffect(() => {
38
+ if (isShow)
39
+ requestAnimationFrame(() => scrollToBottom(scrollbarWrapRef));
40
+ }, [isShow]);
41
+ const propsView = PARAMS.HISTORY_VIEW.VIEW_PROPS.lines;
42
+ return (_jsx(PositionBox, { ...propsView.position, children: _jsx(TextControls, { ...propsView.controls, onClick: onClick, scrollbarWrapRef: scrollbarWrapRef, texts: texts, selectedIndex: currentItem ?? undefined }) }));
43
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./HistoryClose.js";
2
+ export * from "./HistoryLines.js";
@@ -0,0 +1,2 @@
1
+ export * from "./HistoryClose.js";
2
+ export * from "./HistoryLines.js";
@@ -0,0 +1,3 @@
1
+ import type { ViewRenderFunc } from "@vnejs/module.components";
2
+ import type { HistoryPluginState } from "../types.js";
3
+ export declare const render: ViewRenderFunc<HistoryPluginState>;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Screen, createRenderFunc, useStoreState } from "@vnejs/uis.react";
3
+ import { HistoryClose, HistoryLines } from "./components/index.js";
4
+ const History = ({ store, onMount, PARAMS, emit, EVENTS }) => {
5
+ const { isShow = false, isForce = false, locs = {}, history = [], historyLocs = [], historyKeys = [], currentArrowVerticalItem = null, } = useStoreState(store, onMount);
6
+ return (_jsxs(Screen, { ...PARAMS.HISTORY_VIEW.VIEW_PROPS.screen, isShow: isShow, isForce: isForce, children: [_jsx(HistoryLines, { emit: emit, EVENTS: EVENTS, PARAMS: PARAMS, history: history, historyLocs: historyLocs, historyKeys: historyKeys, isShow: isShow, currentItem: currentArrowVerticalItem, locs: locs }), _jsx(HistoryClose, { emit: emit, EVENTS: EVENTS, PARAMS: PARAMS })] }));
7
+ };
8
+ export const render = createRenderFunc(History);
package/package.json CHANGED
@@ -1,6 +1,67 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.controllers.screens.history",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.22",
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.history": "~0.2.0"
34
+ },
35
+ "peerDependencies": {
36
+ "@vnejs/helpers": "~0.2.0",
37
+ "@vnejs/module.components": "~0.2.0",
38
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
39
+ "@vnejs/module.controller.accept": "~0.2.0",
40
+ "@vnejs/module.controller.hide.on.controls": "~0.2.0",
41
+ "@vnejs/module.controller.hide.on.state": "~0.2.0",
42
+ "@vnejs/contracts.controls": "~0.2.0",
43
+ "@vnejs/contracts.scenario.history": "~0.2.0",
44
+ "@vnejs/contracts.text": "~0.2.0",
45
+ "@vnejs/contracts.text.locs": "~0.2.0",
46
+ "@vnejs/registry": "~0.2.0",
47
+ "@vnejs/uis.react": "~0.2.0"
48
+ },
49
+ "devDependencies": {
50
+ "@vnejs/configs.ts-common": "~0.2.0",
51
+ "@vnejs/configs.vitest": "~0.2.0",
52
+ "@vnejs/test-utils": "~0.2.0",
53
+ "@vnejs/contracts.controls": "~0.2.0",
54
+ "@vnejs/contracts.text": "~0.2.0",
55
+ "@vnejs/contracts.text.locs": "~0.2.0",
56
+ "@vnejs/contracts.scenario.history": "~0.2.0",
57
+ "@vnejs/contracts.controllers.screens.history": "~0.2.0",
58
+ "@vnejs/helpers": "~0.2.0",
59
+ "@vnejs/module.components": "~0.2.0",
60
+ "@vnejs/module.controller.arrows.vertical": "~0.2.0",
61
+ "@vnejs/module.controller.accept": "~0.2.0",
62
+ "@vnejs/module.controller.hide.on.controls": "~0.2.0",
63
+ "@vnejs/module.controller.hide.on.state": "~0.2.0",
64
+ "@vnejs/registry": "~0.2.0",
65
+ "@vnejs/uis.react": "~0.2.0"
66
+ }
67
+ }
package/src/index.ts ADDED
@@ -0,0 +1,24 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import "@vnejs/contracts.controllers.screens.history";
3
+
4
+ import { regPlugin } from "@vnejs/registry";
5
+
6
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.history";
7
+
8
+ import { HistoryViewControllerAccept } from "./modules/controller.accept.js";
9
+ import { HistoryViewControllerArrows } from "./modules/controller.arrows.js";
10
+ import { HistoryViewControllerClick } from "./modules/controller.click.js";
11
+ import { HistoryViewController } from "./modules/controller.js";
12
+ import { HistoryViewHideControls } from "./modules/hide.controls.js";
13
+ import { HistoryViewHideState } from "./modules/hide.state.js";
14
+ import { HistoryView } from "./modules/view.js";
15
+
16
+ regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [
17
+ HistoryViewController,
18
+ HistoryViewControllerAccept,
19
+ HistoryViewControllerArrows,
20
+ HistoryViewControllerClick,
21
+ HistoryViewHideControls,
22
+ HistoryViewHideState,
23
+ HistoryView,
24
+ ]);
@@ -0,0 +1,28 @@
1
+ import { ModuleControllerAccept } from "@vnejs/module.controller.accept";
2
+
3
+ import type { HistoryModuleState } from "@vnejs/contracts.scenario.history";
4
+
5
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
6
+ import type { HistoryPluginState } from "../types.js";
7
+ export class HistoryViewControllerAccept extends ModuleControllerAccept<
8
+ HistoryPluginEvents,
9
+ HistoryPluginConstants,
10
+ HistoryPluginSettings,
11
+ HistoryPluginParams,
12
+ HistoryPluginState
13
+ > {
14
+ name = "history.view.controller.accept";
15
+
16
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
17
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
18
+ EVENT_ACCEPT = this.EVENTS.HISTORY_VIEW.ACCEPT;
19
+ EVENT_UPDATE_STATE = this.EVENTS.HISTORY_VIEW.UPDATE_STATE;
20
+
21
+ CONTROLS_ZINDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
22
+
23
+ onAccept = () => {
24
+ if (this.state.currentArrowVerticalItem === null || this.state.currentArrowVerticalItem === undefined) return;
25
+
26
+ this.emit(this.EVENTS.HISTORY_VIEW.CLICK, { uid: (this.globalState.history as HistoryModuleState).history[this.state.currentArrowVerticalItem].uid });
27
+ };
28
+ }
@@ -0,0 +1,23 @@
1
+ import { ModuleControllerArrowsVertical } from "@vnejs/module.controller.arrows.vertical";
2
+
3
+ import type { HistoryModuleState } from "@vnejs/contracts.scenario.history";
4
+
5
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
6
+
7
+ export class HistoryViewControllerArrows extends ModuleControllerArrowsVertical<
8
+ HistoryPluginEvents,
9
+ HistoryPluginConstants,
10
+ HistoryPluginSettings,
11
+ HistoryPluginParams
12
+ > {
13
+ name = "history.view.controller.arrows";
14
+
15
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
16
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
17
+ EVENT_UPDATE_STATE = this.EVENTS.HISTORY_VIEW.UPDATE_STATE;
18
+ EVENT_UPDATE_FAST = this.EVENTS.HISTORY_VIEW.UPDATE_FAST;
19
+
20
+ CONTROLS_ZINDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
21
+
22
+ getMaxCurrentItem = () => ((this.globalState.history as HistoryModuleState | undefined)?.history ?? []).length - 1;
23
+ }
@@ -0,0 +1,23 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import type { HistoryClickPayload } from "@vnejs/contracts.controllers.screens.history";
4
+
5
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
6
+
7
+ export class HistoryViewControllerClick extends ModuleCore<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams> {
8
+ name = "history.view.controller.click";
9
+
10
+ subscribe = () => {
11
+ this.on(this.EVENTS.HISTORY_VIEW.CLICK, this.onClick);
12
+ };
13
+
14
+ onClick = async ({ uid }: HistoryClickPayload = {}) => {
15
+ if (uid == null) return;
16
+
17
+ const keys = (await this.emitOne(this.EVENTS.HISTORY.KEYS)) ?? [];
18
+
19
+ if (!keys.includes(uid)) return;
20
+
21
+ return this.emit(this.EVENTS.HISTORY.LOAD, { uid });
22
+ };
23
+ }
@@ -0,0 +1,49 @@
1
+ import { ModuleController } from "@vnejs/module.components";
2
+
3
+ import type { HistoryEntry, HistoryModuleState } from "@vnejs/contracts.scenario.history";
4
+ import type { TextReplacePayload } from "@vnejs/contracts.text";
5
+
6
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
7
+ import type { HistoryPluginState } from "../types.js";
8
+
9
+ const MARK_REG = /\{.*?\}/g;
10
+
11
+ export class HistoryViewController extends ModuleController<
12
+ HistoryPluginEvents,
13
+ HistoryPluginConstants,
14
+ HistoryPluginSettings,
15
+ HistoryPluginParams,
16
+ HistoryPluginState
17
+ > {
18
+ name = "history.view.controller";
19
+
20
+ EVENT_UPDATE_VIEW = this.EVENTS.HISTORY_VIEW.UPDATE;
21
+ EVENT_UPDATE_STATE = this.EVENTS.HISTORY_VIEW.UPDATE_STATE;
22
+ EVENT_UPDATE_FAST = this.EVENTS.HISTORY_VIEW.UPDATE_FAST;
23
+ EVENT_UPDATE_FORCE = this.EVENTS.HISTORY_VIEW.UPDATE_FORCE;
24
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
25
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
26
+
27
+ CONTROLS = {};
28
+ CONTROLS_INDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
29
+
30
+ onShowBefore = async () => {
31
+ const history = (this.globalState.history as HistoryModuleState).history;
32
+
33
+ this.updateState({
34
+ historyLocs: await Promise.all(history.map(this.getHistoryText)),
35
+ historyKeys: (await this.emitOne(this.EVENTS.HISTORY.KEYS)) ?? [],
36
+ history,
37
+ });
38
+ };
39
+ getHistoryText = async ({ label, text, args, uid, locKey }: HistoryEntry) => {
40
+ const state = (await this.emitOne(this.EVENTS.HISTORY.GET, { uid })) ?? undefined;
41
+ const replaceArg = locKey
42
+ ? { label: this.PARAMS.HISTORY_VIEW.LOC_LABEL, text: locKey, args, state, group: this.PARAMS.LOCS.GROUPS.VIEWS }
43
+ : { label, text, args, state };
44
+
45
+ const resolved = (await this.emitOne(this.EVENTS.TEXT.REPLACE, replaceArg satisfies TextReplacePayload)) ?? "";
46
+
47
+ return resolved.replace(MARK_REG, "");
48
+ };
49
+ }
@@ -0,0 +1,17 @@
1
+ import { ModuleControllerHideOnControls } from "@vnejs/module.controller.hide.on.controls";
2
+
3
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
4
+
5
+ export class HistoryViewHideControls extends ModuleControllerHideOnControls<
6
+ HistoryPluginEvents,
7
+ HistoryPluginConstants,
8
+ HistoryPluginSettings,
9
+ HistoryPluginParams
10
+ > {
11
+ name = "history.view.hide.controls";
12
+
13
+ EVENT_SHOW = this.EVENTS.HISTORY_VIEW.SHOW;
14
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
15
+
16
+ CONTROLS_ZINDEX = this.PARAMS.HISTORY_VIEW.ZINDEX;
17
+ }
@@ -0,0 +1,11 @@
1
+ import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
2
+
3
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
4
+
5
+ export class HistoryViewHideState extends ModuleControllerHideOnState<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams> {
6
+ name = "history.view.hide.state";
7
+
8
+ EVENT_HIDE = this.EVENTS.HISTORY_VIEW.HIDE;
9
+
10
+ IS_STATE_CLEAR_ENABLED = false;
11
+ }
@@ -0,0 +1,17 @@
1
+ import { ModuleView } from "@vnejs/module.components";
2
+
3
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
4
+ import type { HistoryPluginState } from "../types.js";
5
+
6
+ import { render } from "../view/index.js";
7
+ export class HistoryView extends ModuleView<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState> {
8
+ name = "history.view";
9
+
10
+ EVENT_UPDATE_VIEW = this.EVENTS.HISTORY_VIEW.UPDATE;
11
+
12
+ LOC_LABEL = this.PARAMS.HISTORY_VIEW.LOC_LABEL;
13
+
14
+ TRANSITION = this.PARAMS.HISTORY_VIEW.TRANSITION;
15
+
16
+ renderFunc = render;
17
+ }
@@ -0,0 +1,72 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { HistoryViewControllerAccept } from "../modules/controller.accept.js";
6
+
7
+ import { CONTROLS_EVENTS, createHistoryTestModule, registerHistoryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("HistoryViewControllerAccept", () => {
10
+ beforeEach(() => {
11
+ registerHistoryPluginVne();
12
+ });
13
+
14
+ it("SHOW pushes ACCEPT and INTERACT controls", async () => {
15
+ const { module, observer } = createHistoryTestModule(HistoryViewControllerAccept);
16
+ const accept = module as HistoryViewControllerAccept;
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: "history.view.controller.accept",
24
+ checkNext: true,
25
+ index: accept.PARAMS.HISTORY_VIEW.ZINDEX + 1,
26
+ }),
27
+ );
28
+ expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.ACCEPT);
29
+ expect(push.mock.calls[0][0].controls).toHaveProperty(accept.CONST.CONTROLS.BUTTONS.INTERACT);
30
+ });
31
+
32
+ it("HIDE pops ACCEPT controls", async () => {
33
+ const { observer } = createHistoryTestModule(HistoryViewControllerAccept);
34
+ const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
35
+
36
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
37
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
38
+
39
+ expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "history.view.controller.accept" });
40
+ });
41
+
42
+ it("ACCEPT and INTERACT emit HISTORY_VIEW.ACCEPT", async () => {
43
+ const { module, observer } = createHistoryTestModule(HistoryViewControllerAccept, {
44
+ state: { history: { history: [{ uid: "line-1" }] } },
45
+ });
46
+ const accept = module as HistoryViewControllerAccept;
47
+ const acceptEvent = spyEvent(observer, SUBSCRIBE_EVENTS.ACCEPT);
48
+
49
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.ACCEPT]();
50
+ accept.CONTROLS[accept.CONST.CONTROLS.BUTTONS.INTERACT]();
51
+ await Promise.resolve();
52
+ await Promise.resolve();
53
+
54
+ expect(acceptEvent).toHaveBeenCalledTimes(2);
55
+ });
56
+
57
+ it("UPDATE_STATE caches currentArrowVerticalItem for CLICK", async () => {
58
+ const { module, observer } = createHistoryTestModule(HistoryViewControllerAccept, {
59
+ state: { history: { history: [{ uid: "a" }, { uid: "b" }] } },
60
+ });
61
+ const accept = module as HistoryViewControllerAccept;
62
+ const click = spyEvent(observer, SUBSCRIBE_EVENTS.CLICK);
63
+
64
+ await observer.emit(SUBSCRIBE_EVENTS.UPDATE_STATE, { currentArrowVerticalItem: 1 });
65
+
66
+ expect(accept.state.currentArrowVerticalItem).toBe(1);
67
+
68
+ await observer.emit(SUBSCRIBE_EVENTS.ACCEPT);
69
+
70
+ expect(click).toHaveBeenCalledExactlyOnceWith({ uid: "b" });
71
+ });
72
+ });
@@ -0,0 +1,88 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { HistoryViewControllerArrows } from "../modules/controller.arrows.js";
6
+
7
+ import { CONTROLS_EVENTS, createHistoryTestModule, registerHistoryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ const historyState = {
10
+ history: {
11
+ history: [
12
+ { uid: "uid-1", text: "A" },
13
+ { uid: "uid-2", text: "B" },
14
+ ],
15
+ },
16
+ };
17
+
18
+ describe("HistoryViewControllerArrows", () => {
19
+ beforeEach(() => {
20
+ registerHistoryPluginVne();
21
+ });
22
+
23
+ it("SHOW pushes arrow controls above the controller layer", async () => {
24
+ const { module, observer } = createHistoryTestModule(HistoryViewControllerArrows, { state: historyState });
25
+ const arrows = module as HistoryViewControllerArrows;
26
+ const push = spyEvent(observer, CONTROLS_EVENTS.PUSH);
27
+
28
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
29
+
30
+ expect(arrows.currentItem).toBeNull();
31
+ expect(push).toHaveBeenCalledExactlyOnceWith(
32
+ expect.objectContaining({
33
+ key: "history.view.controller.arrows",
34
+ checkNext: true,
35
+ index: arrows.PARAMS.HISTORY_VIEW.ZINDEX + 1,
36
+ }),
37
+ );
38
+ });
39
+
40
+ it("HIDE pops arrow controls", async () => {
41
+ const { observer } = createHistoryTestModule(HistoryViewControllerArrows, { state: historyState });
42
+ const pop = spyEvent(observer, CONTROLS_EVENTS.POP);
43
+
44
+ await observer.emit(SUBSCRIBE_EVENTS.SHOW);
45
+ await observer.emit(SUBSCRIBE_EVENTS.HIDE);
46
+
47
+ expect(pop).toHaveBeenCalledExactlyOnceWith({ key: "history.view.controller.arrows" });
48
+ });
49
+
50
+ it("first ARROW_BOTTOM selects 0 and emits UPDATE_STATE plus UPDATE_FAST", async () => {
51
+ const { module, observer } = createHistoryTestModule(HistoryViewControllerArrows, { state: historyState });
52
+ const arrows = module as HistoryViewControllerArrows;
53
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
54
+ const updateFast = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
55
+
56
+ await arrows.incCurrentItem();
57
+
58
+ expect(arrows.currentItem).toBe(0);
59
+ expect(stateUpdate).toHaveBeenCalledExactlyOnceWith({ currentArrowVerticalItem: 0 });
60
+ expect(updateFast).toHaveBeenCalledOnce();
61
+ });
62
+
63
+ it("arrow wrap cycles items", async () => {
64
+ const { module, observer } = createHistoryTestModule(HistoryViewControllerArrows, { state: historyState });
65
+ const arrows = module as HistoryViewControllerArrows;
66
+ const stateUpdate = spyEvent(observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
67
+
68
+ await arrows.incCurrentItem();
69
+ await arrows.incCurrentItem();
70
+ expect(arrows.currentItem).toBe(1);
71
+
72
+ await arrows.incCurrentItem();
73
+ expect(arrows.currentItem).toBe(0);
74
+ expect(stateUpdate).toHaveBeenLastCalledWith({ currentArrowVerticalItem: 0 });
75
+
76
+ await arrows.decCurrentItem();
77
+ expect(arrows.currentItem).toBe(1);
78
+ });
79
+
80
+ it("first ARROW_UP selects the last item", async () => {
81
+ const { module } = createHistoryTestModule(HistoryViewControllerArrows, { state: historyState });
82
+ const arrows = module as HistoryViewControllerArrows;
83
+
84
+ await arrows.decCurrentItem();
85
+
86
+ expect(arrows.currentItem).toBe(1);
87
+ });
88
+ });
@@ -0,0 +1,35 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent, stubEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as HISTORY_EVENTS } from "@vnejs/contracts.scenario.history";
6
+
7
+ import { HistoryViewControllerClick } from "../modules/controller.click.js";
8
+
9
+ import { createHistoryTestModule, registerHistoryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("HistoryViewControllerClick", () => {
12
+ beforeEach(() => {
13
+ registerHistoryPluginVne();
14
+ });
15
+
16
+ it("CLICK loads uid when HISTORY.KEYS includes it", async () => {
17
+ const { observer } = createHistoryTestModule(HistoryViewControllerClick);
18
+ stubEvent(observer, HISTORY_EVENTS.KEYS, () => ["uid-1"]);
19
+ const load = spyEvent(observer, HISTORY_EVENTS.LOAD);
20
+
21
+ await observer.emit(SUBSCRIBE_EVENTS.CLICK, { uid: "uid-1" });
22
+
23
+ expect(load).toHaveBeenCalledWith({ uid: "uid-1" });
24
+ });
25
+
26
+ it("CLICK skips uid missing from HISTORY.KEYS", async () => {
27
+ const { observer } = createHistoryTestModule(HistoryViewControllerClick);
28
+ stubEvent(observer, HISTORY_EVENTS.KEYS, () => ["other"]);
29
+ const load = spyEvent(observer, HISTORY_EVENTS.LOAD);
30
+
31
+ await observer.emit(SUBSCRIBE_EVENTS.CLICK, { uid: "uid-1" });
32
+
33
+ expect(load).not.toHaveBeenCalled();
34
+ });
35
+ });
@@ -0,0 +1,57 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { HistoryViewHideControls } from "../modules/hide.controls.js";
6
+
7
+ import { CONTROLS_EVENTS, createHistoryTestModule, registerHistoryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
8
+
9
+ describe("HistoryViewHideControls", () => {
10
+ beforeEach(() => {
11
+ registerHistoryPluginVne();
12
+ });
13
+
14
+ it("SHOW pushes BACK, MENU and GAMEMENU controls", async () => {
15
+ const { module, observer } = createHistoryTestModule(HistoryViewHideControls);
16
+ const hide = module as HistoryViewHideControls;
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: "history.view.hide.controls",
24
+ checkNext: true,
25
+ index: hide.PARAMS.HISTORY_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 } = createHistoryTestModule(HistoryViewHideControls);
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: "history.view.hide.controls" });
41
+ });
42
+
43
+ it("BACK, MENU and GAMEMENU emit HISTORY_VIEW.HIDE", async () => {
44
+ const { module, observer } = createHistoryTestModule(HistoryViewHideControls);
45
+ const hide = module as HistoryViewHideControls;
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 Promise.resolve();
52
+ await Promise.resolve();
53
+ await Promise.resolve();
54
+
55
+ expect(hideEvent).toHaveBeenCalledTimes(3);
56
+ });
57
+ });
@@ -0,0 +1,25 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
6
+
7
+ import { HistoryViewHideState } from "../modules/hide.state.js";
8
+
9
+ import { createHistoryTestModule, registerHistoryPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
10
+
11
+ describe("HistoryViewHideState", () => {
12
+ beforeEach(() => {
13
+ registerHistoryPluginVne();
14
+ });
15
+
16
+ it("STATE.SET emits HIDE with isForce and STATE.CLEAR does not", async () => {
17
+ const { observer } = createHistoryTestModule(HistoryViewHideState);
18
+ const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
19
+
20
+ await observer.emit(STATE_EVENTS.SET);
21
+ await observer.emit(STATE_EVENTS.CLEAR);
22
+
23
+ expect(hide).toHaveBeenCalledExactlyOnceWith({ isForce: true });
24
+ });
25
+ });
@@ -0,0 +1,45 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent, stubEvent } from "@vnejs/test-utils";
4
+
5
+ import { SUBSCRIBE_EVENTS as TEXT_EVENTS } from "@vnejs/contracts.text";
6
+
7
+ import { HistoryViewController } from "../modules/controller.js";
8
+
9
+ import { createHistoryTestModule, PARAMS, registerHistoryPluginVne } from "./setup.js";
10
+
11
+ describe("HistoryViewController", () => {
12
+ beforeEach(() => {
13
+ registerHistoryPluginVne();
14
+ });
15
+
16
+ it("getHistoryText resolves locKey via HISTORY_VIEW.LOC_LABEL", async () => {
17
+ const { module, observer } = createHistoryTestModule(HistoryViewController);
18
+ const replace = spyEvent(observer, TEXT_EVENTS.REPLACE);
19
+
20
+ await (module as HistoryViewController).getHistoryText({ uid: "uid-1", locKey: "choice" });
21
+
22
+ expect(replace).toHaveBeenCalledOnce();
23
+ expect(replace.mock.calls[0]?.[0]).toMatchObject({ label: PARAMS.LOC_LABEL, text: "choice" });
24
+ });
25
+
26
+ it("getHistoryText looks up the key with marks and strips them from the translation", async () => {
27
+ const { module, observer } = createHistoryTestModule(HistoryViewController);
28
+ let payload: unknown;
29
+
30
+ stubEvent(observer, TEXT_EVENTS.REPLACE, (arg) => {
31
+ payload = arg;
32
+
33
+ return "{i}Damn{/i}";
34
+ });
35
+
36
+ const text = await (module as HistoryViewController).getHistoryText({
37
+ uid: "uid-1",
38
+ label: "prologue/1",
39
+ text: "{i}Вот чёрт{/i}",
40
+ });
41
+
42
+ expect(payload).toMatchObject({ label: "prologue/1", text: "{i}Вот чёрт{/i}" });
43
+ expect(text).toBe("Damn");
44
+ });
45
+ });
@@ -0,0 +1,46 @@
1
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubEvent, stubSilentEvent } from "@vnejs/test-utils";
2
+
3
+ import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.screens.history";
4
+ import { CONSTANTS as CONTROLS_CONST, PLUGIN_NAME as CONTROLS, SUBSCRIBE_EVENTS as CONTROLS_EVENTS } from "@vnejs/contracts.controls";
5
+ import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
6
+ import { SUBSCRIBE_EVENTS as STATE_EVENTS } from "@vnejs/contracts.core.state";
7
+ import { PARAMS as HISTORY_PARAMS, PLUGIN_NAME as HISTORY, SUBSCRIBE_EVENTS as HISTORY_EVENTS } from "@vnejs/contracts.scenario.history";
8
+ import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
9
+ import { PARAMS as LOCS_PARAMS, PLUGIN_NAME as LOCS } from "@vnejs/contracts.text.locs";
10
+
11
+ export const registerHistoryPluginVne = () => {
12
+ registerCoreVne();
13
+ registerVnePlugin(CONTROLS, { constants: CONTROLS_CONST, events: CONTROLS_EVENTS });
14
+ registerVnePlugin(TEXT, { events: TEXT_EVENTS });
15
+ registerVnePlugin(LOCS, { params: LOCS_PARAMS });
16
+ registerVnePlugin(HISTORY, { events: HISTORY_EVENTS, params: HISTORY_PARAMS });
17
+ registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
18
+ };
19
+
20
+ export const createHistoryTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
21
+ ModuleClass: T,
22
+ options: Parameters<typeof baseCreateTestModule>[1] = {},
23
+ ) => {
24
+ const result = baseCreateTestModule(ModuleClass, {
25
+ state: {
26
+ history: { history: [] },
27
+ ...(options.state ?? {}),
28
+ },
29
+ ...options,
30
+ });
31
+
32
+ stubEvent(result.observer, STATE_EVENTS.GET, () => ({ scenario: { label: "start" } }));
33
+ stubSilentEvent(result.observer, STATE_EVENTS.LOAD);
34
+ stubSilentEvent(result.observer, SCENARIO_EVENTS.LABEL_GET);
35
+ stubEvent(result.observer, "vne:memory:set", () => undefined);
36
+ stubEvent(result.observer, "vne:memory:get", () => ({ scenario: { label: "start" } }));
37
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
38
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
39
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
40
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_STATE);
41
+ stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE_FAST);
42
+
43
+ return result;
44
+ };
45
+
46
+ export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, CONTROLS_EVENTS };
package/src/types.ts ADDED
@@ -0,0 +1,29 @@
1
+ import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
2
+
3
+ import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.screens.history";
4
+ import type { Constants as ControlsConstants, PluginName as ControlsPluginName } from "@vnejs/contracts.controls";
5
+ import type { HistoryEntry, PluginName as HistoryPluginName, SubscribeEvents as HistorySubscribeEvents } from "@vnejs/contracts.scenario.history";
6
+ import type { Params as TextParams, PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
7
+ import type { Params as LocsParams, PluginName as LocsPluginName } from "@vnejs/contracts.text.locs";
8
+
9
+ export type HistoryPluginEvents = ModuleComponentsEvents &
10
+ Record<PluginName, SubscribeEvents> &
11
+ Record<HistoryPluginName, HistorySubscribeEvents> &
12
+ Record<TextPluginName, TextSubscribeEvents>;
13
+
14
+ export type HistoryPluginConstants = ModuleComponentsConstants & Record<ControlsPluginName, ControlsConstants>;
15
+
16
+ export type HistoryPluginSettings = ModuleComponentsSettings;
17
+
18
+ export type HistoryPluginParams = ModuleComponentsParams & Record<PluginName, Params> & Record<TextPluginName, TextParams> & Record<LocsPluginName, LocsParams>;
19
+
20
+ export type HistoryPluginState = {
21
+ isShow: boolean;
22
+ isForce: boolean;
23
+ locs?: Record<string, string>;
24
+ history?: HistoryEntry[];
25
+ historyLocs?: string[];
26
+ historyKeys?: string[];
27
+ currentItem?: number | null;
28
+ currentArrowVerticalItem?: number | null;
29
+ };
@@ -0,0 +1,9 @@
1
+ import type { Module } from "@vnejs/module";
2
+
3
+ import type { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings, HistoryPluginState } from "../types.js";
4
+
5
+ export type HistoryViewContext = {
6
+ emit: Module<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState>["emit"];
7
+ EVENTS: HistoryPluginEvents;
8
+ PARAMS: HistoryPluginParams;
9
+ };
@@ -0,0 +1,12 @@
1
+ import { PositionBox, Svg } from "@vnejs/uis.react";
2
+
3
+ import type { HistoryViewContext } from "../../utils/history.js";
4
+
5
+ export const HistoryClose = ({ emit, EVENTS, PARAMS }: HistoryViewContext) => (
6
+ <PositionBox {...PARAMS.HISTORY_VIEW.VIEW_PROPS.close.position}>
7
+ <Svg.Cross
8
+ {...PARAMS.HISTORY_VIEW.VIEW_PROPS.close.svg}
9
+ onClick={() => void emit(EVENTS.HISTORY_VIEW.HIDE)}
10
+ />
11
+ </PositionBox>
12
+ );
@@ -0,0 +1,84 @@
1
+ import { useEffect, useRef } from "react";
2
+
3
+ import { PositionBox, Text, TextControls } from "@vnejs/uis.react";
4
+
5
+ import type { HistoryEntry } from "@vnejs/contracts.scenario.history";
6
+ import type { TextSpeakerInfo } from "@vnejs/contracts.text";
7
+
8
+ import type { HistoryViewContext } from "../../utils/history.js";
9
+
10
+ type HistoryLinesProps = HistoryViewContext & {
11
+ isShow?: boolean;
12
+ history?: HistoryEntry[];
13
+ currentItem?: number | null;
14
+ historyLocs?: string[];
15
+ historyKeys?: (string | null | undefined)[];
16
+ locs?: Record<string, string>;
17
+ };
18
+
19
+ const scrollToBottom = (scrollbarWrapRef: React.RefObject<HTMLDivElement | null>) => {
20
+ if (!scrollbarWrapRef.current) return requestAnimationFrame(() => scrollToBottom(scrollbarWrapRef));
21
+ if (scrollbarWrapRef.current.clientHeight === scrollbarWrapRef.current.scrollHeight || scrollbarWrapRef.current.scrollTop !== 0) return;
22
+
23
+ scrollbarWrapRef.current.scrollTop = 9999999;
24
+ requestAnimationFrame(() => scrollToBottom(scrollbarWrapRef));
25
+ };
26
+
27
+ export const HistoryLines = ({
28
+ isShow = false,
29
+ history = [],
30
+ currentItem = null,
31
+ historyLocs = [],
32
+ historyKeys = [],
33
+ locs = {},
34
+ emit,
35
+ EVENTS,
36
+ PARAMS,
37
+ }: HistoryLinesProps) => {
38
+ const scrollbarWrapRef = useRef<HTMLDivElement | null>(null);
39
+
40
+ const onClick = (uid?: unknown) => {
41
+ if (typeof uid === "string" && historyKeys.includes(uid)) void emit(EVENTS.HISTORY_VIEW.CLICK, { uid });
42
+ };
43
+
44
+ const texts = history.map(({ text, uid, speaker, speakerInfo }: HistoryEntry, i: number) => {
45
+ const speakers = PARAMS.TEXT.SPEAKERS_INFO;
46
+
47
+ const { speakerColor = "white" } = (speakers[speaker || ""] || speakers.default || {}) as TextSpeakerInfo;
48
+ const speakerKey = speaker ?? "";
49
+ const meet = (speakerInfo as { meet?: number | string } | undefined)?.meet ?? 0;
50
+ const defaultSpeakerName = PARAMS.TEXT.DEFAULT_SPEAKER_NAME;
51
+ const speakerName =
52
+ locs[`speaker.${speakerKey}.${meet}`] ??
53
+ locs[`speaker.${speakerKey}`] ??
54
+ speakers[speakerKey]?.displayName ??
55
+ (speakerKey !== defaultSpeakerName ? speakerKey : undefined);
56
+
57
+ return {
58
+ text: (historyLocs && historyLocs[i]) || text,
59
+ value: uid,
60
+ textPrefix: speakerName ? `${speakerName}: ` : undefined,
61
+ colorPrefix: speakerColor,
62
+ weightPrefix: Text.WEIGHT.BOLD,
63
+ isHoverable: Boolean(historyKeys.find((key) => key === uid)),
64
+ };
65
+ });
66
+
67
+ useEffect(() => {
68
+ if (isShow) requestAnimationFrame(() => scrollToBottom(scrollbarWrapRef));
69
+ }, [isShow]);
70
+
71
+ const propsView = PARAMS.HISTORY_VIEW.VIEW_PROPS.lines;
72
+
73
+ return (
74
+ <PositionBox {...propsView.position}>
75
+ <TextControls
76
+ {...propsView.controls}
77
+ onClick={onClick}
78
+ scrollbarWrapRef={scrollbarWrapRef}
79
+ texts={texts}
80
+ selectedIndex={currentItem ?? undefined}
81
+ />
82
+ </PositionBox>
83
+ );
84
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./HistoryClose.js";
2
+ export * from "./HistoryLines.js";
@@ -0,0 +1,51 @@
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 { HistoryPluginConstants, HistoryPluginEvents, HistoryPluginParams, HistoryPluginSettings } from "../types.js";
8
+ import type { HistoryPluginState } from "../types.js";
9
+
10
+ import { HistoryClose, HistoryLines } from "./components/index.js";
11
+
12
+ type HistoryComponentProps = ReactComponentProps<HistoryPluginEvents, HistoryPluginConstants, HistoryPluginSettings, HistoryPluginParams, HistoryPluginState>;
13
+
14
+ const History = ({ store, onMount, PARAMS, emit, EVENTS }: HistoryComponentProps) => {
15
+ const {
16
+ isShow = false,
17
+ isForce = false,
18
+ locs = {},
19
+ history = [],
20
+ historyLocs = [],
21
+ historyKeys = [],
22
+ currentArrowVerticalItem = null,
23
+ } = useStoreState<HistoryPluginState>(store, onMount);
24
+
25
+ return (
26
+ <Screen
27
+ {...PARAMS.HISTORY_VIEW.VIEW_PROPS.screen}
28
+ isShow={isShow}
29
+ isForce={isForce}
30
+ >
31
+ <HistoryLines
32
+ emit={emit}
33
+ EVENTS={EVENTS}
34
+ PARAMS={PARAMS}
35
+ history={history}
36
+ historyLocs={historyLocs}
37
+ historyKeys={historyKeys}
38
+ isShow={isShow}
39
+ currentItem={currentArrowVerticalItem}
40
+ locs={locs}
41
+ />
42
+ <HistoryClose
43
+ emit={emit}
44
+ EVENTS={EVENTS}
45
+ PARAMS={PARAMS}
46
+ />
47
+ </Screen>
48
+ );
49
+ };
50
+
51
+ export const render: ViewRenderFunc<HistoryPluginState> = createRenderFunc(History);
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.