Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
- [ComputeTypeParams](type-aliases/ComputeTypeParams.md)
- [CustomizableKey](type-aliases/CustomizableKey.md)
- [CustomizationMap](type-aliases/CustomizationMap.md)
- [DesignerHotkey](type-aliases/DesignerHotkey.md)
- [DesignerHotkeyAction](type-aliases/DesignerHotkeyAction.md)
- [DesignerHotkeysOptions](type-aliases/DesignerHotkeysOptions.md)
- [DesignerHotkeysProp](type-aliases/DesignerHotkeysProp.md)
- [FormBuilderI18n](type-aliases/FormBuilderI18n.md)
- [FormBuilderI18nData](type-aliases/FormBuilderI18nData.md)
- [FormBuilderTheme](type-aliases/FormBuilderTheme.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ the string or Promise with the form.

***

### hotkeys?

> `optional` **hotkeys?**: [`DesignerHotkeysProp`](../type-aliases/DesignerHotkeysProp.md)

Controls the FormBuilder global keyboard shortcuts.
Pass `false` to disable all built-in global hotkeys so the host can register its own
and invoke actions through [IFormBuilder](IFormBuilder.md). Pass an options object to remap or
disable individual actions.

***

### i18n?

> `optional` **i18n?**: [`FormBuilderI18n`](../type-aliases/FormBuilderI18n.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
# Interface: IFormBuilder

The form builder settings interface.
Imperative action methods are optional for backward-compatible mocks and custom
implementations; the designer `builderRef` / `useFormBuilder()` instance always provides them.

## Properties

### cloneSelected?

> `optional` **cloneSelected?**: () => `void`

Clones the selected component when exactly one component is selected.

#### Returns

`void`

***

### deleteSelected?

> `optional` **deleteSelected?**: () => `void`

Deletes the currently selected components from the form.

#### Returns

`void`

***

### parseForm

> **parseForm**: (`text`) => `void`
Expand All @@ -24,6 +50,30 @@ the form serialized in JSON.

***

### print?

> `optional` **print?**: () => `void`

Prints the form (switches to viewer mode for printing when needed).

#### Returns

`void`

***

### redo?

> `optional` **redo?**: () => `void`

Redoes the last undone form edit.

#### Returns

`void`

***

### reloadFormList

> **reloadFormList**: () => `void`
Expand All @@ -34,6 +84,41 @@ Updates the form list on the Forms tab.

`void`

***

### save?

> `optional` **save?**: (`formName?`) => `Promise`\<`void`\>

Saves the current form to form storage without showing the designer toast.
Built-in Ctrl/Cmd+S and the Save menu still show success/error toasts via the UI layer.

#### Parameters

##### formName?

`string`

the optional form name. When omitted, the active form name is used.

#### Returns

`Promise`\<`void`\>

the promise that resolves when the form is saved.

***

### undo?

> `optional` **undo?**: () => `void`

Undoes the last form edit.

#### Returns

`void`

## Accessors

### builderMode
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Type Alias: DesignerHotkey

> **DesignerHotkey** = `object`

A single keyboard chord for a designer hotkey.

## Properties

### alt?

> `optional` **alt?**: `boolean`

Whether the Alt key must be pressed.

***

### ctrl?

> `optional` **ctrl?**: `boolean`

Whether the Control key must be pressed.

***

### key

> **key**: `string`

The keyboard event `key` value, e.g. `'s'` or `'Delete'`.

***

### meta?

> `optional` **meta?**: `boolean`

Whether the Meta (Command) key must be pressed.

***

### shift?

> `optional` **shift?**: `boolean`

Whether the Shift key must be pressed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Type Alias: DesignerHotkeyAction

> **DesignerHotkeyAction** = `"cloneSelected"` \| `"deleteSelected"` \| `"print"` \| `"redo"` \| `"save"` \| `"undo"`

Designer actions that can be bound to keyboard shortcuts or invoked via the form builder ref.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Type Alias: DesignerHotkeysOptions

> **DesignerHotkeysOptions** = `object`

Options for remapping or disabling individual designer hotkeys.

## Properties

### bindings?

> `optional` **bindings?**: `Partial`\<`Record`\<[`DesignerHotkeyAction`](DesignerHotkeyAction.md), [`DesignerHotkey`](DesignerHotkey.md)[] \| [`DesignerHotkey`](DesignerHotkey.md) \| `false`\>\>

Per-action binding overrides. A value of `false` disables that action’s shortcuts.
An unspecified action keeps the built-in default chords.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Type Alias: DesignerHotkeysProp

> **DesignerHotkeysProp** = [`DesignerHotkeysOptions`](DesignerHotkeysOptions.md) \| `false`

Controls the FormBuilder global keyboard shortcuts.
Pass `false` to disable all built-in global hotkeys so the host can register its own.
20 changes: 20 additions & 0 deletions documentation/docs/api-reference/typedoc-sidebar.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3277,6 +3277,26 @@ const typedocSidebar = {
id: "api-reference/@react-form-builder/designer/type-aliases/CustomizationMap",
label: "CustomizationMap"
},
{
type: "doc",
id: "api-reference/@react-form-builder/designer/type-aliases/DesignerHotkey",
label: "DesignerHotkey"
},
{
type: "doc",
id: "api-reference/@react-form-builder/designer/type-aliases/DesignerHotkeyAction",
label: "DesignerHotkeyAction"
},
{
type: "doc",
id: "api-reference/@react-form-builder/designer/type-aliases/DesignerHotkeysOptions",
label: "DesignerHotkeysOptions"
},
{
type: "doc",
id: "api-reference/@react-form-builder/designer/type-aliases/DesignerHotkeysProp",
label: "DesignerHotkeysProp"
},
{
type: "doc",
id: "api-reference/@react-form-builder/designer/type-aliases/FormBuilderI18n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ its [customizable key](/api-reference/@react-form-builder/designer/type-aliases/

You can manage the FormBuilder and get its state in custom components
using [useFormBuilder](/api-reference/@react-form-builder/designer/variables/useFormBuilder). It provides access
to [IFormBuilder](/api-reference/@react-form-builder/designer/interfaces/IFormBuilder). The management options are limited at the moment,
but they will be expanded in the future.
to [IFormBuilder](/api-reference/@react-form-builder/designer/interfaces/IFormBuilder), including imperative shortcut
actions such as save, print, undo, and redo. See [Designer hotkeys](#designer-hotkeys) for embedding details.

Another option for customizing the component is to use pure CSS. Each component has a static CSS class named with the component's name
prefixed by `FE_`. This class is applied to the same element as the style or className attributes, utilizing
Expand Down Expand Up @@ -386,5 +386,79 @@ const FormBuilderApp = () => {
}
```

## Designer hotkeys

By default the FormBuilder registers global keyboard shortcuts (delete, duplicate, save, print, undo, and redo).
When you embed the designer inside a host application, those shortcuts can conflict with the browser or the host
(especially Ctrl/Cmd+S and Ctrl/Cmd+P).

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.

### Disable all built-in hotkeys

```tsx
import {FormBuilder, type IFormBuilder} from '@react-form-builder/designer'
import {useEffect, useRef} from 'react'

const EmbeddedDesigner = () => {
const builderRef = useRef<IFormBuilder>(null)

useEffect(() => {
const onKeyDown = (event: KeyboardEvent) => {
if (!(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== 's') return
event.preventDefault()
void builderRef.current?.save?.()
}
globalThis.addEventListener('keydown', onKeyDown)
return () => globalThis.removeEventListener('keydown', onKeyDown)
}, [])

return <FormBuilder hotkeys={false} builderRef={builderRef} /* other props */ />
}
```

### Remap or disable individual shortcuts

Only the actions you list under `bindings` change. Every other action keeps its built-in default chords.
For a listed action, the value **replaces** that action’s defaults (it does not add to them). Use `false` to turn that
action’s shortcuts off while leaving the rest unchanged.

```tsx
<FormBuilder
hotkeys={{
bindings: {
// Replace only Save’s default Ctrl/Cmd+S chord; Delete, duplicate, print, undo, redo stay default.
// Prefer non-character keys such as F8: Option+S is layout-dependent on macOS (e.g. ß).
save: {key: 'F8'},
// Disable Print’s shortcut only; menu Print and IFormBuilder.print() still work
print: false
}
}}
/* other props */
/>
```

Action ids: `deleteSelected`, `cloneSelected`, `save`, `print`, `undo`, `redo`.
Pass an array of chords when one action should accept multiple bindings.
If two actions claim the same chord, the later entry in `bindings` wins and the earlier action loses that chord.
On macOS prefer `meta`; on Windows and Linux prefer `ctrl`. Use function keys when the chord must be layout-independent.

### Imperative actions

| Method | Same core behavior as | Notes |
| ------------------- | ----------------------------------------------------------- | --------------------------------------------- |
| `deleteSelected()` | Delete | |
| `cloneSelected()` | Ctrl/Cmd+D (no-op unless exactly one component is selected) | |
| `save()` | Ctrl/Cmd+S form persistence | Silent: no designer toast (host can show one) |
| `print()` | Ctrl/Cmd+P | |
| `undo()` / `redo()` | Undo / redo | |

Built-in Ctrl/Cmd+S and the Save menu item still show the designer success/error toast.
`IFormBuilder.save()` only persists the form so embedders can own feedback when they register external shortcuts.

These methods are available on the object returned by `useFormBuilder()` and through the `builderRef` prop.

[formStorage]: /formengine-designer/features/form-storage/
[jsonSchema]: /formengine-designer/features/forms-json/#json-schema
6 changes: 6 additions & 0 deletions packages/designer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export type {CustomizationMap} from './src/features/customization/CustomizationM
export type {Options} from './src/features/customization/Options'
export type {CustomizableKey} from './src/features/customization/types'
export {CustomizableZone} from './src/features/customization/types'
export type {
DesignerHotkey,
DesignerHotkeyAction,
DesignerHotkeysOptions,
DesignerHotkeysProp,
} from './src/features/hotkeys/types'
export {verifyDomain} from './src/features/license/domain'
export {isElectron} from './src/features/license/isElectron'
export type {StylesProviderProps} from './src/features/localization/components/StylesProviderProps'
Expand Down
5 changes: 4 additions & 1 deletion packages/designer/src/FormBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {Loader} from 'rsuite'
import styles from './FormBuilder.module.css'
import type {FormBuilderProps} from './FormBuilderProps'
import {customizableObserver} from './features/customization/customizableObserver'
import {useHotkeysProp} from './features/hotkeys/HotkeysPropContext'
import {useHotkeys} from './features/hotkeys/useHotKeys'
import {useLicense} from './features/license/LicenseContext'
import {BottomPanel} from './features/ui/BottomPanel/BottomPanel'
Expand All @@ -19,12 +20,14 @@ import {useBuilderStore} from './utils/BuilderStoreContext'

const GlobalHotkeys = ({children}: {children: ReactNode}) => {
const handleKeyDown = useHotkeys()
const hotkeysDisabled = useHotkeysProp() === false

// we need this effect to be inside Suspense
useEffect(() => {
if (hotkeysDisabled) return
globalThis.addEventListener('keydown', handleKeyDown)
return () => globalThis.removeEventListener('keydown', handleKeyDown)
}, [handleKeyDown])
}, [handleKeyDown, hotkeysDisabled])

return <div className={styles.container}>{children}</div>
}
Expand Down
9 changes: 9 additions & 0 deletions packages/designer/src/FormBuilderProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {ComponentType, ForwardedRef} from 'react'
import type {FormBuilderTheme} from './FormBuilderTheme'
import type {AnnotationEditorProps} from './features/annotation-editors/AnnotationEditorProps'
import type {CustomizationMap} from './features/customization/CustomizationMap'
import type {DesignerHotkeysProp} from './features/hotkeys/types'
import type {StylesProviderProps} from './features/localization/components/StylesProviderProps'
import type {FormBuilderI18n} from './features/localization/FormBuilderLanguage'
import type {IPresetComponentOptions} from './features/preset-component/IPresetComponentOptions'
Expand Down Expand Up @@ -87,6 +88,14 @@ export interface FormBuilderProps extends Omit<FormViewerProps, 'view' | 'langua
*/
customization?: CustomizationMap

/**
* Controls the FormBuilder global keyboard shortcuts.
* Pass `false` to disable all built-in global hotkeys so the host can register its own
* and invoke actions through {@link IFormBuilder}. Pass an options object to remap or
* disable individual actions.
*/
hotkeys?: DesignerHotkeysProp

/**
* The event is called whenever a form schema changes.
* @param formSchema the current form schema serialized to JSON.
Expand Down
Loading