@nascentdigital/funnel-core 4.4.4
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/dist/app/AppConfig.d.ts +41 -0
- package/dist/app/AppConfig.js +93 -0
- package/dist/app/BrandConfig.d.ts +13 -0
- package/dist/app/BrandConfig.js +2 -0
- package/dist/app/FeaturesConfig.d.ts +6 -0
- package/dist/app/FeaturesConfig.js +2 -0
- package/dist/app/RegionsConfig.d.ts +43 -0
- package/dist/app/RegionsConfig.js +113 -0
- package/dist/app/UIConfig.d.ts +4 -0
- package/dist/app/UIConfig.js +2 -0
- package/dist/app/index.d.ts +5 -0
- package/dist/app/index.js +21 -0
- package/dist/consent/ConsentCategory.d.ts +12 -0
- package/dist/consent/ConsentCategory.js +28 -0
- package/dist/consent/ConsentService.d.ts +15 -0
- package/dist/consent/ConsentService.js +37 -0
- package/dist/consent/index.d.ts +2 -0
- package/dist/consent/index.js +18 -0
- package/dist/errors/IsometricError.d.ts +19 -0
- package/dist/errors/IsometricError.js +30 -0
- package/dist/errors/IsometricErrorModule.d.ts +11 -0
- package/dist/errors/IsometricErrorModule.js +2 -0
- package/dist/errors/IsometricErrorUtils.d.ts +9 -0
- package/dist/errors/IsometricErrorUtils.js +85 -0
- package/dist/errors/SerializedIsometricError.d.ts +10 -0
- package/dist/errors/SerializedIsometricError.js +15 -0
- package/dist/errors/api/ApiError.d.ts +15 -0
- package/dist/errors/api/ApiError.js +23 -0
- package/dist/errors/api/ApiErrors.d.ts +7 -0
- package/dist/errors/api/ApiErrors.js +67 -0
- package/dist/errors/api/ArgumentError.d.ts +7 -0
- package/dist/errors/api/ArgumentError.js +18 -0
- package/dist/errors/api/ConcurrencyError.d.ts +4 -0
- package/dist/errors/api/ConcurrencyError.js +11 -0
- package/dist/errors/api/ConflictError.d.ts +4 -0
- package/dist/errors/api/ConflictError.js +11 -0
- package/dist/errors/api/DependencyError.d.ts +4 -0
- package/dist/errors/api/DependencyError.js +11 -0
- package/dist/errors/api/IllegalStateError.d.ts +4 -0
- package/dist/errors/api/IllegalStateError.js +11 -0
- package/dist/errors/api/InvalidOperationError.d.ts +4 -0
- package/dist/errors/api/InvalidOperationError.js +11 -0
- package/dist/errors/api/NotAuthenticatedError.d.ts +4 -0
- package/dist/errors/api/NotAuthenticatedError.js +11 -0
- package/dist/errors/api/NotAuthorizedError.d.ts +4 -0
- package/dist/errors/api/NotAuthorizedError.js +11 -0
- package/dist/errors/api/NotAvailableError.d.ts +4 -0
- package/dist/errors/api/NotAvailableError.js +11 -0
- package/dist/errors/api/NotFoundError.d.ts +4 -0
- package/dist/errors/api/NotFoundError.js +11 -0
- package/dist/errors/api/NotImplementedError.d.ts +4 -0
- package/dist/errors/api/NotImplementedError.js +11 -0
- package/dist/errors/api/OfflineError.d.ts +4 -0
- package/dist/errors/api/OfflineError.js +11 -0
- package/dist/errors/api/RangeError.d.ts +4 -0
- package/dist/errors/api/RangeError.js +11 -0
- package/dist/errors/api/ServerError.d.ts +4 -0
- package/dist/errors/api/ServerError.js +11 -0
- package/dist/errors/api/TimeoutError.d.ts +4 -0
- package/dist/errors/api/TimeoutError.js +11 -0
- package/dist/errors/api/index.d.ts +16 -0
- package/dist/errors/api/index.js +32 -0
- package/dist/errors/index.d.ts +5 -0
- package/dist/errors/index.js +26 -0
- package/dist/forms/FormModel.d.ts +47 -0
- package/dist/forms/FormModel.js +149 -0
- package/dist/forms/Forms.d.ts +15 -0
- package/dist/forms/Forms.js +35 -0
- package/dist/forms/IFormService.d.ts +6 -0
- package/dist/forms/IFormService.js +2 -0
- package/dist/forms/TranslateSchema.d.ts +8 -0
- package/dist/forms/TranslateSchema.js +2 -0
- package/dist/forms/index.d.ts +4 -0
- package/dist/forms/index.js +20 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +49 -0
- package/dist/regionalization/Country.d.ts +266 -0
- package/dist/regionalization/Country.js +338 -0
- package/dist/regionalization/Language.d.ts +199 -0
- package/dist/regionalization/Language.js +237 -0
- package/dist/regionalization/Locale.d.ts +28 -0
- package/dist/regionalization/Locale.js +49 -0
- package/dist/regionalization/Localized.d.ts +10 -0
- package/dist/regionalization/Localized.js +36 -0
- package/dist/regionalization/LocalizedCopy.d.ts +9 -0
- package/dist/regionalization/LocalizedCopy.js +26 -0
- package/dist/regionalization/Regionalization.d.ts +50 -0
- package/dist/regionalization/Regionalization.js +260 -0
- package/dist/regionalization/Regions.d.ts +2 -0
- package/dist/regionalization/Regions.js +2 -0
- package/dist/regionalization/index.d.ts +7 -0
- package/dist/regionalization/index.js +23 -0
- package/dist/schema/Asset.d.ts +23 -0
- package/dist/schema/Asset.js +36 -0
- package/dist/schema/AssetScope.d.ts +75 -0
- package/dist/schema/AssetScope.js +146 -0
- package/dist/schema/Block.d.ts +105 -0
- package/dist/schema/Block.js +122 -0
- package/dist/schema/ChangeSet.d.ts +108 -0
- package/dist/schema/ChangeSet.js +187 -0
- package/dist/schema/Collection.d.ts +197 -0
- package/dist/schema/Collection.js +165 -0
- package/dist/schema/CollectionModel.d.ts +30 -0
- package/dist/schema/CollectionModel.js +383 -0
- package/dist/schema/CollectionSnapshot.d.ts +11 -0
- package/dist/schema/CollectionSnapshot.js +12 -0
- package/dist/schema/Fields.d.ts +31 -0
- package/dist/schema/Fields.js +21 -0
- package/dist/schema/Form.d.ts +31 -0
- package/dist/schema/Form.js +23 -0
- package/dist/schema/LinkedCollectionModel.d.ts +9 -0
- package/dist/schema/LinkedCollectionModel.js +19 -0
- package/dist/schema/LinkedData.d.ts +44 -0
- package/dist/schema/LinkedData.js +288 -0
- package/dist/schema/LinkedPageModel.d.ts +11 -0
- package/dist/schema/LinkedPageModel.js +26 -0
- package/dist/schema/Optional.d.ts +23 -0
- package/dist/schema/Optional.js +34 -0
- package/dist/schema/Page.d.ts +299 -0
- package/dist/schema/Page.js +244 -0
- package/dist/schema/PageModel.d.ts +58 -0
- package/dist/schema/PageModel.js +881 -0
- package/dist/schema/PageQuery.d.ts +60 -0
- package/dist/schema/PageQuery.js +116 -0
- package/dist/schema/PageRoute.d.ts +7 -0
- package/dist/schema/PageRoute.js +48 -0
- package/dist/schema/PageSnapshot.d.ts +11 -0
- package/dist/schema/PageSnapshot.js +12 -0
- package/dist/schema/Section.d.ts +71 -0
- package/dist/schema/Section.js +35 -0
- package/dist/schema/Seo.d.ts +13 -0
- package/dist/schema/Seo.js +25 -0
- package/dist/schema/Site.d.ts +40 -0
- package/dist/schema/Site.js +87 -0
- package/dist/schema/SiteModel.d.ts +5 -0
- package/dist/schema/SiteModel.js +10 -0
- package/dist/schema/Tag.d.ts +28 -0
- package/dist/schema/Tag.js +59 -0
- package/dist/schema/TagGroup.d.ts +26 -0
- package/dist/schema/TagGroup.js +64 -0
- package/dist/schema/field/Field.d.ts +179 -0
- package/dist/schema/field/Field.js +309 -0
- package/dist/schema/field/base/AssetField.d.ts +148 -0
- package/dist/schema/field/base/AssetField.js +206 -0
- package/dist/schema/field/base/BooleanField.d.ts +21 -0
- package/dist/schema/field/base/BooleanField.js +38 -0
- package/dist/schema/field/base/CollectionField.d.ts +34 -0
- package/dist/schema/field/base/CollectionField.js +85 -0
- package/dist/schema/field/base/DateField.d.ts +21 -0
- package/dist/schema/field/base/DateField.js +37 -0
- package/dist/schema/field/base/DynamicPagesField.d.ts +36 -0
- package/dist/schema/field/base/DynamicPagesField.js +50 -0
- package/dist/schema/field/base/EmbeddedVideoField.d.ts +45 -0
- package/dist/schema/field/base/EmbeddedVideoField.js +176 -0
- package/dist/schema/field/base/EnumField.d.ts +40 -0
- package/dist/schema/field/base/EnumField.js +131 -0
- package/dist/schema/field/base/FormField.d.ts +25 -0
- package/dist/schema/field/base/FormField.js +48 -0
- package/dist/schema/field/base/LinkField.d.ts +103 -0
- package/dist/schema/field/base/LinkField.js +201 -0
- package/dist/schema/field/base/PageField.d.ts +46 -0
- package/dist/schema/field/base/PageField.js +83 -0
- package/dist/schema/field/base/RichTextField.d.ts +71 -0
- package/dist/schema/field/base/RichTextField.js +196 -0
- package/dist/schema/field/base/TextField.d.ts +33 -0
- package/dist/schema/field/base/TextField.js +86 -0
- package/dist/schema/field/base/TimestampField.d.ts +25 -0
- package/dist/schema/field/base/TimestampField.js +41 -0
- package/dist/schema/field/base/index.d.ts +13 -0
- package/dist/schema/field/base/index.js +29 -0
- package/dist/schema/field/composite/ListField.d.ts +47 -0
- package/dist/schema/field/composite/ListField.js +107 -0
- package/dist/schema/field/composite/ObjectField.d.ts +56 -0
- package/dist/schema/field/composite/ObjectField.js +19 -0
- package/dist/schema/field/composite/index.d.ts +2 -0
- package/dist/schema/field/composite/index.js +18 -0
- package/dist/schema/field/index.d.ts +3 -0
- package/dist/schema/field/index.js +19 -0
- package/dist/schema/index.d.ts +25 -0
- package/dist/schema/index.js +41 -0
- package/dist/services/EventBus.d.ts +17 -0
- package/dist/services/EventBus.js +37 -0
- package/dist/services/humanVerification/IHumanVerification.d.ts +8 -0
- package/dist/services/humanVerification/IHumanVerification.js +2 -0
- package/dist/services/humanVerification/index.d.ts +1 -0
- package/dist/services/humanVerification/index.js +17 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +19 -0
- package/dist/services/leadGen/Contact.d.ts +40 -0
- package/dist/services/leadGen/Contact.js +38 -0
- package/dist/services/leadGen/ILeadGen.d.ts +16 -0
- package/dist/services/leadGen/ILeadGen.js +2 -0
- package/dist/services/leadGen/index.d.ts +2 -0
- package/dist/services/leadGen/index.js +18 -0
- package/dist/types/BoxedValue.d.ts +3 -0
- package/dist/types/BoxedValue.js +2 -0
- package/dist/types/Callback.d.ts +9 -0
- package/dist/types/Callback.js +2 -0
- package/dist/types/DateString.d.ts +35 -0
- package/dist/types/DateString.js +172 -0
- package/dist/types/FilterConditionally.d.ts +3 -0
- package/dist/types/FilterConditionally.js +2 -0
- package/dist/types/MaybeConditionalValue.d.ts +8 -0
- package/dist/types/MaybeConditionalValue.js +12 -0
- package/dist/types/Ordinal.d.ts +17 -0
- package/dist/types/Ordinal.js +38 -0
- package/dist/types/OverridableStringUnion.d.ts +2 -0
- package/dist/types/OverridableStringUnion.js +2 -0
- package/dist/types/PartialBy.d.ts +1 -0
- package/dist/types/PartialBy.js +2 -0
- package/dist/types/PickData.d.ts +6 -0
- package/dist/types/PickData.js +2 -0
- package/dist/types/Provider.d.ts +4 -0
- package/dist/types/Provider.js +2 -0
- package/dist/types/RequiredBy.d.ts +1 -0
- package/dist/types/RequiredBy.js +2 -0
- package/dist/types/Result.d.ts +16 -0
- package/dist/types/Result.js +2 -0
- package/dist/types/Timestamp.d.ts +17 -0
- package/dist/types/Timestamp.js +57 -0
- package/dist/types/Transform.d.ts +4 -0
- package/dist/types/Transform.js +2 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.js +30 -0
- package/dist/ui/Accessible.d.ts +5 -0
- package/dist/ui/Accessible.js +15 -0
- package/dist/ui/BlockThemes.d.ts +19 -0
- package/dist/ui/BlockThemes.js +29 -0
- package/dist/ui/ColorMode.d.ts +12 -0
- package/dist/ui/ColorMode.js +49 -0
- package/dist/ui/File.d.ts +43 -0
- package/dist/ui/File.js +55 -0
- package/dist/ui/FileType.d.ts +8 -0
- package/dist/ui/FileType.js +48 -0
- package/dist/ui/ImageSource.d.ts +12 -0
- package/dist/ui/ImageSource.js +48 -0
- package/dist/ui/MimeType.d.ts +28 -0
- package/dist/ui/MimeType.js +110 -0
- package/dist/ui/Placement.d.ts +21 -0
- package/dist/ui/Placement.js +135 -0
- package/dist/ui/Position.d.ts +6 -0
- package/dist/ui/Position.js +42 -0
- package/dist/ui/Selector.d.ts +6 -0
- package/dist/ui/Selector.js +23 -0
- package/dist/ui/SemanticColor.d.ts +8 -0
- package/dist/ui/SemanticColor.js +237 -0
- package/dist/ui/Visual.d.ts +24 -0
- package/dist/ui/Visual.js +66 -0
- package/dist/ui/block-layout/BlockLayout.d.ts +99 -0
- package/dist/ui/block-layout/BlockLayout.js +286 -0
- package/dist/ui/block-layout/index.d.ts +1 -0
- package/dist/ui/block-layout/index.js +17 -0
- package/dist/ui/browser/BlurHasher.d.ts +13 -0
- package/dist/ui/browser/BlurHasher.js +76 -0
- package/dist/ui/browser/Browser.d.ts +107 -0
- package/dist/ui/browser/Browser.js +313 -0
- package/dist/ui/browser/ImageProxy.d.ts +30 -0
- package/dist/ui/browser/ImageProxy.js +132 -0
- package/dist/ui/browser/InputEvent.d.ts +13 -0
- package/dist/ui/browser/InputEvent.js +2 -0
- package/dist/ui/browser/SVGProxy.d.ts +9 -0
- package/dist/ui/browser/SVGProxy.js +59 -0
- package/dist/ui/browser/VideoProxy.d.ts +42 -0
- package/dist/ui/browser/VideoProxy.js +235 -0
- package/dist/ui/browser/index.d.ts +6 -0
- package/dist/ui/browser/index.js +22 -0
- package/dist/ui/fields/Field.d.ts +80 -0
- package/dist/ui/fields/Field.js +298 -0
- package/dist/ui/fields/FieldList.d.ts +80 -0
- package/dist/ui/fields/FieldList.js +421 -0
- package/dist/ui/fields/FieldListValidator.d.ts +9 -0
- package/dist/ui/fields/FieldListValidator.js +37 -0
- package/dist/ui/fields/FieldModel.d.ts +15 -0
- package/dist/ui/fields/FieldModel.js +28 -0
- package/dist/ui/fields/FieldSerializer.d.ts +13 -0
- package/dist/ui/fields/FieldSerializer.js +71 -0
- package/dist/ui/fields/FieldValidator.d.ts +19 -0
- package/dist/ui/fields/FieldValidator.js +98 -0
- package/dist/ui/fields/ObjectField.d.ts +75 -0
- package/dist/ui/fields/ObjectField.js +288 -0
- package/dist/ui/fields/errors.json +44 -0
- package/dist/ui/fields/index.d.ts +7 -0
- package/dist/ui/fields/index.js +23 -0
- package/dist/ui/fields/validators/AssetValidator.d.ts +9 -0
- package/dist/ui/fields/validators/AssetValidator.js +25 -0
- package/dist/ui/fields/validators/DateValidator.d.ts +9 -0
- package/dist/ui/fields/validators/DateValidator.js +41 -0
- package/dist/ui/fields/validators/EnumValidator.d.ts +10 -0
- package/dist/ui/fields/validators/EnumValidator.js +77 -0
- package/dist/ui/fields/validators/GenericValidator.d.ts +6 -0
- package/dist/ui/fields/validators/GenericValidator.js +22 -0
- package/dist/ui/fields/validators/LinkValidator.d.ts +9 -0
- package/dist/ui/fields/validators/LinkValidator.js +146 -0
- package/dist/ui/fields/validators/RichTextValidator.d.ts +6 -0
- package/dist/ui/fields/validators/RichTextValidator.js +35 -0
- package/dist/ui/fields/validators/TextValidator.d.ts +10 -0
- package/dist/ui/fields/validators/TextValidator.js +138 -0
- package/dist/ui/fields/validators/TimestampValidator.d.ts +9 -0
- package/dist/ui/fields/validators/TimestampValidator.js +41 -0
- package/dist/ui/fields/validators/ValidatorHelper.d.ts +23 -0
- package/dist/ui/fields/validators/ValidatorHelper.js +55 -0
- package/dist/ui/fields/validators/index.d.ts +8 -0
- package/dist/ui/fields/validators/index.js +24 -0
- package/dist/ui/geometry/AspectRatio.d.ts +27 -0
- package/dist/ui/geometry/AspectRatio.js +77 -0
- package/dist/ui/geometry/Bounds.d.ts +4 -0
- package/dist/ui/geometry/Bounds.js +11 -0
- package/dist/ui/geometry/Frame.d.ts +3 -0
- package/dist/ui/geometry/Frame.js +2 -0
- package/dist/ui/geometry/Insets.d.ts +14 -0
- package/dist/ui/geometry/Insets.js +14 -0
- package/dist/ui/geometry/PixelSize.d.ts +1 -0
- package/dist/ui/geometry/PixelSize.js +2 -0
- package/dist/ui/geometry/Point.d.ts +7 -0
- package/dist/ui/geometry/Point.js +15 -0
- package/dist/ui/geometry/Rect.d.ts +19 -0
- package/dist/ui/geometry/Rect.js +68 -0
- package/dist/ui/geometry/ScreenSize.d.ts +1 -0
- package/dist/ui/geometry/ScreenSize.js +2 -0
- package/dist/ui/geometry/Size.d.ts +7 -0
- package/dist/ui/geometry/Size.js +9 -0
- package/dist/ui/geometry/index.d.ts +9 -0
- package/dist/ui/geometry/index.js +25 -0
- package/dist/ui/index.d.ts +18 -0
- package/dist/ui/index.js +34 -0
- package/dist/ui/responsive/Breakpoint.d.ts +8 -0
- package/dist/ui/responsive/Breakpoint.js +24 -0
- package/dist/ui/responsive/BreakpointObserver.d.ts +16 -0
- package/dist/ui/responsive/BreakpointObserver.js +104 -0
- package/dist/ui/responsive/Breakpoints.d.ts +5 -0
- package/dist/ui/responsive/Breakpoints.js +15 -0
- package/dist/ui/responsive/ResponsiveValue.d.ts +7 -0
- package/dist/ui/responsive/ResponsiveValue.js +26 -0
- package/dist/ui/responsive/index.d.ts +4 -0
- package/dist/ui/responsive/index.js +20 -0
- package/dist/ui/richtext/LexicalUtils.d.ts +31 -0
- package/dist/ui/richtext/LexicalUtils.js +314 -0
- package/dist/ui/richtext/StyledTextNode.d.ts +33 -0
- package/dist/ui/richtext/StyledTextNode.js +101 -0
- package/dist/ui/richtext/index.d.ts +2 -0
- package/dist/ui/richtext/index.js +18 -0
- package/dist/utils/ArrayUtils.d.ts +17 -0
- package/dist/utils/ArrayUtils.js +66 -0
- package/dist/utils/ByteSize.d.ts +19 -0
- package/dist/utils/ByteSize.js +33 -0
- package/dist/utils/DateUtils.d.ts +15 -0
- package/dist/utils/DateUtils.js +100 -0
- package/dist/utils/Deferral.d.ts +28 -0
- package/dist/utils/Deferral.js +107 -0
- package/dist/utils/Duration.d.ts +7 -0
- package/dist/utils/Duration.js +35 -0
- package/dist/utils/Fn.d.ts +14 -0
- package/dist/utils/Fn.js +52 -0
- package/dist/utils/ObjectUtils.d.ts +89 -0
- package/dist/utils/ObjectUtils.js +159 -0
- package/dist/utils/Random.d.ts +15 -0
- package/dist/utils/Random.js +72 -0
- package/dist/utils/StringUtils.d.ts +10 -0
- package/dist/utils/StringUtils.js +51 -0
- package/dist/utils/UrlUtils.d.ts +22 -0
- package/dist/utils/UrlUtils.js +119 -0
- package/dist/utils/Value.d.ts +23 -0
- package/dist/utils/Value.js +122 -0
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +28 -0
- package/dist/utils/isDefined.d.ts +1 -0
- package/dist/utils/isDefined.js +6 -0
- package/package.json +64 -0
|
@@ -0,0 +1,881 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.PageModel = void 0;
|
|
15
|
+
const app_1 = require("../app");
|
|
16
|
+
const errors_1 = require("../errors");
|
|
17
|
+
const regionalization_1 = require("../regionalization");
|
|
18
|
+
const utils_1 = require("../utils");
|
|
19
|
+
const field_1 = require("./field");
|
|
20
|
+
const Page_1 = require("./Page");
|
|
21
|
+
const PageRoute_1 = require("./PageRoute");
|
|
22
|
+
const Seo_1 = require("./Seo");
|
|
23
|
+
const Site_1 = require("./Site");
|
|
24
|
+
// class
|
|
25
|
+
class PageModel {
|
|
26
|
+
constructor(data) {
|
|
27
|
+
this.data = data;
|
|
28
|
+
}
|
|
29
|
+
get schema() {
|
|
30
|
+
const { data: page } = this;
|
|
31
|
+
const { region } = page;
|
|
32
|
+
const schemas = Site_1.Site.current().regions[region];
|
|
33
|
+
return schemas[page.type];
|
|
34
|
+
}
|
|
35
|
+
get seo() {
|
|
36
|
+
var _a;
|
|
37
|
+
return (_a = this.data.discover) === null || _a === void 0 ? void 0 : _a.seo;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Synchronizes computed properties with the latest `PageModel` data (e.g. updating `url` from route template or name)
|
|
41
|
+
*/
|
|
42
|
+
sync() {
|
|
43
|
+
var _a;
|
|
44
|
+
// update url
|
|
45
|
+
const { data: page } = this;
|
|
46
|
+
page.url = this.computeUrl();
|
|
47
|
+
// update name
|
|
48
|
+
page.name = this.computeName();
|
|
49
|
+
// update preview
|
|
50
|
+
page.preview = (_a = this.computePreview()) !== null && _a !== void 0 ? _a : undefined;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Applies updates *in place* to the underlying `Page.Data`.
|
|
54
|
+
*
|
|
55
|
+
* @param updates - a collection of updates to be applied to this page.
|
|
56
|
+
*/
|
|
57
|
+
update(updates) {
|
|
58
|
+
// apply updates
|
|
59
|
+
updates.forEach(update => {
|
|
60
|
+
switch (update.type) {
|
|
61
|
+
case 'tags':
|
|
62
|
+
this.updateTags(update);
|
|
63
|
+
break;
|
|
64
|
+
case 'block.create':
|
|
65
|
+
this.updateBlockCreate(update);
|
|
66
|
+
break;
|
|
67
|
+
case 'block.delete':
|
|
68
|
+
this.updateBlockDelete(update);
|
|
69
|
+
break;
|
|
70
|
+
case 'section.insert':
|
|
71
|
+
this.updateSectionInsert(update);
|
|
72
|
+
break;
|
|
73
|
+
case 'section.delete':
|
|
74
|
+
this.updateSectionDelete(update);
|
|
75
|
+
break;
|
|
76
|
+
case 'section.reorder':
|
|
77
|
+
this.updateSectionReorder(update);
|
|
78
|
+
break;
|
|
79
|
+
case 'section.blockName':
|
|
80
|
+
this.updateSectionBlockName(update);
|
|
81
|
+
break;
|
|
82
|
+
case 'object.insert':
|
|
83
|
+
this.updateObjectInsert(update);
|
|
84
|
+
break;
|
|
85
|
+
case 'array.insert':
|
|
86
|
+
this.updateArrayInsert(update);
|
|
87
|
+
break;
|
|
88
|
+
case 'array.delete':
|
|
89
|
+
this.updateArrayDelete(update);
|
|
90
|
+
break;
|
|
91
|
+
case 'array.reorder':
|
|
92
|
+
this.updateArrayReorder(update);
|
|
93
|
+
break;
|
|
94
|
+
case 'value':
|
|
95
|
+
this.updateValue(update);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
// finally, sync the model
|
|
100
|
+
this.sync();
|
|
101
|
+
}
|
|
102
|
+
updateTags(update) {
|
|
103
|
+
// replace slug
|
|
104
|
+
const { data: page } = this;
|
|
105
|
+
page.tags = update.tags;
|
|
106
|
+
}
|
|
107
|
+
updateBlockCreate(update) {
|
|
108
|
+
var _a;
|
|
109
|
+
// resolve target
|
|
110
|
+
const { data: page } = this;
|
|
111
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
112
|
+
const root = ((_a = page[area]) !== null && _a !== void 0 ? _a : {});
|
|
113
|
+
// fail if there isn't a single key
|
|
114
|
+
if (path.length !== 1) {
|
|
115
|
+
console.error(`[PageChanges/updateBlockCreate] Invalid block path "${path.join(',')}"`);
|
|
116
|
+
throw new errors_1.ArgumentError(`Block path is invalid: [${path.join(',')}]`);
|
|
117
|
+
}
|
|
118
|
+
// skip if page has an entry already at the path
|
|
119
|
+
const [key] = path;
|
|
120
|
+
if (key in root) {
|
|
121
|
+
console.warn(`[PageChanges/updateBlockCreate] Block already exists in "${area}" for key "${key}"`);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
// or add the block
|
|
125
|
+
else {
|
|
126
|
+
console.debug(`[PageChanges/updateBlockCreate] added Block to "${area}" at "${key}"`, update.block);
|
|
127
|
+
root[key] = update.block;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
updateBlockDelete(update) {
|
|
131
|
+
var _a;
|
|
132
|
+
// resolve target
|
|
133
|
+
const { data: page } = this;
|
|
134
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
135
|
+
const root = ((_a = page[area]) !== null && _a !== void 0 ? _a : {});
|
|
136
|
+
// fail if there isn't a single key
|
|
137
|
+
if (path.length !== 1) {
|
|
138
|
+
console.error(`[PageChanges/updateBlockDelete] Invalid block path "${path.join(',')}"`);
|
|
139
|
+
throw new errors_1.ArgumentError(`Block path is invalid: [${path.join(',')}]`);
|
|
140
|
+
}
|
|
141
|
+
// skip if page has no entry at the path (already deleted?)
|
|
142
|
+
const [key] = path;
|
|
143
|
+
if (!(key in root)) {
|
|
144
|
+
console.warn(`[PageChanges/updateBlockDelete] Block no longer exists in "${area}" for key "${key}"`, root);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
// or delete the block
|
|
148
|
+
else {
|
|
149
|
+
console.debug(`[PageChanges/updateBlockDelete] deleted Block from "${area}" at "${key}"`);
|
|
150
|
+
delete root[key];
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
updateSectionInsert(_a) {
|
|
154
|
+
var { block, index } = _a, update = __rest(_a, ["block", "index"]);
|
|
155
|
+
// resolve target
|
|
156
|
+
const { data: page } = this;
|
|
157
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
158
|
+
// blow up if not targeting page content
|
|
159
|
+
if (area === 'discover' || area === 'preview') {
|
|
160
|
+
console.error(`[PageChanges/updateSectionInsert] invalid target for Section: "${area}"`);
|
|
161
|
+
throw new errors_1.ArgumentError(`Section can only be inserted in "content", not "${area}"`);
|
|
162
|
+
}
|
|
163
|
+
// blow up if path isn't a single item
|
|
164
|
+
if (path.length !== 1) {
|
|
165
|
+
console.error(`[PageChanges/updateSectionInsert] invalid path for Section "${path.join('.')}"`);
|
|
166
|
+
throw new errors_1.ArgumentError(`Invalid Section path "${path.join('.')}"`);
|
|
167
|
+
}
|
|
168
|
+
// add section if it doesn't exist
|
|
169
|
+
const [sectionKey] = path;
|
|
170
|
+
const section = page.content[sectionKey];
|
|
171
|
+
if (!section) {
|
|
172
|
+
page.content[sectionKey] = Object.assign(Object.assign({}, update.section), { blocks: [block] });
|
|
173
|
+
}
|
|
174
|
+
// or blow up if section isn't a section
|
|
175
|
+
else if (section.type !== 'section') {
|
|
176
|
+
console.error(`[PageChanges/updateSectionInsert] expected Section but found other type at "${path.join('.')}"`);
|
|
177
|
+
throw new errors_1.IllegalStateError(`Found non-Section at path "${path.join('.')}"`);
|
|
178
|
+
}
|
|
179
|
+
// or fail if block is already in section
|
|
180
|
+
else if (section.blocks.some(sectionBlock => sectionBlock.section.id === block.section.id)) {
|
|
181
|
+
console.warn(`[PageChanges/updateSectionInsert] SectionBlock is already in list at "${path.join('.')}" - ignoring`);
|
|
182
|
+
}
|
|
183
|
+
// or add to end of section if out-of-bounds
|
|
184
|
+
else if (index < 0 || index > section.blocks.length) {
|
|
185
|
+
console.debug(`[PageChanges/updateSectionInsert] item "${block.section.id}" index "${index}" is out of bounds (0, ${section.blocks.length} at "${path.join('.')}" - adding to end:`, block);
|
|
186
|
+
section.blocks.push(block);
|
|
187
|
+
}
|
|
188
|
+
// or insert into section
|
|
189
|
+
else {
|
|
190
|
+
console.debug(`[PageChanges/updateSectionInsert] inserting SectionBlock "${block.section.id}" to "${index}" in list at "${path.join('.')}":`, block);
|
|
191
|
+
section.blocks.splice(index, 0, block);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
updateSectionDelete(_a) {
|
|
195
|
+
var { id } = _a, update = __rest(_a, ["id"]);
|
|
196
|
+
// resolve target
|
|
197
|
+
const { data: page } = this;
|
|
198
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
199
|
+
// blow up if not targeting page content
|
|
200
|
+
if (area === 'discover' || area === 'preview') {
|
|
201
|
+
console.error(`[PageChanges/updateSectionDelete] invalid target for Section: "${area}"`);
|
|
202
|
+
throw new errors_1.ArgumentError(`Section can only be deleted from "content", not "${area}"`);
|
|
203
|
+
}
|
|
204
|
+
// blow up if path isn't a single item
|
|
205
|
+
if (path.length !== 1) {
|
|
206
|
+
console.error(`[PageChanges/updateSectionDelete] invalid path for Section "${path.join('.')}"`);
|
|
207
|
+
throw new errors_1.ArgumentError(`Invalid Section path "${path.join('.')}"`);
|
|
208
|
+
}
|
|
209
|
+
// add section if it doesn't exist
|
|
210
|
+
const [sectionKey] = path;
|
|
211
|
+
const section = page.content[sectionKey];
|
|
212
|
+
if ((section === null || section === void 0 ? void 0 : section.type) !== 'section') {
|
|
213
|
+
console.error(`[PageChanges/updateSectionDelete] encountered non-Section at "${path.join('.')}"`);
|
|
214
|
+
throw new errors_1.IllegalStateError(`Found non-Section at path "${path.join('.')}"`);
|
|
215
|
+
}
|
|
216
|
+
// find section index (skip if it's not there)
|
|
217
|
+
const index = section.blocks.findIndex(block => block.section.id === id);
|
|
218
|
+
if (index < 0) {
|
|
219
|
+
console.warn(`[PageChanges/updateSectionDelete] no SectionBlock with ID "${id}" in list at "${path.join('.')}"`);
|
|
220
|
+
}
|
|
221
|
+
// or splice it out
|
|
222
|
+
else {
|
|
223
|
+
console.warn(`[PageChanges/updateSectionDelete] removed item "${id}" from list at "${path.join('.')}"`);
|
|
224
|
+
section.blocks.splice(index, 1);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
updateSectionReorder(_a) {
|
|
228
|
+
var { ids } = _a, update = __rest(_a, ["ids"]);
|
|
229
|
+
// resolve target
|
|
230
|
+
const { data: page } = this;
|
|
231
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
232
|
+
// blow up if not targeting page content
|
|
233
|
+
if (area === 'discover' || area === 'preview') {
|
|
234
|
+
console.error(`[PageChanges/updateSectionReorder] invalid target for Section: "${area}"`);
|
|
235
|
+
throw new errors_1.ArgumentError(`Section can only be reordered in "content", not "${area}"`);
|
|
236
|
+
}
|
|
237
|
+
// blow up if path isn't a single item
|
|
238
|
+
if (path.length !== 1) {
|
|
239
|
+
console.error(`[PageChanges/updateSectionReorder] invalid path for Section "${path.join('.')}"`);
|
|
240
|
+
throw new errors_1.ArgumentError(`Invalid Section path "${path.join('.')}"`);
|
|
241
|
+
}
|
|
242
|
+
// add section if it doesn't exist
|
|
243
|
+
const [sectionKey] = path;
|
|
244
|
+
const section = page.content[sectionKey];
|
|
245
|
+
if ((section === null || section === void 0 ? void 0 : section.type) !== 'section') {
|
|
246
|
+
console.error(`[PageChanges/updateSectionReorder] encountered non-Section at "${path.join('.')}"`);
|
|
247
|
+
throw new errors_1.IllegalStateError(`Found non-Section at path "${path.join('.')}"`);
|
|
248
|
+
}
|
|
249
|
+
// create new array with the correct order - this drops item's that aren't in the intersection
|
|
250
|
+
const reorderedBlocks = [];
|
|
251
|
+
ids.forEach(id => {
|
|
252
|
+
// add Block if it's in the original
|
|
253
|
+
const block = section.blocks.find(block => block.section.id === id);
|
|
254
|
+
if (block) {
|
|
255
|
+
reorderedBlocks.push(block);
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
console.error(`[PageChanges/updateSectionReorder] reordered ${reorderedBlocks.length} SectionBlock items at "${path.join('.')}"`);
|
|
259
|
+
// replace the value
|
|
260
|
+
section.blocks = reorderedBlocks;
|
|
261
|
+
}
|
|
262
|
+
updateSectionBlockName(_a) {
|
|
263
|
+
var { id } = _a, update = __rest(_a, ["id"]);
|
|
264
|
+
// resolve target
|
|
265
|
+
const { data: page } = this;
|
|
266
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
267
|
+
// blow up if not targeting page content
|
|
268
|
+
if (area === 'discover' || area === 'preview') {
|
|
269
|
+
console.error(`[PageChanges/updateSectionBlockName] invalid target for Section: "${area}"`);
|
|
270
|
+
throw new errors_1.ArgumentError(`Section block can only be named from "content", not "${area}"`);
|
|
271
|
+
}
|
|
272
|
+
// blow up if path isn't a single item
|
|
273
|
+
if (path.length !== 1) {
|
|
274
|
+
console.error(`[PageChanges/updateSectionBlockName] invalid path for Section "${path.join('.')}"`);
|
|
275
|
+
throw new errors_1.ArgumentError(`Invalid Section path "${path.join('.')}"`);
|
|
276
|
+
}
|
|
277
|
+
// add section if it doesn't exist
|
|
278
|
+
const [sectionKey] = path;
|
|
279
|
+
const section = page.content[sectionKey];
|
|
280
|
+
if ((section === null || section === void 0 ? void 0 : section.type) !== 'section') {
|
|
281
|
+
console.error(`[PageChanges/updateSectionBlockName] encountered non-Section at "${path.join('.')}"`);
|
|
282
|
+
throw new errors_1.IllegalStateError(`Found non-Section at path "${path.join('.')}"`);
|
|
283
|
+
}
|
|
284
|
+
// find section index (skip if it's not there)
|
|
285
|
+
const index = section.blocks.findIndex(block => block.section.id === id);
|
|
286
|
+
if (index < 0) {
|
|
287
|
+
console.error(`[PageChanges/updateSectionBlockName] no SectionBlock with ID "${id}" in list at "${path.join('.')}"`);
|
|
288
|
+
throw new errors_1.IllegalStateError(`No SectionBlock with ID "${id}" in list at "${path.join('.')}"`);
|
|
289
|
+
}
|
|
290
|
+
// saving user's block name in config
|
|
291
|
+
const config = section.blocks[index].config;
|
|
292
|
+
console.debug(`[PageChanges/updateSectionBlockName] set SectionBlock name to "${update.value}" at "${path.join('.')}"`);
|
|
293
|
+
if (update.value === null) {
|
|
294
|
+
delete config.name;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
config.name = update.value;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
updateObjectInsert(_a) {
|
|
301
|
+
var _b;
|
|
302
|
+
var { value } = _a, update = __rest(_a, ["value"]);
|
|
303
|
+
// resolve target
|
|
304
|
+
const { data: page } = this;
|
|
305
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
306
|
+
const root = ((_b = page[area]) !== null && _b !== void 0 ? _b : {});
|
|
307
|
+
const { parentPath, childKey } = splitPath(path);
|
|
308
|
+
const target = this.find(root, {
|
|
309
|
+
path: parentPath,
|
|
310
|
+
parentPath: [area],
|
|
311
|
+
issues: []
|
|
312
|
+
});
|
|
313
|
+
// fail if there's no target (shouldn't happen)
|
|
314
|
+
if (!target || typeof target !== 'object' || Array.isArray(target)) {
|
|
315
|
+
console.warn(`[PageModel/updateObjectInsert] could not find object parent at path "${path.join('.')}"`);
|
|
316
|
+
}
|
|
317
|
+
// or just add object
|
|
318
|
+
else {
|
|
319
|
+
console.debug(`[PageModel/updateObjectInsert] setting object at "${childKey}"`);
|
|
320
|
+
this.setValue(target, parentPath, childKey, value);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
updateArrayInsert(_a) {
|
|
324
|
+
var _b;
|
|
325
|
+
var { index, id, value } = _a, update = __rest(_a, ["index", "id", "value"]);
|
|
326
|
+
// resolve target
|
|
327
|
+
const { data: page } = this;
|
|
328
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
329
|
+
const root = ((_b = page[area]) !== null && _b !== void 0 ? _b : {});
|
|
330
|
+
let target = this.find(root, {
|
|
331
|
+
path,
|
|
332
|
+
parentPath: [area],
|
|
333
|
+
issues: []
|
|
334
|
+
});
|
|
335
|
+
// simply create the array if it doesn't exist
|
|
336
|
+
if (target === undefined || target === null) {
|
|
337
|
+
// resolve parent
|
|
338
|
+
const { parentPath, childKey } = splitPath(path);
|
|
339
|
+
target = this.find(root, {
|
|
340
|
+
path: parentPath,
|
|
341
|
+
parentPath: [area],
|
|
342
|
+
issues: []
|
|
343
|
+
});
|
|
344
|
+
// fail if item's parent isn't found
|
|
345
|
+
if (!target) {
|
|
346
|
+
console.warn(`[PageChanges/updateArrayInsert] could not find array parent at path "${path.join('.')}"`);
|
|
347
|
+
}
|
|
348
|
+
// or set value
|
|
349
|
+
else {
|
|
350
|
+
this.setValue(target, parentPath, childKey, { type: 'list', value: [value] });
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
// or fail if target isn't an array
|
|
354
|
+
else if (target.type !== 'list') {
|
|
355
|
+
console.warn(`[PageChanges/updateArrayInsert] could not find array at path "${path.join('.')}"`);
|
|
356
|
+
}
|
|
357
|
+
// or fail if item is already in list
|
|
358
|
+
else if (target.value.some(item => item.id === id)) {
|
|
359
|
+
console.warn(`[PageChanges/updateArrayInsert] item is already in list at "${path.join('.')}" - ignoring`);
|
|
360
|
+
}
|
|
361
|
+
// or insert at end if index is out-of-bounds
|
|
362
|
+
else if (index < 0 || target.value.length < index) {
|
|
363
|
+
console.debug(`[PageChanges/updateArrayInsert] item "${id}" index "${index}" is out of bounds (0, ${target.value.length} at "${path.join('.')}" - adding to end:`, value);
|
|
364
|
+
target.value.push(value);
|
|
365
|
+
}
|
|
366
|
+
// or insert item at index
|
|
367
|
+
else {
|
|
368
|
+
console.debug(`[PageChanges/updateArrayInsert] inserting item "${id}" to "${index}" in list at "${path.join('.')}":`, value);
|
|
369
|
+
target.value.splice(index, 0, value);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
updateArrayDelete(_a) {
|
|
373
|
+
var _b;
|
|
374
|
+
var { id } = _a, update = __rest(_a, ["id"]);
|
|
375
|
+
// resolve target
|
|
376
|
+
const { data: page } = this;
|
|
377
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
378
|
+
const root = ((_b = page[area]) !== null && _b !== void 0 ? _b : {});
|
|
379
|
+
const target = this.find(root, {
|
|
380
|
+
path,
|
|
381
|
+
parentPath: [area],
|
|
382
|
+
issues: []
|
|
383
|
+
});
|
|
384
|
+
// skip if target isn't an array
|
|
385
|
+
if ((target === null || target === void 0 ? void 0 : target.type) !== 'list') {
|
|
386
|
+
console.warn(`[PageChanges/updateArrayDelete] could not find array at path "${path.join('.')}"`);
|
|
387
|
+
}
|
|
388
|
+
// or remove target
|
|
389
|
+
else {
|
|
390
|
+
// find target index (fail if it's not there)
|
|
391
|
+
const list = target.value;
|
|
392
|
+
const index = list.findIndex(item => item.id === id);
|
|
393
|
+
if (index < 0) {
|
|
394
|
+
console.warn(`[PageChanges/updateArrayDelete] no item with ID "${id}" in list at "${path.join('.')}"`);
|
|
395
|
+
}
|
|
396
|
+
// or splice it out
|
|
397
|
+
else {
|
|
398
|
+
console.warn(`[PageChanges/updateArrayDelete] removed item "${id}" from list at "${path.join('.')}"`);
|
|
399
|
+
list.splice(index, 1);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
updateArrayReorder(_a) {
|
|
404
|
+
var _b;
|
|
405
|
+
var { ids } = _a, update = __rest(_a, ["ids"]);
|
|
406
|
+
// resolve target
|
|
407
|
+
const { data: page } = this;
|
|
408
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
409
|
+
const root = ((_b = page[area]) !== null && _b !== void 0 ? _b : {});
|
|
410
|
+
const target = this.find(root, {
|
|
411
|
+
path,
|
|
412
|
+
parentPath: [area],
|
|
413
|
+
issues: []
|
|
414
|
+
});
|
|
415
|
+
// fail if target isn't an array
|
|
416
|
+
if ((target === null || target === void 0 ? void 0 : target.type) !== 'list') {
|
|
417
|
+
console.warn(`[PageChanges/updateArrayReorder] could not find array at path "${path.join('.')}"`);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
// create new array with the correct order - this drops item's that aren't in the intersection
|
|
421
|
+
const updatedValue = [];
|
|
422
|
+
ids.forEach(id => {
|
|
423
|
+
// add item if it's in the original
|
|
424
|
+
const item = target.value.find(item => item.id === id);
|
|
425
|
+
if (item) {
|
|
426
|
+
updatedValue.push(item);
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
// replace the value
|
|
430
|
+
target.value = updatedValue;
|
|
431
|
+
}
|
|
432
|
+
updateValue(_a) {
|
|
433
|
+
var _b;
|
|
434
|
+
var { value } = _a, update = __rest(_a, ["value"]);
|
|
435
|
+
console.debug(`[PageChanges/updateValue] executing value update`, { update, value });
|
|
436
|
+
// resolve target
|
|
437
|
+
const { data: page } = this;
|
|
438
|
+
const { area, path } = PageModel.TargetArea.extract(update.path);
|
|
439
|
+
const root = ((_b = page[area]) !== null && _b !== void 0 ? _b : {});
|
|
440
|
+
const { parentPath, childKey } = splitPath(path);
|
|
441
|
+
const target = this.find(root, {
|
|
442
|
+
path: parentPath,
|
|
443
|
+
parentPath: [area],
|
|
444
|
+
issues: []
|
|
445
|
+
});
|
|
446
|
+
// skip if target can't be resolved (track issue)
|
|
447
|
+
if (!target) {
|
|
448
|
+
// TODO: track issue
|
|
449
|
+
console.warn(`[PageChanges/applyValueChange] no target to update`);
|
|
450
|
+
// stop processing
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
// set value
|
|
454
|
+
this.setValue(target, parentPath, childKey, value);
|
|
455
|
+
console.warn(`[PageChanges/updateValue] updated value for "${path.join('.')}" to:`, value);
|
|
456
|
+
}
|
|
457
|
+
setValue(target, parentPath, key, data) {
|
|
458
|
+
// update list value
|
|
459
|
+
if (target.type === 'list') {
|
|
460
|
+
// add back item if it's gone
|
|
461
|
+
const items = target.value;
|
|
462
|
+
const itemIndex = target.value.findIndex(item => item.id === key);
|
|
463
|
+
if (itemIndex < 0) {
|
|
464
|
+
console.warn(`[PageChanges/setValue] adding back missing item "${key}"`, data);
|
|
465
|
+
items.push(data);
|
|
466
|
+
}
|
|
467
|
+
// or pave over value
|
|
468
|
+
else {
|
|
469
|
+
console.debug(`[PageChanges/setValue] updating ListField at "${key}" to:`, data);
|
|
470
|
+
items[itemIndex] = data;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// or update object value
|
|
474
|
+
else if (target.type === 'object') {
|
|
475
|
+
console.debug(`[PageChanges/setValue] updating ObjectField at "${key}" to:`, data);
|
|
476
|
+
// delete entry if there's no data
|
|
477
|
+
if (data === null || data === undefined) {
|
|
478
|
+
console.debug(`[PageChanges/setValue] deleting ObjectField at "${key}"`);
|
|
479
|
+
delete target.value[key];
|
|
480
|
+
}
|
|
481
|
+
// or pave over if entry
|
|
482
|
+
else {
|
|
483
|
+
console.debug(`[PageChanges/setValue] setting ObjectField at "${key}" to:`, data);
|
|
484
|
+
const values = target.value;
|
|
485
|
+
values[key] = data;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
// or update block value
|
|
489
|
+
else if (target.type === 'block') {
|
|
490
|
+
// update config
|
|
491
|
+
const bucket = utils_1.ArrayUtils.last(parentPath);
|
|
492
|
+
if (bucket === 'config') {
|
|
493
|
+
// get config (or create it)
|
|
494
|
+
let config = target.config;
|
|
495
|
+
if (!config) {
|
|
496
|
+
console.debug(`[PageChanges/setValue] creating new config for block at "${parentPath.join('.')}"`);
|
|
497
|
+
config = {};
|
|
498
|
+
target.config = config;
|
|
499
|
+
}
|
|
500
|
+
// delete if there's no value
|
|
501
|
+
if (data === null || data === undefined) {
|
|
502
|
+
console.debug(`[PageChanges/setValue] deleting block config at "${key}"`);
|
|
503
|
+
delete config[key];
|
|
504
|
+
}
|
|
505
|
+
// or update
|
|
506
|
+
else {
|
|
507
|
+
console.debug(`[PageChanges/setValue] updating block config at "${key}" to:`, data);
|
|
508
|
+
config[key] = data;
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
// or update fields
|
|
512
|
+
else if (bucket === 'fields') {
|
|
513
|
+
console.debug(`[PageChanges/setValue] updating block content at "${key}" to:`, data);
|
|
514
|
+
target.fields[key] = data;
|
|
515
|
+
}
|
|
516
|
+
// or raise error
|
|
517
|
+
else {
|
|
518
|
+
console.warn(`[PageChanges/setValue] unrecognized block path at "${parentPath.join('.')}"`);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
// or ignore (this should never happen)
|
|
522
|
+
else {
|
|
523
|
+
console.warn(`[PageChanges/setValue] invalid parent found at path "${key}"`, target);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
findValue(path) {
|
|
527
|
+
var _a;
|
|
528
|
+
// tokenize path
|
|
529
|
+
const { data: page } = this;
|
|
530
|
+
const [areaIdRaw, ...pathComponents] = path.split('.');
|
|
531
|
+
const areaId = areaIdRaw;
|
|
532
|
+
switch (areaId) {
|
|
533
|
+
// handle direct values
|
|
534
|
+
case 'id':
|
|
535
|
+
case 'groupId':
|
|
536
|
+
case 'region':
|
|
537
|
+
case 'brand':
|
|
538
|
+
case 'type':
|
|
539
|
+
case 'slug':
|
|
540
|
+
case 'url':
|
|
541
|
+
case 'language':
|
|
542
|
+
case 'name':
|
|
543
|
+
case 'errors':
|
|
544
|
+
case 'state':
|
|
545
|
+
case 'createdOn':
|
|
546
|
+
case 'updatedOn':
|
|
547
|
+
case 'publishedOn':
|
|
548
|
+
return (_a = page[areaId]) !== null && _a !== void 0 ? _a : undefined;
|
|
549
|
+
// or search in sections
|
|
550
|
+
case 'discover':
|
|
551
|
+
case 'preview':
|
|
552
|
+
case 'content': {
|
|
553
|
+
// fail if there aren't at least 2 more path components (need to reach a section/block value)
|
|
554
|
+
if (pathComponents.length < 2) {
|
|
555
|
+
console.warn(`[PageChanges/findValue] TargetPath "${path}" is too short for resolving a value`);
|
|
556
|
+
return undefined;
|
|
557
|
+
}
|
|
558
|
+
console.debug(`[PageChanges/findValue] resolving TargetPath "${path}"`);
|
|
559
|
+
// helper (pops keys)
|
|
560
|
+
const popComponent = () => pathComponents.splice(0, 1)[0];
|
|
561
|
+
// get area
|
|
562
|
+
const area = page[areaId];
|
|
563
|
+
// keep iterating until path is collapsed
|
|
564
|
+
let target = area[popComponent()];
|
|
565
|
+
while (pathComponents.length > 0) {
|
|
566
|
+
// update
|
|
567
|
+
const key = popComponent();
|
|
568
|
+
switch (target.type) {
|
|
569
|
+
case 'section': {
|
|
570
|
+
// find block (or stop)
|
|
571
|
+
const sectionBlock = target.blocks.find(({ section: { block } }) => block === key);
|
|
572
|
+
if (!sectionBlock) {
|
|
573
|
+
console.warn(`[PageChanges/findValue] no Section entry for key "${key}" in TargetPath ${path}`);
|
|
574
|
+
return undefined;
|
|
575
|
+
}
|
|
576
|
+
// update
|
|
577
|
+
target = sectionBlock;
|
|
578
|
+
break;
|
|
579
|
+
}
|
|
580
|
+
case 'block': {
|
|
581
|
+
// find field data (or stop)
|
|
582
|
+
const field = target.fields[key];
|
|
583
|
+
if (!field) {
|
|
584
|
+
console.warn(`[PageChanges/findValue] no Block entry for key "${key}" in TargetPath ${path}`);
|
|
585
|
+
return undefined;
|
|
586
|
+
}
|
|
587
|
+
// update
|
|
588
|
+
target = field;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
case 'object': {
|
|
592
|
+
// find child data (or stop)
|
|
593
|
+
const field = target.value[key];
|
|
594
|
+
if (!field) {
|
|
595
|
+
console.warn(`[PageChanges/findValue] no ObjectField entry for key "${key}" in TargetPath ${path}`);
|
|
596
|
+
return undefined;
|
|
597
|
+
}
|
|
598
|
+
// update
|
|
599
|
+
target = field;
|
|
600
|
+
break;
|
|
601
|
+
}
|
|
602
|
+
default:
|
|
603
|
+
console.warn(`[PageChanges/findValue] no support for drilling into ${target.type} entry with key ${key} in TargetPath ${path}`);
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
// return underlying value
|
|
608
|
+
console.debug(`[PageChanges/findValue] returning leaf value for ${target.type}`);
|
|
609
|
+
switch (target.type) {
|
|
610
|
+
// handle supported/direct values
|
|
611
|
+
case 'text':
|
|
612
|
+
case 'enum':
|
|
613
|
+
case 'boolean':
|
|
614
|
+
case 'date':
|
|
615
|
+
return target.value;
|
|
616
|
+
default:
|
|
617
|
+
console.warn(`[PageChanges/findValue] no support for ${target.type} leaf value at TargetPath ${path}`);
|
|
618
|
+
return undefined;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
// or fail
|
|
622
|
+
default:
|
|
623
|
+
throw new errors_1.ArgumentError(`No support for TargetPath "${path}" - unsupported root "${areaId}"`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
find(root, context) {
|
|
627
|
+
// skip if there's no path
|
|
628
|
+
const { path, parentPath } = context;
|
|
629
|
+
if (path.length === 0) {
|
|
630
|
+
throw new errors_1.ArgumentError('Cannot resolveTarget of 0 path components');
|
|
631
|
+
}
|
|
632
|
+
console.debug(`[PageChanges/find] resolving content target: ${path.join('.')}`);
|
|
633
|
+
// grab top-level block/section from content
|
|
634
|
+
const [key, ...remainingPath] = path;
|
|
635
|
+
const sectionOrBlock = root[key];
|
|
636
|
+
// ignore if there's no section/block
|
|
637
|
+
if (!sectionOrBlock) {
|
|
638
|
+
console.warn(`[PageChanges/find] no Section/Block for key "${key}"`);
|
|
639
|
+
}
|
|
640
|
+
// or drill into section
|
|
641
|
+
else if (sectionOrBlock.type === 'section') {
|
|
642
|
+
return this.findInSection(sectionOrBlock, Object.assign(Object.assign({}, context), { path: remainingPath, parentPath: [...parentPath, key] }));
|
|
643
|
+
}
|
|
644
|
+
// or drill into block
|
|
645
|
+
else {
|
|
646
|
+
return this.findInBlock(sectionOrBlock, Object.assign(Object.assign({}, context), { path: remainingPath, parentPath: [...parentPath, key] }));
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
findInSection(section, context) {
|
|
650
|
+
// return section if there's no path
|
|
651
|
+
const { path, parentPath } = context;
|
|
652
|
+
if (path.length === 0) {
|
|
653
|
+
console.debug(`[PageChanges/findInSection] returning Section for: ${parentPath.join('.')}`);
|
|
654
|
+
return section;
|
|
655
|
+
}
|
|
656
|
+
// resolve section block (or bail if it's not there)
|
|
657
|
+
const [sectionBlockId, ...remainingPath] = path;
|
|
658
|
+
const sectionBlock = section.blocks.find(sectionBlock => sectionBlock.section.id === sectionBlockId);
|
|
659
|
+
if (!sectionBlock) {
|
|
660
|
+
console.warn(`[PageChanges/findInSection] unable to resolve SectionBlock "${sectionBlockId}" in "${parentPath.join('.')}"`);
|
|
661
|
+
return undefined;
|
|
662
|
+
}
|
|
663
|
+
console.debug(`[PageChanges/findInSection] found Section "${sectionBlockId}" in "${parentPath.join('.')}"`);
|
|
664
|
+
// return section if there are no more components
|
|
665
|
+
if (remainingPath.length === 0) {
|
|
666
|
+
console.debug(`[PageChanges/findInSection] no components - returning SectionBlock at: ${path.join('.')}`);
|
|
667
|
+
return sectionBlock;
|
|
668
|
+
}
|
|
669
|
+
// resolve value
|
|
670
|
+
else {
|
|
671
|
+
console.debug(`[PageChanges/findInSection] drilling into Block for "${remainingPath.join('.')}"`);
|
|
672
|
+
return this.findInBlock(sectionBlock, Object.assign(Object.assign({}, context), { path: remainingPath, parentPath: [...parentPath, sectionBlockId] }));
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
findInBlock(block, context) {
|
|
676
|
+
var _a;
|
|
677
|
+
// return block content if there's no path
|
|
678
|
+
const { path, parentPath } = context;
|
|
679
|
+
if (path.length === 1) {
|
|
680
|
+
console.debug(`[PageChanges/findInBlock] returning Block fields for: ${parentPath.join('.')}`);
|
|
681
|
+
return block;
|
|
682
|
+
}
|
|
683
|
+
// fail if there's not at least 2 keys
|
|
684
|
+
else if (path.length < 2) {
|
|
685
|
+
console.warn(`[PageChanges/findInBlock] invalid path for block in "${block.type}/${parentPath.join('.')}"`);
|
|
686
|
+
return undefined;
|
|
687
|
+
}
|
|
688
|
+
// fail if we can't pull the bucket
|
|
689
|
+
const [bucket, key, ...remainingPath] = path;
|
|
690
|
+
if (bucket !== 'config' && bucket !== 'fields') {
|
|
691
|
+
console.warn(`[PageChanges/findInBlock] unrecognized path component "${bucket}" in "${block.type}/${parentPath.join('.')}"`);
|
|
692
|
+
return undefined;
|
|
693
|
+
}
|
|
694
|
+
// resolve item (or bail if it's not there)
|
|
695
|
+
const blockValue = bucket === 'config'
|
|
696
|
+
? ((_a = block.config) !== null && _a !== void 0 ? _a : {})[key]
|
|
697
|
+
: block.fields[key];
|
|
698
|
+
if (!blockValue) {
|
|
699
|
+
console.warn(`[PageChanges/findInBlock] unable to resolve Block field "${bucket}/${key}" in "${block.type}/${parentPath.join('.')}"`);
|
|
700
|
+
return undefined;
|
|
701
|
+
}
|
|
702
|
+
// return item if there are no more components
|
|
703
|
+
else if (remainingPath.length === 0) {
|
|
704
|
+
console.debug(`[PageChanges/findInBlock] no more components - returning Block value "${bucket}/${key}" at: ${path.join('.')}`);
|
|
705
|
+
return blockValue;
|
|
706
|
+
}
|
|
707
|
+
// resolve value
|
|
708
|
+
else {
|
|
709
|
+
console.debug(`[PageChanges/findInBlock] drilling into Block value for "${bucket}/${key}": ${remainingPath.join('.')}`);
|
|
710
|
+
return this.findInValue(blockValue, Object.assign(Object.assign({}, context), { path: remainingPath, parentPath: [...parentPath, bucket, key] }));
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
findInValue(data, context) {
|
|
714
|
+
// return item if there's no more path components
|
|
715
|
+
const { path, parentPath } = context;
|
|
716
|
+
if (path.length === 0) {
|
|
717
|
+
console.debug(`[PageChanges/findInValue] return leaf value "${parentPath.join('.')}":`, data);
|
|
718
|
+
return data;
|
|
719
|
+
}
|
|
720
|
+
// or return undefined if there's nothing here
|
|
721
|
+
else if (data === undefined || data === null) {
|
|
722
|
+
console.warn(`[PageChanges/findInValue] encountered empty Value while navigating "${path.join('.')}" at "${parentPath.join('.')}"`);
|
|
723
|
+
return data;
|
|
724
|
+
}
|
|
725
|
+
// or recurse into an array
|
|
726
|
+
else if (data.type === 'list') {
|
|
727
|
+
// skip if entry isn't found
|
|
728
|
+
const value = data.value;
|
|
729
|
+
const [itemId, ...remainingPath] = path;
|
|
730
|
+
const item = value.find(item => item.id === itemId);
|
|
731
|
+
if (!item) {
|
|
732
|
+
console.warn(`[PageChanges/findInValue] unable to find array item with ID "${itemId}" at "${parentPath.join('.')}"`);
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
// or recurse
|
|
736
|
+
else {
|
|
737
|
+
console.debug(`[PageChanges/findInValue] drilling into item with ID "${itemId}" at "${remainingPath.join('.')}"`, item);
|
|
738
|
+
return this.findInValue(item, Object.assign(Object.assign({}, context), { path: remainingPath, parentPath: [...parentPath, itemId] }));
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
// or recurse into an object
|
|
742
|
+
else if (data.type === 'object') {
|
|
743
|
+
// skip if there's no value for the key
|
|
744
|
+
const [entryKey, ...remainingPath] = path;
|
|
745
|
+
const entry = data.value[entryKey];
|
|
746
|
+
if (!entry) {
|
|
747
|
+
console.warn(`[PageChanges/findInValue] unable to find object entry for key "${entryKey}" at "${parentPath.join('.')}"`);
|
|
748
|
+
return undefined;
|
|
749
|
+
}
|
|
750
|
+
// or recurse
|
|
751
|
+
else {
|
|
752
|
+
return this.findInValue(entry, Object.assign(Object.assign({}, context), { path: remainingPath, parentPath: [...parentPath, entryKey] }));
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
// or blow up
|
|
756
|
+
else {
|
|
757
|
+
throw new errors_1.IllegalStateError(`Unable to recurse into value at "${parentPath.join('.')}" for type "${data.type}"`);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
computeUrl() {
|
|
761
|
+
// resolve the route
|
|
762
|
+
const { schema, data: page } = this;
|
|
763
|
+
const { region, language } = page;
|
|
764
|
+
const route = regionalization_1.Localized.Maybe.get(schema.route, language);
|
|
765
|
+
// extract params
|
|
766
|
+
const keys = Array.from(PageRoute_1.PageRoute.getParams(route));
|
|
767
|
+
// extract params (if any)
|
|
768
|
+
const params = keys.reduce((params, path) => {
|
|
769
|
+
// find value
|
|
770
|
+
params[path] = String(this.findValue(path));
|
|
771
|
+
// keep reducing
|
|
772
|
+
return params;
|
|
773
|
+
}, {});
|
|
774
|
+
// get page path (doesn't include localization)
|
|
775
|
+
const pagePath = PageRoute_1.PageRoute.toUrl(route, params);
|
|
776
|
+
// use regionalization + locate to create full path
|
|
777
|
+
const { regionalization } = app_1.AppConfig.brandConfig();
|
|
778
|
+
const { targetPath } = regionalization_1.Regionalization.getTargetPath({
|
|
779
|
+
sourceLocale: { region, language },
|
|
780
|
+
pagePath,
|
|
781
|
+
regionalization
|
|
782
|
+
});
|
|
783
|
+
// return full path
|
|
784
|
+
return targetPath || '/';
|
|
785
|
+
}
|
|
786
|
+
computeName() {
|
|
787
|
+
var _a, _b, _c, _d, _e;
|
|
788
|
+
// resolve schema/page
|
|
789
|
+
const { schema, data: page } = this;
|
|
790
|
+
const { discover, slug, content } = page;
|
|
791
|
+
// return fallback if there's no display path
|
|
792
|
+
const displayPath = schema.displayName;
|
|
793
|
+
const fallback = schema.variant === 'static'
|
|
794
|
+
? schema.name
|
|
795
|
+
: ((_d = (_c = (_b = (_a = discover === null || discover === void 0 ? void 0 : discover.seo) === null || _a === void 0 ? void 0 : _a.fields) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.value) === null || _d === void 0 ? void 0 : _d.trim()) || slug || schema.name;
|
|
796
|
+
if (!displayPath) {
|
|
797
|
+
return fallback;
|
|
798
|
+
}
|
|
799
|
+
// try to get the block's field's content (skip if it isn't a block)
|
|
800
|
+
const [blockId, fieldId] = displayPath.split('.');
|
|
801
|
+
const block = (content !== null && content !== void 0 ? content : {})[blockId];
|
|
802
|
+
if (!block || block.type !== 'block') {
|
|
803
|
+
return fallback;
|
|
804
|
+
}
|
|
805
|
+
// get block field value (or use default if there isn't one)
|
|
806
|
+
const field = block.fields[fieldId];
|
|
807
|
+
return (_e = field_1.Field.Data.getText(field)) !== null && _e !== void 0 ? _e : fallback;
|
|
808
|
+
}
|
|
809
|
+
computePreview() {
|
|
810
|
+
// resolve schema/page
|
|
811
|
+
const { schema, data: page } = this;
|
|
812
|
+
const { preview } = schema;
|
|
813
|
+
// resolve block data (if any)
|
|
814
|
+
const blockData = preview
|
|
815
|
+
? page.content[preview]
|
|
816
|
+
: undefined;
|
|
817
|
+
// return data if it's valid
|
|
818
|
+
return (blockData === null || blockData === void 0 ? void 0 : blockData.type) === 'block'
|
|
819
|
+
? blockData
|
|
820
|
+
: undefined;
|
|
821
|
+
}
|
|
822
|
+
static from(data) {
|
|
823
|
+
return new PageModel(data);
|
|
824
|
+
}
|
|
825
|
+
static fromDraft(data) {
|
|
826
|
+
console.debug('PageModel.fromDraft', data);
|
|
827
|
+
const now = Date.now();
|
|
828
|
+
return new PageModel(Object.assign(Object.assign({}, data), { __root: 'page', id: Page_1.Page.Id.draft, discover: {
|
|
829
|
+
seo: {
|
|
830
|
+
id: Seo_1.Seo.id,
|
|
831
|
+
type: Seo_1.Seo.type,
|
|
832
|
+
version: Seo_1.Seo.version,
|
|
833
|
+
config: {},
|
|
834
|
+
fields: {
|
|
835
|
+
title: field_1.TextField.Value.toData(data.name),
|
|
836
|
+
description: field_1.Field.Data.newValue('text'),
|
|
837
|
+
keywords: field_1.Field.Data.newValue('list')
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}, preview: {}, content: {}, files: [], pages: [], collections: [], errors: true, state: 'draft', createdOn: now, updatedOn: now }));
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
exports.PageModel = PageModel;
|
|
844
|
+
// helpers
|
|
845
|
+
(function (PageModel) {
|
|
846
|
+
let TargetArea;
|
|
847
|
+
(function (TargetArea) {
|
|
848
|
+
function extract([area, ...path]) {
|
|
849
|
+
// fail if area is invalid
|
|
850
|
+
if (!filter(area)) {
|
|
851
|
+
throw new errors_1.ArgumentError(`Invalid TargetArea ${area} in path`);
|
|
852
|
+
}
|
|
853
|
+
// return extraction
|
|
854
|
+
return { area, path };
|
|
855
|
+
}
|
|
856
|
+
TargetArea.extract = extract;
|
|
857
|
+
function filter(key) {
|
|
858
|
+
switch (key) {
|
|
859
|
+
case 'discover':
|
|
860
|
+
case 'preview':
|
|
861
|
+
case 'content':
|
|
862
|
+
return true;
|
|
863
|
+
default:
|
|
864
|
+
return false;
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
TargetArea.filter = filter;
|
|
868
|
+
})(TargetArea = PageModel.TargetArea || (PageModel.TargetArea = {}));
|
|
869
|
+
})(PageModel || (exports.PageModel = PageModel = {}));
|
|
870
|
+
function splitPath(path) {
|
|
871
|
+
// fail if there are no path elements
|
|
872
|
+
if (path.length === 0) {
|
|
873
|
+
throw new errors_1.ArgumentError('Path elements must have a list one segment');
|
|
874
|
+
}
|
|
875
|
+
// split
|
|
876
|
+
const childIndex = path.length - 1;
|
|
877
|
+
return {
|
|
878
|
+
parentPath: path.slice(0, childIndex),
|
|
879
|
+
childKey: path[childIndex]
|
|
880
|
+
};
|
|
881
|
+
}
|