Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

experimental: support ws:element component in CLI (#5071)

Bogdan Chadkin9032a109ca89
diff --git a/packages/icons/icons/html-element.svg b/packages/icons/icons/html-element.svg
new file mode 100644
index 0000000000..9ffecde745
--- /dev/null
+++ b/packages/icons/icons/html-element.svg
@@ -0,0 +1,20 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ d="M13.5556 2H3.44444C2.6467 2 2 2.6467 2 3.44444V13.5556C2 14.3533 2.6467 15 3.44444 15H13.5556C14.3533 15 15 14.3533 15 13.5556V3.44444C15 2.6467 14.3533 2 13.5556 2Z"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ <path
+ d="M10.5 10L12 8.5L10.5 7M6 7L4.5 8.5L6 10M9.1875 5.5L7.3125 11.5"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+</svg>
diff --git a/packages/icons/src/__generated__/components.tsx b/packages/icons/src/__generated__/components.tsx
index 78bb0e630a..6452673540 100644
--- a/packages/icons/src/__generated__/components.tsx
+++ b/packages/icons/src/__generated__/components.tsx
@@ -2714,6 +2714,36 @@ export const HomeIcon: IconComponent = forwardRef(
);
HomeIcon.displayName = "HomeIcon";
+export const HtmlElementIcon: IconComponent = forwardRef(
+ ({ fill = "none", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 16 16"
+ width={size}
+ height={size}
+ fill={fill}
+ {...props}
+ ref={forwardedRef}
+ >
+ <path
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M13.556 2H3.444C2.647 2 2 2.647 2 3.444v10.112C2 14.353 2.647 15 3.444 15h10.112c.797 0 1.444-.647 1.444-1.444V3.444C15 2.647 14.353 2 13.556 2Z"
+ />
+ <path
+ stroke="currentColor"
+ strokeLinecap="round"
+ strokeLinejoin="round"
+ d="M10.5 10 12 8.5 10.5 7M6 7 4.5 8.5 6 10m3.188-4.5-1.876 6"
+ />
+ </svg>
+ );
+ }
+);
+HtmlElementIcon.displayName = "HtmlElementIcon";
+
export const ImageIcon: IconComponent = forwardRef(
({ fill = "none", size = 16, ...props }, forwardedRef) => {
return (
diff --git a/packages/icons/src/__generated__/svg.ts b/packages/icons/src/__generated__/svg.ts
index 1b99efa7ec..fbf48bf7a7 100644
--- a/packages/icons/src/__generated__/svg.ts
+++ b/packages/icons/src/__generated__/svg.ts
@@ -202,6 +202,8 @@ export const HelpIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" vie
export const HomeIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M10 14V8.667A.667.667 0 0 0 9.333 8H6.667A.667.667 0 0 0 6 8.667V14"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M2 6.667a1.333 1.333 0 0 1 .473-1.019l4.666-4a1.333 1.333 0 0 1 1.722 0l4.666 4A1.332 1.332 0 0 1 14 6.667v6A1.334 1.334 0 0 1 12.667 14H3.333A1.334 1.334 0 0 1 2 12.667v-6Z"/></svg>`;
+export const HtmlElementIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M13.556 2H3.444C2.647 2 2 2.647 2 3.444v10.112C2 14.353 2.647 15 3.444 15h10.112c.797 0 1.444-.647 1.444-1.444V3.444C15 2.647 14.353 2 13.556 2Z"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M10.5 10 12 8.5 10.5 7M6 7 4.5 8.5 6 10m3.188-4.5-1.876 6"/></svg>`;
+
export const ImageIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M12.667 2H3.333C2.597 2 2 2.597 2 3.333v9.334C2 13.403 2.597 14 3.333 14h9.334c.736 0 1.333-.597 1.333-1.333V3.333C14 2.597 13.403 2 12.667 2Z"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M6 7.333a1.333 1.333 0 1 0 0-2.666 1.333 1.333 0 0 0 0 2.666ZM14 10l-2.057-2.057a1.333 1.333 0 0 0-1.886 0L4 14"/></svg>`;
export const InfoCircleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><circle cx="8" cy="8" r="6.5" stroke="currentColor"/><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" d="M8 11.516V7.853"/><rect width="1.4" height="1.4" x="7.3" y="4.484" fill="currentColor" rx=".7"/></svg>`;
diff --git a/packages/react-sdk/src/component-generator.test.tsx b/packages/react-sdk/src/component-generator.test.tsx
index 34f28e463d..e7f5fbb870 100644
--- a/packages/react-sdk/src/component-generator.test.tsx
+++ b/packages/react-sdk/src/component-generator.test.tsx
@@ -1301,3 +1301,137 @@ test("render tag property on components", () => {
)
);
});
+
+test("render ws:element component with div tag by default", () => {
+ expect(
+ generateWebstudioComponent({
+ classesMap: new Map(),
+ scope: createScope(),
+ name: "Page",
+ rootInstanceId: "bodyId",
+ parameters: [],
+ metas: new Map(),
+ ...renderData(
+ <$.Body ws:id="bodyId">
+ <ws.element id="element1">
+ <ws.element id="element2"></ws.element>
+ </ws.element>
+ </$.Body>
+ ),
+ })
+ ).toEqual(
+ validateJSX(
+ clear(`
+ const Page = () => {
+ return <Body>
+ <div
+ id={"element1"}>
+ <div
+ id={"element2"} />
+ </div>
+ </Body>
+ }
+ `)
+ )
+ );
+});
+
+test("render ws:element component with ws:tag", () => {
+ expect(
+ generateWebstudioComponent({
+ classesMap: new Map(),
+ scope: createScope(),
+ name: "Page",
+ rootInstanceId: "bodyId",
+ parameters: [],
+ metas: new Map(),
+ ...renderData(
+ <$.Body ws:id="bodyId">
+ <ws.element ws:tag="p" id="paragraph">
+ <ws.element ws:tag="span" id="span"></ws.element>
+ </ws.element>
+ </$.Body>
+ ),
+ })
+ ).toEqual(
+ validateJSX(
+ clear(`
+ const Page = () => {
+ return <Body>
+ <p
+ id={"paragraph"}>
+ <span
+ id={"span"} />
+ </p>
+ </Body>
+ }
+ `)
+ )
+ );
+});
+
+test("convert attributes to react compatible when render ws:element", () => {
+ expect(
+ generateWebstudioComponent({
+ classesMap: new Map(),
+ scope: createScope(),
+ name: "Page",
+ rootInstanceId: "bodyId",
+ parameters: [],
+ metas: new Map(),
+ ...renderData(
+ <$.Body ws:id="bodyId">
+ <ws.element
+ class="my-class"
+ for="my-id"
+ autocomplete="off"
+ ></ws.element>
+ </$.Body>
+ ),
+ })
+ ).toEqual(
+ validateJSX(
+ clear(`
+ const Page = () => {
+ return <Body>
+ <div
+ htmlFor={"my-id"}
+ autoComplete={"off"}
+ className={\`\${"my-class"}\`} />
+ </Body>
+ }
+ `)
+ )
+ );
+});
+
+test("ignore props similar to standard attributes on react components", () => {
+ expect(
+ generateWebstudioComponent({
+ classesMap: new Map(),
+ scope: createScope(),
+ name: "Page",
+ rootInstanceId: "bodyId",
+ parameters: [],
+ metas: new Map(),
+ ...renderData(
+ <$.Body ws:id="bodyId">
+ <$.Box class="my-class" for="my-id" autocomplete="off"></$.Box>
+ </$.Body>
+ ),
+ })
+ ).toEqual(
+ validateJSX(
+ clear(`
+ const Page = () => {
+ return <Body>
+ <Box
+ class={"my-class"}
+ for={"my-id"}
+ autocomplete={"off"} />
+ </Body>
+ }
+ `)
+ )
+ );
+});
diff --git a/packages/react-sdk/src/component-generator.ts b/packages/react-sdk/src/component-generator.ts
index d72b17382b..09b5f210b2 100644
--- a/packages/react-sdk/src/component-generator.ts
+++ b/packages/react-sdk/src/component-generator.ts
@@ -19,9 +19,11 @@ import {
collectionComponent,
descendantComponent,
getIndexesWithinAncestors,
+ elementComponent,
} from "@webstudio-is/sdk";
import { tagProperty } from "@webstudio-is/sdk/runtime";
import { indexAttribute, isAttributeNameSafe, showAttribute } from "./props";
+import { standardAttributesToReactProps } from "./standard-attributes";
/**
* (arg1) => {
@@ -172,7 +174,7 @@ export const generateJsxElement = ({
if (index !== undefined) {
generatedProps += `\n${indexAttribute}="${index}"`;
}
- if (instance.tag !== undefined) {
+ if (instance.tag !== undefined && instance.component !== elementComponent) {
generatedProps += `\n${tagProperty}=${JSON.stringify(instance.tag)}`;
}
@@ -196,6 +198,10 @@ export const generateJsxElement = ({
if (isAttributeNameSafe(prop.name) === false) {
continue;
}
+ let name = prop.name;
+ if (instance.component === elementComponent) {
+ name = standardAttributesToReactProps[prop.name] ?? prop.name;
+ }
// show prop controls conditional rendering and need to be handled separately
if (prop.name === showAttribute) {
@@ -221,12 +227,12 @@ export const generateJsxElement = ({
continue;
}
// We need to merge atomic classes with user-defined className prop.
- if (prop.name === "className" && propValue !== undefined) {
+ if (name === "className" && propValue !== undefined) {
classNameValue = propValue;
continue;
}
if (propValue !== undefined) {
- generatedProps += `\n${prop.name}={${propValue}}`;
+ generatedProps += `\n${name}={${propValue}}`;
}
}
@@ -267,6 +273,15 @@ export const generateJsxElement = ({
generatedElement += `)}\n`;
} else if (instance.component === blockComponent) {
generatedElement += children;
+ } else if (instance.component === elementComponent) {
+ const tagName = instance.tag ?? "div";
+ if (instance.children.length === 0) {
+ generatedElement += `<${tagName}${generatedProps} />\n`;
+ } else {
+ generatedElement += `<${tagName}${generatedProps}>\n`;
+ generatedElement += children;
+ generatedElement += `</${tagName}>\n`;
+ }
} else {
const [_namespace, shortName] = parseComponentName(instance.component);
const componentVariable = scope.getName(instance.component, shortName);
diff --git a/packages/react-sdk/src/standard-attributes.ts b/packages/react-sdk/src/standard-attributes.ts
new file mode 100644
index 0000000000..447f153546
--- /dev/null
+++ b/packages/react-sdk/src/standard-attributes.ts
@@ -0,0 +1,509 @@
+/**
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ */
+
+// https://github.com/facebook/react/blob/6377903074d4b3a2de48c4da91783a5af9fc5237/packages/react-dom-bindings/src/shared/possibleStandardNames.js
+
+// When adding attributes to the HTML or SVG allowed attribute list, be sure to
+// also add them to this module to ensure casing and incorrect name
+// warnings.
+export const standardAttributesToReactProps: Record<string, string> = {
+ // HTML
+ accept: "accept",
+ acceptcharset: "acceptCharset",
+ "accept-charset": "acceptCharset",
+ accesskey: "accessKey",
+ action: "action",
+ allowfullscreen: "allowFullScreen",
+ alt: "alt",
+ as: "as",
+ async: "async",
+ autocapitalize: "autoCapitalize",
+ autocomplete: "autoComplete",
+ autocorrect: "autoCorrect",
+ autofocus: "autoFocus",
+ autoplay: "autoPlay",
+ autosave: "autoSave",
+ capture: "capture",
+ cellpadding: "cellPadding",
+ cellspacing: "cellSpacing",
+ challenge: "challenge",
+ charset: "charSet",
+ checked: "checked",
+ children: "children",
+ cite: "cite",
+ class: "className",
+ classid: "classID",
+ classname: "className",
+ cols: "cols",
+ colspan: "colSpan",
+ content: "content",
+ contenteditable: "contentEditable",
+ contextmenu: "contextMenu",
+ controls: "controls",
+ controlslist: "controlsList",
+ coords: "coords",
+ crossorigin: "crossOrigin",
+ dangerouslysetinnerhtml: "dangerouslySetInnerHTML",
+ data: "data",
+ datetime: "dateTime",
+ default: "default",
+ defaultchecked: "defaultChecked",
+ defaultvalue: "defaultValue",
+ defer: "defer",
+ dir: "dir",
+ disabled: "disabled",
+ disablepictureinpicture: "disablePictureInPicture",
+ disableremoteplayback: "disableRemotePlayback",
+ download: "download",
+ draggable: "draggable",
+ enctype: "encType",
+ enterkeyhint: "enterKeyHint",
+ fetchpriority: "fetchPriority",
+ for: "htmlFor",
+ form: "form",
+ formmethod: "formMethod",
+ formaction: "formAction",
+ formenctype: "formEncType",
+ formnovalidate: "formNoValidate",
+ formtarget: "formTarget",
+ frameborder: "frameBorder",
+ headers: "headers",
+ height: "height",
+ hidden: "hidden",
+ high: "high",
+ href: "href",
+ hreflang: "hrefLang",
+ htmlfor: "htmlFor",
+ httpequiv: "httpEquiv",
+ "http-equiv": "httpEquiv",
+ icon: "icon",
+ id: "id",
+ imagesizes: "imageSizes",
+ imagesrcset: "imageSrcSet",
+ inert: "inert",
+ innerhtml: "innerHTML",
+ inputmode: "inputMode",
+ integrity: "integrity",
+ is: "is",
+ itemid: "itemID",
+ itemprop: "itemProp",
+ itemref: "itemRef",
+ itemscope: "itemScope",
+ itemtype: "itemType",
+ keyparams: "keyParams",
+ keytype: "keyType",
+ kind: "kind",
+ label: "label",
+ lang: "lang",
+ list: "list",
+ loop: "loop",
+ low: "low",
+ manifest: "manifest",
+ marginwidth: "marginWidth",
+ marginheight: "marginHeight",
+ max: "max",
+ maxlength: "maxLength",
+ media: "media",
+ mediagroup: "mediaGroup",
+ method: "method",
+ min: "min",
+ minlength: "minLength",
+ multiple: "multiple",
+ muted: "muted",
+ name: "name",
+ nomodule: "noModule",
+ nonce: "nonce",
+ novalidate: "noValidate",
+ open: "open",
+ optimum: "optimum",
+ pattern: "pattern",
+ placeholder: "placeholder",
+ playsinline: "playsInline",
+ poster: "poster",
+ preload: "preload",
+ profile: "profile",
+ radiogroup: "radioGroup",
+ readonly: "readOnly",
+ referrerpolicy: "referrerPolicy",
+ rel: "rel",
+ required: "required",
+ reversed: "reversed",
+ role: "role",
+ rows: "rows",
+ rowspan: "rowSpan",
+ sandbox: "sandbox",
+ scope: "scope",
+ scoped: "scoped",
+ scrolling: "scrolling",
+ seamless: "seamless",
+ selected: "selected",
+ shape: "shape",
+ size: "size",
+ sizes: "sizes",
+ span: "span",
+ spellcheck: "spellCheck",
+ src: "src",
+ srcdoc: "srcDoc",
+ srclang: "srcLang",
+ srcset: "srcSet",
+ start: "start",
+ step: "step",
+ style: "style",
+ summary: "summary",
+ tabindex: "tabIndex",
+ target: "target",
+ title: "title",
+ type: "type",
+ usemap: "useMap",
+ value: "value",
+ width: "width",
+ wmode: "wmode",
+ wrap: "wrap",
+
+ // SVG
+ about: "about",
+ accentheight: "accentHeight",
+ "accent-height": "accentHeight",
+ accumulate: "accumulate",
+ additive: "additive",
+ alignmentbaseline: "alignmentBaseline",
+ "alignment-baseline": "alignmentBaseline",
+ allowreorder: "allowReorder",
+ alphabetic: "alphabetic",
+ amplitude: "amplitude",
+ arabicform: "arabicForm",
+ "arabic-form": "arabicForm",
+ ascent: "ascent",
+ attributename: "attributeName",
+ attributetype: "attributeType",
+ autoreverse: "autoReverse",
+ azimuth: "azimuth",
+ basefrequency: "baseFrequency",
+ baselineshift: "baselineShift",
+ "baseline-shift": "baselineShift",
+ baseprofile: "baseProfile",
+ bbox: "bbox",
+ begin: "begin",
+ bias: "bias",
+ by: "by",
+ calcmode: "calcMode",
+ capheight: "capHeight",
+ "cap-height": "capHeight",
+ clip: "clip",
+ clippath: "clipPath",
+ "clip-path": "clipPath",
+ clippathunits: "clipPathUnits",
+ cliprule: "clipRule",
+ "clip-rule": "clipRule",
+ color: "color",
+ colorinterpolation: "colorInterpolation",
+ "color-interpolation": "colorInterpolation",
+ colorinterpolationfilters: "colorInterpolationFilters",
+ "color-interpolation-filters": "colorInterpolationFilters",
+ colorprofile: "colorProfile",
+ "color-profile": "colorProfile",
+ colorrendering: "colorRendering",
+ "color-rendering": "colorRendering",
+ contentscripttype: "contentScriptType",
+ contentstyletype: "contentStyleType",
+ cursor: "cursor",
+ cx: "cx",
+ cy: "cy",
+ d: "d",
+ datatype: "datatype",
+ decelerate: "decelerate",
+ descent: "descent",
+ diffuseconstant: "diffuseConstant",
+ direction: "direction",
+ display: "display",
+ divisor: "divisor",
+ dominantbaseline: "dominantBaseline",
+ "dominant-baseline": "dominantBaseline",
+ dur: "dur",
+ dx: "dx",
+ dy: "dy",
+ edgemode: "edgeMode",
+ elevation: "elevation",
+ enablebackground: "enableBackground",
+ "enable-background": "enableBackground",
+ end: "end",
+ exponent: "exponent",
+ externalresourcesrequired: "externalResourcesRequired",
+ fill: "fill",
+ fillopacity: "fillOpacity",
+ "fill-opacity": "fillOpacity",
+ fillrule: "fillRule",
+ "fill-rule": "fillRule",
+ filter: "filter",
+ filterres: "filterRes",
+ filterunits: "filterUnits",
+ floodopacity: "floodOpacity",
+ "flood-opacity": "floodOpacity",
+ floodcolor: "floodColor",
+ "flood-color": "floodColor",
+ focusable: "focusable",
+ fontfamily: "fontFamily",
+ "font-family": "fontFamily",
+ fontsize: "fontSize",
+ "font-size": "fontSize",
+ fontsizeadjust: "fontSizeAdjust",
+ "font-size-adjust": "fontSizeAdjust",
+ fontstretch: "fontStretch",
+ "font-stretch": "fontStretch",
+ fontstyle: "fontStyle",
+ "font-style": "fontStyle",
+ fontvariant: "fontVariant",
+ "font-variant": "fontVariant",
+ fontweight: "fontWeight",
+ "font-weight": "fontWeight",
+ format: "format",
+ from: "from",
+ fx: "fx",
+ fy: "fy",
+ g1: "g1",
+ g2: "g2",
+ glyphname: "glyphName",
+ "glyph-name": "glyphName",
+ glyphorientationhorizontal: "glyphOrientationHorizontal",
+ "glyph-orientation-horizontal": "glyphOrientationHorizontal",
+ glyphorientationvertical: "glyphOrientationVertical",
+ "glyph-orientation-vertical": "glyphOrientationVertical",
+ glyphref: "glyphRef",
+ gradienttransform: "gradientTransform",
+ gradientunits: "gradientUnits",
+ hanging: "hanging",
+ horizadvx: "horizAdvX",
+ "horiz-adv-x": "horizAdvX",
+ horizoriginx: "horizOriginX",
+ "horiz-origin-x": "horizOriginX",
+ ideographic: "ideographic",
+ imagerendering: "imageRendering",
+ "image-rendering": "imageRendering",
+ in2: "in2",
+ in: "in",
+ inlist: "inlist",
+ intercept: "intercept",
+ k1: "k1",
+ k2: "k2",
+ k3: "k3",
+ k4: "k4",
+ k: "k",
+ kernelmatrix: "kernelMatrix",
+ kernelunitlength: "kernelUnitLength",
+ kerning: "kerning",
+ keypoints: "keyPoints",
+ keysplines: "keySplines",
+ keytimes: "keyTimes",
+ lengthadjust: "lengthAdjust",
+ letterspacing: "letterSpacing",
+ "letter-spacing": "letterSpacing",
+ lightingcolor: "lightingColor",
+ "lighting-color": "lightingColor",
+ limitingconeangle: "limitingConeAngle",
+ local: "local",
+ markerend: "markerEnd",
+ "marker-end": "markerEnd",
+ markerheight: "markerHeight",
+ markermid: "markerMid",
+ "marker-mid": "markerMid",
+ markerstart: "markerStart",
+ "marker-start": "markerStart",
+ markerunits: "markerUnits",
+ markerwidth: "markerWidth",
+ mask: "mask",
+ maskcontentunits: "maskContentUnits",
+ maskunits: "maskUnits",
+ mathematical: "mathematical",
+ mode: "mode",
+ numoctaves: "numOctaves",
+ offset: "offset",
+ opacity: "opacity",
+ operator: "operator",
+ order: "order",
+ orient: "orient",
+ orientation: "orientation",
+ origin: "origin",
+ overflow: "overflow",
+ overlineposition: "overlinePosition",
+ "overline-position": "overlinePosition",
+ overlinethickness: "overlineThickness",
+ "overline-thickness": "overlineThickness",
+ paintorder: "paintOrder",
+ "paint-order": "paintOrder",
+ panose1: "panose1",
+ "panose-1": "panose1",
+ pathlength: "pathLength",
+ patterncontentunits: "patternContentUnits",
+ patterntransform: "patternTransform",
+ patternunits: "patternUnits",
+ pointerevents: "pointerEvents",
+ "pointer-events": "pointerEvents",
+ points: "points",
+ pointsatx: "pointsAtX",
+ pointsaty: "pointsAtY",
+ pointsatz: "pointsAtZ",
+ popover: "popover",
+ popovertarget: "popoverTarget",
+ popovertargetaction: "popoverTargetAction",
+ prefix: "prefix",
+ preservealpha: "preserveAlpha",
+ preserveaspectratio: "preserveAspectRatio",
+ primitiveunits: "primitiveUnits",
+ property: "property",
+ r: "r",
+ radius: "radius",
+ refx: "refX",
+ refy: "refY",
+ renderingintent: "renderingIntent",
+ "rendering-intent": "renderingIntent",
+ repeatcount: "repeatCount",
+ repeatdur: "repeatDur",
+ requiredextensions: "requiredExtensions",
+ requiredfeatures: "requiredFeatures",
+ resource: "resource",
+ restart: "restart",
+ result: "result",
+ results: "results",
+ rotate: "rotate",
+ rx: "rx",
+ ry: "ry",
+ scale: "scale",
+ security: "security",
+ seed: "seed",
+ shaperendering: "shapeRendering",
+ "shape-rendering": "shapeRendering",
+ slope: "slope",
+ spacing: "spacing",
+ specularconstant: "specularConstant",
+ specularexponent: "specularExponent",
+ speed: "speed",
+ spreadmethod: "spreadMethod",
+ startoffset: "startOffset",
+ stddeviation: "stdDeviation",
+ stemh: "stemh",
+ stemv: "stemv",
+ stitchtiles: "stitchTiles",
+ stopcolor: "stopColor",
+ "stop-color": "stopColor",
+ stopopacity: "stopOpacity",
+ "stop-opacity": "stopOpacity",
+ strikethroughposition: "strikethroughPosition",
+ "strikethrough-position": "strikethroughPosition",
+ strikethroughthickness: "strikethroughThickness",
+ "strikethrough-thickness": "strikethroughThickness",
+ string: "string",
+ stroke: "stroke",
+ strokedasharray: "strokeDasharray",
+ "stroke-dasharray": "strokeDasharray",
+ strokedashoffset: "strokeDashoffset",
+ "stroke-dashoffset": "strokeDashoffset",
+ strokelinecap: "strokeLinecap",
+ "stroke-linecap": "strokeLinecap",
+ strokelinejoin: "strokeLinejoin",
+ "stroke-linejoin": "strokeLinejoin",
+ strokemiterlimit: "strokeMiterlimit",
+ "stroke-miterlimit": "strokeMiterlimit",
+ strokewidth: "strokeWidth",
+ "stroke-width": "strokeWidth",
+ strokeopacity: "strokeOpacity",
+ "stroke-opacity": "strokeOpacity",
+ suppresscontenteditablewarning: "suppressContentEditableWarning",
+ suppresshydrationwarning: "suppressHydrationWarning",
+ surfacescale: "surfaceScale",
+ systemlanguage: "systemLanguage",
+ tablevalues: "tableValues",
+ targetx: "targetX",
+ targety: "targetY",
+ textanchor: "textAnchor",
+ "text-anchor": "textAnchor",
+ textdecoration: "textDecoration",
+ "text-decoration": "textDecoration",
+ textlength: "textLength",
+ textrendering: "textRendering",
+ "text-rendering": "textRendering",
+ to: "to",
+ transform: "transform",
+ transformorigin: "transformOrigin",
+ "transform-origin": "transformOrigin",
+ typeof: "typeof",
+ u1: "u1",
+ u2: "u2",
+ underlineposition: "underlinePosition",
+ "underline-position": "underlinePosition",
+ underlinethickness: "underlineThickness",
+ "underline-thickness": "underlineThickness",
+ unicode: "unicode",
+ unicodebidi: "unicodeBidi",
+ "unicode-bidi": "unicodeBidi",
+ unicoderange: "unicodeRange",
+ "unicode-range": "unicodeRange",
+ unitsperem: "unitsPerEm",
+ "units-per-em": "unitsPerEm",
+ unselectable: "unselectable",
+ valphabetic: "vAlphabetic",
+ "v-alphabetic": "vAlphabetic",
+ values: "values",
+ vectoreffect: "vectorEffect",
+ "vector-effect": "vectorEffect",
+ version: "version",
+ vertadvy: "vertAdvY",
+ "vert-adv-y": "vertAdvY",
+ vertoriginx: "vertOriginX",
+ "vert-origin-x": "vertOriginX",
+ vertoriginy: "vertOriginY",
+ "vert-origin-y": "vertOriginY",
+ vhanging: "vHanging",
+ "v-hanging": "vHanging",
+ videographic: "vIdeographic",
+ "v-ideographic": "vIdeographic",
+ viewbox: "viewBox",
+ viewtarget: "viewTarget",
+ visibility: "visibility",
+ vmathematical: "vMathematical",
+ "v-mathematical": "vMathematical",
+ vocab: "vocab",
+ widths: "widths",
+ wordspacing: "wordSpacing",
+ "word-spacing": "wordSpacing",
+ writingmode: "writingMode",
+ "writing-mode": "writingMode",
+ x1: "x1",
+ x2: "x2",
+ x: "x",
+ xchannelselector: "xChannelSelector",
+ xheight: "xHeight",
+ "x-height": "xHeight",
+ xlinkactuate: "xlinkActuate",
+ "xlink:actuate": "xlinkActuate",
+ xlinkarcrole: "xlinkArcrole",
+ "xlink:arcrole": "xlinkArcrole",
+ xlinkhref: "xlinkHref",
+ "xlink:href": "xlinkHref",
+ xlinkrole: "xlinkRole",
+ "xlink:role": "xlinkRole",
+ xlinkshow: "xlinkShow",
+ "xlink:show": "xlinkShow",
+ xlinktitle: "xlinkTitle",
+ "xlink:title": "xlinkTitle",
+ xlinktype: "xlinkType",
+ "xlink:type": "xlinkType",
+ xmlbase: "xmlBase",
+ "xml:base": "xmlBase",
+ xmllang: "xmlLang",
+ "xml:lang": "xmlLang",
+ xmlns: "xmlns",
+ "xml:space": "xmlSpace",
+ xmlnsxlink: "xmlnsXlink",
+ "xmlns:xlink": "xmlnsXlink",
+ xmlspace: "xmlSpace",
+ y1: "y1",
+ y2: "y2",
+ y: "y",
+ ychannelselector: "yChannelSelector",
+ z: "z",
+ zoomandpan: "zoomAndPan",
+};
diff --git a/packages/sdk/src/core-metas.ts b/packages/sdk/src/core-metas.ts
index f779d0f50c..702f5101e9 100644
--- a/packages/sdk/src/core-metas.ts
+++ b/packages/sdk/src/core-metas.ts
@@ -4,6 +4,7 @@ import {
PaintBrushIcon,
SettingsIcon,
AddTemplateInstanceIcon,
+ HtmlElementIcon,
} from "@webstudio-is/icons/svg";
import { html } from "./__generated__/normalize.css";
import type {
@@ -26,6 +27,18 @@ const rootPropsMeta: WsComponentPropsMeta = {
props: {},
};
+export const elementComponent = "ws:element";
+
+const elementMeta: WsComponentMeta = {
+ type: "container",
+ label: "Element",
+ icon: HtmlElementIcon,
+};
+
+const elementPropsMeta: WsComponentPropsMeta = {
+ props: {},
+};
+
export const portalComponent = "Slot";
export const collectionComponent = "ws:collection";
@@ -129,6 +142,7 @@ const blockPropsMeta: WsComponentPropsMeta = {
export const coreMetas = {
[rootComponent]: rootMeta,
+ [elementComponent]: elementMeta,
[collectionComponent]: collectionMeta,
[descendantComponent]: descendantMeta,
[blockComponent]: blockMeta,
@@ -137,6 +151,7 @@ export const coreMetas = {
export const corePropsMetas = {
[rootComponent]: rootPropsMeta,
+ [elementComponent]: elementPropsMeta,
[collectionComponent]: collectionPropsMeta,
[descendantComponent]: descendantPropsMeta,
[blockComponent]: blockPropsMeta,
@@ -147,6 +162,7 @@ export const corePropsMetas = {
// should not be imported as react component
export const isCoreComponent = (component: string) =>
component === rootComponent ||
+ component === elementComponent ||
component === collectionComponent ||
component === descendantComponent ||
component === blockComponent ||
diff --git a/packages/template/src/jsx.test.tsx b/packages/template/src/jsx.test.tsx
index d48cbfd745..9916ec2a38 100644
--- a/packages/template/src/jsx.test.tsx
+++ b/packages/template/src/jsx.test.tsx
@@ -11,6 +11,7 @@ import {
renderTemplate,
ResourceValue,
Variable,
+ ws,
} from "./jsx";
import { css } from "./css";
@@ -593,3 +594,27 @@ test("render ws:tag property", () => {
]);
expect(props).toEqual([]);
});
+
+test("render ws:element with ws:tag prop", () => {
+ const { instances, props } = renderTemplate(
+ <$.Body ws:id="body">
+ <ws.element ws:tag="span"></ws.element>
+ </$.Body>
+ );
+ expect(instances).toEqual([
+ {
+ type: "instance",
+ id: "body",
+ component: "Body",
+ children: [{ type: "id", value: "0" }],
+ },
+ {
+ type: "instance",
+ id: "0",
+ component: "ws:element",
+ tag: "span",
+ children: [],
+ },
+ ]);
+ expect(props).toEqual([]);
+});