@vnejs/bridge.plugins.text.plugins.scenario.history 0.0.0-stage → 0.2.8

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.
@@ -0,0 +1,2 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import "@vnejs/contracts.text";
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import "@vnejs/contracts.text";
3
+ import { regPlugin } from "@vnejs/registry";
4
+ import { BridgePluginTextPluginHistory } from "./modules/bridge_plugin_text_plugin_history.js";
5
+ const PLUGIN_NAME = "BRIDGE_PLUGIN_TEXT_PLUGIN_HISTORY";
6
+ regPlugin(PLUGIN_NAME, {}, [BridgePluginTextPluginHistory]);
@@ -0,0 +1,7 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "../types.js";
3
+ export declare class BridgePluginTextPluginHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
4
+ name: string;
5
+ subscribe: () => void;
6
+ onTextEmitNext: () => Promise<import("@vnejs/registry").EmitResults<"vne:history:add"> | undefined>;
7
+ }
@@ -0,0 +1,20 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+ import { getTextSpeakerInfo } from "@vnejs/contracts.text";
3
+ export class BridgePluginTextPluginHistory extends ModuleCore {
4
+ name = "bridge_plugin_text_plugin_history";
5
+ subscribe = () => {
6
+ this.on(this.EVENTS.TEXT.EMIT_NEXT, this.onTextEmitNext, { priority: -1000 });
7
+ };
8
+ onTextEmitNext = async () => {
9
+ const texts = this.globalState.text.texts;
10
+ if (!texts.length)
11
+ return;
12
+ const label = this.globalState.scenario.label;
13
+ const text = texts[texts.length - 1].text;
14
+ const args = texts[texts.length - 1].args;
15
+ const speakerState = this.globalState["text.speaker"];
16
+ const speaker = speakerState.speaker;
17
+ const speakerInfo = structuredClone(getTextSpeakerInfo(speakerState, speaker));
18
+ return this.emit(this.EVENTS.HISTORY.ADD, { label, text, args, speaker, speakerInfo });
19
+ };
20
+ }
@@ -0,0 +1,8 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
3
+ import type { Constants as TextConstants, PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
4
+ import type { PluginName as HistoryPluginName, SubscribeEvents as HistorySubscribeEvents } from "@vnejs/contracts.scenario.history";
5
+ export type PluginEvents = ModuleCoreEvents & Record<TextPluginName, TextSubscribeEvents> & Record<HistoryPluginName, HistorySubscribeEvents>;
6
+ export type PluginConstants = ModuleCoreConstants & Record<TextPluginName, TextConstants>;
7
+ export type PluginSettings = ModuleCoreSettings;
8
+ export type PluginParams = ModuleCoreParams;
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ import "@vnejs/contracts.scenario.history";
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@vnejs/bridge.plugins.text.plugins.scenario.history",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.8",
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
+ "peerDependencies": {
33
+ "@vnejs/module.core": "~0.2.0",
34
+ "@vnejs/contracts.text": "~0.2.0",
35
+ "@vnejs/contracts.scenario.history": "~0.2.0",
36
+ "@vnejs/registry": "~0.2.0"
37
+ },
38
+ "devDependencies": {
39
+ "@vnejs/configs.ts-common": "~0.2.0",
40
+ "@vnejs/configs.vitest": "~0.2.0",
41
+ "@vnejs/test-utils": "~0.2.0"
42
+ }
43
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+ import "@vnejs/contracts.text";
3
+
4
+ import { regPlugin } from "@vnejs/registry";
5
+
6
+ import { BridgePluginTextPluginHistory } from "./modules/bridge_plugin_text_plugin_history.js";
7
+
8
+ const PLUGIN_NAME = "BRIDGE_PLUGIN_TEXT_PLUGIN_HISTORY";
9
+
10
+ regPlugin(PLUGIN_NAME, {}, [BridgePluginTextPluginHistory]);
@@ -0,0 +1,28 @@
1
+ import { ModuleCore } from "@vnejs/module.core";
2
+
3
+ import { getTextSpeakerInfo } from "@vnejs/contracts.text";
4
+
5
+ import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "../types.js";
6
+
7
+ export class BridgePluginTextPluginHistory extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
8
+ name = "bridge_plugin_text_plugin_history";
9
+
10
+ subscribe = () => {
11
+ this.on(this.EVENTS.TEXT.EMIT_NEXT, this.onTextEmitNext, { priority: -1000 });
12
+ };
13
+
14
+ onTextEmitNext = async () => {
15
+ const texts = this.globalState.text.texts;
16
+
17
+ if (!texts.length) return;
18
+
19
+ const label = this.globalState.scenario.label;
20
+ const text = texts[texts.length - 1].text;
21
+ const args = texts[texts.length - 1].args;
22
+ const speakerState = this.globalState["text.speaker"];
23
+ const speaker = speakerState.speaker;
24
+ const speakerInfo = structuredClone(getTextSpeakerInfo(speakerState, speaker));
25
+
26
+ return this.emit(this.EVENTS.HISTORY.ADD, { label, text, args, speaker, speakerInfo });
27
+ };
28
+ }
@@ -0,0 +1,52 @@
1
+ import { beforeEach, describe, expect, it } from "vitest";
2
+
3
+ import { spyEvent } from "@vnejs/test-utils";
4
+
5
+ import { BridgePluginTextPluginHistory } from "../modules/bridge_plugin_text_plugin_history.js";
6
+ import { createCompatibilityTestModule, HISTORY_EVENTS, registerCompatibilityVne, TEXT_EVENTS } from "./setup.js";
7
+
8
+ describe("BridgePluginTextPluginHistory", () => {
9
+ beforeEach(() => registerCompatibilityVne());
10
+
11
+ it("subscribe registers TEXT.EMIT_NEXT handler", () => {
12
+ const { module, observer } = createCompatibilityTestModule(BridgePluginTextPluginHistory, { subscribe: false });
13
+
14
+ (module as BridgePluginTextPluginHistory).subscribe();
15
+
16
+ expect(observer.subscribers[TEXT_EVENTS.EMIT_NEXT]?.flatMap((group) => group.subscribers)).toEqual(
17
+ expect.arrayContaining([expect.objectContaining({ func: (module as BridgePluginTextPluginHistory).onTextEmitNext })]),
18
+ );
19
+ });
20
+
21
+ it("handler emits HISTORY.ADD with the loc key, including marks", async () => {
22
+ const { observer } = createCompatibilityTestModule(BridgePluginTextPluginHistory, {
23
+ state: {
24
+ "text": { uid: "u1", texts: [{ text: "{i}Вот чёрт{/i}", args: {} }], tokens: [], speaker: "" },
25
+ "text.speaker": { speaker: "", args: {}, speakersInfo: {} },
26
+ "scenario": { curLine: 1, label: "prologue/1" },
27
+ },
28
+ });
29
+ const add = spyEvent(observer, HISTORY_EVENTS.ADD);
30
+
31
+ await observer.emit(TEXT_EVENTS.EMIT_NEXT);
32
+
33
+ expect(add).toHaveBeenCalledOnce();
34
+ expect(add.mock.calls[0]?.[0]).toMatchObject({ label: "prologue/1", text: "{i}Вот чёрт{/i}" });
35
+ });
36
+
37
+ it("handler emits HISTORY.ADD with the loc key, keeping marks", async () => {
38
+ const { observer } = createCompatibilityTestModule(BridgePluginTextPluginHistory, {
39
+ state: {
40
+ "text": { uid: "u1", texts: [{ text: "Hello {mark}", args: { a: 1 } }], tokens: [], speaker: "hero" },
41
+ "text.speaker": { speaker: "hero", args: {}, speakersInfo: {} },
42
+ "scenario": { curLine: 1, label: "scene" },
43
+ },
44
+ });
45
+ const add = spyEvent(observer, HISTORY_EVENTS.ADD);
46
+
47
+ await observer.emit(TEXT_EVENTS.EMIT_NEXT);
48
+
49
+ expect(add).toHaveBeenCalledOnce();
50
+ expect(add.mock.calls[0]?.[0]).toMatchObject({ label: "scene", text: "Hello {mark}", speaker: "hero", args: { a: 1 } });
51
+ });
52
+ });
@@ -0,0 +1,25 @@
1
+ import { PARAMS as TEXT_PARAMS, PLUGIN_NAME as TEXT, SETTINGS_KEYS as TEXT_SETTINGS, SUBSCRIBE_EVENTS as TEXT_EVENTS } from "@vnejs/contracts.text";
2
+ import { SUBSCRIBE_EVENTS as HISTORY_EVENTS, PLUGIN_NAME as HISTORY } from "@vnejs/contracts.scenario.history";
3
+ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
4
+
5
+ export const registerCompatibilityVne = () => {
6
+ registerCoreVne();
7
+ registerVnePlugin(TEXT, { events: TEXT_EVENTS, params: TEXT_PARAMS, settings: TEXT_SETTINGS });
8
+ registerVnePlugin(HISTORY, { events: HISTORY_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
+ state: {
17
+ "text": { uid: "", texts: [], tokens: [], speaker: "" },
18
+ "text.speaker": { speakers: {} },
19
+ "scenario": { curLine: 0, label: "start" },
20
+ ...(options.state ?? {}),
21
+ },
22
+ ...options,
23
+ });
24
+
25
+ export { HISTORY_EVENTS, TEXT_EVENTS };
package/src/types.ts ADDED
@@ -0,0 +1,13 @@
1
+ import "@vnejs/contracts.scenario.history";
2
+
3
+ import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
4
+ import type { Constants as TextConstants, PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
5
+ import type { PluginName as HistoryPluginName, SubscribeEvents as HistorySubscribeEvents } from "@vnejs/contracts.scenario.history";
6
+
7
+ export type PluginEvents = ModuleCoreEvents & Record<TextPluginName, TextSubscribeEvents> & Record<HistoryPluginName, HistorySubscribeEvents>;
8
+
9
+ export type PluginConstants = ModuleCoreConstants & Record<TextPluginName, TextConstants>;
10
+
11
+ export type PluginSettings = ModuleCoreSettings;
12
+
13
+ export type PluginParams = ModuleCoreParams;
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@vnejs/configs.ts-common/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "node_modules", "src/tests"]
9
+ }
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.