Skip to content

Commit 37e85b1

Browse files
author
Niklas Kiefer
committed
feat(editor): support modeling image view
Closes #383
1 parent 6b9c753 commit 37e85b1

File tree

15 files changed

+316
-12
lines changed

15 files changed

+316
-12
lines changed

packages/form-js-editor/src/features/palette/components/Palette.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const types = [
3737
label: 'Text',
3838
type: 'text'
3939
},
40+
{
41+
label: 'Image view',
42+
type: 'image'
43+
},
4044
{
4145
label: 'Button',
4246
type: 'button'

packages/form-js-editor/src/features/properties-panel/PropertiesPanelHeaderProvider.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const labelsByType = {
1010
checklist: 'CHECKLIST',
1111
columns: 'COLUMNS',
1212
default: 'FORM',
13+
image: 'IMAGE',
1314
number: 'NUMBER',
1415
radio: 'RADIO',
1516
select: 'SELECT',
@@ -30,6 +31,10 @@ export const PropertiesPanelHeaderProvider = {
3031
return textToLabel(field.text);
3132
}
3233

34+
if (type === 'image') {
35+
return field.alt;
36+
}
37+
3338
if (type === 'default') {
3439
return field.id;
3540
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { get } from 'min-dash';
2+
3+
import { useService, useVariables } from '../hooks';
4+
5+
import { FeelEntry, isFeelEntryEdited } from '@bpmn-io/properties-panel';
6+
7+
export default function AltTextEntry(props) {
8+
const {
9+
editField,
10+
field
11+
} = props;
12+
13+
const {
14+
type
15+
} = field;
16+
17+
const entries = [];
18+
19+
if (type === 'image') {
20+
entries.push({
21+
id: 'alt',
22+
component: AltText,
23+
editField: editField,
24+
field: field,
25+
isEdited: isFeelEntryEdited
26+
});
27+
}
28+
29+
return entries;
30+
}
31+
32+
function AltText(props) {
33+
const {
34+
editField,
35+
field,
36+
id
37+
} = props;
38+
39+
const debounce = useService('debounce');
40+
41+
const variables = useVariables().map(name => ({ name }));
42+
43+
const path = [ 'alt' ];
44+
45+
const getValue = () => {
46+
return get(field, path, '');
47+
};
48+
49+
const setValue = (value) => {
50+
return editField(field, path, value);
51+
};
52+
53+
return FeelEntry({
54+
debounce,
55+
element: field,
56+
feel: 'optional',
57+
getValue,
58+
id,
59+
label: 'Alternative text',
60+
setValue,
61+
variables
62+
});
63+
}

packages/form-js-editor/src/features/properties-panel/entries/ConditionEntry.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { FeelEntry, isFeelEntryEdited } from '@bpmn-io/properties-panel';
22
import { get } from 'min-dash';
33

4-
import {
5-
useService,
6-
useVariables
7-
} from '../hooks';
4+
import { useService, useVariables } from '../hooks';
85

96

107
export function ConditionEntry(props) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { get } from 'min-dash';
2+
3+
import { useService, useVariables } from '../hooks';
4+
5+
import { FeelEntry, isFeelEntryEdited } from '@bpmn-io/properties-panel';
6+
7+
export default function SourceEntry(props) {
8+
const {
9+
editField,
10+
field
11+
} = props;
12+
13+
const {
14+
type
15+
} = field;
16+
17+
const entries = [];
18+
19+
if (type === 'image') {
20+
entries.push({
21+
id: 'source',
22+
component: Source,
23+
editField: editField,
24+
field: field,
25+
isEdited: isFeelEntryEdited
26+
});
27+
}
28+
29+
return entries;
30+
}
31+
32+
function Source(props) {
33+
const {
34+
editField,
35+
field,
36+
id
37+
} = props;
38+
39+
const debounce = useService('debounce');
40+
41+
const variables = useVariables().map(name => ({ name }));
42+
43+
const path = [ 'source' ];
44+
45+
const getValue = () => {
46+
return get(field, path, '');
47+
};
48+
49+
const setValue = (value) => {
50+
return editField(field, path, value);
51+
};
52+
53+
return FeelEntry({
54+
debounce,
55+
description: 'Expression or static value (link/data URI)',
56+
element: field,
57+
feel: 'optional',
58+
getValue,
59+
id,
60+
label: 'Image source',
61+
setValue,
62+
variables
63+
});
64+
}

packages/form-js-editor/src/features/properties-panel/entries/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
export { default as ActionEntry } from './ActionEntry';
2+
export { default as AltTextEntry } from './AltTextEntry';
23
export { default as ColumnsEntry } from './ColumnsEntry';
34
export { default as DescriptionEntry } from './DescriptionEntry';
45
export { default as DefaultValueEntry } from './DefaultValueEntry';
56
export { default as DisabledEntry } from './DisabledEntry';
67
export { default as IdEntry } from './IdEntry';
78
export { default as KeyEntry } from './KeyEntry';
89
export { default as LabelEntry } from './LabelEntry';
10+
export { default as ImageSourceEntry } from './ImageSourceEntry';
911
export { default as TextEntry } from './TextEntry';
1012
export { default as NumberEntries } from './NumberEntries';
1113
export { default as NumberSerializationEntry } from './NumberSerializationEntry';

packages/form-js-editor/src/features/properties-panel/groups/GeneralGroup.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import {
22
ActionEntry,
3+
AltTextEntry,
34
ColumnsEntry,
45
DescriptionEntry,
56
DefaultValueEntry,
67
DisabledEntry,
78
IdEntry,
9+
ImageSourceEntry,
810
KeyEntry,
911
LabelEntry,
1012
TextEntry,
@@ -24,6 +26,8 @@ export default function GeneralGroup(field, editField) {
2426
...ColumnsEntry({ field, editField }),
2527
...TextEntry({ field, editField }),
2628
...NumberEntries({ field, editField }),
29+
...ImageSourceEntry({ field, editField }),
30+
...AltTextEntry({ field, editField }),
2731
...DisabledEntry({ field, editField })
2832
];
2933

Lines changed: 4 additions & 0 deletions
Loading

packages/form-js-editor/src/render/components/icons/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@ import SelectIcon from './Select.svg';
1010
import TextIcon from './Text.svg';
1111
import TextfieldIcon from './Textfield.svg';
1212
import TextareaIcon from './Textarea.svg';
13+
import ImageIcon from './Image.svg';
1314

1415
export const iconsByType = {
1516
button: ButtonIcon,
1617
checkbox: CheckboxIcon,
1718
checklist: ChecklistIcon,
1819
columns: ColumnsIcon,
20+
image: ImageIcon,
1921
number: NumberIcon,
2022
radio: RadioIcon,
2123
select: SelectIcon,

packages/form-js-editor/test/helper/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
merge
55
} from 'min-dash';
66

7+
import { act } from 'preact/test-utils';
8+
79
import TestContainer from 'mocha-test-container-support';
810

911
import FormEditor from '../../src/FormEditor';
@@ -165,4 +167,13 @@ export function insertCSS(name, css) {
165167
style.appendChild(document.createTextNode(css));
166168

167169
head.appendChild(style);
170+
}
171+
172+
export async function setEditorValue(editor, value) {
173+
await act(() => {
174+
editor.textContent = value;
175+
});
176+
177+
// Requires 2 ticks to propagate the change to bpmn-js
178+
await act(() => {});
168179
}

0 commit comments

Comments
 (0)