Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type ComponentOption = {
category: TemplateMeta["category"];
icon: undefined | string;
order: undefined | number;
firstInstance: { component: string };
};

const getComponentScore = (meta: ComponentOption) => {
Expand Down Expand Up @@ -158,6 +159,7 @@ const $componentOptions = computed(
category,
icon: meta.icon,
order: meta.order,
firstInstance: { component: name },
});
}
for (const [name, meta] of templates) {
Expand Down Expand Up @@ -188,6 +190,7 @@ const $componentOptions = computed(
category: meta.category,
icon: meta.icon ?? componentMeta?.icon,
order: meta.order,
firstInstance: meta.template.instances[0],
});
}
componentOptions.sort(
Expand All @@ -205,7 +208,7 @@ const ComponentOptionsGroup = ({ options }: { options: ComponentOption[] }) => {
heading={<CommandGroupHeading>Components</CommandGroupHeading>}
actions={["add"]}
>
{options.map(({ component, label, category, icon }) => {
{options.map(({ component, label, category, icon, firstInstance }) => {
return (
<CommandItem
key={component}
Expand All @@ -225,7 +228,7 @@ const ComponentOptionsGroup = ({ options }: { options: ComponentOption[] }) => {
>
<Flex gap={2}>
<CommandIcon>
<InstanceIcon instance={{ component }} icon={icon} />
<InstanceIcon instance={firstInstance} icon={icon} />
</CommandIcon>
<Text variant="labelsTitleCase">
{label}{" "}
Expand Down Expand Up @@ -265,7 +268,9 @@ const $tagOptions = computed(
newInstances.set(childInstance.id, childInstance);
newInstances.set(instance.id, {
...instance,
children: [...instance.children, { type: "id", value: childInstance.id }],
// avoid preserving original children to not invalidate tag
// when some descendants do not satisfy content model
children: [{ type: "id", value: childInstance.id }],
});
for (const tag of tags) {
childInstance.tag = tag;
Expand Down
16 changes: 10 additions & 6 deletions apps/builder/app/builder/features/style-panel/shared/model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ const getDefinedStyles = ({
];
};

const $model = computed(
export const $styleObjectModel = computed(
[
$styles,
$styleSourceSelections,
Expand Down Expand Up @@ -241,7 +241,7 @@ const $model = computed(

export const $computedStyleDeclarations = computed(
[
$model,
$styleObjectModel,
$selectedInstancePathWithRoot,
$selectedOrLastStyleSourceSelector,
$registeredComponentMetas,
Expand Down Expand Up @@ -331,7 +331,11 @@ export const $availableColorVariables = computed(

export const createComputedStyleDeclStore = (property: CssProperty) => {
return computed(
[$model, $selectedInstancePathWithRoot, $selectedOrLastStyleSourceSelector],
[
$styleObjectModel,
$selectedInstancePathWithRoot,
$selectedOrLastStyleSourceSelector,
],
(model, instancePath, styleSourceSelector) => {
return getComputedStyleDecl({
model,
Expand All @@ -345,7 +349,7 @@ export const createComputedStyleDeclStore = (property: CssProperty) => {
};

export const useStyleObjectModel = () => {
return useStore($model);
return useStore($styleObjectModel);
};

export const useComputedStyleDecl = (property: CssProperty) => {
Expand Down Expand Up @@ -378,7 +382,7 @@ export const useParentComputedStyleDecl = (property: CssProperty) => {
const $store = useMemo(
() =>
computed(
[$model, $closestStylableInstanceSelector],
[$styleObjectModel, $closestStylableInstanceSelector],
(model, instanceSelector) => {
return getComputedStyleDecl({
model,
Expand All @@ -397,7 +401,7 @@ export const getInstanceStyleDecl = (
instanceSelector: InstanceSelector
) => {
return getComputedStyleDecl({
model: $model.get(),
model: $styleObjectModel.get(),
instanceSelector,
property,
});
Expand Down
Loading