summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/gitbook-core/package.json2
-rw-r--r--packages/gitbook-core/src/components/IntlProvider.js22
-rw-r--r--packages/gitbook-core/src/index.js10
-rw-r--r--packages/gitbook-core/src/renderWithStore.js6
-rw-r--r--packages/gitbook-plugin-search/index.js (renamed from packages/gitbook-plugin-sharing/index.js)0
-rw-r--r--packages/gitbook-plugin-search/package.json24
-rw-r--r--packages/gitbook-plugin-search/src/actions/search.js49
-rw-r--r--packages/gitbook-plugin-search/src/actions/types.js7
-rw-r--r--packages/gitbook-plugin-search/src/components/Input.js47
-rw-r--r--packages/gitbook-plugin-search/src/components/Results.js28
-rw-r--r--packages/gitbook-plugin-search/src/index.js13
-rw-r--r--packages/gitbook-plugin-search/src/reducers/index.js3
-rw-r--r--packages/gitbook-plugin-search/src/reducers/search.js37
-rw-r--r--packages/gitbook-plugin-sharing/package.json52
-rw-r--r--packages/gitbook-plugin-sharing/src/Button.js17
-rw-r--r--packages/gitbook-plugin-sharing/src/index.js6
16 files changed, 245 insertions, 78 deletions
diff --git a/packages/gitbook-core/package.json b/packages/gitbook-core/package.json
index 8899a0d..7105525 100644
--- a/packages/gitbook-core/package.json
+++ b/packages/gitbook-core/package.json
@@ -4,6 +4,7 @@
"description": "Core for GitBook plugins API",
"main": "./lib/index.js",
"dependencies": {
+ "bluebird": "^3.4.6",
"classnames": "^2.2.5",
"html-tags": "^1.1.1",
"immutable": "^3.8.1",
@@ -11,6 +12,7 @@
"react-dom": "^15.3.1",
"react-helmet": "^3.1.0",
"react-immutable-proptypes": "^2.1.0",
+ "react-intl": "^2.1.5",
"react-redux": "^4.4.5",
"react-safe-html": "^0.3.0",
"redux": "^3.5.2",
diff --git a/packages/gitbook-core/src/components/IntlProvider.js b/packages/gitbook-core/src/components/IntlProvider.js
new file mode 100644
index 0000000..0377b4d
--- /dev/null
+++ b/packages/gitbook-core/src/components/IntlProvider.js
@@ -0,0 +1,22 @@
+const React = require('react');
+const intl = require('react-intl');
+const ReactRedux = require('react-redux');
+
+const IntlProvider = React.createClass({
+ propTypes: {
+ children: React.PropTypes.node
+ },
+
+ render() {
+ // TODO
+ const messages = {};
+
+ return (
+ <intl.IntlProvider locale={'en'} messages={messages}>
+ {this.props.children}
+ </intl.IntlProvider>
+ );
+ }
+});
+
+module.exports = ReactRedux.connect()(IntlProvider);
diff --git a/packages/gitbook-core/src/index.js b/packages/gitbook-core/src/index.js
index 02eb68f..cb107c8 100644
--- a/packages/gitbook-core/src/index.js
+++ b/packages/gitbook-core/src/index.js
@@ -1,5 +1,7 @@
const React = require('react');
+const Immutable = require('immutable');
const Head = require('react-helmet');
+const Promise = require('bluebird');
const { Provider } = require('react-redux');
const { Flex, Box } = require('reflexbox');
@@ -9,6 +11,7 @@ const HTMLContent = require('./components/HTMLContent');
const Link = require('./components/Link');
const Icon = require('./components/Icon');
const Button = require('./components/Button');
+const IntlProvider = require('./components/IntlProvider');
const { registerComponent } = require('./actions/components');
const ACTIONS = require('./actions/TYPES');
@@ -46,7 +49,10 @@ module.exports = {
Link,
Icon,
Button,
- React,
// Utilities
- Shapes
+ Shapes,
+ // Librairies
+ React,
+ Immutable,
+ Promise
};
diff --git a/packages/gitbook-core/src/renderWithStore.js b/packages/gitbook-core/src/renderWithStore.js
index 48fff89..55594c4 100644
--- a/packages/gitbook-core/src/renderWithStore.js
+++ b/packages/gitbook-core/src/renderWithStore.js
@@ -1,7 +1,9 @@
const React = require('react');
const { Provider } = require('react-redux');
+
const { InjectedComponent } = require('./components/InjectedComponent');
const PJAXWrapper = require('./components/PJAXWrapper');
+const IntlProvider = require('./components/IntlProvider');
/**
* Render the application for a store
@@ -12,7 +14,9 @@ function renderWithStore(store) {
return (
<Provider store={store}>
<PJAXWrapper>
- <InjectedComponent matching={{ role: 'Body' }} />
+ <IntlProvider>
+ <InjectedComponent matching={{ role: 'Body' }} />
+ </IntlProvider>
</PJAXWrapper>
</Provider>
);
diff --git a/packages/gitbook-plugin-sharing/index.js b/packages/gitbook-plugin-search/index.js
index 5803889..5803889 100644
--- a/packages/gitbook-plugin-sharing/index.js
+++ b/packages/gitbook-plugin-search/index.js
diff --git a/packages/gitbook-plugin-search/package.json b/packages/gitbook-plugin-search/package.json
new file mode 100644
index 0000000..df84726
--- /dev/null
+++ b/packages/gitbook-plugin-search/package.json
@@ -0,0 +1,24 @@
+{
+ "name": "gitbook-plugin-search",
+ "description": "Search integration in GitBook",
+ "main": "index.js",
+ "version": "2.0.0",
+ "dependencies": {
+ "gitbook-core": "^0.0.0"
+ },
+ "devDependencies": {
+ "gitbook-plugin": "*"
+ },
+ "engines": {
+ "gitbook": ">=3.0.0"
+ },
+ "homepage": "https://github.com/GitbookIO/gitbook",
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/GitbookIO/gitbook.git"
+ },
+ "license": "Apache-2.0",
+ "bugs": {
+ "url": "https://github.com/GitbookIO/gitbook/issues"
+ }
+}
diff --git a/packages/gitbook-plugin-search/src/actions/search.js b/packages/gitbook-plugin-search/src/actions/search.js
new file mode 100644
index 0000000..e9852cc
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/actions/search.js
@@ -0,0 +1,49 @@
+const { Promise, Immutable } = require('gitbook-core');
+const { List } = Immutable;
+const TYPES = require('./types');
+
+/**
+ * Start a search query
+ * @param {String} q
+ * @return {Action}
+ */
+function query(q) {
+ return (dispatch, getState) => {
+ const handlers = getState().search;
+
+ dispatch({ type: TYPES.UPDATE_QUERY, query: q });
+
+ return Promise.reduce(handlers, (results, handler) => {
+ return Promise(handler(q))
+ .then(handlerResults => results.concat(handlerResults));
+ }, List())
+ .then(results => {
+ dispatch({ type: TYPES.UPDATE_RESULTS, query: q });
+ });
+ };
+}
+
+/**
+ * Register a search handler
+ * @param {String} name
+ * @param {Function} handler
+ * @return {Action}
+ */
+function registerHandler(name, handler) {
+ return { type: TYPES.REGISTER_HANDLER, name, handler };
+}
+
+/**
+ * Unregister a search handler
+ * @param {String} name
+ * @return {Action}
+ */
+function unregisterHandler(name) {
+ return { type: TYPES.UNREGISTER_HANDLER, name };
+}
+
+module.exports = {
+ query,
+ registerHandler,
+ unregisterHandler
+};
diff --git a/packages/gitbook-plugin-search/src/actions/types.js b/packages/gitbook-plugin-search/src/actions/types.js
new file mode 100644
index 0000000..a88b1f0
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/actions/types.js
@@ -0,0 +1,7 @@
+
+module.exports = {
+ REGISTER_HANDLER: 'search/register_handler',
+ UNREGISTER_HANDLER: 'search/unregister_handler',
+ UPDATE_QUERY: 'search/update_query',
+ UPDATE_RESULTS: 'search/update_results'
+};
diff --git a/packages/gitbook-plugin-search/src/components/Input.js b/packages/gitbook-plugin-search/src/components/Input.js
new file mode 100644
index 0000000..c4d1288
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/components/Input.js
@@ -0,0 +1,47 @@
+const GitBook = require('gitbook-core');
+const { React } = GitBook;
+
+const search = require('../actions/search');
+
+const DEBOUNCE_MS = 600;
+
+const SearchInput = React.createClass({
+ propTypes: {
+ dispatch: React.PropTypes.func
+ },
+
+ onUpdateQuery(q) {
+ const { dispatch } = this.props;
+
+ dispatch(search.query(q));
+ },
+
+ onKeyDown(event) {
+ const { value } = event.currentTarget;
+
+ if (this.debouncedSearch) {
+ clearTimeout(this.debouncedSearch);
+ }
+
+ this.debouncedSearch = setTimeout(() => {
+ this.debouncedSearch = null;
+ this.onUpdateQuery(value);
+ }, DEBOUNCE_MS);
+ },
+
+ componentWillUnmount() {
+ if (this.debouncedSearch) {
+ clearTimeout(this.debouncedSearch);
+ }
+ },
+
+ render() {
+ return (
+ <div className="Search/Input">
+ <input type="text" placeholder="" onKeyDown={this.onKeyDown} />
+ </div>
+ );
+ }
+});
+
+module.exports = GitBook.connect(SearchInput);
diff --git a/packages/gitbook-plugin-search/src/components/Results.js b/packages/gitbook-plugin-search/src/components/Results.js
new file mode 100644
index 0000000..99bc63d
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/components/Results.js
@@ -0,0 +1,28 @@
+const GitBook = require('gitbook-core');
+const { React } = GitBook;
+
+const SearchResults = React.createClass({
+ propTypes: {
+ results: GitBook.Shapes.list
+ },
+
+ render() {
+ const { results } = this.props;
+
+ return (
+ <div className="Search/Results">
+ {results.map(result => {
+
+ })}
+ </div>
+ );
+ }
+});
+
+function mapStateToProps(state) {
+ return {
+ results: state.search.results
+ };
+}
+
+module.exports = GitBook.connect(SearchResults, mapStateToProps);
diff --git a/packages/gitbook-plugin-search/src/index.js b/packages/gitbook-plugin-search/src/index.js
new file mode 100644
index 0000000..94a5d35
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/index.js
@@ -0,0 +1,13 @@
+const GitBook = require('gitbook-core');
+
+const SearchInput = require('./components/Input');
+const SearchResults = require('./components/Results');
+const reducers = require('./reducers');
+
+module.exports = GitBook.createPlugin(
+ (dispatch, state) => {
+ dispatch(GitBook.registerComponent(SearchInput, { role: 'search:input' }));
+ dispatch(GitBook.registerComponent(SearchResults, { role: 'search:results' }));
+ },
+ reducers
+);
diff --git a/packages/gitbook-plugin-search/src/reducers/index.js b/packages/gitbook-plugin-search/src/reducers/index.js
new file mode 100644
index 0000000..bfce2bd
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/reducers/index.js
@@ -0,0 +1,3 @@
+const GitBook = require('gitbook-core');
+
+module.exports = GitBook.createReducer('search', require('./search'));
diff --git a/packages/gitbook-plugin-search/src/reducers/search.js b/packages/gitbook-plugin-search/src/reducers/search.js
new file mode 100644
index 0000000..ac49698
--- /dev/null
+++ b/packages/gitbook-plugin-search/src/reducers/search.js
@@ -0,0 +1,37 @@
+const GitBook = require('gitbook-core');
+const { Record, List, OrderedMap } = GitBook.Immutable;
+
+const TYPES = require('../actions/types');
+
+const Result = Record({
+ url: String(''),
+ title: String(''),
+ body: String('')
+});
+
+const SearchState = Record({
+ // Current query
+ query: String(''),
+ // Current list of results
+ results: List(),
+ // Search handlers
+ handlers: OrderedMap()
+});
+
+module.exports = (state = SearchState(), action) => {
+ switch (action.type) {
+
+ case TYPES.REGISTER_HANDLER:
+ return state.merge({
+ handlers: state.handlers.set(action.name, action.handler)
+ });
+
+ case TYPES.UNREGISTER_HANDLER:
+ return state.merge({
+ handlers: state.handlers.remove(action.name)
+ });
+
+ default:
+ return state;
+ }
+};
diff --git a/packages/gitbook-plugin-sharing/package.json b/packages/gitbook-plugin-sharing/package.json
deleted file mode 100644
index 134acb8..0000000
--- a/packages/gitbook-plugin-sharing/package.json
+++ /dev/null
@@ -1,52 +0,0 @@
-{
- "name": "gitbook-plugin-sharing",
- "description": "Sharing buttons in GitBooks website",
- "main": "index.js",
- "version": "1.0.2",
- "dependencies": {
- "gitbook-core": "^0.0.0",
- "react": "^15.3.1"
- },
- "devDependencies": {
- "gitbook-plugin": "*"
- },
- "engines": {
- "gitbook": ">=3.0.0"
- },
- "homepage": "https://github.com/GitbookIO/plugin-sharing",
- "repository": {
- "type": "git",
- "url": "https://github.com/GitbookIO/plugin-sharing.git"
- },
- "license": "Apache-2.0",
- "bugs": {
- "url": "https://github.com/GitbookIO/plugin-sharing/issues"
- },
- "gitbook": {
- "properties": {
- "facebook": { "type": "boolean", "default": true, "title": "Facebook" },
- "twitter": { "type": "boolean", "default": true, "title": "Twitter" },
- "google": { "type": "boolean", "default": false, "title": "Google" },
- "weibo": { "type": "boolean", "default": false, "description": "Weibo" },
- "instapaper": { "type": "boolean", "default": false, "description": "Instapaper" },
- "vk": { "type": "boolean", "default": false, "description": "VK" },
- "all": {
- "type": "array",
- "items": {
- "type": "string"
- },
- "default": [
- "facebook",
- "google",
- "twitter",
- "weibo",
- "instapaper"
- ],
- "uniqueItems": true
- }
- }
- },
- "devDependencies": {
- "eslint": "^2.7.0"
- }
-}
diff --git a/packages/gitbook-plugin-sharing/src/Button.js b/packages/gitbook-plugin-sharing/src/Button.js
deleted file mode 100644
index 0cfce7c..0000000
--- a/packages/gitbook-plugin-sharing/src/Button.js
+++ /dev/null
@@ -1,17 +0,0 @@
-const React = require('react');
-const GitBook = require('gitbook-core');
-
-const ShareButton = React.createClass({
- render() {
- return (
- <button>Share</button>
- );
- }
-});
-
-function mapStateToProps(state) {
-
-}
-
-
-module.exports = GitBook.connect(ShareButton, mapStateToProps);
diff --git a/packages/gitbook-plugin-sharing/src/index.js b/packages/gitbook-plugin-sharing/src/index.js
deleted file mode 100644
index e33a470..0000000
--- a/packages/gitbook-plugin-sharing/src/index.js
+++ /dev/null
@@ -1,6 +0,0 @@
-const GitBook = require('gitbook-core');
-const ShareButton = require('./Button');
-
-module.exports = GitBook.createPlugin((dispatch, state) => {
- dispatch(GitBook.registerComponent(ShareButton, { role: 'Toolbar:ActionButton' }));
-});