@constructor-io/constructorio-ui-autocomplete 1.7.0 → 1.7.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.
@@ -1,5 +1,5 @@
1
1
  import { AutocompleteSubmitEvent } from './types';
2
- export declare const apiKey = "key_Gep3oQOu5IMcNh9A";
2
+ export declare const apiKey = "key_M57QS8SMPdLdLx4x";
3
3
  export declare const componentDescription = "- import `CioAutocomplete` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, an `apiKey` or `cioJsClient` are required, and an `onSubmit` callback must be passed. All other values are optional.\n- Use different props to configure the behavior of this component.\n- The following stories shows how different props affect the component's behavior\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
4
4
  export declare const hookDescription = "- import `useCioAutocomplete` and call this custom hook in a functional component.\n- This hook leaves rendering logic up to you, while handling:\n - state management\n - data fetching\n - keyboard navigation\n - mouse interactions\n - focus and submit event handling\n- To use this hook, an `apiKey` or `cioJsClient` are required, and an `onSubmit` callback must be passed to the `useCioAutocomplete` hook to configure behavior. All other values are optional.\n- use the <a href=\"https://kentcdodds.com/blog/how-to-give-rendering-control-to-users-with-prop-getters\" target=\"__blank\">prop getters</a> and other variables returned by this hook (below) to leverage the functionality described above with jsx elements in your react component definitions\n\nCalling the `useCioAutocomplete` hook returns an object with the following keys:\n\n```jsx\nconst {\n // must be used for a hooks integrations\n query: string, // current input field value\n sections: [{...}], // array of sections data to render in menu list\n getFormProps: () => ({...})), // prop getter for jsx form element\n getInputProps: () => ({...})), // prop getter for jsx input element\n getMenuProps: () => ({...})), // prop getter for jsx element rendering the results container\n getItemProps: (item) => ({...})), // prop getter for jsx element rendering each result\n\n // available for use, but not required for all use cases\n selectedItem: item, // undefined or current selected item (via hover or arrow keys)\n isOpen: boolean, // current state of the menu list\n openMenu: () => void, // open menu\n closeMenu: () => void, // close menu\n setQuery: () => void, // update the current input field value\n getLabelProps: () => ({...})), // prop getter for a jsx label element\n cioJsClient, // instance of constructorio-client-javascript\n } = useCioAutocomplete(args);\n```\n\n> Note: when we say `cioJsClient`, we are referring to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n\nThe following stories show how different options affect the hook's behavior!\n";
5
5
  export declare const sectionsDescription = "- by default, typing a query will fetch data for search suggestions and Products\n- to override this, pass an array of sections objects\n- the order of the objects in the `sections` array determines the order of the results\n- each section object must have an `identifier`\n- each section object can specify a `type`\n- each section object can override the default `numResults` of 8\n\nWhen no values are passed for the `sections` argument, the following defaults are used:\n\n```jsx\n[\n {\n identifier: 'Search Suggestions',\n type: 'autocomplete',\n numResults: 8\n },\n {\n identifier: 'Products',\n type: 'autocomplete',\n numResults: 8\n }\n]\n```\n";
@@ -1,9 +1,9 @@
1
- import { CioAutocompleteProps, Item, Section, UserDefinedSection } from '../types';
1
+ import { CioAutocompleteProps, UserDefinedSection } from '../types';
2
2
  export declare const defaultSections: UserDefinedSection[];
3
3
  export type UseCioAutocompleteOptions = Omit<CioAutocompleteProps, 'children'>;
4
4
  declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
5
5
  query: string;
6
- sections: Section[];
6
+ sections: import("../types").Section[];
7
7
  isOpen: boolean;
8
8
  getMenuProps: () => any;
9
9
  getLabelProps: (options?: import("downshift").UseComboboxGetLabelPropsOptions | undefined) => any;
@@ -21,6 +21,6 @@ declare const useCioAutocomplete: (options: UseCioAutocompleteOptions) => {
21
21
  setQuery: import("react").Dispatch<import("react").SetStateAction<string>>;
22
22
  cioClient: import("@constructor-io/constructorio-client-javascript/lib/types/types").Nullable<import("@constructor-io/constructorio-client-javascript")>;
23
23
  autocompleteClassName: string;
24
- selectedItem: Item;
24
+ selectedItem: import("../types").Item;
25
25
  };
26
26
  export default useCioAutocomplete;
@@ -0,0 +1,2 @@
1
+ declare const useConsoleErrors: (sections: any, zeroStateSections: any) => void;
2
+ export default useConsoleErrors;
@@ -9,7 +9,6 @@ type UseDownShiftOptions = {
9
9
  onSubmit: OnSubmit;
10
10
  previousQuery?: string;
11
11
  cioClient: Nullable<ConstructorIOClient>;
12
- onChange?: (string: any) => void;
13
12
  };
14
13
  export type DownShift = UseComboboxReturnValue<Item>;
15
14
  type UseDownShift = (options: UseDownShiftOptions) => DownShift;
@@ -0,0 +1,3 @@
1
+ import { Item, Section } from '../types';
2
+ declare const useItems: (activeSectionsWithData: Section[]) => Item[];
3
+ export default useItems;
@@ -0,0 +1,8 @@
1
+ import ConstructorIO from '@constructor-io/constructorio-client-javascript';
2
+ import { Nullable } from '@constructor-io/constructorio-client-javascript/lib/types/types';
3
+ import { AdvancedParameters, UserDefinedSection } from '../types';
4
+ export default function useSections(query: string, cioClient: Nullable<ConstructorIO>, sections: UserDefinedSection[], zeroStateSections: UserDefinedSection[] | undefined, advancedParameters: AdvancedParameters): {
5
+ activeSections: UserDefinedSection[];
6
+ activeSectionsWithData: import("../types").Section[];
7
+ zeroStateActiveSections: false | UserDefinedSection[] | undefined;
8
+ };
@@ -13,7 +13,7 @@ export type CioAutocompleteProps = CioClientConfig & {
13
13
  openOnFocus?: boolean;
14
14
  onSubmit: OnSubmit;
15
15
  onFocus?: () => void;
16
- onChange?: () => void;
16
+ onChange?: (string: any) => void;
17
17
  placeholder?: string;
18
18
  children?: ReactNode;
19
19
  sections?: UserDefinedSection[];
@@ -1,5 +1,5 @@
1
1
  import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
- import { OnSubmit, Item } from './types';
2
+ import { OnSubmit, Item, Section, UserDefinedSection, AutocompleteResultSections } from './types';
3
3
  export type GetItemPosition = (args: {
4
4
  item: Item;
5
5
  items: Item[];
@@ -23,12 +23,14 @@ export declare const getStoryParams: (storyCode: any, templateCode: any, importC
23
23
  };
24
24
  };
25
25
  };
26
- export declare const defaultOnSubmitCode = "\"onSubmit\": (submitEvent) => console.dir(submitEvent)";
27
- export declare const defaultArgumentsCode: (apiKey: string) => string;
26
+ export declare const functionStrings: {
27
+ onSubmit: string;
28
+ };
28
29
  export declare const stringifyWithDefaults: (obj: {
29
30
  apiKey: string;
30
31
  onSubmit: OnSubmit;
31
- }) => any;
32
+ }) => string;
32
33
  export declare const disableStoryActions: (story: any) => void;
33
34
  export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | null;
35
+ export declare const getActiveSectionsWithData: (activeSections: UserDefinedSection[], sectionResults: AutocompleteResultSections) => Section[];
34
36
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-ui-autocomplete",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "Constructor.io Autocomplete UI library for web applications",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -23,6 +23,7 @@
23
23
  "scripts": {
24
24
  "lint": "eslint src --ext js,ts,jsx,tsx",
25
25
  "check-types": "npx tsc --noEmit",
26
+ "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause'",
26
27
  "copy-styles": "cp src/styles.css lib/styles.css",
27
28
  "prepare": "husky install",
28
29
  "dev": "storybook dev -p 6006",
@@ -82,6 +83,7 @@
82
83
  "eslint-plugin-react-hooks": "^4.6.0",
83
84
  "eslint-plugin-storybook": "^0.6.12",
84
85
  "husky": "^8.0.1",
86
+ "license-checker": "^25.0.1",
85
87
  "react": "^18.2.0",
86
88
  "react-dom": "^18.2.0",
87
89
  "start-server-and-test": "^1.15.2",