webstorm-init
Version:
CLI tool to write initial WebStorm settings into a new project
164 lines • 6.11 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StoreContext = exports.store = exports.Store = void 0;
const mobx_1 = require("mobx");
const api_1 = require("./api");
const consts_1 = require("./consts");
const react_1 = require("react");
const debounce_1 = __importDefault(require("lodash/debounce"));
class Store {
constructor() {
// input
this.input = "";
this.updateInputs = (value) => {
this.input = value;
this.debouncedSearch();
};
this.debouncedSearch = debounce_1.default(() => __awaiter(this, void 0, void 0, function* () {
if (!this.input.length) {
this.results = [];
return;
}
const data = yield api_1.fetchSearchResults(this.input);
if (data.type === "Results") {
this.error = null;
this.results = data.results;
}
else {
this.error = data;
this.results = [];
}
this.selectedIndex = 0;
}), 200);
// selectedIndex
this.selectedIndex = 0;
this.selectNext = () => {
const index = this.selectedIndex + 1;
if (index >= 0 && this.results.length > index) {
this.selectedIndex = index;
}
};
this.selectPrev = () => {
const index = this.selectedIndex - 1;
if (index >= 0 && this.results.length > index) {
this.selectedIndex = index;
}
};
// article
this.article = { type: "Article", title: "", summary: "" };
this.updateArticle = () => __awaiter(this, void 0, void 0, function* () {
this.article.title = this.selectedTitle;
this.article.summary = "Loading...";
const article = yield api_1.fetchArticle(this.selectedPageID);
if (article.type === "SearchError") {
this.article.summary = article.reason;
}
else {
this.article.summary = article.summary;
}
});
// results
this.results = [];
// isDetailsOpen
this.isDetailsOpen = false;
this.toggleDetails = () => {
if (this.isDetailsOpen) {
this.isDetailsOpen = false;
}
else if (this.results.length > 0) {
this.updateArticle();
this.isDetailsOpen = true;
}
};
this.isCleanUpTime = false;
this.lang = consts_1.DEFAULT_LANGUAGE;
this.error = null;
}
get selectedPageID() {
return this.results[this.selectedIndex].pageid;
}
get selectedURL() {
if (this.selectedIndex >= 0 && this.results.length > this.selectedIndex) {
return `https://${this.lang}.wikipedia.org/?curid=${this.selectedPageID}`;
}
else {
return "";
}
}
get selectedTitle() {
return this.results[this.selectedIndex].title;
}
}
__decorate([
mobx_1.observable
], Store.prototype, "input", void 0);
__decorate([
mobx_1.action
], Store.prototype, "updateInputs", void 0);
__decorate([
mobx_1.action
], Store.prototype, "debouncedSearch", void 0);
__decorate([
mobx_1.observable
], Store.prototype, "selectedIndex", void 0);
__decorate([
mobx_1.action
], Store.prototype, "selectNext", void 0);
__decorate([
mobx_1.action
], Store.prototype, "selectPrev", void 0);
__decorate([
mobx_1.computed
], Store.prototype, "selectedPageID", null);
__decorate([
mobx_1.computed
], Store.prototype, "selectedURL", null);
__decorate([
mobx_1.computed
], Store.prototype, "selectedTitle", null);
__decorate([
mobx_1.observable
], Store.prototype, "article", void 0);
__decorate([
mobx_1.action
], Store.prototype, "updateArticle", void 0);
__decorate([
mobx_1.observable
], Store.prototype, "results", void 0);
__decorate([
mobx_1.observable
], Store.prototype, "isDetailsOpen", void 0);
__decorate([
mobx_1.action
], Store.prototype, "toggleDetails", void 0);
__decorate([
mobx_1.observable
], Store.prototype, "isCleanUpTime", void 0);
__decorate([
mobx_1.observable
], Store.prototype, "lang", void 0);
__decorate([
mobx_1.observable
], Store.prototype, "error", void 0);
exports.Store = Store;
exports.store = new Store();
exports.StoreContext = react_1.createContext(exports.store);
//# sourceMappingURL=store.js.map