@open-pioneer/selection 0.7.0 → 0.8.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 CHANGED
@@ -1,5 +1,56 @@
1
1
  # @open-pioneer/selection
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - e7978a8: Support reactive changes on the `SelectionSource`'s `status` property using the reactivity API.
8
+ **Remove** support for the `changed:status"` event on the selection source: use signals instead.
9
+
10
+ For example, to implement a `SelectionSource` with changing availability:
11
+
12
+ ```ts
13
+ class MySelectionSource implements SelectionSource {
14
+ private _status = reactive("available");
15
+
16
+ label = "My selection source";
17
+
18
+ get status() {
19
+ return this._status.value;
20
+ }
21
+
22
+ someEventHandler() {
23
+ // Change the status by updating the signal's value.
24
+ // The UI will update automatically.
25
+ this._status.value = "unavailable";
26
+ }
27
+ }
28
+ ```
29
+
30
+ - b717121: Update from OL 9 to OL 10.
31
+ - b717121: Adjust the type the property `vectorLayer` of the exported interface `VectorLayerSelectionSourceOptions`.
32
+ The type is now `VectorLayer<VectorSource, Feature>` instead of `VectorLayer<Feature>`.
33
+ - 2fa8020: Update trails core package dependencies.
34
+
35
+ - Also updates Chakra UI to the latest 2.x version and Chakra React Select to version 5.
36
+ - Removes any obsolete references to `@chakra-ui/system`.
37
+ This dependency seems to be no longer required and may lead to duplicate packages in your dependency tree.
38
+
39
+ ### Patch Changes
40
+
41
+ - 49f0207: Update trails core packages to version 2.4.0
42
+ - Updated dependencies [b717121]
43
+ - Updated dependencies [e7978a8]
44
+ - Updated dependencies [7a5f1e1]
45
+ - Updated dependencies [7ae9f90]
46
+ - Updated dependencies [d8337a6]
47
+ - Updated dependencies [49f0207]
48
+ - Updated dependencies [b2127df]
49
+ - Updated dependencies [2fa8020]
50
+ - Updated dependencies [7ae9f90]
51
+ - Updated dependencies [d8337a6]
52
+ - @open-pioneer/map@0.8.0
53
+
3
54
  ## 0.7.0
4
55
 
5
56
  ### Minor Changes
package/Selection.js CHANGED
@@ -6,6 +6,7 @@ import { Select, chakraComponents } from 'chakra-react-select';
6
6
  import { useIntl, useService } from './_virtual/_virtual-pioneer-module_react-hooks.js';
7
7
  import { useState, useMemo, useEffect, useRef } from 'react';
8
8
  import { FiAlertTriangle } from 'react-icons/fi';
9
+ import { useReactiveSnapshot } from '@open-pioneer/reactivity';
9
10
  import { DragController } from './DragController.js';
10
11
  import { SelectionController } from './SelectionController.js';
11
12
 
@@ -210,22 +211,13 @@ function getSourceStatus(source, sourceNotAvailableReason) {
210
211
  };
211
212
  }
212
213
  function useSourceStatus(source, defaultNotAvailableMessage) {
213
- const [status, setStatus] = useState(() => ({
214
- kind: "unavailable",
215
- reason: defaultNotAvailableMessage
216
- }));
217
- useEffect(() => {
214
+ const sourceStatus = useReactiveSnapshot(() => {
218
215
  if (!source) {
219
- setStatus({ kind: "unavailable", reason: defaultNotAvailableMessage });
220
- return;
216
+ return { kind: "unavailable", reason: defaultNotAvailableMessage };
221
217
  }
222
- setStatus(getSourceStatus(source, defaultNotAvailableMessage));
223
- const resource = source.on?.("changed:status", () => {
224
- setStatus(getSourceStatus(source, defaultNotAvailableMessage));
225
- });
226
- return () => resource?.destroy();
218
+ return getSourceStatus(source, defaultNotAvailableMessage);
227
219
  }, [source, defaultNotAvailableMessage]);
228
- return status;
220
+ return sourceStatus;
229
221
  }
230
222
  function useDragSelection(map, intl, onExtentSelected, isActive, hasSelectedSource) {
231
223
  useEffect(() => {
package/Selection.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Selection.js","sources":["Selection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Box,\n Flex,\n FormControl,\n FormLabel,\n Icon,\n Tooltip,\n VStack,\n chakra,\n useToken\n} from \"@open-pioneer/chakra-integration\";\nimport { MapModel, MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { NotificationService } from \"@open-pioneer/notifier\";\nimport { CommonComponentProps, useCommonComponentProps, useEvent } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport {\n ChakraStylesConfig,\n GroupBase,\n OptionProps,\n Select,\n Props as SelectProps,\n SingleValueProps,\n chakraComponents,\n type SingleValue\n} from \"chakra-react-select\";\nimport { Geometry } from \"ol/geom\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { FC, KeyboardEvent, useEffect, useMemo, useRef, useState } from \"react\";\nimport { FiAlertTriangle } from \"react-icons/fi\";\nimport { DragController } from \"./DragController\";\nimport { SelectionController } from \"./SelectionController\";\nimport { SelectionResult, SelectionSource, SelectionSourceStatusObject } from \"./api\";\n\n/**\n * Properties supported by the {@link Selection} component.\n */\nexport interface SelectionProps extends CommonComponentProps, MapModelProps {\n /**\n * Array of selection sources available for spatial selection.\n */\n sources: SelectionSource[];\n\n /**\n * This handler is called whenever the user has successfully selected\n * some items.\n */\n onSelectionComplete?(event: SelectionCompleteEvent): void;\n\n /**\n * This handler is called whenever the user has changed the selected source\n */\n onSelectionSourceChanged?(event: SelectionSourceChangedEvent): void;\n}\n\nexport interface SelectionCompleteEvent {\n /** The source that returned the {@link results}. */\n source: SelectionSource;\n\n /** Results selected by the user. */\n results: SelectionResult[];\n}\n\nexport interface SelectionSourceChangedEvent {\n /** The new selected source */\n source: SelectionSource | undefined;\n}\n\n/**\n * Properties for single select options.\n */\ninterface SelectionOption {\n /**\n * The label of the selection source option.\n */\n label: string;\n\n /**\n * The value (SelectionSource) of the selection source option.\n */\n value: SelectionSource;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst COMMON_SELECT_PROPS: SelectProps<any, any, any> = {\n classNamePrefix: \"react-select\",\n menuPosition: \"fixed\",\n isSearchable: false,\n isClearable: false\n};\n\n/**\n * A component that allows the user to perform a spatial selection on a given set of {@link SelectionSource}.\n */\nexport const Selection: FC<SelectionProps> = (props) => {\n const intl = useIntl();\n const { sources, onSelectionComplete, onSelectionSourceChanged } = props;\n const { containerProps } = useCommonComponentProps(\"selection\", props);\n const defaultNotAvailableMessage = intl.formatMessage({ id: \"sourceNotAvailable\" });\n\n const [currentSource, setCurrentSource] = useCurrentSelectionSource(\n sources,\n onSelectionSourceChanged\n );\n\n const currentSourceStatus = useSourceStatus(currentSource, defaultNotAvailableMessage);\n\n const mapState = useMapModel(props);\n const { onExtentSelected } = useSelectionController(\n mapState.map,\n sources,\n currentSource,\n onSelectionComplete\n );\n const chakraStyles = useChakraStyles();\n const [isOpenSelect, setIsOpenSelect] = useState(false);\n\n useDragSelection(\n mapState.map,\n intl,\n onExtentSelected,\n currentSourceStatus.kind === \"available\",\n !!currentSource\n );\n\n const sourceOptions = useMemo(\n () =>\n sources.map<SelectionOption>((source) => {\n return { label: source.label, value: source };\n }),\n [sources]\n );\n const currentSourceOption = useMemo(() => {\n const foundOption: SelectionOption | undefined = sourceOptions.find(\n (option) => option.value === currentSource\n );\n return foundOption || null;\n }, [sourceOptions, currentSource]);\n\n const onSourceOptionChanged = useEvent((newValue: SingleValue<SelectionOption>) => {\n setCurrentSource(newValue?.value);\n });\n\n const keyDown = useEvent((event: KeyboardEvent<HTMLDivElement>) => {\n //if the menu is already open, do noting\n if (!isOpenSelect && event.key === \"Enter\") {\n setIsOpenSelect(true);\n }\n });\n\n return (\n <VStack {...containerProps} spacing={2}>\n <FormControl>\n <FormLabel>{intl.formatMessage({ id: \"selectSource\" })}</FormLabel>\n <Select<SelectionOption>\n className=\"selection-source react-select\"\n {...COMMON_SELECT_PROPS}\n options={sourceOptions}\n placeholder={intl.formatMessage({ id: \"selectionPlaceholder\" })}\n value={currentSourceOption}\n onChange={onSourceOptionChanged}\n components={{\n Option: SourceSelectOption,\n SingleValue: SourceSelectValue\n }}\n isOptionDisabled={() => false} // allow to select disabled options; optical disabling is done in option\n // optionLabel is used by screenreaders\n getOptionLabel={(option) => {\n const label = option.label;\n const status = getSourceStatus(option.value, defaultNotAvailableMessage);\n if (status.kind == \"available\") return label;\n return label + \" \" + status.reason;\n }}\n ariaLiveMessages={{\n guidance: () => \"\",\n onChange: (props) => {\n if (\n props.action == \"select-option\" ||\n props.action == \"initial-input-focus\"\n )\n return props.label + \" \" + intl.formatMessage({ id: \"selected\" });\n else return \"\";\n },\n onFilter: () => \"\",\n onFocus: () => \"\"\n }}\n chakraStyles={chakraStyles}\n onKeyDown={keyDown}\n menuIsOpen={isOpenSelect}\n onMenuOpen={() => setIsOpenSelect(true)}\n onMenuClose={() => setIsOpenSelect(false)}\n />\n </FormControl>\n </VStack>\n );\n};\n\nfunction SourceSelectOption(props: OptionProps<SelectionOption>): JSX.Element {\n const { value } = props.data;\n const { isAvailable, content } = useSourceItem(value, false);\n\n return (\n <chakraComponents.Option\n {...props}\n isDisabled={!isAvailable}\n className=\"selection-source-option\"\n >\n {content}\n </chakraComponents.Option>\n );\n}\n\nfunction SourceSelectValue(props: SingleValueProps<SelectionOption>): JSX.Element {\n const { value } = props.data;\n const { isAvailable, content } = useSourceItem(value, true);\n const clazz = isAvailable\n ? \"selection-source-value\"\n : \"selection-source-value selection-source-value--disabled\";\n\n return (\n <chakraComponents.SingleValue {...props} isDisabled={!isAvailable} className={clazz}>\n {content}\n </chakraComponents.SingleValue>\n );\n}\n\nfunction useCurrentSelectionSource(\n sources: SelectionSource[],\n onSourceChanged: ((event: SelectionSourceChangedEvent) => void) | undefined\n): [SelectionSource | undefined, (source: SelectionSource | undefined) => void] {\n const [currentSource, setCurrentSource] = useState<SelectionSource | undefined>(\n () => sources[0]\n );\n\n // Reset to undefined if the current source is not in the list of sources\n useEffect(() => {\n if (currentSource && !sources.includes(currentSource)) {\n setCurrentSource(undefined);\n }\n }, [sources, currentSource]);\n\n // Track the current source and notify the parent component if it changes\n const prevSelectedSource = useRef<SelectionSource | undefined>(undefined);\n useEffect(() => {\n if (currentSource !== prevSelectedSource.current) {\n prevSelectedSource.current = currentSource;\n onSourceChanged?.({ source: currentSource });\n }\n }, [currentSource, onSourceChanged]);\n return [currentSource, setCurrentSource];\n}\n\n/**\n * Hook to manage source option in selection-source react-select\n */\nfunction useSourceItem(source: SelectionSource | undefined, isSelected: boolean) {\n const intl = useIntl();\n const label: string | undefined = source?.label;\n const defaultNotAvailableMessage = intl.formatMessage({ id: \"sourceNotAvailable\" });\n const status = useSourceStatus(source, defaultNotAvailableMessage);\n\n return {\n isAvailable: status.kind === \"available\",\n content: (\n <Flex direction=\"row\" alignItems=\"center\" grow={1}>\n {!isSelected && <Flex grow={1}>{label}</Flex>}\n {status.kind === \"unavailable\" && (\n <Box ml={2}>\n <Tooltip label={status.reason} placement=\"right\" openDelay={500}>\n <chakra.span>\n <Icon\n as={FiAlertTriangle}\n color=\"red\"\n className=\"warning-icon\"\n aria-label={status.reason}\n />\n </chakra.span>\n </Tooltip>\n </Box>\n )}\n {isSelected && label}\n </Flex>\n )\n };\n}\n\n/**\n * Hook to manage selection sources\n */\nfunction useSelectionController(\n mapModel: MapModel | undefined,\n sources: SelectionSource[],\n currentSource: SelectionSource | undefined,\n onSelectionComplete: ((event: SelectionCompleteEvent) => void) | undefined\n) {\n const notifier = useService<NotificationService>(\"notifier.NotificationService\");\n const intl = useIntl();\n const [controller, setController] = useState<SelectionController | undefined>(undefined);\n useEffect(() => {\n if (!mapModel) {\n return;\n }\n const controller = new SelectionController({\n mapModel,\n onError() {\n notifier.notify({\n level: \"error\",\n message: intl.formatMessage({ id: \"selectionFailed\" })\n });\n }\n });\n setController(controller);\n return () => {\n controller.destroy();\n };\n }, [mapModel, notifier, sources, intl]);\n\n const onExtentSelected = useEvent(async (geometry: Geometry) => {\n if (!controller || !currentSource) {\n return;\n }\n\n const selectionResult = await controller.select(currentSource, geometry.getExtent());\n if (!selectionResult) {\n return;\n }\n\n onSelectionComplete?.(selectionResult);\n });\n return {\n controller,\n onExtentSelected\n };\n}\n\ntype SimpleStatus =\n | {\n kind: \"available\";\n }\n | {\n kind: \"unavailable\";\n reason: string;\n };\n\nfunction getSourceStatus(source: SelectionSource, sourceNotAvailableReason: string): SimpleStatus {\n const rawCurrent = source.status ?? \"available\";\n const current: SelectionSourceStatusObject =\n typeof rawCurrent === \"string\" ? { kind: rawCurrent } : rawCurrent;\n if (current.kind === \"available\") {\n return current;\n }\n\n return {\n kind: \"unavailable\",\n reason: current.reason ?? sourceNotAvailableReason\n };\n}\n\n/**\n * Hook to manage source status\n */\nfunction useSourceStatus(\n source: SelectionSource | undefined,\n defaultNotAvailableMessage: string\n): SimpleStatus {\n const [status, setStatus] = useState<SimpleStatus>(() => ({\n kind: \"unavailable\",\n reason: defaultNotAvailableMessage\n }));\n useEffect(() => {\n if (!source) {\n setStatus({ kind: \"unavailable\", reason: defaultNotAvailableMessage });\n return;\n }\n setStatus(getSourceStatus(source, defaultNotAvailableMessage));\n const resource = source.on?.(\"changed:status\", () => {\n setStatus(getSourceStatus(source, defaultNotAvailableMessage));\n });\n return () => resource?.destroy();\n }, [source, defaultNotAvailableMessage]);\n return status;\n}\n\n/**\n * Hook to manage map controls and tooltip\n */\nfunction useDragSelection(\n map: MapModel | undefined,\n intl: PackageIntl,\n onExtentSelected: (geometry: Geometry) => void,\n isActive: boolean,\n hasSelectedSource: boolean\n) {\n useEffect(() => {\n if (!map) {\n return;\n }\n\n const disabledMessage = hasSelectedSource\n ? intl.formatMessage({ id: \"disabledTooltip\" })\n : intl.formatMessage({ id: \"noSourceTooltip\" });\n\n const dragController = new DragController(\n map.olMap,\n intl.formatMessage({ id: \"tooltip\" }),\n disabledMessage,\n onExtentSelected\n );\n\n dragController.setActive(isActive);\n return () => {\n dragController?.destroy();\n };\n }, [map, intl, onExtentSelected, isActive, hasSelectedSource]);\n}\n\n/**\n * Customizes components styles within the select component.\n */\nfunction useChakraStyles() {\n const [dropDownBackground, borderColor] = useToken(\n \"colors\",\n [\"background_body\", \"border\"],\n [\"#ffffff\", \"#ffffff\"]\n );\n return useMemo(() => {\n const chakraStyles: ChakraStylesConfig<\n SelectionOption,\n false,\n GroupBase<SelectionOption>\n > = {\n control: (styles) => ({ ...styles, cursor: \"pointer\" }),\n indicatorSeparator: (styles) => ({\n ...styles,\n borderColor: borderColor\n }),\n dropdownIndicator: (provided) => ({\n ...provided,\n backgroundColor: dropDownBackground\n })\n };\n return chakraStyles;\n }, [dropDownBackground, borderColor]);\n}\n"],"names":["props","controller"],"mappings":";;;;;;;;;;;AAqFA,MAAM,mBAAkD,GAAA;AAAA,EACpD,eAAiB,EAAA,cAAA;AAAA,EACjB,YAAc,EAAA,OAAA;AAAA,EACd,YAAc,EAAA,KAAA;AAAA,EACd,WAAa,EAAA,KAAA;AACjB,CAAA,CAAA;AAKa,MAAA,SAAA,GAAgC,CAAC,KAAU,KAAA;AACpD,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAA,MAAM,EAAE,OAAA,EAAS,mBAAqB,EAAA,wBAAA,EAA6B,GAAA,KAAA,CAAA;AACnE,EAAA,MAAM,EAAE,cAAA,EAAmB,GAAA,uBAAA,CAAwB,aAAa,KAAK,CAAA,CAAA;AACrE,EAAA,MAAM,6BAA6B,IAAK,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,sBAAsB,CAAA,CAAA;AAElF,EAAM,MAAA,CAAC,aAAe,EAAA,gBAAgB,CAAI,GAAA,yBAAA;AAAA,IACtC,OAAA;AAAA,IACA,wBAAA;AAAA,GACJ,CAAA;AAEA,EAAM,MAAA,mBAAA,GAAsB,eAAgB,CAAA,aAAA,EAAe,0BAA0B,CAAA,CAAA;AAErF,EAAM,MAAA,QAAA,GAAW,YAAY,KAAK,CAAA,CAAA;AAClC,EAAM,MAAA,EAAE,kBAAqB,GAAA,sBAAA;AAAA,IACzB,QAAS,CAAA,GAAA;AAAA,IACT,OAAA;AAAA,IACA,aAAA;AAAA,IACA,mBAAA;AAAA,GACJ,CAAA;AACA,EAAA,MAAM,eAAe,eAAgB,EAAA,CAAA;AACrC,EAAA,MAAM,CAAC,YAAA,EAAc,eAAe,CAAA,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EAAgB,OAAQ,EAAA,CAAA;AAAA,KAC5B,CAAA;AAAA,KACD,CAAC,GAAA,EAAK,MAAM,gBAAkB,EAAA,QAAA,EAAU,iBAAiB,CAAC,CAAA,CAAA;AACjE,CAAA;AAKA,SAAS,eAAkB,GAAA;AACvB,EAAM,MAAA,CAAC,kBAAoB,EAAA,WAAW,CAAI,GAAA,QAAA;AAAA,IACtC,QAAA;AAAA,IACA,CAAC,mBAAmB,QAAQ,CAAA;AAAA,IAC5B,CAAC,WAAW,SAAS,CAAA;AAAA,GACzB,CAAA;AACA,EAAA,OAAO,QAAQ,MAAM;AACjB,IAAA,MAAM,YAIF,GAAA;AAAA,MACA,SAAS,CAAC,MAAA,MAAY,EAAE,GAAG,MAAA,EAAQ,QAAQ,SAAU,EAAA,CAAA;AAAA,MACrD,kBAAA,EAAoB,CAAC,MAAY,MAAA;AAAA,QAC7B,GAAG,MAAA;AAAA,QACH,WAAA;AAAA,OACJ,CAAA;AAAA,MACA,iBAAA,EAAmB,CAAC,QAAc,MAAA;AAAA,QAC9B,GAAG,QAAA;AAAA,QACH,eAAiB,EAAA,kBAAA;AAAA,OACrB,CAAA;AAAA,KACJ,CAAA;AACA,IAAO,OAAA,YAAA,CAAA;AAAA,GACR,EAAA,CAAC,kBAAoB,EAAA,WAAW,CAAC,CAAA,CAAA;AACxC;;;;"}
1
+ {"version":3,"file":"Selection.js","sources":["Selection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Box,\n Flex,\n FormControl,\n FormLabel,\n Icon,\n Tooltip,\n VStack,\n chakra,\n useToken\n} from \"@open-pioneer/chakra-integration\";\nimport { MapModel, MapModelProps, useMapModel } from \"@open-pioneer/map\";\nimport { NotificationService } from \"@open-pioneer/notifier\";\nimport { CommonComponentProps, useCommonComponentProps, useEvent } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport {\n ChakraStylesConfig,\n GroupBase,\n OptionProps,\n Select,\n Props as SelectProps,\n SingleValueProps,\n chakraComponents,\n type SingleValue\n} from \"chakra-react-select\";\nimport { Geometry } from \"ol/geom\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { FC, KeyboardEvent, useEffect, useMemo, useRef, useState } from \"react\";\nimport { FiAlertTriangle } from \"react-icons/fi\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { DragController } from \"./DragController\";\nimport { SelectionController } from \"./SelectionController\";\nimport { SelectionResult, SelectionSource, SelectionSourceStatusObject } from \"./api\";\n\n/**\n * Properties supported by the {@link Selection} component.\n */\nexport interface SelectionProps extends CommonComponentProps, MapModelProps {\n /**\n * Array of selection sources available for spatial selection.\n */\n sources: SelectionSource[];\n\n /**\n * This handler is called whenever the user has successfully selected\n * some items.\n */\n onSelectionComplete?(event: SelectionCompleteEvent): void;\n\n /**\n * This handler is called whenever the user has changed the selected source\n */\n onSelectionSourceChanged?(event: SelectionSourceChangedEvent): void;\n}\n\nexport interface SelectionCompleteEvent {\n /** The source that returned the {@link results}. */\n source: SelectionSource;\n\n /** Results selected by the user. */\n results: SelectionResult[];\n}\n\nexport interface SelectionSourceChangedEvent {\n /** The new selected source */\n source: SelectionSource | undefined;\n}\n\n/**\n * Properties for single select options.\n */\ninterface SelectionOption {\n /**\n * The label of the selection source option.\n */\n label: string;\n\n /**\n * The value (SelectionSource) of the selection source option.\n */\n value: SelectionSource;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst COMMON_SELECT_PROPS: SelectProps<any, any, any> = {\n classNamePrefix: \"react-select\",\n menuPosition: \"fixed\",\n isSearchable: false,\n isClearable: false\n};\n\n/**\n * A component that allows the user to perform a spatial selection on a given set of {@link SelectionSource}.\n */\nexport const Selection: FC<SelectionProps> = (props) => {\n const intl = useIntl();\n const { sources, onSelectionComplete, onSelectionSourceChanged } = props;\n const { containerProps } = useCommonComponentProps(\"selection\", props);\n const defaultNotAvailableMessage = intl.formatMessage({ id: \"sourceNotAvailable\" });\n\n const [currentSource, setCurrentSource] = useCurrentSelectionSource(\n sources,\n onSelectionSourceChanged\n );\n\n const currentSourceStatus = useSourceStatus(currentSource, defaultNotAvailableMessage);\n\n const mapState = useMapModel(props);\n const { onExtentSelected } = useSelectionController(\n mapState.map,\n sources,\n currentSource,\n onSelectionComplete\n );\n const chakraStyles = useChakraStyles();\n const [isOpenSelect, setIsOpenSelect] = useState(false);\n\n useDragSelection(\n mapState.map,\n intl,\n onExtentSelected,\n currentSourceStatus.kind === \"available\",\n !!currentSource\n );\n\n const sourceOptions = useMemo(\n () =>\n sources.map<SelectionOption>((source) => {\n return { label: source.label, value: source };\n }),\n [sources]\n );\n const currentSourceOption = useMemo(() => {\n const foundOption: SelectionOption | undefined = sourceOptions.find(\n (option) => option.value === currentSource\n );\n return foundOption || null;\n }, [sourceOptions, currentSource]);\n\n const onSourceOptionChanged = useEvent((newValue: SingleValue<SelectionOption>) => {\n setCurrentSource(newValue?.value);\n });\n\n const keyDown = useEvent((event: KeyboardEvent<HTMLDivElement>) => {\n //if the menu is already open, do noting\n if (!isOpenSelect && event.key === \"Enter\") {\n setIsOpenSelect(true);\n }\n });\n\n return (\n <VStack {...containerProps} spacing={2}>\n <FormControl>\n <FormLabel>{intl.formatMessage({ id: \"selectSource\" })}</FormLabel>\n <Select<SelectionOption>\n className=\"selection-source react-select\"\n {...COMMON_SELECT_PROPS}\n options={sourceOptions}\n placeholder={intl.formatMessage({ id: \"selectionPlaceholder\" })}\n value={currentSourceOption}\n onChange={onSourceOptionChanged}\n components={{\n Option: SourceSelectOption,\n SingleValue: SourceSelectValue\n }}\n isOptionDisabled={() => false} // allow to select disabled options; optical disabling is done in option\n // optionLabel is used by screenreaders\n getOptionLabel={(option) => {\n const label = option.label;\n const status = getSourceStatus(option.value, defaultNotAvailableMessage);\n if (status.kind == \"available\") return label;\n return label + \" \" + status.reason;\n }}\n ariaLiveMessages={{\n guidance: () => \"\",\n onChange: (props) => {\n if (\n props.action == \"select-option\" ||\n props.action == \"initial-input-focus\"\n )\n return props.label + \" \" + intl.formatMessage({ id: \"selected\" });\n else return \"\";\n },\n onFilter: () => \"\",\n onFocus: () => \"\"\n }}\n chakraStyles={chakraStyles}\n onKeyDown={keyDown}\n menuIsOpen={isOpenSelect}\n onMenuOpen={() => setIsOpenSelect(true)}\n onMenuClose={() => setIsOpenSelect(false)}\n />\n </FormControl>\n </VStack>\n );\n};\n\nfunction SourceSelectOption(props: OptionProps<SelectionOption>): JSX.Element {\n const { value } = props.data;\n const { isAvailable, content } = useSourceItem(value, false);\n\n return (\n <chakraComponents.Option\n {...props}\n isDisabled={!isAvailable}\n className=\"selection-source-option\"\n >\n {content}\n </chakraComponents.Option>\n );\n}\n\nfunction SourceSelectValue(props: SingleValueProps<SelectionOption>): JSX.Element {\n const { value } = props.data;\n const { isAvailable, content } = useSourceItem(value, true);\n const clazz = isAvailable\n ? \"selection-source-value\"\n : \"selection-source-value selection-source-value--disabled\";\n\n return (\n <chakraComponents.SingleValue {...props} isDisabled={!isAvailable} className={clazz}>\n {content}\n </chakraComponents.SingleValue>\n );\n}\n\nfunction useCurrentSelectionSource(\n sources: SelectionSource[],\n onSourceChanged: ((event: SelectionSourceChangedEvent) => void) | undefined\n): [SelectionSource | undefined, (source: SelectionSource | undefined) => void] {\n const [currentSource, setCurrentSource] = useState<SelectionSource | undefined>(\n () => sources[0]\n );\n\n // Reset to undefined if the current source is not in the list of sources\n useEffect(() => {\n if (currentSource && !sources.includes(currentSource)) {\n setCurrentSource(undefined);\n }\n }, [sources, currentSource]);\n\n // Track the current source and notify the parent component if it changes\n const prevSelectedSource = useRef<SelectionSource | undefined>(undefined);\n useEffect(() => {\n if (currentSource !== prevSelectedSource.current) {\n prevSelectedSource.current = currentSource;\n onSourceChanged?.({ source: currentSource });\n }\n }, [currentSource, onSourceChanged]);\n return [currentSource, setCurrentSource];\n}\n\n/**\n * Hook to manage source option in selection-source react-select\n */\nfunction useSourceItem(source: SelectionSource | undefined, isSelected: boolean) {\n const intl = useIntl();\n const label: string | undefined = source?.label;\n const defaultNotAvailableMessage = intl.formatMessage({ id: \"sourceNotAvailable\" });\n const status = useSourceStatus(source, defaultNotAvailableMessage);\n\n return {\n isAvailable: status.kind === \"available\",\n content: (\n <Flex direction=\"row\" alignItems=\"center\" grow={1}>\n {!isSelected && <Flex grow={1}>{label}</Flex>}\n {status.kind === \"unavailable\" && (\n <Box ml={2}>\n <Tooltip label={status.reason} placement=\"right\" openDelay={500}>\n <chakra.span>\n <Icon\n as={FiAlertTriangle}\n color=\"red\"\n className=\"warning-icon\"\n aria-label={status.reason}\n />\n </chakra.span>\n </Tooltip>\n </Box>\n )}\n {isSelected && label}\n </Flex>\n )\n };\n}\n\n/**\n * Hook to manage selection sources\n */\nfunction useSelectionController(\n mapModel: MapModel | undefined,\n sources: SelectionSource[],\n currentSource: SelectionSource | undefined,\n onSelectionComplete: ((event: SelectionCompleteEvent) => void) | undefined\n) {\n const notifier = useService<NotificationService>(\"notifier.NotificationService\");\n const intl = useIntl();\n const [controller, setController] = useState<SelectionController | undefined>(undefined);\n useEffect(() => {\n if (!mapModel) {\n return;\n }\n const controller = new SelectionController({\n mapModel,\n onError() {\n notifier.notify({\n level: \"error\",\n message: intl.formatMessage({ id: \"selectionFailed\" })\n });\n }\n });\n setController(controller);\n return () => {\n controller.destroy();\n };\n }, [mapModel, notifier, sources, intl]);\n\n const onExtentSelected = useEvent(async (geometry: Geometry) => {\n if (!controller || !currentSource) {\n return;\n }\n\n const selectionResult = await controller.select(currentSource, geometry.getExtent());\n if (!selectionResult) {\n return;\n }\n\n onSelectionComplete?.(selectionResult);\n });\n return {\n controller,\n onExtentSelected\n };\n}\n\ntype SimpleStatus =\n | {\n kind: \"available\";\n }\n | {\n kind: \"unavailable\";\n reason: string;\n };\n\nfunction getSourceStatus(source: SelectionSource, sourceNotAvailableReason: string): SimpleStatus {\n const rawCurrent = source.status ?? \"available\";\n const current: SelectionSourceStatusObject =\n typeof rawCurrent === \"string\" ? { kind: rawCurrent } : rawCurrent;\n if (current.kind === \"available\") {\n return current;\n }\n\n return {\n kind: \"unavailable\",\n reason: current.reason ?? sourceNotAvailableReason\n };\n}\n\n/**\n * Hook to manage source status\n */\nfunction useSourceStatus(\n source: SelectionSource | undefined,\n defaultNotAvailableMessage: string\n): SimpleStatus {\n const sourceStatus = useReactiveSnapshot((): SimpleStatus => {\n if (!source) {\n return { kind: \"unavailable\", reason: defaultNotAvailableMessage };\n }\n return getSourceStatus(source, defaultNotAvailableMessage);\n }, [source, defaultNotAvailableMessage]);\n return sourceStatus;\n}\n\n/**\n * Hook to manage map controls and tooltip\n */\nfunction useDragSelection(\n map: MapModel | undefined,\n intl: PackageIntl,\n onExtentSelected: (geometry: Geometry) => void,\n isActive: boolean,\n hasSelectedSource: boolean\n) {\n useEffect(() => {\n if (!map) {\n return;\n }\n\n const disabledMessage = hasSelectedSource\n ? intl.formatMessage({ id: \"disabledTooltip\" })\n : intl.formatMessage({ id: \"noSourceTooltip\" });\n\n const dragController = new DragController(\n map.olMap,\n intl.formatMessage({ id: \"tooltip\" }),\n disabledMessage,\n onExtentSelected\n );\n\n dragController.setActive(isActive);\n return () => {\n dragController?.destroy();\n };\n }, [map, intl, onExtentSelected, isActive, hasSelectedSource]);\n}\n\n/**\n * Customizes components styles within the select component.\n */\nfunction useChakraStyles() {\n const [dropDownBackground, borderColor] = useToken(\n \"colors\",\n [\"background_body\", \"border\"],\n [\"#ffffff\", \"#ffffff\"]\n );\n return useMemo(() => {\n const chakraStyles: ChakraStylesConfig<\n SelectionOption,\n false,\n GroupBase<SelectionOption>\n > = {\n control: (styles) => ({ ...styles, cursor: \"pointer\" }),\n indicatorSeparator: (styles) => ({\n ...styles,\n borderColor: borderColor\n }),\n dropdownIndicator: (provided) => ({\n ...provided,\n backgroundColor: dropDownBackground\n })\n };\n return chakraStyles;\n }, [dropDownBackground, borderColor]);\n}\n"],"names":["props","controller"],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AAc,MAAA;AAAA,QAC9B,GAAG,QAAA;AAAA,QACH,eAAiB,EAAA,kBAAA;AAAA,OACrB,CAAA;AAAA,KACJ,CAAA;AACA,IAAO,OAAA,YAAA,CAAA;AAAA,GACR,EAAA,CAAC,kBAAoB,EAAA,WAAW,CAAC,CAAA,CAAA;AACxC;;;;"}
@@ -0,0 +1,20 @@
1
+ import { SelectionResult, SelectionOptions, SelectionKind, VectorLayerSelectionSource, SelectionSourceStatusObject } from "./api";
2
+ import VectorLayer from "ol/layer/Vector";
3
+ import Feature from "ol/Feature";
4
+ import VectorSource from "ol/source/Vector";
5
+ /**
6
+ * A SelectionSource to use an OpenLayers VectorLayer with an OpenLayers VectorSource (e.g. layer of the map).
7
+ * Features are:
8
+ * - using only the extent as selection kind
9
+ * - listening to layer visibility changes and updating the status of the source
10
+ * - limiting the number of returned selection results to the corresponding selection option
11
+ * - throwing an event `changed:status` when the status updates
12
+ */
13
+ export declare class VectorLayerSelectionSourceImpl implements VectorLayerSelectionSource {
14
+ #private;
15
+ readonly label: string;
16
+ constructor(vectorLayer: VectorLayer<VectorSource, Feature>, label: string, layerNotVisibleReason: string);
17
+ destroy(): void;
18
+ get status(): SelectionSourceStatusObject;
19
+ select(selectionKind: SelectionKind, options: SelectionOptions): Promise<SelectionResult[]>;
20
+ }
@@ -1,22 +1,14 @@
1
- import { Point } from 'ol/geom.js';
2
- import { EventEmitter } from '@open-pioneer/core';
3
1
  import { unByKey } from 'ol/Observable.js';
4
2
  import { v4 } from 'uuid';
3
+ import { reactive } from '@conterra/reactivity-core';
5
4
 
6
- [
7
- new Point([407354, 5754673]),
8
- // con terra (Bottom Right)
9
- new Point([404740, 5757893])
10
- // Schloss (Top Left)
11
- ];
12
- class VectorLayerSelectionSourceImpl extends EventEmitter {
5
+ class VectorLayerSelectionSourceImpl {
13
6
  label;
14
- #status = { kind: "available" };
7
+ #status = reactive({ kind: "available" });
15
8
  #vectorLayer;
16
9
  #eventHandler;
17
10
  #layerNotVisibleReason;
18
11
  constructor(vectorLayer, label, layerNotVisibleReason) {
19
- super();
20
12
  this.label = label;
21
13
  this.#vectorLayer = vectorLayer;
22
14
  this.#layerNotVisibleReason = layerNotVisibleReason;
@@ -29,13 +21,14 @@ class VectorLayerSelectionSourceImpl extends EventEmitter {
29
21
  unByKey(this.#eventHandler);
30
22
  }
31
23
  get status() {
32
- return this.#status;
24
+ return this.#status.value;
33
25
  }
34
26
  async select(selectionKind, options) {
35
27
  if (selectionKind.type !== "extent") {
36
28
  throw new Error(`Unsupported selection kind: ${selectionKind.type}`);
37
29
  }
38
- if (this.#status.kind !== "available" || this.#vectorLayer.getSource() === null) return [];
30
+ if (this.#status.value.kind !== "available" || this.#vectorLayer.getSource() === null)
31
+ return [];
39
32
  const allResults = [];
40
33
  this.#vectorLayer.getSource().forEachFeatureIntersectingExtent(selectionKind.extent, (feature) => {
41
34
  if (!feature.getGeometry()) return;
@@ -55,12 +48,11 @@ class VectorLayerSelectionSourceImpl extends EventEmitter {
55
48
  #updateStatus() {
56
49
  const layerIsVisible = this.#vectorLayer.getVisible();
57
50
  const newStatus = layerIsVisible ? { kind: "available" } : { kind: "unavailable", reason: this.#layerNotVisibleReason };
58
- if (newStatus.kind !== this.#status.kind) {
59
- this.#status = newStatus;
60
- this.emit("changed:status");
51
+ if (newStatus.kind !== this.#status.value.kind) {
52
+ this.#status.value = newStatus;
61
53
  }
62
54
  }
63
55
  }
64
56
 
65
57
  export { VectorLayerSelectionSourceImpl };
66
- //# sourceMappingURL=selectionSources.js.map
58
+ //# sourceMappingURL=VectorSelectionSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VectorSelectionSource.js","sources":["VectorSelectionSource.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n SelectionResult,\n SelectionOptions,\n SelectionSourceStatus,\n SelectionKind,\n VectorLayerSelectionSource,\n SelectionSourceStatusObject\n} from \"./api\";\nimport VectorLayer from \"ol/layer/Vector\";\nimport { EventsKey } from \"ol/events\";\nimport { unByKey } from \"ol/Observable\";\nimport { v4 as uuid4v } from \"uuid\";\nimport Feature from \"ol/Feature\";\nimport { reactive } from \"@conterra/reactivity-core\";\nimport VectorSource from \"ol/source/Vector\";\n\n/**\n * A SelectionSource to use an OpenLayers VectorLayer with an OpenLayers VectorSource (e.g. layer of the map).\n * Features are:\n * - using only the extent as selection kind\n * - listening to layer visibility changes and updating the status of the source\n * - limiting the number of returned selection results to the corresponding selection option\n * - throwing an event `changed:status` when the status updates\n */\nexport class VectorLayerSelectionSourceImpl implements VectorLayerSelectionSource {\n readonly label: string;\n #status = reactive<SelectionSourceStatusObject>({ kind: \"available\" });\n #vectorLayer: VectorLayer<VectorSource, Feature>;\n #eventHandler: EventsKey;\n #layerNotVisibleReason: string;\n\n constructor(\n vectorLayer: VectorLayer<VectorSource, Feature>,\n label: string,\n layerNotVisibleReason: string\n ) {\n this.label = label;\n this.#vectorLayer = vectorLayer;\n this.#layerNotVisibleReason = layerNotVisibleReason;\n this.#updateStatus();\n this.#eventHandler = this.#vectorLayer.on(\"change:visible\", () => {\n this.#updateStatus();\n });\n }\n\n destroy() {\n unByKey(this.#eventHandler);\n }\n\n get status() {\n return this.#status.value;\n }\n\n async select(\n selectionKind: SelectionKind,\n options: SelectionOptions\n ): Promise<SelectionResult[]> {\n if (selectionKind.type !== \"extent\") {\n throw new Error(`Unsupported selection kind: ${selectionKind.type}`);\n }\n\n if (this.#status.value.kind !== \"available\" || this.#vectorLayer.getSource() === null)\n return [];\n\n const allResults: SelectionResult[] = [];\n this.#vectorLayer\n .getSource()!\n .forEachFeatureIntersectingExtent(selectionKind.extent, (feature) => {\n if (!feature.getGeometry()) return;\n\n // TODO: Think about where to implement Date-Formatting, if the dates are already\n // encoded as Strings...\n\n const filteredProperties = { ...feature.getProperties() };\n delete filteredProperties.geometries;\n\n const result: SelectionResult = {\n id: feature.getId()?.toString() || uuid4v(),\n geometry: feature.getGeometry()!,\n properties: filteredProperties\n };\n\n allResults.push(result);\n });\n const selectedFeatures = allResults.filter((s): s is SelectionResult => s != null);\n const limitedFeatures =\n selectedFeatures.length > options.maxResults\n ? selectedFeatures.slice(0, options.maxResults)\n : selectedFeatures;\n return limitedFeatures;\n }\n\n #updateStatus() {\n const layerIsVisible = this.#vectorLayer.getVisible();\n const newStatus: SelectionSourceStatus = layerIsVisible\n ? { kind: \"available\" }\n : { kind: \"unavailable\", reason: this.#layerNotVisibleReason };\n if (newStatus.kind !== this.#status.value.kind) {\n this.#status.value = newStatus;\n }\n }\n}\n"],"names":["uuid4v"],"mappings":";;;;AA0BO,MAAM,8BAAqE,CAAA;AAAA,EACrE,KAAA,CAAA;AAAA,EACT,OAAU,GAAA,QAAA,CAAsC,EAAE,IAAA,EAAM,aAAa,CAAA,CAAA;AAAA,EACrE,YAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,sBAAA,CAAA;AAAA,EAEA,WAAA,CACI,WACA,EAAA,KAAA,EACA,qBACF,EAAA;AACE,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AACb,IAAA,IAAA,CAAK,YAAe,GAAA,WAAA,CAAA;AACpB,IAAA,IAAA,CAAK,sBAAyB,GAAA,qBAAA,CAAA;AAC9B,IAAA,IAAA,CAAK,aAAc,EAAA,CAAA;AACnB,IAAA,IAAA,CAAK,aAAgB,GAAA,IAAA,CAAK,YAAa,CAAA,EAAA,CAAG,kBAAkB,MAAM;AAC9D,MAAA,IAAA,CAAK,aAAc,EAAA,CAAA;AAAA,KACtB,CAAA,CAAA;AAAA,GACL;AAAA,EAEA,OAAU,GAAA;AACN,IAAA,OAAA,CAAQ,KAAK,aAAa,CAAA,CAAA;AAAA,GAC9B;AAAA,EAEA,IAAI,MAAS,GAAA;AACT,IAAA,OAAO,KAAK,OAAQ,CAAA,KAAA,CAAA;AAAA,GACxB;AAAA,EAEA,MAAM,MACF,CAAA,aAAA,EACA,OAC0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AM,MAAA,cAAA,GAAiB,IAAK,CAAA,YAAA,CAAa,UAAW,EAAA,CAAA;AACpD,IAAM,MAAA,SAAA,GAAmC,cACnC,GAAA,EAAE,IAAM,EAAA,WAAA,EACR,GAAA,EAAE,IAAM,EAAA,aAAA,EAAe,MAAQ,EAAA,IAAA,CAAK,sBAAuB,EAAA,CAAA;AACjE,IAAA,IAAI,SAAU,CAAA,IAAA,KAAS,IAAK,CAAA,OAAA,CAAQ,MAAM,IAAM,EAAA;AAC5C,MAAA,IAAA,CAAK,QAAQ,KAAQ,GAAA,SAAA,CAAA;AAAA,KACzB;AAAA,GACJ;AACJ;;;;"}
package/api.d.ts CHANGED
@@ -1,17 +1,21 @@
1
1
  import type { Geometry } from "ol/geom";
2
2
  import type { Projection } from "ol/proj";
3
3
  import type { Extent } from "ol/extent";
4
- import type { EventSource, Resource } from "@open-pioneer/core";
4
+ import type { Resource } from "@open-pioneer/core";
5
5
  import { BaseFeature } from "@open-pioneer/map";
6
6
  import { DeclaredService } from "@open-pioneer/runtime";
7
7
  import VectorLayer from "ol/layer/Vector";
8
8
  import Feature from "ol/Feature";
9
+ import VectorSource from "ol/source/Vector";
9
10
  /**
10
11
  * The status of a selection source.
11
12
  *
12
13
  * This is used to indicate whether the source is ready for selection.
13
14
  */
14
15
  export type SelectionSourceStatus = "available" | "unavailable" | SelectionSourceStatusObject;
16
+ /**
17
+ * Advanced form of the {@link SelectionSourceStatus} that allows providing a reason why the source is not available.
18
+ */
15
19
  export type SelectionSourceStatusObject = {
16
20
  kind: "available";
17
21
  } | {
@@ -56,12 +60,6 @@ export interface SelectionOptions {
56
60
  */
57
61
  signal: AbortSignal;
58
62
  }
59
- /** Events emitted by the {@link SelectionSource}. */
60
- export interface SelectionSourceEvents {
61
- "changed:status": void;
62
- }
63
- /** Optional base type for selection source: the event emitter interface is not required. */
64
- export type SelectionSourceEventBase = EventSource<SelectionSourceEvents>;
65
63
  /**
66
64
  * The user has selected an extent.
67
65
  */
@@ -83,13 +81,8 @@ export type SelectionKind = ExtentSelection;
83
81
  * An object that allows spatial selection.
84
82
  *
85
83
  * Developers can create classes that implement this interface for different selection sources.
86
- *
87
- * The implementation of `SelectionSourceEventBase` is optional: it is only necessary if the status changes
88
- * during the lifetime of the selection source.
89
- * To implement events, you can write `class MySelectionSource extends EventEmitter<SelectionSourceEvents>`.
90
- *
91
84
  */
92
- export interface SelectionSource extends Partial<SelectionSourceEventBase> {
85
+ export interface SelectionSource {
93
86
  /**
94
87
  * The label of this source.
95
88
  *
@@ -101,6 +94,8 @@ export interface SelectionSource extends Partial<SelectionSourceEventBase> {
101
94
  * source is always available.
102
95
  *
103
96
  * This will be displayed by the user interface.
97
+ *
98
+ * This value can be reactive; changes will be reflected in the UI.
104
99
  */
105
100
  readonly status?: SelectionSourceStatus;
106
101
  /**
@@ -115,7 +110,7 @@ export interface SelectionSource extends Partial<SelectionSourceEventBase> {
115
110
  select(selectionKind: SelectionKind, options: SelectionOptions): Promise<SelectionResult[]>;
116
111
  }
117
112
  export interface VectorLayerSelectionSourceOptions {
118
- vectorLayer: VectorLayer<Feature>;
113
+ vectorLayer: VectorLayer<VectorSource, Feature>;
119
114
  label: string;
120
115
  }
121
116
  export interface VectorLayerSelectionSource extends Required<SelectionSource>, Resource {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@open-pioneer/selection",
4
- "version": "0.7.0",
4
+ "version": "0.8.0",
5
5
  "description": "This package provides a UI component to perform a selection on given selection sources from the map.",
6
6
  "keywords": [
7
7
  "open-pioneer-trails"
@@ -15,18 +15,20 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@chakra-ui/icons": "^2.2.4",
18
- "@open-pioneer/chakra-integration": "^2.3.0",
19
- "@open-pioneer/core": "^2.3.0",
20
- "@open-pioneer/notifier": "^2.3.0",
21
- "@open-pioneer/react-utils": "^2.3.0",
22
- "@open-pioneer/runtime": "^2.3.0",
18
+ "@open-pioneer/chakra-integration": "^2.4.0",
19
+ "@open-pioneer/core": "^2.4.0",
20
+ "@open-pioneer/notifier": "^2.4.0",
21
+ "@open-pioneer/react-utils": "^2.4.0",
22
+ "@open-pioneer/runtime": "^2.4.0",
23
23
  "classnames": "^2.3.2",
24
- "chakra-react-select": "^4.7.6",
25
- "ol": "^9.2.4",
24
+ "chakra-react-select": "^5.0.2",
25
+ "ol": "^10.2.1",
26
26
  "react": "^18.3.1",
27
27
  "react-icons": "^5.3.0",
28
28
  "uuid": "^10.0.0",
29
- "@open-pioneer/map": "^0.7.0"
29
+ "@conterra/reactivity-core": "^0.4.3",
30
+ "@open-pioneer/reactivity": "^2.4.0",
31
+ "@open-pioneer/map": "^0.8.0"
30
32
  },
31
33
  "exports": {
32
34
  "./package.json": "./package.json",
package/services.js CHANGED
@@ -1,4 +1,4 @@
1
- import { VectorLayerSelectionSourceImpl } from './selectionSources.js';
1
+ import { VectorLayerSelectionSourceImpl } from './VectorSelectionSource.js';
2
2
 
3
3
  class VectorSelectionSourceFactory {
4
4
  #intl;
package/services.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"services.js","sources":["services.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { type PackageIntl, ServiceOptions } from \"@open-pioneer/runtime\";\nimport { VectorLayerSelectionSourceImpl } from \"./selectionSources\";\nimport {\n VectorLayerSelectionSource,\n VectorLayerSelectionSourceFactory,\n VectorLayerSelectionSourceOptions\n} from \"./api\";\n\nexport class VectorSelectionSourceFactory implements VectorLayerSelectionSourceFactory {\n #intl: PackageIntl;\n\n constructor({ intl }: ServiceOptions<PackageIntl>) {\n this.#intl = intl;\n }\n createSelectionSource(options: VectorLayerSelectionSourceOptions): VectorLayerSelectionSource {\n return new VectorLayerSelectionSourceImpl(\n options.vectorLayer,\n options.label,\n this.#intl.formatMessage({ id: \"layerNotVisibleReason\" })\n );\n }\n}\n"],"names":[],"mappings":";;AAUO,MAAM,4BAA0E,CAAA;AAAA,EACnF,KAAA,CAAA;AAAA,EAEA,WAAA,CAAY,EAAE,IAAA,EAAqC,EAAA;AAC/C,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAA,CAAA;AAAA,GACjB;AAAA,EACA,sBAAsB,OAAwE,EAAA;AAC1F,IAAA,OAAO,IAAI,8BAAA;AAAA,MACP,OAAQ,CAAA,WAAA;AAAA,MACR,OAAQ,CAAA,KAAA;AAAA,MACR,KAAK,KAAM,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,yBAAyB,CAAA;AAAA,KAC5D,CAAA;AAAA,GACJ;AACJ;;;;"}
1
+ {"version":3,"file":"services.js","sources":["services.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { type PackageIntl, ServiceOptions } from \"@open-pioneer/runtime\";\nimport { VectorLayerSelectionSourceImpl } from \"./VectorSelectionSource\";\nimport {\n VectorLayerSelectionSource,\n VectorLayerSelectionSourceFactory,\n VectorLayerSelectionSourceOptions\n} from \"./api\";\n\nexport class VectorSelectionSourceFactory implements VectorLayerSelectionSourceFactory {\n #intl: PackageIntl;\n\n constructor({ intl }: ServiceOptions<PackageIntl>) {\n this.#intl = intl;\n }\n createSelectionSource(options: VectorLayerSelectionSourceOptions): VectorLayerSelectionSource {\n return new VectorLayerSelectionSourceImpl(\n options.vectorLayer,\n options.label,\n this.#intl.formatMessage({ id: \"layerNotVisibleReason\" })\n );\n }\n}\n"],"names":[],"mappings":";;AAUO,MAAM,4BAA0E,CAAA;AAAA,EACnF,KAAA,CAAA;AAAA,EAEA,WAAA,CAAY,EAAE,IAAA,EAAqC,EAAA;AAC/C,IAAA,IAAA,CAAK,KAAQ,GAAA,IAAA,CAAA;AAAA,GACjB;AAAA,EACA,sBAAsB,OAAwE,EAAA;AAC1F,IAAA,OAAO,IAAI,8BAAA;AAAA,MACP,OAAQ,CAAA,WAAA;AAAA,MACR,OAAQ,CAAA,KAAA;AAAA,MACR,KAAK,KAAM,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,yBAAyB,CAAA;AAAA,KAC5D,CAAA;AAAA,GACJ;AACJ;;;;"}
@@ -1,37 +0,0 @@
1
- import { SelectionSource, SelectionResult, SelectionOptions, SelectionSourceStatus, SelectionSourceEvents, SelectionKind, VectorLayerSelectionSource } from "./api";
2
- import { Point } from "ol/geom";
3
- import { EventEmitter } from "@open-pioneer/core";
4
- import VectorLayer from "ol/layer/Vector";
5
- import Feature from "ol/Feature";
6
- export declare const fakeSelectedPointFeatures: Point[];
7
- export declare class FakePointSelectionSource extends EventEmitter<SelectionSourceEvents> implements SelectionSource {
8
- #private;
9
- readonly label: string;
10
- constructor(timeout?: number, status?: SelectionSourceStatus, pointFeatures?: Point[]);
11
- get status(): SelectionSourceStatus;
12
- set status(value: SelectionSourceStatus);
13
- select(selectionKind: SelectionKind, options: SelectionOptions): Promise<SelectionResult[]>;
14
- }
15
- /**
16
- * A SelectionSource to use an OpenLayers VectorLayer with an OpenLayers VectorSource (e.g. layer of the map).
17
- * Features are:
18
- * - using only the extent as selection kind
19
- * - listening to layer visibility changes and updating the status of the source
20
- * - limiting the number of returned selection results to the corresponding selection option
21
- * - throwing an event `changed:status` when the status updates
22
- */
23
- export declare class VectorLayerSelectionSourceImpl extends EventEmitter<SelectionSourceEvents> implements VectorLayerSelectionSource {
24
- #private;
25
- readonly label: string;
26
- constructor(vectorLayer: VectorLayer<Feature>, label: string, layerNotVisibleReason: string);
27
- destroy(): void;
28
- get status(): import("./api").SelectionSourceStatusObject;
29
- select(selectionKind: SelectionKind, options: SelectionOptions): Promise<SelectionResult[]>;
30
- }
31
- /**
32
- * For testing purposes only
33
- */
34
- export declare class NoStatusSelectionSource extends EventEmitter<SelectionSourceEvents> implements SelectionSource {
35
- readonly label: string;
36
- select(_: SelectionKind, __: SelectionOptions): Promise<SelectionResult[]>;
37
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"selectionSources.js","sources":["selectionSources.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n SelectionSource,\n SelectionResult,\n SelectionOptions,\n SelectionSourceStatus,\n SelectionSourceEvents,\n SelectionKind,\n VectorLayerSelectionSource\n} from \"./api\";\nimport { Point } from \"ol/geom\";\nimport { EventEmitter } from \"@open-pioneer/core\";\nimport VectorLayer from \"ol/layer/Vector\";\nimport { EventsKey } from \"ol/events\";\nimport { unByKey } from \"ol/Observable\";\nimport { v4 as uuid4v } from \"uuid\";\nimport Feature from \"ol/Feature\";\n\nexport const fakeSelectedPointFeatures = [\n new Point([407354, 5754673]), // con terra (Bottom Right)\n new Point([404740, 5757893]) // Schloss (Top Left)\n];\n\nlet count = 0;\n\nexport class FakePointSelectionSource\n extends EventEmitter<SelectionSourceEvents>\n implements SelectionSource\n{\n readonly label = `Fake Selection Source #${++count}`;\n #timeout: number;\n #status: SelectionSourceStatus;\n #pointFeatures: Point[];\n\n constructor(\n timeout?: number,\n status?: SelectionSourceStatus,\n pointFeatures: Point[] = fakeSelectedPointFeatures\n ) {\n super();\n this.#timeout = timeout || 0;\n this.#status = status || \"unavailable\";\n this.#pointFeatures = pointFeatures;\n }\n\n get status(): SelectionSourceStatus {\n return this.#status;\n }\n\n set status(value: SelectionSourceStatus) {\n if (value !== this.#status) {\n this.#status = value;\n this.emit(\"changed:status\");\n }\n }\n\n async select(\n selectionKind: SelectionKind,\n options: SelectionOptions\n ): Promise<SelectionResult[]> {\n if (selectionKind.type !== \"extent\") {\n throw new Error(`Unsupported selection kind: ${selectionKind.type}`);\n }\n\n if (this.#status !== \"available\") return [];\n\n await new Promise((resolve) => setTimeout(resolve, this.#timeout));\n\n const allPoints = this.#pointFeatures.map((point, index) => {\n const result: SelectionResult = {\n id: index,\n geometry: point\n };\n if (!point.intersectsExtent(selectionKind.extent)) {\n return undefined;\n }\n return result;\n });\n\n const selectedPoints = allPoints.filter((s): s is SelectionResult => s != null);\n const limitedResults =\n selectedPoints.length > options.maxResults\n ? selectedPoints.slice(0, options.maxResults)\n : selectedPoints;\n return limitedResults;\n }\n}\n\n/**\n * A SelectionSource to use an OpenLayers VectorLayer with an OpenLayers VectorSource (e.g. layer of the map).\n * Features are:\n * - using only the extent as selection kind\n * - listening to layer visibility changes and updating the status of the source\n * - limiting the number of returned selection results to the corresponding selection option\n * - throwing an event `changed:status` when the status updates\n */\nexport class VectorLayerSelectionSourceImpl\n extends EventEmitter<SelectionSourceEvents>\n implements VectorLayerSelectionSource\n{\n readonly label: string;\n #status: Exclude<SelectionSourceStatus, string> = { kind: \"available\" };\n #vectorLayer: VectorLayer<Feature>;\n #eventHandler: EventsKey;\n #layerNotVisibleReason: string;\n\n constructor(vectorLayer: VectorLayer<Feature>, label: string, layerNotVisibleReason: string) {\n super();\n this.label = label;\n this.#vectorLayer = vectorLayer;\n this.#layerNotVisibleReason = layerNotVisibleReason;\n this.#updateStatus();\n this.#eventHandler = this.#vectorLayer.on(\"change:visible\", () => {\n this.#updateStatus();\n });\n }\n\n destroy() {\n unByKey(this.#eventHandler);\n }\n\n get status() {\n return this.#status;\n }\n\n async select(\n selectionKind: SelectionKind,\n options: SelectionOptions\n ): Promise<SelectionResult[]> {\n if (selectionKind.type !== \"extent\") {\n throw new Error(`Unsupported selection kind: ${selectionKind.type}`);\n }\n\n if (this.#status.kind !== \"available\" || this.#vectorLayer.getSource() === null) return [];\n\n const allResults: SelectionResult[] = [];\n this.#vectorLayer\n .getSource()!\n .forEachFeatureIntersectingExtent(selectionKind.extent, (feature) => {\n if (!feature.getGeometry()) return;\n const filteredProperties = { ...feature.getProperties() };\n delete filteredProperties.geometries;\n\n const result: SelectionResult = {\n id: feature.getId()?.toString() || uuid4v(),\n geometry: feature.getGeometry()!,\n properties: filteredProperties\n };\n\n allResults.push(result);\n });\n const selectedFeatures = allResults.filter((s): s is SelectionResult => s != null);\n const limitedFeatures =\n selectedFeatures.length > options.maxResults\n ? selectedFeatures.slice(0, options.maxResults)\n : selectedFeatures;\n return limitedFeatures;\n }\n\n #updateStatus() {\n const layerIsVisible = this.#vectorLayer.getVisible();\n const newStatus: SelectionSourceStatus = layerIsVisible\n ? { kind: \"available\" }\n : { kind: \"unavailable\", reason: this.#layerNotVisibleReason };\n if (newStatus.kind !== this.#status.kind) {\n this.#status = newStatus;\n this.emit(\"changed:status\");\n }\n }\n}\n\n/**\n * For testing purposes only\n */\nexport class NoStatusSelectionSource\n extends EventEmitter<SelectionSourceEvents>\n implements SelectionSource\n{\n readonly label: string = \"Testlabel\";\n\n async select(_: SelectionKind, __: SelectionOptions): Promise<SelectionResult[]> {\n const allPoints = fakeSelectedPointFeatures.map((point, index) => {\n const result: SelectionResult = {\n id: index,\n geometry: point\n };\n return result;\n });\n return allPoints;\n }\n}\n"],"names":["uuid4v"],"mappings":";;;;;AAmByC;AAAA,EACrC,IAAI,KAAA,CAAM,CAAC,MAAA,EAAQ,OAAO,CAAC,CAAA;AAAA;AAAA,EAC3B,IAAI,KAAA,CAAM,CAAC,MAAA,EAAQ,OAAO,CAAC,CAAA;AAAA;AAC/B,EAAA;AA2EO,MAAM,uCACD,YAEZ,CAAA;AAAA,EACa,KAAA,CAAA;AAAA,EACT,OAAA,GAAkD,EAAE,IAAA,EAAM,WAAY,EAAA,CAAA;AAAA,EACtE,YAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,sBAAA,CAAA;AAAA,EAEA,WAAA,CAAY,WAAmC,EAAA,KAAA,EAAe,qBAA+B,EAAA;AACzF,IAAM,KAAA,EAAA,CAAA;AACN,IAAA,IAAA,CAAK,KAAQ,GAAA,KAAA,CAAA;AACb,IAAA,IAAA,CAAK,YAAe,GAAA,WAAA,CAAA;AACpB,IAAA,IAAA,CAAK,sBAAyB,GAAA,qBAAA,CAAA;AAC9B,IAAA,IAAA,CAAK,aAAc,EAAA,CAAA;AACnB,IAAA,IAAA,CAAK,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