triggerix-editor-preset-war3 0.0.0 → 0.0.4

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.
@@ -0,0 +1,239 @@
1
+ import { BaseItemDef, BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
2
+ export { BaseItemDef, Preset } from '@triggerix/editor';
3
+ import { Value, Rule } from '@triggerix/core';
4
+
5
+ interface SlotDef {
6
+ label: string;
7
+ tools: string[];
8
+ }
9
+ interface SlotValueEntry {
10
+ tool: string | null;
11
+ value: unknown;
12
+ subSlots?: Record<string, SlotValueEntry>;
13
+ }
14
+ interface LeafToolInput<TValue = unknown> {
15
+ type: 'text' | 'number' | 'select';
16
+ placeholder?: string;
17
+ options?: Array<{
18
+ value: TValue;
19
+ label: string;
20
+ }>;
21
+ }
22
+ interface LeafToolDef<TInput = unknown, TOutput = unknown> {
23
+ kind: 'leaf';
24
+ type?: string;
25
+ label: string;
26
+ input: LeafToolInput<TInput>;
27
+ resolve: (input: TInput) => TOutput;
28
+ }
29
+ interface CompositeToolDef<TSlotValues extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> {
30
+ kind: 'composite';
31
+ type?: string;
32
+ label: string;
33
+ template: string;
34
+ slots: Record<keyof TSlotValues & string, SlotDef>;
35
+ resolve: (slotValues: TSlotValues) => TOutput;
36
+ }
37
+ type ToolDef = LeafToolDef<any, any> | CompositeToolDef<any, any>;
38
+ interface War3EventDef extends BaseItemDef {
39
+ template: string;
40
+ slots?: Record<string, SlotDef>;
41
+ }
42
+ interface War3ActionDef extends BaseItemDef {
43
+ template: string;
44
+ slots?: Record<string, SlotDef>;
45
+ }
46
+ interface War3ConditionDef<TSlotValues extends Record<string, unknown> = Record<string, unknown>> extends BaseItemDef {
47
+ template: string;
48
+ slots?: Record<string, SlotDef>;
49
+ resolve?: (slotValues: TSlotValues) => unknown;
50
+ }
51
+ type Segment = {
52
+ type: 'text';
53
+ content: string;
54
+ } | {
55
+ type: 'slot';
56
+ key: string;
57
+ label: string;
58
+ tools: string[];
59
+ value: unknown;
60
+ entry?: SlotValueEntry;
61
+ };
62
+ interface ItemDescriptor {
63
+ id: string;
64
+ segments: Segment[];
65
+ }
66
+ interface LeafToolDescriptor {
67
+ kind: 'leaf';
68
+ name: string;
69
+ label: string;
70
+ input: LeafToolInput;
71
+ }
72
+ interface CompositeToolDescriptor {
73
+ kind: 'composite';
74
+ name: string;
75
+ label: string;
76
+ segments: Segment[];
77
+ }
78
+ type ToolDescriptor = LeafToolDescriptor | CompositeToolDescriptor;
79
+ interface ItemState {
80
+ id: string;
81
+ slotValues: Record<string, SlotValueEntry>;
82
+ }
83
+ interface War3EditorState {
84
+ event: ItemState | null;
85
+ conditions: ItemState[];
86
+ actions: ItemState[];
87
+ }
88
+ interface War3PresetOptions {
89
+ name: string;
90
+ events?: War3EventDef[];
91
+ actions?: War3ActionDef[];
92
+ conditions?: War3ConditionDef[];
93
+ tools?: Record<string, ToolDef>;
94
+ }
95
+
96
+ /**
97
+ * War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
98
+ */
99
+ declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
100
+ private tools;
101
+ registerTool(name: string, def: ToolDef): void;
102
+ getTool(name: string): ToolDef | undefined;
103
+ getTools(): Map<string, ToolDef>;
104
+ getValueSources(valueType?: string): {
105
+ conditions: War3ConditionDef[];
106
+ tools: Map<string, ToolDef>;
107
+ };
108
+ }
109
+
110
+ interface War3Editor extends Editor<War3EditorState> {
111
+ registerEvent: (def: War3EventDef) => void;
112
+ registerAction: (def: War3ActionDef) => void;
113
+ registerCondition: (def: War3ConditionDef) => void;
114
+ registerTool: (name: string, def: ToolDef) => void;
115
+ getRegistry: () => War3Registry;
116
+ getAvailableEvents: () => War3EventDef[];
117
+ getAvailableActions: () => War3ActionDef[];
118
+ getAvailableConditions: () => War3ConditionDef[];
119
+ getEventDescriptor: () => ItemDescriptor | null;
120
+ getActionDescriptor: (actionIndex: number) => ItemDescriptor | null;
121
+ getConditionDescriptor: (conditionIndex: number) => ItemDescriptor | null;
122
+ getToolDescriptor: (toolName: string, slotValues?: Record<string, SlotValueEntry>) => ToolDescriptor | null;
123
+ getSlotTools: (slotDef: SlotDef) => ToolDescriptor[];
124
+ setEvent: (id: string) => void;
125
+ clearEvent: () => void;
126
+ setEventSlot: (key: string, entry: SlotValueEntry) => void;
127
+ addAction: (id: string) => void;
128
+ removeAction: (index: number) => void;
129
+ moveAction: (from: number, to: number) => void;
130
+ setActionSlot: (actionIndex: number, key: string, entry: SlotValueEntry) => void;
131
+ addCondition: (id: string) => void;
132
+ removeCondition: (index: number) => void;
133
+ setConditionSlot: (conditionIndex: number, key: string, entry: SlotValueEntry) => void;
134
+ getValueSources: (valueType?: string) => {
135
+ conditions: War3ConditionDef[];
136
+ tools: Map<string, ToolDef>;
137
+ };
138
+ applyPreset: (preset: Preset<War3Editor>) => void;
139
+ resolveSlotValue: (entry: SlotValueEntry) => unknown;
140
+ }
141
+ declare function createWar3Editor(): War3Editor;
142
+
143
+ declare function getEventDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
144
+ declare function getActionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
145
+ declare function getConditionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
146
+ declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
147
+ declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
148
+
149
+ /**
150
+ * 递归解析 SlotValueEntry 为人类可读的展示文本
151
+ *
152
+ * - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
153
+ * - 如果 tool 为 leaf:
154
+ * - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
155
+ * - 其它类型:返回 value 的字符串形式
156
+ * - 若 value 为空:返回 fallbackLabel
157
+ * - 如果 tool 为 composite:使用 tool 的 template 递归展开
158
+ */
159
+ declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
160
+
161
+ /**
162
+ * 类型安全地定义 LeafTool
163
+ * 用户通过回调参数注解来指定输入类型,TS 自动推导输出类型
164
+ */
165
+ declare function defineLeafTool<TInput, TOutput>(def: {
166
+ type?: string;
167
+ label: string;
168
+ input: LeafToolInput<TInput>;
169
+ resolve: (input: TInput) => TOutput;
170
+ }): {
171
+ kind: "leaf";
172
+ type?: string;
173
+ label: string;
174
+ input: LeafToolInput<TInput>;
175
+ resolve: (input: TInput) => TOutput;
176
+ };
177
+ /**
178
+ * 类型安全地定义 CompositeTool
179
+ * 用户注解 resolve 回调参数来指定 slot 值类型,TS 验证 slots keys 一致性
180
+ */
181
+ declare function defineCompositeTool<TSlotValues extends Record<string, unknown>, TOutput>(def: {
182
+ type?: string;
183
+ label: string;
184
+ template: string;
185
+ slots: Record<keyof TSlotValues & string, SlotDef>;
186
+ resolve: (slotValues: TSlotValues) => TOutput;
187
+ }): CompositeToolDef<TSlotValues, TOutput>;
188
+ /**
189
+ * 类型安全地定义 Condition
190
+ */
191
+ declare function defineCondition<TSlotValues extends Record<string, unknown> = Record<string, unknown>>(def: Omit<War3ConditionDef<TSlotValues>, 'resolve'> & {
192
+ resolve?: (slotValues: TSlotValues) => unknown;
193
+ }): War3ConditionDef;
194
+
195
+ /**
196
+ * 解析模板字符串为 Segment 数组
197
+ * 模板格式: "普通文本${slotKey}更多文本"
198
+ */
199
+ declare function parseTemplate(template: string, slots?: Record<string, SlotDef>, slotValues?: Record<string, SlotValueEntry>): Segment[];
200
+
201
+ declare function defineWar3Preset(options: War3PresetOptions): Preset<War3Editor>;
202
+
203
+ /**
204
+ * 递归解析单个 slot 值
205
+ */
206
+ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry): Value | undefined;
207
+ /**
208
+ * 将编辑器状态序列化为标准 Rule JSON
209
+ *
210
+ * 输出结构(与 @triggerix/core 兼容):
211
+ * {
212
+ * id, event: { type, payload? }, conditions?: { type:'and', conditions:[...] },
213
+ * actions: [{ type, params? }]
214
+ * }
215
+ */
216
+ declare function toRule(state: War3EditorState, registry: War3Registry, ruleId?: string): Rule;
217
+
218
+ /**
219
+ * War3 编辑器状态管理
220
+ * 继承 ObservableState,提供模板模式特有的状态操作
221
+ */
222
+ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
223
+ constructor();
224
+ setEvent(id: string): void;
225
+ clearEvent(): void;
226
+ setEventSlot(key: string, entry: SlotValueEntry): void;
227
+ addAction(id: string): void;
228
+ removeAction(index: number): void;
229
+ moveAction(from: number, to: number): void;
230
+ setActionSlot(actionIndex: number, key: string, entry: SlotValueEntry): void;
231
+ addCondition(id: string): void;
232
+ removeCondition(index: number): void;
233
+ setConditionSlot(conditionIndex: number, key: string, entry: SlotValueEntry): void;
234
+ reset(): void;
235
+ private setItemSlot;
236
+ }
237
+
238
+ export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toRule };
239
+ export type { CompositeToolDef, CompositeToolDescriptor, ItemDescriptor, ItemState, LeafToolDef, LeafToolDescriptor, LeafToolInput, Segment, SlotDef, SlotValueEntry, ToolDef, ToolDescriptor, War3ActionDef, War3ConditionDef, War3Editor, War3EditorState, War3EventDef, War3PresetOptions };
@@ -0,0 +1,239 @@
1
+ import { BaseItemDef, BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
2
+ export { BaseItemDef, Preset } from '@triggerix/editor';
3
+ import { Value, Rule } from '@triggerix/core';
4
+
5
+ interface SlotDef {
6
+ label: string;
7
+ tools: string[];
8
+ }
9
+ interface SlotValueEntry {
10
+ tool: string | null;
11
+ value: unknown;
12
+ subSlots?: Record<string, SlotValueEntry>;
13
+ }
14
+ interface LeafToolInput<TValue = unknown> {
15
+ type: 'text' | 'number' | 'select';
16
+ placeholder?: string;
17
+ options?: Array<{
18
+ value: TValue;
19
+ label: string;
20
+ }>;
21
+ }
22
+ interface LeafToolDef<TInput = unknown, TOutput = unknown> {
23
+ kind: 'leaf';
24
+ type?: string;
25
+ label: string;
26
+ input: LeafToolInput<TInput>;
27
+ resolve: (input: TInput) => TOutput;
28
+ }
29
+ interface CompositeToolDef<TSlotValues extends Record<string, unknown> = Record<string, unknown>, TOutput = unknown> {
30
+ kind: 'composite';
31
+ type?: string;
32
+ label: string;
33
+ template: string;
34
+ slots: Record<keyof TSlotValues & string, SlotDef>;
35
+ resolve: (slotValues: TSlotValues) => TOutput;
36
+ }
37
+ type ToolDef = LeafToolDef<any, any> | CompositeToolDef<any, any>;
38
+ interface War3EventDef extends BaseItemDef {
39
+ template: string;
40
+ slots?: Record<string, SlotDef>;
41
+ }
42
+ interface War3ActionDef extends BaseItemDef {
43
+ template: string;
44
+ slots?: Record<string, SlotDef>;
45
+ }
46
+ interface War3ConditionDef<TSlotValues extends Record<string, unknown> = Record<string, unknown>> extends BaseItemDef {
47
+ template: string;
48
+ slots?: Record<string, SlotDef>;
49
+ resolve?: (slotValues: TSlotValues) => unknown;
50
+ }
51
+ type Segment = {
52
+ type: 'text';
53
+ content: string;
54
+ } | {
55
+ type: 'slot';
56
+ key: string;
57
+ label: string;
58
+ tools: string[];
59
+ value: unknown;
60
+ entry?: SlotValueEntry;
61
+ };
62
+ interface ItemDescriptor {
63
+ id: string;
64
+ segments: Segment[];
65
+ }
66
+ interface LeafToolDescriptor {
67
+ kind: 'leaf';
68
+ name: string;
69
+ label: string;
70
+ input: LeafToolInput;
71
+ }
72
+ interface CompositeToolDescriptor {
73
+ kind: 'composite';
74
+ name: string;
75
+ label: string;
76
+ segments: Segment[];
77
+ }
78
+ type ToolDescriptor = LeafToolDescriptor | CompositeToolDescriptor;
79
+ interface ItemState {
80
+ id: string;
81
+ slotValues: Record<string, SlotValueEntry>;
82
+ }
83
+ interface War3EditorState {
84
+ event: ItemState | null;
85
+ conditions: ItemState[];
86
+ actions: ItemState[];
87
+ }
88
+ interface War3PresetOptions {
89
+ name: string;
90
+ events?: War3EventDef[];
91
+ actions?: War3ActionDef[];
92
+ conditions?: War3ConditionDef[];
93
+ tools?: Record<string, ToolDef>;
94
+ }
95
+
96
+ /**
97
+ * War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
98
+ */
99
+ declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
100
+ private tools;
101
+ registerTool(name: string, def: ToolDef): void;
102
+ getTool(name: string): ToolDef | undefined;
103
+ getTools(): Map<string, ToolDef>;
104
+ getValueSources(valueType?: string): {
105
+ conditions: War3ConditionDef[];
106
+ tools: Map<string, ToolDef>;
107
+ };
108
+ }
109
+
110
+ interface War3Editor extends Editor<War3EditorState> {
111
+ registerEvent: (def: War3EventDef) => void;
112
+ registerAction: (def: War3ActionDef) => void;
113
+ registerCondition: (def: War3ConditionDef) => void;
114
+ registerTool: (name: string, def: ToolDef) => void;
115
+ getRegistry: () => War3Registry;
116
+ getAvailableEvents: () => War3EventDef[];
117
+ getAvailableActions: () => War3ActionDef[];
118
+ getAvailableConditions: () => War3ConditionDef[];
119
+ getEventDescriptor: () => ItemDescriptor | null;
120
+ getActionDescriptor: (actionIndex: number) => ItemDescriptor | null;
121
+ getConditionDescriptor: (conditionIndex: number) => ItemDescriptor | null;
122
+ getToolDescriptor: (toolName: string, slotValues?: Record<string, SlotValueEntry>) => ToolDescriptor | null;
123
+ getSlotTools: (slotDef: SlotDef) => ToolDescriptor[];
124
+ setEvent: (id: string) => void;
125
+ clearEvent: () => void;
126
+ setEventSlot: (key: string, entry: SlotValueEntry) => void;
127
+ addAction: (id: string) => void;
128
+ removeAction: (index: number) => void;
129
+ moveAction: (from: number, to: number) => void;
130
+ setActionSlot: (actionIndex: number, key: string, entry: SlotValueEntry) => void;
131
+ addCondition: (id: string) => void;
132
+ removeCondition: (index: number) => void;
133
+ setConditionSlot: (conditionIndex: number, key: string, entry: SlotValueEntry) => void;
134
+ getValueSources: (valueType?: string) => {
135
+ conditions: War3ConditionDef[];
136
+ tools: Map<string, ToolDef>;
137
+ };
138
+ applyPreset: (preset: Preset<War3Editor>) => void;
139
+ resolveSlotValue: (entry: SlotValueEntry) => unknown;
140
+ }
141
+ declare function createWar3Editor(): War3Editor;
142
+
143
+ declare function getEventDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
144
+ declare function getActionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
145
+ declare function getConditionDescriptor(registry: War3Registry, id: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
146
+ declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
147
+ declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
148
+
149
+ /**
150
+ * 递归解析 SlotValueEntry 为人类可读的展示文本
151
+ *
152
+ * - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
153
+ * - 如果 tool 为 leaf:
154
+ * - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
155
+ * - 其它类型:返回 value 的字符串形式
156
+ * - 若 value 为空:返回 fallbackLabel
157
+ * - 如果 tool 为 composite:使用 tool 的 template 递归展开
158
+ */
159
+ declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
160
+
161
+ /**
162
+ * 类型安全地定义 LeafTool
163
+ * 用户通过回调参数注解来指定输入类型,TS 自动推导输出类型
164
+ */
165
+ declare function defineLeafTool<TInput, TOutput>(def: {
166
+ type?: string;
167
+ label: string;
168
+ input: LeafToolInput<TInput>;
169
+ resolve: (input: TInput) => TOutput;
170
+ }): {
171
+ kind: "leaf";
172
+ type?: string;
173
+ label: string;
174
+ input: LeafToolInput<TInput>;
175
+ resolve: (input: TInput) => TOutput;
176
+ };
177
+ /**
178
+ * 类型安全地定义 CompositeTool
179
+ * 用户注解 resolve 回调参数来指定 slot 值类型,TS 验证 slots keys 一致性
180
+ */
181
+ declare function defineCompositeTool<TSlotValues extends Record<string, unknown>, TOutput>(def: {
182
+ type?: string;
183
+ label: string;
184
+ template: string;
185
+ slots: Record<keyof TSlotValues & string, SlotDef>;
186
+ resolve: (slotValues: TSlotValues) => TOutput;
187
+ }): CompositeToolDef<TSlotValues, TOutput>;
188
+ /**
189
+ * 类型安全地定义 Condition
190
+ */
191
+ declare function defineCondition<TSlotValues extends Record<string, unknown> = Record<string, unknown>>(def: Omit<War3ConditionDef<TSlotValues>, 'resolve'> & {
192
+ resolve?: (slotValues: TSlotValues) => unknown;
193
+ }): War3ConditionDef;
194
+
195
+ /**
196
+ * 解析模板字符串为 Segment 数组
197
+ * 模板格式: "普通文本${slotKey}更多文本"
198
+ */
199
+ declare function parseTemplate(template: string, slots?: Record<string, SlotDef>, slotValues?: Record<string, SlotValueEntry>): Segment[];
200
+
201
+ declare function defineWar3Preset(options: War3PresetOptions): Preset<War3Editor>;
202
+
203
+ /**
204
+ * 递归解析单个 slot 值
205
+ */
206
+ declare function resolveSlotValue(entry: SlotValueEntry, registry: War3Registry): Value | undefined;
207
+ /**
208
+ * 将编辑器状态序列化为标准 Rule JSON
209
+ *
210
+ * 输出结构(与 @triggerix/core 兼容):
211
+ * {
212
+ * id, event: { type, payload? }, conditions?: { type:'and', conditions:[...] },
213
+ * actions: [{ type, params? }]
214
+ * }
215
+ */
216
+ declare function toRule(state: War3EditorState, registry: War3Registry, ruleId?: string): Rule;
217
+
218
+ /**
219
+ * War3 编辑器状态管理
220
+ * 继承 ObservableState,提供模板模式特有的状态操作
221
+ */
222
+ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
223
+ constructor();
224
+ setEvent(id: string): void;
225
+ clearEvent(): void;
226
+ setEventSlot(key: string, entry: SlotValueEntry): void;
227
+ addAction(id: string): void;
228
+ removeAction(index: number): void;
229
+ moveAction(from: number, to: number): void;
230
+ setActionSlot(actionIndex: number, key: string, entry: SlotValueEntry): void;
231
+ addCondition(id: string): void;
232
+ removeCondition(index: number): void;
233
+ setConditionSlot(conditionIndex: number, key: string, entry: SlotValueEntry): void;
234
+ reset(): void;
235
+ private setItemSlot;
236
+ }
237
+
238
+ export { War3EditorStateManager, War3Registry, createWar3Editor, defineCompositeTool, defineCondition, defineLeafTool, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toRule };
239
+ export type { CompositeToolDef, CompositeToolDescriptor, ItemDescriptor, ItemState, LeafToolDef, LeafToolDescriptor, LeafToolInput, Segment, SlotDef, SlotValueEntry, ToolDef, ToolDescriptor, War3ActionDef, War3ConditionDef, War3Editor, War3EditorState, War3EventDef, War3PresetOptions };