UNPKG

@nextcloud/vue

Version:
103 lines (102 loc) 4.67 kB
import p from "./NcEllipsisedOption.mjs"; import l from "./NcSelect.mjs"; import c from "@nextcloud/axios"; import { generateRemoteUrl as d } from "@nextcloud/router"; import { t as a } from "../chunks/l10n-9a5a6afc.mjs"; import { n as h } from "../chunks/_plugin-vue2_normalizer-5b4c43a4.mjs"; const o = (t) => { let e = {}; if (t.nodeType === 1) { if (t.attributes.length > 0) { e["@attributes"] = {}; for (let s = 0; s < t.attributes.length; s++) { const i = t.attributes.item(s); e["@attributes"][i.nodeName] = i.nodeValue; } } } else t.nodeType === 3 && (e = t.nodeValue); if (t.hasChildNodes()) for (let s = 0; s < t.childNodes.length; s++) { const i = t.childNodes.item(s), n = i.nodeName; if (typeof e[n] > "u") e[n] = o(i); else { if (typeof e[n].push > "u") { const u = e[n]; e[n] = [], e[n].push(u); } e[n].push(o(i)); } } return e; }, m = (t) => { let e = null; try { e = new DOMParser().parseFromString(t, "text/xml"); } catch (s) { console.error("Failed to parse xml document", s); } return e; }, r = (t) => { const e = o(m(t))["d:multistatus"]["d:response"], s = []; for (const i in e) { const n = e[i]["d:propstat"]; n["d:status"]["#text"] === "HTTP/1.1 200 OK" && s.push({ id: parseInt(n["d:prop"]["oc:id"]["#text"]), displayName: n["d:prop"]["oc:display-name"]["#text"], canAssign: n["d:prop"]["oc:can-assign"]["#text"] === "true", userAssignable: n["d:prop"]["oc:user-assignable"]["#text"] === "true", userVisible: n["d:prop"]["oc:user-visible"]["#text"] === "true" }); } return s; }, f = async function() { if (window.NextcloudVueDocs) return Promise.resolve(r(window.NextcloudVueDocs.tags)); const t = await c({ method: "PROPFIND", url: d("dav") + "/systemtags/", data: `<?xml version="1.0"?> <d:propfind xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns"> <d:prop> <oc:id /> <oc:display-name /> <oc:user-visible /> <oc:user-assignable /> <oc:can-assign /> </d:prop> </d:propfind>` }); return r(t.data); }, g = { name: "NcSelectTags", components: { NcEllipsisedOption: p, NcSelect: l }, props: { ...l.props, fetchTags: { type: Boolean, default: !0 }, getOptionLabel: { type: Function, default: (t) => { const { displayName: e, userVisible: s, userAssignable: i } = t; return s === !1 ? a("{tag} (invisible)", { tag: e }) : i === !1 ? a("{tag} (restricted)", { tag: e }) : e; } }, limit: { type: Number, default: 5 }, multiple: { type: Boolean, default: !0 }, optionsFilter: { type: Function, default: null }, passthru: { type: Boolean, default: !1 }, placeholder: { type: String, default: a("Select a tag") }, value: { type: [Number, Array], default: null }, " ": {} }, emits: ["input", " "], data() { return { search: "", availableTags: [] }; }, computed: { availableOptions() { return this.optionsFilter ? this.tags.filter(this.optionsFilter) : this.tags; }, localValue() { return this.tags.length === 0 ? [] : this.multiple ? this.value.filter((t) => t !== "").map((t) => this.tags.find((e) => e.id === t)) : this.tags.find((t) => t.id === this.value); }, propsToForward() { const { fetchTags: t, optionsFilter: e, passthru: s, ...i } = this.$props; return i; }, tags() { return this.fetchTags ? this.availableTags : this.options; } }, async created() { if (this.fetchTags) try { const t = await f(); this.availableTags = t; } catch (t) { console.error("Loading systemtags failed", t); } }, methods: { handleInput(t) { this.multiple ? this.$emit("input", t.map((e) => e.id)) : t === null ? this.$emit("input", null) : this.$emit("input", t.id); } } }; var y = function() { var t = this, e = t._self._c; return e("NcSelect", t._g(t._b({ attrs: { options: t.availableOptions, "close-on-select": !t.multiple, value: t.passthru ? t.value : t.localValue }, on: { search: (s) => t.search = s }, scopedSlots: t._u([{ key: "option", fn: function(s) { return [e("NcEllipsisedOption", { attrs: { name: t.getOptionLabel(s), search: t.search } })]; } }, { key: "selected-option", fn: function(s) { return [e("NcEllipsisedOption", { attrs: { name: t.getOptionLabel(s), search: t.search } })]; } }, t._l(t.$scopedSlots, function(s, i) { return { key: i, fn: function(n) { return [t._t(i, null, null, n)]; } }; })], null, !0) }, "NcSelect", t.propsToForward, !1), { ...t.$listeners, input: t.passthru ? t.$listeners.input : t.handleInput })); }, b = [], N = h(g, y, b, !1, null, null, null, null); const S = N.exports; export { S as default };