@anvilkit/plugin-asset-manager 0.1.6 → 0.1.8
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 +28 -20
- package/dist/adapters/data-url.d.cts +13 -0
- package/dist/adapters/data-url.d.cts.map +1 -1
- package/dist/adapters/data-url.d.ts +13 -0
- package/dist/adapters/data-url.d.ts.map +1 -1
- package/dist/adapters/in-memory.d.cts +8 -1
- package/dist/adapters/in-memory.d.cts.map +1 -1
- package/dist/adapters/in-memory.d.ts +8 -1
- package/dist/adapters/in-memory.d.ts.map +1 -1
- package/dist/i18n/entry.cjs +75 -0
- package/dist/i18n/entry.d.cts +15 -0
- package/dist/i18n/entry.d.cts.map +1 -0
- package/dist/i18n/entry.d.ts +15 -0
- package/dist/i18n/entry.d.ts.map +1 -0
- package/dist/i18n/entry.js +29 -0
- package/dist/i18n/provider.cjs +49 -0
- package/dist/i18n/provider.d.cts +20 -0
- package/dist/i18n/provider.d.cts.map +1 -0
- package/dist/i18n/provider.d.ts +20 -0
- package/dist/i18n/provider.d.ts.map +1 -0
- package/dist/i18n/provider.js +11 -0
- 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 +70 -5
- 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 +70 -5
- package/dist/sources/composite-source.cjs +138 -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 +100 -0
- package/dist/sources/federated-search.cjs +173 -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 +123 -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 +194 -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 +150 -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 +21 -27
- package/dist/types/types.d.cts.map +1 -1
- package/dist/types/types.d.ts +21 -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 +183 -121
- 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 +183 -121
- package/dist/ui/AssetCommandPalette.cjs +20 -18
- package/dist/ui/AssetCommandPalette.d.cts.map +1 -1
- package/dist/ui/AssetCommandPalette.d.ts.map +1 -1
- package/dist/ui/AssetCommandPalette.js +20 -18
- package/dist/ui/AssetManagerUI.cjs +31 -17
- 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 +31 -17
- package/dist/ui/DeleteAssetDialog.cjs +5 -3
- package/dist/ui/DeleteAssetDialog.d.cts.map +1 -1
- package/dist/ui/DeleteAssetDialog.d.ts.map +1 -1
- package/dist/ui/DeleteAssetDialog.js +5 -3
- package/dist/ui/DeleteFolderDialog.cjs +80 -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 +42 -0
- package/dist/ui/EmptyFolderState.cjs +56 -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 +18 -0
- package/dist/ui/FolderBreadcrumb.cjs +76 -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 +38 -0
- package/dist/ui/FolderNameDialog.cjs +105 -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 +67 -0
- package/dist/ui/FolderTree.cjs +85 -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 +44 -0
- package/dist/ui/MetadataPanel.cjs +23 -17
- package/dist/ui/MetadataPanel.d.cts.map +1 -1
- package/dist/ui/MetadataPanel.d.ts.map +1 -1
- package/dist/ui/MetadataPanel.js +23 -17
- package/dist/ui/MoveTargetPicker.cjs +87 -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 +49 -0
- package/dist/ui/ReplaceAssetDialog.cjs +19 -17
- 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/ReplaceAssetDialog.js +19 -17
- package/dist/ui/UnsplashPanel.cjs +137 -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 +99 -0
- package/dist/ui/UploadButton.cjs +12 -13
- 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 +12 -13
- package/dist/ui/index.cjs +41 -0
- package/dist/ui/index.d.cts +15 -0
- package/dist/ui/index.d.cts.map +1 -1
- package/dist/ui/index.d.ts +15 -0
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +8 -0
- package/dist/utils/data-source.cjs +190 -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 +149 -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 +335 -0
- package/dist/utils/folders.d.cts +54 -0
- package/dist/utils/folders.d.cts.map +1 -0
- package/dist/utils/folders.d.ts +54 -0
- package/dist/utils/folders.d.ts.map +1 -0
- package/dist/utils/folders.js +297 -0
- package/dist/utils/header-action.cjs +1 -1
- package/dist/utils/header-action.d.cts.map +1 -1
- package/dist/utils/header-action.d.ts.map +1 -1
- package/dist/utils/header-action.js +1 -1
- package/dist/utils/registry.cjs +38 -12
- package/dist/utils/registry.d.cts +29 -1
- package/dist/utils/registry.d.cts.map +1 -1
- package/dist/utils/registry.d.ts +29 -1
- package/dist/utils/registry.d.ts.map +1 -1
- package/dist/utils/registry.js +31 -11
- package/dist/utils/resolver.cjs +5 -4
- package/dist/utils/resolver.d.cts.map +1 -1
- package/dist/utils/resolver.d.ts.map +1 -1
- package/dist/utils/resolver.js +5 -4
- package/dist/utils/studio-asset-source.cjs +13 -4
- 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 +9 -3
- 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/i18n/messages/en.json +99 -0
- package/i18n/messages/ja.json +99 -0
- package/i18n/messages/ko.json +99 -0
- package/i18n/messages/zh.json +99 -0
- package/meta/config.json +1 -1
- package/package.json +19 -8
package/dist/plugin.cjs
CHANGED
|
@@ -47,6 +47,8 @@ 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");
|
|
51
|
+
const entry_cjs_namespaceObject = require("./i18n/entry.cjs");
|
|
50
52
|
const asset_reference_cjs_namespaceObject = require("./utils/asset-reference.cjs");
|
|
51
53
|
const errors_cjs_namespaceObject = require("./utils/errors.cjs");
|
|
52
54
|
const header_action_cjs_namespaceObject = require("./utils/header-action.cjs");
|
|
@@ -63,7 +65,7 @@ const META = {
|
|
|
63
65
|
};
|
|
64
66
|
const stateByToken = new WeakMap();
|
|
65
67
|
const tokenByContext = new WeakMap();
|
|
66
|
-
function createAssetManagerPlugin(options) {
|
|
68
|
+
function createAssetManagerPlugin(options = {}) {
|
|
67
69
|
const token = {};
|
|
68
70
|
const registry = (0, registry_cjs_namespaceObject.createAssetRegistry)();
|
|
69
71
|
const normalizedOptions = normalizeOptions(options);
|
|
@@ -74,7 +76,8 @@ function createAssetManagerPlugin(options) {
|
|
|
74
76
|
});
|
|
75
77
|
return {
|
|
76
78
|
meta: META,
|
|
77
|
-
register (
|
|
79
|
+
register (ctx) {
|
|
80
|
+
ctx.registerMessages(entry_cjs_namespaceObject.ASSET_MANAGER_ENTRY);
|
|
78
81
|
const registration = {
|
|
79
82
|
meta: META,
|
|
80
83
|
headerActions: [
|
|
@@ -90,15 +93,34 @@ function createAssetManagerPlugin(options) {
|
|
|
90
93
|
});
|
|
91
94
|
tokenByContext.set(initCtx, token);
|
|
92
95
|
initCtx.registerAssetResolver(assetResolver);
|
|
96
|
+
const upload = (file, opts)=>uploadAsset(initCtx, file, opts?.signal);
|
|
93
97
|
const studioAssetSource = (0, studio_asset_source_cjs_namespaceObject.createStudioAssetSource)({
|
|
94
98
|
registry,
|
|
95
|
-
upload
|
|
99
|
+
upload,
|
|
96
100
|
...normalizedOptions.getThumbnail ? {
|
|
97
101
|
getThumbnail: normalizedOptions.getThumbnail
|
|
98
102
|
} : {}
|
|
99
103
|
});
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
let unregisterAssetSource = initCtx.registerAssetSource?.(studioAssetSource);
|
|
105
|
+
cleanups.push(()=>unregisterAssetSource?.());
|
|
106
|
+
if (needsRichSource(normalizedOptions)) {
|
|
107
|
+
let disposed = false;
|
|
108
|
+
cleanups.push(()=>{
|
|
109
|
+
disposed = true;
|
|
110
|
+
});
|
|
111
|
+
loadRichSource(initCtx, registry, upload, normalizedOptions).then((composite)=>{
|
|
112
|
+
if (disposed) return;
|
|
113
|
+
unregisterAssetSource?.();
|
|
114
|
+
unregisterAssetSource = void 0;
|
|
115
|
+
const unregisterComposite = initCtx.registerAssetSource?.(composite);
|
|
116
|
+
if (disposed) return void unregisterComposite?.();
|
|
117
|
+
cleanups.push(()=>unregisterComposite?.());
|
|
118
|
+
}).catch((error)=>{
|
|
119
|
+
initCtx.log("error", "asset-manager: failed to load the data source.", {
|
|
120
|
+
error
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
}
|
|
102
124
|
},
|
|
103
125
|
onDestroy (destroyCtx) {
|
|
104
126
|
const state = stateByToken.get(token);
|
|
@@ -162,9 +184,52 @@ function getRuntimeState(ctx) {
|
|
|
162
184
|
if (!state) throw new Error("createAssetManagerPlugin: uploadAsset called before the plugin runtime was initialized.");
|
|
163
185
|
return state;
|
|
164
186
|
}
|
|
187
|
+
function needsRichSource(options) {
|
|
188
|
+
return false !== options.folders || void 0 !== options.dataSource || void 0 !== options.providers && options.providers.length > 0 || void 0 !== options.unsplash;
|
|
189
|
+
}
|
|
190
|
+
async function loadRichSource(ctx, registry, upload, options) {
|
|
191
|
+
const [{ resolveDataSource }, { createCompositeAssetSource }] = await Promise.all([
|
|
192
|
+
import("./utils/data-source.cjs"),
|
|
193
|
+
import("./sources/composite-source.cjs")
|
|
194
|
+
]);
|
|
195
|
+
const maxDepth = "object" == typeof options.folders ? options.folders.maxDepth : void 0;
|
|
196
|
+
const resolved = resolveDataSource({
|
|
197
|
+
registry,
|
|
198
|
+
upload,
|
|
199
|
+
...options.dataSource ? {
|
|
200
|
+
hostDataSource: options.dataSource
|
|
201
|
+
} : {},
|
|
202
|
+
...void 0 !== maxDepth ? {
|
|
203
|
+
maxDepth
|
|
204
|
+
} : {},
|
|
205
|
+
warn: (message)=>ctx.log("warn", message)
|
|
206
|
+
});
|
|
207
|
+
const providers = [
|
|
208
|
+
...options.providers ?? []
|
|
209
|
+
];
|
|
210
|
+
if (void 0 !== options.unsplash) {
|
|
211
|
+
const { createUnsplashProvider, unsplashEnabled } = await import("./sources/unsplash/index.cjs");
|
|
212
|
+
if (unsplashEnabled(options.unsplash)) {
|
|
213
|
+
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.");
|
|
214
|
+
providers.push(createUnsplashProvider(options.unsplash));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return createCompositeAssetSource({
|
|
218
|
+
source: resolved,
|
|
219
|
+
registry,
|
|
220
|
+
upload,
|
|
221
|
+
...providers.length > 0 ? {
|
|
222
|
+
providers
|
|
223
|
+
} : {},
|
|
224
|
+
...options.getThumbnail ? {
|
|
225
|
+
getThumbnail: options.getThumbnail
|
|
226
|
+
} : {}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
165
229
|
function normalizeOptions(options) {
|
|
166
230
|
return {
|
|
167
231
|
...options,
|
|
232
|
+
uploader: options.uploader ?? (0, in_memory_cjs_namespaceObject.inMemoryUploader)(),
|
|
168
233
|
...options.acceptedMimeTypes ? {
|
|
169
234
|
acceptedMimeTypes: Object.freeze([
|
|
170
235
|
...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;AAU7D,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,CA4F7D;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;AAU7D,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,CA4F7D;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,8 @@ 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";
|
|
7
|
+
import { ASSET_MANAGER_ENTRY } from "./i18n/entry.js";
|
|
6
8
|
import { createAssetReference } from "./utils/asset-reference.js";
|
|
7
9
|
import { AssetValidationError } from "./utils/errors.js";
|
|
8
10
|
import { uploadAssetAction } from "./utils/header-action.js";
|
|
@@ -19,7 +21,7 @@ const META = {
|
|
|
19
21
|
};
|
|
20
22
|
const stateByToken = new WeakMap();
|
|
21
23
|
const tokenByContext = new WeakMap();
|
|
22
|
-
function createAssetManagerPlugin(options) {
|
|
24
|
+
function createAssetManagerPlugin(options = {}) {
|
|
23
25
|
const token = {};
|
|
24
26
|
const registry = createAssetRegistry();
|
|
25
27
|
const normalizedOptions = normalizeOptions(options);
|
|
@@ -30,7 +32,8 @@ function createAssetManagerPlugin(options) {
|
|
|
30
32
|
});
|
|
31
33
|
return {
|
|
32
34
|
meta: META,
|
|
33
|
-
register (
|
|
35
|
+
register (ctx) {
|
|
36
|
+
ctx.registerMessages(ASSET_MANAGER_ENTRY);
|
|
34
37
|
const registration = {
|
|
35
38
|
meta: META,
|
|
36
39
|
headerActions: [
|
|
@@ -46,15 +49,34 @@ function createAssetManagerPlugin(options) {
|
|
|
46
49
|
});
|
|
47
50
|
tokenByContext.set(initCtx, token);
|
|
48
51
|
initCtx.registerAssetResolver(assetResolver);
|
|
52
|
+
const upload = (file, opts)=>uploadAsset(initCtx, file, opts?.signal);
|
|
49
53
|
const studioAssetSource = createStudioAssetSource({
|
|
50
54
|
registry,
|
|
51
|
-
upload
|
|
55
|
+
upload,
|
|
52
56
|
...normalizedOptions.getThumbnail ? {
|
|
53
57
|
getThumbnail: normalizedOptions.getThumbnail
|
|
54
58
|
} : {}
|
|
55
59
|
});
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
let unregisterAssetSource = initCtx.registerAssetSource?.(studioAssetSource);
|
|
61
|
+
cleanups.push(()=>unregisterAssetSource?.());
|
|
62
|
+
if (needsRichSource(normalizedOptions)) {
|
|
63
|
+
let disposed = false;
|
|
64
|
+
cleanups.push(()=>{
|
|
65
|
+
disposed = true;
|
|
66
|
+
});
|
|
67
|
+
loadRichSource(initCtx, registry, upload, normalizedOptions).then((composite)=>{
|
|
68
|
+
if (disposed) return;
|
|
69
|
+
unregisterAssetSource?.();
|
|
70
|
+
unregisterAssetSource = void 0;
|
|
71
|
+
const unregisterComposite = initCtx.registerAssetSource?.(composite);
|
|
72
|
+
if (disposed) return void unregisterComposite?.();
|
|
73
|
+
cleanups.push(()=>unregisterComposite?.());
|
|
74
|
+
}).catch((error)=>{
|
|
75
|
+
initCtx.log("error", "asset-manager: failed to load the data source.", {
|
|
76
|
+
error
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
58
80
|
},
|
|
59
81
|
onDestroy (destroyCtx) {
|
|
60
82
|
const state = stateByToken.get(token);
|
|
@@ -118,9 +140,52 @@ function getRuntimeState(ctx) {
|
|
|
118
140
|
if (!state) throw new Error("createAssetManagerPlugin: uploadAsset called before the plugin runtime was initialized.");
|
|
119
141
|
return state;
|
|
120
142
|
}
|
|
143
|
+
function needsRichSource(options) {
|
|
144
|
+
return false !== options.folders || void 0 !== options.dataSource || void 0 !== options.providers && options.providers.length > 0 || void 0 !== options.unsplash;
|
|
145
|
+
}
|
|
146
|
+
async function loadRichSource(ctx, registry, upload, options) {
|
|
147
|
+
const [{ resolveDataSource }, { createCompositeAssetSource }] = await Promise.all([
|
|
148
|
+
import("./utils/data-source.js"),
|
|
149
|
+
import("./sources/composite-source.js")
|
|
150
|
+
]);
|
|
151
|
+
const maxDepth = "object" == typeof options.folders ? options.folders.maxDepth : void 0;
|
|
152
|
+
const resolved = resolveDataSource({
|
|
153
|
+
registry,
|
|
154
|
+
upload,
|
|
155
|
+
...options.dataSource ? {
|
|
156
|
+
hostDataSource: options.dataSource
|
|
157
|
+
} : {},
|
|
158
|
+
...void 0 !== maxDepth ? {
|
|
159
|
+
maxDepth
|
|
160
|
+
} : {},
|
|
161
|
+
warn: (message)=>ctx.log("warn", message)
|
|
162
|
+
});
|
|
163
|
+
const providers = [
|
|
164
|
+
...options.providers ?? []
|
|
165
|
+
];
|
|
166
|
+
if (void 0 !== options.unsplash) {
|
|
167
|
+
const { createUnsplashProvider, unsplashEnabled } = await import("./sources/unsplash/index.js");
|
|
168
|
+
if (unsplashEnabled(options.unsplash)) {
|
|
169
|
+
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.");
|
|
170
|
+
providers.push(createUnsplashProvider(options.unsplash));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return createCompositeAssetSource({
|
|
174
|
+
source: resolved,
|
|
175
|
+
registry,
|
|
176
|
+
upload,
|
|
177
|
+
...providers.length > 0 ? {
|
|
178
|
+
providers
|
|
179
|
+
} : {},
|
|
180
|
+
...options.getThumbnail ? {
|
|
181
|
+
getThumbnail: options.getThumbnail
|
|
182
|
+
} : {}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
121
185
|
function normalizeOptions(options) {
|
|
122
186
|
return {
|
|
123
187
|
...options,
|
|
188
|
+
uploader: options.uploader ?? inMemoryUploader(),
|
|
124
189
|
...options.acceptedMimeTypes ? {
|
|
125
190
|
acceptedMimeTypes: Object.freeze([
|
|
126
191
|
...options.acceptedMimeTypes
|
|
@@ -0,0 +1,138 @@
|
|
|
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 themeLists = await Promise.all(providers.flatMap((provider)=>"local" === provider.id ? [] : [
|
|
126
|
+
provider.listThemes()
|
|
127
|
+
]));
|
|
128
|
+
return themeLists.flat();
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.createCompositeAssetSource = __webpack_exports__.createCompositeAssetSource;
|
|
133
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
134
|
+
"createCompositeAssetSource"
|
|
135
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
136
|
+
Object.defineProperty(exports, '__esModule', {
|
|
137
|
+
value: true
|
|
138
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `CompositeAssetSource` (PRD 0002 §6.1, §8.1). Implements core's
|
|
3
|
+
* `StudioAssetSource` by routing reads + catalog mutations through the resolved
|
|
4
|
+
* `AssetDataSource` (so host backends and folder scoping work), while reusing
|
|
5
|
+
* the proven upload pipeline + projection from `createStudioAssetSource`.
|
|
6
|
+
*
|
|
7
|
+
* Lazy-loaded by the factory only when a host opts into a richer surface
|
|
8
|
+
* (`dataSource`/`providers`/`unsplash`), so flat callers never pull this — or
|
|
9
|
+
* the folder/data-source code it imports — into the headless entry chunk.
|
|
10
|
+
*/
|
|
11
|
+
import type { StudioAssetSource } from "@anvilkit/core/types";
|
|
12
|
+
import type { AssetFolder, FolderId } from "../types/folders.js";
|
|
13
|
+
import type { AssetRegistry, UploadResult } from "../types/types.js";
|
|
14
|
+
import type { ResolvedAssetDataSource, UploadFn } from "../utils/data-source.js";
|
|
15
|
+
import type { AssetSourceProvider } from "./provider.js";
|
|
16
|
+
export interface CreateCompositeAssetSourceOptions {
|
|
17
|
+
readonly source: ResolvedAssetDataSource;
|
|
18
|
+
readonly registry: AssetRegistry;
|
|
19
|
+
readonly upload: UploadFn;
|
|
20
|
+
readonly getThumbnail?: (entry: UploadResult) => string | undefined;
|
|
21
|
+
/** External read-only sources (e.g. Unsplash) federated alongside the local library. */
|
|
22
|
+
readonly providers?: readonly AssetSourceProvider[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The core `StudioAssetSource` plus the folder methods the plugin's `./ui` and
|
|
26
|
+
* (Phase 2) core `ImageModule` consume. The folder methods are additive — core
|
|
27
|
+
* ignores what it doesn't know until its sidebar types adopt them.
|
|
28
|
+
*/
|
|
29
|
+
export interface CompositeAssetSource extends StudioAssetSource {
|
|
30
|
+
createFolder(parentId: FolderId | null, name: string): Promise<AssetFolder>;
|
|
31
|
+
renameFolder(id: FolderId, name: string): Promise<AssetFolder>;
|
|
32
|
+
removeFolder(id: FolderId, opts?: {
|
|
33
|
+
readonly cascade?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
moveFolder(id: FolderId, parentId: FolderId | null): Promise<AssetFolder>;
|
|
36
|
+
moveAsset(assetId: string, folderId: FolderId | null): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare function createCompositeAssetSource(options: CreateCompositeAssetSourceOptions): CompositeAssetSource;
|
|
39
|
+
//# sourceMappingURL=composite-source.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-source.d.cts","sourceRoot":"","sources":["../../src/sources/composite-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAIX,iBAAiB,EAEjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,KAAK,EACX,uBAAuB,EACvB,QAAQ,EACR,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,WAAW,iCAAiC;IACjD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;IACpE,wFAAwF;IACxF,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACpD;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC9D,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5E,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/D,YAAY,CACX,EAAE,EAAE,QAAQ,EACZ,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1E,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,iCAAiC,GACxC,oBAAoB,CAiItB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file `CompositeAssetSource` (PRD 0002 §6.1, §8.1). Implements core's
|
|
3
|
+
* `StudioAssetSource` by routing reads + catalog mutations through the resolved
|
|
4
|
+
* `AssetDataSource` (so host backends and folder scoping work), while reusing
|
|
5
|
+
* the proven upload pipeline + projection from `createStudioAssetSource`.
|
|
6
|
+
*
|
|
7
|
+
* Lazy-loaded by the factory only when a host opts into a richer surface
|
|
8
|
+
* (`dataSource`/`providers`/`unsplash`), so flat callers never pull this — or
|
|
9
|
+
* the folder/data-source code it imports — into the headless entry chunk.
|
|
10
|
+
*/
|
|
11
|
+
import type { StudioAssetSource } from "@anvilkit/core/types";
|
|
12
|
+
import type { AssetFolder, FolderId } from "../types/folders.js";
|
|
13
|
+
import type { AssetRegistry, UploadResult } from "../types/types.js";
|
|
14
|
+
import type { ResolvedAssetDataSource, UploadFn } from "../utils/data-source.js";
|
|
15
|
+
import type { AssetSourceProvider } from "./provider.js";
|
|
16
|
+
export interface CreateCompositeAssetSourceOptions {
|
|
17
|
+
readonly source: ResolvedAssetDataSource;
|
|
18
|
+
readonly registry: AssetRegistry;
|
|
19
|
+
readonly upload: UploadFn;
|
|
20
|
+
readonly getThumbnail?: (entry: UploadResult) => string | undefined;
|
|
21
|
+
/** External read-only sources (e.g. Unsplash) federated alongside the local library. */
|
|
22
|
+
readonly providers?: readonly AssetSourceProvider[];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The core `StudioAssetSource` plus the folder methods the plugin's `./ui` and
|
|
26
|
+
* (Phase 2) core `ImageModule` consume. The folder methods are additive — core
|
|
27
|
+
* ignores what it doesn't know until its sidebar types adopt them.
|
|
28
|
+
*/
|
|
29
|
+
export interface CompositeAssetSource extends StudioAssetSource {
|
|
30
|
+
createFolder(parentId: FolderId | null, name: string): Promise<AssetFolder>;
|
|
31
|
+
renameFolder(id: FolderId, name: string): Promise<AssetFolder>;
|
|
32
|
+
removeFolder(id: FolderId, opts?: {
|
|
33
|
+
readonly cascade?: boolean;
|
|
34
|
+
}): Promise<void>;
|
|
35
|
+
moveFolder(id: FolderId, parentId: FolderId | null): Promise<AssetFolder>;
|
|
36
|
+
moveAsset(assetId: string, folderId: FolderId | null): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
export declare function createCompositeAssetSource(options: CreateCompositeAssetSourceOptions): CompositeAssetSource;
|
|
39
|
+
//# sourceMappingURL=composite-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composite-source.d.ts","sourceRoot":"","sources":["../../src/sources/composite-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAIX,iBAAiB,EAEjB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,KAAK,EACX,uBAAuB,EACvB,QAAQ,EACR,MAAM,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,WAAW,iCAAiC;IACjD,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,aAAa,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;IACpE,wFAAwF;IACxF,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;CACpD;AAED;;;;GAIG;AACH,MAAM,WAAW,oBAAqB,SAAQ,iBAAiB;IAC9D,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC5E,YAAY,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/D,YAAY,CACX,EAAE,EAAE,QAAQ,EACZ,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;KAAE,GACnC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjB,UAAU,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAC1E,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrE;AAED,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,iCAAiC,GACxC,oBAAoB,CAiItB"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createAssetReference } from "../utils/asset-reference.js";
|
|
2
|
+
import { createStudioAssetSource, toStudioAsset } from "../utils/studio-asset-source.js";
|
|
3
|
+
import { createLocalProvider, federatedSearch } from "./federated-search.js";
|
|
4
|
+
function createCompositeAssetSource(options) {
|
|
5
|
+
const { source, registry, upload, getThumbnail } = options;
|
|
6
|
+
const base = createStudioAssetSource({
|
|
7
|
+
registry,
|
|
8
|
+
upload,
|
|
9
|
+
...getThumbnail ? {
|
|
10
|
+
getThumbnail
|
|
11
|
+
} : {}
|
|
12
|
+
});
|
|
13
|
+
const project = (entry)=>{
|
|
14
|
+
const attribution = entry.meta?.attribution;
|
|
15
|
+
const isExternal = entry.id.startsWith("unsplash:");
|
|
16
|
+
return {
|
|
17
|
+
...toStudioAsset(entry, getThumbnail),
|
|
18
|
+
...isExternal ? {
|
|
19
|
+
url: entry.url
|
|
20
|
+
} : {},
|
|
21
|
+
folderId: source.folders.folderOf(entry.id),
|
|
22
|
+
source: isExternal ? "unsplash" : "local",
|
|
23
|
+
...attribution ? {
|
|
24
|
+
attribution: {
|
|
25
|
+
photographerName: attribution.photographerName,
|
|
26
|
+
photographerUrl: attribution.photographerUrl,
|
|
27
|
+
sourceUrl: attribution.unsplashUrl
|
|
28
|
+
}
|
|
29
|
+
} : {}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const providers = [
|
|
33
|
+
createLocalProvider(source, registry),
|
|
34
|
+
...options.providers ?? []
|
|
35
|
+
];
|
|
36
|
+
const runList = (filter, signal)=>1 === providers.length ? source.list(filter, signal) : federatedSearch({
|
|
37
|
+
providers,
|
|
38
|
+
filter,
|
|
39
|
+
signal
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
async list () {
|
|
43
|
+
const page = await runList({});
|
|
44
|
+
return Object.freeze(page.items.map(project));
|
|
45
|
+
},
|
|
46
|
+
async listPaginated (query) {
|
|
47
|
+
const page = await runList({
|
|
48
|
+
...query
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
items: Object.freeze(page.items.map(project)),
|
|
52
|
+
total: page.total,
|
|
53
|
+
nextCursor: page.nextCursor,
|
|
54
|
+
...page.folders ? {
|
|
55
|
+
folders: page.folders
|
|
56
|
+
} : {},
|
|
57
|
+
...page.folderPath ? {
|
|
58
|
+
folderPath: page.folderPath
|
|
59
|
+
} : {},
|
|
60
|
+
...page.sourceCursors ? {
|
|
61
|
+
sourceCursors: page.sourceCursors
|
|
62
|
+
} : {}
|
|
63
|
+
};
|
|
64
|
+
},
|
|
65
|
+
upload: base.upload,
|
|
66
|
+
setTags: base.setTags,
|
|
67
|
+
subscribeUploads: base.subscribeUploads,
|
|
68
|
+
getUrl: (assetId)=>createAssetReference(assetId),
|
|
69
|
+
async delete (assetId) {
|
|
70
|
+
await source.remove(assetId);
|
|
71
|
+
},
|
|
72
|
+
async rename (assetId, nextName) {
|
|
73
|
+
await source.rename(assetId, nextName);
|
|
74
|
+
},
|
|
75
|
+
async replace (assetId, file) {
|
|
76
|
+
return project(await source.replace(assetId, file));
|
|
77
|
+
},
|
|
78
|
+
subscribe: (listener)=>source.subscribe(listener),
|
|
79
|
+
createFolder: (parentId, name)=>source.createFolder(parentId, name),
|
|
80
|
+
renameFolder: (id, name)=>source.renameFolder(id, name),
|
|
81
|
+
removeFolder: (id, opts)=>source.removeFolder(id, opts),
|
|
82
|
+
moveFolder: (id, parentId)=>source.moveFolder(id, parentId),
|
|
83
|
+
moveAsset: (assetId, folderId)=>source.move(assetId, folderId),
|
|
84
|
+
async pickResult (asset) {
|
|
85
|
+
const provider = providers.find((p)=>p.id === asset.source);
|
|
86
|
+
if (void 0 === provider || "local" === provider.id) return asset;
|
|
87
|
+
const result = await provider.pickResult(asset);
|
|
88
|
+
registry.register(result);
|
|
89
|
+
return project(result);
|
|
90
|
+
},
|
|
91
|
+
subscribeStatus: (listener)=>source.subscribeStatus(listener),
|
|
92
|
+
async listThemes () {
|
|
93
|
+
const themeLists = await Promise.all(providers.flatMap((provider)=>"local" === provider.id ? [] : [
|
|
94
|
+
provider.listThemes()
|
|
95
|
+
]));
|
|
96
|
+
return themeLists.flat();
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
export { createCompositeAssetSource };
|