@webiny/website-builder-sdk 6.6.0-alpha.1 → 6.6.0-alpha.11
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/BindingsResolver.d.ts +4 -1
- package/BindingsResolver.js.map +1 -1
- package/ComponentInputTraverser.js +1 -0
- package/ComponentInputTraverser.js.map +1 -1
- package/ComponentManifestToAstConverter.d.ts +23 -1
- package/ComponentManifestToAstConverter.js +122 -2
- package/ComponentManifestToAstConverter.js.map +1 -1
- package/ComponentRegistry.d.ts +2 -1
- package/ComponentRegistry.js +7 -0
- package/ComponentRegistry.js.map +1 -1
- package/ComponentResolver.d.ts +6 -3
- package/ComponentResolver.js +9 -4
- package/ComponentResolver.js.map +1 -1
- package/ConstraintEvaluator.d.ts +5 -0
- package/ConstraintEvaluator.js +20 -4
- package/ConstraintEvaluator.js.map +1 -1
- package/ConstraintEvaluator.test.js +137 -0
- package/ConstraintEvaluator.test.js.map +1 -1
- package/ContentSdk.d.ts +64 -2
- package/ContentSdk.js +90 -12
- package/ContentSdk.js.map +1 -1
- package/DocumentStoreManager.d.ts +9 -2
- package/DocumentStoreManager.js +24 -5
- package/DocumentStoreManager.js.map +1 -1
- package/EditingSdk.d.ts +18 -2
- package/EditingSdk.js +30 -5
- package/EditingSdk.js.map +1 -1
- package/ElementBindings.d.ts +28 -0
- package/ElementBindings.js +88 -0
- package/ElementBindings.js.map +1 -0
- package/ElementBindings.test.d.ts +1 -0
- package/ElementBindings.test.js +127 -0
- package/ElementBindings.test.js.map +1 -0
- package/ElementFactory.d.ts +10 -1
- package/ElementFactory.js +38 -7
- package/ElementFactory.js.map +1 -1
- package/ElementFactory.test.js +260 -0
- package/ElementFactory.test.js.map +1 -1
- package/ElementSelection.d.ts +20 -0
- package/ElementSelection.js +32 -0
- package/ElementSelection.js.map +1 -0
- package/ElementSelection.test.d.ts +1 -0
- package/ElementSelection.test.js +73 -0
- package/ElementSelection.test.js.map +1 -0
- package/Environment.d.ts +7 -0
- package/Environment.js +2 -1
- package/Environment.js.map +1 -1
- package/Environment.test.d.ts +1 -0
- package/Environment.test.js +39 -0
- package/Environment.test.js.map +1 -0
- package/GlobalComponentLanguage.d.ts +31 -0
- package/GlobalComponentLanguage.js +37 -0
- package/GlobalComponentLanguage.js.map +1 -0
- package/InheritanceProcessor.test.js +8 -0
- package/InheritanceProcessor.test.js.map +1 -1
- package/InheritedValueResolver.d.ts +6 -0
- package/InheritedValueResolver.js +7 -0
- package/InheritedValueResolver.js.map +1 -1
- package/InputBindingsProcessor.js +6 -2
- package/InputBindingsProcessor.js.map +1 -1
- package/InputRenderer.test.d.ts +1 -0
- package/InputRenderer.test.js +186 -0
- package/InputRenderer.test.js.map +1 -0
- package/InputsBindingsProcessor.test.js +130 -0
- package/InputsBindingsProcessor.test.js.map +1 -1
- package/InputsUpdater.js +1 -0
- package/InputsUpdater.js.map +1 -1
- package/LayoutContentArea.d.ts +68 -0
- package/LayoutContentArea.js +78 -0
- package/LayoutContentArea.js.map +1 -0
- package/LayoutContentArea.test.d.ts +1 -0
- package/LayoutContentArea.test.js +111 -0
- package/LayoutContentArea.test.js.map +1 -0
- package/LiveSdk.d.ts +5 -2
- package/LiveSdk.js +6 -2
- package/LiveSdk.js.map +1 -1
- package/NullSdk.d.ts +2 -1
- package/NullSdk.js +3 -0
- package/NullSdk.js.map +1 -1
- package/PreviewDocument.d.ts +2 -1
- package/PreviewDocument.js +2 -2
- package/PreviewDocument.js.map +1 -1
- package/PreviewSdk.d.ts +5 -2
- package/PreviewSdk.js +6 -2
- package/PreviewSdk.js.map +1 -1
- package/PreviewViewport.d.ts +5 -0
- package/PreviewViewport.js +9 -0
- package/PreviewViewport.js.map +1 -1
- package/PreviewViewport.test.d.ts +1 -0
- package/PreviewViewport.test.js +27 -0
- package/PreviewViewport.test.js.map +1 -0
- package/RadioOptionInputs.test.d.ts +1 -0
- package/RadioOptionInputs.test.js +521 -0
- package/RadioOptionInputs.test.js.map +1 -0
- package/ResizeObserver.js +1 -1
- package/ResizeObserver.js.map +1 -1
- package/StylesUpdater.js +4 -1
- package/StylesUpdater.js.map +1 -1
- package/asset/deliveryUrl.test.js +1 -1
- package/asset/deliveryUrl.test.js.map +1 -1
- package/asset/imageSrcSet.test.js +1 -1
- package/asset/imageSrcSet.test.js.map +1 -1
- package/asset/normalize.d.ts +1 -1
- package/asset/normalize.js +18 -14
- package/asset/normalize.js.map +1 -1
- package/asset/normalize.test.js +15 -8
- package/asset/normalize.test.js.map +1 -1
- package/componentLoader/ComponentLoader.d.ts +16 -0
- package/componentLoader/ComponentLoader.js +0 -0
- package/componentLoader/RegistryOnlyComponentLoader.d.ts +9 -0
- package/componentLoader/RegistryOnlyComponentLoader.js +8 -0
- package/componentLoader/RegistryOnlyComponentLoader.js.map +1 -0
- package/componentLoader/createComponentLoader.d.ts +7 -0
- package/componentLoader/createComponentLoader.js +10 -0
- package/componentLoader/createComponentLoader.js.map +1 -0
- package/componentLoader/defaultComponentLoader.d.ts +7 -0
- package/componentLoader/defaultComponentLoader.js +8 -0
- package/componentLoader/defaultComponentLoader.js.map +1 -0
- package/componentLoader/index.d.ts +3 -0
- package/componentLoader/index.js +3 -0
- package/contentClientState.test.d.ts +1 -0
- package/contentClientState.test.js +404 -0
- package/contentClientState.test.js.map +1 -0
- package/contentEntry/ContentEntryBindingsResolver.d.ts +33 -0
- package/contentEntry/ContentEntryBindingsResolver.js +52 -0
- package/contentEntry/ContentEntryBindingsResolver.js.map +1 -0
- package/contentEntry/ContentEntryCache.d.ts +49 -0
- package/contentEntry/ContentEntryCache.js +51 -0
- package/contentEntry/ContentEntryCache.js.map +1 -0
- package/contentEntry/resolveContentEntry.d.ts +74 -0
- package/contentEntry/resolveContentEntry.js +53 -0
- package/contentEntry/resolveContentEntry.js.map +1 -0
- package/contentEntry/resolveContentEntry.test.d.ts +1 -0
- package/contentEntry/resolveContentEntry.test.js +213 -0
- package/contentEntry/resolveContentEntry.test.js.map +1 -0
- package/createContentClient.d.ts +17 -0
- package/createContentClient.js +16 -0
- package/createContentClient.js.map +1 -0
- package/createContentClient.test.d.ts +1 -0
- package/createContentClient.test.js +165 -0
- package/createContentClient.test.js.map +1 -0
- package/createGlobalElementDocument.d.ts +6 -0
- package/createGlobalElementDocument.js +23 -0
- package/createGlobalElementDocument.js.map +1 -0
- package/createInput.d.ts +10 -2
- package/createInput.js +8 -1
- package/createInput.js.map +1 -1
- package/dataProviders/ApiClient.d.ts +3 -0
- package/dataProviders/ApiClient.js +23 -5
- package/dataProviders/ApiClient.js.map +1 -1
- package/dataProviders/ApiClient.test.d.ts +1 -0
- package/dataProviders/ApiClient.test.js +116 -0
- package/dataProviders/ApiClient.test.js.map +1 -0
- package/dataProviders/DefaultDataProvider.d.ts +2 -1
- package/dataProviders/DefaultDataProvider.js +12 -0
- package/dataProviders/DefaultDataProvider.js.map +1 -1
- package/dataProviders/DefaultDataProvider.test.d.ts +1 -0
- package/dataProviders/DefaultDataProvider.test.js +81 -0
- package/dataProviders/DefaultDataProvider.test.js.map +1 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.d.ts +1 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.js +27 -0
- package/dataProviders/GET_LAYOUT_BY_SLUG.js.map +1 -0
- package/dataProviders/GET_PAGE_BY_ID.d.ts +1 -1
- package/dataProviders/GET_PAGE_BY_ID.js +7 -0
- package/dataProviders/GET_PAGE_BY_ID.js.map +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.d.ts +1 -1
- package/dataProviders/GET_PAGE_BY_PATH.js +7 -0
- package/dataProviders/GET_PAGE_BY_PATH.js.map +1 -1
- package/dataProviders/NullDataProvider.d.ts +2 -1
- package/dataProviders/NullDataProvider.js +3 -0
- package/dataProviders/NullDataProvider.js.map +1 -1
- package/dataProviders/queries.test.d.ts +1 -0
- package/dataProviders/queries.test.js +53 -0
- package/dataProviders/queries.test.js.map +1 -0
- package/experiments/render.d.ts +3 -0
- package/experiments/render.js +1 -1
- package/experiments/render.js.map +1 -1
- package/globalElements.d.ts +43 -0
- package/globalElements.js +79 -0
- package/globalElements.js.map +1 -0
- package/globalElements.test.d.ts +1 -0
- package/globalElements.test.js +343 -0
- package/globalElements.test.js.map +1 -0
- package/headersProvider.d.ts +1 -2
- package/headersProvider.js.map +1 -1
- package/index.d.ts +14 -0
- package/index.js +14 -0
- package/messages.d.ts +3 -0
- package/messages.js +4 -1
- package/messages.js.map +1 -1
- package/package.json +10 -10
- package/radioOptionInputs.d.ts +24 -0
- package/radioOptionInputs.js +26 -0
- package/radioOptionInputs.js.map +1 -0
- package/types.d.ts +159 -7
- package/withGlobalElementDefaults.d.ts +8 -0
- package/withGlobalElementDefaults.js +60 -0
- package/withGlobalElementDefaults.js.map +1 -0
package/types.d.ts
CHANGED
|
@@ -197,6 +197,11 @@ export type ComponentManifest = {
|
|
|
197
197
|
canDelete?: boolean | ComponentConstraint;
|
|
198
198
|
acceptsChildren?: boolean;
|
|
199
199
|
hideFromToolbar?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* A global component has exactly one instance per site, stored outside of pages.
|
|
202
|
+
* The frontend layout decides where it renders, via `<GlobalComponent>`.
|
|
203
|
+
*/
|
|
204
|
+
global?: boolean;
|
|
200
205
|
hideStyleSettings?: string[];
|
|
201
206
|
autoApplyStyles?: boolean;
|
|
202
207
|
applyDefaultStyles?: boolean;
|
|
@@ -233,6 +238,7 @@ export type DocumentElement = {
|
|
|
233
238
|
export type SerializableCSSStyleDeclaration = {
|
|
234
239
|
[K in keyof CssProperties]?: CssProperties[K];
|
|
235
240
|
};
|
|
241
|
+
export type DocumentCache = Record<string, unknown>;
|
|
236
242
|
export type Document = {
|
|
237
243
|
id: string;
|
|
238
244
|
state: DocumentState;
|
|
@@ -242,10 +248,54 @@ export type Document = {
|
|
|
242
248
|
metadata: DocumentMetadata;
|
|
243
249
|
bindings: DocumentBindings;
|
|
244
250
|
elements: ElementMap;
|
|
251
|
+
layout?: PageLayout | null;
|
|
252
|
+
previewPage?: PreviewPage | null;
|
|
253
|
+
__cache?: DocumentCache;
|
|
245
254
|
};
|
|
246
|
-
|
|
255
|
+
/**
|
|
256
|
+
* A page shown inside a layout in the layout editor, in place of its page content placeholder.
|
|
257
|
+
* It's only shown: it's never saved with the layout.
|
|
258
|
+
*/
|
|
259
|
+
export type PreviewPage = Pick<Document, "id" | "properties" | "elements" | "bindings">;
|
|
260
|
+
/**
|
|
261
|
+
* A page layout built in the layout editor: elements placed around one `Webiny/LayoutContent` element
|
|
262
|
+
* (main content), where the page renders its own content, and any `Webiny/NamedContent` areas. Global components are placed in it like on a page, by placement
|
|
263
|
+
* elements: their instances (`$global:{name}`) come with the page. Its bindings may also hold overrides of
|
|
264
|
+
* global components, under their element ids.
|
|
265
|
+
*/
|
|
266
|
+
export type PageLayout = Pick<Document, "elements" | "bindings"> & {
|
|
267
|
+
id: string;
|
|
268
|
+
entryId?: string;
|
|
269
|
+
properties?: Record<string, any>;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Elements and bindings of global components, keyed `$global:{componentName}` (plus anything nested inside).
|
|
273
|
+
* Pages are delivered with the stored global components merged into their own elements and bindings.
|
|
274
|
+
*/
|
|
275
|
+
export type GlobalDocument = Pick<Document, "elements" | "bindings">;
|
|
276
|
+
/**
|
|
277
|
+
* The stored instance of one global component in one language. Each global component is stored as its
|
|
278
|
+
* own record per language.
|
|
279
|
+
*/
|
|
280
|
+
export type GlobalComponentRecord = GlobalDocument & {
|
|
281
|
+
name: string;
|
|
282
|
+
language: string;
|
|
283
|
+
};
|
|
284
|
+
export type PublicPage = Pick<Page, "id" | "version" | "properties" | "bindings" | "elements" | "extensions" | "metadata" | "state" | "layout"> & {
|
|
247
285
|
languagePaths: Record<string, string>;
|
|
248
286
|
};
|
|
287
|
+
/**
|
|
288
|
+
* A layout delivered by slug, for content code renders in it (e.g. a CMS entry): composed like a page with no
|
|
289
|
+
* content of its own. `elements` and `bindings` hold the instances of the global components, in the requested
|
|
290
|
+
* language, and `layout` is the layout itself, whose Main content is where the content goes.
|
|
291
|
+
*/
|
|
292
|
+
export type PublicLayout = Pick<Document, "elements" | "bindings"> & {
|
|
293
|
+
layout: PageLayout;
|
|
294
|
+
};
|
|
295
|
+
export interface GetLayoutParams {
|
|
296
|
+
slug: string;
|
|
297
|
+
language?: string | null;
|
|
298
|
+
}
|
|
249
299
|
export type PublicRedirect = {
|
|
250
300
|
id: string;
|
|
251
301
|
from: string;
|
|
@@ -279,6 +329,7 @@ export type Page = Document & {
|
|
|
279
329
|
path: string;
|
|
280
330
|
language?: string;
|
|
281
331
|
sourcePage?: string;
|
|
332
|
+
layout?: string | null;
|
|
282
333
|
tags: string[];
|
|
283
334
|
seo: {
|
|
284
335
|
title: string;
|
|
@@ -352,6 +403,7 @@ export type EditorViewportData = {
|
|
|
352
403
|
export type PreviewViewportData = {
|
|
353
404
|
boxes: BoxesData;
|
|
354
405
|
viewport: PreviewViewportInfo;
|
|
406
|
+
layout: string[];
|
|
355
407
|
};
|
|
356
408
|
export type ApiOptions = Record<string, any>;
|
|
357
409
|
export type GetPageOptions = ApiOptions;
|
|
@@ -374,6 +426,7 @@ export interface ListPagesResult {
|
|
|
374
426
|
export interface IDataProvider {
|
|
375
427
|
getPageByPath(path: string, options?: GetPageOptions): Promise<PublicPage | null>;
|
|
376
428
|
getPageById(id: string, options?: GetPageOptions): Promise<PublicPage | null>;
|
|
429
|
+
getLayoutBySlug(params: GetLayoutParams): Promise<PublicLayout | null>;
|
|
377
430
|
listPages(options?: ListPagesOptions): Promise<ListPagesResult>;
|
|
378
431
|
getPageExperiment(path: string): Promise<ActiveExperiment | null>;
|
|
379
432
|
getVariantContent(variantId: string): Promise<VariantContent | null>;
|
|
@@ -386,8 +439,27 @@ export interface IEnvironment {
|
|
|
386
439
|
}
|
|
387
440
|
export interface IContentSdk {
|
|
388
441
|
getPage(path: string): Promise<PublicPage | null>;
|
|
442
|
+
getLayout(params: GetLayoutParams): Promise<PublicLayout | null>;
|
|
389
443
|
listPages(options?: ListPagesOptions): Promise<ListPagesResult>;
|
|
390
444
|
}
|
|
445
|
+
/**
|
|
446
|
+
* An input's renderer with settings for it. The settings belong to the named renderer: Webiny passes
|
|
447
|
+
* them to it untouched (`ElementInputRendererProps.settings`) and never reads them itself. `name` is
|
|
448
|
+
* required, so an input factory that spreads the author's input over its default renderer can't end
|
|
449
|
+
* up with settings and no renderer.
|
|
450
|
+
*/
|
|
451
|
+
export type InputRendererConfig = {
|
|
452
|
+
name: string;
|
|
453
|
+
settings?: Record<string, any>;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* The renderer as the editor resolves it (`InputAstNode.renderer`): always an object, `name` is `""`
|
|
457
|
+
* when the input names no renderer, `settings` is `{}` when it has none.
|
|
458
|
+
*/
|
|
459
|
+
export type ResolvedInputRenderer = {
|
|
460
|
+
name: string;
|
|
461
|
+
settings: Record<string, any>;
|
|
462
|
+
};
|
|
391
463
|
export type BaseInput<T = any> = {
|
|
392
464
|
name: string;
|
|
393
465
|
type: string;
|
|
@@ -401,7 +473,11 @@ export type BaseInput<T = any> = {
|
|
|
401
473
|
responsive?: boolean;
|
|
402
474
|
required?: boolean;
|
|
403
475
|
hideFromUi?: boolean;
|
|
404
|
-
|
|
476
|
+
/**
|
|
477
|
+
* The editor's renderer for this input: its name, or `{ name, settings }` to give the renderer
|
|
478
|
+
* settings (e.g. `{ name: "Webiny/Textarea", settings: { maxLength: 54 } }`).
|
|
479
|
+
*/
|
|
480
|
+
renderer?: string | InputRendererConfig;
|
|
405
481
|
list?: boolean;
|
|
406
482
|
translatable?: boolean;
|
|
407
483
|
};
|
|
@@ -446,12 +522,88 @@ export type SelectInput = BaseInput<string> & {
|
|
|
446
522
|
}[];
|
|
447
523
|
showResetAction?: boolean;
|
|
448
524
|
};
|
|
525
|
+
/**
|
|
526
|
+
* A radio option. `image` is a URL or a data URI, for renderers that draw options as pictures.
|
|
527
|
+
* `inputs` are shown while the option is selected. When any option has `inputs`, the radio is
|
|
528
|
+
* stored as an object: `<radio>/value` holds the selected option, and the options' inputs are its
|
|
529
|
+
* other children, merged by name (see `ComponentManifestToAstConverter`).
|
|
530
|
+
*/
|
|
531
|
+
export type RadioOption = {
|
|
532
|
+
value: string;
|
|
533
|
+
label?: string;
|
|
534
|
+
description?: string;
|
|
535
|
+
image?: string;
|
|
536
|
+
inputs?: ComponentInput[];
|
|
537
|
+
};
|
|
449
538
|
export type RadioInput = BaseInput<string> & {
|
|
450
539
|
type: "radio";
|
|
451
|
-
options:
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
540
|
+
options: RadioOption[];
|
|
541
|
+
};
|
|
542
|
+
export interface ContentEntryReference {
|
|
543
|
+
id: string;
|
|
544
|
+
modelId: string;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Query-mode configuration, declared by the component author. The editor then
|
|
548
|
+
* builds a query within these bounds (see `ContentEntryQueryValue`).
|
|
549
|
+
*/
|
|
550
|
+
/**
|
|
551
|
+
* A field the editor may sort by: a bare read-API sort key, or a key paired with
|
|
552
|
+
* a display label shown in the editor.
|
|
553
|
+
*/
|
|
554
|
+
export type ContentEntrySortField = string | {
|
|
555
|
+
field: string;
|
|
556
|
+
label?: string;
|
|
557
|
+
};
|
|
558
|
+
export interface ContentEntryQueryConfig {
|
|
559
|
+
/**
|
|
560
|
+
* Fields the editor may sort by (one at a time). Each `field` is a CMS read-API
|
|
561
|
+
* sort key — value fields as `values_<fieldId>` (e.g. `values_title`), meta
|
|
562
|
+
* fields bare (e.g. `createdOn`). Provide a `label` for a friendlier UI; a bare
|
|
563
|
+
* string uses the key as its label.
|
|
564
|
+
*/
|
|
565
|
+
sort?: {
|
|
566
|
+
fields: ContentEntrySortField[];
|
|
567
|
+
};
|
|
568
|
+
/** Editor-configurable result limit, with an optional default and hard cap. */
|
|
569
|
+
limit?: {
|
|
570
|
+
default?: number;
|
|
571
|
+
max?: number;
|
|
572
|
+
};
|
|
573
|
+
/** Show a free-text search box (matches fullTextSearch-enabled fields). */
|
|
574
|
+
search?: boolean;
|
|
575
|
+
/** Enable "load more" pagination in the rendered component. */
|
|
576
|
+
pagination?: boolean;
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* The value stored for a query-mode input: the editor's chosen query.
|
|
580
|
+
* `modelId` identifies the CMS model so the frontend SDK can resolve the
|
|
581
|
+
* query without component manifests.
|
|
582
|
+
*/
|
|
583
|
+
export interface ContentEntryQueryValue {
|
|
584
|
+
modelId: string;
|
|
585
|
+
sort?: {
|
|
586
|
+
field: string;
|
|
587
|
+
order: "asc" | "desc";
|
|
588
|
+
};
|
|
589
|
+
limit?: number;
|
|
590
|
+
search?: string;
|
|
591
|
+
}
|
|
592
|
+
export type ContentEntryInput = BaseInput<ContentEntryReference | ContentEntryReference[] | ContentEntryQueryValue> & {
|
|
593
|
+
type: "contentEntry";
|
|
594
|
+
/**
|
|
595
|
+
* The content model(s) the editor may pick entries from. Author-fixed.
|
|
596
|
+
*/
|
|
597
|
+
models: string[];
|
|
598
|
+
/**
|
|
599
|
+
* "manual" (default): the editor hand-picks entries (stored as references).
|
|
600
|
+
* "query": the editor configures a dynamic query on the fixed model.
|
|
601
|
+
*/
|
|
602
|
+
mode?: "manual" | "query";
|
|
603
|
+
/**
|
|
604
|
+
* Query-mode configuration. Only used when `mode` is "query".
|
|
605
|
+
*/
|
|
606
|
+
query?: ContentEntryQueryConfig;
|
|
455
607
|
};
|
|
456
608
|
export type ObjectInput = BaseInput<Record<string, any>> & {
|
|
457
609
|
type: "object";
|
|
@@ -461,7 +613,7 @@ export type CustomInput = BaseInput<any> & {
|
|
|
461
613
|
type: string;
|
|
462
614
|
fields: ComponentInput[];
|
|
463
615
|
};
|
|
464
|
-
export type ComponentInput = TextInput | LongTextInput | NumberInput | BooleanInput | ColorInput | FileInput | DateTimeInput | LexicalInput | SelectInput | RadioInput | TagsInput | ObjectInput | SlotInput | CustomInput;
|
|
616
|
+
export type ComponentInput = TextInput | LongTextInput | NumberInput | BooleanInput | ColorInput | FileInput | DateTimeInput | LexicalInput | SelectInput | RadioInput | TagsInput | ObjectInput | SlotInput | ContentEntryInput | CustomInput;
|
|
465
617
|
export type ManifestInputsArray<TInputs, TAllowChildren extends boolean> = TAllowChildren extends true ? {
|
|
466
618
|
[K in Exclude<keyof TInputs, "children">]: InputFactory<K & string>;
|
|
467
619
|
}[Exclude<keyof TInputs, "children">][] : {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ComponentManifest, GlobalDocument } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Add a default instance for every registered global component that has no stored instance,
|
|
4
|
+
* so a global defined in code appears immediately, without a data backfill.
|
|
5
|
+
* The page may still come with bindings for such a global: the layout's and the page's overrides, merged by
|
|
6
|
+
* the backend. They're kept over the defaults.
|
|
7
|
+
*/
|
|
8
|
+
export declare const withGlobalElementDefaults: (globals: GlobalDocument, components: Record<string, ComponentManifest>) => GlobalDocument;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { GlobalElementId } from "./globalElements.js";
|
|
2
|
+
import { createGlobalElementDocument } from "./createGlobalElementDocument.js";
|
|
3
|
+
const withGlobalElementDefaults = (globals, components)=>{
|
|
4
|
+
const missing = Object.values(components).filter((manifest)=>manifest.global && !globals.elements[GlobalElementId.fromName(manifest.name).toString()]);
|
|
5
|
+
if (!missing.length) return globals;
|
|
6
|
+
const result = {
|
|
7
|
+
elements: {
|
|
8
|
+
...globals.elements
|
|
9
|
+
},
|
|
10
|
+
bindings: {
|
|
11
|
+
...globals.bindings
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
for (const manifest of missing){
|
|
15
|
+
const defaults = createGlobalElementDocument(manifest.name, components);
|
|
16
|
+
Object.assign(result.elements, defaults.elements);
|
|
17
|
+
for(const id in defaults.bindings){
|
|
18
|
+
const delivered = globals.bindings[id];
|
|
19
|
+
result.bindings[id] = delivered ? withDefaultBindings(defaults.bindings[id], delivered) : defaults.bindings[id];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
const withDefaultBindings = (defaults, delivered)=>{
|
|
25
|
+
const overrides = {
|
|
26
|
+
...defaults.overrides
|
|
27
|
+
};
|
|
28
|
+
for(const breakpoint in delivered.overrides){
|
|
29
|
+
const base = defaults.overrides?.[breakpoint];
|
|
30
|
+
const value = delivered.overrides[breakpoint];
|
|
31
|
+
overrides[breakpoint] = {
|
|
32
|
+
...base,
|
|
33
|
+
...value,
|
|
34
|
+
inputs: {
|
|
35
|
+
...base?.inputs,
|
|
36
|
+
...value?.inputs
|
|
37
|
+
},
|
|
38
|
+
styles: {
|
|
39
|
+
...base?.styles,
|
|
40
|
+
...value?.styles
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
...defaults,
|
|
46
|
+
...delivered,
|
|
47
|
+
inputs: {
|
|
48
|
+
...defaults.inputs,
|
|
49
|
+
...delivered.inputs
|
|
50
|
+
},
|
|
51
|
+
styles: {
|
|
52
|
+
...defaults.styles,
|
|
53
|
+
...delivered.styles
|
|
54
|
+
},
|
|
55
|
+
overrides
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
export { withGlobalElementDefaults };
|
|
59
|
+
|
|
60
|
+
//# sourceMappingURL=withGlobalElementDefaults.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withGlobalElementDefaults.js","sources":["../src/withGlobalElementDefaults.ts"],"sourcesContent":["import type { ComponentManifest, DocumentElementBindings, GlobalDocument } from \"./types.js\";\nimport { GlobalElementId } from \"./globalElements.js\";\nimport { createGlobalElementDocument } from \"./createGlobalElementDocument.js\";\n\n/**\n * Add a default instance for every registered global component that has no stored instance,\n * so a global defined in code appears immediately, without a data backfill.\n * The page may still come with bindings for such a global: the layout's and the page's overrides, merged by\n * the backend. They're kept over the defaults.\n */\nexport const withGlobalElementDefaults = (\n globals: GlobalDocument,\n components: Record<string, ComponentManifest>\n): GlobalDocument => {\n const missing = Object.values(components).filter(manifest => {\n return (\n manifest.global && !globals.elements[GlobalElementId.fromName(manifest.name).toString()]\n );\n });\n\n if (!missing.length) {\n return globals;\n }\n\n const result: GlobalDocument = {\n elements: { ...globals.elements },\n bindings: { ...globals.bindings }\n };\n\n for (const manifest of missing) {\n const defaults = createGlobalElementDocument(manifest.name, components);\n Object.assign(result.elements, defaults.elements);\n for (const id in defaults.bindings) {\n const delivered = globals.bindings[id];\n result.bindings[id] = delivered\n ? withDefaultBindings(defaults.bindings[id], delivered)\n : defaults.bindings[id];\n }\n }\n\n return result;\n};\n\n/**\n * The defaults are only the bottom layer: what's delivered wins per input and per style, also per\n * breakpoint override, so overriding one input of a global keeps the rest of its defaults.\n */\nconst withDefaultBindings = (\n defaults: DocumentElementBindings,\n delivered: DocumentElementBindings\n): DocumentElementBindings => {\n const overrides: NonNullable<DocumentElementBindings[\"overrides\"]> = {\n ...defaults.overrides\n };\n for (const breakpoint in delivered.overrides) {\n const base = defaults.overrides?.[breakpoint];\n const value = delivered.overrides[breakpoint];\n overrides[breakpoint] = {\n ...base,\n ...value,\n inputs: { ...base?.inputs, ...value?.inputs },\n styles: { ...base?.styles, ...value?.styles }\n };\n }\n\n return {\n ...defaults,\n ...delivered,\n inputs: { ...defaults.inputs, ...delivered.inputs },\n styles: { ...defaults.styles, ...delivered.styles },\n overrides\n };\n};\n"],"names":["withGlobalElementDefaults","globals","components","missing","Object","manifest","GlobalElementId","result","defaults","createGlobalElementDocument","id","delivered","withDefaultBindings","overrides","breakpoint","base","value"],"mappings":";;AAUO,MAAMA,4BAA4B,CACrCC,SACAC;IAEA,MAAMC,UAAUC,OAAO,MAAM,CAACF,YAAY,MAAM,CAACG,CAAAA,WAEzCA,SAAS,MAAM,IAAI,CAACJ,QAAQ,QAAQ,CAACK,gBAAgB,QAAQ,CAACD,SAAS,IAAI,EAAE,QAAQ,GAAG;IAIhG,IAAI,CAACF,QAAQ,MAAM,EACf,OAAOF;IAGX,MAAMM,SAAyB;QAC3B,UAAU;YAAE,GAAGN,QAAQ,QAAQ;QAAC;QAChC,UAAU;YAAE,GAAGA,QAAQ,QAAQ;QAAC;IACpC;IAEA,KAAK,MAAMI,YAAYF,QAAS;QAC5B,MAAMK,WAAWC,4BAA4BJ,SAAS,IAAI,EAAEH;QAC5DE,OAAO,MAAM,CAACG,OAAO,QAAQ,EAAEC,SAAS,QAAQ;QAChD,IAAK,MAAME,MAAMF,SAAS,QAAQ,CAAE;YAChC,MAAMG,YAAYV,QAAQ,QAAQ,CAACS,GAAG;YACtCH,OAAO,QAAQ,CAACG,GAAG,GAAGC,YAChBC,oBAAoBJ,SAAS,QAAQ,CAACE,GAAG,EAAEC,aAC3CH,SAAS,QAAQ,CAACE,GAAG;QAC/B;IACJ;IAEA,OAAOH;AACX;AAMA,MAAMK,sBAAsB,CACxBJ,UACAG;IAEA,MAAME,YAA+D;QACjE,GAAGL,SAAS,SAAS;IACzB;IACA,IAAK,MAAMM,cAAcH,UAAU,SAAS,CAAE;QAC1C,MAAMI,OAAOP,SAAS,SAAS,EAAE,CAACM,WAAW;QAC7C,MAAME,QAAQL,UAAU,SAAS,CAACG,WAAW;QAC7CD,SAAS,CAACC,WAAW,GAAG;YACpB,GAAGC,IAAI;YACP,GAAGC,KAAK;YACR,QAAQ;gBAAE,GAAGD,MAAM,MAAM;gBAAE,GAAGC,OAAO,MAAM;YAAC;YAC5C,QAAQ;gBAAE,GAAGD,MAAM,MAAM;gBAAE,GAAGC,OAAO,MAAM;YAAC;QAChD;IACJ;IAEA,OAAO;QACH,GAAGR,QAAQ;QACX,GAAGG,SAAS;QACZ,QAAQ;YAAE,GAAGH,SAAS,MAAM;YAAE,GAAGG,UAAU,MAAM;QAAC;QAClD,QAAQ;YAAE,GAAGH,SAAS,MAAM;YAAE,GAAGG,UAAU,MAAM;QAAC;QAClDE;IACJ;AACJ"}
|