@vnejs/plugins.scenario.point_and_click 0.2.4 → 0.2.6

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.
@@ -1,3 +1,4 @@
1
+ import { getBlockOptions } from "@vnejs/helpers";
1
2
  import { ModuleCore } from "@vnejs/module.core";
2
3
  export class PointAndClickScenario extends ModuleCore {
3
4
  name = "point_and_click.scenario";
@@ -6,17 +7,7 @@ export class PointAndClickScenario extends ModuleCore {
6
7
  onLineExec = async ({ args = {} } = {}) => {
7
8
  const { curLine = 0, label } = this.globalState.scenario;
8
9
  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] }));
10
+ const options = getBlockOptions(lines, curLine, `% ${this.execName}.option`);
20
11
  return this.emit(this.EVENTS.POINT_AND_CLICK.EMIT, { args, options });
21
12
  };
22
13
  }
@@ -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.4",
3
+ "version": "0.2.6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -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";
@@ -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
  };