@open-pioneer/feature-editing 1.3.0-dev.20260512095810 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -1
- package/api/editor/context.d.ts +16 -18
- package/api/editor/context.js +3 -3
- package/api/editor/context.js.map +1 -1
- package/api/fields/standardFieldConfigs.d.ts +2 -1
- package/api/model/FeatureTemplate.d.ts +2 -2
- package/i18n/de.yaml +13 -0
- package/i18n/en.yaml +15 -2
- package/implementation/FeatureEditor.js +6 -6
- package/implementation/FeatureEditor.js.map +1 -1
- package/implementation/components/action-selector/SelectButton.js +1 -1
- package/implementation/components/action-selector/SelectButton.js.map +1 -1
- package/implementation/components/controls/NumberFieldControl.js +1 -0
- package/implementation/components/controls/NumberFieldControl.js.map +1 -1
- package/implementation/components/property-editor/CancelConfirmationDialog.d.ts +8 -0
- package/implementation/components/property-editor/CancelConfirmationDialog.js +51 -0
- package/implementation/components/property-editor/CancelConfirmationDialog.js.map +1 -0
- package/implementation/components/property-editor/PropertyEditor.d.ts +10 -5
- package/implementation/components/property-editor/PropertyEditor.js +99 -21
- package/implementation/components/property-editor/PropertyEditor.js.map +1 -1
- package/implementation/components/property-editor/PropertyField.js +30 -4
- package/implementation/components/property-editor/PropertyField.js.map +1 -1
- package/implementation/components/property-editor/PropertyForm.d.ts +4 -7
- package/implementation/components/property-editor/PropertyForm.js +49 -67
- package/implementation/components/property-editor/PropertyForm.js.map +1 -1
- package/implementation/context/PropertyFormContext.d.ts +26 -10
- package/implementation/context/PropertyFormContext.js +96 -21
- package/implementation/context/PropertyFormContext.js.map +1 -1
- package/implementation/context/usePropertyFormContext.d.ts +17 -2
- package/implementation/context/usePropertyFormContext.js +17 -3
- package/implementation/context/usePropertyFormContext.js.map +1 -1
- package/implementation/geometry-editing/controller/EditingController.js +3 -0
- package/implementation/geometry-editing/controller/EditingController.js.map +1 -1
- package/implementation/geometry-editing/interactions/BaseInteraction.js +2 -0
- package/implementation/geometry-editing/interactions/BaseInteraction.js.map +1 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +13 -13
- package/implementation/context/PropertyFormContextProvider.d.ts +0 -9
- package/implementation/context/PropertyFormContextProvider.js +0 -18
- package/implementation/context/PropertyFormContextProvider.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyEditor.js","sources":["PropertyEditor.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"PropertyEditor.js","sources":["PropertyEditor.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Flex, useDisclosure } from \"@chakra-ui/react\";\nimport { useEvent } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { useCallback, useMemo, type ReactElement } from \"react\";\nimport { ButtonRow } from \"./ButtonRow\";\nimport { CancelConfirmationDialog } from \"./CancelConfirmationDialog\";\nimport { DeleteConfirmationDialog } from \"./DeleteConfirmationDialog\";\nimport { FeatureEditorProps, FormTemplateContext } from \"../../../api/editor/editor\";\nimport { CreationStep, UpdateStep } from \"../../../api/model/EditingStep\";\nimport { FeatureTemplate, FormTemplate } from \"../../../api/model/FeatureTemplate\";\nimport {\n DeclarativeFormContext,\n CustomFormContextImpl,\n FormContext\n} from \"../../context/PropertyFormContext\";\nimport { EditingCallbacks } from \"../../editor/useEditingCallbacks\";\nimport { PropertyField } from \"./PropertyField\";\nimport { PropertyForm } from \"./PropertyForm\";\nimport { usePropertyFormContext } from \"../../context/usePropertyFormContext\";\n\nexport function PropertyEditor(props: {\n editingStep: CreationStep | UpdateStep;\n callbacks: EditingCallbacks;\n templates: FeatureTemplate[];\n resolveFormTemplate: FeatureEditorProps[\"resolveFormTemplate\"];\n}) {\n const { editingStep, callbacks, templates, resolveFormTemplate } = props;\n const formTemplate = useFormTemplate(templates, resolveFormTemplate, editingStep);\n\n const context = useMemo(() => {\n if (!formTemplate) {\n return undefined;\n }\n\n if (formTemplate.kind === \"declarative\") {\n return new DeclarativeFormContext(editingStep, callbacks, formTemplate);\n } else {\n return new CustomFormContextImpl(editingStep, callbacks, formTemplate);\n }\n }, [formTemplate, editingStep, callbacks]);\n\n return (\n context &&\n formTemplate && (\n <FormContext value={context}>\n <Flex\n className=\"editor__property-editor\"\n direction=\"column\"\n height=\"full\"\n overflowY={\"hidden\"}\n >\n <PropertyForm>\n {formTemplate.kind === \"dynamic\"\n ? formTemplate.renderForm()\n : formTemplate.fields.map((field, index) => (\n <PropertyField key={index} field={field} />\n ))}\n </PropertyForm>\n <EditorControls></EditorControls>\n </Flex>\n </FormContext>\n )\n );\n}\n\nfunction useFormTemplate(\n templates: FeatureTemplate[],\n customResolver: FeatureEditorProps[\"resolveFormTemplate\"],\n editingStep: CreationStep | UpdateStep\n): FormTemplate | undefined {\n const defaultResolver = useDefaultFormTemplateResolver(templates);\n const resolveFormTemplate = customResolver ?? defaultResolver;\n\n const feature = editingStep.feature;\n const layer = editingStep.id === \"update\" ? editingStep.layer : undefined;\n const explicitTemplate = editingStep.id === \"creation\" ? editingStep.template : undefined;\n\n return useMemo(() => {\n if (explicitTemplate) {\n return explicitTemplate;\n } else if (editingStep.id === \"update\") {\n return resolveFormTemplate({ feature, layer });\n } else {\n return undefined;\n }\n }, [explicitTemplate, editingStep.id, feature, layer, resolveFormTemplate]);\n}\n\nfunction useDefaultFormTemplateResolver(templates: FeatureTemplate[]) {\n return useCallback(\n ({ layer }: FormTemplateContext) => {\n if (layer?.id != null) {\n return templates.find(({ layerId }) => layer.id === layerId);\n } else {\n return undefined;\n }\n },\n [templates]\n );\n}\n\nfunction EditorControls(): ReactElement {\n const context = usePropertyFormContext();\n const canSave = useReactiveSnapshot(() => context.isValid, [context]);\n\n const {\n open: deleteDialogIsOpen,\n onOpen: openDeleteDialog,\n onClose: closeDeleteDialog\n } = useDisclosure();\n const {\n open: cancelDialogIsOpen,\n onOpen: openCancelDialog,\n onClose: closeCancelConfirmationDialog\n } = useDisclosure();\n\n const onSaveClick = useEvent(async () => {\n const properties = context.getPropertiesAsObject();\n context.feature.setProperties(properties);\n await context.callbacks.onSave();\n });\n\n const onDeleteClick = useEvent(async () => {\n await context.callbacks.onDelete();\n closeDeleteDialog();\n });\n\n const onConfirmCancelClick = useEvent(() => {\n context.callbacks.onCancel();\n closeCancelConfirmationDialog();\n });\n\n return (\n <>\n <ButtonRow\n canSave={canSave}\n showDeleteButton={context.mode === \"update\"}\n onSave={onSaveClick}\n onDelete={openDeleteDialog}\n onCancel={openCancelDialog}\n />\n <DeleteConfirmationDialog\n isOpen={deleteDialogIsOpen}\n onDelete={onDeleteClick}\n onCancel={closeDeleteDialog}\n />\n <CancelConfirmationDialog\n isOpen={cancelDialogIsOpen}\n onConfirmCancel={onConfirmCancelClick}\n onAbortCancel={closeCancelConfirmationDialog}\n />\n </>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAsBO,SAAS,eAAe,KAAA,EAK5B;AACC,EAAA,MAAM,EAAE,WAAA,EAAa,SAAA,EAAW,SAAA,EAAW,qBAAoB,GAAI,KAAA;AACnE,EAAA,MAAM,YAAA,GAAe,eAAA,CAAgB,SAAA,EAAW,mBAAA,EAAqB,WAAW,CAAA;AAEhF,EAAA,MAAM,OAAA,GAAU,QAAQ,MAAM;AAC1B,IAAA,IAAI,CAAC,YAAA,EAAc;AACf,MAAA,OAAO,MAAA;AAAA,IACX;AAEA,IAAA,IAAI,YAAA,CAAa,SAAS,aAAA,EAAe;AACrC,MAAA,OAAO,IAAI,sBAAA,CAAuB,WAAA,EAAa,SAAA,EAAW,YAAY,CAAA;AAAA,IAC1E,CAAA,MAAO;AACH,MAAA,OAAO,IAAI,qBAAA,CAAsB,WAAA,EAAa,SAAA,EAAW,YA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gB,SAAS,YAAY;AACvC,IAAA,MAAM,OAAA,CAAQ,UAAU,QAAA,EAAS;AACjC,IAAA,iBAAA,EAAkB;AAAA,EACtB,CAAC,CAAA;AAED,EAAA,MAAM,oBAAA,GAAuB,SAAS,MAAM;AACxC,IAAA,OAAA,CAAQ,UAAU,QAAA,EAAS;AAC3B,IAAA,6BAAA,EAA8B;AAAA,EAClC,CAAC,CAAA;AAED,EAAA,uBACI,IAAA,CAAA,QAAA,EAAA,EACI,QAAA,EAAA;AAAA,oBAAA,GAAA;AAAA,MAAC,SAAA;AAAA,MAAA;AAAA,QACG,OAAA;AAAA,QACA,gBAAA,EAAkB,QAAQ,IAAA,KAAS,QAAA;AAAA,QACnC,MAAA,EAAQ,WAAA;AAAA,QACR,QAAA,EAAU,gBAAA;AAAA,QACV,QAAA,EAAU;AAAA;AAAA,KACd;AAAA,oBACA,GAAA;AAAA,MAAC,wBAAA;AAAA,MAAA;AAAA,QACG,MAAA,EAAQ,kBAAA;AAAA,QACR,QAAA,EAAU,aAAA;AAAA,QACV,QAAA,EAAU;AAAA;AAAA,KACd;AAAA,oBACA,GAAA;AAAA,MAAC,wBAAA;AAAA,MAAA;AAAA,QACG,MAAA,EAAQ,kBAAA;AAAA,QACR,eAAA,EAAiB,oBAAA;AAAA,QACjB,aAAA,EAAe;AAAA;AAAA;AACnB,GAAA,EACJ,CAAA;AAER;;;;"}
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { Field } from '@chakra-ui/react';
|
|
3
3
|
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
4
|
-
import {
|
|
4
|
+
import { useIntl } from '../../../_virtual/hooks.js';
|
|
5
|
+
import { useState, useMemo } from 'react';
|
|
6
|
+
import { useDeclarativeFormContext, usePropertyFormContext } from '../../context/usePropertyFormContext.js';
|
|
5
7
|
import { DefaultControl } from '../controls/DefaultControl.js';
|
|
6
8
|
|
|
7
9
|
function PropertyField({ field }) {
|
|
10
|
+
const context = useDeclarativeFormContext();
|
|
8
11
|
const isRequired = useValue(field.isRequired) ?? false;
|
|
9
12
|
const isEnabled = useValue(field.isEnabled) ?? true;
|
|
10
13
|
const isVisible = useValue(field.isVisible) ?? true;
|
|
11
|
-
const isValid =
|
|
12
|
-
const
|
|
14
|
+
const isValid = useReactiveSnapshot(() => context.isFieldValid(field), [context, field]);
|
|
15
|
+
const defaultErrorText = useDefaultErrorText(field);
|
|
16
|
+
const errorText = useValue(field.errorText) ?? defaultErrorText;
|
|
13
17
|
const helperText = useValue(field.helperText);
|
|
18
|
+
const [hadFocus, setHadFocus] = useState(false);
|
|
14
19
|
if (isVisible) {
|
|
15
20
|
return /* @__PURE__ */ jsxs(
|
|
16
21
|
Field.Root,
|
|
@@ -18,8 +23,11 @@ function PropertyField({ field }) {
|
|
|
18
23
|
className: "editor__property-field",
|
|
19
24
|
required: isRequired,
|
|
20
25
|
disabled: !isEnabled,
|
|
21
|
-
invalid: !isValid,
|
|
26
|
+
invalid: hadFocus && !isValid,
|
|
22
27
|
"data-editor-property-name": field.propertyName,
|
|
28
|
+
onFocus: () => {
|
|
29
|
+
setHadFocus(true);
|
|
30
|
+
},
|
|
23
31
|
children: [
|
|
24
32
|
/* @__PURE__ */ jsxs(Field.Label, { children: [
|
|
25
33
|
field.label,
|
|
@@ -35,6 +43,24 @@ function PropertyField({ field }) {
|
|
|
35
43
|
return void 0;
|
|
36
44
|
}
|
|
37
45
|
}
|
|
46
|
+
function useDefaultErrorText(field) {
|
|
47
|
+
const intl = useIntl();
|
|
48
|
+
return useMemo(() => {
|
|
49
|
+
if (field.type !== "number-field" || field.min == null && field.max == null) {
|
|
50
|
+
return void 0;
|
|
51
|
+
}
|
|
52
|
+
const { min, max } = field;
|
|
53
|
+
let messageId;
|
|
54
|
+
if (min != null && max != null) {
|
|
55
|
+
messageId = "propertyEditor.errors.minAndMax";
|
|
56
|
+
} else if (min != null) {
|
|
57
|
+
messageId = "propertyEditor.errors.minOnly";
|
|
58
|
+
} else {
|
|
59
|
+
messageId = "propertyEditor.errors.maxOnly";
|
|
60
|
+
}
|
|
61
|
+
return intl.formatMessage({ id: messageId }, { min, max });
|
|
62
|
+
}, [intl, field]);
|
|
63
|
+
}
|
|
38
64
|
function useValue(value) {
|
|
39
65
|
const context = usePropertyFormContext();
|
|
40
66
|
return useReactiveSnapshot(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyField.js","sources":["PropertyField.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Field } from \"@chakra-ui/react\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { type ReactElement } from \"react\";\nimport type { PropertyFunction, PropertyFunctionOr } from \"../../../api/fields/BaseFieldConfig\";\nimport type { FieldConfig } from \"../../../api/fields/FieldConfig\";\nimport {
|
|
1
|
+
{"version":3,"file":"PropertyField.js","sources":["PropertyField.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Field } from \"@chakra-ui/react\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { useMemo, useState, type ReactElement } from \"react\";\nimport type { PropertyFunction, PropertyFunctionOr } from \"../../../api/fields/BaseFieldConfig\";\nimport type { FieldConfig } from \"../../../api/fields/FieldConfig\";\nimport {\n useDeclarativeFormContext,\n usePropertyFormContext\n} from \"../../context/usePropertyFormContext\";\nimport { DefaultControl } from \"../controls/DefaultControl\";\n\nexport interface PropertyFieldProps {\n readonly field: FieldConfig;\n}\n\nexport function PropertyField({ field }: PropertyFieldProps): ReactElement | undefined {\n const context = useDeclarativeFormContext();\n const isRequired = useValue(field.isRequired) ?? false;\n const isEnabled = useValue(field.isEnabled) ?? true;\n const isVisible = useValue(field.isVisible) ?? true;\n const isValid = useReactiveSnapshot(() => context.isFieldValid(field), [context, field]);\n\n const defaultErrorText = useDefaultErrorText(field);\n const errorText = useValue(field.errorText) ?? defaultErrorText;\n const helperText = useValue(field.helperText);\n\n const [hadFocus, setHadFocus] = useState(false);\n\n if (isVisible) {\n return (\n <Field.Root\n className=\"editor__property-field\"\n required={isRequired}\n disabled={!isEnabled}\n invalid={hadFocus && !isValid}\n data-editor-property-name={field.propertyName}\n onFocus={() => {\n setHadFocus(true);\n }}\n >\n <Field.Label>\n {field.label}\n <Field.RequiredIndicator />\n </Field.Label>\n <DefaultControl field={field} />\n {helperText && <Field.HelperText>{helperText}</Field.HelperText>}\n {errorText && <Field.ErrorText>{errorText}</Field.ErrorText>}\n </Field.Root>\n );\n } else {\n return undefined;\n }\n}\n\nfunction useDefaultErrorText(field: FieldConfig): string | undefined {\n const intl = useIntl();\n return useMemo(() => {\n if (field.type !== \"number-field\" || (field.min == null && field.max == null)) {\n return undefined;\n }\n\n const { min, max } = field;\n let messageId;\n if (min != null && max != null) {\n messageId = \"propertyEditor.errors.minAndMax\";\n } else if (min != null) {\n messageId = \"propertyEditor.errors.minOnly\";\n } else {\n messageId = \"propertyEditor.errors.maxOnly\";\n }\n return intl.formatMessage({ id: messageId }, { min, max });\n }, [intl, field]);\n}\n\nfunction useValue<T>(value: PropertyFunctionOr<T> | undefined): T | undefined {\n const context = usePropertyFormContext();\n\n return useReactiveSnapshot(() => {\n if (isPropertyFunction(value)) {\n const properties = context.getPropertiesAsObject();\n return value(properties);\n } else {\n return value;\n }\n }, [context, value]);\n}\n\nfunction isPropertyFunction<T>(value: PropertyFunctionOr<T>): value is PropertyFunction<T> {\n return typeof value === \"function\";\n}\n"],"names":[],"mappings":";;;;;;;;AAkBO,SAAS,aAAA,CAAc,EAAE,KAAA,EAAM,EAAiD;AACnF,EAAA,MAAM,UAAU,yBAAA,EAA0B;AAC1C,EAAA,MAAM,UAAA,GAAa,QAAA,CAAS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A,IAC3B,CAAA,MAAO;AACH,MAAA,OAAO,KAAA;AAAA,IACX;AAAA,EACJ,CAAA,EAAG,CAAC,OAAA,EAAS,KAAK,CAAC,CAAA;AACvB;AAEA,SAAS,mBAAsB,KAAA,EAA4D;AACvF,EAAA,OAAO,OAAO,KAAA,KAAU,UAAA;AAC5B;;;;"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { type ReactElement } from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export interface PropertyForm {
|
|
5
|
-
readonly templates: FeatureTemplate[];
|
|
6
|
-
readonly resolveFormTemplate?: (context: FormTemplateContext) => FormTemplate | undefined;
|
|
1
|
+
import { ReactNode, type ReactElement } from "react";
|
|
2
|
+
export interface PropertyFormProps {
|
|
3
|
+
children?: ReactNode;
|
|
7
4
|
}
|
|
8
|
-
export declare function PropertyForm(
|
|
5
|
+
export declare function PropertyForm(props: PropertyFormProps): ReactElement;
|
|
@@ -1,81 +1,63 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { Flex,
|
|
3
|
-
import { effect } from '@conterra/reactivity-core';
|
|
2
|
+
import { Flex, VStack, Text } from '@chakra-ui/react';
|
|
4
3
|
import { TitledSection, SectionHeading } from '@open-pioneer/react-utils';
|
|
5
4
|
import { useIntl } from '../../../_virtual/hooks.js';
|
|
6
|
-
import { useMemo, useEffect, useCallback } from 'react';
|
|
7
5
|
import { usePropertyFormContext } from '../../context/usePropertyFormContext.js';
|
|
8
|
-
import {
|
|
6
|
+
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
9
7
|
|
|
10
|
-
function PropertyForm(
|
|
11
|
-
const
|
|
12
|
-
const heading = useHeading(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
8
|
+
function PropertyForm(props) {
|
|
9
|
+
const { children } = props;
|
|
10
|
+
const heading = useHeading();
|
|
11
|
+
const context = usePropertyFormContext();
|
|
12
|
+
const hasRequiredFields = useReactiveSnapshot(() => context.hasRequiredFields, [context]);
|
|
13
|
+
const { formatRichMessage } = useIntl();
|
|
14
|
+
return /* @__PURE__ */ jsx(TitledSection, { children: /* @__PURE__ */ jsxs(
|
|
15
|
+
Flex,
|
|
16
|
+
{
|
|
17
|
+
className: "editor__property-form",
|
|
18
|
+
direction: "column",
|
|
19
|
+
flex: 1,
|
|
20
|
+
overflowY: "hidden",
|
|
21
|
+
children: [
|
|
22
|
+
/* @__PURE__ */ jsx(SectionHeading, { mb: 2, size: "sm", children: heading }),
|
|
23
|
+
/* @__PURE__ */ jsx(
|
|
24
|
+
VStack,
|
|
25
|
+
{
|
|
26
|
+
gap: 4,
|
|
27
|
+
align: "stretch",
|
|
28
|
+
px: "1px",
|
|
29
|
+
pb: "4px",
|
|
30
|
+
flex: 1,
|
|
31
|
+
overflowY: "auto",
|
|
32
|
+
children
|
|
33
|
+
}
|
|
34
|
+
),
|
|
35
|
+
hasRequiredFields && /* @__PURE__ */ jsxs(
|
|
36
|
+
Text,
|
|
37
|
+
{
|
|
38
|
+
fontSize: "sm",
|
|
39
|
+
"aria-hidden": "true",
|
|
40
|
+
textAlign: "right",
|
|
41
|
+
paddingRight: 2,
|
|
42
|
+
mb: 2,
|
|
43
|
+
children: [
|
|
44
|
+
/* @__PURE__ */ jsx(Text, { as: "span", color: "fg.error", children: "*" }),
|
|
45
|
+
" ",
|
|
46
|
+
formatRichMessage({ id: "propertyEditor.requiredFieldHint" })
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
)
|
|
50
|
+
]
|
|
39
51
|
}
|
|
40
|
-
}
|
|
52
|
+
) });
|
|
41
53
|
}
|
|
42
|
-
function useHeading(
|
|
54
|
+
function useHeading() {
|
|
43
55
|
const intl = useIntl();
|
|
44
|
-
const { mode } = usePropertyFormContext();
|
|
56
|
+
const { mode, formTemplate: template } = usePropertyFormContext();
|
|
45
57
|
const defaultHeading = intl.formatMessage({
|
|
46
58
|
id: mode === "update" ? "propertyEditor.defaultEditHeading" : "propertyEditor.defaultCreateHeading"
|
|
47
59
|
});
|
|
48
|
-
return template?.name
|
|
49
|
-
}
|
|
50
|
-
function useDefaultFormTemplateResolver(templates) {
|
|
51
|
-
return useCallback(
|
|
52
|
-
({ layer }) => {
|
|
53
|
-
if (layer?.id != null) {
|
|
54
|
-
return templates.find(({ layerId }) => layer.id === layerId);
|
|
55
|
-
} else {
|
|
56
|
-
return void 0;
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
[templates]
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
function useUpdateValidity(template) {
|
|
63
|
-
const context = usePropertyFormContext();
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
const handle = effect(() => {
|
|
66
|
-
if (template?.kind === "declarative") {
|
|
67
|
-
const properties = context.getPropertiesAsObject();
|
|
68
|
-
context.isValid = template.fields.every((field) => isValid(field, properties));
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
return () => handle.destroy();
|
|
72
|
-
}, [context, template]);
|
|
73
|
-
}
|
|
74
|
-
function isValid(field, properties) {
|
|
75
|
-
return (!isTrue(field.isRequired, properties) || properties[field.propertyName] != null) && isTrue(field.isValid, properties, true);
|
|
76
|
-
}
|
|
77
|
-
function isTrue(value, properties, defaultValue = false) {
|
|
78
|
-
return typeof value === "function" ? value(properties) : value ?? defaultValue;
|
|
60
|
+
return template?.name ? `${defaultHeading}: ${template?.name} ` : defaultHeading;
|
|
79
61
|
}
|
|
80
62
|
|
|
81
63
|
export { PropertyForm };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyForm.js","sources":["PropertyForm.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"PropertyForm.js","sources":["PropertyForm.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Flex, VStack, Text } from \"@chakra-ui/react\";\nimport { SectionHeading, TitledSection } from \"@open-pioneer/react-utils\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { ReactNode, type ReactElement } from \"react\";\nimport { usePropertyFormContext } from \"../../context/usePropertyFormContext\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\n\nexport interface PropertyFormProps {\n children?: ReactNode;\n}\n\nexport function PropertyForm(props: PropertyFormProps): ReactElement {\n const { children } = props;\n const heading = useHeading();\n const context = usePropertyFormContext();\n const hasRequiredFields = useReactiveSnapshot(() => context.hasRequiredFields, [context]);\n const { formatRichMessage } = useIntl();\n\n return (\n <TitledSection>\n <Flex\n className=\"editor__property-form\"\n direction={\"column\"}\n flex={1}\n overflowY=\"hidden\"\n >\n <SectionHeading mb={2} size=\"sm\">\n {heading}\n </SectionHeading>\n <VStack\n gap={4}\n align=\"stretch\"\n // for focus ring\n px=\"1px\"\n pb=\"4px\"\n flex={1}\n overflowY={\"auto\"}\n >\n {children}\n </VStack>\n {hasRequiredFields && (\n <Text\n fontSize={\"sm\"}\n aria-hidden=\"true\"\n textAlign={\"right\"}\n paddingRight={2}\n mb={2}\n >\n <Text as=\"span\" color=\"fg.error\">\n *\n </Text>{\" \"}\n {formatRichMessage({ id: \"propertyEditor.requiredFieldHint\" })}\n </Text>\n )}\n </Flex>\n </TitledSection>\n );\n}\n\nfunction useHeading() {\n const intl = useIntl();\n const { mode, formTemplate: template } = usePropertyFormContext();\n const defaultHeading = intl.formatMessage({\n id:\n mode === \"update\"\n ? \"propertyEditor.defaultEditHeading\"\n : \"propertyEditor.defaultCreateHeading\"\n });\n return template?.name ? `${defaultHeading}: ${template?.name} ` : defaultHeading;\n}\n"],"names":[],"mappings":";;;;;;;AAaO,SAAS,aAAa,KAAA,EAAwC;AACjE,EAAA,MAAM,EAAE,UAAS,GAAI,KAAA;AACrB,EAAA,MAAM,UAAU,UAAA,EAAW;AAC3B,EAAA,MAAM,UAAU,sBAAA,EAAuB;AACvC,EAAA,MAAM,oBAAoB,mBAAA,CAAoB,MAAM,QAAQ,iBAAA,EAAmB,CAAC,OAAO,CAAC,CAAA;AACxF,EAAA,MAAM,EAAE,iBAAA,EAAkB,GAAI,OAAA,EAAQ;AAEtC,EAAA,2BACK,aAAA,EAAA,EACG,QAAA,kBAAA,IAAA;AAAA,IAAC,IAAA;AAAA,IAAA;AAAA,MACG,SAAA,EAAU,uBAAA;AAAA,MACV,SAAA,EAAW,QAAA;AAAA,MACX,IAAA,EAAM,CAAA;AAAA,MACN,SAAA,EAAU,QAAA;AAAA,MAEV,QAAA,EAAA;AAAA,wBAAA,GAAA,CAAC,cAAA,EAAA,EAAe,EAAA,EAAI,CAAA,EAAG,IAAA,EAAK,MACvB,QAAA,EAAA,OAAA,EACL,CAAA;AAAA,wBACA,GAAA;AAAA,UAAC,MAAA;AAAA,UAAA;AAAA,YACG,GAAA,EAAK,CAAA;AAAA,YACL,KAAA,EAAM,SAAA;AAAA,YAEN,EAAA,EAAG,KAAA;AAAA,YACH,EAAA,EAAG,KAAA;AAAA,YACH,IAAA,EAAM,CAAA;AAAA,YACN,SAAA,EAAW,MAAA;AAAA,YAEV;AAAA;AAAA,SACL;AAAA,QACC,iBAAA,oBACG,IAAA;AAAA,UAAC,IAAA;AAAA,UAAA;AAAA,YACG,QAAA,EAAU,IAAA;AAAA,YACV,aAAA,EAAY,MAAA;AAAA,YACZ,SAAA,EAAW,OAAA;AAAA,YACX,YAAA,EAAc,CAAA;AAAA,YACd,EAAA,EAAI,CAAA;AAAA,YAEJ,QAAA,EAAA;AAAA,8BAAA,GAAA,CAAC,IAAA,EAAA,EAAK,EAAA,EAAG,MAAA,EAAO,KAAA,EAAM,YAAW,QAAA,EAAA,GAAA,EAEjC,CAAA;AAAA,cAAQ,GAAA;AAAA,cACP,iBAAA,CAAkB,EAAE,EAAA,EAAI,kCAAA,EAAoC;AAAA;AAAA;AAAA;AACjE;AAAA;AAAA,GAER,EACJ,CAAA;AAER;AAEA,SAAS,UAAA,GAAa;AAClB,EAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,MAAM,EAAE,IAAA,EAAM,YAAA,EAAc,QAAA,KAAa,sBAAA,EAAuB;AAChE,EAAA,MAAM,cAAA,GAAiB,KAAK,aAAA,CAAc;AAAA,IACtC,EAAA,EACI,IAAA,KAAS,QAAA,GACH,mCAAA,GACA;AAAA,GACb,CAAA;AACD,EAAA,OAAO,UAAU,IAAA,GAAO,CAAA,EAAG,cAAc,CAAA,EAAA,EAAK,QAAA,EAAU,IAAI,CAAA,CAAA,CAAA,GAAM,cAAA;AACtE;;;;"}
|
|
@@ -1,25 +1,41 @@
|
|
|
1
1
|
import { type ReactiveMap } from "@conterra/reactivity-core";
|
|
2
2
|
import type { Layer } from "@open-pioneer/map";
|
|
3
3
|
import type { Feature } from "ol";
|
|
4
|
-
import type {
|
|
4
|
+
import type { CustomFormContext, Mode } from "../../api/editor/context";
|
|
5
|
+
import { FieldConfig } from "../../api/fields/FieldConfig";
|
|
5
6
|
import type { ModificationStep } from "../../api/model/EditingStep";
|
|
6
|
-
import type { FeatureTemplate } from "../../api/model/FeatureTemplate";
|
|
7
|
+
import type { DeclarativeFormTemplate, FeatureTemplate, FormTemplate } from "../../api/model/FeatureTemplate";
|
|
7
8
|
import { EditingCallbacks } from "../editor/useEditingCallbacks";
|
|
8
|
-
export declare class
|
|
9
|
-
private
|
|
9
|
+
export declare abstract class BaseFormContext {
|
|
10
|
+
#private;
|
|
10
11
|
readonly callbacks: EditingCallbacks;
|
|
11
|
-
|
|
12
|
-
private readonly isValidSignal;
|
|
13
|
-
constructor(modificationStep: ModificationStep, callbacks: EditingCallbacks);
|
|
12
|
+
constructor(modificationStep: ModificationStep, callbacks: EditingCallbacks, formTemplate: FormTemplate);
|
|
14
13
|
getPropertiesAsObject(): Record<string, unknown>;
|
|
15
14
|
get feature(): Feature;
|
|
16
15
|
get mode(): Mode;
|
|
17
16
|
get editingStep(): ModificationStep;
|
|
18
17
|
get properties(): ReactiveMap<string, unknown>;
|
|
19
|
-
get
|
|
20
|
-
set isValid(value: boolean);
|
|
18
|
+
get formTemplate(): FormTemplate;
|
|
21
19
|
get template(): FeatureTemplate | undefined;
|
|
22
20
|
get layer(): Layer | undefined;
|
|
21
|
+
abstract get isValid(): boolean;
|
|
22
|
+
abstract get hasRequiredFields(): boolean;
|
|
23
23
|
private static getPropertyEntries;
|
|
24
24
|
}
|
|
25
|
-
export declare
|
|
25
|
+
export declare class DeclarativeFormContext extends BaseFormContext {
|
|
26
|
+
#private;
|
|
27
|
+
constructor(modificationStep: ModificationStep, callbacks: EditingCallbacks, template: DeclarativeFormTemplate);
|
|
28
|
+
isFieldValid(field: FieldConfig): boolean;
|
|
29
|
+
get isValid(): boolean;
|
|
30
|
+
get formTemplate(): DeclarativeFormTemplate;
|
|
31
|
+
get hasRequiredFields(): boolean;
|
|
32
|
+
}
|
|
33
|
+
export declare class CustomFormContextImpl extends BaseFormContext implements CustomFormContext {
|
|
34
|
+
#private;
|
|
35
|
+
constructor(modificationStep: ModificationStep, callbacks: EditingCallbacks, template: FormTemplate);
|
|
36
|
+
get isValid(): boolean;
|
|
37
|
+
set isValid(isValid: boolean);
|
|
38
|
+
get hasRequiredFields(): boolean;
|
|
39
|
+
}
|
|
40
|
+
export type AnyPropertyFormContext = DeclarativeFormContext | CustomFormContextImpl;
|
|
41
|
+
export declare const FormContext: import("react").Context<AnyPropertyFormContext | undefined>;
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
import { reactiveMap,
|
|
1
|
+
import { reactive, reactiveMap, computed } from '@conterra/reactivity-core';
|
|
2
2
|
import { createContext } from 'react';
|
|
3
3
|
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
class BaseFormContext {
|
|
5
|
+
#propertiesMap;
|
|
6
|
+
#modificationStep;
|
|
7
|
+
#formTemplate;
|
|
8
|
+
#propsAsObject;
|
|
9
|
+
callbacks;
|
|
10
|
+
constructor(modificationStep, callbacks, formTemplate) {
|
|
11
|
+
this.#modificationStep = modificationStep;
|
|
7
12
|
this.callbacks = callbacks;
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
this.#formTemplate = formTemplate;
|
|
14
|
+
const entries = BaseFormContext.getPropertyEntries(modificationStep.feature);
|
|
15
|
+
this.#propertiesMap = reactiveMap(entries);
|
|
16
|
+
this.#propsAsObject = computed(() => {
|
|
17
|
+
const entries2 = this.properties.entries();
|
|
18
|
+
const object = Object.fromEntries(entries2);
|
|
19
|
+
return object;
|
|
20
|
+
});
|
|
10
21
|
}
|
|
11
|
-
propertiesMap;
|
|
12
|
-
isValidSignal = reactive(false);
|
|
13
22
|
getPropertiesAsObject() {
|
|
14
|
-
|
|
15
|
-
return Object.fromEntries(entries);
|
|
23
|
+
return this.#propsAsObject.value;
|
|
16
24
|
}
|
|
17
25
|
get feature() {
|
|
18
26
|
return this.editingStep.feature;
|
|
@@ -21,16 +29,13 @@ class PropertyFormContextClass {
|
|
|
21
29
|
return this.editingStep.id === "creation" ? "create" : "update";
|
|
22
30
|
}
|
|
23
31
|
get editingStep() {
|
|
24
|
-
return this
|
|
32
|
+
return this.#modificationStep;
|
|
25
33
|
}
|
|
26
34
|
get properties() {
|
|
27
|
-
return this
|
|
35
|
+
return this.#propertiesMap;
|
|
28
36
|
}
|
|
29
|
-
get
|
|
30
|
-
return this
|
|
31
|
-
}
|
|
32
|
-
set isValid(value) {
|
|
33
|
-
this.isValidSignal.value = value;
|
|
37
|
+
get formTemplate() {
|
|
38
|
+
return this.#formTemplate;
|
|
34
39
|
}
|
|
35
40
|
get template() {
|
|
36
41
|
return this.editingStep.id === "creation" ? this.editingStep.template : void 0;
|
|
@@ -44,9 +49,79 @@ class PropertyFormContextClass {
|
|
|
44
49
|
return Object.entries(properties).filter(([key, _]) => key !== geometryName);
|
|
45
50
|
}
|
|
46
51
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
class DeclarativeFormContext extends BaseFormContext {
|
|
53
|
+
#isValid;
|
|
54
|
+
#hasRequiredFields;
|
|
55
|
+
constructor(modificationStep, callbacks, template) {
|
|
56
|
+
super(modificationStep, callbacks, template);
|
|
57
|
+
this.#isValid = computed(() => {
|
|
58
|
+
const props = this.getPropertiesAsObject();
|
|
59
|
+
return this.formTemplate.fields.every((field) => this.#isFieldValidImpl(field, props));
|
|
60
|
+
});
|
|
61
|
+
this.#hasRequiredFields = computed(() => {
|
|
62
|
+
const props = this.getPropertiesAsObject();
|
|
63
|
+
return this.formTemplate.fields.some((field) => isTrue(field.isRequired, props, false));
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
isFieldValid(field) {
|
|
67
|
+
const props = this.getPropertiesAsObject();
|
|
68
|
+
return this.#isFieldValidImpl(field, props);
|
|
69
|
+
}
|
|
70
|
+
#isFieldValidImpl(field, props) {
|
|
71
|
+
const isRequired = isTrue(field.isRequired, props, false);
|
|
72
|
+
const isPresent = props[field.propertyName] != null;
|
|
73
|
+
if (!isRequired && !isPresent) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
if (isRequired && !isPresent) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (!isTrue(field.isValid, props, true)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
if (field.type === "number-field") {
|
|
83
|
+
const value = props[field.propertyName];
|
|
84
|
+
if (field.min != null && (!isPresent || value < field.min)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (field.max != null && (!isPresent || value > field.max)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
get isValid() {
|
|
94
|
+
return this.#isValid.value;
|
|
95
|
+
}
|
|
96
|
+
get formTemplate() {
|
|
97
|
+
return super.formTemplate;
|
|
98
|
+
}
|
|
99
|
+
get hasRequiredFields() {
|
|
100
|
+
return this.#hasRequiredFields.value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
class CustomFormContextImpl extends BaseFormContext {
|
|
104
|
+
#isValid = reactive(false);
|
|
105
|
+
constructor(modificationStep, callbacks, template) {
|
|
106
|
+
super(modificationStep, callbacks, template);
|
|
107
|
+
}
|
|
108
|
+
get isValid() {
|
|
109
|
+
return this.#isValid.value;
|
|
110
|
+
}
|
|
111
|
+
set isValid(isValid) {
|
|
112
|
+
this.#isValid.value = isValid;
|
|
113
|
+
}
|
|
114
|
+
get hasRequiredFields() {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const FormContext = createContext(void 0);
|
|
119
|
+
function isTrue(value, properties, defaultValue) {
|
|
120
|
+
if (value == null) {
|
|
121
|
+
return defaultValue;
|
|
122
|
+
}
|
|
123
|
+
return typeof value === "function" ? value(properties) : value;
|
|
124
|
+
}
|
|
50
125
|
|
|
51
|
-
export {
|
|
126
|
+
export { CustomFormContextImpl, DeclarativeFormContext, FormContext };
|
|
52
127
|
//# sourceMappingURL=PropertyFormContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PropertyFormContext.js","sources":["PropertyFormContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { reactive, reactiveMap, type ReactiveMap } from \"@conterra/reactivity-core\";\nimport type { Layer } from \"@open-pioneer/map\";\n\nimport type { Feature } from \"ol\";\nimport { createContext } from \"react\";\n\nimport type { Mode, PropertyFormContext } from \"../../api/editor/context\";\nimport type { ModificationStep } from \"../../api/model/EditingStep\";\nimport type { FeatureTemplate } from \"../../api/model/FeatureTemplate\";\nimport { EditingCallbacks } from \"../editor/useEditingCallbacks\";\n\nexport class PropertyFormContextClass implements PropertyFormContext {\n private readonly propertiesMap: ReactiveMap<string, unknown>;\n private readonly isValidSignal = reactive(false);\n\n constructor(\n private readonly modificationStep: ModificationStep,\n readonly callbacks: EditingCallbacks\n ) {\n const entries = PropertyFormContextClass.getPropertyEntries(modificationStep.feature);\n this.propertiesMap = reactiveMap(entries);\n }\n\n getPropertiesAsObject(): Record<string, unknown> {\n const entries = this.properties.entries();\n return Object.fromEntries(entries);\n }\n\n get feature(): Feature {\n return this.editingStep.feature;\n }\n\n get mode(): Mode {\n return this.editingStep.id === \"creation\" ? \"create\" : \"update\";\n }\n\n get editingStep(): ModificationStep {\n return this.modificationStep;\n }\n\n get properties(): ReactiveMap<string, unknown> {\n return this.propertiesMap;\n }\n\n get isValid(): boolean {\n return this.isValidSignal.value;\n }\n\n set isValid(value: boolean) {\n this.isValidSignal.value = value;\n }\n\n get template(): FeatureTemplate | undefined {\n return this.editingStep.id === \"creation\" ? this.editingStep.template : undefined;\n }\n\n get layer(): Layer | undefined {\n return this.editingStep.id === \"update\" ? this.editingStep.layer : undefined;\n }\n\n private static getPropertyEntries(feature: Feature): [string, unknown][] {\n const properties = feature.getProperties();\n const geometryName = feature.getGeometryName();\n return Object.entries(properties).filter(([key, _]) => key !== geometryName);\n }\n}\n\nexport const PropertyFormContextObject = createContext<PropertyFormContextClass | undefined>(\n undefined\n);\n"],"names":[],"mappings":";;;AAaO,MAAM,wBAAA,CAAwD;AAAA,EAIjE,WAAA,CACqB,kBACR,SAAA,EACX;AAFmB,IAAA,IAAA,CAAA,gBAAA,GAAA,gBAAA;AACR,IAAA,IAAA,CAAA,SAAA,GAAA,SAAA;AAET,IAAA,MAAM,OAAA,GA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E,IAAA,MAAM,UAAA,GAAa,QAAQ,aAAA,EAAc;AACzC,IAAA,MAAM,YAAA,GAAe,QAAQ,eAAA,EAAgB;AAC7C,IAAA,OAAO,MAAA,CAAO,OAAA,CAAQ,UAAU,CAAA,CAAE,MAAA,CAAO,CAAC,CAAC,GAAA,EAAK,CAAC,CAAA,KAAM,GAAA,KAAQ,YAAY,CAAA;AAAA,EAC/E;AACJ;AAEO,MAAM,yBAAA,GAA4B,aAAA;AAAA,EACrC;AACJ;;;;"}
|
|
1
|
+
{"version":3,"file":"PropertyFormContext.js","sources":["PropertyFormContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n computed,\n reactive,\n reactiveMap,\n ReadonlyReactive,\n type ReactiveMap\n} from \"@conterra/reactivity-core\";\nimport type { Layer } from \"@open-pioneer/map\";\nimport type { Feature } from \"ol\";\nimport { createContext } from \"react\";\nimport type { CustomFormContext, Mode } from \"../../api/editor/context\";\nimport { PropertyFunctionOr } from \"../../api/fields/BaseFieldConfig\";\nimport { FieldConfig } from \"../../api/fields/FieldConfig\";\nimport type { ModificationStep } from \"../../api/model/EditingStep\";\nimport type {\n DeclarativeFormTemplate,\n FeatureTemplate,\n FormTemplate\n} from \"../../api/model/FeatureTemplate\";\nimport { EditingCallbacks } from \"../editor/useEditingCallbacks\";\n\nexport abstract class BaseFormContext {\n readonly #propertiesMap: ReactiveMap<string, unknown>;\n readonly #modificationStep: ModificationStep;\n readonly #formTemplate: FormTemplate;\n readonly #propsAsObject: ReadonlyReactive<Record<string, unknown>>;\n\n readonly callbacks: EditingCallbacks;\n\n constructor(\n modificationStep: ModificationStep,\n callbacks: EditingCallbacks,\n formTemplate: FormTemplate\n ) {\n this.#modificationStep = modificationStep;\n this.callbacks = callbacks;\n this.#formTemplate = formTemplate;\n\n const entries = BaseFormContext.getPropertyEntries(modificationStep.feature);\n this.#propertiesMap = reactiveMap(entries);\n this.#propsAsObject = computed(() => {\n const entries = this.properties.entries();\n const object = Object.fromEntries(entries);\n return object;\n });\n }\n\n getPropertiesAsObject(): Record<string, unknown> {\n return this.#propsAsObject.value;\n }\n\n get feature(): Feature {\n return this.editingStep.feature;\n }\n\n get mode(): Mode {\n return this.editingStep.id === \"creation\" ? \"create\" : \"update\";\n }\n\n get editingStep(): ModificationStep {\n return this.#modificationStep;\n }\n\n get properties(): ReactiveMap<string, unknown> {\n return this.#propertiesMap;\n }\n\n get formTemplate(): FormTemplate {\n return this.#formTemplate;\n }\n\n get template(): FeatureTemplate | undefined {\n return this.editingStep.id === \"creation\" ? this.editingStep.template : undefined;\n }\n\n get layer(): Layer | undefined {\n return this.editingStep.id === \"update\" ? this.editingStep.layer : undefined;\n }\n\n abstract get isValid(): boolean;\n abstract get hasRequiredFields(): boolean;\n\n private static getPropertyEntries(feature: Feature): [string, unknown][] {\n const properties = feature.getProperties();\n const geometryName = feature.getGeometryName();\n return Object.entries(properties).filter(([key, _]) => key !== geometryName);\n }\n}\n\nexport class DeclarativeFormContext extends BaseFormContext {\n readonly #isValid: ReadonlyReactive<boolean>;\n readonly #hasRequiredFields: ReadonlyReactive<boolean>;\n\n constructor(\n modificationStep: ModificationStep,\n callbacks: EditingCallbacks,\n template: DeclarativeFormTemplate\n ) {\n super(modificationStep, callbacks, template);\n\n this.#isValid = computed(() => {\n const props = this.getPropertiesAsObject();\n return this.formTemplate.fields.every((field) => this.#isFieldValidImpl(field, props));\n });\n this.#hasRequiredFields = computed(() => {\n const props = this.getPropertiesAsObject();\n return this.formTemplate.fields.some((field) => isTrue(field.isRequired, props, false));\n });\n }\n\n isFieldValid(field: FieldConfig) {\n const props = this.getPropertiesAsObject();\n return this.#isFieldValidImpl(field, props);\n }\n\n #isFieldValidImpl(field: FieldConfig, props: Record<string, unknown>) {\n const isRequired = isTrue(field.isRequired, props, false);\n const isPresent = props[field.propertyName] != null;\n if (!isRequired && !isPresent) {\n return true;\n }\n\n if (isRequired && !isPresent) {\n return false;\n }\n\n // Perform user-defined validation first.\n if (!isTrue(field.isValid, props, true)) {\n return false;\n }\n\n // Fallback/default validation for builtin rules.\n if (field.type === \"number-field\") {\n const value = props[field.propertyName] as number | undefined;\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (field.min != null && (!isPresent || value! < field.min)) {\n return false;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (field.max != null && (!isPresent || value! > field.max)) {\n return false;\n }\n }\n\n return true;\n }\n\n get isValid(): boolean {\n return this.#isValid.value;\n }\n\n override get formTemplate(): DeclarativeFormTemplate {\n // See constructor\n return super.formTemplate as DeclarativeFormTemplate;\n }\n\n get hasRequiredFields(): boolean {\n return this.#hasRequiredFields.value;\n }\n}\n\nexport class CustomFormContextImpl extends BaseFormContext implements CustomFormContext {\n readonly #isValid = reactive(false);\n\n constructor(\n modificationStep: ModificationStep,\n callbacks: EditingCallbacks,\n template: FormTemplate\n ) {\n super(modificationStep, callbacks, template);\n }\n\n get isValid(): boolean {\n return this.#isValid.value;\n }\n\n set isValid(isValid: boolean) {\n this.#isValid.value = isValid;\n }\n\n get hasRequiredFields(): boolean {\n return false;\n }\n}\n\nexport type AnyPropertyFormContext = DeclarativeFormContext | CustomFormContextImpl;\n\nexport const FormContext = createContext<AnyPropertyFormContext | undefined>(undefined);\n\nfunction isTrue(\n value: PropertyFunctionOr<boolean> | undefined,\n properties: Record<string, unknown>,\n defaultValue: boolean\n): boolean {\n if (value == null) {\n return defaultValue;\n }\n return typeof value === \"function\" ? value(properties) : value;\n}\n"],"names":["entries"],"mappings":";;;AAuBO,MAAe,eAAA,CAAgB;AAAA,EACzB,cAAA;AAAA,EACA,iBAAA;AAAA,EACA,aAAA;AAAA,EACA,cAAA;AAAA,EAEA,SAAA;AAAA,EAET,WAAA,CACI,gBAAA,EACA,SAAA,EACA,YAAA,EACF;AACE,IAAA,IAAA,CAAK,iBAAA,GAAoB,gBAAA;AACzB,IAAA,IAAA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,8BAA8B,eAAA,CAA6C;AAAA,EAC3E,QAAA,GAAW,SAAS,KAAK,CAAA;AAAA,EAElC,WAAA,CACI,gBAAA,EACA,SAAA,EACA,QAAA,EACF;AACE,IAAA,KAAA,CAAM,gBAAA,EAAkB,WAAW,QAAQ,CAAA;AAAA,EAC/C;AAAA,EAEA,IAAI,OAAA,GAAmB;AACnB,IAAA,OAAO,KAAK,QAAA,CAAS,KAAA;AAAA,EACzB;AAAA,EAEA,IAAI,QAAQ,OAAA,EAAkB;AAC1B,IAAA,IAAA,CAAK,SAAS,KAAA,GAAQ,OAAA;AAAA,EAC1B;AAAA,EAEA,IAAI,iBAAA,GAA6B;AAC7B,IAAA,OAAO,KAAA;AAAA,EACX;AACJ;AAIO,MAAM,WAAA,GAAc,cAAkD,MAAS;AAEtF,SAAS,MAAA,CACL,KAAA,EACA,UAAA,EACA,YAAA,EACO;AACP,EAAA,IAAI,SAAS,IAAA,EAAM;AACf,IAAA,OAAO,YAAA;AAAA,EACX;AACA,EAAA,OAAO,OAAO,KAAA,KAAU,UAAA,GAAa,KAAA,CAAM,UAAU,CAAA,GAAI,KAAA;AAC7D;;;;"}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
|
|
1
|
+
import { CustomFormContextImpl, DeclarativeFormContext, type AnyPropertyFormContext } from "./PropertyFormContext";
|
|
2
|
+
/**
|
|
3
|
+
* Used by the property editor, internally.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function usePropertyFormContext(): AnyPropertyFormContext;
|
|
8
|
+
/**
|
|
9
|
+
* Used by the property editor, internally.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export declare function useDeclarativeFormContext(): DeclarativeFormContext;
|
|
14
|
+
/**
|
|
15
|
+
* Used for custom form contents.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useCustomFormContext(): CustomFormContextImpl;
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { CustomFormContextImpl, FormContext, DeclarativeFormContext } from './PropertyFormContext.js';
|
|
3
3
|
|
|
4
4
|
function usePropertyFormContext() {
|
|
5
|
-
const context = useContext(
|
|
5
|
+
const context = useContext(FormContext);
|
|
6
6
|
if (context != null) {
|
|
7
7
|
return context;
|
|
8
8
|
} else {
|
|
9
9
|
throw new Error("No property form context available");
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
|
+
function useDeclarativeFormContext() {
|
|
13
|
+
const value = usePropertyFormContext();
|
|
14
|
+
if (!(value instanceof DeclarativeFormContext)) {
|
|
15
|
+
throw new Error("No declarative form context available");
|
|
16
|
+
}
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
function useCustomFormContext() {
|
|
20
|
+
const value = usePropertyFormContext();
|
|
21
|
+
if (!(value instanceof CustomFormContextImpl)) {
|
|
22
|
+
throw new Error("No custom form context available");
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
12
26
|
|
|
13
|
-
export { usePropertyFormContext };
|
|
27
|
+
export { useCustomFormContext, useDeclarativeFormContext, usePropertyFormContext };
|
|
14
28
|
//# sourceMappingURL=usePropertyFormContext.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePropertyFormContext.js","sources":["usePropertyFormContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useContext } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"file":"usePropertyFormContext.js","sources":["usePropertyFormContext.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { useContext } from \"react\";\nimport {\n CustomFormContextImpl,\n DeclarativeFormContext,\n FormContext,\n type AnyPropertyFormContext\n} from \"./PropertyFormContext\";\n\n/**\n * Used by the property editor, internally.\n *\n * @internal\n */\nexport function usePropertyFormContext(): AnyPropertyFormContext {\n const context = useContext(FormContext);\n if (context != null) {\n return context;\n } else {\n throw new Error(\"No property form context available\");\n }\n}\n\n/**\n * Used by the property editor, internally.\n *\n * @internal\n */\nexport function useDeclarativeFormContext(): DeclarativeFormContext {\n const value = usePropertyFormContext();\n if (!(value instanceof DeclarativeFormContext)) {\n throw new Error(\"No declarative form context available\");\n }\n return value;\n}\n\n/**\n * Used for custom form contents.\n */\nexport function useCustomFormContext(): CustomFormContextImpl {\n const value = usePropertyFormContext();\n if (!(value instanceof CustomFormContextImpl)) {\n throw new Error(\"No custom form context available\");\n }\n return value;\n}\n"],"names":[],"mappings":";;;AAeO,SAAS,sBAAA,GAAiD;AAC7D,EAAA,MAAM,OAAA,GAAU,WAAW,WAAW,CAAA;AACtC,EAAA,IAAI,WAAW,IAAA,EAAM;AACjB,IAAA,OAAO,OAAA;AAAA,EACX,CAAA,MAAO;AACH,IAAA,MAAM,IAAI,MAAM,oCAAoC,CAAA;AAAA,EACxD;AACJ;AAOO,SAAS,yBAAA,GAAoD;AAChE,EAAA,MAAM,QAAQ,sBAAA,EAAuB;AACrC,EAAA,IAAI,EAAE,iBAAiB,sBAAA,CAAA,EAAyB;AAC5C,IAAA,MAAM,IAAI,MAAM,uCAAuC,CAAA;AAAA,EAC3D;AACA,EAAA,OAAO,KAAA;AACX;AAKO,SAAS,oBAAA,GAA8C;AAC1D,EAAA,MAAM,QAAQ,sBAAA,EAAuB;AACrC,EAAA,IAAI,EAAE,iBAAiB,qBAAA,CAAA,EAAwB;AAC3C,IAAA,MAAM,IAAI,MAAM,kCAAkC,CAAA;AAAA,EACtD;AACA,EAAA,OAAO,KAAA;AACX;;;;"}
|