Skip to content
Merged
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 @@ -24,6 +24,7 @@ import {
componentCategories,
collectionComponent,
parseComponentName,
elementComponent,
} from "@webstudio-is/sdk";
import type { Breakpoint, Page } from "@webstudio-is/sdk";
import type { TemplateMeta } from "@webstudio-is/template";
Expand Down Expand Up @@ -162,6 +163,9 @@ const $componentOptions = computed(
) {
continue;
}
if (isFeatureEnabled("element") === false && name === elementComponent) {
continue;
}

const componentMeta = metas.get(name);
const label =
Expand Down
4 changes: 4 additions & 0 deletions apps/builder/app/builder/features/components/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
componentCategories,
collectionComponent,
parseComponentName,
elementComponent,
} from "@webstudio-is/sdk";
import {
theme,
Expand Down Expand Up @@ -97,6 +98,9 @@ const $metas = computed(
) {
continue;
}
if (isFeatureEnabled("element") === false && name === elementComponent) {
continue;
}

metas.push({
name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const TagControl = ({ meta, prop }: ControlProps<"tag">) => {
}}
getDescription={(item) => (
<Box css={{ width: theme.spacing[28] }}>
{elementsByTag[item].description}
{elementsByTag[item]?.description}
</Box>
)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
blockComponent,
blockTemplateComponent,
getIndexesWithinAncestors,
elementComponent,
} from "@webstudio-is/sdk";
import { indexProperty, tagProperty } from "@webstudio-is/sdk/runtime";
import {
Expand Down Expand Up @@ -471,10 +472,14 @@ export const WebstudioComponentCanvas = forwardRef<
return <></>;
}

let Component =
let Component: string | AnyComponent =
components.get(instance.component) ??
(MissingComponentStub as AnyComponent);

if (instance.component === elementComponent) {
Component = instance.tag ?? "div";
}

if (instance.component === collectionComponent) {
const data = instanceProps.data;
if (data && Array.isArray(data) === false) {
Expand Down Expand Up @@ -662,7 +667,13 @@ export const WebstudioComponentPreview = forwardRef<
return <></>;
}

let Component = components.get(instance.component);
let Component: undefined | string | AnyComponent = components.get(
instance.component
);

if (instance.component === elementComponent) {
Component = instance.tag ?? "div";
}

if (instance.component === blockComponent) {
Component = Block;
Expand Down
15 changes: 9 additions & 6 deletions apps/builder/app/shared/instance-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
Prop,
parseComponentName,
Props,
elementComponent,
} from "@webstudio-is/sdk";
import {
$props,
Expand Down Expand Up @@ -171,14 +172,16 @@ const getLabelFromComponentName = (component: Instance["component"]) => {
};

export const getInstanceLabel = (
instance: { component: string; label?: string },
instance: { component: string; label?: string; tag?: string },
meta: { label?: string }
) => {
return (
instance.label ||
meta.label ||
getLabelFromComponentName(instance.component)
);
if (instance.label) {
return instance.label;
}
if (instance.component === elementComponent && instance.tag) {
return `<${instance.tag}>`;
}
return meta.label || getLabelFromComponentName(instance.component);
};

export const findAllEditableInstanceSelector = ({
Expand Down
1 change: 1 addition & 0 deletions packages/feature-flags/src/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export const aiRadixComponents = false;
export const animation = false;
export const videoAnimation = false;
export const resourceProp = false;
export const element = false;
17 changes: 17 additions & 0 deletions packages/html-data/bin/elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,20 @@ export const elementsByTag: Record<string, Element> = ${JSON.stringify(elementsB
const contentModelFile = "./src/__generated__/elements.ts";
await mkdir(dirname(contentModelFile), { recursive: true });
await writeFile(contentModelFile, contentModel);

const tags: string[] = [];
for (const [tag, element] of Object.entries(elementsByTag)) {
if (element.categories.includes("metadata")) {
continue;
}
// @todo remove when element insert can adapt to parent
if (element.categories.includes("none")) {
continue;
}
tags.push(tag);
}
const tagsContent = `export const tags: string[] = ${JSON.stringify(tags, null, 2)};
`;
const tagsFile = "../sdk/src/__generated__/tags.ts";
await mkdir(dirname(tagsFile), { recursive: true });
await writeFile(tagsFile, tagsContent);
83 changes: 83 additions & 0 deletions packages/sdk/src/__generated__/tags.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions packages/sdk/src/core-metas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import {
PaintBrushIcon,
SettingsIcon,
AddTemplateInstanceIcon,
HtmlElementIcon,
BoxIcon,
} from "@webstudio-is/icons/svg";
import { html } from "./__generated__/normalize.css";
import * as normalize from "./__generated__/normalize.css";
import type {
WsComponentMeta,
WsComponentPropsMeta,
} from "./schema/component-meta";
import type { Instance } from "./schema/instances";
import { tagProperty } from "./runtime";
import { tags } from "./__generated__/tags";

export const rootComponent = "ws:root";

Expand All @@ -31,11 +34,20 @@ export const elementComponent = "ws:element";

const elementMeta: WsComponentMeta = {
label: "Element",
icon: HtmlElementIcon,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to delete the svg as well

icon: BoxIcon,
// convert [object Module] to [object Object] to enable structured cloning
presetStyle: { ...normalize },
};

const elementPropsMeta: WsComponentPropsMeta = {
props: {},
props: {
[tagProperty]: {
type: "string",
control: "tag",
required: true,
options: tags,
},
},
};

export const portalComponent = "Slot";
Expand Down
10 changes: 10 additions & 0 deletions packages/sdk/src/core-templates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ import {
blockComponent,
collectionComponent,
descendantComponent,
elementComponent,
} from "./core-metas";

const elementMeta: TemplateMeta = {
category: "general",
order: 0,
description:
"An HTML element is a core building block for web pages, structuring and displaying content like text, images, and links.",
template: <ws.element ws:tag="div"></ws.element>,
};

const collectionItem = new Parameter("collectionItem");

const collectionMeta: TemplateMeta = {
Expand Down Expand Up @@ -97,6 +106,7 @@ const blockMeta: TemplateMeta = {
};

export const coreTemplates = {
[elementComponent]: elementMeta,
[collectionComponent]: collectionMeta,
[descendantComponent]: descendantMeta,
[blockComponent]: blockMeta,
Expand Down