UNPKG

filepond

Version:

FilePond, where files go to stretch their bits.

60 lines (59 loc) • 1.69 kB
/*! * FilePond v5.0.2 * Copyright (c) 2017-2026 Pqina B.V. * Released under the MIT License * https://filepond.com */ import { noop as d } from "../utils/placeholder.js"; import { isFileEntry as E, isFile as V } from "../utils/test.js"; import { createExtension as v } from "./common/createExtension.js"; import { arrayRemoveFalsy as g, arrayItemsEqual as I } from "../utils/array.js"; import { Status as u } from "../common/status.js"; import { debounce as T } from "../utils/debounce.js"; const q = v({ name: "ValueCallbackStore", type: "store", props: { // if the value is required or not required: !1, // need to know the value key valueKey: "value", // custom function to convert entry to value for formdata entryToValue: void 0, // called when formdata object changed onChange: d }, factory: ({ props: a, didSetProps: i }, { on: s, getEntries: f, setExtensionStatus: n }) => { let t = []; i(() => { l(f()); }); function m(e) { const { valueKey: r } = a; if (Object.hasOwn(e.state, r)) return e.state[r]; if (!(!E(e) || !V(e.file))) return e.file; } function l(e) { const { required: r, onChange: p, entryToValue: y = m } = a, o = g(e.map(y)); t.length && I(t, o) || (t = o, r && !o.length ? n({ type: u.Error, code: "VALIDATION_INVALID_EMPTY", meta: { flag: "valueMissing" } }) : n({ type: u.System, code: "VALIDATION_COMPLETE" }), p(o)); } const c = s("updateEntries", T(l)); return { destroy: () => { t.length = 0, c(); } }; } }); export { q as ValueCallbackStore };