@routevn/creator-model 1.0.5 → 1.1.0
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 +1 -1
- package/src/model.js +108 -8
package/package.json
CHANGED
package/src/model.js
CHANGED
|
@@ -112,6 +112,7 @@ const LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS = ["left", "center", "right"];
|
|
|
112
112
|
const LAYOUT_ELEMENT_BASE_TYPES = [
|
|
113
113
|
"folder",
|
|
114
114
|
"container",
|
|
115
|
+
"rect",
|
|
115
116
|
"sprite",
|
|
116
117
|
"text",
|
|
117
118
|
"text-revealing",
|
|
@@ -387,8 +388,8 @@ const validateSceneItems = ({ items, path, errorFactory }) => {
|
|
|
387
388
|
value: item,
|
|
388
389
|
allowedKeys:
|
|
389
390
|
item?.type === "scene"
|
|
390
|
-
? ["id", "type", "name", "position", "sections"]
|
|
391
|
-
: ["id", "type", "name", "position"],
|
|
391
|
+
? ["id", "type", "name", "description", "position", "sections"]
|
|
392
|
+
: ["id", "type", "name", "description", "position"],
|
|
392
393
|
path: itemPath,
|
|
393
394
|
errorFactory,
|
|
394
395
|
});
|
|
@@ -425,6 +426,13 @@ const validateSceneItems = ({ items, path, errorFactory }) => {
|
|
|
425
426
|
);
|
|
426
427
|
}
|
|
427
428
|
|
|
429
|
+
if (item.description !== undefined && !isString(item.description)) {
|
|
430
|
+
return invalidFromErrorFactory(
|
|
431
|
+
errorFactory,
|
|
432
|
+
`${itemPath}.description must be a string when provided`,
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
|
|
428
436
|
{
|
|
429
437
|
const result = validateOptionalPosition({
|
|
430
438
|
value: item.position,
|
|
@@ -2121,6 +2129,47 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
|
|
|
2121
2129
|
}
|
|
2122
2130
|
};
|
|
2123
2131
|
|
|
2132
|
+
const validateLayoutElementBorder = ({ border, path, errorFactory }) => {
|
|
2133
|
+
{
|
|
2134
|
+
const result = validateAllowedKeys({
|
|
2135
|
+
value: border,
|
|
2136
|
+
allowedKeys: ["color", "alpha", "width"],
|
|
2137
|
+
path,
|
|
2138
|
+
errorFactory,
|
|
2139
|
+
});
|
|
2140
|
+
if (result?.valid === false) {
|
|
2141
|
+
return result;
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
if (border.color !== undefined && !isString(border.color)) {
|
|
2146
|
+
return invalidFromErrorFactory(
|
|
2147
|
+
errorFactory,
|
|
2148
|
+
`${path}.color must be a string when provided`,
|
|
2149
|
+
);
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
if (
|
|
2153
|
+
border.alpha !== undefined &&
|
|
2154
|
+
(!isFiniteNumber(border.alpha) || border.alpha < 0 || border.alpha > 1)
|
|
2155
|
+
) {
|
|
2156
|
+
return invalidFromErrorFactory(
|
|
2157
|
+
errorFactory,
|
|
2158
|
+
`${path}.alpha must be a finite number between 0 and 1 when provided`,
|
|
2159
|
+
);
|
|
2160
|
+
}
|
|
2161
|
+
|
|
2162
|
+
if (
|
|
2163
|
+
border.width !== undefined &&
|
|
2164
|
+
(!isFiniteNumber(border.width) || border.width < 0)
|
|
2165
|
+
) {
|
|
2166
|
+
return invalidFromErrorFactory(
|
|
2167
|
+
errorFactory,
|
|
2168
|
+
`${path}.width must be a finite number greater than or equal to 0 when provided`,
|
|
2169
|
+
);
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
|
|
2124
2173
|
const validateLayoutElementData = ({
|
|
2125
2174
|
data,
|
|
2126
2175
|
path,
|
|
@@ -2144,6 +2193,8 @@ const validateLayoutElementData = ({
|
|
|
2144
2193
|
"scaleY",
|
|
2145
2194
|
"rotation",
|
|
2146
2195
|
"opacity",
|
|
2196
|
+
"fill",
|
|
2197
|
+
"border",
|
|
2147
2198
|
"text",
|
|
2148
2199
|
"style",
|
|
2149
2200
|
"displaySpeed",
|
|
@@ -2273,6 +2324,13 @@ const validateLayoutElementData = ({
|
|
|
2273
2324
|
}
|
|
2274
2325
|
}
|
|
2275
2326
|
|
|
2327
|
+
if (data.fill !== undefined && !isString(data.fill)) {
|
|
2328
|
+
return invalidFromErrorFactory(
|
|
2329
|
+
errorFactory,
|
|
2330
|
+
`${path}.fill must be a string when provided`,
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2276
2334
|
if (
|
|
2277
2335
|
data.direction !== undefined &&
|
|
2278
2336
|
data.direction !== "horizontal" &&
|
|
@@ -2314,6 +2372,26 @@ const validateLayoutElementData = ({
|
|
|
2314
2372
|
}
|
|
2315
2373
|
}
|
|
2316
2374
|
|
|
2375
|
+
if (data.border !== undefined) {
|
|
2376
|
+
if (!isPlainObject(data.border)) {
|
|
2377
|
+
return invalidFromErrorFactory(
|
|
2378
|
+
errorFactory,
|
|
2379
|
+
`${path}.border must be an object when provided`,
|
|
2380
|
+
);
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
{
|
|
2384
|
+
const result = validateLayoutElementBorder({
|
|
2385
|
+
border: data.border,
|
|
2386
|
+
path: `${path}.border`,
|
|
2387
|
+
errorFactory,
|
|
2388
|
+
});
|
|
2389
|
+
if (result?.valid === false) {
|
|
2390
|
+
return result;
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2317
2395
|
if (data.click !== undefined && !isPlainObject(data.click)) {
|
|
2318
2396
|
return invalidFromErrorFactory(
|
|
2319
2397
|
errorFactory,
|
|
@@ -2357,6 +2435,8 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
|
|
|
2357
2435
|
"scaleY",
|
|
2358
2436
|
"rotation",
|
|
2359
2437
|
"opacity",
|
|
2438
|
+
"fill",
|
|
2439
|
+
"border",
|
|
2360
2440
|
"text",
|
|
2361
2441
|
"style",
|
|
2362
2442
|
"displaySpeed",
|
|
@@ -2630,7 +2710,6 @@ const validateLayoutItems = ({ items, path, errorFactory }) => {
|
|
|
2630
2710
|
return result;
|
|
2631
2711
|
}
|
|
2632
2712
|
}
|
|
2633
|
-
|
|
2634
2713
|
}
|
|
2635
2714
|
}
|
|
2636
2715
|
};
|
|
@@ -4085,7 +4164,7 @@ const validateSceneCreateData = ({ data, errorFactory }) => {
|
|
|
4085
4164
|
{
|
|
4086
4165
|
const result = validateAllowedKeys({
|
|
4087
4166
|
value: data,
|
|
4088
|
-
allowedKeys: ["name", "type", "position"],
|
|
4167
|
+
allowedKeys: ["name", "description", "type", "position"],
|
|
4089
4168
|
path: "payload.data",
|
|
4090
4169
|
errorFactory,
|
|
4091
4170
|
});
|
|
@@ -4101,6 +4180,13 @@ const validateSceneCreateData = ({ data, errorFactory }) => {
|
|
|
4101
4180
|
);
|
|
4102
4181
|
}
|
|
4103
4182
|
|
|
4183
|
+
if (data.description !== undefined && !isString(data.description)) {
|
|
4184
|
+
return invalidFromErrorFactory(
|
|
4185
|
+
errorFactory,
|
|
4186
|
+
"payload.data.description must be a string when provided",
|
|
4187
|
+
);
|
|
4188
|
+
}
|
|
4189
|
+
|
|
4104
4190
|
if (
|
|
4105
4191
|
data.type !== undefined &&
|
|
4106
4192
|
data.type !== "scene" &&
|
|
@@ -4128,7 +4214,7 @@ const validateSceneUpdateData = ({ data, errorFactory }) => {
|
|
|
4128
4214
|
{
|
|
4129
4215
|
const result = validateAllowedKeys({
|
|
4130
4216
|
value: data,
|
|
4131
|
-
allowedKeys: ["name", "position"],
|
|
4217
|
+
allowedKeys: ["name", "description", "position"],
|
|
4132
4218
|
path: "payload.data",
|
|
4133
4219
|
errorFactory,
|
|
4134
4220
|
});
|
|
@@ -4138,9 +4224,10 @@ const validateSceneUpdateData = ({ data, errorFactory }) => {
|
|
|
4138
4224
|
}
|
|
4139
4225
|
|
|
4140
4226
|
const hasName = data.name !== undefined;
|
|
4227
|
+
const hasDescription = data.description !== undefined;
|
|
4141
4228
|
const hasPosition = data.position !== undefined;
|
|
4142
4229
|
|
|
4143
|
-
if (!hasName && !hasPosition) {
|
|
4230
|
+
if (!hasName && !hasDescription && !hasPosition) {
|
|
4144
4231
|
return invalidFromErrorFactory(
|
|
4145
4232
|
errorFactory,
|
|
4146
4233
|
"payload.data must include at least one updatable field",
|
|
@@ -4154,6 +4241,13 @@ const validateSceneUpdateData = ({ data, errorFactory }) => {
|
|
|
4154
4241
|
);
|
|
4155
4242
|
}
|
|
4156
4243
|
|
|
4244
|
+
if (hasDescription && !isString(data.description)) {
|
|
4245
|
+
return invalidFromErrorFactory(
|
|
4246
|
+
errorFactory,
|
|
4247
|
+
"payload.data.description must be a string when provided",
|
|
4248
|
+
);
|
|
4249
|
+
}
|
|
4250
|
+
|
|
4157
4251
|
if (hasPosition) {
|
|
4158
4252
|
{
|
|
4159
4253
|
const result = validateOptionalPosition({
|
|
@@ -6055,7 +6149,6 @@ const validateLayoutCreateData = ({ data, errorFactory }) => {
|
|
|
6055
6149
|
return result;
|
|
6056
6150
|
}
|
|
6057
6151
|
}
|
|
6058
|
-
|
|
6059
6152
|
}
|
|
6060
6153
|
};
|
|
6061
6154
|
|
|
@@ -6095,7 +6188,6 @@ const validateLayoutUpdateData = ({ data, errorFactory }) => {
|
|
|
6095
6188
|
"payload.data.layoutType must be 'normal', 'dialogue', 'nvl', or 'choice' when provided",
|
|
6096
6189
|
);
|
|
6097
6190
|
}
|
|
6098
|
-
|
|
6099
6191
|
};
|
|
6100
6192
|
|
|
6101
6193
|
const validateControlCreateData = ({ data, errorFactory }) => {
|
|
@@ -7326,6 +7418,10 @@ const COMMAND_DEFINITIONS = [
|
|
|
7326
7418
|
name: payload.data.name,
|
|
7327
7419
|
};
|
|
7328
7420
|
|
|
7421
|
+
if (payload.data.description !== undefined) {
|
|
7422
|
+
nextScene.description = payload.data.description;
|
|
7423
|
+
}
|
|
7424
|
+
|
|
7329
7425
|
if (nextScene.type === "scene") {
|
|
7330
7426
|
nextScene.sections = createEmptyNestedCollection();
|
|
7331
7427
|
}
|
|
@@ -7395,6 +7491,10 @@ const COMMAND_DEFINITIONS = [
|
|
|
7395
7491
|
nextScene.name = payload.data.name;
|
|
7396
7492
|
}
|
|
7397
7493
|
|
|
7494
|
+
if (payload.data.description !== undefined) {
|
|
7495
|
+
nextScene.description = payload.data.description;
|
|
7496
|
+
}
|
|
7497
|
+
|
|
7398
7498
|
if (payload.data.position !== undefined) {
|
|
7399
7499
|
nextScene.position = {
|
|
7400
7500
|
...(isPlainObject(nextScene.position) ? nextScene.position : {}),
|