@vnejs/bridge.plugins.scenario.choose.plugins.text 0.0.0-stage → 0.2.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/index.d.ts +2 -0
- package/dist/index.js +6 -0
- package/dist/modules/bridge_plugin_choose_plugin_text.d.ts +8 -0
- package/dist/modules/bridge_plugin_choose_plugin_text.js +9 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/package.json +47 -4
- package/src/index.ts +9 -0
- package/src/modules/bridge_plugin_choose_plugin_text.ts +16 -0
- package/src/tests/setup.ts +16 -0
- package/src/tests/text.test.ts +46 -0
- package/src/types.ts +11 -0
- package/tsconfig.json +9 -0
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import "@vnejs/contracts.text";
|
|
3
|
+
import { PLUGIN_NAME } from "@vnejs/contracts.bridge.plugins.scenario.choose.plugins.text";
|
|
4
|
+
import { regPlugin } from "@vnejs/registry";
|
|
5
|
+
import { BridgePluginChoosePluginText } from "./modules/bridge_plugin_choose_plugin_text.js";
|
|
6
|
+
regPlugin(PLUGIN_NAME, {}, [BridgePluginChoosePluginText]);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ChooseOptionTextHandler } from "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
3
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "../types.js";
|
|
4
|
+
export declare class BridgePluginChoosePluginText extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
5
|
+
name: string;
|
|
6
|
+
init: () => Promise<import("@vnejs/registry").EmitResults<"vne:choose:option_text_reg">> | undefined;
|
|
7
|
+
onOptionText: ChooseOptionTextHandler;
|
|
8
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
export class BridgePluginChoosePluginText extends ModuleCore {
|
|
3
|
+
name = "bridge_plugin_choose_plugin_text";
|
|
4
|
+
init = () => this.emit(this.EVENTS.CHOOSE.OPTION_TEXT_REG, { handler: this.onOptionText });
|
|
5
|
+
onOptionText = async (payload = {}) => {
|
|
6
|
+
const replaced = await this.emitOne(this.EVENTS.TEXT.REPLACE, payload);
|
|
7
|
+
return typeof replaced === "string" ? replaced : (payload.text ?? "");
|
|
8
|
+
};
|
|
9
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { PluginName as ChoosePluginName, SubscribeEvents as ChooseSubscribeEvents } from "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
3
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
4
|
+
export type PluginEvents = ModuleCoreEvents & Record<ChoosePluginName, ChooseSubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
|
|
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
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/bridge.plugins.scenario.choose.plugins.text",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.4",
|
|
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.scenario.choose": "~0.2.0",
|
|
35
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
36
|
+
"@vnejs/registry": "~0.2.0",
|
|
37
|
+
"@vnejs/contracts.bridge.plugins.scenario.choose.plugins.text": "~0.2.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@vnejs/configs.ts-common": "~0.2.0",
|
|
41
|
+
"@vnejs/configs.vitest": "~0.2.0",
|
|
42
|
+
"@vnejs/test-utils": "~0.2.0",
|
|
43
|
+
"@vnejs/contracts.scenario.choose": "~0.2.0",
|
|
44
|
+
"@vnejs/contracts.text": "~0.2.0",
|
|
45
|
+
"@vnejs/module.core": "~0.2.0",
|
|
46
|
+
"@vnejs/registry": "~0.2.0",
|
|
47
|
+
"@vnejs/contracts.bridge.plugins.scenario.choose.plugins.text": "~0.2.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import "@vnejs/contracts.text";
|
|
3
|
+
|
|
4
|
+
import { PLUGIN_NAME } from "@vnejs/contracts.bridge.plugins.scenario.choose.plugins.text";
|
|
5
|
+
import { regPlugin } from "@vnejs/registry";
|
|
6
|
+
|
|
7
|
+
import { BridgePluginChoosePluginText } from "./modules/bridge_plugin_choose_plugin_text.js";
|
|
8
|
+
|
|
9
|
+
regPlugin(PLUGIN_NAME, {}, [BridgePluginChoosePluginText]);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ChooseOptionTextHandler } from "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
3
|
+
|
|
4
|
+
import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "../types.js";
|
|
5
|
+
|
|
6
|
+
export class BridgePluginChoosePluginText extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
|
|
7
|
+
name = "bridge_plugin_choose_plugin_text";
|
|
8
|
+
|
|
9
|
+
init = () => this.emit(this.EVENTS.CHOOSE.OPTION_TEXT_REG, { handler: this.onOptionText });
|
|
10
|
+
|
|
11
|
+
onOptionText: ChooseOptionTextHandler = async (payload = {}) => {
|
|
12
|
+
const replaced = await this.emitOne(this.EVENTS.TEXT.REPLACE, payload);
|
|
13
|
+
|
|
14
|
+
return typeof replaced === "string" ? replaced : (payload.text ?? "");
|
|
15
|
+
};
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { PARAMS as CHOOSE_PARAMS, PLUGIN_NAME as CHOOSE, SUBSCRIBE_EVENTS as CHOOSE_EVENTS } from "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import { PLUGIN_NAME as TEXT, SUBSCRIBE_EVENTS as TEXT_EVENTS } from "@vnejs/contracts.text";
|
|
3
|
+
import { createTestModule as baseCreateTestModule, registerCoreVne, registerVnePlugin } from "@vnejs/test-utils";
|
|
4
|
+
|
|
5
|
+
export const registerCompatibilityVne = () => {
|
|
6
|
+
registerCoreVne();
|
|
7
|
+
registerVnePlugin(CHOOSE, { events: CHOOSE_EVENTS, params: CHOOSE_PARAMS });
|
|
8
|
+
registerVnePlugin(TEXT, { events: TEXT_EVENTS });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const createCompatibilityTestModule = <T extends Parameters<typeof baseCreateTestModule>[0]>(
|
|
12
|
+
ModuleClass: T,
|
|
13
|
+
options: Parameters<typeof baseCreateTestModule>[1] = {},
|
|
14
|
+
) => baseCreateTestModule(ModuleClass, options);
|
|
15
|
+
|
|
16
|
+
export { CHOOSE_EVENTS, TEXT_EVENTS };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import type { ChooseOptionTextHandler } from "@vnejs/contracts.scenario.choose";
|
|
4
|
+
import { spyEvent, stubEvent } from "@vnejs/test-utils";
|
|
5
|
+
|
|
6
|
+
import { BridgePluginChoosePluginText } from "../modules/bridge_plugin_choose_plugin_text.js";
|
|
7
|
+
import { CHOOSE_EVENTS, createCompatibilityTestModule, registerCompatibilityVne, TEXT_EVENTS } from "./setup.js";
|
|
8
|
+
|
|
9
|
+
describe("BridgePluginChoosePluginText", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
registerCompatibilityVne();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("init registers OPTION_TEXT handler", async () => {
|
|
15
|
+
const { module, observer } = createCompatibilityTestModule(BridgePluginChoosePluginText, { subscribe: false });
|
|
16
|
+
const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_TEXT_REG);
|
|
17
|
+
|
|
18
|
+
await (module as BridgePluginChoosePluginText).init();
|
|
19
|
+
|
|
20
|
+
expect(replaceReg).toHaveBeenCalledOnce();
|
|
21
|
+
expect(replaceReg.mock.calls[0]?.[0]?.handler).toBeTypeOf("function");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("handler returns TEXT.REPLACE result", async () => {
|
|
25
|
+
const { module, observer } = createCompatibilityTestModule(BridgePluginChoosePluginText, { subscribe: false });
|
|
26
|
+
const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_TEXT_REG);
|
|
27
|
+
|
|
28
|
+
stubEvent(observer, TEXT_EVENTS.REPLACE, ({ text = "" }) => `loc:${text}`);
|
|
29
|
+
await (module as BridgePluginChoosePluginText).init();
|
|
30
|
+
|
|
31
|
+
const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionTextHandler;
|
|
32
|
+
|
|
33
|
+
expect(await handler({ text: "Hello", label: "start" })).toBe("loc:Hello");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("handler keeps the original text when TEXT.REPLACE has no subscriber", async () => {
|
|
37
|
+
const { module, observer } = createCompatibilityTestModule(BridgePluginChoosePluginText, { subscribe: false });
|
|
38
|
+
const replaceReg = spyEvent(observer, CHOOSE_EVENTS.OPTION_TEXT_REG);
|
|
39
|
+
|
|
40
|
+
await (module as BridgePluginChoosePluginText).init();
|
|
41
|
+
|
|
42
|
+
const handler = replaceReg.mock.calls[0]?.[0]?.handler as ChooseOptionTextHandler;
|
|
43
|
+
|
|
44
|
+
expect(await handler({ text: "Hello" })).toBe("Hello");
|
|
45
|
+
});
|
|
46
|
+
});
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PluginName as ChoosePluginName, SubscribeEvents as ChooseSubscribeEvents } from "@vnejs/contracts.scenario.choose";
|
|
2
|
+
import type { PluginName as TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
3
|
+
import type { ModuleCoreConstants, ModuleCoreEvents, ModuleCoreParams, ModuleCoreSettings } from "@vnejs/module.core";
|
|
4
|
+
|
|
5
|
+
export type PluginEvents = ModuleCoreEvents & Record<ChoosePluginName, ChooseSubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
|
|
6
|
+
|
|
7
|
+
export type PluginConstants = ModuleCoreConstants;
|
|
8
|
+
|
|
9
|
+
export type PluginSettings = ModuleCoreSettings;
|
|
10
|
+
|
|
11
|
+
export type PluginParams = ModuleCoreParams;
|
package/tsconfig.json
ADDED
package/README.md
DELETED