@payloadcms/ui 4.0.0-canary.5 → 4.0.0-canary.6
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/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/Table/DefaultCell/fields/Hierarchy/index.js +24 -24
- package/dist/elements/Table/DefaultCell/fields/Hierarchy/index.js.map +1 -1
- package/dist/elements/TimezonePicker/index.css +1 -1
- package/dist/exports/client/index.d.ts +2 -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/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/styles.css +1 -1
- package/package.json +5 -5
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.js","names":["getTranslation","React","useCallback","useMemo","FieldDescription","FieldError","FieldLabel","mergeFieldStyles","fieldBaseClass","useField","CirclePlusIcon","useConfig","useDocumentInfo","useTranslation","Button","RenderCustomComponent","useHierarchyDrawer","SelectedHierarchies","baseClass","HierarchyFieldClient","props","field","admin","className","description","hasMany","label","localized","relationTo","relationToProp","required","Icon","path","pathFromProps","readOnly","validate","hierarchySlug","Array","isArray","getEntityConfig","collectionSlug","documentCollectionSlug","i18n","t","collectionConfig","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","styles","selectedIds","initialSelections","filterByCollection","undefined","HierarchyDrawer","openDrawer","hierarchyCollectionSlug","handleDrawerSave","closeDrawer","selections","ids","from","keys","newValue","handleRemove","id","idToRemove","newIds","filter","length","handleOpenDrawer","hierarchyLabel","labels","plural","singular","_jsxs","Boolean","join","replace","style","_jsx","CustomComponent","Fallback","onRemove","buttonStyle","icon","size","iconPosition","margin","onClick","onSave"],"sources":["../../../../src/elements/Hierarchy/Field/index.client.tsx"],"sourcesContent":["'use client'\nimport type { RelationshipFieldClientProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback, useMemo } from 'react'\n\nimport type { SelectionWithPath } from '../Drawer/types.js'\n\nimport { FieldDescription } from '../../../fields/FieldDescription/index.js'\nimport { FieldError } from '../../../fields/FieldError/index.js'\nimport { FieldLabel } from '../../../fields/FieldLabel/index.js'\nimport { mergeFieldStyles } from '../../../fields/mergeFieldStyles.js'\nimport { fieldBaseClass } from '../../../fields/shared/index.js'\nimport { useField } from '../../../forms/useField/index.js'\nimport { CirclePlusIcon } from '../../../icons/CirclePlus/index.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 { RenderCustomComponent } from '../../RenderCustomComponent/index.js'\nimport { useHierarchyDrawer } from '../Drawer/useHierarchyDrawer.js'\nimport { SelectedHierarchies } from './SelectedHierarchies.js'\nimport './index.css'\n\nconst baseClass = 'hierarchy-field'\n\ntype Value = (number | string)[] | null | (number | string)\n\nexport type HierarchyFieldClientProps = {\n Icon?: React.ReactNode\n} & RelationshipFieldClientProps\n\nexport const HierarchyFieldClient: React.FC<HierarchyFieldClientProps> = (props) => {\n const {\n field,\n field: {\n admin: { className, description } = {},\n hasMany,\n label,\n localized,\n relationTo: relationToProp,\n required,\n },\n Icon,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const hierarchySlug = Array.isArray(relationToProp) ? relationToProp[0] : relationToProp\n\n const { getEntityConfig } = useConfig()\n const { collectionSlug: documentCollectionSlug } = useDocumentInfo()\n const { i18n, t } = useTranslation()\n\n const collectionConfig = getEntityConfig({ collectionSlug: hierarchySlug })\n\n const memoizedValidate = useCallback(\n (value: Value, validationOptions: Parameters<typeof validate>[1]) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, required })\n }\n },\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField<Value>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n // Normalize value to array of IDs for display\n const selectedIds = useMemo((): (number | string)[] => {\n if (!value) {\n return []\n }\n\n if (Array.isArray(value)) {\n return value\n }\n\n return [value]\n }, [value])\n\n // Initialize selections for the drawer - use current value so drawer expands to current selection\n const initialSelections = useMemo(() => {\n if (!value) {\n return []\n }\n\n if (Array.isArray(value)) {\n return value\n }\n\n return [value] as (number | string)[]\n }, [value])\n\n // Memoize to prevent new array references on every render\n const filterByCollection = useMemo(\n () => (documentCollectionSlug ? [documentCollectionSlug] : undefined),\n [documentCollectionSlug],\n )\n\n const [HierarchyDrawer, , { openDrawer }] = useHierarchyDrawer({\n filterByCollection,\n hierarchyCollectionSlug: hierarchySlug,\n Icon,\n })\n\n const handleDrawerSave = useCallback(\n ({\n closeDrawer,\n selections,\n }: {\n closeDrawer: () => void\n selections: Map<number | string, SelectionWithPath>\n }) => {\n const ids = Array.from(selections.keys())\n const newValue = hasMany ? ids : (ids[0] ?? null)\n setValue(newValue)\n closeDrawer()\n },\n [hasMany, setValue],\n )\n\n const handleRemove = useCallback(\n ({ id: idToRemove }: { id: number | string }) => {\n if (hasMany) {\n const newIds = selectedIds.filter((id) => id !== idToRemove)\n setValue(newIds.length > 0 ? newIds : null)\n } else {\n setValue(null)\n }\n },\n [hasMany, selectedIds, setValue],\n )\n\n const handleOpenDrawer = useCallback(() => {\n openDrawer()\n }, [openDrawer])\n\n const hierarchyLabel =\n getTranslation(\n hasMany ? collectionConfig?.labels?.plural : collectionConfig?.labels?.singular,\n i18n,\n ) || hierarchySlug\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n readOnly && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path?.replace(/\\./g, '__')}`}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n }\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n <div className={`${baseClass}__content`}>\n {selectedIds.length > 0 && (\n <SelectedHierarchies\n hierarchySlug={hierarchySlug}\n onRemove={handleRemove}\n readOnly={readOnly || disabled}\n selectedIds={selectedIds}\n />\n )}\n {!readOnly && (hasMany || selectedIds.length === 0) && (\n <Button\n buttonStyle=\"dashed\"\n className={`${baseClass}__manage-button`}\n disabled={disabled}\n icon={<CirclePlusIcon size={24} />}\n iconPosition=\"left\"\n margin={false}\n onClick={handleOpenDrawer}\n size=\"medium\"\n >\n {t('general:selectLabel', { label: hierarchyLabel })}\n </Button>\n )}\n </div>\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n <HierarchyDrawer\n hasMany={hasMany}\n initialSelections={initialSelections}\n onSave={handleDrawerSave}\n />\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,WAAW,EAAEC,OAAO,QAAQ;AAI5C,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,UAAU,QAAQ;AAC3B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,qBAAqB,QAAQ;AACtC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,mBAAmB,QAAQ;AACpC,OAAO;AAEP,MAAMC,SAAA,GAAY;AAQlB,OAAO,MAAMC,oBAAA,GAA6DC,KAAA;EACxE,MAAM;IACJC,KAAK;IACLA,KAAA,EAAO;MACLC,KAAA,EAAO;QAAEC,SAAS;QAAEC;MAAW,CAAE,GAAG,CAAC,CAAC;MACtCC,OAAO;MACPC,KAAK;MACLC,SAAS;MACTC,UAAA,EAAYC,cAAc;MAC1BC;IAAQ,CACT;IACDC,I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AaT,OAAA,IAAWkC,WAAA,CAAYmB,MAAM,KAAK,mBAC/CW,IAAA,CAAC3E,MAAA;UACC+E,WAAA,EAAY;UACZtE,SAAA,EAAW,GAAGL,SAAA,iBAA0B;UACxCoC,QAAA,EAAUA,QAAA;UACVwC,IAAA,eAAML,IAAA,CAAC/E,cAAA;YAAeqF,IAAA,EAAM;;UAC5BC,YAAA,EAAa;UACbC,MAAA,EAAQ;UACRC,OAAA,EAASnB,gBAAA;UACTgB,IAAA,EAAK;oBAEJpD,CAAA,CAAE,uBAAuB;YAAEjB,KAAA,EAAOsD;UAAe;;UAIvD/B,UAAA,E,aACDwC,IAAA,CAAC1E,qBAAA;QACC2E,eAAA,EAAiBvC,WAAA;QACjBwC,QAAA,eAAUF,IAAA,CAACrF,gBAAA;UAAiBoB,WAAA,EAAaA,WAAA;UAAaQ,IAAA,EAAMA;;;qBAGhEyD,IAAA,CAAC1B,eAAA;MACCtC,OAAA,EAASA,OAAA;MACTmC,iBAAA,EAAmBA,iBAAA;MACnBuC,MAAA,EAAQjC;;;AAIhB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.client.js","names":["getTranslation","React","useCallback","useMemo","FieldDescription","FieldError","FieldLabel","mergeFieldStyles","fieldBaseClass","useField","CirclePlusIcon","useConfig","useDocumentInfo","useTranslation","Button","RenderCustomComponent","useHierarchyModal","SelectedHierarchies","baseClass","HierarchyFieldClient","props","field","admin","className","description","hasMany","label","localized","relationTo","relationToProp","required","Icon","path","pathFromProps","readOnly","validate","hierarchySlug","Array","isArray","getEntityConfig","collectionSlug","documentCollectionSlug","i18n","t","collectionConfig","memoizedValidate","value","validationOptions","customComponents","AfterInput","BeforeInput","Description","Error","Label","disabled","setValue","showError","potentiallyStalePath","styles","selectedIds","initialSelections","filterByCollection","undefined","HierarchyModal","openModal","hierarchyCollectionSlug","handleModalSave","closeModal","selections","ids","from","keys","newValue","handleRemove","id","idToRemove","newIds","filter","length","handleOpenModal","hierarchyLabel","labels","plural","singular","_jsxs","Boolean","join","replace","style","_jsx","CustomComponent","Fallback","onRemove","buttonStyle","icon","size","iconPosition","margin","onClick","onSave"],"sources":["../../../../src/elements/Hierarchy/Field/index.client.tsx"],"sourcesContent":["'use client'\nimport type { RelationshipFieldClientProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useCallback, useMemo } from 'react'\n\nimport type { SelectionWithPath } from '../Modal/types.js'\n\nimport { FieldDescription } from '../../../fields/FieldDescription/index.js'\nimport { FieldError } from '../../../fields/FieldError/index.js'\nimport { FieldLabel } from '../../../fields/FieldLabel/index.js'\nimport { mergeFieldStyles } from '../../../fields/mergeFieldStyles.js'\nimport { fieldBaseClass } from '../../../fields/shared/index.js'\nimport { useField } from '../../../forms/useField/index.js'\nimport { CirclePlusIcon } from '../../../icons/CirclePlus/index.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 { RenderCustomComponent } from '../../RenderCustomComponent/index.js'\nimport { useHierarchyModal } from '../Modal/useHierarchyModal.js'\nimport { SelectedHierarchies } from './SelectedHierarchies.js'\nimport './index.css'\n\nconst baseClass = 'hierarchy-field'\n\ntype Value = (number | string)[] | null | (number | string)\n\nexport type HierarchyFieldClientProps = {\n Icon?: React.ReactNode\n} & RelationshipFieldClientProps\n\nexport const HierarchyFieldClient: React.FC<HierarchyFieldClientProps> = (props) => {\n const {\n field,\n field: {\n admin: { className, description } = {},\n hasMany,\n label,\n localized,\n relationTo: relationToProp,\n required,\n },\n Icon,\n path: pathFromProps,\n readOnly,\n validate,\n } = props\n\n const hierarchySlug = Array.isArray(relationToProp) ? relationToProp[0] : relationToProp\n\n const { getEntityConfig } = useConfig()\n const { collectionSlug: documentCollectionSlug } = useDocumentInfo()\n const { i18n, t } = useTranslation()\n\n const collectionConfig = getEntityConfig({ collectionSlug: hierarchySlug })\n\n const memoizedValidate = useCallback(\n (value: Value, validationOptions: Parameters<typeof validate>[1]) => {\n if (typeof validate === 'function') {\n return validate(value, { ...validationOptions, required })\n }\n },\n [validate, required],\n )\n\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n disabled,\n path,\n setValue,\n showError,\n value,\n } = useField<Value>({\n potentiallyStalePath: pathFromProps,\n validate: memoizedValidate,\n })\n\n const styles = useMemo(() => mergeFieldStyles(field), [field])\n\n // Normalize value to array of IDs for display\n const selectedIds = useMemo((): (number | string)[] => {\n if (!value) {\n return []\n }\n\n if (Array.isArray(value)) {\n return value\n }\n\n return [value]\n }, [value])\n\n // Initialize selections for the modal - use current value so modal expands to current selection\n const initialSelections = useMemo(() => {\n if (!value) {\n return []\n }\n\n if (Array.isArray(value)) {\n return value\n }\n\n return [value] as (number | string)[]\n }, [value])\n\n // Memoize to prevent new array references on every render\n const filterByCollection = useMemo(\n () => (documentCollectionSlug ? [documentCollectionSlug] : undefined),\n [documentCollectionSlug],\n )\n\n const [HierarchyModal, , { openModal }] = useHierarchyModal({\n filterByCollection,\n hierarchyCollectionSlug: hierarchySlug,\n Icon,\n })\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 setValue(newValue)\n closeModal()\n },\n [hasMany, setValue],\n )\n\n const handleRemove = useCallback(\n ({ id: idToRemove }: { id: number | string }) => {\n if (hasMany) {\n const newIds = selectedIds.filter((id) => id !== idToRemove)\n setValue(newIds.length > 0 ? newIds : null)\n } else {\n setValue(null)\n }\n },\n [hasMany, selectedIds, setValue],\n )\n\n const handleOpenModal = useCallback(() => {\n openModal()\n }, [openModal])\n\n const hierarchyLabel =\n getTranslation(\n hasMany ? collectionConfig?.labels?.plural : collectionConfig?.labels?.singular,\n i18n,\n ) || hierarchySlug\n\n return (\n <div\n className={[\n fieldBaseClass,\n baseClass,\n className,\n showError && 'error',\n readOnly && `${baseClass}--read-only`,\n ]\n .filter(Boolean)\n .join(' ')}\n id={`field-${path?.replace(/\\./g, '__')}`}\n style={styles}\n >\n <RenderCustomComponent\n CustomComponent={Label}\n Fallback={\n <FieldLabel label={label} localized={localized} path={path} required={required} />\n }\n />\n <div className={`${fieldBaseClass}__wrap`}>\n <RenderCustomComponent\n CustomComponent={Error}\n Fallback={<FieldError path={path} showError={showError} />}\n />\n {BeforeInput}\n <div className={`${baseClass}__content`}>\n {selectedIds.length > 0 && (\n <SelectedHierarchies\n hierarchySlug={hierarchySlug}\n onRemove={handleRemove}\n readOnly={readOnly || disabled}\n selectedIds={selectedIds}\n />\n )}\n {!readOnly && (hasMany || selectedIds.length === 0) && (\n <Button\n buttonStyle=\"dashed\"\n className={`${baseClass}__manage-button`}\n disabled={disabled}\n icon={<CirclePlusIcon size={24} />}\n iconPosition=\"left\"\n margin={false}\n onClick={handleOpenModal}\n size=\"medium\"\n >\n {t('general:selectLabel', { label: hierarchyLabel })}\n </Button>\n )}\n </div>\n {AfterInput}\n <RenderCustomComponent\n CustomComponent={Description}\n Fallback={<FieldDescription description={description} path={path} />}\n />\n </div>\n <HierarchyModal\n hasMany={hasMany}\n initialSelections={initialSelections}\n onSave={handleModalSave}\n />\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,WAAW,EAAEC,OAAO,QAAQ;AAI5C,SAASC,gBAAgB,QAAQ;AACjC,SAASC,UAAU,QAAQ;AAC3B,SAASC,UAAU,QAAQ;AAC3B,SAASC,gBAAgB,QAAQ;AACjC,SAASC,cAAc,QAAQ;AAC/B,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,qBAAqB,QAAQ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AAA;UAAW2B,IAAA,EAAMA,IAAA;UAAMwB,SAAA,EAAWA;;UAE9CN,WAAA,E,aACDkC,KAAA,CAAC;QAAI7D,SAAA,EAAW,GAAGL,SAAA,WAAoB;mBACpCyC,WAAA,CAAYmB,MAAM,GAAG,kBACpBW,IAAA,CAACxE,mBAAA;UACCmB,aAAA,EAAeA,aAAA;UACfwD,QAAA,EAAUnB,YAAA;UACVvC,QAAA,EAAUA,QAAA,IAAYoB,QAAA;UACtBK,WAAA,EAAaA;YAGhB,CAACzB,QAAA,KAAaT,OAAA,IAAWkC,WAAA,CAAYmB,MAAM,KAAK,mBAC/CW,IAAA,CAAC3E,MAAA;UACC+E,WAAA,EAAY;UACZtE,SAAA,EAAW,GAAGL,SAAA,iBAA0B;UACxCoC,QAAA,EAAUA,QAAA;UACVwC,IAAA,eAAML,IAAA,CAAC/E,cAAA;YAAeqF,IAAA,EAAM;;UAC5BC,YAAA,EAAa;UACbC,MAAA,EAAQ;UACRC,OAAA,EAASnB,eAAA;UACTgB,IAAA,EAAK;oBAEJpD,CAAA,CAAE,uBAAuB;YAAEjB,KAAA,EAAOsD;UAAe;;UAIvD/B,UAAA,E,aACDwC,IAAA,CAAC1E,qBAAA;QACC2E,eAAA,EAAiBvC,WAAA;QACjBwC,QAAA,eAAUF,IAAA,CAACrF,gBAAA;UAAiBoB,WAAA,EAAaA,WAAA;UAAaQ,IAAA,EAAMA;;;qBAGhEyD,IAAA,CAAC1B,cAAA;MACCtC,OAAA,EAASA,OAAA;MACTmC,iBAAA,EAAmBA,iBAAA;MACnBuC,MAAA,EAAQjC;;;AAIhB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchAncestorPath.d.ts","sourceRoot":"","sources":["../../../../src/elements/Hierarchy/Modal/fetchAncestorPath.ts"],"names":[],"mappings":"AAGA,KAAK,qBAAqB,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAA;IACX,cAAc,EAAE,MAAM,CAAA;IACtB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AAID;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,EACtC,GAAG,EACH,cAAc,EACd,MAAM,EACN,eAAe,EACf,SAAS,GACV,EAAE,qBAAqB,GAAG,OAAO,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CA+CtD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchAncestorPath.js","names":["formatAdminURL","qs","MAX_HIERARCHY_DEPTH","fetchAncestorPath","api","collectionSlug","itemId","parentFieldName","serverURL","queryString","stringify","depth","limit","select","where","id","equals","addQueryPrefix","url","apiRoute","path","response","fetch","credentials","ok","data","json","doc","docs","current","undefined","parentId","unshift"],"sources":["../../../../src/elements/Hierarchy/Modal/fetchAncestorPath.ts"],"sourcesContent":["import { formatAdminURL } from 'payload/shared'\nimport * as qs from 'qs-esm'\n\ntype FetchAncestorPathArgs = {\n api: string\n collectionSlug: string\n itemId: number | string\n parentFieldName: string\n serverURL: string\n}\n\nconst MAX_HIERARCHY_DEPTH = 20\n\n/**\n * Fetches the ancestor path for an item using a single API call with depth.\n * Returns array of ancestor IDs from root to item's parent.\n * Example: item at level 3 returns [grandparentId, parentId]\n */\nexport async function fetchAncestorPath({\n api,\n collectionSlug,\n itemId,\n parentFieldName,\n serverURL,\n}: FetchAncestorPathArgs): Promise<(number | string)[]> {\n const queryString = qs.stringify(\n {\n depth: MAX_HIERARCHY_DEPTH,\n limit: 1,\n select: { [parentFieldName]: true },\n where: { id: { equals: itemId } },\n },\n { addQueryPrefix: true },\n )\n\n const url = formatAdminURL({\n apiRoute: api,\n path: `/${collectionSlug}${queryString}`,\n serverURL,\n })\n\n const response = await fetch(url, { credentials: 'include' })\n\n if (!response.ok) {\n return []\n }\n\n const data = await response.json()\n const doc = data.docs?.[0]\n\n if (!doc) {\n return []\n }\n\n // Walk the nested parent chain to build path from root to immediate parent\n const path: (number | string)[] = []\n let current = doc[parentFieldName]\n\n while (current !== null && current !== undefined) {\n // Parent could be an ID (number/string) or a populated object\n const parentId = typeof current === 'object' ? current.id : current\n\n if (parentId !== null && parentId !== undefined) {\n path.unshift(parentId)\n }\n\n // Move to next parent (only if current is populated object)\n current = typeof current === 'object' ? current[parentFieldName] : null\n }\n\n return path\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ;AAC/B,YAAYC,EAAA,MAAQ;AAUpB,MAAMC,mBAAA,GAAsB;AAE5B;;;;;AAKA,OAAO,eAAeC,kBAAkB;EACtCC,GAAG;EACHC,cAAc;EACdC,MAAM;EACNC,eAAe;EACfC;AAAS,CACa;EACtB,MAAMC,WAAA,GAAcR,EAAA,CAAGS,SAAS,CAC9B;IACEC,KAAA,EAAOT,mBAAA;IACPU,KAAA,EAAO;IACPC,MAAA,EAAQ;MAAE,CAACN,eAAA,GAAkB;IAAK;IAClCO,KAAA,EAAO;MAAEC,EAAA,EAAI;QAAEC,MAAA,EAAQV;MAAO;IAAE;EAClC,GACA;IAAEW,cAAA,EAAgB;EAAK;EAGzB,MAAMC,GAAA,GAAMlB,cAAA,CAAe;IACzBmB,QAAA,EAAUf,GAAA;IACVgB,IAAA,EAAM,IAAIf,cAAA,GAAiBI,WAAA,EAAa;IACxCD;EACF;EAEA,MAAMa,QAAA,GAAW,MAAMC,KAAA,CAAMJ,GAAA,EAAK;IAAEK,WAAA,EAAa;EAAU;EAE3D,IAAI,CAACF,QAAA,CAASG,EAAE,EAAE;IAChB,OAAO,EAAE;EACX;EAEA,MAAMC,IAAA,GAAO,MAAMJ,QAAA,CAASK,IAAI;EAChC,MAAMC,GAAA,GAAMF,IAAA,CAAKG,IAAI,GAAG,EAAE;EAE1B,IAAI,CAACD,GAAA,EAAK;IACR,OAAO,EAAE;EACX;EAEA;EACA,MAAMP,IAAA,GAA4B,EAAE;EACpC,IAAIS,OAAA,GAAUF,GAAG,CAACpB,eAAA,CAAgB;EAElC,OAAOsB,OAAA,KAAY,QAAQA,OAAA,KAAYC,SAAA,EAAW;IAChD;IACA,MAAMC,QAAA,GAAW,OAAOF,OAAA,KAAY,WAAWA,OAAA,CAAQd,EAAE,GAAGc,OAAA;IAE5D,IAAIE,QAAA,KAAa,QAAQA,QAAA,KAAaD,SAAA,EAAW;MAC/CV,IAAA,CAAKY,OAAO,CAACD,QAAA;IACf;IAEA;IACAF,OAAA,GAAU,OAAOA,OAAA,KAAY,WAAWA,OAAO,CAACtB,eAAA,CAAgB,GAAG;EACrE;EAEA,OAAOa,IAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@layer payload-default {
|
|
2
|
+
.dialog.hierarchy-modal {
|
|
3
|
+
width: min(900px, calc(100vw - var(--spacer-6)));
|
|
4
|
+
height: min(700px, calc(100vh - var(--spacer-6)));
|
|
5
|
+
max-width: calc(100vw - var(--spacer-6));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.hierarchy-modal__content {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
height: 100%;
|
|
12
|
+
background: var(--color-bg);
|
|
13
|
+
border-radius: var(--radius-large);
|
|
14
|
+
overflow: clip;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.hierarchy-modal__header-actions {
|
|
18
|
+
display: flex;
|
|
19
|
+
gap: var(--spacer-2);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.dialog.hierarchy-modal .dialog__body {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
padding: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.hierarchy-modal__subheader {
|
|
29
|
+
display: flex;
|
|
30
|
+
justify-content: space-between;
|
|
31
|
+
align-items: center;
|
|
32
|
+
padding: var(--spacer-1) var(--spacer-3);
|
|
33
|
+
padding-inline-start: var(--spacer-2-5);
|
|
34
|
+
border-bottom: var(--stroke-width-small) solid var(--color-border);
|
|
35
|
+
flex-shrink: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.hierarchy-modal__subheader-left {
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
gap: var(--spacer-1);
|
|
42
|
+
font-weight: 500;
|
|
43
|
+
color: var(--color-text);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.hierarchy-modal__subheader-right {
|
|
47
|
+
display: flex;
|
|
48
|
+
align-items: center;
|
|
49
|
+
gap: var(--spacer-2);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.hierarchy-modal__selection-info {
|
|
53
|
+
color: var(--color-text-secondary);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
.hierarchy-modal__move-to-root,
|
|
57
|
+
.hierarchy-modal__clear-all {
|
|
58
|
+
height: auto;
|
|
59
|
+
padding: 0;
|
|
60
|
+
border: 0;
|
|
61
|
+
border-radius: 0;
|
|
62
|
+
background: transparent;
|
|
63
|
+
color: var(--color-text-secondary);
|
|
64
|
+
text-decoration: underline;
|
|
65
|
+
text-underline-offset: 2px;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.hierarchy-modal__move-to-root:hover:not(.btn--disabled),
|
|
69
|
+
.hierarchy-modal__clear-all:hover:not(.btn--disabled) {
|
|
70
|
+
background: transparent;
|
|
71
|
+
color: var(--color-text);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.hierarchy-modal__move-to-root:active:not(.btn--disabled),
|
|
75
|
+
.hierarchy-modal__clear-all:active:not(.btn--disabled) {
|
|
76
|
+
background: transparent;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.hierarchy-modal__columns {
|
|
80
|
+
flex: 1;
|
|
81
|
+
overflow: hidden;
|
|
82
|
+
display: flex;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.hierarchy-modal__toggler {
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { HierarchyColumnBrowserRef } from '../ColumnBrowser/index.js';
|
|
3
|
+
import type { HierarchyModalInternalProps } from './types.js';
|
|
4
|
+
import './index.css';
|
|
5
|
+
export declare const baseClass = "hierarchy-modal";
|
|
6
|
+
type HierarchyModalContentProps = {
|
|
7
|
+
columnBrowserRef?: React.RefObject<HierarchyColumnBrowserRef | null>;
|
|
8
|
+
onCreateNew?: (params: {
|
|
9
|
+
parentId: null | number | string;
|
|
10
|
+
}) => void;
|
|
11
|
+
} & HierarchyModalInternalProps;
|
|
12
|
+
export type HierarchyModalContentRef = {
|
|
13
|
+
selectItem: (id: number | string) => void;
|
|
14
|
+
};
|
|
15
|
+
export declare const HierarchyModalContent: ({ baseFilter, closeModal, columnBrowserRef, disabledIds, filterByCollection, hasMany, hierarchyCollectionSlug, Icon, initialSelections, onCreateNew, onMoveToRoot, onSave, parentFieldName, ref, showMoveToRoot, useAsTitle, }: {
|
|
16
|
+
ref?: React.RefObject<HierarchyModalContentRef | null>;
|
|
17
|
+
} & HierarchyModalContentProps) => React.JSX.Element;
|
|
18
|
+
export declare const HierarchyModal: React.FC<HierarchyModalInternalProps>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/Hierarchy/Modal/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAON,MAAM,OAAO,CAAA;AAEd,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,KAAK,EAAE,2BAA2B,EAAqB,MAAM,YAAY,CAAA;AAahF,OAAO,aAAa,CAAA;AAEpB,eAAO,MAAM,SAAS,oBAAoB,CAAA;AAE1C,KAAK,0BAA0B,GAAG;IAChC,gBAAgB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,yBAAyB,GAAG,IAAI,CAAC,CAAA;IACpE,WAAW,CAAC,EAAE,CAAC,MAAM,EAAE;QAAE,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;CACrE,GAAG,2BAA2B,CAAA;AAE/B,MAAM,MAAM,wBAAwB,GAAG;IACrC,UAAU,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,KAAK,IAAI,CAAA;CAC1C,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAkC,gOAiBjE;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAA;CAAE,GAAG,0BAA0B,sBAmNzF,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA+FhE,CAAA"}
|
|
@@ -8,17 +8,17 @@ import { TagIcon } from '../../../icons/Tag/index.js';
|
|
|
8
8
|
import { useConfig } from '../../../providers/Config/index.js';
|
|
9
9
|
import { useHierarchy } from '../../../providers/Hierarchy/index.js';
|
|
10
10
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
11
|
-
import {
|
|
11
|
+
import { Button } from '../../Button/index.js';
|
|
12
|
+
import { DialogBody, DialogHeader, DialogModal } from '../../Dialog/index.js';
|
|
12
13
|
import { useDocumentDrawer } from '../../DocumentDrawer/index.js';
|
|
13
14
|
import { DrawerDepthProvider } from '../../Drawer/index.js';
|
|
14
|
-
import { DrawerActionHeader } from '../../DrawerActionHeader/index.js';
|
|
15
15
|
import { HierarchyColumnBrowser } from '../ColumnBrowser/index.js';
|
|
16
16
|
import { fetchAncestorPath } from './fetchAncestorPath.js';
|
|
17
17
|
import './index.css';
|
|
18
|
-
export const baseClass = 'hierarchy-
|
|
19
|
-
export const
|
|
18
|
+
export const baseClass = 'hierarchy-modal';
|
|
19
|
+
export const HierarchyModalContent = function HierarchyModalContent({
|
|
20
20
|
baseFilter,
|
|
21
|
-
|
|
21
|
+
closeModal,
|
|
22
22
|
columnBrowserRef,
|
|
23
23
|
disabledIds,
|
|
24
24
|
filterByCollection,
|
|
@@ -39,7 +39,7 @@ export const HierarchyDrawerContent = function HierarchyDrawerContent({
|
|
|
39
39
|
t
|
|
40
40
|
} = useTranslation();
|
|
41
41
|
// NOTE: Do NOT use useModal() here - it causes re-renders when any modal state changes
|
|
42
|
-
// Use
|
|
42
|
+
// Use closeModal prop instead which already handles closing the modal
|
|
43
43
|
const {
|
|
44
44
|
config: {
|
|
45
45
|
routes: {
|
|
@@ -58,6 +58,18 @@ export const HierarchyDrawerContent = function HierarchyDrawerContent({
|
|
|
58
58
|
const [isLoadingPath, setIsLoadingPath] = useState(Boolean(initialSelections?.length));
|
|
59
59
|
const hasLoadedPathRef = React.useRef(false);
|
|
60
60
|
const firstSelection = initialSelections?.[0];
|
|
61
|
+
const mapSelections = useCallback(ids => {
|
|
62
|
+
const map = new Map();
|
|
63
|
+
if (ids) {
|
|
64
|
+
for (const id of ids) {
|
|
65
|
+
map.set(id, {
|
|
66
|
+
id,
|
|
67
|
+
path: []
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return map;
|
|
72
|
+
}, []);
|
|
61
73
|
const loadAncestorPath = useEffectEvent(async itemId => {
|
|
62
74
|
if (!itemId) {
|
|
63
75
|
setIsLoadingPath(false);
|
|
@@ -86,30 +98,16 @@ export const HierarchyDrawerContent = function HierarchyDrawerContent({
|
|
|
86
98
|
hasLoadedPathRef.current = true;
|
|
87
99
|
void loadAncestorPath(firstSelection);
|
|
88
100
|
}, [firstSelection]);
|
|
89
|
-
const [selections, setSelections] = useState(() =>
|
|
90
|
-
const map = new Map();
|
|
91
|
-
if (initialSelections) {
|
|
92
|
-
for (const id of initialSelections) {
|
|
93
|
-
map.set(id, {
|
|
94
|
-
id,
|
|
95
|
-
path: []
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return map;
|
|
100
|
-
});
|
|
101
|
+
const [selections, setSelections] = useState(() => mapSelections(initialSelections));
|
|
101
102
|
const selectedIds = useMemo(() => new Set(selections.keys()), [selections]);
|
|
102
103
|
// For now, ancestorsWithSelections is empty - will be computed when we have path tracking
|
|
103
104
|
const ancestorsWithSelections = useMemo(() => new Set(), []);
|
|
104
|
-
const handleCancel = useCallback(() => {
|
|
105
|
-
closeDrawer();
|
|
106
|
-
}, [closeDrawer]);
|
|
107
105
|
const handleSave = useCallback(() => {
|
|
108
106
|
onSave({
|
|
109
|
-
|
|
107
|
+
closeModal,
|
|
110
108
|
selections
|
|
111
109
|
});
|
|
112
|
-
}, [onSave, selections,
|
|
110
|
+
}, [onSave, selections, closeModal]);
|
|
113
111
|
const handleSelect = useCallback(({
|
|
114
112
|
id: id_0,
|
|
115
113
|
path: path_0
|
|
@@ -134,6 +132,10 @@ export const HierarchyDrawerContent = function HierarchyDrawerContent({
|
|
|
134
132
|
const handleClearAll = useCallback(() => {
|
|
135
133
|
setSelections(new Map());
|
|
136
134
|
}, []);
|
|
135
|
+
const handleCancel = useCallback(() => {
|
|
136
|
+
setSelections(mapSelections(initialSelections));
|
|
137
|
+
closeModal();
|
|
138
|
+
}, [closeModal, initialSelections, mapSelections]);
|
|
137
139
|
// Expose selectItem for programmatic selection (e.g., after creating a new item)
|
|
138
140
|
useImperativeHandle(ref, () => ({
|
|
139
141
|
selectItem: id_1 => {
|
|
@@ -154,66 +156,88 @@ export const HierarchyDrawerContent = function HierarchyDrawerContent({
|
|
|
154
156
|
const selectionCount = selections.size;
|
|
155
157
|
return /*#__PURE__*/_jsxs("div", {
|
|
156
158
|
className: `${baseClass}__content`,
|
|
157
|
-
children: [/*#__PURE__*/_jsx(
|
|
158
|
-
onCancel: handleCancel,
|
|
159
|
-
onSave: handleSave,
|
|
160
|
-
saveLabel: t('general:select'),
|
|
159
|
+
children: [/*#__PURE__*/_jsx(DialogHeader, {
|
|
161
160
|
title: t('general:selectValue', {
|
|
162
161
|
label: collectionLabel
|
|
162
|
+
}),
|
|
163
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
164
|
+
className: `${baseClass}__header-actions`,
|
|
165
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
166
|
+
buttonStyle: "secondary",
|
|
167
|
+
margin: false,
|
|
168
|
+
onClick: handleCancel,
|
|
169
|
+
size: "medium",
|
|
170
|
+
children: t('general:cancel')
|
|
171
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
172
|
+
margin: false,
|
|
173
|
+
onClick: handleSave,
|
|
174
|
+
size: "medium",
|
|
175
|
+
children: t('general:select')
|
|
176
|
+
})]
|
|
163
177
|
})
|
|
164
|
-
}), /*#__PURE__*/_jsxs(
|
|
165
|
-
className: `${baseClass}__subheader`,
|
|
178
|
+
}), /*#__PURE__*/_jsxs(DialogBody, {
|
|
166
179
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
167
|
-
className: `${baseClass}__subheader
|
|
168
|
-
children: [
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
className: `${baseClass}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
children:
|
|
182
|
-
}), /*#__PURE__*/
|
|
183
|
-
children: "
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
180
|
+
className: `${baseClass}__subheader`,
|
|
181
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
182
|
+
className: `${baseClass}__subheader-left`,
|
|
183
|
+
children: [Icon || /*#__PURE__*/_jsx(TagIcon, {}), /*#__PURE__*/_jsx("h4", {
|
|
184
|
+
children: collectionLabel
|
|
185
|
+
})]
|
|
186
|
+
}), /*#__PURE__*/_jsxs("div", {
|
|
187
|
+
className: `${baseClass}__subheader-right`,
|
|
188
|
+
children: [showMoveToRoot && onMoveToRoot && /*#__PURE__*/_jsx(Button, {
|
|
189
|
+
buttonStyle: "ghost",
|
|
190
|
+
className: `${baseClass}__move-to-root`,
|
|
191
|
+
margin: false,
|
|
192
|
+
onClick: onMoveToRoot,
|
|
193
|
+
size: "medium",
|
|
194
|
+
children: t('hierarchy:moveToRoot')
|
|
195
|
+
}), Boolean(selectionCount) && /*#__PURE__*/_jsxs(_Fragment, {
|
|
196
|
+
children: [/*#__PURE__*/_jsx("span", {
|
|
197
|
+
className: `${baseClass}__selection-info`,
|
|
198
|
+
children: t('general:selectedCount', {
|
|
199
|
+
count: selectionCount,
|
|
200
|
+
label: ''
|
|
201
|
+
})
|
|
202
|
+
}), /*#__PURE__*/_jsx("span", {
|
|
203
|
+
children: "—"
|
|
204
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
205
|
+
buttonStyle: "ghost",
|
|
206
|
+
className: `${baseClass}__clear-all`,
|
|
207
|
+
margin: false,
|
|
208
|
+
onClick: handleClearAll,
|
|
209
|
+
size: "medium",
|
|
210
|
+
children: t('general:clear')
|
|
211
|
+
})]
|
|
189
212
|
})]
|
|
190
213
|
})]
|
|
214
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
215
|
+
className: `${baseClass}__columns`,
|
|
216
|
+
children: /*#__PURE__*/_jsx(HierarchyColumnBrowser, {
|
|
217
|
+
ancestorsWithSelections: ancestorsWithSelections,
|
|
218
|
+
baseFilter: baseFilter,
|
|
219
|
+
disabledIds: disabledIds,
|
|
220
|
+
filterByCollection: filterByCollection,
|
|
221
|
+
hierarchyCollectionSlug: hierarchyCollectionSlug,
|
|
222
|
+
initialExpandedPath: initialExpandedPath,
|
|
223
|
+
isLoadingPath: isLoadingPath,
|
|
224
|
+
onCreateNew: onCreateNew,
|
|
225
|
+
onSelect: handleSelect,
|
|
226
|
+
parentFieldName: parentFieldName,
|
|
227
|
+
ref: columnBrowserRef,
|
|
228
|
+
selectedIds: selectedIds,
|
|
229
|
+
useAsTitle: useAsTitle
|
|
230
|
+
})
|
|
191
231
|
})]
|
|
192
|
-
}), /*#__PURE__*/_jsx("div", {
|
|
193
|
-
className: `${baseClass}__columns`,
|
|
194
|
-
children: /*#__PURE__*/_jsx(HierarchyColumnBrowser, {
|
|
195
|
-
ancestorsWithSelections: ancestorsWithSelections,
|
|
196
|
-
baseFilter: baseFilter,
|
|
197
|
-
disabledIds: disabledIds,
|
|
198
|
-
filterByCollection: filterByCollection,
|
|
199
|
-
hierarchyCollectionSlug: hierarchyCollectionSlug,
|
|
200
|
-
initialExpandedPath: initialExpandedPath,
|
|
201
|
-
isLoadingPath: isLoadingPath,
|
|
202
|
-
onCreateNew: onCreateNew,
|
|
203
|
-
onSelect: handleSelect,
|
|
204
|
-
parentFieldName: parentFieldName,
|
|
205
|
-
ref: columnBrowserRef,
|
|
206
|
-
selectedIds: selectedIds,
|
|
207
|
-
useAsTitle: useAsTitle
|
|
208
|
-
})
|
|
209
232
|
})]
|
|
210
233
|
});
|
|
211
234
|
};
|
|
212
|
-
export const
|
|
235
|
+
export const HierarchyModal = props => {
|
|
213
236
|
const {
|
|
214
|
-
drawerSlug,
|
|
215
237
|
hierarchyCollectionSlug,
|
|
216
|
-
|
|
238
|
+
modalSlug,
|
|
239
|
+
parentFieldName,
|
|
240
|
+
reopenCount
|
|
217
241
|
} = props;
|
|
218
242
|
const {
|
|
219
243
|
refreshTree
|
|
@@ -231,12 +255,12 @@ export const HierarchyDrawer = props => {
|
|
|
231
255
|
// Ref to access column browser's refresh function
|
|
232
256
|
const columnBrowserRef = useRef(null);
|
|
233
257
|
// Ref to access drawer content's selectItem function
|
|
234
|
-
const
|
|
258
|
+
const modalContentRef = useRef(null);
|
|
235
259
|
// Key for DocumentDrawer to force remount when parentId changes
|
|
236
260
|
const [documentDrawerKey, setDocumentDrawerKey] = useState(0);
|
|
237
261
|
// Stable drawer slug for the document drawer - must not change on remount
|
|
238
|
-
const documentDrawerSlug = `${
|
|
239
|
-
// Document drawer for creating new items - rendered OUTSIDE the
|
|
262
|
+
const documentDrawerSlug = `${modalSlug}-create-doc`;
|
|
263
|
+
// Document drawer for creating new items - rendered OUTSIDE the modal to avoid nested modal issues
|
|
240
264
|
const [DocumentDrawer,, {
|
|
241
265
|
closeDrawer: closeDocumentDrawer,
|
|
242
266
|
openDrawer: openDocumentDrawer
|
|
@@ -262,26 +286,26 @@ export const HierarchyDrawer = props => {
|
|
|
262
286
|
if (columnBrowserRef.current && createParentId !== undefined) {
|
|
263
287
|
void columnBrowserRef.current.refreshColumn(createParentId);
|
|
264
288
|
}
|
|
265
|
-
if (
|
|
266
|
-
|
|
289
|
+
if (modalContentRef.current && doc?.id) {
|
|
290
|
+
modalContentRef.current.selectItem(doc.id);
|
|
267
291
|
}
|
|
268
292
|
refreshTree(hierarchyCollectionSlug);
|
|
269
293
|
closeDocumentDrawer();
|
|
270
294
|
}, [closeDocumentDrawer, createParentId, hierarchyCollectionSlug, refreshTree]);
|
|
271
295
|
// Memoize the content - only depends on stable values
|
|
272
|
-
const
|
|
296
|
+
const modalContent = useMemo(() => /*#__PURE__*/_jsx(HierarchyModalContent, {
|
|
273
297
|
...props,
|
|
274
298
|
columnBrowserRef: columnBrowserRef,
|
|
275
299
|
onCreateNew: handleCreateNew,
|
|
276
|
-
ref:
|
|
277
|
-
}), [handleCreateNew, props]);
|
|
300
|
+
ref: modalContentRef
|
|
301
|
+
}, reopenCount), [handleCreateNew, props, reopenCount]);
|
|
278
302
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
279
303
|
children: [/*#__PURE__*/_jsx(DialogModal, {
|
|
280
304
|
className: baseClass,
|
|
281
305
|
closeOnBlur: true,
|
|
282
306
|
size: "large",
|
|
283
|
-
slug:
|
|
284
|
-
children:
|
|
307
|
+
slug: modalSlug,
|
|
308
|
+
children: modalContent
|
|
285
309
|
}), /*#__PURE__*/_jsx(DrawerDepthProvider, {
|
|
286
310
|
children: /*#__PURE__*/_jsx(DocumentDrawer, {
|
|
287
311
|
initialData: createParentId !== null ? {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["getTranslation","React","useCallback","useEffect","useImperativeHandle","useMemo","useRef","useState","useEffectEvent","TagIcon","useConfig","useHierarchy","useTranslation","Button","DialogBody","DialogHeader","DialogModal","useDocumentDrawer","DrawerDepthProvider","HierarchyColumnBrowser","fetchAncestorPath","baseClass","HierarchyModalContent","baseFilter","closeModal","columnBrowserRef","disabledIds","filterByCollection","hasMany","hierarchyCollectionSlug","Icon","initialSelections","onCreateNew","onMoveToRoot","onSave","parentFieldName","ref","showMoveToRoot","useAsTitle","i18n","t","config","routes","api","serverURL","getEntityConfig","collectionConfig","collectionSlug","collectionLabel","labels","plural","parentFieldName_internal","hierarchy","initialExpandedPath","setInitialExpandedPath","isLoadingPath","setIsLoadingPath","Boolean","length","hasLoadedPathRef","firstSelection","mapSelections","ids","map","Map","id","set","path","loadAncestorPath","itemId","current","selections","setSelections","selectedIds","Set","keys","ancestorsWithSelections","handleSave","handleSelect","prev","next","has","delete","clear","handleClearAll","handleCancel","selectItem","selectionCount","size","_jsxs","className","_jsx","title","label","buttonStyle","margin","onClick","_Fragment","count","onSelect","HierarchyModal","props","modalSlug","reopenCount","refreshTree","createParentId","setCreateParentId","modalContentRef","documentDrawerKey","setDocumentDrawerKey","documentDrawerSlug","DocumentDrawer","closeDrawer","closeDocumentDrawer","openDrawer","openDocumentDrawer","drawerSlug","handleCreateNew","parentId","setTimeout","handleDocumentSave","doc","undefined","refreshColumn","modalContent","closeOnBlur","slug","initialData"],"sources":["../../../../src/elements/Hierarchy/Modal/index.tsx"],"sourcesContent":["'use client'\nimport { getTranslation } from '@payloadcms/translations'\nimport React, {\n useCallback,\n useEffect,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from 'react'\n\nimport type { HierarchyColumnBrowserRef } from '../ColumnBrowser/index.js'\nimport type { HierarchyModalInternalProps, SelectionWithPath } from './types.js'\n\nimport { useEffectEvent } from '../../../hooks/useEffectEvent.js'\nimport { TagIcon } from '../../../icons/Tag/index.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useHierarchy } from '../../../providers/Hierarchy/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { Button } from '../../Button/index.js'\nimport { DialogBody, DialogHeader, DialogModal } from '../../Dialog/index.js'\nimport { useDocumentDrawer } from '../../DocumentDrawer/index.js'\nimport { DrawerDepthProvider } from '../../Drawer/index.js'\nimport { HierarchyColumnBrowser } from '../ColumnBrowser/index.js'\nimport { fetchAncestorPath } from './fetchAncestorPath.js'\nimport './index.css'\n\nexport const baseClass = 'hierarchy-modal'\n\ntype HierarchyModalContentProps = {\n columnBrowserRef?: React.RefObject<HierarchyColumnBrowserRef | null>\n onCreateNew?: (params: { parentId: null | number | string }) => void\n} & HierarchyModalInternalProps\n\nexport type HierarchyModalContentRef = {\n selectItem: (id: number | string) => void\n}\n\nexport const HierarchyModalContent = function HierarchyModalContent({\n baseFilter,\n closeModal,\n columnBrowserRef,\n disabledIds,\n filterByCollection,\n hasMany = false,\n hierarchyCollectionSlug,\n Icon,\n initialSelections,\n onCreateNew,\n onMoveToRoot,\n onSave,\n parentFieldName,\n ref,\n showMoveToRoot,\n useAsTitle,\n}: { ref?: React.RefObject<HierarchyModalContentRef | null> } & HierarchyModalContentProps) {\n const { i18n, t } = useTranslation()\n // NOTE: Do NOT use useModal() here - it causes re-renders when any modal state changes\n // Use closeModal prop instead which already handles closing the modal\n const {\n config: {\n routes: { api },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const collectionConfig = getEntityConfig({ collectionSlug: hierarchyCollectionSlug })\n const collectionLabel = collectionConfig\n ? getTranslation(collectionConfig.labels?.plural || hierarchyCollectionSlug, i18n)\n : hierarchyCollectionSlug\n\n const parentFieldName_internal =\n collectionConfig?.hierarchy && typeof collectionConfig.hierarchy === 'object'\n ? collectionConfig.hierarchy.parentFieldName\n : parentFieldName\n\n const [initialExpandedPath, setInitialExpandedPath] = useState<(number | string)[] | undefined>()\n const [isLoadingPath, setIsLoadingPath] = useState(Boolean(initialSelections?.length))\n const hasLoadedPathRef = React.useRef(false)\n const firstSelection = initialSelections?.[0]\n\n const mapSelections = useCallback((ids?: (number | string)[]) => {\n const map = new Map<number | string, SelectionWithPath>()\n\n if (ids) {\n for (const id of ids) {\n map.set(id, { id, path: [] })\n }\n }\n\n return map\n }, [])\n\n const loadAncestorPath = useEffectEvent(async (itemId?: number | string) => {\n if (!itemId) {\n setIsLoadingPath(false)\n return\n }\n\n try {\n const path = await fetchAncestorPath({\n api,\n collectionSlug: hierarchyCollectionSlug,\n itemId,\n parentFieldName: parentFieldName_internal,\n serverURL,\n })\n setInitialExpandedPath(path)\n } catch {\n // Silently handle fetch errors - will just start at root\n } finally {\n setIsLoadingPath(false)\n }\n })\n\n // Load ancestor path on mount\n useEffect(() => {\n if (hasLoadedPathRef.current) {\n return\n }\n hasLoadedPathRef.current = true\n void loadAncestorPath(firstSelection)\n }, [firstSelection])\n\n const [selections, setSelections] = useState<Map<number | string, SelectionWithPath>>(() =>\n mapSelections(initialSelections),\n )\n\n const selectedIds = useMemo(() => new Set(selections.keys()), [selections])\n\n // For now, ancestorsWithSelections is empty - will be computed when we have path tracking\n const ancestorsWithSelections = useMemo(() => new Set<number | string>(), [])\n\n const handleSave = useCallback(() => {\n onSave({ closeModal, selections })\n }, [onSave, selections, closeModal])\n\n const handleSelect = useCallback(\n ({\n id,\n path,\n }: {\n id: number | string\n path: Array<{ id: number | string; title: string }>\n }) => {\n setSelections((prev) => {\n const next = new Map(prev)\n\n if (next.has(id)) {\n next.delete(id)\n } else {\n if (!hasMany) {\n // Single select: clear previous selections\n next.clear()\n }\n next.set(id, { id, path })\n }\n\n return next\n })\n },\n [hasMany],\n )\n\n const handleClearAll = useCallback(() => {\n setSelections(new Map())\n }, [])\n\n const handleCancel = useCallback(() => {\n setSelections(mapSelections(initialSelections))\n closeModal()\n }, [closeModal, initialSelections, mapSelections])\n\n // Expose selectItem for programmatic selection (e.g., after creating a new item)\n useImperativeHandle(\n ref,\n () => ({\n selectItem: (id: number | string) => {\n setSelections((prev) => {\n const next = new Map(prev)\n if (!hasMany) {\n next.clear()\n }\n // Path will be empty for newly created items - could be enhanced later\n next.set(id, { id, path: [] })\n return next\n })\n },\n }),\n [hasMany],\n )\n\n const selectionCount = selections.size\n\n return (\n <div className={`${baseClass}__content`}>\n <DialogHeader title={t('general:selectValue', { label: collectionLabel })}>\n <div className={`${baseClass}__header-actions`}>\n <Button buttonStyle=\"secondary\" margin={false} onClick={handleCancel} size=\"medium\">\n {t('general:cancel')}\n </Button>\n <Button margin={false} onClick={handleSave} size=\"medium\">\n {t('general:select')}\n </Button>\n </div>\n </DialogHeader>\n <DialogBody>\n <div className={`${baseClass}__subheader`}>\n <div className={`${baseClass}__subheader-left`}>\n {Icon || <TagIcon />}\n <h4>{collectionLabel}</h4>\n </div>\n <div className={`${baseClass}__subheader-right`}>\n {showMoveToRoot && onMoveToRoot && (\n <Button\n buttonStyle=\"ghost\"\n className={`${baseClass}__move-to-root`}\n margin={false}\n onClick={onMoveToRoot}\n size=\"medium\"\n >\n {t('hierarchy:moveToRoot')}\n </Button>\n )}\n {Boolean(selectionCount) && (\n <>\n {\n <span className={`${baseClass}__selection-info`}>\n {t('general:selectedCount', { count: selectionCount, label: '' })}\n </span>\n }\n <span>—</span>\n <Button\n buttonStyle=\"ghost\"\n className={`${baseClass}__clear-all`}\n margin={false}\n onClick={handleClearAll}\n size=\"medium\"\n >\n {t('general:clear')}\n </Button>\n </>\n )}\n </div>\n </div>\n <div className={`${baseClass}__columns`}>\n <HierarchyColumnBrowser\n ancestorsWithSelections={ancestorsWithSelections}\n baseFilter={baseFilter}\n disabledIds={disabledIds}\n filterByCollection={filterByCollection}\n hierarchyCollectionSlug={hierarchyCollectionSlug}\n initialExpandedPath={initialExpandedPath}\n isLoadingPath={isLoadingPath}\n onCreateNew={onCreateNew}\n onSelect={handleSelect}\n parentFieldName={parentFieldName}\n ref={columnBrowserRef}\n selectedIds={selectedIds}\n useAsTitle={useAsTitle}\n />\n </div>\n </DialogBody>\n </div>\n )\n}\n\nexport const HierarchyModal: React.FC<HierarchyModalInternalProps> = (props) => {\n const { hierarchyCollectionSlug, modalSlug, parentFieldName, reopenCount } = props\n\n const { refreshTree } = useHierarchy()\n\n // Get parentFieldName from hierarchy config\n const { getEntityConfig } = useConfig()\n const collectionConfig = getEntityConfig({ collectionSlug: hierarchyCollectionSlug })\n const parentFieldName_internal =\n collectionConfig?.hierarchy && typeof collectionConfig.hierarchy === 'object'\n ? collectionConfig.hierarchy.parentFieldName\n : parentFieldName\n\n // Track which parentId is being used for the document drawer - use state to trigger re-render\n const [createParentId, setCreateParentId] = useState<null | number | string>(null)\n\n // Ref to access column browser's refresh function\n const columnBrowserRef = useRef<HierarchyColumnBrowserRef | null>(null)\n\n // Ref to access drawer content's selectItem function\n const modalContentRef = useRef<HierarchyModalContentRef | null>(null)\n\n // Key for DocumentDrawer to force remount when parentId changes\n const [documentDrawerKey, setDocumentDrawerKey] = useState(0)\n\n // Stable drawer slug for the document drawer - must not change on remount\n const documentDrawerSlug = `${modalSlug}-create-doc`\n\n // Document drawer for creating new items - rendered OUTSIDE the modal to avoid nested modal issues\n const [DocumentDrawer, , { closeDrawer: closeDocumentDrawer, openDrawer: openDocumentDrawer }] =\n useDocumentDrawer({\n collectionSlug: hierarchyCollectionSlug,\n drawerSlug: documentDrawerSlug,\n })\n\n const handleCreateNew = useCallback(\n ({ parentId }: { parentId: null | number | string }) => {\n // Increment key to force DocumentDrawer remount with new initialData\n setDocumentDrawerKey((prev) => prev + 1)\n setCreateParentId(parentId)\n // Use setTimeout to ensure state update triggers re-render before opening drawer\n setTimeout(() => {\n openDocumentDrawer()\n }, 0)\n },\n [openDocumentDrawer],\n )\n\n // Refresh the column, select the new item, and close the document drawer after creation\n const handleDocumentSave = useCallback<\n NonNullable<React.ComponentProps<typeof DocumentDrawer>['onSave']>\n >(\n ({ doc }) => {\n if (columnBrowserRef.current && createParentId !== undefined) {\n void columnBrowserRef.current.refreshColumn(createParentId)\n }\n if (modalContentRef.current && doc?.id) {\n modalContentRef.current.selectItem(doc.id)\n }\n refreshTree(hierarchyCollectionSlug)\n closeDocumentDrawer()\n },\n [closeDocumentDrawer, createParentId, hierarchyCollectionSlug, refreshTree],\n )\n\n // Memoize the content - only depends on stable values\n const modalContent = useMemo(\n () => (\n <HierarchyModalContent\n key={reopenCount}\n {...props}\n columnBrowserRef={columnBrowserRef}\n onCreateNew={handleCreateNew}\n ref={modalContentRef}\n />\n ),\n [handleCreateNew, props, reopenCount],\n )\n\n return (\n <>\n <DialogModal className={baseClass} closeOnBlur size=\"large\" slug={modalSlug}>\n {modalContent}\n </DialogModal>\n <DrawerDepthProvider>\n <DocumentDrawer\n initialData={\n createParentId !== null ? { [parentFieldName_internal]: createParentId } : undefined\n }\n key={documentDrawerKey}\n onSave={handleDocumentSave}\n />\n </DrawerDepthProvider>\n </>\n )\n}\n"],"mappings":"AAAA;;;AACA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IACLC,WAAW,EACXC,SAAS,EACTC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACH;AAKP,SAASC,cAAc,QAAQ;AAC/B,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAC1B,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,UAAU,EAAEC,YAAY,EAAEC,WAAW,QAAQ;AACtD,SAASC,iBAAiB,QAAQ;AAClC,SAASC,mBAAmB,QAAQ;AACpC,SAASC,sBAAsB,QAAQ;AACvC,SAASC,iBAAiB,QAAQ;AAClC,OAAO;AAEP,OAAO,MAAMC,SAAA,GAAY;AAWzB,OAAO,MAAMC,qBAAA,GAAwB,SAASA,sBAAsB;EAClEC,UAAU;EACVC,UAAU;EACVC,gBAAgB;EAChBC,WAAW;EACXC,kBAAkB;EAClBC,OAAA,GAAU,KAAK;EAC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B;qBAEHjC,IAAA,CAACzE,mBAAA;gBACC,aAAAyE,IAAA,CAACoB,cAAA;QACCgB,WAAA,EACEtB,cAAA,KAAmB,OAAO;UAAE,CAACtD,wBAAA,GAA2BsD;QAAe,IAAIiB,SAAA;QAG7ExF,MAAA,EAAQsF;SADHZ,iBAAA;;;AAMf","ignoreList":[]}
|
|
@@ -8,7 +8,7 @@ export type SelectionWithPath = {
|
|
|
8
8
|
title: string;
|
|
9
9
|
}>;
|
|
10
10
|
};
|
|
11
|
-
export type
|
|
11
|
+
export type UseHierarchyModalArgs = {
|
|
12
12
|
/** IDs that should be disabled (e.g., items being moved can't be selected as destination) */
|
|
13
13
|
disabledIds?: Set<number | string>;
|
|
14
14
|
/**
|
|
@@ -19,23 +19,22 @@ export type UseHierarchyDrawerArgs = {
|
|
|
19
19
|
hierarchyCollectionSlug: string;
|
|
20
20
|
Icon?: React.ReactNode;
|
|
21
21
|
};
|
|
22
|
-
export type
|
|
22
|
+
export type HierarchyModalProps = {
|
|
23
23
|
readonly hasMany?: boolean;
|
|
24
24
|
readonly initialSelections?: (number | string)[];
|
|
25
25
|
readonly onMoveToRoot?: () => void;
|
|
26
26
|
readonly onSave: (params: {
|
|
27
|
-
|
|
27
|
+
closeModal: () => void;
|
|
28
28
|
selections: Map<number | string, SelectionWithPath>;
|
|
29
29
|
}) => void;
|
|
30
30
|
readonly showMoveToRoot?: boolean;
|
|
31
31
|
};
|
|
32
|
-
export type
|
|
32
|
+
export type HierarchyModalInternalProps = {
|
|
33
33
|
/** Base filter constraint (e.g., tenant filter) to apply to all queries */
|
|
34
34
|
readonly baseFilter?: null | Where;
|
|
35
|
-
readonly
|
|
35
|
+
readonly closeModal: () => void;
|
|
36
36
|
/** IDs that should be disabled (e.g., items being moved can't be selected as destination) */
|
|
37
37
|
readonly disabledIds?: Set<number | string>;
|
|
38
|
-
readonly drawerSlug: string;
|
|
39
38
|
/**
|
|
40
39
|
* When provided, filters hierarchy items to only show those that accept these collections.
|
|
41
40
|
* Used with collectionSpecific hierarchy config.
|
|
@@ -43,26 +42,31 @@ export type HierarchyDrawerInternalProps = {
|
|
|
43
42
|
readonly filterByCollection?: string[];
|
|
44
43
|
readonly hierarchyCollectionSlug: string;
|
|
45
44
|
readonly Icon?: React.ReactNode;
|
|
45
|
+
readonly modalSlug: string;
|
|
46
46
|
readonly parentFieldName: string;
|
|
47
|
+
readonly reopenCount?: number;
|
|
47
48
|
readonly useAsTitle?: string;
|
|
48
|
-
} &
|
|
49
|
-
export type
|
|
49
|
+
} & HierarchyModalProps;
|
|
50
|
+
export type HierarchyModalTogglerProps = {
|
|
50
51
|
children?: React.ReactNode;
|
|
51
52
|
className?: string;
|
|
52
53
|
disabled?: boolean;
|
|
53
|
-
|
|
54
|
+
modalSlug?: string;
|
|
54
55
|
} & HTMLAttributes<HTMLButtonElement>;
|
|
55
|
-
export type
|
|
56
|
-
React.FC<
|
|
57
|
-
React.FC<Omit<
|
|
56
|
+
export type UseHierarchyModal = (args: UseHierarchyModalArgs) => [
|
|
57
|
+
React.FC<HierarchyModalProps>,
|
|
58
|
+
React.FC<Omit<HierarchyModalTogglerProps, 'modalSlug'>>,
|
|
58
59
|
{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
closeModal: () => void;
|
|
61
|
+
isModalOpen: boolean;
|
|
62
|
+
modalDepth: number;
|
|
63
|
+
modalSlug: string;
|
|
64
|
+
openModal: () => void;
|
|
65
|
+
toggleModal: () => void;
|
|
65
66
|
}
|
|
66
67
|
];
|
|
68
|
+
export type HierarchyDrawerProps = HierarchyModalProps;
|
|
69
|
+
export type HierarchyDrawerInternalProps = HierarchyModalInternalProps;
|
|
70
|
+
export type HierarchyDrawerTogglerProps = HierarchyModalTogglerProps;
|
|
67
71
|
export type { ColumnItemData } from '../ColumnBrowser/types.js';
|
|
68
72
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1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,CAAA;AAGD,MAAM,MAAM,oBAAoB,GAAG,mBAAmB,CAAA;AACtD,MAAM,MAAM,4BAA4B,GAAG,2BAA2B,CAAA;AACtE,MAAM,MAAM,2BAA2B,GAAG,0BAA0B,CAAA;AAGpE,YAAY,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../../src/elements/Hierarchy/Modal/types.ts"],"sourcesContent":["import type { Where } from 'payload'\nimport type React from 'react'\nimport type { HTMLAttributes } from 'react'\n\nexport type SelectionWithPath = {\n id: number | string\n path: Array<{ id: number | string; title: string }>\n}\n\nexport type UseHierarchyModalArgs = {\n /** IDs that should be disabled (e.g., items being moved can't be selected as destination) */\n disabledIds?: Set<number | string>\n /**\n * When provided, filters hierarchy items to only show those that accept these collections.\n * Used with collectionSpecific hierarchy config.\n */\n filterByCollection?: string[]\n hierarchyCollectionSlug: string\n Icon?: React.ReactNode\n}\n\nexport type HierarchyModalProps = {\n readonly hasMany?: boolean\n readonly initialSelections?: (number | string)[]\n readonly onMoveToRoot?: () => void\n readonly onSave: (params: {\n closeModal: () => void\n selections: Map<number | string, SelectionWithPath>\n }) => void\n readonly showMoveToRoot?: boolean\n}\n\nexport type HierarchyModalInternalProps = {\n /** Base filter constraint (e.g., tenant filter) to apply to all queries */\n readonly baseFilter?: null | Where\n readonly closeModal: () => void\n /** IDs that should be disabled (e.g., items being moved can't be selected as destination) */\n readonly disabledIds?: Set<number | string>\n /**\n * When provided, filters hierarchy items to only show those that accept these collections.\n * Used with collectionSpecific hierarchy config.\n */\n readonly filterByCollection?: string[]\n readonly hierarchyCollectionSlug: string\n readonly Icon?: React.ReactNode\n readonly modalSlug: string\n readonly parentFieldName: string\n readonly reopenCount?: number\n readonly useAsTitle?: string\n} & HierarchyModalProps\n\nexport type HierarchyModalTogglerProps = {\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n modalSlug?: string\n} & HTMLAttributes<HTMLButtonElement>\n\nexport type UseHierarchyModal = (args: UseHierarchyModalArgs) => [\n React.FC<HierarchyModalProps>,\n React.FC<Omit<HierarchyModalTogglerProps, 'modalSlug'>>,\n {\n closeModal: () => void\n isModalOpen: boolean\n modalDepth: number\n modalSlug: string\n openModal: () => void\n toggleModal: () => void\n },\n]\n\n// Backward-compatible aliases\nexport type HierarchyDrawerProps = HierarchyModalProps\nexport type HierarchyDrawerInternalProps = HierarchyModalInternalProps\nexport type HierarchyDrawerTogglerProps = HierarchyModalTogglerProps\n\n// Re-export column browser types for backwards compatibility\nexport type { ColumnItemData } from '../ColumnBrowser/types.js'\n"],"mappings":"AA4EA;AACA","ignoreList":[]}
|