@vnejs/compatibility.views.scenario.interface-with-text 0.2.1
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 +13 -0
- package/dist/index.js +22 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/package.json +40 -0
- package/src/index.ts +33 -0
- package/src/tests/setup.ts +23 -0
- package/src/tests/text.test.ts +70 -0
- package/src/types.ts +11 -0
- package/tsconfig.json +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import "@vnejs/contracts.text";
|
|
2
|
+
import "@vnejs/contracts.views.scenario.interface";
|
|
3
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
4
|
+
import type { ModuleGlobalStateText, TextSpeakerChangedPayload } from "@vnejs/contracts.text";
|
|
5
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
6
|
+
export declare class CompatibilityViewsScenarioInterfaceWithText extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
7
|
+
name: string;
|
|
8
|
+
subscribe: () => void;
|
|
9
|
+
init: () => Promise<unknown[]> | undefined;
|
|
10
|
+
onTextChanged: ({ tokens, uid }?: Partial<Pick<ModuleGlobalStateText, "tokens" | "uid">>) => Promise<unknown[]> | undefined;
|
|
11
|
+
onTextSpeakerChanged: ({ speaker }?: TextSpeakerChangedPayload) => Promise<unknown[]> | undefined;
|
|
12
|
+
onTextEmitBefore: () => Promise<unknown[]> | undefined;
|
|
13
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import "@vnejs/contracts.text";
|
|
2
|
+
import "@vnejs/contracts.views.scenario.interface";
|
|
3
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
4
|
+
import { regModule } from "@vnejs/shared";
|
|
5
|
+
export class CompatibilityViewsScenarioInterfaceWithText extends ModuleCore {
|
|
6
|
+
name = "compatibility.views.scenario.interface-with-text";
|
|
7
|
+
subscribe = () => {
|
|
8
|
+
this.on(this.EVENTS.TEXT.CHANGED, this.onTextChanged);
|
|
9
|
+
this.on(this.EVENTS.TEXT.SPEAKER_CHANGED, this.onTextSpeakerChanged);
|
|
10
|
+
};
|
|
11
|
+
init = () => {
|
|
12
|
+
this.shared.interfaceTextShowAllTokensOnChange = true;
|
|
13
|
+
return this.emit(this.EVENTS.TEXT.EMIT_BEFORE_REG, { handler: this.onTextEmitBefore });
|
|
14
|
+
};
|
|
15
|
+
onTextChanged = ({ tokens = [], uid = "" } = {}) => {
|
|
16
|
+
const tokensVisible = this.shared.interfaceTextShowAllTokensOnChange ? tokens.length : 0;
|
|
17
|
+
return this.emit(this.EVENTS.INTERFACE.TEXT_CHANGED, { tokens, uid, tokensVisible });
|
|
18
|
+
};
|
|
19
|
+
onTextSpeakerChanged = ({ speaker } = {}) => this.emit(this.EVENTS.INTERFACE.SPEAKER_CHANGED, { speaker });
|
|
20
|
+
onTextEmitBefore = () => this.emit(this.EVENTS.INTERFACE.SHOW);
|
|
21
|
+
}
|
|
22
|
+
regModule(CompatibilityViewsScenarioInterfaceWithText);
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { PluginName as InterfacePluginName, SubscribeEvents as InterfaceSubscribeEvents } from "@vnejs/contracts.views.scenario.interface";
|
|
3
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
4
|
+
export type PluginEvents = ModuleCoreEvents & Record<TextPluginName, TextSubscribeEvents> & Record<InterfacePluginName, InterfaceSubscribeEvents>;
|
|
5
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
6
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
7
|
+
export type PluginParams = ModuleCoreParams;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/compatibility.views.scenario.interface-with-text",
|
|
3
|
+
"version": "0.2.1",
|
|
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": "npx @vnejs/monorepo publish major --access public",
|
|
24
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
25
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
26
|
+
},
|
|
27
|
+
"author": "",
|
|
28
|
+
"license": "ISC",
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@vnejs/module.core": "~0.2.0",
|
|
31
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
32
|
+
"@vnejs/contracts.views.scenario.interface": "~0.2.0",
|
|
33
|
+
"@vnejs/shared": "~0.2.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
37
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
38
|
+
"@vnejs/test-utils": "~0.2.0"
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import "@vnejs/contracts.text";
|
|
2
|
+
import "@vnejs/contracts.views.scenario.interface";
|
|
3
|
+
|
|
4
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
5
|
+
import type { ModuleGlobalStateText, TextSpeakerChangedPayload } from "@vnejs/contracts.text";
|
|
6
|
+
import { regModule } from "@vnejs/shared";
|
|
7
|
+
|
|
8
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
|
|
9
|
+
|
|
10
|
+
export class CompatibilityViewsScenarioInterfaceWithText extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
11
|
+
name = "compatibility.views.scenario.interface-with-text";
|
|
12
|
+
|
|
13
|
+
subscribe = () => {
|
|
14
|
+
this.on(this.EVENTS.TEXT.CHANGED, this.onTextChanged);
|
|
15
|
+
this.on(this.EVENTS.TEXT.SPEAKER_CHANGED, this.onTextSpeakerChanged);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
init = () => {
|
|
19
|
+
this.shared.interfaceTextShowAllTokensOnChange = true;
|
|
20
|
+
|
|
21
|
+
return this.emit(this.EVENTS.TEXT.EMIT_BEFORE_REG, { handler: this.onTextEmitBefore });
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
onTextChanged = ({ tokens = [], uid = "" }: Partial<Pick<ModuleGlobalStateText, "tokens" | "uid">> = {}) => {
|
|
25
|
+
const tokensVisible = this.shared.interfaceTextShowAllTokensOnChange ? tokens.length : 0;
|
|
26
|
+
|
|
27
|
+
return this.emit(this.EVENTS.INTERFACE.TEXT_CHANGED, { tokens, uid, tokensVisible });
|
|
28
|
+
};
|
|
29
|
+
onTextSpeakerChanged = ({ speaker }: TextSpeakerChangedPayload = {}) => this.emit(this.EVENTS.INTERFACE.SPEAKER_CHANGED, { speaker });
|
|
30
|
+
onTextEmitBefore = () => this.emit(this.EVENTS.INTERFACE.SHOW);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
regModule(CompatibilityViewsScenarioInterfaceWithText);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SUBSCRIBE_EVENTS as TEXT_EVENTS, PLUGIN_NAME as TEXT } from "@vnejs/contracts.text";
|
|
2
|
+
import { SUBSCRIBE_EVENTS as INTERFACE_EVENTS, PLUGIN_NAME as INTERFACE } from "@vnejs/contracts.views.scenario.interface";
|
|
3
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
export const registerCompatibilityVne = () => {
|
|
6
|
+
registerCoreVne();
|
|
7
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
8
|
+
registerVnePlugin(INTERFACE, { events: INTERFACE_EVENTS });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
12
|
+
ModuleClass: T,
|
|
13
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
14
|
+
) =>
|
|
15
|
+
baseCreateTestModule(ModuleClass, {
|
|
16
|
+
shared: {
|
|
17
|
+
interfaceTextShowAllTokensOnChange: true,
|
|
18
|
+
...(options.shared ?? {}),
|
|
19
|
+
},
|
|
20
|
+
...options,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export { INTERFACE_EVENTS, TEXT_EVENTS };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import { spyEvent } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
import { CompatibilityViewsScenarioInterfaceWithText } from "../index.js";
|
|
6
|
+
import { createCompatibilityTestModule, INTERFACE_EVENTS, registerCompatibilityVne, TEXT_EVENTS } from "./setup.js";
|
|
7
|
+
|
|
8
|
+
describe("CompatibilityViewsScenarioInterfaceWithText", () => {
|
|
9
|
+
beforeEach(() => registerCompatibilityVne());
|
|
10
|
+
|
|
11
|
+
it("init sets interfaceTextShowAllTokensOnChange and registers TEXT.EMIT_BEFORE", async () => {
|
|
12
|
+
const { module, observer, shared } = createCompatibilityTestModule(CompatibilityViewsScenarioInterfaceWithText, {
|
|
13
|
+
subscribe: false,
|
|
14
|
+
shared: { interfaceTextShowAllTokensOnChange: false },
|
|
15
|
+
});
|
|
16
|
+
const emitBeforeReg = spyEvent(observer, TEXT_EVENTS.EMIT_BEFORE_REG);
|
|
17
|
+
|
|
18
|
+
await (module as CompatibilityViewsScenarioInterfaceWithText).init();
|
|
19
|
+
|
|
20
|
+
expect(shared.interfaceTextShowAllTokensOnChange).toBe(true);
|
|
21
|
+
expect(emitBeforeReg).toHaveBeenCalledOnce();
|
|
22
|
+
expect(emitBeforeReg).toHaveBeenCalledWith({ handler: (module as CompatibilityViewsScenarioInterfaceWithText).onTextEmitBefore });
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("onTextEmitBefore shows interface", async () => {
|
|
26
|
+
const { module, observer } = createCompatibilityTestModule(CompatibilityViewsScenarioInterfaceWithText);
|
|
27
|
+
const show = spyEvent(observer, INTERFACE_EVENTS.SHOW);
|
|
28
|
+
|
|
29
|
+
await (module as CompatibilityViewsScenarioInterfaceWithText).onTextEmitBefore();
|
|
30
|
+
|
|
31
|
+
expect(show).toHaveBeenCalledOnce();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("TEXT.CHANGED with flag true forwards all tokens as visible", async () => {
|
|
35
|
+
const { observer } = createCompatibilityTestModule(CompatibilityViewsScenarioInterfaceWithText);
|
|
36
|
+
const changed = spyEvent(observer, INTERFACE_EVENTS.TEXT_CHANGED);
|
|
37
|
+
const tokens = [
|
|
38
|
+
{ token: "H", marks: [] },
|
|
39
|
+
{ token: "i", marks: [] },
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
await observer.emit(TEXT_EVENTS.CHANGED, { tokens, uid: "line-1" });
|
|
43
|
+
|
|
44
|
+
expect(changed).toHaveBeenCalledOnce();
|
|
45
|
+
expect(changed).toHaveBeenCalledWith({ tokens, uid: "line-1", tokensVisible: 2 });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("TEXT.CHANGED with flag false forwards tokensVisible 0", async () => {
|
|
49
|
+
const { observer } = createCompatibilityTestModule(CompatibilityViewsScenarioInterfaceWithText, {
|
|
50
|
+
shared: { interfaceTextShowAllTokensOnChange: false },
|
|
51
|
+
});
|
|
52
|
+
const changed = spyEvent(observer, INTERFACE_EVENTS.TEXT_CHANGED);
|
|
53
|
+
const tokens = [{ token: "H", marks: [] }];
|
|
54
|
+
|
|
55
|
+
await observer.emit(TEXT_EVENTS.CHANGED, { tokens, uid: "line-2" });
|
|
56
|
+
|
|
57
|
+
expect(changed).toHaveBeenCalledOnce();
|
|
58
|
+
expect(changed).toHaveBeenCalledWith({ tokens, uid: "line-2", tokensVisible: 0 });
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("TEXT.SPEAKER_CHANGED forwards speaker to INTERFACE.SPEAKER_CHANGED", async () => {
|
|
62
|
+
const { observer } = createCompatibilityTestModule(CompatibilityViewsScenarioInterfaceWithText);
|
|
63
|
+
const speakerChanged = spyEvent(observer, INTERFACE_EVENTS.SPEAKER_CHANGED);
|
|
64
|
+
|
|
65
|
+
await observer.emit(TEXT_EVENTS.SPEAKER_CHANGED, { speaker: "hero" });
|
|
66
|
+
|
|
67
|
+
expect(speakerChanged).toHaveBeenCalledOnce();
|
|
68
|
+
expect(speakerChanged).toHaveBeenCalledWith({ speaker: "hero" });
|
|
69
|
+
});
|
|
70
|
+
});
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
2
|
+
import type { PluginName as InterfacePluginName, SubscribeEvents as InterfaceSubscribeEvents } from "@vnejs/contracts.views.scenario.interface";
|
|
3
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
4
|
+
|
|
5
|
+
export type PluginEvents = ModuleCoreEvents & Record<TextPluginName, TextSubscribeEvents> & Record<InterfacePluginName, InterfaceSubscribeEvents>;
|
|
6
|
+
|
|
7
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
8
|
+
|
|
9
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
10
|
+
|
|
11
|
+
export type PluginParams = ModuleCoreParams;
|