aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/commands.js4
-rw-r--r--src/shared/settings/default.js (renamed from src/shared/default-settings.js)4
-rw-r--r--src/shared/settings/values.js98
-rw-r--r--src/shared/store/provider.jsx13
4 files changed, 106 insertions, 13 deletions
diff --git a/src/shared/commands.js b/src/shared/commands.js
index 8edeb5c..ed64a63 100644
--- a/src/shared/commands.js
+++ b/src/shared/commands.js
@@ -9,7 +9,7 @@ const normalizeUrl = (args, searchConfig) => {
if (concat.includes('.') && !concat.includes(' ')) {
return 'http://' + concat;
}
- let query = encodeURI(concat);
+ let query = concat;
let template = searchConfig.engines[
searchConfig.default
];
@@ -19,7 +19,7 @@ const normalizeUrl = (args, searchConfig) => {
template = searchConfig.engines[key];
}
}
- return template.replace('{}', query);
+ return template.replace('{}', encodeURIComponent(query));
}
};
diff --git a/src/shared/default-settings.js b/src/shared/settings/default.js
index 608890b..d187565 100644
--- a/src/shared/default-settings.js
+++ b/src/shared/settings/default.js
@@ -15,8 +15,6 @@ export default {
"j": { "type": "scroll.vertically", "count": 1 },
"h": { "type": "scroll.horizonally", "count": -1 },
"l": { "type": "scroll.horizonally", "count": 1 },
- "<C-Y>": { "type": "scroll.vertically", "count": -1 },
- "<C-E>": { "type": "scroll.vertically", "count": 1 },
"<C-U>": { "type": "scroll.pages", "count": -0.5 },
"<C-D>": { "type": "scroll.pages", "count": 0.5 },
"<C-B>": { "type": "scroll.pages", "count": -1 },
@@ -62,5 +60,5 @@ export default {
"wikipedia": "https://en.wikipedia.org/w/index.php?search={}"
}
}
-}`
+}`,
};
diff --git a/src/shared/settings/values.js b/src/shared/settings/values.js
new file mode 100644
index 0000000..4e55fa0
--- /dev/null
+++ b/src/shared/settings/values.js
@@ -0,0 +1,98 @@
+const operationFromFormName = (name) => {
+ let [type, argStr] = name.split('?');
+ let args = {};
+ if (argStr) {
+ args = JSON.parse(argStr);
+ }
+ return Object.assign({ type }, args);
+};
+
+const operationToFormName = (op) => {
+ let type = op.type;
+ let args = Object.assign({}, op);
+ delete args.type;
+
+ if (Object.keys(args).length === 0) {
+ return type;
+ }
+ return op.type + '?' + JSON.stringify(args);
+};
+
+const valueFromJson = (json) => {
+ return JSON.parse(json);
+};
+
+const valueFromForm = (form) => {
+ let keymaps = undefined;
+ if (form.keymaps) {
+ keymaps = {};
+ for (let name of Object.keys(form.keymaps)) {
+ let keys = form.keymaps[name];
+ keymaps[keys] = operationFromFormName(name);
+ }
+ }
+
+ let search = undefined;
+ if (form.search) {
+ search = { default: form.search.default };
+
+ if (form.search.engines) {
+ search.engines = {};
+ for (let [name, url] of form.search.engines) {
+ search.engines[name] = url;
+ }
+ }
+ }
+
+ let blacklist = form.blacklist;
+
+ return { keymaps, search, blacklist };
+};
+
+const jsonFromValue = (value) => {
+ return JSON.stringify(value, undefined, 2);
+};
+
+const formFromValue = (value, allowedOps) => {
+ let keymaps = undefined;
+
+ if (value.keymaps) {
+ let allowedSet = new Set(allowedOps);
+
+ keymaps = {};
+ for (let keys of Object.keys(value.keymaps)) {
+ let op = operationToFormName(value.keymaps[keys]);
+ if (allowedSet.has(op)) {
+ keymaps[op] = keys;
+ }
+ }
+ }
+
+ let search = undefined;
+ if (value.search) {
+ search = { default: value.search.default };
+ if (value.search.engines) {
+ search.engines = Object.keys(value.search.engines).map((name) => {
+ return [name, value.search.engines[name]];
+ });
+ }
+ }
+
+ let blacklist = value.blacklist;
+
+ return { keymaps, search, blacklist };
+};
+
+const jsonFromForm = (form) => {
+ return jsonFromValue(valueFromForm(form));
+};
+
+const formFromJson = (json, allowedOps) => {
+ let value = valueFromJson(json);
+ return formFromValue(value, allowedOps);
+};
+
+export {
+ valueFromJson, valueFromForm, jsonFromValue, formFromValue,
+ jsonFromForm, formFromJson
+};
diff --git a/src/shared/store/provider.jsx b/src/shared/store/provider.jsx
index 743f656..fe925aa 100644
--- a/src/shared/store/provider.jsx
+++ b/src/shared/store/provider.jsx
@@ -1,18 +1,15 @@
-import React from 'react';
-import PropTypes from 'prop-types';
+import { h, Component } from 'preact';
-class Provider extends React.PureComponent {
+class Provider extends Component {
getChildContext() {
return { store: this.props.store };
}
render() {
- return React.Children.only(this.props.children);
+ return <div>
+ { this.props.children }
+ </div>;
}
}
-Provider.childContextTypes = {
- store: PropTypes.any,
-};
-
export default Provider;