type FileId = string;
const fileProcessors = new Map<FileId, FileProcessor>();
+const callbacks = new Map<FileId, ((values: undefined | number | Set<number>) => void)[]>();
export interface ExtraButton {
title: string;
const result = await deleteFile(element.fileId!);
if (result.ok) {
this.#unregisterFile(element);
+
+ notifyValueChange(this.#fieldId, this.values);
} else {
let container: HTMLElement = element;
if (!this.#useBigPreview) {
container.append(input);
this.addButtons(container, element);
+
+ notifyValueChange(this.#fieldId, this.values);
}
get values(): undefined | number | Set<number> {
return field.values;
}
+
+/**
+ * Registers a callback that will be called when the value of the field changes.
+ *
+ * @since 6.2
+ */
+export function registerCallback(fieldId: string, callback: (values: undefined | number | Set<number>) => void): void {
+ if (!callbacks.has(fieldId)) {
+ callbacks.set(fieldId, []);
+ }
+
+ callbacks.get(fieldId)!.push(callback);
+}
+
+/**
+ * @since 6.2
+ */
+export function unregisterCallback(
+ fieldId: string,
+ callback: (values: undefined | number | Set<number>) => void,
+): void {
+ callbacks.set(fieldId, callbacks.get(fieldId)?.filter((registeredCallback) => registeredCallback !== callback) ?? []);
+}
+
+function notifyValueChange(fieldId: string, values: undefined | number | Set<number>): void {
+ callbacks.get(fieldId)?.forEach((callback) => callback(values));
+}
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileProcessor = void 0;
exports.getValues = getValues;
+ exports.registerCallback = registerCallback;
+ exports.unregisterCallback = unregisterCallback;
Listener_1 = tslib_1.__importDefault(Listener_1);
const fileProcessors = new Map();
+ const callbacks = new Map();
class FileProcessor {
#container;
#uploadButton;
const result = await (0, DeleteFile_1.deleteFile)(element.fileId);
if (result.ok) {
this.#unregisterFile(element);
+ notifyValueChange(this.#fieldId, this.values);
}
else {
let container = element;
input.value = element.fileId.toString();
container.append(input);
this.addButtons(container, element);
+ notifyValueChange(this.#fieldId, this.values);
}
get values() {
if (this.#singleFileUpload) {
}
return field.values;
}
+ /**
+ * Registers a callback that will be called when the value of the field changes.
+ *
+ * @since 6.2
+ */
+ function registerCallback(fieldId, callback) {
+ if (!callbacks.has(fieldId)) {
+ callbacks.set(fieldId, []);
+ }
+ callbacks.get(fieldId).push(callback);
+ }
+ /**
+ * @since 6.2
+ */
+ function unregisterCallback(fieldId, callback) {
+ callbacks.set(fieldId, callbacks.get(fieldId)?.filter((registeredCallback) => registeredCallback !== callback) ?? []);
+ }
+ function notifyValueChange(fieldId, values) {
+ callbacks.get(fieldId)?.forEach((callback) => callback(values));
+ }
});