@vnejs/compatibility.scenario.choose-with-scenario.qte 0.2.2 → 0.2.3

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 CHANGED
@@ -11,7 +11,7 @@ declare module "@vnejs/contracts.scenario.choose" {
11
11
  export declare class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore<PluginEvents, PluginConstants, PluginSettings, PluginParams> {
12
12
  name: string;
13
13
  pendingResolve: ((success: boolean) => void) | null;
14
- init: () => Promise<unknown[]> | undefined;
14
+ init: () => Promise<import("@vnejs/shared").EmitResults<"vne:choose:option_replace_reg">> | undefined;
15
15
  subscribe: () => void;
16
16
  onQteResult: ({ success }?: QteResultPayload) => void;
17
17
  onOptionReplace: ChooseOptionReplaceHandler;
package/dist/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import "@vnejs/contracts.scenario.choose";
2
2
  import { ModuleCore } from "@vnejs/module.core";
3
3
  import { regModule } from "@vnejs/shared";
4
+ const LOGS_ACTIONS = {
5
+ MISSING: "missing",
6
+ MISSING_FALLBACK: "missing_fallback",
7
+ };
4
8
  export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore {
5
9
  name = "compatibility.scenario.choose-with-scenario.qte";
6
10
  pendingResolve = null;
7
- init = () => this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, {
8
- handler: this.onOptionReplace,
9
- });
11
+ init = () => this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, { handler: this.onOptionReplace });
10
12
  subscribe = () => {
11
13
  this.on(this.EVENTS.QTE.RESULT, this.onQteResult);
12
14
  };
@@ -24,7 +26,7 @@ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore {
24
26
  return index;
25
27
  const item = this.PARAMS.QTE.ITEMS[qteId];
26
28
  if (!item) {
27
- this.emitLog({ action: "missing", id: qteId });
29
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING, id: qteId });
28
30
  return this.resolveFailIndex(index, options);
29
31
  }
30
32
  const success = await new Promise((resolve) => {
@@ -38,7 +40,7 @@ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore {
38
40
  resolveFailIndex = (index, options) => {
39
41
  const fallbackIndex = options.findIndex((option) => option.keywords?.includes(this.CONST.QTE.LINE_KEYWORDS.QTE_FALLBACK));
40
42
  if (fallbackIndex < 0) {
41
- this.emitLog({ action: "missing_fallback", index });
43
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING_FALLBACK, index });
42
44
  return index;
43
45
  }
44
46
  return fallbackIndex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/compatibility.scenario.choose-with-scenario.qte",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -7,6 +7,11 @@ import type { QteEmitPayload, QteResultPayload } from "@vnejs/contracts.scenario
7
7
 
8
8
  import type { PluginConstants, PluginEvents, PluginParams, PluginSettings } from "./types.js";
9
9
 
10
+ const LOGS_ACTIONS = {
11
+ MISSING: "missing",
12
+ MISSING_FALLBACK: "missing_fallback",
13
+ } as const;
14
+
10
15
  declare module "@vnejs/contracts.scenario.choose" {
11
16
  interface ChooseOption {
12
17
  qte?: string;
@@ -18,10 +23,7 @@ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore<Plugi
18
23
 
19
24
  pendingResolve: ((success: boolean) => void) | null = null;
20
25
 
21
- init = () =>
22
- this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, {
23
- handler: this.onOptionReplace,
24
- } satisfies ChooseOptionReplaceRegPayload);
26
+ init = () => this.emit(this.EVENTS.CHOOSE.OPTION_REPLACE_REG, { handler: this.onOptionReplace } satisfies ChooseOptionReplaceRegPayload);
25
27
 
26
28
  subscribe = () => {
27
29
  this.on(this.EVENTS.QTE.RESULT, this.onQteResult);
@@ -44,7 +46,7 @@ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore<Plugi
44
46
  const item = this.PARAMS.QTE.ITEMS[qteId];
45
47
 
46
48
  if (!item) {
47
- this.emitLog({ action: "missing", id: qteId });
49
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING, id: qteId });
48
50
  return this.resolveFailIndex(index, options);
49
51
  }
50
52
 
@@ -62,7 +64,7 @@ export class CompatibilityScenarioChooseWithScenarioQte extends ModuleCore<Plugi
62
64
  const fallbackIndex = options.findIndex((option) => option.keywords?.includes(this.CONST.QTE.LINE_KEYWORDS.QTE_FALLBACK));
63
65
 
64
66
  if (fallbackIndex < 0) {
65
- this.emitLog({ action: "missing_fallback", index });
67
+ this.emit(this.EVENTS.LOGS.EMIT, { action: LOGS_ACTIONS.MISSING_FALLBACK, index });
66
68
  return index;
67
69
  }
68
70