@routevn/creator-model 1.3.1 → 1.3.3

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 +206 -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.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "license": "MIT",
package/src/model.js CHANGED
@@ -2395,6 +2395,7 @@ const validateParticleItems = ({ items, path, errorFactory }) => {
2395
2395
  "height",
2396
2396
  "seed",
2397
2397
  "modules",
2398
+ "thumbnailFileId",
2398
2399
  ],
2399
2400
  path: itemPath,
2400
2401
  errorFactory,
@@ -2469,6 +2470,16 @@ const validateParticleItems = ({ items, path, errorFactory }) => {
2469
2470
  );
2470
2471
  }
2471
2472
 
2473
+ if (
2474
+ item.thumbnailFileId !== undefined &&
2475
+ !isNonEmptyString(item.thumbnailFileId)
2476
+ ) {
2477
+ return invalidFromErrorFactory(
2478
+ errorFactory,
2479
+ `${itemPath}.thumbnailFileId must be a non-empty string when provided`,
2480
+ );
2481
+ }
2482
+
2472
2483
  {
2473
2484
  const result = validateParticleModules({
2474
2485
  modules: item.modules,
@@ -3068,6 +3079,8 @@ const validateLayoutElementData = ({
3068
3079
  "imageId",
3069
3080
  "hoverImageId",
3070
3081
  "clickImageId",
3082
+ "hoverSoundId",
3083
+ "clickSoundId",
3071
3084
  "textStyleId",
3072
3085
  "hoverTextStyleId",
3073
3086
  "clickTextStyleId",
@@ -3195,6 +3208,8 @@ const validateLayoutElementData = ({
3195
3208
  "imageId",
3196
3209
  "hoverImageId",
3197
3210
  "clickImageId",
3211
+ "hoverSoundId",
3212
+ "clickSoundId",
3198
3213
  "textStyleId",
3199
3214
  "hoverTextStyleId",
3200
3215
  "clickTextStyleId",
@@ -3351,6 +3366,8 @@ const validateLayoutElementData = ({
3351
3366
  "imageId",
3352
3367
  "hoverImageId",
3353
3368
  "clickImageId",
3369
+ "hoverSoundId",
3370
+ "clickSoundId",
3354
3371
  "opacity",
3355
3372
  "anchorX",
3356
3373
  "anchorY",
@@ -3372,6 +3389,8 @@ const validateLayoutElementData = ({
3372
3389
  "imageId",
3373
3390
  "hoverImageId",
3374
3391
  "clickImageId",
3392
+ "hoverSoundId",
3393
+ "clickSoundId",
3375
3394
  ]) {
3376
3395
  if (
3377
3396
  rule.set[field] !== undefined &&
@@ -3608,6 +3627,8 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
3608
3627
  "imageId",
3609
3628
  "hoverImageId",
3610
3629
  "clickImageId",
3630
+ "hoverSoundId",
3631
+ "clickSoundId",
3611
3632
  "textStyleId",
3612
3633
  "hoverTextStyleId",
3613
3634
  "clickTextStyleId",
@@ -6190,6 +6211,19 @@ export const assertInvariants = ({ state }) => {
6190
6211
  continue;
6191
6212
  }
6192
6213
 
6214
+ if (particle.thumbnailFileId !== undefined) {
6215
+ const result = validateFileReference({
6216
+ state,
6217
+ fileId: particle.thumbnailFileId,
6218
+ path: "particle.thumbnailFileId",
6219
+ details: { particleId, thumbnailFileId: particle.thumbnailFileId },
6220
+ errorFactory: createInvariantValidationError,
6221
+ });
6222
+ if (!result.valid) {
6223
+ return result;
6224
+ }
6225
+ }
6226
+
6193
6227
  {
6194
6228
  const result = validateTagIdsAgainstScope({
6195
6229
  state,
@@ -6395,6 +6429,30 @@ export const assertInvariants = ({ state }) => {
6395
6429
  return VALID_RESULT;
6396
6430
  };
6397
6431
 
6432
+ const assertSoundReference = ({
6433
+ ownerIdField,
6434
+ ownerId,
6435
+ ownerLabel,
6436
+ elementId,
6437
+ field,
6438
+ targetId,
6439
+ }) => {
6440
+ const sound = state.sounds.items[targetId];
6441
+ if (!isPlainObject(sound) || sound.type === "folder") {
6442
+ return invalidInvariant(
6443
+ `${ownerLabel} element ${field} must reference an existing non-folder sound`,
6444
+ {
6445
+ [ownerIdField]: ownerId,
6446
+ elementId,
6447
+ field,
6448
+ targetId,
6449
+ },
6450
+ );
6451
+ }
6452
+
6453
+ return VALID_RESULT;
6454
+ };
6455
+
6398
6456
  const assertVariableReference = ({
6399
6457
  ownerIdField,
6400
6458
  ownerId,
@@ -6571,6 +6629,22 @@ export const assertInvariants = ({ state }) => {
6571
6629
  }
6572
6630
  }
6573
6631
 
6632
+ for (const field of ["hoverSoundId", "clickSoundId"]) {
6633
+ if (element[field] !== undefined) {
6634
+ const result = assertSoundReference({
6635
+ ownerIdField,
6636
+ ownerId,
6637
+ ownerLabel,
6638
+ elementId,
6639
+ field,
6640
+ targetId: element[field],
6641
+ });
6642
+ if (!result.valid) {
6643
+ return result;
6644
+ }
6645
+ }
6646
+ }
6647
+
6574
6648
  for (const field of [
6575
6649
  "textStyleId",
6576
6650
  "hoverTextStyleId",
@@ -6599,6 +6673,22 @@ export const assertInvariants = ({ state }) => {
6599
6673
  ) {
6600
6674
  const rule = element.conditionalOverrides[index];
6601
6675
 
6676
+ for (const field of ["hoverSoundId", "clickSoundId"]) {
6677
+ if (rule?.set?.[field] !== undefined) {
6678
+ const result = assertSoundReference({
6679
+ ownerIdField,
6680
+ ownerId,
6681
+ ownerLabel,
6682
+ elementId,
6683
+ field: `conditionalOverrides.${index}.set.${field}`,
6684
+ targetId: rule.set[field],
6685
+ });
6686
+ if (!result.valid) {
6687
+ return result;
6688
+ }
6689
+ }
6690
+ }
6691
+
6602
6692
  for (const field of [
6603
6693
  "textStyleId",
6604
6694
  "hoverTextStyleId",
@@ -8698,6 +8788,7 @@ const validateParticleCreateData = ({ data, errorFactory }) => {
8698
8788
  "height",
8699
8789
  "seed",
8700
8790
  "modules",
8791
+ "thumbnailFileId",
8701
8792
  ],
8702
8793
  path: "payload.data",
8703
8794
  errorFactory,
@@ -8725,6 +8816,16 @@ const validateParticleCreateData = ({ data, errorFactory }) => {
8725
8816
  return;
8726
8817
  }
8727
8818
 
8819
+ if (
8820
+ data.thumbnailFileId !== undefined &&
8821
+ !isNonEmptyString(data.thumbnailFileId)
8822
+ ) {
8823
+ return invalidFromErrorFactory(
8824
+ errorFactory,
8825
+ "payload.data.thumbnailFileId must be a non-empty string when provided",
8826
+ );
8827
+ }
8828
+
8728
8829
  {
8729
8830
  const result = validateOptionalUniqueIdArray({
8730
8831
  value: data.tagIds,
@@ -8785,6 +8886,7 @@ const validateParticleUpdateData = ({ data, errorFactory }) => {
8785
8886
  "height",
8786
8887
  "seed",
8787
8888
  "modules",
8889
+ "thumbnailFileId",
8788
8890
  ],
8789
8891
  path: "payload.data",
8790
8892
  errorFactory,
@@ -8815,6 +8917,16 @@ const validateParticleUpdateData = ({ data, errorFactory }) => {
8815
8917
  );
8816
8918
  }
8817
8919
 
8920
+ if (
8921
+ data.thumbnailFileId !== undefined &&
8922
+ !isNonEmptyString(data.thumbnailFileId)
8923
+ ) {
8924
+ return invalidFromErrorFactory(
8925
+ errorFactory,
8926
+ "payload.data.thumbnailFileId must be a non-empty string when provided",
8927
+ );
8928
+ }
8929
+
8818
8930
  {
8819
8931
  const result = validateOptionalUniqueIdArray({
8820
8932
  value: data.tagIds,
@@ -10243,6 +10355,38 @@ const validateVisualElementReferenceTargets = ({
10243
10355
  }
10244
10356
  }
10245
10357
 
10358
+ if (data.hoverSoundId !== undefined) {
10359
+ const sound = state.sounds.items[data.hoverSoundId];
10360
+ if (!isPlainObject(sound) || sound.type === "folder") {
10361
+ return invalidFromErrorFactory(
10362
+ errorFactory,
10363
+ `${ownerLabel} element hoverSoundId must reference an existing non-folder sound`,
10364
+ {
10365
+ [ownerIdField]: ownerId,
10366
+ elementId,
10367
+ field: "hoverSoundId",
10368
+ targetId: data.hoverSoundId,
10369
+ },
10370
+ );
10371
+ }
10372
+ }
10373
+
10374
+ if (data.clickSoundId !== undefined) {
10375
+ const sound = state.sounds.items[data.clickSoundId];
10376
+ if (!isPlainObject(sound) || sound.type === "folder") {
10377
+ return invalidFromErrorFactory(
10378
+ errorFactory,
10379
+ `${ownerLabel} element clickSoundId must reference an existing non-folder sound`,
10380
+ {
10381
+ [ownerIdField]: ownerId,
10382
+ elementId,
10383
+ field: "clickSoundId",
10384
+ targetId: data.clickSoundId,
10385
+ },
10386
+ );
10387
+ }
10388
+ }
10389
+
10246
10390
  if (data.thumbImageId !== undefined) {
10247
10391
  const image = state.images.items[data.thumbImageId];
10248
10392
  if (!isPlainObject(image) || image.type === "folder") {
@@ -10383,6 +10527,26 @@ const validateVisualElementReferenceTargets = ({
10383
10527
  }
10384
10528
  }
10385
10529
 
10530
+ for (const field of ["hoverSoundId", "clickSoundId"]) {
10531
+ if (rule?.set?.[field] === undefined) {
10532
+ continue;
10533
+ }
10534
+
10535
+ const sound = state.sounds.items[rule.set[field]];
10536
+ if (!isPlainObject(sound) || sound.type === "folder") {
10537
+ return invalidFromErrorFactory(
10538
+ errorFactory,
10539
+ `${ownerLabel} element conditionalOverrides.${index}.set.${field} must reference an existing non-folder sound`,
10540
+ {
10541
+ [ownerIdField]: ownerId,
10542
+ elementId,
10543
+ field: `conditionalOverrides.${index}.set.${field}`,
10544
+ targetId: rule.set[field],
10545
+ },
10546
+ );
10547
+ }
10548
+ }
10549
+
10386
10550
  for (const field of ["imageId", "hoverImageId", "clickImageId"]) {
10387
10551
  if (rule?.set?.[field] === undefined) {
10388
10552
  continue;
@@ -11145,6 +11309,20 @@ const findReferencedFileUsage = ({ state, fileId }) => {
11145
11309
  }
11146
11310
  }
11147
11311
 
11312
+ for (const [particleId, particle] of Object.entries(state.particles.items)) {
11313
+ if (particle.type !== "particle") {
11314
+ continue;
11315
+ }
11316
+
11317
+ if (particle.thumbnailFileId === fileId) {
11318
+ return {
11319
+ kind: "particle",
11320
+ field: "thumbnailFileId",
11321
+ ownerId: particleId,
11322
+ };
11323
+ }
11324
+ }
11325
+
11148
11326
  return null;
11149
11327
  };
11150
11328
 
@@ -15248,6 +15426,10 @@ const COMMAND_DEFINITIONS = [
15248
15426
  item.seed = payload.data.seed;
15249
15427
  }
15250
15428
 
15429
+ if (payload.data.thumbnailFileId !== undefined) {
15430
+ item.thumbnailFileId = payload.data.thumbnailFileId;
15431
+ }
15432
+
15251
15433
  return item;
15252
15434
  },
15253
15435
  updateItem: ({ currentItem, payload }) => {
@@ -15275,6 +15457,18 @@ const COMMAND_DEFINITIONS = [
15275
15457
  }
15276
15458
 
15277
15459
  if (currentItem.type === "particle") {
15460
+ const fileResult = validateReferencedFilesInData({
15461
+ state,
15462
+ data: payload.data,
15463
+ fields: ["thumbnailFileId"],
15464
+ details: {
15465
+ particleId: payload.particleId,
15466
+ },
15467
+ });
15468
+ if (!fileResult.valid) {
15469
+ return fileResult;
15470
+ }
15471
+
15278
15472
  return validateTagIdsAgainstScope({
15279
15473
  state,
15280
15474
  tagIds: payload.data.tagIds,
@@ -15291,6 +15485,18 @@ const COMMAND_DEFINITIONS = [
15291
15485
  return;
15292
15486
  }
15293
15487
 
15488
+ const fileResult = validateReferencedFilesInData({
15489
+ state,
15490
+ data: payload.data,
15491
+ fields: ["thumbnailFileId"],
15492
+ details: {
15493
+ particleId: payload.particleId,
15494
+ },
15495
+ });
15496
+ if (!fileResult.valid) {
15497
+ return fileResult;
15498
+ }
15499
+
15294
15500
  return validateTagIdsAgainstScope({
15295
15501
  state,
15296
15502
  tagIds: payload.data.tagIds,