@easyops-cn/docusaurus-search-local 0.21.2 → 0.22.0

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [0.22.0](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.4...v0.22.0) (2022-02-28)
6
+
7
+
8
+ ### Features
9
+
10
+ * improve focus for search bar ([e4ede16](https://www.github.com/easyops-cn/docusaurus-search-local/commit/e4ede1650883e326bcbc7ff17c5ed3d37b279d17))
11
+
12
+ ### [0.21.4](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.3...v0.21.4) (2021-12-15)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * set max-width for dropdown on small screen ([cec8c39](https://www.github.com/easyops-cn/docusaurus-search-local/commit/cec8c3924beacd900d880fd66edaf52dbdbdd952)), closes [#135](https://www.github.com/easyops-cn/docusaurus-search-local/issues/135)
18
+
19
+ ### [0.21.3](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.2...v0.21.3) (2021-12-14)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * use keydown instead of keypress ([d871f0b](https://www.github.com/easyops-cn/docusaurus-search-local/commit/d871f0bbb1e1c6fe191341f7166b89b6aeb11bf2)), closes [#132](https://www.github.com/easyops-cn/docusaurus-search-local/issues/132)
25
+
5
26
  ### [0.21.2](https://www.github.com/easyops-cn/docusaurus-search-local/compare/v0.21.1...v0.21.2) (2021-12-13)
6
27
 
7
28
 
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![CI Status](https://github.com/easyops-cn/docusaurus-search-local/workflows/CI/badge.svg?event=push)](https://github.com/easyops-cn/docusaurus-search-local/actions?query=workflow%3ACI)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/easyops-cn/docusaurus-search-local/badge.svg?branch=master)](https://coveralls.io/github/easyops-cn/docusaurus-search-local?branch=master)
6
6
 
7
- An offline/local search plugin for [Docusaurus v2](https://v2.docusaurus.io/), which supports multiple languages, especially optimized for language of zh.
7
+ An offline/local search plugin/theme for [Docusaurus v2](https://v2.docusaurus.io/), which supports multiple languages, especially optimized for language of zh.
8
8
 
9
9
  > Originally forked from [cmfcmf/docusaurus-search-local](https://github.com/cmfcmf/docusaurus-search-local).
10
10
  >
@@ -14,7 +14,7 @@ An offline/local search plugin for [Docusaurus v2](https://v2.docusaurus.io/), w
14
14
  - [Screen Shots](#screen-shots)
15
15
  - [Installation](#installation)
16
16
  - [Usage](#usage)
17
- - [Plugin Options](#plugin-options)
17
+ - [Theme Options](#theme-options)
18
18
  - [Custom Styles](#custom-styles)
19
19
  - [Trouble Shooting](#trouble-shooting)
20
20
  - [Further Reading](#further-reading)
@@ -40,14 +40,14 @@ yarn add @easyops-cn/docusaurus-search-local
40
40
 
41
41
  ## Usage
42
42
 
43
- Add `@easyops-cn/docusaurus-search-local` into your docusaurus plugins.
43
+ Add `@easyops-cn/docusaurus-search-local` into your docusaurus themes.
44
44
 
45
45
  ````js
46
46
  // In your `docusaurus.config.js`:
47
47
  module.exports = {
48
48
  // ... Your other configurations.
49
- plugins: [
50
- // ... Your other plugins.
49
+ themes: [
50
+ // ... Your other themes.
51
51
  [
52
52
  require.resolve("@easyops-cn/docusaurus-search-local"),
53
53
  {
@@ -67,7 +67,9 @@ module.exports = {
67
67
 
68
68
  > Notice!
69
69
  >
70
- > When applying `"zh"` in language, please also install `nodejieba` in your project, which is required for tokenizing Chinese words. It is removed from peerDependencies since v0.20.0, so you have to install it manually even if you're using npm v7+.
70
+ > - We present this as a theme instead of plugin now, see [this comment](https://github.com/facebook/docusaurus/issues/6488#issuecomment-1024124096).
71
+ >
72
+ > - When applying `"zh"` in language, please also install `nodejieba` in your project, which is required for tokenizing Chinese words. It is removed from peerDependencies since v0.20.0, so you have to install it manually even if you're using npm v7+.
71
73
 
72
74
  ```shell
73
75
  npm install nodejieba
@@ -75,7 +77,7 @@ npm install nodejieba
75
77
  yarn add nodejieba
76
78
  ```
77
79
 
78
- ## Plugin Options
80
+ ## Theme Options
79
81
 
80
82
  | Name | Type | Default | Description |
81
83
  | -------------------------------- | ---------------------------------------- | ------------ | -------------------------------------------------------------------------------------------------------------------------------------------- |
@@ -92,12 +94,12 @@ yarn add nodejieba
92
94
  | highlightSearchTermsOnTargetPage | boolean | `false` | Highlight search terms on target page. |
93
95
  | searchResultLimits | number | `8` | Limit the search results. |
94
96
  | searchResultContextMaxLength | number | `50` | Set the max length of characters of each search result to show. |
95
- | translations | TranslationMap | - | Set translations of this plugin, see [docs below](#translations). |
97
+ | translations | TranslationMap | - | Set translations of this theme, see [docs below](#translations). |
96
98
  | ignoreFiles | string \| RegExp \| (string \| RegExp)[] | /**meta**\$/ | Set the match rules to ignore some files. |
97
99
 
98
100
  ### Translations
99
101
 
100
- To make this plugin localized, pass a `translations` option which defaults to:
102
+ To make this theme localized, pass a `translations` option which defaults to:
101
103
 
102
104
  ```json
103
105
  {
@@ -116,7 +118,7 @@ Note that `*_plural` can be omitted if it is the same as singular.
116
118
 
117
119
  ## Custom Styles
118
120
 
119
- This plugin is shipped with polished styles just like the Algolia Search on the Docusaurus v2 website. Feel free to override these css custom properties (css variables) below.
121
+ This theme is shipped with polished styles just like the Algolia Search on the Docusaurus v2 website. Feel free to override these css custom properties (css variables) below.
120
122
 
121
123
  | Var | Default (light) | Default (dark) |
122
124
  | -------------------------------- | ---------------------------------------------------------------------- | ------------------------------------------------------- |
@@ -48,6 +48,7 @@ export default function SearchBar({ handleSearchBarToggle, }) {
48
48
  const search = autoComplete(searchBarRef.current, {
49
49
  hint: false,
50
50
  autoselect: true,
51
+ openOnFocus: true,
51
52
  cssClasses: {
52
53
  root: styles.searchBar,
53
54
  noPrefix: true,
@@ -88,7 +89,9 @@ export default function SearchBar({ handleSearchBarToggle, }) {
88
89
  },
89
90
  },
90
91
  },
91
- ]).on("autocomplete:selected", function (event, { document: { u, h }, tokens }) {
92
+ ])
93
+ .on("autocomplete:selected", function (event, { document: { u, h }, tokens }) {
94
+ searchBarRef.current?.blur();
92
95
  let url = u;
93
96
  if (Mark && tokens.length > 0) {
94
97
  const params = new URLSearchParams();
@@ -101,6 +104,9 @@ export default function SearchBar({ handleSearchBarToggle, }) {
101
104
  url += h;
102
105
  }
103
106
  history.push(url);
107
+ })
108
+ .on("autocomplete:closed", () => {
109
+ searchBarRef.current?.blur();
104
110
  });
105
111
  indexState.current = "done";
106
112
  setLoading(false);
@@ -162,16 +168,14 @@ export default function SearchBar({ handleSearchBarToggle, }) {
162
168
  if ((isMac ? event.metaKey : event.ctrlKey) && event.code === "KeyK") {
163
169
  event.preventDefault();
164
170
  searchBarRef.current?.focus();
171
+ onInputFocus();
165
172
  }
166
173
  }
167
- // "keydown" is the only way to capture the "command" key on mac.
168
- // Then we use the metaKey boolean prop to see if the "command" key was pressed.
169
- const eventType = isMac ? "keydown" : "keypress";
170
- document.addEventListener(eventType, handleShortcut);
174
+ document.addEventListener("keydown", handleShortcut);
171
175
  return () => {
172
- document.removeEventListener(eventType, handleShortcut);
176
+ document.removeEventListener("keydown", handleShortcut);
173
177
  };
174
- }, [isMac]);
178
+ }, [isMac, onInputFocus]);
175
179
  return (<div className={clsx("navbar__search", styles.searchBarContainer, {
176
180
  [styles.searchIndexLoading]: loading && inputChanged,
177
181
  })}>
@@ -23,6 +23,7 @@
23
23
 
24
24
  .searchBar .dropdownMenu {
25
25
  width: var(--search-local-modal-width-sm, 340px);
26
+ max-width: calc(100vw - var(--ifm-navbar-padding-horizontal) * 2);
26
27
  }
27
28
  }
28
29
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyops-cn/docusaurus-search-local",
3
- "version": "0.21.2",
3
+ "version": "0.22.0",
4
4
  "description": "An offline/local search plugin for Docusaurus v2.",
5
5
  "repository": "https://github.com/easyops-cn/docusaurus-search-local",
6
6
  "homepage": "https://github.com/easyops-cn/docusaurus-search-local",