@open-pioneer/selection 0.2.4 → 0.7.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 +30 -0
- package/Selection.d.ts +2 -5
- package/Selection.js +2 -2
- package/Selection.js.map +1 -1
- package/package.json +10 -12
- package/selectionSources.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,35 @@
|
|
|
1
1
|
# @open-pioneer/selection
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 310800c: Switch from `peerDependencies` to normal `dependencies`. Peer dependencies have some usability problems when used at scale.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 310800c: Update core packages version.
|
|
12
|
+
- 583f1d6: The `mapId` or `map` properties are now optional on individual components.
|
|
13
|
+
You can use the `DefaultMapProvider` to configure an implicit default value.
|
|
14
|
+
|
|
15
|
+
Note that configuring _neither_ a default _nor_ an explicit `map` or `mapId` will trigger a runtime error.
|
|
16
|
+
|
|
17
|
+
- 583f1d6: All UI components in this project now accept the `mapId` (a `string`) _or_ the `map` (a `MapModel`) directly.
|
|
18
|
+
- a8b3449: Switch to a new versioning strategy.
|
|
19
|
+
From now on, packages released by this repository share a common version number.
|
|
20
|
+
- 900eb11: Update dependencies.
|
|
21
|
+
- Updated dependencies [310800c]
|
|
22
|
+
- Updated dependencies [2502050]
|
|
23
|
+
- Updated dependencies [583f1d6]
|
|
24
|
+
- Updated dependencies [583f1d6]
|
|
25
|
+
- Updated dependencies [397d617]
|
|
26
|
+
- Updated dependencies [a8b3449]
|
|
27
|
+
- Updated dependencies [310800c]
|
|
28
|
+
- Updated dependencies [900eb11]
|
|
29
|
+
- Updated dependencies [583f1d6]
|
|
30
|
+
- Updated dependencies [397d617]
|
|
31
|
+
- @open-pioneer/map@0.7.0
|
|
32
|
+
|
|
3
33
|
## 0.2.4
|
|
4
34
|
|
|
5
35
|
### Patch Changes
|
package/Selection.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
1
2
|
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
2
3
|
import { FC } from "react";
|
|
3
4
|
import { SelectionResult, SelectionSource } from "./api";
|
|
4
5
|
/**
|
|
5
6
|
* Properties supported by the {@link Selection} component.
|
|
6
7
|
*/
|
|
7
|
-
export interface SelectionProps extends CommonComponentProps {
|
|
8
|
-
/**
|
|
9
|
-
* The id of the map.
|
|
10
|
-
*/
|
|
11
|
-
mapId: string;
|
|
8
|
+
export interface SelectionProps extends CommonComponentProps, MapModelProps {
|
|
12
9
|
/**
|
|
13
10
|
* Array of selection sources available for spatial selection.
|
|
14
11
|
*/
|
package/Selection.js
CHANGED
|
@@ -17,7 +17,7 @@ const COMMON_SELECT_PROPS = {
|
|
|
17
17
|
};
|
|
18
18
|
const Selection = (props) => {
|
|
19
19
|
const intl = useIntl();
|
|
20
|
-
const {
|
|
20
|
+
const { sources, onSelectionComplete, onSelectionSourceChanged } = props;
|
|
21
21
|
const { containerProps } = useCommonComponentProps("selection", props);
|
|
22
22
|
const defaultNotAvailableMessage = intl.formatMessage({ id: "sourceNotAvailable" });
|
|
23
23
|
const [currentSource, setCurrentSource] = useCurrentSelectionSource(
|
|
@@ -25,7 +25,7 @@ const Selection = (props) => {
|
|
|
25
25
|
onSelectionSourceChanged
|
|
26
26
|
);
|
|
27
27
|
const currentSourceStatus = useSourceStatus(currentSource, defaultNotAvailableMessage);
|
|
28
|
-
const mapState = useMapModel(
|
|
28
|
+
const mapState = useMapModel(props);
|
|
29
29
|
const { onExtentSelected } = useSelectionController(
|
|
30
30
|
mapState.map,
|
|
31
31
|
sources,
|
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, 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 {\n /**\n * The id of the map.\n */\n mapId: string;\n\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 { mapId, 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(mapId);\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":";;;;;;;;;;;AA0FA,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,KAAA,EAAO,OAAS,EAAA,mBAAA,EAAqB,0BAA6B,GAAA,KAAA,CAAA;AAC1E,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,C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cAAA;AAAA,MACvB,GAAI,CAAA,KAAA;AAAA,MACJ,IAAK,CAAA,aAAA,CAAc,EAAE,EAAA,EAAI,WAAW,CAAA;AAAA,MACpC,eAAA;AAAA,MACA,gBAAA;AAAA,KACJ,CAAA;AAEA,IAAA,cAAA,CAAe,UAAU,QAAQ,CAAA,CAAA;AACjC,IAAA,OAAO,MAAM;AACT,MAAA,cAAA,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 { 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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,eAAA;AAAA,MACA,gBAAA;AAAA,KACJ,CAAA;AAEA,IAAA,cAAA,CAAe,UAAU,QAAQ,CAAA,CAAA;AACjC,IAAA,OAAO,MAAM;AACT,MAAA,cAAA,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;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/selection",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.7.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"
|
|
@@ -14,21 +14,19 @@
|
|
|
14
14
|
"directory": "src/packages/selection"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
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",
|
|
17
23
|
"classnames": "^2.3.2",
|
|
18
|
-
"uuid": "^10.0.0"
|
|
19
|
-
},
|
|
20
|
-
"peerDependencies": {
|
|
21
|
-
"@chakra-ui/icons": "^2.1.1",
|
|
22
|
-
"@open-pioneer/chakra-integration": "^1.1.4",
|
|
23
|
-
"@open-pioneer/core": "^1.3.0",
|
|
24
|
-
"@open-pioneer/notifier": "^0.3.6",
|
|
25
|
-
"@open-pioneer/react-utils": "^1.0.1",
|
|
26
|
-
"@open-pioneer/runtime": "^2.1.7",
|
|
27
24
|
"chakra-react-select": "^4.7.6",
|
|
28
25
|
"ol": "^9.2.4",
|
|
29
26
|
"react": "^18.3.1",
|
|
30
|
-
"react-icons": "^5.
|
|
31
|
-
"
|
|
27
|
+
"react-icons": "^5.3.0",
|
|
28
|
+
"uuid": "^10.0.0",
|
|
29
|
+
"@open-pioneer/map": "^0.7.0"
|
|
32
30
|
},
|
|
33
31
|
"exports": {
|
|
34
32
|
"./package.json": "./package.json",
|
package/selectionSources.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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,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,IAAK,CAAA,OAAA,CAAA;AAAA,GAChB;AAAA,EAEA,MAAM,MACF,CAAA,aAAA,EACA,OAC0B,EAAA;AAC1B,IAAI,IAAA,aAAA,CAAc,SAAS,QAAU,EAAA;AACjC,MAAA,MAAM,IAAI,KA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