@vnejs/plugins.text.wall 0.1.2 → 0.1.4
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/modules/wall.d.ts +1 -1
- package/dist/modules/wall.js +5 -2
- package/package.json +6 -3
- package/src/modules/wall.ts +5 -2
- package/src/tests/setup.ts +29 -0
- package/src/tests/wall.test.ts +36 -0
- package/tsconfig.json +1 -1
package/dist/modules/wall.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare class TextWall extends ModuleCore<TextWallPluginEvents, TextWallP
|
|
|
20
20
|
texts: import("@vnejs/contracts.text").TextItem[];
|
|
21
21
|
uid: string;
|
|
22
22
|
speaker: string;
|
|
23
|
-
|
|
23
|
+
speakerInfo: import("@vnejs/contracts.text").TextSpeakerEntry;
|
|
24
24
|
}>;
|
|
25
25
|
getDefaultState: () => ModuleGlobalStateTextWall;
|
|
26
26
|
}
|
package/dist/modules/wall.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ModuleCore } from "@vnejs/module.core";
|
|
2
2
|
import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
|
|
3
|
+
import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
3
4
|
export class TextWall extends ModuleCore {
|
|
4
5
|
name = "text.wall";
|
|
5
6
|
subscribe = () => {
|
|
@@ -29,9 +30,11 @@ export class TextWall extends ModuleCore {
|
|
|
29
30
|
if (this.state.shouldSkip)
|
|
30
31
|
return this.updateState({ shouldSkip: false });
|
|
31
32
|
const { texts, tokens, uid } = this.globalState.text;
|
|
32
|
-
const
|
|
33
|
+
const speakerState = this.globalState["text.speaker"];
|
|
34
|
+
const { speaker } = speakerState;
|
|
35
|
+
const speakerInfo = await this.emitClone(getTextSpeakerInfo(speakerState, speaker));
|
|
33
36
|
const wall = await this.emitClone(this.state.wall);
|
|
34
|
-
const wallElement = await this.emitClone({ texts, tokens, uid, speaker,
|
|
37
|
+
const wallElement = await this.emitClone({ texts, tokens, uid, speaker, speakerInfo });
|
|
35
38
|
this.updateState({ wall: [...wall, wallElement] });
|
|
36
39
|
await this.emitWallChanged();
|
|
37
40
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.text.wall",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"tsconfig.json"
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "npx @vnejs/monorepo test",
|
|
22
22
|
"build": "npx @vnejs/monorepo package",
|
|
23
23
|
"publish:major:plugin": "npm run publish:major",
|
|
24
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
@@ -39,6 +39,9 @@
|
|
|
39
39
|
"@vnejs/shared": "~0.1.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@vnejs/configs.ts-common": "~0.1.0"
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.1.0",
|
|
43
|
+
"@vnejs/configs.vitest": "~0.1.0",
|
|
44
|
+
"@vnejs/test-utils": "~0.1.0",
|
|
45
|
+
"@vnejs/contracts.text": "~0.1.0"
|
|
43
46
|
}
|
|
44
47
|
}
|
package/src/modules/wall.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { ModuleGlobalStateRegistry } from "@vnejs/module.core";
|
|
|
3
3
|
import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
|
|
4
4
|
|
|
5
5
|
import type { TextEmitBeforePayload, TokenizedChar } from "@vnejs/contracts.text";
|
|
6
|
+
import { getTextSpeakerInfo } from "@vnejs/contracts.text";
|
|
6
7
|
import type { ModuleGlobalStateTextWall, WallElement } from "@vnejs/contracts.text.wall";
|
|
7
8
|
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
8
9
|
|
|
@@ -49,10 +50,12 @@ export class TextWall extends ModuleCore<
|
|
|
49
50
|
if (this.state.shouldSkip) return this.updateState({ shouldSkip: false });
|
|
50
51
|
|
|
51
52
|
const { texts, tokens, uid } = this.globalState.text;
|
|
52
|
-
const
|
|
53
|
+
const speakerState = this.globalState["text.speaker"];
|
|
54
|
+
const { speaker } = speakerState;
|
|
55
|
+
const speakerInfo = await this.emitClone(getTextSpeakerInfo(speakerState, speaker));
|
|
53
56
|
|
|
54
57
|
const wall = await this.emitClone<WallElement[]>(this.state.wall);
|
|
55
|
-
const wallElement = await this.emitClone<WallElement>({ texts, tokens, uid, speaker,
|
|
58
|
+
const wallElement = await this.emitClone<WallElement>({ texts, tokens, uid, speaker, speakerInfo });
|
|
56
59
|
|
|
57
60
|
this.updateState({ wall: [...wall, wallElement] });
|
|
58
61
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { CONSTANTS as TEXT_CONST, PLUGIN_NAME as TEXT, SUBSCRIBE_EVENTS as TEXT_EVENTS } from "@vnejs/contracts.text";
|
|
2
|
+
import { PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.text.wall";
|
|
3
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin, stubSilentEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
export const registerTextWallPluginVne = () => {
|
|
6
|
+
registerCoreVne();
|
|
7
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
8
|
+
registerVnePlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const createTextWallTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
12
|
+
ModuleClass: T,
|
|
13
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
14
|
+
) => {
|
|
15
|
+
const result = baseCreateTestModule(ModuleClass, {
|
|
16
|
+
state: {
|
|
17
|
+
text: { uid: "1", texts: [{ text: "line", args: {} }], tokens: [], speaker: "hero" },
|
|
18
|
+
"text.speaker": { speakers: { hero: {} }, speaker: "hero" },
|
|
19
|
+
...(options.state ?? {}),
|
|
20
|
+
},
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
stubSilentEvent(result.observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
25
|
+
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { SUBSCRIBE_EVENTS, PLUGIN_NAME };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { SUBSCRIBE_EVENTS as SCENARIO_EVENTS } from "@vnejs/contracts.core.scenario";
|
|
4
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
5
|
+
|
|
6
|
+
import { TextWall } from "../modules/wall.js";
|
|
7
|
+
import { createTextWallTestModule, registerTextWallPluginVne, SUBSCRIBE_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("TextWall", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerTextWallPluginVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("start command enables wall capture", async () => {
|
|
15
|
+
const { module, observer } = createTextWallTestModule(TextWall, { subscribe: false });
|
|
16
|
+
const changed = spyEvent(observer, SUBSCRIBE_EVENTS.CHANGED);
|
|
17
|
+
const next = spyEvent(observer, SCENARIO_EVENTS.NEXT);
|
|
18
|
+
|
|
19
|
+
await (module as TextWall).onLineExec({ line: "start" });
|
|
20
|
+
|
|
21
|
+
expect((module as TextWall).state.isStarted).toBe(true);
|
|
22
|
+
expect(changed).toHaveBeenCalledOnce();
|
|
23
|
+
expect(next).toHaveBeenCalledOnce();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("clear command resets wall", async () => {
|
|
27
|
+
const { module, observer } = createTextWallTestModule(TextWall, { subscribe: false });
|
|
28
|
+
|
|
29
|
+
(module as TextWall).setState({ wall: [{ texts: [], tokens: [], uid: "1", speaker: "hero", speakerInfo: {} }], isStarted: true, shouldSkip: false });
|
|
30
|
+
|
|
31
|
+
await (module as TextWall).onLineExec({ line: "clear" });
|
|
32
|
+
|
|
33
|
+
expect((module as TextWall).state.wall).toEqual([]);
|
|
34
|
+
expect((module as TextWall).state.shouldSkip).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
package/tsconfig.json
CHANGED