Skip to content

Commit 4a3cb85

Browse files
committed
feat: add "Calls Function On Click" attribute
1 parent b352a35 commit 4a3cb85

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

apps/builder/app/canvas/canvas.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { useMemo, useEffect, useState, useLayoutEffect, useRef } from "react";
22
import { ErrorBoundary, type FallbackProps } from "react-error-boundary";
33
import { useStore } from "@nanostores/react";
4-
import { type Instances, coreMetas, corePropsMetas } from "@webstudio-is/sdk";
4+
import {
5+
type Instances,
6+
PropMeta,
7+
coreMetas,
8+
corePropsMetas,
9+
} from "@webstudio-is/sdk";
510
import { coreTemplates } from "@webstudio-is/sdk/core-templates";
611
import type { Components } from "@webstudio-is/react-sdk";
712
import { wsImageLoader } from "@webstudio-is/image";
@@ -239,16 +244,31 @@ export const Canvas = () => {
239244
propsMetas: Object.fromEntries(
240245
Object.entries(baseComponentPropsMetas).map(
241246
([component, propsMeta]) => {
242-
propsMeta.props.comment = {
243-
type: "string",
244-
control: "text",
245-
required: false,
246-
description:
247-
"Describe the behavior of this layer and optionally its children.",
248-
maxRows: 20,
247+
const globalProps: Record<string, PropMeta> = {
248+
comment: {
249+
type: "string",
250+
control: "text",
251+
required: false,
252+
description:
253+
"Describe the behavior of this layer and optionally its children.",
254+
maxRows: 20,
255+
},
256+
callsFunctionOnClick: {
257+
type: "boolean",
258+
control: "boolean",
259+
required: false,
260+
description:
261+
"When true, this layer calls a component prop when clicked.",
262+
},
249263
};
250-
propsMeta.initialProps ??= [];
251-
propsMeta.initialProps.push("comment");
264+
265+
Object.assign(propsMeta.props, globalProps);
266+
267+
const initialProps = (propsMeta.initialProps ??= []);
268+
Object.keys(globalProps).forEach((key) => {
269+
initialProps.push(key);
270+
});
271+
252272
return [component, propsMeta];
253273
}
254274
)

0 commit comments

Comments
 (0)