@valbuild/core 0.144.0 → 0.146.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.
- package/CHANGELOG.md +32 -0
- package/dist/declarations/src/index.d.ts +10 -2
- package/dist/declarations/src/initSchema.d.ts +23 -1
- package/dist/declarations/src/render.d.ts +38 -5
- package/dist/declarations/src/schema/image.d.ts +2 -0
- package/dist/declarations/src/schema/number.d.ts +45 -5
- package/dist/declarations/src/schema/numberRules.d.ts +27 -0
- package/dist/declarations/src/schema/validation/ValidationFix.d.ts +1 -1
- package/dist/declarations/src/source/media.d.ts +22 -0
- package/dist/{index-2d194c90.cjs.prod.js → index-4bd4b62a.cjs.prod.js} +322 -44
- package/dist/{index-aa16dd90.esm.js → index-8519c554.esm.js} +322 -44
- package/dist/{index-8b22b2c1.cjs.dev.js → index-89993829.cjs.dev.js} +322 -44
- package/dist/valbuild-core.cjs.dev.js +1 -1
- package/dist/valbuild-core.cjs.prod.js +1 -1
- package/dist/valbuild-core.esm.js +1 -1
- package/package.json +1 -1
- package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
- package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
- package/patch/dist/valbuild-core-patch.esm.js +2 -2
|
@@ -3034,6 +3034,50 @@ function galleryKeyOf(path, isKey) {
|
|
|
3034
3034
|
return null;
|
|
3035
3035
|
}
|
|
3036
3036
|
|
|
3037
|
+
/**
|
|
3038
|
+
* A gallery-backed field whose path the gallery, as the schema holds it, does
|
|
3039
|
+
* not have: the `image:check-gallery` (`file:`, `video:`) marker.
|
|
3040
|
+
*
|
|
3041
|
+
* The schema holds the gallery as it was EVALUATED -- in a built site, the
|
|
3042
|
+
* gallery as it was built. An entry added since (a pending change, a save in
|
|
3043
|
+
* a proposal, a content-only publish that never rebuilt the site) is only in
|
|
3044
|
+
* the gallery's current Source, so whether the field is wrong is a question
|
|
3045
|
+
* for a project-wide snapshot (`resolveSchemaSourceFixes`), as a keyOf's key
|
|
3046
|
+
* is. The message is the answer when the gallery does not have it either, so
|
|
3047
|
+
* a consumer that does not resolve markers reports what it always did.
|
|
3048
|
+
*/
|
|
3049
|
+
function galleryMarker(media, source, galleryModulePath) {
|
|
3050
|
+
var what = media === "image" ? "The gallery does not have an image" : media === "file" ? "The gallery does not have a file" : "The set does not have a video";
|
|
3051
|
+
return {
|
|
3052
|
+
message: "".concat(what, " at '").concat(source.path, "'."),
|
|
3053
|
+
value: {
|
|
3054
|
+
path: source.path,
|
|
3055
|
+
gallery: galleryModulePath,
|
|
3056
|
+
source: source
|
|
3057
|
+
},
|
|
3058
|
+
fixes: ["".concat(media, ":check-gallery")]
|
|
3059
|
+
};
|
|
3060
|
+
}
|
|
3061
|
+
|
|
3062
|
+
/** A {@link galleryMarker}'s fields, or `null` for any other error. */
|
|
3063
|
+
function galleryMarkerOf(error) {
|
|
3064
|
+
var _error$fixes;
|
|
3065
|
+
var fixes = (_error$fixes = error.fixes) !== null && _error$fixes !== void 0 ? _error$fixes : [];
|
|
3066
|
+
if (!fixes.includes("image:check-gallery") && !fixes.includes("file:check-gallery") && !fixes.includes("video:check-gallery")) {
|
|
3067
|
+
return null;
|
|
3068
|
+
}
|
|
3069
|
+
var value = error.value;
|
|
3070
|
+
if (_typeof(value) !== "object" || value === null) return null;
|
|
3071
|
+
var path = "path" in value ? value.path : undefined;
|
|
3072
|
+
var gallery = "gallery" in value ? value.gallery : undefined;
|
|
3073
|
+
if (typeof path !== "string" || typeof gallery !== "string") return null;
|
|
3074
|
+
return {
|
|
3075
|
+
path: path,
|
|
3076
|
+
gallery: gallery,
|
|
3077
|
+
source: "source" in value ? value.source : undefined
|
|
3078
|
+
};
|
|
3079
|
+
}
|
|
3080
|
+
|
|
3037
3081
|
/**
|
|
3038
3082
|
* What a gallery entry holds as a DEFAULT for the fields picked from it, in
|
|
3039
3083
|
* the groups a field overrides together.
|
|
@@ -4226,10 +4270,7 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4226
4270
|
if (galleryKeyOf(src.path, function (key) {
|
|
4227
4271
|
return key in galleryEntries;
|
|
4228
4272
|
}) === null) {
|
|
4229
|
-
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [
|
|
4230
|
-
message: "The gallery does not have an image at '".concat(src.path, "'."),
|
|
4231
|
-
value: src
|
|
4232
|
-
}]));
|
|
4273
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [galleryMarker("image", src, this.galleryModulePath())]));
|
|
4233
4274
|
}
|
|
4234
4275
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
4235
4276
|
}
|
|
@@ -4293,6 +4334,13 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
|
|
|
4293
4334
|
* alt — it carries its own — so it only needs the entry keys and the
|
|
4294
4335
|
* dimensions, and a gallery of any alt shape can back it.
|
|
4295
4336
|
*/
|
|
4337
|
+
/** The module path of the gallery this field points at. */
|
|
4338
|
+
}, {
|
|
4339
|
+
key: "galleryModulePath",
|
|
4340
|
+
value: function galleryModulePath() {
|
|
4341
|
+
var _Object$keys$;
|
|
4342
|
+
return (_Object$keys$ = Object.keys(this.moduleMetadata)[0]) !== null && _Object$keys$ !== void 0 ? _Object$keys$ : "";
|
|
4343
|
+
}
|
|
4296
4344
|
}, {
|
|
4297
4345
|
key: "galleryEntries",
|
|
4298
4346
|
value: function galleryEntries() {
|
|
@@ -10185,6 +10233,87 @@ function patchPathToModulePath(patchPath) {
|
|
|
10185
10233
|
}).join(".");
|
|
10186
10234
|
}
|
|
10187
10235
|
|
|
10236
|
+
/**
|
|
10237
|
+
* What a number schema accepts, in one place, so the validator and the
|
|
10238
|
+
* Studio's "Round to …" / "Set to …" buttons cannot disagree about it.
|
|
10239
|
+
*
|
|
10240
|
+
* A button that offers a value the validator then rejects is worse than no
|
|
10241
|
+
* button, which is exactly what two copies of this arithmetic would drift into.
|
|
10242
|
+
*/
|
|
10243
|
+
|
|
10244
|
+
/**
|
|
10245
|
+
* Division of decimals is not exact (`0.3 / 0.1` is `2.9999999999999996`), so a
|
|
10246
|
+
* value counts as on the grid when it is within this many steps of it.
|
|
10247
|
+
*/
|
|
10248
|
+
var GRID_EPSILON = 1e-9;
|
|
10249
|
+
|
|
10250
|
+
/** Where the step grid starts: the schema's `min`, or 0 when it has none. */
|
|
10251
|
+
function stepOrigin(rules) {
|
|
10252
|
+
var _rules$min;
|
|
10253
|
+
return (_rules$min = rules.min) !== null && _rules$min !== void 0 ? _rules$min : 0;
|
|
10254
|
+
}
|
|
10255
|
+
|
|
10256
|
+
/** Is `value` one of `origin + n * step`? */
|
|
10257
|
+
function isOnStep(value, origin, step) {
|
|
10258
|
+
var steps = (value - origin) / step;
|
|
10259
|
+
return Math.abs(steps - Math.round(steps)) < GRID_EPSILON;
|
|
10260
|
+
}
|
|
10261
|
+
|
|
10262
|
+
/**
|
|
10263
|
+
* The allowed value closest to `value`: inside `min`/`max`, on the step grid,
|
|
10264
|
+
* and whole when the schema is an int.
|
|
10265
|
+
*
|
|
10266
|
+
* Returns `null` when the rules leave nothing to snap to — a `min` above
|
|
10267
|
+
* `max`, or a range too narrow to hold a single step or a single whole number.
|
|
10268
|
+
*/
|
|
10269
|
+
function nearestAllowedNumber(value, rules) {
|
|
10270
|
+
var _rules$step;
|
|
10271
|
+
var step = (_rules$step = rules.step) !== null && _rules$step !== void 0 ? _rules$step : rules.integer ? 1 : undefined;
|
|
10272
|
+
var lo = rules.min;
|
|
10273
|
+
var hi = rules.max;
|
|
10274
|
+
if (lo !== undefined && hi !== undefined && lo > hi) {
|
|
10275
|
+
return null;
|
|
10276
|
+
}
|
|
10277
|
+
var clamp = function clamp(n) {
|
|
10278
|
+
return Math.min(hi !== null && hi !== void 0 ? hi : Infinity, Math.max(lo !== null && lo !== void 0 ? lo : -Infinity, n));
|
|
10279
|
+
};
|
|
10280
|
+
if (step === undefined) {
|
|
10281
|
+
return clamp(value);
|
|
10282
|
+
}
|
|
10283
|
+
var origin = rules.integer && rules.step === undefined ? 0 : stepOrigin(rules);
|
|
10284
|
+
var toGrid = function toGrid(n) {
|
|
10285
|
+
return roundToDecimals(origin + n * step);
|
|
10286
|
+
};
|
|
10287
|
+
var n = Math.round((clamp(value) - origin) / step);
|
|
10288
|
+
// Rounding can step outside the range by one; walk back in.
|
|
10289
|
+
if (lo !== undefined && toGrid(n) < lo) n += 1;
|
|
10290
|
+
if (hi !== undefined && toGrid(n) > hi) n -= 1;
|
|
10291
|
+
var snapped = toGrid(n);
|
|
10292
|
+
if (lo !== undefined && snapped < lo || hi !== undefined && snapped > hi) {
|
|
10293
|
+
return null;
|
|
10294
|
+
}
|
|
10295
|
+
if (rules.integer && !Number.isInteger(snapped)) {
|
|
10296
|
+
return null;
|
|
10297
|
+
}
|
|
10298
|
+
return snapped;
|
|
10299
|
+
}
|
|
10300
|
+
|
|
10301
|
+
/**
|
|
10302
|
+
* `0.1 + 0.2` is `0.30000000000000004`. A value offered to an editor should
|
|
10303
|
+
* read `0.3`, so grid values are rounded to 12 significant decimals — far below
|
|
10304
|
+
* any step anyone writes, far above floating point noise.
|
|
10305
|
+
*/
|
|
10306
|
+
function roundToDecimals(n) {
|
|
10307
|
+
return Number.parseFloat(n.toFixed(12));
|
|
10308
|
+
}
|
|
10309
|
+
|
|
10310
|
+
/**
|
|
10311
|
+
* What the value has to be. `integer` is what makes a number schema an
|
|
10312
|
+
* `s.int()`: the source is a number either way, so an int is a number schema
|
|
10313
|
+
* with one more rule rather than a schema type of its own (which every walk
|
|
10314
|
+
* over a schema would have had to learn).
|
|
10315
|
+
*/
|
|
10316
|
+
|
|
10188
10317
|
var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
10189
10318
|
function NumberSchema(options) {
|
|
10190
10319
|
var _this;
|
|
@@ -10194,6 +10323,7 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10194
10323
|
var isHidden = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
10195
10324
|
var description = arguments.length > 5 ? arguments[5] : undefined;
|
|
10196
10325
|
var previewInput = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
|
|
10326
|
+
var renderInput = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
|
|
10197
10327
|
_classCallCheck(this, NumberSchema);
|
|
10198
10328
|
_this = _callSuper(this, NumberSchema);
|
|
10199
10329
|
_this.options = options;
|
|
@@ -10203,6 +10333,8 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10203
10333
|
_this.isHidden = isHidden;
|
|
10204
10334
|
_this.description = description;
|
|
10205
10335
|
_this.previewInput = previewInput;
|
|
10336
|
+
_this.renderInput = renderInput;
|
|
10337
|
+
assertNumberSchemaIsConsistent(_this.options, _this.renderInput);
|
|
10206
10338
|
return _this;
|
|
10207
10339
|
}
|
|
10208
10340
|
|
|
@@ -10227,7 +10359,7 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10227
10359
|
return _createClass(NumberSchema, [{
|
|
10228
10360
|
key: "describe",
|
|
10229
10361
|
value: function describe(description) {
|
|
10230
|
-
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.previewInput);
|
|
10362
|
+
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.previewInput, this.renderInput);
|
|
10231
10363
|
}
|
|
10232
10364
|
|
|
10233
10365
|
/**
|
|
@@ -10253,12 +10385,12 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10253
10385
|
}, {
|
|
10254
10386
|
key: "validate",
|
|
10255
10387
|
value: function validate(validationFunction) {
|
|
10256
|
-
return new NumberSchema(this.options, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.previewInput);
|
|
10388
|
+
return new NumberSchema(this.options, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
10257
10389
|
}
|
|
10258
10390
|
}, {
|
|
10259
10391
|
key: "executeValidate",
|
|
10260
10392
|
value: function executeValidate(path, src) {
|
|
10261
|
-
var _this$options
|
|
10393
|
+
var _this$options;
|
|
10262
10394
|
var customValidationErrors = this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
|
|
10263
10395
|
path: path
|
|
10264
10396
|
});
|
|
@@ -10271,20 +10403,35 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10271
10403
|
value: src
|
|
10272
10404
|
}]));
|
|
10273
10405
|
}
|
|
10274
|
-
|
|
10275
|
-
|
|
10276
|
-
|
|
10406
|
+
var errors = _toConsumableArray(customValidationErrors);
|
|
10407
|
+
var options = (_this$options = this.options) !== null && _this$options !== void 0 ? _this$options : {};
|
|
10408
|
+
// `!== undefined`, not truthiness: a bound of 0 is a bound. `.max(0)` and
|
|
10409
|
+
// `.min(0)` used to be ignored, which a slider from 0 makes common.
|
|
10410
|
+
if (options.max !== undefined && src > options.max) {
|
|
10411
|
+
errors.push({
|
|
10412
|
+
message: "Must be at most ".concat(options.max),
|
|
10277
10413
|
value: src
|
|
10278
|
-
}
|
|
10414
|
+
});
|
|
10279
10415
|
}
|
|
10280
|
-
if (
|
|
10281
|
-
|
|
10282
|
-
message: "
|
|
10416
|
+
if (options.min !== undefined && src < options.min) {
|
|
10417
|
+
errors.push({
|
|
10418
|
+
message: "Must be at least ".concat(options.min),
|
|
10283
10419
|
value: src
|
|
10284
|
-
}
|
|
10420
|
+
});
|
|
10285
10421
|
}
|
|
10286
|
-
if (
|
|
10287
|
-
|
|
10422
|
+
if (options.integer && !Number.isInteger(src)) {
|
|
10423
|
+
errors.push({
|
|
10424
|
+
message: "Must be a whole number",
|
|
10425
|
+
value: src
|
|
10426
|
+
});
|
|
10427
|
+
} else if (options.step !== undefined && !isOnStep(src, stepOrigin(options), options.step)) {
|
|
10428
|
+
errors.push({
|
|
10429
|
+
message: "Must be a multiple of ".concat(options.step, ", counted from ").concat(stepOrigin(options)),
|
|
10430
|
+
value: src
|
|
10431
|
+
});
|
|
10432
|
+
}
|
|
10433
|
+
if (errors.length > 0) {
|
|
10434
|
+
return _defineProperty({}, path, errors);
|
|
10288
10435
|
}
|
|
10289
10436
|
return false;
|
|
10290
10437
|
}
|
|
@@ -10323,19 +10470,19 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10323
10470
|
}, {
|
|
10324
10471
|
key: "nullable",
|
|
10325
10472
|
value: function nullable() {
|
|
10326
|
-
return new NumberSchema(this.options, true, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput);
|
|
10473
|
+
return new NumberSchema(this.options, true, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
10327
10474
|
}
|
|
10328
10475
|
}, {
|
|
10329
10476
|
key: "readonly",
|
|
10330
10477
|
value: function readonly() {
|
|
10331
10478
|
var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
10332
|
-
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.previewInput);
|
|
10479
|
+
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
10333
10480
|
}
|
|
10334
10481
|
}, {
|
|
10335
10482
|
key: "hidden",
|
|
10336
10483
|
value: function hidden() {
|
|
10337
10484
|
var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
10338
|
-
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.previewInput);
|
|
10485
|
+
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.previewInput, this.renderInput);
|
|
10339
10486
|
}
|
|
10340
10487
|
|
|
10341
10488
|
/**
|
|
@@ -10350,7 +10497,7 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10350
10497
|
value: function max(_max) {
|
|
10351
10498
|
return new NumberSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
10352
10499
|
max: _max
|
|
10353
|
-
}), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput);
|
|
10500
|
+
}), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
10354
10501
|
}
|
|
10355
10502
|
|
|
10356
10503
|
/**
|
|
@@ -10365,7 +10512,50 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10365
10512
|
value: function min(_min) {
|
|
10366
10513
|
return new NumberSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
10367
10514
|
min: _min
|
|
10368
|
-
}), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput);
|
|
10515
|
+
}), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
10516
|
+
}
|
|
10517
|
+
|
|
10518
|
+
/**
|
|
10519
|
+
* Validate that the number is on a grid of `step`: one of `min`, `min + step`,
|
|
10520
|
+
* `min + 2 * step` and so on, counted from 0 when there is no `.min()`.
|
|
10521
|
+
*
|
|
10522
|
+
* A slider rendered on this field moves in the same steps unless its render
|
|
10523
|
+
* says otherwise (and then its step has to be a multiple of this one).
|
|
10524
|
+
*
|
|
10525
|
+
* @example
|
|
10526
|
+
* const schema = s.int().min(0).max(100).step(5);
|
|
10527
|
+
* export default c.define("/example.val.ts", schema, 40);
|
|
10528
|
+
*/
|
|
10529
|
+
}, {
|
|
10530
|
+
key: "step",
|
|
10531
|
+
value: function step(_step) {
|
|
10532
|
+
return new NumberSchema(_objectSpread2(_objectSpread2({}, this.options), {}, {
|
|
10533
|
+
step: _step
|
|
10534
|
+
}), this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
10535
|
+
}
|
|
10536
|
+
|
|
10537
|
+
/**
|
|
10538
|
+
* Choose how this field is edited. `{ as: "slider", min, max }` edits it with
|
|
10539
|
+
* a slider from `min` to `max`, next to a box for typing an exact value.
|
|
10540
|
+
*
|
|
10541
|
+
* `min` and `max` are required — a slider without ends is not a slider — and
|
|
10542
|
+
* they are the slider's, not validation: use `.min()` / `.max()` for what the
|
|
10543
|
+
* value may be. The slider can only produce values this schema accepts, so
|
|
10544
|
+
* its range must lie inside `.min()`/`.max()`, its `step` (which defaults to
|
|
10545
|
+
* `.step()`, then 1) must be a multiple of `.step()`, and on `s.int()` all of
|
|
10546
|
+
* them must be whole numbers. A schema that breaks this throws here.
|
|
10547
|
+
*
|
|
10548
|
+
* Static configuration, not a callback — see `render.ts`. A second
|
|
10549
|
+
* `.render(...)` replaces the first.
|
|
10550
|
+
*
|
|
10551
|
+
* @example
|
|
10552
|
+
* const schema = s.int().render({ as: "slider", min: 0, max: 100, step: 5 });
|
|
10553
|
+
* export default c.define("/example.val.ts", schema, 40);
|
|
10554
|
+
*/
|
|
10555
|
+
}, {
|
|
10556
|
+
key: "render",
|
|
10557
|
+
value: function render(input) {
|
|
10558
|
+
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, input);
|
|
10369
10559
|
}
|
|
10370
10560
|
}, {
|
|
10371
10561
|
key: "executeCustomValidateAt",
|
|
@@ -10389,7 +10579,7 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10389
10579
|
}, {
|
|
10390
10580
|
key: "preview",
|
|
10391
10581
|
value: function preview(select) {
|
|
10392
|
-
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, select);
|
|
10582
|
+
return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, select, this.renderInput);
|
|
10393
10583
|
}
|
|
10394
10584
|
}, {
|
|
10395
10585
|
key: "executePreviewItem",
|
|
@@ -10409,11 +10599,12 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10409
10599
|
}, {
|
|
10410
10600
|
key: "executeSerialize",
|
|
10411
10601
|
value: function executeSerialize() {
|
|
10412
|
-
var _this$customValidateF;
|
|
10602
|
+
var _this$renderInput, _this$customValidateF;
|
|
10413
10603
|
return {
|
|
10414
10604
|
type: "number",
|
|
10415
10605
|
preview: this.previewInput ? true : undefined,
|
|
10416
10606
|
options: this.options,
|
|
10607
|
+
render: (_this$renderInput = this.renderInput) !== null && _this$renderInput !== void 0 ? _this$renderInput : undefined,
|
|
10417
10608
|
opt: this.opt,
|
|
10418
10609
|
customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
|
|
10419
10610
|
readonly: this.isReadonly,
|
|
@@ -10426,6 +10617,63 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
|
|
|
10426
10617
|
var number = function number(options) {
|
|
10427
10618
|
return new NumberSchema(options);
|
|
10428
10619
|
};
|
|
10620
|
+
var _int = function _int() {
|
|
10621
|
+
return new NumberSchema({
|
|
10622
|
+
integer: true
|
|
10623
|
+
});
|
|
10624
|
+
};
|
|
10625
|
+
function assertNumberSchemaIsConsistent(options, render) {
|
|
10626
|
+
var opts = options !== null && options !== void 0 ? options : {};
|
|
10627
|
+
var kind = opts.integer ? "s.int()" : "s.number()";
|
|
10628
|
+
if (opts.step !== undefined) {
|
|
10629
|
+
if (!(opts.step > 0) || !Number.isFinite(opts.step)) {
|
|
10630
|
+
throw new Error("".concat(kind, ".step(").concat(opts.step, "): the step must be above 0"));
|
|
10631
|
+
}
|
|
10632
|
+
if (opts.integer && !Number.isInteger(opts.step)) {
|
|
10633
|
+
throw new Error("".concat(kind, ".step(").concat(opts.step, "): the step of an int must be a whole number"));
|
|
10634
|
+
}
|
|
10635
|
+
}
|
|
10636
|
+
if (render === null) {
|
|
10637
|
+
return;
|
|
10638
|
+
}
|
|
10639
|
+
var where = "".concat(kind, ".render({ as: \"slider\", min: ").concat(render.min, ", max: ").concat(render.max, " })");
|
|
10640
|
+
if (!Number.isFinite(render.min) || !Number.isFinite(render.max)) {
|
|
10641
|
+
throw new Error("".concat(where, ": the slider needs a min and a max"));
|
|
10642
|
+
}
|
|
10643
|
+
if (!(render.min < render.max)) {
|
|
10644
|
+
throw new Error("".concat(where, ": the slider's min must be below its max"));
|
|
10645
|
+
}
|
|
10646
|
+
if (opts.min !== undefined && render.min < opts.min) {
|
|
10647
|
+
throw new Error("".concat(where, ": the slider's min ").concat(render.min, " is below the schema's min ").concat(opts.min));
|
|
10648
|
+
}
|
|
10649
|
+
if (opts.max !== undefined && render.max > opts.max) {
|
|
10650
|
+
throw new Error("".concat(where, ": the slider's max ").concat(render.max, " is above the schema's max ").concat(opts.max));
|
|
10651
|
+
}
|
|
10652
|
+
if (render.step !== undefined && !(render.step > 0)) {
|
|
10653
|
+
throw new Error("".concat(where, ": the slider's step must be above 0"));
|
|
10654
|
+
}
|
|
10655
|
+
if (opts.integer) {
|
|
10656
|
+
var sliderNumbers = [["min", render.min], ["max", render.max], ["step", render.step]];
|
|
10657
|
+
for (var _i = 0, _sliderNumbers = sliderNumbers; _i < _sliderNumbers.length; _i++) {
|
|
10658
|
+
var _sliderNumbers$_i = _slicedToArray(_sliderNumbers[_i], 2),
|
|
10659
|
+
name = _sliderNumbers$_i[0],
|
|
10660
|
+
value = _sliderNumbers$_i[1];
|
|
10661
|
+
if (value !== undefined && !Number.isInteger(value)) {
|
|
10662
|
+
throw new Error("".concat(where, ": the slider's ").concat(name, " ").concat(value, " must be a whole number on an int"));
|
|
10663
|
+
}
|
|
10664
|
+
}
|
|
10665
|
+
}
|
|
10666
|
+
if (opts.step !== undefined) {
|
|
10667
|
+
var _render$step;
|
|
10668
|
+
var sliderStep = (_render$step = render.step) !== null && _render$step !== void 0 ? _render$step : opts.step;
|
|
10669
|
+
if (!isOnStep(sliderStep, 0, opts.step)) {
|
|
10670
|
+
throw new Error("".concat(where, ": the slider's step ").concat(sliderStep, " must be a multiple of the schema's step ").concat(opts.step));
|
|
10671
|
+
}
|
|
10672
|
+
if (!isOnStep(render.min, stepOrigin(opts), opts.step)) {
|
|
10673
|
+
throw new Error("".concat(where, ": the slider's min ").concat(render.min, " is not one of the schema's steps (").concat(opts.step, ", counted from ").concat(stepOrigin(opts), ")"));
|
|
10674
|
+
}
|
|
10675
|
+
}
|
|
10676
|
+
}
|
|
10429
10677
|
|
|
10430
10678
|
/**
|
|
10431
10679
|
* @deprecated Use {@link SerializedDiscriminatedUnionSchema} or
|
|
@@ -11025,10 +11273,8 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
|
|
|
11025
11273
|
if (galleryKeyOf(src.path, function (key) {
|
|
11026
11274
|
return key in galleryEntries;
|
|
11027
11275
|
}) === null) {
|
|
11028
|
-
|
|
11029
|
-
|
|
11030
|
-
value: src
|
|
11031
|
-
}]));
|
|
11276
|
+
var _Object$keys$;
|
|
11277
|
+
return _defineProperty({}, path, [].concat(_toConsumableArray(customValidationErrors), [galleryMarker("file", src, (_Object$keys$ = Object.keys(this.moduleMetadata)[0]) !== null && _Object$keys$ !== void 0 ? _Object$keys$ : "")]));
|
|
11032
11278
|
}
|
|
11033
11279
|
return customValidationErrors.length > 0 ? _defineProperty({}, path, customValidationErrors) : false;
|
|
11034
11280
|
}
|
|
@@ -11484,10 +11730,7 @@ var VideoSchema = /*#__PURE__*/function (_Schema) {
|
|
|
11484
11730
|
}
|
|
11485
11731
|
var entry = gallery.entries === null ? null : gallery.entries[src.path];
|
|
11486
11732
|
if (entry === undefined) {
|
|
11487
|
-
return [
|
|
11488
|
-
message: "The set does not have a video at '".concat(src.path, "'."),
|
|
11489
|
-
value: src
|
|
11490
|
-
}];
|
|
11733
|
+
return [galleryMarker("video", src, gallery.modulePath)];
|
|
11491
11734
|
}
|
|
11492
11735
|
// The poster and the captions are the field's own files, and live where
|
|
11493
11736
|
// the set keeps its videos. The video itself is the set's to move.
|
|
@@ -13204,6 +13447,7 @@ function initSchema(options) {
|
|
|
13204
13447
|
array: array,
|
|
13205
13448
|
object: object,
|
|
13206
13449
|
number: number,
|
|
13450
|
+
"int": _int,
|
|
13207
13451
|
discriminatedUnion: discriminatedUnion,
|
|
13208
13452
|
"enum": enumSchema,
|
|
13209
13453
|
union: union,
|
|
@@ -15114,7 +15358,7 @@ function deserializeSchema(serialized) {
|
|
|
15114
15358
|
return schema;
|
|
15115
15359
|
}
|
|
15116
15360
|
function deserializeSchemaImpl(serialized) {
|
|
15117
|
-
var _serialized$options, _serialized$options2, _serialized$multiline, _serialized$render, _serialized$accept, _serialized$dir, _serialized$remote, _serialized$jsonValue, _serialized$
|
|
15361
|
+
var _serialized$options, _serialized$options2, _serialized$multiline, _serialized$render, _serialized$render2, _serialized$accept, _serialized$dir, _serialized$remote, _serialized$jsonValue, _serialized$render3, _serialized$external, _serialized$render4, _serialized$render5, _serialized$remote2, _serialized$readonly, _serialized$hidden;
|
|
15118
15362
|
switch (serialized.type) {
|
|
15119
15363
|
case "string":
|
|
15120
15364
|
return new StringSchema(_objectSpread2(_objectSpread2({}, serialized.options), {}, {
|
|
@@ -15126,7 +15370,7 @@ function deserializeSchemaImpl(serialized) {
|
|
|
15126
15370
|
case "boolean":
|
|
15127
15371
|
return new BooleanSchema(serialized.opt, [], false, false, serialized.description);
|
|
15128
15372
|
case "number":
|
|
15129
|
-
return new NumberSchema(serialized.options, serialized.opt, [], false, false, serialized.description);
|
|
15373
|
+
return new NumberSchema(serialized.options, serialized.opt, [], false, false, serialized.description, null, (_serialized$render = serialized.render) !== null && _serialized$render !== void 0 ? _serialized$render : null);
|
|
15130
15374
|
case "object":
|
|
15131
15375
|
return new ObjectSchema(Object.fromEntries(Object.entries(serialized.items).map(function (_ref) {
|
|
15132
15376
|
var _ref2 = _slicedToArray(_ref, 2),
|
|
@@ -15149,7 +15393,7 @@ function deserializeSchemaImpl(serialized) {
|
|
|
15149
15393
|
case "array":
|
|
15150
15394
|
return new ArraySchema(deserializeSchema(serialized.item), serialized.opt, [], false, false, serialized.description,
|
|
15151
15395
|
// The preview closure cannot survive serialization; the render can.
|
|
15152
|
-
null, (_serialized$
|
|
15396
|
+
null, (_serialized$render2 = serialized.render) !== null && _serialized$render2 !== void 0 ? _serialized$render2 : null);
|
|
15153
15397
|
case "discriminated-union":
|
|
15154
15398
|
return new DiscriminatedUnionSchema(serialized.key,
|
|
15155
15399
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -15178,12 +15422,12 @@ function deserializeSchemaImpl(serialized) {
|
|
|
15178
15422
|
altSchema: serialized.alt ? deserializeSchema(serialized.alt) : undefined
|
|
15179
15423
|
} : undefined, false, false, serialized.description, (_serialized$jsonValue = serialized.jsonValues) !== null && _serialized$jsonValue !== void 0 ? _serialized$jsonValue : false,
|
|
15180
15424
|
// The preview closure cannot survive serialization; the render can.
|
|
15181
|
-
null, (_serialized$
|
|
15425
|
+
null, (_serialized$render3 = serialized.render) !== null && _serialized$render3 !== void 0 ? _serialized$render3 : null, // The external label is static data, so it survives serialization and
|
|
15182
15426
|
// must be carried back: a deserialized schema that forgot it would walk
|
|
15183
15427
|
// an external record as if its entries were local.
|
|
15184
15428
|
(_serialized$external = serialized.external) !== null && _serialized$external !== void 0 ? _serialized$external : null);
|
|
15185
15429
|
case "keyOf":
|
|
15186
|
-
return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt, [], false, false, serialized.description, (_serialized$
|
|
15430
|
+
return new KeyOfSchema(serialized.schema, serialized.path, serialized.opt, [], false, false, serialized.description, (_serialized$render4 = serialized.render) !== null && _serialized$render4 !== void 0 ? _serialized$render4 : null);
|
|
15187
15431
|
case "locale":
|
|
15188
15432
|
{
|
|
15189
15433
|
return new LocaleSchema(serialized.opt, [], false, false, serialized.description);
|
|
@@ -15201,7 +15445,7 @@ function deserializeSchemaImpl(serialized) {
|
|
|
15201
15445
|
case "image":
|
|
15202
15446
|
return new ImageSchema(serialized.options, serialized.opt, serialized.remote, [], {}, false, false, serialized.description);
|
|
15203
15447
|
case "video":
|
|
15204
|
-
return new VideoSchema(serialized.options, serialized.opt, serialized.remote, [], false, false, serialized.description, (_serialized$
|
|
15448
|
+
return new VideoSchema(serialized.options, serialized.opt, serialized.remote, [], false, false, serialized.description, (_serialized$render5 = serialized.render) !== null && _serialized$render5 !== void 0 ? _serialized$render5 : null, null, serialized.referencedModule ? {
|
|
15205
15449
|
modulePath: serialized.referencedModule,
|
|
15206
15450
|
entries: null,
|
|
15207
15451
|
remote: (_serialized$remote2 = serialized.remote) !== null && _serialized$remote2 !== void 0 ? _serialized$remote2 : false
|
|
@@ -15260,11 +15504,12 @@ function deserializeSchemaImpl(serialized) {
|
|
|
15260
15504
|
*/
|
|
15261
15505
|
/**
|
|
15262
15506
|
* A RENDER is how a field is laid out in the editor, and it applies only when
|
|
15263
|
-
* you are looking at the field.
|
|
15264
|
-
* children, never by a child about itself: `s.array(item).render({ as: "inline" })`
|
|
15265
|
-
* and `s.record(item).render({ as: "inline" })`.
|
|
15266
|
-
*
|
|
15267
|
-
* `KeyOfSchema.render`).
|
|
15507
|
+
* you are looking at the field. On a list it is declared by the CONTAINER about
|
|
15508
|
+
* its children, never by a child about itself: `s.array(item).render({ as: "inline" })`
|
|
15509
|
+
* and `s.record(item).render({ as: "inline" })`. Two other schemas take a
|
|
15510
|
+
* render, each meaning something of its own: `s.keyOf(...)` (see
|
|
15511
|
+
* `KeyOfSchema.render`) and `s.number()` / `s.int()`, whose `{ as: "slider" }`
|
|
15512
|
+
* is a different input for the same value (see {@link SliderRender}).
|
|
15268
15513
|
*
|
|
15269
15514
|
* Why the container: inline is a property of the LIST — "my items are edited in
|
|
15270
15515
|
* their rows" — and the item schema is the wrong place to say it. An item can be
|
|
@@ -15320,6 +15565,33 @@ function deserializeSchemaImpl(serialized) {
|
|
|
15320
15565
|
* What `.render(...)` takes, and what the serialized schema carries verbatim.
|
|
15321
15566
|
*/
|
|
15322
15567
|
|
|
15568
|
+
/**
|
|
15569
|
+
* `{ as: "slider", min, max }` on `s.int()` or `s.number()`: the value is
|
|
15570
|
+
* edited with a slider from `min` to `max`, next to a box that takes a typed
|
|
15571
|
+
* value.
|
|
15572
|
+
*
|
|
15573
|
+
* `min` and `max` are REQUIRED, because a slider without ends is not a slider.
|
|
15574
|
+
* They are the slider's own and are not validation: a value outside them is
|
|
15575
|
+
* still valid content (if the schema allows it), and the field says it is out
|
|
15576
|
+
* of the slider's reach and offers to bring it back. What the schema accepts is
|
|
15577
|
+
* `.min()`, `.max()` and `.step()` on the schema itself.
|
|
15578
|
+
*
|
|
15579
|
+
* The one rule tying the two together: **the slider may only produce values
|
|
15580
|
+
* the schema accepts.** So its range has to lie inside the schema's, its step
|
|
15581
|
+
* has to be a multiple of the schema's step and its `min` on the schema's grid,
|
|
15582
|
+
* and on `s.int()` all of them have to be whole numbers. A schema that breaks
|
|
15583
|
+
* that throws where it is defined — see `NumberSchema`.
|
|
15584
|
+
*
|
|
15585
|
+
* `step` defaults to the schema's `.step()`, and to 1 when there is none.
|
|
15586
|
+
*
|
|
15587
|
+
* Unlike `inline` this is about the field itself — no list reads it, and
|
|
15588
|
+
* {@link isInlineRender} answers `false` for it.
|
|
15589
|
+
*/
|
|
15590
|
+
|
|
15591
|
+
/**
|
|
15592
|
+
* What `s.number().render(...)` and `s.int().render(...)` take.
|
|
15593
|
+
*/
|
|
15594
|
+
|
|
15323
15595
|
/**
|
|
15324
15596
|
* Does this CONTAINER edit its items inside their list rows, rather than behind
|
|
15325
15597
|
* clickable preview rows that navigate to them?
|
|
@@ -15901,7 +16173,7 @@ function isPageRouter(routerId) {
|
|
|
15901
16173
|
|
|
15902
16174
|
var corePackageJson = {
|
|
15903
16175
|
name: "@valbuild/core",
|
|
15904
|
-
version: "0.
|
|
16176
|
+
version: "0.146.2",
|
|
15905
16177
|
"private": false,
|
|
15906
16178
|
description: "Val - supercharged hard-coded content",
|
|
15907
16179
|
repository: {
|
|
@@ -16008,6 +16280,7 @@ var Internal = {
|
|
|
16008
16280
|
galleriesOf: galleriesOf,
|
|
16009
16281
|
galleryEntryOf: galleryEntryOf,
|
|
16010
16282
|
galleryKeyOf: galleryKeyOf,
|
|
16283
|
+
galleryMarkerOf: galleryMarkerOf,
|
|
16011
16284
|
GALLERY_DEFAULT_GROUPS: GALLERY_DEFAULT_GROUPS,
|
|
16012
16285
|
isHlsVideo: isHlsVideo,
|
|
16013
16286
|
HLS_MIME_TYPE: HLS_MIME_TYPE
|
|
@@ -16028,6 +16301,11 @@ var Internal = {
|
|
|
16028
16301
|
rejectScheme: rejectScheme,
|
|
16029
16302
|
schemeOf: schemeOf,
|
|
16030
16303
|
UNSAFE_URL_SCHEMES: UNSAFE_URL_SCHEMES,
|
|
16304
|
+
number: {
|
|
16305
|
+
nearestAllowedNumber: nearestAllowedNumber,
|
|
16306
|
+
isOnStep: isOnStep,
|
|
16307
|
+
stepOrigin: stepOrigin
|
|
16308
|
+
},
|
|
16031
16309
|
color: {
|
|
16032
16310
|
parseColor: parseColor,
|
|
16033
16311
|
formatColor: formatColor,
|