@vnejs/plugins.feature.choose 0.0.2 → 0.1.0
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/modules/choose.js +9 -9
- package/package.json +5 -6
package/modules/choose.js
CHANGED
|
@@ -12,26 +12,26 @@ export class Choose extends Module {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
onChooseEmit = async ({ options, args } = {}) => {
|
|
15
|
-
this.
|
|
15
|
+
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "emit", options, args } });
|
|
16
16
|
this.updateState({ isShow: true, options: await this.getRealOptions(options), args });
|
|
17
17
|
await this.emit(this.EVENTS.CHOOSE.SHOW);
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
onChooseOption = async ({ index = 0 } = {}) => {
|
|
21
|
-
this.
|
|
21
|
+
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "choose", index } });
|
|
22
22
|
this.globalState.scenario.curLine = this.state.options[index].index + 1;
|
|
23
23
|
await this.emit(this.EVENTS.CHOOSE.HIDE);
|
|
24
24
|
this.setDefaultState();
|
|
25
|
-
this.
|
|
25
|
+
this.emit(this.EVENTS.SCENARIO.NEXT, { module: this.name });
|
|
26
26
|
};
|
|
27
27
|
onStateSet = async ({ [this.name]: state } = {}) => {
|
|
28
28
|
if (this.state.isShow === state.isShow) return;
|
|
29
29
|
|
|
30
30
|
this.setState(state);
|
|
31
31
|
|
|
32
|
-
return this.emit(state.isShow ? this.EVENTS.CHOOSE.SHOW : this.EVENTS.CHOOSE.HIDE, {
|
|
32
|
+
return this.emit(state.isShow ? this.EVENTS.CHOOSE.SHOW : this.EVENTS.CHOOSE.HIDE, { isForce: true });
|
|
33
33
|
};
|
|
34
|
-
onStateClear = () => this.emit(this.EVENTS.CHOOSE.HIDE, {
|
|
34
|
+
onStateClear = () => this.emit(this.EVENTS.CHOOSE.HIDE, { isForce: true });
|
|
35
35
|
|
|
36
36
|
getRealOptions = async (options = []) => Promise.all(options.map(this.mapOptions));
|
|
37
37
|
mapOptions = async ({ optionLine, index } = {}) => {
|
|
@@ -43,21 +43,21 @@ export class Choose extends Module {
|
|
|
43
43
|
if (typeof optionLine.args[key] !== "string" || !optionLine.args[key].startsWith("$")) return;
|
|
44
44
|
const [dollar, module, ...other] = optionLine.args[key].split(" ");
|
|
45
45
|
result[key] = await this.emitOne(this.EVENTS.CHOOSE.EXEC_GET, { module, line: other.join(" ") });
|
|
46
|
-
})
|
|
46
|
+
}),
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
return result;
|
|
50
50
|
};
|
|
51
|
-
getOptionText =
|
|
51
|
+
getOptionText = (line) => {
|
|
52
52
|
const quotedText = line.slice(line.indexOf('"'), line.lastIndexOf('"') + 1);
|
|
53
53
|
|
|
54
|
-
return this.
|
|
54
|
+
return this.emitOne(this.EVENTS.LOCS.GET_TEXT, { key: quotedText.slice(1, quotedText.length - 1), label: this.globalState.scenario.label });
|
|
55
55
|
};
|
|
56
56
|
getOptionCoords = (line) => {
|
|
57
57
|
const lineText = line.slice("% option ".length);
|
|
58
58
|
const numbers = lineText.slice(lineText.lastIndexOf('"') + 2);
|
|
59
59
|
|
|
60
|
-
return numbers.split(" ").map(Number);
|
|
60
|
+
return numbers === "" ? undefined : numbers.split(" ").map(Number);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
getDefaultState = () => ({ options: [], args: {}, isShow: false });
|
package/package.json
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.feature.choose",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"publish:major:plugin": "npm run publish:major",
|
|
8
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
9
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
7
10
|
"publish:major": "npm version major && npm publish --access public",
|
|
8
11
|
"publish:minor": "npm version minor && npm publish --access public",
|
|
9
12
|
"publish:patch": "npm version patch && npm publish --access public"
|
|
10
13
|
},
|
|
11
14
|
"author": "",
|
|
12
15
|
"license": "ISC",
|
|
13
|
-
"description": ""
|
|
14
|
-
"peerDependencies": {
|
|
15
|
-
"@vnejs/shared": "*",
|
|
16
|
-
"@vnejs/module": "*"
|
|
17
|
-
}
|
|
16
|
+
"description": ""
|
|
18
17
|
}
|