@cratis/components 0.1.9 → 0.1.12
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/CommandForm/CommandFormFields.js +9 -3
- package/dist/cjs/CommandForm/CommandFormFields.js.map +1 -1
- package/dist/cjs/CommandForm/ValidationMessage.js +24 -0
- package/dist/cjs/CommandForm/ValidationMessage.js.map +1 -0
- package/dist/cjs/CommandForm/asCommandFormField.js +47 -0
- package/dist/cjs/CommandForm/asCommandFormField.js.map +1 -0
- package/dist/cjs/CommandForm/fields/CheckboxField.js +13 -0
- package/dist/cjs/CommandForm/fields/CheckboxField.js.map +1 -0
- package/dist/cjs/CommandForm/fields/DropdownField.js +13 -0
- package/dist/cjs/CommandForm/fields/DropdownField.js.map +1 -0
- package/dist/cjs/CommandForm/fields/InputTextField.js +13 -0
- package/dist/cjs/CommandForm/fields/InputTextField.js.map +1 -0
- package/dist/cjs/CommandForm/fields/NumberField.js +13 -0
- package/dist/cjs/CommandForm/fields/NumberField.js.map +1 -0
- package/dist/cjs/CommandForm/fields/SliderField.js +17 -0
- package/dist/cjs/CommandForm/fields/SliderField.js.map +1 -0
- package/dist/cjs/CommandForm/fields/TextAreaField.js +13 -0
- package/dist/cjs/CommandForm/fields/TextAreaField.js.map +1 -0
- package/dist/cjs/CommandForm/index.js +15 -7
- package/dist/cjs/CommandForm/index.js.map +1 -1
- package/dist/cjs/PivotViewer/PivotViewer.css +1258 -0
- package/dist/cjs/PivotViewer/PivotViewer.js +14 -0
- package/dist/cjs/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotCanvas.js +33 -10
- package/dist/cjs/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotViewerMain.js +1 -1
- package/dist/cjs/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/cjs/PivotViewer/components/Spinner.css +77 -0
- package/dist/cjs/PivotViewer/components/pivot/sprites.js +79 -15
- package/dist/cjs/PivotViewer/components/pivot/sprites.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/visibility.js +36 -10
- package/dist/cjs/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/cjs/PivotViewer/engine/layout.js +2 -1
- package/dist/cjs/PivotViewer/engine/layout.js.map +1 -1
- package/dist/cjs/PivotViewer/hooks/usePivotEngine.js +37 -2
- package/dist/cjs/PivotViewer/hooks/usePivotEngine.js.map +1 -1
- package/dist/cjs/PivotViewer/index.js +3 -0
- package/dist/cjs/PivotViewer/index.js.map +1 -1
- package/dist/cjs/PivotViewer/types.js +22 -0
- package/dist/cjs/PivotViewer/types.js.map +1 -0
- package/dist/cjs/TimeMachine/EventsView.css +213 -0
- package/dist/cjs/TimeMachine/TimeMachine.css +567 -0
- package/dist/cjs/TimeMachine/TimeMachine.js +8 -3
- package/dist/cjs/TimeMachine/TimeMachine.js.map +1 -1
- package/dist/esm/CommandForm/CommandForm.stories.d.ts +1 -0
- package/dist/esm/CommandForm/CommandForm.stories.d.ts.map +1 -1
- package/dist/esm/CommandForm/CommandForm.stories.js +34 -1
- package/dist/esm/CommandForm/CommandForm.stories.js.map +1 -1
- package/dist/esm/CommandForm/CommandFormFields.d.ts.map +1 -1
- package/dist/esm/CommandForm/CommandFormFields.js +9 -3
- package/dist/esm/CommandForm/CommandFormFields.js.map +1 -1
- package/dist/esm/CommandForm/UserRegistrationCommand.d.ts +63 -0
- package/dist/esm/CommandForm/UserRegistrationCommand.d.ts.map +1 -0
- package/dist/esm/CommandForm/UserRegistrationCommand.js +143 -0
- package/dist/esm/CommandForm/UserRegistrationCommand.js.map +1 -0
- package/dist/esm/CommandForm/ValidationMessage.d.ts +8 -0
- package/dist/esm/CommandForm/ValidationMessage.d.ts.map +1 -0
- package/dist/esm/CommandForm/ValidationMessage.js +22 -0
- package/dist/esm/CommandForm/ValidationMessage.js.map +1 -0
- package/dist/esm/CommandForm/asCommandFormField.d.ts +32 -0
- package/dist/esm/CommandForm/asCommandFormField.d.ts.map +1 -0
- package/dist/esm/CommandForm/asCommandFormField.js +45 -0
- package/dist/esm/CommandForm/asCommandFormField.js.map +1 -0
- package/dist/esm/CommandForm/fields/CheckboxField.d.ts +10 -0
- package/dist/esm/CommandForm/fields/CheckboxField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/CheckboxField.js +11 -0
- package/dist/esm/CommandForm/fields/CheckboxField.js.map +1 -0
- package/dist/esm/CommandForm/fields/DropdownField.d.ts +15 -0
- package/dist/esm/CommandForm/fields/DropdownField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/DropdownField.js +11 -0
- package/dist/esm/CommandForm/fields/DropdownField.js.map +1 -0
- package/dist/esm/CommandForm/fields/InputTextField.d.ts +11 -0
- package/dist/esm/CommandForm/fields/InputTextField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/InputTextField.js +11 -0
- package/dist/esm/CommandForm/fields/InputTextField.js.map +1 -0
- package/dist/esm/CommandForm/fields/NumberField.d.ts +13 -0
- package/dist/esm/CommandForm/fields/NumberField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/NumberField.js +11 -0
- package/dist/esm/CommandForm/fields/NumberField.js.map +1 -0
- package/dist/esm/CommandForm/fields/SliderField.d.ts +12 -0
- package/dist/esm/CommandForm/fields/SliderField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/SliderField.js +15 -0
- package/dist/esm/CommandForm/fields/SliderField.js.map +1 -0
- package/dist/esm/CommandForm/fields/TextAreaField.d.ts +12 -0
- package/dist/esm/CommandForm/fields/TextAreaField.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/TextAreaField.js +11 -0
- package/dist/esm/CommandForm/fields/TextAreaField.js.map +1 -0
- package/dist/esm/CommandForm/fields/index.d.ts +7 -0
- package/dist/esm/CommandForm/fields/index.d.ts.map +1 -0
- package/dist/esm/CommandForm/fields/index.js +7 -0
- package/dist/esm/CommandForm/fields/index.js.map +1 -0
- package/dist/esm/CommandForm/index.d.ts +3 -4
- package/dist/esm/CommandForm/index.d.ts.map +1 -1
- package/dist/esm/CommandForm/index.js +8 -4
- package/dist/esm/CommandForm/index.js.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.css +1258 -0
- package/dist/esm/PivotViewer/PivotViewer.d.ts.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.js +14 -0
- package/dist/esm/PivotViewer/PivotViewer.js.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.stories.d.ts +1 -0
- package/dist/esm/PivotViewer/PivotViewer.stories.d.ts.map +1 -1
- package/dist/esm/PivotViewer/PivotViewer.stories.js +43 -3
- package/dist/esm/PivotViewer/PivotViewer.stories.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.js +33 -10
- package/dist/esm/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.js +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/esm/PivotViewer/components/Spinner.css +77 -0
- package/dist/esm/PivotViewer/components/pivot/sprites.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/sprites.js +79 -15
- package/dist/esm/PivotViewer/components/pivot/sprites.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/visibility.js +36 -10
- package/dist/esm/PivotViewer/components/pivot/visibility.js.map +1 -1
- package/dist/esm/PivotViewer/engine/layout.js +2 -1
- package/dist/esm/PivotViewer/engine/layout.js.map +1 -1
- package/dist/esm/PivotViewer/engine/pivot.worker.d.ts.map +1 -1
- package/dist/esm/PivotViewer/engine/pivot.worker.js +22 -7
- package/dist/esm/PivotViewer/engine/pivot.worker.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/useFilteredData.d.ts +2 -2
- package/dist/esm/PivotViewer/hooks/useFilteredData.d.ts.map +1 -1
- package/dist/esm/PivotViewer/hooks/useFilteredData.js +4 -2
- package/dist/esm/PivotViewer/hooks/useFilteredData.js.map +1 -1
- package/dist/esm/PivotViewer/hooks/usePivotEngine.d.ts.map +1 -1
- package/dist/esm/PivotViewer/hooks/usePivotEngine.js +37 -2
- package/dist/esm/PivotViewer/hooks/usePivotEngine.js.map +1 -1
- package/dist/esm/PivotViewer/index.d.ts +2 -1
- package/dist/esm/PivotViewer/index.d.ts.map +1 -1
- package/dist/esm/PivotViewer/index.js +1 -0
- package/dist/esm/PivotViewer/index.js.map +1 -1
- package/dist/esm/PivotViewer/types.d.ts +4 -1
- package/dist/esm/PivotViewer/types.d.ts.map +1 -1
- package/dist/esm/PivotViewer/types.js +19 -2
- package/dist/esm/PivotViewer/types.js.map +1 -1
- package/dist/esm/TimeMachine/EventsView.css +213 -0
- package/dist/esm/TimeMachine/TimeMachine.css +567 -0
- package/dist/esm/TimeMachine/TimeMachine.d.ts.map +1 -1
- package/dist/esm/TimeMachine/TimeMachine.js +8 -3
- package/dist/esm/TimeMachine/TimeMachine.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +31 -32
- package/.storybook/main.ts +0 -24
- package/CommandDialog/CommandDialog.stories.tsx +0 -25
- package/CommandDialog/CommandDialog.tsx +0 -161
- package/CommandDialog/index.ts +0 -4
- package/CommandForm/CommandForm.stories.tsx +0 -24
- package/CommandForm/CommandForm.tsx +0 -266
- package/CommandForm/CommandFormField.tsx +0 -27
- package/CommandForm/CommandFormFields.tsx +0 -142
- package/CommandForm/DatePickerField.tsx +0 -57
- package/CommandForm/DropdownField.tsx +0 -65
- package/CommandForm/InputTextField.tsx +0 -62
- package/CommandForm/SliderField.tsx +0 -68
- package/CommandForm/index.ts +0 -10
- package/Common/ErrorBoundary.stories.tsx +0 -10
- package/Common/ErrorBoundary.tsx +0 -41
- package/Common/FormElement.stories.tsx +0 -10
- package/Common/FormElement.tsx +0 -20
- package/Common/Page.stories.tsx +0 -10
- package/Common/Page.tsx +0 -21
- package/Common/index.ts +0 -6
- package/DataPage/DataPage.stories.tsx +0 -10
- package/DataPage/DataPage.tsx +0 -191
- package/DataPage/index.ts +0 -4
- package/DataTables/DataTableForObservableQuery.stories.tsx +0 -10
- package/DataTables/DataTableForObservableQuery.tsx +0 -97
- package/DataTables/DataTableForQuery.stories.tsx +0 -10
- package/DataTables/DataTableForQuery.tsx +0 -97
- package/DataTables/index.ts +0 -5
- package/Dialogs/BusyIndicatorDialog.stories.tsx +0 -26
- package/Dialogs/BusyIndicatorDialog.tsx +0 -26
- package/Dialogs/ConfirmationDialog.stories.tsx +0 -36
- package/Dialogs/ConfirmationDialog.tsx +0 -75
- package/Dialogs/index.ts +0 -5
- package/Dropdown/Dropdown.tsx +0 -23
- package/Dropdown/index.ts +0 -4
- package/PivotViewer/PivotViewer.stories.tsx +0 -24
- package/PivotViewer/PivotViewer.tsx +0 -791
- package/PivotViewer/components/AxisLabels.tsx +0 -69
- package/PivotViewer/components/DetailPanel.tsx +0 -108
- package/PivotViewer/components/FilterPanel.tsx +0 -189
- package/PivotViewer/components/FilterPanelContainer.tsx +0 -10
- package/PivotViewer/components/PivotCanvas.tsx +0 -660
- package/PivotViewer/components/PivotViewerMain.tsx +0 -229
- package/PivotViewer/components/RangeHistogramFilter.tsx +0 -220
- package/PivotViewer/components/Spinner.tsx +0 -21
- package/PivotViewer/components/Toolbar.tsx +0 -130
- package/PivotViewer/components/ToolbarContainer.tsx +0 -10
- package/PivotViewer/components/index.ts +0 -12
- package/PivotViewer/components/pivot/animation.ts +0 -108
- package/PivotViewer/components/pivot/buckets.ts +0 -152
- package/PivotViewer/components/pivot/colorResolver.ts +0 -67
- package/PivotViewer/components/pivot/constants.ts +0 -46
- package/PivotViewer/components/pivot/sprites.ts +0 -265
- package/PivotViewer/components/pivot/visibility.ts +0 -319
- package/PivotViewer/constants.ts +0 -9
- package/PivotViewer/engine/layout.ts +0 -149
- package/PivotViewer/engine/pivot.worker.ts +0 -86
- package/PivotViewer/engine/store.ts +0 -437
- package/PivotViewer/engine/types.ts +0 -255
- package/PivotViewer/hooks/index.ts +0 -13
- package/PivotViewer/hooks/useContainerDimensions.ts +0 -45
- package/PivotViewer/hooks/useDimensionState.ts +0 -53
- package/PivotViewer/hooks/useFilterOptions.ts +0 -36
- package/PivotViewer/hooks/useFilterPanelDrag.ts +0 -49
- package/PivotViewer/hooks/useFilterState.ts +0 -106
- package/PivotViewer/hooks/useFilteredData.ts +0 -119
- package/PivotViewer/hooks/usePanning.ts +0 -163
- package/PivotViewer/hooks/usePivotEngine.ts +0 -252
- package/PivotViewer/hooks/useSelectedItem.ts +0 -402
- package/PivotViewer/hooks/useWheelZoom.ts +0 -114
- package/PivotViewer/hooks/useZoomState.ts +0 -34
- package/PivotViewer/index.ts +0 -7
- package/PivotViewer/types.ts +0 -59
- package/PivotViewer/utils/animations.ts +0 -249
- package/PivotViewer/utils/constants.ts +0 -20
- package/PivotViewer/utils/index.ts +0 -6
- package/PivotViewer/utils/selection.ts +0 -292
- package/PivotViewer/utils/utils.ts +0 -259
- package/TimeMachine/EventsView.stories.tsx +0 -10
- package/TimeMachine/EventsView.tsx +0 -119
- package/TimeMachine/Properties.stories.tsx +0 -10
- package/TimeMachine/Properties.tsx +0 -98
- package/TimeMachine/ReadModelView.stories.tsx +0 -10
- package/TimeMachine/ReadModelView.tsx +0 -143
- package/TimeMachine/TimeMachine.stories.tsx +0 -10
- package/TimeMachine/TimeMachine.tsx +0 -244
- package/TimeMachine/index.ts +0 -8
- package/TimeMachine/types.ts +0 -23
- package/dist/cjs/CommandForm/DatePickerField.js +0 -31
- package/dist/cjs/CommandForm/DatePickerField.js.map +0 -1
- package/dist/cjs/CommandForm/DropdownField.js +0 -31
- package/dist/cjs/CommandForm/DropdownField.js.map +0 -1
- package/dist/cjs/CommandForm/InputTextField.js +0 -32
- package/dist/cjs/CommandForm/InputTextField.js.map +0 -1
- package/dist/cjs/CommandForm/SliderField.js +0 -34
- package/dist/cjs/CommandForm/SliderField.js.map +0 -1
- package/dist/esm/CommandForm/DatePickerField.d.ts +0 -20
- package/dist/esm/CommandForm/DatePickerField.d.ts.map +0 -1
- package/dist/esm/CommandForm/DatePickerField.js +0 -29
- package/dist/esm/CommandForm/DatePickerField.js.map +0 -1
- package/dist/esm/CommandForm/DropdownField.d.ts +0 -24
- package/dist/esm/CommandForm/DropdownField.d.ts.map +0 -1
- package/dist/esm/CommandForm/DropdownField.js +0 -29
- package/dist/esm/CommandForm/DropdownField.js.map +0 -1
- package/dist/esm/CommandForm/InputTextField.d.ts +0 -20
- package/dist/esm/CommandForm/InputTextField.d.ts.map +0 -1
- package/dist/esm/CommandForm/InputTextField.js +0 -30
- package/dist/esm/CommandForm/InputTextField.js.map +0 -1
- package/dist/esm/CommandForm/SliderField.d.ts +0 -23
- package/dist/esm/CommandForm/SliderField.d.ts.map +0 -1
- package/dist/esm/CommandForm/SliderField.js +0 -32
- package/dist/esm/CommandForm/SliderField.js.map +0 -1
- package/global.d.ts +0 -11
- package/index.ts +0 -22
- package/useOverlayZIndex.ts +0 -32
- package/vite.config.ts +0 -80
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { useCommandFormContext } from './CommandForm';
|
|
5
|
-
import React from 'react';
|
|
6
|
-
import { Tooltip } from 'primereact/tooltip';
|
|
7
|
-
import type { CommandFormFieldProps } from './CommandFormField';
|
|
8
|
-
|
|
9
|
-
export interface ColumnInfo {
|
|
10
|
-
fields: React.ReactElement<CommandFormFieldProps<any>>[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface CommandFormFieldsProps {
|
|
14
|
-
fields?: React.ReactElement<CommandFormFieldProps<any>>[];
|
|
15
|
-
columns?: ColumnInfo[];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Separate component for each field to prevent re-rendering all fields
|
|
19
|
-
const CommandFormFieldWrapper = ({ field, index }: { field: React.ReactElement<CommandFormFieldProps<any>>; index: number }) => {
|
|
20
|
-
const context = useCommandFormContext<any>();
|
|
21
|
-
const fieldProps = field.props as CommandFormFieldProps<any>;
|
|
22
|
-
const propertyAccessor = fieldProps.value;
|
|
23
|
-
|
|
24
|
-
// Get the property name from the accessor function
|
|
25
|
-
const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : '';
|
|
26
|
-
|
|
27
|
-
// Get the current value from the command instance
|
|
28
|
-
const currentValue = propertyName ? (context.commandInstance as any)?.[propertyName] : undefined;
|
|
29
|
-
|
|
30
|
-
// Get the error message for this field, if any
|
|
31
|
-
const errorMessage = propertyName ? context.getFieldError(propertyName) : undefined;
|
|
32
|
-
|
|
33
|
-
// Get the property descriptor for this field from the command instance
|
|
34
|
-
const propertyDescriptor = propertyName && (context.commandInstance as any)?.propertyDescriptors
|
|
35
|
-
? (context.commandInstance as any).propertyDescriptors.find((pd: any) => pd.name === propertyName)
|
|
36
|
-
: undefined;
|
|
37
|
-
|
|
38
|
-
// Clone the field element with the current value and onChange handler
|
|
39
|
-
const clonedField = React.cloneElement(field as React.ReactElement, {
|
|
40
|
-
...fieldProps,
|
|
41
|
-
currentValue,
|
|
42
|
-
propertyDescriptor,
|
|
43
|
-
fieldName: propertyName,
|
|
44
|
-
onValueChange: (value: unknown) => {
|
|
45
|
-
if (propertyName) {
|
|
46
|
-
const oldValue = currentValue;
|
|
47
|
-
|
|
48
|
-
// Call custom field validator if provided
|
|
49
|
-
if (context.onFieldValidate) {
|
|
50
|
-
const validationError = context.onFieldValidate(context.commandInstance as any, propertyName, oldValue, value);
|
|
51
|
-
context.setCustomFieldError(propertyName, validationError);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
context.setCommandValues({ [propertyName]: value } as any);
|
|
55
|
-
|
|
56
|
-
// Call field change callback if provided
|
|
57
|
-
if (context.onFieldChange) {
|
|
58
|
-
context.onFieldChange(context.commandInstance as any, propertyName, oldValue, value);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
fieldProps.onChange?.(value as any);
|
|
62
|
-
},
|
|
63
|
-
required: fieldProps.required ?? true,
|
|
64
|
-
invalid: !!errorMessage
|
|
65
|
-
} as any);
|
|
66
|
-
|
|
67
|
-
const tooltipId = fieldProps.description ? `tooltip-${propertyName}-${index}` : undefined;
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
<div style={{ width: '100%' }}>
|
|
71
|
-
<div className="p-inputgroup" style={{ width: '100%' }}>
|
|
72
|
-
{fieldProps.description && (
|
|
73
|
-
<Tooltip target={`.${tooltipId}`} content={fieldProps.description} />
|
|
74
|
-
)}
|
|
75
|
-
{fieldProps.icon && (
|
|
76
|
-
<span className={`p-inputgroup-addon ${tooltipId || ''}`}>
|
|
77
|
-
{fieldProps.icon}
|
|
78
|
-
</span>
|
|
79
|
-
)}
|
|
80
|
-
{clonedField}
|
|
81
|
-
</div>
|
|
82
|
-
{errorMessage && (
|
|
83
|
-
<small className="p-error block mt-1">{errorMessage}</small>
|
|
84
|
-
)}
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const CommandFormFields = (props: CommandFormFieldsProps) => {
|
|
90
|
-
const { fields, columns } = props;
|
|
91
|
-
|
|
92
|
-
// Render columns if provided
|
|
93
|
-
if (columns && columns.length > 0) {
|
|
94
|
-
return (
|
|
95
|
-
<div className="card flex flex-column md:flex-row gap-3">
|
|
96
|
-
{columns.map((column, columnIndex) => (
|
|
97
|
-
<div key={`column-${columnIndex}`} className="flex flex-column gap-3 flex-1">
|
|
98
|
-
{column.fields.map((field, index) => {
|
|
99
|
-
const fieldProps = field.props as CommandFormFieldProps<any>;
|
|
100
|
-
const propertyAccessor = fieldProps.value;
|
|
101
|
-
const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : `field-${columnIndex}-${index}`;
|
|
102
|
-
|
|
103
|
-
return (
|
|
104
|
-
<CommandFormFieldWrapper
|
|
105
|
-
key={propertyName}
|
|
106
|
-
field={field}
|
|
107
|
-
index={index}
|
|
108
|
-
/>
|
|
109
|
-
);
|
|
110
|
-
})}
|
|
111
|
-
</div>
|
|
112
|
-
))}
|
|
113
|
-
</div>
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Render fields (single column layout)
|
|
118
|
-
return (
|
|
119
|
-
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem', width: '100%' }}>
|
|
120
|
-
{(fields || []).map((field, index) => {
|
|
121
|
-
const fieldProps = field.props as CommandFormFieldProps<any>;
|
|
122
|
-
const propertyAccessor = fieldProps.value;
|
|
123
|
-
const propertyName = propertyAccessor ? getPropertyName(propertyAccessor) : `field-${index}`;
|
|
124
|
-
|
|
125
|
-
return (
|
|
126
|
-
<CommandFormFieldWrapper
|
|
127
|
-
key={propertyName}
|
|
128
|
-
field={field}
|
|
129
|
-
index={index}
|
|
130
|
-
/>
|
|
131
|
-
);
|
|
132
|
-
})}
|
|
133
|
-
</div>
|
|
134
|
-
);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// Helper function to extract property name from accessor function
|
|
138
|
-
function getPropertyName<T>(accessor: (obj: T) => unknown): string {
|
|
139
|
-
const fnStr = accessor.toString();
|
|
140
|
-
const match = fnStr.match(/\.([a-zA-Z_$][a-zA-Z0-9_$]*)/);
|
|
141
|
-
return match ? match[1] : '';
|
|
142
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
-
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
6
|
-
import React, { useState, useEffect } from 'react';
|
|
7
|
-
import { InputText } from 'primereact/inputtext';
|
|
8
|
-
import { useCommandFormContext } from './CommandForm';
|
|
9
|
-
|
|
10
|
-
export interface DatePickerFieldProps<TCommand> {
|
|
11
|
-
icon?: React.ReactElement;
|
|
12
|
-
value: PropertyAccessor<TCommand>;
|
|
13
|
-
onChange?: (value: unknown) => void;
|
|
14
|
-
currentValue?: string;
|
|
15
|
-
onValueChange?: (value: string) => void;
|
|
16
|
-
required?: boolean;
|
|
17
|
-
title?: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
propertyDescriptor?: PropertyDescriptor;
|
|
20
|
-
fieldName?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const DatePickerField = <TCommand,>(props: DatePickerFieldProps<TCommand>) => {
|
|
24
|
-
const [localValue, setLocalValue] = useState(props.currentValue || '');
|
|
25
|
-
const required = props.required ?? true;
|
|
26
|
-
const isValid = !required || localValue.trim().length > 0;
|
|
27
|
-
const { setFieldValidity } = useCommandFormContext();
|
|
28
|
-
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
setLocalValue(props.currentValue || '');
|
|
31
|
-
}, [props.currentValue]);
|
|
32
|
-
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
if (props.fieldName) {
|
|
35
|
-
setFieldValidity(props.fieldName, isValid);
|
|
36
|
-
}
|
|
37
|
-
}, [isValid, props.fieldName, setFieldValidity]);
|
|
38
|
-
|
|
39
|
-
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
40
|
-
const newValue = e.target.value;
|
|
41
|
-
setLocalValue(newValue);
|
|
42
|
-
props.onValueChange?.(newValue);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<InputText
|
|
47
|
-
type="date"
|
|
48
|
-
value={localValue}
|
|
49
|
-
onChange={handleChange}
|
|
50
|
-
required={required}
|
|
51
|
-
invalid={!isValid}
|
|
52
|
-
placeholder={props.title}
|
|
53
|
-
/>
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
DatePickerField.displayName = 'CommandFormField';
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
-
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
6
|
-
import React, { useState, useEffect } from 'react';
|
|
7
|
-
import { DropdownChangeEvent } from 'primereact/dropdown';
|
|
8
|
-
import { Dropdown } from '../Dropdown';
|
|
9
|
-
import { useCommandFormContext } from './CommandForm';
|
|
10
|
-
|
|
11
|
-
export interface DropdownFieldProps<TCommand, TOption> {
|
|
12
|
-
icon?: React.ReactElement;
|
|
13
|
-
value: PropertyAccessor<TCommand>;
|
|
14
|
-
options: TOption[];
|
|
15
|
-
optionIdField: keyof TOption;
|
|
16
|
-
optionLabelField: keyof TOption;
|
|
17
|
-
placeholder?: string;
|
|
18
|
-
onChange?: (value: unknown) => void;
|
|
19
|
-
currentValue?: unknown;
|
|
20
|
-
onValueChange?: (value: unknown) => void;
|
|
21
|
-
required?: boolean;
|
|
22
|
-
title?: string;
|
|
23
|
-
description?: string;
|
|
24
|
-
propertyDescriptor?: PropertyDescriptor;
|
|
25
|
-
fieldName?: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export const DropdownField = <TCommand, TOption>(props: DropdownFieldProps<TCommand, TOption>) => {
|
|
29
|
-
const [localValue, setLocalValue] = useState(props.currentValue);
|
|
30
|
-
const required = props.required ?? true;
|
|
31
|
-
const isValid = !required || localValue !== null && localValue !== undefined;
|
|
32
|
-
const { setFieldValidity } = useCommandFormContext();
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
setLocalValue(props.currentValue);
|
|
36
|
-
}, [props.currentValue]);
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (props.fieldName) {
|
|
40
|
-
setFieldValidity(props.fieldName, isValid);
|
|
41
|
-
}
|
|
42
|
-
}, [isValid, props.fieldName, setFieldValidity]);
|
|
43
|
-
|
|
44
|
-
const handleChange = (e: DropdownChangeEvent) => {
|
|
45
|
-
const newValue = e.value;
|
|
46
|
-
setLocalValue(newValue);
|
|
47
|
-
props.onValueChange?.(newValue);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<Dropdown
|
|
52
|
-
value={localValue}
|
|
53
|
-
onChange={handleChange}
|
|
54
|
-
options={props.options}
|
|
55
|
-
optionLabel={props.optionLabelField as string}
|
|
56
|
-
optionValue={props.optionIdField as string}
|
|
57
|
-
placeholder={props.placeholder || props.title}
|
|
58
|
-
required={required}
|
|
59
|
-
invalid={!isValid}
|
|
60
|
-
className="w-full"
|
|
61
|
-
/>
|
|
62
|
-
);
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
DropdownField.displayName = 'CommandFormField';
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
-
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
6
|
-
import React, { useState, useEffect } from 'react';
|
|
7
|
-
import { InputText } from 'primereact/inputtext';
|
|
8
|
-
import { useCommandFormContext } from './CommandForm';
|
|
9
|
-
|
|
10
|
-
export interface InputTextFieldProps<TCommand> {
|
|
11
|
-
icon?: React.ReactElement;
|
|
12
|
-
value: PropertyAccessor<TCommand>;
|
|
13
|
-
onChange?: (value: unknown) => void;
|
|
14
|
-
currentValue?: string;
|
|
15
|
-
onValueChange?: (value: string) => void;
|
|
16
|
-
required?: boolean;
|
|
17
|
-
title?: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
propertyDescriptor?: PropertyDescriptor;
|
|
20
|
-
fieldName?: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const InputTextField = <TCommand,>(props: InputTextFieldProps<TCommand>) => {
|
|
24
|
-
const [localValue, setLocalValue] = useState(props.currentValue || '');
|
|
25
|
-
const required = props.required ?? true;
|
|
26
|
-
const isValid = !required || localValue.trim().length > 0;
|
|
27
|
-
const { setFieldValidity } = useCommandFormContext();
|
|
28
|
-
|
|
29
|
-
// Determine input type based on property descriptor
|
|
30
|
-
const inputType = props.propertyDescriptor?.type === Number ? 'number' : 'text';
|
|
31
|
-
|
|
32
|
-
// Update local value when prop changes from outside
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
setLocalValue(props.currentValue || '');
|
|
35
|
-
}, [props.currentValue]);
|
|
36
|
-
|
|
37
|
-
// Report validity changes
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (props.fieldName) {
|
|
40
|
-
setFieldValidity(props.fieldName, isValid);
|
|
41
|
-
}
|
|
42
|
-
}, [isValid, props.fieldName, setFieldValidity]);
|
|
43
|
-
|
|
44
|
-
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
45
|
-
const newValue = e.target.value;
|
|
46
|
-
setLocalValue(newValue);
|
|
47
|
-
props.onValueChange?.(newValue);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<InputText
|
|
52
|
-
type={inputType}
|
|
53
|
-
value={localValue}
|
|
54
|
-
onChange={handleChange}
|
|
55
|
-
required={required}
|
|
56
|
-
invalid={!isValid}
|
|
57
|
-
placeholder={props.title}
|
|
58
|
-
/>
|
|
59
|
-
);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
InputTextField.displayName = 'CommandFormField';
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { PropertyAccessor } from '@cratis/fundamentals';
|
|
5
|
-
import { PropertyDescriptor } from '@cratis/arc/reflection';
|
|
6
|
-
import React, { useState, useEffect } from 'react';
|
|
7
|
-
import { Slider, SliderChangeEvent } from 'primereact/slider';
|
|
8
|
-
import { useCommandFormContext } from './CommandForm';
|
|
9
|
-
|
|
10
|
-
export interface SliderFieldProps<TCommand> {
|
|
11
|
-
icon?: React.ReactElement;
|
|
12
|
-
value: PropertyAccessor<TCommand>;
|
|
13
|
-
onChange?: (value: unknown) => void;
|
|
14
|
-
currentValue?: number;
|
|
15
|
-
onValueChange?: (value: number) => void;
|
|
16
|
-
required?: boolean;
|
|
17
|
-
title?: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
propertyDescriptor?: PropertyDescriptor;
|
|
20
|
-
fieldName?: string;
|
|
21
|
-
min?: number;
|
|
22
|
-
max?: number;
|
|
23
|
-
step?: number;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const SliderField = <TCommand,>(props: SliderFieldProps<TCommand>) => {
|
|
27
|
-
const [localValue, setLocalValue] = useState(props.currentValue ?? 0);
|
|
28
|
-
const required = props.required ?? true;
|
|
29
|
-
const min = props.min ?? 0;
|
|
30
|
-
const max = props.max ?? 1;
|
|
31
|
-
const step = props.step ?? 0.01;
|
|
32
|
-
const isValid = !required || (localValue >= min && localValue <= max);
|
|
33
|
-
const { setFieldValidity } = useCommandFormContext();
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
setLocalValue(props.currentValue ?? 0);
|
|
37
|
-
}, [props.currentValue]);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (props.fieldName) {
|
|
41
|
-
setFieldValidity(props.fieldName, isValid);
|
|
42
|
-
}
|
|
43
|
-
}, [isValid, props.fieldName, setFieldValidity]);
|
|
44
|
-
|
|
45
|
-
const handleChange = (e: SliderChangeEvent) => {
|
|
46
|
-
const newValue = e.value as number;
|
|
47
|
-
setLocalValue(newValue);
|
|
48
|
-
props.onValueChange?.(newValue);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
return (
|
|
52
|
-
<div className="p-inputtext w-full flex align-items-center gap-3" style={{ display: 'flex', alignItems: 'center', borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }}>
|
|
53
|
-
<Slider
|
|
54
|
-
value={localValue}
|
|
55
|
-
onChange={handleChange}
|
|
56
|
-
min={min}
|
|
57
|
-
max={max}
|
|
58
|
-
step={step}
|
|
59
|
-
className="flex-1 ml-2"
|
|
60
|
-
/>
|
|
61
|
-
<span className="font-semibold" style={{ minWidth: '3rem', textAlign: 'right' }}>
|
|
62
|
-
{localValue.toFixed(2)}
|
|
63
|
-
</span>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
SliderField.displayName = 'CommandFormField';
|
package/CommandForm/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
export * from './CommandForm';
|
|
5
|
-
export * from './CommandFormField';
|
|
6
|
-
export * from './CommandFormFields';
|
|
7
|
-
export * from './InputTextField';
|
|
8
|
-
export * from './DatePickerField';
|
|
9
|
-
export * from './DropdownField';
|
|
10
|
-
export * from './SliderField';
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import * as Comp from './ErrorBoundary';
|
|
6
|
-
const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
|
|
7
|
-
|
|
8
|
-
export default { title: 'Common/ErrorBoundary', component: Component };
|
|
9
|
-
|
|
10
|
-
export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
|
package/Common/ErrorBoundary.tsx
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { Component, ErrorInfo, ReactNode } from 'react';
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
}
|
|
9
|
-
interface State {
|
|
10
|
-
hasError: boolean;
|
|
11
|
-
error: Error;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class ErrorBoundary extends Component<Props, State> {
|
|
15
|
-
public state: State = {
|
|
16
|
-
hasError: false,
|
|
17
|
-
error: new Error(),
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
public static getDerivedStateFromError(error: Error): State {
|
|
21
|
-
return { hasError: true, error: error };
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
25
|
-
console.error('Uncaught error:', error, errorInfo);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
public render() {
|
|
29
|
-
if (this.state.hasError) {
|
|
30
|
-
return (
|
|
31
|
-
<div className='p-4'>
|
|
32
|
-
<h1 className='text-3xl m-3'>Error</h1>
|
|
33
|
-
<p>{this.state.error.message}</p>
|
|
34
|
-
<p>{this.state.error.stack}</p>
|
|
35
|
-
</div>
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return this.props.children;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import * as Comp from './FormElement';
|
|
6
|
-
const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
|
|
7
|
-
|
|
8
|
-
export default { title: 'Common/FormElement', component: Component };
|
|
9
|
-
|
|
10
|
-
export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
|
package/Common/FormElement.tsx
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
export interface FormElementProps {
|
|
5
|
-
children: React.ReactNode;
|
|
6
|
-
icon: React.ReactNode;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export const FormElement = (props: FormElementProps) => {
|
|
10
|
-
return (
|
|
11
|
-
<div className="card flex flex-column md:flex-row gap-3">
|
|
12
|
-
<div className="p-inputgroup flex-1">
|
|
13
|
-
<span className="p-inputgroup-addon">
|
|
14
|
-
{props.icon}
|
|
15
|
-
</span>
|
|
16
|
-
{props.children}
|
|
17
|
-
</div>
|
|
18
|
-
</div>
|
|
19
|
-
);
|
|
20
|
-
};
|
package/Common/Page.stories.tsx
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import * as Comp from './Page';
|
|
6
|
-
const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
|
|
7
|
-
|
|
8
|
-
export default { title: 'Common/Page', component: Component };
|
|
9
|
-
|
|
10
|
-
export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
|
package/Common/Page.tsx
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import { HTMLAttributes, ReactNode } from 'react';
|
|
5
|
-
|
|
6
|
-
export interface PageProps extends HTMLAttributes<HTMLDivElement> {
|
|
7
|
-
title: string;
|
|
8
|
-
children?: ReactNode;
|
|
9
|
-
panel?: boolean
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export const Page = ({ title, children, panel, ...rest }: PageProps) => {
|
|
13
|
-
return (
|
|
14
|
-
<div className='flex flex-col h-full' {...rest}>
|
|
15
|
-
<h1 className='text-3xl mt-3 mb-4'>{title}</h1>
|
|
16
|
-
<main className={`overflow-hidden h-full flex flex-col flex-1 ${panel ? 'panel' : ''}`}>
|
|
17
|
-
{children}
|
|
18
|
-
</main>
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
};
|
package/Common/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
-
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
-
|
|
4
|
-
import React from 'react';
|
|
5
|
-
import * as Comp from './DataPage';
|
|
6
|
-
const Component: React.ComponentType<any> | undefined = (Comp as any).default || (Object.values(Comp)[0] as any);
|
|
7
|
-
|
|
8
|
-
export default { title: 'DataPage/DataPage', component: Component };
|
|
9
|
-
|
|
10
|
-
export const Default = () => (Component ? <Component /> : <div>Unable to render component</div>);
|