@routevn/creator-model 1.0.5 → 1.1.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/model.js +124 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.0.5",
3
+ "version": "1.1.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
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,
@@ -2087,10 +2095,14 @@ const validateCharacterSpriteItems = ({ items, path, errorFactory }) => {
2087
2095
  }
2088
2096
  };
2089
2097
 
2090
- const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2098
+ const validateLayoutElementTextStyle = ({
2099
+ textStyle,
2100
+ path,
2101
+ errorFactory,
2102
+ }) => {
2091
2103
  {
2092
2104
  const result = validateAllowedKeys({
2093
- value: style,
2105
+ value: textStyle,
2094
2106
  allowedKeys: ["align", "wordWrapWidth"],
2095
2107
  path,
2096
2108
  errorFactory,
@@ -2101,8 +2113,8 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2101
2113
  }
2102
2114
 
2103
2115
  if (
2104
- style.align !== undefined &&
2105
- !LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS.includes(style.align)
2116
+ textStyle.align !== undefined &&
2117
+ !LAYOUT_ELEMENT_TEXT_STYLE_ALIGN_KEYS.includes(textStyle.align)
2106
2118
  ) {
2107
2119
  return invalidFromErrorFactory(
2108
2120
  errorFactory,
@@ -2111,8 +2123,8 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2111
2123
  }
2112
2124
 
2113
2125
  if (
2114
- style.wordWrapWidth !== undefined &&
2115
- !isFiniteNumber(style.wordWrapWidth)
2126
+ textStyle.wordWrapWidth !== undefined &&
2127
+ !isFiniteNumber(textStyle.wordWrapWidth)
2116
2128
  ) {
2117
2129
  return invalidFromErrorFactory(
2118
2130
  errorFactory,
@@ -2121,6 +2133,47 @@ const validateLayoutElementStyle = ({ style, path, errorFactory }) => {
2121
2133
  }
2122
2134
  };
2123
2135
 
2136
+ const validateLayoutElementBorder = ({ border, path, errorFactory }) => {
2137
+ {
2138
+ const result = validateAllowedKeys({
2139
+ value: border,
2140
+ allowedKeys: ["color", "alpha", "width"],
2141
+ path,
2142
+ errorFactory,
2143
+ });
2144
+ if (result?.valid === false) {
2145
+ return result;
2146
+ }
2147
+ }
2148
+
2149
+ if (border.color !== undefined && !isString(border.color)) {
2150
+ return invalidFromErrorFactory(
2151
+ errorFactory,
2152
+ `${path}.color must be a string when provided`,
2153
+ );
2154
+ }
2155
+
2156
+ if (
2157
+ border.alpha !== undefined &&
2158
+ (!isFiniteNumber(border.alpha) || border.alpha < 0 || border.alpha > 1)
2159
+ ) {
2160
+ return invalidFromErrorFactory(
2161
+ errorFactory,
2162
+ `${path}.alpha must be a finite number between 0 and 1 when provided`,
2163
+ );
2164
+ }
2165
+
2166
+ if (
2167
+ border.width !== undefined &&
2168
+ (!isFiniteNumber(border.width) || border.width < 0)
2169
+ ) {
2170
+ return invalidFromErrorFactory(
2171
+ errorFactory,
2172
+ `${path}.width must be a finite number greater than or equal to 0 when provided`,
2173
+ );
2174
+ }
2175
+ };
2176
+
2124
2177
  const validateLayoutElementData = ({
2125
2178
  data,
2126
2179
  path,
@@ -2144,8 +2197,10 @@ const validateLayoutElementData = ({
2144
2197
  "scaleY",
2145
2198
  "rotation",
2146
2199
  "opacity",
2200
+ "fill",
2201
+ "border",
2147
2202
  "text",
2148
- "style",
2203
+ "textStyle",
2149
2204
  "displaySpeed",
2150
2205
  "imageId",
2151
2206
  "hoverImageId",
@@ -2273,6 +2328,13 @@ const validateLayoutElementData = ({
2273
2328
  }
2274
2329
  }
2275
2330
 
2331
+ if (data.fill !== undefined && !isString(data.fill)) {
2332
+ return invalidFromErrorFactory(
2333
+ errorFactory,
2334
+ `${path}.fill must be a string when provided`,
2335
+ );
2336
+ }
2337
+
2276
2338
  if (
2277
2339
  data.direction !== undefined &&
2278
2340
  data.direction !== "horizontal" &&
@@ -2301,11 +2363,31 @@ const validateLayoutElementData = ({
2301
2363
  );
2302
2364
  }
2303
2365
 
2304
- if (data.style !== undefined) {
2366
+ if (data.textStyle !== undefined) {
2367
+ {
2368
+ const result = validateLayoutElementTextStyle({
2369
+ textStyle: data.textStyle,
2370
+ path: `${path}.textStyle`,
2371
+ errorFactory,
2372
+ });
2373
+ if (result?.valid === false) {
2374
+ return result;
2375
+ }
2376
+ }
2377
+ }
2378
+
2379
+ if (data.border !== undefined) {
2380
+ if (!isPlainObject(data.border)) {
2381
+ return invalidFromErrorFactory(
2382
+ errorFactory,
2383
+ `${path}.border must be an object when provided`,
2384
+ );
2385
+ }
2386
+
2305
2387
  {
2306
- const result = validateLayoutElementStyle({
2307
- style: data.style,
2308
- path: `${path}.style`,
2388
+ const result = validateLayoutElementBorder({
2389
+ border: data.border,
2390
+ path: `${path}.border`,
2309
2391
  errorFactory,
2310
2392
  });
2311
2393
  if (result?.valid === false) {
@@ -2357,8 +2439,10 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
2357
2439
  "scaleY",
2358
2440
  "rotation",
2359
2441
  "opacity",
2442
+ "fill",
2443
+ "border",
2360
2444
  "text",
2361
- "style",
2445
+ "textStyle",
2362
2446
  "displaySpeed",
2363
2447
  "imageId",
2364
2448
  "hoverImageId",
@@ -2630,7 +2714,6 @@ const validateLayoutItems = ({ items, path, errorFactory }) => {
2630
2714
  return result;
2631
2715
  }
2632
2716
  }
2633
-
2634
2717
  }
2635
2718
  }
2636
2719
  };
@@ -4085,7 +4168,7 @@ const validateSceneCreateData = ({ data, errorFactory }) => {
4085
4168
  {
4086
4169
  const result = validateAllowedKeys({
4087
4170
  value: data,
4088
- allowedKeys: ["name", "type", "position"],
4171
+ allowedKeys: ["name", "description", "type", "position"],
4089
4172
  path: "payload.data",
4090
4173
  errorFactory,
4091
4174
  });
@@ -4101,6 +4184,13 @@ const validateSceneCreateData = ({ data, errorFactory }) => {
4101
4184
  );
4102
4185
  }
4103
4186
 
4187
+ if (data.description !== undefined && !isString(data.description)) {
4188
+ return invalidFromErrorFactory(
4189
+ errorFactory,
4190
+ "payload.data.description must be a string when provided",
4191
+ );
4192
+ }
4193
+
4104
4194
  if (
4105
4195
  data.type !== undefined &&
4106
4196
  data.type !== "scene" &&
@@ -4128,7 +4218,7 @@ const validateSceneUpdateData = ({ data, errorFactory }) => {
4128
4218
  {
4129
4219
  const result = validateAllowedKeys({
4130
4220
  value: data,
4131
- allowedKeys: ["name", "position"],
4221
+ allowedKeys: ["name", "description", "position"],
4132
4222
  path: "payload.data",
4133
4223
  errorFactory,
4134
4224
  });
@@ -4138,9 +4228,10 @@ const validateSceneUpdateData = ({ data, errorFactory }) => {
4138
4228
  }
4139
4229
 
4140
4230
  const hasName = data.name !== undefined;
4231
+ const hasDescription = data.description !== undefined;
4141
4232
  const hasPosition = data.position !== undefined;
4142
4233
 
4143
- if (!hasName && !hasPosition) {
4234
+ if (!hasName && !hasDescription && !hasPosition) {
4144
4235
  return invalidFromErrorFactory(
4145
4236
  errorFactory,
4146
4237
  "payload.data must include at least one updatable field",
@@ -4154,6 +4245,13 @@ const validateSceneUpdateData = ({ data, errorFactory }) => {
4154
4245
  );
4155
4246
  }
4156
4247
 
4248
+ if (hasDescription && !isString(data.description)) {
4249
+ return invalidFromErrorFactory(
4250
+ errorFactory,
4251
+ "payload.data.description must be a string when provided",
4252
+ );
4253
+ }
4254
+
4157
4255
  if (hasPosition) {
4158
4256
  {
4159
4257
  const result = validateOptionalPosition({
@@ -6055,7 +6153,6 @@ const validateLayoutCreateData = ({ data, errorFactory }) => {
6055
6153
  return result;
6056
6154
  }
6057
6155
  }
6058
-
6059
6156
  }
6060
6157
  };
6061
6158
 
@@ -6095,7 +6192,6 @@ const validateLayoutUpdateData = ({ data, errorFactory }) => {
6095
6192
  "payload.data.layoutType must be 'normal', 'dialogue', 'nvl', or 'choice' when provided",
6096
6193
  );
6097
6194
  }
6098
-
6099
6195
  };
6100
6196
 
6101
6197
  const validateControlCreateData = ({ data, errorFactory }) => {
@@ -7326,6 +7422,10 @@ const COMMAND_DEFINITIONS = [
7326
7422
  name: payload.data.name,
7327
7423
  };
7328
7424
 
7425
+ if (payload.data.description !== undefined) {
7426
+ nextScene.description = payload.data.description;
7427
+ }
7428
+
7329
7429
  if (nextScene.type === "scene") {
7330
7430
  nextScene.sections = createEmptyNestedCollection();
7331
7431
  }
@@ -7395,6 +7495,10 @@ const COMMAND_DEFINITIONS = [
7395
7495
  nextScene.name = payload.data.name;
7396
7496
  }
7397
7497
 
7498
+ if (payload.data.description !== undefined) {
7499
+ nextScene.description = payload.data.description;
7500
+ }
7501
+
7398
7502
  if (payload.data.position !== undefined) {
7399
7503
  nextScene.position = {
7400
7504
  ...(isPlainObject(nextScene.position) ? nextScene.position : {}),