-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Niklas Kiefer
committed
Jul 26, 2022
1 parent
20dc130
commit 4633e78
Showing
59 changed files
with
770 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
packages/form-js-editor/src/features/properties-panel/PropertiesPanel.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { PropertiesPanel } from '@bpmn-io/properties-panel'; | ||
|
||
import { | ||
useCallback, | ||
useState, | ||
useLayoutEffect | ||
} from 'preact/hooks'; | ||
|
||
import { FormPropertiesPanelContext } from './context'; | ||
|
||
import { PropertiesPanelHeaderProvider } from './PropertiesPanelHeaderProvider'; | ||
import { PropertiesPanelPlaceholderProvider } from './PropertiesPanelPlaceholderProvider'; | ||
|
||
import { | ||
CustomValuesGroup, | ||
GeneralGroup, | ||
ValidationGroup, | ||
ValuesGroups | ||
} from './groups'; | ||
|
||
function getGroups(field, editField) { | ||
|
||
if (!field) { | ||
return []; | ||
} | ||
|
||
const groups = [ | ||
GeneralGroup(field, editField), | ||
...ValuesGroups(field, editField), | ||
ValidationGroup(field, editField), | ||
CustomValuesGroup(field, editField) | ||
]; | ||
|
||
// contract: if a group returns null, it should not be displayed at all | ||
return groups.filter(group => group !== null); | ||
} | ||
|
||
export default function FormPropertiesPanel(props) { | ||
const { | ||
eventBus, | ||
injector | ||
} = props; | ||
|
||
const formEditor = injector.get('formEditor'); | ||
const modeling = injector.get('modeling'); | ||
const selection = injector.get('selection'); | ||
|
||
const { schema } = formEditor._getState(); | ||
|
||
const [ state, setState ] = useState({ | ||
selectedFormField: selection.get() || schema | ||
}); | ||
|
||
const _update = (field) => { | ||
|
||
setState({ | ||
...state, | ||
selectedFormField: field | ||
}); | ||
|
||
// notify interested parties on property panel updates | ||
eventBus.fire('propertiesPanel.updated', { | ||
formField: field | ||
}); | ||
}; | ||
|
||
// TODO(pinussilvestrus): it's not working with normal useEffect | ||
useLayoutEffect(() => { | ||
function onSelectionChange(event) { | ||
_update(event.selection || schema); | ||
} | ||
|
||
eventBus.on('selection.changed', onSelectionChange); | ||
|
||
return () => { | ||
eventBus.off('selection.changed', onSelectionChange); | ||
}; | ||
}, []); | ||
|
||
useLayoutEffect(() => { | ||
const onFieldChanged = () => { | ||
|
||
/** | ||
* TODO(pinussilvestrus): update with actual updated element, | ||
* once we have a proper updater/change support | ||
*/ | ||
_update(selection.get() || schema); | ||
}; | ||
|
||
eventBus.on('changed', onFieldChanged); | ||
|
||
return () => { | ||
eventBus.off('changed', onFieldChanged); | ||
}; | ||
}, []); | ||
|
||
const selectedFormField = state.selectedFormField; | ||
|
||
const propertiesPanelContext = { | ||
getService(type, strict = true) { | ||
return injector.get(type, strict); | ||
} | ||
}; | ||
|
||
const onFocus = () => eventBus.fire('propertiesPanel.focusin'); | ||
|
||
const onBlur = () => eventBus.fire('propertiesPanel.focusout'); | ||
|
||
const editField = useCallback((formField, key, value) => modeling.editFormField(formField, key, value), [ modeling ]); | ||
|
||
return ( | ||
<div | ||
class="fjs-properties-panel" | ||
data-field={ selectedFormField && selectedFormField.id } | ||
onFocusCapture={ onFocus } | ||
onBlurCapture={ onBlur } | ||
> | ||
<FormPropertiesPanelContext.Provider value={ propertiesPanelContext }> | ||
<PropertiesPanel | ||
element={ selectedFormField } | ||
eventBus={ eventBus } | ||
groups={ getGroups(selectedFormField, editField) } | ||
headerProvider={ PropertiesPanelHeaderProvider } | ||
placeholderProvider={ PropertiesPanelPlaceholderProvider } | ||
/> | ||
</FormPropertiesPanelContext.Provider> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
103 changes: 103 additions & 0 deletions
103
packages/form-js-editor/src/features/properties-panel/PropertiesPanelRenderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import PropertiesPanel from './PropertiesPanel'; | ||
|
||
import { | ||
render | ||
} from 'preact'; | ||
|
||
import { | ||
domify, | ||
query as domQuery | ||
} from 'min-dom'; | ||
|
||
/** | ||
* @typedef { { parent: Element } } PropertiesPanelConfig | ||
* @typedef { import('../../core/EventBus').default } EventBus | ||
* @typedef { import('../../types').Injector } Injector | ||
*/ | ||
|
||
/** | ||
* @param {PropertiesPanelConfig} propertiesPanelConfig | ||
* @param {Injector} injector | ||
* @param {EventBus} eventBus | ||
*/ | ||
export default class PropertiesPanelRenderer { | ||
|
||
constructor(propertiesPanelConfig, injector, eventBus) { | ||
const { | ||
parent | ||
} = propertiesPanelConfig || {}; | ||
|
||
this._eventBus = eventBus; | ||
this._injector = injector; | ||
|
||
this._container = domify('<div class="fjs-properties-container" input-handle-modified-keys="y,z"></div>'); | ||
|
||
if (parent) { | ||
this.attachTo(parent); | ||
} | ||
|
||
this._eventBus.once('formEditor.rendered', 500, () => { | ||
this._render(); | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* Attach the properties panel to a parent node. | ||
* | ||
* @param {HTMLElement} container | ||
*/ | ||
attachTo(container) { | ||
if (!container) { | ||
throw new Error('container required'); | ||
} | ||
|
||
if (typeof container === 'string') { | ||
container = domQuery(container); | ||
} | ||
|
||
// (1) detach from old parent | ||
this.detach(); | ||
|
||
// (2) append to parent container | ||
container.appendChild(this._container); | ||
|
||
// (3) notify interested parties | ||
this._eventBus.fire('propertiesPanel.attach'); | ||
} | ||
|
||
/** | ||
* Detach the properties panel from its parent node. | ||
*/ | ||
detach() { | ||
const parentNode = this._container.parentNode; | ||
|
||
if (parentNode) { | ||
parentNode.removeChild(this._container); | ||
|
||
this._eventBus.fire('propertiesPanel.detach'); | ||
} | ||
} | ||
|
||
_render() { | ||
render( | ||
<PropertiesPanel | ||
eventBus={ this._eventBus } | ||
injector={ this._injector } | ||
/>, | ||
this._container | ||
); | ||
|
||
this._eventBus.fire('propertiesPanel.rendered'); | ||
} | ||
|
||
_destroy() { | ||
if (this._container) { | ||
render(null, this._container); | ||
|
||
this._eventBus.fire('propertiesPanel.destroyed'); | ||
} | ||
} | ||
} | ||
|
||
PropertiesPanelRenderer.$inject = [ 'config.propertiesPanel', 'injector', 'eventBus' ]; |
File renamed without changes.
15 changes: 15 additions & 0 deletions
15
packages/form-js-editor/src/features/properties-panel/context/FormPropertiesPanelContext.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { createContext } from 'preact'; | ||
|
||
/** | ||
* @param {string} type | ||
* @param {boolean} [strict] | ||
* | ||
* @returns {any} | ||
*/ | ||
function getService(type, strict) {} | ||
|
||
const PropertiesPanelContext = createContext({ | ||
getService | ||
}); | ||
|
||
export default PropertiesPanelContext; |
1 change: 1 addition & 0 deletions
1
packages/form-js-editor/src/features/properties-panel/context/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as FormPropertiesPanelContext } from './FormPropertiesPanelContext'; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../properties-panel/entries/ColumnsEntry.js → .../properties-panel/entries/ColumnsEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...perties-panel/entries/CustomValueEntry.js → ...perties-panel/entries/CustomValueEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...perties-panel/entries/DescriptionEntry.js → ...perties-panel/entries/DescriptionEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...nents/properties-panel/entries/IdEntry.js → ...tures/properties-panel/entries/IdEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...anel/entries/InputKeyValuesSourceEntry.js → ...anel/entries/InputKeyValuesSourceEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.