@valbuild/core 0.153.5 → 0.154.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 +31 -0
- package/dist/declarations/src/index.d.ts +5 -2
- package/dist/declarations/src/read.d.ts +239 -0
- package/dist/declarations/src/render.d.ts +175 -3
- package/dist/declarations/src/schema/discriminatedUnion.d.ts +2 -0
- package/dist/declarations/src/schema/index.d.ts +7 -0
- package/dist/declarations/src/schema/object.d.ts +55 -1
- package/dist/declarations/src/source/component.d.ts +40 -0
- package/dist/declarations/src/val/index.d.ts +7 -0
- package/dist/{index-448b7c26.cjs.dev.js → index-48d6f61b.cjs.dev.js} +353 -37
- package/dist/{index-6a63e2dc.cjs.prod.js → index-58e0cce0.cjs.prod.js} +353 -37
- package/dist/{index-3d811c89.esm.js → index-676a0af1.esm.js} +348 -38
- package/dist/valbuild-core.cjs.dev.js +7 -1
- package/dist/valbuild-core.cjs.prod.js +7 -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
|
@@ -60,6 +60,13 @@ export type ParentPatchId = string & {
|
|
|
60
60
|
[brand]: "ParentPatchId";
|
|
61
61
|
};
|
|
62
62
|
export declare function getValPath(valOrSelector: Val<Json> | Selector<Source>): SourcePath | undefined;
|
|
63
|
+
/**
|
|
64
|
+
* The path a value was read from, for a value of ANY type: `getValPath` for
|
|
65
|
+
* code that was handed something and does not know it to be a `Val`. An
|
|
66
|
+
* object or a list a reader gave back carries one in draft mode
|
|
67
|
+
* (`setValPath`); anything else, and everything in production, does not.
|
|
68
|
+
*/
|
|
69
|
+
export declare function valPathOf(value: unknown): SourcePath | undefined;
|
|
63
70
|
/**
|
|
64
71
|
* Gives an object Val read the path it was read from, where `getValPath`
|
|
65
72
|
* finds it: the readers' (`stegaEncode`'s) half of `getValPath`, for objects,
|
|
@@ -93,6 +93,28 @@ function _defineProperty(e, r, t) {
|
|
|
93
93
|
}) : e[r] = t, e;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
function ownKeys(e, r) {
|
|
97
|
+
var t = Object.keys(e);
|
|
98
|
+
if (Object.getOwnPropertySymbols) {
|
|
99
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
100
|
+
r && (o = o.filter(function (r) {
|
|
101
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
102
|
+
})), t.push.apply(t, o);
|
|
103
|
+
}
|
|
104
|
+
return t;
|
|
105
|
+
}
|
|
106
|
+
function _objectSpread2(e) {
|
|
107
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
108
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
109
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
110
|
+
_defineProperty(e, r, t[r]);
|
|
111
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
112
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return e;
|
|
116
|
+
}
|
|
117
|
+
|
|
96
118
|
function _classCallCheck(a, n) {
|
|
97
119
|
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
98
120
|
}
|
|
@@ -525,6 +547,16 @@ var Schema = /*#__PURE__*/function () {
|
|
|
525
547
|
value: function executePreviewItem(src) {
|
|
526
548
|
return null;
|
|
527
549
|
}
|
|
550
|
+
/**
|
|
551
|
+
* EXPERIMENTAL: the component that renders this value, for a value whose
|
|
552
|
+
* source is `src`. Only `s.object(...).component(...)` declares
|
|
553
|
+
* one; a discriminated union answers for the variant `src` takes.
|
|
554
|
+
*/
|
|
555
|
+
}, {
|
|
556
|
+
key: "executeComponentRender",
|
|
557
|
+
value: function executeComponentRender(src) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
528
560
|
/**
|
|
529
561
|
* Could {@link executePreviewItem} ever answer? A container reifies a rows
|
|
530
562
|
* preview only when its item schema says yes — asked here rather than by
|
|
@@ -603,28 +635,6 @@ var Schema = /*#__PURE__*/function () {
|
|
|
603
635
|
|
|
604
636
|
// TODO: SourceError<"Could not determine type of Schema">
|
|
605
637
|
|
|
606
|
-
function ownKeys(e, r) {
|
|
607
|
-
var t = Object.keys(e);
|
|
608
|
-
if (Object.getOwnPropertySymbols) {
|
|
609
|
-
var o = Object.getOwnPropertySymbols(e);
|
|
610
|
-
r && (o = o.filter(function (r) {
|
|
611
|
-
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
612
|
-
})), t.push.apply(t, o);
|
|
613
|
-
}
|
|
614
|
-
return t;
|
|
615
|
-
}
|
|
616
|
-
function _objectSpread2(e) {
|
|
617
|
-
for (var r = 1; r < arguments.length; r++) {
|
|
618
|
-
var t = null != arguments[r] ? arguments[r] : {};
|
|
619
|
-
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
620
|
-
_defineProperty(e, r, t[r]);
|
|
621
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
622
|
-
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
return e;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
638
|
/**
|
|
629
639
|
* THE RULE, and the only sentence that needs to be remembered:
|
|
630
640
|
*
|
|
@@ -915,6 +925,19 @@ function isVal(val) {
|
|
|
915
925
|
function getValPath(valOrSelector) {
|
|
916
926
|
return valOrSelector[Path];
|
|
917
927
|
}
|
|
928
|
+
function carriesValPath(value) {
|
|
929
|
+
return Path in value && typeof value[Path] === "string";
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* The path a value was read from, for a value of ANY type: `getValPath` for
|
|
934
|
+
* code that was handed something and does not know it to be a `Val`. An
|
|
935
|
+
* object or a list a reader gave back carries one in draft mode
|
|
936
|
+
* (`setValPath`); anything else, and everything in production, does not.
|
|
937
|
+
*/
|
|
938
|
+
function valPathOf(value) {
|
|
939
|
+
return _typeof(value) === "object" && value !== null && carriesValPath(value) ? value[Path] : undefined;
|
|
940
|
+
}
|
|
918
941
|
|
|
919
942
|
/**
|
|
920
943
|
* Gives an object Val read the path it was read from, where `getValPath`
|
|
@@ -1333,6 +1356,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1333
1356
|
var isHidden = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
1334
1357
|
var description = arguments.length > 5 ? arguments[5] : undefined;
|
|
1335
1358
|
var previewInput = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : null;
|
|
1359
|
+
var renderInput = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : null;
|
|
1336
1360
|
_classCallCheck(this, ObjectSchema);
|
|
1337
1361
|
_this = _callSuper(this, ObjectSchema);
|
|
1338
1362
|
_this.items = items;
|
|
@@ -1342,6 +1366,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1342
1366
|
_this.isHidden = isHidden;
|
|
1343
1367
|
_this.description = description;
|
|
1344
1368
|
_this.previewInput = previewInput;
|
|
1369
|
+
_this.renderInput = renderInput;
|
|
1345
1370
|
return _this;
|
|
1346
1371
|
}
|
|
1347
1372
|
|
|
@@ -1371,7 +1396,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1371
1396
|
return _createClass(ObjectSchema, [{
|
|
1372
1397
|
key: "describe",
|
|
1373
1398
|
value: function describe(description) {
|
|
1374
|
-
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.previewInput);
|
|
1399
|
+
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, description !== null && description !== void 0 ? description : undefined, this.previewInput, this.renderInput);
|
|
1375
1400
|
}
|
|
1376
1401
|
|
|
1377
1402
|
/**
|
|
@@ -1403,7 +1428,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1403
1428
|
}, {
|
|
1404
1429
|
key: "validate",
|
|
1405
1430
|
value: function validate(validationFunction) {
|
|
1406
|
-
return new ObjectSchema(this.items, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.previewInput);
|
|
1431
|
+
return new ObjectSchema(this.items, this.opt, [].concat(_toConsumableArray(this.customValidateFunctions), [validationFunction]), this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
1407
1432
|
}
|
|
1408
1433
|
}, {
|
|
1409
1434
|
key: "executeValidate",
|
|
@@ -1536,19 +1561,19 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1536
1561
|
key: "nullable",
|
|
1537
1562
|
value: function nullable() {
|
|
1538
1563
|
// Explicit type args: `previewInput` would otherwise pin inference to `Src`.
|
|
1539
|
-
return new ObjectSchema(this.items, true, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput);
|
|
1564
|
+
return new ObjectSchema(this.items, true, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
1540
1565
|
}
|
|
1541
1566
|
}, {
|
|
1542
1567
|
key: "readonly",
|
|
1543
1568
|
value: function readonly() {
|
|
1544
1569
|
var isReadonly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1545
|
-
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.previewInput);
|
|
1570
|
+
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, isReadonly, this.isHidden, this.description, this.previewInput, this.renderInput);
|
|
1546
1571
|
}
|
|
1547
1572
|
}, {
|
|
1548
1573
|
key: "hidden",
|
|
1549
1574
|
value: function hidden() {
|
|
1550
1575
|
var isHidden = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1551
|
-
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.previewInput);
|
|
1576
|
+
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, isHidden, this.description, this.previewInput, this.renderInput);
|
|
1552
1577
|
}
|
|
1553
1578
|
|
|
1554
1579
|
/** The names of this object's `s.locale()` fields, in declaration order. */
|
|
@@ -1603,7 +1628,74 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1603
1628
|
}, {
|
|
1604
1629
|
key: "preview",
|
|
1605
1630
|
value: function preview(select) {
|
|
1606
|
-
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, select);
|
|
1631
|
+
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, select, this.renderInput);
|
|
1632
|
+
}
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* EXPERIMENTAL: the component that renders this object on the site.
|
|
1636
|
+
*
|
|
1637
|
+
* The site renders the object with it through `ValComponentEditor`, and the
|
|
1638
|
+
* Studio shows it next to the fields while they are edited, so the two
|
|
1639
|
+
* cannot drift.
|
|
1640
|
+
*
|
|
1641
|
+
* `load` is a lazy `import()`, never the component itself: a `.val.ts` is
|
|
1642
|
+
* evaluated outside of the app, where a component's CSS, images and
|
|
1643
|
+
* framework code cannot be loaded. See {@link ComponentRender}.
|
|
1644
|
+
*
|
|
1645
|
+
* It is type checked against the component's own props. An object whose
|
|
1646
|
+
* fields ARE the props needs nothing else. One whose fields are not - any
|
|
1647
|
+
* component that was not written for this schema - takes a `props`
|
|
1648
|
+
* function, which is then required and whose result is checked instead.
|
|
1649
|
+
* `props` is given the value as a reader returns it (an image has its
|
|
1650
|
+
* `url`), so a string it passes on unchanged can still be clicked to edit.
|
|
1651
|
+
*
|
|
1652
|
+
* Do not type the component's props from the schema it is linked from
|
|
1653
|
+
* (`t.inferSchema<typeof hero>` where `hero` is the result of this call):
|
|
1654
|
+
* the schema's type then depends on the component's and the component's on
|
|
1655
|
+
* the schema's, and TypeScript gives up on both. Declare the fields first
|
|
1656
|
+
* and link them in a second `const`, or let the component own its props.
|
|
1657
|
+
*
|
|
1658
|
+
* `example` is content that is not on the site, to preview with as well:
|
|
1659
|
+
* long titles and empty lists that make layout problems easy to spot.
|
|
1660
|
+
*
|
|
1661
|
+
* @example
|
|
1662
|
+
* const hero = s
|
|
1663
|
+
* .object({ title: s.string() })
|
|
1664
|
+
* .component(() => import("./HeroSection"), {
|
|
1665
|
+
* example: { title: "A very long title that should wrap nicely" },
|
|
1666
|
+
* });
|
|
1667
|
+
* export default c.define("/example.val.ts", s.array(hero), []);
|
|
1668
|
+
*
|
|
1669
|
+
* @example
|
|
1670
|
+
* // A component with props of its own: `props` says how to make them.
|
|
1671
|
+
* const banner = s
|
|
1672
|
+
* .object({ heading: s.string() })
|
|
1673
|
+
* .component(() => import("./HeroSection"), {
|
|
1674
|
+
* props: (value) => ({ title: value.heading }),
|
|
1675
|
+
* });
|
|
1676
|
+
* export default c.define("/example.val.ts", banner, { heading: "Hello" });
|
|
1677
|
+
*/
|
|
1678
|
+
}, {
|
|
1679
|
+
key: "component",
|
|
1680
|
+
value: function component(load) {
|
|
1681
|
+
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key3 = 1; _key3 < _len; _key3++) {
|
|
1682
|
+
rest[_key3 - 1] = arguments[_key3];
|
|
1683
|
+
}
|
|
1684
|
+
var options = rest[0];
|
|
1685
|
+
var input = _objectSpread2(_objectSpread2({
|
|
1686
|
+
as: "component",
|
|
1687
|
+
component: load
|
|
1688
|
+
}, (options === null || options === void 0 ? void 0 : options.props) !== undefined ? {
|
|
1689
|
+
props: options.props
|
|
1690
|
+
} : {}), (options === null || options === void 0 ? void 0 : options.example) !== undefined ? {
|
|
1691
|
+
example: options.example
|
|
1692
|
+
} : {});
|
|
1693
|
+
return new ObjectSchema(this.items, this.opt, this.customValidateFunctions, this.isReadonly, this.isHidden, this.description, this.previewInput, input);
|
|
1694
|
+
}
|
|
1695
|
+
}, {
|
|
1696
|
+
key: "executeComponentRender",
|
|
1697
|
+
value: function executeComponentRender(src) {
|
|
1698
|
+
return this.renderInput;
|
|
1607
1699
|
}
|
|
1608
1700
|
}, {
|
|
1609
1701
|
key: "executePreviewItem",
|
|
@@ -1624,7 +1716,7 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1624
1716
|
key: "executeSerialize",
|
|
1625
1717
|
value: function executeSerialize() {
|
|
1626
1718
|
var _this$customValidateF;
|
|
1627
|
-
return {
|
|
1719
|
+
return _objectSpread2({
|
|
1628
1720
|
type: "object",
|
|
1629
1721
|
preview: this.previewInput ? true : undefined,
|
|
1630
1722
|
items: Object.fromEntries(Object.entries(this.items).map(function (_ref5) {
|
|
@@ -1638,7 +1730,12 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1638
1730
|
readonly: this.isReadonly,
|
|
1639
1731
|
hidden: this.isHidden,
|
|
1640
1732
|
description: this.description
|
|
1641
|
-
}
|
|
1733
|
+
}, this.renderInput ? {
|
|
1734
|
+
render: {
|
|
1735
|
+
as: "component",
|
|
1736
|
+
example: this.renderInput.example !== undefined ? true : undefined
|
|
1737
|
+
}
|
|
1738
|
+
} : {});
|
|
1642
1739
|
}
|
|
1643
1740
|
}, {
|
|
1644
1741
|
key: "executePreview",
|
|
@@ -1647,19 +1744,19 @@ var ObjectSchema = /*#__PURE__*/function (_Schema) {
|
|
|
1647
1744
|
if (src === null) {
|
|
1648
1745
|
return res;
|
|
1649
1746
|
}
|
|
1650
|
-
for (var
|
|
1651
|
-
var itemSrc = src[
|
|
1747
|
+
for (var _key4 in this.items) {
|
|
1748
|
+
var itemSrc = src[_key4];
|
|
1652
1749
|
if (itemSrc === null || itemSrc === undefined) {
|
|
1653
1750
|
continue;
|
|
1654
1751
|
}
|
|
1655
|
-
var subPath = unsafeCreateSourcePath(sourcePath,
|
|
1752
|
+
var subPath = unsafeCreateSourcePath(sourcePath, _key4);
|
|
1656
1753
|
// An object produces no preview of its own, so it is pure recursion — and
|
|
1657
1754
|
// pruning it is the whole contribution: a field deep in one branch stops
|
|
1658
1755
|
// paying for every sibling branch's previews.
|
|
1659
1756
|
if (scope !== undefined && !scope.wantsUnder(subPath)) {
|
|
1660
1757
|
continue;
|
|
1661
1758
|
}
|
|
1662
|
-
mergePreviewInto(res, this.items[
|
|
1759
|
+
mergePreviewInto(res, this.items[_key4]["executePreview"](subPath, itemSrc, scope));
|
|
1663
1760
|
}
|
|
1664
1761
|
// An object reifies no rows of its own, so the only thing it adds is what
|
|
1665
1762
|
// IT is called — which nothing else can supply for a field of an object.
|
|
@@ -2695,6 +2792,12 @@ var DiscriminatedUnionSchema = /*#__PURE__*/function (_Schema) {
|
|
|
2695
2792
|
}
|
|
2696
2793
|
return null;
|
|
2697
2794
|
}
|
|
2795
|
+
}, {
|
|
2796
|
+
key: "executeComponentRender",
|
|
2797
|
+
value: function executeComponentRender(src) {
|
|
2798
|
+
var matched = this.matchedVariant(src);
|
|
2799
|
+
return matched ? matched["executeComponentRender"](src) : null;
|
|
2800
|
+
}
|
|
2698
2801
|
}, {
|
|
2699
2802
|
key: "declaresItemPreview",
|
|
2700
2803
|
value: function declaresItemPreview() {
|
|
@@ -16893,11 +16996,16 @@ function routerForParams(routerId) {
|
|
|
16893
16996
|
* A RENDER is how a field is laid out in the editor, and it applies only when
|
|
16894
16997
|
* you are looking at the field. On a list it is declared by the CONTAINER about
|
|
16895
16998
|
* its children, never by a child about itself: `s.array(item).render({ as: "inline" })`
|
|
16896
|
-
* and `s.record(item).render({ as: "inline" })`.
|
|
16999
|
+
* and `s.record(item).render({ as: "inline" })`. Three other schemas take a
|
|
16897
17000
|
* render, each meaning something of its own: `s.keyOf(...)` (see
|
|
16898
|
-
* `KeyOfSchema.render`)
|
|
17001
|
+
* `KeyOfSchema.render`), `s.number()` / `s.int()`, whose `{ as: "slider" }`
|
|
16899
17002
|
* is a different input for the same value (see {@link SliderRender}).
|
|
16900
17003
|
*
|
|
17004
|
+
* EXPERIMENTAL: an object's component is declared with `.component(...)` and
|
|
17005
|
+
* not with `.render(...)`, because it is more than layout in the editor: the
|
|
17006
|
+
* site renders the object with it (see {@link ComponentRender}). Its marker
|
|
17007
|
+
* still travels as the serialized `render`, `{ as: "component" }`.
|
|
17008
|
+
*
|
|
16901
17009
|
* Why the container: inline is a property of the LIST — "my items are edited in
|
|
16902
17010
|
* their rows" — and the item schema is the wrong place to say it. An item can be
|
|
16903
17011
|
* reused in a list that wants preview rows and one that wants forms; a tagged
|
|
@@ -17002,9 +17110,210 @@ function isInlineRender(container) {
|
|
|
17002
17110
|
return ((_container$render = container.render) === null || _container$render === void 0 ? void 0 : _container$render.as) === "inline";
|
|
17003
17111
|
}
|
|
17004
17112
|
|
|
17113
|
+
/**
|
|
17114
|
+
* EXPERIMENTAL. A React (or any) component, typed loosely because core knows
|
|
17115
|
+
* nothing about React. `never` in the parameter position accepts a component
|
|
17116
|
+
* of any props, since parameters are contravariant.
|
|
17117
|
+
*/
|
|
17118
|
+
|
|
17119
|
+
/**
|
|
17120
|
+
* What the `component` thunk of a {@link ComponentRender} resolves to: the
|
|
17121
|
+
* component itself, or a module whose default export is the component.
|
|
17122
|
+
*/
|
|
17123
|
+
|
|
17124
|
+
/**
|
|
17125
|
+
* The props a component takes, read off its own type: what `.component()`
|
|
17126
|
+
* checks a schema's fields (or its `props` function) against. Structural, so
|
|
17127
|
+
* it needs nothing of React: a function component is a function of its props,
|
|
17128
|
+
* and a class component is constructed with them.
|
|
17129
|
+
*/
|
|
17130
|
+
|
|
17131
|
+
/**
|
|
17132
|
+
* EXPERIMENTAL. What `.component(load, options)` on `s.object(...)` holds:
|
|
17133
|
+
* the component that renders this object on the site.
|
|
17134
|
+
*
|
|
17135
|
+
* The site renders the object through it (`ValComponentEditor`), and the
|
|
17136
|
+
* app's preview route (`ValComponentPreview`) renders it alone. Both go
|
|
17137
|
+
* through the same thunk and the same `props`, so what the editor sees cannot
|
|
17138
|
+
* drift from what a visitor gets. In the Studio's field panel the object is
|
|
17139
|
+
* edited as any other object: its fields, with no component beside them.
|
|
17140
|
+
*
|
|
17141
|
+
* It holds CLOSURES - the `component` thunk and `props` - so, exactly like a
|
|
17142
|
+
* preview, only a marker travels in the serialized schema
|
|
17143
|
+
* ({@link SerializedComponentRender}) and the component is rendered by the
|
|
17144
|
+
* host app, which has the schema instance.
|
|
17145
|
+
*
|
|
17146
|
+
* `component` is a lazy `import()` rather than the component itself. A
|
|
17147
|
+
* `.val.ts` may not import app code (`@valbuild/eslint-plugin`'s
|
|
17148
|
+
* `no-illegal-imports`), because Val evaluates val files outside of the app -
|
|
17149
|
+
* `val validate`, the language server and the Studio all do - and a component
|
|
17150
|
+
* pulls in CSS, images and framework code none of those can load. A thunk is
|
|
17151
|
+
* never called there, so the component's file is never loaded either. On the
|
|
17152
|
+
* site it also means a page downloads the components it shows and no others.
|
|
17153
|
+
*
|
|
17154
|
+
* `props` turns the value into the component's props, for a component whose
|
|
17155
|
+
* props are not the object's fields: one that was written before the schema,
|
|
17156
|
+
* or belongs to a design system. It is called with the READ value (an image
|
|
17157
|
+
* has its `url`, a string carries its edit tag), so a string it passes on
|
|
17158
|
+
* unchanged is still a click away from its field, and one it transforms is
|
|
17159
|
+
* not. Without it the value itself is the props.
|
|
17160
|
+
*
|
|
17161
|
+
* `example` is content to preview the component with that is not on the site:
|
|
17162
|
+
* a fixture, and a good place for deliberately unrepresentative values (very
|
|
17163
|
+
* long titles, empty lists) that make layout problems easy to spot.
|
|
17164
|
+
*/
|
|
17165
|
+
|
|
17166
|
+
/**
|
|
17167
|
+
* The options of `.component(load, options)` that are not the `props`
|
|
17168
|
+
* function. See {@link ComponentRender} for each.
|
|
17169
|
+
*/
|
|
17170
|
+
|
|
17171
|
+
/** {@link ComponentOptions} for a component whose props ARE the read value. */
|
|
17172
|
+
|
|
17173
|
+
/**
|
|
17174
|
+
* {@link ComponentOptions} for a component whose props are NOT the read
|
|
17175
|
+
* value: `props` is what makes them, so it is required.
|
|
17176
|
+
*/
|
|
17177
|
+
|
|
17178
|
+
/**
|
|
17179
|
+
* What follows the thunk in `.component(load, ...)`: nothing or options when
|
|
17180
|
+
* the value a reader gives back (`Read`) is assignable to the component's
|
|
17181
|
+
* props, and options with a `props` function when it is not. That is the
|
|
17182
|
+
* whole type check: a component that cannot be handed this object does not
|
|
17183
|
+
* compile, on the line that links them.
|
|
17184
|
+
*
|
|
17185
|
+
* In tuples so the test does not distribute over a union of props.
|
|
17186
|
+
*/
|
|
17187
|
+
|
|
17188
|
+
/**
|
|
17189
|
+
* What a {@link ComponentRender} serializes to. The component is a closure and
|
|
17190
|
+
* cannot travel; `example` says whether there is one to preview with.
|
|
17191
|
+
*/
|
|
17192
|
+
|
|
17193
|
+
/**
|
|
17194
|
+
* The messages between the Studio and the host app's preview route, which run
|
|
17195
|
+
* in different frames. Both sides read them from here so they cannot drift.
|
|
17196
|
+
*
|
|
17197
|
+
* - `ready`: preview to Studio. The preview is listening; tell it whether
|
|
17198
|
+
* clicking picks.
|
|
17199
|
+
* - `refresh`: Studio to preview. The content changed; render it again.
|
|
17200
|
+
* - `size`: preview to Studio, with `{ height }`. What the component rendered
|
|
17201
|
+
* is this tall, so the Studio can size the frame to fit it.
|
|
17202
|
+
* - `picking`: Studio to preview, with `{ enabled }`. Whether a click on
|
|
17203
|
+
* content picks the field it came from, rather than doing what a click on
|
|
17204
|
+
* the site does.
|
|
17205
|
+
* - `pick`: preview to Studio, with `{ paths }`. The editor clicked content
|
|
17206
|
+
* with these source paths behind it (from its `data-val-path`).
|
|
17207
|
+
*/
|
|
17208
|
+
var VAL_PREVIEW_MESSAGES = {
|
|
17209
|
+
ready: "val-preview-ready",
|
|
17210
|
+
refresh: "val-preview-refresh",
|
|
17211
|
+
size: "val-preview-size",
|
|
17212
|
+
picking: "val-preview-picking",
|
|
17213
|
+
pick: "val-preview-pick"
|
|
17214
|
+
};
|
|
17215
|
+
|
|
17216
|
+
/**
|
|
17217
|
+
* EXPERIMENTAL: the component that renders a value of `schema` whose source is
|
|
17218
|
+
* `src`, or `null` when there is none. A discriminated union answers for the
|
|
17219
|
+
* variant `src` takes, which is what a list of page sections needs.
|
|
17220
|
+
*/
|
|
17221
|
+
function getComponentRender(schema, src) {
|
|
17222
|
+
return schema["executeComponentRender"](src);
|
|
17223
|
+
}
|
|
17224
|
+
|
|
17225
|
+
/**
|
|
17226
|
+
* EXPERIMENTAL: call a {@link ComponentRender}'s thunk and unwrap a module's
|
|
17227
|
+
* default export.
|
|
17228
|
+
*/
|
|
17229
|
+
function loadComponent(_x) {
|
|
17230
|
+
return _loadComponent.apply(this, arguments);
|
|
17231
|
+
}
|
|
17232
|
+
|
|
17233
|
+
/**
|
|
17234
|
+
* EXPERIMENTAL: the props to render a {@link ComponentRender}'s component
|
|
17235
|
+
* with, for `value` as a reader gave it back: what its `props` function makes
|
|
17236
|
+
* of it, or the value itself when it has none.
|
|
17237
|
+
*
|
|
17238
|
+
* The one place the mapper is called, so the site (`ValComponentEditor`) and
|
|
17239
|
+
* the Studio's preview cannot disagree about what the component is handed.
|
|
17240
|
+
*/
|
|
17241
|
+
function _loadComponent() {
|
|
17242
|
+
_loadComponent = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(render) {
|
|
17243
|
+
var imported;
|
|
17244
|
+
return _regenerator().w(function (_context) {
|
|
17245
|
+
while (1) switch (_context.n) {
|
|
17246
|
+
case 0:
|
|
17247
|
+
_context.n = 1;
|
|
17248
|
+
return render.component();
|
|
17249
|
+
case 1:
|
|
17250
|
+
imported = _context.v;
|
|
17251
|
+
return _context.a(2, typeof imported === "function" ? imported : imported["default"]);
|
|
17252
|
+
}
|
|
17253
|
+
}, _callee);
|
|
17254
|
+
}));
|
|
17255
|
+
return _loadComponent.apply(this, arguments);
|
|
17256
|
+
}
|
|
17257
|
+
function componentPropsOf(render, value) {
|
|
17258
|
+
if (render.props === undefined) {
|
|
17259
|
+
return value;
|
|
17260
|
+
}
|
|
17261
|
+
// `.component()` checked this function against the read type of the schema
|
|
17262
|
+
// that holds it. A render found by path has lost that relation - it is why
|
|
17263
|
+
// the parameter is `never` - and `value` is that schema's value, read: this
|
|
17264
|
+
// assertion is what restores it, here and nowhere else.
|
|
17265
|
+
return render.props(value);
|
|
17266
|
+
}
|
|
17267
|
+
|
|
17268
|
+
/**
|
|
17269
|
+
* Where a value's component rides. Registered globally for the reason the
|
|
17270
|
+
* selector symbols are (`selector/index.ts`): two bundled copies of core must
|
|
17271
|
+
* agree on it, or what one attached the other cannot find.
|
|
17272
|
+
*/
|
|
17273
|
+
var ComponentOfValue = Symbol["for"]("@valbuild/core/ComponentOfValue");
|
|
17274
|
+
function isComponentRender(value) {
|
|
17275
|
+
return _typeof(value) === "object" && value !== null && "as" in value && value.as === "component" && "component" in value && typeof value.component === "function";
|
|
17276
|
+
}
|
|
17277
|
+
|
|
17278
|
+
/**
|
|
17279
|
+
* EXPERIMENTAL: attach, to a value a reader is about to give back, the
|
|
17280
|
+
* component its schema links it to (`.component()`), so `ValComponentEditor`
|
|
17281
|
+
* can render the value without a registry: the value says what renders it.
|
|
17282
|
+
*
|
|
17283
|
+
* The same idea as a view's handle, for the same reason. The app cannot get
|
|
17284
|
+
* from a value back to its schema, and the reader (`stegaEncode`) is the one
|
|
17285
|
+
* place that has both.
|
|
17286
|
+
*
|
|
17287
|
+
* Not enumerable, and a symbol: `Object.keys`, `JSON.stringify` and every
|
|
17288
|
+
* walk that reads content as data still see only the content. So, like a
|
|
17289
|
+
* view's handle, it does not survive serialization: a value passed from a
|
|
17290
|
+
* server component to a client one arrives without it.
|
|
17291
|
+
*/
|
|
17292
|
+
function setComponentOfValue(target, render) {
|
|
17293
|
+
Object.defineProperty(target, ComponentOfValue, {
|
|
17294
|
+
value: render,
|
|
17295
|
+
enumerable: false,
|
|
17296
|
+
configurable: true
|
|
17297
|
+
});
|
|
17298
|
+
}
|
|
17299
|
+
|
|
17300
|
+
/**
|
|
17301
|
+
* EXPERIMENTAL: the component a read value is linked to, or `null` when it
|
|
17302
|
+
* carries none: its schema has no `.component()`, or the value crossed a
|
|
17303
|
+
* server/client boundary and lost it.
|
|
17304
|
+
*/
|
|
17305
|
+
function componentOfValue(value) {
|
|
17306
|
+
var _Object$getOwnPropert;
|
|
17307
|
+
if (_typeof(value) !== "object" || value === null) {
|
|
17308
|
+
return null;
|
|
17309
|
+
}
|
|
17310
|
+
var render = (_Object$getOwnPropert = Object.getOwnPropertyDescriptor(value, ComponentOfValue)) === null || _Object$getOwnPropert === void 0 ? void 0 : _Object$getOwnPropert.value;
|
|
17311
|
+
return isComponentRender(render) ? render : null;
|
|
17312
|
+
}
|
|
17313
|
+
|
|
17005
17314
|
var corePackageJson = {
|
|
17006
17315
|
name: "@valbuild/core",
|
|
17007
|
-
version: "0.
|
|
17316
|
+
version: "0.154.2",
|
|
17008
17317
|
"private": false,
|
|
17009
17318
|
description: "Val - supercharged hard-coded content",
|
|
17010
17319
|
repository: {
|
|
@@ -17125,6 +17434,7 @@ var Internal = {
|
|
|
17125
17434
|
getSchema: getSchema,
|
|
17126
17435
|
getValPath: getValPath,
|
|
17127
17436
|
setValPath: setValPath,
|
|
17437
|
+
valPathOf: valPathOf,
|
|
17128
17438
|
getSource: getSource,
|
|
17129
17439
|
isValModule: isValModule,
|
|
17130
17440
|
resolvePath: resolvePath,
|
|
@@ -17288,6 +17598,7 @@ exports.THEME_RADIUS_LENGTHS = THEME_RADIUS_LENGTHS;
|
|
|
17288
17598
|
exports.THEME_RADIUS_STEPS = THEME_RADIUS_STEPS;
|
|
17289
17599
|
exports.UNSAFE_URL_SCHEMES = UNSAFE_URL_SCHEMES;
|
|
17290
17600
|
exports.VAL_EXTENSION = VAL_EXTENSION;
|
|
17601
|
+
exports.VAL_PREVIEW_MESSAGES = VAL_PREVIEW_MESSAGES;
|
|
17291
17602
|
exports.ValViewSchema = ValViewSchema;
|
|
17292
17603
|
exports.VideoSchema = VideoSchema;
|
|
17293
17604
|
exports._classCallCheck = _classCallCheck;
|
|
@@ -17296,6 +17607,8 @@ exports._slicedToArray = _slicedToArray;
|
|
|
17296
17607
|
exports._toConsumableArray = _toConsumableArray;
|
|
17297
17608
|
exports._typeof = _typeof;
|
|
17298
17609
|
exports.assistantAvailability = assistantAvailability;
|
|
17610
|
+
exports.componentOfValue = componentOfValue;
|
|
17611
|
+
exports.componentPropsOf = componentPropsOf;
|
|
17299
17612
|
exports.computeSchemaSha = computeSchemaSha;
|
|
17300
17613
|
exports.computeSourcesSha = computeSourcesSha;
|
|
17301
17614
|
exports.computeValModuleShas = computeValModuleShas;
|
|
@@ -17305,6 +17618,7 @@ exports.describeSchemeRejection = describeSchemeRejection;
|
|
|
17305
17618
|
exports.deserializeSchema = deserializeSchema;
|
|
17306
17619
|
exports.discriminatedUnionBranchOf = discriminatedUnionBranchOf;
|
|
17307
17620
|
exports.extractValModules = extractValModules;
|
|
17621
|
+
exports.getComponentRender = getComponentRender;
|
|
17308
17622
|
exports.getSourcePathFromRoute = getSourcePathFromRoute;
|
|
17309
17623
|
exports.hasMediaSchema = hasMediaSchema;
|
|
17310
17624
|
exports.hasRemoteFileSchema = hasRemoteFileSchema;
|
|
@@ -17314,6 +17628,7 @@ exports.isInlineRender = isInlineRender;
|
|
|
17314
17628
|
exports.isPageRouter = isPageRouter;
|
|
17315
17629
|
exports.isRootModuleFilePath = isRootModuleFilePath;
|
|
17316
17630
|
exports.isValViewSource = isValViewSource;
|
|
17631
|
+
exports.loadComponent = loadComponent;
|
|
17317
17632
|
exports.localeOfValue = localeOfValue;
|
|
17318
17633
|
exports.localeTagError = localeTagError;
|
|
17319
17634
|
exports.matchRoutePattern = matchRoutePattern;
|
|
@@ -17326,6 +17641,7 @@ exports.rejectScheme = rejectScheme;
|
|
|
17326
17641
|
exports.resolveSettingsModule = resolveSettingsModule;
|
|
17327
17642
|
exports.routePatternOf = routePatternOf;
|
|
17328
17643
|
exports.schemeOf = schemeOf;
|
|
17644
|
+
exports.setComponentOfValue = setComponentOfValue;
|
|
17329
17645
|
exports.splitModuleFilePathAndModulePath = splitModuleFilePathAndModulePath;
|
|
17330
17646
|
exports.tanStackSegmentsOfRoutePath = tanStackSegmentsOfRoutePath;
|
|
17331
17647
|
exports.validateUrlAgainstPattern = validateUrlAgainstPattern;
|