Merge branch 'feat/v3'
This commit is contained in:
commit
c3cabb13cf
10 changed files with 2831 additions and 2721 deletions
|
|
@ -1,3 +1,10 @@
|
|||
{
|
||||
"singleQuote": true
|
||||
"overrides": [
|
||||
{
|
||||
"files": "*.scss",
|
||||
"options": {
|
||||
"singleQuote": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
5361
package-lock.json
generated
5361
package-lock.json
generated
File diff suppressed because it is too large
Load diff
51
scripts/playground.html
Normal file
51
scripts/playground.html
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>DocSearch playground</title>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap/3.3.6/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="http://127.0.0.1:8080/docsearch.min.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="mt-1">
|
||||
<h1>Assets are served from http://127.0.0.1:8080/ </h1>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="input-group">
|
||||
<input type="search" placeholder="DocSearch input" class="form-control" id="q">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- at the end of the BODY -->
|
||||
<script type="text/javascript" src="http://127.0.0.1:8080/docsearch.js"></script>
|
||||
<script type="text/javascript">
|
||||
docsearch({
|
||||
apiKey: '25626fae796133dc1e734c6bcaaeac3c',
|
||||
indexName: 'docsearch',
|
||||
inputSelector: '#q',
|
||||
handleSelected(input, event, suggestion) {
|
||||
console.info(input);
|
||||
console.info(event);
|
||||
console.info(suggestion);
|
||||
},
|
||||
debug: true // Set debug to true if you want to inspect the dropdown
|
||||
});
|
||||
</script>
|
||||
<style>
|
||||
|
||||
.container {
|
||||
margin: 10%;
|
||||
}
|
||||
|
||||
.input-group {
|
||||
width: 60%;
|
||||
margin: auto;
|
||||
margin-top: 10%;
|
||||
}
|
||||
</style>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -6,4 +6,6 @@ echo "Find all files at http://127.0.0.1:8080/";
|
|||
parallelshell \
|
||||
'webpack --config webpack.serve.config.babel.js -w' \
|
||||
'onchange "./src/styles/*.scss" -- yarn run build:css' \
|
||||
'live-server ./dist/cdn' \
|
||||
'live-server --no-browser ./dist/cdn' \
|
||||
"${BROWSER} scripts/playground.html"
|
||||
|
||||
|
|
|
|||
|
|
@ -3,5 +3,6 @@ set -e
|
|||
jest \
|
||||
--no-cache \
|
||||
--watch \
|
||||
--no-watchman \
|
||||
./src/lib/
|
||||
|
||||
|
|
|
|||
|
|
@ -100,10 +100,22 @@ class DocSearch {
|
|||
},
|
||||
},
|
||||
]);
|
||||
|
||||
// If user defined its own handleSelected, we prevent clicks on suggestions
|
||||
// link to do anything
|
||||
if (handleSelected) {
|
||||
$('.algolia-autocomplete').on('click', '.ds-suggestions a', event => {
|
||||
event.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
// Click on suggestions will follow the link, but keyboard navigation still
|
||||
// need the handleSelected
|
||||
this.autocomplete.on(
|
||||
'autocomplete:selected',
|
||||
handleSelected.bind(null, this.autocomplete.autocomplete)
|
||||
);
|
||||
|
||||
this.autocomplete.on(
|
||||
'autocomplete:shown',
|
||||
this.handleShown.bind(null, this.input)
|
||||
|
|
@ -125,6 +137,14 @@ class DocSearch {
|
|||
throw new Error(usage);
|
||||
}
|
||||
|
||||
if (typeof args.inputSelector !== 'string') {
|
||||
throw new Error(
|
||||
`Error: inputSelector:${
|
||||
args.inputSelector
|
||||
} must be a string. Each selector must match only one element and separated by ','`
|
||||
);
|
||||
}
|
||||
|
||||
if (!DocSearch.getInputFromSelector(args.inputSelector)) {
|
||||
throw new Error(
|
||||
`Error: No input element in the page matches ${args.inputSelector}`
|
||||
|
|
@ -325,7 +345,6 @@ class DocSearch {
|
|||
middleOfInput - middleOfWindow < 0
|
||||
? 'algolia-autocomplete-right'
|
||||
: 'algolia-autocomplete-left';
|
||||
|
||||
const autocompleteWrapper = $('.algolia-autocomplete');
|
||||
if (!autocompleteWrapper.hasClass(alignClass)) {
|
||||
autocompleteWrapper.addClass(alignClass);
|
||||
|
|
|
|||
|
|
@ -142,9 +142,9 @@ describe('DocSearch', () => {
|
|||
const actual = new DocSearch(options);
|
||||
|
||||
// Then
|
||||
const $input = actual.input;
|
||||
expect($input.text()).toEqual('foo');
|
||||
expect($input[0].tagName).toEqual('SPAN');
|
||||
const $inputs = actual.input;
|
||||
expect($inputs.text()).toEqual('foo');
|
||||
expect($inputs[0].tagName).toEqual('SPAN');
|
||||
});
|
||||
it('should pass secondary options as instance properties', () => {
|
||||
// Given
|
||||
|
|
@ -211,7 +211,7 @@ describe('DocSearch', () => {
|
|||
});
|
||||
it('should listen to the selected and shown event of autocomplete', () => {
|
||||
// Given
|
||||
const options = defaultOptions;
|
||||
const options = { ...defaultOptions, handleSelected() {} };
|
||||
|
||||
// When
|
||||
new DocSearch(options);
|
||||
|
|
@ -390,7 +390,7 @@ describe('DocSearch', () => {
|
|||
});
|
||||
|
||||
describe('handleSelected', () => {
|
||||
it('should change the location', () => {
|
||||
it('should change the location if no handleSelected specified', () => {
|
||||
// Given
|
||||
const options = {
|
||||
apiKey: 'key',
|
||||
|
|
@ -411,6 +411,45 @@ describe('DocSearch', () => {
|
|||
resolve();
|
||||
});
|
||||
});
|
||||
it('should call the custom handleSelected if defined', () => {
|
||||
// Given
|
||||
const customHandleSelected = jest.fn();
|
||||
const options = {
|
||||
apiKey: 'key',
|
||||
indexName: 'foo',
|
||||
inputSelector: '#input',
|
||||
handleSelected: customHandleSelected,
|
||||
};
|
||||
const expectedInput = expect.objectContaining({
|
||||
open: expect.any(Function),
|
||||
});
|
||||
const expectedEvent = expect.objectContaining({
|
||||
type: 'autocomplete:selected'
|
||||
});
|
||||
const expectedSuggestion = expect.objectContaining({
|
||||
url: 'https://website.com/doc/page',
|
||||
});
|
||||
|
||||
// When
|
||||
const ds = new DocSearch(options);
|
||||
ds.autocomplete.trigger('autocomplete:selected', {
|
||||
url: 'https://website.com/doc/page',
|
||||
});
|
||||
|
||||
return new Promise(resolve => {
|
||||
expect(customHandleSelected).toHaveBeenCalledWith(
|
||||
expectedInput,
|
||||
expectedEvent,
|
||||
expectedSuggestion,
|
||||
);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
xit('should prevent all clicks on links if a custom handleSelected is specified', () => {
|
||||
// TODO
|
||||
// If handleSelected, we target one link, we manually trigger a click on
|
||||
// it, and we check that preventDefault is called on the event
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleShown', () => {
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -1 +1 @@
|
|||
export default '2.5.2';
|
||||
export default '3.0.0';
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue