Merge branch 'ds-js' of https://github.com/francoischalifour/autocomplete.js
This commit is contained in:
commit
c12dc4e912
8 changed files with 170 additions and 0 deletions
15
README.md
Normal file
15
README.md
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# @docsearch/js
|
||||
|
||||
JavaScript package for [DocSearch](http://docsearch.algolia.com/), the best search experience for docs.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
yarn add @docsearch/js@alpha
|
||||
# or
|
||||
npm install @docsearch/js@alpha
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
[Read documentation →](https://autocomplete-experimental.netlify.app/docs/docsearch-js)
|
||||
39
babel.config.js
Normal file
39
babel.config.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
/* eslint-disable import/no-commonjs */
|
||||
|
||||
module.exports = (api) => {
|
||||
const isTest = api.env('test');
|
||||
const modules = isTest ? 'commonjs' : false;
|
||||
const targets = {};
|
||||
|
||||
if (isTest) {
|
||||
targets.node = true;
|
||||
} else {
|
||||
targets.browsers = ['last 2 versions', 'ie >= 11'];
|
||||
}
|
||||
|
||||
return {
|
||||
presets: [
|
||||
'@babel/preset-typescript',
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
modules,
|
||||
targets,
|
||||
},
|
||||
],
|
||||
],
|
||||
plugins: [
|
||||
['@babel/plugin-transform-react-jsx'],
|
||||
[
|
||||
'module-resolver',
|
||||
{
|
||||
root: ['./src'],
|
||||
alias: {
|
||||
react: 'preact/compat',
|
||||
'react-dom': 'preact/compat',
|
||||
},
|
||||
},
|
||||
],
|
||||
],
|
||||
};
|
||||
};
|
||||
36
package.json
Normal file
36
package.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "@docsearch/js",
|
||||
"description": "JavaScript package for DocSearch, the best search experience for docs.",
|
||||
"version": "1.0.0-alpha.28",
|
||||
"license": "MIT",
|
||||
"homepage": "https://github.com/francoischalifour/autocomplete.js",
|
||||
"repository": "francoischalifour/autocomplete.js",
|
||||
"author": {
|
||||
"name": "Algolia, Inc.",
|
||||
"url": "https://www.algolia.com"
|
||||
},
|
||||
"sideEffects": false,
|
||||
"files": [
|
||||
"dist/"
|
||||
],
|
||||
"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",
|
||||
"scripts": {
|
||||
"build": "yarn build:clean && yarn build:umd && yarn build:esm && yarn build:types",
|
||||
"build:umd": "BUILD=umd rollup --config",
|
||||
"build:esm": "BUILD=esm rollup --config",
|
||||
"build:types": "tsc -p ./tsconfig.declaration.json --outFile ./dist/esm/index.d.ts",
|
||||
"build:clean": "rm -rf ./dist",
|
||||
"on:change": "concurrently \"yarn build:esm\" \"yarn build:types\"",
|
||||
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\""
|
||||
},
|
||||
"dependencies": {
|
||||
"@docsearch/react": "^1.0.0-alpha.28",
|
||||
"preact": "^10.0.0"
|
||||
}
|
||||
}
|
||||
30
rollup.config.js
Normal file
30
rollup.config.js
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import { plugins } from '../../rollup.base.config';
|
||||
import { getBundleBanner } from '../../scripts/getBundleBanner';
|
||||
|
||||
import pkg from './package.json';
|
||||
|
||||
if (!process.env.BUILD) {
|
||||
throw new Error('The `BUILD` environment variable is required to build.');
|
||||
}
|
||||
|
||||
const output = {
|
||||
umd: {
|
||||
file: 'dist/umd/index.js',
|
||||
format: 'umd',
|
||||
sourcemap: true,
|
||||
name: 'docsearch',
|
||||
banner: getBundleBanner(pkg),
|
||||
},
|
||||
esm: {
|
||||
file: 'dist/esm/index.js',
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
banner: getBundleBanner(pkg),
|
||||
},
|
||||
};
|
||||
|
||||
export default {
|
||||
input: 'src/index.ts',
|
||||
output: output[process.env.BUILD],
|
||||
plugins,
|
||||
};
|
||||
38
src/docsearch.tsx
Normal file
38
src/docsearch.tsx
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import {
|
||||
DocSearch,
|
||||
DocSearchProps as DocSearchComponentProps,
|
||||
version,
|
||||
} from '@docsearch/react';
|
||||
import React, { render } from 'preact/compat';
|
||||
|
||||
function getHTMLElement(
|
||||
value: string | HTMLElement,
|
||||
environment: DocSearchProps['environment'] = window
|
||||
): HTMLElement {
|
||||
if (typeof value === 'string') {
|
||||
return environment.document.querySelector<HTMLElement>(value)!;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
interface DocSearchProps extends DocSearchComponentProps {
|
||||
container: string | HTMLElement;
|
||||
environment?: typeof window;
|
||||
}
|
||||
|
||||
export function docsearch(props: DocSearchProps) {
|
||||
render(
|
||||
<DocSearch
|
||||
{...props}
|
||||
transformSearchClient={(searchClient) => {
|
||||
searchClient.addAlgoliaAgent('docsearch.js', version);
|
||||
|
||||
return props.transformSearchClient
|
||||
? props.transformSearchClient(searchClient)
|
||||
: searchClient;
|
||||
}}
|
||||
/>,
|
||||
getHTMLElement(props.container, props.environment)
|
||||
);
|
||||
}
|
||||
1
src/index.ts
Normal file
1
src/index.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export { docsearch as default } from './docsearch';
|
||||
8
tsconfig.declaration.json
Normal file
8
tsconfig.declaration.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "./tsconfig",
|
||||
"compilerOptions": {
|
||||
"noEmit": false,
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true
|
||||
}
|
||||
}
|
||||
3
tsconfig.json
Normal file
3
tsconfig.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "../../tsconfig"
|
||||
}
|
||||
Loading…
Reference in a new issue