Files
wekan/models/lib/editorSubmitKey.js
T
Lauri Ojansivu 8d1fae4f7d Convert client-reachable models/lib helpers from CommonJS to ES modules (1/2).
The rspack client build treats a `module.exports` file imported into the
client bundle as an ES module and throws
"ES Modules may not assign module.exports" at evaluation time, aborting
the whole client module chain (No such template: swimlane / notifications
/ boardButtons, blank board, missing top bar). This is not an rspack
version regression (the lockfile has pinned ~1.7.x since v8.40); it is
that WeKan added CommonJS helpers to the client bundle.

Convert the 42 client-reachable pure-logic models/lib helpers from
`module.exports = { ... }` to `export { ... }`, and calendarFilter's
internal require('./swimlaneFilter') to an import with a .js extension
(node ESM needs it; rspack/reify tolerate it). Server-only helpers that
use node built-ins (fs/path/child_process) stay CommonJS. The plain-Node
.cjs unit tests for these helpers now use `await import(...js)` (wrapped
in an async IIFE); a source-guard in importVirtualMembers was updated
from module.exports to export. Verified: the full tests/*.test.cjs suite
has the SAME 7 pre-existing failures as before this change and no new
ones.
2026-07-23 18:55:30 +03:00

33 lines
1.4 KiB
JavaScript

'use strict';
// #4236 "The processing strategy for the enter key is different". The card
// TITLE textarea submitted on PLAIN Enter (only Shift+Enter made a newline),
// while the card DESCRIPTION textarea — and the shared inlinedForm — insert a
// newline on plain Enter and only submit on Ctrl/Cmd+Enter. That inconsistency
// meant Enter could not add a new line in the title.
//
// isSubmitKey centralizes the "does this keydown submit the editor?" rule so
// every multi-line editor field behaves the same.
//
// Default (submitOnEnter off): submit ONLY on Enter together with Ctrl or Cmd;
// plain Enter and Shift+Enter fall through to the textarea default (a newline).
//
// Opt-in per-user setting (submitOnEnter on, Member Settings): plain Enter
// submits and Shift+Enter inserts a newline — restoring the pre-#4236 fast
// title-editing workflow for users who prefer it, without affecting anyone else.
//
// Meteor-free and unit tested. The caller passes the current user's preference
// as opts.submitOnEnter so this stays a pure function.
function isSubmitKey(event, opts = {}) {
if (!event) return false;
const isEnter = event.keyCode === 13 || event.key === 'Enter';
if (!isEnter) return false;
if (opts.submitOnEnter) {
// plain Enter submits; Shift+Enter is a newline (Ctrl/Cmd+Enter also submits)
return !event.shiftKey;
}
return !!(event.ctrlKey || event.metaKey);
}
export { isSubmitKey };