UNPKG

vue-bag-admin

Version:

Unified entry package for the Vue Bag Admin runtime ecosystem.

99 lines (98 loc) 3.08 kB
const a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), f = (t) => { a.set(t.code, t), t.options && o.set(t.code, { options: t.options, loadedAt: Date.now() }); }, D = (t) => { t.forEach(f); }, S = (t) => a.get(t), h = (t) => { var e; return ((e = o.get(t)) == null ? void 0 : e.options) ?? []; }, m = (t) => { if (t) { o.delete(t); return; } o.clear(); }, w = (t, e) => e ? t.ttl ? Date.now() - e.loadedAt < t.ttl : e.options.length > 0 : !1, b = async (t, e = !1) => { const n = a.get(t); if (!n) throw new Error(`[Dictionary] unknown code: ${t}`); const s = o.get(t); if (!e && w(n, s)) return (s == null ? void 0 : s.options) ?? []; if (n.options) return o.set(t, { options: n.options, loadedAt: Date.now() }), n.options; if (!n.getOptions) return []; const d = await n.getOptions(); return o.set(t, { options: d, loadedAt: Date.now() }), d; }, C = async (t, e) => (await b(t)).find((s) => s.value === e), c = "bag.admin.disabledPlugins", r = /* @__PURE__ */ new Map(), l = (t = []) => t.reduce((e, n) => e + 1 + l(n.children), 0), u = (t = []) => t.reduce((e, n) => e + 1 + u(n.children), 0), P = (t) => Object.values(t.contributes ?? {}).reduce((e, n) => e + n.length, 0), v = (t) => { r.clear(), t.forEach((e) => { r.set(e.id, e); }); }, g = { getDisabledPluginIds: () => { if (typeof window > "u") return []; try { const t = window.localStorage.getItem(c), e = t ? JSON.parse(t) : []; return Array.isArray(e) ? e.filter((n) => typeof n == "string") : []; } catch { return []; } }, setPluginEnabledState: (t, e) => { if (typeof window > "u") return; const n = new Set(i.getDisabledPluginIds()); e ? n.delete(t) : n.add(t), window.localStorage.setItem(c, JSON.stringify([...n])); } }; let i = g; const O = (t) => { i = t; }, I = () => { i = g; }, y = () => typeof window > "u" ? [] : i.getDisabledPluginIds(), p = (t) => { const e = y(); return t.enabled !== !1 && !e.includes(t.id); }, A = (t, e) => { i.setPluginEnabledState(t, e); }, E = () => [...r.values()].sort((t, e) => (t.order ?? 0) - (e.order ?? 0)).map((t) => { var e, n; return { id: t.id, name: t.name, version: t.version, order: t.order ?? 0, enabledByConfig: t.enabled !== !1, enabled: p(t), dependsOn: t.dependsOn ?? [], routeCount: l(t.routes), menuCount: u(t.menus), permissionCount: ((e = t.permissions) == null ? void 0 : e.length) ?? 0, settingCount: ((n = t.settings) == null ? void 0 : n.length) ?? 0, contributionCount: P(t) }; }); export { m as clearDictionaryCache, h as getCachedDictionaryOptions, S as getDictionaryDefinition, C as getDictionaryOption, y as getStoredDisabledPluginIds, p as isPluginEnabled, E as listRuntimePlugins, D as registerDictionaries, f as registerDictionary, v as registerRuntimePlugins, I as resetPluginStateProvider, b as resolveDictionaryOptions, A as setPluginEnabledState, O as setPluginStateProvider };