import { EditModal } from "./components/EditModal.js"; export function initEditModal({ app = null, editModalOverride = null, container = null, services = {}, utilities = {}, callbacks = {}, eventTarget = null, } = {}) { const events = eventTarget instanceof EventTarget ? eventTarget : new EventTarget(); const { getMode = null, sanitizers = {}, r2Service = null, s3Service = null, storageService = null, } = services; const { removeTrackingScripts: removeTrackingScriptsFn = null, setGlobalModalState: setGlobalModalStateFn = null, escapeHtml = null, } = utilities; const { showError = null, showSuccess = null, getCurrentPubkey = null, safeEncodeNpub = null, onSubmit = null, onCancel = null, } = callbacks; const modal = (typeof editModalOverride === "function" ? editModalOverride({ app, eventTarget: events }) : editModalOverride) || new EditModal({ removeTrackingScripts: removeTrackingScriptsFn, setGlobalModalState: setGlobalModalStateFn, showError, showSuccess, getMode, sanitizers, escapeHtml, r2Service, s3Service, storageService, getCurrentPubkey, safeEncodeNpub, // Shared signer gate (#56): lets the "Replace file" pickers unlock storage // inline (cached keep-unlocked key or one passphrase prompt). ensureSigner: (options) => typeof app?.ensureEncryptionCapableSigner === "function" ? app.ensureEncryptionCapableSigner(options) : null, eventTarget: events, container, }); const boundSubmitHandler = typeof onSubmit === "function" ? (event) => onSubmit(event) : null; const boundCancelHandler = typeof onCancel === "function" ? () => onCancel() : null; if (boundSubmitHandler && typeof modal?.addEventListener === "function") { modal.addEventListener("video:edit-submit", boundSubmitHandler); } if (boundCancelHandler && typeof modal?.addEventListener === "function") { modal.addEventListener("video:edit-cancel", boundCancelHandler); } return { modal, events, handlers: { submit: boundSubmitHandler, cancel: boundCancelHandler, }, }; } export default initEditModal;