@synerise/ds-item-picker 2.3.0 → 2.4.1

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/CLAUDE.md +67 -9
  3. package/README.md +42 -0
  4. package/dist/components/ItemPickerList/ItemPickerList.js +40 -8
  5. package/dist/components/ItemPickerList/ItemPickerList.styles.d.ts +4 -1
  6. package/dist/components/ItemPickerList/ItemPickerList.styles.js +21 -6
  7. package/dist/components/ItemPickerList/components/EmptyListMessage.d.ts +3 -2
  8. package/dist/components/ItemPickerList/components/EmptyListMessage.js +4 -0
  9. package/dist/components/ItemPickerList/components/ItemPickerListRow.js +1 -1
  10. package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.d.ts +3 -1
  11. package/dist/components/ItemPickerList/components/ItemPickerListSkeleton.js +17 -10
  12. package/dist/components/ItemPickerList/components/ListSearchInput.d.ts +3 -1
  13. package/dist/components/ItemPickerList/components/ListSearchInput.js +10 -3
  14. package/dist/components/ItemPickerList/constants.d.ts +2 -0
  15. package/dist/components/ItemPickerList/constants.js +4 -0
  16. package/dist/components/ItemPickerList/hooks/index.d.ts +1 -0
  17. package/dist/components/ItemPickerList/hooks/index.js +2 -0
  18. package/dist/components/ItemPickerList/hooks/useFolderLevel.d.ts +9 -0
  19. package/dist/components/ItemPickerList/hooks/useFolderLevel.js +31 -0
  20. package/dist/components/ItemPickerList/hooks/useItemsInSections.d.ts +5 -0
  21. package/dist/components/ItemPickerList/hooks/useItemsInSections.js +208 -68
  22. package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.d.ts +9 -1
  23. package/dist/components/ItemPickerList/hooks/useItemsInSections.utils.js +33 -1
  24. package/dist/components/ItemPickerList/types/renderMode.d.ts +1 -0
  25. package/dist/components/ItemPickerList/types/renderMode.js +2 -1
  26. package/dist/components/ItemPickerList/utils/actionItemsUtils.js +6 -2
  27. package/dist/components/ItemPickerList/utils/formatFolderPath.d.ts +4 -0
  28. package/dist/components/ItemPickerList/utils/formatFolderPath.js +13 -0
  29. package/dist/components/ItemPickerList/utils/index.d.ts +1 -0
  30. package/dist/components/ItemPickerList/utils/index.js +5 -1
  31. package/dist/components/ItemPickerList/utils/typeguards.utils.d.ts +7 -2
  32. package/dist/components/ItemPickerList/utils/typeguards.utils.js +4 -0
  33. package/dist/components/ItemPickerNew/ItemPickerNew.js +5 -3
  34. package/dist/components/ItemPickerNew/ItemPickerNew.types.d.ts +2 -1
  35. package/dist/components/ItemPickerNew/types/actions.types.d.ts +5 -0
  36. package/dist/components/ItemPickerNew/types/itemPickerListTexts.types.d.ts +1 -1
  37. package/dist/components/ItemPickerNew/types/mixedLoader.types.d.ts +52 -0
  38. package/dist/components/ItemPickerNew/types/mixedLoader.types.js +1 -0
  39. package/dist/hooks/useDefaultTexts.js +8 -0
  40. package/dist/index.d.ts +1 -0
  41. package/package.json +23 -23
@@ -14,6 +14,8 @@ const isItemsConfig = (items) => {
14
14
  }
15
15
  return false;
16
16
  };
17
+ const isMixedLoaderConfig = (items) => !Array.isArray(items) && "loadLevel" in items;
18
+ const isItemLoaderConfig = (items) => !Array.isArray(items) && "loadItems" in items;
17
19
  const isWithOutSections = (sections) => {
18
20
  return sections === void 0;
19
21
  };
@@ -27,8 +29,10 @@ const isSearchInAction = (action) => {
27
29
  return action?.actionType === ACTION_TYPES.searchIn;
28
30
  };
29
31
  export {
32
+ isItemLoaderConfig,
30
33
  isItems,
31
34
  isItemsConfig,
35
+ isMixedLoaderConfig,
32
36
  isSearchByAction,
33
37
  isSearchInAction,
34
38
  isTitle,
@@ -4,6 +4,7 @@ import Dropdown from "@synerise/ds-dropdown";
4
4
  import FormField from "@synerise/ds-form-field";
5
5
  import { useDefaultTexts } from "../../hooks/useDefaultTexts.js";
6
6
  import { ItemPickerWrapper } from "../../ItemPicker.styles.js";
7
+ import { GET_ITEM_KEY } from "../ItemPickerList/constants.js";
7
8
  import { ItemPickerList } from "../ItemPickerList/ItemPickerList.js";
8
9
  import Trigger from "../ItemPickerTrigger/Trigger.js";
9
10
  const ItemPickerNewInner = ({
@@ -46,12 +47,13 @@ const ItemPickerNewInner = ({
46
47
  onChange?.(item);
47
48
  closeDropdown();
48
49
  };
50
+ const selectedItemKey = selectedItem ? GET_ITEM_KEY(selectedItem) : void 0;
51
+ useEffect(() => setSelected(selectedItem), [selectedItem]);
49
52
  useEffect(() => {
50
- setSelected(selectedItem);
51
- if (selectedItem) {
53
+ if (selectedItemKey !== void 0) {
52
54
  setVisible(false);
53
55
  }
54
- }, [selectedItem]);
56
+ }, [selectedItemKey]);
55
57
  const trigger = useMemo(() => {
56
58
  return renderTrigger ? renderTrigger({
57
59
  selected: selectedItem,
@@ -11,6 +11,7 @@ import { ItemPickerTriggerProps, ItemPickerTriggerTexts } from '../ItemPickerTri
11
11
  import { Action } from './types/actions.types';
12
12
  import { BaseItemType, BaseSectionType, BaseSectionTypeWithFolders } from './types/baseItemSectionType.types';
13
13
  import { ItemPickerListTexts } from './types/itemPickerListTexts.types';
14
+ import { MixedLoaderConfig } from './types/mixedLoader.types';
14
15
  type HeightConfig = {
15
16
  defaultHeight: number;
16
17
  viewportHeightThreshold?: number;
@@ -87,7 +88,7 @@ export type ItemPickerListProps<ItemType extends BaseItemType, SectionType exten
87
88
  scrollbarProps?: ScrollbarAdditionalProps;
88
89
  searchBarProps?: Omit<SearchBarProps, 'value' | 'onSearchChange' | 'placeholder'>;
89
90
  onRefresh?: () => void;
90
- items: ItemType[] | ItemsConfig<ItemType> | ItemLoaderConfig<ItemType>;
91
+ items: ItemType[] | ItemsConfig<ItemType> | ItemLoaderConfig<ItemType> | MixedLoaderConfig<ItemType>;
91
92
  isLoading?: boolean;
92
93
  isVisible?: boolean;
93
94
  sections?: SectionType extends BaseSectionType ? BaseSectionTypeWithFolders<SectionType>[] : undefined;
@@ -11,6 +11,11 @@ type BasicAction = Omit<InheritedFromListItem, 'onClick'> & {
11
11
  id: string | number;
12
12
  text: ReactNode;
13
13
  icon?: ReactNode;
14
+ /**
15
+ * `false` keeps the action out of the list; it is still offered under `/`.
16
+ * @default true
17
+ */
18
+ showInList?: boolean;
14
19
  };
15
20
  type RedirectAction = BasicAction & {
16
21
  actionType: typeof ACTION_TYPES.redirect;
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- type TextsAsReactNode = 'basicSearchPlaceholder' | 'searchPlaceholder' | 'refreshButtonLabel' | 'showMoreResultsLabel' | 'noItems' | 'noResults' | 'noResultsInSection' | 'searchAllFoldersButtonLabel' | 'recentsSectionLabel' | 'actionsSectionLabel' | 'resultsSectionLabel' | 'noActions' | 'emptyStateLabel' | 'itemsSectionLabel' | 'infiniteScrollLoadingMore' | 'infiniteScrollLoadingError' | 'errorMessageTitle' | 'errorMessageDetails' | 'backTooltip' | 'clearSearchTooltip' | 'infiniteScrollAllLoaded';
2
+ type TextsAsReactNode = 'basicSearchPlaceholder' | 'searchPlaceholder' | 'refreshButtonLabel' | 'showMoreResultsLabel' | 'noItems' | 'noResults' | 'noResultsInSection' | 'searchAllFoldersButtonLabel' | 'recentsSectionLabel' | 'actionsSectionLabel' | 'resultsSectionLabel' | 'noActions' | 'emptyStateLabel' | 'itemsSectionLabel' | 'infiniteScrollLoadingMore' | 'infiniteScrollLoadingError' | 'errorMessageTitle' | 'errorMessageDetails' | 'backTooltip' | 'clearSearchTooltip' | 'infiniteScrollAllLoaded' | 'searchInFolderPlaceholder' | 'emptyFolder';
3
3
  export type ItemPickerListTexts = {
4
4
  [key in TextsAsReactNode]: ReactNode;
5
5
  };
@@ -0,0 +1,52 @@
1
+ import { ReactNode } from 'react';
2
+ import { InformationCardProps } from '@synerise/ds-information-card';
3
+ import { BaseItemType } from './baseItemSectionType.types';
4
+ export type FolderNode = {
5
+ id: string;
6
+ text: string;
7
+ /** Second line of a large row. */
8
+ description?: ReactNode;
9
+ disabled?: boolean;
10
+ /** Shown on the right of a disabled default row, or as the second line of a large one. */
11
+ disabledReason?: ReactNode;
12
+ informationCardProps?: InformationCardProps;
13
+ };
14
+ export type LevelEntry<ItemType extends BaseItemType> = ({
15
+ type: 'folder';
16
+ folder: FolderNode;
17
+ } | {
18
+ type: 'item';
19
+ item: ItemType;
20
+ }) & {
21
+ /** Where a search result sits; the second line of a large row in search results. */
22
+ location?: ReactNode;
23
+ };
24
+ /** `id: null` is the root. */
25
+ export type PathStep = {
26
+ id: string | null;
27
+ text: string;
28
+ };
29
+ export type LoadLevelParams = {
30
+ /** `null` is the root. */
31
+ folderId: string | null;
32
+ /** Empty: the level itself. Otherwise: matches from this level and every level below it. */
33
+ searchQuery: string;
34
+ searchKey?: string;
35
+ page: number;
36
+ limit: number;
37
+ abortController?: AbortController;
38
+ };
39
+ export type LoadLevelResult<ItemType extends BaseItemType> = {
40
+ /** One page, folders first. */
41
+ entries: LevelEntry<ItemType>[];
42
+ total: number;
43
+ /** From the root to `folderId`. */
44
+ path: PathStep[];
45
+ };
46
+ export type MixedLoaderConfig<ItemType extends BaseItemType> = {
47
+ loadLevel: (params: LoadLevelParams) => Promise<LoadLevelResult<ItemType>>;
48
+ /** @default 30 */
49
+ limitPerPage?: number;
50
+ /** @default 'default' */
51
+ rowSize?: 'default' | 'large';
52
+ };
@@ -88,6 +88,14 @@ const useDefaultTexts = (texts) => {
88
88
  id: "DS.ITEM-PICKER-DROPDOWN.LOADED-ALL",
89
89
  defaultMessage: "All items loaded"
90
90
  }),
91
+ searchInFolderPlaceholder: intl.formatMessage({
92
+ id: "DS.ITEM-PICKER-DROPDOWN.SEARCH-IN-FOLDER-PLACEHOLDER",
93
+ defaultMessage: "Search in this folder"
94
+ }),
95
+ emptyFolder: intl.formatMessage({
96
+ id: "DS.ITEM-PICKER-DROPDOWN.EMPTY-FOLDER",
97
+ defaultMessage: "This folder is empty"
98
+ }),
91
99
  errorMessageTitle: intl.formatMessage({
92
100
  id: "DS.ITEM-PICKER-DROPDOWN.ERROR-TITLE",
93
101
  defaultMessage: "Items can`t be loaded"
package/dist/index.d.ts CHANGED
@@ -8,5 +8,6 @@ export type { ItemLoaderConfig, ItemLoaderResponse, ItemPickerListProps, ItemPic
8
8
  export type { Action } from './components/ItemPickerNew/types/actions.types';
9
9
  export type { BaseItemType, BaseSectionType, BaseSectionTypeWithFolders, } from './components/ItemPickerNew/types/baseItemSectionType.types';
10
10
  export type { ItemPickerListTexts } from './components/ItemPickerNew/types/itemPickerListTexts.types';
11
+ export type { FolderNode, LevelEntry, LoadLevelParams, LoadLevelResult, MixedLoaderConfig, PathStep, } from './components/ItemPickerNew/types/mixedLoader.types';
11
12
  export { default as ItemPickerTrigger } from './components/ItemPickerTrigger/Trigger';
12
13
  export { default } from './ItemPicker';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-item-picker",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "ItemPicker UI Component for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "Synerise/synerise-design",
@@ -42,27 +42,27 @@
42
42
  ],
43
43
  "types": "dist/index.d.ts",
44
44
  "dependencies": {
45
- "@synerise/ds-avatar": "^2.1.0",
46
- "@synerise/ds-button": "^2.2.0",
47
- "@synerise/ds-dropdown": "^2.2.0",
48
- "@synerise/ds-empty-states": "^2.1.0",
49
- "@synerise/ds-flag": "^2.0.3",
50
- "@synerise/ds-form-field": "^2.1.0",
51
- "@synerise/ds-icon": "^2.3.0",
52
- "@synerise/ds-information-card": "^2.1.0",
53
- "@synerise/ds-inline-alert": "^2.1.0",
54
- "@synerise/ds-list-item": "^2.3.0",
55
- "@synerise/ds-loader": "^2.1.0",
56
- "@synerise/ds-popconfirm": "^2.1.0",
57
- "@synerise/ds-result": "^2.1.0",
58
- "@synerise/ds-scrollbar": "^2.1.0",
59
- "@synerise/ds-search": "^2.1.0",
60
- "@synerise/ds-search-bar": "^2.1.0",
61
- "@synerise/ds-short-cuts": "^2.1.0",
62
- "@synerise/ds-skeleton": "^2.1.0",
63
- "@synerise/ds-tooltip": "^2.1.0",
64
- "@synerise/ds-typography": "^2.1.0",
65
- "@synerise/ds-utils": "^2.3.0",
45
+ "@synerise/ds-avatar": "^2.1.1",
46
+ "@synerise/ds-button": "^2.2.2",
47
+ "@synerise/ds-dropdown": "^2.2.2",
48
+ "@synerise/ds-empty-states": "^2.1.1",
49
+ "@synerise/ds-flag": "^2.0.4",
50
+ "@synerise/ds-form-field": "^2.1.1",
51
+ "@synerise/ds-icon": "^2.3.1",
52
+ "@synerise/ds-information-card": "^2.1.2",
53
+ "@synerise/ds-inline-alert": "^2.1.1",
54
+ "@synerise/ds-list-item": "^2.4.1",
55
+ "@synerise/ds-loader": "^2.1.1",
56
+ "@synerise/ds-popconfirm": "^2.1.2",
57
+ "@synerise/ds-result": "^2.1.2",
58
+ "@synerise/ds-scrollbar": "^2.1.1",
59
+ "@synerise/ds-search": "^2.1.2",
60
+ "@synerise/ds-search-bar": "^2.1.1",
61
+ "@synerise/ds-short-cuts": "^2.1.1",
62
+ "@synerise/ds-skeleton": "^2.1.2",
63
+ "@synerise/ds-tooltip": "^2.1.1",
64
+ "@synerise/ds-typography": "^2.1.1",
65
+ "@synerise/ds-utils": "^2.3.1",
66
66
  "lodash.debounce": "^4.0.8",
67
67
  "react-window": "^1.8.11"
68
68
  },
@@ -76,5 +76,5 @@
76
76
  "react-intl": ">=3.12.0 <= 6.8",
77
77
  "styled-components": "^5.3.3"
78
78
  },
79
- "gitHead": "5c3d61e30289486d14c7d6becb682e2d4a08ce41"
79
+ "gitHead": "4547f33b8c9317ccc697f89a2b2c62bcf97fbec3"
80
80
  }