@talxis/base-controls 1.2408.1 → 1.2408.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DateTime/DateTime.js +133 -1
- package/dist/components/DateTime/DateTime.js.map +1 -0
- package/dist/components/DateTime/components/Calendar.js +63 -1
- package/dist/components/DateTime/components/Calendar.js.map +1 -0
- package/dist/components/DateTime/hooks/useDateTime.js +137 -1
- package/dist/components/DateTime/hooks/useDateTime.js.map +1 -0
- package/dist/components/DateTime/index.js +3 -1
- package/dist/components/DateTime/index.js.map +1 -0
- package/dist/components/DateTime/styles.js +37 -1
- package/dist/components/DateTime/styles.js.map +1 -0
- package/dist/components/DateTime/translations.js +23 -1
- package/dist/components/DateTime/translations.js.map +1 -0
- package/dist/components/Decimal/Decimal.js +200 -1
- package/dist/components/Decimal/Decimal.js.map +1 -0
- package/dist/components/Decimal/components/ArrowButtons.js +38 -1
- package/dist/components/Decimal/components/ArrowButtons.js.map +1 -0
- package/dist/components/Decimal/components/styles.js +26 -1
- package/dist/components/Decimal/components/styles.js.map +1 -0
- package/dist/components/Decimal/index.js +2 -1
- package/dist/components/Decimal/index.js.map +1 -0
- package/dist/components/Decimal/interfaces.d.ts +1 -1
- package/dist/components/Duration/Duration.js +132 -1
- package/dist/components/Duration/Duration.js.map +1 -0
- package/dist/components/Duration/durationOptions.d.ts +2 -0
- package/dist/components/Duration/durationOptions.js +27 -0
- package/dist/components/Duration/durationOptions.js.map +1 -0
- package/dist/components/Duration/index.js +2 -1
- package/dist/components/Duration/index.js.map +1 -0
- package/dist/components/Duration/translations.js +31 -1
- package/dist/components/Duration/translations.js.map +1 -0
- package/dist/components/Grid/Grid.js +30 -1
- package/dist/components/Grid/Grid.js.map +1 -0
- package/dist/components/Grid/GridContext.js +6 -1
- package/dist/components/Grid/GridContext.js.map +1 -0
- package/dist/components/Grid/constants.js +4 -1
- package/dist/components/Grid/constants.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/AgGrid.js +85 -1
- package/dist/components/Grid/core/components/AgGrid/AgGrid.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/components/EmptyRecordsOverlay/EmptyRecords.js +12 -1
- package/dist/components/Grid/core/components/AgGrid/components/EmptyRecordsOverlay/EmptyRecords.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/components/EmptyRecordsOverlay/styles.js +23 -1
- package/dist/components/Grid/core/components/AgGrid/components/EmptyRecordsOverlay/styles.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/components/LoadingOverlay/LoadingOverlay.js +11 -1
- package/dist/components/Grid/core/components/AgGrid/components/LoadingOverlay/LoadingOverlay.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/components/LoadingOverlay/styles.js +82 -1
- package/dist/components/Grid/core/components/AgGrid/components/LoadingOverlay/styles.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/controllers/useAgGridController.js +169 -1
- package/dist/components/Grid/core/components/AgGrid/controllers/useAgGridController.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/model/AgGrid.js +116 -1
- package/dist/components/Grid/core/components/AgGrid/model/AgGrid.js.map +1 -0
- package/dist/components/Grid/core/components/AgGrid/styles.js +91 -1
- package/dist/components/Grid/core/components/AgGrid/styles.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/Commands/Commands.js +29 -1
- package/dist/components/Grid/core/components/Cell/Commands/Commands.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/Commands/Icon.js +14 -1
- package/dist/components/Grid/core/components/Cell/Commands/Icon.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/Commands/styles.js +54 -1
- package/dist/components/Grid/core/components/Cell/Commands/styles.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/Commands/useCommands.js +52 -1
- package/dist/components/Grid/core/components/Cell/Commands/useCommands.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/EditableCell/EditableCell.js +148 -1
- package/dist/components/Grid/core/components/Cell/EditableCell/EditableCell.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/ReadOnlyCell.js +139 -1
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/ReadOnlyCell.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/ReadOnlyOptionSet/ReadOnlyOptionSet.js +49 -1
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/ReadOnlyOptionSet/ReadOnlyOptionSet.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/ReadOnlyOptionSet/styles.js +27 -1
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/ReadOnlyOptionSet/styles.js.map +1 -0
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/styles.js +58 -1
- package/dist/components/Grid/core/components/Cell/ReadOnlyCell/styles.js.map +1 -0
- package/dist/components/Grid/core/components/ColumnHeader/ColumnHeader.js +60 -1
- package/dist/components/Grid/core/components/ColumnHeader/ColumnHeader.js.map +1 -0
- package/dist/components/Grid/core/components/ColumnHeader/components/GlobalCheckbox/GlobalCheckbox.js +26 -1
- package/dist/components/Grid/core/components/ColumnHeader/components/GlobalCheckbox/GlobalCheckbox.js.map +1 -0
- package/dist/components/Grid/core/components/ColumnHeader/components/GlobalCheckbox/styles.js +19 -1
- package/dist/components/Grid/core/components/ColumnHeader/components/GlobalCheckbox/styles.js.map +1 -0
- package/dist/components/Grid/core/components/ColumnHeader/styles.js +44 -1
- package/dist/components/Grid/core/components/ColumnHeader/styles.js.map +1 -0
- package/dist/components/Grid/core/components/Component/Component.js +53 -1
- package/dist/components/Grid/core/components/Component/Component.js.map +1 -0
- package/dist/components/Grid/core/components/Component/controller/useComponentController.js +31 -1
- package/dist/components/Grid/core/components/Component/controller/useComponentController.js.map +1 -0
- package/dist/components/Grid/core/components/Component/model/Component.js +225 -1
- package/dist/components/Grid/core/components/Component/model/Component.js.map +1 -0
- package/dist/components/Grid/core/components/Dialog/Constants.js +9 -1
- package/dist/components/Grid/core/components/Dialog/Constants.js.map +1 -0
- package/dist/components/Grid/core/components/Dialog/Styles.js +61 -1
- package/dist/components/Grid/core/components/Dialog/Styles.js.map +1 -0
- package/dist/components/Grid/core/components/Dialog/index.js +16 -1
- package/dist/components/Grid/core/components/Dialog/index.js.map +1 -0
- package/dist/components/Grid/core/components/Dialog/interfaces/index.js +1 -0
- package/dist/components/Grid/core/components/Dialog/interfaces/index.js.map +1 -0
- package/dist/components/Grid/core/components/Save/Save.js +47 -1
- package/dist/components/Grid/core/components/Save/Save.js.map +1 -0
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/ChangeEditor.js +39 -1
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/ChangeEditor.js.map +1 -0
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/components/RecordGrids/RecordGrids.js +136 -1
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/components/RecordGrids/RecordGrids.js.map +1 -0
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/components/RecordGrids/styles.js +54 -1
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/components/RecordGrids/styles.js.map +1 -0
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/styles.js +37 -1
- package/dist/components/Grid/core/components/Save/components/ChangeEditor/styles.js.map +1 -0
- package/dist/components/Grid/core/components/Save/hooks/useSave.js +45 -1
- package/dist/components/Grid/core/components/Save/hooks/useSave.js.map +1 -0
- package/dist/components/Grid/core/components/Save/styles.js +44 -1
- package/dist/components/Grid/core/components/Save/styles.js.map +1 -0
- package/dist/components/Grid/core/controllers/useGridController.js +39 -1
- package/dist/components/Grid/core/controllers/useGridController.js.map +1 -0
- package/dist/components/Grid/core/enums/ConditionOperator.js +50 -1
- package/dist/components/Grid/core/enums/ConditionOperator.js.map +1 -0
- package/dist/components/Grid/core/enums/DataType.js +30 -1
- package/dist/components/Grid/core/enums/DataType.js.map +1 -0
- package/dist/components/Grid/core/hooks/useGridInstance.js +9 -1
- package/dist/components/Grid/core/hooks/useGridInstance.js.map +1 -0
- package/dist/components/Grid/core/hooks/useRefreshCallback.js +20 -1
- package/dist/components/Grid/core/hooks/useRefreshCallback.js.map +1 -0
- package/dist/components/Grid/core/hooks/useRerender.js +13 -1
- package/dist/components/Grid/core/hooks/useRerender.js.map +1 -0
- package/dist/components/Grid/core/model/Grid.js +249 -1
- package/dist/components/Grid/core/model/Grid.js.map +1 -0
- package/dist/components/Grid/core/model/GridDependency.js +28 -1
- package/dist/components/Grid/core/model/GridDependency.js.map +1 -0
- package/dist/components/Grid/core/model/Metadata.js +22 -1
- package/dist/components/Grid/core/model/Metadata.js.map +1 -0
- package/dist/components/Grid/core/services/RecordUpdateService/controllers/useRecordUpdateServiceController.js +25 -1
- package/dist/components/Grid/core/services/RecordUpdateService/controllers/useRecordUpdateServiceController.js.map +1 -0
- package/dist/components/Grid/core/services/RecordUpdateService/model/RecordUpdateService.js +190 -1
- package/dist/components/Grid/core/services/RecordUpdateService/model/RecordUpdateService.js.map +1 -0
- package/dist/components/Grid/filtering/components/FilterCallout/FilterCallout.js +50 -1
- package/dist/components/Grid/filtering/components/FilterCallout/FilterCallout.js.map +1 -0
- package/dist/components/Grid/filtering/components/FilterCallout/components/ConditionOperator/ConditionOperator.js +58 -1
- package/dist/components/Grid/filtering/components/FilterCallout/components/ConditionOperator/ConditionOperator.js.map +1 -0
- package/dist/components/Grid/filtering/components/FilterCallout/components/ConditionValue/ConditionValue.js +52 -1
- package/dist/components/Grid/filtering/components/FilterCallout/components/ConditionValue/ConditionValue.js.map +1 -0
- package/dist/components/Grid/filtering/components/FilterCallout/components/ConditionValue/model/ConditionComponentValue.js +125 -1
- package/dist/components/Grid/filtering/components/FilterCallout/components/ConditionValue/model/ConditionComponentValue.js.map +1 -0
- package/dist/components/Grid/filtering/components/FilterCallout/styles.js +40 -1
- package/dist/components/Grid/filtering/components/FilterCallout/styles.js.map +1 -0
- package/dist/components/Grid/filtering/constants.js +51 -1
- package/dist/components/Grid/filtering/constants.js.map +1 -0
- package/dist/components/Grid/filtering/controller/useColumnFilterConditionController.js +42 -1
- package/dist/components/Grid/filtering/controller/useColumnFilterConditionController.js.map +1 -0
- package/dist/components/Grid/filtering/model/Condition.js +297 -1
- package/dist/components/Grid/filtering/model/Condition.js.map +1 -0
- package/dist/components/Grid/filtering/model/Filtering.js +78 -1
- package/dist/components/Grid/filtering/model/Filtering.js.map +1 -0
- package/dist/components/Grid/filtering/utils/FilteringUtilts.js +195 -1
- package/dist/components/Grid/filtering/utils/FilteringUtilts.js.map +1 -0
- package/dist/components/Grid/index.js +2 -1
- package/dist/components/Grid/index.js.map +1 -0
- package/dist/components/Grid/paging/components/Paging/Paging.js +63 -1
- package/dist/components/Grid/paging/components/Paging/Paging.js.map +1 -0
- package/dist/components/Grid/paging/components/Paging/styles.js +41 -1
- package/dist/components/Grid/paging/components/Paging/styles.js.map +1 -0
- package/dist/components/Grid/paging/controllers/usePagingController.js +23 -1
- package/dist/components/Grid/paging/controllers/usePagingController.js.map +1 -0
- package/dist/components/Grid/paging/model/Paging.js +56 -1
- package/dist/components/Grid/paging/model/Paging.js.map +1 -0
- package/dist/components/Grid/selection/controllers/useSelectionController.js +17 -1
- package/dist/components/Grid/selection/controllers/useSelectionController.js.map +1 -0
- package/dist/components/Grid/selection/model/Selection.js +69 -1
- package/dist/components/Grid/selection/model/Selection.js.map +1 -0
- package/dist/components/Grid/sorting/Sorting.js +33 -1
- package/dist/components/Grid/sorting/Sorting.js.map +1 -0
- package/dist/components/Grid/sorting/components/SortingContextualMenu/SortingContextualMenu.js +120 -1
- package/dist/components/Grid/sorting/components/SortingContextualMenu/SortingContextualMenu.js.map +1 -0
- package/dist/components/Grid/sorting/components/SortingContextualMenu/styles.js +15 -1
- package/dist/components/Grid/sorting/components/SortingContextualMenu/styles.js.map +1 -0
- package/dist/components/Grid/sorting/controllers/useColumnSortingController.js +21 -1
- package/dist/components/Grid/sorting/controllers/useColumnSortingController.js.map +1 -0
- package/dist/components/Grid/translations.js +81 -1
- package/dist/components/Grid/translations.js.map +1 -0
- package/dist/components/Grid/validation/controllers/useRecordValidationController.js +25 -1
- package/dist/components/Grid/validation/controllers/useRecordValidationController.js.map +1 -0
- package/dist/components/Grid/validation/model/ColumnValidation.js +84 -1
- package/dist/components/Grid/validation/model/ColumnValidation.js.map +1 -0
- package/dist/components/Lookup/Lookup.js +201 -1
- package/dist/components/Lookup/Lookup.js.map +1 -0
- package/dist/components/Lookup/components/RecordCreator.js +37 -1
- package/dist/components/Lookup/components/RecordCreator.js.map +1 -0
- package/dist/components/Lookup/components/TargetSelector.js +19 -1
- package/dist/components/Lookup/components/TargetSelector.js.map +1 -0
- package/dist/components/Lookup/hooks/useFetchXml.js +27 -1
- package/dist/components/Lookup/hooks/useFetchXml.js.map +1 -0
- package/dist/components/Lookup/hooks/useLoadedEntities.js +20 -1
- package/dist/components/Lookup/hooks/useLoadedEntities.js.map +1 -0
- package/dist/components/Lookup/hooks/useLookup.js +111 -1
- package/dist/components/Lookup/hooks/useLookup.js.map +1 -0
- package/dist/components/Lookup/index.js +3 -1
- package/dist/components/Lookup/index.js.map +1 -0
- package/dist/components/Lookup/styles.js +98 -1
- package/dist/components/Lookup/styles.js.map +1 -0
- package/dist/components/Lookup/translations.js +33 -1
- package/dist/components/Lookup/translations.js.map +1 -0
- package/dist/components/MultiSelectOptionSet/MultiSelectOptionSet.js +74 -1
- package/dist/components/MultiSelectOptionSet/MultiSelectOptionSet.js.map +1 -0
- package/dist/components/MultiSelectOptionSet/index.js +2 -1
- package/dist/components/MultiSelectOptionSet/index.js.map +1 -0
- package/dist/components/OptionSet/OptionSet.js +61 -1
- package/dist/components/OptionSet/OptionSet.js.map +1 -0
- package/dist/components/OptionSet/index.js +2 -1
- package/dist/components/OptionSet/index.js.map +1 -0
- package/dist/components/TextField/TextField.js +113 -1
- package/dist/components/TextField/TextField.js.map +1 -0
- package/dist/components/TextField/index.js +2 -1
- package/dist/components/TextField/index.js.map +1 -0
- package/dist/components/TwoOptions/TwoOptions.js +36 -1
- package/dist/components/TwoOptions/TwoOptions.js.map +1 -0
- package/dist/components/TwoOptions/index.js +2 -1
- package/dist/components/TwoOptions/index.js.map +1 -0
- package/dist/constants.js +35 -1
- package/dist/constants.js.map +1 -0
- package/dist/hooks/index.js +7 -1
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/useControl.js +95 -1
- package/dist/hooks/useControl.js.map +1 -0
- package/dist/hooks/useControlSizing.js +15 -1
- package/dist/hooks/useControlSizing.js.map +1 -0
- package/dist/hooks/useControlTheme.js +9 -1
- package/dist/hooks/useControlTheme.js.map +1 -0
- package/dist/hooks/useFocusIn.js +33 -1
- package/dist/hooks/useFocusIn.js.map +1 -0
- package/dist/hooks/useInputBasedControl.js +38 -1
- package/dist/hooks/useInputBasedControl.js.map +1 -0
- package/dist/hooks/useMouseOver.js +23 -1
- package/dist/hooks/useMouseOver.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +19 -1
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/utils/Numeral.js +64 -1
- package/dist/utils/Numeral.js.map +1 -0
- package/dist/utils/Theme.js +72 -1
- package/dist/utils/Theme.js.map +1 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -0
- package/package.json +4 -2
- package/dist/Grid-b7e6190d.js +0 -1
- package/dist/components/DateTime/interfaces.js +0 -1
- package/dist/components/Decimal/interfaces.js +0 -1
- package/dist/components/Duration/interfaces.js +0 -1
- package/dist/components/Grid/core/interfaces/IGridColumn.js +0 -1
- package/dist/components/Grid/core/interfaces/IGridContext.js +0 -1
- package/dist/components/Grid/interfaces.js +0 -1
- package/dist/components/Lookup/interfaces.js +0 -1
- package/dist/components/MultiSelectOptionSet/interfaces.js +0 -1
- package/dist/components/OptionSet/interfaces.js +0 -1
- package/dist/components/TextField/interfaces.js +0 -1
- package/dist/components/TwoOptions/interfaces.js +0 -1
- package/dist/interfaces/context.js +0 -1
- package/dist/interfaces/parameters.js +0 -1
- package/dist/interfaces/property.js +0 -1
- package/dist/interfaces/theme.js +0 -1
|
@@ -1 +1,201 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useLookup } from './hooks/useLookup.js';
|
|
3
|
+
import { useRef, useState, useEffect } from 'react';
|
|
4
|
+
import { ThemeProvider } from '@fluentui/react';
|
|
5
|
+
import { TagPicker } from '@talxis/react-components';
|
|
6
|
+
import { TargetSelector } from './components/TargetSelector.js';
|
|
7
|
+
import { useMouseOver } from '../../hooks/useMouseOver.js';
|
|
8
|
+
import { getLookupStyles } from './styles.js';
|
|
9
|
+
import { RecordCreator } from './components/RecordCreator.js';
|
|
10
|
+
import { useFocusIn } from '../../hooks/useFocusIn.js';
|
|
11
|
+
import { useControlSizing } from '../../hooks/useControlSizing.js';
|
|
12
|
+
|
|
13
|
+
const Lookup = (props) => {
|
|
14
|
+
const context = props.context;
|
|
15
|
+
const ref = useRef(null);
|
|
16
|
+
const componentRef = useRef(null);
|
|
17
|
+
const itemLimit = props.parameters.MultipleEnabled?.raw === true ? Infinity : 1;
|
|
18
|
+
const { height } = useControlSizing(props.context.mode);
|
|
19
|
+
const [value, entities, labels, records, selectEntity, getSearchResults, theme] = useLookup(props);
|
|
20
|
+
const styles = getLookupStyles(theme, itemLimit === 1, height);
|
|
21
|
+
const mouseOver = useMouseOver(ref);
|
|
22
|
+
const isFocused = useFocusIn(ref, 100);
|
|
23
|
+
const firstRenderRef = useRef(true);
|
|
24
|
+
const shouldFocusRef = useRef(false);
|
|
25
|
+
const [placeholder, setPlaceholder] = useState('---');
|
|
26
|
+
const onOverrideComponentProps = props.onOverrideComponentProps ?? ((props) => props);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (firstRenderRef.current) {
|
|
29
|
+
firstRenderRef.current = false;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
//@ts-ignore
|
|
33
|
+
if (componentRef.current.state.suggestionsVisible) {
|
|
34
|
+
//if the suggestions callout is open and the selected target changes, refresh the results
|
|
35
|
+
forceSearch();
|
|
36
|
+
}
|
|
37
|
+
}, [entities]);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
const onKeyPress = (ev) => {
|
|
40
|
+
if (context.mode.isControlDisabled) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
if (ev.key === 'Backspace') {
|
|
44
|
+
const picker = ref.current?.querySelector('[class*="TALXIS__tag-picker__root"]');
|
|
45
|
+
if ((document.activeElement === picker) && value.length === 1) {
|
|
46
|
+
records.select(undefined);
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
componentRef.current?.focusInput();
|
|
49
|
+
}, 200);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
document.addEventListener('keydown', onKeyPress);
|
|
54
|
+
return () => {
|
|
55
|
+
document.removeEventListener('keydown', onKeyPress);
|
|
56
|
+
};
|
|
57
|
+
}, [value]);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (props.parameters.AutoFocus?.raw === true) {
|
|
60
|
+
focus();
|
|
61
|
+
}
|
|
62
|
+
}, []);
|
|
63
|
+
const focus = () => {
|
|
64
|
+
if (componentRef.current?.items?.length === itemLimit) {
|
|
65
|
+
const el = ref.current?.querySelector(':scope>div');
|
|
66
|
+
el?.click();
|
|
67
|
+
el?.focus();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
componentRef.current?.focusInput();
|
|
71
|
+
};
|
|
72
|
+
const forceSearch = async () => {
|
|
73
|
+
//@ts-ignore - We need to use internal methods to show and fill the suggestions on entity change
|
|
74
|
+
componentRef.current.suggestionStore.updateSuggestions([]);
|
|
75
|
+
//@ts-ignore - ^^same as above
|
|
76
|
+
componentRef.current.setState({
|
|
77
|
+
suggestionsVisible: true,
|
|
78
|
+
suggestionsLoading: true,
|
|
79
|
+
});
|
|
80
|
+
//@ts-ignore - ^^same as above
|
|
81
|
+
const results = await onResolveSuggestions(componentRef.current.input.current.value);
|
|
82
|
+
//@ts-ignore - ^^same as above
|
|
83
|
+
componentRef.current.updateSuggestionsList(results);
|
|
84
|
+
//@ts-ignore - ^^same above
|
|
85
|
+
componentRef.current.setState({
|
|
86
|
+
isMostRecentlyUsedVisible: false,
|
|
87
|
+
suggestionsVisible: true,
|
|
88
|
+
moreSuggestionsAvailable: false,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const isComponentActive = () => {
|
|
92
|
+
return mouseOver || isFocused;
|
|
93
|
+
};
|
|
94
|
+
const onResolveSuggestions = async (filter, selectedItems) => {
|
|
95
|
+
//TODO: onResolveSuggestions gets called when the record gets selected resulting in unnecessary call
|
|
96
|
+
const results = await getSearchResults(filter);
|
|
97
|
+
const suggestions = [];
|
|
98
|
+
for (const result of results) {
|
|
99
|
+
if (selectedItems?.find(x => x.key === result.id)) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const metadata = await entities.find(x => x.entityName === result.entityType)?.metadata;
|
|
103
|
+
suggestions.push({
|
|
104
|
+
key: result.id,
|
|
105
|
+
text: result.name || labels.noName(),
|
|
106
|
+
secondaryText: metadata?.DisplayName,
|
|
107
|
+
'data-entity': result.entityType
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return suggestions;
|
|
111
|
+
};
|
|
112
|
+
const componentProps = onOverrideComponentProps({
|
|
113
|
+
ref: componentRef,
|
|
114
|
+
underlined: theme.effects.underlined,
|
|
115
|
+
readOnly: context.mode.isControlDisabled,
|
|
116
|
+
resolveDelay: 200,
|
|
117
|
+
stackItems: itemLimit === 1,
|
|
118
|
+
errorMessage: props.parameters.value.errorMessage,
|
|
119
|
+
hideErrorMessage: !props.parameters.ShowErrorMessage?.raw,
|
|
120
|
+
pickerCalloutProps: {
|
|
121
|
+
layerProps: {
|
|
122
|
+
eventBubblingEnabled: true
|
|
123
|
+
},
|
|
124
|
+
className: styles.suggestions
|
|
125
|
+
},
|
|
126
|
+
inputProps: {
|
|
127
|
+
placeholder: placeholder,
|
|
128
|
+
onMouseEnter: () => {
|
|
129
|
+
if (context.mode.isControlDisabled) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
setPlaceholder(`${labels.placeholder()} ${props.parameters.value.attributes.DisplayName}`);
|
|
133
|
+
},
|
|
134
|
+
onMouseLeave: () => {
|
|
135
|
+
setPlaceholder("---");
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
pickerSuggestionsProps: {
|
|
139
|
+
loadingText: labels.searching(),
|
|
140
|
+
noResultsFoundText: labels.noRecordsFound(),
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
suggestionsHeaderText: (jsxs(Fragment, { children: [props.parameters.IsInlineNewEnabled?.raw !== false && (jsx(RecordCreator, { labels: labels, entities: entities, onCreateRecord: records.create })), props.parameters.value.attributes.Targets.length > 1 && (jsx(TargetSelector, { labels: labels, entities: entities, onEntitySelected: (entityName) => {
|
|
143
|
+
selectEntity(entityName);
|
|
144
|
+
} }))] }))
|
|
145
|
+
},
|
|
146
|
+
transparent: itemLimit === 1,
|
|
147
|
+
onChange: (items) => {
|
|
148
|
+
records.select(items?.map((item) => {
|
|
149
|
+
return {
|
|
150
|
+
entityType: item['data-entity'],
|
|
151
|
+
id: item.key,
|
|
152
|
+
name: item.text
|
|
153
|
+
};
|
|
154
|
+
}));
|
|
155
|
+
},
|
|
156
|
+
searchBtnProps: {
|
|
157
|
+
key: 'search',
|
|
158
|
+
iconProps: {
|
|
159
|
+
iconName: 'Search'
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
selectedItems: value.map((lookup) => {
|
|
163
|
+
return {
|
|
164
|
+
key: lookup.id,
|
|
165
|
+
text: lookup.name || labels.noName(),
|
|
166
|
+
'data-entity': lookup.entityType,
|
|
167
|
+
'data-navigation-enabled': props.parameters.EnableNavigation?.raw !== false,
|
|
168
|
+
onClick: () => {
|
|
169
|
+
if (props.parameters.EnableNavigation?.raw === false) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
context.navigation.openForm({
|
|
173
|
+
entityName: lookup.entityType,
|
|
174
|
+
entityId: lookup.id
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
deleteButtonProps: isComponentActive() || itemLimit > 1
|
|
178
|
+
? {
|
|
179
|
+
key: 'delete',
|
|
180
|
+
iconProps: {
|
|
181
|
+
iconName: 'Cancel',
|
|
182
|
+
},
|
|
183
|
+
onClick: () => {
|
|
184
|
+
shouldFocusRef.current = false;
|
|
185
|
+
records.deselect(lookup);
|
|
186
|
+
setTimeout(() => {
|
|
187
|
+
focus();
|
|
188
|
+
}, 200);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
: undefined
|
|
192
|
+
};
|
|
193
|
+
}),
|
|
194
|
+
itemLimit: itemLimit,
|
|
195
|
+
onResolveSuggestions: onResolveSuggestions
|
|
196
|
+
});
|
|
197
|
+
return (jsx(ThemeProvider, { applyTo: "none", theme: theme, className: `talxis__lookupControl ${styles.root}`, ref: ref, children: jsx(TagPicker, { ...componentProps }) }));
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
export { Lookup };
|
|
201
|
+
//# sourceMappingURL=Lookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Lookup.js","sources":["../../../src/components/Lookup/Lookup.tsx"],"sourcesContent":["\nimport { ILookup } from \"./interfaces\";\nimport { useLookup } from \"./hooks/useLookup\";\nimport React, { useEffect, useRef, useState } from 'react';\nimport { ThemeProvider } from \"@fluentui/react\";\nimport { IItemProps, TagPicker } from \"@talxis/react-components\";\nimport { TargetSelector } from \"./components/TargetSelector\";\nimport { useMouseOver } from \"../../hooks/useMouseOver\";\nimport { getLookupStyles } from \"./styles\";\nimport { IBasePicker } from \"@fluentui/react/lib/components/pickers/BasePicker.types\";\nimport { ITag } from \"@fluentui/react/lib/components/pickers/TagPicker/TagPicker.types\";\nimport { RecordCreator } from \"./components/RecordCreator\";\nimport { useFocusIn } from \"../../hooks/useFocusIn\";\nimport { useControlSizing } from \"../../hooks/useControlSizing\";\n\nexport const Lookup = (props: ILookup) => {\n const context = props.context;\n const ref = useRef<HTMLDivElement>(null);\n const componentRef = useRef<IBasePicker<ITag>>(null);\n const itemLimit = props.parameters.MultipleEnabled?.raw === true ? Infinity : 1\n const { height } = useControlSizing(props.context.mode);\n const [value, entities, labels, records, selectEntity, getSearchResults, theme] = useLookup(props);\n const styles = getLookupStyles(theme, itemLimit === 1, height);\n const mouseOver = useMouseOver(ref);\n const isFocused = useFocusIn(ref, 100);\n const firstRenderRef = useRef(true);\n const shouldFocusRef = useRef(false);\n const [placeholder, setPlaceholder] = useState('---');\n const onOverrideComponentProps = props.onOverrideComponentProps ?? ((props) => props);\n\n\n useEffect(() => {\n if (firstRenderRef.current) {\n firstRenderRef.current = false;\n return;\n }\n //@ts-ignore\n if (componentRef.current.state.suggestionsVisible) {\n //if the suggestions callout is open and the selected target changes, refresh the results\n forceSearch();\n }\n }, [entities])\n\n useEffect(() => {\n const onKeyPress = (ev: KeyboardEvent) => {\n if (context.mode.isControlDisabled) {\n return;\n }\n if (ev.key === 'Backspace') {\n const picker = ref.current?.querySelector('[class*=\"TALXIS__tag-picker__root\"]');\n if ((document.activeElement === picker) && value.length === 1) {\n records.select(undefined);\n setTimeout(() => {\n componentRef.current?.focusInput()\n }, 200)\n }\n }\n }\n document.addEventListener('keydown', onKeyPress)\n return () => {\n document.removeEventListener('keydown', onKeyPress);\n }\n }, [value]);\n\n useEffect(() => {\n if (props.parameters.AutoFocus?.raw === true) {\n focus();\n }\n }, []);\n\n const focus = () => {\n if(componentRef.current?.items?.length === itemLimit) {\n const el = ref.current?.querySelector(':scope>div') as HTMLDivElement;\n el?.click();\n el?.focus();\n return;\n }\n componentRef.current?.focusInput();\n }\n\n const forceSearch = async () => {\n //@ts-ignore - We need to use internal methods to show and fill the suggestions on entity change\n componentRef.current.suggestionStore.updateSuggestions([]);\n //@ts-ignore - ^^same as above\n componentRef.current.setState({\n suggestionsVisible: true,\n suggestionsLoading: true,\n });\n //@ts-ignore - ^^same as above\n const results = await onResolveSuggestions(componentRef.current.input.current.value)\n //@ts-ignore - ^^same as above\n componentRef.current.updateSuggestionsList(results);\n //@ts-ignore - ^^same above\n componentRef.current.setState({\n isMostRecentlyUsedVisible: false,\n suggestionsVisible: true,\n moreSuggestionsAvailable: false,\n });\n }\n\n const isComponentActive = () => {\n return mouseOver || isFocused;\n }\n\n const onResolveSuggestions = async (filter: string, selectedItems?: IItemProps[] | undefined): Promise<IItemProps[]> => {\n //TODO: onResolveSuggestions gets called when the record gets selected resulting in unnecessary call\n const results = await getSearchResults(filter);\n const suggestions: IItemProps[] = [];\n for (const result of results) {\n if (selectedItems?.find(x => x.key === result.id)) {\n continue;\n }\n const metadata = await entities.find(x => x.entityName === result.entityType)?.metadata;\n suggestions.push({\n key: result.id,\n text: result.name || labels.noName(),\n secondaryText: metadata?.DisplayName,\n 'data-entity': result.entityType\n })\n }\n return suggestions;\n }\n const componentProps = onOverrideComponentProps({\n ref: componentRef,\n underlined: theme.effects.underlined,\n readOnly: context.mode.isControlDisabled,\n resolveDelay: 200,\n stackItems: itemLimit === 1,\n errorMessage: props.parameters.value.errorMessage,\n hideErrorMessage: !props.parameters.ShowErrorMessage?.raw,\n pickerCalloutProps: {\n layerProps: {\n eventBubblingEnabled: true\n },\n className: styles.suggestions\n },\n\n inputProps: {\n placeholder: placeholder,\n onMouseEnter: () => {\n if (context.mode.isControlDisabled) {\n return;\n }\n setPlaceholder(`${labels.placeholder()} ${props.parameters.value.attributes.DisplayName}`);\n },\n onMouseLeave: () => {\n setPlaceholder(\"---\");\n }\n },\n pickerSuggestionsProps: {\n loadingText: labels.searching(),\n noResultsFoundText: labels.noRecordsFound(),\n // @ts-ignore\n suggestionsHeaderText: (\n <>\n {props.parameters.IsInlineNewEnabled?.raw !== false && (\n <RecordCreator labels={labels} entities={entities} onCreateRecord={records.create} />\n )}\n {props.parameters.value.attributes.Targets.length > 1 && (\n <TargetSelector\n labels={labels}\n entities={entities}\n onEntitySelected={(entityName) => {\n selectEntity(entityName);\n }}\n />\n )}\n </>\n )\n },\n transparent: itemLimit === 1,\n onChange: (items) => {\n records.select(\n items?.map((item) => {\n return {\n entityType: item['data-entity'],\n id: item.key,\n name: item.text\n };\n })\n );\n },\n searchBtnProps: {\n key: 'search',\n iconProps: {\n iconName: 'Search'\n }\n },\n selectedItems: value.map((lookup) => {\n return {\n key: lookup.id,\n text: lookup.name || labels.noName(),\n 'data-entity': lookup.entityType,\n 'data-navigation-enabled': props.parameters.EnableNavigation?.raw !== false,\n onClick: () => {\n if (props.parameters.EnableNavigation?.raw === false) {\n return;\n }\n context.navigation.openForm({\n entityName: lookup.entityType,\n entityId: lookup.id\n });\n },\n deleteButtonProps:\n isComponentActive() || itemLimit > 1\n ? {\n key: 'delete',\n iconProps: {\n iconName: 'Cancel',\n },\n onClick: () => {\n shouldFocusRef.current = false;\n records.deselect(lookup);\n setTimeout(() => {\n focus();\n }, 200);\n }\n }\n : undefined\n };\n }),\n itemLimit: itemLimit,\n onResolveSuggestions: onResolveSuggestions\n });\n\n return (\n <ThemeProvider applyTo=\"none\" theme={theme} className={`talxis__lookupControl ${styles.root}`} ref={ref}>\n <TagPicker {...componentProps} />\n </ThemeProvider>\n );\n};"],"names":["_jsxs","_Fragment","_jsx"],"mappings":";;;;;;;;;;;;AAea,MAAA,MAAM,GAAG,CAAC,KAAc,KAAI;AACrC,IAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;AAC9B,IAAA,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;AACzC,IAAA,MAAM,YAAY,GAAG,MAAM,CAAoB,IAAI,CAAC,CAAC;AACrD,IAAA,MAAM,SAAS,GAAG,KAAK,CAAC,UAAU,CAAC,eAAe,EAAE,GAAG,KAAK,IAAI,GAAG,QAAQ,GAAG,CAAC,CAAA;AAC/E,IAAA,MA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sx
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useTheme, CommandBarButton, ContextualMenuItemType } from '@fluentui/react';
|
|
3
|
+
import { getLookupStyles } from '../styles.js';
|
|
4
|
+
import { useLoadedEntities } from '../hooks/useLoadedEntities.js';
|
|
5
|
+
|
|
6
|
+
const RecordCreator = (props) => {
|
|
7
|
+
const { labels, entities, onCreateRecord } = { ...props };
|
|
8
|
+
const [loadedEntities] = useLoadedEntities(entities);
|
|
9
|
+
const theme = useTheme();
|
|
10
|
+
const styles = getLookupStyles(theme, 0);
|
|
11
|
+
const selectedEntity = entities.find(x => x.selected);
|
|
12
|
+
return (jsx(CommandBarButton, { className: styles.createRecordBtn, iconProps: {
|
|
13
|
+
iconName: 'Add'
|
|
14
|
+
}, onClick: selectedEntity ? () => onCreateRecord(selectedEntity.entityName) : undefined, menuProps: !selectedEntity ? {
|
|
15
|
+
calloutProps: {
|
|
16
|
+
coverTarget: false
|
|
17
|
+
},
|
|
18
|
+
isBeakVisible: true,
|
|
19
|
+
items: loadedEntities ? (() => {
|
|
20
|
+
const items = [{
|
|
21
|
+
key: 'header',
|
|
22
|
+
itemType: ContextualMenuItemType.Header,
|
|
23
|
+
text: 'Vyberte tabulku'
|
|
24
|
+
}];
|
|
25
|
+
return [...items, ...loadedEntities.map(entity => {
|
|
26
|
+
return {
|
|
27
|
+
key: entity.entityName,
|
|
28
|
+
text: entity.metadata.DisplayName,
|
|
29
|
+
onClick: () => onCreateRecord(entity.entityName)
|
|
30
|
+
};
|
|
31
|
+
})];
|
|
32
|
+
})() : []
|
|
33
|
+
} : undefined, text: labels.newRecord() }));
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { RecordCreator };
|
|
37
|
+
//# sourceMappingURL=RecordCreator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RecordCreator.js","sources":["../../../../src/components/Lookup/components/RecordCreator.tsx"],"sourcesContent":["\n//@ts-nocheck - typescript\nimport { ContextualMenuItemType, IContextualMenuItem, useTheme } from \"@fluentui/react\";\nimport { CommandBarButton } from \"@fluentui/react\";\nimport { IEntity, ILookupTranslations } from \"../interfaces\";\nimport { getLookupStyles } from \"../styles\";\nimport { StringProps } from '../../../types';\nimport { useLoadedEntities } from \"../hooks/useLoadedEntities\";\nimport React from 'react';\n\ninterface IRecordCreator {\n labels: Required<StringProps<ILookupTranslations>>,\n entities: IEntity[];\n onCreateRecord: (entityName: string) => void;\n}\n\nexport const RecordCreator = (props: IRecordCreator) => {\n const {labels, entities, onCreateRecord} = {...props};\n const [loadedEntities] = useLoadedEntities(entities);\n const theme = useTheme();\n const styles = getLookupStyles(theme, 0)\n const selectedEntity = entities.find(x => x.selected);\n\n return (\n <CommandBarButton\n className={styles.createRecordBtn}\n iconProps={{\n iconName: 'Add'\n }}\n onClick={selectedEntity ? () => onCreateRecord(selectedEntity.entityName) : undefined}\n menuProps={!selectedEntity ? {\n calloutProps: {\n coverTarget: false \n },\n isBeakVisible: true,\n items: loadedEntities ? (() => {\n const items: IContextualMenuItem[] = [{\n key: 'header',\n itemType: ContextualMenuItemType.Header,\n text: 'Vyberte tabulku'\n }]\n return [...items, ...loadedEntities.map(entity => {\n return {\n key: entity.entityName,\n text: entity.metadata.DisplayName,\n onClick: () => onCreateRecord(entity.entityName)\n }\n })];\n })() : []\n }: undefined} \n text={labels.newRecord()} />\n )\n}"],"names":["_jsx"],"mappings":";;;;;AAgBa,MAAA,aAAa,GAAG,CAAC,KAAqB,KAAI;AACnD,IAAA,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAE,cAAc,EAAC,GAAG,EAAC,GAAG,KAAK,EAAC,CAAC;IACtD,MAAM,CAAC,cAAc,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;IACzB,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AACxC,IAAA,MAAM,cAAc,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;IAEtD,QACIA,GAAC,CAAA,gBAAgB,EACb,EAAA,SAAS,EAAE,MAAM,CAAC,eAAe,EACjC,SAAS,EAAE;AACP,YAAA,QAAQ,EAAE,KAAK;SAClB,EACD,OAAO,EAAE,cAAc,GAAG,MAAM,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,SAAS,EACrF,SAAS,EAAE,CAAC,cAAc,GAAG;AACzB,YAAA,YAAY,EAAE;AACV,gBAAA,WAAW,EAAE,KAAK;AACrB,aAAA;AACD,YAAA,aAAa,EAAE,IAAI;AACnB,YAAA,KAAK,EAAE,cAAc,GAAG,CAAC,MAAK;gBAC1B,MAAM,KAAK,GAA0B,CAAC;AAClC,wBAAA,GAAG,EAAE,QAAQ;wBACb,QAAQ,EAAE,sBAAsB,CAAC,MAAM;AACvC,wBAAA,IAAI,EAAE,iBAAiB;AACvB,qBAAA,CAAC,CAAA;gBACF,OAAO,CAAC,GAAG,KAAK,EAAE,GAAG,cAAc,CAAC,GAAG,CAAC,MAAM,IAAG;wBAC7C,OAAO;4BACH,GAAG,EAAE,MAAM,CAAC,UAAU;AACtB,4BAAA,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,WAAW;4BACjC,OAAO,EAAE,MAAM,cAAc,CAAC,MAAM,CAAC,UAAU,CAAC;yBACnD,CAAA;qBACJ,CAAC,CAAC,CAAC;AACX,aAAC,GAAG,GAAG,EAAE;AACZ,SAAA,GAAE,SAAS,EACZ,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,EAAI,CAAA,EACnC;AACL;;;;"}
|
|
@@ -1 +1,19 @@
|
|
|
1
|
-
import{jsxs
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { Text } from '@fluentui/react/lib/Text';
|
|
3
|
+
import { useTheme, Link } from '@fluentui/react';
|
|
4
|
+
import { getTargetSelectorStyles } from '../styles.js';
|
|
5
|
+
import { useLoadedEntities } from '../hooks/useLoadedEntities.js';
|
|
6
|
+
|
|
7
|
+
const TargetSelector = (props) => {
|
|
8
|
+
const { labels, entities, onEntitySelected } = { ...props };
|
|
9
|
+
const [loadedEntities] = useLoadedEntities(entities);
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
const styles = getTargetSelectorStyles(theme);
|
|
12
|
+
return (jsxs("div", { className: styles.targetSelector, children: [jsxs(Text, { variant: 'small', children: [labels.resultsFrom(), " "] }), jsxs("div", { className: styles.targetSelectorLinks, children: [jsx(Link, { onClick: () => onEntitySelected(null), className: styles.targetSelectorLink, "data-selected": !entities.find(x => x.selected), children: "All" }), loadedEntities &&
|
|
13
|
+
jsx(Fragment, { children: loadedEntities.map((entity) => {
|
|
14
|
+
return jsx(Link, { className: styles.targetSelectorLink, "data-selected": entity.selected, onClick: () => onEntitySelected(entity.entityName), children: entity.metadata.DisplayName });
|
|
15
|
+
}) })] })] }));
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export { TargetSelector };
|
|
19
|
+
//# sourceMappingURL=TargetSelector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TargetSelector.js","sources":["../../../../src/components/Lookup/components/TargetSelector.tsx"],"sourcesContent":["import React from 'react';\nimport { IEntity } from '../interfaces';\nimport { Text } from '@fluentui/react/lib/Text';\nimport { Link, useTheme } from '@fluentui/react';\nimport { getTargetSelectorStyles } from '../styles';\nimport { useLoadedEntities } from '../hooks/useLoadedEntities';\n\ninterface ITargetSelector {\n labels: any;\n entities: IEntity[];\n onEntitySelected: (entityName: string | null) => void;\n}\n\n\nexport const TargetSelector = (props: ITargetSelector) => {\n const { labels, entities, onEntitySelected } = { ...props };\n const [loadedEntities] = useLoadedEntities(entities);\n const theme = useTheme();\n const styles = getTargetSelectorStyles(theme);\n\n return (\n <div className={styles.targetSelector}>\n <Text variant='small'>{labels.resultsFrom()} </Text>\n <div className={styles.targetSelectorLinks}>\n <Link\n onClick={() => onEntitySelected(null)}\n className={styles.targetSelectorLink}\n data-selected={!entities.find(x => x.selected)}>All</Link>\n {loadedEntities &&\n <>\n {loadedEntities.map((entity) => {\n return <Link\n className={styles.targetSelectorLink}\n data-selected={entity.selected}\n onClick={() => onEntitySelected(entity.entityName)}>{entity.metadata.DisplayName}</Link>\n })}\n </>\n }\n </div>\n </div>\n )\n}"],"names":["_jsxs","_jsx","_Fragment"],"mappings":";;;;;;AAca,MAAA,cAAc,GAAG,CAAC,KAAsB,KAAI;AACrD,IAAA,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;IAC5D,MAAM,CAAC,cAAc,CAAC,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrD,IAAA,MAAM,KAAK,GAAG,QAAQ,EAAE,CAAC;AACzB,IAAA,MAAM,MAAM,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAC;AAE9C,IAAA,QACIA,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,cAAc,EAAA,QAAA,EAAA,CACjCA,IAAC,CAAA,IAAI,EAAC,EAAA,OAAO,EAAC,OAAO,EAAE,QAAA,EAAA,CAAA,MAAM,CAAC,WAAW,EAAE,EAAA,GAAA,CAAA,EAAA,CAAS,EACpDA,IAAA,CAAA,KAAA,EAAA,EAAK,SAAS,EAAE,MAAM,CAAC,mBAAmB,EAAA,QAAA,EAAA,CACtCC,IAAC,IAAI,EAAA,EACD,OAAO,EAAE,MAAM,gBAAgB,CAAC,IAAI,CAAC,EACrC,SAAS,EAAE,MAAM,CAAC,kBAAkB,EAAA,eAAA,EACrB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAA,QAAA,EAAA,KAAA,EAAA,CAAY,EAC7D,cAAc;AACX,wBAAAA,GAAA,CAAAC,QAAA,EAAA,EAAA,QAAA,EACK,cAAc,CAAC,GAAG,CAAC,CAAC,MAAM,KAAI;AAC3B,gCAAA,OAAOD,GAAC,CAAA,IAAI,EACR,EAAA,SAAS,EAAE,MAAM,CAAC,kBAAkB,EACrB,eAAA,EAAA,MAAM,CAAC,QAAQ,EAC9B,OAAO,EAAE,MAAM,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAG,QAAA,EAAA,MAAM,CAAC,QAAQ,CAAC,WAAW,GAAQ,CAAA;AAChG,6BAAC,CAAC,EAAA,CACH,CAEL,EAAA,CAAA,CAAA,EAAA,CACJ,EACT;AACL;;;;"}
|
|
@@ -1 +1,27 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { useRef } from 'react';
|
|
2
|
+
import { FetchXmlBuilder } from '@talxis/client-libraries';
|
|
3
|
+
|
|
4
|
+
const useFetchXml = (context) => {
|
|
5
|
+
const cachedFetchXml = useRef({});
|
|
6
|
+
const get = async (viewId) => {
|
|
7
|
+
if (!cachedFetchXml.current[viewId]) {
|
|
8
|
+
cachedFetchXml.current[viewId] = context.webAPI.retrieveRecord('savedquery', viewId, '?$select=fetchxml');
|
|
9
|
+
}
|
|
10
|
+
return (await cachedFetchXml.current[viewId]).fetchxml;
|
|
11
|
+
};
|
|
12
|
+
const applyLookupQuery = async (entity, fetchXml, query) => {
|
|
13
|
+
if (!query) {
|
|
14
|
+
return fetchXml;
|
|
15
|
+
}
|
|
16
|
+
const metadata = await entity.metadata;
|
|
17
|
+
const xmlObject = FetchXmlBuilder.fetch.fromXml(fetchXml);
|
|
18
|
+
xmlObject.entity.addFilter(new FetchXmlBuilder.filter(FetchXmlBuilder.FilterType.Or, [
|
|
19
|
+
new FetchXmlBuilder.condition(metadata.PrimaryNameAttribute, FetchXmlBuilder.Operator.Like, [new FetchXmlBuilder.value(`%${query}%`)])
|
|
20
|
+
]));
|
|
21
|
+
return xmlObject.toXml();
|
|
22
|
+
};
|
|
23
|
+
return [get, applyLookupQuery];
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export { useFetchXml };
|
|
27
|
+
//# sourceMappingURL=useFetchXml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFetchXml.js","sources":["../../../../src/components/Lookup/hooks/useFetchXml.ts"],"sourcesContent":["import { useRef } from \"react\"\nimport { IEntity } from \"../interfaces\";\nimport { FetchXmlBuilder } from \"@talxis/client-libraries\";\n\nexport const useFetchXml = (context: ComponentFramework.Context<any>): [\n (viewId: string) => Promise<string>,\n (entity: IEntity, fetchXml: string, query: string) => Promise<string>\n] => {\n const cachedFetchXml = useRef<{\n [viewId: string]: Promise<ComponentFramework.WebApi.Entity>\n }>({});\n\n const get = async (viewId: string): Promise<string> => {\n if (!cachedFetchXml.current[viewId]) {\n cachedFetchXml.current[viewId] = context.webAPI.retrieveRecord('savedquery', viewId, '?$select=fetchxml');\n }\n return (await cachedFetchXml.current[viewId]).fetchxml;\n }\n const applyLookupQuery = async (entity: IEntity, fetchXml: string, query: string): Promise<string> => {\n if (!query) {\n return fetchXml\n }\n const metadata = await entity.metadata;\n const xmlObject = FetchXmlBuilder.fetch.fromXml(fetchXml);\n xmlObject.entity.addFilter(new FetchXmlBuilder.filter(FetchXmlBuilder.FilterType.Or, [\n new FetchXmlBuilder.condition(metadata.PrimaryNameAttribute, FetchXmlBuilder.Operator.Like, [new FetchXmlBuilder.value(`%${query}%`)])\n ]))\n return xmlObject.toXml();\n }\n return [get, applyLookupQuery]\n}"],"names":[],"mappings":";;;AAIa,MAAA,WAAW,GAAG,CAAC,OAAwC,KAGhE;AACA,IAAA,MAAM,cAAc,GAAG,MAAM,CAE1B,EAAE,CAAC,CAAC;AAEP,IAAA,MAAM,GAAG,GAAG,OAAO,MAAc,KAAqB;AAClD,QAAA,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;AACjC,YAAA,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAC7G,SAAA;QACD,OAAO,CAAC,MAAM,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC;AAC3D,KAAC,CAAA;IACD,MAAM,gBAAgB,GAAG,OAAO,MAAe,EAAE,QAAgB,EAAE,KAAa,KAAqB;QACjG,IAAI,CAAC,KAAK,EAAE;AACR,YAAA,OAAO,QAAQ,CAAA;AAClB,SAAA;AACD,QAAA,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC;QACvC,MAAM,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC1D,QAAA,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,eAAe,CAAC,UAAU,CAAC,EAAE,EAAE;YACjF,IAAI,eAAe,CAAC,SAAS,CAAC,QAAQ,CAAC,oBAAoB,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,eAAe,CAAC,KAAK,CAAC,CAAA,CAAA,EAAI,KAAK,CAAA,CAAA,CAAG,CAAC,CAAC,CAAC;AACzI,SAAA,CAAC,CAAC,CAAA;AACH,QAAA,OAAO,SAAS,CAAC,KAAK,EAAE,CAAC;AAC7B,KAAC,CAAA;AACD,IAAA,OAAO,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAA;AAClC;;;;"}
|
|
@@ -1 +1,20 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useLoadedEntities = (entities) => {
|
|
4
|
+
const [loadedEntities, setLoadedEntities] = useState(null);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
(async () => {
|
|
7
|
+
setLoadedEntities(await Promise.all(entities.map(async (entity) => {
|
|
8
|
+
return {
|
|
9
|
+
entityName: entity.entityName,
|
|
10
|
+
selected: entity.selected,
|
|
11
|
+
metadata: await entity.metadata
|
|
12
|
+
};
|
|
13
|
+
})));
|
|
14
|
+
})();
|
|
15
|
+
}, [entities]);
|
|
16
|
+
return [loadedEntities];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { useLoadedEntities };
|
|
20
|
+
//# sourceMappingURL=useLoadedEntities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLoadedEntities.js","sources":["../../../../src/components/Lookup/hooks/useLoadedEntities.ts"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { IEntity, IMetadata } from \"../interfaces\";\n\ninterface ILoadedEntity extends Omit<IEntity, 'metadata'> {\n metadata: IMetadata\n}\n\nexport const useLoadedEntities = (entities: IEntity[]): [ILoadedEntity[] | null] => {\n const [loadedEntities, setLoadedEntities] = useState<ILoadedEntity[] | null>(null);\n useEffect(() => {\n (async () => {\n setLoadedEntities(await Promise.all(entities.map(async entity => {\n return {\n entityName: entity.entityName,\n selected: entity.selected,\n metadata: await entity.metadata\n }\n })))\n })();\n }, [entities]);\n\n return [loadedEntities]\n}"],"names":[],"mappings":";;AAOa,MAAA,iBAAiB,GAAG,CAAC,QAAmB,KAA8B;IAC/E,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAyB,IAAI,CAAC,CAAC;IACnF,SAAS,CAAC,MAAK;QACX,CAAC,YAAW;AACR,YAAA,iBAAiB,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAM,MAAM,KAAG;gBAC5D,OAAO;oBACH,UAAU,EAAE,MAAM,CAAC,UAAU;oBAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;AACzB,oBAAA,QAAQ,EAAE,MAAM,MAAM,CAAC,QAAQ;iBAClC,CAAA;aACJ,CAAC,CAAC,CAAC,CAAA;SACP,GAAG,CAAC;AACT,KAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,OAAO,CAAC,cAAc,CAAC,CAAA;AAC3B;;;;"}
|
|
@@ -1 +1,111 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { lookupTranslations } from '../translations.js';
|
|
3
|
+
import { useFetchXml } from './useFetchXml.js';
|
|
4
|
+
import { useControl } from '../../../hooks/useControl.js';
|
|
5
|
+
|
|
6
|
+
const useLookup = (props) => {
|
|
7
|
+
const targets = props.parameters.value.attributes.Targets;
|
|
8
|
+
const boundValue = props.parameters.value.raw;
|
|
9
|
+
const context = props.context;
|
|
10
|
+
const { labels, theme, onNotifyOutputChanged } = useControl('Lookup', props, lookupTranslations);
|
|
11
|
+
const [getFetchXml, applyLookupQuery] = useFetchXml(context);
|
|
12
|
+
const [entities, setEntities] = useState(() => {
|
|
13
|
+
return targets.map(target => {
|
|
14
|
+
return {
|
|
15
|
+
entityName: target,
|
|
16
|
+
selected: targets.length === 1 ? true : false,
|
|
17
|
+
metadata: props.context.utils.getEntityMetadata(target, []),
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
const selectedEntity = entities.find(x => x.selected);
|
|
22
|
+
const selectEntity = (entityName) => {
|
|
23
|
+
setEntities([...entities].map(entity => {
|
|
24
|
+
return {
|
|
25
|
+
entityName: entity.entityName,
|
|
26
|
+
metadata: entity.metadata,
|
|
27
|
+
selected: entity.entityName === entityName
|
|
28
|
+
};
|
|
29
|
+
}));
|
|
30
|
+
};
|
|
31
|
+
const selectRecords = (records) => {
|
|
32
|
+
onNotifyOutputChanged({
|
|
33
|
+
value: records
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const getSearchFetchXml = async (entityName, query) => {
|
|
37
|
+
const response = (await props.parameters.value.getAllViews(entityName)).find(x => x.isDefault);
|
|
38
|
+
if (!response?.viewId) {
|
|
39
|
+
throw new Error(`Entity ${entityName} does not have a default view id!`);
|
|
40
|
+
}
|
|
41
|
+
let fetchXml = response?.fetchXml;
|
|
42
|
+
if (!fetchXml) {
|
|
43
|
+
fetchXml = await getFetchXml(response.viewId);
|
|
44
|
+
}
|
|
45
|
+
return applyLookupQuery(entities.find(x => x.entityName === entityName), fetchXml, query);
|
|
46
|
+
};
|
|
47
|
+
const getSearchResults = async (query) => {
|
|
48
|
+
if (props.onSearch) {
|
|
49
|
+
return props.onSearch(selectedEntity ? [selectedEntity?.entityName] : targets, query);
|
|
50
|
+
}
|
|
51
|
+
const fetchXmlMap = new Map();
|
|
52
|
+
if (selectedEntity) {
|
|
53
|
+
fetchXmlMap.set(selectedEntity.entityName, getSearchFetchXml(selectedEntity.entityName, query));
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
for (const entity of targets) {
|
|
57
|
+
fetchXmlMap.set(entity, getSearchFetchXml(entity, query));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
await Promise.all(fetchXmlMap.values());
|
|
61
|
+
const responsePromiseMap = new Map();
|
|
62
|
+
for (const [entityName, fetchXml] of fetchXmlMap) {
|
|
63
|
+
responsePromiseMap.set(entityName, context.webAPI.retrieveMultipleRecords(entityName, `?$top=25&fetchXml=${encodeURIComponent((await fetchXml))}`));
|
|
64
|
+
}
|
|
65
|
+
await Promise.all(responsePromiseMap.values());
|
|
66
|
+
const result = [];
|
|
67
|
+
for (const [entityName, response] of responsePromiseMap) {
|
|
68
|
+
for (const entity of (await response).entities) {
|
|
69
|
+
const entityMetadata = await entities.find(x => x.entityName === entityName).metadata;
|
|
70
|
+
result.push({
|
|
71
|
+
entityType: entityName,
|
|
72
|
+
id: entity[entityMetadata.PrimaryIdAttribute],
|
|
73
|
+
name: entity[entityMetadata.PrimaryNameAttribute]
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
};
|
|
79
|
+
const createRecord = async (entityName) => {
|
|
80
|
+
const result = await context.navigation.openForm({
|
|
81
|
+
entityName: entityName,
|
|
82
|
+
useQuickCreateForm: true
|
|
83
|
+
});
|
|
84
|
+
if (!result.savedEntityReference) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
onNotifyOutputChanged({
|
|
88
|
+
value: result.savedEntityReference
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
const deselectRecord = (record) => {
|
|
92
|
+
const map = new Map(boundValue.map(value => [value.id, value]));
|
|
93
|
+
map.delete(record.id);
|
|
94
|
+
onNotifyOutputChanged({
|
|
95
|
+
value: [...map.values()]
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
return [
|
|
99
|
+
boundValue, entities, labels, {
|
|
100
|
+
create: createRecord,
|
|
101
|
+
deselect: deselectRecord,
|
|
102
|
+
select: selectRecords
|
|
103
|
+
},
|
|
104
|
+
selectEntity,
|
|
105
|
+
getSearchResults,
|
|
106
|
+
theme
|
|
107
|
+
];
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export { useLookup };
|
|
111
|
+
//# sourceMappingURL=useLookup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLookup.js","sources":["../../../../src/components/Lookup/hooks/useLookup.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { ITranslation, useControl } from \"../../../hooks\";\nimport { ITheme } from \"../../../interfaces/theme\";\nimport { IEntity, ILookup } from \"../interfaces\";\nimport { lookupTranslations } from \"../translations\";\nimport { useFetchXml } from \"./useFetchXml\";\n\nexport const useLookup = (props: ILookup): [\n ComponentFramework.LookupValue[],\n IEntity[],\n ITranslation<Required<ILookup>['translations']>,\n {\n create: (entityName: string) => void,\n select: (record: ComponentFramework.LookupValue[] | undefined) => void,\n deselect: (record: ComponentFramework.LookupValue) => void,\n },\n (entityName: string | null) => void,\n (query: string) => Promise<ComponentFramework.LookupValue[]>,\n ITheme\n] => {\n\n const targets = props.parameters.value.attributes.Targets;\n const boundValue = props.parameters.value.raw;\n const context = props.context;\n const {labels, theme, onNotifyOutputChanged} = useControl('Lookup', props, lookupTranslations);\n const [getFetchXml, applyLookupQuery] = useFetchXml(context);\n \n const [entities, setEntities] = useState<IEntity[]>(() => {\n return targets.map(target => {\n return {\n entityName: target,\n selected: targets.length === 1 ? true : false,\n metadata: props.context.utils.getEntityMetadata(target, []) as any,\n }\n })\n });\n\n const selectedEntity = entities.find(x => x.selected);\n\n const selectEntity = (entityName: string | null) => {\n setEntities([...entities as IEntity[]].map(entity => {\n return {\n entityName: entity.entityName,\n metadata: entity.metadata,\n selected: entity.entityName === entityName\n }\n }))\n }\n\n const selectRecords = (records: ComponentFramework.LookupValue[] | undefined) => {\n onNotifyOutputChanged({\n value: records\n })\n }\n const getSearchFetchXml = async (entityName: string, query: string): Promise<string> => {\n const response = (await props.parameters.value.getAllViews(entityName)).find(x => x.isDefault);\n if (!response?.viewId) {\n throw new Error(`Entity ${entityName} does not have a default view id!`);\n }\n let fetchXml = response?.fetchXml\n if(!fetchXml) {\n fetchXml = await getFetchXml(response.viewId)\n }\n return applyLookupQuery(entities.find(x => x.entityName === entityName)!, fetchXml, query);\n\n }\n const getSearchResults = async (query: string): Promise<ComponentFramework.LookupValue[]> => {\n if(props.onSearch) { \n return props.onSearch(selectedEntity ? [selectedEntity?.entityName] : targets, query);\n }\n const fetchXmlMap = new Map<string, Promise<string>>();\n if(selectedEntity) {\n fetchXmlMap.set(selectedEntity.entityName, getSearchFetchXml(selectedEntity.entityName, query))\n }\n else {\n for (const entity of targets) {\n fetchXmlMap.set(entity, getSearchFetchXml(entity, query))\n }\n }\n await Promise.all(fetchXmlMap.values());\n const responsePromiseMap = new Map<string, Promise<ComponentFramework.WebApi.RetrieveMultipleResponse>>()\n for (const [entityName, fetchXml] of fetchXmlMap) {\n responsePromiseMap.set(entityName, context.webAPI.retrieveMultipleRecords(entityName, `?$top=25&fetchXml=${encodeURIComponent((await fetchXml))}`))\n }\n await Promise.all(responsePromiseMap.values());\n const result: ComponentFramework.LookupValue[] = [];\n for (const [entityName, response] of responsePromiseMap) {\n for (const entity of (await response).entities) {\n const entityMetadata = await entities.find(x => x.entityName === entityName)!.metadata;\n result.push({\n entityType: entityName,\n id: entity[entityMetadata.PrimaryIdAttribute],\n name: entity[entityMetadata.PrimaryNameAttribute]\n });\n }\n }\n return result;\n }\n\n const createRecord = async (entityName: string) => {\n const result = await context.navigation.openForm({\n entityName: entityName,\n useQuickCreateForm: true\n });\n if (!result.savedEntityReference) {\n return;\n }\n onNotifyOutputChanged({\n value: result.savedEntityReference\n })\n }\n\n const deselectRecord = (record: ComponentFramework.LookupValue) => {\n const map = new Map<string, ComponentFramework.LookupValue>(boundValue.map(value => [value.id, value]));\n map.delete(record.id);\n onNotifyOutputChanged({\n value: [...map.values()]\n })\n }\n\n return [\n boundValue, entities, labels, {\n create: createRecord,\n deselect: deselectRecord,\n select: selectRecords\n },\n selectEntity,\n getSearchResults,\n theme\n ];\n};"],"names":[],"mappings":";;;;;AAOa,MAAA,SAAS,GAAG,CAAC,KAAc,KAYpC;IAEA,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC;IAC1D,MAAM,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC;AAC9C,IAAA,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;AAC9B,IAAA,MAAM,EAAC,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAC,GAAG,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAC/F,MAAM,CAAC,WAAW,EAAE,gBAAgB,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC;IAE7D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAY,MAAK;AACrD,QAAA,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,IAAG;YACxB,OAAO;AACH,gBAAA,UAAU,EAAE,MAAM;AAClB,gBAAA,QAAQ,EAAE,OAAO,CAAC,MAAM,KAAK,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AAA,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AACtB,QAAA,qBAAqB,CAAC;AAClB,YAAA,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;AAC3B,SAAA,CAAC,CAAA;AACN,KAAC,CAAA;IAED,OAAO;AACH,QAAA,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE;AAC1B,YAAA,MAAM,EAAE,YAAY;AACpB,YAAA,QAAQ,EAAE,cAAc;AACxB,YAAA,MAAM,EAAE,aAAa;AACxB,SAAA;QACD,YAAY;QACZ,gBAAgB;QAChB,KAAK;KACR,CAAC;AACN;;;;"}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
export{Lookup}from
|
|
1
|
+
export { Lookup } from './Lookup.js';
|
|
2
|
+
export { useLookup } from './hooks/useLookup.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|