Files
aibuddytool/public/build/assets/NativeImageBlock-78162560.js
2023-11-26 18:56:40 +08:00

427 lines
12 KiB
JavaScript

import {
Y as _,
_ as y,
a as b,
i as g,
D as c,
G as w,
I as $,
h as f,
Z as S,
$ as I,
} from "./app-admin-62da08c5.js";
var m = _();
class p {
constructor(e, t, r) {
(this.name = e),
(this.definition = t),
(this.bindings = t.bindings ?? {}),
(this.wheres = t.wheres ?? {}),
(this.config = r);
}
get template() {
return `${this.origin}/${this.definition.uri}`.replace(/\/+$/, "");
}
get origin() {
return this.config.absolute
? this.definition.domain
? `${this.config.url.match(/^\w+:\/\//)[0]}${this.definition.domain}${
this.config.port ? `:${this.config.port}` : ""
}`
: this.config.url
: "";
}
get parameterSegments() {
var e;
return (
((e = this.template.match(/{[^}?]+\??}/g)) == null
? void 0
: e.map((t) => ({
name: t.replace(/{|\??}/g, ""),
required: !/\?}$/.test(t),
}))) ?? []
);
}
matchesUrl(e) {
if (!this.definition.methods.includes("GET")) return !1;
const t = this.template
.replace(/(\/?){([^}?]*)(\??)}/g, (n, l, u, h) => {
var d;
const a = `(?<${u}>${
((d = this.wheres[u]) == null
? void 0
: d.replace(/(^\^)|(\$$)/g, "")) || "[^/?]+"
})`;
return h ? `(${l}${a})?` : `${l}${a}`;
})
.replace(/^\w+:\/\//, ""),
[r, s] = e.replace(/^\w+:\/\//, "").split("?"),
i = new RegExp(`^${t}/?$`).exec(r);
if (i) {
for (const n in i.groups)
i.groups[n] =
typeof i.groups[n] == "string"
? decodeURIComponent(i.groups[n])
: i.groups[n];
return { params: i.groups, query: m.parse(s) };
}
return !1;
}
compile(e) {
const t = this.parameterSegments;
return t.length
? this.template
.replace(/{([^}?]+)(\??)}/g, (r, s, i) => {
if (!i && [null, void 0].includes(e[s]))
throw new Error(
`Ziggy error: '${s}' parameter is required for route '${this.name}'.`,
);
if (this.wheres[s]) {
if (
!new RegExp(
`^${i ? `(${this.wheres[s]})?` : this.wheres[s]}$`,
).test(e[s] ?? "")
)
throw new Error(
`Ziggy error: '${s}' parameter does not match required format '${this.wheres[s]}' for route '${this.name}'.`,
);
if (t[t.length - 1].name === s)
return encodeURIComponent(e[s] ?? "").replace(/%2F/g, "/");
}
return encodeURIComponent(e[s] ?? "");
})
.replace(`${this.origin}//`, `${this.origin}/`)
.replace(/\/+$/, "")
: this.template;
}
}
class v extends String {
constructor(e, t, r = !0, s) {
if (
(super(),
(this._config =
s ??
(typeof Ziggy < "u"
? Ziggy
: globalThis == null
? void 0
: globalThis.Ziggy)),
(this._config = { ...this._config, absolute: r }),
e)
) {
if (!this._config.routes[e])
throw new Error(`Ziggy error: route '${e}' is not in the route list.`);
(this._route = new p(e, this._config.routes[e], this._config)),
(this._params = this._parse(t));
}
}
toString() {
const e = Object.keys(this._params)
.filter(
(t) => !this._route.parameterSegments.some(({ name: r }) => r === t),
)
.filter((t) => t !== "_query")
.reduce((t, r) => ({ ...t, [r]: this._params[r] }), {});
return (
this._route.compile(this._params) +
m.stringify(
{ ...e, ...this._params._query },
{
addQueryPrefix: !0,
arrayFormat: "indices",
encodeValuesOnly: !0,
skipNulls: !0,
encoder: (t, r) => (typeof t == "boolean" ? Number(t) : r(t)),
},
)
);
}
_unresolve(e) {
e
? this._config.absolute &&
e.startsWith("/") &&
(e = this._location().host + e)
: (e = this._currentUrl());
let t = {};
const [r, s] = Object.entries(this._config.routes).find(
([i, n]) => (t = new p(i, n, this._config).matchesUrl(e)),
) || [void 0, void 0];
return { name: r, ...t, route: s };
}
_currentUrl() {
const { host: e, pathname: t, search: r } = this._location();
return (
(this._config.absolute
? e + t
: t
.replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ""), "")
.replace(/^\/+/, "/")) + r
);
}
current(e, t) {
const { name: r, params: s, query: i, route: n } = this._unresolve();
if (!e) return r;
const l = new RegExp(
`^${e.replace(/\./g, "\\.").replace(/\*/g, ".*")}$`,
).test(r);
if ([null, void 0].includes(t) || !l) return l;
const u = new p(r, n, this._config);
t = this._parse(t, u);
const h = { ...s, ...i };
return Object.values(t).every((a) => !a) &&
!Object.values(h).some((a) => a !== void 0)
? !0
: Object.entries(t).every(([a, d]) => h[a] == d);
}
_location() {
var s, i, n;
const {
host: e = "",
pathname: t = "",
search: r = "",
} = typeof window < "u" ? window.location : {};
return {
host: ((s = this._config.location) == null ? void 0 : s.host) ?? e,
pathname:
((i = this._config.location) == null ? void 0 : i.pathname) ?? t,
search: ((n = this._config.location) == null ? void 0 : n.search) ?? r,
};
}
get params() {
const { params: e, query: t } = this._unresolve();
return { ...e, ...t };
}
has(e) {
return Object.keys(this._config.routes).includes(e);
}
_parse(e = {}, t = this._route) {
e ?? (e = {}), (e = ["string", "number"].includes(typeof e) ? [e] : e);
const r = t.parameterSegments.filter(
({ name: s }) => !this._config.defaults[s],
);
return (
Array.isArray(e)
? (e = e.reduce(
(s, i, n) =>
r[n]
? { ...s, [r[n].name]: i }
: typeof i == "object"
? { ...s, ...i }
: { ...s, [i]: "" },
{},
))
: r.length === 1 &&
!e[r[0].name] &&
(e.hasOwnProperty(Object.values(t.bindings)[0]) ||
e.hasOwnProperty("id")) &&
(e = { [r[0].name]: e }),
{ ...this._defaults(t), ...this._substituteBindings(e, t) }
);
}
_defaults(e) {
return e.parameterSegments
.filter(({ name: t }) => this._config.defaults[t])
.reduce(
(t, { name: r }, s) => ({ ...t, [r]: this._config.defaults[r] }),
{},
);
}
_substituteBindings(e, { bindings: t, parameterSegments: r }) {
return Object.entries(e).reduce((s, [i, n]) => {
if (
!n ||
typeof n != "object" ||
Array.isArray(n) ||
!r.some(({ name: l }) => l === i)
)
return { ...s, [i]: n };
if (!n.hasOwnProperty(t[i]))
if (n.hasOwnProperty("id")) t[i] = "id";
else
throw new Error(
`Ziggy error: object passed as '${i}' parameter is missing route model binding key '${t[i]}'.`,
);
return { ...s, [i]: n[t[i]] };
}, {});
}
valueOf() {
return this.toString();
}
check(e) {
return this.has(e);
}
}
function x(o, e, t, r) {
const s = new v(o, e, t, r);
return o ? s.toString() : s;
}
const O = {
name: "NativeImageBlock",
props: { inputImage: { type: String, default: null } },
data: () => ({
isLoaded: !1,
isUploading: !1,
imgSrc: null,
placeholderSrc: "https://placekitten.com/g/2100/900",
}),
computed: {
getButtonName() {
var o;
return this.imgSrc != null &&
((o = this.imgSrc) == null ? void 0 : o.length) > 0
? "Change featured image"
: "Upload featured image";
},
getBlurPx() {
return this.imgSrc ? 0 : 12;
},
bgStyle() {
return {
backgroundImage: `url(${this.getImgSrc})`,
backgroundPosition: "center",
backgroundSize: "cover",
filter: `blur(${this.getBlurPx}px)`,
webkitFilter: `blur(${this.getBlurPx}px)`,
};
},
getImgSrc() {
var o;
return this.imgSrc != null &&
((o = this.imgSrc) == null ? void 0 : o.length) > 0
? this.imgSrc
: this.placeholderSrc;
},
},
methods: {
openFileInput() {
this.$refs.fileInput.click();
},
handleFileChange(o) {
const e = o.target.files[0];
e && this.uploadImage(e);
},
uploadImage(o) {
this.isUploading = !0;
const e = new FormData();
e.append("file", o),
e.append("forceSize", "true"),
b
.post(x("api.admin.upload.cloud.image"), e, {
headers: { "Content-Type": "multipart/form-data" },
})
.then((t) => {
t.data.success === 1 && t.data.file && t.data.file.url
? ((this.imgSrc = t.data.file.url),
this.$emit("saved", t.data.file.url))
: console.error(
"Image upload failed. Invalid response format.",
);
})
.catch((t) => {
console.error("Image upload failed:", t.response);
})
.finally(() => {
this.isUploading = !1;
});
},
setInputImage() {
var o;
this.inputImage != null &&
((o = this.inputImage) == null ? void 0 : o.length) > 0 &&
(this.imgSrc = this.inputImage),
(this.isLoaded = !0);
},
},
mounted() {
(this.isUploading = !1),
setTimeout(
function () {
this.setInputImage(), (this.isLoaded = !0);
}.bind(this),
3e3,
);
},
},
j = (o) => (S("data-v-d3857a0e"), (o = o()), I(), o),
k = { class: "card" },
B = { class: "card-body ratio ratio-21x9 bg-dark overflow-hidden" },
P = {
class:
"position-absolute w-100 h-100 d-flex justify-content-center text-center",
},
U = { key: 0, class: "align-self-center" },
q = j(() =>
c(
"div",
{ class: "spinner-border text-light", role: "status" },
[c("span", { class: "visually-hidden" }, "Loading...")],
-1,
),
),
C = [q],
E = { key: 1, class: "align-self-center" };
function F(o, e, t, r, s, i) {
return (
f(),
g("div", null, [
c("div", k, [
c("div", B, [
c(
"div",
{
class: "d-flex justify-content-center text-center rounded-2",
style: w(i.bgStyle),
},
null,
4,
),
c("div", P, [
o.isUploading || !o.isLoaded
? (f(), g("div", U, C))
: (f(),
g("div", E, [
c(
"input",
{
type: "file",
onChange:
e[0] ||
(e[0] = (...n) =>
i.handleFileChange && i.handleFileChange(...n)),
accept: "image/*",
ref: "fileInput",
style: { display: "none" },
},
null,
544,
),
c(
"button",
{
class: "btn btn-primary",
onClick:
e[1] ||
(e[1] = (...n) =>
i.openFileInput && i.openFileInput(...n)),
},
$(i.getButtonName),
1,
),
])),
]),
]),
]),
])
);
}
const N = y(O, [
["render", F],
["__scopeId", "data-v-d3857a0e"],
]),
Z = Object.freeze(
Object.defineProperty({ __proto__: null, default: N }, Symbol.toStringTag, {
value: "Module",
}),
);
export { Z as N, N as _, x as r };