fix: show flex child for collection item (#4467)

Fixes https://github.com/webstudio-is/webstudio/issues/4458

Collection is not stylable and was checked for display: flex but instead
should be skipped.
This commit is contained in:
Bogdan Chadkin authored and GitHub committed 2024-11-25 12:13:32 +07:00
1 parent fd2bc2607d
commit b8b489c93c
1 file changed
+28 -2
@@ -318,15 +318,41 @@ export const useComputedStyleDecl = (property: StyleProperty) => {
return useStore($store);
};
const $closestStylableInstanceSelector = computed(
[$instanceAndRootSelector, $instances, $registeredComponentMetas],
(instanceSelector, instances, metas) => {
// ignore unstylable instances which do not affect parent/child relationships
if (instanceSelector === undefined) {
return;
}
const closestStylableIndex = instanceSelector.findIndex(
(instanceId, index) => {
// start with parent
if (index === 0) {
return false;
}
const component = instances.get(instanceId)?.component;
if (component) {
return metas.get(component)?.stylable ?? true;
}
// ids without instances are collection items
// they are not stylable
return false;
}
);
return instanceSelector.slice(closestStylableIndex);
}
);
export const useParentComputedStyleDecl = (property: StyleProperty) => {
const $store = useMemo(
() =>
computed(
[$model, $instanceAndRootSelector],
[$model, $closestStylableInstanceSelector],
(model, instanceSelector) => {
return getComputedStyleDecl({
model,
instanceSelector: instanceSelector?.slice(1),
instanceSelector,
property,
});
}