@phis/ui 0.6.1 → 0.6.3
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/components/cms/phi-cms-root-layout.js +2 -0
- package/components/controls/phi-mask-picker-control.d.ts +7 -1
- package/components/controls/phi-mask-picker-control.js +18 -16
- package/components/controls/phi-media-picker-control.d.ts +30 -1
- package/components/controls/phi-media-picker-control.js +15 -2
- package/components/controls/phi-media-source-item-tile-control.d.ts +22 -0
- package/components/controls/phi-media-source-item-tile-control.js +65 -0
- package/components/forms/form-field-labels.d.ts +19 -0
- package/components/forms/form-field-labels.js +78 -0
- package/components/forms/form-provider-contract.d.ts +1 -17
- package/components/forms/form-provider-contract.js +4 -18
- package/components/forms/media-asset-field-keys.d.ts +27 -0
- package/components/forms/media-asset-field-keys.js +27 -0
- package/components/forms/phi-form-widget.js +5 -1
- package/components/forms/upload-field-keys.d.ts +27 -0
- package/components/forms/upload-field-keys.js +27 -0
- package/components/forms/upload-form-control.js +11 -5
- package/components/media/asset-controller-requirement.d.ts +9 -0
- package/components/media/asset-controller-requirement.js +42 -0
- package/components/media/label-sets/media-upload.d.ts +10 -0
- package/components/media/label-sets/media-upload.js +85 -0
- package/components/media/label-sets/media.js +31 -135
- package/components/media/media-upload-labels.d.ts +43 -0
- package/components/media/media-upload-labels.js +23 -0
- package/components/media/media-upload-refusals.d.ts +12 -0
- package/components/media/media-upload-refusals.js +28 -0
- package/components/media/media-widget-labels.d.ts +33 -26
- package/components/media/media-widget-labels.js +27 -36
- package/components/media/phi-area-upload-widget.js +3 -4
- package/components/media/phi-asset-inspector-section.d.ts +2 -2
- package/components/media/phi-image-inspector-widget.d.ts +2 -5
- package/components/media/phi-media-picker-binding.d.ts +17 -0
- package/components/media/phi-media-picker-binding.js +199 -4
- package/components/media/phi-media-picker-labels.d.ts +7 -0
- package/components/media/phi-media-picker-labels.js +25 -0
- package/components/media/phi-media-sources.d.ts +69 -0
- package/components/media/phi-media-sources.js +254 -0
- package/components/media/phi-media-upload.d.ts +1 -27
- package/components/media/phi-media-upload.js +4 -48
- package/components/runtime/runtime-controller-materialization.d.ts +5 -4
- package/components/runtime/runtime-controller-materialization.js +5 -4
- package/components/runtime/runtime-module-context.d.ts +5 -1
- package/components/runtime/runtime-module-context.js +4 -1
- package/components/runtime/runtime-module-media-source-client-manifest.d.ts +17 -0
- package/components/runtime/runtime-module-media-source-client-manifest.js +53 -0
- package/components/widgets/client/shared/phi-mask-picker.js +23 -13
- package/components/widgets/client/shared/phi-widget-image-tool-button.d.ts +7 -5
- package/components/widgets/client/shared/phi-widget-image-tool-button.js +11 -7
- package/components/widgets/client/shared/phi-widget-tool-buttons.js +2 -2
- package/components/widgets/config/mask.d.ts +6 -8
- package/components/widgets/config/mask.js +14 -12
- package/components/widgets/label-sets/authoring-tools.js +55 -1
- package/components/widgets/label-sets/history.js +0 -2
- package/components/widgets/label-sets/slot-upload.js +4 -4
- package/components/widgets/label-types/authoring-tools.d.ts +10 -0
- package/components/widgets/label-types/authoring-tools.js +6 -0
- package/components/widgets/label-types/history.d.ts +1 -1
- package/components/widgets/label-types/history.js +0 -1
- package/components/widgets/label-types/mask-picker.d.ts +31 -0
- package/components/widgets/label-types/mask-picker.js +30 -0
- package/components/widgets/label-types/slot-upload.d.ts +2 -2
- package/controls.d.ts +2 -0
- package/controls.js +1 -0
- package/helpers/cms-region-keys.d.ts +1 -1
- package/module-client.d.ts +5 -1
- package/module-projection-client.js +1 -0
- package/next/areas/accounting-client.js +3 -2
- package/next/areas/admin-client.js +3 -2
- package/next/areas/app-client.js +3 -2
- package/next/areas/builder-client.js +3 -2
- package/next/areas/editor-client.js +3 -2
- package/next/areas/public-client.js +3 -2
- package/next/runtime-module-client-boundary.d.ts +3 -1
- package/next/runtime-module-client-boundary.js +3 -2
- package/package.json +7 -2
- package/plugins/runtime-modules/area-module-defaults.js +4 -3
- package/plugins/runtime-modules/asset/controller/definition.d.ts +2 -2
- package/plugins/runtime-modules/asset/controller/runtime.js +2 -2
- package/plugins/runtime-modules/asset/definition.d.ts +3 -2
- package/plugins/runtime-modules/asset/definition.js +11 -3
- package/plugins/runtime-modules/asset/ids.d.ts +8 -0
- package/plugins/runtime-modules/asset/ids.js +8 -0
- package/plugins/runtime-modules/asset/labels.d.ts +4 -0
- package/plugins/runtime-modules/asset/labels.js +94 -0
- package/plugins/runtime-modules/asset/media-asset-form-control.js +32 -7
- package/plugins/runtime-modules/asset/metadata-form.js +27 -18
- package/plugins/runtime-modules/asset/trees/phi-default-builder-media-page-tree.js +14 -11
- package/plugins/runtime-modules/asset/widgets/area-upload/config.d.ts +2 -0
- package/plugins/runtime-modules/asset/widgets/area-upload/config.js +3 -0
- package/plugins/runtime-modules/asset/widgets/area-upload/server.js +3 -3
- package/plugins/runtime-modules/asset/widgets/asset-focal-rect/config.d.ts +2 -0
- package/plugins/runtime-modules/asset/widgets/asset-focal-rect/config.js +3 -0
- package/plugins/runtime-modules/asset/widgets/image-inspector/config.d.ts +2 -0
- package/plugins/runtime-modules/asset/widgets/image-inspector/config.js +3 -0
- package/plugins/runtime-modules/asset/widgets/image-inspector/server.js +2 -2
- package/plugins/runtime-modules/asset/widgets/media-picker/config.d.ts +1 -0
- package/plugins/runtime-modules/asset/widgets/media-picker/config.js +3 -0
- package/plugins/runtime-modules/auth/presets.d.ts +11 -0
- package/plugins/runtime-modules/auth/presets.js +17 -8
- package/plugins/runtime-modules/builder/clients/inspector-config-field.d.ts +1 -4
- package/plugins/runtime-modules/builder/clients/inspector-config-field.js +2 -2
- package/plugins/runtime-modules/builder/clients/inspector-image-field.d.ts +1 -3
- package/plugins/runtime-modules/builder/clients/inspector-image-field.js +4 -5
- package/plugins/runtime-modules/builder/clients/inspector-section-widget.js +3 -8
- package/plugins/runtime-modules/builder/clients/pages-header.js +2 -0
- package/plugins/runtime-modules/builder/clients/pages-workspace.js +4 -4
- package/plugins/runtime-modules/builder/clients/widget-inspector.js +0 -1
- package/plugins/runtime-modules/builder/controller/draft-command-controller.js +2 -2
- package/plugins/runtime-modules/builder/controller/page-controller.d.ts +1 -1
- package/plugins/runtime-modules/builder/controller/page-controller.js +8 -8
- package/plugins/runtime-modules/builder/controller/workspace-controller.js +4 -1
- package/plugins/runtime-modules/builder/inspector-section-widget.js +5 -2
- package/plugins/runtime-modules/builder/module-authoring-catalog.server.js +3 -1
- package/plugins/runtime-modules/builder/navigation-catalog.server.js +3 -0
- package/plugins/runtime-modules/builder/offered-page-catalog.d.ts +1 -1
- package/plugins/runtime-modules/builder/offered-page-catalog.js +8 -3
- package/plugins/runtime-modules/builder/options-providers.js +2 -2
- package/plugins/runtime-modules/builder/page-address-rule.d.ts +7 -0
- package/plugins/runtime-modules/builder/page-address-rule.js +12 -0
- package/plugins/runtime-modules/builder/page-presets.server.js +4 -0
- package/plugins/runtime-modules/builder/persistence.js +6 -7
- package/plugins/runtime-modules/builder/public-route-collisions.d.ts +1 -1
- package/plugins/runtime-modules/builder/public-route-collisions.js +6 -1
- package/plugins/runtime-modules/builder/region-keys.d.ts +10 -0
- package/plugins/runtime-modules/builder/region-keys.js +10 -0
- package/plugins/runtime-modules/builder/runtime-module-sandbox.server.js +8 -1
- package/plugins/runtime-modules/builder/runtime-module-selection.js +5 -5
- package/plugins/runtime-modules/builder/services/runtime-modules-table.js +24 -6
- package/plugins/runtime-modules/builder/signal-endpoints.js +2 -1
- package/plugins/runtime-modules/builder/use-offered-page-catalog.d.ts +2 -2
- package/plugins/runtime-modules/builder/use-offered-page-catalog.js +5 -3
- package/plugins/runtime-modules/builder/widgets/structure-region/plugin.js +19 -12
- package/plugins/runtime-modules/client-manifests/accounting.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/accounting.js +1 -0
- package/plugins/runtime-modules/client-manifests/admin.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/admin.js +1 -0
- package/plugins/runtime-modules/client-manifests/app.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/app.js +1 -0
- package/plugins/runtime-modules/client-manifests/builder.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/builder.js +1 -0
- package/plugins/runtime-modules/client-manifests/common.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/common.js +3 -0
- package/plugins/runtime-modules/client-manifests/editor.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/editor.js +1 -0
- package/plugins/runtime-modules/client-manifests/public.d.ts +1 -0
- package/plugins/runtime-modules/client-manifests/public.js +1 -0
- package/plugins/runtime-modules/contracts.js +61 -0
- package/plugins/runtime-modules/core/client-media-sources.d.ts +5 -0
- package/plugins/runtime-modules/core/client-media-sources.js +6 -0
- package/plugins/runtime-modules/core/messaging/forms.js +2 -15
- package/plugins/runtime-modules/core/messaging/labels.d.ts +0 -12
- package/plugins/runtime-modules/core/messaging/labels.js +0 -24
- package/plugins/runtime-modules/core/widgets/collection-view/asset-binding.js +10 -6
- package/plugins/runtime-modules/core/widgets/collection-view/config.d.ts +1 -0
- package/plugins/runtime-modules/core/widgets/collection-view/config.js +7 -0
- package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.d.ts +8 -2
- package/plugins/runtime-modules/core/widgets/collection-view/image-preview-grid.js +2 -2
- package/plugins/runtime-modules/core/widgets/collection-view/server.d.ts +1 -1
- package/plugins/runtime-modules/core/widgets/collection-view/server.js +14 -2
- package/plugins/runtime-modules/core/widgets/image/authoring.js +1 -1
- package/plugins/runtime-modules/core/widgets/image/editor.d.ts +1 -4
- package/plugins/runtime-modules/core/widgets/image/editor.js +2 -2
- package/plugins/runtime-modules/core/widgets/slot-upload/client.js +2 -3
- package/plugins/runtime-modules/phi-default-site-area-preset-tree.js +4 -25
- package/plugins/runtime-modules/preset-contracts/pub-area.d.ts +1 -1
- package/plugins/runtime-modules/preset-contracts/pub-area.js +0 -1
- package/plugins/runtime-modules/resolver.js +27 -1
- package/plugins/runtime-modules/settings.d.ts +20 -3
- package/plugins/runtime-modules/settings.js +35 -5
- package/plugins/runtime-modules/site-module-client-manifests.d.ts +2 -0
- package/plugins/runtime-modules/site-module-client-manifests.js +2 -0
- package/plugins/runtime-modules/site-modules-client.d.ts +5 -0
- package/plugins/runtime-modules/site-modules-client.js +1 -0
- package/plugins/runtime-modules/theme/brand-theme-model.js +0 -1
- package/plugins/runtime-modules/theme/widgets/brand-controls/client.js +97 -192
- package/plugins/runtime-modules/theme/widgets/brand-controls/plugin.js +6 -2
- package/runtime-client-manifests-accounting.d.ts +1 -1
- package/runtime-client-manifests-accounting.js +1 -1
- package/runtime-client-manifests-admin.d.ts +1 -1
- package/runtime-client-manifests-admin.js +1 -1
- package/runtime-client-manifests-app.d.ts +1 -1
- package/runtime-client-manifests-app.js +1 -1
- package/runtime-client-manifests-builder.d.ts +1 -1
- package/runtime-client-manifests-builder.js +1 -1
- package/runtime-client-manifests-editor.d.ts +1 -1
- package/runtime-client-manifests-editor.js +1 -1
- package/runtime-client-manifests-public.d.ts +2 -1
- package/runtime-client-manifests-public.js +1 -1
- package/runtime-media-source-client.d.ts +3 -0
- package/runtime-media-source-client.js +2 -0
- package/server-helpers/cms-request.js +10 -4
- package/server-helpers/search-index.js +7 -6
- package/server-helpers/site-build-id.d.ts +25 -0
- package/server-helpers/site-build-id.js +27 -0
- package/theme/phi-theme-presets.d.ts +13 -3
- package/theme/phi-theme-presets.js +20 -3
- package/theme/phi-theme-seed-derivation.d.ts +240 -0
- package/theme/phi-theme-seed-derivation.js +126 -0
- package/types/cms-plugins.d.ts +29 -0
- package/types/media-source.d.ts +48 -0
- package/types/media-source.js +1 -0
- package/types/site-config.d.ts +1 -2
- package/types/site-theme.d.ts +0 -6
- package/types.d.ts +1 -0
- package/components/media/asset-controller-routes.d.ts +0 -8
- package/components/media/asset-controller-routes.js +0 -31
- package/helpers/brand-contact.d.ts +0 -14
- package/helpers/brand-contact.js +0 -26
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { type PhisMediaSourceItem, type PhisMediaSourceListInput, type PhisMediaSourcePage } from "@phis/contracts/media-source";
|
|
2
|
+
import type { PhiMediaAssetTile } from "../../types/media";
|
|
3
|
+
import type { PhiMediaUploadLabels } from "./media-upload-labels";
|
|
4
|
+
/**
|
|
5
|
+
* The media sources of this Area, as the Media picker holds them: somewhere other than the Site's library a
|
|
6
|
+
* file can be taken from (`@phis/contracts/media-source`).
|
|
7
|
+
*
|
|
8
|
+
* Two suppliers answer one shape. A Module of the Site's build runs in the browser, so the picker asks it
|
|
9
|
+
* directly and uploads what is chosen like any other file; an Add-on runs on the server, so Core asks it
|
|
10
|
+
* and imports what is chosen. Either way the result of choosing is an ordinary Asset of the Site's Media
|
|
11
|
+
* library, and nothing here ever keeps a reference into a source.
|
|
12
|
+
*/
|
|
13
|
+
/** What the picker's source switch offers: the id it names a source by, and the words for it. */
|
|
14
|
+
export type PhiMediaSourceOption = {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
};
|
|
18
|
+
/** What a Module's file is titled and described after it was uploaded; the Add-on's import does this itself. */
|
|
19
|
+
export type PhiMediaSourceImportMetadata = {
|
|
20
|
+
title: string;
|
|
21
|
+
altText: string | null;
|
|
22
|
+
};
|
|
23
|
+
export type PhiMediaSourceImport = {
|
|
24
|
+
asset: PhiMediaAssetTile;
|
|
25
|
+
/** Present where the picker still has to write title and alt text onto the Asset it just uploaded. */
|
|
26
|
+
metadata: PhiMediaSourceImportMetadata | null;
|
|
27
|
+
};
|
|
28
|
+
export type PhiMediaSource = PhiMediaSourceOption & {
|
|
29
|
+
list(input: PhisMediaSourceListInput & {
|
|
30
|
+
signal: AbortSignal;
|
|
31
|
+
}): Promise<PhisMediaSourcePage>;
|
|
32
|
+
/** Always into the Site Space: an import never goes anywhere else. */
|
|
33
|
+
importItem(input: {
|
|
34
|
+
item: PhisMediaSourceItem;
|
|
35
|
+
folderId: number | null;
|
|
36
|
+
signal: AbortSignal;
|
|
37
|
+
}): Promise<PhiMediaSourceImport>;
|
|
38
|
+
};
|
|
39
|
+
/** A source that answered with a refusal; `code` is the library's or the route's own, when it said one. */
|
|
40
|
+
export declare class PhiMediaSourceError extends Error {
|
|
41
|
+
readonly code: string | null;
|
|
42
|
+
readonly status: number;
|
|
43
|
+
constructor(message: string, code?: string | null, status?: number);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The words for an import that did not work: the upload refusals' where the code is one they have words
|
|
47
|
+
* for, and one generic text for everything else -- a source's own failure included, which the reader can
|
|
48
|
+
* do nothing about and the server has logged.
|
|
49
|
+
*/
|
|
50
|
+
export declare function readPhiMediaSourceImportErrorMessage(error: unknown, refusals: PhiMediaUploadLabels, genericText: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* One page of a source, read field by field whoever supplied it.
|
|
53
|
+
*
|
|
54
|
+
* A thumbnail is loaded by the reader's browser from wherever it points, so an address that is not an
|
|
55
|
+
* absolute `https:` one is a source that does not hold the contract, not an item to leave out.
|
|
56
|
+
*/
|
|
57
|
+
export declare function readPhiMediaSourcePage(value: unknown): PhisMediaSourcePage;
|
|
58
|
+
/** For tests: forgets the one request a page makes. */
|
|
59
|
+
export declare function resetPhiMediaAddonSourcesForTests(): void;
|
|
60
|
+
/**
|
|
61
|
+
* The sources this Area's picker offers: its Modules' (those active in the Area, named in the reader's
|
|
62
|
+
* language by their own `describe`) and the Add-ons' (`GET /api/site/media/sources`).
|
|
63
|
+
*
|
|
64
|
+
* Nothing is asked until `enabled` -- a picker that is open -- and the Add-on request is made once per
|
|
65
|
+
* page. A Module source whose `describe` fails is left out rather than shown nameless.
|
|
66
|
+
*/
|
|
67
|
+
export declare function usePhiMediaSources({ enabled }: {
|
|
68
|
+
enabled: boolean;
|
|
69
|
+
}): readonly PhiMediaSource[];
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useMemo, useState } from "react";
|
|
3
|
+
import { PHIS_MEDIA_SOURCE_PAGE_MAX_ITEMS, } from "@phis/contracts/media-source";
|
|
4
|
+
import { isPhiRecord } from "../../helpers/is-record";
|
|
5
|
+
import { usePhiMediaSourceClientDefinitions, loadPhiMediaSourceClient } from "../runtime/runtime-module-media-source-client-manifest";
|
|
6
|
+
import { usePhiIntlLocale } from "../root/phi-intl-locale";
|
|
7
|
+
import { readPhiMediaUploadRefusalMessage } from "./media-upload-refusals";
|
|
8
|
+
import { normalizePhiImagePreviewTile, readPhiMediaAssetTiles } from "./phi-image-preview-data";
|
|
9
|
+
import { buildPhiMediaRequestHeaders } from "./phi-media-request-headers";
|
|
10
|
+
/** A source that answered with a refusal; `code` is the library's or the route's own, when it said one. */
|
|
11
|
+
export class PhiMediaSourceError extends Error {
|
|
12
|
+
code;
|
|
13
|
+
status;
|
|
14
|
+
constructor(message, code = null, status = 0) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.name = "PhiMediaSourceError";
|
|
17
|
+
this.code = code;
|
|
18
|
+
this.status = status;
|
|
19
|
+
Object.setPrototypeOf(this, PhiMediaSourceError.prototype);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const SOURCES_PATH = "/api/site/media/sources";
|
|
23
|
+
/**
|
|
24
|
+
* The words for an import that did not work: the upload refusals' where the code is one they have words
|
|
25
|
+
* for, and one generic text for everything else -- a source's own failure included, which the reader can
|
|
26
|
+
* do nothing about and the server has logged.
|
|
27
|
+
*/
|
|
28
|
+
export function readPhiMediaSourceImportErrorMessage(error, refusals, genericText) {
|
|
29
|
+
const code = error?.code;
|
|
30
|
+
return readPhiMediaUploadRefusalMessage(code, refusals) ?? genericText;
|
|
31
|
+
}
|
|
32
|
+
function readNullableString(value) {
|
|
33
|
+
return typeof value === "string" ? value : null;
|
|
34
|
+
}
|
|
35
|
+
function readNullableDimension(value) {
|
|
36
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : null;
|
|
37
|
+
}
|
|
38
|
+
function isHttpsAddress(value) {
|
|
39
|
+
try {
|
|
40
|
+
return new URL(value).protocol === "https:";
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* One page of a source, read field by field whoever supplied it.
|
|
48
|
+
*
|
|
49
|
+
* A thumbnail is loaded by the reader's browser from wherever it points, so an address that is not an
|
|
50
|
+
* absolute `https:` one is a source that does not hold the contract, not an item to leave out.
|
|
51
|
+
*/
|
|
52
|
+
export function readPhiMediaSourcePage(value) {
|
|
53
|
+
if (!isPhiRecord(value) || !Array.isArray(value.items)) {
|
|
54
|
+
throw new PhiMediaSourceError("A media source answered no list.");
|
|
55
|
+
}
|
|
56
|
+
if (value.items.length > PHIS_MEDIA_SOURCE_PAGE_MAX_ITEMS) {
|
|
57
|
+
throw new PhiMediaSourceError("A media source answered more items than were asked for.");
|
|
58
|
+
}
|
|
59
|
+
const items = value.items.map((entry) => {
|
|
60
|
+
if (!isPhiRecord(entry) ||
|
|
61
|
+
typeof entry.id !== "string" || !entry.id ||
|
|
62
|
+
typeof entry.kind !== "string" || !entry.kind ||
|
|
63
|
+
typeof entry.title !== "string" ||
|
|
64
|
+
typeof entry.thumbnailUrl !== "string" || !isHttpsAddress(entry.thumbnailUrl)) {
|
|
65
|
+
throw new PhiMediaSourceError("A media source answered an item that holds no contract.");
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
id: entry.id,
|
|
69
|
+
kind: entry.kind,
|
|
70
|
+
title: entry.title,
|
|
71
|
+
thumbnailUrl: entry.thumbnailUrl,
|
|
72
|
+
width: readNullableDimension(entry.width),
|
|
73
|
+
height: readNullableDimension(entry.height),
|
|
74
|
+
credit: readNullableString(entry.credit),
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
const nextCursor = value.nextCursor;
|
|
78
|
+
if (nextCursor != null && typeof nextCursor !== "string") {
|
|
79
|
+
throw new PhiMediaSourceError("A media source answered a cursor that is not text.");
|
|
80
|
+
}
|
|
81
|
+
return { items, nextCursor: nextCursor ?? null };
|
|
82
|
+
}
|
|
83
|
+
async function readErrorResponse(response) {
|
|
84
|
+
const payload = await response.json().catch(() => null);
|
|
85
|
+
throw new PhiMediaSourceError(typeof payload?.message === "string" ? payload.message : `Media source request failed (${response.status}).`, typeof payload?.error === "string" ? payload.error : null, response.status);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Asked once per page lifetime, and only when a picker first opens: most Sites have no Add-on that offers
|
|
89
|
+
* a source, and a page that never opens a picker should not find that out. A refused or failed request is
|
|
90
|
+
* "no Add-on sources", not an error -- somebody who may not manage Media gets the picker they always had.
|
|
91
|
+
*/
|
|
92
|
+
let addonSourceRows = null;
|
|
93
|
+
function loadPhiMediaAddonSourceRows() {
|
|
94
|
+
addonSourceRows ??= (async () => {
|
|
95
|
+
try {
|
|
96
|
+
const response = await fetch(SOURCES_PATH, {
|
|
97
|
+
method: "GET",
|
|
98
|
+
headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
|
|
99
|
+
cache: "no-store",
|
|
100
|
+
credentials: "include",
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok)
|
|
103
|
+
return [];
|
|
104
|
+
const payload = await response.json().catch(() => null);
|
|
105
|
+
if (!Array.isArray(payload?.rows))
|
|
106
|
+
return [];
|
|
107
|
+
return payload.rows.flatMap((row) => isPhiRecord(row) && typeof row.source === "string" && row.source && typeof row.label === "string"
|
|
108
|
+
? [{ source: row.source, label: row.label }]
|
|
109
|
+
: []);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
return [];
|
|
113
|
+
}
|
|
114
|
+
})();
|
|
115
|
+
return addonSourceRows;
|
|
116
|
+
}
|
|
117
|
+
/** For tests: forgets the one request a page makes. */
|
|
118
|
+
export function resetPhiMediaAddonSourcesForTests() {
|
|
119
|
+
addonSourceRows = null;
|
|
120
|
+
}
|
|
121
|
+
function createPhiMediaAddonSource(row) {
|
|
122
|
+
return {
|
|
123
|
+
id: `addon:${row.source}`,
|
|
124
|
+
label: row.label,
|
|
125
|
+
async list({ signal, ...input }) {
|
|
126
|
+
const search = new URLSearchParams({
|
|
127
|
+
source: row.source,
|
|
128
|
+
q: input.query,
|
|
129
|
+
limit: String(input.limit),
|
|
130
|
+
locale: input.locale,
|
|
131
|
+
});
|
|
132
|
+
if (input.cursor)
|
|
133
|
+
search.set("cursor", input.cursor);
|
|
134
|
+
for (const kind of input.kinds ?? [])
|
|
135
|
+
search.append("kind", kind);
|
|
136
|
+
const response = await fetch(`${SOURCES_PATH}/items?${search.toString()}`, {
|
|
137
|
+
method: "GET",
|
|
138
|
+
headers: buildPhiMediaRequestHeaders({ Accept: "application/json" }),
|
|
139
|
+
cache: "no-store",
|
|
140
|
+
credentials: "include",
|
|
141
|
+
signal,
|
|
142
|
+
});
|
|
143
|
+
if (!response.ok)
|
|
144
|
+
return readErrorResponse(response);
|
|
145
|
+
return readPhiMediaSourcePage(await response.json().catch(() => null));
|
|
146
|
+
},
|
|
147
|
+
async importItem({ item, folderId, signal }) {
|
|
148
|
+
const response = await fetch(`${SOURCES_PATH}/import`, {
|
|
149
|
+
method: "POST",
|
|
150
|
+
headers: buildPhiMediaRequestHeaders({
|
|
151
|
+
Accept: "application/json",
|
|
152
|
+
"Content-Type": "application/json",
|
|
153
|
+
}),
|
|
154
|
+
cache: "no-store",
|
|
155
|
+
credentials: "include",
|
|
156
|
+
signal,
|
|
157
|
+
body: JSON.stringify({ source: row.source, itemId: item.id, ...(folderId != null ? { folderId } : {}) }),
|
|
158
|
+
});
|
|
159
|
+
if (!response.ok)
|
|
160
|
+
return readErrorResponse(response);
|
|
161
|
+
const payload = await response.json().catch(() => null);
|
|
162
|
+
// The Asset exactly as the Media listing serialises a tile, read the way the listing is read.
|
|
163
|
+
const [asset] = readPhiMediaAssetTiles(payload?.asset == null ? [] : [payload.asset]);
|
|
164
|
+
if (!asset)
|
|
165
|
+
throw new PhiMediaSourceError("The import answered no Asset.");
|
|
166
|
+
return { asset, metadata: null };
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
function createPhiMediaModuleSource(key, label, client) {
|
|
171
|
+
return {
|
|
172
|
+
id: `module:${key}`,
|
|
173
|
+
label,
|
|
174
|
+
async list({ signal, ...input }) {
|
|
175
|
+
return readPhiMediaSourcePage(await client.list({ ...input, signal }));
|
|
176
|
+
},
|
|
177
|
+
async importItem({ item, folderId, signal }) {
|
|
178
|
+
const taken = await client.take({ itemId: item.id, signal });
|
|
179
|
+
const file = new File([taken.file], taken.fileName, { type: taken.file.type });
|
|
180
|
+
/*
|
|
181
|
+
* The picker uploads, through the transport every upload takes: init, bytes, finalize, into the Site
|
|
182
|
+
* Space (no Space named) and the Folder the picker shows. `meta` is a record of where the file came
|
|
183
|
+
* from and nothing reads it to find the file again. The Module never writes an Asset itself.
|
|
184
|
+
*
|
|
185
|
+
* The transport is loaded here and not with the picker: a picker is opened far more often than a
|
|
186
|
+
* Module's source is imported from, and an Add-on's source never needs it.
|
|
187
|
+
*/
|
|
188
|
+
const { runPhiMediaUploadSession } = await import("./media-upload-flow");
|
|
189
|
+
const { asset } = await runPhiMediaUploadSession(file, undefined, {
|
|
190
|
+
folderId,
|
|
191
|
+
spaceAddress: null,
|
|
192
|
+
meta: {
|
|
193
|
+
source: "media-source",
|
|
194
|
+
sourceKey: key,
|
|
195
|
+
itemId: item.id,
|
|
196
|
+
credit: taken.credit ?? item.credit ?? null,
|
|
197
|
+
},
|
|
198
|
+
}, signal);
|
|
199
|
+
return {
|
|
200
|
+
asset: normalizePhiImagePreviewTile(asset, []),
|
|
201
|
+
metadata: { title: taken.title, altText: taken.altText ?? null },
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* The sources this Area's picker offers: its Modules' (those active in the Area, named in the reader's
|
|
208
|
+
* language by their own `describe`) and the Add-ons' (`GET /api/site/media/sources`).
|
|
209
|
+
*
|
|
210
|
+
* Nothing is asked until `enabled` -- a picker that is open -- and the Add-on request is made once per
|
|
211
|
+
* page. A Module source whose `describe` fails is left out rather than shown nameless.
|
|
212
|
+
*/
|
|
213
|
+
export function usePhiMediaSources({ enabled }) {
|
|
214
|
+
const definitions = usePhiMediaSourceClientDefinitions();
|
|
215
|
+
const locale = usePhiIntlLocale();
|
|
216
|
+
const [addonSources, setAddonSources] = useState([]);
|
|
217
|
+
const [moduleSources, setModuleSources] = useState([]);
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
if (!enabled)
|
|
220
|
+
return;
|
|
221
|
+
let current = true;
|
|
222
|
+
void loadPhiMediaAddonSourceRows().then((rows) => {
|
|
223
|
+
if (current)
|
|
224
|
+
setAddonSources(rows.map(createPhiMediaAddonSource));
|
|
225
|
+
});
|
|
226
|
+
return () => { current = false; };
|
|
227
|
+
}, [enabled]);
|
|
228
|
+
useEffect(() => {
|
|
229
|
+
if (!enabled || definitions.length === 0)
|
|
230
|
+
return;
|
|
231
|
+
let current = true;
|
|
232
|
+
void Promise.all(definitions.map(async (definition) => {
|
|
233
|
+
try {
|
|
234
|
+
const client = await loadPhiMediaSourceClient(definition);
|
|
235
|
+
const { label } = await client.describe({ locale });
|
|
236
|
+
return typeof label === "string" && label.trim()
|
|
237
|
+
? createPhiMediaModuleSource(definition.key, label, client)
|
|
238
|
+
: null;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.error(`Media source "${definition.key}" could not be described.`, error);
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
})).then((sources) => {
|
|
245
|
+
if (current)
|
|
246
|
+
setModuleSources(sources.filter((source) => source != null));
|
|
247
|
+
});
|
|
248
|
+
return () => { current = false; };
|
|
249
|
+
}, [definitions, enabled, locale]);
|
|
250
|
+
return useMemo(() => {
|
|
251
|
+
const offered = new Set(definitions.map((definition) => `module:${definition.key}`));
|
|
252
|
+
return [...moduleSources.filter((source) => offered.has(source.id)), ...addonSources];
|
|
253
|
+
}, [addonSources, definitions, moduleSources]);
|
|
254
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { PhiMediaKindValue } from "../../types/media";
|
|
2
2
|
import type { PhiAreaUploadWidgetLabels } from "./media-widget-labels";
|
|
3
|
+
import type { PhiMediaUploadLabels } from "./media-upload-labels";
|
|
3
4
|
import { type PhiMediaUploadSessionRunner, type PhiMediaUploadInitOptions } from "./media-upload-flow";
|
|
4
5
|
/**
|
|
5
6
|
* What a surface accepts, stated by the Module that offers it.
|
|
@@ -19,33 +20,6 @@ export type PhiMediaUploadAcceptance = {
|
|
|
19
20
|
maxBytes?: number;
|
|
20
21
|
multiple?: boolean;
|
|
21
22
|
};
|
|
22
|
-
export type PhiMediaUploadLabels = {
|
|
23
|
-
errorGeneric: string;
|
|
24
|
-
errorNetwork: string;
|
|
25
|
-
errorTooLarge: string;
|
|
26
|
-
errorDuplicate: string;
|
|
27
|
-
errorTypeNotAllowed: string;
|
|
28
|
-
errorQuotaExceeded: string;
|
|
29
|
-
errorSpaceUnavailable: string;
|
|
30
|
-
/** The body never reached the storage Provider, or the Provider refused it. */
|
|
31
|
-
errorStorageUnreachable: string;
|
|
32
|
-
/** The Folder the upload was meant for is locked; only an upload that names a Folder can meet it. */
|
|
33
|
-
errorFolderLocked: string;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Text for a surface that has no label set of its own.
|
|
37
|
-
*
|
|
38
|
-
* Not a substitute for one: it exists so a surface without translations still says something an ordinary
|
|
39
|
-
* person can act on, rather than showing whatever string the server happened to send. Leaking a control
|
|
40
|
-
* plane message into an interface is what these replace.
|
|
41
|
-
*/
|
|
42
|
-
export declare const PHI_MEDIA_UPLOAD_DEFAULT_LABELS: PhiMediaUploadLabels;
|
|
43
|
-
/**
|
|
44
|
-
* The wording of every refusal on a Media upload surface that has the Media label set: the Widget's own
|
|
45
|
-
* duplicate, failure and storage texts, and the shared ones for the rest -- so no control plane string
|
|
46
|
-
* reaches a person. The Media folder's upload Widget and an Add-on's slot upload read it the same way.
|
|
47
|
-
*/
|
|
48
|
-
export declare function resolvePhiAreaUploadLabels(labels: PhiAreaUploadWidgetLabels): PhiMediaUploadLabels;
|
|
49
23
|
/** What an item of an upload says of its state: the percentage on its way, "Failed", or "Done". */
|
|
50
24
|
export declare function resolvePhiUploadStatusLabel(item: {
|
|
51
25
|
status: "uploading" | "done" | "error";
|
|
@@ -2,39 +2,7 @@
|
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { PhiMediaKind, resolvePhiMediaKindFromContentType } from "../../constants/media";
|
|
4
4
|
import { PhiMediaUploadError, isPhiMediaUploadCancelled, runPhiMediaUploadSession, } from "./media-upload-flow";
|
|
5
|
-
import {
|
|
6
|
-
/**
|
|
7
|
-
* Text for a surface that has no label set of its own.
|
|
8
|
-
*
|
|
9
|
-
* Not a substitute for one: it exists so a surface without translations still says something an ordinary
|
|
10
|
-
* person can act on, rather than showing whatever string the server happened to send. Leaking a control
|
|
11
|
-
* plane message into an interface is what these replace.
|
|
12
|
-
*/
|
|
13
|
-
export const PHI_MEDIA_UPLOAD_DEFAULT_LABELS = {
|
|
14
|
-
errorGeneric: "The upload did not work.",
|
|
15
|
-
errorNetwork: "The site could not be reached.",
|
|
16
|
-
errorTooLarge: "That file is too large.",
|
|
17
|
-
errorDuplicate: "That file is already here.",
|
|
18
|
-
errorTypeNotAllowed: "That file type is not accepted here.",
|
|
19
|
-
errorQuotaExceeded: "There is no room left in this space.",
|
|
20
|
-
errorSpaceUnavailable: "That space is not available.",
|
|
21
|
-
errorStorageUnreachable: "The file storage could not be reached.",
|
|
22
|
-
errorFolderLocked: "This folder is locked. Nothing can be uploaded into it until it is unlocked.",
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* The wording of every refusal on a Media upload surface that has the Media label set: the Widget's own
|
|
26
|
-
* duplicate, failure and storage texts, and the shared ones for the rest -- so no control plane string
|
|
27
|
-
* reaches a person. The Media folder's upload Widget and an Add-on's slot upload read it the same way.
|
|
28
|
-
*/
|
|
29
|
-
export function resolvePhiAreaUploadLabels(labels) {
|
|
30
|
-
return {
|
|
31
|
-
...PHI_MEDIA_UPLOAD_DEFAULT_LABELS,
|
|
32
|
-
errorGeneric: labels.uploadFailedText,
|
|
33
|
-
errorDuplicate: labels.assetExistsLabel,
|
|
34
|
-
errorStorageUnreachable: labels.uploadStorageUnreachableText,
|
|
35
|
-
errorFolderLocked: labels.uploadFolderLockedText,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
5
|
+
import { readPhiMediaUploadRefusalMessage } from "./media-upload-refusals";
|
|
38
6
|
/** What an item of an upload says of its state: the percentage on its way, "Failed", or "Done". */
|
|
39
7
|
export function resolvePhiUploadStatusLabel(item, labels) {
|
|
40
8
|
if (item.status === "error")
|
|
@@ -109,21 +77,9 @@ export function readPhiMediaUploadErrorMessage(error, labels) {
|
|
|
109
77
|
const code = error instanceof PhiMediaUploadError
|
|
110
78
|
? error.code
|
|
111
79
|
: error?.code;
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
case "content_type_not_allowed": return labels.errorTypeNotAllowed;
|
|
116
|
-
case "media_quota_exceeded": return labels.errorQuotaExceeded;
|
|
117
|
-
case "space_kind_unavailable":
|
|
118
|
-
case "space_forbidden":
|
|
119
|
-
case "space_not_found": return labels.errorSpaceUnavailable;
|
|
120
|
-
// A presigned plan is delivered past the Site: reaching the Site says nothing about reaching the
|
|
121
|
-
// Provider, so this is deliberately not the same reading as a network failure.
|
|
122
|
-
case "storage_unreachable":
|
|
123
|
-
case "storage_rejected": return labels.errorStorageUnreachable;
|
|
124
|
-
case PHI_MEDIA_UPLOAD_FOLDER_LOCKED_CODE: return labels.errorFolderLocked;
|
|
125
|
-
default: break;
|
|
126
|
-
}
|
|
80
|
+
const refusal = readPhiMediaUploadRefusalMessage(code, labels);
|
|
81
|
+
if (refusal)
|
|
82
|
+
return refusal;
|
|
127
83
|
// A TypeError from fetch is the browser saying it never reached the site at all.
|
|
128
84
|
return error instanceof TypeError ? labels.errorNetwork : labels.errorGeneric;
|
|
129
85
|
}
|
|
@@ -38,10 +38,11 @@ export type PhiRuntimeControllerMaterializationOptions = {
|
|
|
38
38
|
/**
|
|
39
39
|
* The configs a Page gives Controllers its Area already runs.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
41
|
+
* A Controller its Module mounts for the whole Area (`controllerMountPolicy: "area"`) is running before
|
|
42
|
+
* any Page is shown, and a Page may be the one that knows what it answers into -- the Theme Page tells
|
|
43
|
+
* the Theme Controller. Mounting a second one for the Page would put two listeners behind one address;
|
|
44
|
+
* instead the Page's config reaches the running one while the Page is shown
|
|
45
|
+
* (`PhiRuntimeControllerConfigOverlays`) and leaves with it.
|
|
45
46
|
*/
|
|
46
47
|
export declare function collectPhiRuntimeControllerConfigOverlays({ tree, ownerMountScope, enclosingSettings, }: Pick<PhiRuntimeControllerMaterializationOptions, "tree" | "ownerMountScope" | "enclosingSettings">): {
|
|
47
48
|
type: `${string}/${string}`;
|
|
@@ -24,10 +24,11 @@ function readTreeControllerSettings(tree, ownerMountScope) {
|
|
|
24
24
|
/**
|
|
25
25
|
* The configs a Page gives Controllers its Area already runs.
|
|
26
26
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
27
|
+
* A Controller its Module mounts for the whole Area (`controllerMountPolicy: "area"`) is running before
|
|
28
|
+
* any Page is shown, and a Page may be the one that knows what it answers into -- the Theme Page tells
|
|
29
|
+
* the Theme Controller. Mounting a second one for the Page would put two listeners behind one address;
|
|
30
|
+
* instead the Page's config reaches the running one while the Page is shown
|
|
31
|
+
* (`PhiRuntimeControllerConfigOverlays`) and leaves with it.
|
|
31
32
|
*/
|
|
32
33
|
export function collectPhiRuntimeControllerConfigOverlays({ tree, ownerMountScope, enclosingSettings, }) {
|
|
33
34
|
const enclosingKeys = new Set((enclosingSettings ?? []).map(buildControllerKey));
|
|
@@ -2,6 +2,7 @@ import { type ReactNode } from "react";
|
|
|
2
2
|
import type { PhiRuntimeModuleDataProviderDescriptor, PhiRuntimeModuleClientWidgetDefinition } from "../../types/cms-plugins";
|
|
3
3
|
import type { PhiRuntimeDataProviderKey } from "../../types/runtime-data-provider";
|
|
4
4
|
import type { PhiCalendarAdapterDescriptor, PhiCalendarAdapterKey } from "../../types/calendar";
|
|
5
|
+
import type { PhiMediaSourceDescriptor, PhiMediaSourceKey } from "../../types/media-source";
|
|
5
6
|
import type { PhiVideoProviderDescriptor, PhiVideoProviderKey } from "../../types/video";
|
|
6
7
|
import type { PhiCollectionItemRendererDescriptor } from "../../types/collection-provider";
|
|
7
8
|
type PhiRuntimeModuleClientState = {
|
|
@@ -11,6 +12,8 @@ type PhiRuntimeModuleClientState = {
|
|
|
11
12
|
widgetDefinitionsByType: ReadonlyMap<string, PhiRuntimeModuleClientWidgetDefinition>;
|
|
12
13
|
dataProviderDescriptorsByKey: ReadonlyMap<PhiRuntimeDataProviderKey, PhiRuntimeModuleDataProviderDescriptor>;
|
|
13
14
|
calendarAdapterDescriptorsByKey: ReadonlyMap<PhiCalendarAdapterKey, PhiCalendarAdapterDescriptor>;
|
|
15
|
+
/** The media sources the Area's active Modules declare; a source whose Module is not active is absent. */
|
|
16
|
+
mediaSourceDescriptorsByKey: ReadonlyMap<PhiMediaSourceKey, PhiMediaSourceDescriptor>;
|
|
14
17
|
/**
|
|
15
18
|
* Where a video may be fetched from, by provider key.
|
|
16
19
|
*
|
|
@@ -29,13 +32,14 @@ type PhiRuntimeModuleClientState = {
|
|
|
29
32
|
*/
|
|
30
33
|
collectionItemRendererKeys: ReadonlySet<string> | null;
|
|
31
34
|
};
|
|
32
|
-
export declare function PhiRuntimeModuleProvider({ moduleIds, widgetTypes, layoutTypes, widgetDefinitions, dataProviderDescriptors, calendarAdapterDescriptors, videoProviderDescriptors, collectionItemRendererDescriptors, children, }: {
|
|
35
|
+
export declare function PhiRuntimeModuleProvider({ moduleIds, widgetTypes, layoutTypes, widgetDefinitions, dataProviderDescriptors, calendarAdapterDescriptors, mediaSourceDescriptors, videoProviderDescriptors, collectionItemRendererDescriptors, children, }: {
|
|
33
36
|
moduleIds: readonly string[];
|
|
34
37
|
widgetTypes: readonly string[];
|
|
35
38
|
layoutTypes: readonly string[];
|
|
36
39
|
widgetDefinitions?: readonly PhiRuntimeModuleClientWidgetDefinition[];
|
|
37
40
|
dataProviderDescriptors?: readonly PhiRuntimeModuleDataProviderDescriptor[];
|
|
38
41
|
calendarAdapterDescriptors?: readonly PhiCalendarAdapterDescriptor[];
|
|
42
|
+
mediaSourceDescriptors?: readonly PhiMediaSourceDescriptor[];
|
|
39
43
|
videoProviderDescriptors?: readonly PhiVideoProviderDescriptor[];
|
|
40
44
|
collectionItemRendererDescriptors?: readonly PhiCollectionItemRendererDescriptor[];
|
|
41
45
|
children: ReactNode;
|
|
@@ -8,11 +8,12 @@ const EMPTY_RUNTIME_MODULE_STATE = {
|
|
|
8
8
|
widgetDefinitionsByType: new Map(),
|
|
9
9
|
dataProviderDescriptorsByKey: new Map(),
|
|
10
10
|
calendarAdapterDescriptorsByKey: new Map(),
|
|
11
|
+
mediaSourceDescriptorsByKey: new Map(),
|
|
11
12
|
videoProviderDescriptorsByKey: new Map(),
|
|
12
13
|
collectionItemRendererKeys: null,
|
|
13
14
|
};
|
|
14
15
|
const PhiRuntimeModuleContext = createContext(EMPTY_RUNTIME_MODULE_STATE);
|
|
15
|
-
export function PhiRuntimeModuleProvider({ moduleIds, widgetTypes, layoutTypes, widgetDefinitions = [], dataProviderDescriptors = [], calendarAdapterDescriptors = [], videoProviderDescriptors = [], collectionItemRendererDescriptors, children, }) {
|
|
16
|
+
export function PhiRuntimeModuleProvider({ moduleIds, widgetTypes, layoutTypes, widgetDefinitions = [], dataProviderDescriptors = [], calendarAdapterDescriptors = [], mediaSourceDescriptors = [], videoProviderDescriptors = [], collectionItemRendererDescriptors, children, }) {
|
|
16
17
|
const state = useMemo(() => ({
|
|
17
18
|
moduleIds: new Set(moduleIds),
|
|
18
19
|
widgetTypes: new Set(widgetTypes),
|
|
@@ -20,6 +21,7 @@ export function PhiRuntimeModuleProvider({ moduleIds, widgetTypes, layoutTypes,
|
|
|
20
21
|
widgetDefinitionsByType: new Map(widgetDefinitions.map((definition) => [definition.type, definition])),
|
|
21
22
|
dataProviderDescriptorsByKey: new Map(dataProviderDescriptors.map((descriptor) => [descriptor.key, descriptor])),
|
|
22
23
|
calendarAdapterDescriptorsByKey: new Map(calendarAdapterDescriptors.map((descriptor) => [descriptor.key, descriptor])),
|
|
24
|
+
mediaSourceDescriptorsByKey: new Map(mediaSourceDescriptors.map((descriptor) => [descriptor.key, descriptor])),
|
|
23
25
|
videoProviderDescriptorsByKey: new Map(videoProviderDescriptors.map((descriptor) => [descriptor.key, descriptor])),
|
|
24
26
|
collectionItemRendererKeys: collectionItemRendererDescriptors
|
|
25
27
|
? new Set(collectionItemRendererDescriptors.map((descriptor) => descriptor.key))
|
|
@@ -29,6 +31,7 @@ export function PhiRuntimeModuleProvider({ moduleIds, widgetTypes, layoutTypes,
|
|
|
29
31
|
collectionItemRendererDescriptors,
|
|
30
32
|
dataProviderDescriptors,
|
|
31
33
|
layoutTypes,
|
|
34
|
+
mediaSourceDescriptors,
|
|
32
35
|
moduleIds,
|
|
33
36
|
videoProviderDescriptors,
|
|
34
37
|
widgetDefinitions,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { PhiMediaSourceClient, PhiMediaSourceClientDefinition, PhiMediaSourceKey } from "../../types/media-source";
|
|
3
|
+
export type PhiRuntimeModuleMediaSourceClientManifest = ReadonlyMap<PhiMediaSourceKey, PhiMediaSourceClientDefinition>;
|
|
4
|
+
export declare function createPhiRuntimeModuleMediaSourceClientManifest(definitions: readonly PhiMediaSourceClientDefinition[]): PhiRuntimeModuleMediaSourceClientManifest;
|
|
5
|
+
export declare function extendPhiRuntimeModuleMediaSourceClientManifest(base: PhiRuntimeModuleMediaSourceClientManifest, definitions: readonly PhiMediaSourceClientDefinition[]): PhiRuntimeModuleMediaSourceClientManifest;
|
|
6
|
+
export declare function PhiRuntimeModuleMediaSourceClientManifestProvider({ manifest, children, }: {
|
|
7
|
+
manifest?: PhiRuntimeModuleMediaSourceClientManifest;
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
/**
|
|
11
|
+
* The media sources this Area offers: those the manifest holds a Client for whose Module declared them
|
|
12
|
+
* and is active here. A source of a Module that is not active is not offered, and a Client without a
|
|
13
|
+
* descriptor of the same owner is a wiring error to name.
|
|
14
|
+
*/
|
|
15
|
+
export declare function usePhiMediaSourceClientDefinitions(): readonly PhiMediaSourceClientDefinition[];
|
|
16
|
+
/** The Client of one definition, loaded once per loader. */
|
|
17
|
+
export declare function loadPhiMediaSourceClient(definition: PhiMediaSourceClientDefinition): Promise<PhiMediaSourceClient>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { usePhiRuntimeModuleState } from "./runtime-module-context";
|
|
5
|
+
import { createPhiRuntimeModuleClientManifestContext, extendPhiRuntimeModuleClientManifest, } from "./runtime-module-client-manifest-context";
|
|
6
|
+
const EMPTY_MEDIA_SOURCE_MANIFEST = new Map();
|
|
7
|
+
const clientPromiseByLoader = new WeakMap();
|
|
8
|
+
/*
|
|
9
|
+
* Not mounted means no media sources, rather than an error: no first-party Module declares one, and a
|
|
10
|
+
* picker in an Area without any looks as it always did.
|
|
11
|
+
*/
|
|
12
|
+
const mediaSourceClientManifest = createPhiRuntimeModuleClientManifestContext("Media source Client manifest is not mounted.");
|
|
13
|
+
export function createPhiRuntimeModuleMediaSourceClientManifest(definitions) {
|
|
14
|
+
return extendPhiRuntimeModuleMediaSourceClientManifest(new Map(), definitions);
|
|
15
|
+
}
|
|
16
|
+
export function extendPhiRuntimeModuleMediaSourceClientManifest(base, definitions) {
|
|
17
|
+
return extendPhiRuntimeModuleClientManifest(base, definitions.map((definition) => [definition.key, definition]), (key) => `Duplicate media source Client loader for "${key}".`);
|
|
18
|
+
}
|
|
19
|
+
export function PhiRuntimeModuleMediaSourceClientManifestProvider({ manifest, children, }) {
|
|
20
|
+
return (_jsx(mediaSourceClientManifest.Provider, { manifest: manifest ?? EMPTY_MEDIA_SOURCE_MANIFEST, children: children }));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The media sources this Area offers: those the manifest holds a Client for whose Module declared them
|
|
24
|
+
* and is active here. A source of a Module that is not active is not offered, and a Client without a
|
|
25
|
+
* descriptor of the same owner is a wiring error to name.
|
|
26
|
+
*/
|
|
27
|
+
export function usePhiMediaSourceClientDefinitions() {
|
|
28
|
+
const manifest = mediaSourceClientManifest.useOptionalManifest() ?? EMPTY_MEDIA_SOURCE_MANIFEST;
|
|
29
|
+
const runtimeModuleState = usePhiRuntimeModuleState();
|
|
30
|
+
return useMemo(() => {
|
|
31
|
+
const offered = [];
|
|
32
|
+
for (const definition of manifest.values()) {
|
|
33
|
+
const descriptor = runtimeModuleState.mediaSourceDescriptorsByKey.get(definition.key);
|
|
34
|
+
if (!descriptor || !runtimeModuleState.moduleIds.has(descriptor.ownerModuleId)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (definition.ownerModuleId !== descriptor.ownerModuleId) {
|
|
38
|
+
throw new Error(`Media source "${definition.key}" has inconsistent Server and Client owners.`);
|
|
39
|
+
}
|
|
40
|
+
offered.push(definition);
|
|
41
|
+
}
|
|
42
|
+
return offered;
|
|
43
|
+
}, [manifest, runtimeModuleState]);
|
|
44
|
+
}
|
|
45
|
+
/** The Client of one definition, loaded once per loader. */
|
|
46
|
+
export function loadPhiMediaSourceClient(definition) {
|
|
47
|
+
let promise = clientPromiseByLoader.get(definition.load);
|
|
48
|
+
if (!promise) {
|
|
49
|
+
promise = definition.load();
|
|
50
|
+
clientPromiseByLoader.set(definition.load, promise);
|
|
51
|
+
}
|
|
52
|
+
return promise;
|
|
53
|
+
}
|