@cratis/components 0.1.12 → 0.1.14
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/cjs/CommandDialog/CommandDialog.js.map +1 -1
- package/dist/cjs/CommandForm/CommandForm.js +6 -2
- package/dist/cjs/CommandForm/CommandForm.js.map +1 -1
- package/dist/cjs/CommandForm/CommandFormFields.js.map +1 -1
- package/dist/cjs/DataTables/DataTableForObservableQuery.js.map +1 -1
- package/dist/cjs/DataTables/DataTableForQuery.js.map +1 -1
- package/dist/cjs/PivotViewer/PivotViewer.js +57 -378
- package/dist/cjs/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotCanvas.js +3 -3
- package/dist/cjs/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/cjs/PivotViewer/components/RangeHistogramFilter.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/buckets.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/sprites.js +1 -1
- package/dist/cjs/PivotViewer/components/pivot/sprites.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/cjs/PivotViewer/hooks/useAnimationModeTracking.js +37 -0
- package/dist/cjs/PivotViewer/hooks/useAnimationModeTracking.js.map +1 -0
- package/dist/cjs/PivotViewer/hooks/useCardSelection.js +64 -0
- package/dist/cjs/PivotViewer/hooks/useCardSelection.js.map +1 -0
- package/dist/cjs/PivotViewer/hooks/useCurrentFilters.js +52 -0
- package/dist/cjs/PivotViewer/hooks/useCurrentFilters.js.map +1 -0
- package/dist/cjs/PivotViewer/hooks/useDetailPanelClose.js +63 -0
- package/dist/cjs/PivotViewer/hooks/useDetailPanelClose.js.map +1 -0
- package/dist/cjs/PivotViewer/hooks/useFieldExtractors.js +50 -0
- package/dist/cjs/PivotViewer/hooks/useFieldExtractors.js.map +1 -0
- package/dist/cjs/PivotViewer/hooks/usePanning.js.map +1 -1
- package/dist/cjs/PivotViewer/hooks/usePivotEngine.js.map +1 -1
- package/dist/cjs/PivotViewer/hooks/useScrollSync.js +21 -0
- package/dist/cjs/PivotViewer/hooks/useScrollSync.js.map +1 -0
- package/dist/cjs/PivotViewer/hooks/useViewModeScrollHandling.js +42 -0
- package/dist/cjs/PivotViewer/hooks/useViewModeScrollHandling.js.map +1 -0
- package/dist/cjs/PivotViewer/types.js.map +1 -1
- package/dist/cjs/PivotViewer/utils/cardPosition.js +67 -0
- package/dist/cjs/PivotViewer/utils/cardPosition.js.map +1 -0
- package/dist/cjs/PivotViewer/utils/constants.js +4 -0
- package/dist/cjs/PivotViewer/utils/constants.js.map +1 -1
- package/dist/cjs/PivotViewer/utils/idResolution.js +34 -0
- package/dist/cjs/PivotViewer/utils/idResolution.js.map +1 -0
- package/dist/esm/CommandDialog/CommandDialog.d.ts +2 -2
- package/dist/esm/CommandDialog/CommandDialog.d.ts.map +1 -1
- package/dist/esm/CommandDialog/CommandDialog.js.map +1 -1
- package/dist/esm/CommandForm/CommandForm.d.ts +2 -2
- package/dist/esm/CommandForm/CommandForm.d.ts.map +1 -1
- package/dist/esm/CommandForm/CommandForm.js +6 -2
- package/dist/esm/CommandForm/CommandForm.js.map +1 -1
- package/dist/esm/CommandForm/CommandFormFields.d.ts +2 -2
- package/dist/esm/CommandForm/CommandFormFields.d.ts.map +1 -1
- package/dist/esm/CommandForm/CommandFormFields.js.map +1 -1
- package/dist/esm/Common/ErrorBoundary.stories.d.ts +1 -1
- package/dist/esm/Common/ErrorBoundary.stories.js.map +1 -1
- package/dist/esm/Common/FormElement.stories.d.ts +1 -1
- package/dist/esm/Common/FormElement.stories.js.map +1 -1
- package/dist/esm/Common/Page.stories.d.ts +1 -1
- package/dist/esm/Common/Page.stories.js.map +1 -1
- package/dist/esm/DataPage/DataPage.stories.d.ts +1 -1
- package/dist/esm/DataPage/DataPage.stories.js.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.d.ts +4 -4
- package/dist/esm/DataTables/DataTableForObservableQuery.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.js.map +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.stories.d.ts +1 -1
- package/dist/esm/DataTables/DataTableForObservableQuery.stories.js.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.d.ts +4 -4
- package/dist/esm/DataTables/DataTableForQuery.d.ts.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.js.map +1 -1
- package/dist/esm/DataTables/DataTableForQuery.stories.d.ts +1 -1
- package/dist/esm/DataTables/DataTableForQuery.stories.js.map +1 -1
- package/dist/esm/Dialogs/ConfirmationDialog.stories.js.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.d.ts.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.js +57 -378
- package/dist/esm/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.d.ts +2 -2
- package/dist/esm/PivotViewer/components/PivotCanvas.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.js +3 -3
- package/dist/esm/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/esm/PivotViewer/components/RangeHistogramFilter.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/buckets.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/sprites.js +1 -1
- package/dist/esm/PivotViewer/components/pivot/sprites.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/esm/PivotViewer/engine/pivot.worker.d.ts.map +1 -1
- package/dist/esm/PivotViewer/engine/pivot.worker.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/index.d.ts +7 -0
- package/dist/esm/PivotViewer/hooks/index.d.ts.map +1 -1
- package/dist/esm/PivotViewer/hooks/index.js +7 -0
- package/dist/esm/PivotViewer/hooks/index.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/useAnimationModeTracking.d.ts +2 -0
- package/dist/esm/PivotViewer/hooks/useAnimationModeTracking.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useAnimationModeTracking.js +35 -0
- package/dist/esm/PivotViewer/hooks/useAnimationModeTracking.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useCardSelection.d.ts +37 -0
- package/dist/esm/PivotViewer/hooks/useCardSelection.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useCardSelection.js +62 -0
- package/dist/esm/PivotViewer/hooks/useCardSelection.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useCurrentFilters.d.ts +5 -0
- package/dist/esm/PivotViewer/hooks/useCurrentFilters.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useCurrentFilters.js +49 -0
- package/dist/esm/PivotViewer/hooks/useCurrentFilters.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useDetailPanelClose.d.ts +27 -0
- package/dist/esm/PivotViewer/hooks/useDetailPanelClose.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useDetailPanelClose.js +61 -0
- package/dist/esm/PivotViewer/hooks/useDetailPanelClose.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useFieldExtractors.d.ts +7 -0
- package/dist/esm/PivotViewer/hooks/useFieldExtractors.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useFieldExtractors.js +48 -0
- package/dist/esm/PivotViewer/hooks/useFieldExtractors.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useFilterPanelDrag.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/usePanning.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/usePivotEngine.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/useScrollSync.d.ts +3 -0
- package/dist/esm/PivotViewer/hooks/useScrollSync.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useScrollSync.js +19 -0
- package/dist/esm/PivotViewer/hooks/useScrollSync.js.map +1 -0
- package/dist/esm/PivotViewer/hooks/useViewModeScrollHandling.d.ts +16 -0
- package/dist/esm/PivotViewer/hooks/useViewModeScrollHandling.d.ts.map +1 -0
- package/dist/esm/PivotViewer/hooks/useViewModeScrollHandling.js +40 -0
- package/dist/esm/PivotViewer/hooks/useViewModeScrollHandling.js.map +1 -0
- package/dist/esm/PivotViewer/types.js.map +1 -1
- package/dist/esm/PivotViewer/utils/cardPosition.d.ts +18 -0
- package/dist/esm/PivotViewer/utils/cardPosition.d.ts.map +1 -0
- package/dist/esm/PivotViewer/utils/cardPosition.js +63 -0
- package/dist/esm/PivotViewer/utils/cardPosition.js.map +1 -0
- package/dist/esm/PivotViewer/utils/constants.js +3 -1
- package/dist/esm/PivotViewer/utils/constants.js.map +1 -1
- package/dist/esm/PivotViewer/utils/idResolution.d.ts +13 -0
- package/dist/esm/PivotViewer/utils/idResolution.d.ts.map +1 -0
- package/dist/esm/PivotViewer/utils/idResolution.js +31 -0
- package/dist/esm/PivotViewer/utils/idResolution.js.map +1 -0
- package/dist/esm/PivotViewer/utils/index.d.ts +2 -0
- package/dist/esm/PivotViewer/utils/index.d.ts.map +1 -1
- package/dist/esm/PivotViewer/utils/index.js +2 -0
- package/dist/esm/PivotViewer/utils/index.js.map +1 -1
- package/dist/esm/TimeMachine/EventsView.stories.d.ts +1 -1
- package/dist/esm/TimeMachine/EventsView.stories.js.map +1 -1
- package/dist/esm/TimeMachine/Properties.stories.d.ts +1 -1
- package/dist/esm/TimeMachine/Properties.stories.js.map +1 -1
- package/dist/esm/TimeMachine/ReadModelView.stories.d.ts +1 -1
- package/dist/esm/TimeMachine/ReadModelView.stories.js.map +1 -1
- package/dist/esm/TimeMachine/TimeMachine.stories.d.ts +1 -1
- package/dist/esm/TimeMachine/TimeMachine.stories.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/vite.config.js.map +1 -1
- package/dist/esm/vitest.setup.d.ts +2 -0
- package/dist/esm/vitest.setup.d.ts.map +1 -0
- package/dist/esm/vitest.setup.js +8 -0
- package/dist/esm/vitest.setup.js.map +1 -0
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { Constructor } from '@cratis/fundamentals';\nimport { Dialog } from 'primereact/dialog';\nimport { Button } from 'primereact/button';\nimport React, { createContext, useContext } from 'react';\nimport { CommandForm, useCommandFormContext, BeforeExecuteCallback } from '../CommandForm/CommandForm';\nimport { useCommandInstance } from '../CommandForm/CommandForm';\n\nexport type FieldValidator<TCommand> = (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => string | undefined;\nexport type FieldChangeCallback<TCommand> = (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => void;\n\nexport interface CommandDialogProps<TCommand, TResponse = object> {\n command: Constructor<TCommand>;\n initialValues?: Partial<TCommand>;\n currentValues?: Partial<TCommand> | undefined;\n visible: boolean;\n header: string;\n confirmLabel?: string;\n cancelLabel?: string;\n confirmIcon?: string;\n cancelIcon?: string;\n onConfirm: (result: ICommandResult<TResponse>) => void | Promise<void>;\n onCancel: () => void;\n onFieldValidate?: FieldValidator<TCommand>;\n onFieldChange?: FieldChangeCallback<TCommand>;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n children?: React.ReactNode;\n style?: React.CSSProperties;\n width?: string;\n}\n\ninterface CommandDialogContextValue<TCommand = unknown> {\n onSuccess: (result: ICommandResult<
|
|
1
|
+
{"version":3,"file":"CommandDialog.js","sources":["../../../CommandDialog/CommandDialog.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { Constructor } from '@cratis/fundamentals';\nimport { Dialog } from 'primereact/dialog';\nimport { Button } from 'primereact/button';\nimport React, { createContext, useContext } from 'react';\nimport { CommandForm, useCommandFormContext, BeforeExecuteCallback } from '../CommandForm/CommandForm';\nimport { useCommandInstance } from '../CommandForm/CommandForm';\n\nexport type FieldValidator<TCommand> = (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => string | undefined;\nexport type FieldChangeCallback<TCommand> = (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => void;\n\nexport interface CommandDialogProps<TCommand, TResponse = object> {\n command: Constructor<TCommand>;\n initialValues?: Partial<TCommand>;\n currentValues?: Partial<TCommand> | undefined;\n visible: boolean;\n header: string;\n confirmLabel?: string;\n cancelLabel?: string;\n confirmIcon?: string;\n cancelIcon?: string;\n onConfirm: (result: ICommandResult<TResponse>) => void | Promise<void>;\n onCancel: () => void;\n onFieldValidate?: FieldValidator<TCommand>;\n onFieldChange?: FieldChangeCallback<TCommand>;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n children?: React.ReactNode;\n style?: React.CSSProperties;\n width?: string;\n}\n\ninterface CommandDialogContextValue<TCommand = unknown> {\n onSuccess: (result: ICommandResult<unknown>) => void | Promise<void>;\n onCancel: () => void;\n confirmLabel: string;\n cancelLabel: string;\n confirmIcon: string;\n cancelIcon: string;\n onFieldValidate?: FieldValidator<TCommand>;\n onFieldChange?: FieldChangeCallback<TCommand>;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n}\n\nconst CommandDialogContext = createContext<CommandDialogContextValue<unknown> | undefined>(undefined);\n\nexport const useCommandDialogContext = <TCommand = unknown,>() => {\n const context = useContext(CommandDialogContext);\n if (!context) {\n throw new Error('useCommandDialogContext must be used within a CommandDialog');\n }\n return context as CommandDialogContextValue<TCommand>;\n};\n\nconst CommandDialogFormContent = <TCommand extends { execute: () => Promise<ICommandResult<unknown>> }>() => {\n const command = useCommandInstance<TCommand>();\n const { setCommandResult, setCommandValues, isValid, onBeforeExecute } = useCommandFormContext<TCommand>();\n const { onSuccess: onConfirm, onCancel, confirmLabel, cancelLabel, confirmIcon, cancelIcon } = useCommandDialogContext<TCommand>();\n\n const handleConfirm = async () => {\n if (onBeforeExecute) {\n const transformedValues = onBeforeExecute(command);\n setCommandValues(transformedValues);\n }\n const result = await command.execute();\n if (result.isSuccess) {\n await onConfirm(result);\n } else {\n setCommandResult(result);\n }\n };\n\n const handleCancel = () => {\n onCancel();\n };\n\n return (\n <>\n <div className=\"card flex flex-wrap justify-content-center gap-3 mt-8\">\n <Button label={confirmLabel} icon={confirmIcon} onClick={handleConfirm} disabled={!isValid} />\n <Button label={cancelLabel} icon={cancelIcon} severity='secondary' onClick={handleCancel} />\n </div>\n </>\n );\n};\n\nconst CommandDialogFieldsWrapper = (props: { children: React.ReactNode }) => {\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n const component = child.type as React.ComponentType<unknown>;\n if (component.displayName !== 'CommandFormField') {\n throw new Error(`Only CommandFormField components are allowed as children of CommandDialog.Fields. Got: ${component.displayName || component.name || 'Unknown'}`);\n }\n }\n });\n\n return (\n <CommandForm.Fields>\n {props.children}\n </CommandForm.Fields>\n );\n};\n\nconst CommandDialogComponent = <TCommand extends object = object, TResponse = object>(props: CommandDialogProps<TCommand, TResponse>) => {\n const {\n command,\n initialValues,\n currentValues,\n visible,\n header,\n confirmLabel = 'Confirm',\n cancelLabel = 'Cancel',\n confirmIcon = 'pi pi-check',\n cancelIcon = 'pi pi-times',\n onConfirm,\n onCancel,\n onFieldValidate,\n onFieldChange,\n onBeforeExecute,\n children,\n style = { width: '50vw' },\n width\n } = props;\n\n const dialogStyle = width ? { ...style, width } : style;\n\n const contextValue: CommandDialogContextValue<TCommand> = {\n onSuccess: onConfirm,\n onCancel,\n confirmLabel,\n cancelLabel,\n confirmIcon,\n cancelIcon,\n onFieldValidate,\n onFieldChange,\n onBeforeExecute\n };\n\n return (\n <Dialog\n header={header}\n visible={visible}\n style={dialogStyle}\n onHide={onCancel}\n contentStyle={{ overflow: 'visible' }}\n >\n <CommandDialogContext.Provider value={contextValue}>\n <CommandForm command={command} initialValues={initialValues} currentValues={currentValues} onFieldValidate={onFieldValidate} onFieldChange={onFieldChange} onBeforeExecute={onBeforeExecute}>\n {children}\n <CommandDialogFormContent />\n </CommandForm>\n </CommandDialogContext.Provider>\n </Dialog>\n );\n};\n\nCommandDialogComponent.Fields = CommandDialogFieldsWrapper;\n\nexport const CommandDialog = CommandDialogComponent;\n"],"names":["createContext","useContext","useCommandInstance","useCommandFormContext","_jsx","_jsxs","Button","CommandForm","Dialog"],"mappings":";;;;;;;;AA8CA,MAAM,oBAAoB,GAAGA,mBAAa,CAAiD,SAAS,CAAC;AAE9F,MAAM,uBAAuB,GAAG,MAA0B;AAC7D,IAAA,MAAM,OAAO,GAAGC,gBAAU,CAAC,oBAAoB,CAAC;IAChD,IAAI,CAAC,OAAO,EAAE;AACV,QAAA,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC;IAClF;AACA,IAAA,OAAO,OAA8C;AACzD;AAEA,MAAM,wBAAwB,GAAG,MAA2E;AACxG,IAAA,MAAM,OAAO,GAAGC,8BAAkB,EAAY;AAC9C,IAAA,MAAM,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,OAAO,EAAE,eAAe,EAAE,GAAGC,iCAAqB,EAAY;AAC1G,IAAA,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,uBAAuB,EAAY;AAElI,IAAA,MAAM,aAAa,GAAG,YAAW;QAC7B,IAAI,eAAe,EAAE;AACjB,YAAA,MAAM,iBAAiB,GAAG,eAAe,CAAC,OAAO,CAAC;YAClD,gBAAgB,CAAC,iBAAiB,CAAC;QACvC;AACA,QAAA,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,EAAE;AACtC,QAAA,IAAI,MAAM,CAAC,SAAS,EAAE;AAClB,YAAA,MAAM,S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OrColumns: hasColumns ? columns : fields, otherChildren, initialValuesFromFields };
|
|
100
100
|
};
|
|
101
101
|
function getPropertyNameFromAccessor(accessor) {
|
|
102
|
+
if (typeof accessor !== 'function')
|
|
103
|
+
return '';
|
|
102
104
|
const fnStr = accessor.toString();
|
|
103
105
|
const match = fnStr.match(/\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
104
106
|
return match ? match[1] : '';
|
|
@@ -109,7 +111,7 @@ const CommandFormComponent = (props) => {
|
|
|
109
111
|
if (!props.currentValues)
|
|
110
112
|
return {};
|
|
111
113
|
const tempCommand = new props.command();
|
|
112
|
-
const commandProperties = tempCommand.properties || [];
|
|
114
|
+
const commandProperties = (tempCommand.properties || []);
|
|
113
115
|
const extracted = {};
|
|
114
116
|
commandProperties.forEach((propertyName) => {
|
|
115
117
|
if (props.currentValues[propertyName] !== undefined) {
|
|
@@ -123,7 +125,9 @@ const CommandFormComponent = (props) => {
|
|
|
123
125
|
...initialValuesFromFields,
|
|
124
126
|
...props.initialValues
|
|
125
127
|
}), [valuesFromCurrentValues, initialValuesFromFields, props.initialValues]);
|
|
126
|
-
const
|
|
128
|
+
const useCommandResult = commands.useCommand(props.command, mergedInitialValues);
|
|
129
|
+
const commandInstance = useCommandResult[0];
|
|
130
|
+
const setCommandValues = useCommandResult[1];
|
|
127
131
|
const [commandResult, setCommandResult] = React.useState(undefined);
|
|
128
132
|
const [fieldValidities, setFieldValidities] = React.useState({});
|
|
129
133
|
const [customFieldErrors, setCustomFieldErrors] = React.useState({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandForm.js","sources":["../../../CommandForm/CommandForm.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { CommandFormFields, ColumnInfo } from './CommandFormFields';\nimport { Constructor } from '@cratis/fundamentals';\nimport { useCommand, SetCommandValues } from '@cratis/arc.react/commands';\nimport { ICommandResult } from '@cratis/arc/commands';\nimport React, { createContext, useContext, useMemo, useState, useCallback } from 'react';\nimport type { CommandFormFieldProps } from './CommandFormField';\nimport { Panel } from 'primereact/panel';\n\nexport type BeforeExecuteCallback<TCommand> = (values: TCommand) => TCommand;\n\nexport interface CommandFormProps<TCommand extends object> {\n command: Constructor<TCommand>;\n initialValues?: Partial<TCommand>;\n currentValues?: Partial<TCommand> | undefined;\n onFieldValidate?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => string | undefined;\n onFieldChange?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => void;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n children?: React.ReactNode;\n}\n\ninterface CommandFormContextValue<TCommand> {\n command: Constructor<TCommand>;\n commandInstance: TCommand;\n setCommandValues: SetCommandValues<TCommand>;\n commandResult?: ICommandResult<unknown>;\n setCommandResult: (result: ICommandResult<unknown>) => void;\n getFieldError: (propertyName: string) => string | undefined;\n isValid: boolean;\n setFieldValidity: (fieldName: string, isValid: boolean) => void;\n onFieldValidate?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => string | undefined;\n onFieldChange?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => void;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n customFieldErrors: Record<string, string>;\n setCustomFieldError: (fieldName: string, error: string | undefined) => void;\n}\n\nconst CommandFormContext = createContext<CommandFormContextValue<any> | undefined>(undefined);\n\nexport const useCommandFormContext = <TCommand,>() => {\n const context = useContext(CommandFormContext);\n if (!context) {\n throw new Error('useCommandFormContext must be used within a CommandForm');\n }\n return context as CommandFormContextValue<TCommand>;\n};\n\n// Hook to get just the command instance for easier access\nexport const useCommandInstance = <TCommand = any>() => {\n const { commandInstance } = useCommandFormContext<any>();\n return commandInstance as TCommand;\n};\n\n// Hook to get setCommandResult for easier access\nexport const useSetCommandResult = () => {\n const { setCommandResult } = useCommandFormContext();\n return setCommandResult;\n};\n\nconst CommandFormFieldsWrapper = (props: { children: React.ReactNode }) => {\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n const component = child.type as any;\n if (component.displayName !== 'CommandFormField') {\n throw new Error(`Only CommandFormField components are allowed as children of CommandForm.Fields. Got: ${component.displayName || component.name || 'Unknown'}`);\n }\n }\n });\n\n return <></>;\n};\n\nCommandFormFieldsWrapper.displayName = 'CommandFormFieldsWrapper';\n\nconst getCommandFormFields = <TCommand,>(props: { children?: React.ReactNode }): { fieldsOrColumns: React.ReactElement[] | ColumnInfo[], otherChildren: React.ReactNode[], initialValuesFromFields: Partial<TCommand> } => {\n if (!props.children) {\n return { fieldsOrColumns: [], otherChildren: [], initialValuesFromFields: {} };\n }\n let fields: React.ReactElement<CommandFormFieldProps<any>>[] = [];\n const columns: ColumnInfo[] = [];\n let hasColumns = false;\n const otherChildren: React.ReactNode[] = [];\n let initialValuesFromFields: Partial<TCommand> = {};\n\n const extractInitialValue = (field: React.ReactElement) => {\n const fieldProps = field.props as any;\n if (fieldProps.currentValue !== undefined && fieldProps.value) {\n const propertyAccessor = fieldProps.value;\n const propertyName = getPropertyNameFromAccessor(propertyAccessor);\n if (propertyName) {\n initialValuesFromFields = { ...initialValuesFromFields, [propertyName]: fieldProps.currentValue } as Partial<TCommand>;\n }\n }\n };\n\n React.Children.toArray(props.children).forEach(child => {\n if (!React.isValidElement(child)) {\n otherChildren.push(child);\n return;\n }\n\n const component = child.type as any;\n\n // Check if child is a CommandFormColumn\n if (component.displayName === 'CommandFormColumn') {\n hasColumns = true;\n const childProps = child.props as { children?: React.ReactNode };\n const columnFields = React.Children.toArray(childProps.children).filter(child => {\n if (React.isValidElement(child)) {\n const comp = child.type as any;\n if (comp.displayName === 'CommandFormField') {\n extractInitialValue(child as React.ReactElement);\n return true;\n }\n }\n return false;\n }) as React.ReactElement[];\n columns.push({ fields: columnFields as React.ReactElement<CommandFormFieldProps<any>>[] });\n }\n // Check if child is a CommandFormField (direct child)\n else if (component.displayName === 'CommandFormField') {\n extractInitialValue(child as React.ReactElement);\n fields.push(child as React.ReactElement<CommandFormFieldProps<any>>);\n }\n // Check if child is Fields wrapper (backwards compatibility)\n else if (component === CommandFormFieldsWrapper || component.displayName === 'CommandFormFieldsWrapper') {\n const childProps = child.props as { children: React.ReactNode };\n const relevantChildren = React.Children.toArray(childProps.children).filter(child => {\n if (React.isValidElement(child)) {\n const component = child.type as any;\n if (component.displayName === 'CommandFormField') {\n extractInitialValue(child as React.ReactElement);\n return true;\n }\n }\n return false;\n }) as React.ReactElement[];\n fields = [...fields, ...(relevantChildren as React.ReactElement<CommandFormFieldProps<any>>[])];\n }\n // Everything else is not a field, keep it as other children\n else {\n otherChildren.push(child);\n }\n });\n\n return { fieldsOrColumns: hasColumns ? columns : fields, otherChildren, initialValuesFromFields };\n};\n\n// Helper function to extract property name from accessor function\nfunction getPropertyNameFromAccessor<T>(accessor: (obj: T) => unknown): string {\n const fnStr = accessor.toString();\n const match = fnStr.match(/\\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);\n return match ? match[1] : '';\n}\n\nconst CommandFormComponent = <TCommand extends object = any>(props: CommandFormProps<TCommand>) => {\n const { fieldsOrColumns, otherChildren, initialValuesFromFields } = useMemo(() => getCommandFormFields<TCommand>(props), [props.children]);\n\n // Extract matching properties from currentValues\n const valuesFromCurrentValues = useMemo(() => {\n if (!props.currentValues) return {};\n\n const tempCommand = new props.command();\n const commandProperties = (tempCommand as any).properties || [];\n const extracted: Partial<TCommand> = {};\n\n commandProperties.forEach((propertyName: string) => {\n if ((props.currentValues as any)[propertyName] !== undefined) {\n (extracted as any)[propertyName] = (props.currentValues as any)[propertyName];\n }\n });\n\n return extracted;\n }, [props.currentValues, props.command]);\n\n // Merge initialValues prop with values extracted from field currentValue props and currentValues\n const mergedInitialValues = useMemo(() => ({\n ...valuesFromCurrentValues,\n ...initialValuesFromFields,\n ...props.initialValues\n }), [valuesFromCurrentValues, initialValuesFromFields, props.initialValues]);\n\n // useCommand returns [instance, setter] for the typed command. Provide generics so commandInstance is TCommand.\n const [commandInstance, setCommandValues] = useCommand<any>(props.command as Constructor<any>, mergedInitialValues as Partial<any>);\n const [commandResult, setCommandResult] = useState<ICommandResult<unknown> | undefined>(undefined);\n const [fieldValidities, setFieldValidities] = useState<Record<string, boolean>>({});\n const [customFieldErrors, setCustomFieldErrors] = useState<Record<string, string>>({});\n\n // Update command values when mergedInitialValues changes (e.g., when data loads asynchronously)\n React.useEffect(() => {\n if (mergedInitialValues && Object.keys(mergedInitialValues).length > 0) {\n setCommandValues(mergedInitialValues as TCommand);\n }\n }, [mergedInitialValues, setCommandValues]);\n\n const isValid = Object.values(fieldValidities).every(valid => valid);\n\n const setFieldValidity = useCallback((fieldName: string, isFieldValid: boolean) => {\n setFieldValidities(prev => ({ ...prev, [fieldName]: isFieldValid }));\n }, []);\n\n const setCustomFieldError = useCallback((fieldName: string, error: string | undefined) => {\n setCustomFieldErrors(prev => {\n if (error === undefined) {\n const newErrors = { ...prev };\n delete newErrors[fieldName];\n return newErrors;\n }\n return { ...prev, [fieldName]: error };\n });\n }, []);\n\n const getFieldError = (propertyName: string): string | undefined => {\n // Check custom field errors first\n if (customFieldErrors[propertyName]) {\n return customFieldErrors[propertyName];\n }\n\n if (!commandResult || !commandResult.validationResults) {\n return undefined;\n }\n\n for (const validationResult of commandResult.validationResults) {\n if (validationResult.members && validationResult.members.includes(propertyName)) {\n return validationResult.message;\n }\n }\n\n return undefined;\n };\n\n const exceptionMessages = commandResult?.exceptionMessages || [];\n const hasColumns = fieldsOrColumns.length > 0 && 'fields' in fieldsOrColumns[0];\n\n return (\n <CommandFormContext.Provider value={{ command: props.command, commandInstance, setCommandValues, commandResult, setCommandResult, getFieldError, isValid, setFieldValidity, onFieldValidate: props.onFieldValidate, onFieldChange: props.onFieldChange, onBeforeExecute: props.onBeforeExecute, customFieldErrors, setCustomFieldError }}>\n <CommandFormFields fields={hasColumns ? undefined : (fieldsOrColumns as React.ReactElement<CommandFormFieldProps<any>>[])} columns={hasColumns ? fieldsOrColumns as ColumnInfo[] : undefined} />\n {exceptionMessages.length > 0 && (\n <div className=\"card flex flex-row gap-3 mt-3\">\n <Panel header=\"The server responded with\" className=\"w-full\">\n <ul>\n {exceptionMessages.map((msg, idx) => (\n <li key={idx}>{msg}</li>\n ))}\n </ul>\n </Panel>\n </div>\n )}\n {otherChildren}\n </CommandFormContext.Provider>\n );\n};\n\nconst CommandFormColumnComponent = (_props: { children: React.ReactNode }) => {\n void _props;\n return <></>;\n};\n\nCommandFormColumnComponent.displayName = 'CommandFormColumn';\n\nCommandFormComponent.Fields = CommandFormFieldsWrapper;\nCommandFormComponent.Column = CommandFormColumnComponent;\n\nexport const CommandForm = CommandFormComponent;\n"],"names":["createContext","useContext","_jsx","useMemo","useCommand","useState","useCallback","_jsxs","CommandFormFields","Panel"],"mappings":";;;;;;;;AAuCA,MAAM,kBAAkB,GAAGA,mBAAa,CAA2C,SAAS,CAAC;AAEtF,MAAM,qBAAqB,GAAG,MAAgB;AACjD,IAAA,MAAM,OAAO,GAAGC,gBAAU,CAAC,kBAAkB,CAAC;IAC9C,IAAI,CAAC,OAAO,EAAE;AACV,QAAA,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;IAC9E;AACA,IAAA,OAAO,OAA4C;AACvD;AAGO,MAAM,kBAAkB,GAAG,MAAqB;AACnD,IAAA,MAAM,EAAE,eAAe,EAAE,GAAG,qBAAqB,EAAO;AACxD,IAAA,OAAO,eAA2B;AACtC;AAGO,MAAM,mBAAmB,GAAG,MAAK;AACpC,IAAA,MAAM,EAAE,gBAAgB,EAAE,GAAG,qBAAqB,EAAE;AACpD,IAAA,OAAO,gBAAgB;AAC3B;AAEA,MAAM,wBAAwB,GAAG,CAAC,KAAoC,KAAI;IACtE,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,IAAG;AAC3C,QAAA,IAAI,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE;AAC7B,YAAA,MAAM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,CAAC,MAAM,GAAG,0BAA0B;AAEjD,MAAM,WAAW,GAAG;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"CommandForm.js","sources":["../../../CommandForm/CommandForm.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { CommandFormFields, ColumnInfo } from './CommandFormFields';\nimport { Constructor } from '@cratis/fundamentals';\nimport { useCommand, SetCommandValues } from '@cratis/arc.react/commands';\nimport { ICommandResult } from '@cratis/arc/commands';\nimport { Command } from '@cratis/arc/commands';\nimport React, { createContext, useContext, useMemo, useState, useCallback } from 'react';\nimport type { CommandFormFieldProps } from './CommandFormField';\nimport { Panel } from 'primereact/panel';\n\nexport type BeforeExecuteCallback<TCommand> = (values: TCommand) => TCommand;\n\nexport interface CommandFormProps<TCommand extends object> {\n command: Constructor<TCommand>;\n initialValues?: Partial<TCommand>;\n currentValues?: Partial<TCommand> | undefined;\n onFieldValidate?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => string | undefined;\n onFieldChange?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => void;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n children?: React.ReactNode;\n}\n\ninterface CommandFormContextValue<TCommand> {\n command: Constructor<TCommand>;\n commandInstance: TCommand;\n setCommandValues: SetCommandValues<TCommand>;\n commandResult?: ICommandResult<unknown>;\n setCommandResult: (result: ICommandResult<unknown>) => void;\n getFieldError: (propertyName: string) => string | undefined;\n isValid: boolean;\n setFieldValidity: (fieldName: string, isValid: boolean) => void;\n onFieldValidate?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => string | undefined;\n onFieldChange?: (command: TCommand, fieldName: string, oldValue: unknown, newValue: unknown) => void;\n onBeforeExecute?: BeforeExecuteCallback<TCommand>;\n customFieldErrors: Record<string, string>;\n setCustomFieldError: (fieldName: string, error: string | undefined) => void;\n}\n\nconst CommandFormContext = createContext<CommandFormContextValue<unknown> | undefined>(undefined);\n\nexport const useCommandFormContext = <TCommand,>() => {\n const context = useContext(CommandFormContext);\n if (!context) {\n throw new Error('useCommandFormContext must be used within a CommandForm');\n }\n return context as CommandFormContextValue<TCommand>;\n};\n\n// Hook to get just the command instance for easier access\nexport const useCommandInstance = <TCommand = unknown>() => {\n const { commandInstance } = useCommandFormContext<TCommand>();\n return commandInstance as TCommand;\n};\n\n// Hook to get setCommandResult for easier access\nexport const useSetCommandResult = () => {\n const { setCommandResult } = useCommandFormContext();\n return setCommandResult;\n};\n\nconst CommandFormFieldsWrapper = (props: { children: React.ReactNode }) => {\n React.Children.forEach(props.children, child => {\n if (React.isValidElement(child)) {\n const component = child.type as React.ComponentType<unknown>;\n if (component.displayName !== 'CommandFormField') {\n throw new Error(`Only CommandFormField components are allowed as children of CommandForm.Fields. Got: ${component.displayName || component.name || 'Unknown'}`);\n }\n }\n });\n\n return <></>;\n};\n\nCommandFormFieldsWrapper.displayName = 'CommandFormFieldsWrapper';\n\nconst getCommandFormFields = <TCommand,>(props: { children?: React.ReactNode }): { fieldsOrColumns: React.ReactElement[] | ColumnInfo[], otherChildren: React.ReactNode[], initialValuesFromFields: Partial<TCommand> } => {\n if (!props.children) {\n return { fieldsOrColumns: [], otherChildren: [], initialValuesFromFields: {} };\n }\n let fields: React.ReactElement<CommandFormFieldProps<unknown>>[] = [];\n const columns: ColumnInfo[] = [];\n let hasColumns = false;\n const otherChildren: React.ReactNode[] = [];\n let initialValuesFromFields: Partial<TCommand> = {};\n\n const extractInitialValue = (field: React.ReactElement) => {\n const fieldProps = field.props as Record<string, unknown>;\n if (fieldProps.currentValue !== undefined && fieldProps.value) {\n const propertyAccessor = fieldProps.value;\n const propertyName = getPropertyNameFromAccessor(propertyAccessor);\n if (propertyName) {\n initialValuesFromFields = { ...initialValuesFromFields, [propertyName]: fieldProps.currentValue } as Partial<TCommand>;\n }\n }\n };\n\n React.Children.toArray(props.children).forEach(child => {\n if (!React.isValidElement(child)) {\n otherChildren.push(child);\n return;\n }\n\n const component = child.type as React.ComponentType<unknown>;\n\n // Check if child is a CommandFormColumn\n if (component.displayName === 'CommandFormColumn') {\n hasColumns = true;\n const childProps = child.props as { children?: React.ReactNode };\n const columnFields = React.Children.toArray(childProps.children).filter(child => {\n if (React.isValidElement(child)) {\n const comp = child.type as React.ComponentType<unknown>;\n if (comp.displayName === 'CommandFormField') {\n extractInitialValue(child as React.ReactElement);\n return true;\n }\n }\n return false;\n }) as React.ReactElement[];\n columns.push({ fields: columnFields as React.ReactElement<CommandFormFieldProps<unknown>>[] });\n }\n // Check if child is a CommandFormField (direct child)\n else if (component.displayName === 'CommandFormField') {\n extractInitialValue(child as React.ReactElement);\n fields.push(child as React.ReactElement<CommandFormFieldProps<unknown>>);\n }\n // Check if child is Fields wrapper (backwards compatibility)\n else if (component === CommandFormFieldsWrapper || component.displayName === 'CommandFormFieldsWrapper') {\n const childProps = child.props as { children: React.ReactNode };\n const relevantChildren = React.Children.toArray(childProps.children).filter(child => {\n if (React.isValidElement(child)) {\n const component = child.type as React.ComponentType<unknown>;\n if (component.displayName === 'CommandFormField') {\n extractInitialValue(child as React.ReactElement);\n return true;\n }\n }\n return false;\n }) as React.ReactElement[];\n fields = [...fields, ...(relevantChildren as React.ReactElement<CommandFormFieldProps<unknown>>[])];\n }\n // Everything else is not a field, keep it as other children\n else {\n otherChildren.push(child);\n }\n });\n\n return { fieldsOrColumns: hasColumns ? columns : fields, otherChildren, initialValuesFromFields };\n};\n\n// Helper function to extract property name from accessor function\nfunction getPropertyNameFromAccessor<T = unknown>(accessor: ((obj: T) => unknown) | unknown): string {\n if (typeof accessor !== 'function') return '';\n const fnStr = accessor.toString();\n const match = fnStr.match(/\\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);\n return match ? match[1] : '';\n}\n\nconst CommandFormComponent = <TCommand extends object = object>(props: CommandFormProps<TCommand>) => {\n const { fieldsOrColumns, otherChildren, initialValuesFromFields } = useMemo(() => getCommandFormFields<TCommand>(props), [props.children]);\n\n // Extract matching properties from currentValues\n const valuesFromCurrentValues = useMemo(() => {\n if (!props.currentValues) return {};\n\n const tempCommand = new props.command();\n const commandProperties = ((tempCommand as Record<string, unknown>).properties || []) as string[];\n const extracted: Partial<TCommand> = {};\n\n commandProperties.forEach((propertyName: string) => {\n if ((props.currentValues as Record<string, unknown>)[propertyName] !== undefined) {\n (extracted as Record<string, unknown>)[propertyName] = (props.currentValues as Record<string, unknown>)[propertyName];\n }\n });\n\n return extracted;\n }, [props.currentValues, props.command]);\n\n // Merge initialValues prop with values extracted from field currentValue props and currentValues\n const mergedInitialValues = useMemo(() => ({\n ...valuesFromCurrentValues,\n ...initialValuesFromFields,\n ...props.initialValues\n }), [valuesFromCurrentValues, initialValuesFromFields, props.initialValues]);\n\n // useCommand returns [instance, setter] for the typed command. Provide generics so commandInstance is TCommand.\n // Using type assertion through unknown to work around generic constraint mismatch\n const useCommandResult = useCommand(props.command as unknown as Constructor<Command<Partial<TCommand>, object>>, mergedInitialValues);\n const commandInstance = useCommandResult[0] as unknown as TCommand;\n const setCommandValues = useCommandResult[1] as SetCommandValues<TCommand>;\n const [commandResult, setCommandResult] = useState<ICommandResult<unknown> | undefined>(undefined);\n const [fieldValidities, setFieldValidities] = useState<Record<string, boolean>>({});\n const [customFieldErrors, setCustomFieldErrors] = useState<Record<string, string>>({});\n\n // Update command values when mergedInitialValues changes (e.g., when data loads asynchronously)\n React.useEffect(() => {\n if (mergedInitialValues && Object.keys(mergedInitialValues).length > 0) {\n setCommandValues(mergedInitialValues as TCommand);\n }\n }, [mergedInitialValues, setCommandValues]);\n\n const isValid = Object.values(fieldValidities).every(valid => valid);\n\n const setFieldValidity = useCallback((fieldName: string, isFieldValid: boolean) => {\n setFieldValidities(prev => ({ ...prev, [fieldName]: isFieldValid }));\n }, []);\n\n const setCustomFieldError = useCallback((fieldName: string, error: string | undefined) => {\n setCustomFieldErrors(prev => {\n if (error === undefined) {\n const newErrors = { ...prev };\n delete newErrors[fieldName];\n return newErrors;\n }\n return { ...prev, [fieldName]: error };\n });\n }, []);\n\n const getFieldError = (propertyName: string): string | undefined => {\n // Check custom field errors first\n if (customFieldErrors[propertyName]) {\n return customFieldErrors[propertyName];\n }\n\n if (!commandResult || !commandResult.validationResults) {\n return undefined;\n }\n\n for (const validationResult of commandResult.validationResults) {\n if (validationResult.members && validationResult.members.includes(propertyName)) {\n return validationResult.message;\n }\n }\n\n return undefined;\n };\n\n const exceptionMessages = commandResult?.exceptionMessages || [];\n const hasColumns = fieldsOrColumns.length > 0 && 'fields' in fieldsOrColumns[0];\n\n return (\n <CommandFormContext.Provider value={{ command: props.command, commandInstance, setCommandValues, commandResult, setCommandResult, getFieldError, isValid, setFieldValidity, onFieldValidate: props.onFieldValidate, onFieldChange: props.onFieldChange, onBeforeExecute: props.onBeforeExecute, customFieldErrors, setCustomFieldError }}>\n <CommandFormFields fields={hasColumns ? undefined : (fieldsOrColumns as React.ReactElement<CommandFormFieldProps<unknown>>[])} columns={hasColumns ? fieldsOrColumns as ColumnInfo[] : undefined} />\n {exceptionMessages.length > 0 && (\n <div className=\"card flex flex-row gap-3 mt-3\">\n <Panel header=\"The server responded with\" className=\"w-full\">\n <ul>\n {exceptionMessages.map((msg, idx) => (\n <li key={idx}>{msg}</li>\n ))}\n </ul>\n </Panel>\n </div>\n )}\n {otherChildren}\n </CommandFormContext.Provider>\n );\n};\n\nconst CommandFormColumnComponent = (_props: { children: React.ReactNode }) => {\n void _props;\n return <></>;\n};\n\nCommandFormColumnComponent.displayName = 'CommandFormColumn';\n\nCommandFormComponent.Fields = CommandFormFieldsWrapper;\nCommandFormComponent.Column = CommandFormColumnComponent;\n\nexport const CommandForm = CommandFormComponent;\n"],"names":["createContext","useContext","_jsx","useMemo","useCommand","useState","useCallback","_jsxs","CommandFormFields","Panel"],"mappings":";;;;;;;;AAwCA,MAAM,kBAAkB,GAAGA,mBAAa,CAA+C,SAAS,CAAC;AAE1F,MAAM,qBAAqB,GAAG,MAAgB;AACjD,IAA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AAiB,EAAA,EAAC,MAAM,EAAE,UAAU,GAAG,SAAS,GAAI,eAAwE,EAAE,OAAO,EAAE,UAAU,GAAG,eAA+B,GAAG,SAAS,EAAA,CAAI,EACnM,iBAAiB,CAAC,MAAM,GAAG,CAAC,KACzBN,cAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAC,+BAA+B,EAAA,QAAA,EAC1CA,cAAA,CAACO,WAAK,EAAA,EAAC,MAAM,EAAC,2BAA2B,EAAC,SAAS,EAAC,QAAQ,EAAA,QAAA,EACxDP,cAAA,CAAA,IAAA,EAAA,EAAA,QAAA,EACK,iBAAiB,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,MAC5BA,cAAA,CAAA,IAAA,EAAA,EAAA,QAAA,EAAe,GAAG,EAAA,EAAT,GAAG,CAAY,CAC3B,CAAC,EAAA,CACD,EAAA,CACD,EAAA,CACN,CACT,EACA,aAAa,CAAA,EAAA,CACY;AAEtC,CAAC;AAED,MAAM,0BAA0B,GAAG,CAAC,MAAqC,KAAI;AAEzE,IAAA,OAAOA,uCAAK;AAChB,CAAC;AAED,0BAA0B,CAAC,WAAW,GAAG,mBAAmB;AAE5D,oBAAoB,CAAC,MAAM,GAAG,wBAAwB;AACtD,oBAAoB,CAAC,MAAM,GAAG,0BAA0B;AAEjD,MAAM,WAAW,GAAG;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CommandFormFields.js","sources":["../../../CommandForm/CommandFormFields.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useCommandFormContext } from './CommandForm';\nimport React from 'react';\nimport { Tooltip } from 'primereact/tooltip';\nimport type { CommandFormFieldProps } from './CommandFormField';\n\nexport interface ColumnInfo {\n fields: React.ReactElement<CommandFormFieldProps<any>>[];\n}\n\nexport interface CommandFormFieldsProps {\n fields?: React.ReactElement<CommandFormFieldProps<any>>[];\n columns?: ColumnInfo[];\n}\n\n// Separate component for each field to prevent re-rendering all fields\nconst CommandFormFieldWrapper = ({ field, index }: { field: React.ReactElement<CommandFormFieldProps<any>>; index: number }) => {\n const context = useCommandFormContext<any>();\n const fieldProps = field.props as CommandFormFieldProps<any>;\n const propertyAccessor = fieldProps.value;\n\n // Get the property name from the accessor function\n const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : '';\n\n // Get the current value from the command instance\n const currentValue = propertyName ? (context.commandInstance as any)?.[propertyName] : undefined;\n\n // Get the error message for this field, if any\n const errorMessage = propertyName ? context.getFieldError(propertyName) : undefined;\n\n // Get the property descriptor for this field from the command instance\n const propertyDescriptor = propertyName && (context.commandInstance as any)?.propertyDescriptors\n ? (context.commandInstance as any).propertyDescriptors.find((pd: any) => pd.name === propertyName)\n : undefined;\n\n // Clone the field element with the current value and onChange handler\n const clonedField = React.cloneElement(field as React.ReactElement, {\n ...fieldProps,\n currentValue,\n propertyDescriptor,\n fieldName: propertyName,\n onValueChange: (value: unknown) => {\n if (propertyName) {\n const oldValue = currentValue;\n\n // Update the command value\n context.setCommandValues({ [propertyName]: value } as any);\n\n // Call validate() on the command instance and store the result\n if (context.commandInstance && typeof (context.commandInstance as any).validate === 'function') {\n const validationResult = (context.commandInstance as any).validate();\n if (validationResult) {\n context.setCommandResult(validationResult);\n }\n }\n\n // Call custom field validator if provided\n if (context.onFieldValidate) {\n const validationError = context.onFieldValidate(context.commandInstance as any, propertyName, oldValue, value);\n context.setCustomFieldError(propertyName, validationError);\n }\n\n // Call field change callback if provided\n if (context.onFieldChange) {\n context.onFieldChange(context.commandInstance as any, propertyName, oldValue, value);\n }\n }\n fieldProps.onChange?.(value as any);\n },\n required: fieldProps.required ?? true,\n invalid: !!errorMessage\n } as any);\n\n const tooltipId = fieldProps.description ? `tooltip-${propertyName}-${index}` : undefined;\n\n return (\n <div className=\"w-full\">\n <div className=\"p-inputgroup w-full\">\n {fieldProps.description && (\n <Tooltip target={`.${tooltipId}`} content={fieldProps.description} />\n )}\n {fieldProps.icon && (\n <span className={`p-inputgroup-addon ${tooltipId || ''}`}>\n {fieldProps.icon}\n </span>\n )}\n {clonedField}\n </div>\n {errorMessage && (\n <small className=\"p-error block mt-1\">{errorMessage}</small>\n )}\n </div>\n );\n};\n\nexport const CommandFormFields = (props: CommandFormFieldsProps) => {\n const { fields, columns } = props;\n\n // Render columns if provided\n if (columns && columns.length > 0) {\n return (\n <div className=\"card flex flex-column md:flex-row gap-3\">\n {columns.map((column, columnIndex) => (\n <div key={`column-${columnIndex}`} className=\"flex flex-column gap-3 flex-1\">\n {column.fields.map((field, index) => {\n const fieldProps = field.props as CommandFormFieldProps<any>;\n const propertyAccessor = fieldProps.value;\n const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : `field-${columnIndex}-${index}`;\n\n return (\n <CommandFormFieldWrapper\n key={propertyName}\n field={field}\n index={index}\n />\n );\n })}\n </div>\n ))}\n </div>\n );\n }\n\n // Render fields (single column layout)\n return (\n <div className=\"flex flex-col gap-4 w-full\">\n {(fields || []).map((field, index) => {\n const fieldProps = field.props as CommandFormFieldProps<any>;\n const propertyAccessor = fieldProps.value;\n const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : `field-${index}`;\n\n return (\n <CommandFormFieldWrapper\n key={propertyName}\n field={field}\n index={index}\n />\n );\n })}\n </div>\n );\n};\n\n// Helper function to extract property name from accessor function\nfunction getPropertyName<T>(accessor: (obj: T) => unknown): string {\n const fnStr = accessor.toString();\n const match = fnStr.match(/\\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);\n return match ? match[1] : '';\n}\n"],"names":["useCommandFormContext","_jsxs","_jsx","Tooltip"],"mappings":";;;;;;;AAkBA,MAAM,uBAAuB,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAA4E,KAAI;AAC3H,IAAA,MAAM,OAAO,GAAGA,iCAAqB,EAAO;AAC5C,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,KAAmC;AAC5D,IAAA,MAAM,gBAAg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,CAAC,uBAAuB,EAAA,EAEpB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EAAA,EAFP,YAAY,CAGnB;QAEV,CAAC,CAAC,EAAA,CACA;AAEd;AAGA,SAAS,eAAe,CAAI,QAA6B,EAAA;AACrD,IAAA,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,EAAE;IACjC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,8BAA8B,CAAC;AACzD,IAAA,OAAO,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE;AAChC;;;;"}
|
|
1
|
+
{"version":3,"file":"CommandFormFields.js","sources":["../../../CommandForm/CommandFormFields.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { useCommandFormContext } from './CommandForm';\nimport React from 'react';\nimport { Tooltip } from 'primereact/tooltip';\nimport type { CommandFormFieldProps } from './CommandFormField';\nimport type { ICommandResult } from '@cratis/arc/commands';\n\nexport interface ColumnInfo {\n fields: React.ReactElement<CommandFormFieldProps<unknown>>[];\n}\n\nexport interface CommandFormFieldsProps {\n fields?: React.ReactElement<CommandFormFieldProps<unknown>>[];\n columns?: ColumnInfo[];\n}\n\n// Separate component for each field to prevent re-rendering all fields\nconst CommandFormFieldWrapper = ({ field, index }: { field: React.ReactElement<CommandFormFieldProps<unknown>>; index: number }) => {\n const context = useCommandFormContext<unknown>();\n const fieldProps = field.props as CommandFormFieldProps<unknown>;\n const propertyAccessor = fieldProps.value;\n\n // Get the property name from the accessor function\n const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : '';\n\n // Get the current value from the command instance\n const currentValue = propertyName ? (context.commandInstance as Record<string, unknown>)?.[propertyName] : undefined;\n\n // Get the error message for this field, if any\n const errorMessage = propertyName ? context.getFieldError(propertyName) : undefined;\n\n // Get the property descriptor for this field from the command instance\n const propertyDescriptor = propertyName && (context.commandInstance as Record<string, unknown>)?.propertyDescriptors\n ? ((context.commandInstance as Record<string, unknown>).propertyDescriptors as Array<Record<string, unknown>>).find((pd: Record<string, unknown>) => pd.name === propertyName)\n : undefined;\n\n // Clone the field element with the current value and onChange handler\n const clonedField = React.cloneElement(field as React.ReactElement, {\n ...fieldProps,\n currentValue,\n propertyDescriptor,\n fieldName: propertyName,\n onValueChange: (value: unknown) => {\n if (propertyName) {\n const oldValue = currentValue;\n\n // Update the command value\n context.setCommandValues({ [propertyName]: value } as Record<string, unknown>);\n\n // Call validate() on the command instance and store the result\n if (context.commandInstance && typeof (context.commandInstance as Record<string, unknown>).validate === 'function') {\n const validationResult = ((context.commandInstance as Record<string, unknown>).validate as () => ICommandResult<unknown>)();\n if (validationResult) {\n context.setCommandResult(validationResult);\n }\n }\n\n // Call custom field validator if provided\n if (context.onFieldValidate) {\n const validationError = context.onFieldValidate(context.commandInstance as Record<string, unknown>, propertyName, oldValue, value);\n context.setCustomFieldError(propertyName, validationError);\n }\n\n // Call field change callback if provided\n if (context.onFieldChange) {\n context.onFieldChange(context.commandInstance as Record<string, unknown>, propertyName, oldValue, value);\n }\n }\n fieldProps.onChange?.(value as unknown);\n },\n required: fieldProps.required ?? true,\n invalid: !!errorMessage\n } as Record<string, unknown>);\n\n const tooltipId = fieldProps.description ? `tooltip-${propertyName}-${index}` : undefined;\n\n return (\n <div className=\"w-full\">\n <div className=\"p-inputgroup w-full\">\n {fieldProps.description && (\n <Tooltip target={`.${tooltipId}`} content={fieldProps.description} />\n )}\n {fieldProps.icon && (\n <span className={`p-inputgroup-addon ${tooltipId || ''}`}>\n {fieldProps.icon}\n </span>\n )}\n {clonedField}\n </div>\n {errorMessage && (\n <small className=\"p-error block mt-1\">{errorMessage}</small>\n )}\n </div>\n );\n};\n\nexport const CommandFormFields = (props: CommandFormFieldsProps) => {\n const { fields, columns } = props;\n\n // Render columns if provided\n if (columns && columns.length > 0) {\n return (\n <div className=\"card flex flex-column md:flex-row gap-3\">\n {columns.map((column, columnIndex) => (\n <div key={`column-${columnIndex}`} className=\"flex flex-column gap-3 flex-1\">\n {column.fields.map((field, index) => {\n const fieldProps = field.props as CommandFormFieldProps<unknown>;\n const propertyAccessor = fieldProps.value;\n const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : `field-${columnIndex}-${index}`;\n\n return (\n <CommandFormFieldWrapper\n key={propertyName}\n field={field}\n index={index}\n />\n );\n })}\n </div>\n ))}\n </div>\n );\n }\n\n // Render fields (single column layout)\n return (\n <div className=\"flex flex-col gap-4 w-full\">\n {(fields || []).map((field, index) => {\n const fieldProps = field.props as CommandFormFieldProps<unknown>;\n const propertyAccessor = fieldProps.value;\n const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : `field-${index}`;\n\n return (\n <CommandFormFieldWrapper\n key={propertyName}\n field={field}\n index={index}\n />\n );\n })}\n </div>\n );\n};\n\n// Helper function to extract property name from accessor function\nfunction getPropertyName<T>(accessor: (obj: T) => unknown): string {\n const fnStr = accessor.toString();\n const match = fnStr.match(/\\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);\n return match ? match[1] : '';\n}\n"],"names":["useCommandFormContext","_jsxs","_jsx","Tooltip"],"mappings":";;;;;;;AAmBA,MAAM,uBAAuB,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAgF,KAAI;AAC/H,IAAA,MAAM,OAAO,GAAGA,iCAAqB,EAAW;AAChD,IAAA,MAAM,UAAU,GAAG,KAAK,CAAC,KAAuC;AAChE,IAAA,MAAM,gBAAgB,GAAG,UAAU,CAAC,KAAK;AAGzC,IAAA,MAAM,YAAY,GAAG,gBAAgB,GAAG,eAAe,CAAC,gBAAgB,CAAC,GAAG,EAAE;AAG9E,IAAA,MAAM,YAAY,GAAG,YAAY,GAAI,OAAO,CAAC,eAA2C,GAAG,YAAY,CAAC,GAAG,SAAS;AAGpH,IAAA,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,YAAY,CAAC,GAAG,SAAS;IAGnF,MAAM,kBAAk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AK,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE;AAChC;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableForObservableQuery.js","sources":["../../../DataTables/DataTableForObservableQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DataTable, DataTableFilterMeta, DataTableSelectionSingleChangeEvent } from 'primereact/datatable';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IObservableQueryFor, Paging } from '@cratis/arc/queries';\nimport { useObservableQueryWithPaging } from '@cratis/arc.react/queries';\nimport { ReactNode, useState } from 'react';\n\n \n\n/**\n * Props for the DataTableForQuery component\n */\nexport interface DataTableForObservableQueryProps<TQuery extends IObservableQueryFor<TDataType>, TDataType, TArguments> {\n /**\n * Children to render\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?:
|
|
1
|
+
{"version":3,"file":"DataTableForObservableQuery.js","sources":["../../../DataTables/DataTableForObservableQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DataTable, DataTableFilterMeta, DataTableSelectionSingleChangeEvent } from 'primereact/datatable';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IObservableQueryFor, Paging } from '@cratis/arc/queries';\nimport { useObservableQueryWithPaging } from '@cratis/arc.react/queries';\nimport { ReactNode, useState } from 'react';\n\n \n\n/**\n * Props for the DataTableForQuery component\n */\nexport interface DataTableForObservableQueryProps<TQuery extends IObservableQueryFor<TDataType, TArguments>, TDataType extends object, TArguments extends object> {\n /**\n * Children to render\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes\n */\n onSelectionChange?(event: DataTableSelectionSingleChangeEvent<TDataType[]>): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n}\n\nconst paging = new Paging(0, 20);\n\n/**\n * Represents a DataTable for a query.\n * @param props Props for the component\n * @returns Function to render the DataTableForQuery component\n */\nexport const DataTableForObservableQuery = <TQuery extends IObservableQueryFor<TDataType, TArguments>, TDataType extends object, TArguments extends object>(props: DataTableForObservableQueryProps<TQuery, TDataType, TArguments>) => {\n const [filters, setFilters] = useState<DataTableFilterMeta>(props.defaultFilters ?? {});\n const [result, , setPage] = useObservableQueryWithPaging(props.query, paging, props.queryArguments);\n\n return (\n <DataTable\n value={result.data as unknown as object[]}\n lazy\n rows={paging.pageSize}\n totalRecords={result.paging.totalItems}\n paginator\n alwaysShowPaginator={false}\n first={result.paging.page * paging.pageSize}\n onPage={(e) => setPage(e.page ?? 0)}\n scrollable\n scrollHeight={'flex'}\n selectionMode='single'\n selection={props.selection}\n onSelectionChange={props.onSelectionChange}\n dataKey={props.dataKey}\n filters={filters}\n filterDisplay='menu'\n onFilter={(e) => setFilters(e.filters)}\n globalFilterFields={props.globalFilterFields}\n emptyMessage={props.emptyMessage}>\n {props.children}\n </DataTable>\n );\n};\n"],"names":["Paging","useState","useObservableQueryWithPaging","_jsx","DataTable"],"mappings":";;;;;;;;AA6DA,MAAM,MAAM,GAAG,IAAIA,cAAM,CAAC,CAAC,EAAE,EAAE,CAAC;AAOzB,MAAM,2BAA2B,GAAG,CAAiH,KAAsE,KAAI;AAClO,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,cAAQ,CAAsB,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC;IACvF,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,GAAGC,sCAA4B,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC;AAEnG,IAAA,QACIC,cAAA,CAACC,mBAAS,EAAA,EACN,KAAK,EAAE,MAAM,CAAC,IAA2B,EACzC,IAAI,EAAA,IAAA,EACJ,IAAI,EAAE,MAAM,CAAC,QAAQ,EACrB,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,EACtC,SAAS,EAAA,IAAA,EACT,mBAAmB,EAAE,KAAK,EAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,QAAQ,EAC3C,MAAM,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,EACnC,UAAU,EAAA,IAAA,EACV,YAAY,EAAE,MAAM,EACpB,aAAa,EAAC,QAAQ,EACtB,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,EAC1C,OAAO,EAAE,KAAK,CAAC,OAAO,EACtB,OAAO,EAAE,OAAO,EAChB,aAAa,EAAC,MAAM,EACpB,QAAQ,EAAE,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,EACtC,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAC5C,YAAY,EAAE,KAAK,CAAC,YAAY,EAAA,QAAA,EAC/B,KAAK,CAAC,QAAQ,EAAA,CACP;AAEpB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataTableForQuery.js","sources":["../../../DataTables/DataTableForQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DataTable, DataTableFilterMeta, DataTableSelectionSingleChangeEvent } from 'primereact/datatable';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IQueryFor, Paging } from '@cratis/arc/queries';\nimport { useQueryWithPaging } from '@cratis/arc.react/queries';\nimport { ReactNode, useState } from 'react';\n\n \n\n/**\n * Props for the DataTableForQuery component\n */\nexport interface DataTableForQueryProps<TQuery extends IQueryFor<TDataType>, TDataType, TArguments> {\n /**\n * Children to render\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional Arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?:
|
|
1
|
+
{"version":3,"file":"DataTableForQuery.js","sources":["../../../DataTables/DataTableForQuery.tsx"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { DataTable, DataTableFilterMeta, DataTableSelectionSingleChangeEvent } from 'primereact/datatable';\nimport { Constructor } from '@cratis/fundamentals';\nimport { IQueryFor, Paging } from '@cratis/arc/queries';\nimport { useQueryWithPaging } from '@cratis/arc.react/queries';\nimport { ReactNode, useState } from 'react';\n\n \n\n/**\n * Props for the DataTableForQuery component\n */\nexport interface DataTableForQueryProps<TQuery extends IQueryFor<TDataType, TArguments>, TDataType extends object, TArguments extends object> {\n /**\n * Children to render\n */\n children?: ReactNode;\n\n /**\n * The type of query to use\n */\n query: Constructor<TQuery>;\n\n /**\n * Optional Arguments to pass to the query\n */\n queryArguments?: TArguments;\n\n /**\n * The message to show when there is no data\n */\n emptyMessage: string;\n\n /**\n * The key to use for the data\n */\n dataKey?: string | undefined;\n\n /**\n * The current selection.\n */\n selection?: TDataType | undefined | null;\n\n /**\n * Callback for when the selection changes\n */\n onSelectionChange?(event: DataTableSelectionSingleChangeEvent<TDataType[]>): void;\n\n /**\n * Fields to use for global filtering\n */\n globalFilterFields?: string[] | undefined;\n\n /**\n * Default filters to use\n */\n defaultFilters?: DataTableFilterMeta;\n}\n\nconst paging = new Paging(0, 20);\n\n/**\n * Represents a DataTable for a query.\n * @param props Props for the component\n * @returns Function to render the DataTableForQuery component\n */\nexport const DataTableForQuery = <TQuery extends IQueryFor<TDataType, TArguments>, TDataType extends object, TArguments extends object>(props: DataTableForQueryProps<TQuery, TDataType, TArguments>) => {\n const [filters, setFilters] = useState<DataTableFilterMeta>(props.defaultFilters ?? {});\n const [result, , , setPage] = useQueryWithPaging(props.query, paging, props.queryArguments);\n\n return (\n <DataTable\n value={result.data as unknown as object[]}\n lazy\n rows={paging.pageSize}\n totalRecords={result.paging.totalItems}\n paginator\n alwaysShowPaginator={false}\n first={result.paging.page * paging.pageSize}\n onPage={(e) => setPage(e.page ?? 0)}\n scrollable\n scrollHeight={'flex'}\n selectionMode='single'\n selection={props.selection}\n onSelectionChange={props.onSelectionChange}\n dataKey={props.dataKey}\n filters={filters}\n filterDisplay='menu'\n onFilter={(e) => setFilters(e.filters)}\n globalFilterFields={props.globalFilterFields}\n emptyMessage={props.emptyMessage} >\n {props.children}\n </DataTable >\n );\n};\n"],"names":["Paging","useState","useQueryWithPaging","_jsx","DataTable"],"mappings":";;;;;;;;AA6DA,MAAM,MAAM,GAAG,IAAIA,cAAM,CAAC,CAAC,EAAE,EAAE,CAAC;AAOzB,MAAM,iBAAiB,GAAG,CAAuG,KAA4D,KAAI;AACpM,IAAA,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAGC,cAAQ,CAAsB,KAAK,CAAC,cAAc,IAAI,EAAE,CAAC;IACvF,MAAM,CAAC,MAAM,MAAM,OAAO,CAAC,GAAGC,4BAAkB,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC;AAE3F,IAAA,QACIC,cAAA,CAACC,mBAAS,EAAA,EACN,KAAK,EAAE,MAAM,CAAC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