@vnejs/plugins.text.wall 0.1.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 +1 -0
- package/dist/index.js +5 -0
- package/dist/modules/wall.d.ts +27 -0
- package/dist/modules/wall.js +58 -0
- package/dist/types.d.ts +7 -0
- package/dist/types.js +1 -0
- package/dist/utils/wall.d.ts +3 -0
- package/dist/utils/wall.js +1 -0
- package/package.json +44 -0
- package/src/index.ts +8 -0
- package/src/modules/wall.ts +87 -0
- package/src/types.ts +11 -0
- package/src/utils/wall.ts +3 -0
- package/tsconfig.json +9 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "@vnejs/contracts.text.wall";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import "@vnejs/contracts.text.wall";
|
|
2
|
+
import { regPlugin } from "@vnejs/shared";
|
|
3
|
+
import { PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.text.wall";
|
|
4
|
+
import { TextWall } from "./modules/wall.js";
|
|
5
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS }, [TextWall]);
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { ModuleGlobalStateRegistry } from "@vnejs/module.core";
|
|
3
|
+
import type { TokenizedChar } from "@vnejs/contracts.text";
|
|
4
|
+
import type { ModuleGlobalStateTextWall, WallElement } from "@vnejs/contracts.text.wall";
|
|
5
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
6
|
+
import type { TextWallPluginConstants, TextWallPluginEvents, TextWallPluginParams, TextWallPluginSettings } from "../types.js";
|
|
7
|
+
import type { TextEmitBeforePayload } from "../utils/wall.js";
|
|
8
|
+
export declare class TextWall extends ModuleCore<TextWallPluginEvents, TextWallPluginConstants, TextWallPluginSettings, TextWallPluginParams, ModuleGlobalStateTextWall> {
|
|
9
|
+
name: string;
|
|
10
|
+
subscribe: () => void;
|
|
11
|
+
init: () => Promise<unknown[]> | undefined;
|
|
12
|
+
emitWallChanged: () => Promise<unknown[]> | undefined;
|
|
13
|
+
onLineExec: ({ line }?: LineExecHandlerArg) => Promise<void>;
|
|
14
|
+
onTextEmitBefore: ({ isExtend }?: TextEmitBeforePayload) => Promise<void>;
|
|
15
|
+
onTextRecalc: () => Promise<unknown[] | undefined>;
|
|
16
|
+
onStateSet: (payload: ModuleGlobalStateRegistry) => Promise<unknown[] | undefined>;
|
|
17
|
+
onStateClear: () => Promise<unknown[] | undefined>;
|
|
18
|
+
getRealText: (text: string, args: Record<string, unknown>) => Promise<string>;
|
|
19
|
+
recalcWallObjToken: (wallObj: WallElement) => Promise<{
|
|
20
|
+
tokens: TokenizedChar[];
|
|
21
|
+
texts: import("@vnejs/contracts.text").TextItem[];
|
|
22
|
+
uid: string;
|
|
23
|
+
speaker: string;
|
|
24
|
+
meet: number;
|
|
25
|
+
}>;
|
|
26
|
+
getDefaultState: () => ModuleGlobalStateTextWall;
|
|
27
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
|
|
3
|
+
export class TextWall extends ModuleCore {
|
|
4
|
+
name = "text.wall";
|
|
5
|
+
subscribe = () => {
|
|
6
|
+
this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
|
|
7
|
+
this.on(this.EVENTS.TEXT.RECALC, this.onTextRecalc);
|
|
8
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
9
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
10
|
+
};
|
|
11
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
12
|
+
emitWallChanged = () => this.emit(this.EVENTS.TEXT_WALL.CHANGED, { wall: this.state.wall });
|
|
13
|
+
onLineExec = async ({ line = "" } = {}) => {
|
|
14
|
+
const [action = ""] = tokenizeExecLine(line).map(String);
|
|
15
|
+
if (action === "clear")
|
|
16
|
+
this.updateState({ wall: [], shouldSkip: true });
|
|
17
|
+
if (action === "start")
|
|
18
|
+
this.updateState({ wall: [], isStarted: true, shouldSkip: true });
|
|
19
|
+
if (action === "end")
|
|
20
|
+
this.updateState({ wall: [], isStarted: false, shouldSkip: true });
|
|
21
|
+
await this.emitWallChanged();
|
|
22
|
+
this.emitNext();
|
|
23
|
+
};
|
|
24
|
+
onTextEmitBefore = async ({ isExtend = false } = {}) => {
|
|
25
|
+
if (isExtend || !this.state.isStarted)
|
|
26
|
+
return;
|
|
27
|
+
if (this.state.shouldSkip)
|
|
28
|
+
return this.updateState({ shouldSkip: false });
|
|
29
|
+
const { texts, tokens, uid } = this.globalState.text;
|
|
30
|
+
const { speaker, meet } = this.globalState["text.speaker"];
|
|
31
|
+
const wall = await this.emitClone(this.state.wall);
|
|
32
|
+
const wallElement = await this.emitClone({ texts, tokens, uid, speaker, meet });
|
|
33
|
+
this.updateState({ wall: [...wall, wallElement] });
|
|
34
|
+
await this.emitWallChanged();
|
|
35
|
+
};
|
|
36
|
+
onTextRecalc = async () => {
|
|
37
|
+
if (!this.state.wall.length)
|
|
38
|
+
return;
|
|
39
|
+
this.updateState({ wall: await Promise.all(this.state.wall.map(this.recalcWallObjToken)) });
|
|
40
|
+
return this.emitWallChanged();
|
|
41
|
+
};
|
|
42
|
+
onStateSet = async (payload) => {
|
|
43
|
+
await this.onSetStateClone(payload);
|
|
44
|
+
return this.emitWallChanged();
|
|
45
|
+
};
|
|
46
|
+
onStateClear = async () => {
|
|
47
|
+
this.setDefaultState();
|
|
48
|
+
return this.emitWallChanged();
|
|
49
|
+
};
|
|
50
|
+
getRealText = (text, args) => this.emitOne(this.EVENTS.TEXT.REPLACE, { text, args, label: this.globalState.scenario.label, state: this.globalState });
|
|
51
|
+
recalcWallObjToken = async (wallObj) => {
|
|
52
|
+
const tokens = [];
|
|
53
|
+
for (let i = 0; i < wallObj.texts.length; i++)
|
|
54
|
+
tokens.push(...tokenizeText(await this.getRealText(wallObj.texts[i].text, wallObj.texts[i].args)));
|
|
55
|
+
return { ...wallObj, tokens };
|
|
56
|
+
};
|
|
57
|
+
getDefaultState = () => ({ wall: [], isStarted: false, shouldSkip: false });
|
|
58
|
+
}
|
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 TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
3
|
+
import type { PluginName, SubscribeEvents } from "@vnejs/contracts.text.wall";
|
|
4
|
+
export type TextWallPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
|
|
5
|
+
export type TextWallPluginConstants = ModuleCoreConstants;
|
|
6
|
+
export type TextWallPluginSettings = ModuleCoreSettings;
|
|
7
|
+
export type TextWallPluginParams = ModuleCoreParams;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vnejs/plugins.text.wall",
|
|
3
|
+
"version": "0.1.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": "echo \"Error: no test specified\" && exit 1",
|
|
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.text.wall": "~0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/helpers": "~0.1.0",
|
|
37
|
+
"@vnejs/module.core": "~0.1.0",
|
|
38
|
+
"@vnejs/contracts.text": "~0.1.0",
|
|
39
|
+
"@vnejs/shared": "~0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@vnejs/configs.ts-common": "~0.1.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@vnejs/contracts.text.wall";
|
|
2
|
+
|
|
3
|
+
import { regPlugin } from "@vnejs/shared";
|
|
4
|
+
import { PLUGIN_NAME, SUBSCRIBE_EVENTS } from "@vnejs/contracts.text.wall";
|
|
5
|
+
|
|
6
|
+
import { TextWall } from "./modules/wall.js";
|
|
7
|
+
|
|
8
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS }, [TextWall]);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ModuleCore } from "@vnejs/module.core";
|
|
2
|
+
import type { ModuleGlobalStateRegistry } from "@vnejs/module.core";
|
|
3
|
+
import { tokenizeExecLine, tokenizeText } from "@vnejs/helpers";
|
|
4
|
+
|
|
5
|
+
import type { TokenizedChar } from "@vnejs/contracts.text";
|
|
6
|
+
import type { ModuleGlobalStateTextWall, WallElement } from "@vnejs/contracts.text.wall";
|
|
7
|
+
import type { LineExecHandlerArg } from "@vnejs/module.core";
|
|
8
|
+
|
|
9
|
+
import type { TextWallPluginConstants, TextWallPluginEvents, TextWallPluginParams, TextWallPluginSettings } from "../types.js";
|
|
10
|
+
import type { TextEmitBeforePayload } from "../utils/wall.js";
|
|
11
|
+
|
|
12
|
+
export class TextWall extends ModuleCore<TextWallPluginEvents, TextWallPluginConstants, TextWallPluginSettings, TextWallPluginParams, ModuleGlobalStateTextWall> {
|
|
13
|
+
name = "text.wall";
|
|
14
|
+
|
|
15
|
+
subscribe = () => {
|
|
16
|
+
this.on(this.EVENTS.TEXT.EMIT_BEFORE, this.onTextEmitBefore);
|
|
17
|
+
|
|
18
|
+
this.on(this.EVENTS.TEXT.RECALC, this.onTextRecalc);
|
|
19
|
+
|
|
20
|
+
this.on(this.EVENTS.STATE.CLEAR, this.onStateClear);
|
|
21
|
+
this.on(this.EVENTS.STATE.SET, this.onStateSet);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec });
|
|
25
|
+
|
|
26
|
+
emitWallChanged = () => this.emit(this.EVENTS.TEXT_WALL.CHANGED, { wall: this.state.wall });
|
|
27
|
+
|
|
28
|
+
onLineExec = async ({ line = "" }: LineExecHandlerArg = {}) => {
|
|
29
|
+
const [action = ""] = tokenizeExecLine(line).map(String);
|
|
30
|
+
|
|
31
|
+
if (action === "clear") this.updateState({ wall: [], shouldSkip: true });
|
|
32
|
+
if (action === "start") this.updateState({ wall: [], isStarted: true, shouldSkip: true });
|
|
33
|
+
if (action === "end") this.updateState({ wall: [], isStarted: false, shouldSkip: true });
|
|
34
|
+
|
|
35
|
+
await this.emitWallChanged();
|
|
36
|
+
|
|
37
|
+
this.emitNext();
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
onTextEmitBefore = async ({ isExtend = false }: TextEmitBeforePayload = {}) => {
|
|
41
|
+
if (isExtend || !this.state.isStarted) return;
|
|
42
|
+
if (this.state.shouldSkip) return this.updateState({ shouldSkip: false });
|
|
43
|
+
|
|
44
|
+
const { texts, tokens, uid } = this.globalState.text;
|
|
45
|
+
const { speaker, meet } = this.globalState["text.speaker"];
|
|
46
|
+
|
|
47
|
+
const wall = await this.emitClone<WallElement[]>(this.state.wall);
|
|
48
|
+
const wallElement = await this.emitClone<WallElement>({ texts, tokens, uid, speaker, meet });
|
|
49
|
+
|
|
50
|
+
this.updateState({ wall: [...wall, wallElement] });
|
|
51
|
+
|
|
52
|
+
await this.emitWallChanged();
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
onTextRecalc = async () => {
|
|
56
|
+
if (!this.state.wall.length) return;
|
|
57
|
+
|
|
58
|
+
this.updateState({ wall: await Promise.all(this.state.wall.map(this.recalcWallObjToken)) });
|
|
59
|
+
|
|
60
|
+
return this.emitWallChanged();
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
onStateSet = async (payload: ModuleGlobalStateRegistry) => {
|
|
64
|
+
await this.onSetStateClone(payload);
|
|
65
|
+
|
|
66
|
+
return this.emitWallChanged();
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
onStateClear = async () => {
|
|
70
|
+
this.setDefaultState();
|
|
71
|
+
|
|
72
|
+
return this.emitWallChanged();
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
getRealText = (text: string, args: Record<string, unknown>) =>
|
|
76
|
+
this.emitOne(this.EVENTS.TEXT.REPLACE, { text, args, label: this.globalState.scenario.label, state: this.globalState }) as Promise<string>;
|
|
77
|
+
|
|
78
|
+
recalcWallObjToken = async (wallObj: WallElement) => {
|
|
79
|
+
const tokens: TokenizedChar[] = [];
|
|
80
|
+
|
|
81
|
+
for (let i = 0; i < wallObj.texts.length; i++) tokens.push(...tokenizeText(await this.getRealText(wallObj.texts[i].text, wallObj.texts[i].args)));
|
|
82
|
+
|
|
83
|
+
return { ...wallObj, tokens };
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
getDefaultState = (): ModuleGlobalStateTextWall => ({ wall: [], isStarted: false, shouldSkip: false });
|
|
87
|
+
}
|
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 TextPluginName, SubscribeEvents as TextSubscribeEvents } from "@vnejs/contracts.text";
|
|
3
|
+
import type { PluginName, SubscribeEvents } from "@vnejs/contracts.text.wall";
|
|
4
|
+
|
|
5
|
+
export type TextWallPluginEvents = ModuleCoreEvents & Record<PluginName, SubscribeEvents> & Record<TextPluginName, TextSubscribeEvents>;
|
|
6
|
+
|
|
7
|
+
export type TextWallPluginConstants = ModuleCoreConstants;
|
|
8
|
+
|
|
9
|
+
export type TextWallPluginSettings = ModuleCoreSettings;
|
|
10
|
+
|
|
11
|
+
export type TextWallPluginParams = ModuleCoreParams;
|