@rebasepro/cms 0.26.0 → 0.28.0

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.
Files changed (67) hide show
  1. package/dist/collection_editor/serializable_utils.js +5 -2
  2. package/dist/collection_editor/serializable_utils.js.map +1 -1
  3. package/dist/collection_editor/ui/collection_editor/EnumForm.d.ts +17 -0
  4. package/dist/collection_editor/ui/collection_editor/EnumForm.js +31 -17
  5. package/dist/collection_editor/ui/collection_editor/EnumForm.js.map +1 -1
  6. package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js +6 -5
  7. package/dist/collection_editor/ui/collection_editor/properties/EnumPropertyField.js.map +1 -1
  8. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js +3 -2
  9. package/dist/components/CollectionTableBinding/internal/popup_field/PopupFormField.js.map +1 -1
  10. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js +32 -16
  11. package/dist/components/CollectionViewBinding/CollectionListViewBinding.js.map +1 -1
  12. package/dist/components/DefaultDrawer.js +3 -2
  13. package/dist/components/DefaultDrawer.js.map +1 -1
  14. package/dist/components/DetailViewBinding.js +4 -3
  15. package/dist/components/DetailViewBinding.js.map +1 -1
  16. package/dist/components/EditViewBinding.js +23 -5
  17. package/dist/components/EditViewBinding.js.map +1 -1
  18. package/dist/components/EntityPreviewBinding.js +1 -0
  19. package/dist/components/EntityPreviewBinding.js.map +1 -1
  20. package/dist/components/HomePage/ContentHomePage.js +3 -2
  21. package/dist/components/HomePage/ContentHomePage.js.map +1 -1
  22. package/dist/components/SelectableTable/filters/StringNumberFilterField.js +3 -3
  23. package/dist/components/SelectableTable/filters/StringNumberFilterField.js.map +1 -1
  24. package/dist/components/SidePanelBinding.js +7 -6
  25. package/dist/components/SidePanelBinding.js.map +1 -1
  26. package/dist/components/app/Scaffold.js +16 -1
  27. package/dist/components/app/Scaffold.js.map +1 -1
  28. package/dist/components/history/EntityHistoryView.js +2 -1
  29. package/dist/components/history/EntityHistoryView.js.map +1 -1
  30. package/dist/data_export/export/export.js +3 -3
  31. package/dist/data_export/export/export.js.map +1 -1
  32. package/dist/data_import/import/ImportCollectionAction.js +10 -12
  33. package/dist/data_import/import/ImportCollectionAction.js.map +1 -1
  34. package/dist/data_import/utils/id_column.d.ts +19 -0
  35. package/dist/data_import/utils/id_column.js +19 -1
  36. package/dist/data_import/utils/id_column.js.map +1 -1
  37. package/dist/data_import/utils/transforms.js +24 -7
  38. package/dist/data_import/utils/transforms.js.map +1 -1
  39. package/dist/form/EntityForm.d.ts +1 -1
  40. package/dist/form/EntityForm.js +14 -4
  41. package/dist/form/EntityForm.js.map +1 -1
  42. package/dist/form/EntityFormBinding.js +12 -8
  43. package/dist/form/EntityFormBinding.js.map +1 -1
  44. package/dist/form/components/FieldBlock.js +2 -1
  45. package/dist/form/components/FieldBlock.js.map +1 -1
  46. package/dist/form/field_bindings/KeyValueFieldBinding.js +3 -1
  47. package/dist/form/field_bindings/KeyValueFieldBinding.js.map +1 -1
  48. package/dist/form/field_bindings/ReadOnlyFieldBinding.js +0 -2
  49. package/dist/form/field_bindings/ReadOnlyFieldBinding.js.map +1 -1
  50. package/dist/form/field_bindings/TextFieldBinding.js +3 -2
  51. package/dist/form/field_bindings/TextFieldBinding.js.map +1 -1
  52. package/dist/form/validation.js +12 -1
  53. package/dist/form/validation.js.map +1 -1
  54. package/dist/hooks/navigation/url_segments.d.ts +33 -0
  55. package/dist/hooks/navigation/url_segments.js +56 -0
  56. package/dist/hooks/navigation/url_segments.js.map +1 -0
  57. package/dist/hooks/navigation/useBuildUrlController.js +4 -2
  58. package/dist/hooks/navigation/useBuildUrlController.js.map +1 -1
  59. package/dist/hooks/useBuildSidePanel.js +6 -5
  60. package/dist/hooks/useBuildSidePanel.js.map +1 -1
  61. package/dist/hooks/useHistory.js +4 -3
  62. package/dist/hooks/useHistory.js.map +1 -1
  63. package/dist/routes/RebaseRoute.js +20 -30
  64. package/dist/routes/RebaseRoute.js.map +1 -1
  65. package/dist/util/navigation_utils.js +4 -3
  66. package/dist/util/navigation_utils.js.map +1 -1
  67. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"PopupFormField.js","names":[],"sources":["../../../../../src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx"],"sourcesContent":["import type { Properties } from \"@rebasepro/types\";\n\nimport type { FormContext, PropertyFieldBindingProps } from \"../../../../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport React, { useCallback, useEffect, useLayoutEffect, useState } from \"react\";\n\nimport { Button, DialogActions, IconButton, Portal, Typography, XIcon } from \"@rebasepro/ui\";\n\nimport { Entity, EntityValues } from \"@rebasepro/types\";\nimport { PluginProviderStack, useTranslation } from \"@rebasepro/app\";\nimport { Formex, FormexController, getIn, useCreateFormex } from \"@rebasepro/forms\";\nimport { useDraggable } from \"./useDraggable\";\nimport { applyValueTransforms, CustomFieldValidator, getEntitySchema } from \"../../../../form/validation\";\nimport { cellValidationProperties } from \"../../../../form/resolve_cell_property\";\nimport { useWindowSize } from \"./useWindowSize\";\nimport { getPropertyInPath } from \"../../../../util/property_utils\";\nimport { PropertyFieldBinding, zodToFormErrors } from \"../../../../form\";\nimport { useAuthController, useCustomizationController, useData, useRebaseContext } from \"@rebasepro/app\";\nimport type { OnCellValueChangeParams } from \"@rebasepro/app\";\nimport { isDisabled, isReadOnly } from \"@rebasepro/app\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\ninterface PopupFormFieldProps<M extends Record<string, unknown>> {\n customFieldValidator?: CustomFieldValidator;\n path: string;\n entityId: string | number;\n tableKey: string;\n propertyKey?: Extract<keyof M, string>;\n // `AdminCollection<M>`, not `<any>`: the admin block's key-shaped fields\n // (titleProperty, sort, propertiesOrder) are typed against M, and\n // `AdminCollection<any>` collapses them to `string` — which then fails to\n // flow into the `FormContext<M>` built below.\n collection?: AdminCollection<M>;\n cellRect?: DOMRect;\n open: boolean;\n onClose: () => void;\n container: HTMLElement | null;\n /**\n * Callback when the value of a cell has been edited\n * @param params\n */\n onCellValueChange?: (params: OnCellValueChangeParams<any, any>) => Promise<void> | void;\n}\n\nexport function PopupFormField<M extends Record<string, unknown>>(props: PopupFormFieldProps<M>) {\n if (!props.open) return null;\n return <PopupFormFieldLoading {...props}/>;\n\n}\n\nexport function PopupFormFieldLoading<M extends Record<string, unknown>>({\n tableKey,\n entityId,\n customFieldValidator,\n propertyKey,\n collection: inputCollection,\n path,\n cellRect,\n open,\n onClose,\n onCellValueChange,\n container\n}: PopupFormFieldProps<M>) {\n const dataClient = useData();\n const [entity, setEntity] = useState<Entity<M> | undefined>(undefined);\n useEffect(() => {\n if (entityId && inputCollection) {\n dataClient.collection(path).findById(entityId).then((result) => setEntity(result as Entity<M> | undefined));\n }\n }, [entityId, inputCollection, dataClient, path]);\n\n if (!entity) return null;\n return <PopupFormFieldInternal {...{\n tableKey,\n entityId,\n customFieldValidator,\n propertyKey,\n collection: inputCollection,\n path,\n cellRect,\n open,\n onClose,\n onCellValueChange,\n container\n }} entity={entity}/>;\n}\n\nexport function PopupFormFieldInternal<M extends Record<string, unknown>>({\n tableKey,\n entityId,\n customFieldValidator,\n propertyKey,\n collection,\n path,\n cellRect,\n open,\n onClose,\n onCellValueChange,\n container,\n entity\n}: PopupFormFieldProps<M> & {\n entity?: Entity<M>\n}) {\n const { t } = useTranslation();\n\n const rebaseContext = useRebaseContext();\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n\n const [savingError, setSavingError] = React.useState<any>();\n const [popupLocation, setPopupLocation] = useState<{\n x: number,\n y: number\n }>();\n\n const windowSize = useWindowSize();\n\n const draggableRef = React.useRef<HTMLDivElement>(null);\n const innerRef = React.useRef<HTMLDivElement>(null);\n\n const initialPositionSet = React.useRef<boolean>(false);\n\n const getInitialLocation = useCallback(() => {\n if (!cellRect) throw Error(\"getInitialLocation error\");\n\n return {\n x: cellRect.left < windowSize.width - cellRect.right\n ? cellRect.x + cellRect.width / 2\n : cellRect.x - cellRect.width / 2,\n y: cellRect.top < windowSize.height - cellRect.bottom\n ? cellRect.y + cellRect.height / 2\n : cellRect.y - cellRect.height / 2\n };\n }, [cellRect, windowSize.height, windowSize.width]);\n\n const normalizePosition = useCallback((\n pos: { x: number, y: number },\n draggableBoundingRect: DOMRect,\n currentWindowSize: { width: number, height: number }\n ) => {\n if (!draggableBoundingRect || draggableBoundingRect.width === 0 || draggableBoundingRect.height === 0) {\n return pos;\n }\n return {\n x: Math.max(0, Math.min(pos.x, currentWindowSize.width - draggableBoundingRect.width)),\n y: Math.max(0, Math.min(pos.y, currentWindowSize.height - draggableBoundingRect.height))\n };\n }, []);\n\n const updatePopupLocation = useCallback((newPositionCandidate?: {\n x: number,\n y: number\n }) => {\n const draggableBoundingRect = draggableRef.current?.getBoundingClientRect();\n if (!cellRect || !draggableBoundingRect || draggableBoundingRect.width === 0 || draggableBoundingRect.height === 0) {\n return;\n }\n const basePosition = newPositionCandidate ?? getInitialLocation();\n const newNormalizedPosition = normalizePosition(basePosition, draggableBoundingRect, windowSize);\n\n if (!popupLocation || newNormalizedPosition.x !== popupLocation.x || newNormalizedPosition.y !== popupLocation.y) {\n setPopupLocation(newNormalizedPosition);\n }\n }, [cellRect, getInitialLocation, normalizePosition, popupLocation, windowSize]);\n\n useDraggable({\n containerRef: draggableRef,\n innerRef,\n x: popupLocation?.x,\n y: popupLocation?.y,\n onMove: updatePopupLocation\n });\n\n useEffect(\n () => {\n initialPositionSet.current = false;\n },\n [propertyKey, entity]\n );\n\n useLayoutEffect(\n () => {\n if (!cellRect || initialPositionSet.current) return;\n // Ensure draggableRef is available and has dimensions before initial positioning\n const draggableBoundingRect = draggableRef.current?.getBoundingClientRect();\n if (!draggableBoundingRect || draggableBoundingRect.width === 0 || draggableBoundingRect.height === 0) {\n // If not ready, perhaps wait or log. For now, just return.\n // This might need a retry mechanism or ensure content is rendered first.\n return;\n }\n updatePopupLocation();\n initialPositionSet.current = true;\n },\n [cellRect, updatePopupLocation] // Removed initialPositionSet.current from deps as it's a ref\n );\n\n useLayoutEffect(\n () => {\n updatePopupLocation(popupLocation);\n },\n [windowSize, cellRect, updatePopupLocation, popupLocation]\n );\n\n // Built per validation, from the properties resolved against the values\n // the popup holds: a `conditions` rule or a `dynamicProps` validation\n // depends on them, as it does in the record form.\n const validationSchemaFor = (values: Partial<M>) => {\n if (!collection || !entityId || !propertyKey) return undefined;\n return getEntitySchema(\n entityId,\n cellValidationProperties<M>(collection.properties, propertyKey as string, values, entity?.values, entityId, {\n path,\n authController,\n propertyConfigs: customizationController.propertyConfigs\n }),\n customFieldValidator);\n };\n\n const adaptResize = useCallback(() => {\n // When the popup resizes, we want to re-evaluate its position\n // based on its current location and new dimensions.\n return updatePopupLocation(popupLocation);\n }, [popupLocation, updatePopupLocation]);\n\n // Setup ResizeObserver\n useEffect(() => {\n const element = draggableRef.current;\n if (!element) return;\n\n const observer = new ResizeObserver(() => {\n adaptResize();\n });\n\n observer.observe(element);\n\n return () => {\n observer.unobserve(element);\n observer.disconnect();\n };\n }, [adaptResize, draggableRef]);\n\n const saveValue = async (values: M) => {\n setSavingError(null);\n if (collection && entity && onCellValueChange && propertyKey) {\n // Written the way the form writes it: with the string transforms\n // the properties declare (`trim`, `lowercase`, `uppercase`) applied.\n const writtenValues = applyValueTransforms(values, collection.properties);\n return onCellValueChange({\n // By path: a spread map's child is `address.street`, which is\n // nested in the form values, not a key of them.\n value: getIn(writtenValues, propertyKey as string),\n propertyKey: propertyKey as string,\n data: entity,\n setError: setSavingError,\n onValueUpdated: () => {\n }\n });\n }\n return Promise.resolve();\n };\n\n const formex = useCreateFormex<M>({\n initialValues: (entity?.values ?? {}) as EntityValues<M>,\n validation: async (values) => {\n const validationSchema = validationSchemaFor(values);\n if (!validationSchema) return {};\n const result = await validationSchema.safeParseAsync(values);\n if (result.success) return {};\n return zodToFormErrors(result.error) as Record<string, string>;\n },\n validateOnInitialRender: true,\n onSubmit: (values, actions) => {\n saveValue(values)\n .then(() => {\n formex.resetForm({\n values: values\n })\n onClose();\n })\n .finally(() => actions.setSubmitting(false));\n }\n });\n\n const {\n values,\n isSubmitting,\n setFieldValue,\n handleSubmit\n } = formex;\n\n const disabled = isSubmitting;\n\n const formContext: FormContext<M> = {\n collection: collection,\n entityId,\n values,\n path,\n setFieldValue,\n save: saveValue,\n submit: handleSubmit,\n formex,\n status: \"existing\",\n openEntityMode: \"side_panel\",\n disabled: false\n };\n\n const property: Property | undefined = propertyKey && getPropertyInPath(collection?.properties ?? {} as Properties, propertyKey as string);\n const fieldProps: PropertyFieldBindingProps<M> | undefined = propertyKey && property\n ? {\n propertyKey: propertyKey as string,\n disabled: isSubmitting || isReadOnly(property) || isDisabled(property),\n property,\n includeDescription: false,\n underlyingValueHasChanged: false,\n context: formContext,\n partOfArray: false,\n minimalistView: true,\n autoFocus: open\n }\n : undefined;\n\n let internalForm = <>\n <div\n key={`popup_form_${tableKey}_${entityId}_${propertyKey}`}\n className=\"w-[700px] max-w-full max-h-[85vh]\">\n <form\n onSubmit={handleSubmit}\n noValidate>\n\n <div\n className=\"mb-1 p-4 flex flex-col relative\">\n <div\n ref={innerRef}\n className=\"cursor-auto\"\n style={{ cursor: \"auto !important\" }}>\n {fieldProps &&\n <PropertyFieldBinding {...fieldProps}/>}\n </div>\n </div>\n\n <DialogActions>\n <Button\n variant=\"filled\"\n color=\"primary\"\n type=\"submit\"\n disabled={disabled}\n >\n Save\n </Button>\n </DialogActions>\n\n </form>\n\n </div>\n\n </>;\n\n const plugins = customizationController.plugins;\n if (plugins && plugins.length > 0) {\n internalForm = (\n <PluginProviderStack\n plugins={plugins}\n scope=\"form\"\n scopeProps={{\n status: \"existing\",\n path,\n collection,\n entity,\n context: rebaseContext,\n currentEntityId: entityId,\n formContext\n }}>\n {internalForm}\n </PluginProviderStack>\n );\n }\n const form = <div\n className={`text-surface-900 dark:text-white overflow-auto rounded-xs rounded-md bg-surface-card ${!open ? \"hidden\" : \"\"} cursor-grab max-w-[100vw]`}>\n\n {internalForm}\n\n {savingError &&\n <Typography color={\"error\"}>\n {savingError.message}\n </Typography>\n }\n </div>;\n\n const draggable = (\n <div\n key={`draggable_${propertyKey as string}_${entityId}_${open}`}\n style={{\n boxShadow: \"0 0 0 2px rgba(128,128,128,0.2)\"\n }}\n className={`inline-block fixed z-20 shadow-outline rounded-md bg-surface-card ${!open ? \"invisible\" : \"visible\"\n } cursor-grab overflow-visible`}\n ref={draggableRef}>\n\n {/* ElementResizeListener removed from here */}\n\n <div\n className=\"overflow-hidden\">\n\n {form}\n\n <div\n className=\"absolute -top-3.5 -right-3.5 bg-surface-500 rounded-full\"\n style={{\n width: \"32px\",\n height: \"32px\"\n }}>\n <IconButton aria-label={t(\"close\")}\n size={\"small\"}\n onClick={(event) => {\n event.stopPropagation();\n onClose();\n }}>\n <XIcon className=\"text-white\"/>\n </IconButton>\n </div>\n </div>\n\n </div>\n );\n\n return (\n <Portal.Root asChild\n container={container}>\n <Formex value={formex as FormexController<Record<string, unknown>>}>\n {draggable}\n </Formex>\n </Portal.Root>\n );\n\n}\n"],"mappings":";;;;;;;;;;;;;AA4CA,SAAgB,eAAkD,OAA+B;CAC7F,IAAI,CAAC,MAAM,MAAM,OAAO;CACxB,OAAO,oBAAC,uBAAD,EAAuB,GAAI,MAAO,CAAA;AAE7C;AAEA,SAAgB,sBAAyD,EACrE,UACA,UACA,sBACA,aACA,YAAY,iBACZ,MACA,UACA,MACA,SACA,mBACA,aACuB;CACvB,MAAM,aAAa,QAAQ;CAC3B,MAAM,CAAC,QAAQ,aAAa,SAAgC,KAAA,CAAS;CACrE,gBAAgB;EACZ,IAAI,YAAY,iBACZ,WAAW,WAAW,IAAI,CAAC,CAAC,SAAS,QAAQ,CAAC,CAAC,MAAM,WAAW,UAAU,MAA+B,CAAC;CAElH,GAAG;EAAC;EAAU;EAAiB;EAAY;CAAI,CAAC;CAEhD,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO,oBAAC,wBAAD;EACH;EACA;EACA;EACA;EACA,YAAY;EACZ;EACA;EACA;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,WAAU,aAAa,CAAA;IACtB,CAAA;GACX,CAAA,CACJ;;CAEJ,GAhCI,aAAa,YAAsB,GAAG,SAAS,GAAG,MAgCtD;CAGT,OACI,oBAAC,OAAO,MAAR;EAAa,SAAA;EACE;YACX,oBAAC,QAAD;GAAQ,OAAO;aACV;EACG,CAAA;CACC,CAAA;AAGrB"}
1
+ {"version":3,"file":"PopupFormField.js","names":[],"sources":["../../../../../src/components/CollectionTableBinding/internal/popup_field/PopupFormField.tsx"],"sourcesContent":["import type { Properties } from \"@rebasepro/types\";\nimport { hasEntityId } from \"@rebasepro/common\";\n\nimport type { FormContext, PropertyFieldBindingProps } from \"../../../../types/fields\";\nimport type { Property } from \"@rebasepro/types\";\nimport React, { useCallback, useEffect, useLayoutEffect, useState } from \"react\";\n\nimport { Button, DialogActions, IconButton, Portal, Typography, XIcon } from \"@rebasepro/ui\";\n\nimport { Entity, EntityValues } from \"@rebasepro/types\";\nimport { PluginProviderStack, useTranslation } from \"@rebasepro/app\";\nimport { Formex, FormexController, getIn, useCreateFormex } from \"@rebasepro/forms\";\nimport { useDraggable } from \"./useDraggable\";\nimport { applyValueTransforms, CustomFieldValidator, getEntitySchema } from \"../../../../form/validation\";\nimport { cellValidationProperties } from \"../../../../form/resolve_cell_property\";\nimport { useWindowSize } from \"./useWindowSize\";\nimport { getPropertyInPath } from \"../../../../util/property_utils\";\nimport { PropertyFieldBinding, zodToFormErrors } from \"../../../../form\";\nimport { useAuthController, useCustomizationController, useData, useRebaseContext } from \"@rebasepro/app\";\nimport type { OnCellValueChangeParams } from \"@rebasepro/app\";\nimport { isDisabled, isReadOnly } from \"@rebasepro/app\";\nimport type { AdminCollection } from \"@rebasepro/cms-types\";\n\ninterface PopupFormFieldProps<M extends Record<string, unknown>> {\n customFieldValidator?: CustomFieldValidator;\n path: string;\n entityId: string | number;\n tableKey: string;\n propertyKey?: Extract<keyof M, string>;\n // `AdminCollection<M>`, not `<any>`: the admin block's key-shaped fields\n // (titleProperty, sort, propertiesOrder) are typed against M, and\n // `AdminCollection<any>` collapses them to `string` — which then fails to\n // flow into the `FormContext<M>` built below.\n collection?: AdminCollection<M>;\n cellRect?: DOMRect;\n open: boolean;\n onClose: () => void;\n container: HTMLElement | null;\n /**\n * Callback when the value of a cell has been edited\n * @param params\n */\n onCellValueChange?: (params: OnCellValueChangeParams<any, any>) => Promise<void> | void;\n}\n\nexport function PopupFormField<M extends Record<string, unknown>>(props: PopupFormFieldProps<M>) {\n if (!props.open) return null;\n return <PopupFormFieldLoading {...props}/>;\n\n}\n\nexport function PopupFormFieldLoading<M extends Record<string, unknown>>({\n tableKey,\n entityId,\n customFieldValidator,\n propertyKey,\n collection: inputCollection,\n path,\n cellRect,\n open,\n onClose,\n onCellValueChange,\n container\n}: PopupFormFieldProps<M>) {\n const dataClient = useData();\n const [entity, setEntity] = useState<Entity<M> | undefined>(undefined);\n useEffect(() => {\n if (hasEntityId(entityId) && inputCollection) {\n dataClient.collection(path).findById(entityId).then((result) => setEntity(result as Entity<M> | undefined));\n }\n }, [entityId, inputCollection, dataClient, path]);\n\n if (!entity) return null;\n return <PopupFormFieldInternal {...{\n tableKey,\n entityId,\n customFieldValidator,\n propertyKey,\n collection: inputCollection,\n path,\n cellRect,\n open,\n onClose,\n onCellValueChange,\n container\n }} entity={entity}/>;\n}\n\nexport function PopupFormFieldInternal<M extends Record<string, unknown>>({\n tableKey,\n entityId,\n customFieldValidator,\n propertyKey,\n collection,\n path,\n cellRect,\n open,\n onClose,\n onCellValueChange,\n container,\n entity\n}: PopupFormFieldProps<M> & {\n entity?: Entity<M>\n}) {\n const { t } = useTranslation();\n\n const rebaseContext = useRebaseContext();\n const authController = useAuthController();\n const customizationController = useCustomizationController();\n\n const [savingError, setSavingError] = React.useState<any>();\n const [popupLocation, setPopupLocation] = useState<{\n x: number,\n y: number\n }>();\n\n const windowSize = useWindowSize();\n\n const draggableRef = React.useRef<HTMLDivElement>(null);\n const innerRef = React.useRef<HTMLDivElement>(null);\n\n const initialPositionSet = React.useRef<boolean>(false);\n\n const getInitialLocation = useCallback(() => {\n if (!cellRect) throw Error(\"getInitialLocation error\");\n\n return {\n x: cellRect.left < windowSize.width - cellRect.right\n ? cellRect.x + cellRect.width / 2\n : cellRect.x - cellRect.width / 2,\n y: cellRect.top < windowSize.height - cellRect.bottom\n ? cellRect.y + cellRect.height / 2\n : cellRect.y - cellRect.height / 2\n };\n }, [cellRect, windowSize.height, windowSize.width]);\n\n const normalizePosition = useCallback((\n pos: { x: number, y: number },\n draggableBoundingRect: DOMRect,\n currentWindowSize: { width: number, height: number }\n ) => {\n if (!draggableBoundingRect || draggableBoundingRect.width === 0 || draggableBoundingRect.height === 0) {\n return pos;\n }\n return {\n x: Math.max(0, Math.min(pos.x, currentWindowSize.width - draggableBoundingRect.width)),\n y: Math.max(0, Math.min(pos.y, currentWindowSize.height - draggableBoundingRect.height))\n };\n }, []);\n\n const updatePopupLocation = useCallback((newPositionCandidate?: {\n x: number,\n y: number\n }) => {\n const draggableBoundingRect = draggableRef.current?.getBoundingClientRect();\n if (!cellRect || !draggableBoundingRect || draggableBoundingRect.width === 0 || draggableBoundingRect.height === 0) {\n return;\n }\n const basePosition = newPositionCandidate ?? getInitialLocation();\n const newNormalizedPosition = normalizePosition(basePosition, draggableBoundingRect, windowSize);\n\n if (!popupLocation || newNormalizedPosition.x !== popupLocation.x || newNormalizedPosition.y !== popupLocation.y) {\n setPopupLocation(newNormalizedPosition);\n }\n }, [cellRect, getInitialLocation, normalizePosition, popupLocation, windowSize]);\n\n useDraggable({\n containerRef: draggableRef,\n innerRef,\n x: popupLocation?.x,\n y: popupLocation?.y,\n onMove: updatePopupLocation\n });\n\n useEffect(\n () => {\n initialPositionSet.current = false;\n },\n [propertyKey, entity]\n );\n\n useLayoutEffect(\n () => {\n if (!cellRect || initialPositionSet.current) return;\n // Ensure draggableRef is available and has dimensions before initial positioning\n const draggableBoundingRect = draggableRef.current?.getBoundingClientRect();\n if (!draggableBoundingRect || draggableBoundingRect.width === 0 || draggableBoundingRect.height === 0) {\n // If not ready, perhaps wait or log. For now, just return.\n // This might need a retry mechanism or ensure content is rendered first.\n return;\n }\n updatePopupLocation();\n initialPositionSet.current = true;\n },\n [cellRect, updatePopupLocation] // Removed initialPositionSet.current from deps as it's a ref\n );\n\n useLayoutEffect(\n () => {\n updatePopupLocation(popupLocation);\n },\n [windowSize, cellRect, updatePopupLocation, popupLocation]\n );\n\n // Built per validation, from the properties resolved against the values\n // the popup holds: a `conditions` rule or a `dynamicProps` validation\n // depends on them, as it does in the record form.\n const validationSchemaFor = (values: Partial<M>) => {\n if (!collection || !hasEntityId(entityId) || !propertyKey) return undefined;\n return getEntitySchema(\n entityId,\n cellValidationProperties<M>(collection.properties, propertyKey as string, values, entity?.values, entityId, {\n path,\n authController,\n propertyConfigs: customizationController.propertyConfigs\n }),\n customFieldValidator);\n };\n\n const adaptResize = useCallback(() => {\n // When the popup resizes, we want to re-evaluate its position\n // based on its current location and new dimensions.\n return updatePopupLocation(popupLocation);\n }, [popupLocation, updatePopupLocation]);\n\n // Setup ResizeObserver\n useEffect(() => {\n const element = draggableRef.current;\n if (!element) return;\n\n const observer = new ResizeObserver(() => {\n adaptResize();\n });\n\n observer.observe(element);\n\n return () => {\n observer.unobserve(element);\n observer.disconnect();\n };\n }, [adaptResize, draggableRef]);\n\n const saveValue = async (values: M) => {\n setSavingError(null);\n if (collection && entity && onCellValueChange && propertyKey) {\n // Written the way the form writes it: with the string transforms\n // the properties declare (`trim`, `lowercase`, `uppercase`) applied.\n const writtenValues = applyValueTransforms(values, collection.properties);\n return onCellValueChange({\n // By path: a spread map's child is `address.street`, which is\n // nested in the form values, not a key of them.\n value: getIn(writtenValues, propertyKey as string),\n propertyKey: propertyKey as string,\n data: entity,\n setError: setSavingError,\n onValueUpdated: () => {\n }\n });\n }\n return Promise.resolve();\n };\n\n const formex = useCreateFormex<M>({\n initialValues: (entity?.values ?? {}) as EntityValues<M>,\n validation: async (values) => {\n const validationSchema = validationSchemaFor(values);\n if (!validationSchema) return {};\n const result = await validationSchema.safeParseAsync(values);\n if (result.success) return {};\n return zodToFormErrors(result.error) as Record<string, string>;\n },\n validateOnInitialRender: true,\n onSubmit: (values, actions) => {\n saveValue(values)\n .then(() => {\n formex.resetForm({\n values: values\n })\n onClose();\n })\n .finally(() => actions.setSubmitting(false));\n }\n });\n\n const {\n values,\n isSubmitting,\n setFieldValue,\n handleSubmit\n } = formex;\n\n const disabled = isSubmitting;\n\n const formContext: FormContext<M> = {\n collection: collection,\n entityId,\n values,\n path,\n setFieldValue,\n save: saveValue,\n submit: handleSubmit,\n formex,\n status: \"existing\",\n openEntityMode: \"side_panel\",\n disabled: false\n };\n\n const property: Property | undefined = propertyKey && getPropertyInPath(collection?.properties ?? {} as Properties, propertyKey as string);\n const fieldProps: PropertyFieldBindingProps<M> | undefined = propertyKey && property\n ? {\n propertyKey: propertyKey as string,\n disabled: isSubmitting || isReadOnly(property) || isDisabled(property),\n property,\n includeDescription: false,\n underlyingValueHasChanged: false,\n context: formContext,\n partOfArray: false,\n minimalistView: true,\n autoFocus: open\n }\n : undefined;\n\n let internalForm = <>\n <div\n key={`popup_form_${tableKey}_${entityId}_${propertyKey}`}\n className=\"w-[700px] max-w-full max-h-[85vh]\">\n <form\n onSubmit={handleSubmit}\n noValidate>\n\n <div\n className=\"mb-1 p-4 flex flex-col relative\">\n <div\n ref={innerRef}\n className=\"cursor-auto\"\n style={{ cursor: \"auto !important\" }}>\n {fieldProps &&\n <PropertyFieldBinding {...fieldProps}/>}\n </div>\n </div>\n\n <DialogActions>\n <Button\n variant=\"filled\"\n color=\"primary\"\n type=\"submit\"\n disabled={disabled}\n >\n Save\n </Button>\n </DialogActions>\n\n </form>\n\n </div>\n\n </>;\n\n const plugins = customizationController.plugins;\n if (plugins && plugins.length > 0) {\n internalForm = (\n <PluginProviderStack\n plugins={plugins}\n scope=\"form\"\n scopeProps={{\n status: \"existing\",\n path,\n collection,\n entity,\n context: rebaseContext,\n currentEntityId: entityId,\n formContext\n }}>\n {internalForm}\n </PluginProviderStack>\n );\n }\n const form = <div\n className={`text-surface-900 dark:text-white overflow-auto rounded-xs rounded-md bg-surface-card ${!open ? \"hidden\" : \"\"} cursor-grab max-w-[100vw]`}>\n\n {internalForm}\n\n {savingError &&\n <Typography color={\"error\"}>\n {savingError.message}\n </Typography>\n }\n </div>;\n\n const draggable = (\n <div\n key={`draggable_${propertyKey as string}_${entityId}_${open}`}\n style={{\n boxShadow: \"0 0 0 2px rgba(128,128,128,0.2)\"\n }}\n className={`inline-block fixed z-20 shadow-outline rounded-md bg-surface-card ${!open ? \"invisible\" : \"visible\"\n } cursor-grab overflow-visible`}\n ref={draggableRef}>\n\n {/* ElementResizeListener removed from here */}\n\n <div\n className=\"overflow-hidden\">\n\n {form}\n\n <div\n className=\"absolute -top-3.5 -right-3.5 bg-surface-500 rounded-full\"\n style={{\n width: \"32px\",\n height: \"32px\"\n }}>\n <IconButton aria-label={t(\"close\")}\n size={\"small\"}\n onClick={(event) => {\n event.stopPropagation();\n onClose();\n }}>\n <XIcon className=\"text-white\"/>\n </IconButton>\n </div>\n </div>\n\n </div>\n );\n\n return (\n <Portal.Root asChild\n container={container}>\n <Formex value={formex as FormexController<Record<string, unknown>>}>\n {draggable}\n </Formex>\n </Portal.Root>\n );\n\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,SAAgB,eAAkD,OAA+B;CAC7F,IAAI,CAAC,MAAM,MAAM,OAAO;CACxB,OAAO,oBAAC,uBAAD,EAAuB,GAAI,MAAO,CAAA;AAE7C;AAEA,SAAgB,sBAAyD,EACrE,UACA,UACA,sBACA,aACA,YAAY,iBACZ,MACA,UACA,MACA,SACA,mBACA,aACuB;CACvB,MAAM,aAAa,QAAQ;CAC3B,MAAM,CAAC,QAAQ,aAAa,SAAgC,KAAA,CAAS;CACrE,gBAAgB;EACZ,IAAI,YAAY,QAAQ,KAAK,iBACzB,WAAW,WAAW,IAAI,CAAC,CAAC,SAAS,QAAQ,CAAC,CAA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ED,oBAAC,OAAD;IACI,WAAU;IACV,OAAO;KACH,OAAO;KACP,QAAQ;IACZ;cACA,oBAAC,YAAD;KAAY,cAAY,EAAE,OAAO;KAC7B,MAAM;KACN,UAAU,UAAU;MAChB,MAAM,gBAAgB;MACtB,QAAQ;KACZ;eACA,oBAAC,OAAD,EAAO,WAAU,aAAa,CAAA;IACtB,CAAA;GACX,CAAA,CACJ;;CAEJ,GAhCI,aAAa,YAAsB,GAAG,SAAS,GAAG,MAgCtD;CAGT,OACI,oBAAC,OAAO,MAAR;EAAa,SAAA;EACE;YACX,oBAAC,QAAD;GAAQ,OAAO;aACV;EACG,CAAA;CACC,CAAA;AAGrB"}
@@ -12,14 +12,12 @@ import { SlotValue, TagChips } from "./SlotValue.js";
12
12
  import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
13
13
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
14
  import { ArrowDownIcon, ArrowUpIcon, Checkbox, Chip, IconButton, ListView, Tooltip, Typography, cls, defaultBorderMixin, useUiLabels } from "@rebasepro/ui";
15
- import { IconForView, getIcon, hasDeclaredDisplay, useAnalyticsController, useAuthController, useCustomizationController, useTranslation } from "@rebasepro/app";
15
+ import { IconForView, getDisplayResolver, getIcon, hasDeclaredDisplay, useAnalyticsController, useAuthController, useCustomizationController, useTranslation } from "@rebasepro/app";
16
16
  import { getValueInPath } from "@rebasepro/utils";
17
17
  //#region src/components/CollectionViewBinding/CollectionListViewBinding.tsx
18
18
  /** A column left over from a sort or filter that is no longer applied. */
19
19
  var PRIORITY_STALE_REQUEST = 1e3;
20
- /** The collection's own columns. Slots sit just above it, in give-way order. */
21
- var PRIORITY_DECLARED = 2e3;
22
- var PRIORITY_DATE = PRIORITY_DECLARED;
20
+ var PRIORITY_DATE = 2e3;
23
21
  var PRIORITY_STATUS = 2001;
24
22
  var PRIORITY_TAGS = 2002;
25
23
  /** The sort or filter currently in force. */
@@ -222,6 +220,15 @@ function CollectionListViewBinding({ collection, tableController, onEntityClick,
222
220
  * title; otherwise it stays in {@link declaredColumns} and gets a cell.
223
221
  */
224
222
  const titleColumn = useMemo(() => {
223
+ if (getDisplayResolver(resolvedCollection, "title")) return {
224
+ key: "display:title",
225
+ label: resolvedCollection.singularName || resolvedCollection.name || "Name",
226
+ align: "left",
227
+ width: "flex-1 min-w-0",
228
+ widthPx: TITLE_COMFORTABLE_WIDTH,
229
+ sortable: false,
230
+ priority: Number.MAX_SAFE_INTEGER
231
+ };
225
232
  const key = titlePropertyKey ?? (columnMode ? resolvedCollection.listProperties?.[0] : void 0);
226
233
  if (!key) return void 0;
227
234
  const property = resolvedCollection.properties[key];
@@ -243,38 +250,47 @@ function CollectionListViewBinding({ collection, tableController, onEntityClick,
243
250
  ]);
244
251
  /**
245
252
  * The trailing columns the collection itself implies: the developer's
246
- * `listProperties` when there are any, otherwise the display slots the row
247
- * has always shown to the right of the title.
253
+ * `listProperties`, then the display slots the row has always shown to the
254
+ * right of the title.
255
+ *
256
+ * Both, not one or the other. `listProperties` names the extra columns a
257
+ * collection wants; it says nothing about dropping the status and date its
258
+ * `display` already declares, and reading it that way hid "Finished" and
259
+ * the start time of every game the moment the collection asked for a
260
+ * score column as well.
248
261
  */
249
262
  const declaredColumns = useMemo(() => {
263
+ const cols = [];
250
264
  if (columnMode) {
251
265
  const keys = resolvedCollection.listProperties.filter((key) => key !== titleColumn?.key);
252
- return keys.flatMap((key, index) => {
266
+ keys.forEach((key, index) => {
253
267
  const property = resolvedCollection.properties[key];
254
- if (!property) return [];
255
- return [{
268
+ if (!property) return;
269
+ cols.push({
256
270
  key,
257
271
  label: property.name || key,
258
272
  property,
259
273
  align: property.type === "number" || property.type === "date" ? "right" : "left",
260
274
  ...getIdealColumnWidth(property),
261
275
  sortable: sortableKeys.has(key),
262
- priority: PRIORITY_DECLARED + (keys.length - index)
263
- }];
276
+ priority: PRIORITY_TAGS + (keys.length - index)
277
+ });
264
278
  });
265
279
  }
266
- const cols = [];
267
280
  const slotColumn = (slot, key, fallbackLabel, layout, priority) => {
268
281
  const declared = hasDeclaredDisplay(resolvedCollection, slot);
269
- if (!key && !declared) return void 0;
270
- const property = key ? resolvedCollection.properties[key] : void 0;
282
+ if (columnMode && !declared) return void 0;
283
+ const slotKey = getDisplayResolver(resolvedCollection, slot) ? void 0 : key;
284
+ if (!slotKey && !declared) return void 0;
285
+ if (slotKey && cols.some((col) => col.key === slotKey)) return void 0;
286
+ const property = slotKey ? resolvedCollection.properties[slotKey] : void 0;
271
287
  return {
272
- key: key ?? `display:${slot}`,
288
+ key: slotKey ?? `display:${slot}`,
273
289
  label: property?.name || fallbackLabel,
274
290
  slot,
275
291
  property,
276
292
  ...layout,
277
- sortable: !!key && sortableKeys.has(key),
293
+ sortable: !!slotKey && sortableKeys.has(slotKey),
278
294
  priority
279
295
  };
280
296
  };