Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
feat(docsearch): introduce DocSearch.js v3 (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
francoischalifour authored Jul 9, 2020
1 parent fe56ef3 commit 0ff2462
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 773 deletions.
4 changes: 4 additions & 0 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
{
"path": "packages/docsearch-react/dist/umd/index.js",
"maxSize": "28 kB"
},
{
"path": "packages/docsearch-js/dist/umd/index.js",
"maxSize": "38 kB"
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
"cy:run:firefox": "yarn run cy:run --browser firefox",
"cy:run:edge": "yarn run cy:run --browser edge",
"cy:clean": "rm -rf cypress/screenshots",
"docsearch:lint:css": "stylelint packages/docsearch-react/src/**/*.css"
"docsearch:lint:css": "stylelint packages/docsearch-css/src/**/*.css"
},
"devDependencies": {
"@babel/cli": "7.10.1",
"@babel/plugin-transform-react-jsx": "7.10.1",
"@babel/preset-env": "7.10.2",
"@babel/preset-typescript": "7.10.1",
"@percy/cypress": "2.3.1",
"@rollup/plugin-alias": "3.1.1",
"@rollup/plugin-json": "4.0.2",
"@rollup/plugin-node-resolve": "7.1.1",
"@rollup/plugin-replace": "2.3.1",
Expand Down
25 changes: 25 additions & 0 deletions packages/docsearch-css/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@docsearch/css",
"version": "1.0.0-alpha.21",
"license": "MIT",
"homepage": "https://github.com/algolia/autocomplete.js",
"repository": "algolia/autocomplete.js",
"author": {
"name": "Algolia, Inc.",
"url": "https://www.algolia.com"
},
"sideEffects": false,
"files": [
"dist/"
],
"main": "dist/style.css",
"unpkg": "dist/style.css",
"jsdelivr": "dist/style.css",
"scripts": {
"build": "yarn build:clean && yarn build:css",
"build:css": "mkdir dist && cp src/_variables.css dist/ && cp src/modal.css dist/ && cp src/search-button.css dist/ && cat src/*.css > dist/style.css",
"build:css:watch": "chokidar src/*.css --command \"yarn build:css\"",
"build:clean": "rm -rf ./dist",
"watch": "concurrently \"yarn build:css:watch\""
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* Search Button */

.DocSearch-SearchButton {
align-items: center;
background: var(--docsearch-searchbox-background);
Expand Down
27 changes: 27 additions & 0 deletions packages/docsearch-js/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* 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']],
};
};
36 changes: 36 additions & 0 deletions packages/docsearch-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@docsearch/js",
"version": "1.0.0-alpha.21",
"license": "MIT",
"homepage": "https://github.com/algolia/autocomplete.js",
"repository": "algolia/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",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm",
"build:esm:watch": "yarn build:esm --watch",
"build:umd": "rollup --config",
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
"build:types:watch": "chokidar \"**/*.ts\" \"**/*.tsx\" --command \"yarn build:types\" --ignore \"dist\"",
"build:clean": "rm -rf ./dist",
"watch": "concurrently \"yarn build:esm:watch\" \"yarn build:types:watch\""
},
"dependencies": {
"@docsearch/react": "^1.0.0-alpha.21",
"preact": "^10.0.0"
}
}
24 changes: 24 additions & 0 deletions packages/docsearch-js/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';

import { sharedPlugins } from '../autocomplete-core/rollup.config';

export default {
input: 'src/index.ts',
output: {
file: 'dist/umd/index.js',
format: 'umd',
sourcemap: true,
name: 'docsearch',
},
plugins: [
json(),
alias({
entries: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom', replacement: 'preact/compat' },
],
}),
...sharedPlugins,
],
};
21 changes: 21 additions & 0 deletions packages/docsearch-js/src/docsearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, { render } from 'preact/compat';

import { DocSearch } from '@docsearch/react';

function getHTMLElement(
value: string | HTMLElement,
environment: typeof window = window
): HTMLElement {
if (typeof value === 'string') {
return environment.document.querySelector<HTMLElement>(value)!;
}

return value;
}

export function docsearch(props) {
render(
<DocSearch {...props} />,
getHTMLElement(props.container, props.environment)
);
}
1 change: 1 addition & 0 deletions packages/docsearch-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { docsearch as default } from './docsearch';
8 changes: 8 additions & 0 deletions packages/docsearch-js/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true
}
}
3 changes: 3 additions & 0 deletions packages/docsearch-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig"
}
8 changes: 3 additions & 5 deletions packages/docsearch-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@
"unpkg": "dist/umd/index.js",
"jsdelivr": "dist/umd/index.js",
"scripts": {
"build": "yarn build:clean && yarn build:umd && yarn build:esm && yarn build:css",
"": "// TODO: have a proper build:css, probably including autoprefixer?",
"build:css": "cp src/styles/*.css dist/",
"build:css:watch": "chokidar src/styles/*.css --command \"yarn build:css\"",
"build": "yarn build:clean && yarn build:umd && yarn build:esm",
"build:esm": "babel src --root-mode upward --extensions '.ts,.tsx' --out-dir dist/esm",
"build:esm:watch": "yarn build:esm --watch",
"build:umd": "rollup --config",
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
"build:types:watch": "chokidar \"**/*.ts\" \"**/*.tsx\" --command \"yarn build:types\" --ignore \"dist\"",
"build:clean": "rm -rf ./dist",
"watch": "concurrently \"yarn build:esm:watch\" \"yarn build:types:watch\" \"yarn build:css:watch\""
"watch": "concurrently \"yarn build:esm:watch\" \"yarn build:types:watch\""
},
"dependencies": {
"@docsearch/css": "^1.0.0-alpha.21",
"@francoischalifour/autocomplete-core": "^1.0.0-alpha.21",
"@francoischalifour/autocomplete-preset-algolia": "^1.0.0-alpha.21",
"algoliasearch": "^4.0.0"
Expand Down
Loading

0 comments on commit 0ff2462

Please sign in to comment.