@valbuild/core 0.117.0 → 0.121.0

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 (38) hide show
  1. package/CHANGELOG.md +135 -0
  2. package/dist/declarations/src/index.d.ts +3 -0
  3. package/dist/declarations/src/initSchema.d.ts +27 -0
  4. package/dist/declarations/src/initVal.d.ts +11 -8
  5. package/dist/declarations/src/schema/array.d.ts +2 -2
  6. package/dist/declarations/src/schema/boolean.d.ts +2 -2
  7. package/dist/declarations/src/schema/code.d.ts +2 -2
  8. package/dist/declarations/src/schema/color.d.ts +2 -2
  9. package/dist/declarations/src/schema/date.d.ts +2 -2
  10. package/dist/declarations/src/schema/datetime.d.ts +2 -2
  11. package/dist/declarations/src/schema/file.d.ts +2 -2
  12. package/dist/declarations/src/schema/image.d.ts +2 -2
  13. package/dist/declarations/src/schema/index.d.ts +12 -3
  14. package/dist/declarations/src/schema/keyOf.d.ts +2 -2
  15. package/dist/declarations/src/schema/literal.d.ts +2 -2
  16. package/dist/declarations/src/schema/number.d.ts +2 -2
  17. package/dist/declarations/src/schema/object.d.ts +2 -2
  18. package/dist/declarations/src/schema/record.d.ts +2 -2
  19. package/dist/declarations/src/schema/richtext.d.ts +3 -3
  20. package/dist/declarations/src/schema/route.d.ts +2 -2
  21. package/dist/declarations/src/schema/settings.d.ts +102 -0
  22. package/dist/declarations/src/schema/string.d.ts +2 -2
  23. package/dist/declarations/src/schema/union.d.ts +2 -2
  24. package/dist/declarations/src/selector/index.d.ts +3 -2
  25. package/dist/declarations/src/settingsModule.d.ts +60 -0
  26. package/dist/declarations/src/source/index.d.ts +2 -1
  27. package/dist/declarations/src/source/richtext.d.ts +57 -67
  28. package/dist/declarations/src/source/settings.d.ts +94 -0
  29. package/dist/{index-b8004eea.esm.js → index-5fe6fb98.esm.js} +767 -266
  30. package/dist/{index-941877c6.cjs.prod.js → index-61237991.cjs.prod.js} +772 -265
  31. package/dist/{index-0ba5047e.cjs.dev.js → index-9860179f.cjs.dev.js} +772 -265
  32. package/dist/valbuild-core.cjs.dev.js +7 -1
  33. package/dist/valbuild-core.cjs.prod.js +7 -1
  34. package/dist/valbuild-core.esm.js +1 -1
  35. package/package.json +1 -1
  36. package/patch/dist/valbuild-core-patch.cjs.dev.js +1 -1
  37. package/patch/dist/valbuild-core-patch.cjs.prod.js +1 -1
  38. package/patch/dist/valbuild-core-patch.esm.js +2 -2
@@ -591,12 +591,14 @@ var StringSchema = /*#__PURE__*/function (_Schema) {
591
591
  }, {
592
592
  key: "readonly",
593
593
  value: function readonly() {
594
- return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions, this.renderInput, true, this.isHidden, this.description, this.previewInput, this.isMultiline);
594
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
595
+ return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions, this.renderInput, isReadonly, this.isHidden, this.description, this.previewInput, this.isMultiline);
595
596
  }
596
597
  }, {
597
598
  key: "hidden",
598
599
  value: function hidden() {
599
- return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions, this.renderInput, this.isReadonly, true, this.description, this.previewInput, this.isMultiline);
600
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
601
+ return new StringSchema(this.options, this.opt, this.isRaw, this.customValidateFunctions, this.renderInput, this.isReadonly, isHidden, this.description, this.previewInput, this.isMultiline);
600
602
  }
601
603
  }, {
602
604
  key: "raw",
@@ -869,12 +871,14 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
869
871
  }, {
870
872
  key: "readonly",
871
873
  value: function readonly() {
872
- return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
874
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
875
+ return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
873
876
  }
874
877
  }, {
875
878
  key: "hidden",
876
879
  value: function hidden() {
877
- return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
880
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
881
+ return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
878
882
  }
879
883
  }, {
880
884
  key: "executeCustomValidateAt",
@@ -1085,12 +1089,14 @@ var ArraySchema = /*#__PURE__*/function (_Schema) {
1085
1089
  }, {
1086
1090
  key: "readonly",
1087
1091
  value: function readonly() {
1088
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.previewInput, this.renderInput);
1092
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1093
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
1089
1094
  }
1090
1095
  }, {
1091
1096
  key: "hidden",
1092
1097
  value: function hidden() {
1093
- return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.previewInput, this.renderInput);
1098
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1099
+ return new ArraySchema(this.item, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.previewInput, this.renderInput);
1094
1100
  }
1095
1101
  }, {
1096
1102
  key: "executeCustomValidateAt",
@@ -1338,12 +1344,14 @@ var LiteralSchema = /*#__PURE__*/function (_Schema) {
1338
1344
  }, {
1339
1345
  key: "readonly",
1340
1346
  value: function readonly() {
1341
- return new LiteralSchema(this.value, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
1347
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1348
+ return new LiteralSchema(this.value, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
1342
1349
  }
1343
1350
  }, {
1344
1351
  key: "hidden",
1345
1352
  value: function hidden() {
1346
- return new LiteralSchema(this.value, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
1353
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1354
+ return new LiteralSchema(this.value, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
1347
1355
  }
1348
1356
  }, {
1349
1357
  key: "executeCustomValidateAt",
@@ -1749,12 +1757,14 @@ var UnionSchema = /*#__PURE__*/function (_Schema) {
1749
1757
  }, {
1750
1758
  key: "readonly",
1751
1759
  value: function readonly() {
1752
- return new UnionSchema(this.key, this.items, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
1760
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1761
+ return new UnionSchema(this.key, this.items, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
1753
1762
  }
1754
1763
  }, {
1755
1764
  key: "hidden",
1756
1765
  value: function hidden() {
1757
- return new UnionSchema(this.key, this.items, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
1766
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
1767
+ return new UnionSchema(this.key, this.items, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
1758
1768
  }
1759
1769
  }, {
1760
1770
  key: "executeCustomValidateAt",
@@ -3127,12 +3137,14 @@ var ImageSchema = /*#__PURE__*/function (_Schema) {
3127
3137
  }, {
3128
3138
  key: "readonly",
3129
3139
  value: function readonly() {
3130
- return new ImageSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, true, this.isHidden, this.description, this.renderInput, this.previewInput);
3140
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
3141
+ return new ImageSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
3131
3142
  }
3132
3143
  }, {
3133
3144
  key: "hidden",
3134
3145
  value: function hidden() {
3135
- return new ImageSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
3146
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
3147
+ return new ImageSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
3136
3148
  }
3137
3149
  }, {
3138
3150
  key: "executeCustomValidateAt",
@@ -3364,12 +3376,14 @@ var RouteSchema = /*#__PURE__*/function (_Schema) {
3364
3376
  }, {
3365
3377
  key: "readonly",
3366
3378
  value: function readonly() {
3367
- return new RouteSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
3379
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
3380
+ return new RouteSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
3368
3381
  }
3369
3382
  }, {
3370
3383
  key: "hidden",
3371
3384
  value: function hidden() {
3372
- return new RouteSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
3385
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
3386
+ return new RouteSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
3373
3387
  }
3374
3388
  }, {
3375
3389
  key: "executeCustomValidateAt",
@@ -3553,7 +3567,6 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3553
3567
  _step;
3554
3568
  try {
3555
3569
  var _loop = function _loop() {
3556
- var _this2$options$block, _this2$options$block2, _this2$options$block3, _this2$options$block4, _this2$options$block5, _this2$options$block6, _this2$options$block7, _this2$options$block8, _this2$options$block9, _this2$options$block0;
3557
3570
  var node = _step.value;
3558
3571
  var path = unsafeCreateSourcePath(rootPath, nodes.indexOf(node));
3559
3572
  if (typeof node === "string") {
@@ -3596,39 +3609,37 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3596
3609
  if (!supportedTags.includes(node.tag)) {
3597
3610
  addError(path, "Tag '".concat(node.tag, "' is not supported. Supported tags: ").concat(supportedTags.join(", ")), true);
3598
3611
  }
3599
- if (node.tag === "h1" && !((_this2$options$block = _this2.options.block) !== null && _this2$options$block !== void 0 && _this2$options$block.h1)) {
3600
- addError(path, "'h' block is not valid", false);
3612
+ if (node.tag === "h1" && !_this2.options.h1) {
3613
+ addError(path, "'h1' block is not valid", false);
3601
3614
  }
3602
- if (node.tag === "h2" && !((_this2$options$block2 = _this2.options.block) !== null && _this2$options$block2 !== void 0 && _this2$options$block2.h2)) {
3615
+ if (node.tag === "h2" && !_this2.options.h2) {
3603
3616
  addError(path, "'h2' block is not valid", false);
3604
3617
  }
3605
- if (node.tag === "h3" && !((_this2$options$block3 = _this2.options.block) !== null && _this2$options$block3 !== void 0 && _this2$options$block3.h3)) {
3618
+ if (node.tag === "h3" && !_this2.options.h3) {
3606
3619
  addError(path, "'h3' block is not valid", false);
3607
3620
  }
3608
- if (node.tag === "h4" && !((_this2$options$block4 = _this2.options.block) !== null && _this2$options$block4 !== void 0 && _this2$options$block4.h4)) {
3621
+ if (node.tag === "h4" && !_this2.options.h4) {
3609
3622
  addError(path, "'h4' block is not valid", false);
3610
3623
  }
3611
- if (node.tag === "h5" && !((_this2$options$block5 = _this2.options.block) !== null && _this2$options$block5 !== void 0 && _this2$options$block5.h5)) {
3624
+ if (node.tag === "h5" && !_this2.options.h5) {
3612
3625
  addError(path, "'h5' block is not valid", false);
3613
3626
  }
3614
- if (node.tag === "h6" && !((_this2$options$block6 = _this2.options.block) !== null && _this2$options$block6 !== void 0 && _this2$options$block6.h6)) {
3627
+ if (node.tag === "h6" && !_this2.options.h6) {
3615
3628
  addError(path, "'h6' block is not valid", false);
3616
3629
  }
3617
- if (node.tag === "ol" && !((_this2$options$block7 = _this2.options.block) !== null && _this2$options$block7 !== void 0 && _this2$options$block7.ol)) {
3630
+ if (node.tag === "ol" && !_this2.options.ol) {
3618
3631
  addError(path, "'ol' block is not valid", false);
3619
3632
  }
3620
- if (node.tag === "ul" && !((_this2$options$block8 = _this2.options.block) !== null && _this2$options$block8 !== void 0 && _this2$options$block8.ul)) {
3633
+ if (node.tag === "ul" && !_this2.options.ul) {
3621
3634
  addError(path, "'ul' block is not valid", false);
3622
3635
  }
3623
- if (node.tag === "li" && !((_this2$options$block9 = _this2.options.block) !== null && _this2$options$block9 !== void 0 && _this2$options$block9.ul) && !((_this2$options$block0 = _this2.options.block) !== null && _this2$options$block0 !== void 0 && _this2$options$block0.ol)) {
3624
- addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is not valid", false);
3636
+ if (node.tag === "li" && !_this2.options.ul && !_this2.options.ol) {
3637
+ addError(path, "'li' tag is invalid since neither 'ul' nor 'ol' block is valid", false);
3625
3638
  }
3626
3639
  if (node.tag === "a") {
3627
- var _this2$options$inline, _this2$options$inline2;
3628
- if (!((_this2$options$inline = _this2.options.inline) !== null && _this2$options$inline !== void 0 && _this2$options$inline.a)) {
3640
+ if (!_this2.options.a) {
3629
3641
  addError(path, "'a' inline is not valid", false);
3630
- } else if ((_this2$options$inline2 = _this2.options.inline) !== null && _this2$options$inline2 !== void 0 && _this2$options$inline2.a) {
3631
- var _this2$options$inline3;
3642
+ } else if (_this2.options.a) {
3632
3643
  if (!("href" in node)) {
3633
3644
  return {
3634
3645
  v: _defineProperty({}, path, [{
@@ -3638,7 +3649,7 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3638
3649
  };
3639
3650
  }
3640
3651
  var hrefPath = unsafeCreateSourcePath(path, "href");
3641
- var hrefSchema = typeof ((_this2$options$inline3 = _this2.options.inline) === null || _this2$options$inline3 === void 0 ? void 0 : _this2$options$inline3.a) === "boolean" ? new RouteSchema() : _this2.options.inline.a;
3652
+ var hrefSchema = typeof _this2.options.a === "boolean" ? new RouteSchema() : _this2.options.a;
3642
3653
  var executeValidate = function executeValidate() {
3643
3654
  if (hrefSchema instanceof RouteSchema) {
3644
3655
  return hrefSchema["executeValidate"](hrefPath, node.href);
@@ -3664,11 +3675,9 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3664
3675
  }
3665
3676
  }
3666
3677
  if (node.tag === "img") {
3667
- var _this2$options$inline4, _this2$options$inline5;
3668
- if (!((_this2$options$inline4 = _this2.options.inline) !== null && _this2$options$inline4 !== void 0 && _this2$options$inline4.img)) {
3678
+ if (!_this2.options.img) {
3669
3679
  addError(path, "'img' inline is not valid", false);
3670
- } else if ((_this2$options$inline5 = _this2.options.inline) !== null && _this2$options$inline5 !== void 0 && _this2$options$inline5.img) {
3671
- var _this2$options$inline6;
3680
+ } else if (_this2.options.img) {
3672
3681
  if (!("src" in node)) {
3673
3682
  return {
3674
3683
  v: _defineProperty({}, path, [{
@@ -3678,7 +3687,7 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3678
3687
  };
3679
3688
  }
3680
3689
  var srcPath = unsafeCreateSourcePath(path, "src");
3681
- var imgSchema = (_this2$options$inline6 = _this2.options.inline) === null || _this2$options$inline6 === void 0 ? void 0 : _this2$options$inline6.img;
3690
+ var imgSchema = _this2.options.img;
3682
3691
  var imageValidationErrors = _typeof(imgSchema) === "object" ? imgSchema["executeValidate"](srcPath, node.src) : new ImageSchema({}, false, false)["executeValidate"](srcPath, node.src);
3683
3692
  if (imageValidationErrors) {
3684
3693
  for (var _validationErrorPathS in imageValidationErrors) {
@@ -3711,7 +3720,6 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3711
3720
  }
3712
3721
  var stylesPath = unsafeCreateSourcePath(path, "styles");
3713
3722
  for (var i = 0; i < node.styles.length; i++) {
3714
- var _this2$options$style, _this2$options$style2, _this2$options$style3;
3715
3723
  var style = node.styles[i];
3716
3724
  var currentStylePath = unsafeCreateSourcePath(stylesPath, i);
3717
3725
  if (typeof style !== "string") {
@@ -3722,13 +3730,13 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3722
3730
  }])
3723
3731
  };
3724
3732
  }
3725
- if (style === "bold" && !((_this2$options$style = _this2.options.style) !== null && _this2$options$style !== void 0 && _this2$options$style.bold)) {
3733
+ if (style === "bold" && !_this2.options.bold) {
3726
3734
  addError(currentStylePath, "Style 'bold' is not valid", false);
3727
3735
  }
3728
- if (style === "italic" && !((_this2$options$style2 = _this2.options.style) !== null && _this2$options$style2 !== void 0 && _this2$options$style2.italic)) {
3736
+ if (style === "italic" && !_this2.options.italic) {
3729
3737
  addError(currentStylePath, "Style 'italic' is not valid", false);
3730
3738
  }
3731
- if (style === "lineThrough" && !((_this2$options$style3 = _this2.options.style) !== null && _this2$options$style3 !== void 0 && _this2$options$style3.lineThrough)) {
3739
+ if (style === "lineThrough" && !_this2.options.lineThrough) {
3732
3740
  addError(currentStylePath, "Style 'lineThrough' is not valid", false);
3733
3741
  }
3734
3742
  }
@@ -3954,12 +3962,14 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
3954
3962
  }, {
3955
3963
  key: "readonly",
3956
3964
  value: function readonly() {
3957
- return new RichTextSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
3965
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
3966
+ return new RichTextSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
3958
3967
  }
3959
3968
  }, {
3960
3969
  key: "hidden",
3961
3970
  value: function hidden() {
3962
- return new RichTextSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
3971
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
3972
+ return new RichTextSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
3963
3973
  }
3964
3974
  }, {
3965
3975
  key: "executeCustomValidateAt",
@@ -4014,27 +4024,30 @@ var RichTextSchema = /*#__PURE__*/function (_Schema) {
4014
4024
  _this$renderInput,
4015
4025
  _this$customValidateF;
4016
4026
  var serializeAnchorSchema = function serializeAnchorSchema() {
4017
- var _this3$options$inline, _this3$options$inline3;
4018
- if (((_this3$options$inline = _this3.options.inline) === null || _this3$options$inline === void 0 ? void 0 : _this3$options$inline.a) instanceof RouteSchema) {
4019
- var _this3$options$inline2;
4020
- return (_this3$options$inline2 = _this3.options.inline) === null || _this3$options$inline2 === void 0 ? void 0 : _this3$options$inline2.a["executeSerialize"]();
4021
- } else if (((_this3$options$inline3 = _this3.options.inline) === null || _this3$options$inline3 === void 0 ? void 0 : _this3$options$inline3.a) instanceof StringSchema) {
4022
- var _this3$options$inline4;
4023
- return (_this3$options$inline4 = _this3.options.inline) === null || _this3$options$inline4 === void 0 ? void 0 : _this3$options$inline4.a["executeSerialize"]();
4027
+ if (_this3.options.a instanceof RouteSchema) {
4028
+ return _this3.options.a["executeSerialize"]();
4029
+ } else if (_this3.options.a instanceof StringSchema) {
4030
+ return _this3.options.a["executeSerialize"]();
4024
4031
  } else {
4025
- var _this3$options$inline5;
4026
- return (_this3$options$inline5 = _this3.options.inline) === null || _this3$options$inline5 === void 0 ? void 0 : _this3$options$inline5.a;
4032
+ return _this3.options.a;
4027
4033
  }
4028
4034
  };
4029
4035
  var serializedOptions = {
4030
4036
  maxLength: this.options.maxLength,
4031
4037
  minLength: this.options.minLength,
4032
- style: this.options.style,
4033
- block: this.options.block,
4034
- inline: this.options.inline && {
4035
- a: serializeAnchorSchema(),
4036
- img: this.options.inline.img && _typeof(this.options.inline.img) === "object" ? this.options.inline.img["executeSerialize"]() : this.options.inline.img
4037
- }
4038
+ bold: this.options.bold,
4039
+ italic: this.options.italic,
4040
+ lineThrough: this.options.lineThrough,
4041
+ h1: this.options.h1,
4042
+ h2: this.options.h2,
4043
+ h3: this.options.h3,
4044
+ h4: this.options.h4,
4045
+ h5: this.options.h5,
4046
+ h6: this.options.h6,
4047
+ ul: this.options.ul,
4048
+ ol: this.options.ol,
4049
+ a: serializeAnchorSchema(),
4050
+ img: this.options.img && _typeof(this.options.img) === "object" ? this.options.img["executeSerialize"]() : this.options.img
4038
4051
  };
4039
4052
  return {
4040
4053
  type: "richtext",
@@ -4758,12 +4771,14 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
4758
4771
  }, {
4759
4772
  key: "readonly",
4760
4773
  value: function readonly() {
4761
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, true, this.isHidden, this.description, this.isJsonValues, this.previewInput, this.renderInput);
4774
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
4775
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, isReadonly, this.isHidden, this.description, this.isJsonValues, this.previewInput, this.renderInput);
4762
4776
  }
4763
4777
  }, {
4764
4778
  key: "hidden",
4765
4779
  value: function hidden() {
4766
- return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, true, this.description, this.isJsonValues, this.previewInput, this.renderInput);
4780
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
4781
+ return new RecordSchema(this.item, this.opt, this.customValidateFunctions, this.currentRouter, this.keySchema, this.mediaOptions, this.isReadonly, isHidden, this.description, this.isJsonValues, this.previewInput, this.renderInput);
4767
4782
  }
4768
4783
  }, {
4769
4784
  key: "router",
@@ -5037,19 +5052,500 @@ var RecordSchema = /*#__PURE__*/function (_Schema) {
5037
5052
  }]);
5038
5053
  }(Schema);
5039
5054
 
5040
- // Overload: with key schema
5041
-
5042
- // Overload: without key schema
5043
-
5044
- // Implementation
5045
- function record(keyOrSchema, schema) {
5046
- if (schema) {
5047
- // Two-argument call: first is key schema, second is value schema
5048
- return new RecordSchema(schema, false, [], null, keyOrSchema);
5049
- } else {
5050
- // One-argument call: only value schema
5051
- return new RecordSchema(keyOrSchema, false, [], null, null);
5052
- }
5055
+ // Overload: with key schema
5056
+
5057
+ // Overload: without key schema
5058
+
5059
+ // Implementation
5060
+ function record(keyOrSchema, schema) {
5061
+ if (schema) {
5062
+ // Two-argument call: first is key schema, second is value schema
5063
+ return new RecordSchema(schema, false, [], null, keyOrSchema);
5064
+ } else {
5065
+ // One-argument call: only value schema
5066
+ return new RecordSchema(keyOrSchema, false, [], null, null);
5067
+ }
5068
+ }
5069
+
5070
+ /**
5071
+ * The source of the project's settings module — `s.settings()`.
5072
+ *
5073
+ * **Every key is optional, at every level, and that is the whole point.** A
5074
+ * settings module is written as
5075
+ *
5076
+ * ```typescript
5077
+ * export default c.define("/settings.val.ts", s.settings(), {});
5078
+ * ```
5079
+ *
5080
+ * and `{}` has to keep validating as sections are added to it. A project that
5081
+ * never touched the assistant's settings should not have to edit its settings
5082
+ * file the day `locales` or `permissions` land.
5083
+ *
5084
+ * That is why settings is not sugar over `s.object()`: an object schema errors
5085
+ * with `Expected key 'assistant' not found in object` for any absent key (see
5086
+ * `ObjectSchema.executeAssert`), and `.nullable()` permits `null`, not absence.
5087
+ * `SettingsSchema` gives absent keys the meaning "unset" instead.
5088
+ *
5089
+ * `null` means unset too, so the editor can clear a field it has already
5090
+ * written without removing the key.
5091
+ */
5092
+
5093
+ /**
5094
+ * The assistant: whether editors have one, and what it is told about the
5095
+ * project on every message.
5096
+ *
5097
+ * `context` and `tone` are prose the model reads, not instructions Val
5098
+ * interprets, and both are capped (see {@link ASSISTANT_SETTINGS_MAX_LENGTH}):
5099
+ * they are prepended to every request the chat makes, so an unbounded field
5100
+ * here is an unbounded cost on every turn.
5101
+ */
5102
+
5103
+ /**
5104
+ * The cap on each of the assistant's prose fields, in characters.
5105
+ *
5106
+ * Roughly a thousand tokens each. Generous enough for a paragraph of
5107
+ * background and a house style, small enough that the two of them together do
5108
+ * not dominate the system prompt they are appended to.
5109
+ */
5110
+ var ASSISTANT_SETTINGS_MAX_LENGTH = 4000;
5111
+
5112
+ /**
5113
+ * Whether a project has an assistant — and the answer is not a boolean.
5114
+ *
5115
+ * - `"on"`: use it.
5116
+ * - `"off"`: every trace of it goes. No button in the top bar, no row in the
5117
+ * quick actions, no panel, nothing sent. A project that says `false` has
5118
+ * decided, and the Studio does not keep offering.
5119
+ * - `"unconfigured"`: nobody has said. The affordances are SHOWN, and asking to
5120
+ * use the assistant asks to turn it on first. That is the difference between
5121
+ * this and `"off"`, and the reason `enabled` is a tri-state: hiding an
5122
+ * unconfigured assistant means nobody discovers it, and quietly enabling one
5123
+ * means a project starts sending its content to a model because it did not
5124
+ * know to say no.
5125
+ *
5126
+ * A project with NO settings module is `"on"`. There is nowhere to record a
5127
+ * decision, so there is nothing to prompt for and nothing to prompt INTO — the
5128
+ * prompt writes to a settings module, and that project has none.
5129
+ *
5130
+ * This is the only answer to "does this project have an assistant":
5131
+ * `config.ai.chat` is gone, and with it the chat's title, description and
5132
+ * suggestions, which nothing replaces. The AI commit-message summariser is
5133
+ * deliberately not part of this — `config.ai.commitMessages` stays where it is,
5134
+ * and gets settings of its own later.
5135
+ */
5136
+
5137
+ function assistantAvailability(/** The settings module's source, or `undefined` where the project has none. */
5138
+ settings) {
5139
+ var _settings$assistant;
5140
+ if (settings === undefined) {
5141
+ return "on";
5142
+ }
5143
+ var enabled = (_settings$assistant = settings.assistant) === null || _settings$assistant === void 0 ? void 0 : _settings$assistant.enabled;
5144
+ if (enabled === true) {
5145
+ return "on";
5146
+ }
5147
+ if (enabled === false) {
5148
+ return "off";
5149
+ }
5150
+ return "unconfigured";
5151
+ }
5152
+
5153
+ var BooleanSchema = /*#__PURE__*/function (_Schema) {
5154
+ function BooleanSchema() {
5155
+ var _this;
5156
+ var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
5157
+ var customValidateFunctions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
5158
+ var isReadonly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5159
+ var isHidden = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
5160
+ var description = arguments.length > 4 ? arguments[4] : undefined;
5161
+ var renderInput = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
5162
+ var previewInput = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
5163
+ _classCallCheck(this, BooleanSchema);
5164
+ _this = _callSuper(this, BooleanSchema);
5165
+ _this.opt = opt;
5166
+ _this.customValidateFunctions = customValidateFunctions;
5167
+ _this.isReadonly = isReadonly;
5168
+ _this.isHidden = isHidden;
5169
+ _this.description = description;
5170
+ _this.renderInput = renderInput;
5171
+ _this.previewInput = previewInput;
5172
+ return _this;
5173
+ }
5174
+ _inherits(BooleanSchema, _Schema);
5175
+ return _createClass(BooleanSchema, [{
5176
+ key: "describe",
5177
+ value: function describe(description) {
5178
+ return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.renderInput, this.previewInput);
5179
+ }
5180
+ }, {
5181
+ key: "validate",
5182
+ value: function validate(validationFunction) {
5183
+ return new BooleanSchema(this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
5184
+ }
5185
+ }, {
5186
+ key: "executeValidate",
5187
+ value: function executeValidate(path, src) {
5188
+ if (this.opt && (src === null || src === undefined)) {
5189
+ return false;
5190
+ }
5191
+ if (typeof src !== "boolean") {
5192
+ return _defineProperty({}, path, [{
5193
+ message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
5194
+ value: src
5195
+ }]);
5196
+ }
5197
+ return false;
5198
+ }
5199
+ }, {
5200
+ key: "executeAssert",
5201
+ value: function executeAssert(path, src) {
5202
+ if (this.opt && src === null) {
5203
+ return {
5204
+ success: true,
5205
+ data: src
5206
+ };
5207
+ }
5208
+ if (src === null) {
5209
+ return {
5210
+ success: false,
5211
+ errors: _defineProperty({}, path, [{
5212
+ message: "Expected 'boolean', got 'null'",
5213
+ typeError: true
5214
+ }])
5215
+ };
5216
+ }
5217
+ if (typeof src !== "boolean") {
5218
+ return {
5219
+ success: false,
5220
+ errors: _defineProperty({}, path, [{
5221
+ message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
5222
+ typeError: true
5223
+ }])
5224
+ };
5225
+ }
5226
+ return {
5227
+ success: true,
5228
+ data: src
5229
+ };
5230
+ }
5231
+ }, {
5232
+ key: "nullable",
5233
+ value: function nullable() {
5234
+ return new BooleanSchema(true, [], this.isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
5235
+ }
5236
+ }, {
5237
+ key: "readonly",
5238
+ value: function readonly() {
5239
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5240
+ return new BooleanSchema(this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
5241
+ }
5242
+ }, {
5243
+ key: "hidden",
5244
+ value: function hidden() {
5245
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
5246
+ return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
5247
+ }
5248
+ }, {
5249
+ key: "executeCustomValidateAt",
5250
+ value: function executeCustomValidateAt(path, src) {
5251
+ return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5252
+ path: path
5253
+ });
5254
+ }
5255
+
5256
+ /**
5257
+ * How this field is laid out in the editor when it is the item of an array
5258
+ * or record: `{ as: "inline" }` renders the field itself inside each row,
5259
+ * instead of a preview row that navigates to it.
5260
+ *
5261
+ * Static configuration, not a callback — see `render.ts`.
5262
+ */
5263
+ }, {
5264
+ key: "render",
5265
+ value: function render(input) {
5266
+ return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, input, this.previewInput);
5267
+ }
5268
+
5269
+ /**
5270
+ * How this VALUE is shown where a preview of it is needed — a row in a
5271
+ * sortable list, a reference dropdown, a search hit. Never how the field
5272
+ * itself is edited (that is `render`). See `preview.ts`.
5273
+ */
5274
+ }, {
5275
+ key: "preview",
5276
+ value: function preview(select) {
5277
+ return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.renderInput, select);
5278
+ }
5279
+ }, {
5280
+ key: "executePreviewItem",
5281
+ value: function executePreviewItem(src) {
5282
+ if (this.previewInput === null) {
5283
+ return null;
5284
+ }
5285
+ return this.previewInput({
5286
+ val: src
5287
+ });
5288
+ }
5289
+ }, {
5290
+ key: "declaresItemPreview",
5291
+ value: function declaresItemPreview() {
5292
+ return this.previewInput !== null;
5293
+ }
5294
+ }, {
5295
+ key: "executeSerialize",
5296
+ value: function executeSerialize() {
5297
+ var _this$renderInput, _this$customValidateF;
5298
+ return {
5299
+ type: "boolean",
5300
+ render: (_this$renderInput = this.renderInput) !== null && _this$renderInput !== void 0 ? _this$renderInput : undefined,
5301
+ preview: this.previewInput ? true : undefined,
5302
+ opt: this.opt,
5303
+ customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
5304
+ readonly: this.isReadonly,
5305
+ hidden: this.isHidden,
5306
+ description: this.description
5307
+ };
5308
+ }
5309
+ }, {
5310
+ key: "executePreview",
5311
+ value: function executePreview() {
5312
+ return {};
5313
+ }
5314
+ }]);
5315
+ }(Schema);
5316
+ var _boolean = function _boolean() {
5317
+ return new BooleanSchema();
5318
+ };
5319
+
5320
+ /**
5321
+ * An object whose keys are all optional: absent means unset.
5322
+ *
5323
+ * Both the settings module itself and each of its sections are this. See
5324
+ * {@link SettingsSource} for why settings cannot be an object schema, and
5325
+ * {@link settings} for what a settings module holds.
5326
+ *
5327
+ * There is no `describe`, `validate`, `render` or `preview` on purpose: the
5328
+ * shape is Val's, not the schema author's — `s.settings()` takes no arguments —
5329
+ * and the Studio renders each section with a UI built for it.
5330
+ */
5331
+ var SettingsSchema = /*#__PURE__*/function (_Schema) {
5332
+ function SettingsSchema(items) {
5333
+ var _this;
5334
+ var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
5335
+ var isReadonly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5336
+ var isHidden = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
5337
+ var description = arguments.length > 4 ? arguments[4] : undefined;
5338
+ _classCallCheck(this, SettingsSchema);
5339
+ _this = _callSuper(this, SettingsSchema);
5340
+ _this.items = items;
5341
+ _this.opt = opt;
5342
+ _this.isReadonly = isReadonly;
5343
+ _this.isHidden = isHidden;
5344
+ _this.description = description;
5345
+ return _this;
5346
+ }
5347
+ _inherits(SettingsSchema, _Schema);
5348
+ return _createClass(SettingsSchema, [{
5349
+ key: "executeValidate",
5350
+ value: function executeValidate(path, src) {
5351
+ var error = false;
5352
+ if (src === null || src === undefined) {
5353
+ if (this.opt) {
5354
+ return false;
5355
+ }
5356
+ return _defineProperty({}, path, [{
5357
+ message: "Expected 'object', got '".concat(src, "'")
5358
+ }]);
5359
+ }
5360
+ if (_typeof(src) !== "object") {
5361
+ return _defineProperty({}, path, [{
5362
+ message: "Expected 'object', got '".concat(_typeof(src), "'")
5363
+ }]);
5364
+ }
5365
+ if (Array.isArray(src)) {
5366
+ return _defineProperty({}, path, [{
5367
+ message: "Expected 'object', got 'array'"
5368
+ }]);
5369
+ }
5370
+ for (var _i = 0, _Object$entries = Object.entries(this.items); _i < _Object$entries.length; _i++) {
5371
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
5372
+ _key = _Object$entries$_i[0],
5373
+ schema = _Object$entries$_i[1];
5374
+ // Absent is the unset value, so there is nothing to validate. A key that
5375
+ // is present as `undefined` is the same statement written differently.
5376
+ if (src[_key] === undefined) {
5377
+ continue;
5378
+ }
5379
+ var subPath = createValPathOfItem(path, _key);
5380
+ if (!subPath) {
5381
+ error = this.appendValidationError(error, path, "Internal error: could not create path at ".concat(!path && typeof path === "string" ? "<empty string>" : path, " at key ").concat(_key),
5382
+ // Should! never happen
5383
+ src);
5384
+ } else {
5385
+ var subError = schema["executeValidate"](subPath, src[_key]);
5386
+ error = this.mergeValidationErrors(error, subError);
5387
+ }
5388
+ }
5389
+ // An unknown key is reported rather than ignored (which is what an object
5390
+ // schema does with extra keys): the shape is closed and Val-defined, so the
5391
+ // realistic cause is a typo — `toneOfVoice` for `tone` — and silence there
5392
+ // means a setting that never takes effect and never says why.
5393
+ for (var _i2 = 0, _Object$keys = Object.keys(src); _i2 < _Object$keys.length; _i2++) {
5394
+ var _key2 = _Object$keys[_i2];
5395
+ if (!(_key2 in this.items)) {
5396
+ error = this.appendValidationError(error, path, "Unknown settings key: '".concat(_key2, "'. Expected one of: ").concat(Object.keys(this.items).map(function (key) {
5397
+ return "'".concat(key, "'");
5398
+ }).join(", ")), src, true);
5399
+ }
5400
+ }
5401
+ return error;
5402
+ }
5403
+ }, {
5404
+ key: "executeAssert",
5405
+ value: function executeAssert(path, src) {
5406
+ if (this.opt && src === null) {
5407
+ return {
5408
+ success: true,
5409
+ data: src
5410
+ };
5411
+ }
5412
+ var typeError = function typeError(got) {
5413
+ return {
5414
+ message: "Expected 'object', got '".concat(got, "'"),
5415
+ typeError: true
5416
+ };
5417
+ };
5418
+ if (src === null) {
5419
+ return {
5420
+ success: false,
5421
+ errors: _defineProperty({}, path, [typeError("null")])
5422
+ };
5423
+ }
5424
+ if (_typeof(src) !== "object") {
5425
+ return {
5426
+ success: false,
5427
+ errors: _defineProperty({}, path, [typeError(_typeof(src))])
5428
+ };
5429
+ }
5430
+ if (Array.isArray(src)) {
5431
+ return {
5432
+ success: false,
5433
+ errors: _defineProperty({}, path, [typeError("array")])
5434
+ };
5435
+ }
5436
+ // No per-key check, unlike an object schema: every key is optional, so an
5437
+ // object is all this can assert.
5438
+ return {
5439
+ success: true,
5440
+ data: src
5441
+ };
5442
+ }
5443
+ }, {
5444
+ key: "nullable",
5445
+ value: function nullable() {
5446
+ return new SettingsSchema(this.items, true, this.isReadonly, this.isHidden, this.description);
5447
+ }
5448
+ }, {
5449
+ key: "readonly",
5450
+ value: function readonly() {
5451
+ return new SettingsSchema(this.items, this.opt, true, this.isHidden, this.description);
5452
+ }
5453
+ }, {
5454
+ key: "hidden",
5455
+ value: function hidden() {
5456
+ return new SettingsSchema(this.items, this.opt, this.isReadonly, true, this.description);
5457
+ }
5458
+ }, {
5459
+ key: "executeCustomValidateAt",
5460
+ value: function executeCustomValidateAt() {
5461
+ // Settings declares no `validate`, so there are no custom validators to
5462
+ // run. Implemented rather than inherited because the base class makes this
5463
+ // abstract on purpose — see `Schema.executeCustomValidateAt`.
5464
+ return [];
5465
+ }
5466
+ }, {
5467
+ key: "executeSerialize",
5468
+ value: function executeSerialize() {
5469
+ return {
5470
+ type: "settings",
5471
+ items: Object.fromEntries(Object.entries(this.items).map(function (_ref4) {
5472
+ var _ref5 = _slicedToArray(_ref4, 2),
5473
+ key = _ref5[0],
5474
+ schema = _ref5[1];
5475
+ return [key, schema["executeSerialize"]()];
5476
+ })),
5477
+ opt: this.opt,
5478
+ readonly: this.isReadonly,
5479
+ hidden: this.isHidden,
5480
+ description: this.description
5481
+ };
5482
+ }
5483
+ }, {
5484
+ key: "executePreview",
5485
+ value: function executePreview(sourcePath, src, scope) {
5486
+ var res = {};
5487
+ if (src === null) {
5488
+ return res;
5489
+ }
5490
+ for (var _key3 in this.items) {
5491
+ var itemSrc = src[_key3];
5492
+ if (itemSrc === null || itemSrc === undefined) {
5493
+ continue;
5494
+ }
5495
+ var subPath = unsafeCreateSourcePath(sourcePath, _key3);
5496
+ if (scope !== undefined && !scope.wantsUnder(subPath)) {
5497
+ continue;
5498
+ }
5499
+ var itemResult = this.items[_key3]["executePreview"](subPath, itemSrc, scope);
5500
+ for (var keyS in itemResult) {
5501
+ var _key4 = keyS;
5502
+ res[_key4] = itemResult[_key4];
5503
+ }
5504
+ }
5505
+ return res;
5506
+ }
5507
+ }]);
5508
+ }(Schema);
5509
+
5510
+ /**
5511
+ * Define the project's settings.
5512
+ *
5513
+ * One settings module per project, at the root of the content tree — a module
5514
+ * file path with no directory segment, `/settings.val.ts` by convention:
5515
+ *
5516
+ * ```typescript
5517
+ * export default c.define("/settings.val.ts", s.settings(), {});
5518
+ * ```
5519
+ *
5520
+ * Every section is optional, so `{}` is a complete settings module and stays
5521
+ * one as sections are added. Fill in what the project needs:
5522
+ *
5523
+ * ```typescript
5524
+ * export default c.define("/settings.val.ts", s.settings(), {
5525
+ * assistant: {
5526
+ * enabled: true,
5527
+ * context: "Val is a CMS for developers. British English, and 'Val' is never 'VAL'.",
5528
+ * tone: "Plain and direct. No exclamation marks, sentence case in headings.",
5529
+ * },
5530
+ * });
5531
+ * ```
5532
+ *
5533
+ * The Studio edits it under the cog at the foot of the left rail, and the
5534
+ * assistant is told `assistant.context` and `assistant.tone` on every message.
5535
+ *
5536
+ * `s.settings()` takes no arguments: the shape is Val's, which is what lets the
5537
+ * Studio render a UI built for each field rather than a generic form. A
5538
+ * project's own global content — a site name, social links — belongs in a
5539
+ * module of its own.
5540
+ */
5541
+ function settings() {
5542
+ return new SettingsSchema({
5543
+ assistant: new SettingsSchema({
5544
+ enabled: _boolean().nullable().describe("Whether editors have an assistant in this project. Unset means nobody has decided: it is offered, and turned on when someone accepts."),
5545
+ context: string().multiline().maxLength(ASSISTANT_SETTINGS_MAX_LENGTH).nullable().describe("Background the assistant would otherwise have to guess: what this site is, who runs it, names and spellings that matter."),
5546
+ tone: string().multiline().maxLength(ASSISTANT_SETTINGS_MAX_LENGTH).nullable().describe("How the assistant should write when it writes content: formal or playful, British or American, how headings are cased.")
5547
+ })
5548
+ });
5053
5549
  }
5054
5550
 
5055
5551
  function define(id,
@@ -5089,6 +5585,17 @@ function joinModuleFilePathAndModulePath(moduleFilePath, modulePath) {
5089
5585
  function isObjectSchema(schema) {
5090
5586
  return schema instanceof ObjectSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "object";
5091
5587
  }
5588
+
5589
+ /**
5590
+ * Settings, which walks like an object but whose keys are all OPTIONAL.
5591
+ *
5592
+ * That difference is the whole reason it is not an object schema: descending
5593
+ * into an unset section must resolve to `undefined`, not fail — see
5594
+ * `SettingsSource`.
5595
+ */
5596
+ function isSettingsSchema(schema) {
5597
+ return schema instanceof SettingsSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "settings";
5598
+ }
5092
5599
  function isRecordSchema(schema) {
5093
5600
  return schema instanceof RecordSchema || _typeof(schema) === "object" && "type" in schema && schema.type === "record";
5094
5601
  }
@@ -5167,6 +5674,16 @@ function resolvePath(path, valModule, schema) {
5167
5674
  if (isJson(resolvedSource) && parts.length > 0) {
5168
5675
  throw Error("Cannot resolve path into a jsonValues entry until its content is loaded. Path: ".concat(path));
5169
5676
  }
5677
+ } else if (isSettingsSchema(resolvedSchema)) {
5678
+ if (resolvedSource !== null && resolvedSource !== undefined && _typeof(resolvedSource) !== "object") {
5679
+ throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
5680
+ }
5681
+ // An absent key is NOT an error here, unlike an object's: every settings
5682
+ // key is optional, so a path into a section the project has not set
5683
+ // resolves to `undefined` — and keeps resolving, one level per part, so a
5684
+ // path two deep into an unset section still lands on the right schema.
5685
+ resolvedSource = resolvedSource === null || resolvedSource === undefined ? resolvedSource : resolvedSource[part];
5686
+ resolvedSchema = resolvedSchema instanceof SettingsSchema ? resolvedSchema["items"][part] : resolvedSchema.items[part];
5170
5687
  } else if (isObjectSchema(resolvedSchema)) {
5171
5688
  if (_typeof(resolvedSource) !== "object") {
5172
5689
  throw Error("Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource)));
@@ -5241,11 +5758,11 @@ function resolvePath(path, valModule, schema) {
5241
5758
  } else if (isRichTextSchema(resolvedSchema)) {
5242
5759
  if ("src" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "img" && parts.length === 0) {
5243
5760
  var _resolvedSchema$optio, _resolvedSchema$optio2;
5244
- resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio = resolvedSchema["options"]) !== null && _resolvedSchema$optio !== void 0 && (_resolvedSchema$optio = _resolvedSchema$optio.inline) !== null && _resolvedSchema$optio !== void 0 && _resolvedSchema$optio.img && typeof ((_resolvedSchema$optio2 = resolvedSchema["options"]) === null || _resolvedSchema$optio2 === void 0 || (_resolvedSchema$optio2 = _resolvedSchema$optio2.inline) === null || _resolvedSchema$optio2 === void 0 ? void 0 : _resolvedSchema$optio2.img) !== "boolean" ? resolvedSchema["options"].inline.img : resolvedSchema : resolvedSchema;
5761
+ resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio = resolvedSchema["options"]) !== null && _resolvedSchema$optio !== void 0 && _resolvedSchema$optio.img && typeof ((_resolvedSchema$optio2 = resolvedSchema["options"]) === null || _resolvedSchema$optio2 === void 0 ? void 0 : _resolvedSchema$optio2.img) !== "boolean" ? resolvedSchema["options"].img : resolvedSchema : resolvedSchema;
5245
5762
  }
5246
5763
  if ("href" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "a" && parts.length === 0) {
5247
5764
  var _resolvedSchema$optio3, _resolvedSchema$optio4;
5248
- resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio3 = resolvedSchema["options"]) !== null && _resolvedSchema$optio3 !== void 0 && (_resolvedSchema$optio3 = _resolvedSchema$optio3.inline) !== null && _resolvedSchema$optio3 !== void 0 && _resolvedSchema$optio3.a && typeof ((_resolvedSchema$optio4 = resolvedSchema["options"]) === null || _resolvedSchema$optio4 === void 0 || (_resolvedSchema$optio4 = _resolvedSchema$optio4.inline) === null || _resolvedSchema$optio4 === void 0 ? void 0 : _resolvedSchema$optio4.a) !== "boolean" ? resolvedSchema["options"].inline.a : resolvedSchema : resolvedSchema;
5765
+ resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio3 = resolvedSchema["options"]) !== null && _resolvedSchema$optio3 !== void 0 && _resolvedSchema$optio3.a && typeof ((_resolvedSchema$optio4 = resolvedSchema["options"]) === null || _resolvedSchema$optio4 === void 0 ? void 0 : _resolvedSchema$optio4.a) !== "boolean" ? resolvedSchema["options"].a : resolvedSchema : resolvedSchema;
5249
5766
  }
5250
5767
  resolvedSource = resolvedSource[part];
5251
5768
  } else {
@@ -5381,6 +5898,21 @@ function safeResolvePath(path, valModule, schema) {
5381
5898
  }
5382
5899
  };
5383
5900
  }
5901
+ } else if (isSettingsSchema(resolvedSchema)) {
5902
+ if (resolvedSource !== null && resolvedSource !== undefined && _typeof(resolvedSource) !== "object") {
5903
+ return {
5904
+ v: {
5905
+ status: "error",
5906
+ message: "Schema type error: expected source to be type of object, but got ".concat(_typeof(resolvedSource))
5907
+ }
5908
+ };
5909
+ }
5910
+ // Absent is a value here — see the note in `resolvePath`. `undefined` has
5911
+ // to be let through as well as `null`: descending into a section the
5912
+ // project has not set produces one, and the NEXT part then arrives with
5913
+ // an undefined source that is not an error either.
5914
+ resolvedSource = resolvedSource === null || resolvedSource === undefined ? resolvedSource : resolvedSource[part];
5915
+ resolvedSchema = resolvedSchema instanceof SettingsSchema ? resolvedSchema["items"][part] : resolvedSchema.items[part];
5384
5916
  } else if (isObjectSchema(resolvedSchema)) {
5385
5917
  if (resolvedSource === undefined) {
5386
5918
  return {
@@ -5487,11 +6019,11 @@ function safeResolvePath(path, valModule, schema) {
5487
6019
  } else if (isRichTextSchema(resolvedSchema)) {
5488
6020
  if ("src" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "img" && parts.length === 0) {
5489
6021
  var _resolvedSchema$optio5, _resolvedSchema$optio6;
5490
- resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio5 = resolvedSchema["options"]) !== null && _resolvedSchema$optio5 !== void 0 && (_resolvedSchema$optio5 = _resolvedSchema$optio5.inline) !== null && _resolvedSchema$optio5 !== void 0 && _resolvedSchema$optio5.img && typeof ((_resolvedSchema$optio6 = resolvedSchema["options"]) === null || _resolvedSchema$optio6 === void 0 || (_resolvedSchema$optio6 = _resolvedSchema$optio6.inline) === null || _resolvedSchema$optio6 === void 0 ? void 0 : _resolvedSchema$optio6.img) !== "boolean" ? resolvedSchema["options"].inline.img : resolvedSchema : resolvedSchema;
6022
+ resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio5 = resolvedSchema["options"]) !== null && _resolvedSchema$optio5 !== void 0 && _resolvedSchema$optio5.img && typeof ((_resolvedSchema$optio6 = resolvedSchema["options"]) === null || _resolvedSchema$optio6 === void 0 ? void 0 : _resolvedSchema$optio6.img) !== "boolean" ? resolvedSchema["options"].img : resolvedSchema : resolvedSchema;
5491
6023
  }
5492
6024
  if ("href" in resolvedSource && "tag" in resolvedSource && resolvedSource.tag === "a" && parts.length === 0) {
5493
6025
  var _resolvedSchema$optio7, _resolvedSchema$optio8;
5494
- resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio7 = resolvedSchema["options"]) !== null && _resolvedSchema$optio7 !== void 0 && (_resolvedSchema$optio7 = _resolvedSchema$optio7.inline) !== null && _resolvedSchema$optio7 !== void 0 && _resolvedSchema$optio7.a && typeof ((_resolvedSchema$optio8 = resolvedSchema["options"]) === null || _resolvedSchema$optio8 === void 0 || (_resolvedSchema$optio8 = _resolvedSchema$optio8.inline) === null || _resolvedSchema$optio8 === void 0 ? void 0 : _resolvedSchema$optio8.a) !== "boolean" ? resolvedSchema["options"].inline.a : resolvedSchema : resolvedSchema;
6026
+ resolvedSchema = resolvedSchema instanceof RichTextSchema ? (_resolvedSchema$optio7 = resolvedSchema["options"]) !== null && _resolvedSchema$optio7 !== void 0 && _resolvedSchema$optio7.a && typeof ((_resolvedSchema$optio8 = resolvedSchema["options"]) === null || _resolvedSchema$optio8 === void 0 ? void 0 : _resolvedSchema$optio8.a) !== "boolean" ? resolvedSchema["options"].a : resolvedSchema : resolvedSchema;
5495
6027
  }
5496
6028
  resolvedSource = resolvedSource[part];
5497
6029
  } else {
@@ -5699,12 +6231,14 @@ var NumberSchema = /*#__PURE__*/function (_Schema) {
5699
6231
  }, {
5700
6232
  key: "readonly",
5701
6233
  value: function readonly() {
5702
- return new NumberSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
6234
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6235
+ return new NumberSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
5703
6236
  }
5704
6237
  }, {
5705
6238
  key: "hidden",
5706
6239
  value: function hidden() {
5707
- return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
6240
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6241
+ return new NumberSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
5708
6242
  }
5709
6243
  }, {
5710
6244
  key: "max",
@@ -5793,171 +6327,6 @@ var number = function number(options) {
5793
6327
  return new NumberSchema(options);
5794
6328
  };
5795
6329
 
5796
- var BooleanSchema = /*#__PURE__*/function (_Schema) {
5797
- function BooleanSchema() {
5798
- var _this;
5799
- var opt = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
5800
- var customValidateFunctions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
5801
- var isReadonly = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
5802
- var isHidden = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
5803
- var description = arguments.length > 4 ? arguments[4] : undefined;
5804
- var renderInput = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : null;
5805
- var previewInput = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
5806
- _classCallCheck(this, BooleanSchema);
5807
- _this = _callSuper(this, BooleanSchema);
5808
- _this.opt = opt;
5809
- _this.customValidateFunctions = customValidateFunctions;
5810
- _this.isReadonly = isReadonly;
5811
- _this.isHidden = isHidden;
5812
- _this.description = description;
5813
- _this.renderInput = renderInput;
5814
- _this.previewInput = previewInput;
5815
- return _this;
5816
- }
5817
- _inherits(BooleanSchema, _Schema);
5818
- return _createClass(BooleanSchema, [{
5819
- key: "describe",
5820
- value: function describe(description) {
5821
- return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.renderInput, this.previewInput);
5822
- }
5823
- }, {
5824
- key: "validate",
5825
- value: function validate(validationFunction) {
5826
- return new BooleanSchema(this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
5827
- }
5828
- }, {
5829
- key: "executeValidate",
5830
- value: function executeValidate(path, src) {
5831
- if (this.opt && (src === null || src === undefined)) {
5832
- return false;
5833
- }
5834
- if (typeof src !== "boolean") {
5835
- return _defineProperty({}, path, [{
5836
- message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
5837
- value: src
5838
- }]);
5839
- }
5840
- return false;
5841
- }
5842
- }, {
5843
- key: "executeAssert",
5844
- value: function executeAssert(path, src) {
5845
- if (this.opt && src === null) {
5846
- return {
5847
- success: true,
5848
- data: src
5849
- };
5850
- }
5851
- if (src === null) {
5852
- return {
5853
- success: false,
5854
- errors: _defineProperty({}, path, [{
5855
- message: "Expected 'boolean', got 'null'",
5856
- typeError: true
5857
- }])
5858
- };
5859
- }
5860
- if (typeof src !== "boolean") {
5861
- return {
5862
- success: false,
5863
- errors: _defineProperty({}, path, [{
5864
- message: "Expected 'boolean', got '".concat(_typeof(src), "'"),
5865
- typeError: true
5866
- }])
5867
- };
5868
- }
5869
- return {
5870
- success: true,
5871
- data: src
5872
- };
5873
- }
5874
- }, {
5875
- key: "nullable",
5876
- value: function nullable() {
5877
- return new BooleanSchema(true, [], this.isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
5878
- }
5879
- }, {
5880
- key: "readonly",
5881
- value: function readonly() {
5882
- return new BooleanSchema(this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
5883
- }
5884
- }, {
5885
- key: "hidden",
5886
- value: function hidden() {
5887
- return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
5888
- }
5889
- }, {
5890
- key: "executeCustomValidateAt",
5891
- value: function executeCustomValidateAt(path, src) {
5892
- return this.executeCustomValidateFunctions(src, this.customValidateFunctions, {
5893
- path: path
5894
- });
5895
- }
5896
-
5897
- /**
5898
- * How this field is laid out in the editor when it is the item of an array
5899
- * or record: `{ as: "inline" }` renders the field itself inside each row,
5900
- * instead of a preview row that navigates to it.
5901
- *
5902
- * Static configuration, not a callback — see `render.ts`.
5903
- */
5904
- }, {
5905
- key: "render",
5906
- value: function render(input) {
5907
- return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, input, this.previewInput);
5908
- }
5909
-
5910
- /**
5911
- * How this VALUE is shown where a preview of it is needed — a row in a
5912
- * sortable list, a reference dropdown, a search hit. Never how the field
5913
- * itself is edited (that is `render`). See `preview.ts`.
5914
- */
5915
- }, {
5916
- key: "preview",
5917
- value: function preview(select) {
5918
- return new BooleanSchema(this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.renderInput, select);
5919
- }
5920
- }, {
5921
- key: "executePreviewItem",
5922
- value: function executePreviewItem(src) {
5923
- if (this.previewInput === null) {
5924
- return null;
5925
- }
5926
- return this.previewInput({
5927
- val: src
5928
- });
5929
- }
5930
- }, {
5931
- key: "declaresItemPreview",
5932
- value: function declaresItemPreview() {
5933
- return this.previewInput !== null;
5934
- }
5935
- }, {
5936
- key: "executeSerialize",
5937
- value: function executeSerialize() {
5938
- var _this$renderInput, _this$customValidateF;
5939
- return {
5940
- type: "boolean",
5941
- render: (_this$renderInput = this.renderInput) !== null && _this$renderInput !== void 0 ? _this$renderInput : undefined,
5942
- preview: this.previewInput ? true : undefined,
5943
- opt: this.opt,
5944
- customValidate: this.customValidateFunctions && ((_this$customValidateF = this.customValidateFunctions) === null || _this$customValidateF === void 0 ? void 0 : _this$customValidateF.length) > 0,
5945
- readonly: this.isReadonly,
5946
- hidden: this.isHidden,
5947
- description: this.description
5948
- };
5949
- }
5950
- }, {
5951
- key: "executePreview",
5952
- value: function executePreview() {
5953
- return {};
5954
- }
5955
- }]);
5956
- }(Schema);
5957
- var _boolean = function _boolean() {
5958
- return new BooleanSchema();
5959
- };
5960
-
5961
6330
  var KeyOfSchema = /*#__PURE__*/function (_Schema) {
5962
6331
  function KeyOfSchema(schema, sourcePath) {
5963
6332
  var _this;
@@ -6125,12 +6494,14 @@ var KeyOfSchema = /*#__PURE__*/function (_Schema) {
6125
6494
  }, {
6126
6495
  key: "readonly",
6127
6496
  value: function readonly() {
6128
- return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
6497
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6498
+ return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
6129
6499
  }
6130
6500
  }, {
6131
6501
  key: "hidden",
6132
6502
  value: function hidden() {
6133
- return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
6503
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6504
+ return new KeyOfSchema(this.schema, this.sourcePath, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
6134
6505
  }
6135
6506
  }, {
6136
6507
  key: "executeCustomValidateAt",
@@ -6467,12 +6838,14 @@ var FileSchema = /*#__PURE__*/function (_Schema) {
6467
6838
  }, {
6468
6839
  key: "readonly",
6469
6840
  value: function readonly() {
6470
- return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, true, this.isHidden, this.description, this.renderInput, this.previewInput);
6841
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6842
+ return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
6471
6843
  }
6472
6844
  }, {
6473
6845
  key: "hidden",
6474
6846
  value: function hidden() {
6475
- return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
6847
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6848
+ return new FileSchema(this.options, this.opt, this.isRemote, this.customValidateFunctions, this.moduleMetadata, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
6476
6849
  }
6477
6850
  }, {
6478
6851
  key: "executeCustomValidateAt",
@@ -6746,12 +7119,14 @@ var DateSchema = /*#__PURE__*/function (_Schema) {
6746
7119
  }, {
6747
7120
  key: "readonly",
6748
7121
  value: function readonly() {
6749
- return new DateSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
7122
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7123
+ return new DateSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
6750
7124
  }
6751
7125
  }, {
6752
7126
  key: "hidden",
6753
7127
  value: function hidden() {
6754
- return new DateSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
7128
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7129
+ return new DateSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
6755
7130
  }
6756
7131
  }, {
6757
7132
  key: "executeCustomValidateAt",
@@ -6995,12 +7370,14 @@ var DateTimeSchema = /*#__PURE__*/function (_Schema) {
6995
7370
  }, {
6996
7371
  key: "readonly",
6997
7372
  value: function readonly() {
6998
- return new DateTimeSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
7373
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7374
+ return new DateTimeSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
6999
7375
  }
7000
7376
  }, {
7001
7377
  key: "hidden",
7002
7378
  value: function hidden() {
7003
- return new DateTimeSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
7379
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7380
+ return new DateTimeSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
7004
7381
  }
7005
7382
  }, {
7006
7383
  key: "executeCustomValidateAt",
@@ -7180,12 +7557,14 @@ var CodeSchema = /*#__PURE__*/function (_Schema) {
7180
7557
  }, {
7181
7558
  key: "readonly",
7182
7559
  value: function readonly() {
7183
- return new CodeSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
7560
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7561
+ return new CodeSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
7184
7562
  }
7185
7563
  }, {
7186
7564
  key: "hidden",
7187
7565
  value: function hidden() {
7188
- return new CodeSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
7566
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
7567
+ return new CodeSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
7189
7568
  }
7190
7569
 
7191
7570
  /**
@@ -7866,12 +8245,14 @@ var ColorSchema = /*#__PURE__*/function (_Schema) {
7866
8245
  }, {
7867
8246
  key: "readonly",
7868
8247
  value: function readonly() {
7869
- return new ColorSchema(this.options, this.opt, this.customValidateFunctions, true, this.isHidden, this.description, this.renderInput, this.previewInput);
8248
+ var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
8249
+ return new ColorSchema(this.options, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.renderInput, this.previewInput);
7870
8250
  }
7871
8251
  }, {
7872
8252
  key: "hidden",
7873
8253
  value: function hidden() {
7874
- return new ColorSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, true, this.description, this.renderInput, this.previewInput);
8254
+ var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
8255
+ return new ColorSchema(this.options, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.renderInput, this.previewInput);
7875
8256
  }
7876
8257
 
7877
8258
  /**
@@ -8034,7 +8415,8 @@ function initSchema() {
8034
8415
  code: code,
8035
8416
  route: route,
8036
8417
  router: router,
8037
- images: images
8418
+ images: images,
8419
+ settings: settings
8038
8420
  // i18n: i18n(locales),
8039
8421
  };
8040
8422
  }
@@ -8435,6 +8817,98 @@ var getSHA256Hash = function getSHA256Hash(bits) {
8435
8817
  return createHash().update(bits).digest("hex");
8436
8818
  };
8437
8819
 
8820
+ /**
8821
+ * Where a settings module goes unless a project has a reason not to.
8822
+ *
8823
+ * A convention, not a rule: any module file path at the root of the content
8824
+ * tree may hold `s.settings()` — see {@link resolveSettingsModule}.
8825
+ */
8826
+ var SETTINGS_MODULE_CONVENTION = "/settings.val.ts";
8827
+
8828
+ /**
8829
+ * Whether a module file path is at the root of the content tree.
8830
+ *
8831
+ * `/settings.val.ts` is; `/content/settings.val.ts` is not. The settings module
8832
+ * is the project's, not a folder's, and a project-wide setting found three
8833
+ * directories down reads as one section's — so the position is part of what it
8834
+ * means.
8835
+ */
8836
+ function isRootModuleFilePath(moduleFilePath) {
8837
+ return moduleFilePath.startsWith("/") && !moduleFilePath.slice(1).includes("/");
8838
+ }
8839
+
8840
+ /**
8841
+ * Structurally an `ExtractedModuleError`, declared here rather than imported to
8842
+ * keep `extractValModules` -> `settingsModule` a one-way dependency.
8843
+ */
8844
+
8845
+ /**
8846
+ * Find the project's settings module among all its schemas.
8847
+ *
8848
+ * One per project, at the root: a settings module in a subdirectory is an
8849
+ * error, and so is a second one. Both are reported rather than resolved by
8850
+ * picking a winner — a project with two settings modules has a question to
8851
+ * answer, and answering it by sort order means the answer changes when a file
8852
+ * is renamed.
8853
+ */
8854
+ function resolveSettingsModule(schemas) {
8855
+ var rootModules = [];
8856
+ var nestedModules = [];
8857
+ var _iterator = result._createForOfIteratorHelper(Object.keys(schemas).sort()),
8858
+ _step;
8859
+ try {
8860
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
8861
+ var _schemas$_moduleFileP;
8862
+ var moduleFilePathS = _step.value;
8863
+ var _moduleFilePath2 = moduleFilePathS;
8864
+ if (((_schemas$_moduleFileP = schemas[_moduleFilePath2]) === null || _schemas$_moduleFileP === void 0 ? void 0 : _schemas$_moduleFileP.type) !== "settings") {
8865
+ continue;
8866
+ }
8867
+ if (isRootModuleFilePath(_moduleFilePath2)) {
8868
+ rootModules.push(_moduleFilePath2);
8869
+ } else {
8870
+ nestedModules.push(_moduleFilePath2);
8871
+ }
8872
+ }
8873
+ } catch (err) {
8874
+ _iterator.e(err);
8875
+ } finally {
8876
+ _iterator.f();
8877
+ }
8878
+ var errors = [];
8879
+ for (var _i = 0, _nestedModules = nestedModules; _i < _nestedModules.length; _i++) {
8880
+ var moduleFilePath = _nestedModules[_i];
8881
+ errors.push({
8882
+ path: moduleFilePath,
8883
+ message: "Settings must be defined at the root of the content tree, but s.settings() was found in '".concat(moduleFilePath, "'. Move it to a module file path with no directory in it, e.g. '").concat(SETTINGS_MODULE_CONVENTION, "'.")
8884
+ });
8885
+ }
8886
+ if (rootModules.length > 1) {
8887
+ var listed = rootModules.map(function (moduleFilePath) {
8888
+ return "'".concat(moduleFilePath, "'");
8889
+ }).join(" and ");
8890
+ var _iterator2 = result._createForOfIteratorHelper(rootModules),
8891
+ _step2;
8892
+ try {
8893
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
8894
+ var _moduleFilePath = _step2.value;
8895
+ errors.push({
8896
+ path: _moduleFilePath,
8897
+ message: "A project can only define settings once, but s.settings() was found in ".concat(listed, ". Keep one of them.")
8898
+ });
8899
+ }
8900
+ } catch (err) {
8901
+ _iterator2.e(err);
8902
+ } finally {
8903
+ _iterator2.f();
8904
+ }
8905
+ }
8906
+ return {
8907
+ moduleFilePath: errors.length === 0 && rootModules.length === 1 ? rootModules[0] : null,
8908
+ errors: errors
8909
+ };
8910
+ }
8911
+
8438
8912
  // Lazily constructed: this module is also evaluated inside the `vm` sandbox
8439
8913
  // used by loadValModules (when user val modules import @valbuild/core), and
8440
8914
  // that sandbox has no `TextEncoder` global. `hash()` is never called from
@@ -8602,7 +9076,7 @@ function extractValModules(_x) {
8602
9076
  }
8603
9077
  function _extractValModules() {
8604
9078
  _extractValModules = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(valModules) {
8605
- var moduleErrors, addModuleError, sources, schemas, serializedSchemas, shaEntries, moduleIdx, module, at, value, path, schema, source, serializedSchema, pathM, _t, _t2;
9079
+ var moduleErrors, addModuleError, sources, schemas, serializedSchemas, shaEntries, moduleIdx, module, at, value, path, schema, source, serializedSchema, pathM, _iterator2, _step2, error, _t, _t2;
8606
9080
  return _regenerator().w(function (_context) {
8607
9081
  while (1) switch (_context.p = _context.n) {
8608
9082
  case 0:
@@ -8741,6 +9215,25 @@ function _extractValModules() {
8741
9215
  _context.n = 1;
8742
9216
  break;
8743
9217
  case 18:
9218
+ // Settings is the one rule that cannot be checked while looking at a single
9219
+ // module: "one per project, at the root" is a statement about the whole set.
9220
+ // Reported here so that every consumer of extraction gets it — the dev
9221
+ // server, `val validate` and the Studio all read `moduleErrors`.
9222
+ //
9223
+ // Appended AFTER the loop on purpose: each entry's `moduleErrorsAt` is the
9224
+ // error count at the time it was folded in, so the SHAs stay a function of
9225
+ // the modules themselves.
9226
+ _iterator2 = result._createForOfIteratorHelper(resolveSettingsModule(serializedSchemas).errors);
9227
+ try {
9228
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
9229
+ error = _step2.value;
9230
+ moduleErrors.push(error);
9231
+ }
9232
+ } catch (err) {
9233
+ _iterator2.e(err);
9234
+ } finally {
9235
+ _iterator2.f();
9236
+ }
8744
9237
  return _context.a(2, _objectSpread2(_objectSpread2({
8745
9238
  sources: sources,
8746
9239
  schemas: schemas,
@@ -8792,8 +9285,8 @@ function hasRemoteFileSchema(schema) {
8792
9285
  return !!schema.remote;
8793
9286
  } else if (schema.type === "richtext") {
8794
9287
  var _schema$options;
8795
- if (_typeof((_schema$options = schema.options) === null || _schema$options === void 0 || (_schema$options = _schema$options.inline) === null || _schema$options === void 0 ? void 0 : _schema$options.img) === "object") {
8796
- return hasRemoteFileSchema(schema.options.inline.img);
9288
+ if (_typeof((_schema$options = schema.options) === null || _schema$options === void 0 ? void 0 : _schema$options.img) === "object") {
9289
+ return hasRemoteFileSchema(schema.options.img);
8797
9290
  }
8798
9291
  return false;
8799
9292
  } else if (schema.type === "array") {
@@ -8812,7 +9305,10 @@ function hasRemoteFileSchema(schema) {
8812
9305
  return true;
8813
9306
  }
8814
9307
  return hasRemoteFileSchema(schema.item);
8815
- } else if (schema.type === "object") {
9308
+ } else if (schema.type === "object" || schema.type === "settings") {
9309
+ // Settings holds its sections the way an object holds its keys, so looking
9310
+ // inside is the same walk. Nothing in settings takes a file today, but the
9311
+ // answer should stay right when something does.
8816
9312
  for (var key in schema.items) {
8817
9313
  var hasRemoteFile = hasRemoteFileSchema(schema.items[key]);
8818
9314
  if (hasRemoteFile) {
@@ -9080,6 +9576,13 @@ function deserializeSchemaImpl(serialized) {
9080
9576
  item = _ref2[1];
9081
9577
  return [key, deserializeSchema(item)];
9082
9578
  })), serialized.opt, [], false, false, serialized.description, (_serialized$render5 = serialized.render) !== null && _serialized$render5 !== void 0 ? _serialized$render5 : null);
9579
+ case "settings":
9580
+ return new SettingsSchema(Object.fromEntries(Object.entries(serialized.items).map(function (_ref3) {
9581
+ var _ref4 = _slicedToArray(_ref3, 2),
9582
+ key = _ref4[0],
9583
+ item = _ref4[1];
9584
+ return [key, deserializeSchema(item)];
9585
+ })), serialized.opt, false, false, serialized.description);
9083
9586
  case "array":
9084
9587
  return new ArraySchema(deserializeSchema(serialized.item), serialized.opt, [], false, false, serialized.description,
9085
9588
  // The preview closure cannot survive serialization; the render can.
@@ -9095,12 +9598,10 @@ function deserializeSchemaImpl(serialized) {
9095
9598
  serialized.opt, [], false, false, serialized.description, (_serialized$render7 = serialized.render) !== null && _serialized$render7 !== void 0 ? _serialized$render7 : null);
9096
9599
  case "richtext":
9097
9600
  {
9098
- var _serialized$options3, _serialized$options4, _serialized$options5, _serialized$options6, _serialized$options7, _serialized$options8, _serialized$options9, _serialized$render8;
9601
+ var _serialized$options3, _serialized$options4, _serialized$options5, _serialized$options6, _serialized$render8;
9099
9602
  var deserializedOptions = _objectSpread2(_objectSpread2({}, serialized.options || {}), {}, {
9100
- inline: _typeof((_serialized$options3 = serialized.options) === null || _serialized$options3 === void 0 || (_serialized$options3 = _serialized$options3.inline) === null || _serialized$options3 === void 0 ? void 0 : _serialized$options3.img) === "object" || _typeof((_serialized$options4 = serialized.options) === null || _serialized$options4 === void 0 || (_serialized$options4 = _serialized$options4.inline) === null || _serialized$options4 === void 0 ? void 0 : _serialized$options4.a) === "object" ? {
9101
- a: _typeof((_serialized$options5 = serialized.options) === null || _serialized$options5 === void 0 || (_serialized$options5 = _serialized$options5.inline) === null || _serialized$options5 === void 0 ? void 0 : _serialized$options5.a) === "object" ? deserializeSchema(serialized.options.inline.a) : (_serialized$options6 = serialized.options) === null || _serialized$options6 === void 0 || (_serialized$options6 = _serialized$options6.inline) === null || _serialized$options6 === void 0 ? void 0 : _serialized$options6.a,
9102
- img: _typeof((_serialized$options7 = serialized.options) === null || _serialized$options7 === void 0 || (_serialized$options7 = _serialized$options7.inline) === null || _serialized$options7 === void 0 ? void 0 : _serialized$options7.img) === "object" ? deserializeSchema(serialized.options.inline.img) : (_serialized$options8 = serialized.options) === null || _serialized$options8 === void 0 || (_serialized$options8 = _serialized$options8.inline) === null || _serialized$options8 === void 0 ? void 0 : _serialized$options8.img
9103
- } : (_serialized$options9 = serialized.options) === null || _serialized$options9 === void 0 ? void 0 : _serialized$options9.inline
9603
+ a: _typeof((_serialized$options3 = serialized.options) === null || _serialized$options3 === void 0 ? void 0 : _serialized$options3.a) === "object" ? deserializeSchema(serialized.options.a) : (_serialized$options4 = serialized.options) === null || _serialized$options4 === void 0 ? void 0 : _serialized$options4.a,
9604
+ img: _typeof((_serialized$options5 = serialized.options) === null || _serialized$options5 === void 0 ? void 0 : _serialized$options5.img) === "object" ? deserializeSchema(serialized.options.img) : (_serialized$options6 = serialized.options) === null || _serialized$options6 === void 0 ? void 0 : _serialized$options6.img
9104
9605
  });
9105
9606
  return new RichTextSchema(deserializedOptions, serialized.opt, [], false, false, serialized.description, (_serialized$render8 = serialized.render) !== null && _serialized$render8 !== void 0 ? _serialized$render8 : null);
9106
9607
  }
@@ -9739,6 +10240,7 @@ function tryJsonParse(str) {
9739
10240
  }
9740
10241
  }
9741
10242
 
10243
+ exports.ASSISTANT_SETTINGS_MAX_LENGTH = ASSISTANT_SETTINGS_MAX_LENGTH;
9742
10244
  exports.ArraySchema = ArraySchema;
9743
10245
  exports.BooleanSchema = BooleanSchema;
9744
10246
  exports.CODE_LANGUAGES = CODE_LANGUAGES;
@@ -9765,7 +10267,9 @@ exports.PatchError = PatchError;
9765
10267
  exports.RecordSchema = RecordSchema;
9766
10268
  exports.RichTextSchema = RichTextSchema;
9767
10269
  exports.RouteSchema = RouteSchema;
10270
+ exports.SETTINGS_MODULE_CONVENTION = SETTINGS_MODULE_CONVENTION;
9768
10271
  exports.Schema = Schema;
10272
+ exports.SettingsSchema = SettingsSchema;
9769
10273
  exports.StringSchema = StringSchema;
9770
10274
  exports.UnionSchema = UnionSchema;
9771
10275
  exports.VAL_EXTENSION = VAL_EXTENSION;
@@ -9774,6 +10278,7 @@ exports._createClass = _createClass;
9774
10278
  exports._slicedToArray = _slicedToArray;
9775
10279
  exports._toConsumableArray = _toConsumableArray;
9776
10280
  exports._typeof = _typeof;
10281
+ exports.assistantAvailability = assistantAvailability;
9777
10282
  exports.computeValModuleShas = computeValModuleShas;
9778
10283
  exports.derefPatch = derefPatch;
9779
10284
  exports.deserializeSchema = deserializeSchema;
@@ -9782,6 +10287,8 @@ exports.getSourcePathFromRoute = getSourcePathFromRoute;
9782
10287
  exports.hasRemoteFileSchema = hasRemoteFileSchema;
9783
10288
  exports.initVal = initVal;
9784
10289
  exports.isInlineRender = isInlineRender;
10290
+ exports.isRootModuleFilePath = isRootModuleFilePath;
9785
10291
  exports.modules = modules;
9786
10292
  exports.previewScope = previewScope;
10293
+ exports.resolveSettingsModule = resolveSettingsModule;
9787
10294
  exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;