@routevn/creator-model 1.3.1 → 1.3.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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/model.js +118 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@routevn/creator-model",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/model.js CHANGED
@@ -3068,6 +3068,8 @@ const validateLayoutElementData = ({
3068
3068
  "imageId",
3069
3069
  "hoverImageId",
3070
3070
  "clickImageId",
3071
+ "hoverSoundId",
3072
+ "clickSoundId",
3071
3073
  "textStyleId",
3072
3074
  "hoverTextStyleId",
3073
3075
  "clickTextStyleId",
@@ -3195,6 +3197,8 @@ const validateLayoutElementData = ({
3195
3197
  "imageId",
3196
3198
  "hoverImageId",
3197
3199
  "clickImageId",
3200
+ "hoverSoundId",
3201
+ "clickSoundId",
3198
3202
  "textStyleId",
3199
3203
  "hoverTextStyleId",
3200
3204
  "clickTextStyleId",
@@ -3351,6 +3355,8 @@ const validateLayoutElementData = ({
3351
3355
  "imageId",
3352
3356
  "hoverImageId",
3353
3357
  "clickImageId",
3358
+ "hoverSoundId",
3359
+ "clickSoundId",
3354
3360
  "opacity",
3355
3361
  "anchorX",
3356
3362
  "anchorY",
@@ -3372,6 +3378,8 @@ const validateLayoutElementData = ({
3372
3378
  "imageId",
3373
3379
  "hoverImageId",
3374
3380
  "clickImageId",
3381
+ "hoverSoundId",
3382
+ "clickSoundId",
3375
3383
  ]) {
3376
3384
  if (
3377
3385
  rule.set[field] !== undefined &&
@@ -3608,6 +3616,8 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
3608
3616
  "imageId",
3609
3617
  "hoverImageId",
3610
3618
  "clickImageId",
3619
+ "hoverSoundId",
3620
+ "clickSoundId",
3611
3621
  "textStyleId",
3612
3622
  "hoverTextStyleId",
3613
3623
  "clickTextStyleId",
@@ -6395,6 +6405,30 @@ export const assertInvariants = ({ state }) => {
6395
6405
  return VALID_RESULT;
6396
6406
  };
6397
6407
 
6408
+ const assertSoundReference = ({
6409
+ ownerIdField,
6410
+ ownerId,
6411
+ ownerLabel,
6412
+ elementId,
6413
+ field,
6414
+ targetId,
6415
+ }) => {
6416
+ const sound = state.sounds.items[targetId];
6417
+ if (!isPlainObject(sound) || sound.type === "folder") {
6418
+ return invalidInvariant(
6419
+ `${ownerLabel} element ${field} must reference an existing non-folder sound`,
6420
+ {
6421
+ [ownerIdField]: ownerId,
6422
+ elementId,
6423
+ field,
6424
+ targetId,
6425
+ },
6426
+ );
6427
+ }
6428
+
6429
+ return VALID_RESULT;
6430
+ };
6431
+
6398
6432
  const assertVariableReference = ({
6399
6433
  ownerIdField,
6400
6434
  ownerId,
@@ -6571,6 +6605,22 @@ export const assertInvariants = ({ state }) => {
6571
6605
  }
6572
6606
  }
6573
6607
 
6608
+ for (const field of ["hoverSoundId", "clickSoundId"]) {
6609
+ if (element[field] !== undefined) {
6610
+ const result = assertSoundReference({
6611
+ ownerIdField,
6612
+ ownerId,
6613
+ ownerLabel,
6614
+ elementId,
6615
+ field,
6616
+ targetId: element[field],
6617
+ });
6618
+ if (!result.valid) {
6619
+ return result;
6620
+ }
6621
+ }
6622
+ }
6623
+
6574
6624
  for (const field of [
6575
6625
  "textStyleId",
6576
6626
  "hoverTextStyleId",
@@ -6599,6 +6649,22 @@ export const assertInvariants = ({ state }) => {
6599
6649
  ) {
6600
6650
  const rule = element.conditionalOverrides[index];
6601
6651
 
6652
+ for (const field of ["hoverSoundId", "clickSoundId"]) {
6653
+ if (rule?.set?.[field] !== undefined) {
6654
+ const result = assertSoundReference({
6655
+ ownerIdField,
6656
+ ownerId,
6657
+ ownerLabel,
6658
+ elementId,
6659
+ field: `conditionalOverrides.${index}.set.${field}`,
6660
+ targetId: rule.set[field],
6661
+ });
6662
+ if (!result.valid) {
6663
+ return result;
6664
+ }
6665
+ }
6666
+ }
6667
+
6602
6668
  for (const field of [
6603
6669
  "textStyleId",
6604
6670
  "hoverTextStyleId",
@@ -10243,6 +10309,38 @@ const validateVisualElementReferenceTargets = ({
10243
10309
  }
10244
10310
  }
10245
10311
 
10312
+ if (data.hoverSoundId !== undefined) {
10313
+ const sound = state.sounds.items[data.hoverSoundId];
10314
+ if (!isPlainObject(sound) || sound.type === "folder") {
10315
+ return invalidFromErrorFactory(
10316
+ errorFactory,
10317
+ `${ownerLabel} element hoverSoundId must reference an existing non-folder sound`,
10318
+ {
10319
+ [ownerIdField]: ownerId,
10320
+ elementId,
10321
+ field: "hoverSoundId",
10322
+ targetId: data.hoverSoundId,
10323
+ },
10324
+ );
10325
+ }
10326
+ }
10327
+
10328
+ if (data.clickSoundId !== undefined) {
10329
+ const sound = state.sounds.items[data.clickSoundId];
10330
+ if (!isPlainObject(sound) || sound.type === "folder") {
10331
+ return invalidFromErrorFactory(
10332
+ errorFactory,
10333
+ `${ownerLabel} element clickSoundId must reference an existing non-folder sound`,
10334
+ {
10335
+ [ownerIdField]: ownerId,
10336
+ elementId,
10337
+ field: "clickSoundId",
10338
+ targetId: data.clickSoundId,
10339
+ },
10340
+ );
10341
+ }
10342
+ }
10343
+
10246
10344
  if (data.thumbImageId !== undefined) {
10247
10345
  const image = state.images.items[data.thumbImageId];
10248
10346
  if (!isPlainObject(image) || image.type === "folder") {
@@ -10383,6 +10481,26 @@ const validateVisualElementReferenceTargets = ({
10383
10481
  }
10384
10482
  }
10385
10483
 
10484
+ for (const field of ["hoverSoundId", "clickSoundId"]) {
10485
+ if (rule?.set?.[field] === undefined) {
10486
+ continue;
10487
+ }
10488
+
10489
+ const sound = state.sounds.items[rule.set[field]];
10490
+ if (!isPlainObject(sound) || sound.type === "folder") {
10491
+ return invalidFromErrorFactory(
10492
+ errorFactory,
10493
+ `${ownerLabel} element conditionalOverrides.${index}.set.${field} must reference an existing non-folder sound`,
10494
+ {
10495
+ [ownerIdField]: ownerId,
10496
+ elementId,
10497
+ field: `conditionalOverrides.${index}.set.${field}`,
10498
+ targetId: rule.set[field],
10499
+ },
10500
+ );
10501
+ }
10502
+ }
10503
+
10386
10504
  for (const field of ["imageId", "hoverImageId", "clickImageId"]) {
10387
10505
  if (rule?.set?.[field] === undefined) {
10388
10506
  continue;