downshift 6.1.3 → 6.1.5

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.
@@ -0,0 +1 @@
1
+ export default function downshiftCommonReducer(state: any, action: any, stateChangeTypes: any): any;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export default function downshiftSelectReducer(state: any, action: any): any;
@@ -0,0 +1,23 @@
1
+ export const MenuKeyDownArrowDown: any;
2
+ export const MenuKeyDownArrowUp: any;
3
+ export const MenuKeyDownEscape: any;
4
+ export const MenuKeyDownHome: any;
5
+ export const MenuKeyDownEnd: any;
6
+ export const MenuKeyDownEnter: any;
7
+ export const MenuKeyDownSpaceButton: any;
8
+ export const MenuKeyDownCharacter: any;
9
+ export const MenuBlur: any;
10
+ export const MenuMouseLeave: any;
11
+ export const ItemMouseMove: any;
12
+ export const ItemClick: any;
13
+ export const ToggleButtonClick: any;
14
+ export const ToggleButtonKeyDownArrowDown: any;
15
+ export const ToggleButtonKeyDownArrowUp: any;
16
+ export const ToggleButtonKeyDownCharacter: any;
17
+ export const FunctionToggleMenu: any;
18
+ export const FunctionOpenMenu: any;
19
+ export const FunctionCloseMenu: any;
20
+ export const FunctionSetHighlightedIndex: any;
21
+ export const FunctionSelectItem: any;
22
+ export const FunctionSetInputValue: any;
23
+ export const FunctionReset: any;
@@ -0,0 +1,7 @@
1
+ export interface GetItemIndexByCharacterKeyOptions<Item> {
2
+ keysSoFar: string;
3
+ highlightedIndex: number;
4
+ items: Item[];
5
+ itemToString(item: Item | null): string;
6
+ getItemNodeFromIndex(index: number): HTMLElement | undefined;
7
+ }
@@ -0,0 +1,23 @@
1
+ import { A11yStatusMessageOptions } from '../../types';
2
+ import { GetItemIndexByCharacterKeyOptions } from './types';
3
+ export declare function getItemIndexByCharacterKey<Item>({ keysSoFar, highlightedIndex, items, itemToString, getItemNodeFromIndex, }: GetItemIndexByCharacterKeyOptions<Item>): number;
4
+ /**
5
+ * Default implementation for status message. Only added when menu is open.
6
+ * Will specift if there are results in the list, and if so, how many,
7
+ * and what keys are relevant.
8
+ *
9
+ * @param {Object} param the downshift state and other relevant properties
10
+ * @return {String} the a11y status message
11
+ */
12
+ declare function getA11yStatusMessage<Item>({ isOpen, resultCount, previousResultCount, }: A11yStatusMessageOptions<Item>): string;
13
+ export declare const defaultProps: {
14
+ getA11yStatusMessage: typeof getA11yStatusMessage;
15
+ itemToString: (item: any) => string;
16
+ stateReducer: (s: Object, a: Object) => Object;
17
+ getA11ySelectionMessage: (selectionParameters: Object) => string;
18
+ scrollIntoView: typeof import("../../utils").scrollIntoView;
19
+ circularNavigation: boolean;
20
+ environment: {};
21
+ };
22
+ export declare let validatePropTypes: (options: unknown, caller: Function) => void;
23
+ export {};
@@ -0,0 +1,112 @@
1
+ export let useControlPropsValidator: typeof noop;
2
+ export function useScrollIntoView({ highlightedIndex, isOpen, itemRefs, getItemNodeFromIndex, menuElement, scrollIntoView: scrollIntoViewProp, }: {
3
+ highlightedIndex: any;
4
+ isOpen: any;
5
+ itemRefs: any;
6
+ getItemNodeFromIndex: any;
7
+ menuElement: any;
8
+ scrollIntoView: any;
9
+ }): import("react").MutableRefObject<boolean>;
10
+ export function useA11yMessageSetter(getA11yMessage: any, dependencyArray: any, { isInitialMount, highlightedIndex, items, environment, ...rest }: {
11
+ [x: string]: any;
12
+ isInitialMount: any;
13
+ highlightedIndex: any;
14
+ items: any;
15
+ environment: any;
16
+ }): void;
17
+ export function useGetterPropsCalledChecker(): typeof noop;
18
+ /**
19
+ * Reuse the movement tracking of mouse and touch events.
20
+ *
21
+ * @param {boolean} isOpen Whether the dropdown is open or not.
22
+ * @param {Array<Object>} downshiftElementRefs Downshift element refs to track movement (toggleButton, menu etc.)
23
+ * @param {Object} environment Environment where component/hook exists.
24
+ * @param {Function} handleBlur Handler on blur from mouse or touch.
25
+ * @returns {Object} Ref containing whether mouseDown or touchMove event is happening
26
+ */
27
+ export function useMouseAndTouchTracker(isOpen: boolean, downshiftElementRefs: Array<Object>, environment: Object, handleBlur: Function): Object;
28
+ export function getHighlightedIndexOnOpen(props: any, state: any, offset: any, getItemNodeFromIndex: any): any;
29
+ export function getInitialState(props: any): {
30
+ highlightedIndex: any;
31
+ isOpen: any;
32
+ selectedItem: any;
33
+ inputValue: any;
34
+ };
35
+ export function getInitialValue(props: any, propKey: any, defaultStateValues?: {
36
+ highlightedIndex: number;
37
+ isOpen: boolean;
38
+ selectedItem: null;
39
+ inputValue: string;
40
+ }): any;
41
+ export function getDefaultValue(props: any, propKey: any, defaultStateValues?: {
42
+ highlightedIndex: number;
43
+ isOpen: boolean;
44
+ selectedItem: null;
45
+ inputValue: string;
46
+ }): any;
47
+ export namespace defaultProps {
48
+ export { itemToString };
49
+ export { stateReducer };
50
+ export { getA11ySelectionMessage };
51
+ export { scrollIntoView };
52
+ export const circularNavigation: boolean;
53
+ export const environment: {};
54
+ }
55
+ /**
56
+ * Wraps the useEnhancedReducer and applies the controlled prop values before
57
+ * returning the new state.
58
+ *
59
+ * @param {Function} reducer Reducer function from downshift.
60
+ * @param {Object} initialState Initial state of the hook.
61
+ * @param {Object} props The hook props.
62
+ * @returns {Array} An array with the state and an action dispatcher.
63
+ */
64
+ export function useControlledReducer(reducer: Function, initialState: Object, props: Object): any[];
65
+ /**
66
+ * Computes the controlled state using a the previous state, props,
67
+ * two reducers, one from downshift and an optional one from the user.
68
+ * Also calls the onChange handlers for state values that have changed.
69
+ *
70
+ * @param {Function} reducer Reducer function from downshift.
71
+ * @param {Object} initialState Initial state of the hook.
72
+ * @param {Object} props The hook props.
73
+ * @returns {Array} An array with the state and an action dispatcher.
74
+ */
75
+ export function useEnhancedReducer(reducer: Function, initialState: Object, props: Object): any[];
76
+ export function useLatestRef(val: any): import("react").MutableRefObject<any>;
77
+ export function capitalizeString(string: any): string;
78
+ export function isAcceptedCharacterKey(key: any): boolean;
79
+ export function getItemIndex(index: any, item: any, items: any): any;
80
+ export function useElementIds({ id, labelId, menuId, getItemId, toggleButtonId, inputId, }: {
81
+ id?: string | undefined;
82
+ labelId: any;
83
+ menuId: any;
84
+ getItemId: any;
85
+ toggleButtonId: any;
86
+ inputId: any;
87
+ }): {
88
+ labelId: any;
89
+ menuId: any;
90
+ getItemId: any;
91
+ toggleButtonId: any;
92
+ inputId: any;
93
+ };
94
+ import { noop } from "../utils";
95
+ declare function itemToString(item: any): string;
96
+ /**
97
+ * Default state reducer that returns the changes.
98
+ *
99
+ * @param {Object} s state.
100
+ * @param {Object} a action with changes.
101
+ * @returns {Object} changes.
102
+ */
103
+ declare function stateReducer(s: Object, a: Object): Object;
104
+ /**
105
+ * Returns a message to be added to aria-live region when item is selected.
106
+ *
107
+ * @param {Object} selectionParameters Parameters required to build the message.
108
+ * @returns {string} The a11y message.
109
+ */
110
+ declare function getA11ySelectionMessage(selectionParameters: Object): string;
111
+ import { scrollIntoView } from "../utils";
112
+ export {};
@@ -0,0 +1,2 @@
1
+ declare const _exports: any;
2
+ export = _exports;
@@ -0,0 +1,2 @@
1
+ declare const _exports: any;
2
+ export = _exports;
@@ -0,0 +1,6 @@
1
+ export default setStatus;
2
+ /**
3
+ * @param {String} status the status message
4
+ * @param {Object} documentProp document passed by the user.
5
+ */
6
+ declare function setStatus(status: string, documentProp: Object): void;
@@ -0,0 +1,10 @@
1
+ export interface A11yStatusMessageOptions<Item> {
2
+ highlightedIndex: number | null;
3
+ inputValue: string;
4
+ isOpen: boolean;
5
+ itemToString: (item: Item | null) => string;
6
+ previousResultCount: number;
7
+ resultCount: number;
8
+ highlightedItem: Item;
9
+ selectedItem: Item | null;
10
+ }
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Accepts a parameter and returns it if it's a function
3
+ * or a noop function if it's not. This allows us to
4
+ * accept a callback, but not worry about it if it's not
5
+ * passed.
6
+ * @param {Function} cb the callback
7
+ * @return {Function} a function
8
+ */
9
+ export function cbToCb(cb: Function): Function;
10
+ /**
11
+ * This is intended to be used to compose event handlers.
12
+ * They are executed in order until one of them sets
13
+ * `event.preventDownshiftDefault = true`.
14
+ * @param {...Function} fns the event handler functions
15
+ * @return {Function} the event handler to add to an element
16
+ */
17
+ export function callAllEventHandlers(...fns: Function[]): Function;
18
+ export function handleRefs(...refs: any[]): (node: any) => void;
19
+ /**
20
+ * Simple debounce implementation. Will call the given
21
+ * function once after the time given has passed since
22
+ * it was last called.
23
+ * @param {Function} fn the function to call after the time
24
+ * @param {Number} time the time to wait
25
+ * @return {Function} the debounced function
26
+ */
27
+ export function debounce(fn: Function, time: number): Function;
28
+ /**
29
+ * Scroll node into view if necessary
30
+ * @param {HTMLElement} node the element that should scroll into view
31
+ * @param {HTMLElement} menuNode the menu element of the component
32
+ */
33
+ export function scrollIntoView(node: HTMLElement, menuNode: HTMLElement): void;
34
+ /**
35
+ * This generates a unique ID for an instance of Downshift
36
+ * @return {String} the unique ID
37
+ */
38
+ export function generateId(): string;
39
+ /**
40
+ * Default implementation for status message. Only added when menu is open.
41
+ * Will specify if there are results in the list, and if so, how many,
42
+ * and what keys are relevant.
43
+ *
44
+ * @param {Object} param the downshift state and other relevant properties
45
+ * @return {String} the a11y status message
46
+ */
47
+ export function getA11yStatusMessage({ isOpen, resultCount, previousResultCount }: Object): string;
48
+ /**
49
+ * Takes an argument and if it's an array, returns the first item in the array
50
+ * otherwise returns the argument
51
+ * @param {*} arg the maybe-array
52
+ * @param {*} defaultValue the value if arg is falsey not defined
53
+ * @return {*} the arg or it's first item
54
+ */
55
+ export function unwrapArray(arg: any, defaultValue: any): any;
56
+ /**
57
+ * @param {Object} element (P)react element
58
+ * @return {Boolean} whether it's a DOM element
59
+ */
60
+ export function isDOMElement(element: Object): boolean;
61
+ /**
62
+ * @param {Object} element (P)react element
63
+ * @return {Object} the props
64
+ */
65
+ export function getElementProps(element: Object): Object;
66
+ export function noop(): void;
67
+ /**
68
+ * Throws a helpful error message for required properties. Useful
69
+ * to be used as a default in destructuring or object params.
70
+ * @param {String} fnName the function name
71
+ * @param {String} propName the prop name
72
+ */
73
+ export function requiredProp(fnName: string, propName: string): void;
74
+ /**
75
+ * This is only used in tests
76
+ * @param {Number} num the number to set the idCounter to
77
+ */
78
+ export function setIdCounter(num: number): void;
79
+ /**
80
+ * Resets idCounter to 0. Used for SSR.
81
+ */
82
+ export function resetIdCounter(): void;
83
+ /**
84
+ * @param {Object} state the state object
85
+ * @return {Object} state that is relevant to downshift
86
+ */
87
+ export function pickState(state?: Object): Object;
88
+ /**
89
+ * Simple check if the value passed is object literal
90
+ * @param {*} obj any things
91
+ * @return {Boolean} whether it's object literal
92
+ */
93
+ export function isPlainObject(obj: any): boolean;
94
+ /**
95
+ * Normalizes the 'key' property of a KeyboardEvent in IE/Edge
96
+ * @param {Object} event a keyboardEvent object
97
+ * @return {String} keyboard key
98
+ */
99
+ export function normalizeArrowKey(event: Object): string;
100
+ /**
101
+ * Returns the new index in the list, in a circular way. If next value is out of bonds from the total,
102
+ * it will wrap to either 0 or itemCount - 1.
103
+ *
104
+ * @param {number} moveAmount Number of positions to move. Negative to move backwards, positive forwards.
105
+ * @param {number} baseIndex The initial position to move from.
106
+ * @param {number} itemCount The total number of items.
107
+ * @param {Function} getItemNodeFromIndex Used to check if item is disabled.
108
+ * @param {boolean} circular Specify if navigation is circular. Default is true.
109
+ * @returns {number} The new index after the move.
110
+ */
111
+ export function getNextWrappingIndex(moveAmount: number, baseIndex: number, itemCount: number, getItemNodeFromIndex: Function, circular?: boolean): number;
112
+ /**
113
+ * Returns the next index in the list of an item that is not disabled.
114
+ *
115
+ * @param {number} moveAmount Number of positions to move. Negative to move backwards, positive forwards.
116
+ * @param {number} baseIndex The initial position to move from.
117
+ * @param {number} itemCount The total number of items.
118
+ * @param {Function} getItemNodeFromIndex Used to check if item is disabled.
119
+ * @param {boolean} circular Specify if navigation is circular. Default is true.
120
+ * @returns {number} The new index. Returns baseIndex if item is not disabled. Returns next non-disabled item otherwise. If no non-disabled found it will return -1.
121
+ */
122
+ export function getNextNonDisabledIndex(moveAmount: number, baseIndex: number, itemCount: number, getItemNodeFromIndex: Function, circular: boolean): number;
123
+ /**
124
+ * Checks if event target is within the downshift elements.
125
+ *
126
+ * @param {EventTarget} target Target to check.
127
+ * @param {HTMLElement[]} downshiftElements The elements that form downshift (list, toggle button etc).
128
+ * @param {Window} environment The window context where downshift renders.
129
+ * @param {boolean} checkActiveElement Whether to also check activeElement.
130
+ *
131
+ * @returns {boolean} Whether or not the target is within downshift elements.
132
+ */
133
+ export function targetWithinDownshift(target: EventTarget, downshiftElements: HTMLElement[], environment: Window, checkActiveElement?: boolean): boolean;
134
+ /**
135
+ * This will perform a shallow merge of the given state object
136
+ * with the state coming from props
137
+ * (for the controlled component scenario)
138
+ * This is used in state updater functions so they're referencing
139
+ * the right state regardless of where it comes from.
140
+ *
141
+ * @param {Object} state The state of the component/hook.
142
+ * @param {Object} props The props that may contain controlled values.
143
+ * @returns {Object} The merged controlled state.
144
+ */
145
+ export function getState(state: Object, props: Object): Object;
146
+ /**
147
+ * This determines whether a prop is a "controlled prop" meaning it is
148
+ * state which is controlled by the outside of this component rather
149
+ * than within this component.
150
+ *
151
+ * @param {Object} props The props that may contain controlled values.
152
+ * @param {String} key the key to check
153
+ * @return {Boolean} whether it is a controlled controlled prop
154
+ */
155
+ export function isControlledProp(props: Object, key: string): boolean;
156
+ export function validateControlledUnchanged(): void;
File without changes
File without changes
@@ -0,0 +1 @@
1
+ import '@testing-library/jest-dom/extend-expect';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "downshift",
3
- "version": "6.1.3",
3
+ "version": "6.1.5",
4
4
  "description": "🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.",
5
5
  "main": "dist/downshift.cjs.js",
6
6
  "react-native": "dist/downshift.native.cjs.js",
@@ -66,73 +66,74 @@
66
66
  "react": ">=16.12.0"
67
67
  },
68
68
  "dependencies": {
69
- "@babel/runtime": "^7.13.10",
69
+ "@babel/runtime": "^7.14.8",
70
70
  "compute-scroll-into-view": "^1.0.17",
71
71
  "prop-types": "^15.7.2",
72
72
  "react-is": "^17.0.2"
73
73
  },
74
74
  "devDependencies": {
75
- "@babel/helpers": "^7.13.10",
76
- "@rollup/plugin-commonjs": "^18.0.0",
77
- "@testing-library/cypress": "^7.0.6",
78
- "@testing-library/dom": "^7.30.3",
79
- "@testing-library/jest-dom": "^5.11.10",
75
+ "@babel/helpers": "^7.14.8",
76
+ "@rollup/plugin-babel": "^5.3.0",
77
+ "@rollup/plugin-commonjs": "^20.0.0",
78
+ "@rollup/plugin-typescript": "^8.2.5",
79
+ "@testing-library/cypress": "^8.0.0",
80
+ "@testing-library/dom": "^8.1.0",
81
+ "@testing-library/jest-dom": "^5.14.1",
80
82
  "@testing-library/preact": "^2.0.1",
81
- "@testing-library/react": "^11.2.6",
82
- "@testing-library/react-hooks": "^5.1.1",
83
- "@testing-library/user-event": "^13.1.4",
84
- "@types/jest": "^26.0.22",
85
- "@types/react": "^17.0.3",
86
- "babel-plugin-macros": "^3.0.1",
83
+ "@testing-library/react": "^12.0.0",
84
+ "@testing-library/react-hooks": "^7.0.1",
85
+ "@testing-library/user-event": "^13.2.1",
86
+ "@types/jest": "^26.0.24",
87
+ "@types/react": "^17.0.15",
88
+ "@typescript-eslint/eslint-plugin": "^4.28.5",
89
+ "@typescript-eslint/parser": "^4.28.5",
90
+ "babel-plugin-macros": "^3.1.0",
87
91
  "babel-plugin-no-side-effect-class-properties": "0.0.7",
88
92
  "babel-preset-react-native": "^4.0.1",
89
93
  "buble": "^0.20.0",
90
94
  "cpy-cli": "^3.1.1",
91
95
  "cross-env": "^7.0.3",
92
- "cypress": "^7.1.0",
96
+ "cypress": "^8.1.0",
93
97
  "docz": "^2.3.1",
94
98
  "docz-theme-default": "^1.2.0",
95
- "eslint-plugin-cypress": "^2.11.2",
96
- "eslint-plugin-react": "7.23.1",
97
- "flow-bin": "^0.148.0",
99
+ "eslint": "^7.32.0",
100
+ "eslint-plugin-cypress": "^2.11.3",
101
+ "eslint-plugin-react": "7.24.0",
102
+ "flow-bin": "^0.156.0",
98
103
  "flow-coverage-report": "^0.8.0",
99
- "kcd-scripts": "^9.0.0",
104
+ "get-pkg-repo": "4.1.1",
105
+ "kcd-scripts": "^11.2.0",
100
106
  "npm-run-all": "^4.1.5",
101
- "preact": "^10.5.13",
102
- "react": "^16.13.1",
107
+ "preact": "^10.5.14",
108
+ "react": "^17.0.2",
103
109
  "react-dom": "^17.0.2",
104
- "react-native": "^0.64.0",
110
+ "react-native": "^0.64.2",
105
111
  "react-test-renderer": "^17.0.2",
106
- "rollup-plugin-babel": "^4.4.0",
107
- "serve": "^11.3.2",
108
- "start-server-and-test": "^1.12.1",
109
- "typescript": "^4.2.4"
112
+ "serve": "^12.0.0",
113
+ "start-server-and-test": "^1.13.1",
114
+ "typescript": "^4.3.5"
110
115
  },
111
116
  "eslintConfig": {
117
+ "settings": {
118
+ "import/resolver": {
119
+ "node": {
120
+ "extensions": [
121
+ ".js",
122
+ ".jsx",
123
+ ".ts",
124
+ ".tsx"
125
+ ]
126
+ }
127
+ }
128
+ },
112
129
  "extends": "./node_modules/kcd-scripts/eslint.js",
113
130
  "rules": {
114
- "eqeqeq": "off",
115
- "import/no-useless-path-segments": "off",
116
- "import/no-unassigned-import": "off",
117
- "max-lines": "off",
118
- "max-lines-per-function": "off",
119
- "no-eq-null": "off",
120
131
  "react/jsx-indent": "off",
121
132
  "react/prop-types": "off",
133
+ "max-lines-per-function": "off",
122
134
  "jsx-a11y/label-has-for": "off",
123
135
  "jsx-a11y/label-has-associated-control": "off",
124
136
  "jsx-a11y/autocomplete-valid": "off",
125
- "complexity": [
126
- "error",
127
- 12
128
- ],
129
- "no-unsafe-optional-chaining": "off",
130
- "no-loss-of-precision": "off",
131
- "no-unreachable-loop": "off",
132
- "no-useless-backreference": "off",
133
- "default-case-last": "off",
134
- "no-nonoctal-decimal-escape": "off",
135
- "id-denylist": "off",
136
137
  "testing-library/prefer-user-event": "off",
137
138
  "testing-library/no-node-access": "off",
138
139
  "testing-library/no-container": "off",