@anvilkit/plugin-asset-manager 0.1.6 → 0.1.7
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/README.md +26 -18
- package/dist/index.cjs +7 -0
- package/dist/index.d.cts +11 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/plugin.cjs +67 -4
- package/dist/plugin.d.cts +3 -2
- package/dist/plugin.d.cts.map +1 -1
- package/dist/plugin.d.ts +3 -2
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +67 -4
- package/dist/sources/composite-source.cjs +137 -0
- package/dist/sources/composite-source.d.cts +39 -0
- package/dist/sources/composite-source.d.cts.map +1 -0
- package/dist/sources/composite-source.d.ts +39 -0
- package/dist/sources/composite-source.d.ts.map +1 -0
- package/dist/sources/composite-source.js +99 -0
- package/dist/sources/federated-search.cjs +163 -0
- package/dist/sources/federated-search.d.cts +33 -0
- package/dist/sources/federated-search.d.cts.map +1 -0
- package/dist/sources/federated-search.d.ts +33 -0
- package/dist/sources/federated-search.d.ts.map +1 -0
- package/dist/sources/federated-search.js +113 -0
- package/dist/sources/provider.cjs +18 -0
- package/dist/sources/provider.d.cts +51 -0
- package/dist/sources/provider.d.cts.map +1 -0
- package/dist/sources/provider.d.ts +51 -0
- package/dist/sources/provider.d.ts.map +1 -0
- package/dist/sources/provider.js +1 -0
- package/dist/sources/unsplash/client.cjs +189 -0
- package/dist/sources/unsplash/client.d.cts +87 -0
- package/dist/sources/unsplash/client.d.cts.map +1 -0
- package/dist/sources/unsplash/client.d.ts +87 -0
- package/dist/sources/unsplash/client.d.ts.map +1 -0
- package/dist/sources/unsplash/client.js +151 -0
- package/dist/sources/unsplash/index.cjs +192 -0
- package/dist/sources/unsplash/index.d.cts +16 -0
- package/dist/sources/unsplash/index.d.cts.map +1 -0
- package/dist/sources/unsplash/index.d.ts +16 -0
- package/dist/sources/unsplash/index.d.ts.map +1 -0
- package/dist/sources/unsplash/index.js +148 -0
- package/dist/sources/unsplash/themes.cjs +141 -0
- package/dist/sources/unsplash/themes.d.cts +18 -0
- package/dist/sources/unsplash/themes.d.cts.map +1 -0
- package/dist/sources/unsplash/themes.d.ts +18 -0
- package/dist/sources/unsplash/themes.d.ts.map +1 -0
- package/dist/sources/unsplash/themes.js +93 -0
- package/dist/sources/unsplash/throttle-cache.cjs +86 -0
- package/dist/sources/unsplash/throttle-cache.d.cts +25 -0
- package/dist/sources/unsplash/throttle-cache.d.cts.map +1 -0
- package/dist/sources/unsplash/throttle-cache.d.ts +25 -0
- package/dist/sources/unsplash/throttle-cache.d.ts.map +1 -0
- package/dist/sources/unsplash/throttle-cache.js +45 -0
- package/dist/types/categories.cjs +18 -0
- package/dist/types/categories.d.cts +48 -0
- package/dist/types/categories.d.cts.map +1 -0
- package/dist/types/categories.d.ts +48 -0
- package/dist/types/categories.d.ts.map +1 -0
- package/dist/types/categories.js +1 -0
- package/dist/types/data-source.cjs +18 -0
- package/dist/types/data-source.d.cts +59 -0
- package/dist/types/data-source.d.cts.map +1 -0
- package/dist/types/data-source.d.ts +59 -0
- package/dist/types/data-source.d.ts.map +1 -0
- package/dist/types/data-source.js +1 -0
- package/dist/types/filter.cjs +18 -0
- package/dist/types/filter.d.cts +55 -0
- package/dist/types/filter.d.cts.map +1 -0
- package/dist/types/filter.d.ts +55 -0
- package/dist/types/filter.d.ts.map +1 -0
- package/dist/types/filter.js +1 -0
- package/dist/types/folders.cjs +42 -0
- package/dist/types/folders.d.cts +46 -0
- package/dist/types/folders.d.cts.map +1 -0
- package/dist/types/folders.d.ts +46 -0
- package/dist/types/folders.d.ts.map +1 -0
- package/dist/types/folders.js +4 -0
- package/dist/types/options.cjs +18 -0
- package/dist/types/options.d.cts +68 -0
- package/dist/types/options.d.cts.map +1 -0
- package/dist/types/options.d.ts +68 -0
- package/dist/types/options.d.ts.map +1 -0
- package/dist/types/options.js +1 -0
- package/dist/types/types.d.cts +15 -27
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.ts +15 -27
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/unsplash.cjs +18 -0
- package/dist/types/unsplash.d.cts +60 -0
- package/dist/types/unsplash.d.cts.map +1 -0
- package/dist/types/unsplash.d.ts +60 -0
- package/dist/types/unsplash.d.ts.map +1 -0
- package/dist/types/unsplash.js +1 -0
- package/dist/ui/AssetBrowser.cjs +33 -12
- package/dist/ui/AssetBrowser.d.cts +12 -1
- package/dist/ui/AssetBrowser.d.cts.map +1 -1
- package/dist/ui/AssetBrowser.d.ts +12 -1
- package/dist/ui/AssetBrowser.d.ts.map +1 -1
- package/dist/ui/AssetBrowser.js +33 -12
- package/dist/ui/AssetManagerUI.cjs +8 -2
- package/dist/ui/AssetManagerUI.d.cts +19 -3
- package/dist/ui/AssetManagerUI.d.cts.map +1 -1
- package/dist/ui/AssetManagerUI.d.ts +19 -3
- package/dist/ui/AssetManagerUI.d.ts.map +1 -1
- package/dist/ui/AssetManagerUI.js +8 -2
- package/dist/ui/DeleteFolderDialog.cjs +78 -0
- package/dist/ui/DeleteFolderDialog.d.cts +11 -0
- package/dist/ui/DeleteFolderDialog.d.cts.map +1 -0
- package/dist/ui/DeleteFolderDialog.d.ts +11 -0
- package/dist/ui/DeleteFolderDialog.d.ts.map +1 -0
- package/dist/ui/DeleteFolderDialog.js +40 -0
- package/dist/ui/EmptyFolderState.cjs +53 -0
- package/dist/ui/EmptyFolderState.d.cts +6 -0
- package/dist/ui/EmptyFolderState.d.cts.map +1 -0
- package/dist/ui/EmptyFolderState.d.ts +6 -0
- package/dist/ui/EmptyFolderState.d.ts.map +1 -0
- package/dist/ui/EmptyFolderState.js +15 -0
- package/dist/ui/FolderBreadcrumb.cjs +73 -0
- package/dist/ui/FolderBreadcrumb.d.cts +9 -0
- package/dist/ui/FolderBreadcrumb.d.cts.map +1 -0
- package/dist/ui/FolderBreadcrumb.d.ts +9 -0
- package/dist/ui/FolderBreadcrumb.d.ts.map +1 -0
- package/dist/ui/FolderBreadcrumb.js +35 -0
- package/dist/ui/FolderNameDialog.cjs +98 -0
- package/dist/ui/FolderNameDialog.d.cts +14 -0
- package/dist/ui/FolderNameDialog.d.cts.map +1 -0
- package/dist/ui/FolderNameDialog.d.ts +14 -0
- package/dist/ui/FolderNameDialog.d.ts.map +1 -0
- package/dist/ui/FolderNameDialog.js +60 -0
- package/dist/ui/FolderTree.cjs +83 -0
- package/dist/ui/FolderTree.d.cts +13 -0
- package/dist/ui/FolderTree.d.cts.map +1 -0
- package/dist/ui/FolderTree.d.ts +13 -0
- package/dist/ui/FolderTree.d.ts.map +1 -0
- package/dist/ui/FolderTree.js +42 -0
- package/dist/ui/MetadataPanel.cjs +7 -4
- package/dist/ui/MetadataPanel.d.cts.map +1 -1
- package/dist/ui/MetadataPanel.d.ts.map +1 -1
- package/dist/ui/MetadataPanel.js +7 -4
- package/dist/ui/MoveTargetPicker.cjs +84 -0
- package/dist/ui/MoveTargetPicker.d.cts +16 -0
- package/dist/ui/MoveTargetPicker.d.cts.map +1 -0
- package/dist/ui/MoveTargetPicker.d.ts +16 -0
- package/dist/ui/MoveTargetPicker.d.ts.map +1 -0
- package/dist/ui/MoveTargetPicker.js +46 -0
- package/dist/ui/ReplaceAssetDialog.d.cts +2 -1
- package/dist/ui/ReplaceAssetDialog.d.cts.map +1 -1
- package/dist/ui/ReplaceAssetDialog.d.ts +2 -1
- package/dist/ui/ReplaceAssetDialog.d.ts.map +1 -1
- package/dist/ui/UnsplashPanel.cjs +134 -0
- package/dist/ui/UnsplashPanel.d.cts +28 -0
- package/dist/ui/UnsplashPanel.d.cts.map +1 -0
- package/dist/ui/UnsplashPanel.d.ts +28 -0
- package/dist/ui/UnsplashPanel.d.ts.map +1 -0
- package/dist/ui/UnsplashPanel.js +96 -0
- package/dist/ui/UploadButton.cjs +1 -5
- package/dist/ui/UploadButton.d.cts +9 -2
- package/dist/ui/UploadButton.d.cts.map +1 -1
- package/dist/ui/UploadButton.d.ts +9 -2
- package/dist/ui/UploadButton.d.ts.map +1 -1
- package/dist/ui/UploadButton.js +1 -5
- package/dist/ui/index.cjs +37 -0
- package/dist/ui/index.d.cts +14 -0
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.ts +14 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +7 -0
- package/dist/utils/data-source.cjs +177 -0
- package/dist/utils/data-source.d.cts +63 -0
- package/dist/utils/data-source.d.cts.map +1 -0
- package/dist/utils/data-source.d.ts +63 -0
- package/dist/utils/data-source.d.ts.map +1 -0
- package/dist/utils/data-source.js +136 -0
- package/dist/utils/errors.cjs +18 -0
- package/dist/utils/errors.d.cts +27 -0
- package/dist/utils/errors.d.cts.map +1 -1
- package/dist/utils/errors.d.ts +27 -0
- package/dist/utils/errors.d.ts.map +1 -1
- package/dist/utils/errors.js +16 -1
- package/dist/utils/folders.cjs +261 -0
- package/dist/utils/folders.d.cts +49 -0
- package/dist/utils/folders.d.cts.map +1 -0
- package/dist/utils/folders.d.ts +49 -0
- package/dist/utils/folders.d.ts.map +1 -0
- package/dist/utils/folders.js +223 -0
- package/dist/utils/registry.cjs +27 -12
- package/dist/utils/registry.d.cts +21 -1
- package/dist/utils/registry.d.cts.map +1 -1
- package/dist/utils/registry.d.ts +21 -1
- package/dist/utils/registry.d.ts.map +1 -1
- package/dist/utils/registry.js +20 -11
- package/dist/utils/studio-asset-source.cjs +5 -2
- package/dist/utils/studio-asset-source.d.cts +6 -1
- package/dist/utils/studio-asset-source.d.cts.map +1 -1
- package/dist/utils/studio-asset-source.d.ts +6 -1
- package/dist/utils/studio-asset-source.d.ts.map +1 -1
- package/dist/utils/studio-asset-source.js +1 -1
- package/dist/utils/validate-upload-result.d.cts +2 -1
- package/dist/utils/validate-upload-result.d.cts.map +1 -1
- package/dist/utils/validate-upload-result.d.ts +2 -1
- package/dist/utils/validate-upload-result.d.ts.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/meta/config.json +1 -1
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @anvilkit/plugin-asset-manager
|
|
2
2
|
|
|
3
|
-
> **Alpha (`0.1.
|
|
3
|
+
> **Alpha (`0.1.7`).** Public surface may still shift before `v1.0`. Bundle budgets enforced in CI: headless entry ≤ 8 KB gzip, UI subpath ≤ 12 KB gzip, Unsplash subpath ≤ 4 KB gzip.
|
|
4
4
|
|
|
5
5
|
Headless asset manager plugin for Anvilkit Studio. The host provides the upload backend; the plugin handles validation, registration, search, IR-time resolution, CSP guidance, and (optionally) a React UI for the upload + browse experience. Designed for pluggable production backends (S3, GCS, custom HTTP) with strict trust-boundary enforcement on every adapter response.
|
|
6
6
|
|
|
@@ -15,34 +15,36 @@ Non-optional peers: `react >=19.0.0`, `react-dom >=19.0.0`, `@puckeditor/core ^0
|
|
|
15
15
|
Subpath imports:
|
|
16
16
|
|
|
17
17
|
- `@anvilkit/plugin-asset-manager` — plugin factory, validation, adapters, CSP advisor, errors.
|
|
18
|
-
- `@anvilkit/plugin-asset-manager/ui` — React UI components.
|
|
18
|
+
- `@anvilkit/plugin-asset-manager/ui` — React UI components (browser + folders + Unsplash panel).
|
|
19
19
|
- `@anvilkit/plugin-asset-manager/retry` — generic `RetryableError` + `withRetry()`.
|
|
20
20
|
- `@anvilkit/plugin-asset-manager/adapters/s3` — production `s3PresignedAdapter`.
|
|
21
|
+
- `@anvilkit/plugin-asset-manager/providers/unsplash` — the lazy, dependency-free Unsplash provider.
|
|
21
22
|
- `@anvilkit/plugin-asset-manager/testing` — fixtures for downstream plugin tests.
|
|
22
23
|
|
|
23
24
|
## Quickstart
|
|
24
25
|
|
|
25
26
|
```ts
|
|
26
|
-
import {
|
|
27
|
-
createAssetManagerPlugin,
|
|
28
|
-
dataUrlUploader,
|
|
29
|
-
} from "@anvilkit/plugin-asset-manager";
|
|
27
|
+
import { createAssetManagerPlugin } from "@anvilkit/plugin-asset-manager";
|
|
30
28
|
import { Studio } from "@anvilkit/core";
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
30
|
+
// Zero-config: an in-memory library with folders enabled. Every option is optional.
|
|
31
|
+
const assetManager = createAssetManagerPlugin();
|
|
35
32
|
|
|
36
33
|
<Studio puckConfig={puckConfig} plugins={[assetManager]} />;
|
|
37
34
|
```
|
|
38
35
|
|
|
39
|
-
`dataUrlUploader` is dev-only — files are converted to in-memory `data:` URLs (1 MB cap by default). For production, swap in `s3PresignedAdapter` or a custom `UploadAdapter`.
|
|
36
|
+
For real uploads pass an `uploader`. `dataUrlUploader` is dev-only — files are converted to in-memory `data:` URLs (1 MB cap by default). For production, swap in `s3PresignedAdapter` or a custom `UploadAdapter`. The default Studio sidebar's **Images** rail renders the library, folder breadcrumb/tree, source tabs and (when configured) the Unsplash picker with no extra wiring.
|
|
40
37
|
|
|
41
38
|
## Core features
|
|
42
39
|
|
|
43
40
|
- **Pluggable upload adapters** — `dataUrlUploader`, `inMemoryUploader`, and `s3PresignedAdapter` ship in-box; custom adapters implement the `UploadAdapter` function signature.
|
|
44
41
|
- **Strict trust model** — every adapter response is validated through `validateUploadResult`: scheme allowlist, path-traversal guard, IDN homoglyph guard. `javascript:` / `vbscript:` are hard-blocked. `data:` is opt-in.
|
|
45
42
|
- **In-memory asset registry** — search (`query` / `kinds` / `tags`), opaque cursor pagination, auto-derived tags, rename / retag / replace / delete.
|
|
43
|
+
- **Zero required config** — `createAssetManagerPlugin()` (no args) yields a working in-memory library with folders; wire only the `dataSource` operations you need.
|
|
44
|
+
- **Folders** — tree management (create / rename / move / remove with reparent-or-cascade); membership is library metadata, never IR, so moves never change a rendered page.
|
|
45
|
+
- **Host-backed data source** — optional async `AssetDataSource` (list returns assets + folder tree); per-plane fallback to the in-memory default for omitted methods.
|
|
46
|
+
- **Unsplash** — built-in, lazy, proxy-first source with multiple themes, attribution + mandatory download-trigger; never enters the headless chunk.
|
|
47
|
+
- **Categories & faceted filtering** — kind / tags / folder / source axes (AND-composed) plus host-defined categories & facets; federates across sources with a composite cursor.
|
|
46
48
|
- **IR-time resolution** — `createIRAssetResolver` + `resolveAssets` turn `asset://<id>` references into validated URLs at export / render time.
|
|
47
49
|
- **CSP advisor** — `getRequiredCsp` computes the minimum `connect-src` / `img-src` / `media-src` directives the configured adapters need.
|
|
48
50
|
- **Production-ready S3 adapter** — `s3PresignedAdapter` POST-then-PUT with exponential-backoff retry on 5xx + network failures (4xx fails fast).
|
|
@@ -57,14 +59,20 @@ const assetManager = createAssetManagerPlugin({
|
|
|
57
59
|
function createAssetManagerPlugin(options: AssetManagerOptions): StudioPlugin;
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
| Field | Type | Default
|
|
61
|
-
| --------------------------- | ---------------------------------------------- |
|
|
62
|
-
| `uploader` | `UploadAdapter` |
|
|
63
|
-
| `
|
|
64
|
-
| `
|
|
65
|
-
| `
|
|
66
|
-
| `
|
|
67
|
-
| `
|
|
62
|
+
| Field | Type | Default | Purpose |
|
|
63
|
+
| --------------------------- | ---------------------------------------------- | --------- | ---------------------------------------------------------------------------- |
|
|
64
|
+
| `uploader` | `UploadAdapter` | in-memory | Binary ingest backend (optional; defaults to an in-memory uploader). |
|
|
65
|
+
| `dataSource` | `AssetDataSource` | in-memory | Host-backed catalog (list / remove / replace / rename / move + folders). |
|
|
66
|
+
| `folders` | `boolean \| FolderOptions` | `true` | Folder management; `false` for a flat library, or `{ maxDepth, allowMove }`. |
|
|
67
|
+
| `providers` | `readonly AssetSourceProvider[]` | `[]` | Extra read-only sources, federated alongside the local library. |
|
|
68
|
+
| `unsplash` | `UnsplashSourceOptions` | none | Built-in Unsplash source (proxy-first; no bundled key). |
|
|
69
|
+
| `categories` | `readonly AssetCategory[]` | none | Saved-view chips beside the kind filters. |
|
|
70
|
+
| `facets` | `readonly AssetFacetDefinition[]` | none | Custom faceted filters (local `valueOf` or remote). |
|
|
71
|
+
| `maxFileSize` | `number` | none | Bytes. Enforced before the adapter runs. |
|
|
72
|
+
| `acceptedMimeTypes` | `readonly string[]` | none | Allowlist. Enforced before the adapter runs. |
|
|
73
|
+
| `dataUrlAllowlistOptIn` | `boolean` | `false` | When `true`, `data:` URLs are valid output. |
|
|
74
|
+
| `allowMixedScriptHostnames` | `boolean` | `false` | When `true`, hostnames mixing Latin with a confusable script are allowed. |
|
|
75
|
+
| `getThumbnail` | `(entry: UploadResult) => string \| undefined` | none | Optional override for the displayed thumbnail. |
|
|
68
76
|
|
|
69
77
|
### Imperative API on the plugin context
|
|
70
78
|
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __webpack_exports__ = {};
|
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
__webpack_require__.d(__webpack_exports__, {
|
|
31
31
|
AssetResolutionError: ()=>errors_cjs_namespaceObject.AssetResolutionError,
|
|
32
|
+
AssetSourceError: ()=>errors_cjs_namespaceObject.AssetSourceError,
|
|
32
33
|
AssetValidationError: ()=>errors_cjs_namespaceObject.AssetValidationError,
|
|
33
34
|
createAssetManagerPlugin: ()=>external_plugin_cjs_namespaceObject.createAssetManagerPlugin,
|
|
34
35
|
createAssetReference: ()=>external_plugin_cjs_namespaceObject.createAssetReference,
|
|
@@ -42,12 +43,14 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
42
43
|
inferAssetKind: ()=>infer_kind_cjs_namespaceObject.inferAssetKind,
|
|
43
44
|
inferStudioAssetKind: ()=>studio_asset_source_cjs_namespaceObject.inferStudioAssetKind,
|
|
44
45
|
resolveAssets: ()=>resolver_cjs_namespaceObject.resolveAssets,
|
|
46
|
+
resolveFolderId: ()=>folders_cjs_namespaceObject.resolveFolderId,
|
|
45
47
|
uploadAsset: ()=>external_plugin_cjs_namespaceObject.uploadAsset,
|
|
46
48
|
validateUploadResult: ()=>validate_upload_result_cjs_namespaceObject.validateUploadResult
|
|
47
49
|
});
|
|
48
50
|
const data_url_cjs_namespaceObject = require("./adapters/data-url.cjs");
|
|
49
51
|
const in_memory_cjs_namespaceObject = require("./adapters/in-memory.cjs");
|
|
50
52
|
const external_plugin_cjs_namespaceObject = require("./plugin.cjs");
|
|
53
|
+
const folders_cjs_namespaceObject = require("./types/folders.cjs");
|
|
51
54
|
const csp_cjs_namespaceObject = require("./utils/csp.cjs");
|
|
52
55
|
const errors_cjs_namespaceObject = require("./utils/errors.cjs");
|
|
53
56
|
const infer_kind_cjs_namespaceObject = require("./utils/infer-kind.cjs");
|
|
@@ -56,6 +59,7 @@ const resolver_cjs_namespaceObject = require("./utils/resolver.cjs");
|
|
|
56
59
|
const studio_asset_source_cjs_namespaceObject = require("./utils/studio-asset-source.cjs");
|
|
57
60
|
const validate_upload_result_cjs_namespaceObject = require("./utils/validate-upload-result.cjs");
|
|
58
61
|
exports.AssetResolutionError = __webpack_exports__.AssetResolutionError;
|
|
62
|
+
exports.AssetSourceError = __webpack_exports__.AssetSourceError;
|
|
59
63
|
exports.AssetValidationError = __webpack_exports__.AssetValidationError;
|
|
60
64
|
exports.createAssetManagerPlugin = __webpack_exports__.createAssetManagerPlugin;
|
|
61
65
|
exports.createAssetReference = __webpack_exports__.createAssetReference;
|
|
@@ -69,10 +73,12 @@ exports.inMemoryUploader = __webpack_exports__.inMemoryUploader;
|
|
|
69
73
|
exports.inferAssetKind = __webpack_exports__.inferAssetKind;
|
|
70
74
|
exports.inferStudioAssetKind = __webpack_exports__.inferStudioAssetKind;
|
|
71
75
|
exports.resolveAssets = __webpack_exports__.resolveAssets;
|
|
76
|
+
exports.resolveFolderId = __webpack_exports__.resolveFolderId;
|
|
72
77
|
exports.uploadAsset = __webpack_exports__.uploadAsset;
|
|
73
78
|
exports.validateUploadResult = __webpack_exports__.validateUploadResult;
|
|
74
79
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
75
80
|
"AssetResolutionError",
|
|
81
|
+
"AssetSourceError",
|
|
76
82
|
"AssetValidationError",
|
|
77
83
|
"createAssetManagerPlugin",
|
|
78
84
|
"createAssetReference",
|
|
@@ -86,6 +92,7 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
86
92
|
"inferAssetKind",
|
|
87
93
|
"inferStudioAssetKind",
|
|
88
94
|
"resolveAssets",
|
|
95
|
+
"resolveFolderId",
|
|
89
96
|
"uploadAsset",
|
|
90
97
|
"validateUploadResult"
|
|
91
98
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
package/dist/index.d.cts
CHANGED
|
@@ -2,11 +2,19 @@ export type { DataUrlUploaderOptions } from "./adapters/data-url.js";
|
|
|
2
2
|
export { dataUrlUploader } from "./adapters/data-url.js";
|
|
3
3
|
export { inMemoryUploader } from "./adapters/in-memory.js";
|
|
4
4
|
export { createAssetManagerPlugin, createAssetReference, getAssetRegistry, uploadAsset, } from "./plugin.js";
|
|
5
|
-
export type {
|
|
5
|
+
export type { AssetSourceCapabilities, AssetSourceProvider, AssetTheme, } from "./sources/provider.js";
|
|
6
|
+
export type { AssetCategory, AssetFacetDefinition, AssetFacetOption, } from "./types/categories.js";
|
|
7
|
+
export type { AssetDataSource, AssetSourceStatus, ReplacePayload, } from "./types/data-source.js";
|
|
8
|
+
export type { AssetFilter, AssetListPage, AssetSort, AssetSortField, AssetSourceId, } from "./types/filter.js";
|
|
9
|
+
export type { AssetFolder, FolderId, FolderOptions } from "./types/folders.js";
|
|
10
|
+
export { resolveFolderId } from "./types/folders.js";
|
|
11
|
+
export type { AssetManagerOptions } from "./types/options.js";
|
|
12
|
+
export type { AssetKind, AssetMeta, AssetRegistry, AssetRegistryListener, AssetSearchOptions, AssetSearchPage, UploadAdapter, UploadAdapterOptions, UploadResult, } from "./types/types.js";
|
|
13
|
+
export type { UnsplashSourceOptions, UnsplashTheme, UnsplashThemeConfig, } from "./types/unsplash.js";
|
|
6
14
|
export type { RequiredCsp, RequiredCspOptions, S3CspOptions, } from "./utils/csp.js";
|
|
7
15
|
export { getRequiredCsp } from "./utils/csp.js";
|
|
8
|
-
export type { AssetResolutionErrorCode } from "./utils/errors.js";
|
|
9
|
-
export { AssetResolutionError, AssetValidationError } from "./utils/errors.js";
|
|
16
|
+
export type { AssetResolutionErrorCode, AssetSourceErrorCode, } from "./utils/errors.js";
|
|
17
|
+
export { AssetResolutionError, AssetSourceError, AssetValidationError, } from "./utils/errors.js";
|
|
10
18
|
export { inferAssetKind } from "./utils/infer-kind.js";
|
|
11
19
|
export { createAssetRegistry } from "./utils/registry.js";
|
|
12
20
|
export type { CreateIRAssetResolverOptions } from "./utils/resolver.js";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACX,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,SAAS,EACT,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACX,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACX,aAAa,EACb,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,cAAc,EACd,aAAa,GACb,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACX,qBAAqB,EACrB,aAAa,EACb,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACX,WAAW,EACX,kBAAkB,EAClB,YAAY,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EACX,wBAAwB,EACxB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,YAAY,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AACrF,OAAO,EACN,uBAAuB,EACvB,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,11 +2,19 @@ export type { DataUrlUploaderOptions } from "./adapters/data-url.js";
|
|
|
2
2
|
export { dataUrlUploader } from "./adapters/data-url.js";
|
|
3
3
|
export { inMemoryUploader } from "./adapters/in-memory.js";
|
|
4
4
|
export { createAssetManagerPlugin, createAssetReference, getAssetRegistry, uploadAsset, } from "./plugin.js";
|
|
5
|
-
export type {
|
|
5
|
+
export type { AssetSourceCapabilities, AssetSourceProvider, AssetTheme, } from "./sources/provider.js";
|
|
6
|
+
export type { AssetCategory, AssetFacetDefinition, AssetFacetOption, } from "./types/categories.js";
|
|
7
|
+
export type { AssetDataSource, AssetSourceStatus, ReplacePayload, } from "./types/data-source.js";
|
|
8
|
+
export type { AssetFilter, AssetListPage, AssetSort, AssetSortField, AssetSourceId, } from "./types/filter.js";
|
|
9
|
+
export type { AssetFolder, FolderId, FolderOptions } from "./types/folders.js";
|
|
10
|
+
export { resolveFolderId } from "./types/folders.js";
|
|
11
|
+
export type { AssetManagerOptions } from "./types/options.js";
|
|
12
|
+
export type { AssetKind, AssetMeta, AssetRegistry, AssetRegistryListener, AssetSearchOptions, AssetSearchPage, UploadAdapter, UploadAdapterOptions, UploadResult, } from "./types/types.js";
|
|
13
|
+
export type { UnsplashSourceOptions, UnsplashTheme, UnsplashThemeConfig, } from "./types/unsplash.js";
|
|
6
14
|
export type { RequiredCsp, RequiredCspOptions, S3CspOptions, } from "./utils/csp.js";
|
|
7
15
|
export { getRequiredCsp } from "./utils/csp.js";
|
|
8
|
-
export type { AssetResolutionErrorCode } from "./utils/errors.js";
|
|
9
|
-
export { AssetResolutionError, AssetValidationError } from "./utils/errors.js";
|
|
16
|
+
export type { AssetResolutionErrorCode, AssetSourceErrorCode, } from "./utils/errors.js";
|
|
17
|
+
export { AssetResolutionError, AssetSourceError, AssetValidationError, } from "./utils/errors.js";
|
|
10
18
|
export { inferAssetKind } from "./utils/infer-kind.js";
|
|
11
19
|
export { createAssetRegistry } from "./utils/registry.js";
|
|
12
20
|
export type { CreateIRAssetResolverOptions } from "./utils/resolver.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACX,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,SAAS,EACT,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EACN,wBAAwB,EACxB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GACX,MAAM,aAAa,CAAC;AACrB,YAAY,EACX,uBAAuB,EACvB,mBAAmB,EACnB,UAAU,GACV,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACX,aAAa,EACb,oBAAoB,EACpB,gBAAgB,GAChB,MAAM,uBAAuB,CAAC;AAC/B,YAAY,EACX,eAAe,EACf,iBAAiB,EACjB,cAAc,GACd,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACX,WAAW,EACX,aAAa,EACb,SAAS,EACT,cAAc,EACd,aAAa,GACb,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EACX,SAAS,EACT,SAAS,EACT,aAAa,EACb,qBAAqB,EACrB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,YAAY,GACZ,MAAM,kBAAkB,CAAC;AAC1B,YAAY,EACX,qBAAqB,EACrB,aAAa,EACb,mBAAmB,GACnB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACX,WAAW,EACX,kBAAkB,EAClB,YAAY,GACZ,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EACX,wBAAwB,EACxB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAC3E,YAAY,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AACrF,OAAO,EACN,uBAAuB,EACvB,oBAAoB,GACpB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { dataUrlUploader } from "./adapters/data-url.js";
|
|
2
2
|
export { inMemoryUploader } from "./adapters/in-memory.js";
|
|
3
3
|
export { createAssetManagerPlugin, createAssetReference, getAssetRegistry, uploadAsset } from "./plugin.js";
|
|
4
|
+
export { resolveFolderId } from "./types/folders.js";
|
|
4
5
|
export { getRequiredCsp } from "./utils/csp.js";
|
|
5
|
-
export { AssetResolutionError, AssetValidationError } from "./utils/errors.js";
|
|
6
|
+
export { AssetResolutionError, AssetSourceError, AssetValidationError } from "./utils/errors.js";
|
|
6
7
|
export { inferAssetKind } from "./utils/infer-kind.js";
|
|
7
8
|
export { createAssetRegistry } from "./utils/registry.js";
|
|
8
9
|
export { createIRAssetResolver, resolveAssets } from "./utils/resolver.js";
|
package/dist/plugin.cjs
CHANGED
|
@@ -47,6 +47,7 @@ const external_lucide_react_namespaceObject = require("lucide-react");
|
|
|
47
47
|
const external_react_namespaceObject = require("react");
|
|
48
48
|
const config_json_namespaceObject = require("../meta/config.json");
|
|
49
49
|
var config_json_default = /*#__PURE__*/ __webpack_require__.n(config_json_namespaceObject);
|
|
50
|
+
const in_memory_cjs_namespaceObject = require("./adapters/in-memory.cjs");
|
|
50
51
|
const asset_reference_cjs_namespaceObject = require("./utils/asset-reference.cjs");
|
|
51
52
|
const errors_cjs_namespaceObject = require("./utils/errors.cjs");
|
|
52
53
|
const header_action_cjs_namespaceObject = require("./utils/header-action.cjs");
|
|
@@ -63,7 +64,7 @@ const META = {
|
|
|
63
64
|
};
|
|
64
65
|
const stateByToken = new WeakMap();
|
|
65
66
|
const tokenByContext = new WeakMap();
|
|
66
|
-
function createAssetManagerPlugin(options) {
|
|
67
|
+
function createAssetManagerPlugin(options = {}) {
|
|
67
68
|
const token = {};
|
|
68
69
|
const registry = (0, registry_cjs_namespaceObject.createAssetRegistry)();
|
|
69
70
|
const normalizedOptions = normalizeOptions(options);
|
|
@@ -90,15 +91,34 @@ function createAssetManagerPlugin(options) {
|
|
|
90
91
|
});
|
|
91
92
|
tokenByContext.set(initCtx, token);
|
|
92
93
|
initCtx.registerAssetResolver(assetResolver);
|
|
94
|
+
const upload = (file, opts)=>uploadAsset(initCtx, file, opts?.signal);
|
|
93
95
|
const studioAssetSource = (0, studio_asset_source_cjs_namespaceObject.createStudioAssetSource)({
|
|
94
96
|
registry,
|
|
95
|
-
upload
|
|
97
|
+
upload,
|
|
96
98
|
...normalizedOptions.getThumbnail ? {
|
|
97
99
|
getThumbnail: normalizedOptions.getThumbnail
|
|
98
100
|
} : {}
|
|
99
101
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
+
let unregisterAssetSource = initCtx.registerAssetSource?.(studioAssetSource);
|
|
103
|
+
cleanups.push(()=>unregisterAssetSource?.());
|
|
104
|
+
if (needsRichSource(normalizedOptions)) {
|
|
105
|
+
let disposed = false;
|
|
106
|
+
cleanups.push(()=>{
|
|
107
|
+
disposed = true;
|
|
108
|
+
});
|
|
109
|
+
loadRichSource(initCtx, registry, upload, normalizedOptions).then((composite)=>{
|
|
110
|
+
if (disposed) return;
|
|
111
|
+
unregisterAssetSource?.();
|
|
112
|
+
unregisterAssetSource = void 0;
|
|
113
|
+
const unregisterComposite = initCtx.registerAssetSource?.(composite);
|
|
114
|
+
if (disposed) return void unregisterComposite?.();
|
|
115
|
+
cleanups.push(()=>unregisterComposite?.());
|
|
116
|
+
}).catch((error)=>{
|
|
117
|
+
initCtx.log("error", "asset-manager: failed to load the data source.", {
|
|
118
|
+
error
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
102
122
|
},
|
|
103
123
|
onDestroy (destroyCtx) {
|
|
104
124
|
const state = stateByToken.get(token);
|
|
@@ -162,9 +182,52 @@ function getRuntimeState(ctx) {
|
|
|
162
182
|
if (!state) throw new Error("createAssetManagerPlugin: uploadAsset called before the plugin runtime was initialized.");
|
|
163
183
|
return state;
|
|
164
184
|
}
|
|
185
|
+
function needsRichSource(options) {
|
|
186
|
+
return false !== options.folders || void 0 !== options.dataSource || void 0 !== options.providers && options.providers.length > 0 || void 0 !== options.unsplash;
|
|
187
|
+
}
|
|
188
|
+
async function loadRichSource(ctx, registry, upload, options) {
|
|
189
|
+
const [{ resolveDataSource }, { createCompositeAssetSource }] = await Promise.all([
|
|
190
|
+
import("./utils/data-source.cjs"),
|
|
191
|
+
import("./sources/composite-source.cjs")
|
|
192
|
+
]);
|
|
193
|
+
const maxDepth = "object" == typeof options.folders ? options.folders.maxDepth : void 0;
|
|
194
|
+
const resolved = resolveDataSource({
|
|
195
|
+
registry,
|
|
196
|
+
upload,
|
|
197
|
+
...options.dataSource ? {
|
|
198
|
+
hostDataSource: options.dataSource
|
|
199
|
+
} : {},
|
|
200
|
+
...void 0 !== maxDepth ? {
|
|
201
|
+
maxDepth
|
|
202
|
+
} : {},
|
|
203
|
+
warn: (message)=>ctx.log("warn", message)
|
|
204
|
+
});
|
|
205
|
+
const providers = [
|
|
206
|
+
...options.providers ?? []
|
|
207
|
+
];
|
|
208
|
+
if (void 0 !== options.unsplash) {
|
|
209
|
+
const { createUnsplashProvider, unsplashEnabled } = await import("./sources/unsplash/index.cjs");
|
|
210
|
+
if (unsplashEnabled(options.unsplash)) {
|
|
211
|
+
if (void 0 !== options.unsplash.accessKey && void 0 === options.unsplash.proxyEndpoint) ctx.log("warn", "asset-manager: the Unsplash accessKey is public in the browser — use a server proxy (proxyEndpoint) in production.");
|
|
212
|
+
providers.push(createUnsplashProvider(options.unsplash));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return createCompositeAssetSource({
|
|
216
|
+
source: resolved,
|
|
217
|
+
registry,
|
|
218
|
+
upload,
|
|
219
|
+
...providers.length > 0 ? {
|
|
220
|
+
providers
|
|
221
|
+
} : {},
|
|
222
|
+
...options.getThumbnail ? {
|
|
223
|
+
getThumbnail: options.getThumbnail
|
|
224
|
+
} : {}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
165
227
|
function normalizeOptions(options) {
|
|
166
228
|
return {
|
|
167
229
|
...options,
|
|
230
|
+
uploader: options.uploader ?? (0, in_memory_cjs_namespaceObject.inMemoryUploader)(),
|
|
168
231
|
...options.acceptedMimeTypes ? {
|
|
169
232
|
acceptedMimeTypes: Object.freeze([
|
|
170
233
|
...options.acceptedMimeTypes
|
package/dist/plugin.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StudioPlugin, StudioPluginContext } from "@anvilkit/core/types";
|
|
2
2
|
import type { Config as PuckConfig } from "@puckeditor/core";
|
|
3
|
-
import type { AssetManagerOptions
|
|
3
|
+
import type { AssetManagerOptions } from "./types/options.js";
|
|
4
|
+
import type { AssetRegistry, UploadResult } from "./types/types.js";
|
|
4
5
|
import { createAssetReference } from "./utils/asset-reference.js";
|
|
5
6
|
export { createAssetReference };
|
|
6
|
-
export declare function createAssetManagerPlugin<UserConfig extends PuckConfig = PuckConfig>(options
|
|
7
|
+
export declare function createAssetManagerPlugin<UserConfig extends PuckConfig = PuckConfig>(options?: AssetManagerOptions): StudioPlugin<UserConfig>;
|
|
7
8
|
export declare function getAssetRegistry<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>): AssetRegistry | undefined;
|
|
8
9
|
export declare function uploadAsset<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>, file: File, signal?: AbortSignal): Promise<UploadResult>;
|
|
9
10
|
export declare function validateSelectedFile(file: File, options: Pick<AssetManagerOptions, "acceptedMimeTypes" | "maxFileSize">): void;
|
package/dist/plugin.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.cts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EACZ,mBAAmB,EAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.cts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EACZ,mBAAmB,EAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAS7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAEX,aAAa,EAEb,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAWlE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AA6BhC,wBAAgB,wBAAwB,CACvC,UAAU,SAAS,UAAU,GAAG,UAAU,EACzC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAAC,UAAU,CAAC,CAyF7D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,UAAU,GAAG,UAAU,EAC1E,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,GAClC,aAAa,GAAG,SAAS,CAG3B;AAED,wBAAsB,WAAW,CAAC,UAAU,SAAS,UAAU,GAAG,UAAU,EAC3E,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACpC,IAAI,EAAE,IAAI,EACV,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,YAAY,CAAC,CAwDvB;AAED,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,aAAa,CAAC,GACrE,IAAI,CAmBN"}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { StudioPlugin, StudioPluginContext } from "@anvilkit/core/types";
|
|
2
2
|
import type { Config as PuckConfig } from "@puckeditor/core";
|
|
3
|
-
import type { AssetManagerOptions
|
|
3
|
+
import type { AssetManagerOptions } from "./types/options.js";
|
|
4
|
+
import type { AssetRegistry, UploadResult } from "./types/types.js";
|
|
4
5
|
import { createAssetReference } from "./utils/asset-reference.js";
|
|
5
6
|
export { createAssetReference };
|
|
6
|
-
export declare function createAssetManagerPlugin<UserConfig extends PuckConfig = PuckConfig>(options
|
|
7
|
+
export declare function createAssetManagerPlugin<UserConfig extends PuckConfig = PuckConfig>(options?: AssetManagerOptions): StudioPlugin<UserConfig>;
|
|
7
8
|
export declare function getAssetRegistry<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>): AssetRegistry | undefined;
|
|
8
9
|
export declare function uploadAsset<UserConfig extends PuckConfig = PuckConfig>(ctx: StudioPluginContext<UserConfig>, file: File, signal?: AbortSignal): Promise<UploadResult>;
|
|
9
10
|
export declare function validateSelectedFile(file: File, options: Pick<AssetManagerOptions, "acceptedMimeTypes" | "maxFileSize">): void;
|
package/dist/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EACZ,mBAAmB,EAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEX,YAAY,EACZ,mBAAmB,EAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAS7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAEX,aAAa,EAEb,YAAY,EACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAWlE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AA6BhC,wBAAgB,wBAAwB,CACvC,UAAU,SAAS,UAAU,GAAG,UAAU,EACzC,OAAO,GAAE,mBAAwB,GAAG,YAAY,CAAC,UAAU,CAAC,CAyF7D;AAED,wBAAgB,gBAAgB,CAAC,UAAU,SAAS,UAAU,GAAG,UAAU,EAC1E,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,GAClC,aAAa,GAAG,SAAS,CAG3B;AAED,wBAAsB,WAAW,CAAC,UAAU,SAAS,UAAU,GAAG,UAAU,EAC3E,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACpC,IAAI,EAAE,IAAI,EACV,MAAM,CAAC,EAAE,WAAW,GAClB,OAAO,CAAC,YAAY,CAAC,CAwDvB;AAED,wBAAgB,oBAAoB,CACnC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,IAAI,CAAC,mBAAmB,EAAE,mBAAmB,GAAG,aAAa,CAAC,GACrE,IAAI,CAmBN"}
|
package/dist/plugin.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createElement } from "react";
|
|
|
3
3
|
import config from "../meta/config.json" with {
|
|
4
4
|
type: "json"
|
|
5
5
|
};
|
|
6
|
+
import { inMemoryUploader } from "./adapters/in-memory.js";
|
|
6
7
|
import { createAssetReference } from "./utils/asset-reference.js";
|
|
7
8
|
import { AssetValidationError } from "./utils/errors.js";
|
|
8
9
|
import { uploadAssetAction } from "./utils/header-action.js";
|
|
@@ -19,7 +20,7 @@ const META = {
|
|
|
19
20
|
};
|
|
20
21
|
const stateByToken = new WeakMap();
|
|
21
22
|
const tokenByContext = new WeakMap();
|
|
22
|
-
function createAssetManagerPlugin(options) {
|
|
23
|
+
function createAssetManagerPlugin(options = {}) {
|
|
23
24
|
const token = {};
|
|
24
25
|
const registry = createAssetRegistry();
|
|
25
26
|
const normalizedOptions = normalizeOptions(options);
|
|
@@ -46,15 +47,34 @@ function createAssetManagerPlugin(options) {
|
|
|
46
47
|
});
|
|
47
48
|
tokenByContext.set(initCtx, token);
|
|
48
49
|
initCtx.registerAssetResolver(assetResolver);
|
|
50
|
+
const upload = (file, opts)=>uploadAsset(initCtx, file, opts?.signal);
|
|
49
51
|
const studioAssetSource = createStudioAssetSource({
|
|
50
52
|
registry,
|
|
51
|
-
upload
|
|
53
|
+
upload,
|
|
52
54
|
...normalizedOptions.getThumbnail ? {
|
|
53
55
|
getThumbnail: normalizedOptions.getThumbnail
|
|
54
56
|
} : {}
|
|
55
57
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
let unregisterAssetSource = initCtx.registerAssetSource?.(studioAssetSource);
|
|
59
|
+
cleanups.push(()=>unregisterAssetSource?.());
|
|
60
|
+
if (needsRichSource(normalizedOptions)) {
|
|
61
|
+
let disposed = false;
|
|
62
|
+
cleanups.push(()=>{
|
|
63
|
+
disposed = true;
|
|
64
|
+
});
|
|
65
|
+
loadRichSource(initCtx, registry, upload, normalizedOptions).then((composite)=>{
|
|
66
|
+
if (disposed) return;
|
|
67
|
+
unregisterAssetSource?.();
|
|
68
|
+
unregisterAssetSource = void 0;
|
|
69
|
+
const unregisterComposite = initCtx.registerAssetSource?.(composite);
|
|
70
|
+
if (disposed) return void unregisterComposite?.();
|
|
71
|
+
cleanups.push(()=>unregisterComposite?.());
|
|
72
|
+
}).catch((error)=>{
|
|
73
|
+
initCtx.log("error", "asset-manager: failed to load the data source.", {
|
|
74
|
+
error
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
58
78
|
},
|
|
59
79
|
onDestroy (destroyCtx) {
|
|
60
80
|
const state = stateByToken.get(token);
|
|
@@ -118,9 +138,52 @@ function getRuntimeState(ctx) {
|
|
|
118
138
|
if (!state) throw new Error("createAssetManagerPlugin: uploadAsset called before the plugin runtime was initialized.");
|
|
119
139
|
return state;
|
|
120
140
|
}
|
|
141
|
+
function needsRichSource(options) {
|
|
142
|
+
return false !== options.folders || void 0 !== options.dataSource || void 0 !== options.providers && options.providers.length > 0 || void 0 !== options.unsplash;
|
|
143
|
+
}
|
|
144
|
+
async function loadRichSource(ctx, registry, upload, options) {
|
|
145
|
+
const [{ resolveDataSource }, { createCompositeAssetSource }] = await Promise.all([
|
|
146
|
+
import("./utils/data-source.js"),
|
|
147
|
+
import("./sources/composite-source.js")
|
|
148
|
+
]);
|
|
149
|
+
const maxDepth = "object" == typeof options.folders ? options.folders.maxDepth : void 0;
|
|
150
|
+
const resolved = resolveDataSource({
|
|
151
|
+
registry,
|
|
152
|
+
upload,
|
|
153
|
+
...options.dataSource ? {
|
|
154
|
+
hostDataSource: options.dataSource
|
|
155
|
+
} : {},
|
|
156
|
+
...void 0 !== maxDepth ? {
|
|
157
|
+
maxDepth
|
|
158
|
+
} : {},
|
|
159
|
+
warn: (message)=>ctx.log("warn", message)
|
|
160
|
+
});
|
|
161
|
+
const providers = [
|
|
162
|
+
...options.providers ?? []
|
|
163
|
+
];
|
|
164
|
+
if (void 0 !== options.unsplash) {
|
|
165
|
+
const { createUnsplashProvider, unsplashEnabled } = await import("./sources/unsplash/index.js");
|
|
166
|
+
if (unsplashEnabled(options.unsplash)) {
|
|
167
|
+
if (void 0 !== options.unsplash.accessKey && void 0 === options.unsplash.proxyEndpoint) ctx.log("warn", "asset-manager: the Unsplash accessKey is public in the browser — use a server proxy (proxyEndpoint) in production.");
|
|
168
|
+
providers.push(createUnsplashProvider(options.unsplash));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return createCompositeAssetSource({
|
|
172
|
+
source: resolved,
|
|
173
|
+
registry,
|
|
174
|
+
upload,
|
|
175
|
+
...providers.length > 0 ? {
|
|
176
|
+
providers
|
|
177
|
+
} : {},
|
|
178
|
+
...options.getThumbnail ? {
|
|
179
|
+
getThumbnail: options.getThumbnail
|
|
180
|
+
} : {}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
121
183
|
function normalizeOptions(options) {
|
|
122
184
|
return {
|
|
123
185
|
...options,
|
|
186
|
+
uploader: options.uploader ?? inMemoryUploader(),
|
|
124
187
|
...options.acceptedMimeTypes ? {
|
|
125
188
|
acceptedMimeTypes: Object.freeze([
|
|
126
189
|
...options.acceptedMimeTypes
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createCompositeAssetSource: ()=>createCompositeAssetSource
|
|
32
|
+
});
|
|
33
|
+
const asset_reference_cjs_namespaceObject = require("../utils/asset-reference.cjs");
|
|
34
|
+
const studio_asset_source_cjs_namespaceObject = require("../utils/studio-asset-source.cjs");
|
|
35
|
+
const external_federated_search_cjs_namespaceObject = require("./federated-search.cjs");
|
|
36
|
+
function createCompositeAssetSource(options) {
|
|
37
|
+
const { source, registry, upload, getThumbnail } = options;
|
|
38
|
+
const base = (0, studio_asset_source_cjs_namespaceObject.createStudioAssetSource)({
|
|
39
|
+
registry,
|
|
40
|
+
upload,
|
|
41
|
+
...getThumbnail ? {
|
|
42
|
+
getThumbnail
|
|
43
|
+
} : {}
|
|
44
|
+
});
|
|
45
|
+
const project = (entry)=>{
|
|
46
|
+
const attribution = entry.meta?.attribution;
|
|
47
|
+
const isExternal = entry.id.startsWith("unsplash:");
|
|
48
|
+
return {
|
|
49
|
+
...(0, studio_asset_source_cjs_namespaceObject.toStudioAsset)(entry, getThumbnail),
|
|
50
|
+
...isExternal ? {
|
|
51
|
+
url: entry.url
|
|
52
|
+
} : {},
|
|
53
|
+
folderId: source.folders.folderOf(entry.id),
|
|
54
|
+
source: isExternal ? "unsplash" : "local",
|
|
55
|
+
...attribution ? {
|
|
56
|
+
attribution: {
|
|
57
|
+
photographerName: attribution.photographerName,
|
|
58
|
+
photographerUrl: attribution.photographerUrl,
|
|
59
|
+
sourceUrl: attribution.unsplashUrl
|
|
60
|
+
}
|
|
61
|
+
} : {}
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
const providers = [
|
|
65
|
+
(0, external_federated_search_cjs_namespaceObject.createLocalProvider)(source, registry),
|
|
66
|
+
...options.providers ?? []
|
|
67
|
+
];
|
|
68
|
+
const runList = (filter, signal)=>1 === providers.length ? source.list(filter, signal) : (0, external_federated_search_cjs_namespaceObject.federatedSearch)({
|
|
69
|
+
providers,
|
|
70
|
+
filter,
|
|
71
|
+
signal
|
|
72
|
+
});
|
|
73
|
+
return {
|
|
74
|
+
async list () {
|
|
75
|
+
const page = await runList({});
|
|
76
|
+
return Object.freeze(page.items.map(project));
|
|
77
|
+
},
|
|
78
|
+
async listPaginated (query) {
|
|
79
|
+
const page = await runList({
|
|
80
|
+
...query
|
|
81
|
+
});
|
|
82
|
+
return {
|
|
83
|
+
items: Object.freeze(page.items.map(project)),
|
|
84
|
+
total: page.total,
|
|
85
|
+
nextCursor: page.nextCursor,
|
|
86
|
+
...page.folders ? {
|
|
87
|
+
folders: page.folders
|
|
88
|
+
} : {},
|
|
89
|
+
...page.folderPath ? {
|
|
90
|
+
folderPath: page.folderPath
|
|
91
|
+
} : {},
|
|
92
|
+
...page.sourceCursors ? {
|
|
93
|
+
sourceCursors: page.sourceCursors
|
|
94
|
+
} : {}
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
upload: base.upload,
|
|
98
|
+
setTags: base.setTags,
|
|
99
|
+
subscribeUploads: base.subscribeUploads,
|
|
100
|
+
getUrl: (assetId)=>(0, asset_reference_cjs_namespaceObject.createAssetReference)(assetId),
|
|
101
|
+
async delete (assetId) {
|
|
102
|
+
await source.remove(assetId);
|
|
103
|
+
},
|
|
104
|
+
async rename (assetId, nextName) {
|
|
105
|
+
await source.rename(assetId, nextName);
|
|
106
|
+
},
|
|
107
|
+
async replace (assetId, file) {
|
|
108
|
+
return project(await source.replace(assetId, file));
|
|
109
|
+
},
|
|
110
|
+
subscribe: (listener)=>source.subscribe(listener),
|
|
111
|
+
createFolder: (parentId, name)=>source.createFolder(parentId, name),
|
|
112
|
+
renameFolder: (id, name)=>source.renameFolder(id, name),
|
|
113
|
+
removeFolder: (id, opts)=>source.removeFolder(id, opts),
|
|
114
|
+
moveFolder: (id, parentId)=>source.moveFolder(id, parentId),
|
|
115
|
+
moveAsset: (assetId, folderId)=>source.move(assetId, folderId),
|
|
116
|
+
async pickResult (asset) {
|
|
117
|
+
const provider = providers.find((p)=>p.id === asset.source);
|
|
118
|
+
if (void 0 === provider || "local" === provider.id) return asset;
|
|
119
|
+
const result = await provider.pickResult(asset);
|
|
120
|
+
registry.register(result);
|
|
121
|
+
return project(result);
|
|
122
|
+
},
|
|
123
|
+
subscribeStatus: (listener)=>source.subscribeStatus(listener),
|
|
124
|
+
async listThemes () {
|
|
125
|
+
const themes = [];
|
|
126
|
+
for (const provider of providers)if ("local" !== provider.id) themes.push(...await provider.listThemes());
|
|
127
|
+
return themes;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
exports.createCompositeAssetSource = __webpack_exports__.createCompositeAssetSource;
|
|
132
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
133
|
+
"createCompositeAssetSource"
|
|
134
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
135
|
+
Object.defineProperty(exports, '__esModule', {
|
|
136
|
+
value: true
|
|
137
|
+
});
|