@vyr/engine 0.0.38 → 0.0.39
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/package.json +2 -2
- package/src/descriptor/Input.ts +2 -2
- package/src/schema/HTML.ts +81 -106
- package/src/scripts/SwitchSceneScriptable.ts +25 -3
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vyr/engine",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.39",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"author": "",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@vyr/locale": "0.0.
|
|
9
|
+
"@vyr/locale": "0.0.39",
|
|
10
10
|
"decamelize-keys": "^2.0.1",
|
|
11
11
|
"camelcase-keys": "^10.0.1",
|
|
12
12
|
"tinycolor2": "1.6.0",
|
package/src/descriptor/Input.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DeserializationObject } from "../Serialization"
|
|
2
|
-
import { HtmlAttributes,
|
|
2
|
+
import { HtmlAttributes, InputAttributesSchema } from "../schema"
|
|
3
3
|
import { Descriptor } from "./Descriptor"
|
|
4
4
|
import { HTML } from "./HTML"
|
|
5
5
|
|
|
@@ -23,7 +23,7 @@ export class Input extends Descriptor implements HTML {
|
|
|
23
23
|
constructor(descriptor: Partial<DeserializationObject<Input>> = {}) {
|
|
24
24
|
super(descriptor)
|
|
25
25
|
this.visible = descriptor.visible ?? true
|
|
26
|
-
this.htmlAttributes =
|
|
26
|
+
this.htmlAttributes = InputAttributesSchema.parse(descriptor.htmlAttributes)
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
Descriptor.register(Input)
|
package/src/schema/HTML.ts
CHANGED
|
@@ -71,109 +71,13 @@ export const HtmlAttributesSchema = z.object({
|
|
|
71
71
|
*/
|
|
72
72
|
classNames: ClassNamesSchema,
|
|
73
73
|
|
|
74
|
-
// ========== Input 元素属性 ==========
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 输入框类型: text, password, email, number, checkbox, radio, file 等
|
|
78
|
-
*/
|
|
79
|
-
type: z.string().optional(),
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 输入框的初始值
|
|
83
|
-
*/
|
|
84
|
-
value: z.union([z.string(), z.number()]).optional(),
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 输入框为空时的提示文本
|
|
88
|
-
*/
|
|
89
|
-
placeholder: z.string().optional(),
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* 是否为必填项
|
|
93
|
-
*/
|
|
94
|
-
required: z.boolean().optional(),
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 正则表达式验证规则
|
|
98
|
-
*/
|
|
99
|
-
pattern: z.string().optional(),
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 最大字符数
|
|
103
|
-
*/
|
|
104
|
-
maxlength: z.number().int().positive().optional(),
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 最小字符数
|
|
108
|
-
*/
|
|
109
|
-
minlength: z.number().int().positive().optional(),
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 数字/日期的最小允许值
|
|
113
|
-
*/
|
|
114
|
-
min: z.union([z.number(), z.string()]).optional(),
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 数字/日期的最大允许值
|
|
118
|
-
*/
|
|
119
|
-
max: z.union([z.number(), z.string()]).optional(),
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 数字/日期的增减步长
|
|
123
|
-
*/
|
|
124
|
-
step: z.union([z.number(), z.string()]).optional(),
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 是否允许多个值(email/file类型)
|
|
128
|
-
*/
|
|
129
|
-
multiple: z.boolean().optional(),
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* 是否禁用输入框
|
|
133
|
-
*/
|
|
134
|
-
disabled: z.boolean().optional(),
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 是否只读
|
|
138
|
-
*/
|
|
139
|
-
readonly: z.boolean().optional(),
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* 复选框/单选框的选中状态
|
|
143
|
-
*/
|
|
144
|
-
checked: z.boolean().optional(),
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 页面加载时自动获得焦点
|
|
148
|
-
*/
|
|
149
|
-
autofocus: z.boolean().optional(),
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 输入框的显示宽度(字符数)
|
|
153
|
-
*/
|
|
154
|
-
size: z.number().int().positive().optional(),
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 浏览器自动填充: on/off/具体字段名
|
|
158
|
-
*/
|
|
159
|
-
autocomplete: z.string().optional(),
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 文件类型限制,如 "image/*", ".pdf,.doc"
|
|
163
|
-
*/
|
|
164
|
-
accept: z.string().optional(),
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* 媒体捕获方式: "environment", "user", true, false
|
|
168
|
-
*/
|
|
169
|
-
capture: z.union([z.string(), z.boolean()]).optional(),
|
|
170
74
|
}).default({ style: HTMLStyleSchema.parse({}), classNames: ClassNamesSchema.parse([]) })
|
|
171
75
|
|
|
172
76
|
/**
|
|
173
77
|
* HTML属性集合
|
|
174
78
|
*
|
|
175
79
|
* 提供结构化的方式定义和管理HTML元素的所有原生属性。
|
|
176
|
-
* style和classNames
|
|
80
|
+
* style和classNames为基础通用属性,其余属性参照DSL定义。
|
|
177
81
|
*
|
|
178
82
|
* classNames(共享CSS类名列表)
|
|
179
83
|
*
|
|
@@ -245,17 +149,88 @@ export const HtmlAttributesSchema = z.object({
|
|
|
245
149
|
* // 与行内样式组合使用(行内样式优先级更高):
|
|
246
150
|
* classNames: ['theme-primary'], // 共享背景色和文字颜色
|
|
247
151
|
* style: { margin: '8px 0' },
|
|
248
|
-
*
|
|
249
|
-
* // Input元素特有属性
|
|
250
|
-
* type: 'text',
|
|
251
|
-
* value: '张三',
|
|
252
|
-
* placeholder: '请输入用户名',
|
|
253
|
-
* required: true,
|
|
254
|
-
* maxlength: 50,
|
|
255
|
-
* pattern: '^[a-zA-Z0-9_]+$',
|
|
256
|
-
* autocomplete: 'off'
|
|
257
152
|
* }
|
|
258
153
|
*
|
|
259
154
|
*/
|
|
260
155
|
export type HtmlAttributes = z.infer<typeof HtmlAttributesSchema>
|
|
261
156
|
|
|
157
|
+
export const InputAttributesSchema = z.object({
|
|
158
|
+
style: HTMLStyleSchema,
|
|
159
|
+
|
|
160
|
+
classNames: ClassNamesSchema,
|
|
161
|
+
|
|
162
|
+
type: z.string().optional(),
|
|
163
|
+
|
|
164
|
+
value: z.union([z.string(), z.number()]).optional(),
|
|
165
|
+
|
|
166
|
+
placeholder: z.string().optional(),
|
|
167
|
+
|
|
168
|
+
required: z.boolean().optional(),
|
|
169
|
+
|
|
170
|
+
pattern: z.string().optional(),
|
|
171
|
+
|
|
172
|
+
maxlength: z.number().int().positive().optional(),
|
|
173
|
+
|
|
174
|
+
minlength: z.number().int().positive().optional(),
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* 数字/日期的最小允许值
|
|
178
|
+
*/
|
|
179
|
+
min: z.union([z.number(), z.string()]).optional(),
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* 数字/日期的最大允许值
|
|
183
|
+
*/
|
|
184
|
+
max: z.union([z.number(), z.string()]).optional(),
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 数字/日期的增减步长
|
|
188
|
+
*/
|
|
189
|
+
step: z.union([z.number(), z.string()]).optional(),
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 是否允许多个值(email/file类型)
|
|
193
|
+
*/
|
|
194
|
+
multiple: z.boolean().optional(),
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* 是否禁用输入框
|
|
198
|
+
*/
|
|
199
|
+
disabled: z.boolean().optional(),
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* 是否只读
|
|
203
|
+
*/
|
|
204
|
+
readonly: z.boolean().optional(),
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 复选框/单选框的选中状态
|
|
208
|
+
*/
|
|
209
|
+
checked: z.boolean().optional(),
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* 页面加载时自动获得焦点
|
|
213
|
+
*/
|
|
214
|
+
autofocus: z.boolean().optional(),
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* 输入框的显示宽度(字符数)
|
|
218
|
+
*/
|
|
219
|
+
size: z.number().int().positive().optional(),
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 浏览器自动填充: on/off/具体字段名
|
|
223
|
+
*/
|
|
224
|
+
autocomplete: z.string().optional(),
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* 文件类型限制,如 "image/*", ".pdf,.doc"
|
|
228
|
+
*/
|
|
229
|
+
accept: z.string().optional(),
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* 媒体捕获方式: "environment", "user", true, false
|
|
233
|
+
*/
|
|
234
|
+
capture: z.union([z.string(), z.boolean()]).optional(),
|
|
235
|
+
}).default({ style: HTMLStyleSchema.parse({}), classNames: ClassNamesSchema.parse([]) })
|
|
236
|
+
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import z from 'zod'
|
|
2
2
|
import { language } from '../locale'
|
|
3
|
+
import { Asset } from '../asset'
|
|
3
4
|
import { Graphics } from '../graphics/Graphics';
|
|
4
5
|
import { Scriptable, ScriptableArgs } from '../Scriptable';
|
|
6
|
+
import { Descriptor, Scene } from '../descriptor';
|
|
5
7
|
|
|
6
8
|
export class SwitchSceneScriptable extends Scriptable {
|
|
7
9
|
static id = 'switch.scene'
|
|
@@ -9,10 +11,30 @@ export class SwitchSceneScriptable extends Scriptable {
|
|
|
9
11
|
static inputSchame = z.object({
|
|
10
12
|
scene: z.string().describe(language.get('scriptable.switchScene.input.scene')),
|
|
11
13
|
})
|
|
14
|
+
current = ''
|
|
12
15
|
|
|
13
|
-
execute(graphics: Graphics, trigger: string, input: z.infer<typeof SwitchSceneScriptable.inputSchame>, args?: ScriptableArgs) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
async execute(graphics: Graphics, trigger: string, input: z.infer<typeof SwitchSceneScriptable.inputSchame>, args?: ScriptableArgs) {
|
|
17
|
+
let loadTask = Asset.getTask(input.scene)
|
|
18
|
+
if (loadTask === null) {
|
|
19
|
+
const nextTask = Asset.getTask(this.current)
|
|
20
|
+
nextTask?.cancel()
|
|
21
|
+
|
|
22
|
+
this.current = input.scene
|
|
23
|
+
await Asset.loadAll(input.scene)
|
|
24
|
+
|
|
25
|
+
let scene: Scene
|
|
26
|
+
const descriptor = Asset.get<Descriptor>(input.scene)
|
|
27
|
+
if (descriptor instanceof Scene) {
|
|
28
|
+
scene = descriptor
|
|
29
|
+
} else {
|
|
30
|
+
scene = new Scene()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Asset.set(this.current, scene)
|
|
34
|
+
Asset.graph.create(input.scene)
|
|
35
|
+
|
|
36
|
+
graphics.engine.switch(scene)
|
|
37
|
+
}
|
|
16
38
|
}
|
|
17
39
|
}
|
|
18
40
|
Scriptable.register(SwitchSceneScriptable)
|