triggerix-ui-preset-war3 0.0.0 → 0.0.2
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/LICENSE +21 -0
- package/dist/index.cjs +53 -1
- package/dist/index.d.cts +31 -13
- package/dist/index.d.mts +31 -13
- package/dist/index.d.ts +31 -13
- package/dist/index.mjs +53 -2
- package/package.json +30 -8
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 imba97 <https://github.com/imba97>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.cjs
CHANGED
|
@@ -20,7 +20,8 @@ function parseTemplate(template, slots, slotValues) {
|
|
|
20
20
|
key,
|
|
21
21
|
label: slotDef.label,
|
|
22
22
|
tools: slotDef.tools,
|
|
23
|
-
value: entry?.value ?? null
|
|
23
|
+
value: entry?.value ?? null,
|
|
24
|
+
entry: entry ?? void 0
|
|
24
25
|
});
|
|
25
26
|
} else {
|
|
26
27
|
segments.push({ type: "text", content: match[0] });
|
|
@@ -273,6 +274,8 @@ function createWar3Editor() {
|
|
|
273
274
|
registerAction: (def) => registry.registerAction(def),
|
|
274
275
|
registerCondition: (def) => registry.registerCondition(def),
|
|
275
276
|
registerTool: (name, def) => registry.registerTool(name, def),
|
|
277
|
+
// --- 注册表访问 ---
|
|
278
|
+
getRegistry: () => registry,
|
|
276
279
|
// --- 查询 ---
|
|
277
280
|
getAvailableEvents: () => registry.getEvents(),
|
|
278
281
|
getAvailableActions: () => registry.getActions(),
|
|
@@ -321,6 +324,54 @@ function createWar3Editor() {
|
|
|
321
324
|
return editor;
|
|
322
325
|
}
|
|
323
326
|
|
|
327
|
+
function valueEquals(a, b) {
|
|
328
|
+
if (a === b) return true;
|
|
329
|
+
if (a == null || b == null) return false;
|
|
330
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
331
|
+
try {
|
|
332
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
333
|
+
} catch {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function stringifyValue(v) {
|
|
338
|
+
if (v == null) return "";
|
|
339
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
340
|
+
return String(v);
|
|
341
|
+
try {
|
|
342
|
+
return JSON.stringify(v);
|
|
343
|
+
} catch {
|
|
344
|
+
return String(v);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
function resolveSlotDisplayText(entry, registry, fallbackLabel) {
|
|
348
|
+
if (!entry?.tool)
|
|
349
|
+
return fallbackLabel;
|
|
350
|
+
const toolDef = registry.getTool(entry.tool);
|
|
351
|
+
if (!toolDef)
|
|
352
|
+
return fallbackLabel;
|
|
353
|
+
if (toolDef.type === "leaf") {
|
|
354
|
+
if (entry.value == null || entry.value === "")
|
|
355
|
+
return fallbackLabel;
|
|
356
|
+
if (toolDef.input.type === "select") {
|
|
357
|
+
const opt = toolDef.input.options?.find((o) => valueEquals(o.value, entry.value));
|
|
358
|
+
if (opt)
|
|
359
|
+
return opt.label;
|
|
360
|
+
}
|
|
361
|
+
return stringifyValue(entry.value);
|
|
362
|
+
}
|
|
363
|
+
const segments = parseTemplate(toolDef.template, toolDef.slots, entry.subSlots ?? {});
|
|
364
|
+
return segments.map((seg) => {
|
|
365
|
+
if (seg.type === "text")
|
|
366
|
+
return seg.content;
|
|
367
|
+
if (seg.type === "slot") {
|
|
368
|
+
const subEntry = entry.subSlots?.[seg.key];
|
|
369
|
+
return resolveSlotDisplayText(subEntry ?? null, registry, seg.label);
|
|
370
|
+
}
|
|
371
|
+
return "";
|
|
372
|
+
}).join("");
|
|
373
|
+
}
|
|
374
|
+
|
|
324
375
|
function defineWar3Preset(options) {
|
|
325
376
|
return {
|
|
326
377
|
name: options.name,
|
|
@@ -347,5 +398,6 @@ exports.getEventDescriptor = getEventDescriptor;
|
|
|
347
398
|
exports.getSlotToolDescriptors = getSlotToolDescriptors;
|
|
348
399
|
exports.getToolDescriptor = getToolDescriptor;
|
|
349
400
|
exports.parseTemplate = parseTemplate;
|
|
401
|
+
exports.resolveSlotDisplayText = resolveSlotDisplayText;
|
|
350
402
|
exports.resolveSlotValue = resolveSlotValue;
|
|
351
403
|
exports.toRule = toRule;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
|
|
2
2
|
export { Preset } from '@triggerix/editor';
|
|
3
3
|
import { Rule } from '@triggerix/core';
|
|
4
4
|
|
|
5
|
+
interface BaseItemDef {
|
|
6
|
+
type: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
5
9
|
interface SlotDef {
|
|
6
10
|
label: string;
|
|
7
11
|
tools: string[];
|
|
@@ -15,7 +19,7 @@ interface LeafToolInput {
|
|
|
15
19
|
type: 'text' | 'number' | 'select';
|
|
16
20
|
placeholder?: string;
|
|
17
21
|
options?: Array<{
|
|
18
|
-
value:
|
|
22
|
+
value: unknown;
|
|
19
23
|
label: string;
|
|
20
24
|
}>;
|
|
21
25
|
}
|
|
@@ -54,6 +58,7 @@ type Segment = {
|
|
|
54
58
|
label: string;
|
|
55
59
|
tools: string[];
|
|
56
60
|
value: unknown;
|
|
61
|
+
entry?: SlotValueEntry;
|
|
57
62
|
};
|
|
58
63
|
interface ItemDescriptor {
|
|
59
64
|
type: string;
|
|
@@ -89,11 +94,22 @@ interface War3PresetOptions {
|
|
|
89
94
|
tools?: Record<string, ToolDef>;
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
/**
|
|
98
|
+
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
99
|
+
*/
|
|
100
|
+
declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
|
|
101
|
+
private tools;
|
|
102
|
+
registerTool(name: string, def: ToolDef): void;
|
|
103
|
+
getTool(name: string): ToolDef | undefined;
|
|
104
|
+
getTools(): Map<string, ToolDef>;
|
|
105
|
+
}
|
|
106
|
+
|
|
92
107
|
interface War3Editor extends Editor<War3EditorState> {
|
|
93
108
|
registerEvent: (def: War3EventDef) => void;
|
|
94
109
|
registerAction: (def: War3ActionDef) => void;
|
|
95
110
|
registerCondition: (def: War3ConditionDef) => void;
|
|
96
111
|
registerTool: (name: string, def: ToolDef) => void;
|
|
112
|
+
getRegistry: () => War3Registry;
|
|
97
113
|
getAvailableEvents: () => War3EventDef[];
|
|
98
114
|
getAvailableActions: () => War3ActionDef[];
|
|
99
115
|
getAvailableConditions: () => War3ConditionDef[];
|
|
@@ -117,22 +133,24 @@ interface War3Editor extends Editor<War3EditorState> {
|
|
|
117
133
|
}
|
|
118
134
|
declare function createWar3Editor(): War3Editor;
|
|
119
135
|
|
|
120
|
-
/**
|
|
121
|
-
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
122
|
-
*/
|
|
123
|
-
declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
|
|
124
|
-
private tools;
|
|
125
|
-
registerTool(name: string, def: ToolDef): void;
|
|
126
|
-
getTool(name: string): ToolDef | undefined;
|
|
127
|
-
getTools(): Map<string, ToolDef>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
136
|
declare function getEventDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
131
137
|
declare function getActionDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
132
138
|
declare function getConditionDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
133
139
|
declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
|
|
134
140
|
declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
|
|
135
141
|
|
|
142
|
+
/**
|
|
143
|
+
* 递归解析 SlotValueEntry 为人类可读的展示文本
|
|
144
|
+
*
|
|
145
|
+
* - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
|
|
146
|
+
* - 如果 tool 为 leaf:
|
|
147
|
+
* - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
|
|
148
|
+
* - 其它类型:返回 value 的字符串形式
|
|
149
|
+
* - 若 value 为空:返回 fallbackLabel
|
|
150
|
+
* - 如果 tool 为 composite:使用 tool 的 template 递归展开
|
|
151
|
+
*/
|
|
152
|
+
declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
|
|
153
|
+
|
|
136
154
|
/**
|
|
137
155
|
* 解析模板字符串为 Segment 数组
|
|
138
156
|
* 模板格式: "普通文本${slotKey}更多文本"
|
|
@@ -178,5 +196,5 @@ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
|
178
196
|
reset(): void;
|
|
179
197
|
}
|
|
180
198
|
|
|
181
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotValue, toRule };
|
|
199
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toRule };
|
|
182
200
|
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,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
|
|
2
2
|
export { Preset } from '@triggerix/editor';
|
|
3
3
|
import { Rule } from '@triggerix/core';
|
|
4
4
|
|
|
5
|
+
interface BaseItemDef {
|
|
6
|
+
type: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
5
9
|
interface SlotDef {
|
|
6
10
|
label: string;
|
|
7
11
|
tools: string[];
|
|
@@ -15,7 +19,7 @@ interface LeafToolInput {
|
|
|
15
19
|
type: 'text' | 'number' | 'select';
|
|
16
20
|
placeholder?: string;
|
|
17
21
|
options?: Array<{
|
|
18
|
-
value:
|
|
22
|
+
value: unknown;
|
|
19
23
|
label: string;
|
|
20
24
|
}>;
|
|
21
25
|
}
|
|
@@ -54,6 +58,7 @@ type Segment = {
|
|
|
54
58
|
label: string;
|
|
55
59
|
tools: string[];
|
|
56
60
|
value: unknown;
|
|
61
|
+
entry?: SlotValueEntry;
|
|
57
62
|
};
|
|
58
63
|
interface ItemDescriptor {
|
|
59
64
|
type: string;
|
|
@@ -89,11 +94,22 @@ interface War3PresetOptions {
|
|
|
89
94
|
tools?: Record<string, ToolDef>;
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
/**
|
|
98
|
+
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
99
|
+
*/
|
|
100
|
+
declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
|
|
101
|
+
private tools;
|
|
102
|
+
registerTool(name: string, def: ToolDef): void;
|
|
103
|
+
getTool(name: string): ToolDef | undefined;
|
|
104
|
+
getTools(): Map<string, ToolDef>;
|
|
105
|
+
}
|
|
106
|
+
|
|
92
107
|
interface War3Editor extends Editor<War3EditorState> {
|
|
93
108
|
registerEvent: (def: War3EventDef) => void;
|
|
94
109
|
registerAction: (def: War3ActionDef) => void;
|
|
95
110
|
registerCondition: (def: War3ConditionDef) => void;
|
|
96
111
|
registerTool: (name: string, def: ToolDef) => void;
|
|
112
|
+
getRegistry: () => War3Registry;
|
|
97
113
|
getAvailableEvents: () => War3EventDef[];
|
|
98
114
|
getAvailableActions: () => War3ActionDef[];
|
|
99
115
|
getAvailableConditions: () => War3ConditionDef[];
|
|
@@ -117,22 +133,24 @@ interface War3Editor extends Editor<War3EditorState> {
|
|
|
117
133
|
}
|
|
118
134
|
declare function createWar3Editor(): War3Editor;
|
|
119
135
|
|
|
120
|
-
/**
|
|
121
|
-
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
122
|
-
*/
|
|
123
|
-
declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
|
|
124
|
-
private tools;
|
|
125
|
-
registerTool(name: string, def: ToolDef): void;
|
|
126
|
-
getTool(name: string): ToolDef | undefined;
|
|
127
|
-
getTools(): Map<string, ToolDef>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
136
|
declare function getEventDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
131
137
|
declare function getActionDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
132
138
|
declare function getConditionDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
133
139
|
declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
|
|
134
140
|
declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
|
|
135
141
|
|
|
142
|
+
/**
|
|
143
|
+
* 递归解析 SlotValueEntry 为人类可读的展示文本
|
|
144
|
+
*
|
|
145
|
+
* - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
|
|
146
|
+
* - 如果 tool 为 leaf:
|
|
147
|
+
* - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
|
|
148
|
+
* - 其它类型:返回 value 的字符串形式
|
|
149
|
+
* - 若 value 为空:返回 fallbackLabel
|
|
150
|
+
* - 如果 tool 为 composite:使用 tool 的 template 递归展开
|
|
151
|
+
*/
|
|
152
|
+
declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
|
|
153
|
+
|
|
136
154
|
/**
|
|
137
155
|
* 解析模板字符串为 Segment 数组
|
|
138
156
|
* 模板格式: "普通文本${slotKey}更多文本"
|
|
@@ -178,5 +196,5 @@ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
|
178
196
|
reset(): void;
|
|
179
197
|
}
|
|
180
198
|
|
|
181
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotValue, toRule };
|
|
199
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toRule };
|
|
182
200
|
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,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseRegistry, Editor, Preset, ObservableState } from '@triggerix/editor';
|
|
2
2
|
export { Preset } from '@triggerix/editor';
|
|
3
3
|
import { Rule } from '@triggerix/core';
|
|
4
4
|
|
|
5
|
+
interface BaseItemDef {
|
|
6
|
+
type: string;
|
|
7
|
+
label?: string;
|
|
8
|
+
}
|
|
5
9
|
interface SlotDef {
|
|
6
10
|
label: string;
|
|
7
11
|
tools: string[];
|
|
@@ -15,7 +19,7 @@ interface LeafToolInput {
|
|
|
15
19
|
type: 'text' | 'number' | 'select';
|
|
16
20
|
placeholder?: string;
|
|
17
21
|
options?: Array<{
|
|
18
|
-
value:
|
|
22
|
+
value: unknown;
|
|
19
23
|
label: string;
|
|
20
24
|
}>;
|
|
21
25
|
}
|
|
@@ -54,6 +58,7 @@ type Segment = {
|
|
|
54
58
|
label: string;
|
|
55
59
|
tools: string[];
|
|
56
60
|
value: unknown;
|
|
61
|
+
entry?: SlotValueEntry;
|
|
57
62
|
};
|
|
58
63
|
interface ItemDescriptor {
|
|
59
64
|
type: string;
|
|
@@ -89,11 +94,22 @@ interface War3PresetOptions {
|
|
|
89
94
|
tools?: Record<string, ToolDef>;
|
|
90
95
|
}
|
|
91
96
|
|
|
97
|
+
/**
|
|
98
|
+
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
99
|
+
*/
|
|
100
|
+
declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
|
|
101
|
+
private tools;
|
|
102
|
+
registerTool(name: string, def: ToolDef): void;
|
|
103
|
+
getTool(name: string): ToolDef | undefined;
|
|
104
|
+
getTools(): Map<string, ToolDef>;
|
|
105
|
+
}
|
|
106
|
+
|
|
92
107
|
interface War3Editor extends Editor<War3EditorState> {
|
|
93
108
|
registerEvent: (def: War3EventDef) => void;
|
|
94
109
|
registerAction: (def: War3ActionDef) => void;
|
|
95
110
|
registerCondition: (def: War3ConditionDef) => void;
|
|
96
111
|
registerTool: (name: string, def: ToolDef) => void;
|
|
112
|
+
getRegistry: () => War3Registry;
|
|
97
113
|
getAvailableEvents: () => War3EventDef[];
|
|
98
114
|
getAvailableActions: () => War3ActionDef[];
|
|
99
115
|
getAvailableConditions: () => War3ConditionDef[];
|
|
@@ -117,22 +133,24 @@ interface War3Editor extends Editor<War3EditorState> {
|
|
|
117
133
|
}
|
|
118
134
|
declare function createWar3Editor(): War3Editor;
|
|
119
135
|
|
|
120
|
-
/**
|
|
121
|
-
* War3 注册表 - 继承 BaseRegistry,增加 Tool 注册能力
|
|
122
|
-
*/
|
|
123
|
-
declare class War3Registry extends BaseRegistry<War3EventDef, War3ActionDef, War3ConditionDef> {
|
|
124
|
-
private tools;
|
|
125
|
-
registerTool(name: string, def: ToolDef): void;
|
|
126
|
-
getTool(name: string): ToolDef | undefined;
|
|
127
|
-
getTools(): Map<string, ToolDef>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
136
|
declare function getEventDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
131
137
|
declare function getActionDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
132
138
|
declare function getConditionDescriptor(registry: War3Registry, type: string, slotValues?: Record<string, SlotValueEntry>): ItemDescriptor | null;
|
|
133
139
|
declare function getToolDescriptor(registry: War3Registry, toolName: string, slotValues?: Record<string, SlotValueEntry>): ToolDescriptor | null;
|
|
134
140
|
declare function getSlotToolDescriptors(registry: War3Registry, slotDef: SlotDef): ToolDescriptor[];
|
|
135
141
|
|
|
142
|
+
/**
|
|
143
|
+
* 递归解析 SlotValueEntry 为人类可读的展示文本
|
|
144
|
+
*
|
|
145
|
+
* - 如果 entry 为 null/undefined 或未选择 tool,返回 fallbackLabel(slot 占位文案)
|
|
146
|
+
* - 如果 tool 为 leaf:
|
|
147
|
+
* - select 类型:尝试匹配 options 找到对应 label(支持对象值的深比较)
|
|
148
|
+
* - 其它类型:返回 value 的字符串形式
|
|
149
|
+
* - 若 value 为空:返回 fallbackLabel
|
|
150
|
+
* - 如果 tool 为 composite:使用 tool 的 template 递归展开
|
|
151
|
+
*/
|
|
152
|
+
declare function resolveSlotDisplayText(entry: SlotValueEntry | null | undefined, registry: War3Registry, fallbackLabel: string): string;
|
|
153
|
+
|
|
136
154
|
/**
|
|
137
155
|
* 解析模板字符串为 Segment 数组
|
|
138
156
|
* 模板格式: "普通文本${slotKey}更多文本"
|
|
@@ -178,5 +196,5 @@ declare class War3EditorStateManager extends ObservableState<War3EditorState> {
|
|
|
178
196
|
reset(): void;
|
|
179
197
|
}
|
|
180
198
|
|
|
181
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotValue, toRule };
|
|
199
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toRule };
|
|
182
200
|
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
|
@@ -18,7 +18,8 @@ function parseTemplate(template, slots, slotValues) {
|
|
|
18
18
|
key,
|
|
19
19
|
label: slotDef.label,
|
|
20
20
|
tools: slotDef.tools,
|
|
21
|
-
value: entry?.value ?? null
|
|
21
|
+
value: entry?.value ?? null,
|
|
22
|
+
entry: entry ?? void 0
|
|
22
23
|
});
|
|
23
24
|
} else {
|
|
24
25
|
segments.push({ type: "text", content: match[0] });
|
|
@@ -271,6 +272,8 @@ function createWar3Editor() {
|
|
|
271
272
|
registerAction: (def) => registry.registerAction(def),
|
|
272
273
|
registerCondition: (def) => registry.registerCondition(def),
|
|
273
274
|
registerTool: (name, def) => registry.registerTool(name, def),
|
|
275
|
+
// --- 注册表访问 ---
|
|
276
|
+
getRegistry: () => registry,
|
|
274
277
|
// --- 查询 ---
|
|
275
278
|
getAvailableEvents: () => registry.getEvents(),
|
|
276
279
|
getAvailableActions: () => registry.getActions(),
|
|
@@ -319,6 +322,54 @@ function createWar3Editor() {
|
|
|
319
322
|
return editor;
|
|
320
323
|
}
|
|
321
324
|
|
|
325
|
+
function valueEquals(a, b) {
|
|
326
|
+
if (a === b) return true;
|
|
327
|
+
if (a == null || b == null) return false;
|
|
328
|
+
if (typeof a !== "object" || typeof b !== "object") return false;
|
|
329
|
+
try {
|
|
330
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
331
|
+
} catch {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function stringifyValue(v) {
|
|
336
|
+
if (v == null) return "";
|
|
337
|
+
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
338
|
+
return String(v);
|
|
339
|
+
try {
|
|
340
|
+
return JSON.stringify(v);
|
|
341
|
+
} catch {
|
|
342
|
+
return String(v);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function resolveSlotDisplayText(entry, registry, fallbackLabel) {
|
|
346
|
+
if (!entry?.tool)
|
|
347
|
+
return fallbackLabel;
|
|
348
|
+
const toolDef = registry.getTool(entry.tool);
|
|
349
|
+
if (!toolDef)
|
|
350
|
+
return fallbackLabel;
|
|
351
|
+
if (toolDef.type === "leaf") {
|
|
352
|
+
if (entry.value == null || entry.value === "")
|
|
353
|
+
return fallbackLabel;
|
|
354
|
+
if (toolDef.input.type === "select") {
|
|
355
|
+
const opt = toolDef.input.options?.find((o) => valueEquals(o.value, entry.value));
|
|
356
|
+
if (opt)
|
|
357
|
+
return opt.label;
|
|
358
|
+
}
|
|
359
|
+
return stringifyValue(entry.value);
|
|
360
|
+
}
|
|
361
|
+
const segments = parseTemplate(toolDef.template, toolDef.slots, entry.subSlots ?? {});
|
|
362
|
+
return segments.map((seg) => {
|
|
363
|
+
if (seg.type === "text")
|
|
364
|
+
return seg.content;
|
|
365
|
+
if (seg.type === "slot") {
|
|
366
|
+
const subEntry = entry.subSlots?.[seg.key];
|
|
367
|
+
return resolveSlotDisplayText(subEntry ?? null, registry, seg.label);
|
|
368
|
+
}
|
|
369
|
+
return "";
|
|
370
|
+
}).join("");
|
|
371
|
+
}
|
|
372
|
+
|
|
322
373
|
function defineWar3Preset(options) {
|
|
323
374
|
return {
|
|
324
375
|
name: options.name,
|
|
@@ -335,4 +386,4 @@ function defineWar3Preset(options) {
|
|
|
335
386
|
};
|
|
336
387
|
}
|
|
337
388
|
|
|
338
|
-
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotValue, toRule };
|
|
389
|
+
export { War3EditorStateManager, War3Registry, createWar3Editor, defineWar3Preset, getActionDescriptor, getConditionDescriptor, getEventDescriptor, getSlotToolDescriptors, getToolDescriptor, parseTemplate, resolveSlotDisplayText, resolveSlotValue, toRule };
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "triggerix-ui-preset-war3",
|
|
3
|
-
"version": "0.0.0",
|
|
4
|
-
"description": "War3-style template editor preset for Triggerix",
|
|
5
3
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
4
|
+
"version": "0.0.2",
|
|
5
|
+
"description": "War3-style template editor preset for Triggerix",
|
|
6
|
+
"homepage": "https://github.com/triggerix-lang/triggerix-ui-preset-war3#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git@github.com:triggerix-lang/triggerix-ui-preset-war3.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/triggerix-lang/triggerix-ui-preset-war3/issues"
|
|
13
|
+
},
|
|
9
14
|
"exports": {
|
|
10
15
|
".": {
|
|
11
16
|
"types": "./dist/index.d.ts",
|
|
@@ -13,20 +18,37 @@
|
|
|
13
18
|
"require": "./dist/index.cjs"
|
|
14
19
|
}
|
|
15
20
|
},
|
|
21
|
+
"main": "./dist/index.cjs",
|
|
22
|
+
"module": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
16
24
|
"files": [
|
|
17
25
|
"dist"
|
|
18
26
|
],
|
|
19
27
|
"dependencies": {
|
|
20
|
-
"@triggerix/core": "^0.0.
|
|
21
|
-
"@triggerix/editor": "^0.0.
|
|
28
|
+
"@triggerix/core": "^0.0.4",
|
|
29
|
+
"@triggerix/editor": "^0.0.4"
|
|
22
30
|
},
|
|
23
31
|
"devDependencies": {
|
|
32
|
+
"@antfu/eslint-config": "^9.0.0",
|
|
33
|
+
"bumpp": "^11.1.0",
|
|
34
|
+
"eslint": "^10.5.0",
|
|
35
|
+
"jiti": "^2.7.0",
|
|
36
|
+
"nano-staged": "^1.0.2",
|
|
37
|
+
"simple-git-hooks": "^2.13.1",
|
|
24
38
|
"typescript": "^6.0.3",
|
|
25
39
|
"unbuild": "^3.6.1"
|
|
26
40
|
},
|
|
41
|
+
"simple-git-hooks": {
|
|
42
|
+
"pre-commit": "pnpm nano-staged"
|
|
43
|
+
},
|
|
44
|
+
"nano-staged": {
|
|
45
|
+
"*": "eslint --cache --fix"
|
|
46
|
+
},
|
|
27
47
|
"scripts": {
|
|
28
48
|
"build": "unbuild",
|
|
29
49
|
"dev": "unbuild --stub",
|
|
30
|
-
"
|
|
50
|
+
"lint": "eslint --cache",
|
|
51
|
+
"typecheck": "tsc --noEmit",
|
|
52
|
+
"release": "bumpp"
|
|
31
53
|
}
|
|
32
54
|
}
|