mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A transitive walk from client/main.js found the remaining CommonJS
(module.exports) helpers that the rspack client build pulls into the ES
module graph and rejects: 3 client/lib helpers (cardDragGeometry,
inlinedFormManager, popupOffset), 4 imports/lib helpers (boardAutoScroll,
datePickerTime, fileNameDisplay, staleWhileRevalidate), imports/simpleSchema
(its meteor/aldeed:simple-schema require becomes a namespace import),
imports/i18n/loadHelpers, and 4 more models/lib helpers (cardLinkRedirect,
sandstormAutoOpen, securityCategories, securityLogFormat). All become
`export { ... }`; their .cjs unit tests use `await import(...js)`.
The only CJS files still reachable in the walk are server-only: the
server/lib/* files (Meteor never bundles server/ to the client) and the
fs-using models/lib file-storage helpers (reached only via the server-side
fileStoreStrategy; they would fail on require("fs") if they were actually in
the client bundle). Those correctly stay CommonJS.
Full tests/*.test.cjs suite: same 7 pre-existing failures, no new ones.
78 lines
3.1 KiB
JavaScript
78 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
// Pure state transitions for the "only one inlined form open at a time"
|
|
// invariant — extracted so it is unit-testable without a DOM / Meteor
|
|
// (see tests/inlinedFormSingleOpen.test.cjs).
|
|
//
|
|
// #2418 ("Checklist item gets overwritten by previous item when selecting
|
|
// another item with mouse"): opening a checklist item's edit form while
|
|
// another item was already in edit mode did not close the previous form.
|
|
// With two edit forms open at once, the submit handlers (which locate the
|
|
// textarea with a template-wide `tpl.find('textarea.js-edit-checklist-item')`,
|
|
// i.e. FIRST match in DOM order) read the OTHER form's textarea and
|
|
// overwrote the submitted item with the previous item's text.
|
|
//
|
|
// Root cause in current code: the `.js-open-inlined-form` click handler
|
|
// tried to close the previously opened form with
|
|
// `EscapeActions.clickExecute(evt.target, 'inlinedForm')`, but the
|
|
// 'inlinedForm' escape action is registered with `enabledOnClick: false`,
|
|
// and EscapeActions._execute skips such actions for click executions
|
|
// (`isEnabled = enabledOnClick || !isClick`). So the call was silently a
|
|
// no-op and the previous form stayed open. (Regression from 8c3ce4bb7,
|
|
// 2021-10-19, which replaced `EscapeActions.executeUpTo('inlinedForm')`
|
|
// with `clickExecute` to stop popups from closing.)
|
|
//
|
|
// A secondary corruption: the close/submit/destroy paths reset the shared
|
|
// `currentlyOpenedForm` tracker UNCONDITIONALLY, so closing a stale form
|
|
// (e.g. checklists' "click all .js-close-inlined-form" workaround) nulled
|
|
// the tracker for a DIFFERENT, still-open form — after which Escape no
|
|
// longer closed the open form but fell through to closing the whole
|
|
// card-details pane.
|
|
//
|
|
// The functions below centralize the transitions and fix both problems:
|
|
// - openForm() explicitly closes the previously tracked form, without
|
|
// touching popups (preserving the 8c3ce4bb7 intent).
|
|
// - closeForm()/forgetForm() only reset the tracker when the form being
|
|
// closed/destroyed IS the tracked one.
|
|
//
|
|
// `tracker` is a ReactiveVar-like object ({ get(), set(v) }) holding the
|
|
// currently opened form; a "form" is any object with an `isOpen`
|
|
// ReactiveVar-like property.
|
|
|
|
/** Open `form`, closing the previously tracked form (if any and different). */
|
|
function openForm(tracker, form) {
|
|
const previous = tracker.get();
|
|
if (previous && previous !== form && previous.isOpen) {
|
|
previous.isOpen.set(false);
|
|
}
|
|
if (form && form.isOpen) {
|
|
form.isOpen.set(true);
|
|
}
|
|
tracker.set(form);
|
|
}
|
|
|
|
/**
|
|
* Close `form`. Resets the tracker ONLY when `form` is the tracked one, so
|
|
* closing a stale/already-closed form cannot orphan another open form.
|
|
*/
|
|
function closeForm(tracker, form) {
|
|
if (form && form.isOpen) {
|
|
form.isOpen.set(false);
|
|
}
|
|
if (tracker.get() === form) {
|
|
tracker.set(null);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Stop tracking `form` without touching its own state (template destroyed).
|
|
* Only resets the tracker when `form` is the tracked one.
|
|
*/
|
|
function forgetForm(tracker, form) {
|
|
if (tracker.get() === form) {
|
|
tracker.set(null);
|
|
}
|
|
}
|
|
|
|
export { openForm, closeForm, forgetForm };
|