filepond
Version:
FilePond, where files go to stretch their bits.
68 lines (67 loc) • 2.02 kB
JavaScript
/*!
* FilePond v5.0.2
* Copyright (c) 2017-2026 Pqina B.V.
* Released under the MIT License
* https://filepond.com
*/
import { getAsElement as v, addListener as b } from "../utils/dom.js";
import { createExtension as I } from "./common/createExtension.js";
import { noop as h } from "../utils/placeholder.js";
import { warn as E } from "../common/console.js";
import { mapTree as g } from "../utils/tree.js";
const L = I({
name: "FileInputSource",
type: "source",
props: {
element: void 0,
resetFilesOnAdd: !1,
insertIndex: 0,
preventAddEntries: void 0,
// source label and icon to use
sourceIcon: "device",
sourceLabel: void 0,
// is disabled
disabled: void 0
},
factory: ({ didSetProps: u, props: d }, { insertEntries: f, removeEntries: m, setExtensionState: p }) => {
let i, e, s, r;
function a() {
const { insertIndex: t, resetFilesOnAdd: o } = d;
s && m(s);
const n = g(Array.from(e.files ?? []), (c) => ({
src: c,
origin: "input"
}));
s = n, f(n, t > -1 ? t : void 0), o && (e.files = new DataTransfer().files);
}
function l() {
const { sourceLabel: t, sourceIcon: o, disabled: n } = d, c = !e.hasAttribute("data-readonly");
p({
source: c ? {
type: "browse",
label: t,
icon: o,
disabled: n,
onclick: () => {
e.click();
}
} : void 0
});
}
return u(({ element: t, preventAddEntries: o }) => {
if (!t)
return;
const n = v(t);
n || E(`FileInputSource: HTMLInputElement not found ${t}`), e !== n && (i?.(), i = void 0, r || (r = new MutationObserver(() => {
l();
})), r.disconnect(), r.observe(n, { attributeFilter: ["data-readonly"] }), e = n), e.disabled = o, i = e ? b(e, "change", a) : h, e.files?.length || Promise.resolve().then(a), l();
}), {
destroy() {
r?.disconnect(), i?.();
}
};
}
});
export {
L as FileInputSource
};