@routevn/creator-model 1.9.0 → 1.10.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.
- package/package.json +1 -1
- package/src/model.js +160 -6
package/package.json
CHANGED
package/src/model.js
CHANGED
|
@@ -394,7 +394,7 @@ const LAYOUT_ELEMENT_BASE_TYPES = [
|
|
|
394
394
|
"container-ref-confirm-dialog-ok",
|
|
395
395
|
"container-ref-confirm-dialog-cancel",
|
|
396
396
|
];
|
|
397
|
-
export const SCHEMA_VERSION =
|
|
397
|
+
export const SCHEMA_VERSION = 10;
|
|
398
398
|
const LAYOUT_CONTAINER_ELEMENT_TYPES = [
|
|
399
399
|
"folder",
|
|
400
400
|
"container",
|
|
@@ -3066,6 +3066,60 @@ const validateVariableItems = ({ items, path, errorFactory }) => {
|
|
|
3066
3066
|
}
|
|
3067
3067
|
};
|
|
3068
3068
|
|
|
3069
|
+
const validateTextStyleShadow = ({ shadow, path, errorFactory }) => {
|
|
3070
|
+
if (!isPlainObject(shadow)) {
|
|
3071
|
+
return invalidFromErrorFactory(errorFactory, `${path} must be an object`);
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
{
|
|
3075
|
+
const result = validateAllowedKeys({
|
|
3076
|
+
value: shadow,
|
|
3077
|
+
allowedKeys: ["colorId", "alpha", "blur", "offsetX", "offsetY"],
|
|
3078
|
+
path,
|
|
3079
|
+
errorFactory,
|
|
3080
|
+
});
|
|
3081
|
+
if (result?.valid === false) {
|
|
3082
|
+
return result;
|
|
3083
|
+
}
|
|
3084
|
+
}
|
|
3085
|
+
|
|
3086
|
+
if (!isNonEmptyString(shadow.colorId)) {
|
|
3087
|
+
return invalidFromErrorFactory(
|
|
3088
|
+
errorFactory,
|
|
3089
|
+
`${path}.colorId must be a non-empty string`,
|
|
3090
|
+
);
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
if (
|
|
3094
|
+
shadow.alpha !== undefined &&
|
|
3095
|
+
(!isFiniteNumber(shadow.alpha) || shadow.alpha < 0 || shadow.alpha > 1)
|
|
3096
|
+
) {
|
|
3097
|
+
return invalidFromErrorFactory(
|
|
3098
|
+
errorFactory,
|
|
3099
|
+
`${path}.alpha must be a finite number between 0 and 1 when provided`,
|
|
3100
|
+
);
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
if (
|
|
3104
|
+
shadow.blur !== undefined &&
|
|
3105
|
+
(!isFiniteNumber(shadow.blur) || shadow.blur < 0)
|
|
3106
|
+
) {
|
|
3107
|
+
return invalidFromErrorFactory(
|
|
3108
|
+
errorFactory,
|
|
3109
|
+
`${path}.blur must be a non-negative finite number when provided`,
|
|
3110
|
+
);
|
|
3111
|
+
}
|
|
3112
|
+
|
|
3113
|
+
for (const key of ["offsetX", "offsetY"]) {
|
|
3114
|
+
if (shadow[key] !== undefined && !isFiniteNumber(shadow[key])) {
|
|
3115
|
+
return invalidFromErrorFactory(
|
|
3116
|
+
errorFactory,
|
|
3117
|
+
`${path}.${key} must be a finite number when provided`,
|
|
3118
|
+
);
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
};
|
|
3122
|
+
|
|
3069
3123
|
const validateTextStyleItems = ({ items, path, errorFactory }) => {
|
|
3070
3124
|
for (const [itemId, item] of Object.entries(items)) {
|
|
3071
3125
|
const itemPath = `${path}.${itemId}`;
|
|
@@ -3103,6 +3157,7 @@ const validateTextStyleItems = ({ items, path, errorFactory }) => {
|
|
|
3103
3157
|
"strokeColorId",
|
|
3104
3158
|
"strokeAlpha",
|
|
3105
3159
|
"strokeWidth",
|
|
3160
|
+
"shadow",
|
|
3106
3161
|
],
|
|
3107
3162
|
path: itemPath,
|
|
3108
3163
|
errorFactory,
|
|
@@ -3262,6 +3317,17 @@ const validateTextStyleItems = ({ items, path, errorFactory }) => {
|
|
|
3262
3317
|
`${itemPath}.strokeWidth must be a finite number when provided`,
|
|
3263
3318
|
);
|
|
3264
3319
|
}
|
|
3320
|
+
|
|
3321
|
+
if (item.shadow !== undefined) {
|
|
3322
|
+
const result = validateTextStyleShadow({
|
|
3323
|
+
shadow: item.shadow,
|
|
3324
|
+
path: `${itemPath}.shadow`,
|
|
3325
|
+
errorFactory,
|
|
3326
|
+
});
|
|
3327
|
+
if (result?.valid === false) {
|
|
3328
|
+
return result;
|
|
3329
|
+
}
|
|
3330
|
+
}
|
|
3265
3331
|
}
|
|
3266
3332
|
}
|
|
3267
3333
|
};
|
|
@@ -3800,6 +3866,7 @@ const validateLayoutElementData = ({
|
|
|
3800
3866
|
"scaleX",
|
|
3801
3867
|
"scaleY",
|
|
3802
3868
|
"rotation",
|
|
3869
|
+
"hidden",
|
|
3803
3870
|
"opacity",
|
|
3804
3871
|
"blur",
|
|
3805
3872
|
"fill",
|
|
@@ -3897,6 +3964,13 @@ const validateLayoutElementData = ({
|
|
|
3897
3964
|
}
|
|
3898
3965
|
}
|
|
3899
3966
|
|
|
3967
|
+
if (data.hidden !== undefined && typeof data.hidden !== "boolean") {
|
|
3968
|
+
return invalidFromErrorFactory(
|
|
3969
|
+
errorFactory,
|
|
3970
|
+
`${path}.hidden must be a boolean when provided`,
|
|
3971
|
+
);
|
|
3972
|
+
}
|
|
3973
|
+
|
|
3900
3974
|
for (const key of [
|
|
3901
3975
|
"x",
|
|
3902
3976
|
"y",
|
|
@@ -4546,6 +4620,7 @@ const validateLayoutElementItems = ({ items, path, errorFactory }) => {
|
|
|
4546
4620
|
"scaleX",
|
|
4547
4621
|
"scaleY",
|
|
4548
4622
|
"rotation",
|
|
4623
|
+
"hidden",
|
|
4549
4624
|
"opacity",
|
|
4550
4625
|
"blur",
|
|
4551
4626
|
"fill",
|
|
@@ -5198,6 +5273,22 @@ const applyTagIdsUpdate = ({ currentItem, data }) => {
|
|
|
5198
5273
|
return nextItem;
|
|
5199
5274
|
};
|
|
5200
5275
|
|
|
5276
|
+
const applyTextStyleUpdate = ({ currentItem, data }) => {
|
|
5277
|
+
const nextData = structuredClone(data);
|
|
5278
|
+
delete nextData.clearShadow;
|
|
5279
|
+
|
|
5280
|
+
const nextItem = applyTagIdsUpdate({
|
|
5281
|
+
currentItem,
|
|
5282
|
+
data: nextData,
|
|
5283
|
+
});
|
|
5284
|
+
|
|
5285
|
+
if (data.clearShadow === true) {
|
|
5286
|
+
delete nextItem.shadow;
|
|
5287
|
+
}
|
|
5288
|
+
|
|
5289
|
+
return nextItem;
|
|
5290
|
+
};
|
|
5291
|
+
|
|
5201
5292
|
const applyCharacterUpdate = ({ currentItem, data }) => {
|
|
5202
5293
|
const nextItem = applyTagIdsUpdate({
|
|
5203
5294
|
currentItem,
|
|
@@ -7089,6 +7180,19 @@ export const assertInvariants = ({ state }) => {
|
|
|
7089
7180
|
);
|
|
7090
7181
|
}
|
|
7091
7182
|
}
|
|
7183
|
+
|
|
7184
|
+
if (textStyle.shadow !== undefined) {
|
|
7185
|
+
const shadowColor = state.colors.items[textStyle.shadow.colorId];
|
|
7186
|
+
if (!isPlainObject(shadowColor) || shadowColor.type === "folder") {
|
|
7187
|
+
return invalidInvariant(
|
|
7188
|
+
"textStyle.shadow.colorId must reference an existing non-folder color",
|
|
7189
|
+
{
|
|
7190
|
+
textStyleId,
|
|
7191
|
+
colorId: textStyle.shadow.colorId,
|
|
7192
|
+
},
|
|
7193
|
+
);
|
|
7194
|
+
}
|
|
7195
|
+
}
|
|
7092
7196
|
}
|
|
7093
7197
|
|
|
7094
7198
|
for (const [imageId, image] of Object.entries(state.images.items)) {
|
|
@@ -11014,6 +11118,7 @@ const validateTextStyleCreateData = ({ data, errorFactory }) => {
|
|
|
11014
11118
|
"strokeColorId",
|
|
11015
11119
|
"strokeAlpha",
|
|
11016
11120
|
"strokeWidth",
|
|
11121
|
+
"shadow",
|
|
11017
11122
|
],
|
|
11018
11123
|
path: "payload.data",
|
|
11019
11124
|
errorFactory,
|
|
@@ -11089,6 +11194,8 @@ const validateTextStyleUpdateData = ({ data, errorFactory }) => {
|
|
|
11089
11194
|
"strokeColorId",
|
|
11090
11195
|
"strokeAlpha",
|
|
11091
11196
|
"strokeWidth",
|
|
11197
|
+
"shadow",
|
|
11198
|
+
"clearShadow",
|
|
11092
11199
|
],
|
|
11093
11200
|
path: "payload.data",
|
|
11094
11201
|
errorFactory,
|
|
@@ -11157,6 +11264,31 @@ const validateTextStyleUpdateData = ({ data, errorFactory }) => {
|
|
|
11157
11264
|
}
|
|
11158
11265
|
}
|
|
11159
11266
|
|
|
11267
|
+
if (data.shadow !== undefined) {
|
|
11268
|
+
const result = validateTextStyleShadow({
|
|
11269
|
+
shadow: data.shadow,
|
|
11270
|
+
path: "payload.data.shadow",
|
|
11271
|
+
errorFactory,
|
|
11272
|
+
});
|
|
11273
|
+
if (result?.valid === false) {
|
|
11274
|
+
return result;
|
|
11275
|
+
}
|
|
11276
|
+
}
|
|
11277
|
+
|
|
11278
|
+
if (data.clearShadow !== undefined && data.clearShadow !== true) {
|
|
11279
|
+
return invalidFromErrorFactory(
|
|
11280
|
+
errorFactory,
|
|
11281
|
+
"payload.data.clearShadow must be true when provided",
|
|
11282
|
+
);
|
|
11283
|
+
}
|
|
11284
|
+
|
|
11285
|
+
if (data.shadow !== undefined && data.clearShadow === true) {
|
|
11286
|
+
return invalidFromErrorFactory(
|
|
11287
|
+
errorFactory,
|
|
11288
|
+
"payload.data.shadow and payload.data.clearShadow cannot both be provided",
|
|
11289
|
+
);
|
|
11290
|
+
}
|
|
11291
|
+
|
|
11160
11292
|
if (data.breakWords !== undefined && typeof data.breakWords !== "boolean") {
|
|
11161
11293
|
return invalidFromErrorFactory(
|
|
11162
11294
|
errorFactory,
|
|
@@ -18313,7 +18445,7 @@ const COMMAND_DEFINITIONS = [
|
|
|
18313
18445
|
};
|
|
18314
18446
|
},
|
|
18315
18447
|
updateItem: ({ currentItem, payload }) =>
|
|
18316
|
-
|
|
18448
|
+
applyTextStyleUpdate({
|
|
18317
18449
|
currentItem,
|
|
18318
18450
|
data: payload.data,
|
|
18319
18451
|
}),
|
|
@@ -18351,6 +18483,15 @@ const COMMAND_DEFINITIONS = [
|
|
|
18351
18483
|
);
|
|
18352
18484
|
}
|
|
18353
18485
|
}
|
|
18486
|
+
|
|
18487
|
+
if (data.shadow !== undefined) {
|
|
18488
|
+
const shadowColor = state.colors.items[data.shadow.colorId];
|
|
18489
|
+
if (!isPlainObject(shadowColor) || shadowColor.type === "folder") {
|
|
18490
|
+
return invalidPrecondition(
|
|
18491
|
+
"payload.data.shadow.colorId must reference an existing non-folder color",
|
|
18492
|
+
);
|
|
18493
|
+
}
|
|
18494
|
+
}
|
|
18354
18495
|
},
|
|
18355
18496
|
validateUpdateState: ({ state, payload, currentItem }) => {
|
|
18356
18497
|
if (
|
|
@@ -18394,6 +18535,15 @@ const COMMAND_DEFINITIONS = [
|
|
|
18394
18535
|
);
|
|
18395
18536
|
}
|
|
18396
18537
|
}
|
|
18538
|
+
|
|
18539
|
+
if (payload.data.shadow !== undefined) {
|
|
18540
|
+
const shadowColor = state.colors.items[payload.data.shadow.colorId];
|
|
18541
|
+
if (!isPlainObject(shadowColor) || shadowColor.type === "folder") {
|
|
18542
|
+
return invalidPrecondition(
|
|
18543
|
+
"payload.data.shadow.colorId must reference an existing non-folder color",
|
|
18544
|
+
);
|
|
18545
|
+
}
|
|
18546
|
+
}
|
|
18397
18547
|
},
|
|
18398
18548
|
}),
|
|
18399
18549
|
...createFolderedCollectionCommandDefinitions({
|
|
@@ -20002,10 +20152,12 @@ const COMMAND_DEFINITIONS = [
|
|
|
20002
20152
|
|
|
20003
20153
|
if (
|
|
20004
20154
|
currentItem.type === "folder" &&
|
|
20005
|
-
Object.keys(payload.data).some(
|
|
20155
|
+
Object.keys(payload.data).some(
|
|
20156
|
+
(key) => key !== "name" && key !== "hidden",
|
|
20157
|
+
)
|
|
20006
20158
|
) {
|
|
20007
20159
|
return invalidPrecondition(
|
|
20008
|
-
"folder layout elements
|
|
20160
|
+
"folder layout elements can only update name and hidden fields",
|
|
20009
20161
|
);
|
|
20010
20162
|
}
|
|
20011
20163
|
|
|
@@ -20361,10 +20513,12 @@ const COMMAND_DEFINITIONS = [
|
|
|
20361
20513
|
|
|
20362
20514
|
if (
|
|
20363
20515
|
currentItem.type === "folder" &&
|
|
20364
|
-
Object.keys(payload.data).some(
|
|
20516
|
+
Object.keys(payload.data).some(
|
|
20517
|
+
(key) => key !== "name" && key !== "hidden",
|
|
20518
|
+
)
|
|
20365
20519
|
) {
|
|
20366
20520
|
return invalidPrecondition(
|
|
20367
|
-
"folder control elements
|
|
20521
|
+
"folder control elements can only update name and hidden fields",
|
|
20368
20522
|
);
|
|
20369
20523
|
}
|
|
20370
20524
|
|