-
Notifications
You must be signed in to change notification settings - Fork 838
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
1,397 additions
and
1 deletion.
There are no files selected for viewing
658 changes: 658 additions & 0 deletions
658
packages/sdk-components-react/src/__generated__/head-link.props.ts
Large diffs are not rendered by default.
Oops, something went wrong.
562 changes: 562 additions & 0 deletions
562
packages/sdk-components-react/src/__generated__/head.props.ts
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; | ||
import { | ||
forwardRef, | ||
type ElementRef, | ||
type ComponentProps, | ||
useContext, | ||
} from "react"; | ||
import { XmlNode } from "./xml-node"; | ||
|
||
export const defaultTag = "link"; | ||
|
||
type LinkRel = | ||
| "alternate" | ||
| "author" | ||
| "canonical" | ||
| "dns-prefetch" | ||
| "help" | ||
| "icon" | ||
| "license" | ||
| "manifest" | ||
| "modulepreload" | ||
| "next" | ||
| "nofollow" | ||
| "noopener" | ||
| "noreferrer" | ||
| "opener" | ||
| "pingback" | ||
| "preconnect" | ||
| "prefetch" | ||
| "preload" | ||
| "prev" | ||
| "search" | ||
| "stylesheet" | ||
| "tag"; | ||
|
||
export const HeadLink = forwardRef< | ||
ElementRef<"div">, | ||
{ rel: LinkRel } & ComponentProps<typeof defaultTag> | ||
>(({ ...props }, ref) => { | ||
const { renderer } = useContext(ReactSdkContext); | ||
|
||
if (renderer === undefined) { | ||
return <link {...props} />; | ||
} | ||
|
||
return <XmlNode tag={defaultTag} {...props} ref={ref} />; | ||
}); | ||
|
||
HeadLink.displayName = "HeadLink"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Link2Icon } from "@webstudio-is/icons/svg"; | ||
import { | ||
type WsComponentMeta, | ||
type WsComponentPropsMeta, | ||
} from "@webstudio-is/sdk"; | ||
|
||
import { props } from "./__generated__/head-link.props"; | ||
|
||
export const meta: WsComponentMeta = { | ||
category: "hidden", | ||
icon: Link2Icon, | ||
type: "container", | ||
constraints: { | ||
relation: "parent", | ||
component: { $eq: "Head" }, | ||
}, | ||
}; | ||
|
||
export const propsMeta: WsComponentPropsMeta = { | ||
props, | ||
initialProps: ["rel", "href", "type", "hreflang"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { type TemplateMeta, $ } from "@webstudio-is/template"; | ||
|
||
export const meta: TemplateMeta = { | ||
category: "general", | ||
description: "Head", | ||
order: 4, | ||
template: ( | ||
<$.Head> | ||
<$.HeadLink rel="help" href="/help"></$.HeadLink> | ||
</$.Head> | ||
), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { | ||
getClosestInstance, | ||
ReactSdkContext, | ||
type Hook, | ||
} from "@webstudio-is/react-sdk/runtime"; | ||
import { | ||
forwardRef, | ||
type ElementRef, | ||
type ComponentProps, | ||
useContext, | ||
} from "react"; | ||
import { XmlNode } from "./xml-node"; | ||
|
||
export const defaultTag = "head"; | ||
|
||
export const Head = forwardRef< | ||
ElementRef<"div">, | ||
{ "data-ws-expand": boolean } & ComponentProps<typeof defaultTag> | ||
>(({ ...props }, ref) => { | ||
const { renderer } = useContext(ReactSdkContext); | ||
|
||
if (props["data-ws-expand"] !== true) { | ||
return null; | ||
} | ||
|
||
if (renderer === undefined) { | ||
return props.children; | ||
} | ||
|
||
return <XmlNode tag={defaultTag} {...props} ref={ref} />; | ||
}); | ||
|
||
Head.displayName = "Head"; | ||
|
||
export const hooksHead: Hook = { | ||
onNavigatorUnselect: (context, event) => { | ||
for (const instance of event.instancePath) { | ||
if (instance.component === `Head`) { | ||
const popover = getClosestInstance( | ||
event.instancePath, | ||
instance, | ||
`Head` | ||
); | ||
if (popover) { | ||
context.setMemoryProp(popover, "data-ws-expand", undefined); | ||
} | ||
} | ||
} | ||
}, | ||
onNavigatorSelect: (context, event) => { | ||
for (const instance of event.instancePath) { | ||
if (instance.component === `Head`) { | ||
const popover = getClosestInstance( | ||
event.instancePath, | ||
instance, | ||
`Head` | ||
); | ||
if (popover) { | ||
context.setMemoryProp(popover, "data-ws-expand", true); | ||
} | ||
} | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { HeaderIcon } from "@webstudio-is/icons/svg"; | ||
import { | ||
type WsComponentMeta, | ||
type WsComponentPropsMeta, | ||
} from "@webstudio-is/sdk"; | ||
|
||
import { props } from "./__generated__/head.props"; | ||
|
||
export const meta: WsComponentMeta = { | ||
icon: HeaderIcon, | ||
type: "container", | ||
constraints: { | ||
relation: "ancestor", | ||
component: { $nin: ["Head"] }, | ||
}, | ||
}; | ||
|
||
export const propsMeta: WsComponentPropsMeta = { | ||
props, | ||
initialProps: [], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import type { Hook } from "@webstudio-is/react-sdk"; | ||
import { hooksSelect } from "./select"; | ||
import { hooksHead } from "./head"; | ||
|
||
export const hooks: Hook[] = [hooksSelect]; | ||
export const hooks: Hook[] = [hooksSelect, hooksHead]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters