diff --git a/cla.json b/cla.json
index 6d978e7e4..b06c78090 100644
--- a/cla.json
+++ b/cla.json
@@ -1,3 +1,9 @@
{
- "signedContributors": []
+ "signedContributors": [
+ {
+ "name": "cherepanov",
+ "id": 876145,
+ "comment_id": 7312519755
+ }
+ ]
}
diff --git a/designer-guide/content/behavior-and-validation/form-level-actions-in-settings.md b/designer-guide/content/behavior-and-validation/form-level-actions-in-settings.md
index 9861b4e7c..1a1e26cb2 100644
--- a/designer-guide/content/behavior-and-validation/form-level-actions-in-settings.md
+++ b/designer-guide/content/behavior-and-validation/form-level-actions-in-settings.md
@@ -36,7 +36,9 @@ Field-level validation still lives on each field's **Rules** tab.
-3. Enter a **Name**, write or paste the script, and click **Save**.
+3. Enter a **Name**, write or paste the script, then click **Save** (or press
+ Ctrl+S /
+ ⌘+S while the cursor is in the editor).
4. Select the button or other component that should run the action.
5. Open its **Actions** tab and click **Add an action** under the event you want to use, such as **onClick**.
6. Open **Code** and select the saved action by name.
@@ -52,7 +54,7 @@ Field-level validation still lives on each field's **Rules** tab.
3. Edit validator code only when your team assigns you that task. Many teams restrict this to developers.
-4. Click **Save** when finished.
+4. Click **Save** when finished (or use the code editor save shortcut).
## Test
@@ -69,5 +71,6 @@ trigger that event in **Preview**.
## See also
+- [Keyboard shortcuts](/help/keyboard-shortcuts)
- [Actions basics](/behavior-and-validation/actions-basics)
- [Actions (developer depth)](docs:formengine-designer/features/actions)
diff --git a/designer-guide/content/help/common-problems-and-fixes.md b/designer-guide/content/help/common-problems-and-fixes.md
index 138b267e1..32ae50a1c 100644
--- a/designer-guide/content/help/common-problems-and-fixes.md
+++ b/designer-guide/content/help/common-problems-and-fixes.md
@@ -11,9 +11,12 @@ Quick fixes for common issues that form authors encounter.
:::warning
-**Symptom:** Delete or Ctrl+S has no effect.
+**Symptom:** Delete or Ctrl+S has no effect on the form.
-**Fix:** Click the canvas background so focus is not inside a text field. See [Keyboard shortcuts](/help/keyboard-shortcuts).
+**Fix:** Click the canvas background so focus is not inside a text field. If the bottom **code editor** is open,
+Ctrl+S /
+⌘+S saves the script, not the form. See
+[Keyboard shortcuts](/help/keyboard-shortcuts).
:::
diff --git a/designer-guide/content/help/faq-for-form-authors.md b/designer-guide/content/help/faq-for-form-authors.md
index d86eaf350..f4ea0b4bd 100644
--- a/designer-guide/content/help/faq-for-form-authors.md
+++ b/designer-guide/content/help/faq-for-form-authors.md
@@ -35,7 +35,9 @@ See [Preview and Edit](/meet-the-designer/preview-and-edit).
Most shortcuts need focus on the page background, not inside a text box. Click the canvas margin first.
**Print** (Ctrl+P /
-⌘+P) still works inside a field.
+⌘+P) still works inside a field. In the bottom
+**code editor**, Ctrl+S /
+⌘+S saves the script instead of the form.
See [Keyboard shortcuts](/help/keyboard-shortcuts).
## Validation does not run on the canvas
diff --git a/designer-guide/content/help/keyboard-shortcuts.md b/designer-guide/content/help/keyboard-shortcuts.md
index 42ee49df0..49f8d5af0 100644
--- a/designer-guide/content/help/keyboard-shortcuts.md
+++ b/designer-guide/content/help/keyboard-shortcuts.md
@@ -1,12 +1,14 @@
---
title: "Keyboard shortcuts"
-description: "Designer keyboard shortcuts for save, print, undo, redo, duplicate, and delete. Windows/Linux and macOS."
+description: "Designer keyboard shortcuts for save, print, undo, redo, duplicate, delete, and saving code in the bottom panel editor."
---
# Keyboard shortcuts
-Shortcuts apply when focus is on the **page background** (not while typing inside a field). Click an empty area of the canvas first.
-**Print** is the exception: it still works with focus inside a field.
+Most shortcuts apply when focus is on the **page background** (not while typing inside a field). Click an empty area of the canvas first.
+**Print** still works with focus inside a field. In the bottom **code editor**,
+Ctrl+S /
+⌘+S saves the script instead of the whole form.
## Windows and Linux
@@ -35,6 +37,24 @@ Shortcuts apply when focus is on the **page background** (not while typing insid
| Undo | ⌘+Z |
| Redo | ⌘+Shift+Z |
+## Code editor
+
+The bottom panel opens a code editor for calculable values, validation **Code**, form actions, and similar scripts. While the cursor is in
+that editor, the same chord as **Save form** saves the **script** (same as clicking **Save** under the editor). It does not save the form
+to storage.
+
+
+
+| Action | Windows / Linux | macOS |
+| ----------- | -------------------------------------------------------------- | ----------------------------------------------------------- |
+| Save script | Ctrl+S | ⌘+S |
+
+Close the code panel or click the canvas when you want
+Ctrl+S /
+⌘+S to save the form again. Host apps that pass
+`hotkeys={false}` also turn off this script-save chord so they can own the key. Remapping only the form Save shortcut
+does not turn off script save in the code editor.
+
## Tips
- Select exactly one component to duplicate with Ctrl+D (Windows/Linux) or
@@ -44,6 +64,8 @@ Shortcuts apply when focus is on the **page background** (not while typing insid
## See also
-- [Select and edit components](/meet-the-designer/select-and-edit-components) - selection basics
+- [Collapse panels and resize the code panel](/meet-the-designer/collapse-panels-and-resize-the-code-panel)
+- [Form-level actions in Settings](/behavior-and-validation/form-level-actions-in-settings)
+- [Select and edit components](/meet-the-designer/select-and-edit-components)
- [Print your form](/preview-and-handoff/print-your-form)
- [Export and share your form](/preview-and-handoff/export-and-share-your-form)
diff --git a/designer-guide/content/manage-forms/save-export-and-import-forms.md b/designer-guide/content/manage-forms/save-export-and-import-forms.md
index 42d7965d4..cb98e5778 100644
--- a/designer-guide/content/manage-forms/save-export-and-import-forms.md
+++ b/designer-guide/content/manage-forms/save-export-and-import-forms.md
@@ -22,7 +22,8 @@ For a short overview, see also [Export and share your form](/preview-and-handoff
| **Save as...** | You need a copy under a new name |
The save shortcut is Ctrl+S on Windows/Linux or
-⌘+S on macOS when focus is on the page background.
+⌘+S on macOS when focus is on the page background. The same chord
+in the bottom **code editor** saves the script, not the form. See [Keyboard shortcuts](/help/keyboard-shortcuts).
diff --git a/designer-guide/content/meet-the-designer/collapse-panels-and-resize-the-code-panel.md b/designer-guide/content/meet-the-designer/collapse-panels-and-resize-the-code-panel.md
index c13c174f5..ddf967226 100644
--- a/designer-guide/content/meet-the-designer/collapse-panels-and-resize-the-code-panel.md
+++ b/designer-guide/content/meet-the-designer/collapse-panels-and-resize-the-code-panel.md
@@ -35,6 +35,11 @@ The bottom panel opens when you edit items that use code or JSON, for example:
5. Drag the **top edge** of the bottom panel up or down to change height.
6. Close or finish editing to hide it when your workflow allows (use the panel **Close** control or finish the property dialog).
+While the cursor is in the editor,
+Ctrl+S /
+⌘+S saves the script (same as **Save** under the editor). See
+[Keyboard shortcuts](/help/keyboard-shortcuts).
+
Height may be remembered during your session.
## Summary
@@ -44,5 +49,6 @@ Expand the side panels again before changing properties.
## See also
+- [Keyboard shortcuts](/help/keyboard-shortcuts)
- [The Designer workspace](/meet-the-designer/the-designer-workspace)
- [Right panel](/meet-the-designer/use-the-right-properties-panel)
diff --git a/documentation/docs/formengine-designer/features/designer-customization.md b/documentation/docs/formengine-designer/features/designer-customization.md
index 41cd734b3..14e451510 100644
--- a/documentation/docs/formengine-designer/features/designer-customization.md
+++ b/documentation/docs/formengine-designer/features/designer-customization.md
@@ -394,7 +394,11 @@ When you embed the designer inside a host application, those shortcuts can confl
Use the [hotkeys](/api-reference/@react-form-builder/designer/interfaces/FormBuilderProps#hotkeys) prop to disable or
remap them, and call the matching methods on [IFormBuilder](/api-reference/@react-form-builder/designer/interfaces/IFormBuilder)
-when the host owns the keyboard.
+when the host owns the keyboard. Passing `hotkeys={false}` also skips the Monaco code-editor Ctrl/Cmd+S script-save
+chord (saves the open script, not the form) so the host can handle that key while focus is in the editor. Remapping or
+disabling form `save` via `hotkeys.bindings` does **not** free Ctrl/Cmd+S in the code editor — use `hotkeys={false}`
+when the host must own that chord in Monaco too. Monaco’s built-in editing shortcuts (and constrained Ctrl/Cmd+A
+select-body) stay enabled.
### Disable all built-in hotkeys
diff --git a/packages/designer/src/FormBuilderProps.tsx b/packages/designer/src/FormBuilderProps.tsx
index 7786010cf..c9ddca11d 100644
--- a/packages/designer/src/FormBuilderProps.tsx
+++ b/packages/designer/src/FormBuilderProps.tsx
@@ -91,8 +91,11 @@ export interface FormBuilderProps extends Omit
const compile = useCallback(
(source: string): CalculableResult => {
- AsyncFunction(source)
- return CalculableResult.success(t('testingEditor.compilationOk'))
+ try {
+ AsyncFunction(source)
+ return CalculableResult.success(t('testingEditor.compilationOk'))
+ } catch (e) {
+ return CalculableResult.error([e as Error])
+ }
},
[t]
)
diff --git a/packages/designer/src/features/calculation/GenericCodeEditor.tsx b/packages/designer/src/features/calculation/GenericCodeEditor.tsx
index 8e065764a..d36a09eba 100644
--- a/packages/designer/src/features/calculation/GenericCodeEditor.tsx
+++ b/packages/designer/src/features/calculation/GenericCodeEditor.tsx
@@ -3,7 +3,7 @@ import type {BaseCompilationResult, IFormData} from '@react-form-builder/core'
import {useStore} from '@react-form-builder/core'
import {action} from 'mobx'
import type {ReactNode} from 'react'
-import {useCallback, useMemo, useRef, useState} from 'react'
+import {useCallback, useEffect, useMemo, useRef, useState} from 'react'
import {useTranslation} from 'react-i18next'
import {Button, ButtonGroup} from 'rsuite'
import {CodeEditor} from '../components/CodeEditor/CodeEditor'
@@ -106,12 +106,16 @@ export const GenericCodeEditor = (props: GenericCodeEditorProps) => {
const [sourceCode, setSourceCode] = useState(propsSourceCode)
const [initialValue, setInitialValue] = useState(propsSourceCode)
const [previousPropsSourceCode, setPreviousPropsSourceCode] = useState(propsSourceCode)
+ const testingEditorRef = useRef({})
+ const compileSourceRef = useRef(sourceCode)
if (previousPropsSourceCode !== propsSourceCode) {
setPreviousPropsSourceCode(propsSourceCode)
setInitialValue(propsSourceCode)
setSourceCode(propsSourceCode)
}
- const testingEditorRef = useRef({})
+ useEffect(() => {
+ compileSourceRef.current = sourceCode
+ }, [sourceCode])
const {formData} = useStore()
const showTestingEditor = !props.compact
const testFormData = props.initialTestData ?? formData.data
@@ -123,19 +127,26 @@ export const GenericCodeEditor = (props: GenericCodeEditorProps) => {
[getSourceForSave]
)
- const handleSave = useCallback(() => {
- const valueToSave = resolveSourceForSave(sourceCode)
- const testResult = validateBeforeSave?.(valueToSave) === 'skip-test' ? undefined : testingEditorRef.current.test?.()
- if (resolveGenericCodeEditorSave(valueToSave, {validateBeforeSave, testResult}) === 'abort') return
+ const handleSaveValue = useCallback(
+ (value: string) => {
+ const valueToSave = resolveSourceForSave(value)
+ // Sync before test(): effect may not have flushed yet vs Monaco's value.
+ compileSourceRef.current = valueToSave
+ const testResult = validateBeforeSave?.(valueToSave) === 'skip-test' ? undefined : testingEditorRef.current.test?.()
+ if (resolveGenericCodeEditorSave(valueToSave, {validateBeforeSave, testResult}) === 'abort') return
+
+ action(() => onSave(valueToSave))()
+ setInitialValue(valueToSave)
+ setSourceCode(valueToSave)
+ },
+ [onSave, resolveSourceForSave, validateBeforeSave]
+ )
- action(() => onSave(valueToSave))()
- setInitialValue(valueToSave)
- setSourceCode(valueToSave)
- }, [onSave, resolveSourceForSave, sourceCode, validateBeforeSave])
+ const handleSave = useCallback(() => handleSaveValue(sourceCode), [handleSaveValue, sourceCode])
const testingFunction = useCallback(
- (formData: IFormData) => onCompile(resolveSourceForSave(sourceCode), formData),
- [onCompile, resolveSourceForSave, sourceCode]
+ (formData: IFormData) => onCompile(resolveSourceForSave(compileSourceRef.current), formData),
+ [onCompile, resolveSourceForSave]
)
const handleClose = useCallback(() => props.onClose(), [props])
@@ -153,6 +164,7 @@ export const GenericCodeEditor = (props: GenericCodeEditorProps) => {
autoformat={props.autoformat}
onMount={props.onEditorMount}
onChange={setSourceCode}
+ onSave={handleSaveValue}
/>
diff --git a/packages/designer/src/features/components/CodeEditor/CodeEditorProps.ts b/packages/designer/src/features/components/CodeEditor/CodeEditorProps.ts
index 4c98fde8c..d22d09e12 100644
--- a/packages/designer/src/features/components/CodeEditor/CodeEditorProps.ts
+++ b/packages/designer/src/features/components/CodeEditor/CodeEditorProps.ts
@@ -19,6 +19,11 @@ export interface UnconstrainedCodeEditorProps {
* @param value the source code.
*/
onChange: (value: string) => void
+ /**
+ * The callback function that is called when save is requested (Ctrl/Cmd+S).
+ * @param value the source code to save.
+ */
+ onSave?: (value: string) => void
/**
* The code editor language.
* @default 'javascript'
diff --git a/packages/designer/src/features/components/CodeEditor/ConstrainedCodeEditor.tsx b/packages/designer/src/features/components/CodeEditor/ConstrainedCodeEditor.tsx
index 08123ee89..ead7bf7b1 100644
--- a/packages/designer/src/features/components/CodeEditor/ConstrainedCodeEditor.tsx
+++ b/packages/designer/src/features/components/CodeEditor/ConstrainedCodeEditor.tsx
@@ -6,6 +6,7 @@ import {buildConstrainedDocument, extractEditableBody, resolveNextConstrainedDoc
import {MonacoCodeEditor} from './MonacoCodeEditor'
import type {ConstrainedMonacoEditorModel} from './setupConstrainedMonaco'
import {setupConstrainedMonaco, withSuppressedConstrainedValidation} from './setupConstrainedMonaco'
+import {useCodeEditorSaveHotkey} from './useCodeEditorSaveHotkey'
type ConstrainedContext = {
beginContextLine?: string
@@ -43,7 +44,7 @@ const applyConstrainedEditorValue = (
* @returns the React element.
*/
export const ConstrainedCodeEditor = (props: CodeEditorProps) => {
- const {initialValue, onChange, onMount} = props
+ const {initialValue, onChange, onMount, onSave} = props
const context = useMemo(
() => ({
beginContextLine: props.beginContextLine,
@@ -52,6 +53,16 @@ export const ConstrainedCodeEditor = (props: CodeEditorProps) => {
}),
[props.beginContextLine, props.canEditBeginContextLine, props.endContextLine]
)
+ const contextRef = useRef(context)
+
+ useEffect(() => {
+ contextRef.current = context
+ }, [context])
+
+ const bindSaveHotkey = useCodeEditorSaveHotkey(onSave, e => {
+ const {beginContextLine, canEditBeginContextLine, endContextLine} = contextRef.current
+ return extractEditableBody(e.getValue(), beginContextLine, canEditBeginContextLine, endContextLine)
+ })
const documentValue = useMemo(
() => buildConstrainedDocument(initialValue, context.beginContextLine, context.canEditBeginContextLine, context.endContextLine),
@@ -93,9 +104,10 @@ export const ConstrainedCodeEditor = (props: CodeEditorProps) => {
onMount?.(editor, monaco)
editorRef.current = editor
constrainedModelRef.current = setupConstrainedMonaco(editor, monaco, context, onChange)
+ bindSaveHotkey(editor)
appliedSourceRef.current = {initialValue, context}
},
- [context, initialValue, onChange, onMount]
+ [bindSaveHotkey, context, initialValue, onChange, onMount]
)
const options = useMemo(
diff --git a/packages/designer/src/features/components/CodeEditor/UnconstrainedCodeEditor.tsx b/packages/designer/src/features/components/CodeEditor/UnconstrainedCodeEditor.tsx
index 5b2164549..11130709c 100644
--- a/packages/designer/src/features/components/CodeEditor/UnconstrainedCodeEditor.tsx
+++ b/packages/designer/src/features/components/CodeEditor/UnconstrainedCodeEditor.tsx
@@ -3,6 +3,7 @@ import type {editor} from 'monaco-editor'
import {useCallback, useEffect, useMemo, useRef} from 'react'
import type {UnconstrainedCodeEditorProps} from './CodeEditorProps'
import {MonacoCodeEditor} from './MonacoCodeEditor'
+import {useCodeEditorSaveHotkey} from './useCodeEditorSaveHotkey'
import {useMonacoAutoformat} from './useMonacoAutoformat'
/**
@@ -12,7 +13,8 @@ import {useMonacoAutoformat} from './useMonacoAutoformat'
*/
export const UnconstrainedCodeEditor = (props: UnconstrainedCodeEditorProps) => {
const editorRef = useRef(null)
- const {onChange, onMount} = props
+ const {onChange, onMount, onSave} = props
+ const bindSaveHotkey = useCodeEditorSaveHotkey(onSave)
useEffect(() => {
const editor = editorRef.current
@@ -26,10 +28,11 @@ export const UnconstrainedCodeEditor = (props: UnconstrainedCodeEditorProps) =>
(editor, monaco) => {
editor.onDidChangeModelContent(() => onChange(editor.getValue()))
editorRef.current = editor
+ bindSaveHotkey(editor)
onMount?.(editor, monaco)
},
- [onChange, onMount]
+ [bindSaveHotkey, onChange, onMount]
)
const options = useMemo(
diff --git a/packages/designer/src/features/components/CodeEditor/registerCodeEditorSaveAction.ts b/packages/designer/src/features/components/CodeEditor/registerCodeEditorSaveAction.ts
new file mode 100644
index 000000000..cc793976b
--- /dev/null
+++ b/packages/designer/src/features/components/CodeEditor/registerCodeEditorSaveAction.ts
@@ -0,0 +1,33 @@
+import type {editor, IDisposable} from 'monaco-editor'
+
+/**
+ * Monaco `KeyMod.CtrlCmd | KeyCode.KeyS` numeric value.
+ * Read from stable enum values instead of the onMount `monaco` object — vitest harnesses often pass `{}`.
+ */
+const CTRL_CMD_S = (1 << 11) | 49
+
+/**
+ * Registers Ctrl/Cmd+S on a Monaco editor instance to invoke {@link onSave}.
+ * Uses {@link editor.IStandaloneCodeEditor.addAction} so the chord is scoped to this editor
+ * (same approach as constrained Ctrl/Cmd+A). Callers skip registration when FormBuilder
+ * `hotkeys={false}` so the host owns the chord.
+ * @param editorInstance the Monaco standalone editor.
+ * @param onSave the callback that receives the value to save.
+ * @param getSaveValue resolves the string passed to {@link onSave}; defaults to the full editor value.
+ * @returns the action disposable.
+ */
+export function registerCodeEditorSaveAction(
+ editorInstance: editor.IStandaloneCodeEditor,
+ onSave: (value: string) => void,
+ getSaveValue: (ed: editor.ICodeEditor) => string = ed => ed.getValue()
+): IDisposable {
+ return editorInstance.addAction({
+ id: 'code-editor.save',
+ label: 'Save',
+ keybindings: [CTRL_CMD_S],
+ precondition: 'editorTextFocus',
+ run: ed => {
+ onSave(getSaveValue(ed))
+ },
+ })
+}
diff --git a/packages/designer/src/features/components/CodeEditor/useCodeEditorSaveHotkey.ts b/packages/designer/src/features/components/CodeEditor/useCodeEditorSaveHotkey.ts
new file mode 100644
index 000000000..1a843af2c
--- /dev/null
+++ b/packages/designer/src/features/components/CodeEditor/useCodeEditorSaveHotkey.ts
@@ -0,0 +1,47 @@
+import type {editor} from 'monaco-editor'
+import {useCallback, useEffect, useRef, useState} from 'react'
+import {useHotkeysProp} from '../../hotkeys/HotkeysPropContext'
+import {registerCodeEditorSaveAction} from './registerCodeEditorSaveAction'
+
+/**
+ * Binds Monaco Ctrl/Cmd+S script save when FormBuilder hotkeys are enabled and {@link onSave} is set.
+ * Does not register the chord when `hotkeys={false}` or `onSave` is omitted, so the host can own Ctrl/Cmd+S.
+ * @param onSave the callback that receives the value to save.
+ * @param getSaveValue resolves the string passed to {@link onSave}; defaults to the full editor value.
+ * @returns a mount binder that stores the editor instance for registration.
+ */
+export function useCodeEditorSaveHotkey(onSave: ((value: string) => void) | undefined, getSaveValue?: (ed: editor.ICodeEditor) => string) {
+ const hotkeys = useHotkeysProp()
+ const onSaveRef = useRef(onSave)
+ const getSaveValueRef = useRef(getSaveValue)
+ const editorRef = useRef(null)
+ const [mountGeneration, setMountGeneration] = useState(0)
+
+ useEffect(() => {
+ onSaveRef.current = onSave
+ }, [onSave])
+
+ useEffect(() => {
+ getSaveValueRef.current = getSaveValue
+ }, [getSaveValue])
+
+ const bindEditor = useCallback((editorInstance: editor.IStandaloneCodeEditor) => {
+ editorRef.current = editorInstance
+ setMountGeneration(generation => generation + 1)
+ }, [])
+
+ useEffect(() => {
+ if (hotkeys === false || !onSave) return
+ const editorInstance = editorRef.current
+ if (!editorInstance) return
+
+ const disposable = registerCodeEditorSaveAction(
+ editorInstance,
+ value => onSaveRef.current?.(value),
+ ed => (getSaveValueRef.current ?? (e => e.getValue()))(ed)
+ )
+ return () => disposable.dispose()
+ }, [hotkeys, mountGeneration, onSave])
+
+ return bindEditor
+}
diff --git a/packages/designer/src/features/hotkeys/types.ts b/packages/designer/src/features/hotkeys/types.ts
index a1eec640a..f4a5d90ca 100644
--- a/packages/designer/src/features/hotkeys/types.ts
+++ b/packages/designer/src/features/hotkeys/types.ts
@@ -43,5 +43,8 @@ export type DesignerHotkeysOptions = {
/**
* Controls the FormBuilder global keyboard shortcuts.
* Pass `false` to disable all built-in global hotkeys so the host can register its own.
+ * Only `false` also skips the Monaco code-editor Ctrl/Cmd+S script-save chord (script only,
+ * not form persistence). Remapping or disabling form `save` in {@link DesignerHotkeysOptions.bindings}
+ * does not turn that editor chord off.
*/
export type DesignerHotkeysProp = false | DesignerHotkeysOptions
diff --git a/packages/designer/src/features/ui/JsonView.tsx b/packages/designer/src/features/ui/JsonView.tsx
index 294ba2b03..6a2d5dcdc 100644
--- a/packages/designer/src/features/ui/JsonView.tsx
+++ b/packages/designer/src/features/ui/JsonView.tsx
@@ -37,11 +37,21 @@ const RawJsonView = () => {
[initialValue, schema]
)
+ const handleSave = useCallback(
+ (value: string) => {
+ sourceRef.current = value
+ builderStore.viewer.applyStringForm(value)
+ },
+ [builderStore]
+ )
+
useEffect(() => {
return () => builderStore.parseForm(sourceRef.current)
}, [builderStore])
- return
+ return (
+
+ )
}
export const JsonView = namedObserver('JsonView', RawJsonView)
diff --git a/scripts/simulate-ci-rc-release.sh b/scripts/simulate-ci-rc-release.sh
index d0009ffba..ff1fc7d24 100755
--- a/scripts/simulate-ci-rc-release.sh
+++ b/scripts/simulate-ci-rc-release.sh
@@ -1,66 +1,101 @@
#!/usr/bin/env bash
#
-# Simulate the GitHub Actions **fb producer** CI build and RC draft-release upload.
+# simulate-ci-rc-release.sh — local Earthly stand-in for `.github/workflows/ci.yml`
#
-# Does NOT run formengine-tools deploy (npm publish, compose-mirrors, GitHub mirrors).
+# =============================================================================
+# USAGE GUIDE
+# =============================================================================
#
-# Mirrors GHA RC release flow (orchestrated by `.github/workflows/ci.yml`):
-# ci-bundle.yml → earthly +prepare-rc-archives-from-pack (RC) or +npm-bundle (PR)
-# ci-build-documentation.yml → earthly +prepare-documentation-sites-archives
-# ci-publish-rc-release.yml → earthly +validate-rc-archives, +npm-publish-rc-release (optional)
+# Purpose
+# Run the same Earthly targets GitHub Actions runs for FormEngine CI, without
+# pushing a PR. Does NOT run formengine-tools deploy (npm publish to the
+# registry, compose-mirrors, or GitHub mirrors).
#
-# Optional CI jobs (disabled by default; pass flags to enable):
-# --checks → earthly +npm-check-all
-# --tests → earthly +npm-test
-# --e2e → earthly +npm-e2e
-# --apps-and-views → earthly +npm-build-apps-and-views
+# Quick start
+# cd
+# cp .env.example .env # once; fill FORMENGINE_* license secrets
+# ./scripts/simulate-ci-rc-release.sh --help
+# npm run simulate:ci-rc-release -- --pr --all --no-publish
#
-# Usage:
-# ./scripts/simulate-ci-rc-release.sh
-# ./scripts/simulate-ci-rc-release.sh --publish
-# ./scripts/simulate-ci-rc-release.sh --no-publish
-# ./scripts/simulate-ci-rc-release.sh --all --publish
-# ./scripts/simulate-ci-rc-release.sh --pr
-# ./scripts/simulate-ci-rc-release.sh --dry-run
+# .env autoload
+# On start, the script loads `/.env` if it exists (`set -a; source`).
+# If `.env` is missing, it prints a warning with setup steps and continues
+# using whatever is already in the process environment. Preflight still fails
+# later if `--tests` / `--e2e` / `--all` need license secrets that are unset.
#
-# -----------------------------------------------------------------------------
-# Environment variables
-# -----------------------------------------------------------------------------
+# Mirror a normal pull-request gate (recommended before opening a PR)
+# ./scripts/simulate-ci-rc-release.sh --pr --all --no-publish
+# Jobs: checks, tests, e2e, apps-and-views, pack-only bundle, docs.
+#
+# Fast feedback (static checks + module/component + e2e/browser only)
+# ./scripts/simulate-ci-rc-release.sh --checks --tests --e2e \
+# --skip-bundle --skip-docs --skip-validate --no-publish
#
-# Publish step (required on `rc/*` branches by default, or with `--publish`):
-# GH_TOKEN
-# GitHub API token with `contents: write`. `GITHUB_TOKEN` is accepted as an alias.
-# Export explicitly, for example: `export GH_TOKEN="$(gh auth token)"`
+# RC release producer path (default when not using --pr)
+# ./scripts/simulate-ci-rc-release.sh # pack+RC archives + docs + validate
+# ./scripts/simulate-ci-rc-release.sh --all --publish # + checks/tests/e2e/apps + draft upload
+# ./scripts/simulate-ci-rc-release.sh --no-publish # never upload, even on rc/*
+# ./scripts/simulate-ci-rc-release.sh --dry-run # print plan / check tooling only
#
-# GITHUB_REPOSITORY / GITHUB_SHA
-# Used by the upload script inside the container. Pass to Earthly as REPO_SLUG and
-# GITHUB_SHA build args (Earthly reserves the GITHUB_REPOSITORY arg name).
+# Flags
+# --checks earthly +npm-check-all (Static checks)
+# --tests earthly +npm-test (Module and component tests)
+# --e2e earthly +npm-e2e (E2E and browser tests)
+# --apps-and-views earthly +npm-build-apps-and-views (Build apps and views)
+# --all enable --checks --tests --e2e --apps-and-views
+# --pr PREPARE_RC_ARCHIVES=0 → pack-only bundle (non-RC PR path)
+# --rc PREPARE_RC_ARCHIVES=1 → RC archives (default)
+# --publish upload draft GitHub release (needs GH_TOKEN)
+# --no-publish never upload (overrides auto-publish on rc/*)
+# --skip-bundle skip bundle / archive prepare
+# --skip-docs skip documentation site archives
+# --skip-validate skip local archive validation
+# --dry-run resolve flags + preflight; do not run Earthly
+# -h, --help print this guide
#
-# Optional:
-# ARCHIVES_DIR
-# Directory containing release archive files. Default: `.archives`
+# GHA job → Earthly target map (orchestrated by ci.yml)
+# Static checks → +npm-check-all
+# Module and component tests → +npm-test
+# E2E and browser tests → +npm-e2e
+# Build apps and view packages → +npm-build-apps-and-views
+# ci-bundle.yml → +prepare-rc-archives-from-pack (RC) or +npm-bundle (PR)
+# ci-build-documentation.yml → +prepare-documentation-sites-archives
+# ci-publish-rc-release.yml → validate + +npm-publish-rc-release (optional)
+#
+# Environment variables
+# Loaded from `.env` when present. Also accepted from the shell.
#
-# PREPARE_RC_ARCHIVES
-# When `1` (default), runs `earthly --output +prepare-rc-archives-from-pack`
-# (pack + RC archives exported to `.archives/`). When `0` (or `--pr`), runs
-# `earthly +npm-bundle` with pack only - same as a non-RC PR.
+# Tests / e2e (required with --tests, --e2e, or --all):
+# FORMENGINE_TEST_LICENSE_KEY
+# FORMENGINE_TEST_LICENSE_KEYS_JSON
+# FORMENGINE_FORMS_WITH_VERSIONS_LICENSE_KEY (optional)
+# Passed to Earthly as `--secret NAME` (same as GHA).
#
-# EARTHLY_BIN
-# Earthly executable name/path. Default: `earthly`
+# Publish (required on rc/* by default, or with --publish):
+# GH_TOKEN contents:write token; GITHUB_TOKEN accepted as alias
+# example: export GH_TOKEN="$(gh auth token)"
+# GITHUB_REPOSITORY / GITHUB_SHA
+# inferred from git/gh when unset; passed as REPO_SLUG /
+# GITHUB_SHA build args (Earthly reserves GITHUB_REPOSITORY)
#
-# EARTHLY_EXTRA_ARGS
-# Extra arguments appended to every earthly invocation (e.g. `--disable-remote-cache`).
+# Optional overrides:
+# ARCHIVES_DIR default `.archives`
+# PREPARE_RC_ARCHIVES `1` RC archives (default), `0` pack-only / --pr
+# EARTHLY_BIN default `earthly`
+# EARTHLY_EXTRA_ARGS appended to every earthly call
#
-# Set inside Earthly targets (normally no need to set locally):
-# NODE_OPTIONS=--max-old-space-size=8192 (npm-bundle, archive prepare)
-# CI=true (npm-test, npm-e2e)
-# PLAYWRIGHT_DOCKER=1 (npm-e2e)
-# PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1 (npm-e2e)
+# Set inside Earthly targets (normally no need to set locally):
+# NODE_OPTIONS=--max-old-space-size=8192
+# CI=true
+# PLAYWRIGHT_DOCKER=1
+# PLAYWRIGHT_SKIP_VALIDATE_HOST_REQUIREMENTS=1
#
-# Prerequisites:
-# earthly, git
-# node - required when archive validation runs (default RC flow)
-# gh - optional; used to infer GITHUB_REPOSITORY
+# Prerequisites
+# earthly, git, Docker (Earthly backend)
+# node — when archive validation runs (default RC flow)
+# gh — optional; used to infer GITHUB_REPOSITORY
+#
+# =============================================================================
#
set -euo pipefail
@@ -72,6 +107,53 @@ fi
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
+log() {
+ printf '==> %s\n' "$*"
+}
+
+warn() {
+ printf 'warning: %s\n' "$*" >&2
+}
+
+die() {
+ printf 'error: %s\n' "$*" >&2
+ exit 1
+}
+
+usage() {
+ sed -n '2,/^set -euo pipefail$/p' "$0" | sed '1d;$d' | sed 's/^# \{0,1\}//'
+}
+
+# Load `/.env` when present. Warn with setup details when missing.
+load_repo_dotenv() {
+ local env_file="${REPO_ROOT}/.env"
+ local example_file="${REPO_ROOT}/.env.example"
+
+ if [[ -f "${env_file}" ]]; then
+ log "Loading environment from ${env_file}"
+ set -a
+ # shellcheck disable=SC1090
+ source "${env_file}"
+ set +a
+ return 0
+ fi
+
+ warn "No ${env_file} found; continuing with the current process environment."
+ warn "Create one so --tests / --e2e / --all can pick up GHA license secrets automatically:"
+ warn " cp .env.example .env"
+ warn "Then set at least:"
+ warn " FORMENGINE_TEST_LICENSE_KEY"
+ warn " FORMENGINE_TEST_LICENSE_KEYS_JSON"
+ warn "Optional:"
+ warn " FORMENGINE_FORMS_WITH_VERSIONS_LICENSE_KEY"
+ if [[ -f "${example_file}" ]]; then
+ warn "Template: ${example_file}"
+ else
+ warn "Expected template missing: ${example_file}"
+ fi
+ warn "Already-exported shell variables are still used if set."
+}
+
ARCHIVES_DIR="${ARCHIVES_DIR:-.archives}"
export ARCHIVES_DIR
PREPARE_RC_ARCHIVES="${PREPARE_RC_ARCHIVES:-1}"
@@ -87,21 +169,9 @@ RUN_APPS_AND_VIEWS=false
RUN_VALIDATE=true
RUN_PUBLISH=false
PUBLISH_EXPLICIT=false
+PREPARE_RC_ARCHIVES_EXPLICIT=false
DRY_RUN=false
-log() {
- printf '==> %s\n' "$*"
-}
-
-die() {
- printf 'error: %s\n' "$*" >&2
- exit 1
-}
-
-usage() {
- sed -n '2,/^set -euo pipefail$/p' "$0" | sed '1d;$d' | sed 's/^# \{0,1\}//'
-}
-
require_command() {
command -v "$1" >/dev/null 2>&1 || die "Missing required command: $1"
}
@@ -122,6 +192,9 @@ report_missing_requirements() {
if [[ " ${missing_env[*]} " == *" GH_TOKEN "* ]]; then
printf ' hint: export GH_TOKEN="$(gh auth token)" or set GITHUB_TOKEN\n' >&2
fi
+ if [[ " ${missing_env[*]} " == *" FORMENGINE_TEST_LICENSE_KEY "* || " ${missing_env[*]} " == *" FORMENGINE_TEST_LICENSE_KEYS_JSON "* ]]; then
+ printf ' hint: cp .env.example .env, fill FORMENGINE_* secrets, then re-run (script autoloads .env)\n' >&2
+ fi
fi
exit 1
fi
@@ -178,6 +251,15 @@ run_earthly() {
"${EARTHLY_BIN}" --ci ${EARTHLY_EXTRA_ARGS} "$@"
}
+# Match ci-tests.yml / ci-e2e.yml: pass license secrets from the environment.
+run_earthly_with_test_secrets() {
+ run_earthly \
+ --secret FORMENGINE_TEST_LICENSE_KEY \
+ --secret FORMENGINE_TEST_LICENSE_KEYS_JSON \
+ --secret FORMENGINE_FORMS_WITH_VERSIONS_LICENSE_KEY \
+ "$@"
+}
+
infer_github_repository() {
if [[ -n "${GITHUB_REPOSITORY:-}" ]]; then
printf '%s' "${GITHUB_REPOSITORY}"
@@ -232,6 +314,15 @@ check_requirements() {
fi
fi
+ if [[ "${RUN_TESTS}" == true || "${RUN_E2E}" == true ]]; then
+ if [[ -z "${FORMENGINE_TEST_LICENSE_KEY:-}" ]]; then
+ MISSING_ENV+=('FORMENGINE_TEST_LICENSE_KEY')
+ fi
+ if [[ -z "${FORMENGINE_TEST_LICENSE_KEYS_JSON:-}" ]]; then
+ MISSING_ENV+=('FORMENGINE_TEST_LICENSE_KEYS_JSON')
+ fi
+ fi
+
if [[ "${RUN_PUBLISH}" == true ]]; then
if [[ "${PREPARE_RC_ARCHIVES}" != 1 ]]; then
die "Cannot publish without RC archives; rerun without --pr or set PREPARE_RC_ARCHIVES=1"
@@ -352,10 +443,12 @@ while [[ $# -gt 0 ]]; do
;;
--pr)
PREPARE_RC_ARCHIVES=0
+ PREPARE_RC_ARCHIVES_EXPLICIT=true
shift
;;
--rc)
PREPARE_RC_ARCHIVES=1
+ PREPARE_RC_ARCHIVES_EXPLICIT=true
shift
;;
-h|--help)
@@ -370,6 +463,22 @@ done
cd "${REPO_ROOT}"
+# Flags are parsed first so `--help` stays quiet. Remember CLI `--pr` / `--rc`
+# before sourcing `.env`, which must not override an explicit mode flag.
+prepare_rc_archives_from_cli="${PREPARE_RC_ARCHIVES}"
+
+load_repo_dotenv
+
+ARCHIVES_DIR="${ARCHIVES_DIR:-.archives}"
+export ARCHIVES_DIR
+EARTHLY_BIN="${EARTHLY_BIN:-earthly}"
+EARTHLY_EXTRA_ARGS="${EARTHLY_EXTRA_ARGS:-}"
+if [[ "${PREPARE_RC_ARCHIVES_EXPLICIT}" == true ]]; then
+ PREPARE_RC_ARCHIVES="${prepare_rc_archives_from_cli}"
+else
+ PREPARE_RC_ARCHIVES="${PREPARE_RC_ARCHIVES:-1}"
+fi
+
if [[ "${PUBLISH_EXPLICIT}" == false ]]; then
current_branch="$(git branch --show-current 2>/dev/null || true)"
if [[ "${current_branch}" == rc/* ]]; then
@@ -391,12 +500,12 @@ fi
if [[ "${RUN_TESTS}" == true ]]; then
log "CI tests (earthly +npm-test)"
- run_earthly +npm-test
+ run_earthly_with_test_secrets +npm-test
fi
if [[ "${RUN_E2E}" == true ]]; then
log "CI e2e (earthly +npm-e2e)"
- run_earthly +npm-e2e
+ run_earthly_with_test_secrets --output +npm-e2e
fi
if [[ "${RUN_BUNDLE}" == true ]]; then
diff --git a/tests/component/tests/code-editor-save-hotkey.browser.spec.tsx b/tests/component/tests/code-editor-save-hotkey.browser.spec.tsx
new file mode 100644
index 000000000..f3ed52ed2
--- /dev/null
+++ b/tests/component/tests/code-editor-save-hotkey.browser.spec.tsx
@@ -0,0 +1,123 @@
+import {render, waitFor} from '@testing-library/react'
+import type {editor} from 'monaco-editor'
+import type {ReactNode} from 'react'
+import {describe, expect, it, vi} from 'vitest'
+import {userEvent} from 'vitest/browser'
+import {UnconstrainedCodeEditor} from '../../../packages/designer/src/features/components/CodeEditor/UnconstrainedCodeEditor'
+import {HotkeysPropProvider} from '../../../packages/designer/src/features/hotkeys/HotkeysPropContext'
+import type {DesignerHotkeysProp} from '../../../packages/designer/src/features/hotkeys/types'
+import {isBrowserMode} from '../config/isBrowserMode'
+
+type SaveHotkeyHarnessProps = {
+ initialValue: string
+ onSave?: (value: string) => void
+ hotkeys?: DesignerHotkeysProp
+ onEditor?: (ed: editor.IStandaloneCodeEditor) => void
+}
+
+const SaveHotkeyHarness = ({initialValue, onSave, hotkeys, onEditor}: SaveHotkeyHarnessProps) => {
+ const wrap = (children: ReactNode) =>
+ hotkeys === undefined ? children : {children}
+
+ return wrap(
+