UNPKG

@patternplate/client

Version:

Universal javascript client application for patternplate

84 lines (70 loc) 3.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.selectDescription = exports.selectContents = exports.selectId = exports.selectFlag = exports.selectVersion = exports.selectTags = exports.selectName = exports.selectIcon = exports.selectActive = exports.selectType = exports.selectContentType = exports.selectManifest = exports.selectDependents = exports.selectDependencies = exports.default = void 0; var _reselect = require("reselect"); var _docs = require("./docs"); var _pool = require("./pool"); var _relation = _interopRequireDefault(require("./relation")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const selectVirtual = (0, _reselect.createSelector)(_docs.flat, docs => { return docs.filter(d => { const manifest = d.manifest; const _manifest$options = manifest.options, options = _manifest$options === void 0 ? {} : _manifest$options; const _options$query = options.query, query = _options$query === void 0 ? "" : _options$query; return Boolean(query); }); }); const selectItem = (0, _reselect.createSelector)(_pool.flat, state => state.id, (pool, id) => { const item = pool.find(item => id === `${item.contentType}/${item.id}`); if (item) { return item; } if (id === '/') { return pool[0]; } }); var _default = selectItem; exports.default = _default; const filter = hidden => { return hidden ? item => (item.manifest.options || {}).hidden !== true : i => i; }; const selectFilter = (0, _reselect.createSelector)(state => state.hide, hide => filter(hide)); const relation = key => (0, _relation.default)(key, selectItem, selectFilter); const selectDependencies = relation("dependencies"); exports.selectDependencies = selectDependencies; const selectDependents = relation("dependents"); exports.selectDependents = selectDependents; const selectManifest = (0, _reselect.createSelector)(selectItem, item => item ? JSON.stringify(item.manifest, null, " ") : ""); exports.selectManifest = selectManifest; const selectContentType = (0, _reselect.createSelector)(selectItem, item => item ? item.contentType : ""); exports.selectContentType = selectContentType; const selectType = (0, _reselect.createSelector)(selectItem, item => item ? item.type : ""); exports.selectType = selectType; const selectActive = (0, _reselect.createSelector)(selectItem, state => state.searchEnabled, (item, search) => !search && item !== null && typeof item !== "undefined"); exports.selectActive = selectActive; const selectIcon = (0, _reselect.createSelector)(selectItem, item => item ? item.manifest.icon || item.type : ""); exports.selectIcon = selectIcon; const selectName = (0, _reselect.createSelector)(selectItem, item => item ? item.manifest.displayName : ""); exports.selectName = selectName; const selectTags = (0, _reselect.createSelector)(selectItem, item => item ? item.manifest.tags || [] : []); exports.selectTags = selectTags; const selectVersion = (0, _reselect.createSelector)(selectItem, item => item ? item.manifest.version : ""); exports.selectVersion = selectVersion; const selectFlag = (0, _reselect.createSelector)(selectItem, item => item ? item.manifest.flag : ""); exports.selectFlag = selectFlag; const selectId = (0, _reselect.createSelector)(selectItem, item => item ? item.id : ""); exports.selectId = selectId; const selectContents = (0, _reselect.createSelector)(selectItem, item => { if (!item) { return null; } return typeof item.contents === "string" ? item.contents : null; }); exports.selectContents = selectContents; const selectDescription = (0, _reselect.createSelector)(selectItem, item => item ? item.manifest.description : ""); exports.selectDescription = selectDescription; //# sourceMappingURL=item.js.map