@snack-uikit/list 0.4.2-preview-3bc93fc3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # 0.5.0 (2024-02-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * **FF-4237:** add onmousedown handling ([1d9347a](https://github.com/cloud-ru-tech/snack-uikit/commit/1d9347a73c24b439d09bde236ebee84cb3843cf4))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.4.1 (2024-02-26)
7
18
 
8
19
  ### Only dependencies have been changed
package/README.md CHANGED
@@ -8,36 +8,11 @@
8
8
 
9
9
  [//]: DOCUMENTATION_SECTION_START
10
10
  [//]: THIS_SECTION_IS_AUTOGENERATED_PLEASE_DONT_EDIT_IT
11
- ## useFuzzySearch
12
- Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
13
- ### Props
14
- | name | type | default value | description |
15
- |------|------|---------------|-------------|
16
11
  ## extractChildIds
17
12
  ### Props
18
13
  | name | type | default value | description |
19
14
  |------|------|---------------|-------------|
20
15
  | items* | `ItemProps[]` | - | |
21
- ## flattenItems
22
- `flattenItems`
23
-
24
- Функция разворачивает массив айтемов в плоский список
25
- ## isAccordionItemProps
26
- ### Props
27
- | name | type | default value | description |
28
- |------|------|---------------|-------------|
29
- ## isBaseItemProps
30
- ### Props
31
- | name | type | default value | description |
32
- |------|------|---------------|-------------|
33
- ## isGroupItemProps
34
- ### Props
35
- | name | type | default value | description |
36
- |------|------|---------------|-------------|
37
- ## isNextListItemProps
38
- ### Props
39
- | name | type | default value | description |
40
- |------|------|---------------|-------------|
41
16
  ## useGroupItemSelection
42
17
  ### Props
43
18
  | name | type | default value | description |
@@ -5,5 +5,5 @@ type AllBaseItemProps = BaseItemProps & BaseItemPrivateProps & {
5
5
  onSelect?(): void;
6
6
  isParentNode?: boolean;
7
7
  };
8
- export declare function BaseItem({ beforeContent, afterContent, content, onClick, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender, ...rest }: AllBaseItemProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
8
+ export declare function BaseItem({ beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender, ...rest }: AllBaseItemProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
9
9
  export {};
@@ -19,7 +19,7 @@ import commonStyles from '../styles.module.css';
19
19
  import { CHECKBOX_SIZE_MAP } from './constants';
20
20
  import styles from './styles.module.css';
21
21
  export function BaseItem(_a) {
22
- var { beforeContent, afterContent, content, onClick, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "onSelect", "isParentNode", "className", "inactive", "itemWrapRender"]);
22
+ var { beforeContent, afterContent, content, onClick, onMouseDown, id, expandIcon, disabled, open, itemRef, switch: switchProp, onKeyDown, onFocus, indeterminate, onSelect, isParentNode, className, inactive, itemWrapRender } = _a, rest = __rest(_a, ["beforeContent", "afterContent", "content", "onClick", "onMouseDown", "id", "expandIcon", "disabled", "open", "itemRef", "switch", "onKeyDown", "onFocus", "indeterminate", "onSelect", "isParentNode", "className", "inactive", "itemWrapRender"]);
23
23
  const { option, caption, description } = content || {};
24
24
  const interactive = !inactive;
25
25
  const { parentResetActiveFocusIndex } = useParentListContext();
@@ -70,7 +70,7 @@ export function BaseItem(_a) {
70
70
  e.stopPropagation();
71
71
  };
72
72
  const props = extractSupportProps(rest);
73
- const item = (_jsxs("li", { role: 'menuitem', "data-test-id": props['data-test-id'] || 'list__base-item_' + id, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem, className), "data-size": size, onClick: handleItemClick, tabIndex: -1, "data-non-pointer": inactive && !onClick, "data-inactive": inactive || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "data-disabled": disabled || undefined, "aria-disabled": disabled || undefined, "data-parent": parent || 'list', onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, children: [!switchProp && isSelectionSingle && marker && !isParentNode && interactive && (_jsx("div", { className: styles.markerContainer, "data-test-id": 'list__base-item-marker' })), !switchProp && isSelectionMultiple && interactive && (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: CHECKBOX_SIZE_MAP[size !== null && size !== void 0 ? size : 's'], disabled: disabled, tabIndex: -1, onChange: handleCheckboxChange, checked: isChecked, "data-test-id": 'list__base-item-checkbox', onClick: handleCheckboxClick, indeterminate: indeterminate }) })), beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), _jsxs("div", { className: styles.content, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.option, children: _jsx(TruncateString, { text: option, maxLines: 1 }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: 2 }) }))] }), afterContent, switchProp && interactive && (_jsx(Switch, { disabled: disabled, checked: isChecked, "data-test-id": 'list__base-item-switch' })), !switchProp && expandIcon && _jsx("span", { className: styles.expandableIcon, children: expandIcon })] }));
73
+ const item = (_jsxs("li", { role: 'menuitem', "data-test-id": props['data-test-id'] || 'list__base-item_' + id, ref: itemRef, className: cn(commonStyles.listItem, styles.droplistItem, className), "data-size": size, onClick: handleItemClick, onMouseDown: onMouseDown, tabIndex: -1, "data-non-pointer": inactive && !onClick, "data-inactive": inactive || undefined, "data-checked": (isParentNode && (indeterminate || isChecked)) || (isChecked && !switchProp) || undefined, "data-variant": mode || undefined, "data-open": open || undefined, "data-disabled": disabled || undefined, "aria-disabled": disabled || undefined, "data-parent": parent || 'list', onKeyDown: handleItemKeyDown, onFocus: handleItemFocus, style: { '--level': level }, children: [!switchProp && isSelectionSingle && marker && !isParentNode && interactive && (_jsx("div", { className: styles.markerContainer, "data-test-id": 'list__base-item-marker' })), !switchProp && isSelectionMultiple && interactive && (_jsx("div", { className: styles.checkbox, children: _jsx(Checkbox, { size: CHECKBOX_SIZE_MAP[size !== null && size !== void 0 ? size : 's'], disabled: disabled, tabIndex: -1, onChange: handleCheckboxChange, checked: isChecked, "data-test-id": 'list__base-item-checkbox', onClick: handleCheckboxClick, indeterminate: indeterminate }) })), beforeContent && _jsx("div", { className: styles.beforeContent, children: beforeContent }), _jsxs("div", { className: styles.content, children: [_jsxs("div", { className: styles.headline, children: [_jsx("span", { className: styles.option, children: _jsx(TruncateString, { text: option, maxLines: 1 }) }), caption && _jsx("span", { className: styles.caption, children: caption })] }), description && (_jsx("div", { className: styles.description, children: _jsx(TruncateString, { text: description, maxLines: 2 }) }))] }), afterContent, switchProp && interactive && (_jsx(Switch, { disabled: disabled, checked: isChecked, "data-test-id": 'list__base-item-switch' })), !switchProp && expandIcon && _jsx("span", { className: styles.expandableIcon, children: expandIcon })] }));
74
74
  if (!itemWrapRender) {
75
75
  return item;
76
76
  }
@@ -26,6 +26,8 @@ export type BaseItemProps = WithSupportProps<{
26
26
  content: ItemContentProps;
27
27
  /** Колбек обработки клика */
28
28
  onClick?(e: MouseEvent<HTMLElement>): void;
29
+ /** Колбек обработки нажатия кнопки мыши */
30
+ onMouseDown?(e: MouseEvent<HTMLElement>): void;
29
31
  /** Колбек обработки нажатия клавиши */
30
32
  onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
31
33
  /** Колбек обработки фокуса */
@@ -1,4 +1,3 @@
1
1
  export * from './Lists';
2
- export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
3
- export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
2
+ export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items/types';
4
3
  export { useGroupItemSelection } from './Items/hooks';
@@ -1,3 +1,2 @@
1
1
  export * from './Lists';
2
- export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
3
2
  export { useGroupItemSelection } from './Items/hooks';
package/dist/hooks.d.ts CHANGED
@@ -1,5 +1,2 @@
1
1
  import { ItemProps } from './components/Items';
2
- /**
3
- * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
4
- */
5
2
  export declare function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number): (search: string) => ItemProps[];
package/dist/hooks.js CHANGED
@@ -1,10 +1,24 @@
1
1
  import FuzzySearch from 'fuzzy-search';
2
2
  import { useCallback } from 'react';
3
- import { flattenItems } from './utils';
3
+ import { isGroupItemProps } from './components/Items';
4
+ function flattenItems(items) {
5
+ const flattenedItems = [];
6
+ function flatten(item) {
7
+ if (!isGroupItemProps(item)) {
8
+ flattenedItems.push(item);
9
+ }
10
+ if ('items' in item) {
11
+ for (const nestedItem of item.items) {
12
+ flatten(nestedItem);
13
+ }
14
+ }
15
+ }
16
+ for (const item of items) {
17
+ flatten(item);
18
+ }
19
+ return flattenedItems;
20
+ }
4
21
  const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
5
- /**
6
- * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
7
- */
8
22
  export function useFuzzySearch(items, minSearchInputLength) {
9
23
  return useCallback((search) => {
10
24
  const searcher = new FuzzySearch(flattenItems(items), ['content.option', 'content.caption', 'content.description', 'label'], {});
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './components';
2
2
  export { useFuzzySearch } from './hooks';
3
3
  export type { SearchState } from './types';
4
- export { extractChildIds, flattenItems } from './utils';
4
+ export { extractChildIds } from './utils';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export * from './components';
2
2
  export { useFuzzySearch } from './hooks';
3
- export { extractChildIds, flattenItems } from './utils';
3
+ export { extractChildIds } from './utils';
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- import { AccordionItemProps, BaseItemProps, ItemProps, NextListItemProps } from './components/Items';
2
+ import { ItemProps } from './components/Items';
3
3
  type WithCollapsedItemsProps = {
4
4
  items: ItemProps[];
5
5
  openCollapsedItems: Array<number | string>;
@@ -11,10 +11,6 @@ export declare function withCollapsedItems({ items, openCollapsedItems }: WithCo
11
11
  expandedIds: (string | number)[];
12
12
  };
13
13
  export declare function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[];
14
- /**
15
- * Функция возвращает массив id дочерних items
16
- * @function extractItemIds
17
- */
18
14
  export declare function extractItemIds(items: ItemProps[]): Array<string | number>;
19
15
  export declare function extractChildIds({ items }: {
20
16
  items: ItemProps[];
@@ -22,9 +18,4 @@ export declare function extractChildIds({ items }: {
22
18
  export declare function extractAllChildIds({ items }: {
23
19
  items: ItemProps[];
24
20
  }): Array<string | number>;
25
- /**
26
- *  Функция разворачивает массив айтемов в плоский список
27
- * @function flattenItems
28
- */
29
- export declare function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[];
30
21
  export {};
package/dist/utils.js CHANGED
@@ -46,10 +46,6 @@ export function extractItemRefs(items) {
46
46
  return item.itemRef ? prev.concat([item.itemRef]) : prev;
47
47
  }, []);
48
48
  }
49
- /**
50
- * Функция возвращает массив id дочерних items
51
- * @function extractItemIds
52
- */
53
49
  export function extractItemIds(items) {
54
50
  return items.reduce((prev, item) => {
55
51
  if (isGroupItemProps(item)) {
@@ -92,24 +88,3 @@ export function extractAllChildIds({ items }) {
92
88
  return item.id && !isGroupItemProps(item) ? prev.concat([item.id]) : prev;
93
89
  }, []);
94
90
  }
95
- /**
96
- *  Функция разворачивает массив айтемов в плоский список
97
- * @function flattenItems
98
- */
99
- export function flattenItems(items) {
100
- const flattenedItems = [];
101
- function flatten(item) {
102
- if (!isGroupItemProps(item)) {
103
- flattenedItems.push(item);
104
- }
105
- if ('items' in item) {
106
- for (const nestedItem of item.items) {
107
- flatten(nestedItem);
108
- }
109
- }
110
- }
111
- for (const item of items) {
112
- flatten(item);
113
- }
114
- return flattenedItems;
115
- }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public"
5
5
  },
6
6
  "title": "List",
7
- "version": "0.4.2-preview-3bc93fc3.0",
7
+ "version": "0.5.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -32,7 +32,7 @@
32
32
  "license": "Apache-2.0",
33
33
  "scripts": {},
34
34
  "dependencies": {
35
- "@snack-uikit/divider": "3.0.2-preview-3bc93fc3.0",
35
+ "@snack-uikit/divider": "3.0.1",
36
36
  "@snack-uikit/dropdown": "0.2.0",
37
37
  "@snack-uikit/icons": "0.20.1",
38
38
  "@snack-uikit/info-block": "0.3.0",
@@ -54,5 +54,5 @@
54
54
  "peerDependencies": {
55
55
  "@snack-uikit/locale": "*"
56
56
  },
57
- "gitHead": "a2fa7717157c8a23fa1fc6b64c67c7b2d9dfc39c"
57
+ "gitHead": "bfdd4a8e3c077eab0d45e177172a62b6dcbda06b"
58
58
  }
@@ -19,6 +19,7 @@ export function BaseItem({
19
19
  afterContent,
20
20
  content,
21
21
  onClick,
22
+ onMouseDown,
22
23
  id,
23
24
  expandIcon,
24
25
  disabled,
@@ -107,6 +108,7 @@ export function BaseItem({
107
108
  className={cn(commonStyles.listItem, styles.droplistItem, className)}
108
109
  data-size={size}
109
110
  onClick={handleItemClick}
111
+ onMouseDown={onMouseDown}
110
112
  tabIndex={-1}
111
113
  data-non-pointer={inactive && !onClick}
112
114
  data-inactive={inactive || undefined}
@@ -32,6 +32,8 @@ export type BaseItemProps = WithSupportProps<{
32
32
 
33
33
  /** Колбек обработки клика */
34
34
  onClick?(e: MouseEvent<HTMLElement>): void;
35
+ /** Колбек обработки нажатия кнопки мыши */
36
+ onMouseDown?(e: MouseEvent<HTMLElement>): void;
35
37
  /** Колбек обработки нажатия клавиши */
36
38
  onKeyDown?(e: KeyboardEvent<HTMLElement>): void;
37
39
  /** Колбек обработки фокуса */
@@ -1,6 +1,5 @@
1
1
  export * from './Lists';
2
2
 
3
- export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items';
4
- export { isAccordionItemProps, isBaseItemProps, isGroupItemProps, isNextListItemProps } from './Items';
3
+ export type { AccordionItemProps, NextListItemProps, BaseItemProps, GroupItemProps, ItemProps } from './Items/types';
5
4
 
6
5
  export { useGroupItemSelection } from './Items/hooks';
package/src/hooks.ts CHANGED
@@ -1,14 +1,32 @@
1
1
  import FuzzySearch from 'fuzzy-search';
2
2
  import { useCallback } from 'react';
3
3
 
4
- import { ItemProps } from './components/Items';
5
- import { flattenItems } from './utils';
4
+ import { isGroupItemProps, ItemProps } from './components/Items';
5
+
6
+ function flattenItems(items: ItemProps[]): ItemProps[] {
7
+ const flattenedItems: ItemProps[] = [];
8
+
9
+ function flatten(item: ItemProps) {
10
+ if (!isGroupItemProps(item)) {
11
+ flattenedItems.push(item);
12
+ }
13
+
14
+ if ('items' in item) {
15
+ for (const nestedItem of item.items) {
16
+ flatten(nestedItem);
17
+ }
18
+ }
19
+ }
20
+
21
+ for (const item of items) {
22
+ flatten(item);
23
+ }
24
+
25
+ return flattenedItems;
26
+ }
6
27
 
7
28
  const DEFAULT_MIN_SEARCH_INPUT_LENGTH = 2;
8
29
 
9
- /**
10
- * Нечеткий поиск среди айтемов по полям 'content.option', 'content.caption', 'content.description', 'label'
11
- */
12
30
  export function useFuzzySearch(items: ItemProps[], minSearchInputLength?: number) {
13
31
  return useCallback(
14
32
  (search: string) => {
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './components';
2
2
  export { useFuzzySearch } from './hooks';
3
3
  export type { SearchState } from './types';
4
- export { extractChildIds, flattenItems } from './utils';
4
+ export { extractChildIds } from './utils';
package/src/utils.ts CHANGED
@@ -1,14 +1,11 @@
1
1
  import { RefObject } from 'react';
2
2
 
3
3
  import {
4
- AccordionItemProps,
5
- BaseItemProps,
6
4
  isAccordionItemProps,
7
5
  isBaseItemProps,
8
6
  isGroupItemProps,
9
7
  isNextListItemProps,
10
8
  ItemProps,
11
- NextListItemProps,
12
9
  } from './components/Items';
13
10
 
14
11
  type WithCollapsedItemsProps = {
@@ -80,11 +77,6 @@ export function extractItemRefs(items: ItemProps[]): RefObject<HTMLElement>[] {
80
77
  }, [] as RefObject<HTMLElement>[]);
81
78
  }
82
79
 
83
- /**
84
- * Функция возвращает массив id дочерних items
85
- * @function extractItemIds
86
- */
87
-
88
80
  export function extractItemIds(items: ItemProps[]): Array<string | number> {
89
81
  return items.reduce(
90
82
  (prev: Array<string | number>, item: ItemProps) => {
@@ -146,30 +138,3 @@ export function extractAllChildIds({ items }: { items: ItemProps[] }): Array<str
146
138
  [] as Array<string | number>,
147
139
  );
148
140
  }
149
-
150
- /**
151
- *  Функция разворачивает массив айтемов в плоский список
152
- * @function flattenItems
153
- */
154
-
155
- export function flattenItems(items: ItemProps[]): (BaseItemProps | AccordionItemProps | NextListItemProps)[] {
156
- const flattenedItems: (BaseItemProps | AccordionItemProps | NextListItemProps)[] = [];
157
-
158
- function flatten(item: ItemProps) {
159
- if (!isGroupItemProps(item)) {
160
- flattenedItems.push(item);
161
- }
162
-
163
- if ('items' in item) {
164
- for (const nestedItem of item.items) {
165
- flatten(nestedItem);
166
- }
167
- }
168
- }
169
-
170
- for (const item of items) {
171
- flatten(item);
172
- }
173
-
174
- return flattenedItems;
175
- }