@algolia/autocomplete-js
Advanced tools
Comparing version 1.0.0-alpha.34 to 1.0.0-alpha.35
import { AutocompleteOptions, AutocompleteApi } from './types'; | ||
export declare function autocomplete<TItem>({ container, render: renderDropdown, dropdownPlacement, classNames, ...props }: AutocompleteOptions<TItem>): AutocompleteApi<TItem>; | ||
export declare function autocomplete<TItem>({ container, render: renderPanel, panelPlacement, classNames, ...props }: AutocompleteOptions<TItem>): AutocompleteApi<TItem>; |
@@ -20,4 +20,4 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
import { debounce } from './debounce'; | ||
import { getDropdownPositionStyle } from './getDropdownPositionStyle'; | ||
import { getHTMLElement } from './getHTMLElement'; | ||
import { getPanelPositionStyle } from './getPanelPositionStyle'; | ||
import { resetIcon, searchIcon } from './icons'; | ||
@@ -49,12 +49,11 @@ import { renderTemplate } from './renderTemplate'; | ||
_ref2$render = _ref2.render, | ||
renderDropdown = _ref2$render === void 0 ? defaultRender : _ref2$render, | ||
_ref2$dropdownPlaceme = _ref2.dropdownPlacement, | ||
dropdownPlacement = _ref2$dropdownPlaceme === void 0 ? 'input-wrapper-width' : _ref2$dropdownPlaceme, | ||
renderPanel = _ref2$render === void 0 ? defaultRender : _ref2$render, | ||
_ref2$panelPlacement = _ref2.panelPlacement, | ||
panelPlacement = _ref2$panelPlacement === void 0 ? 'input-wrapper-width' : _ref2$panelPlacement, | ||
_ref2$classNames = _ref2.classNames, | ||
classNames = _ref2$classNames === void 0 ? {} : _ref2$classNames, | ||
props = _objectWithoutProperties(_ref2, ["container", "render", "dropdownPlacement", "classNames"]); | ||
props = _objectWithoutProperties(_ref2, ["container", "render", "panelPlacement", "classNames"]); | ||
var containerElement = getHTMLElement(container); | ||
var inputWrapper = document.createElement('div'); | ||
var completion = document.createElement('span'); | ||
var input = document.createElement('input'); | ||
@@ -65,3 +64,3 @@ var root = document.createElement('div'); | ||
var resetButton = document.createElement('button'); | ||
var dropdown = document.createElement('div'); | ||
var panel = document.createElement('div'); | ||
var autocomplete = createAutocomplete(_objectSpread(_objectSpread({}, props), {}, { | ||
@@ -78,11 +77,9 @@ onStateChange: function onStateChange(options) { | ||
var onResize = debounce(function () { | ||
if (!dropdown.hasAttribute('hidden')) { | ||
setDropdownPosition(); | ||
} | ||
setPanelPosition(); | ||
}, 100); | ||
function setDropdownPosition() { | ||
setProperties(dropdown, { | ||
style: getDropdownPositionStyle({ | ||
dropdownPlacement: dropdownPlacement, | ||
function setPanelPosition() { | ||
setProperties(panel, { | ||
style: getPanelPositionStyle({ | ||
panelPlacement: panelPlacement, | ||
container: root, | ||
@@ -97,3 +94,3 @@ inputWrapper: inputWrapper, | ||
searchBoxElement: form, | ||
dropdownElement: dropdown, | ||
panelElement: panel, | ||
inputElement: input | ||
@@ -113,3 +110,3 @@ })), {}, { | ||
setProperties(inputWrapper, { | ||
class: ['aa-InputWrapper', classNames.inputWrapper].filter(Boolean).join(' ') | ||
class: concatClassNames(['aa-InputWrapper', classNames.inputWrapper]) | ||
}); | ||
@@ -121,5 +118,2 @@ setProperties(input, _objectSpread(_objectSpread({}, autocomplete.getInputProps({ | ||
})); | ||
setProperties(completion, { | ||
class: concatClassNames(['aa-Completion', classNames.completion]) | ||
}); | ||
setProperties(label, _objectSpread(_objectSpread({}, autocomplete.getLabelProps()), {}, { | ||
@@ -135,5 +129,5 @@ class: concatClassNames(['aa-Label', classNames.label]), | ||
}); | ||
setProperties(dropdown, _objectSpread(_objectSpread({}, autocomplete.getDropdownProps()), {}, { | ||
setProperties(panel, _objectSpread(_objectSpread({}, autocomplete.getPanelProps()), {}, { | ||
hidden: true, | ||
class: concatClassNames(['aa-Dropdown', classNames.dropdown]) | ||
class: concatClassNames(['aa-Panel', classNames.panel]) | ||
})); | ||
@@ -146,15 +140,10 @@ | ||
})); | ||
panel.innerHTML = ''; | ||
if (props.enableCompletion) { | ||
completion.textContent = state.completion; | ||
} | ||
dropdown.innerHTML = ''; | ||
if (state.isOpen) { | ||
setProperties(dropdown, { | ||
setProperties(panel, { | ||
hidden: false | ||
}); | ||
} else { | ||
setProperties(dropdown, { | ||
setProperties(panel, { | ||
hidden: true | ||
@@ -166,13 +155,13 @@ }); | ||
if (state.status === 'stalled') { | ||
dropdown.classList.add('aa-Dropdown--stalled'); | ||
panel.classList.add('aa-Panel--stalled'); | ||
} else { | ||
dropdown.classList.remove('aa-Dropdown--stalled'); | ||
panel.classList.remove('aa-Panel--stalled'); | ||
} | ||
var sections = state.suggestions.map(function (suggestion) { | ||
var items = suggestion.items; | ||
var source = suggestion.source; | ||
var sections = state.collections.map(function (collection) { | ||
var items = collection.items; | ||
var source = collection.source; | ||
var section = document.createElement('section'); | ||
setProperties(section, { | ||
class: concatClassNames(['aa-Section', classNames.section]) | ||
class: concatClassNames(['aa-Source', classNames.source]) | ||
}); | ||
@@ -183,3 +172,3 @@ | ||
setProperties(header, { | ||
class: concatClassNames(['aa-SectionHeader', classNames.sectionHeader]) | ||
class: concatClassNames(['aa-SourceHeader', classNames.sourceHeader]) | ||
}); | ||
@@ -194,7 +183,7 @@ renderTemplate(source.templates.header({ | ||
if (items.length > 0) { | ||
var menu = document.createElement('ul'); | ||
setProperties(menu, _objectSpread(_objectSpread({}, autocomplete.getMenuProps()), {}, { | ||
class: concatClassNames(['aa-Menu', classNames.menu]) | ||
var list = document.createElement('ul'); | ||
setProperties(list, _objectSpread(_objectSpread({}, autocomplete.getListProps()), {}, { | ||
class: concatClassNames(['aa-List', classNames.list]) | ||
})); | ||
var menuItems = items.map(function (item) { | ||
var listItems = items.map(function (item) { | ||
var li = document.createElement('li'); | ||
@@ -215,3 +204,3 @@ setProperties(li, _objectSpread(_objectSpread({}, autocomplete.getItemProps({ | ||
var _iterator2 = _createForOfIteratorHelper(menuItems), | ||
var _iterator2 = _createForOfIteratorHelper(listItems), | ||
_step2; | ||
@@ -221,4 +210,4 @@ | ||
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { | ||
var menuItem = _step2.value; | ||
menu.appendChild(menuItem); | ||
var listItem = _step2.value; | ||
list.appendChild(listItem); | ||
} | ||
@@ -231,3 +220,3 @@ } catch (err) { | ||
section.appendChild(menu); | ||
section.appendChild(list); | ||
} | ||
@@ -238,3 +227,3 @@ | ||
setProperties(footer, { | ||
class: concatClassNames(['aa-SectionFooter', classNames.sectionFooter]) | ||
class: concatClassNames(['aa-SourceFooter', classNames.sourceFooter]) | ||
}); | ||
@@ -250,4 +239,4 @@ renderTemplate(source.templates.footer({ | ||
}); | ||
renderDropdown({ | ||
root: dropdown, | ||
renderPanel({ | ||
root: panel, | ||
sections: sections, | ||
@@ -258,6 +247,2 @@ state: state | ||
if (props.enableCompletion) { | ||
inputWrapper.appendChild(completion); | ||
} | ||
inputWrapper.appendChild(input); | ||
@@ -268,5 +253,5 @@ inputWrapper.appendChild(label); | ||
root.appendChild(form); | ||
root.appendChild(dropdown); | ||
root.appendChild(panel); | ||
containerElement.appendChild(root); | ||
setDropdownPosition(); | ||
setPanelPosition(); | ||
@@ -281,5 +266,5 @@ function destroy() { | ||
return { | ||
setHighlightedIndex: autocomplete.setHighlightedIndex, | ||
setSelectedItemId: autocomplete.setSelectedItemId, | ||
setQuery: autocomplete.setQuery, | ||
setSuggestions: autocomplete.setSuggestions, | ||
setCollections: autocomplete.setCollections, | ||
setIsOpen: autocomplete.setIsOpen, | ||
@@ -286,0 +271,0 @@ setStatus: autocomplete.setStatus, |
import { Hit } from '@algolia/client-search'; | ||
declare type HighlightItemParams<TItem> = { | ||
item: TItem; | ||
hit: TItem; | ||
attribute: keyof TItem; | ||
@@ -12,3 +12,3 @@ highlightPreTag?: string; | ||
*/ | ||
export declare function highlightItem<TItem extends Hit<{}>>({ item, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
export declare function highlightHit<TItem extends Hit<{}>>({ hit, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
/** | ||
@@ -19,7 +19,7 @@ * Highlights and escapes the non-matching parts of an Algolia hit. | ||
*/ | ||
export declare function reverseHighlightItem<TItem extends Hit<{}>>({ item, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
export declare function reverseHighlightHit<TItem extends Hit<{}>>({ hit, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
/** | ||
* Highlights and escapes the matching parts of an Algolia hit snippet. | ||
*/ | ||
export declare function snippetItem<TItem extends Hit<{}>>({ item, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
export declare function snippetHit<TItem extends Hit<{}>>({ hit, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
/** | ||
@@ -30,3 +30,3 @@ * Highlights and escapes the non-matching parts of an Algolia hit snippet. | ||
*/ | ||
export declare function reverseSnippetItem<TItem extends Hit<{}>>({ item, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
export declare function reverseSnippetHit<TItem extends Hit<{}>>({ hit, attribute, highlightPreTag, highlightPostTag, ignoreEscape, }: HighlightItemParams<TItem>): string; | ||
export {}; |
@@ -14,4 +14,4 @@ import { parseAlgoliaHitHighlight, parseAlgoliaHitReverseHighlight, parseAlgoliaHitSnippet, parseAlgoliaHitReverseSnippet } from '@algolia/autocomplete-preset-algolia'; | ||
*/ | ||
export function highlightItem(_ref2) { | ||
var item = _ref2.item, | ||
export function highlightHit(_ref2) { | ||
var hit = _ref2.hit, | ||
attribute = _ref2.attribute, | ||
@@ -24,3 +24,3 @@ _ref2$highlightPreTag = _ref2.highlightPreTag, | ||
return concatParts(parseAlgoliaHitHighlight({ | ||
hit: item, | ||
hit: hit, | ||
attribute: attribute, | ||
@@ -39,4 +39,4 @@ ignoreEscape: ignoreEscape | ||
export function reverseHighlightItem(_ref3) { | ||
var item = _ref3.item, | ||
export function reverseHighlightHit(_ref3) { | ||
var hit = _ref3.hit, | ||
attribute = _ref3.attribute, | ||
@@ -49,3 +49,3 @@ _ref3$highlightPreTag = _ref3.highlightPreTag, | ||
return concatParts(parseAlgoliaHitReverseHighlight({ | ||
hit: item, | ||
hit: hit, | ||
attribute: attribute, | ||
@@ -62,4 +62,4 @@ ignoreEscape: ignoreEscape | ||
export function snippetItem(_ref4) { | ||
var item = _ref4.item, | ||
export function snippetHit(_ref4) { | ||
var hit = _ref4.hit, | ||
attribute = _ref4.attribute, | ||
@@ -72,3 +72,3 @@ _ref4$highlightPreTag = _ref4.highlightPreTag, | ||
return concatParts(parseAlgoliaHitSnippet({ | ||
hit: item, | ||
hit: hit, | ||
attribute: attribute, | ||
@@ -87,4 +87,4 @@ ignoreEscape: ignoreEscape | ||
export function reverseSnippetItem(_ref5) { | ||
var item = _ref5.item, | ||
export function reverseSnippetHit(_ref5) { | ||
var hit = _ref5.hit, | ||
attribute = _ref5.attribute, | ||
@@ -97,3 +97,3 @@ _ref5$highlightPreTag = _ref5.highlightPreTag, | ||
return concatParts(parseAlgoliaHitReverseSnippet({ | ||
hit: item, | ||
hit: hit, | ||
attribute: attribute, | ||
@@ -100,0 +100,0 @@ ignoreEscape: ignoreEscape |
import { GetSourcesParams, AutocompleteSetters as AutocompleteCoreSetters, InternalAutocompleteSource as InternalAutocompleteCoreSource, AutocompleteState as AutocompleteCoreState, AutocompleteOptions as AutocompleteCoreOptions, AutocompleteSource as AutocompleteCoreSource } from '@algolia/autocomplete-core'; | ||
import { MaybePromise } from '@algolia/autocomplete-shared'; | ||
declare type Template<TParams> = (params: TParams) => string | void; | ||
declare type SourceTemplates<TItem> = { | ||
export declare type SourceTemplates<TItem> = { | ||
/** | ||
* Templates to display in the autocomplete dropdown. | ||
* Templates to display in the autocomplete panel. | ||
* | ||
@@ -36,3 +37,3 @@ * A template can either return a string, or perform DOM mutations (manipulating DOM elements with JavaScript and attaching events) without returning a string. | ||
export declare type InternalAutocompleteSource<TItem> = InternalAutocompleteCoreSource<TItem> & SourceTemplates<TItem>; | ||
declare type GetSources<TItem> = (params: GetSourcesParams<TItem>) => Array<AutocompleteCoreSource<TItem>> | Promise<Array<AutocompleteCoreSource<TItem>>>; | ||
declare type GetSources<TItem> = (params: GetSourcesParams<TItem>) => MaybePromise<Array<AutocompleteCoreSource<TItem>>>; | ||
export interface AutocompleteOptions<TItem> extends AutocompleteCoreOptions<TItem> { | ||
@@ -45,9 +46,9 @@ /** | ||
container: string | HTMLElement; | ||
getSources: GetSources<TItem>; | ||
getSources?: GetSources<TItem>; | ||
/** | ||
* The dropdown horizontal position. | ||
* The panel horizontal position. | ||
* | ||
* @default "input-wrapper-width" | ||
*/ | ||
dropdownPlacement?: 'start' | 'end' | 'full-width' | 'input-wrapper-width'; | ||
panelPlacement?: 'start' | 'end' | 'full-width' | 'input-wrapper-width'; | ||
/** | ||
@@ -64,10 +65,9 @@ * The class names to inject in each created DOM element. | ||
input?: string; | ||
completion?: string; | ||
resetButton?: string; | ||
dropdown?: string; | ||
section?: string; | ||
sectionHeader?: string; | ||
menu?: string; | ||
panel?: string; | ||
source?: string; | ||
sourceHeader?: string; | ||
list?: string; | ||
item?: string; | ||
sectionFooter?: string; | ||
sourceFooter?: string; | ||
}; | ||
@@ -74,0 +74,0 @@ /** |
{ | ||
"name": "@algolia/autocomplete-js", | ||
"description": "Fast and fully-featured autocomplete JavaScript library.", | ||
"version": "1.0.0-alpha.34", | ||
"version": "1.0.0-alpha.35", | ||
"license": "MIT", | ||
"homepage": "https://github.com/algolia/autocomplete.js", | ||
"repository": "algolia/autocomplete.js", | ||
"author": { | ||
"name": "Algolia, Inc.", | ||
"url": "https://www.algolia.com" | ||
}, | ||
"source": "src/index.ts", | ||
"types": "dist/esm/index.d.ts", | ||
"module": "dist/esm/index.js", | ||
"main": "dist/umd/index.js", | ||
"umd:main": "dist/umd/index.js", | ||
"unpkg": "dist/umd/index.js", | ||
"jsdelivr": "dist/umd/index.js", | ||
"homepage": "https://github.com/algolia/autocomplete.js", | ||
"repository": "algolia/autocomplete.js", | ||
"main": "dist/umd/index.production.js", | ||
"umd:main": "dist/umd/index.production.js", | ||
"unpkg": "dist/umd/index.production.js", | ||
"jsdelivr": "dist/umd/index.production.js", | ||
"sideEffects": false, | ||
"files": [ | ||
"dist/" | ||
], | ||
"scripts": { | ||
@@ -25,15 +33,13 @@ "build:clean": "rm -rf ./dist", | ||
}, | ||
"author": { | ||
"name": "Algolia, Inc.", | ||
"url": "https://www.algolia.com" | ||
"dependencies": { | ||
"@algolia/autocomplete-core": "1.0.0-alpha.35", | ||
"@algolia/autocomplete-preset-algolia": "1.0.0-alpha.35", | ||
"@algolia/autocomplete-shared": "1.0.0-alpha.35" | ||
}, | ||
"sideEffects": false, | ||
"files": [ | ||
"dist/" | ||
], | ||
"dependencies": { | ||
"@algolia/autocomplete-core": "^1.0.0-alpha.34", | ||
"@algolia/autocomplete-preset-algolia": "^1.0.0-alpha.34", | ||
"devDependencies": { | ||
"@algolia/client-search": "4.5.1" | ||
}, | ||
"peerDependencies": { | ||
"@algolia/client-search": "^4.5.1" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
416870
32
3146
4
1
1
+ Added@algolia/autocomplete-core@1.0.0-alpha.35(transitive)
+ Added@algolia/autocomplete-preset-algolia@1.0.0-alpha.35(transitive)
+ Added@algolia/autocomplete-shared@1.0.0-alpha.35(transitive)
+ Added@algolia/cache-browser-local-storage@4.24.0(transitive)
+ Added@algolia/cache-common@4.24.0(transitive)
+ Added@algolia/cache-in-memory@4.24.0(transitive)
+ Added@algolia/client-account@4.24.0(transitive)
+ Added@algolia/client-analytics@4.24.0(transitive)
+ Added@algolia/client-common@4.24.0(transitive)
+ Added@algolia/client-personalization@4.24.0(transitive)
+ Added@algolia/client-search@4.24.0(transitive)
+ Added@algolia/logger-common@4.24.0(transitive)
+ Added@algolia/logger-console@4.24.0(transitive)
+ Added@algolia/recommend@4.24.0(transitive)
+ Added@algolia/requester-browser-xhr@4.24.0(transitive)
+ Added@algolia/requester-common@4.24.0(transitive)
+ Added@algolia/requester-node-http@4.24.0(transitive)
+ Added@algolia/transporter@4.24.0(transitive)
+ Addedalgoliasearch@4.24.0(transitive)
- Removed@algolia/client-search@4.5.1
- Removed@algolia/autocomplete-core@1.17.6(transitive)
- Removed@algolia/autocomplete-plugin-algolia-insights@1.17.6(transitive)
- Removed@algolia/autocomplete-preset-algolia@1.17.6(transitive)
- Removed@algolia/autocomplete-shared@1.17.6(transitive)
- Removed@algolia/cache-common@4.5.1(transitive)
- Removed@algolia/client-abtesting@5.9.1(transitive)
- Removed@algolia/client-analytics@5.9.1(transitive)
- Removed@algolia/client-common@4.5.15.9.1(transitive)
- Removed@algolia/client-insights@5.9.1(transitive)
- Removed@algolia/client-personalization@5.9.1(transitive)
- Removed@algolia/client-query-suggestions@5.9.1(transitive)
- Removed@algolia/client-search@4.5.15.9.1(transitive)
- Removed@algolia/ingestion@1.9.1(transitive)
- Removed@algolia/logger-common@4.5.1(transitive)
- Removed@algolia/monitoring@1.9.1(transitive)
- Removed@algolia/recommend@5.9.1(transitive)
- Removed@algolia/requester-browser-xhr@5.9.1(transitive)
- Removed@algolia/requester-common@4.5.1(transitive)
- Removed@algolia/requester-fetch@5.9.1(transitive)
- Removed@algolia/requester-node-http@5.9.1(transitive)
- Removed@algolia/transporter@4.5.1(transitive)
- Removedalgoliasearch@5.9.1(transitive)
- Removedsearch-insights@2.17.2(transitive)