UNPKG

@topvisor/ui

Version:

Topvisor UI-kit Vue

217 lines (216 loc) 7.42 kB
import { d } from "../.chunks/forms-EIQ_3SBd.es.js"; import { C as I, i as T, u as b, a as y } from "../.chunks/forms-EIQ_3SBd.es.js"; import { c as G } from "../.chunks/core-BB__WDxl.es.js"; import { watch as p } from "vue"; import { guestLinkToClipboard as f } from "../utils/clipboard.js"; import { camelToSnakeCase as g } from "../utils/string.js"; import { getHash as l, setHash as m } from "../utils/route.js"; import { u as A, a as D } from "../.chunks/utils-CLxr2Yzo.es.js"; import { T as j } from "../.chunks/dialogs.vue_vue_type_script_setup_true_lang-B9iya2uP.es.js"; class u { #s; #t; /** * @deprecated */ #e; #a; #c; #i = []; #o = []; #r = []; #n = []; constructor(s) { var t; this.#t = s.store, this.#s = this.#t.$id, this.#e = s.options.Page, this.#a = s.options.user, this.#c = s.options.Api, this.#i = s.options.tpaNamesUrlHash || [], this.#o = s.options.tpaNamesStorage || [], this.#r = s.options.tpaNamesStorageLocal || [], this.#n = s.options.tpaNamesGuestLink || [], s.store.genGuestLink = (a, i) => this.genGuestLink(a, i), (t = this.#a.guest_data) != null && t.data || (this.#d(), this.#d(!0), this.#m()), this.#S(), this.#E(); const e = d(() => { this.#u(), this.#f(), this.#f(!0); }); s.store.$subscribe(e); } /** * Сгенерировать гостевую ссылку * * Метод, путь к которому указан в path, должен возвращать сгенерированную ссылку */ async genGuestLink(s, e) { const t = this.#g(); e = Object.assign(e, Object.fromEntries(t)); const a = await this.#c.gen(s).setParams(e).call(); if (a != null && a.errors) return; const i = a.result; await f(i); } /** * Сгенерировать опции для гостевой ссылки */ #g() { const s = /* @__PURE__ */ new Map(); return this.#n.forEach((e) => { const t = g(e); s.set(t, this.#t[e]); }), s; } /** * Установить опции из объекта без фиксации состояния */ #h(s) { s.forEach((e, t) => { const a = this.#t[t]; if (e != null && a !== void 0 && e != null && e.constructor && e.constructor === a.constructor) { if (t.indexOf("date") === 0 && !Array.isArray(e)) { if (typeof e == "string" && !/\d\d\d\d-\d\d-\d\d/.test(e)) return; } this.#t[t] = e; } }); } /** * Сгенерировать Map объект с опциями со значениями в виде json строк */ #l(s) { const e = /* @__PURE__ */ new Map(); return s.forEach((t, a) => { t !== null && (t = JSON.stringify(t), e.set(a, t)); }), e; } /** * Сгенерировать Map объект с опциями со значениями в оригинальном виде */ #p(s) { const e = /* @__PURE__ */ new Map(); return s.forEach((t, a) => { if (!(t == null || t === "false")) { try { if (typeof t == "string" && !/^\d\d\d\d-\d\d-\d\d$/.test(t) && (t = JSON.parse(t)), t == null || t === "false") return; } catch { } e.set(a, t); } }), e; } /** * Установить опции из хеша адреса страницы */ #m() { let s; try { s = JSON.parse(l(this.#s)); } catch { } if (!s) return; const e = /* @__PURE__ */ new Map(); this.#i.forEach((t) => { const a = s[t]; a && e.set(t, a); }), this.#h(e); } /** * Сохранить опции в хеш адреса страницы */ #u() { const s = /* @__PURE__ */ new Map(); this.#i.forEach((a) => { const i = this.#t[a]; s.set(a, i); }); const e = Object.fromEntries(s), t = JSON.stringify(e); m(this.#s, t); } /** * Установить опции из localStorage * @param isLocal - сохранить с учетом адреса страницы */ #d(s = !1) { const e = /* @__PURE__ */ new Map(); let t = this.#o, a = "state:" + this.#s; s && (t = this.#r, a = "state:" + this.#s + ":" + location.pathname), t.forEach((o) => { const r = localStorage.getItem(a + ":" + o); e.set(o, r); }); const i = this.#p(e); this.#h(i); } /** * Сохранить опции в localStorage * @param isLocal - сохранить с учетом адреса страницы */ #f(s = !1) { const e = /* @__PURE__ */ new Map(); let t = this.#o, a = "state:" + this.#s; s && (t = this.#r, a = "state:" + this.#s + ":" + location.pathname), t.forEach((o) => { const r = this.#t[o]; e.set(o, r); }); const i = this.#l(e); t.forEach((o) => { const r = i.get(o); localStorage.setItem(a + ":" + o, r); }); } /** * Установить опции из гостевой ссылки */ #S() { var i, o, r; const s = (o = (i = this.#a) == null ? void 0 : i.guest_data) == null ? void 0 : o.data; if (!s) return; this.#a.id === -1 && (this.#a.positionsReverseDates = s.positionsReverseDates); const e = /* @__PURE__ */ new Map(); this.#n.forEach((n) => { const h = s[n]; e.set(n, h); }); const t = this.#p(e); this.#h(t); const a = $(".mod_guest_title"); if (((r = this.#t.competitorsIds) == null ? void 0 : r.length) === 1 && this.#e.page.data.competitors) { let n = this.#e.page.data.competitors.filter((h) => h.id === s.competitorsIds[0]); n.length && ($("a", a).attr("href", "http://" + n[0].url), $("a", a).text(n[0].name)); } } /** * Подготовить входные параметры перед инициализацией основного функционала * * Входные параметры устанавливаются при открытии страницы * * Входные параметры могут меняться пользоваталем и устаревать */ #E() { this.#t.regionsIndexes && p(this.#t.regionsIndexes, (s) => { if (!s.length) return; s.forEach((a, i) => s[i] = a); const e = TplProjectSelectorRegion.genSearchersMap(), t = []; e.forEach((a) => { a.regions.forEach((i) => { i.index !== -1 && t.push(i.index); }); }), this.#t.regionsIndexes = s.filter((a) => t.includes(a)); }, { immediate: !0 }), this.#t.competitorsIds && p(this.#t.competitorsIds, (s) => { if (!s.length) return; s.forEach((t, a) => s[a] = t); const e = [this.#e.page.data.project.id]; this.#e.page.data.project.competitors.forEach((t) => { t.on >= 0 && e.push(t.id); }), this.#t.competitorsIds = s.filter((t) => e.includes(t)); }, { immediate: !0 }); } } const w = (c) => { var e, t, a, i; const s = c; !((e = s.options.tpaNamesUrlHash) != null && e.length) && !((t = s.options.tpaNamesStorage) != null && t.length) && !((a = s.options.tpaNamesStorageLocal) != null && a.length) && !((i = s.options.tpaNamesGuestLink) != null && i.length) || new u(s); }; export { I as Core, j as TopDialogWorker, G as corePlugin, T as i18nPlugin, w as piniaTPAPlugin, A as useAsyncTopDialog, b as useI18n, y as useI18nLang, D as useTopDialog }; //# sourceMappingURL=app.js.map