mirror of
https://github.com/webstudio-is/webstudio.git
synced 2025-03-14 09:57:02 +00:00
feat: Add title support to HeadSlot (#4758)
## Description Add Title to headSlot ## Steps for reproduction Add title <img width="847" alt="image" src="https://github.com/user-attachments/assets/d79f1659-b2cc-4b69-aedf-8989dccde118" /> Check it's shown and not duplicated. <img width="450" alt="image" src="https://github.com/user-attachments/assets/4222f3f8-57f2-43fa-bda4-64e3e70bd748" /> ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 0000) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@ -22,7 +22,7 @@ jobs:
|
||||
DATABASE_URL: postgres://
|
||||
AUTH_SECRET: test
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-24.04-arm
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -1,10 +1,10 @@
|
||||
{
|
||||
"build": {
|
||||
"id": "39af85c6-952a-42a5-953b-67718e2b95d7",
|
||||
"id": "0d43a990-f5cd-43c3-ab26-863ebe71eb27",
|
||||
"projectId": "cddc1d44-af37-4cb6-a430-d300cf6f932d",
|
||||
"version": 455,
|
||||
"createdAt": "2025-01-18T13:58:20.219+00:00",
|
||||
"updatedAt": "2025-01-18T13:58:20.219+00:00",
|
||||
"version": 463,
|
||||
"createdAt": "2025-01-18T19:56:10.675+00:00",
|
||||
"updatedAt": "2025-01-18T19:56:10.675+00:00",
|
||||
"pages": {
|
||||
"meta": {
|
||||
"siteName": "KittyGuardedZone",
|
||||
@ -2979,6 +2979,16 @@
|
||||
"type": "string",
|
||||
"value": "og:title"
|
||||
}
|
||||
],
|
||||
[
|
||||
"Eo5zG6ibHI2ueliryZsqN",
|
||||
{
|
||||
"id": "Eo5zG6ibHI2ueliryZsqN",
|
||||
"instanceId": "f0kF-WmL7DQg7MSyRvqY1",
|
||||
"name": "data-ws-show",
|
||||
"type": "boolean",
|
||||
"value": true
|
||||
}
|
||||
]
|
||||
],
|
||||
"dataSources": [
|
||||
@ -5011,6 +5021,10 @@
|
||||
"id": "Jdxu-0HI2f6Lq-LJwIOyY",
|
||||
"component": "HeadSlot",
|
||||
"children": [
|
||||
{
|
||||
"type": "id",
|
||||
"value": "4DTeDG3l8nX_C_oNtaHZQ"
|
||||
},
|
||||
{
|
||||
"type": "id",
|
||||
"value": "GFN6suio87WybEb7dc8IM"
|
||||
@ -5083,6 +5097,21 @@
|
||||
"label": "Meta",
|
||||
"children": []
|
||||
}
|
||||
],
|
||||
[
|
||||
"4DTeDG3l8nX_C_oNtaHZQ",
|
||||
{
|
||||
"type": "instance",
|
||||
"id": "4DTeDG3l8nX_C_oNtaHZQ",
|
||||
"component": "HeadTitle",
|
||||
"label": "Title",
|
||||
"children": [
|
||||
{
|
||||
"type": "text",
|
||||
"value": "Head Slot Title"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
"deployment": {
|
||||
|
@ -13,6 +13,7 @@ import {
|
||||
HeadLink as HeadLink,
|
||||
HeadMeta as HeadMeta,
|
||||
Heading as Heading,
|
||||
HeadTitle as HeadTitle,
|
||||
} from "@webstudio-is/sdk-components-react";
|
||||
|
||||
export const siteName = "KittyGuardedZone";
|
||||
@ -36,8 +37,9 @@ export const pageBackgroundImageAssets: ImageAsset[] = [];
|
||||
|
||||
const Page = ({}: { system: any }) => {
|
||||
return (
|
||||
<Body className={"w-body"}>
|
||||
<Body className={`w-body`}>
|
||||
<HeadSlot>
|
||||
<HeadTitle>{"Head Slot Title"}</HeadTitle>
|
||||
<HeadLink rel={"help"} href={"/help-head-slot"} />
|
||||
<HeadMeta name={"keywords"} content={"Head Slot Content"} />
|
||||
<HeadMeta
|
||||
@ -46,8 +48,8 @@ const Page = ({}: { system: any }) => {
|
||||
property={"og:title"}
|
||||
/>
|
||||
</HeadSlot>
|
||||
<Heading className={"w-heading"}>{"Test Head Slot"}</Heading>
|
||||
<Link href={"/"} className={"w-link"}>
|
||||
<Heading className={`w-heading`}>{"Test Head Slot"}</Heading>
|
||||
<Link href={"/"} className={`w-link`}>
|
||||
{"Go Home"}
|
||||
</Link>
|
||||
</Body>
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -6,7 +6,7 @@
|
||||
"typecheck": "tsc",
|
||||
"cli": "NODE_OPTIONS='--conditions=webstudio --import=tsx' webstudio",
|
||||
"fixtures:link": "pnpm cli link --link https://p-cddc1d44-af37-4cb6-a430-d300cf6f932d-dot-${BUILDER_HOST:-main.development.webstudio.is}'?authToken=1cdc6026-dd5b-4624-b89b-9bd45e9bcc3d'",
|
||||
"fixtures:sync": "pnpm cli sync --buildId 39af85c6-952a-42a5-953b-67718e2b95d7 && pnpm prettier --write ./.webstudio/",
|
||||
"fixtures:sync": "pnpm cli sync --buildId 0d43a990-f5cd-43c3-ab26-863ebe71eb27 && pnpm prettier --write ./.webstudio/",
|
||||
"fixtures:build": "pnpm cli build --template vercel --template internal --template ./.template && pnpm prettier --write ./app/ ./package.json ./tsconfig.json"
|
||||
},
|
||||
"private": true,
|
||||
|
@ -35,33 +35,45 @@ export const dedupeMeta: Plugin = {
|
||||
const response = new Response(body);
|
||||
|
||||
const metasSet = new Set<string>();
|
||||
let hasTitle = false;
|
||||
|
||||
const rewriter = new HTMLRewriter().on("meta", {
|
||||
element(element) {
|
||||
const propertyOrName =
|
||||
element.getAttribute("property") ||
|
||||
element.getAttribute("name");
|
||||
const rewriter = new HTMLRewriter()
|
||||
.on("meta", {
|
||||
element(element) {
|
||||
const propertyOrName =
|
||||
element.getAttribute("property") ||
|
||||
element.getAttribute("name");
|
||||
|
||||
if (propertyOrName === null) {
|
||||
return;
|
||||
}
|
||||
if (propertyOrName === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (propertyOrName === "viewport") {
|
||||
// Allow "viewport" property deduplication
|
||||
return;
|
||||
}
|
||||
if (propertyOrName === "viewport") {
|
||||
// Allow "viewport" property deduplication
|
||||
return;
|
||||
}
|
||||
|
||||
if (metasSet.has(propertyOrName)) {
|
||||
console.info(
|
||||
`Duplicate meta with name|property = ${propertyOrName} removed`
|
||||
);
|
||||
element.remove();
|
||||
return;
|
||||
}
|
||||
if (metasSet.has(propertyOrName)) {
|
||||
console.info(
|
||||
`Duplicate meta with name|property = ${propertyOrName} removed`
|
||||
);
|
||||
element.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
metasSet.add(propertyOrName);
|
||||
},
|
||||
});
|
||||
metasSet.add(propertyOrName);
|
||||
},
|
||||
})
|
||||
.on("title", {
|
||||
element(element) {
|
||||
if (hasTitle) {
|
||||
element.remove();
|
||||
return;
|
||||
}
|
||||
|
||||
hasTitle = true;
|
||||
},
|
||||
});
|
||||
rewriter
|
||||
// @ts-ignore
|
||||
.transform(response)
|
||||
|
@ -19,6 +19,7 @@ import {
|
||||
import {
|
||||
ReactSdkContext,
|
||||
PageSettingsMeta,
|
||||
PageSettingsTitle,
|
||||
} from "@webstudio-is/react-sdk/runtime";
|
||||
import {
|
||||
Page,
|
||||
@ -121,13 +122,8 @@ export const meta: MetaFunction<typeof loader> = ({ data }) => {
|
||||
return metas;
|
||||
}
|
||||
|
||||
const { pageMeta } = data;
|
||||
const origin = `https://${data.host}`;
|
||||
|
||||
if (pageMeta.title) {
|
||||
metas.push({ title: pageMeta.title });
|
||||
}
|
||||
|
||||
if (siteName) {
|
||||
metas.push({
|
||||
"script:ld+json": {
|
||||
@ -291,6 +287,7 @@ const Outlet = () => {
|
||||
siteName={siteName}
|
||||
imageLoader={imageLoader}
|
||||
/>
|
||||
<PageSettingsTitle>{pageMeta.title}</PageSettingsTitle>
|
||||
</ReactSdkContext.Provider>
|
||||
);
|
||||
};
|
||||
|
@ -9,7 +9,7 @@ type MetaProps = {
|
||||
};
|
||||
|
||||
// Not documented
|
||||
const isElementRenderedWithReact = (element: Element) => {
|
||||
export const isElementRenderedWithReact = (element: Element) => {
|
||||
return Object.keys(element).some((key) => key.startsWith("__react"));
|
||||
};
|
||||
|
||||
|
55
packages/react-sdk/src/page-settings-title.tsx
Normal file
55
packages/react-sdk/src/page-settings-title.tsx
Normal file
@ -0,0 +1,55 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { isElementRenderedWithReact } from "./page-settings-meta";
|
||||
|
||||
type PageSettingsTitleProps = {
|
||||
children: string;
|
||||
};
|
||||
|
||||
const isServer = typeof window === "undefined";
|
||||
|
||||
/**
|
||||
* Title tags are deduplicated on the server using the HTMLRewriter interface.
|
||||
* This is not full deduplication. We simply skip rendering Page Setting title
|
||||
* if it has already been rendered using HeadSlot/HeadTitle.
|
||||
* To prevent React on the client from re-adding the removed title tag, we skip rendering them client-side.
|
||||
* This approach works because React retains server-rendered title tag as long as they are not re-rendered by the client.
|
||||
*
|
||||
* The following component behavior ensures this:
|
||||
* 1. On the server: Render title tag as usual.
|
||||
* 2. On the client: Before rendering, remove any title tag with the same `name` or `property` that were not rendered by Client React,
|
||||
* and then proceed with rendering as usual.
|
||||
*/
|
||||
export const PageSettingsTitle = (props: PageSettingsTitleProps) => {
|
||||
const [localProps, setLocalProps] = useState<
|
||||
PageSettingsTitleProps | undefined
|
||||
>();
|
||||
|
||||
useEffect(() => {
|
||||
const selector = `head > title`;
|
||||
let allTitles = document.querySelectorAll(selector);
|
||||
|
||||
for (const meta of allTitles) {
|
||||
if (!isElementRenderedWithReact(meta)) {
|
||||
meta.remove();
|
||||
}
|
||||
}
|
||||
|
||||
allTitles = document.querySelectorAll(selector);
|
||||
|
||||
if (allTitles.length === 0) {
|
||||
setLocalProps(props);
|
||||
}
|
||||
}, [props]);
|
||||
|
||||
if (isServer) {
|
||||
return <title {...props} />;
|
||||
}
|
||||
|
||||
if (localProps === undefined) {
|
||||
// This method also works during hydration because React retains server-rendered tags
|
||||
// as long as they are not re-rendered by the client.
|
||||
return;
|
||||
}
|
||||
|
||||
return <title {...localProps} />;
|
||||
};
|
@ -1,7 +1,8 @@
|
||||
export * from "./context";
|
||||
export * from "./hook";
|
||||
export * from "./variable-state";
|
||||
export * from "./page-settings-meta";
|
||||
export { PageSettingsMeta } from "./page-settings-meta";
|
||||
export { PageSettingsTitle } from "./page-settings-title";
|
||||
|
||||
/**
|
||||
* React has issues rendering certain elements, such as errors when a <link> element has children.
|
||||
|
562
packages/sdk-components-react/src/__generated__/head-title.props.ts
generated
Normal file
562
packages/sdk-components-react/src/__generated__/head-title.props.ts
generated
Normal file
@ -0,0 +1,562 @@
|
||||
import type { PropMeta } from "@webstudio-is/sdk";
|
||||
|
||||
export const props: Record<string, PropMeta> = {
|
||||
about: { required: false, control: "text", type: "string" },
|
||||
accessKey: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description: "Keyboard shortcut to activate or add focus to the element.",
|
||||
},
|
||||
"aria-activedescendant": {
|
||||
description:
|
||||
"Identifies the currently active element when DOM focus is on a composite widget, textbox, group, or application.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-atomic": {
|
||||
description:
|
||||
"Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-autocomplete": {
|
||||
description:
|
||||
"Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for an input and specifies how predictions would be\npresented if they are made.",
|
||||
required: false,
|
||||
control: "select",
|
||||
type: "string",
|
||||
options: ["list", "none", "inline", "both"],
|
||||
},
|
||||
"aria-braillelabel": {
|
||||
description:
|
||||
"Defines a string value that labels the current element, which is intended to be converted into Braille.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-brailleroledescription": {
|
||||
description:
|
||||
"Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-busy": { required: false, control: "boolean", type: "boolean" },
|
||||
"aria-checked": {
|
||||
description:
|
||||
'Indicates the current "checked" state of checkboxes, radio buttons, and other widgets.',
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-colcount": {
|
||||
description:
|
||||
"Defines the total number of columns in a table, grid, or treegrid.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-colindex": {
|
||||
description:
|
||||
"Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-colindextext": {
|
||||
description: "Defines a human readable text alternative of aria-colindex.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-colspan": {
|
||||
description:
|
||||
"Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-controls": {
|
||||
description:
|
||||
"Identifies the element (or elements) whose contents or presence are controlled by the current element.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-current": {
|
||||
description:
|
||||
"Indicates the element that represents the current item within a container or set of related elements.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-describedby": {
|
||||
description:
|
||||
"Identifies the element (or elements) that describes the object.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-description": {
|
||||
description:
|
||||
"Defines a string value that describes or annotates the current element.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-details": {
|
||||
description:
|
||||
"Identifies the element that provides a detailed, extended description for the object.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-disabled": {
|
||||
description:
|
||||
"Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-dropeffect": {
|
||||
description:
|
||||
"Indicates what functions can be performed when a dragged object is released on the drop target.",
|
||||
required: false,
|
||||
control: "select",
|
||||
type: "string",
|
||||
options: ["link", "none", "copy", "execute", "move", "popup"],
|
||||
},
|
||||
"aria-errormessage": {
|
||||
description:
|
||||
"Identifies the element that provides an error message for the object.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-expanded": {
|
||||
description:
|
||||
"Indicates whether the element, or another grouping element it controls, is currently expanded or collapsed.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-flowto": {
|
||||
description:
|
||||
"Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion,\nallows assistive technology to override the general default of reading in document source order.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-grabbed": {
|
||||
description:
|
||||
'Indicates an element\'s "grabbed" state in a drag-and-drop operation.',
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-haspopup": {
|
||||
description:
|
||||
"Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-hidden": {
|
||||
description:
|
||||
"Indicates whether the element is exposed to an accessibility API.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-invalid": {
|
||||
description:
|
||||
"Indicates the entered value does not conform to the format expected by the application.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-keyshortcuts": {
|
||||
description:
|
||||
"Indicates keyboard shortcuts that an author has implemented to activate or give focus to an element.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-label": {
|
||||
description:
|
||||
"Provides the accessible name that describes an interactive element if no other accessible name exists, for example in a button that contains an image with no text.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-labelledby": {
|
||||
description:
|
||||
"Identifies the element (or elements) that labels the current element.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-level": {
|
||||
description:
|
||||
"Defines the hierarchical level of an element within a structure.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-live": {
|
||||
description:
|
||||
"Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.",
|
||||
required: false,
|
||||
control: "radio",
|
||||
type: "string",
|
||||
options: ["off", "assertive", "polite"],
|
||||
},
|
||||
"aria-modal": {
|
||||
description: "Indicates whether an element is modal when displayed.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-multiline": {
|
||||
description:
|
||||
"Indicates whether a text box accepts multiple lines of input or only a single line.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-multiselectable": {
|
||||
description:
|
||||
"Indicates that the user may select more than one item from the current selectable descendants.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-orientation": {
|
||||
description:
|
||||
"Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.",
|
||||
required: false,
|
||||
control: "radio",
|
||||
type: "string",
|
||||
options: ["horizontal", "vertical"],
|
||||
},
|
||||
"aria-owns": {
|
||||
description:
|
||||
"Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship\nbetween DOM elements where the DOM hierarchy cannot be used to represent the relationship.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-placeholder": {
|
||||
description:
|
||||
"Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value.\nA hint could be a sample value or a brief description of the expected format.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-posinset": {
|
||||
description:
|
||||
"Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-pressed": {
|
||||
description: 'Indicates the current "pressed" state of toggle buttons.',
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-readonly": {
|
||||
description:
|
||||
"Indicates that the element is not editable, but is otherwise operable.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-relevant": {
|
||||
description:
|
||||
"Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified.",
|
||||
required: false,
|
||||
control: "select",
|
||||
type: "string",
|
||||
options: [
|
||||
"text",
|
||||
"additions",
|
||||
"additions removals",
|
||||
"additions text",
|
||||
"all",
|
||||
"removals",
|
||||
"removals additions",
|
||||
"removals text",
|
||||
"text additions",
|
||||
"text removals",
|
||||
],
|
||||
},
|
||||
"aria-required": {
|
||||
description:
|
||||
"Indicates that user input is required on the element before a form may be submitted.",
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-roledescription": {
|
||||
description:
|
||||
"Defines a human-readable, author-localized description for the role of an element.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-rowcount": {
|
||||
description:
|
||||
"Defines the total number of rows in a table, grid, or treegrid.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-rowindex": {
|
||||
description:
|
||||
"Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-rowindextext": {
|
||||
description: "Defines a human readable text alternative of aria-rowindex.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
"aria-rowspan": {
|
||||
description:
|
||||
"Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-selected": {
|
||||
description: 'Indicates the current "selected" state of various widgets.',
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
"aria-setsize": {
|
||||
description:
|
||||
"Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-sort": {
|
||||
description:
|
||||
"Indicates if items in a table or grid are sorted in ascending or descending order.",
|
||||
required: false,
|
||||
control: "select",
|
||||
type: "string",
|
||||
options: ["none", "ascending", "descending", "other"],
|
||||
},
|
||||
"aria-valuemax": {
|
||||
description: "Defines the maximum allowed value for a range widget.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-valuemin": {
|
||||
description: "Defines the minimum allowed value for a range widget.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-valuenow": {
|
||||
description: "Defines the current value for a range widget.",
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
},
|
||||
"aria-valuetext": {
|
||||
description:
|
||||
"Defines the human readable text alternative of aria-valuenow for a range widget.",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
autoCapitalize: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Sets whether input is automatically capitalized when entered by user.",
|
||||
},
|
||||
autoCorrect: { required: false, control: "text", type: "string" },
|
||||
autoFocus: {
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
description:
|
||||
"Indicates that an element should be focused on page load, or when its parent dialog is displayed.",
|
||||
},
|
||||
autoSave: { required: false, control: "text", type: "string" },
|
||||
className: { required: false, control: "text", type: "string" },
|
||||
color: {
|
||||
required: false,
|
||||
control: "color",
|
||||
type: "string",
|
||||
description:
|
||||
"This attribute sets the text color using either a named color or a color specified in the hexadecimal #RRGGBB format. Note: This is a legacy attribute. Please use the CSS color property instead.",
|
||||
},
|
||||
content: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"A value associated with http-equiv orname depending on the context.",
|
||||
},
|
||||
contextMenu: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Defines the ID of a menu element which willserve as the element's context menu.",
|
||||
},
|
||||
datatype: { required: false, control: "text", type: "string" },
|
||||
defaultChecked: { required: false, control: "boolean", type: "boolean" },
|
||||
defaultValue: { required: false, control: "text", type: "string" },
|
||||
dir: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Defines the text direction. Allowed values are ltr (Left-To-Right) or rtl (Right-To-Left)",
|
||||
},
|
||||
draggable: {
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
description: "Defines whether the element can be dragged.",
|
||||
},
|
||||
hidden: {
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
description:
|
||||
"Prevents rendering of given element, while keeping child elements, e.g. script elements, active.",
|
||||
},
|
||||
id: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Often used with CSS to style a specific element. The value of this attribute must be unique.",
|
||||
},
|
||||
inputMode: {
|
||||
description:
|
||||
"Hints at the type of data that might be entered by the user while editing the element or its contents",
|
||||
required: false,
|
||||
control: "select",
|
||||
type: "string",
|
||||
options: [
|
||||
"search",
|
||||
"text",
|
||||
"none",
|
||||
"tel",
|
||||
"url",
|
||||
"email",
|
||||
"numeric",
|
||||
"decimal",
|
||||
],
|
||||
},
|
||||
is: {
|
||||
description:
|
||||
"Specify that a standard HTML element should behave like a defined custom built-in element",
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
},
|
||||
itemID: { required: false, control: "text", type: "string" },
|
||||
itemProp: { required: false, control: "text", type: "string" },
|
||||
itemRef: { required: false, control: "text", type: "string" },
|
||||
itemScope: { required: false, control: "boolean", type: "boolean" },
|
||||
itemType: { required: false, control: "text", type: "string" },
|
||||
lang: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description: "Defines the language used in the element.",
|
||||
},
|
||||
nonce: { required: false, control: "text", type: "string" },
|
||||
prefix: { required: false, control: "text", type: "string" },
|
||||
property: { required: false, control: "text", type: "string" },
|
||||
radioGroup: { required: false, control: "text", type: "string" },
|
||||
rel: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Specifies the relationship of the target object to the link object.",
|
||||
},
|
||||
resource: { required: false, control: "text", type: "string" },
|
||||
results: { required: false, control: "number", type: "number" },
|
||||
rev: { required: false, control: "text", type: "string" },
|
||||
role: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Defines an explicit role for an element for use by assistive technologies.",
|
||||
},
|
||||
security: { required: false, control: "text", type: "string" },
|
||||
slot: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description: "Assigns a slot in a shadow DOM shadow tree to an element.",
|
||||
},
|
||||
spellCheck: {
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
description: "Indicates whether spell checking is allowed for the element.",
|
||||
},
|
||||
suppressContentEditableWarning: {
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
suppressHydrationWarning: {
|
||||
required: false,
|
||||
control: "boolean",
|
||||
type: "boolean",
|
||||
},
|
||||
tabIndex: {
|
||||
required: false,
|
||||
control: "number",
|
||||
type: "number",
|
||||
description:
|
||||
"Overrides the browser's default tab order and follows the one specified instead.",
|
||||
},
|
||||
title: {
|
||||
required: false,
|
||||
control: "text",
|
||||
type: "string",
|
||||
description:
|
||||
"Text to be displayed in a tooltip when hovering over the element.",
|
||||
},
|
||||
translate: {
|
||||
required: false,
|
||||
control: "radio",
|
||||
type: "string",
|
||||
options: ["yes", "no"],
|
||||
description:
|
||||
"Specify whether an element's attribute values and the values of its text node children are to be translated when the page is localized, or whether to leave them unchanged.",
|
||||
},
|
||||
typeof: { required: false, control: "text", type: "string" },
|
||||
unselectable: {
|
||||
required: false,
|
||||
control: "radio",
|
||||
type: "string",
|
||||
options: ["on", "off"],
|
||||
},
|
||||
vocab: { required: false, control: "text", type: "string" },
|
||||
};
|
@ -41,3 +41,4 @@ export { Option } from "./option";
|
||||
export { HeadSlot } from "./head-slot";
|
||||
export { HeadLink } from "./head-link";
|
||||
export { HeadMeta } from "./head-meta";
|
||||
export { HeadTitle } from "./head-title";
|
||||
|
@ -6,6 +6,7 @@ export const meta: TemplateMeta = {
|
||||
order: 4,
|
||||
template: (
|
||||
<$.HeadSlot>
|
||||
<$.HeadTitle ws:label="Title">Title</$.HeadTitle>
|
||||
<$.HeadLink ws:label="Link" rel="help" href="/help"></$.HeadLink>
|
||||
<$.HeadMeta ws:label="Meta" name="keywords" content="SEO"></$.HeadMeta>
|
||||
</$.HeadSlot>
|
||||
|
@ -18,7 +18,7 @@ export const meta: WsComponentMeta = {
|
||||
},
|
||||
{
|
||||
relation: "child",
|
||||
component: { $in: ["HeadLink", "HeadMeta"] },
|
||||
component: { $in: ["HeadLink", "HeadMeta", "HeadTitle"] },
|
||||
},
|
||||
],
|
||||
};
|
||||
|
49
packages/sdk-components-react/src/head-title.tsx
Normal file
49
packages/sdk-components-react/src/head-title.tsx
Normal file
@ -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 = "title";
|
||||
|
||||
const PROPS_ORDER = [] as const;
|
||||
|
||||
export const HeadTitle = forwardRef<
|
||||
ElementRef<"div">,
|
||||
ComponentProps<typeof defaultTag>
|
||||
>(({ ...props }, ref) => {
|
||||
const { renderer } = useContext(ReactSdkContext);
|
||||
|
||||
const propsSet = new Set([...PROPS_ORDER, ...Object.keys(props)]) as Set<
|
||||
keyof typeof props
|
||||
>;
|
||||
|
||||
const cleanOrderedProps: Record<string, unknown> = {};
|
||||
|
||||
for (const prop of propsSet) {
|
||||
// Boolean check is not a mistake; it excludes empty values.
|
||||
// Empty properties must be excluded because there is no UI to reset them to undefined.
|
||||
if (prop in props && Boolean(props[prop])) {
|
||||
cleanOrderedProps[prop] = props[prop];
|
||||
}
|
||||
}
|
||||
|
||||
if (renderer === undefined) {
|
||||
return <title {...cleanOrderedProps} />;
|
||||
}
|
||||
|
||||
// HTML attributes are case-insensitive, but the convention is to use lowercase
|
||||
const htmlAttributes = Object.fromEntries(
|
||||
Object.entries(cleanOrderedProps).map(([key, value]) => [
|
||||
key?.toLowerCase(),
|
||||
value,
|
||||
])
|
||||
);
|
||||
|
||||
return <XmlNode tag={defaultTag} {...htmlAttributes} ref={ref} />;
|
||||
});
|
||||
|
||||
HeadTitle.displayName = "HeadTitle";
|
22
packages/sdk-components-react/src/head-title.ws.ts
Normal file
22
packages/sdk-components-react/src/head-title.ws.ts
Normal file
@ -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-title.props";
|
||||
|
||||
export const meta: WsComponentMeta = {
|
||||
category: "hidden",
|
||||
icon: Link2Icon,
|
||||
type: "container",
|
||||
stylable: false,
|
||||
constraints: {
|
||||
relation: "parent",
|
||||
component: { $eq: "HeadSlot" },
|
||||
},
|
||||
};
|
||||
|
||||
export const propsMeta: WsComponentPropsMeta = {
|
||||
props,
|
||||
};
|
@ -41,3 +41,4 @@ export { meta as Option } from "./option.ws";
|
||||
export { meta as HeadSlot } from "./head-slot.ws";
|
||||
export { meta as HeadLink } from "./head-link.ws";
|
||||
export { meta as HeadMeta } from "./head-meta.ws";
|
||||
export { meta as HeadTitle } from "./head-title.ws";
|
||||
|
@ -41,3 +41,4 @@ export { propsMeta as Option } from "./option.ws";
|
||||
export { propsMeta as HeadSlot } from "./head-slot.ws";
|
||||
export { propsMeta as HeadLink } from "./head-link.ws";
|
||||
export { propsMeta as HeadMeta } from "./head-meta.ws";
|
||||
export { propsMeta as HeadTitle } from "./head-title.ws";
|
||||
|
Reference in New Issue
Block a user