@payloadcms/ui 4.0.0-canary.5 → 4.0.0-canary.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/LICENSE.md +1 -1
- package/dist/css/forms.css +6 -3
- package/dist/css/theme.css +2 -1
- package/dist/elements/AddNewRelation/index.css +1 -1
- package/dist/elements/DatePicker/index.css +1 -1
- package/dist/elements/DatePicker/index.js +1 -1
- package/dist/elements/DatePicker/index.js.map +1 -1
- package/dist/elements/DocumentFields/index.css +1 -0
- package/dist/elements/EditUpload/index.d.ts.map +1 -1
- package/dist/elements/EditUpload/index.js +4 -0
- package/dist/elements/EditUpload/index.js.map +1 -1
- package/dist/elements/Hierarchy/ColumnBrowser/Column/index.css +3 -1
- package/dist/elements/Hierarchy/ColumnBrowser/ColumnItem/index.css +1 -0
- package/dist/elements/Hierarchy/ColumnBrowser/types.d.ts +1 -1
- package/dist/elements/Hierarchy/ColumnBrowser/types.d.ts.map +1 -1
- package/dist/elements/Hierarchy/ColumnBrowser/types.js.map +1 -1
- package/dist/elements/Hierarchy/DocHeaderButton/index.js +12 -12
- package/dist/elements/Hierarchy/DocHeaderButton/index.js.map +1 -1
- package/dist/elements/Hierarchy/Field/index.client.js +14 -14
- package/dist/elements/Hierarchy/Field/index.client.js.map +1 -1
- package/dist/elements/Hierarchy/Modal/fetchAncestorPath.d.ts.map +1 -0
- package/dist/elements/Hierarchy/Modal/fetchAncestorPath.js.map +1 -0
- package/dist/elements/Hierarchy/Modal/index.css +88 -0
- package/dist/elements/Hierarchy/Modal/index.d.ts +20 -0
- package/dist/elements/Hierarchy/Modal/index.d.ts.map +1 -0
- package/dist/elements/Hierarchy/{Drawer → Modal}/index.js +105 -81
- package/dist/elements/Hierarchy/Modal/index.js.map +1 -0
- package/dist/elements/Hierarchy/{Drawer → Modal}/types.d.ts +22 -18
- package/dist/elements/Hierarchy/Modal/types.d.ts.map +1 -0
- package/dist/elements/Hierarchy/Modal/types.js.map +1 -0
- package/dist/elements/Hierarchy/Modal/useHierarchyModal.d.ts +30 -0
- package/dist/elements/Hierarchy/Modal/useHierarchyModal.d.ts.map +1 -0
- package/dist/elements/Hierarchy/{Drawer/useHierarchyDrawer.js → Modal/useHierarchyModal.js} +51 -50
- package/dist/elements/Hierarchy/Modal/useHierarchyModal.js.map +1 -0
- package/dist/elements/Hierarchy/MoveMany/index.d.ts +2 -2
- package/dist/elements/Hierarchy/MoveMany/index.d.ts.map +1 -1
- package/dist/elements/Hierarchy/MoveMany/index.js +9 -9
- package/dist/elements/Hierarchy/MoveMany/index.js.map +1 -1
- package/dist/elements/LivePreview/Toolbar/SizeInput/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/Toolbar/SizeInput/index.js +1 -0
- package/dist/elements/LivePreview/Toolbar/SizeInput/index.js.map +1 -1
- package/dist/elements/LivePreview/Window/index.css +6 -0
- package/dist/elements/ReactSelect/index.css +2 -2
- package/dist/elements/ReactSelect/index.js +1 -1
- package/dist/elements/ReactSelect/index.js.map +1 -1
- package/dist/elements/RelationshipTable/index.css +1 -2
- package/dist/elements/Table/DefaultCell/fields/Hierarchy/index.js +24 -24
- package/dist/elements/Table/DefaultCell/fields/Hierarchy/index.js.map +1 -1
- package/dist/elements/Table/index.css +7 -2
- package/dist/elements/TimezonePicker/index.css +1 -1
- package/dist/exports/client/index.d.ts +3 -2
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +26 -26
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +2 -0
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +2 -0
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/fields/ConfirmPassword/index.d.ts +4 -0
- package/dist/fields/ConfirmPassword/index.d.ts.map +1 -1
- package/dist/fields/ConfirmPassword/index.js +37 -33
- package/dist/fields/ConfirmPassword/index.js.map +1 -1
- package/dist/fields/Number/Input.d.ts.map +1 -1
- package/dist/fields/Number/Input.js +29 -25
- package/dist/fields/Number/Input.js.map +1 -1
- package/dist/fields/Number/types.d.ts +4 -0
- package/dist/fields/Number/types.d.ts.map +1 -1
- package/dist/fields/Number/types.js.map +1 -1
- package/dist/fields/Password/input.d.ts.map +1 -1
- package/dist/fields/Password/input.js +33 -29
- package/dist/fields/Password/input.js.map +1 -1
- package/dist/fields/Password/types.d.ts +4 -0
- package/dist/fields/Password/types.d.ts.map +1 -1
- package/dist/fields/Password/types.js.map +1 -1
- package/dist/fields/Relationship/Input.d.ts.map +1 -1
- package/dist/fields/Relationship/Input.js +2 -0
- package/dist/fields/Relationship/Input.js.map +1 -1
- package/dist/fields/Relationship/types.d.ts +4 -0
- package/dist/fields/Relationship/types.d.ts.map +1 -1
- package/dist/fields/Relationship/types.js.map +1 -1
- package/dist/fields/Select/Input.d.ts +4 -0
- package/dist/fields/Select/Input.d.ts.map +1 -1
- package/dist/fields/Select/Input.js +44 -40
- package/dist/fields/Select/Input.js.map +1 -1
- package/dist/fields/Text/Input.d.ts.map +1 -1
- package/dist/fields/Text/Input.js +25 -21
- package/dist/fields/Text/Input.js.map +1 -1
- package/dist/fields/Text/types.d.ts +4 -0
- package/dist/fields/Text/types.d.ts.map +1 -1
- package/dist/fields/Text/types.js.map +1 -1
- package/dist/fields/Textarea/Input.d.ts.map +1 -1
- package/dist/fields/Textarea/Input.js +27 -23
- package/dist/fields/Textarea/Input.js.map +1 -1
- package/dist/fields/Textarea/index.css +1 -1
- package/dist/fields/Textarea/types.d.ts +4 -0
- package/dist/fields/Textarea/types.d.ts.map +1 -1
- package/dist/fields/Textarea/types.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts +1 -0
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +9 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/index.d.ts +2 -1
- package/dist/forms/fieldSchemasToFormState/index.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/index.js +2 -0
- package/dist/forms/fieldSchemasToFormState/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts +2 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/iterateFields.js +2 -0
- package/dist/forms/fieldSchemasToFormState/iterateFields.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +1 -0
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/formatRelativeDate.d.ts +15 -0
- package/dist/utilities/formatRelativeDate.d.ts.map +1 -0
- package/dist/utilities/formatRelativeDate.js +62 -0
- package/dist/utilities/formatRelativeDate.js.map +1 -0
- package/dist/utilities/recentlyViewed.d.ts +16 -0
- package/dist/utilities/recentlyViewed.d.ts.map +1 -0
- package/dist/utilities/recentlyViewed.js +21 -0
- package/dist/utilities/recentlyViewed.js.map +1 -0
- package/dist/utilities/recentlyViewed.spec.js +92 -0
- package/dist/utilities/recentlyViewed.spec.js.map +1 -0
- package/dist/views/Document/index.d.ts.map +1 -1
- package/dist/views/Document/index.js +9 -0
- package/dist/views/Document/index.js.map +1 -1
- package/dist/views/Document/recordRecentlyViewed.d.ts +12 -0
- package/dist/views/Document/recordRecentlyViewed.d.ts.map +1 -0
- package/dist/views/Document/recordRecentlyViewed.js +40 -0
- package/dist/views/Document/recordRecentlyViewed.js.map +1 -0
- package/dist/widgets/CollectionQuery/index.css +10 -152
- package/dist/widgets/CollectionQuery/index.d.ts +0 -1
- package/dist/widgets/CollectionQuery/index.d.ts.map +1 -1
- package/dist/widgets/CollectionQuery/index.js +40 -111
- package/dist/widgets/CollectionQuery/index.js.map +1 -1
- package/dist/widgets/RecentlyViewed/CollectionsField/index.css +14 -0
- package/dist/widgets/RecentlyViewed/CollectionsField/index.d.ts +10 -0
- package/dist/widgets/RecentlyViewed/CollectionsField/index.d.ts.map +1 -0
- package/dist/widgets/RecentlyViewed/CollectionsField/index.js +76 -0
- package/dist/widgets/RecentlyViewed/CollectionsField/index.js.map +1 -0
- package/dist/widgets/RecentlyViewed/index.d.ts +10 -0
- package/dist/widgets/RecentlyViewed/index.d.ts.map +1 -0
- package/dist/widgets/RecentlyViewed/index.js +148 -0
- package/dist/widgets/RecentlyViewed/index.js.map +1 -0
- package/dist/widgets/WidgetCard/index.css +155 -0
- package/dist/widgets/WidgetCard/index.d.ts +19 -0
- package/dist/widgets/WidgetCard/index.d.ts.map +1 -0
- package/dist/widgets/WidgetCard/index.js +49 -0
- package/dist/widgets/WidgetCard/index.js.map +1 -0
- package/package.json +4 -4
- package/dist/elements/Hierarchy/Drawer/fetchAncestorPath.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/fetchAncestorPath.js.map +0 -1
- package/dist/elements/Hierarchy/Drawer/index.css +0 -90
- package/dist/elements/Hierarchy/Drawer/index.d.ts +0 -20
- package/dist/elements/Hierarchy/Drawer/index.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/index.js.map +0 -1
- package/dist/elements/Hierarchy/Drawer/types.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/types.js.map +0 -1
- package/dist/elements/Hierarchy/Drawer/useHierarchyDrawer.d.ts +0 -30
- package/dist/elements/Hierarchy/Drawer/useHierarchyDrawer.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/useHierarchyDrawer.js.map +0 -1
- /package/dist/elements/Hierarchy/{Drawer → Modal}/fetchAncestorPath.d.ts +0 -0
- /package/dist/elements/Hierarchy/{Drawer → Modal}/fetchAncestorPath.js +0 -0
- /package/dist/elements/Hierarchy/{Drawer → Modal}/types.js +0 -0
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2018-
|
|
3
|
+
Copyright (c) 2018-2026 Payload CMS, LLC <info@payloadcms.com>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
6
|
a copy of this software and associated documentation files (the
|
package/dist/css/forms.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@layer payload-default {
|
|
2
2
|
.form-input {
|
|
3
3
|
width: 100%;
|
|
4
|
-
min-height: var(--field-min-height);
|
|
4
|
+
min-height: var(--field-min-height-large);
|
|
5
5
|
background: var(--field-color-bg);
|
|
6
6
|
border: var(--stroke-width-small) solid var(--field-color-border);
|
|
7
7
|
border-radius: var(--field-border-radius);
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
background: var(--field-color-bg);
|
|
70
70
|
border: var(--stroke-width-small) solid var(--field-color-border);
|
|
71
71
|
border-radius: var(--field-border-radius);
|
|
72
|
-
min-height: var(--field-min-height);
|
|
72
|
+
min-height: var(--field-min-height-large);
|
|
73
73
|
transition-property: box-shadow, background-color;
|
|
74
74
|
transition-duration: 100ms;
|
|
75
75
|
transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
|
|
@@ -91,7 +91,6 @@
|
|
|
91
91
|
|
|
92
92
|
input.form-input {
|
|
93
93
|
flex: 1 1 0%;
|
|
94
|
-
width: 0;
|
|
95
94
|
min-width: 0;
|
|
96
95
|
background: transparent;
|
|
97
96
|
border: none;
|
|
@@ -112,4 +111,8 @@
|
|
|
112
111
|
border-color: var(--field-color-border-focus);
|
|
113
112
|
}
|
|
114
113
|
}
|
|
114
|
+
|
|
115
|
+
.field-type[data-size='medium'] {
|
|
116
|
+
--field-min-height-large: var(--field-min-height-medium);
|
|
117
|
+
}
|
|
115
118
|
}
|
package/dist/css/theme.css
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
@layer payload-default {
|
|
11
11
|
:root {
|
|
12
12
|
/* Fields — controls text inputs, selects, date pickers, code editors, etc. */
|
|
13
|
-
--field-min-height: var(--spacer-5);
|
|
13
|
+
--field-min-height-large: var(--spacer-5);
|
|
14
|
+
--field-min-height-medium: var(--spacer-4);
|
|
14
15
|
--field-padding-inline: var(--spacer-2);
|
|
15
16
|
--field-border-radius: var(--radius-medium);
|
|
16
17
|
|
|
@@ -827,7 +827,7 @@
|
|
|
827
827
|
font-weight: var(--text-body-medium-font-weight);
|
|
828
828
|
line-height: var(--text-body-medium-line-height);
|
|
829
829
|
width: 100%;
|
|
830
|
-
min-height: var(--field-min-height);
|
|
830
|
+
min-height: var(--field-min-height-large);
|
|
831
831
|
border: var(--stroke-width-small) solid var(--field-color-border);
|
|
832
832
|
border-radius: var(--field-border-radius);
|
|
833
833
|
background: var(--field-color-bg);
|
|
@@ -6,7 +6,7 @@ import { ShimmerEffect } from '../ShimmerEffect/index.js';
|
|
|
6
6
|
const DatePicker = /*#__PURE__*/lazy(() => import('./DatePicker.js'));
|
|
7
7
|
export const DatePickerField = props => /*#__PURE__*/_jsx(Suspense, {
|
|
8
8
|
fallback: /*#__PURE__*/_jsx(ShimmerEffect, {
|
|
9
|
-
height: "var(--field-min-height)"
|
|
9
|
+
height: "var(--field-min-height-large)"
|
|
10
10
|
}),
|
|
11
11
|
children: /*#__PURE__*/_jsx(DatePicker, {
|
|
12
12
|
...props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","lazy","Suspense","ShimmerEffect","DatePicker","DatePickerField","props","_jsx","fallback","height"],"sources":["../../../src/elements/DatePicker/index.tsx"],"sourcesContent":["'use client'\nimport React, { lazy, Suspense } from 'react'\n\nimport type { Props } from './types.js'\n\nimport { ShimmerEffect } from '../ShimmerEffect/index.js'\n\nconst DatePicker = lazy(() => import('./DatePicker.js'))\n\nexport const DatePickerField: React.FC<Props> = (props) => (\n <Suspense fallback={<ShimmerEffect height=\"var(--field-min-height)\" />}>\n <DatePicker {...props} />\n </Suspense>\n)\n"],"mappings":"AAAA;;;AACA,OAAOA,KAAA,IAASC,IAAI,EAAEC,QAAQ,QAAQ;AAItC,SAASC,aAAa,QAAQ;AAE9B,MAAMC,UAAA,gBAAaH,IAAA,CAAK,MAAM,MAAM,CAAC;AAErC,OAAO,MAAMI,eAAA,GAAoCC,KAAA,iBAC/CC,IAAA,CAACL,QAAA;EAASM,QAAA,eAAUD,IAAA,CAACJ,aAAA;IAAcM,MAAA,EAAO;;YACxC,aAAAF,IAAA,CAACH,UAAA;IAAY,GAAGE","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","lazy","Suspense","ShimmerEffect","DatePicker","DatePickerField","props","_jsx","fallback","height"],"sources":["../../../src/elements/DatePicker/index.tsx"],"sourcesContent":["'use client'\nimport React, { lazy, Suspense } from 'react'\n\nimport type { Props } from './types.js'\n\nimport { ShimmerEffect } from '../ShimmerEffect/index.js'\n\nconst DatePicker = lazy(() => import('./DatePicker.js'))\n\nexport const DatePickerField: React.FC<Props> = (props) => (\n <Suspense fallback={<ShimmerEffect height=\"var(--field-min-height-large)\" />}>\n <DatePicker {...props} />\n </Suspense>\n)\n"],"mappings":"AAAA;;;AACA,OAAOA,KAAA,IAASC,IAAI,EAAEC,QAAQ,QAAQ;AAItC,SAASC,aAAa,QAAQ;AAE9B,MAAMC,UAAA,gBAAaH,IAAA,CAAK,MAAM,MAAM,CAAC;AAErC,OAAO,MAAMI,eAAA,GAAoCC,KAAA,iBAC/CC,IAAA,CAACL,QAAA;EAASM,QAAA,eAAUD,IAAA,CAACJ,aAAA;IAAcM,MAAA,EAAO;;YACxC,aAAAF,IAAA,CAACH,UAAA;IAAY,GAAGE","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/EditUpload/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C,OAAO,KAA2B,MAAM,OAAO,CAAA;AAW/C,OAAO,aAAa,CAAA;AACpB,OAAO,eAAe,CAAA;AAItB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ACzB,CAAA;AAUD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAgQhD,CAAA"}
|
|
@@ -205,6 +205,7 @@ export const EditUpload = ({
|
|
|
205
205
|
path: "cropWidth",
|
|
206
206
|
prefix: "W",
|
|
207
207
|
readOnly: !imageLoaded,
|
|
208
|
+
size: "medium",
|
|
208
209
|
value: Number(cropWidthPx)
|
|
209
210
|
}), /*#__PURE__*/_jsx(NumberInput, {
|
|
210
211
|
ariaLabel: t('upload:height'),
|
|
@@ -215,6 +216,7 @@ export const EditUpload = ({
|
|
|
215
216
|
path: "cropHeight",
|
|
216
217
|
prefix: "H",
|
|
217
218
|
readOnly: !imageLoaded,
|
|
219
|
+
size: "medium",
|
|
218
220
|
value: Number(cropHeightPx)
|
|
219
221
|
})]
|
|
220
222
|
})]
|
|
@@ -244,6 +246,7 @@ export const EditUpload = ({
|
|
|
244
246
|
}),
|
|
245
247
|
path: "focalX",
|
|
246
248
|
prefix: "X",
|
|
249
|
+
size: "medium",
|
|
247
250
|
suffix: "%",
|
|
248
251
|
value: Math.round(focalPosition.x)
|
|
249
252
|
}), /*#__PURE__*/_jsx(NumberInput, {
|
|
@@ -256,6 +259,7 @@ export const EditUpload = ({
|
|
|
256
259
|
}),
|
|
257
260
|
path: "focalY",
|
|
258
261
|
prefix: "Y",
|
|
262
|
+
size: "medium",
|
|
259
263
|
suffix: "%",
|
|
260
264
|
value: Math.round(focalPosition.y)
|
|
261
265
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["useModal","React","useRef","useState","ReactCrop","editDrawerSlug","NumberInput","PlusIcon","ResetIcon","useTranslation","appendCacheTag","Button","DialogFooter","DialogHeader","DialogModal","baseClass","defaultCrop","height","unit","width","x","y","EditUpload","fileName","fileSrc","imageCacheTag","initialCrop","initialFocalPoint","onSave","showCrop","showFocalPoint","closeModal","t","crop","setCrop","defaultFocalPosition","focalPosition","setFocalPosition","checkBounds","setCheckBounds","uncroppedPixelHeight","setUncroppedPixelHeight","uncroppedPixelWidth","setUncroppedPixelWidth","focalWrapRef","undefined","imageRef","cropRef","imageLoaded","setImageLoaded","onImageLoad","e","currentTarget","naturalHeight","naturalWidth","fineTuneCrop","dimension","value","intValue","parseInt","Number","isNaN","percentage","prev","fineTuneFocalPosition","coordinate","prevPosition","saveEdits","focalPoint","heightInPixels","Math","round","widthInPixels","onDragEnd","useCallback","centerFocalPoint","fileSrcToUse","cropWidthPx","toFixed","cropHeightPx","_jsxs","className","closeOnBlur","size","slug","_jsx","showClose","title","ref","style","aspectRatio","onChange","_","c","onComplete","renderSelectionAddon","alt","onLoad","src","DraggableElement","boundsRef","containerRef","initialPosition","onClick","type","ariaLabel","target","path","prefix","readOnly","max","min","suffix","buttonStyle","disabled","children","position","setPosition","isDragging","setIsDragging","dragRef","positionRef","current","getCoordinates","mouseX","mouseY","containerRect","getBoundingClientRect","left","top","handleMouseDown","event","preventDefault","useEffect","handleMove","clientX","clientY","handleUp","document","addEventListener","removeEventListener","filter","Boolean","join","onMouseDown"],"sources":["../../../src/elements/EditUpload/index.tsx"],"sourcesContent":["'use client'\n\nimport type { UploadEdits } from 'payload'\n\nimport { useModal } from '@faceless-ui/modal'\nimport React, { useRef, useState } from 'react'\nimport ReactCrop from 'react-image-crop'\n\nimport { editDrawerSlug } from '../../elements/Upload/index.js'\nimport { NumberInput } from '../../fields/Number/index.js'\nimport { PlusIcon } from '../../icons/Plus/index.js'\nimport { ResetIcon } from '../../icons/Reset/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { appendCacheTag } from '../../utilities/appendCacheTag.js'\nimport { Button } from '../Button/index.js'\nimport { DialogFooter, DialogHeader, DialogModal } from '../Dialog/index.js'\nimport './index.css'\nimport './library.css'\n\nconst baseClass = 'edit-upload'\n\ntype FocalPosition = {\n x: number\n y: number\n}\n\nexport type EditUploadProps = {\n fileName: string\n fileSrc: string\n imageCacheTag?: false | string\n initialCrop?: UploadEdits['crop']\n initialFocalPoint?: FocalPosition\n onSave?: (uploadEdits: UploadEdits) => void\n showCrop?: boolean\n showFocalPoint?: boolean\n}\n\nconst defaultCrop: UploadEdits['crop'] = {\n height: 100,\n unit: '%',\n width: 100,\n x: 0,\n y: 0,\n}\n\nexport const EditUpload: React.FC<EditUploadProps> = ({\n fileName,\n fileSrc,\n imageCacheTag,\n initialCrop,\n initialFocalPoint,\n onSave,\n showCrop,\n showFocalPoint,\n}) => {\n const { closeModal } = useModal()\n const { t } = useTranslation()\n\n const [crop, setCrop] = useState<UploadEdits['crop']>(() => ({\n ...defaultCrop,\n ...(initialCrop || {}),\n }))\n\n const defaultFocalPosition: FocalPosition = { x: 50, y: 50 }\n\n const [focalPosition, setFocalPosition] = useState<FocalPosition>(() => ({\n ...defaultFocalPosition,\n ...initialFocalPoint,\n }))\n\n const [checkBounds, setCheckBounds] = useState<boolean>(false)\n const [uncroppedPixelHeight, setUncroppedPixelHeight] = useState<number>(0)\n const [uncroppedPixelWidth, setUncroppedPixelWidth] = useState<number>(0)\n\n const focalWrapRef = useRef<HTMLDivElement | undefined>(undefined)\n const imageRef = useRef<HTMLImageElement | undefined>(undefined)\n const cropRef = useRef<HTMLDivElement | undefined>(undefined)\n\n const [imageLoaded, setImageLoaded] = useState<boolean>(false)\n\n const onImageLoad = (e) => {\n setUncroppedPixelHeight(e.currentTarget.naturalHeight)\n setUncroppedPixelWidth(e.currentTarget.naturalWidth)\n setImageLoaded(true)\n }\n\n const fineTuneCrop = ({ dimension, value }: { dimension: 'height' | 'width'; value: string }) => {\n const intValue = parseInt(value)\n if (Number.isNaN(intValue)) {\n return null\n }\n const percentage =\n 100 * (intValue / (dimension === 'width' ? uncroppedPixelWidth : uncroppedPixelHeight))\n if (percentage <= 0 || percentage > 100) {\n return null\n }\n setCrop((prev) => ({ ...prev, [dimension]: percentage }))\n }\n\n const fineTuneFocalPosition = ({\n coordinate,\n value,\n }: {\n coordinate: 'x' | 'y'\n value: string\n }) => {\n const intValue = parseInt(value)\n if (intValue >= 0 && intValue <= 100) {\n setFocalPosition((prevPosition) => ({ ...prevPosition, [coordinate]: intValue }))\n }\n }\n\n const saveEdits = () => {\n if (typeof onSave === 'function') {\n onSave({\n crop: crop ? crop : undefined,\n focalPoint: focalPosition,\n heightInPixels: Math.round((crop.height / 100) * uncroppedPixelHeight),\n widthInPixels: Math.round((crop.width / 100) * uncroppedPixelWidth),\n })\n }\n closeModal(editDrawerSlug)\n }\n\n const onDragEnd = React.useCallback(({ x, y }) => {\n setFocalPosition({ x, y })\n setCheckBounds(false)\n }, [])\n\n const centerFocalPoint = () => {\n setFocalPosition({ x: 50, y: 50 })\n }\n\n const fileSrcToUse = fileSrc ? appendCacheTag(fileSrc, imageCacheTag) : undefined\n\n const cropWidthPx = ((crop.width / 100) * uncroppedPixelWidth).toFixed(0)\n const cropHeightPx = ((crop.height / 100) * uncroppedPixelHeight).toFixed(0)\n\n return (\n <DialogModal\n className={`${baseClass}__dialog`}\n closeOnBlur={false}\n size=\"large\"\n slug={editDrawerSlug}\n >\n <DialogHeader showClose title={`${t('general:editing')} ${fileName}`} />\n <div className={`${baseClass}__body`}>\n <div className={`${baseClass}__content`}>\n {/* Canvas area */}\n <div className={`${baseClass}__crop`}>\n <div\n className={`${baseClass}__focal-wrapper`}\n ref={focalWrapRef}\n style={{ aspectRatio: `${uncroppedPixelWidth / uncroppedPixelHeight}` }}\n >\n {showCrop ? (\n <ReactCrop\n className={`${baseClass}__reactCrop`}\n crop={crop}\n onChange={(_, c) => setCrop(c)}\n onComplete={() => setCheckBounds(true)}\n renderSelectionAddon={() => (\n <div className={`${baseClass}__crop-window`} ref={cropRef} />\n )}\n >\n <img\n alt={t('upload:setCropArea')}\n onLoad={onImageLoad}\n ref={imageRef}\n src={fileSrcToUse}\n />\n </ReactCrop>\n ) : (\n <img\n alt={t('upload:setFocalPoint')}\n onLoad={onImageLoad}\n ref={imageRef}\n src={fileSrcToUse}\n />\n )}\n {showFocalPoint && (\n <DraggableElement\n boundsRef={showCrop ? cropRef : imageRef}\n checkBounds={showCrop ? checkBounds : false}\n className={`${baseClass}__focalPoint`}\n containerRef={focalWrapRef}\n initialPosition={focalPosition}\n onDragEnd={onDragEnd}\n setCheckBounds={showCrop ? setCheckBounds : false}\n >\n <PlusIcon />\n </DraggableElement>\n )}\n </div>\n </div>\n\n {/* Sidebar */}\n {(showCrop || showFocalPoint) && (\n <div className={`${baseClass}__sidebar`}>\n {showCrop && (\n <div className={`${baseClass}__section`}>\n <div className={`${baseClass}__section-header`}>\n <span className={`${baseClass}__section-title`}>{t('upload:crop')}</span>\n <button\n aria-label={t('general:reset')}\n className={`${baseClass}__reset`}\n onClick={() => setCrop({ height: 100, unit: '%', width: 100, x: 0, y: 0 })}\n type=\"button\"\n >\n <ResetIcon />\n </button>\n </div>\n <div className={`${baseClass}__fieldset`}>\n <NumberInput\n ariaLabel={t('upload:width')}\n onChange={(e) => fineTuneCrop({ dimension: 'width', value: e.target.value })}\n path=\"cropWidth\"\n prefix=\"W\"\n readOnly={!imageLoaded}\n value={Number(cropWidthPx)}\n />\n <NumberInput\n ariaLabel={t('upload:height')}\n onChange={(e) => fineTuneCrop({ dimension: 'height', value: e.target.value })}\n path=\"cropHeight\"\n prefix=\"H\"\n readOnly={!imageLoaded}\n value={Number(cropHeightPx)}\n />\n </div>\n </div>\n )}\n\n {showFocalPoint && (\n <div className={`${baseClass}__section`}>\n <div className={`${baseClass}__section-header`}>\n <span className={`${baseClass}__section-title`}>{t('upload:focalPoint')}</span>\n <button\n aria-label={t('general:reset')}\n className={`${baseClass}__reset`}\n onClick={centerFocalPoint}\n type=\"button\"\n >\n <ResetIcon />\n </button>\n </div>\n <div className={`${baseClass}__fieldset`}>\n <NumberInput\n ariaLabel={`${t('upload:focalPoint')} X`}\n max={100}\n min={0}\n onChange={(e) =>\n fineTuneFocalPosition({ coordinate: 'x', value: e.target.value })\n }\n path=\"focalX\"\n prefix=\"X\"\n suffix=\"%\"\n value={Math.round(focalPosition.x)}\n />\n <NumberInput\n ariaLabel={`${t('upload:focalPoint')} Y`}\n max={100}\n min={0}\n onChange={(e) =>\n fineTuneFocalPosition({ coordinate: 'y', value: e.target.value })\n }\n path=\"focalY\"\n prefix=\"Y\"\n suffix=\"%\"\n value={Math.round(focalPosition.y)}\n />\n </div>\n </div>\n )}\n </div>\n )}\n </div>\n </div>\n <DialogFooter>\n <Button\n aria-label={t('general:cancel')}\n buttonStyle=\"secondary\"\n onClick={() => closeModal(editDrawerSlug)}\n >\n {t('general:cancel')}\n </Button>\n <Button\n aria-label={t('general:applyChanges')}\n buttonStyle=\"primary\"\n disabled={!imageLoaded}\n onClick={saveEdits}\n >\n {t('general:applyChanges')}\n </Button>\n </DialogFooter>\n </DialogModal>\n )\n}\n\nconst DraggableElement = ({\n boundsRef,\n checkBounds,\n children,\n className,\n containerRef,\n initialPosition = { x: 50, y: 50 },\n onDragEnd,\n setCheckBounds,\n}) => {\n const [position, setPosition] = useState({ x: initialPosition.x, y: initialPosition.y })\n const [isDragging, setIsDragging] = useState(false)\n const dragRef = useRef<HTMLButtonElement | undefined>(undefined)\n // Keep a ref to the latest position so global mouseup handler can read it without a stale closure\n const positionRef = useRef(position)\n positionRef.current = position\n\n const getCoordinates = React.useCallback(\n (mouseX: number, mouseY: number) => {\n const containerRect = containerRef.current.getBoundingClientRect()\n const x = ((mouseX - containerRect.left) / containerRect.width) * 100\n const y = ((mouseY - containerRect.top) / containerRect.height) * 100\n return { x: Math.max(0, Math.min(100, x)), y: Math.max(0, Math.min(100, y)) }\n },\n [containerRef],\n )\n\n const handleMouseDown = (event) => {\n event.preventDefault()\n setIsDragging(true)\n }\n\n // Attach global listeners while dragging — this ensures events fire even when\n // the cursor leaves the focal wrapper area during a fast drag\n React.useEffect(() => {\n if (!isDragging) {\n return\n }\n\n const handleMove = (e: MouseEvent) => {\n if (!containerRef.current) {\n return\n }\n const { x, y } = getCoordinates(e.clientX, e.clientY)\n setPosition({ x, y })\n }\n\n const handleUp = () => {\n setIsDragging(false)\n onDragEnd(positionRef.current)\n }\n\n document.addEventListener('mousemove', handleMove)\n document.addEventListener('mouseup', handleUp)\n\n return () => {\n document.removeEventListener('mousemove', handleMove)\n document.removeEventListener('mouseup', handleUp)\n }\n }, [isDragging, getCoordinates, onDragEnd, containerRef])\n\n // Re-check position when crop changes (the crop window may have moved)\n React.useEffect(() => {\n if (isDragging || !checkBounds || !dragRef.current) {\n return\n }\n const { height, left, top, width } = dragRef.current.getBoundingClientRect()\n const { x, y } = getCoordinates(left + width / 2, top + height / 2)\n onDragEnd({ x, y })\n setPosition({ x, y })\n setCheckBounds(false)\n }, [getCoordinates, isDragging, checkBounds, setCheckBounds, onDragEnd])\n\n React.useEffect(() => {\n setPosition({ x: initialPosition.x, y: initialPosition.y })\n }, [initialPosition.x, initialPosition.y])\n\n return (\n <div className={`${baseClass}__draggable-container`}>\n <button\n className={[`${baseClass}__draggable`, className].filter(Boolean).join(' ')}\n onMouseDown={handleMouseDown}\n ref={dragRef}\n style={{ left: `${position.x}%`, top: `${position.y}%` }}\n type=\"button\"\n >\n {children}\n </button>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,QAAQ,QAAQ;AACzB,OAAOC,KAAA,IAASC,MAAM,EAAEC,QAAQ,QAAQ;AACxC,OAAOC,SAAA,MAAe;AAEtB,SAASC,cAAc,QAAQ;AAC/B,SAASC,WAAW,QAAQ;AAC5B,SAASC,QAAQ,QAAQ;AACzB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,YAAY,EAAEC,YAAY,EAAEC,WAAW,QAAQ;AACxD,OAAO;AACP,OAAO;AAEP,MAAMC,SAAA,GAAY;AAkBlB,MAAMC,WAAA,GAAmC;EACvCC,MAAA,EAAQ;EACRC,IAAA,EAAM;EACNC,KAAA,EAAO;EACPC,CAAA,EAAG;EACHC,CAAA,EAAG;AACL;AAEA,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IAAE;IACnBkB,cAAA,CAAe;EACjB,GAAG,CAACoF,cAAA,EAAgBL,UAAA,EAAYhF,WAAA,EAAaC,cAAA,EAAgBkC,SAAA,CAAU;EAEvExE,KAAA,CAAMoI,SAAS,CAAC;IACdhB,WAAA,CAAY;MAAEjG,CAAA,EAAGkF,eAAA,CAAgBlF,CAAC;MAAEC,CAAA,EAAGiF,eAAA,CAAgBjF;IAAE;EAC3D,GAAG,CAACiF,eAAA,CAAgBlF,CAAC,EAAEkF,eAAA,CAAgBjF,CAAC,CAAC;EAEzC,oBACEgE,IAAA,CAAC;IAAIJ,SAAA,EAAW,GAAGlE,SAAA,uBAAgC;cACjD,aAAAsE,IAAA,CAAC;MACCJ,SAAA,EAAW,CAAC,GAAGlE,SAAA,aAAsB,EAAEkE,SAAA,CAAU,CAAC4D,MAAM,CAACC,OAAA,EAASC,IAAI,CAAC;MACvEC,WAAA,EAAad,eAAA;MACb1C,GAAA,EAAKgC,OAAA;MACL/B,KAAA,EAAO;QAAEuC,IAAA,EAAM,GAAGZ,QAAA,CAAShG,CAAC,GAAG;QAAE6G,GAAA,EAAK,GAAGb,QAAA,CAAS/F,CAAC;MAAI;MACvDmF,IAAA,EAAK;gBAEJW;;;AAIT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["useModal","React","useRef","useState","ReactCrop","editDrawerSlug","NumberInput","PlusIcon","ResetIcon","useTranslation","appendCacheTag","Button","DialogFooter","DialogHeader","DialogModal","baseClass","defaultCrop","height","unit","width","x","y","EditUpload","fileName","fileSrc","imageCacheTag","initialCrop","initialFocalPoint","onSave","showCrop","showFocalPoint","closeModal","t","crop","setCrop","defaultFocalPosition","focalPosition","setFocalPosition","checkBounds","setCheckBounds","uncroppedPixelHeight","setUncroppedPixelHeight","uncroppedPixelWidth","setUncroppedPixelWidth","focalWrapRef","undefined","imageRef","cropRef","imageLoaded","setImageLoaded","onImageLoad","e","currentTarget","naturalHeight","naturalWidth","fineTuneCrop","dimension","value","intValue","parseInt","Number","isNaN","percentage","prev","fineTuneFocalPosition","coordinate","prevPosition","saveEdits","focalPoint","heightInPixels","Math","round","widthInPixels","onDragEnd","useCallback","centerFocalPoint","fileSrcToUse","cropWidthPx","toFixed","cropHeightPx","_jsxs","className","closeOnBlur","size","slug","_jsx","showClose","title","ref","style","aspectRatio","onChange","_","c","onComplete","renderSelectionAddon","alt","onLoad","src","DraggableElement","boundsRef","containerRef","initialPosition","onClick","type","ariaLabel","target","path","prefix","readOnly","max","min","suffix","buttonStyle","disabled","children","position","setPosition","isDragging","setIsDragging","dragRef","positionRef","current","getCoordinates","mouseX","mouseY","containerRect","getBoundingClientRect","left","top","handleMouseDown","event","preventDefault","useEffect","handleMove","clientX","clientY","handleUp","document","addEventListener","removeEventListener","filter","Boolean","join","onMouseDown"],"sources":["../../../src/elements/EditUpload/index.tsx"],"sourcesContent":["'use client'\n\nimport type { UploadEdits } from 'payload'\n\nimport { useModal } from '@faceless-ui/modal'\nimport React, { useRef, useState } from 'react'\nimport ReactCrop from 'react-image-crop'\n\nimport { editDrawerSlug } from '../../elements/Upload/index.js'\nimport { NumberInput } from '../../fields/Number/index.js'\nimport { PlusIcon } from '../../icons/Plus/index.js'\nimport { ResetIcon } from '../../icons/Reset/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { appendCacheTag } from '../../utilities/appendCacheTag.js'\nimport { Button } from '../Button/index.js'\nimport { DialogFooter, DialogHeader, DialogModal } from '../Dialog/index.js'\nimport './index.css'\nimport './library.css'\n\nconst baseClass = 'edit-upload'\n\ntype FocalPosition = {\n x: number\n y: number\n}\n\nexport type EditUploadProps = {\n fileName: string\n fileSrc: string\n imageCacheTag?: false | string\n initialCrop?: UploadEdits['crop']\n initialFocalPoint?: FocalPosition\n onSave?: (uploadEdits: UploadEdits) => void\n showCrop?: boolean\n showFocalPoint?: boolean\n}\n\nconst defaultCrop: UploadEdits['crop'] = {\n height: 100,\n unit: '%',\n width: 100,\n x: 0,\n y: 0,\n}\n\nexport const EditUpload: React.FC<EditUploadProps> = ({\n fileName,\n fileSrc,\n imageCacheTag,\n initialCrop,\n initialFocalPoint,\n onSave,\n showCrop,\n showFocalPoint,\n}) => {\n const { closeModal } = useModal()\n const { t } = useTranslation()\n\n const [crop, setCrop] = useState<UploadEdits['crop']>(() => ({\n ...defaultCrop,\n ...(initialCrop || {}),\n }))\n\n const defaultFocalPosition: FocalPosition = { x: 50, y: 50 }\n\n const [focalPosition, setFocalPosition] = useState<FocalPosition>(() => ({\n ...defaultFocalPosition,\n ...initialFocalPoint,\n }))\n\n const [checkBounds, setCheckBounds] = useState<boolean>(false)\n const [uncroppedPixelHeight, setUncroppedPixelHeight] = useState<number>(0)\n const [uncroppedPixelWidth, setUncroppedPixelWidth] = useState<number>(0)\n\n const focalWrapRef = useRef<HTMLDivElement | undefined>(undefined)\n const imageRef = useRef<HTMLImageElement | undefined>(undefined)\n const cropRef = useRef<HTMLDivElement | undefined>(undefined)\n\n const [imageLoaded, setImageLoaded] = useState<boolean>(false)\n\n const onImageLoad = (e) => {\n setUncroppedPixelHeight(e.currentTarget.naturalHeight)\n setUncroppedPixelWidth(e.currentTarget.naturalWidth)\n setImageLoaded(true)\n }\n\n const fineTuneCrop = ({ dimension, value }: { dimension: 'height' | 'width'; value: string }) => {\n const intValue = parseInt(value)\n if (Number.isNaN(intValue)) {\n return null\n }\n const percentage =\n 100 * (intValue / (dimension === 'width' ? uncroppedPixelWidth : uncroppedPixelHeight))\n if (percentage <= 0 || percentage > 100) {\n return null\n }\n setCrop((prev) => ({ ...prev, [dimension]: percentage }))\n }\n\n const fineTuneFocalPosition = ({\n coordinate,\n value,\n }: {\n coordinate: 'x' | 'y'\n value: string\n }) => {\n const intValue = parseInt(value)\n if (intValue >= 0 && intValue <= 100) {\n setFocalPosition((prevPosition) => ({ ...prevPosition, [coordinate]: intValue }))\n }\n }\n\n const saveEdits = () => {\n if (typeof onSave === 'function') {\n onSave({\n crop: crop ? crop : undefined,\n focalPoint: focalPosition,\n heightInPixels: Math.round((crop.height / 100) * uncroppedPixelHeight),\n widthInPixels: Math.round((crop.width / 100) * uncroppedPixelWidth),\n })\n }\n closeModal(editDrawerSlug)\n }\n\n const onDragEnd = React.useCallback(({ x, y }) => {\n setFocalPosition({ x, y })\n setCheckBounds(false)\n }, [])\n\n const centerFocalPoint = () => {\n setFocalPosition({ x: 50, y: 50 })\n }\n\n const fileSrcToUse = fileSrc ? appendCacheTag(fileSrc, imageCacheTag) : undefined\n\n const cropWidthPx = ((crop.width / 100) * uncroppedPixelWidth).toFixed(0)\n const cropHeightPx = ((crop.height / 100) * uncroppedPixelHeight).toFixed(0)\n\n return (\n <DialogModal\n className={`${baseClass}__dialog`}\n closeOnBlur={false}\n size=\"large\"\n slug={editDrawerSlug}\n >\n <DialogHeader showClose title={`${t('general:editing')} ${fileName}`} />\n <div className={`${baseClass}__body`}>\n <div className={`${baseClass}__content`}>\n {/* Canvas area */}\n <div className={`${baseClass}__crop`}>\n <div\n className={`${baseClass}__focal-wrapper`}\n ref={focalWrapRef}\n style={{ aspectRatio: `${uncroppedPixelWidth / uncroppedPixelHeight}` }}\n >\n {showCrop ? (\n <ReactCrop\n className={`${baseClass}__reactCrop`}\n crop={crop}\n onChange={(_, c) => setCrop(c)}\n onComplete={() => setCheckBounds(true)}\n renderSelectionAddon={() => (\n <div className={`${baseClass}__crop-window`} ref={cropRef} />\n )}\n >\n <img\n alt={t('upload:setCropArea')}\n onLoad={onImageLoad}\n ref={imageRef}\n src={fileSrcToUse}\n />\n </ReactCrop>\n ) : (\n <img\n alt={t('upload:setFocalPoint')}\n onLoad={onImageLoad}\n ref={imageRef}\n src={fileSrcToUse}\n />\n )}\n {showFocalPoint && (\n <DraggableElement\n boundsRef={showCrop ? cropRef : imageRef}\n checkBounds={showCrop ? checkBounds : false}\n className={`${baseClass}__focalPoint`}\n containerRef={focalWrapRef}\n initialPosition={focalPosition}\n onDragEnd={onDragEnd}\n setCheckBounds={showCrop ? setCheckBounds : false}\n >\n <PlusIcon />\n </DraggableElement>\n )}\n </div>\n </div>\n\n {/* Sidebar */}\n {(showCrop || showFocalPoint) && (\n <div className={`${baseClass}__sidebar`}>\n {showCrop && (\n <div className={`${baseClass}__section`}>\n <div className={`${baseClass}__section-header`}>\n <span className={`${baseClass}__section-title`}>{t('upload:crop')}</span>\n <button\n aria-label={t('general:reset')}\n className={`${baseClass}__reset`}\n onClick={() => setCrop({ height: 100, unit: '%', width: 100, x: 0, y: 0 })}\n type=\"button\"\n >\n <ResetIcon />\n </button>\n </div>\n <div className={`${baseClass}__fieldset`}>\n <NumberInput\n ariaLabel={t('upload:width')}\n onChange={(e) => fineTuneCrop({ dimension: 'width', value: e.target.value })}\n path=\"cropWidth\"\n prefix=\"W\"\n readOnly={!imageLoaded}\n size=\"medium\"\n value={Number(cropWidthPx)}\n />\n <NumberInput\n ariaLabel={t('upload:height')}\n onChange={(e) => fineTuneCrop({ dimension: 'height', value: e.target.value })}\n path=\"cropHeight\"\n prefix=\"H\"\n readOnly={!imageLoaded}\n size=\"medium\"\n value={Number(cropHeightPx)}\n />\n </div>\n </div>\n )}\n\n {showFocalPoint && (\n <div className={`${baseClass}__section`}>\n <div className={`${baseClass}__section-header`}>\n <span className={`${baseClass}__section-title`}>{t('upload:focalPoint')}</span>\n <button\n aria-label={t('general:reset')}\n className={`${baseClass}__reset`}\n onClick={centerFocalPoint}\n type=\"button\"\n >\n <ResetIcon />\n </button>\n </div>\n <div className={`${baseClass}__fieldset`}>\n <NumberInput\n ariaLabel={`${t('upload:focalPoint')} X`}\n max={100}\n min={0}\n onChange={(e) =>\n fineTuneFocalPosition({ coordinate: 'x', value: e.target.value })\n }\n path=\"focalX\"\n prefix=\"X\"\n size=\"medium\"\n suffix=\"%\"\n value={Math.round(focalPosition.x)}\n />\n <NumberInput\n ariaLabel={`${t('upload:focalPoint')} Y`}\n max={100}\n min={0}\n onChange={(e) =>\n fineTuneFocalPosition({ coordinate: 'y', value: e.target.value })\n }\n path=\"focalY\"\n prefix=\"Y\"\n size=\"medium\"\n suffix=\"%\"\n value={Math.round(focalPosition.y)}\n />\n </div>\n </div>\n )}\n </div>\n )}\n </div>\n </div>\n <DialogFooter>\n <Button\n aria-label={t('general:cancel')}\n buttonStyle=\"secondary\"\n onClick={() => closeModal(editDrawerSlug)}\n >\n {t('general:cancel')}\n </Button>\n <Button\n aria-label={t('general:applyChanges')}\n buttonStyle=\"primary\"\n disabled={!imageLoaded}\n onClick={saveEdits}\n >\n {t('general:applyChanges')}\n </Button>\n </DialogFooter>\n </DialogModal>\n )\n}\n\nconst DraggableElement = ({\n boundsRef,\n checkBounds,\n children,\n className,\n containerRef,\n initialPosition = { x: 50, y: 50 },\n onDragEnd,\n setCheckBounds,\n}) => {\n const [position, setPosition] = useState({ x: initialPosition.x, y: initialPosition.y })\n const [isDragging, setIsDragging] = useState(false)\n const dragRef = useRef<HTMLButtonElement | undefined>(undefined)\n // Keep a ref to the latest position so global mouseup handler can read it without a stale closure\n const positionRef = useRef(position)\n positionRef.current = position\n\n const getCoordinates = React.useCallback(\n (mouseX: number, mouseY: number) => {\n const containerRect = containerRef.current.getBoundingClientRect()\n const x = ((mouseX - containerRect.left) / containerRect.width) * 100\n const y = ((mouseY - containerRect.top) / containerRect.height) * 100\n return { x: Math.max(0, Math.min(100, x)), y: Math.max(0, Math.min(100, y)) }\n },\n [containerRef],\n )\n\n const handleMouseDown = (event) => {\n event.preventDefault()\n setIsDragging(true)\n }\n\n // Attach global listeners while dragging — this ensures events fire even when\n // the cursor leaves the focal wrapper area during a fast drag\n React.useEffect(() => {\n if (!isDragging) {\n return\n }\n\n const handleMove = (e: MouseEvent) => {\n if (!containerRef.current) {\n return\n }\n const { x, y } = getCoordinates(e.clientX, e.clientY)\n setPosition({ x, y })\n }\n\n const handleUp = () => {\n setIsDragging(false)\n onDragEnd(positionRef.current)\n }\n\n document.addEventListener('mousemove', handleMove)\n document.addEventListener('mouseup', handleUp)\n\n return () => {\n document.removeEventListener('mousemove', handleMove)\n document.removeEventListener('mouseup', handleUp)\n }\n }, [isDragging, getCoordinates, onDragEnd, containerRef])\n\n // Re-check position when crop changes (the crop window may have moved)\n React.useEffect(() => {\n if (isDragging || !checkBounds || !dragRef.current) {\n return\n }\n const { height, left, top, width } = dragRef.current.getBoundingClientRect()\n const { x, y } = getCoordinates(left + width / 2, top + height / 2)\n onDragEnd({ x, y })\n setPosition({ x, y })\n setCheckBounds(false)\n }, [getCoordinates, isDragging, checkBounds, setCheckBounds, onDragEnd])\n\n React.useEffect(() => {\n setPosition({ x: initialPosition.x, y: initialPosition.y })\n }, [initialPosition.x, initialPosition.y])\n\n return (\n <div className={`${baseClass}__draggable-container`}>\n <button\n className={[`${baseClass}__draggable`, className].filter(Boolean).join(' ')}\n onMouseDown={handleMouseDown}\n ref={dragRef}\n style={{ left: `${position.x}%`, top: `${position.y}%` }}\n type=\"button\"\n >\n {children}\n </button>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,QAAQ,QAAQ;AACzB,OAAOC,KAAA,IAASC,MAAM,EAAEC,QAAQ,QAAQ;AACxC,OAAOC,SAAA,MAAe;AAEtB,SAASC,cAAc,QAAQ;AAC/B,SAASC,WAAW,QAAQ;AAC5B,SAASC,QAAQ,QAAQ;AACzB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,YAAY,EAAEC,YAAY,EAAEC,WAAW,QAAQ;AACxD,OAAO;AACP,OAAO;AAEP,MAAMC,SAAA,GAAY;AAkBlB,MAAMC,WAAA,GAAmC;EACvCC,MAAA,EAAQ;EACRC,IAAA,EAAM;EACNC,KAAA,EAAO;EACPC,CAAA,EAAG;EACHC,CAAA,EAAG;AACL;AAEA,OAAO,MAAMC,UAAA,GAAwCA,CAAC;EACpDC,QAAQ;EACRC,OAAO;EACPC,aAAa;EACbC,WAAW;EACXC,iBAAiB;EACjBC,MAAM;EACNC,QAA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AG,CAACoF,cAAA,EAAgBL,UAAA,EAAYhF,WAAA,EAAaC,cAAA,EAAgBkC,SAAA,CAAU;EAEvExE,KAAA,CAAMoI,SAAS,CAAC;IACdhB,WAAA,CAAY;MAAEjG,CAAA,EAAGkF,eAAA,CAAgBlF,CAAC;MAAEC,CAAA,EAAGiF,eAAA,CAAgBjF;IAAE;EAC3D,GAAG,CAACiF,eAAA,CAAgBlF,CAAC,EAAEkF,eAAA,CAAgBjF,CAAC,CAAC;EAEzC,oBACEgE,IAAA,CAAC;IAAIJ,SAAA,EAAW,GAAGlE,SAAA,uBAAgC;cACjD,aAAAsE,IAAA,CAAC;MACCJ,SAAA,EAAW,CAAC,GAAGlE,SAAA,aAAsB,EAAEkE,SAAA,CAAU,CAAC4D,MAAM,CAACC,OAAA,EAASC,IAAI,CAAC;MACvEC,WAAA,EAAad,eAAA;MACb1C,GAAA,EAAKgC,OAAA;MACL/B,KAAA,EAAO;QAAEuC,IAAA,EAAM,GAAGZ,QAAA,CAAShG,CAAC,GAAG;QAAE6G,GAAA,EAAK,GAAGb,QAAA,CAAS/F,CAAC;MAAI;MACvDmF,IAAA,EAAK;gBAEJW;;;AAIT","ignoreList":[]}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
justify-content: space-between;
|
|
17
17
|
gap: var(--spacer-2);
|
|
18
18
|
padding: var(--spacer-1) var(--spacer-3);
|
|
19
|
+
padding-inline-end: var(--spacer-2);
|
|
19
20
|
flex-shrink: 0;
|
|
20
21
|
margin-bottom: var(--spacer-2);
|
|
21
22
|
border-bottom: var(--stroke-width-small) solid var(--color-border);
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
|
|
24
25
|
.hierarchy-column__add-button {
|
|
25
26
|
flex-shrink: 0;
|
|
27
|
+
color: var(--color-text-secondary);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
30
|
.hierarchy-column__header-checkbox {
|
|
@@ -45,7 +47,7 @@
|
|
|
45
47
|
display: flex;
|
|
46
48
|
flex-direction: column;
|
|
47
49
|
overflow-y: auto;
|
|
48
|
-
margin: 0 var(--spacer-
|
|
50
|
+
margin: 0 var(--spacer-1);
|
|
49
51
|
gap: var(--spacer-1);
|
|
50
52
|
}
|
|
51
53
|
|
|
@@ -40,7 +40,7 @@ export type ColumnProps = {
|
|
|
40
40
|
hasNextPage: boolean;
|
|
41
41
|
isLoading: boolean;
|
|
42
42
|
items: ColumnItemData[];
|
|
43
|
-
/** Called when user clicks "New" button - parent should open
|
|
43
|
+
/** Called when user clicks "New" button - parent should open modal with parentId */
|
|
44
44
|
onCreateNew: (params: {
|
|
45
45
|
parentId: null | number | string;
|
|
46
46
|
}) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/elements/Hierarchy/ColumnBrowser/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAGpC,MAAM,MAAM,cAAc,GAAG;IAC3B,+EAA+E;IAC/E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,WAAW,EAAE,OAAO,CAAA;IACpB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;IACnB,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,2EAA2E;IAC3E,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAA;IAC7B,sBAAsB,EAAE,OAAO,CAAA;IAC/B,UAAU,EAAE,OAAO,CAAA;IACnB,UAAU,EAAE,OAAO,CAAA;IACnB,IAAI,EAAE,cAAc,CAAA;IACpB,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM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AW,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACpE,QAAQ,EAAE,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,IAAI,EAAE,WAAW,EAAE,CAAA;KAAE,KAAK,IAAI,CAAA;IACxE,eAAe,EAAE,MAAM,CAAA;IACvB,WAAW,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;IACjC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/elements/Hierarchy/ColumnBrowser/types.ts"],"sourcesContent":["import type { Where } from 'payload'\nimport type React from 'react'\n\nexport type ColumnItemData = {\n /** For folders with collectionSpecific config, the allowed collection slugs */\n allowedCollections?: string[]\n hasChildren: boolean\n id: number | string\n title: string\n}\n\nexport type PathSegment = {\n id: number | string\n title: string\n}\n\nexport type ColumnItemProps = {\n disabled?: boolean\n /** Required collections that the folder must allow (for superset check) */\n filterByCollection?: string[]\n hasSelectedDescendants: boolean\n isExpanded: boolean\n isSelected: boolean\n item: ColumnItemData\n onExpand: (params: { id: number | string }) => void\n onSelect: (params: { id: number | string }) => void\n}\n\nexport type ColumnProps = {\n ancestorsWithSelections: Set<number | string>\n /** Whether user can create new documents */\n canCreate: boolean\n /** Label for the collection (e.g., \"Folder\") */\n collectionLabel: string\n disabled?: boolean\n /** IDs that should be disabled (e.g., items being moved can't be selected as destination) */\n disabledIds?: Set<number | string>\n expandedId: null | number | string\n /** Required collections for superset check (passed to ColumnItem) */\n filterByCollection?: string[]\n hasNextPage: boolean\n isLoading: boolean\n items: ColumnItemData[]\n /** Called when user clicks \"New\" button - parent should open
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/elements/Hierarchy/ColumnBrowser/types.ts"],"sourcesContent":["import type { Where } from 'payload'\nimport type React from 'react'\n\nexport type ColumnItemData = {\n /** For folders with collectionSpecific config, the allowed collection slugs */\n allowedCollections?: string[]\n hasChildren: boolean\n id: number | string\n title: string\n}\n\nexport type PathSegment = {\n id: number | string\n title: string\n}\n\nexport type ColumnItemProps = {\n disabled?: boolean\n /** Required collections that the folder must allow (for superset check) */\n filterByCollection?: string[]\n hasSelectedDescendants: boolean\n isExpanded: boolean\n isSelected: boolean\n item: ColumnItemData\n onExpand: (params: { id: number | string }) => void\n onSelect: (params: { id: number | string }) => void\n}\n\nexport type ColumnProps = {\n ancestorsWithSelections: Set<number | string>\n /** Whether user can create new documents */\n canCreate: boolean\n /** Label for the collection (e.g., \"Folder\") */\n collectionLabel: string\n disabled?: boolean\n /** IDs that should be disabled (e.g., items being moved can't be selected as destination) */\n disabledIds?: Set<number | string>\n expandedId: null | number | string\n /** Required collections for superset check (passed to ColumnItem) */\n filterByCollection?: string[]\n hasNextPage: boolean\n isLoading: boolean\n items: ColumnItemData[]\n /** Called when user clicks \"New\" button - parent should open modal with parentId */\n onCreateNew: (params: { parentId: null | number | string }) => void\n onExpand: (params: { id: number | string }) => void\n onLoadMore: () => void\n onSelect: (params: { id: number | string; path: PathSegment[] }) => void\n parentId: null | number | string\n parentTitle?: string\n pathToColumn: PathSegment[]\n selectedIds: Set<number | string>\n totalDocs: number\n}\n\nexport type ColumnState = {\n hasNextPage: boolean\n isLoading: boolean\n items: ColumnItemData[]\n page: number\n parentId: null | number | string\n parentTitle?: string\n totalDocs: number\n}\n\nexport type HierarchyColumnBrowserRef = {\n /** Refetch a specific column by parentId */\n refreshColumn: (parentId: null | number | string) => Promise<void>\n}\n\nexport type HierarchyColumnBrowserProps = {\n ancestorsWithSelections: Set<number | string>\n /** Base filter constraint (e.g., tenant filter) to apply to all queries */\n baseFilter?: null | Where\n /** IDs that should be disabled (e.g., items being moved can't be selected as destination) */\n disabledIds?: Set<number | string>\n /**\n * Filters hierarchy items based on collection type restrictions:\n * - `undefined`: No filtering, show all folders\n * - `[]` (empty array): No filtering, show all folders (no constraints)\n * - `['posts', ...]`: Show folders accepting ANY of these collections OR unrestricted folders\n *\n * Note: Query uses ANY semantics due to PG hasMany enum limitations.\n * Client-side enforcement can disable selection of folders that don't allow ALL required collections.\n */\n filterByCollection?: string[]\n hierarchyCollectionSlug: string\n initialExpandedPath?: (number | string)[]\n /** Whether the initial expanded path is still being loaded */\n isLoadingPath?: boolean\n /** Called when user clicks \"New\" button to create a new item */\n onCreateNew?: (params: { parentId: null | number | string }) => void\n onSelect: (params: { id: number | string; path: PathSegment[] }) => void\n parentFieldName: string\n selectedIds: Set<number | string>\n useAsTitle?: string\n}\n"],"mappings":"AAsEA","ignoreList":[]}
|
|
@@ -8,7 +8,7 @@ import { useConfig } from '../../../providers/Config/index.js';
|
|
|
8
8
|
import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js';
|
|
9
9
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
10
10
|
import { Button } from '../../Button/index.js';
|
|
11
|
-
import {
|
|
11
|
+
import { useHierarchyModal } from '../Modal/useHierarchyModal.js';
|
|
12
12
|
import './index.css';
|
|
13
13
|
const baseClass = 'hierarchy-button';
|
|
14
14
|
export const HierarchyButtonClient = ({
|
|
@@ -44,13 +44,13 @@ export const HierarchyButtonClient = ({
|
|
|
44
44
|
});
|
|
45
45
|
const useAsTitle = collectionConfig?.admin?.useAsTitle || 'name';
|
|
46
46
|
const isHierarchyCollection = documentCollectionSlug === hierarchyCollectionSlug;
|
|
47
|
-
// When in hierarchy collection, let the
|
|
47
|
+
// When in hierarchy collection, let the modal use allowedCollections from context
|
|
48
48
|
// When in other collections, filter by that collection's slug
|
|
49
49
|
// Memoize to prevent new array references on every render
|
|
50
50
|
const filterByCollection = useMemo(() => isHierarchyCollection || !documentCollectionSlug ? undefined : [documentCollectionSlug], [isHierarchyCollection, documentCollectionSlug]);
|
|
51
|
-
const [
|
|
52
|
-
|
|
53
|
-
}] =
|
|
51
|
+
const [HierarchyModal,, {
|
|
52
|
+
openModal
|
|
53
|
+
}] = useHierarchyModal({
|
|
54
54
|
filterByCollection,
|
|
55
55
|
hierarchyCollectionSlug,
|
|
56
56
|
Icon
|
|
@@ -87,8 +87,8 @@ export const HierarchyButtonClient = ({
|
|
|
87
87
|
};
|
|
88
88
|
void fetchItemName();
|
|
89
89
|
}, [currentId, hierarchyCollectionSlug, config.routes.api, config.serverURL, useAsTitle, t]);
|
|
90
|
-
const
|
|
91
|
-
|
|
90
|
+
const handleModalSave = useCallback(({
|
|
91
|
+
closeModal,
|
|
92
92
|
selections
|
|
93
93
|
}) => {
|
|
94
94
|
const ids = Array.from(selections.keys());
|
|
@@ -101,13 +101,13 @@ export const HierarchyButtonClient = ({
|
|
|
101
101
|
});
|
|
102
102
|
setModified(true);
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
closeModal();
|
|
105
105
|
}, [currentFieldValue?.value, dispatchField, fieldName, hasMany, setModified]);
|
|
106
106
|
const handleClick = useCallback(() => {
|
|
107
107
|
if (!readOnly) {
|
|
108
|
-
|
|
108
|
+
openModal();
|
|
109
109
|
}
|
|
110
|
-
}, [
|
|
110
|
+
}, [openModal, readOnly]);
|
|
111
111
|
const label = isLoading ? `${t('general:loading')}...` : displayName;
|
|
112
112
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
113
113
|
children: [/*#__PURE__*/_jsx(Button, {
|
|
@@ -119,10 +119,10 @@ export const HierarchyButtonClient = ({
|
|
|
119
119
|
margin: false,
|
|
120
120
|
onClick: handleClick,
|
|
121
121
|
children: label
|
|
122
|
-
}), /*#__PURE__*/_jsx(
|
|
122
|
+
}), /*#__PURE__*/_jsx(HierarchyModal, {
|
|
123
123
|
hasMany: hasMany,
|
|
124
124
|
initialSelections: currentId ? [currentId] : undefined,
|
|
125
|
-
onSave:
|
|
125
|
+
onSave: handleModalSave
|
|
126
126
|
})]
|
|
127
127
|
});
|
|
128
128
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["formatAdminURL","React","useCallback","useEffect","useMemo","useState","useForm","useFormFields","useConfig","useDocumentInfo","useTranslation","Button","
|
|
1
|
+
{"version":3,"file":"index.js","names":["formatAdminURL","React","useCallback","useEffect","useMemo","useState","useForm","useFormFields","useConfig","useDocumentInfo","useTranslation","Button","useHierarchyModal","baseClass","HierarchyButtonClient","fieldName","hasMany","hierarchyCollectionSlug","Icon","readOnly","readOnlyFromProps","SmallIcon","t","config","getEntityConfig","collectionSlug","documentCollectionSlug","disabled","formDisabled","setModified","dispatchField","_","dispatch","currentFieldValue","fields","currentId","value","displayName","setDisplayName","isLoading","setIsLoading","collectionConfig","useAsTitle","admin","isHierarchyCollection","filterByCollection","undefined","HierarchyModal","openModal","fetchItemName","response","fetch","apiRoute","routes","api","path","serverURL","credentials","ok","itemData","json","title","name","id","String","handleModalSave","closeModal","selections","ids","Array","from","keys","newValue","type","handleClick","label","_jsxs","_Fragment","_jsx","buttonStyle","className","filter","Boolean","join","icon","iconPosition","margin","onClick","initialSelections","onSave"],"sources":["../../../../src/elements/Hierarchy/DocHeaderButton/index.tsx"],"sourcesContent":["'use client'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { useCallback, useEffect, useMemo, useState } from 'react'\n\nimport type { SelectionWithPath } from '../Modal/types.js'\n\nimport { useForm, useFormFields } from '../../../forms/Form/context.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../../providers/DocumentInfo/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { Button } from '../../Button/index.js'\nimport { useHierarchyModal } from '../Modal/useHierarchyModal.js'\nimport './index.css'\n\nconst baseClass = 'hierarchy-button'\n\nexport type HierarchyButtonClientProps = {\n fieldName: string\n hasMany?: boolean\n hierarchyCollectionSlug: string\n Icon?: React.ReactNode\n readOnly?: boolean\n SmallIcon?: React.ReactNode\n}\n\nexport const HierarchyButtonClient: React.FC<HierarchyButtonClientProps> = ({\n fieldName,\n hasMany = false,\n hierarchyCollectionSlug,\n Icon,\n readOnly: readOnlyFromProps,\n SmallIcon,\n}) => {\n const { t } = useTranslation()\n const { config, getEntityConfig } = useConfig()\n const { collectionSlug: documentCollectionSlug } = useDocumentInfo()\n const { disabled: formDisabled, setModified } = useForm()\n const readOnly = readOnlyFromProps || formDisabled\n const dispatchField = useFormFields(([_, dispatch]) => dispatch)\n\n const currentFieldValue = useFormFields(([fields]) => (fields && fields?.[fieldName]) || null)\n const currentId = currentFieldValue?.value as null | number | string\n\n const [displayName, setDisplayName] = useState<string>('')\n const [isLoading, setIsLoading] = useState(true)\n\n const collectionConfig = getEntityConfig({ collectionSlug: hierarchyCollectionSlug })\n const useAsTitle = collectionConfig?.admin?.useAsTitle || 'name'\n\n const isHierarchyCollection = documentCollectionSlug === hierarchyCollectionSlug\n\n // When in hierarchy collection, let the modal use allowedCollections from context\n // When in other collections, filter by that collection's slug\n // Memoize to prevent new array references on every render\n const filterByCollection = useMemo(\n () => (isHierarchyCollection || !documentCollectionSlug ? undefined : [documentCollectionSlug]),\n [isHierarchyCollection, documentCollectionSlug],\n )\n\n const [HierarchyModal, , { openModal }] = useHierarchyModal({\n filterByCollection,\n hierarchyCollectionSlug,\n Icon,\n })\n\n // Fetch item name when currentId changes\n useEffect(() => {\n const fetchItemName = async () => {\n if (currentId && (typeof currentId === 'string' || typeof currentId === 'number')) {\n setIsLoading(true)\n try {\n const response = await fetch(\n formatAdminURL({\n apiRoute: config.routes.api,\n path: `/${hierarchyCollectionSlug}/${currentId}`,\n serverURL: config.serverURL,\n }),\n { credentials: 'include' },\n )\n\n if (response.ok) {\n const itemData = await response.json()\n const title = itemData?.[useAsTitle] || itemData?.name || itemData?.id\n\n setDisplayName(String(title))\n } else {\n setDisplayName(t('general:none'))\n }\n } catch {\n setDisplayName(t('general:none'))\n } finally {\n setIsLoading(false)\n }\n } else {\n setDisplayName(t('general:none'))\n setIsLoading(false)\n }\n }\n\n void fetchItemName()\n }, [currentId, hierarchyCollectionSlug, config.routes.api, config.serverURL, useAsTitle, t])\n\n const handleModalSave = useCallback(\n ({\n closeModal,\n selections,\n }: {\n closeModal: () => void\n selections: Map<number | string, SelectionWithPath>\n }) => {\n const ids = Array.from(selections.keys())\n const newValue = hasMany ? ids : (ids[0] ?? null)\n\n if (currentFieldValue?.value !== newValue) {\n dispatchField({\n type: 'UPDATE',\n path: fieldName,\n value: newValue,\n })\n setModified(true)\n }\n closeModal()\n },\n [currentFieldValue?.value, dispatchField, fieldName, hasMany, setModified],\n )\n\n const handleClick = useCallback(() => {\n if (!readOnly) {\n openModal()\n }\n }, [openModal, readOnly])\n\n const label = isLoading ? `${t('general:loading')}...` : displayName\n\n return (\n <>\n <Button\n buttonStyle=\"secondary\"\n className={[baseClass, readOnly && `${baseClass}--read-only`].filter(Boolean).join(' ')}\n disabled={readOnly}\n icon={SmallIcon ?? Icon}\n iconPosition=\"left\"\n margin={false}\n onClick={handleClick}\n >\n {label}\n </Button>\n <HierarchyModal\n hasMany={hasMany}\n initialSelections={currentId ? [currentId] : undefined}\n onSave={handleModalSave}\n />\n </>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ;AAIjE,SAASC,OAAO,EAAEC,aAAa,QAAQ;AACvC,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,iBAAiB,QAAQ;AAClC,OAAO;AAEP,MAAMC,SAAA,GAAY;AAWlB,OAAO,MAAMC,qBAAA,GAA8DA,CAAC;EAC1EC,SAAS;EACTC,OAAA,GAAU,KAAK;EACfC,uBAAuB;EACvBC,IAAI;EACJC,QAAA,EAAUC,iBAAiB;EAC3BC;AAAS,CACV;EACC,MAAM;IAAEC;EAAC,CAAE,GAAGZ,cAA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AA,CAAc;QACZ2C,IAAA,EAAM;QACNlB,IAAA,EAAMxC,SAAA;QACNqB,KAAA,EAAOoC;MACT;MACA3C,WAAA,CAAY;IACd;IACAqC,UAAA;EACF,GACA,CAACjC,iBAAA,EAAmBG,KAAA,EAAON,aAAA,EAAef,SAAA,EAAWC,OAAA,EAASa,WAAA,CAAY;EAG5E,MAAM6C,WAAA,GAAcxE,WAAA,CAAY;IAC9B,IAAI,CAACiB,QAAA,EAAU;MACb6B,SAAA;IACF;EACF,GAAG,CAACA,SAAA,EAAW7B,QAAA,CAAS;EAExB,MAAMwD,KAAA,GAAQpC,SAAA,GAAY,GAAGjB,CAAA,CAAE,uBAAuB,GAAGe,WAAA;EAEzD,oBACEuC,KAAA,CAAAC,SAAA;4BACEC,IAAA,CAACnE,MAAA;MACCoE,WAAA,EAAY;MACZC,SAAA,EAAW,CAACnE,SAAA,EAAWM,QAAA,IAAY,GAAGN,SAAA,aAAsB,CAAC,CAACoE,MAAM,CAACC,OAAA,EAASC,IAAI,CAAC;MACnFxD,QAAA,EAAUR,QAAA;MACViE,IAAA,EAAM/D,SAAA,IAAaH,IAAA;MACnBmE,YAAA,EAAa;MACbC,MAAA,EAAQ;MACRC,OAAA,EAASb,WAAA;gBAERC;qBAEHG,IAAA,CAAC/B,cAAA;MACC/B,OAAA,EAASA,OAAA;MACTwE,iBAAA,EAAmBrD,SAAA,GAAY,CAACA,SAAA,CAAU,GAAGW,SAAA;MAC7C2C,MAAA,EAAQxB;;;AAIhB","ignoreList":[]}
|
|
@@ -15,7 +15,7 @@ import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js';
|
|
|
15
15
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
16
16
|
import { Button } from '../../Button/index.js';
|
|
17
17
|
import { RenderCustomComponent } from '../../RenderCustomComponent/index.js';
|
|
18
|
-
import {
|
|
18
|
+
import { useHierarchyModal } from '../Modal/useHierarchyModal.js';
|
|
19
19
|
import { SelectedHierarchies } from './SelectedHierarchies.js';
|
|
20
20
|
import './index.css';
|
|
21
21
|
const baseClass = 'hierarchy-field';
|
|
@@ -88,7 +88,7 @@ export const HierarchyFieldClient = props => {
|
|
|
88
88
|
}
|
|
89
89
|
return [value_0];
|
|
90
90
|
}, [value_0]);
|
|
91
|
-
// Initialize selections for the
|
|
91
|
+
// Initialize selections for the modal - use current value so modal expands to current selection
|
|
92
92
|
const initialSelections = useMemo(() => {
|
|
93
93
|
if (!value_0) {
|
|
94
94
|
return [];
|
|
@@ -100,21 +100,21 @@ export const HierarchyFieldClient = props => {
|
|
|
100
100
|
}, [value_0]);
|
|
101
101
|
// Memoize to prevent new array references on every render
|
|
102
102
|
const filterByCollection = useMemo(() => documentCollectionSlug ? [documentCollectionSlug] : undefined, [documentCollectionSlug]);
|
|
103
|
-
const [
|
|
104
|
-
|
|
105
|
-
}] =
|
|
103
|
+
const [HierarchyModal,, {
|
|
104
|
+
openModal
|
|
105
|
+
}] = useHierarchyModal({
|
|
106
106
|
filterByCollection,
|
|
107
107
|
hierarchyCollectionSlug: hierarchySlug,
|
|
108
108
|
Icon
|
|
109
109
|
});
|
|
110
|
-
const
|
|
111
|
-
|
|
110
|
+
const handleModalSave = useCallback(({
|
|
111
|
+
closeModal,
|
|
112
112
|
selections
|
|
113
113
|
}) => {
|
|
114
114
|
const ids = Array.from(selections.keys());
|
|
115
115
|
const newValue = hasMany ? ids : ids[0] ?? null;
|
|
116
116
|
setValue(newValue);
|
|
117
|
-
|
|
117
|
+
closeModal();
|
|
118
118
|
}, [hasMany, setValue]);
|
|
119
119
|
const handleRemove = useCallback(({
|
|
120
120
|
id: idToRemove
|
|
@@ -126,9 +126,9 @@ export const HierarchyFieldClient = props => {
|
|
|
126
126
|
setValue(null);
|
|
127
127
|
}
|
|
128
128
|
}, [hasMany, selectedIds, setValue]);
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
}, [
|
|
129
|
+
const handleOpenModal = useCallback(() => {
|
|
130
|
+
openModal();
|
|
131
|
+
}, [openModal]);
|
|
132
132
|
const hierarchyLabel = getTranslation(hasMany ? collectionConfig?.labels?.plural : collectionConfig?.labels?.singular, i18n) || hierarchySlug;
|
|
133
133
|
return /*#__PURE__*/_jsxs("div", {
|
|
134
134
|
className: [fieldBaseClass, baseClass, className, showError && 'error', readOnly && `${baseClass}--read-only`].filter(Boolean).join(' '),
|
|
@@ -166,7 +166,7 @@ export const HierarchyFieldClient = props => {
|
|
|
166
166
|
}),
|
|
167
167
|
iconPosition: "left",
|
|
168
168
|
margin: false,
|
|
169
|
-
onClick:
|
|
169
|
+
onClick: handleOpenModal,
|
|
170
170
|
size: "medium",
|
|
171
171
|
children: t('general:selectLabel', {
|
|
172
172
|
label: hierarchyLabel
|
|
@@ -179,10 +179,10 @@ export const HierarchyFieldClient = props => {
|
|
|
179
179
|
path: path
|
|
180
180
|
})
|
|
181
181
|
})]
|
|
182
|
-
}), /*#__PURE__*/_jsx(
|
|
182
|
+
}), /*#__PURE__*/_jsx(HierarchyModal, {
|
|
183
183
|
hasMany: hasMany,
|
|
184
184
|
initialSelections: initialSelections,
|
|
185
|
-
onSave:
|
|
185
|
+
onSave: handleModalSave
|
|
186
186
|
})]
|
|
187
187
|
});
|
|
188
188
|
};
|