FEAT: Add 'inline-flex' to display selector in Style Manager
Question
What are you trying to add to GrapesJS?
Display style inline-flex.
Description:
Currently the display selector of the Style Manager has only flex as option but same as block and inline-block it is useful to have inline-flex.
When I try to add it manually with this (hack?):
editor.StyleManager.getProperty("general", "display").attributes.list.push({value: "inline-flex"});
I get a result but there are many conditional operators triggered by flex that won't trigger on inline-flex like for example the Style Manager "Flex" section will not appear.
Is there an alternative at the latest version?
[ ] Yes (descripe the alternative) [x] No
Is this related to an issue?
[ ] Yes (Give a link to the issue) [x] No
Answers (3)
For anyone looking for a solution, I didn't manage to do this by modifying the StyleManager options So here is what I did
const sector = editor.StyleManager.getSector('flex')
sector.on('change:visible', () => applyVisibility())
editor.on('component:selected', comp => applyVisibility(comp))
function applyVisibility(comp: Component = editor.getSelected()) {
requestAnimationFrame(() => {
const computedDisplay = comp?.view?.el && getComputedStyle(comp.view.el)['display'] as string || ''
const isFlex = computedDisplay === 'flex' || computedDisplay === 'inline-flex'
const parent = comp.parent()
const parentComputedDisplay = parent?.view?.el && getComputedStyle(parent.view.el)['display'] as string || ''
const parentIsFlex = parentComputedDisplay === 'flex' || parentComputedDisplay === 'inline-flex'
if (parentIsFlex || isFlex) {
sector.set('visible', true)
}
if (parentIsFlex && isFlex) {
sector.getProperties()
.forEach(p => p.set('visible', true))
} else if (isFlex) {
sector.getProperties()
.forEach(p => p.set('visible', FLEX_PROPS.includes(p.getId())))
} else if (parentIsFlex) {
sector.getProperties()
.forEach(p => p.set('visible', FLEX_ITEM_PROPS.includes(p.getId())))
}
})
}
Sorry @fq-selbach but this is something that could be handled via plugins, there is no need to have this logic in the core library
@artf ok, but can you tell me please how I can control the "Flex" category of the Style Manager because the logic of showing/hiding it seems to be hard-coded :-/ I can add 'inline-flex' to the "Display" selector with a plugin ... but it will never show the "Flex" category when its selected. Alternatively can you show me how to make the "Flex" category show always instead of being controlled by "Display=flex"?
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3294
FEAT: Adding options to properties list array in style manager
Hi, How can I add buildProps to properties list such that when an option is selected, the properties of that option will be displayed An ex...
Issue #3067
FEAT: remove 'display: block' inline style from Style Manager sectors and properties
What are you trying to add to GrapesJS? Improve visibility for Style Manager sectors and properties. Describe your feature request detailed...
Issue #3525
FEAT: In Style Manager, Allow Requiring the Default Setting
What are you trying to add to GrapesJS? The CSS property float only makes sense for position: static; elements, which happens to be the def...
Issue #3016
FEAT: secondary block manager
Currently there is only 1 block manager. I wish to move the blocks to the left of canvas. Where I can drag and drop the block from the left...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.