Skip to content

Commit a8aada8

Browse files
author
Niklas Kiefer
committed
feat(editor): render properties panel per default
1 parent 486769e commit a8aada8

File tree

4 files changed

+92
-21
lines changed

4 files changed

+92
-21
lines changed

packages/form-js-editor/assets/form-js-editor.css

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
--color-context-pad-item-fill: var(--color-grey-225-10-35);
99
--color-context-pad-item-hover-fill: var(--color-black);
1010

11-
--color-properties-container-background: var(--color-white);
12-
--color-properties-container-border: var(--color-grey-225-10-80);
13-
1411
--color-dragula-background: var(--color-blue-205-100-45);
1512
--color-dragula-border: var(--color-blue-205-100-45);
1613
--color-dragula-mirror-background: var(--color-white);
@@ -27,6 +24,12 @@
2724
--color-palette-field-hover-background: var(--color-grey-225-10-95);
2825
}
2926

27+
.fjs-properties-container {
28+
--color-properties-container-background: var(--color-white);
29+
--color-properties-container-border: var(--color-grey-225-10-80);
30+
--properties-panel-width: 300px;
31+
}
32+
3033
.fjs-editor-container {
3134
height: 100%;
3235
width: 100%;
@@ -41,7 +44,7 @@
4144

4245
.fjs-editor-container .fjs-form-container,
4346
.fjs-editor-container .fjs-editor-palette-container,
44-
.fjs-editor-container .fjs-properties-container {
47+
.fjs-editor-container .fjs-editor-properties-container {
4548
overflow-y: auto;
4649
position: relative;
4750
}
@@ -188,22 +191,25 @@
188191
* Properties Panel
189192
*/
190193
.fjs-editor-container .fjs-properties-container {
191-
width: 300px;
194+
height: 100%;
195+
}
196+
197+
.fjs-properties-container {
192198
background-color: var(--color-properties-container-background);
199+
width: var(--properties-panel-width);
193200
border-left: solid 1px var(--color-properties-container-border);
194-
height: 100%;
195201
color: var(--color-text);
196202
}
197203

198-
.fjs-editor-container .fjs-properties-panel {
204+
.fjs-properties-container .fjs-properties-panel {
199205
height: 100%;
200206
}
201207

202-
.fjs-editor-container .fjs-properties-panel * {
208+
.fjs-properties-container .fjs-properties-panel * {
203209
box-sizing: border-box;
204210
}
205211

206-
.fjs-editor-container .bio-properties-panel-header-icon svg {
212+
.fjs-properties-container .fjs-properties-panel .bio-properties-panel-header-icon svg {
207213
transform: scale(1.3);
208214
}
209215

packages/form-js-editor/src/FormEditor.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import KeyboardModule from './features/keyboard';
99
import ModelingModule from './features/modeling';
1010
import SelectionModule from './features/selection';
1111
import PaletteModule from './features/palette';
12+
import PropertiesPanelModule from './features/properties-panel';
1213

1314
const ids = new Ids([ 32, 36, 1 ]);
1415

@@ -298,7 +299,8 @@ export default class FormEditor {
298299
EditorActionsModule,
299300
KeyboardModule,
300301
SelectionModule,
301-
PaletteModule
302+
PaletteModule,
303+
PropertiesPanelModule
302304
];
303305
}
304306

packages/form-js-editor/src/render/components/FormEditor.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ import useService from '../hooks/useService';
1717

1818
import { DragAndDropContext } from '../context';
1919

20-
import PropertiesPanel from './properties-panel/PropertiesPanel';
21-
2220
import dragula from 'dragula';
2321

24-
import { ListDeleteIcon } from './properties-panel/icons';
22+
import { ListDeleteIcon } from '../../features/properties-panel/icons';
2523

2624
import { iconsByType } from './icons';
2725

@@ -151,13 +149,16 @@ export default function FormEditor(props) {
151149
modeling = useService('modeling'),
152150
selection = useService('selection'),
153151
palette = useService('palette'),
154-
paletteConfig = useService('config.palette');
152+
paletteConfig = useService('config.palette'),
153+
propertiesPanel = useService('propertiesPanel'),
154+
propertiesPanelConfig = useService('config.propertiesPanel');
155155

156156
const { schema } = formEditor._getState();
157157

158158
const paletteRef = useRef(null);
159+
const propertiesPanelRef = useRef(null);
159160

160-
const [ selectedFormField, setSelection ] = useState(schema);
161+
const [ , setSelection ] = useState(schema);
161162

162163
useEffect(() => {
163164
function handleSelectionChanged(event) {
@@ -254,7 +255,7 @@ export default function FormEditor(props) {
254255
};
255256
}, []);
256257

257-
// fire event after first render to notify interested parties
258+
// fire event after render to notify interested parties
258259
useEffect(() => {
259260
eventBus.fire('formEditor.rendered');
260261
}, []);
@@ -295,8 +296,6 @@ export default function FormEditor(props) {
295296

296297
const onReset = useCallback(() => {}, []);
297298

298-
const editField = useCallback((formField, key, value) => modeling.editFormField(formField, key, value), [ modeling ]);
299-
300299
// attach default palette
301300
const hasDefaultPalette = defaultPalette(paletteConfig);
302301

@@ -306,6 +305,15 @@ export default function FormEditor(props) {
306305
}
307306
}, [ palette, paletteRef, hasDefaultPalette ]);
308307

308+
// attach default properties panel
309+
const hasDefaultPropertiesPanel = defaultPropertiesPanel(propertiesPanelConfig);
310+
311+
useEffect(() => {
312+
if (hasDefaultPropertiesPanel) {
313+
propertiesPanel.attachTo(propertiesPanelRef.current);
314+
}
315+
}, [ propertiesPanelRef, propertiesPanel, hasDefaultPropertiesPanel ]);
316+
309317
return (
310318
<div class="fjs-form-editor">
311319

@@ -323,9 +331,7 @@ export default function FormEditor(props) {
323331
<CreatePreview />
324332
</DragAndDropContext.Provider>
325333

326-
<div class="fjs-properties-container">
327-
<PropertiesPanel field={ selectedFormField } editField={ editField } />
328-
</div>
334+
{ hasDefaultPropertiesPanel && <div class="fjs-editor-properties-container" ref={ propertiesPanelRef } /> }
329335
</div>
330336
);
331337
}
@@ -379,4 +385,8 @@ function CreatePreview(props) {
379385

380386
function defaultPalette(paletteConfig) {
381387
return !(paletteConfig && paletteConfig.parent);
388+
}
389+
390+
function defaultPropertiesPanel(propertiesPanelConfig) {
391+
return !(propertiesPanelConfig && propertiesPanelConfig.parent);
382392
}

packages/form-js-editor/test/spec/FormEditor.spec.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,59 @@ describe('FormEditor', function() {
592592

593593
describe('properties panel', function() {
594594

595+
it('should provide propertiesPanel module', async function() {
596+
597+
// when
598+
formEditor = await createFormEditor({
599+
container,
600+
schema
601+
});
602+
603+
expect(formEditor.get('propertiesPanel')).to.exist;
604+
});
605+
606+
607+
it('should render propertiesPanel per default', async function() {
608+
609+
// given
610+
formEditor = await createFormEditor({
611+
container,
612+
schema
613+
});
614+
615+
// when
616+
const propertiesContainer = domQuery('.fjs-editor-properties-container', container);
617+
618+
// then
619+
expect(propertiesContainer).to.exist;
620+
});
621+
622+
623+
it('should render propertiesPanel on given container', async function() {
624+
625+
// given
626+
const propertiesParent = document.createElement('div');
627+
document.body.appendChild(propertiesParent);
628+
629+
formEditor = await createFormEditor({
630+
container,
631+
schema,
632+
propertiesPanel: {
633+
parent: propertiesParent
634+
}
635+
});
636+
637+
// when
638+
const propertiesContainer = domQuery('.fjs-properties-container', propertiesParent);
639+
640+
// then
641+
expect(domQuery('.fjs-editor-properties-container', container)).to.not.exist;
642+
expect(propertiesContainer).to.exist;
643+
644+
document.body.removeChild(propertiesParent);
645+
});
646+
647+
595648
describe('selection behavior', function() {
596649

597650
const schema = {

0 commit comments

Comments
 (0)