diff --git a/packages/form-js-editor/src/features/palette/components/Palette.js b/packages/form-js-editor/src/features/palette/components/Palette.js index a10dd6afb..43515218d 100644 --- a/packages/form-js-editor/src/features/palette/components/Palette.js +++ b/packages/form-js-editor/src/features/palette/components/Palette.js @@ -5,6 +5,8 @@ import { useState } from 'preact/hooks'; +import { useService } from '../../../render/hooks'; + import { Slot } from '../../render-injection/slot-fill'; @@ -15,7 +17,7 @@ import { SearchIcon } from '../../../render/components/icons'; -import { formFields } from '@bpmn-io/form-js-viewer'; +import { formFields, sanitizeImageSource } from '@bpmn-io/form-js-viewer'; export const PALETTE_ENTRIES = formFields.filter(({ config: fieldConfig }) => fieldConfig.type !== 'default').map(({ config: fieldConfig }) => { return { @@ -25,6 +27,7 @@ export const PALETTE_ENTRIES = formFields.filter(({ config: fieldConfig }) => fi }; }); +// todo(pinussilvestrus): should it be possible to configure the palette groups? export const PALETTE_GROUPS = [ { label: 'Basic input', @@ -46,13 +49,17 @@ export const PALETTE_GROUPS = [ export default function Palette(props) { - const [ entries, setEntries ] = useState(PALETTE_ENTRIES); + const formFields = useService('formFields'); + + const initialPaletteEntries = collectPaletteEntries(formFields); + + const [ paletteEntries, setPaletteEntries ] = useState(initialPaletteEntries); const [ searchTerm, setSearchTerm ] = useState(''); const inputRef = useRef(); - const groups = groupEntries(entries); + const groups = groupEntries(paletteEntries); const simplifyString = useCallback((str) => { return str @@ -78,8 +85,8 @@ export default function Palette(props) { // filter entries on search change useEffect(() => { - const entries = PALETTE_ENTRIES.filter(filter); - setEntries(entries); + const entries = initialPaletteEntries.filter(filter); + setPaletteEntries(entries); }, [ filter, searchTerm ]); const handleInput = useCallback(event => { @@ -120,8 +127,9 @@ export default function Palette(props) { { label }