payload-plugin-aspect-preview 0.2.1 → 0.2.2

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.
@@ -8,18 +8,15 @@ import { DEFAULT_ASPECT_RATIOS } from '../defaults';
8
8
  import { toCropRelativeFocal, toFullImageFocal } from '../focal';
9
9
  import { AspectRatioPreviewGrid } from './AspectRatioPreviewGrid';
10
10
  export const FocalPointEditor = ()=>{
11
- const { data } = useDocumentInfo();
11
+ const { collectionSlug, data } = useDocumentInfo();
12
12
  const { setModified } = useForm();
13
13
  const { uploadEdits, updateUploadEdits } = useUploadEdits();
14
- const { getEntityConfig } = useConfig();
15
- // Read the ratios the plugin stashed in the collection's `custom` config.
16
- // Falls back to the shipped defaults so the editor renders even if a
17
- // consumer wired the field without options.
18
- const collectionSlug = typeof data?.collection === 'string' ? data.collection : undefined;
19
- const entityConfig = collectionSlug ? getEntityConfig({
20
- collectionSlug
21
- }) : undefined;
22
- const aspectRatios = entityConfig?.custom?.aspectPreview?.aspectRatios ?? DEFAULT_ASPECT_RATIOS;
14
+ const { config } = useConfig();
15
+ // Read the ratios the plugin stashed in `admin.custom` (the collection's own
16
+ // `custom` never reaches the client). Falls back to the shipped defaults so
17
+ // the editor renders even if a consumer wired the field without options.
18
+ const stashed = config.admin?.custom?.aspectPreview;
19
+ const aspectRatios = (collectionSlug ? stashed?.[collectionSlug]?.aspectRatios : undefined) ?? DEFAULT_ASPECT_RATIOS;
23
20
  const hasUserEditedRef = useRef(false);
24
21
  // The freshly-picked File lives in the shared `file` form field (set by the
25
22
  // upload component) before the document is saved. Reading it here lets us
package/dist/plugin.js CHANGED
@@ -28,8 +28,26 @@ const UPLOAD_COMPONENT = 'payload-plugin-aspect-preview/client#CustomUpload';
28
28
  */ export const aspectPreviewPlugin = (options)=>(config)=>{
29
29
  const aspectRatios = options.aspectRatios ?? DEFAULT_ASPECT_RATIOS;
30
30
  const enabled = new Set(options.collections);
31
+ // Payload strips `collection.custom` from the client config, so the editor
32
+ // could never see it. `admin.custom` is forwarded to the browser.
33
+ const byCollection = Object.fromEntries(options.collections.map((slug)=>[
34
+ slug,
35
+ {
36
+ aspectRatios
37
+ }
38
+ ]));
31
39
  return {
32
40
  ...config,
41
+ admin: {
42
+ ...config.admin,
43
+ custom: {
44
+ ...config.admin?.custom,
45
+ aspectPreview: {
46
+ ...config.admin?.custom?.aspectPreview,
47
+ ...byCollection
48
+ }
49
+ }
50
+ },
33
51
  collections: config.collections?.map((collection)=>{
34
52
  if (!enabled.has(collection.slug)) return collection;
35
53
  const next = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payload-plugin-aspect-preview",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Single-screen crop, focal point, and live multi-aspect-ratio preview editor for Payload upload collections.",
5
5
  "keywords": [
6
6
  "payload",