Skip to content

Remove form field via keyboard #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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 @@ -17,6 +17,7 @@ export default class FormEditorActions extends EditorActions {
_registerDefaultActions(injector) {
const commandStack = injector.get('commandStack', false),
formFieldRegistry = injector.get('formFieldRegistry', false),
modeling = injector.get('modeling', false),
selection = injector.get('selection', false);

if (commandStack) {
Expand Down Expand Up @@ -48,11 +49,45 @@ export default class FormEditorActions extends EditorActions {
selection.set(formField);
}
});

}

if (modeling && selection) {

// @ts-ignore
this.register('removeSelection', () => {
const selectedFormField = selection.get();

if (!selectedFormField) {
return;
}

const parentField = formFieldRegistry.get(selectedFormField._parent);

const index = getFormFieldIndex(parentField, selectedFormField);

modeling.removeFormField(selectedFormField, parentField, index);
});
}
}
}

FormEditorActions.$inject = [
'eventBus',
'injector'
];
];


// helper ////////////

function getFormFieldIndex(parent, formField) {
let fieldFormIndex = parent.components.length;

parent.components.forEach(({ id }, index) => {
if (id === formField.id) {
fieldFormIndex = index;
}
});

return fieldFormIndex;
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ export default class FormEditorKeyboardBindings {
}
});

// delete selected field
// DEL
addListener('removeSelection', (context) => {

const { keyEvent } = context;

if (isKey([ 'Backspace', 'Delete', 'Del' ], keyEvent)) {

editorActions.trigger('removeSelection');

return true;
}
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/form-js-playground/src/Playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { PlaygroundRoot } from './components/PlaygroundRoot';
* actions?: { display: Boolean }
* container?: Element
* data: any
* editor?: { inlinePropertiesPanel: Boolean }
* editor?: { inlinePropertiesPanel: Boolean, keyboard?: { bindTo: Element } }
* exporter?: { name: String, version: String }
* schema: any
* } } FormPlaygroundOptions
Expand Down
6 changes: 4 additions & 2 deletions packages/form-js-playground/src/components/PlaygroundRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function PlaygroundRoot(props) {
} = actionsConfig;

const {
inlinePropertiesPanel = true
inlinePropertiesPanel = true,
keyboard = {}
} = editorConfig;

const paletteContainerRef = useRef();
Expand Down Expand Up @@ -107,7 +108,8 @@ export function PlaygroundRoot(props) {
propertiesPanel: {
parent: !inlinePropertiesPanel && propertiesPanelContainerRef.current
},
exporter: exporterConfig
exporter: exporterConfig,
keyboard
});

paletteRef.current = formEditor.get('palette');
Expand Down
5 changes: 4 additions & 1 deletion packages/form-js-playground/test/spec/Playground.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ describe('playground', function() {
playground = new Playground({
container,
schema,
data
data,
editor: {
keyboard: { bindTo: document }
}
});

// then
Expand Down