@vnejs/plugins.controllers.common.comment 0.0.0-stage → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -0
- package/dist/index.js +8 -0
- package/dist/modules/comment.d.ts +14 -0
- package/dist/modules/comment.js +30 -0
- package/dist/modules/controller.d.ts +17 -0
- package/dist/modules/controller.js +16 -0
- package/dist/modules/hide.d.ts +6 -0
- package/dist/modules/hide.js +5 -0
- package/dist/modules/view.d.ts +9 -0
- package/dist/modules/view.js +8 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +1 -0
- package/dist/view/index.d.ts +3 -0
- package/dist/view/index.js +9 -0
- package/package.json +55 -4
- package/src/index.ts +12 -0
- package/src/modules/comment.ts +47 -0
- package/src/modules/controller.ts +32 -0
- package/src/modules/hide.ts +9 -0
- package/src/modules/view.ts +15 -0
- package/src/tests/comment.test.ts +70 -0
- package/src/tests/hide.test.ts +27 -0
- package/src/tests/setup.ts +33 -0
- package/src/types.ts +26 -0
- package/src/view/index.tsx +34 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.common.comment";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.common.comment";
|
|
2
|
+
import { regPlugin } from "@vnejs/registry";
|
|
3
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.comment";
|
|
4
|
+
import { CommentModule } from "./modules/comment.js";
|
|
5
|
+
import { CommentController } from "./modules/controller.js";
|
|
6
|
+
import { CommentHide } from "./modules/hide.js";
|
|
7
|
+
import { CommentView } from "./modules/view.js";
|
|
8
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [CommentModule, CommentController, CommentHide, CommentView]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
3
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
4
|
+
export declare class CommentModule extends ModuleCore<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
state: {
|
|
7
|
+
text?: string;
|
|
8
|
+
};
|
|
9
|
+
timeout: ReturnType<typeof setTimeout> | null;
|
|
10
|
+
subscribe: () => void;
|
|
11
|
+
init: () => Promise<import("@vnejs/registry").EmitResults<"vne:scenario:line_exec_reg">> | undefined;
|
|
12
|
+
onLineExec: ({ line, args }?: LineExecHandlerArg) => Promise<void>;
|
|
13
|
+
onHide: () => void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
3
|
+
export class CommentModule extends ModuleCore {
|
|
4
|
+
name = "comment";
|
|
5
|
+
state = {};
|
|
6
|
+
timeout = null;
|
|
7
|
+
subscribe = () => {
|
|
8
|
+
const { HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
9
|
+
this.on(this.EVENTS.COMMENT.HIDE, this.onHide, { priority: HIDE.MAIN });
|
|
10
|
+
};
|
|
11
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
12
|
+
onLineExec = async ({ line = "", args = {} } = {}) => {
|
|
13
|
+
const [text = "", durationToken = "0"] = tokenizeExecLine(line).map(String);
|
|
14
|
+
const duration = Number(durationToken);
|
|
15
|
+
if (text === "hide")
|
|
16
|
+
this.emit(this.EVENTS.COMMENT.HIDE);
|
|
17
|
+
else {
|
|
18
|
+
const { label } = this.globalState.scenario;
|
|
19
|
+
if (duration)
|
|
20
|
+
this.timeout = setTimeout(() => this.state.text === text && this.emit(this.EVENTS.COMMENT.HIDE), duration);
|
|
21
|
+
this.state.text = text;
|
|
22
|
+
this.emit(this.EVENTS.COMMENT.SHOW, { label, text, args });
|
|
23
|
+
}
|
|
24
|
+
this.emit(this.EVENTS.SCENARIO.NEXT);
|
|
25
|
+
};
|
|
26
|
+
onHide = () => {
|
|
27
|
+
if (this.timeout)
|
|
28
|
+
clearTimeout(this.timeout);
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
import type { CommentShowPayload } from "@vnejs/contracts.controllers.common.comment";
|
|
3
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
4
|
+
import type { CommentPluginState } from "../types.js";
|
|
5
|
+
export declare class CommentController extends ModuleController<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams, CommentPluginState> {
|
|
6
|
+
name: string;
|
|
7
|
+
EVENT_UPDATE_VIEW: "vne:comment:update";
|
|
8
|
+
EVENT_UPDATE_STATE: "vne:comment:update_state";
|
|
9
|
+
EVENT_UPDATE_FAST: "vne:comment:update_fast";
|
|
10
|
+
EVENT_UPDATE_FORCE: "vne:comment:update_force";
|
|
11
|
+
EVENT_SHOW: "vne:comment:show";
|
|
12
|
+
EVENT_HIDE: "vne:comment:hide";
|
|
13
|
+
getDefaultState: () => CommentPluginState;
|
|
14
|
+
onExternalUpdate: () => Promise<import("@vnejs/registry").EmitResults<string> | undefined>;
|
|
15
|
+
onShowBefore: ({ label, text, args }?: CommentShowPayload) => Promise<void>;
|
|
16
|
+
getRealText: (label?: string, text?: string, args?: Record<string, unknown>) => Promise<string>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
export class CommentController extends ModuleController {
|
|
3
|
+
name = "comment.controller";
|
|
4
|
+
EVENT_UPDATE_VIEW = this.EVENTS.COMMENT.UPDATE;
|
|
5
|
+
EVENT_UPDATE_STATE = this.EVENTS.COMMENT.UPDATE_STATE;
|
|
6
|
+
EVENT_UPDATE_FAST = this.EVENTS.COMMENT.UPDATE_FAST;
|
|
7
|
+
EVENT_UPDATE_FORCE = this.EVENTS.COMMENT.UPDATE_FORCE;
|
|
8
|
+
EVENT_SHOW = this.EVENTS.COMMENT.SHOW;
|
|
9
|
+
EVENT_HIDE = this.EVENTS.COMMENT.HIDE;
|
|
10
|
+
getDefaultState = () => ({ label: "", text: "", args: {}, isShow: false, isForce: false });
|
|
11
|
+
onExternalUpdate = async () => this.updateStateAndViewFast({ text: await this.getRealText(this.state.label, this.state.text, this.state.args) });
|
|
12
|
+
onShowBefore = async ({ label, text, args } = {}) => {
|
|
13
|
+
return this.updateState({ text: await this.getRealText(label, text, args) });
|
|
14
|
+
};
|
|
15
|
+
getRealText = async (label, text, args) => (await this.emitOne(this.EVENTS.TEXT.REPLACE, { label, text, args, state: this.globalState })) ?? "";
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
|
|
2
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
3
|
+
export declare class CommentHide extends ModuleControllerHideOnState<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams> {
|
|
4
|
+
name: string;
|
|
5
|
+
EVENT_HIDE: "vne:comment:hide";
|
|
6
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
3
|
+
import type { CommentPluginState } from "../types.js";
|
|
4
|
+
export declare class CommentView extends ModuleView<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams, CommentPluginState> {
|
|
5
|
+
name: string;
|
|
6
|
+
EVENT_UPDATE_VIEW: "vne:comment:update";
|
|
7
|
+
TRANSITION: number;
|
|
8
|
+
renderFunc: import("@vnejs/module.components").ViewRenderFunc<CommentPluginState>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
import { render } from "../view/index.js";
|
|
3
|
+
export class CommentView extends ModuleView {
|
|
4
|
+
name = "comment.view";
|
|
5
|
+
EVENT_UPDATE_VIEW = this.EVENTS.COMMENT.UPDATE;
|
|
6
|
+
TRANSITION = this.PARAMS.COMMENT.TRANSITION;
|
|
7
|
+
renderFunc = render;
|
|
8
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.common.comment";
|
|
3
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
|
|
4
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
|
|
5
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
6
|
+
export type CommentPluginEvents = ModuleComponentsEvents & Record<PluginName, SubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<StatePluginName, StateSubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
|
|
7
|
+
export type CommentPluginConstants = ModuleComponentsConstants;
|
|
8
|
+
export type CommentPluginSettings = ModuleComponentsSettings;
|
|
9
|
+
export type CommentPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
10
|
+
export type CommentPluginState = {
|
|
11
|
+
isShow: boolean;
|
|
12
|
+
isForce: boolean;
|
|
13
|
+
label?: string;
|
|
14
|
+
text?: string;
|
|
15
|
+
args?: Record<string, unknown>;
|
|
16
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Flex, Text, View, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
|
|
3
|
+
const Comment = ({ store, onMount, PARAMS }) => {
|
|
4
|
+
const { isShow = false, isForce = false, text = "" } = useStoreState(store, onMount);
|
|
5
|
+
const isRealForce = useIsForceHook(isForce);
|
|
6
|
+
const propsByView = PARAMS.COMMENT.VIEW_PROPS;
|
|
7
|
+
return (_jsx(View, { ...propsByView.view, isShow: isShow, isForce: isRealForce, children: _jsx(Flex, { ...propsByView.flex, children: _jsx(Text, { ...propsByView.text, text: text }) }) }));
|
|
8
|
+
};
|
|
9
|
+
export const render = createRenderFunc(Comment);
|
package/package.json
CHANGED
|
@@ -1,6 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.controllers.common.comment",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.12",
|
|
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.common.comment": "~0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.2.0",
|
|
37
|
+
"@vnejs/module.core": "~0.2.0",
|
|
38
|
+
"@vnejs/module.components": "~0.2.0",
|
|
39
|
+
"@vnejs/module.controller.hide.on.state": "~0.2.0",
|
|
40
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
41
|
+
"@vnejs/registry": "~0.2.0",
|
|
42
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
46
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
47
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
48
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
49
|
+
"@vnejs/contracts.controllers.common.comment": "~0.2.0",
|
|
50
|
+
"@vnejs/helpers": "~0.2.0",
|
|
51
|
+
"@vnejs/module.core": "~0.2.0",
|
|
52
|
+
"@vnejs/module.components": "~0.2.0",
|
|
53
|
+
"@vnejs/module.controller.hide.on.state": "~0.2.0",
|
|
54
|
+
"@vnejs/registry": "~0.2.0",
|
|
55
|
+
"@vnejs/uis.react": "~0.2.0"
|
|
56
|
+
}
|
|
57
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import "@vnejs/contracts.controllers.common.comment";
|
|
2
|
+
|
|
3
|
+
import { regPlugin } from "@vnejs/registry";
|
|
4
|
+
|
|
5
|
+
import { PARAMS, PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.controllers.common.comment";
|
|
6
|
+
|
|
7
|
+
import { CommentModule } from "./modules/comment.js";
|
|
8
|
+
import { CommentController } from "./modules/controller.js";
|
|
9
|
+
import { CommentHide } from "./modules/hide.js";
|
|
10
|
+
import { CommentView } from "./modules/view.js";
|
|
11
|
+
|
|
12
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS }, [CommentModule, CommentController, CommentHide, CommentView]);
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
|
|
3
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
4
|
+
|
|
5
|
+
import { tokenizeExecLine } from "@vnejs/helpers";
|
|
6
|
+
|
|
7
|
+
import type { CommentShowPayload } from "@vnejs/contracts.controllers.common.comment";
|
|
8
|
+
|
|
9
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
10
|
+
|
|
11
|
+
export class CommentModule extends ModuleCore<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams> {
|
|
12
|
+
name = "comment";
|
|
13
|
+
|
|
14
|
+
state: { text?: string } = {};
|
|
15
|
+
|
|
16
|
+
timeout: ReturnType<typeof setTimeout> | null = null;
|
|
17
|
+
|
|
18
|
+
subscribe = () => {
|
|
19
|
+
const { HIDE } = this.CONST.COMPONENTS.LIFECYCLE_PRIORITY;
|
|
20
|
+
|
|
21
|
+
this.on(this.EVENTS.COMMENT.HIDE, this.onHide, { priority: HIDE.MAIN });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
25
|
+
|
|
26
|
+
onLineExec = async ({ line = "", args = {} }: LineExecHandlerArg = {}) => {
|
|
27
|
+
const [text = "", durationToken = "0"] = tokenizeExecLine(line).map(String);
|
|
28
|
+
const duration = Number(durationToken);
|
|
29
|
+
|
|
30
|
+
if (text === "hide") this.emit(this.EVENTS.COMMENT.HIDE);
|
|
31
|
+
else {
|
|
32
|
+
const { label } = this.globalState.scenario;
|
|
33
|
+
|
|
34
|
+
if (duration) this.timeout = setTimeout(() => this.state.text === text && this.emit(this.EVENTS.COMMENT.HIDE), duration);
|
|
35
|
+
|
|
36
|
+
this.state.text = text;
|
|
37
|
+
|
|
38
|
+
this.emit(this.EVENTS.COMMENT.SHOW, { label, text, args } satisfies CommentShowPayload);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.emit(this.EVENTS.SCENARIO.NEXT);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
onHide = () => {
|
|
45
|
+
if (this.timeout) clearTimeout(this.timeout);
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ModuleController } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { CommentReplacePayload, CommentShowPayload } from "@vnejs/contracts.controllers.common.comment";
|
|
4
|
+
|
|
5
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
6
|
+
import type { CommentPluginState } from "../types.js";
|
|
7
|
+
|
|
8
|
+
export class CommentController extends ModuleController<
|
|
9
|
+
CommentPluginEvents,
|
|
10
|
+
CommentPluginConstants,
|
|
11
|
+
CommentPluginSettings,
|
|
12
|
+
CommentPluginParams,
|
|
13
|
+
CommentPluginState
|
|
14
|
+
> {
|
|
15
|
+
name = "comment.controller";
|
|
16
|
+
|
|
17
|
+
EVENT_UPDATE_VIEW = this.EVENTS.COMMENT.UPDATE;
|
|
18
|
+
EVENT_UPDATE_STATE = this.EVENTS.COMMENT.UPDATE_STATE;
|
|
19
|
+
EVENT_UPDATE_FAST = this.EVENTS.COMMENT.UPDATE_FAST;
|
|
20
|
+
EVENT_UPDATE_FORCE = this.EVENTS.COMMENT.UPDATE_FORCE;
|
|
21
|
+
EVENT_SHOW = this.EVENTS.COMMENT.SHOW;
|
|
22
|
+
EVENT_HIDE = this.EVENTS.COMMENT.HIDE;
|
|
23
|
+
|
|
24
|
+
getDefaultState = (): CommentPluginState => ({ label: "", text: "", args: {}, isShow: false, isForce: false });
|
|
25
|
+
|
|
26
|
+
onExternalUpdate = async () => this.updateStateAndViewFast({ text: await this.getRealText(this.state.label, this.state.text, this.state.args) });
|
|
27
|
+
onShowBefore = async ({ label, text, args }: CommentShowPayload = {}) => {
|
|
28
|
+
return this.updateState({ text: await this.getRealText(label, text, args) });
|
|
29
|
+
};
|
|
30
|
+
getRealText = async (label?: string, text?: string, args?: Record<string, unknown>) =>
|
|
31
|
+
(await this.emitOne(this.EVENTS.TEXT.REPLACE, { label, text, args, state: this.globalState } satisfies CommentReplacePayload)) ?? "";
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleControllerHideOnState } from "@vnejs/module.controller.hide.on.state";
|
|
2
|
+
|
|
3
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
4
|
+
|
|
5
|
+
export class CommentHide extends ModuleControllerHideOnState<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams> {
|
|
6
|
+
name = "comment.hide";
|
|
7
|
+
|
|
8
|
+
EVENT_HIDE = this.EVENTS.COMMENT.HIDE;
|
|
9
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ModuleView } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
4
|
+
import type { CommentPluginState } from "../types.js";
|
|
5
|
+
|
|
6
|
+
import { render } from "../view/index.js";
|
|
7
|
+
export class CommentView extends ModuleView<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams, CommentPluginState> {
|
|
8
|
+
name = "comment.view";
|
|
9
|
+
|
|
10
|
+
EVENT_UPDATE_VIEW = this.EVENTS.COMMENT.UPDATE;
|
|
11
|
+
|
|
12
|
+
TRANSITION = this.PARAMS.COMMENT.TRANSITION;
|
|
13
|
+
|
|
14
|
+
renderFunc = render;
|
|
15
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { CommentModule } from "../modules/comment.js";
|
|
6
|
+
|
|
7
|
+
import { createCommentTestModule, registerCommentPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("CommentModule", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerCommentPluginVne();
|
|
12
|
+
vi.useFakeTimers();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("line exec shows comment with scenario label", async () => {
|
|
16
|
+
const { module, observer } = createCommentTestModule(CommentModule, { subscribe: false });
|
|
17
|
+
const show = spyEvent(observer, SUBSCRIBE_EVENTS.SHOW);
|
|
18
|
+
|
|
19
|
+
await (module as CommentModule).init();
|
|
20
|
+
await (module as CommentModule).onLineExec({ line: '"Hello"', args: { foo: 1 } });
|
|
21
|
+
|
|
22
|
+
expect(show).toHaveBeenCalledOnce();
|
|
23
|
+
expect(show.mock.calls[0][0]).toMatchObject({ label: "start", text: "Hello", args: { foo: 1 } });
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("line exec hide emits HIDE", async () => {
|
|
27
|
+
const { module, observer } = createCommentTestModule(CommentModule, { subscribe: false });
|
|
28
|
+
const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
29
|
+
|
|
30
|
+
await (module as CommentModule).onLineExec({ line: "hide" });
|
|
31
|
+
|
|
32
|
+
expect(hide).toHaveBeenCalledOnce();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("line exec with duration auto-hides after timeout", async () => {
|
|
36
|
+
const { module, observer } = createCommentTestModule(CommentModule, { subscribe: false });
|
|
37
|
+
const hide = spyEvent(observer, SUBSCRIBE_EVENTS.HIDE);
|
|
38
|
+
|
|
39
|
+
await (module as CommentModule).onLineExec({ line: '"Hello" 1000' });
|
|
40
|
+
|
|
41
|
+
expect(hide).not.toHaveBeenCalled();
|
|
42
|
+
vi.advanceTimersByTime(1000);
|
|
43
|
+
expect(hide).toHaveBeenCalledOnce();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("HIDE clears the auto-hide timer", async () => {
|
|
47
|
+
const { module, observer } = createCommentTestModule(CommentModule);
|
|
48
|
+
const comment = module as CommentModule;
|
|
49
|
+
|
|
50
|
+
await comment.init();
|
|
51
|
+
await comment.onLineExec({ line: '"Hello" 1000' });
|
|
52
|
+
|
|
53
|
+
expect(vi.getTimerCount()).toBe(1);
|
|
54
|
+
|
|
55
|
+
await observer.emit(SUBSCRIBE_EVENTS.HIDE);
|
|
56
|
+
|
|
57
|
+
expect(vi.getTimerCount()).toBe(0);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("line exec emits SCENARIO.NEXT", async () => {
|
|
61
|
+
const { module, observer } = createCommentTestModule(CommentModule, { subscribe: false });
|
|
62
|
+
const next = vi.fn();
|
|
63
|
+
|
|
64
|
+
observer.subscribe("vne:scenario:next", next);
|
|
65
|
+
|
|
66
|
+
await (module as CommentModule).onLineExec({ line: '"Hello"' });
|
|
67
|
+
|
|
68
|
+
expect(next).toHaveBeenCalledOnce();
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { CommentHide } from "../modules/hide.js";
|
|
8
|
+
|
|
9
|
+
import { createCommentTestModule, registerCommentPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
10
|
+
|
|
11
|
+
describe("CommentHide", () => {
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registerCommentPluginVne();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("STATE.SET and STATE.CLEAR emit HIDE with isForce", async () => {
|
|
17
|
+
const { observer } = createCommentTestModule(CommentHide);
|
|
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).toHaveBeenCalledTimes(2);
|
|
24
|
+
expect(hide).toHaveBeenNthCalledWith(1, { isForce: true });
|
|
25
|
+
expect(hide).toHaveBeenNthCalledWith(2, { isForce: true });
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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.common.comment";
|
|
4
|
+
import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
|
|
5
|
+
|
|
6
|
+
export const registerCommentPluginVne = () => {
|
|
7
|
+
registerCoreVne();
|
|
8
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
9
|
+
registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const createCommentTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
13
|
+
ModuleClass: T,
|
|
14
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
15
|
+
) => {
|
|
16
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
17
|
+
state: {
|
|
18
|
+
comment: { label: "", text: "", args: {}, isShow: false, isForce: false },
|
|
19
|
+
scenario: { label: "start", curLine: 0 },
|
|
20
|
+
...(options.state ?? {}),
|
|
21
|
+
},
|
|
22
|
+
...options,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
stubEvent(result.observer, TEXT_EVENTS.REPLACE, ({ text }) => text);
|
|
26
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.SHOW);
|
|
27
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.HIDE);
|
|
28
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.UPDATE);
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export { SUBSCRIBE_EVENTS, PARAMS, PLUGIN_NAME, TEXT_EVENTS };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ModuleComponentsConstants, ModuleComponentsEvents, ModuleComponentsParams, ModuleComponentsSettings } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import type { Params, PluginName, SubscribeEvents } from "@vnejs/contracts.controllers.common.comment";
|
|
4
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/contracts.core.scenario";
|
|
5
|
+
import type { PluginName as StatePluginName, SubscribeEvents as StateSubscribeEvents } from "@vnejs/contracts.core.state";
|
|
6
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
7
|
+
|
|
8
|
+
export type CommentPluginEvents = ModuleComponentsEvents &
|
|
9
|
+
Record<PluginName, SubscribeEvents> &
|
|
10
|
+
Record<ScenarioPluginName, ScenarioSubscribeEvents> &
|
|
11
|
+
Record<StatePluginName, StateSubscribeEvents> &
|
|
12
|
+
Record<TextPluginName, TextSubscribeEvents>;
|
|
13
|
+
|
|
14
|
+
export type CommentPluginConstants = ModuleComponentsConstants;
|
|
15
|
+
|
|
16
|
+
export type CommentPluginSettings = ModuleComponentsSettings;
|
|
17
|
+
|
|
18
|
+
export type CommentPluginParams = ModuleComponentsParams & Record<PluginName, Params>;
|
|
19
|
+
|
|
20
|
+
export type CommentPluginState = {
|
|
21
|
+
isShow: boolean;
|
|
22
|
+
isForce: boolean;
|
|
23
|
+
label?: string;
|
|
24
|
+
text?: string;
|
|
25
|
+
args?: Record<string, unknown>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ViewRenderFunc } from "@vnejs/module.components";
|
|
2
|
+
|
|
3
|
+
import { Flex, Text, View, createRenderFunc, useIsForceHook, useStoreState } from "@vnejs/uis.react";
|
|
4
|
+
|
|
5
|
+
import type { ReactComponentProps } from "@vnejs/uis.react";
|
|
6
|
+
|
|
7
|
+
import type { CommentPluginConstants, CommentPluginEvents, CommentPluginParams, CommentPluginSettings } from "../types.js";
|
|
8
|
+
import type { CommentPluginState } from "../types.js";
|
|
9
|
+
type CommentComponentProps = ReactComponentProps<CommentPluginEvents, CommentPluginConstants, CommentPluginSettings, CommentPluginParams, CommentPluginState>;
|
|
10
|
+
|
|
11
|
+
const Comment = ({ store, onMount, PARAMS }: CommentComponentProps) => {
|
|
12
|
+
const { isShow = false, isForce = false, text = "" } = useStoreState<CommentPluginState>(store, onMount);
|
|
13
|
+
|
|
14
|
+
const isRealForce = useIsForceHook(isForce);
|
|
15
|
+
|
|
16
|
+
const propsByView = PARAMS.COMMENT.VIEW_PROPS;
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<View
|
|
20
|
+
{...propsByView.view}
|
|
21
|
+
isShow={isShow}
|
|
22
|
+
isForce={isRealForce}
|
|
23
|
+
>
|
|
24
|
+
<Flex {...propsByView.flex}>
|
|
25
|
+
<Text
|
|
26
|
+
{...propsByView.text}
|
|
27
|
+
text={text}
|
|
28
|
+
/>
|
|
29
|
+
</Flex>
|
|
30
|
+
</View>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const render: ViewRenderFunc<CommentPluginState> = createRenderFunc(Comment);
|
package/tsconfig.json
ADDED
package/README.md
DELETED