triggerix-editor-preset-war3 0.0.5 → 0.0.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.
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +9 -9
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -136,31 +136,31 @@ function serializeItems(items, registry) {
|
|
|
136
136
|
return action;
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
|
-
function
|
|
139
|
+
function generateTriggerId() {
|
|
140
140
|
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
141
141
|
return globalThis.crypto.randomUUID();
|
|
142
142
|
}
|
|
143
|
-
return `
|
|
143
|
+
return `trigger-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
144
144
|
}
|
|
145
|
-
function
|
|
145
|
+
function toTrigger(state, registry, triggerId) {
|
|
146
146
|
const eventParams = state.event ? resolveItemParams(state.event.slotValues, registry) : void 0;
|
|
147
147
|
const event = {
|
|
148
148
|
type: state.event?.id ?? "",
|
|
149
149
|
...eventParams ? { payload: eventParams } : {}
|
|
150
150
|
};
|
|
151
151
|
const actions = serializeItems(state.actions, registry);
|
|
152
|
-
const
|
|
153
|
-
id:
|
|
152
|
+
const trigger = {
|
|
153
|
+
id: triggerId ?? generateTriggerId(),
|
|
154
154
|
event,
|
|
155
155
|
actions
|
|
156
156
|
};
|
|
157
157
|
if (state.conditions.length > 0) {
|
|
158
|
-
|
|
158
|
+
trigger.conditions = {
|
|
159
159
|
type: "and",
|
|
160
160
|
conditions: serializeItems(state.conditions, registry)
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
|
-
return
|
|
163
|
+
return trigger;
|
|
164
164
|
}
|
|
165
165
|
|
|
166
166
|
const INITIAL_STATE = {
|
|
@@ -256,7 +256,7 @@ function createWar3Editor() {
|
|
|
256
256
|
// --- Editor 接口 ---
|
|
257
257
|
getState: () => stateManager.getState(),
|
|
258
258
|
onChange: (listener) => stateManager.onChange(listener),
|
|
259
|
-
|
|
259
|
+
toTrigger: (triggerId) => toTrigger(stateManager.getState(), registry, triggerId),
|
|
260
260
|
reset: () => stateManager.reset(),
|
|
261
261
|
dispose: () => stateManager.dispose(),
|
|
262
262
|
// --- 注册 ---
|
|
@@ -409,4 +409,4 @@ exports.getToolDescriptor = getToolDescriptor;
|
|
|
409
409
|
exports.parseTemplate = parseTemplate;
|
|
410
410
|
exports.resolveSlotDisplayText = resolveSlotDisplayText;
|
|
411
411
|
exports.resolveSlotValue = resolveSlotValue;
|
|
412
|
-
exports.
|
|
412
|
+
exports.toTrigger = toTrigger;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseItemDef, BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
|
|
2
2
|
export { BaseItemDef, Preset } from '@triggerix/editor';
|
|
3
|
-
import { Value,
|
|
3
|
+
import { Value, Trigger } from '@triggerix/core';
|
|
4
4
|
|
|
5
5
|
interface SlotDef {
|
|
6
6
|
label: string;
|
|
@@ -205,7 +205,7 @@ declare function defineWar3Preset(options: War3PresetOptions): Preset<War3Editor
|
|
|
205
205
|
*/
|
|
206
206
|
declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry): Value | undefined;
|
|
207
207
|
/**
|
|
208
|
-
* Serialize editor state into a standard
|
|
208
|
+
* Serialize editor state into a standard Trigger JSON.
|
|
209
209
|
*
|
|
210
210
|
* Output shape (compatible with @triggerix/core):
|
|
211
211
|
* {
|
|
@@ -213,7 +213,7 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
|
|
|
213
213
|
* actions: [{ type, params? }]
|
|
214
214
|
* }
|
|
215
215
|
*/
|
|
216
|
-
declare function
|
|
216
|
+
declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
219
|
* War3 编辑器状态管理
|
|
@@ -235,5 +235,5 @@ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
|
235
235
|
private setItemSlot;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue,
|
|
238
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toTrigger };
|
|
239
239
|
export type { CompositeToolDef, CompositeToolDescriptor, ItemDescriptor, ItemState, LeafToolDef, LeafToolDescriptor, LeafToolInput, Segment, SlotDef, SlotValueEntry, ToolDef, ToolDescriptor, War3ActionDef, War3ConditionDef, War3Editor, War3EditorState, War3EventDef, War3PresetOptions };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseItemDef, BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
|
|
2
2
|
export { BaseItemDef, Preset } from '@triggerix/editor';
|
|
3
|
-
import { Value,
|
|
3
|
+
import { Value, Trigger } from '@triggerix/core';
|
|
4
4
|
|
|
5
5
|
interface SlotDef {
|
|
6
6
|
label: string;
|
|
@@ -205,7 +205,7 @@ declare function defineWar3Preset(options: War3PresetOptions): Preset<War3Editor
|
|
|
205
205
|
*/
|
|
206
206
|
declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry): Value | undefined;
|
|
207
207
|
/**
|
|
208
|
-
* Serialize editor state into a standard
|
|
208
|
+
* Serialize editor state into a standard Trigger JSON.
|
|
209
209
|
*
|
|
210
210
|
* Output shape (compatible with @triggerix/core):
|
|
211
211
|
* {
|
|
@@ -213,7 +213,7 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
|
|
|
213
213
|
* actions: [{ type, params? }]
|
|
214
214
|
* }
|
|
215
215
|
*/
|
|
216
|
-
declare function
|
|
216
|
+
declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
219
|
* War3 编辑器状态管理
|
|
@@ -235,5 +235,5 @@ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
|
235
235
|
private setItemSlot;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue,
|
|
238
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toTrigger };
|
|
239
239
|
export type { CompositeToolDef, CompositeToolDescriptor, ItemDescriptor, ItemState, LeafToolDef, LeafToolDescriptor, LeafToolInput, Segment, SlotDef, SlotValueEntry, ToolDef, ToolDescriptor, War3ActionDef, War3ConditionDef, War3Editor, War3EditorState, War3EventDef, War3PresetOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseItemDef, BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
|
|
2
2
|
export { BaseItemDef, Preset } from '@triggerix/editor';
|
|
3
|
-
import { Value,
|
|
3
|
+
import { Value, Trigger } from '@triggerix/core';
|
|
4
4
|
|
|
5
5
|
interface SlotDef {
|
|
6
6
|
label: string;
|
|
@@ -205,7 +205,7 @@ declare function defineWar3Preset(options: War3PresetOptions): Preset<War3Editor
|
|
|
205
205
|
*/
|
|
206
206
|
declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry): Value | undefined;
|
|
207
207
|
/**
|
|
208
|
-
* Serialize editor state into a standard
|
|
208
|
+
* Serialize editor state into a standard Trigger JSON.
|
|
209
209
|
*
|
|
210
210
|
* Output shape (compatible with @triggerix/core):
|
|
211
211
|
* {
|
|
@@ -213,7 +213,7 @@ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry)
|
|
|
213
213
|
* actions: [{ type, params? }]
|
|
214
214
|
* }
|
|
215
215
|
*/
|
|
216
|
-
declare function
|
|
216
|
+
declare function toTrigger(state: War3EditorState, registry: War3Registry, triggerId?: string): Trigger;
|
|
217
217
|
|
|
218
218
|
/**
|
|
219
219
|
* War3 编辑器状态管理
|
|
@@ -235,5 +235,5 @@ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
|
235
235
|
private setItemSlot;
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue,
|
|
238
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toTrigger };
|
|
239
239
|
export type { CompositeToolDef, CompositeToolDescriptor, ItemDescriptor, ItemState, LeafToolDef, LeafToolDescriptor, LeafToolInput, Segment, SlotDef, SlotValueEntry, ToolDef, ToolDescriptor, War3ActionDef, War3ConditionDef, War3Editor, War3EditorState, War3EventDef, War3PresetOptions };
|
package/dist/index.mjs
CHANGED
|
@@ -134,31 +134,31 @@ function serializeItems(items, registry) {
|
|
|
134
134
|
return action;
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
|
-
function
|
|
137
|
+
function generateTriggerId() {
|
|
138
138
|
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
139
139
|
return globalThis.crypto.randomUUID();
|
|
140
140
|
}
|
|
141
|
-
return `
|
|
141
|
+
return `trigger-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
142
142
|
}
|
|
143
|
-
function
|
|
143
|
+
function toTrigger(state, registry, triggerId) {
|
|
144
144
|
const eventParams = state.event ? resolveItemParams(state.event.slotValues, registry) : void 0;
|
|
145
145
|
const event = {
|
|
146
146
|
type: state.event?.id ?? "",
|
|
147
147
|
...eventParams ? { payload: eventParams } : {}
|
|
148
148
|
};
|
|
149
149
|
const actions = serializeItems(state.actions, registry);
|
|
150
|
-
const
|
|
151
|
-
id:
|
|
150
|
+
const trigger = {
|
|
151
|
+
id: triggerId ?? generateTriggerId(),
|
|
152
152
|
event,
|
|
153
153
|
actions
|
|
154
154
|
};
|
|
155
155
|
if (state.conditions.length > 0) {
|
|
156
|
-
|
|
156
|
+
trigger.conditions = {
|
|
157
157
|
type: "and",
|
|
158
158
|
conditions: serializeItems(state.conditions, registry)
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
|
-
return
|
|
161
|
+
return trigger;
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
const INITIAL_STATE = {
|
|
@@ -254,7 +254,7 @@ function createWar3Editor() {
|
|
|
254
254
|
// --- Editor 接口 ---
|
|
255
255
|
getState: () => stateManager.getState(),
|
|
256
256
|
onChange: (listener) => stateManager.onChange(listener),
|
|
257
|
-
|
|
257
|
+
toTrigger: (triggerId) => toTrigger(stateManager.getState(), registry, triggerId),
|
|
258
258
|
reset: () => stateManager.reset(),
|
|
259
259
|
dispose: () => stateManager.dispose(),
|
|
260
260
|
// --- 注册 ---
|
|
@@ -392,4 +392,4 @@ function defineWar3Preset(options) {
|
|
|
392
392
|
};
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue,
|
|
395
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toTrigger };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triggerix-editor-preset-war3",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.6",
|
|
5
5
|
"description": "War3-style template editor preset for Triggerix",
|
|
6
6
|
"homepage": "https://github.com/triggerix-lang/triggerix-editor-preset-war3#readme",
|
|
7
7
|
"repository": {
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@triggerix/core": "^0.0.
|
|
29
|
-
"@triggerix/editor": "^0.0.
|
|
28
|
+
"@triggerix/core": "^0.0.7",
|
|
29
|
+
"@triggerix/editor": "^0.0.7"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@antfu/eslint-config": "^9.0.0",
|