@vnejs/plugins.scenario.point_and_click 0.2.3 → 0.2.5

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.js CHANGED
@@ -5,13 +5,13 @@ import { PointAndClickEmit } from "./modules/emit.js";
5
5
  import { PointAndClickExec } from "./modules/exec.js";
6
6
  import { PointAndClickLogs } from "./modules/logs.js";
7
7
  import { PointAndClickOption } from "./modules/option.js";
8
- import { PointAndClickState } from "./modules/point_and_click.js";
9
- import { PointAndClickScenario } from "./modules/scenario.block.js";
8
+ import { PointAndClick } from "./modules/point_and_click.js";
9
+ import { PointAndClickScenario } from "./modules/scenario.js";
10
10
  import { PointAndClickScenarioModule } from "./modules/scenario.module.js";
11
11
  import { PointAndClickScenarioOption } from "./modules/scenario.option.js";
12
12
  import { PointAndClickSkip } from "./modules/skip.js";
13
13
  regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
14
- PointAndClickState,
14
+ PointAndClick,
15
15
  PointAndClickEmit,
16
16
  PointAndClickOption,
17
17
  PointAndClickSkip,
@@ -1,6 +1,6 @@
1
1
  import { ModuleReplaceExec } from "@vnejs/module.replace.exec";
2
2
  export class PointAndClickExec extends ModuleReplaceExec {
3
- name = "point-and-click.exec";
3
+ name = "point_and_click.exec";
4
4
  EXEC_REG_EVENT = this.EVENTS.POINT_AND_CLICK.EXEC_REG;
5
5
  EXEC_GET_EVENT = this.EVENTS.POINT_AND_CLICK.EXEC_GET;
6
6
  }
@@ -1,7 +1,7 @@
1
1
  import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
2
2
  import type { PointAndClickPluginConstants, PointAndClickPluginEvents, PointAndClickPluginParams, PointAndClickPluginSettings } from "../types.js";
3
3
  import type { PointAndClickPluginModelState } from "../utils/point-and-click.js";
4
- export declare class PointAndClickState extends ModuleCore<PointAndClickPluginEvents, PointAndClickPluginConstants, PointAndClickPluginSettings, PointAndClickPluginParams, PointAndClickPluginModelState> {
4
+ export declare class PointAndClick extends ModuleCore<PointAndClickPluginEvents, PointAndClickPluginConstants, PointAndClickPluginSettings, PointAndClickPluginParams, PointAndClickPluginModelState> {
5
5
  name: string;
6
6
  subscribe: () => void;
7
7
  onStateUpdate: (state?: Partial<PointAndClickPluginModelState>) => void;
@@ -1,5 +1,5 @@
1
1
  import { ModuleCore } from "@vnejs/module.core";
2
- export class PointAndClickState extends ModuleCore {
2
+ export class PointAndClick extends ModuleCore {
3
3
  name = "point_and_click";
4
4
  subscribe = () => {
5
5
  this.on(this.EVENTS.POINT_AND_CLICK.STATE_UPDATE, this.onStateUpdate);
@@ -0,0 +1,13 @@
1
+ import { getBlockOptions } from "@vnejs/helpers";
2
+ import { ModuleCore } from "@vnejs/module.core";
3
+ export class PointAndClickScenario extends ModuleCore {
4
+ name = "point_and_click.scenario";
5
+ execName = "point-and-click";
6
+ init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.execName, handler: this.onLineExec });
7
+ onLineExec = async ({ args = {} } = {}) => {
8
+ const { curLine = 0, label } = this.globalState.scenario;
9
+ const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label }));
10
+ const options = getBlockOptions(lines, curLine, `% ${this.execName}.option`);
11
+ return this.emit(this.EVENTS.POINT_AND_CLICK.EMIT, { args, options });
12
+ };
13
+ }
@@ -1,7 +1,7 @@
1
1
  import { tokenizeExecLine } from "@vnejs/helpers";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
  export class PointAndClickScenarioModule extends ModuleCore {
4
- name = "point-and-click.scenario.module";
4
+ name = "point_and_click.scenario.module";
5
5
  execName = "point-and-click";
6
6
  init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.execName, handler: this.onLineExec });
7
7
  onLineExec = async ({ line = "" } = {}) => {
@@ -1,7 +1,7 @@
1
1
  import { getOptionExecShift } from "@vnejs/helpers";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
  export class PointAndClickScenarioOption extends ModuleCore {
4
- name = "point-and-click.scenario.option";
4
+ name = "point_and_click.scenario.option";
5
5
  execName = "point-and-click";
6
6
  init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: `${this.execName}.option`, handler: this.onLineExec });
7
7
  onLineExec = async () => {
@@ -1,3 +1,4 @@
1
+ import { getBlockSkipShift } from "@vnejs/helpers";
1
2
  import { ModuleCore } from "@vnejs/module.core";
2
3
  export class PointAndClickSkip extends ModuleCore {
3
4
  name = "point_and_click.skip";
@@ -7,14 +8,7 @@ export class PointAndClickSkip extends ModuleCore {
7
8
  onSkip = async () => {
8
9
  const { curLine = 0, label } = this.globalState.scenario;
9
10
  const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label }));
10
- const parentIndent = lines[curLine]?.indent ?? 0;
11
- let indexShift = 1;
12
- let curLineObj = lines[curLine + indexShift];
13
- while (curLineObj && (curLineObj.indent ?? 0) > parentIndent) {
14
- indexShift++;
15
- curLineObj = lines[curLine + indexShift];
16
- }
17
- this.globalState.scenario.curLine = curLine + indexShift;
11
+ this.globalState.scenario.curLine = curLine + getBlockSkipShift(lines, curLine);
18
12
  return this.emitNext();
19
13
  };
20
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/plugins.scenario.point_and_click",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -7,14 +7,14 @@ import { PointAndClickEmit } from "./modules/emit.js";
7
7
  import { PointAndClickExec } from "./modules/exec.js";
8
8
  import { PointAndClickLogs } from "./modules/logs.js";
9
9
  import { PointAndClickOption } from "./modules/option.js";
10
- import { PointAndClickState } from "./modules/point_and_click.js";
11
- import { PointAndClickScenario } from "./modules/scenario.block.js";
10
+ import { PointAndClick } from "./modules/point_and_click.js";
11
+ import { PointAndClickScenario } from "./modules/scenario.js";
12
12
  import { PointAndClickScenarioModule } from "./modules/scenario.module.js";
13
13
  import { PointAndClickScenarioOption } from "./modules/scenario.option.js";
14
14
  import { PointAndClickSkip } from "./modules/skip.js";
15
15
 
16
16
  regPlugin(PLUGIN_NAME, { constants: CONSTANTS, events: SUBSCRIBE_EVENTS, params: PARAMS }, [
17
- PointAndClickState,
17
+ PointAndClick,
18
18
  PointAndClickEmit,
19
19
  PointAndClickOption,
20
20
  PointAndClickSkip,
@@ -10,7 +10,7 @@ export class PointAndClickExec extends ModuleReplaceExec<
10
10
  PointAndClickPluginParams,
11
11
  PointAndClickExecGetPayload
12
12
  > {
13
- name = "point-and-click.exec";
13
+ name = "point_and_click.exec";
14
14
 
15
15
  EXEC_REG_EVENT = this.EVENTS.POINT_AND_CLICK.EXEC_REG;
16
16
  EXEC_GET_EVENT = this.EVENTS.POINT_AND_CLICK.EXEC_GET;
@@ -3,7 +3,7 @@ import { ModuleCore, type ModuleGlobalStateRegistry } from "@vnejs/module.core";
3
3
  import type { PointAndClickPluginConstants, PointAndClickPluginEvents, PointAndClickPluginParams, PointAndClickPluginSettings } from "../types.js";
4
4
  import type { PointAndClickPluginModelState, PointAndClickVisibilityPayload } from "../utils/point-and-click.js";
5
5
 
6
- export class PointAndClickState extends ModuleCore<
6
+ export class PointAndClick extends ModuleCore<
7
7
  PointAndClickPluginEvents,
8
8
  PointAndClickPluginConstants,
9
9
  PointAndClickPluginSettings,
@@ -10,7 +10,7 @@ export class PointAndClickScenarioModule extends ModuleCore<
10
10
  PointAndClickPluginSettings,
11
11
  PointAndClickPluginParams
12
12
  > {
13
- name = "point-and-click.scenario.module";
13
+ name = "point_and_click.scenario.module";
14
14
 
15
15
  execName = "point-and-click";
16
16
 
@@ -10,7 +10,7 @@ export class PointAndClickScenarioOption extends ModuleCore<
10
10
  PointAndClickPluginSettings,
11
11
  PointAndClickPluginParams
12
12
  > {
13
- name = "point-and-click.scenario.option";
13
+ name = "point_and_click.scenario.option";
14
14
 
15
15
  execName = "point-and-click";
16
16
 
@@ -1,3 +1,4 @@
1
+ import { getBlockOptions } from "@vnejs/helpers";
1
2
  import { ModuleCore, type LineExecHandlerArg } from "@vnejs/module.core";
2
3
 
3
4
  import type { PointAndClickPluginConstants, PointAndClickPluginEvents, PointAndClickPluginParams, PointAndClickPluginSettings } from "../types.js";
@@ -9,7 +10,7 @@ export class PointAndClickScenario extends ModuleCore<
9
10
  PointAndClickPluginSettings,
10
11
  PointAndClickPluginParams
11
12
  > {
12
- name = "point-and-click.scenario";
13
+ name = "point_and_click.scenario";
13
14
 
14
15
  execName = "point-and-click";
15
16
 
@@ -18,20 +19,7 @@ export class PointAndClickScenario extends ModuleCore<
18
19
  onLineExec = async ({ args = {} }: LineExecHandlerArg = {}) => {
19
20
  const { curLine = 0, label } = this.globalState.scenario;
20
21
  const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label })) as PointAndClickOptionLine[];
21
- const optionsArr: number[] = [];
22
-
23
- let indexShift = 1;
24
- let curLineObj = lines[curLine + indexShift];
25
-
26
- while (curLineObj && (curLineObj.indent ?? 0) > (lines[curLine]?.indent ?? 0)) {
27
- curLineObj.line.startsWith(`% ${this.execName}.option`) &&
28
- curLineObj.indent === (lines[curLine]?.indent ?? 0) + 2 &&
29
- optionsArr.push(curLine + indexShift);
30
- indexShift++;
31
- curLineObj = lines[curLine + indexShift];
32
- }
33
-
34
- const options = optionsArr.map((index) => ({ index, optionLine: lines[index] }));
22
+ const options = getBlockOptions(lines, curLine, `% ${this.execName}.option`);
35
23
 
36
24
  return this.emit(this.EVENTS.POINT_AND_CLICK.EMIT, { args, options } satisfies PointAndClickEmitPayload);
37
25
  };
@@ -1,3 +1,4 @@
1
+ import { getBlockSkipShift } from "@vnejs/helpers";
1
2
  import { ModuleCore } from "@vnejs/module.core";
2
3
 
3
4
  import type { PointAndClickPluginConstants, PointAndClickPluginEvents, PointAndClickPluginParams, PointAndClickPluginSettings } from "../types.js";
@@ -18,17 +19,8 @@ export class PointAndClickSkip extends ModuleCore<
18
19
  onSkip = async () => {
19
20
  const { curLine = 0, label } = this.globalState.scenario;
20
21
  const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label })) as PointAndClickOptionLine[];
21
- const parentIndent = lines[curLine]?.indent ?? 0;
22
22
 
23
- let indexShift = 1;
24
- let curLineObj = lines[curLine + indexShift];
25
-
26
- while (curLineObj && (curLineObj.indent ?? 0) > parentIndent) {
27
- indexShift++;
28
- curLineObj = lines[curLine + indexShift];
29
- }
30
-
31
- this.globalState.scenario.curLine = curLine + indexShift;
23
+ this.globalState.scenario.curLine = curLine + getBlockSkipShift(lines, curLine);
32
24
 
33
25
  return this.emitNext();
34
26
  };
@@ -2,20 +2,20 @@ import { beforeEach, describe, expect, it } from "vitest";
2
2
 
3
3
  import { spyEvent } from "@vnejs/test-utils";
4
4
 
5
- import { PointAndClickState } from "../modules/point_and_click.js";
5
+ import { PointAndClick } from "../modules/point_and_click.js";
6
6
  import { createPointAndClickFlowModules, createPointAndClickTestModule, registerPointAndClickPluginVne, SCENARIO_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
7
7
 
8
- describe("PointAndClickState", () => {
8
+ describe("PointAndClick", () => {
9
9
  beforeEach(() => {
10
10
  registerPointAndClickPluginVne();
11
11
  });
12
12
 
13
13
  it("STATE_UPDATE merges partial point_and_click state", async () => {
14
- const { module, observer } = createPointAndClickTestModule(PointAndClickState);
14
+ const { module, observer } = createPointAndClickTestModule(PointAndClick);
15
15
 
16
16
  await observer.emit(SUBSCRIBE_EVENTS.STATE_UPDATE, { isShow: true });
17
17
 
18
- expect((module as PointAndClickState).state.isShow).toBe(true);
18
+ expect((module as PointAndClick).state.isShow).toBe(true);
19
19
  });
20
20
  });
21
21
 
@@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
2
2
 
3
3
  import { spyEvent } from "@vnejs/test-utils";
4
4
 
5
- import { PointAndClickScenario } from "../modules/scenario.block.js";
5
+ import { PointAndClickScenario } from "../modules/scenario.js";
6
6
  import { PointAndClickScenarioModule } from "../modules/scenario.module.js";
7
7
  import { PointAndClickScenarioOption } from "../modules/scenario.option.js";
8
8
  import { createPointAndClickTestModule, registerPointAndClickPluginVne, SCENARIO_EVENTS, SUBSCRIBE_EVENTS } from "./setup.js";
@@ -5,7 +5,7 @@ import { createTestModule as baseCreateTestModule, registerCoreVne, registerVneP
5
5
 
6
6
  import { PointAndClickEmit } from "../modules/emit.js";
7
7
  import { PointAndClickOption } from "../modules/option.js";
8
- import { PointAndClickState } from "../modules/point_and_click.js";
8
+ import { PointAndClick } from "../modules/point_and_click.js";
9
9
  import { PointAndClickSkip } from "../modules/skip.js";
10
10
 
11
11
  export const registerPointAndClickPluginVne = () => {
@@ -37,7 +37,7 @@ export const createPointAndClickTestModule = <T extends Parameters<typeof baseCr
37
37
  };
38
38
 
39
39
  export const createPointAndClickFlowModules = (options: Parameters<typeof baseCreateTestModule>[1] = {}) => {
40
- const { module: stateModule, observer, state, shared } = createPointAndClickTestModule(PointAndClickState, options);
40
+ const { module: stateModule, observer, state, shared } = createPointAndClickTestModule(PointAndClick, options);
41
41
 
42
42
  const attach = <T extends new () => InstanceType<T>>(ModuleClass: T) => {
43
43
  const module = new ModuleClass();
@@ -47,7 +47,7 @@ export const createPointAndClickFlowModules = (options: Parameters<typeof baseCr
47
47
  };
48
48
 
49
49
  return {
50
- stateModule: stateModule as PointAndClickState,
50
+ stateModule: stateModule as PointAndClick,
51
51
  emitModule: attach(PointAndClickEmit),
52
52
  optionModule: attach(PointAndClickOption),
53
53
  skipModule: attach(PointAndClickSkip),
@@ -1,22 +0,0 @@
1
- import { ModuleCore } from "@vnejs/module.core";
2
- export class PointAndClickScenario extends ModuleCore {
3
- name = "point-and-click.scenario";
4
- execName = "point-and-click";
5
- init = () => this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { block: this.execName, handler: this.onLineExec });
6
- onLineExec = async ({ args = {} } = {}) => {
7
- const { curLine = 0, label } = this.globalState.scenario;
8
- const lines = (await this.emitOne(this.EVENTS.SCENARIO.LINES_GET, { label }));
9
- const optionsArr = [];
10
- let indexShift = 1;
11
- let curLineObj = lines[curLine + indexShift];
12
- while (curLineObj && (curLineObj.indent ?? 0) > (lines[curLine]?.indent ?? 0)) {
13
- curLineObj.line.startsWith(`% ${this.execName}.option`) &&
14
- curLineObj.indent === (lines[curLine]?.indent ?? 0) + 2 &&
15
- optionsArr.push(curLine + indexShift);
16
- indexShift++;
17
- curLineObj = lines[curLine + indexShift];
18
- }
19
- const options = optionsArr.map((index) => ({ index, optionLine: lines[index] }));
20
- return this.emit(this.EVENTS.POINT_AND_CLICK.EMIT, { args, options });
21
- };
22
- }