webstudio 0.128.0 → 0.130.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cli.js CHANGED
@@ -260,14 +260,16 @@ import merge from "deepmerge";
260
260
  import {
261
261
  generateCss,
262
262
  generateUtilsExport,
263
- generatePageComponent,
263
+ generateWebstudioComponent,
264
264
  getIndexesWithinAncestors,
265
265
  namespaceMeta,
266
266
  normalizeProps,
267
267
  generateRemixRoute,
268
268
  generateRemixParams,
269
269
  generateResourcesLoader,
270
- collectionComponent
270
+ collectionComponent,
271
+ generatePageMeta,
272
+ executeExpression
271
273
  } from "@webstudio-is/react-sdk";
272
274
  import {
273
275
  createScope,
@@ -334,18 +336,22 @@ var isCliTemplate = async (template) => {
334
336
  }
335
337
  return false;
336
338
  };
337
- var copyTemplates = async (template = "defaults") => {
339
+ var getTemplatePath = async (template) => {
338
340
  const currentPath = fileURLToPath(new URL(import.meta.url));
339
- const templatesPath = await isCliTemplate(template) ? normalize(join4(dirname2(currentPath), "..", "templates", template)) : template;
340
- await cp(templatesPath, cwd3(), {
341
+ const templatePath = await isCliTemplate(template) ? normalize(join4(dirname2(currentPath), "..", "templates", template)) : template;
342
+ return templatePath;
343
+ };
344
+ var copyTemplates = async (template = "defaults") => {
345
+ const templatePath = await getTemplatePath(template);
346
+ await cp(templatePath, cwd3(), {
341
347
  recursive: true,
342
348
  filter: (source) => {
343
349
  return basename(source) !== "package.json";
344
350
  }
345
351
  });
346
- if (await isFileExists(join4(templatesPath, "package.json")) === true) {
352
+ if (await isFileExists(join4(templatePath, "package.json")) === true) {
347
353
  await mergeJsonFiles(
348
- join4(templatesPath, "package.json"),
354
+ join4(templatePath, "package.json"),
349
355
  join4(cwd3(), "package.json")
350
356
  );
351
357
  }
@@ -521,28 +527,24 @@ var prebuild = async (options) => {
521
527
  },
522
528
  {
523
529
  assetBaseUrl,
524
- atomic: siteData.build.pages.settings?.atomicStyles ?? true
530
+ atomic: siteData.build.pages.compiler?.atomicStyles ?? true
525
531
  }
526
532
  );
527
533
  await ensureFileInPath(join4(generatedDir, "index.css"), cssText);
528
534
  spinner.text = "Generating routes and pages";
529
- const routeFileTemplate = await readFile4(
530
- normalize(
531
- join4(
532
- dirname2(fileURLToPath(new URL(import.meta.url))),
533
- "..",
534
- "templates",
535
- "route-template.tsx"
536
- )
537
- ),
538
- "utf8"
535
+ const routeTemplatePath = normalize(
536
+ join4(cwd3(), "__templates__", "route-template.tsx")
539
537
  );
538
+ const routeFileTemplate = await readFile4(routeTemplatePath, "utf8");
539
+ await rm(dirname2(routeTemplatePath), { recursive: true });
540
540
  for (const [pageId, pageComponents] of Object.entries(componentsByPage)) {
541
541
  const scope = createScope([
542
542
  // manually maintained list of occupied identifiers
543
543
  "useState",
544
544
  "Fragment",
545
545
  "useResource",
546
+ "PageMeta",
547
+ "createPageMeta",
546
548
  "PageData",
547
549
  "Asset",
548
550
  "fontAssets",
@@ -585,8 +587,7 @@ var prebuild = async (options) => {
585
587
  }
586
588
  const pageData = siteDataByPage[pageId];
587
589
  const renderedPageData = {
588
- project: siteData.build.pages.meta,
589
- page: pageData.page
590
+ project: siteData.build.pages.meta
590
591
  };
591
592
  const rootInstanceId = pageData.page.rootInstanceId;
592
593
  const instances = new Map(pageData.build.instances);
@@ -597,9 +598,27 @@ var prebuild = async (options) => {
597
598
  pages: siteData.build.pages,
598
599
  props
599
600
  });
600
- const pageComponent = generatePageComponent({
601
+ const pathVariableId = pageData.page.pathVariableId ?? "pathVariableId";
602
+ if (pageData.page.pathVariableId === void 0) {
603
+ dataSources.set(pathVariableId, {
604
+ id: pathVariableId,
605
+ name: "Page Params",
606
+ type: "parameter"
607
+ });
608
+ }
609
+ const pageComponent = generateWebstudioComponent({
601
610
  scope,
602
- page: pageData.page,
611
+ name: "Page",
612
+ rootInstanceId: pageData.page.rootInstanceId,
613
+ parameters: [
614
+ {
615
+ id: `params`,
616
+ instanceId: "",
617
+ name: "params",
618
+ type: "parameter",
619
+ value: pathVariableId
620
+ }
621
+ ],
603
622
  instances,
604
623
  props,
605
624
  dataSources,
@@ -616,6 +635,7 @@ var prebuild = async (options) => {
616
635
  import { Fragment, useState } from "react";
617
636
  import type { Asset, ImageAsset, ProjectMeta } from "@webstudio-is/sdk";
618
637
  import { useResource } from "@webstudio-is/react-sdk";
638
+ import type { PageMeta } from "@webstudio-is/react-sdk";
619
639
  ${componentImports}
620
640
  import type { PageData } from "~/routes/_index";
621
641
  export const fontAssets: Asset[] = ${JSON.stringify(fontAssets)}
@@ -626,6 +646,8 @@ export const user: { email: string | null } | undefined = ${JSON.stringify(
626
646
  )};
627
647
  export const projectId = "${siteData.build.projectId}";
628
648
 
649
+ ${generatePageMeta({ scope, page: pageData.page, dataSources })}
650
+
629
651
  ${pageComponent}
630
652
 
631
653
  export { Page }
@@ -637,9 +659,12 @@ ${utilsExport}
637
659
  const path = getPagePath(pageData.page.id, siteData.build.pages);
638
660
  const remixRoute = generateRemixRoute(path);
639
661
  const fileName = `${remixRoute}.tsx`;
640
- const routeFileContent = routeFileTemplate.replace('../__generated__/index"', `../__generated__/${remixRoute}"`).replace(
641
- '../__generated__/index.server"',
642
- `../__generated__/${remixRoute}.server"`
662
+ const routeFileContent = routeFileTemplate.replace(
663
+ /".*\/__generated__\/_index"/,
664
+ `"../__generated__/${remixRoute}"`
665
+ ).replace(
666
+ /".*\/__generated__\/_index.server"/,
667
+ `"../__generated__/${remixRoute}.server"`
643
668
  );
644
669
  await ensureFileInPath(join4(routesDir, fileName), routeFileContent);
645
670
  await ensureFileInPath(join4(generatedDir, fileName), pageExports);
@@ -658,7 +683,9 @@ ${utilsExport}
658
683
  `
659
684
  export const sitemap = ${JSON.stringify(
660
685
  {
661
- pages: siteData.pages.filter((page) => page.meta.excludePageFromSearch !== true).map((page) => ({
686
+ pages: siteData.pages.filter(
687
+ (page) => executeExpression(page.meta.excludePageFromSearch) !== true
688
+ ).map((page) => ({
662
689
  path: page.path,
663
690
  lastModified: siteData.build.updatedAt
664
691
  }))
@@ -841,7 +868,7 @@ import makeCLI from "yargs";
841
868
  // package.json
842
869
  var package_default = {
843
870
  name: "webstudio",
844
- version: "0.128.0",
871
+ version: "0.130.0",
845
872
  description: "Webstudio CLI",
846
873
  author: "Webstudio <github@webstudio.is>",
847
874
  homepage: "https://webstudio.is",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webstudio",
3
- "version": "0.128.0",
3
+ "version": "0.130.0",
4
4
  "description": "Webstudio CLI",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -28,21 +28,21 @@
28
28
  "title-case": "^4.1.0",
29
29
  "yargs": "^17.7.2",
30
30
  "zod": "^3.21.4",
31
- "@webstudio-is/http-client": "0.128.0",
32
- "@webstudio-is/react-sdk": "0.128.0",
33
- "@webstudio-is/image": "0.128.0",
34
- "@webstudio-is/sdk": "0.128.0",
35
- "@webstudio-is/sdk-components-react": "0.128.0",
36
- "@webstudio-is/sdk-components-react-radix": "0.128.0",
37
- "@webstudio-is/sdk-components-react-remix": "0.128.0"
31
+ "@webstudio-is/react-sdk": "0.130.0",
32
+ "@webstudio-is/image": "0.130.0",
33
+ "@webstudio-is/http-client": "0.130.0",
34
+ "@webstudio-is/sdk": "0.130.0",
35
+ "@webstudio-is/sdk-components-react": "0.130.0",
36
+ "@webstudio-is/sdk-components-react-radix": "0.130.0",
37
+ "@webstudio-is/sdk-components-react-remix": "0.130.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/node": "^18.17.1",
41
41
  "@types/prompts": "^2.4.5",
42
42
  "tsx": "^3.12.8",
43
43
  "typescript": "5.2.2",
44
- "@webstudio-is/form-handlers": "0.128.0",
45
- "@webstudio-is/tsconfig": "1.0.7"
44
+ "@webstudio-is/tsconfig": "1.0.7",
45
+ "@webstudio-is/form-handlers": "0.130.0"
46
46
  },
47
47
  "scripts": {
48
48
  "typecheck": "tsc",
@@ -8,7 +8,7 @@ import {
8
8
  json,
9
9
  } from "@remix-run/server-runtime";
10
10
  import { useLoaderData } from "@remix-run/react";
11
- import type { Page as PageType, ProjectMeta } from "@webstudio-is/sdk";
11
+ import type { ProjectMeta } from "@webstudio-is/sdk";
12
12
  import { ReactSdkContext } from "@webstudio-is/react-sdk";
13
13
  import { n8nHandler, getFormId } from "@webstudio-is/form-handlers";
14
14
  import {
@@ -21,19 +21,20 @@ import {
21
21
  Page,
22
22
  imageAssets,
23
23
  getRemixParams,
24
- } from "../__generated__/index";
25
- import { loadResources } from "../__generated__/index.server";
24
+ getPageMeta,
25
+ } from "../../../__generated__/_index";
26
+ import { loadResources } from "../../../__generated__/_index.server";
26
27
  import css from "../__generated__/index.css";
27
28
  import { assetBaseUrl, imageBaseUrl, imageLoader } from "~/constants.mjs";
28
29
 
29
30
  export type PageData = {
30
31
  project?: ProjectMeta;
31
- page: PageType;
32
32
  };
33
33
 
34
34
  export const loader = async (arg: LoaderArgs) => {
35
35
  const params = getRemixParams(arg.params);
36
36
  const resources = await loadResources({ params });
37
+ const pageMeta = getPageMeta({ params, resources });
37
38
 
38
39
  const host =
39
40
  arg.request.headers.get("x-forwarded-host") ||
@@ -54,6 +55,7 @@ export const loader = async (arg: LoaderArgs) => {
54
55
  excludeFromSearch: arg.context.EXCLUDE_FROM_SEARCH,
55
56
  params,
56
57
  resources,
58
+ pageMeta,
57
59
  },
58
60
  // No way for current information to change, so add cache for 10 minutes
59
61
  // In case of CRM Data, this should be set to 0
@@ -68,29 +70,32 @@ export const headers = () => {
68
70
  };
69
71
 
70
72
  export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
71
- const { page, project } = pageData;
72
-
73
73
  const metas: ReturnType<V2_ServerRuntimeMetaFunction> = [];
74
+ if (data === undefined) {
75
+ return metas;
76
+ }
77
+ const { pageMeta } = data;
78
+ const { project } = pageData;
74
79
 
75
- if (data?.url) {
80
+ if (data.url) {
76
81
  metas.push({
77
82
  property: "og:url",
78
83
  content: data.url,
79
84
  });
80
85
  }
81
86
 
82
- if (page.title) {
83
- metas.push({ title: page.title });
87
+ if (pageMeta.title) {
88
+ metas.push({ title: pageMeta.title });
84
89
 
85
90
  metas.push({
86
91
  property: "og:title",
87
- content: page.title,
92
+ content: pageMeta.title,
88
93
  });
89
94
  }
90
95
 
91
96
  metas.push({ property: "og:type", content: "website" });
92
97
 
93
- const origin = `https://${data?.host}`;
98
+ const origin = `https://${data.host}`;
94
99
 
95
100
  if (project?.siteName) {
96
101
  metas.push({
@@ -107,47 +112,47 @@ export const meta: V2_ServerRuntimeMetaFunction<typeof loader> = ({ data }) => {
107
112
  });
108
113
  }
109
114
 
110
- if (page.meta.excludePageFromSearch || data?.excludeFromSearch) {
115
+ if (pageMeta.excludePageFromSearch || data.excludeFromSearch) {
111
116
  metas.push({
112
117
  name: "robots",
113
118
  content: "noindex, nofollow",
114
119
  });
115
120
  }
116
121
 
117
- if (page.meta.description) {
122
+ if (pageMeta.description) {
118
123
  metas.push({
119
124
  name: "description",
120
- content: page.meta.description,
125
+ content: pageMeta.description,
121
126
  });
122
127
  metas.push({
123
128
  property: "og:description",
124
- content: page.meta.description,
129
+ content: pageMeta.description,
125
130
  });
126
131
  }
127
132
 
128
- if (page.meta.socialImageAssetId) {
133
+ if (pageMeta.socialImageAssetId) {
129
134
  const imageAsset = imageAssets.find(
130
- (asset) => asset.id === page.meta.socialImageAssetId
135
+ (asset) => asset.id === pageMeta.socialImageAssetId
131
136
  );
132
137
 
133
138
  if (imageAsset) {
134
139
  metas.push({
135
140
  property: "og:image",
136
- content: `https://${data?.host}${imageLoader({
141
+ content: `https://${data.host}${imageLoader({
137
142
  src: imageAsset.name,
138
143
  // Do not transform social image (not enough information do we need to do this)
139
144
  format: "raw",
140
145
  })}`,
141
146
  });
142
147
  }
148
+ } else if (pageMeta.socialImageUrl) {
149
+ metas.push({
150
+ property: "og:image",
151
+ content: pageMeta.socialImageUrl,
152
+ });
143
153
  }
144
154
 
145
- for (const customMeta of page.meta.custom ?? []) {
146
- if (customMeta.property.trim().length === 0) {
147
- continue;
148
- }
149
- metas.push(customMeta);
150
- }
155
+ metas.push(...pageMeta.custom);
151
156
 
152
157
  return metas;
153
158
  };
@@ -10,13 +10,13 @@
10
10
  "@remix-run/react": "^1.19.2",
11
11
  "@remix-run/server-runtime": "^1.19.2",
12
12
  "@remix-run/node": "^1.19.2",
13
- "@webstudio-is/react-sdk": "0.123.0",
14
- "@webstudio-is/sdk-components-react-radix": "0.123.0",
15
- "@webstudio-is/sdk-components-react-remix": "0.123.0",
16
- "@webstudio-is/sdk-components-react": "0.123.0",
17
- "@webstudio-is/form-handlers": "0.123.0",
18
- "@webstudio-is/image": "0.123.0",
19
- "@webstudio-is/sdk": "0.123.0",
13
+ "@webstudio-is/react-sdk": "0.130.0",
14
+ "@webstudio-is/sdk-components-react-radix": "0.130.0",
15
+ "@webstudio-is/sdk-components-react-remix": "0.130.0",
16
+ "@webstudio-is/sdk-components-react": "0.130.0",
17
+ "@webstudio-is/form-handlers": "0.130.0",
18
+ "@webstudio-is/image": "0.130.0",
19
+ "@webstudio-is/sdk": "0.130.0",
20
20
  "isbot": "^3.6.8",
21
21
  "react": "^18.2.0",
22
22
  "react-dom": "^18.2.0"