@webiny/website-builder-react 6.6.0-alpha.0 → 6.6.0-alpha.10

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.
Files changed (117) hide show
  1. package/components/ConnectToEditor.d.ts +3 -1
  2. package/components/ConnectToEditor.js +7 -5
  3. package/components/ConnectToEditor.js.map +1 -1
  4. package/components/ContentClientContext.d.ts +3 -0
  5. package/components/ContentClientContext.js +6 -0
  6. package/components/ContentClientContext.js.map +1 -0
  7. package/components/ContentClientProvider.d.ts +12 -0
  8. package/components/ContentClientProvider.js +9 -0
  9. package/components/ContentClientProvider.js.map +1 -0
  10. package/components/ContentClientProvider.test.d.ts +1 -0
  11. package/components/ContentClientProvider.test.js +143 -0
  12. package/components/ContentClientProvider.test.js.map +1 -0
  13. package/components/DocumentRenderer.d.ts +8 -3
  14. package/components/DocumentRenderer.js +22 -10
  15. package/components/DocumentRenderer.js.map +1 -1
  16. package/components/DocumentStoreProvider.d.ts +7 -0
  17. package/components/DocumentStoreProvider.js +24 -5
  18. package/components/DocumentStoreProvider.js.map +1 -1
  19. package/components/DocumentStoreProvider.test.d.ts +1 -0
  20. package/components/DocumentStoreProvider.test.js +66 -0
  21. package/components/DocumentStoreProvider.test.js.map +1 -0
  22. package/components/EditingElementRenderer/EditingElementRenderer.d.ts +7 -2
  23. package/components/EditingElementRenderer/EditingElementRenderer.js +21 -9
  24. package/components/EditingElementRenderer/EditingElementRenderer.js.map +1 -1
  25. package/components/EditingElementRenderer/EditingElementRenderer.presenter.d.ts +2 -2
  26. package/components/EditingElementRenderer/EditingElementRenderer.presenter.js +4 -3
  27. package/components/EditingElementRenderer/EditingElementRenderer.presenter.js.map +1 -1
  28. package/components/ElementRenderer.d.ts +2 -2
  29. package/components/ElementRenderer.js +17 -4
  30. package/components/ElementRenderer.js.map +1 -1
  31. package/components/ElementSlot.js +5 -2
  32. package/components/ElementSlot.js.map +1 -1
  33. package/components/FragmentsProvider.js +4 -3
  34. package/components/FragmentsProvider.js.map +1 -1
  35. package/components/GlobalComponent.d.ts +10 -0
  36. package/components/GlobalComponent.js +17 -0
  37. package/components/GlobalComponent.js.map +1 -0
  38. package/components/GlobalPlacement.d.ts +11 -0
  39. package/components/GlobalPlacement.js +27 -0
  40. package/components/GlobalPlacement.js.map +1 -0
  41. package/components/LayoutAreas.d.ts +19 -0
  42. package/components/LayoutAreas.js +15 -0
  43. package/components/LayoutAreas.js.map +1 -0
  44. package/components/LayoutRenderer.d.ts +14 -0
  45. package/components/LayoutRenderer.js +60 -0
  46. package/components/LayoutRenderer.js.map +1 -0
  47. package/components/LayoutRenderer.test.d.ts +1 -0
  48. package/components/LayoutRenderer.test.js +138 -0
  49. package/components/LayoutRenderer.test.js.map +1 -0
  50. package/components/LiveElementRenderer.d.ts +2 -2
  51. package/components/LiveElementRenderer.js +9 -3
  52. package/components/LiveElementRenderer.js.map +1 -1
  53. package/components/PageLayout.d.ts +40 -0
  54. package/components/PageLayout.js +71 -0
  55. package/components/PageLayout.js.map +1 -0
  56. package/components/PreviewElementSlot.js +11 -1
  57. package/components/PreviewElementSlot.js.map +1 -1
  58. package/components/SlotLabel.d.ts +15 -0
  59. package/components/SlotLabel.js +13 -0
  60. package/components/SlotLabel.js.map +1 -0
  61. package/components/index.d.ts +7 -0
  62. package/components/index.js +6 -0
  63. package/components/renderWithLayout.d.ts +5 -0
  64. package/components/renderWithLayout.js +7 -0
  65. package/components/renderWithLayout.js.map +1 -0
  66. package/components/useContentClient.d.ts +6 -0
  67. package/components/useContentClient.js +11 -0
  68. package/components/useContentClient.js.map +1 -0
  69. package/components/useIsElementSelected.d.ts +8 -0
  70. package/components/useIsElementSelected.js +22 -0
  71. package/components/useIsElementSelected.js.map +1 -0
  72. package/components/useSeededDocumentStore.d.ts +10 -0
  73. package/components/useSeededDocumentStore.js +22 -0
  74. package/components/useSeededDocumentStore.js.map +1 -0
  75. package/contentEntry/useContentEntryList.d.ts +22 -0
  76. package/contentEntry/useContentEntryList.js +51 -0
  77. package/contentEntry/useContentEntryList.js.map +1 -0
  78. package/createComponent.d.ts +1 -3
  79. package/createComponent.js +1 -32
  80. package/createComponent.test.js +3 -3
  81. package/createComponent.test.js.map +1 -1
  82. package/editorComponents/Grid.d.ts +1 -1
  83. package/editorComponents/Grid.js +3 -2
  84. package/editorComponents/Grid.js.map +1 -1
  85. package/editorComponents/LayoutContent.d.ts +6 -0
  86. package/editorComponents/LayoutContent.js +121 -0
  87. package/editorComponents/LayoutContent.js.map +1 -0
  88. package/editorComponents/LayoutContent.manifest.d.ts +10 -0
  89. package/editorComponents/LayoutContent.manifest.js +32 -0
  90. package/editorComponents/LayoutContent.manifest.js.map +1 -0
  91. package/editorComponents/LayoutContentLabel.d.ts +2 -0
  92. package/editorComponents/LayoutContentLabel.js +7 -0
  93. package/editorComponents/LayoutContentLabel.js.map +1 -0
  94. package/editorComponents/LayoutContentLabel.test.d.ts +1 -0
  95. package/editorComponents/LayoutContentLabel.test.js +23 -0
  96. package/editorComponents/LayoutContentLabel.test.js.map +1 -0
  97. package/editorComponents/index.js +4 -1
  98. package/editorComponents/index.js.map +1 -1
  99. package/image/BackgroundImage.d.ts +33 -0
  100. package/image/BackgroundImage.js +61 -0
  101. package/image/BackgroundImage.js.map +1 -0
  102. package/image/Image.d.ts +29 -0
  103. package/image/Image.js +43 -0
  104. package/image/Image.js.map +1 -0
  105. package/image/getImageProps.d.ts +42 -0
  106. package/image/getImageProps.js +18 -0
  107. package/image/getImageProps.js.map +1 -0
  108. package/image/getImageProps.test.d.ts +1 -0
  109. package/image/getImageProps.test.js +70 -0
  110. package/image/getImageProps.test.js.map +1 -0
  111. package/image/index.d.ts +3 -0
  112. package/image/index.js +3 -0
  113. package/index.d.ts +3 -2
  114. package/index.js +2 -2
  115. package/package.json +11 -9
  116. package/types.d.ts +4 -4
  117. package/createComponent.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"createComponent.test.js","sources":["../src/createComponent.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport type { ComponentProps, ExtractInputNames } from \"~/types.js\";\nimport { createComponent } from \"~/createComponent.js\";\nimport { createTextInput } from \"~/index.js\";\nimport { createSlotInput } from \"@webiny/website-builder-sdk\";\n\n/**\n * These tests are aimed at testing TS types rather than functionality itself.\n * // TODO: figure out how to enable typechecking for a single test. Currently it only typechecks at build time.\n */\n\ndescribe(\"Component Manifest\", () => {\n it(\"should support input arrays and strict input objects\", () => {\n const Button = (_: ComponentProps<{ title: string; children: React.ReactNode }>) => {\n return null;\n };\n\n type Inputs = ExtractInputNames<typeof Button>;\n\n const button1 = createComponent(Button, {\n name: \"Button\",\n inputs: [\n // Passing a generic narrows down the `name` property and provides autocomplete.\n createTextInput<Inputs>({\n name: \"title\",\n label: \"Title\"\n }),\n // Skipping the generic still performs typechecks, but doesn't provide autocomplete.\n createSlotInput({\n name: \"children\"\n })\n ]\n });\n\n const button2 = createComponent(Button, {\n name: \"Button\",\n inputs: {\n title: createTextInput({\n label: \"Title\"\n }),\n children: createSlotInput({})\n }\n });\n\n const snapshot = {\n name: \"Button\",\n tags: [],\n inputs: [\n {\n type: \"text\",\n label: \"Title\",\n renderer: \"Webiny/Input\",\n name: \"title\"\n },\n {\n type: \"slot\",\n renderer: \"Webiny/Slot\",\n name: \"children\",\n list: true,\n defaultValue: []\n }\n ]\n };\n\n expect(button1.manifest).toEqual(snapshot);\n expect(button2.manifest).toEqual(snapshot);\n });\n\n it(\"acceptsChildren should satisfy the `children` input requirement\", () => {\n const Button = (_: ComponentProps<{ children: React.ReactNode }>) => {\n return null;\n };\n\n const { manifest } = createComponent(Button, {\n name: \"Button\",\n acceptsChildren: true\n });\n\n expect(manifest).toEqual({\n name: \"Button\",\n acceptsChildren: true,\n tags: [],\n inputs: [\n {\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n name: \"children\",\n defaultValue: []\n }\n ]\n });\n });\n\n it(\"`acceptsChildren` should work alongside other inputs\", () => {\n const Button = (_: ComponentProps<{ title: string; children: React.ReactNode }>) => {\n return null;\n };\n\n // Inputs as array\n const button1 = createComponent(Button, {\n name: \"Button\",\n acceptsChildren: true,\n inputs: [\n createTextInput({\n name: \"title\",\n label: \"Title\"\n })\n ]\n });\n\n // Inputs as object\n const button2 = createComponent(Button, {\n name: \"Button\",\n acceptsChildren: true,\n inputs: {\n title: createTextInput({\n label: \"Title\"\n })\n }\n });\n\n // Both must produce the same component manifest\n const snapshot = {\n name: \"Button\",\n acceptsChildren: true,\n tags: [],\n inputs: [\n {\n type: \"text\",\n renderer: \"Webiny/Input\",\n name: \"title\",\n label: \"Title\"\n },\n {\n type: \"slot\",\n renderer: \"Webiny/Slot\",\n name: \"children\",\n list: true,\n defaultValue: []\n }\n ]\n };\n\n expect(button1.manifest).toEqual(snapshot);\n expect(button2.manifest).toEqual(snapshot);\n });\n});\n"],"names":["describe","it","Button","_","button1","createComponent","createTextInput","createSlotInput","button2","snapshot","expect","manifest"],"mappings":";;;;AAWAA,SAAS,sBAAsB;IAC3BC,GAAG,wDAAwD;QACvD,MAAMC,SAAS,CAACC,IACL;QAKX,MAAMC,UAAUC,gBAAgBH,QAAQ;YACpC,MAAM;YACN,QAAQ;gBAEJI,gBAAwB;oBACpB,MAAM;oBACN,OAAO;gBACX;gBAEAC,gBAAgB;oBACZ,MAAM;gBACV;aACH;QACL;QAEA,MAAMC,UAAUH,gBAAgBH,QAAQ;YACpC,MAAM;YACN,QAAQ;gBACJ,OAAOI,gBAAgB;oBACnB,OAAO;gBACX;gBACA,UAAUC,gBAAgB,CAAC;YAC/B;QACJ;QAEA,MAAME,WAAW;YACb,MAAM;YACN,MAAM,EAAE;YACR,QAAQ;gBACJ;oBACI,MAAM;oBACN,OAAO;oBACP,UAAU;oBACV,MAAM;gBACV;gBACA;oBACI,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,MAAM;oBACN,cAAc,EAAE;gBACpB;aACH;QACL;QAEAC,OAAON,QAAQ,QAAQ,EAAE,OAAO,CAACK;QACjCC,OAAOF,QAAQ,QAAQ,EAAE,OAAO,CAACC;IACrC;IAEAR,GAAG,mEAAmE;QAClE,MAAMC,SAAS,CAACC,IACL;QAGX,MAAM,EAAEQ,QAAQ,EAAE,GAAGN,gBAAgBH,QAAQ;YACzC,MAAM;YACN,iBAAiB;QACrB;QAEAQ,OAAOC,UAAU,OAAO,CAAC;YACrB,MAAM;YACN,iBAAiB;YACjB,MAAM,EAAE;YACR,QAAQ;gBACJ;oBACI,MAAM;oBACN,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,cAAc,EAAE;gBACpB;aACH;QACL;IACJ;IAEAV,GAAG,wDAAwD;QACvD,MAAMC,SAAS,CAACC,IACL;QAIX,MAAMC,UAAUC,gBAAgBH,QAAQ;YACpC,MAAM;YACN,iBAAiB;YACjB,QAAQ;gBACJI,gBAAgB;oBACZ,MAAM;oBACN,OAAO;gBACX;aACH;QACL;QAGA,MAAME,UAAUH,gBAAgBH,QAAQ;YACpC,MAAM;YACN,iBAAiB;YACjB,QAAQ;gBACJ,OAAOI,gBAAgB;oBACnB,OAAO;gBACX;YACJ;QACJ;QAGA,MAAMG,WAAW;YACb,MAAM;YACN,iBAAiB;YACjB,MAAM,EAAE;YACR,QAAQ;gBACJ;oBACI,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,OAAO;gBACX;gBACA;oBACI,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,MAAM;oBACN,cAAc,EAAE;gBACpB;aACH;QACL;QAEAC,OAAON,QAAQ,QAAQ,EAAE,OAAO,CAACK;QACjCC,OAAOF,QAAQ,QAAQ,EAAE,OAAO,CAACC;IACrC;AACJ"}
1
+ {"version":3,"file":"createComponent.test.js","sources":["../src/createComponent.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport type { ComponentProps, ExtractInputNames } from \"~/types.js\";\nimport { createComponent } from \"~/createComponent.js\";\nimport { createTextInput } from \"~/index.js\";\nimport { createSlotInput } from \"@webiny/website-builder-sdk\";\n\n/**\n * These tests are aimed at testing TS types rather than functionality itself.\n * // TODO: figure out how to enable typechecking for a single test. Currently it only typechecks at build time.\n */\n\ndescribe(\"Component Manifest\", () => {\n it(\"should support input arrays and strict input objects\", () => {\n const Button = ({}: ComponentProps<{ title: string; children: React.ReactNode }>) => {\n return null;\n };\n\n type Inputs = ExtractInputNames<typeof Button>;\n\n const button1 = createComponent(Button, {\n name: \"Button\",\n inputs: [\n // Passing a generic narrows down the `name` property and provides autocomplete.\n createTextInput<Inputs>({\n name: \"title\",\n label: \"Title\"\n }),\n // Skipping the generic still performs typechecks, but doesn't provide autocomplete.\n createSlotInput({\n name: \"children\"\n })\n ]\n });\n\n const button2 = createComponent(Button, {\n name: \"Button\",\n inputs: {\n title: createTextInput({\n label: \"Title\"\n }),\n children: createSlotInput({})\n }\n });\n\n const snapshot = {\n name: \"Button\",\n tags: [],\n inputs: [\n {\n type: \"text\",\n label: \"Title\",\n renderer: \"Webiny/Input\",\n name: \"title\"\n },\n {\n type: \"slot\",\n renderer: \"Webiny/Slot\",\n name: \"children\",\n list: true,\n defaultValue: []\n }\n ]\n };\n\n expect(button1.manifest).toEqual(snapshot);\n expect(button2.manifest).toEqual(snapshot);\n });\n\n it(\"acceptsChildren should satisfy the `children` input requirement\", () => {\n const Button = ({}: ComponentProps<{ children: React.ReactNode }>) => {\n return null;\n };\n\n const { manifest } = createComponent(Button, {\n name: \"Button\",\n acceptsChildren: true\n });\n\n expect(manifest).toEqual({\n name: \"Button\",\n acceptsChildren: true,\n tags: [],\n inputs: [\n {\n type: \"slot\",\n list: true,\n renderer: \"Webiny/Slot\",\n name: \"children\",\n defaultValue: []\n }\n ]\n });\n });\n\n it(\"`acceptsChildren` should work alongside other inputs\", () => {\n const Button = ({}: ComponentProps<{ title: string; children: React.ReactNode }>) => {\n return null;\n };\n\n // Inputs as array\n const button1 = createComponent(Button, {\n name: \"Button\",\n acceptsChildren: true,\n inputs: [\n createTextInput({\n name: \"title\",\n label: \"Title\"\n })\n ]\n });\n\n // Inputs as object\n const button2 = createComponent(Button, {\n name: \"Button\",\n acceptsChildren: true,\n inputs: {\n title: createTextInput({\n label: \"Title\"\n })\n }\n });\n\n // Both must produce the same component manifest\n const snapshot = {\n name: \"Button\",\n acceptsChildren: true,\n tags: [],\n inputs: [\n {\n type: \"text\",\n renderer: \"Webiny/Input\",\n name: \"title\",\n label: \"Title\"\n },\n {\n type: \"slot\",\n renderer: \"Webiny/Slot\",\n name: \"children\",\n list: true,\n defaultValue: []\n }\n ]\n };\n\n expect(button1.manifest).toEqual(snapshot);\n expect(button2.manifest).toEqual(snapshot);\n });\n});\n"],"names":["describe","it","Button","button1","createComponent","createTextInput","createSlotInput","button2","snapshot","expect","manifest"],"mappings":";;;;AAWAA,SAAS,sBAAsB;IAC3BC,GAAG,wDAAwD;QACvD,MAAMC,SAAS,CAAC,EAAgE,GACrE;QAKX,MAAMC,UAAUC,gBAAgBF,QAAQ;YACpC,MAAM;YACN,QAAQ;gBAEJG,gBAAwB;oBACpB,MAAM;oBACN,OAAO;gBACX;gBAEAC,gBAAgB;oBACZ,MAAM;gBACV;aACH;QACL;QAEA,MAAMC,UAAUH,gBAAgBF,QAAQ;YACpC,MAAM;YACN,QAAQ;gBACJ,OAAOG,gBAAgB;oBACnB,OAAO;gBACX;gBACA,UAAUC,gBAAgB,CAAC;YAC/B;QACJ;QAEA,MAAME,WAAW;YACb,MAAM;YACN,MAAM,EAAE;YACR,QAAQ;gBACJ;oBACI,MAAM;oBACN,OAAO;oBACP,UAAU;oBACV,MAAM;gBACV;gBACA;oBACI,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,MAAM;oBACN,cAAc,EAAE;gBACpB;aACH;QACL;QAEAC,OAAON,QAAQ,QAAQ,EAAE,OAAO,CAACK;QACjCC,OAAOF,QAAQ,QAAQ,EAAE,OAAO,CAACC;IACrC;IAEAP,GAAG,mEAAmE;QAClE,MAAMC,SAAS,CAAC,EAAiD,GACtD;QAGX,MAAM,EAAEQ,QAAQ,EAAE,GAAGN,gBAAgBF,QAAQ;YACzC,MAAM;YACN,iBAAiB;QACrB;QAEAO,OAAOC,UAAU,OAAO,CAAC;YACrB,MAAM;YACN,iBAAiB;YACjB,MAAM,EAAE;YACR,QAAQ;gBACJ;oBACI,MAAM;oBACN,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,cAAc,EAAE;gBACpB;aACH;QACL;IACJ;IAEAT,GAAG,wDAAwD;QACvD,MAAMC,SAAS,CAAC,EAAgE,GACrE;QAIX,MAAMC,UAAUC,gBAAgBF,QAAQ;YACpC,MAAM;YACN,iBAAiB;YACjB,QAAQ;gBACJG,gBAAgB;oBACZ,MAAM;oBACN,OAAO;gBACX;aACH;QACL;QAGA,MAAME,UAAUH,gBAAgBF,QAAQ;YACpC,MAAM;YACN,iBAAiB;YACjB,QAAQ;gBACJ,OAAOG,gBAAgB;oBACnB,OAAO;gBACX;YACJ;QACJ;QAGA,MAAMG,WAAW;YACb,MAAM;YACN,iBAAiB;YACjB,MAAM,EAAE;YACR,QAAQ;gBACJ;oBACI,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,OAAO;gBACX;gBACA;oBACI,MAAM;oBACN,UAAU;oBACV,MAAM;oBACN,MAAM;oBACN,cAAc,EAAE;gBACpB;aACH;QACL;QAEAC,OAAON,QAAQ,QAAQ,EAAE,OAAO,CAACK;QACjCC,OAAOF,QAAQ,QAAQ,EAAE,OAAO,CAACC;IACrC;AACJ"}
@@ -15,5 +15,5 @@ type GridProps = ComponentProps<{
15
15
  stackAtBreakpoint?: string;
16
16
  reverseWhenStacked?: boolean;
17
17
  }>;
18
- export declare const GridComponent: ({ inputs, styles, breakpoint }: GridProps) => React.JSX.Element;
18
+ export declare const GridComponent: ({ inputs, styles, breakpoint, breakpoints }: GridProps) => React.JSX.Element;
19
19
  export {};
@@ -1,12 +1,13 @@
1
1
  import react from "react";
2
2
  const GridColumnComponent = ({ inputs })=>/*#__PURE__*/ react.createElement(react.Fragment, null, inputs.children);
3
- const GridComponent = ({ inputs, styles, breakpoint })=>{
3
+ const GridComponent = ({ inputs, styles, breakpoint, breakpoints })=>{
4
4
  const { gridLayout = "12", columns, columnGap, stackAtBreakpoint, reverseWhenStacked } = inputs;
5
5
  const rowConfig = gridLayout.split("-").map((size)=>parseInt(size));
6
6
  const rows = [];
7
7
  for(let i = 0; i < columns.length; i += rowConfig.length)rows.push(columns.slice(i, i + rowConfig.length));
8
8
  const cellWidthReduction = columnGap ? columnGap - columnGap / rowConfig.length : 0;
9
- const stackColumns = breakpoint === stackAtBreakpoint;
9
+ const stackFrom = stackAtBreakpoint ? breakpoints.indexOf(stackAtBreakpoint) : -1;
10
+ const stackColumns = -1 !== stackFrom && breakpoints.indexOf(breakpoint) >= stackFrom;
10
11
  if (stackColumns) styles.flexDirection = reverseWhenStacked ? "column-reverse" : "column";
11
12
  return /*#__PURE__*/ react.createElement("div", {
12
13
  style: styles
@@ -1 +1 @@
1
- {"version":3,"file":"editorComponents/Grid.js","sources":["../../src/editorComponents/Grid.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ComponentProps, ComponentPropsWithChildren } from \"~/types.js\";\n\nexport const GridColumnComponent = ({\n inputs\n}: {\n inputs: ComponentPropsWithChildren[\"inputs\"];\n}) => {\n return <>{inputs.children}</>;\n};\n\nexport interface Column {\n children: React.ReactNode;\n}\n\ntype GridProps = ComponentProps<{\n gridLayout: string;\n rowCount: number;\n rowGap: number;\n columnGap: number;\n columns: Column[];\n stackAtBreakpoint?: string;\n reverseWhenStacked?: boolean;\n}>;\n\nexport const GridComponent = ({ inputs, styles, breakpoint }: GridProps) => {\n const { gridLayout = \"12\", columns, columnGap, stackAtBreakpoint, reverseWhenStacked } = inputs;\n const rowConfig = gridLayout.split(\"-\").map(size => parseInt(size));\n const rows: Column[][] = [];\n\n // Chunk columns into rows\n for (let i = 0; i < columns.length; i += rowConfig.length) {\n rows.push(columns.slice(i, i + rowConfig.length));\n }\n\n // Number of pixels we need to subtract from each cell to ensure they fit in the grid with column gap\n const cellWidthReduction = columnGap ? columnGap - columnGap / rowConfig.length : 0;\n\n const stackColumns = breakpoint === stackAtBreakpoint;\n\n if (stackColumns) {\n styles.flexDirection = reverseWhenStacked ? \"column-reverse\" : \"column\";\n }\n\n return (\n <div style={styles}>\n {rows.map(columns => {\n return columns.map((column, i) => (\n <Span\n key={i}\n stackColumns={stackColumns}\n size={rowConfig[i]}\n reductionInPx={cellWidthReduction}\n >\n <GridColumnComponent key={i} inputs={{ children: column.children }} />\n </Span>\n ));\n })}\n </div>\n );\n};\n\ninterface SpanProps {\n size: number;\n reductionInPx: number;\n stackColumns: boolean;\n children: React.ReactNode;\n}\n\nconst Span = ({ size, children, reductionInPx, stackColumns }: SpanProps) => {\n const width = stackColumns ? \"100%\" : `calc(${(size / 12) * 100}% - ${reductionInPx}px)`;\n\n return (\n <div\n style={{\n flex: `0 0 ${width}`,\n maxWidth: width,\n boxSizing: \"border-box\"\n }}\n >\n {children}\n </div>\n );\n};\n"],"names":["GridColumnComponent","inputs","GridComponent","styles","breakpoint","gridLayout","columns","columnGap","stackAtBreakpoint","reverseWhenStacked","rowConfig","size","parseInt","rows","i","cellWidthReduction","stackColumns","column","Span","children","reductionInPx","width"],"mappings":";AAGO,MAAMA,sBAAsB,CAAC,EAChCC,MAAM,EAGT,GACU,WAAP,GAAO,0CAAGA,OAAO,QAAQ;AAiBtB,MAAMC,gBAAgB,CAAC,EAAED,MAAM,EAAEE,MAAM,EAAEC,UAAU,EAAa;IACnE,MAAM,EAAEC,aAAa,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,iBAAiB,EAAEC,kBAAkB,EAAE,GAAGR;IACzF,MAAMS,YAAYL,WAAW,KAAK,CAAC,KAAK,GAAG,CAACM,CAAAA,OAAQC,SAASD;IAC7D,MAAME,OAAmB,EAAE;IAG3B,IAAK,IAAIC,IAAI,GAAGA,IAAIR,QAAQ,MAAM,EAAEQ,KAAKJ,UAAU,MAAM,CACrDG,KAAK,IAAI,CAACP,QAAQ,KAAK,CAACQ,GAAGA,IAAIJ,UAAU,MAAM;IAInD,MAAMK,qBAAqBR,YAAYA,YAAYA,YAAYG,UAAU,MAAM,GAAG;IAElF,MAAMM,eAAeZ,eAAeI;IAEpC,IAAIQ,cACAb,OAAO,aAAa,GAAGM,qBAAqB,mBAAmB;IAGnE,OAAO,WAAP,GACI,oBAAC;QAAI,OAAON;OACPU,KAAK,GAAG,CAACP,CAAAA,UACCA,QAAQ,GAAG,CAAC,CAACW,QAAQH,IAAAA,WAAAA,GACxB,oBAACI,MAAIA;gBACD,KAAKJ;gBACL,cAAcE;gBACd,MAAMN,SAAS,CAACI,EAAE;gBAClB,eAAeC;6BAEf,oBAACf,qBAAmBA;gBAAC,KAAKc;gBAAG,QAAQ;oBAAE,UAAUG,OAAO,QAAQ;gBAAC;;AAMzF;AASA,MAAMC,OAAO,CAAC,EAAEP,IAAI,EAAEQ,QAAQ,EAAEC,aAAa,EAAEJ,YAAY,EAAa;IACpE,MAAMK,QAAQL,eAAe,SAAS,CAAC,KAAK,EAAGL,OAAO,KAAM,IAAI,IAAI,EAAES,cAAc,GAAG,CAAC;IAExF,OAAO,WAAP,GACI,oBAAC;QACG,OAAO;YACH,MAAM,CAAC,IAAI,EAAEC,OAAO;YACpB,UAAUA;YACV,WAAW;QACf;OAECF;AAGb"}
1
+ {"version":3,"file":"editorComponents/Grid.js","sources":["../../src/editorComponents/Grid.tsx"],"sourcesContent":["import React from \"react\";\nimport type { ComponentProps, ComponentPropsWithChildren } from \"~/types.js\";\n\nexport const GridColumnComponent = ({\n inputs\n}: {\n inputs: ComponentPropsWithChildren[\"inputs\"];\n}) => {\n return <>{inputs.children}</>;\n};\n\nexport interface Column {\n children: React.ReactNode;\n}\n\ntype GridProps = ComponentProps<{\n gridLayout: string;\n rowCount: number;\n rowGap: number;\n columnGap: number;\n columns: Column[];\n stackAtBreakpoint?: string;\n reverseWhenStacked?: boolean;\n}>;\n\nexport const GridComponent = ({ inputs, styles, breakpoint, breakpoints }: GridProps) => {\n const { gridLayout = \"12\", columns, columnGap, stackAtBreakpoint, reverseWhenStacked } = inputs;\n const rowConfig = gridLayout.split(\"-\").map(size => parseInt(size));\n const rows: Column[][] = [];\n\n // Chunk columns into rows\n for (let i = 0; i < columns.length; i += rowConfig.length) {\n rows.push(columns.slice(i, i + rowConfig.length));\n }\n\n // Number of pixels we need to subtract from each cell to ensure they fit in the grid with column gap\n const cellWidthReduction = columnGap ? columnGap - columnGap / rowConfig.length : 0;\n\n // Stack at the chosen breakpoint and every narrower one.\n const stackFrom = stackAtBreakpoint ? breakpoints.indexOf(stackAtBreakpoint) : -1;\n const stackColumns = stackFrom !== -1 && breakpoints.indexOf(breakpoint) >= stackFrom;\n\n if (stackColumns) {\n styles.flexDirection = reverseWhenStacked ? \"column-reverse\" : \"column\";\n }\n\n return (\n <div style={styles}>\n {rows.map(columns => {\n return columns.map((column, i) => (\n <Span\n key={i}\n stackColumns={stackColumns}\n size={rowConfig[i]}\n reductionInPx={cellWidthReduction}\n >\n <GridColumnComponent key={i} inputs={{ children: column.children }} />\n </Span>\n ));\n })}\n </div>\n );\n};\n\ninterface SpanProps {\n size: number;\n reductionInPx: number;\n stackColumns: boolean;\n children: React.ReactNode;\n}\n\nconst Span = ({ size, children, reductionInPx, stackColumns }: SpanProps) => {\n const width = stackColumns ? \"100%\" : `calc(${(size / 12) * 100}% - ${reductionInPx}px)`;\n\n return (\n <div\n style={{\n flex: `0 0 ${width}`,\n maxWidth: width,\n boxSizing: \"border-box\"\n }}\n >\n {children}\n </div>\n );\n};\n"],"names":["GridColumnComponent","inputs","GridComponent","styles","breakpoint","breakpoints","gridLayout","columns","columnGap","stackAtBreakpoint","reverseWhenStacked","rowConfig","size","parseInt","rows","i","cellWidthReduction","stackFrom","stackColumns","column","Span","children","reductionInPx","width"],"mappings":";AAGO,MAAMA,sBAAsB,CAAC,EAChCC,MAAM,EAGT,GACU,WAAP,GAAO,0CAAGA,OAAO,QAAQ;AAiBtB,MAAMC,gBAAgB,CAAC,EAAED,MAAM,EAAEE,MAAM,EAAEC,UAAU,EAAEC,WAAW,EAAa;IAChF,MAAM,EAAEC,aAAa,IAAI,EAAEC,OAAO,EAAEC,SAAS,EAAEC,iBAAiB,EAAEC,kBAAkB,EAAE,GAAGT;IACzF,MAAMU,YAAYL,WAAW,KAAK,CAAC,KAAK,GAAG,CAACM,CAAAA,OAAQC,SAASD;IAC7D,MAAME,OAAmB,EAAE;IAG3B,IAAK,IAAIC,IAAI,GAAGA,IAAIR,QAAQ,MAAM,EAAEQ,KAAKJ,UAAU,MAAM,CACrDG,KAAK,IAAI,CAACP,QAAQ,KAAK,CAACQ,GAAGA,IAAIJ,UAAU,MAAM;IAInD,MAAMK,qBAAqBR,YAAYA,YAAYA,YAAYG,UAAU,MAAM,GAAG;IAGlF,MAAMM,YAAYR,oBAAoBJ,YAAY,OAAO,CAACI,qBAAqB;IAC/E,MAAMS,eAAeD,AAAc,OAAdA,aAAoBZ,YAAY,OAAO,CAACD,eAAea;IAE5E,IAAIC,cACAf,OAAO,aAAa,GAAGO,qBAAqB,mBAAmB;IAGnE,OAAO,WAAP,GACI,oBAAC;QAAI,OAAOP;OACPW,KAAK,GAAG,CAACP,CAAAA,UACCA,QAAQ,GAAG,CAAC,CAACY,QAAQJ,IAAAA,WAAAA,GACxB,oBAACK,MAAIA;gBACD,KAAKL;gBACL,cAAcG;gBACd,MAAMP,SAAS,CAACI,EAAE;gBAClB,eAAeC;6BAEf,oBAAChB,qBAAmBA;gBAAC,KAAKe;gBAAG,QAAQ;oBAAE,UAAUI,OAAO,QAAQ;gBAAC;;AAMzF;AASA,MAAMC,OAAO,CAAC,EAAER,IAAI,EAAES,QAAQ,EAAEC,aAAa,EAAEJ,YAAY,EAAa;IACpE,MAAMK,QAAQL,eAAe,SAAS,CAAC,KAAK,EAAGN,OAAO,KAAM,IAAI,IAAI,EAAEU,cAAc,GAAG,CAAC;IAExF,OAAO,WAAP,GACI,oBAAC;QACG,OAAO;YACH,MAAM,CAAC,IAAI,EAAEC,OAAO;YACpB,UAAUA;YACV,WAAW;QACf;OAECF;AAGb"}
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ import type { ComponentProps } from "../types.js";
3
+ export declare const MainContentComponent: ({ element }: ComponentProps) => React.JSX.Element;
4
+ export declare const NamedContentComponent: ({ inputs, element }: ComponentProps<{
5
+ area?: string;
6
+ }>) => React.JSX.Element;
@@ -0,0 +1,121 @@
1
+ import react, { useMemo } from "react";
2
+ import { observer } from "mobx-react-lite";
3
+ import { toJS } from "mobx";
4
+ import { LayoutContentArea, withGlobalElementDefaults } from "@webiny/website-builder-sdk";
5
+ import { ElementRenderer } from "../components/ElementRenderer.js";
6
+ import { ElementSlot } from "../components/ElementSlot.js";
7
+ import { DocumentStoreScope, useDocumentStore } from "../components/DocumentStoreProvider.js";
8
+ import { useSeededDocumentStore } from "../components/useSeededDocumentStore.js";
9
+ import { PageScope, ReadOnlyScope, usePageLayout } from "../components/PageLayout.js";
10
+ import { SlotLabel } from "../components/SlotLabel.js";
11
+ import { LayoutAreasProvider, getLayoutAreaContent, useLayoutAreas } from "../components/LayoutAreas.js";
12
+ import { getContentAreaLabel } from "./LayoutContentLabel.js";
13
+ import { useContentClient } from "../components/useContentClient.js";
14
+ const toPreviewDocument = (page, client)=>{
15
+ const document = {
16
+ id: page.id,
17
+ version: 1,
18
+ state: {},
19
+ extensions: {},
20
+ metadata: {},
21
+ properties: page.properties ?? {
22
+ id: page.id
23
+ },
24
+ elements: page.elements ?? {},
25
+ bindings: page.bindings ?? {}
26
+ };
27
+ const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());
28
+ return {
29
+ ...document,
30
+ elements: withDefaults.elements,
31
+ bindings: withDefaults.bindings
32
+ };
33
+ };
34
+ const PageArea = observer(({ area })=>{
35
+ const documentStore = useDocumentStore();
36
+ const slot = area.slot();
37
+ if (area.isMain()) return /*#__PURE__*/ react.createElement(SlotLabel, {
38
+ parentId: "root",
39
+ slot: slot,
40
+ label: getContentAreaLabel(area)
41
+ }, /*#__PURE__*/ react.createElement(ElementRenderer, {
42
+ id: "root"
43
+ }));
44
+ const ids = documentStore.getDocument()?.bindings.root?.inputs?.[slot]?.static;
45
+ return /*#__PURE__*/ react.createElement(SlotLabel, {
46
+ parentId: "root",
47
+ slot: slot,
48
+ label: getContentAreaLabel(area)
49
+ }, /*#__PURE__*/ react.createElement(ElementSlot, {
50
+ parentId: "root",
51
+ slot: slot,
52
+ elements: Array.isArray(ids) ? [
53
+ ...ids
54
+ ] : []
55
+ }));
56
+ });
57
+ const PreviewPageScope = ({ document, children })=>{
58
+ const store = useSeededDocumentStore(document);
59
+ return /*#__PURE__*/ react.createElement(DocumentStoreScope, {
60
+ store: store
61
+ }, children);
62
+ };
63
+ const PreviewPageContent = ({ pageJson, area })=>{
64
+ const client = useContentClient();
65
+ const document = useMemo(()=>toPreviewDocument(JSON.parse(pageJson), client), [
66
+ pageJson,
67
+ client
68
+ ]);
69
+ return /*#__PURE__*/ react.createElement(ReadOnlyScope, null, /*#__PURE__*/ react.createElement(PreviewPageScope, {
70
+ key: document.id,
71
+ document: document
72
+ }, /*#__PURE__*/ react.createElement(PageArea, {
73
+ area: area
74
+ })));
75
+ };
76
+ const Placeholder = ({ area })=>/*#__PURE__*/ react.createElement("div", {
77
+ style: {
78
+ display: "flex",
79
+ minHeight: "200px",
80
+ backgroundColor: "#f4f4f4",
81
+ border: "2px dashed #d0d0d0",
82
+ justifyContent: "center",
83
+ alignItems: "center",
84
+ color: "#6b6b6b"
85
+ }
86
+ }, getContentAreaLabel(area));
87
+ const LayoutEditorContent = observer(({ area })=>{
88
+ const documentStore = useDocumentStore();
89
+ const previewPage = documentStore.getDocument()?.previewPage;
90
+ if (previewPage) return /*#__PURE__*/ react.createElement(PreviewPageContent, {
91
+ pageJson: JSON.stringify(toJS(previewPage)),
92
+ area: area
93
+ });
94
+ return /*#__PURE__*/ react.createElement(Placeholder, {
95
+ area: area
96
+ });
97
+ });
98
+ const ContentArea = ({ area })=>{
99
+ const client = useContentClient();
100
+ const pageLayout = usePageLayout();
101
+ const layoutAreas = useLayoutAreas();
102
+ if (layoutAreas) return /*#__PURE__*/ react.createElement(PageScope, null, /*#__PURE__*/ react.createElement(LayoutAreasProvider, {
103
+ value: void 0
104
+ }, getLayoutAreaContent(layoutAreas, area)));
105
+ if (pageLayout) return /*#__PURE__*/ react.createElement(PageScope, null, /*#__PURE__*/ react.createElement(PageArea, {
106
+ area: area
107
+ }));
108
+ if (!client.isEditing()) return null;
109
+ return /*#__PURE__*/ react.createElement(LayoutEditorContent, {
110
+ area: area
111
+ });
112
+ };
113
+ const MainContentComponent = ({ element })=>/*#__PURE__*/ react.createElement(ContentArea, {
114
+ area: LayoutContentArea.fromElement(element)
115
+ });
116
+ const NamedContentComponent = ({ inputs, element })=>/*#__PURE__*/ react.createElement(ContentArea, {
117
+ area: LayoutContentArea.fromElement(element, inputs?.area)
118
+ });
119
+ export { MainContentComponent, NamedContentComponent };
120
+
121
+ //# sourceMappingURL=LayoutContent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorComponents/LayoutContent.js","sources":["../../src/editorComponents/LayoutContent.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { observer } from \"mobx-react-lite\";\nimport { toJS } from \"mobx\";\nimport {\n type ContentClient,\n type Document,\n LayoutContentArea,\n type PreviewPage,\n withGlobalElementDefaults\n} from \"@webiny/website-builder-sdk\";\nimport { ElementRenderer } from \"~/components/ElementRenderer.js\";\nimport { ElementSlot } from \"~/components/ElementSlot.js\";\nimport type { ComponentProps } from \"~/types.js\";\nimport { DocumentStoreScope, useDocumentStore } from \"~/components/DocumentStoreProvider.js\";\nimport { useSeededDocumentStore } from \"~/components/useSeededDocumentStore.js\";\nimport { PageScope, ReadOnlyScope, usePageLayout } from \"~/components/PageLayout.js\";\nimport { SlotLabel } from \"~/components/SlotLabel.js\";\nimport {\n getLayoutAreaContent,\n LayoutAreasProvider,\n useLayoutAreas\n} from \"~/components/LayoutAreas.js\";\nimport { getContentAreaLabel } from \"./LayoutContentLabel.js\";\nimport { useContentClient } from \"~/components/useContentClient.js\";\n\nconst toPreviewDocument = (page: PreviewPage, client: ContentClient): Document => {\n const document: Document = {\n id: page.id,\n version: 1,\n state: {},\n extensions: {},\n metadata: {},\n properties: page.properties ?? { id: page.id },\n elements: page.elements ?? {},\n bindings: page.bindings ?? {}\n };\n\n // Globals the page has no stored instance of render from their manifest defaults, as on the live site.\n const withDefaults = withGlobalElementDefaults(document, client.getComponentManifests());\n return { ...document, elements: withDefaults.elements, bindings: withDefaults.bindings };\n};\n\n/**\n * The page's content of one area. The main area is the page root, as on a page without a layout; the\n * others are slots of the page root. In the page editor, each is a place to drop content.\n */\nconst PageArea = observer(({ area }: { area: LayoutContentArea }) => {\n const documentStore = useDocumentStore();\n const slot = area.slot();\n\n // While an area is empty, its drop area in the page editor says which one it is.\n if (area.isMain()) {\n return (\n <SlotLabel parentId={\"root\"} slot={slot} label={getContentAreaLabel(area)}>\n <ElementRenderer id={\"root\"} />\n </SlotLabel>\n );\n }\n\n const ids = documentStore.getDocument()?.bindings.root?.inputs?.[slot]?.static;\n\n return (\n <SlotLabel parentId={\"root\"} slot={slot} label={getContentAreaLabel(area)}>\n <ElementSlot\n parentId={\"root\"}\n slot={slot}\n elements={Array.isArray(ids) ? [...ids] : []}\n />\n </SlotLabel>\n );\n});\n\nconst PreviewPageScope = ({\n document,\n children\n}: {\n document: Document;\n children: React.ReactNode;\n}) => {\n const store = useSeededDocumentStore(document);\n\n return <DocumentStoreScope store={store}>{children}</DocumentStoreScope>;\n};\n\n/**\n * In the layout editor, the page picked to preview the layout with: shown in place of the page content,\n * as on the live site. It can't be selected; it belongs to the page, not to the layout.\n */\nconst PreviewPageContent = ({ pageJson, area }: { pageJson: string; area: LayoutContentArea }) => {\n const client = useContentClient();\n const document = useMemo(\n () => toPreviewDocument(JSON.parse(pageJson), client),\n [pageJson, client]\n );\n\n // Keyed by page: picking another page renders it from scratch. Its elements share ids with the previous\n // page's (\"root\"), so they would otherwise keep what they had read from the previous page.\n return (\n <ReadOnlyScope>\n <PreviewPageScope key={document.id} document={document}>\n <PageArea area={area} />\n </PreviewPageScope>\n </ReadOnlyScope>\n );\n};\n\nconst Placeholder = ({ area }: { area: LayoutContentArea }) => {\n return (\n <div\n style={{\n display: \"flex\",\n minHeight: \"200px\",\n backgroundColor: \"#f4f4f4\",\n border: \"2px dashed #d0d0d0\",\n justifyContent: \"center\",\n alignItems: \"center\",\n color: \"#6b6b6b\"\n }}\n >\n {getContentAreaLabel(area)}\n </div>\n );\n};\n\nconst LayoutEditorContent = observer(({ area }: { area: LayoutContentArea }) => {\n const documentStore = useDocumentStore();\n const previewPage = documentStore.getDocument()?.previewPage;\n\n if (previewPage) {\n return <PreviewPageContent pageJson={JSON.stringify(toJS(previewPage))} area={area} />;\n }\n\n return <Placeholder area={area} />;\n});\n\n/**\n * A page content area: where a page renders its own content of that area inside a layout. In the layout\n * editor, there is no page: it shows a placeholder, or the page picked to preview the layout with.\n */\nconst ContentArea = ({ area }: { area: LayoutContentArea }) => {\n const client = useContentClient();\n const pageLayout = usePageLayout();\n const layoutAreas = useLayoutAreas();\n\n // Content from code rendered in the layout (see <LayoutRenderer>). It's not part of the layout, so\n // nothing of the layout is around it any more.\n if (layoutAreas) {\n return (\n <PageScope>\n <LayoutAreasProvider value={undefined}>\n {getLayoutAreaContent(layoutAreas, area)}\n </LayoutAreasProvider>\n </PageScope>\n );\n }\n\n if (pageLayout) {\n return (\n <PageScope>\n <PageArea area={area} />\n </PageScope>\n );\n }\n\n if (!client.isEditing()) {\n return null;\n }\n\n return <LayoutEditorContent area={area} />;\n};\n\nexport const MainContentComponent = ({ element }: ComponentProps) => {\n return <ContentArea area={LayoutContentArea.fromElement(element)} />;\n};\n\nexport const NamedContentComponent = ({ inputs, element }: ComponentProps<{ area?: string }>) => {\n return <ContentArea area={LayoutContentArea.fromElement(element, inputs?.area)} />;\n};\n"],"names":["toPreviewDocument","page","client","document","withDefaults","withGlobalElementDefaults","PageArea","observer","area","documentStore","useDocumentStore","slot","SlotLabel","getContentAreaLabel","ElementRenderer","ids","ElementSlot","Array","PreviewPageScope","children","store","useSeededDocumentStore","DocumentStoreScope","PreviewPageContent","pageJson","useContentClient","useMemo","JSON","ReadOnlyScope","Placeholder","LayoutEditorContent","previewPage","toJS","ContentArea","pageLayout","usePageLayout","layoutAreas","useLayoutAreas","PageScope","LayoutAreasProvider","undefined","getLayoutAreaContent","MainContentComponent","element","LayoutContentArea","NamedContentComponent","inputs"],"mappings":";;;;;;;;;;;;;AAyBA,MAAMA,oBAAoB,CAACC,MAAmBC;IAC1C,MAAMC,WAAqB;QACvB,IAAIF,KAAK,EAAE;QACX,SAAS;QACT,OAAO,CAAC;QACR,YAAY,CAAC;QACb,UAAU,CAAC;QACX,YAAYA,KAAK,UAAU,IAAI;YAAE,IAAIA,KAAK,EAAE;QAAC;QAC7C,UAAUA,KAAK,QAAQ,IAAI,CAAC;QAC5B,UAAUA,KAAK,QAAQ,IAAI,CAAC;IAChC;IAGA,MAAMG,eAAeC,0BAA0BF,UAAUD,OAAO,qBAAqB;IACrF,OAAO;QAAE,GAAGC,QAAQ;QAAE,UAAUC,aAAa,QAAQ;QAAE,UAAUA,aAAa,QAAQ;IAAC;AAC3F;AAMA,MAAME,WAAWC,SAAS,CAAC,EAAEC,IAAI,EAA+B;IAC5D,MAAMC,gBAAgBC;IACtB,MAAMC,OAAOH,KAAK,IAAI;IAGtB,IAAIA,KAAK,MAAM,IACX,OAAO,WAAP,GACI,oBAACI,WAASA;QAAC,UAAU;QAAQ,MAAMD;QAAM,OAAOE,oBAAoBL;qBAChE,oBAACM,iBAAeA;QAAC,IAAI;;IAKjC,MAAMC,MAAMN,cAAc,WAAW,IAAI,SAAS,MAAM,QAAQ,CAACE,KAAK,EAAE;IAExE,OAAO,WAAP,GACI,oBAACC,WAASA;QAAC,UAAU;QAAQ,MAAMD;QAAM,OAAOE,oBAAoBL;qBAChE,oBAACQ,aAAWA;QACR,UAAU;QACV,MAAML;QACN,UAAUM,MAAM,OAAO,CAACF,OAAO;eAAIA;SAAI,GAAG,EAAE;;AAI5D;AAEA,MAAMG,mBAAmB,CAAC,EACtBf,QAAQ,EACRgB,QAAQ,EAIX;IACG,MAAMC,QAAQC,uBAAuBlB;IAErC,OAAO,WAAP,GAAO,oBAACmB,oBAAkBA;QAAC,OAAOF;OAAQD;AAC9C;AAMA,MAAMI,qBAAqB,CAAC,EAAEC,QAAQ,EAAEhB,IAAI,EAAiD;IACzF,MAAMN,SAASuB;IACf,MAAMtB,WAAWuB,QACb,IAAM1B,kBAAkB2B,KAAK,KAAK,CAACH,WAAWtB,SAC9C;QAACsB;QAAUtB;KAAO;IAKtB,OAAO,WAAP,GACI,oBAAC0B,eAAaA,MAAAA,WAAAA,GACV,oBAACV,kBAAgBA;QAAC,KAAKf,SAAS,EAAE;QAAE,UAAUA;qBAC1C,oBAACG,UAAQA;QAAC,MAAME;;AAIhC;AAEA,MAAMqB,cAAc,CAAC,EAAErB,IAAI,EAA+B,GAC/C,WAAP,GACI,oBAAC;QACG,OAAO;YACH,SAAS;YACT,WAAW;YACX,iBAAiB;YACjB,QAAQ;YACR,gBAAgB;YAChB,YAAY;YACZ,OAAO;QACX;OAECK,oBAAoBL;AAKjC,MAAMsB,sBAAsBvB,SAAS,CAAC,EAAEC,IAAI,EAA+B;IACvE,MAAMC,gBAAgBC;IACtB,MAAMqB,cAActB,cAAc,WAAW,IAAI;IAEjD,IAAIsB,aACA,OAAO,WAAP,GAAO,oBAACR,oBAAkBA;QAAC,UAAUI,KAAK,SAAS,CAACK,KAAKD;QAAe,MAAMvB;;IAGlF,OAAO,WAAP,GAAO,oBAACqB,aAAWA;QAAC,MAAMrB;;AAC9B;AAMA,MAAMyB,cAAc,CAAC,EAAEzB,IAAI,EAA+B;IACtD,MAAMN,SAASuB;IACf,MAAMS,aAAaC;IACnB,MAAMC,cAAcC;IAIpB,IAAID,aACA,OAAO,WAAP,GACI,oBAACE,WAASA,MAAAA,WAAAA,GACN,oBAACC,qBAAmBA;QAAC,OAAOC;OACvBC,qBAAqBL,aAAa5B;IAMnD,IAAI0B,YACA,OAAO,WAAP,GACI,oBAACI,WAASA,MAAAA,WAAAA,GACN,oBAAChC,UAAQA;QAAC,MAAME;;IAK5B,IAAI,CAACN,OAAO,SAAS,IACjB,OAAO;IAGX,OAAO,WAAP,GAAO,oBAAC4B,qBAAmBA;QAAC,MAAMtB;;AACtC;AAEO,MAAMkC,uBAAuB,CAAC,EAAEC,OAAO,EAAkB,GACrD,WAAP,GAAO,oBAACV,aAAWA;QAAC,MAAMW,kBAAkB,WAAW,CAACD;;AAGrD,MAAME,wBAAwB,CAAC,EAAEC,MAAM,EAAEH,OAAO,EAAqC,GACjF,WAAP,GAAO,oBAACV,aAAWA;QAAC,MAAMW,kBAAkB,WAAW,CAACD,SAASG,QAAQ"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The main page content area of a layout. Every layout starts with it, and keeps it: it can be moved and
3
+ * styled, but not deleted, renamed or inserted again.
4
+ */
5
+ export declare const LayoutContent: import("@webiny/website-builder-sdk").Component;
6
+ /**
7
+ * A named page content area, inserted in the layout editor (only there). Pages fill each named area in
8
+ * the page editor.
9
+ */
10
+ export declare const NamedContent: import("@webiny/website-builder-sdk").Component;
@@ -0,0 +1,32 @@
1
+ "use client";
2
+ import { LayoutContentArea, createTextInput } from "@webiny/website-builder-sdk";
3
+ import { createComponent } from "../createComponent.js";
4
+ import { MainContentComponent, NamedContentComponent } from "./LayoutContent.js";
5
+ const LayoutContent_manifest_image = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M3 5v14h18V5H3zm16 12H5V7h14v10zM7 9h10v2H7V9zm0 4h7v2H7v-2z"/></svg>';
6
+ const LayoutContent = createComponent(MainContentComponent, {
7
+ name: LayoutContentArea.MAIN_COMPONENT,
8
+ label: "Main content",
9
+ group: "basic",
10
+ hideFromToolbar: true,
11
+ useInAiContentGeneration: false,
12
+ inputs: [],
13
+ image: LayoutContent_manifest_image
14
+ });
15
+ const NamedContent = createComponent(NamedContentComponent, {
16
+ name: LayoutContentArea.NAMED_COMPONENT,
17
+ label: "Named content",
18
+ group: "basic",
19
+ useInAiContentGeneration: false,
20
+ inputs: [
21
+ createTextInput({
22
+ name: LayoutContentArea.NAME_INPUT,
23
+ label: "Area name",
24
+ translatable: false,
25
+ description: "Shown in the page editor so authors can tell the areas apart. Renaming an area keeps the content pages added to it."
26
+ })
27
+ ],
28
+ image: LayoutContent_manifest_image
29
+ });
30
+ export { LayoutContent, NamedContent };
31
+
32
+ //# sourceMappingURL=LayoutContent.manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorComponents/LayoutContent.manifest.js","sources":["../../src/editorComponents/LayoutContent.manifest.ts"],"sourcesContent":["\"use client\";\nimport { createTextInput, LayoutContentArea } from \"@webiny/website-builder-sdk\";\nimport { createComponent } from \"~/createComponent.js\";\nimport { MainContentComponent, NamedContentComponent } from \"./LayoutContent.js\";\n\nconst image = `<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\"><path d=\"M3 5v14h18V5H3zm16 12H5V7h14v10zM7 9h10v2H7V9zm0 4h7v2H7v-2z\"/></svg>`;\n\n/**\n * The main page content area of a layout. Every layout starts with it, and keeps it: it can be moved and\n * styled, but not deleted, renamed or inserted again.\n */\nexport const LayoutContent = createComponent(MainContentComponent, {\n name: LayoutContentArea.MAIN_COMPONENT,\n label: \"Main content\",\n group: \"basic\",\n hideFromToolbar: true,\n useInAiContentGeneration: false,\n inputs: [],\n image\n});\n\n/**\n * A named page content area, inserted in the layout editor (only there). Pages fill each named area in\n * the page editor.\n */\nexport const NamedContent = createComponent(NamedContentComponent, {\n name: LayoutContentArea.NAMED_COMPONENT,\n label: \"Named content\",\n group: \"basic\",\n useInAiContentGeneration: false,\n inputs: [\n createTextInput({\n name: LayoutContentArea.NAME_INPUT,\n label: \"Area name\",\n // A label for people: pages' content of the area is stored by the area element's id.\n translatable: false,\n description:\n \"Shown in the page editor so authors can tell the areas apart. Renaming an area keeps the content pages added to it.\"\n })\n ],\n image\n});\n"],"names":["image","LayoutContent","createComponent","MainContentComponent","LayoutContentArea","NamedContent","NamedContentComponent","createTextInput"],"mappings":";;;;AAKA,MAAMA,+BAAQ;AAMP,MAAMC,gBAAgBC,gBAAgBC,sBAAsB;IAC/D,MAAMC,kBAAkB,cAAc;IACtC,OAAO;IACP,OAAO;IACP,iBAAiB;IACjB,0BAA0B;IAC1B,QAAQ,EAAE;IACVJ,OAAAA;AACJ;AAMO,MAAMK,eAAeH,gBAAgBI,uBAAuB;IAC/D,MAAMF,kBAAkB,eAAe;IACvC,OAAO;IACP,OAAO;IACP,0BAA0B;IAC1B,QAAQ;QACJG,gBAAgB;YACZ,MAAMH,kBAAkB,UAAU;YAClC,OAAO;YAEP,cAAc;YACd,aACI;QACR;KACH;IACDJ,OAAAA;AACJ"}
@@ -0,0 +1,2 @@
1
+ import type { LayoutContentArea } from "@webiny/website-builder-sdk";
2
+ export declare const getContentAreaLabel: (area: LayoutContentArea) => string;
@@ -0,0 +1,7 @@
1
+ const getContentAreaLabel = (area)=>{
2
+ if (area.isMain()) return "Main content";
3
+ return area.name() ?? "Named content";
4
+ };
5
+ export { getContentAreaLabel };
6
+
7
+ //# sourceMappingURL=LayoutContentLabel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorComponents/LayoutContentLabel.js","sources":["../../src/editorComponents/LayoutContentLabel.ts"],"sourcesContent":["import type { LayoutContentArea } from \"@webiny/website-builder-sdk\";\n\n// What a content area is called on the canvas. Its name is only a label: content is stored by its slot.\nexport const getContentAreaLabel = (area: LayoutContentArea) => {\n if (area.isMain()) {\n return \"Main content\";\n }\n return area.name() ?? \"Named content\";\n};\n"],"names":["getContentAreaLabel","area"],"mappings":"AAGO,MAAMA,sBAAsB,CAACC;IAChC,IAAIA,KAAK,MAAM,IACX,OAAO;IAEX,OAAOA,KAAK,IAAI,MAAM;AAC1B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { LayoutContentArea } from "@webiny/website-builder-sdk";
3
+ import { getContentAreaLabel } from "./LayoutContentLabel.js";
4
+ const LayoutContentLabel_test_element = (id, name)=>({
5
+ id,
6
+ component: {
7
+ name
8
+ }
9
+ });
10
+ describe("getContentAreaLabel", ()=>{
11
+ it('labels the main content area "Main content", and a named one by its own name, with no "Named content ·" prefix', ()=>{
12
+ const main = LayoutContentArea.fromElement(LayoutContentLabel_test_element("content", "Webiny/LayoutContent"));
13
+ const named = LayoutContentArea.fromElement(LayoutContentLabel_test_element("sidebar", "Webiny/NamedContent"), "sidebar");
14
+ expect(getContentAreaLabel(main)).toBe("Main content");
15
+ expect(getContentAreaLabel(named)).toBe("sidebar");
16
+ });
17
+ it('labels a named content area without a name "Named content"', ()=>{
18
+ const area = LayoutContentArea.fromElement(LayoutContentLabel_test_element("area", "Webiny/NamedContent"), " ");
19
+ expect(getContentAreaLabel(area)).toBe("Named content");
20
+ });
21
+ });
22
+
23
+ //# sourceMappingURL=LayoutContentLabel.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"editorComponents/LayoutContentLabel.test.js","sources":["../../src/editorComponents/LayoutContentLabel.test.ts"],"sourcesContent":["import { describe, it, expect } from \"vitest\";\nimport { LayoutContentArea } from \"@webiny/website-builder-sdk\";\nimport { getContentAreaLabel } from \"./LayoutContentLabel.js\";\n\nconst element = (id: string, name: string) => ({ id, component: { name } });\n\ndescribe(\"getContentAreaLabel\", () => {\n it('labels the main content area \"Main content\", and a named one by its own name, with no \"Named content ·\" prefix', () => {\n const main = LayoutContentArea.fromElement(element(\"content\", \"Webiny/LayoutContent\"));\n const named = LayoutContentArea.fromElement(\n element(\"sidebar\", \"Webiny/NamedContent\"),\n \"sidebar\"\n );\n\n expect(getContentAreaLabel(main)).toBe(\"Main content\");\n expect(getContentAreaLabel(named)).toBe(\"sidebar\");\n });\n\n it('labels a named content area without a name \"Named content\"', () => {\n const area = LayoutContentArea.fromElement(element(\"area\", \"Webiny/NamedContent\"), \" \");\n\n expect(getContentAreaLabel(area)).toBe(\"Named content\");\n });\n});\n"],"names":["element","id","name","describe","it","main","LayoutContentArea","named","expect","getContentAreaLabel","area"],"mappings":";;;AAIA,MAAMA,kCAAU,CAACC,IAAYC,OAAkB;QAAED;QAAI,WAAW;YAAEC;QAAK;IAAE;AAEzEC,SAAS,uBAAuB;IAC5BC,GAAG,kHAAkH;QACjH,MAAMC,OAAOC,kBAAkB,WAAW,CAACN,gCAAQ,WAAW;QAC9D,MAAMO,QAAQD,kBAAkB,WAAW,CACvCN,gCAAQ,WAAW,wBACnB;QAGJQ,OAAOC,oBAAoBJ,OAAO,IAAI,CAAC;QACvCG,OAAOC,oBAAoBF,QAAQ,IAAI,CAAC;IAC5C;IAEAH,GAAG,8DAA8D;QAC7D,MAAMM,OAAOJ,kBAAkB,WAAW,CAACN,gCAAQ,QAAQ,wBAAwB;QAEnFQ,OAAOC,oBAAoBC,OAAO,IAAI,CAAC;IAC3C;AACJ"}
@@ -5,6 +5,7 @@ import { Lexical } from "./Lexical.manifest.js";
5
5
  import { Root } from "./Root.manifest.js";
6
6
  import { GridColumn } from "./GridColumn.manifest.js";
7
7
  import { Fragment } from "./Fragment.manifest.js";
8
+ import { LayoutContent, NamedContent } from "./LayoutContent.manifest.js";
8
9
  const editorComponents = [
9
10
  Root,
10
11
  Box,
@@ -12,7 +13,9 @@ const editorComponents = [
12
13
  GridColumn,
13
14
  Image,
14
15
  Lexical,
15
- Fragment
16
+ Fragment,
17
+ LayoutContent,
18
+ NamedContent
16
19
  ];
17
20
  export { editorComponents };
18
21
 
@@ -1 +1 @@
1
- {"version":3,"file":"editorComponents/index.js","sources":["../../src/editorComponents/index.ts"],"sourcesContent":["import { Box } from \"./Box.manifest.js\";\nimport { Grid } from \"./Grid.manifest.js\";\nimport { Image } from \"./Image.manifest.js\";\nimport { Lexical } from \"./Lexical.manifest.js\";\nimport { Root } from \"./Root.manifest.js\";\nimport { GridColumn } from \"./GridColumn.manifest.js\";\nimport { Fragment } from \"./Fragment.manifest.js\";\n\nexport const editorComponents = [Root, Box, Grid, GridColumn, Image, Lexical, Fragment];\n"],"names":["editorComponents","Root","Box","Grid","GridColumn","Image","Lexical","Fragment"],"mappings":";;;;;;;AAQO,MAAMA,mBAAmB;IAACC;IAAMC;IAAKC;IAAMC;IAAYC;IAAOC;IAASC;CAAS"}
1
+ {"version":3,"file":"editorComponents/index.js","sources":["../../src/editorComponents/index.ts"],"sourcesContent":["import { Box } from \"./Box.manifest.js\";\nimport { Grid } from \"./Grid.manifest.js\";\nimport { Image } from \"./Image.manifest.js\";\nimport { Lexical } from \"./Lexical.manifest.js\";\nimport { Root } from \"./Root.manifest.js\";\nimport { GridColumn } from \"./GridColumn.manifest.js\";\nimport { Fragment } from \"./Fragment.manifest.js\";\nimport { LayoutContent, NamedContent } from \"./LayoutContent.manifest.js\";\n\nexport const editorComponents = [\n Root,\n Box,\n Grid,\n GridColumn,\n Image,\n Lexical,\n Fragment,\n LayoutContent,\n NamedContent\n];\n"],"names":["editorComponents","Root","Box","Grid","GridColumn","Image","Lexical","Fragment","LayoutContent","NamedContent"],"mappings":";;;;;;;;AASO,MAAMA,mBAAmB;IAC5BC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;IACAC;CACH"}
@@ -0,0 +1,33 @@
1
+ import React from "react";
2
+ import { type Asset } from "@webiny/website-builder-sdk";
3
+ export interface BackgroundImageProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "style"> {
4
+ /** The image value (unified `Asset` or a legacy value — both accepted). */
5
+ image: Asset;
6
+ /** Content rendered on top of the background (auto-stacked above the image). */
7
+ children?: React.ReactNode;
8
+ /** Class applied to the wrapper element. */
9
+ className?: string;
10
+ /** Styles merged into the wrapper. Give it a height (e.g. `minHeight`). */
11
+ style?: React.CSSProperties;
12
+ /** Class applied to the background `<img>`. */
13
+ imgClassName?: string;
14
+ /** Explicit alt text; falls back to the image's stored alt. Empty = decorative. */
15
+ alt?: string;
16
+ /** Delivery width requested for the background image. Defaults to 1920. */
17
+ width?: number;
18
+ /**
19
+ * Responsive URL builder — e.g. `({ src, width }) => \`${src}?width=${width}&format=auto\``.
20
+ * When provided, a `srcSet` is generated from `widths`.
21
+ */
22
+ loader?: (params: {
23
+ src: string;
24
+ width: number;
25
+ }) => string;
26
+ /** Candidate widths for the generated `srcSet`. */
27
+ widths?: number[];
28
+ /** The `sizes` attribute (defaults to `100vw`, since backgrounds are usually full-bleed). */
29
+ sizes?: string;
30
+ /** Native loading strategy for the background image. */
31
+ loading?: "eager" | "lazy";
32
+ }
33
+ export declare function BackgroundImage({ image, children, className, style, imgClassName, alt, width, loader, widths, sizes, loading, ...rest }: BackgroundImageProps): React.JSX.Element;
@@ -0,0 +1,61 @@
1
+ import react from "react";
2
+ import { normalizeToAsset } from "@webiny/website-builder-sdk";
3
+ const DEFAULT_WIDTHS = [
4
+ 640,
5
+ 750,
6
+ 828,
7
+ 1080,
8
+ 1200,
9
+ 1920,
10
+ 2048
11
+ ];
12
+ function BackgroundImage({ image, children, className, style, imgClassName, alt, width = 1920, loader, widths = DEFAULT_WIDTHS, sizes = "100vw", loading, ...rest }) {
13
+ const asset = normalizeToAsset(image);
14
+ const src = asset?.src ?? "";
15
+ const focalPoint = asset?.image?.focalPoint ?? {
16
+ x: 0.5,
17
+ y: 0.5
18
+ };
19
+ const resolvedAlt = alt ?? asset?.image?.alt ?? "";
20
+ const resolvedSrc = loader ? loader({
21
+ src,
22
+ width
23
+ }) : src;
24
+ const srcSet = loader ? widths.map((w)=>`${loader({
25
+ src,
26
+ width: w
27
+ })} ${w}w`).join(", ") || void 0 : void 0;
28
+ return /*#__PURE__*/ react.createElement("div", {
29
+ ...rest,
30
+ className: className,
31
+ style: {
32
+ position: "relative",
33
+ overflow: "hidden",
34
+ ...style
35
+ }
36
+ }, /*#__PURE__*/ react.createElement("img", {
37
+ className: imgClassName,
38
+ src: resolvedSrc,
39
+ srcSet: srcSet,
40
+ sizes: srcSet ? sizes : void 0,
41
+ alt: resolvedAlt,
42
+ "aria-hidden": "" === resolvedAlt ? true : void 0,
43
+ loading: loading,
44
+ style: {
45
+ position: "absolute",
46
+ inset: 0,
47
+ width: "100%",
48
+ height: "100%",
49
+ objectFit: "cover",
50
+ objectPosition: `${100 * focalPoint.x}% ${100 * focalPoint.y}%`
51
+ }
52
+ }), null != children ? /*#__PURE__*/ react.createElement("div", {
53
+ style: {
54
+ position: "relative",
55
+ zIndex: 1
56
+ }
57
+ }, children) : null);
58
+ }
59
+ export { BackgroundImage };
60
+
61
+ //# sourceMappingURL=BackgroundImage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image/BackgroundImage.js","sources":["../../src/image/BackgroundImage.tsx"],"sourcesContent":["import React from \"react\";\nimport { normalizeToAsset, type Asset } from \"@webiny/website-builder-sdk\";\n\nexport interface BackgroundImageProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"style\"> {\n /** The image value (unified `Asset` or a legacy value — both accepted). */\n image: Asset;\n /** Content rendered on top of the background (auto-stacked above the image). */\n children?: React.ReactNode;\n /** Class applied to the wrapper element. */\n className?: string;\n /** Styles merged into the wrapper. Give it a height (e.g. `minHeight`). */\n style?: React.CSSProperties;\n /** Class applied to the background `<img>`. */\n imgClassName?: string;\n /** Explicit alt text; falls back to the image's stored alt. Empty = decorative. */\n alt?: string;\n /** Delivery width requested for the background image. Defaults to 1920. */\n width?: number;\n /**\n * Responsive URL builder — e.g. `({ src, width }) => \\`${src}?width=${width}&format=auto\\``.\n * When provided, a `srcSet` is generated from `widths`.\n */\n loader?: (params: { src: string; width: number }) => string;\n /** Candidate widths for the generated `srcSet`. */\n widths?: number[];\n /** The `sizes` attribute (defaults to `100vw`, since backgrounds are usually full-bleed). */\n sizes?: string;\n /** Native loading strategy for the background image. */\n loading?: \"eager\" | \"lazy\";\n}\n\nconst DEFAULT_WIDTHS = [640, 750, 828, 1080, 1200, 1920, 2048];\n\nexport function BackgroundImage({\n image,\n children,\n className,\n style,\n imgClassName,\n alt,\n width = 1920,\n loader,\n widths = DEFAULT_WIDTHS,\n sizes = \"100vw\",\n loading,\n ...rest\n}: BackgroundImageProps) {\n const asset = normalizeToAsset(image);\n const src = asset?.src ?? \"\";\n const focalPoint = asset?.image?.focalPoint ?? { x: 0.5, y: 0.5 };\n const resolvedAlt = alt ?? asset?.image?.alt ?? \"\";\n\n const resolvedSrc = loader ? loader({ src, width }) : src;\n const srcSet = loader\n ? widths.map(w => `${loader({ src, width: w })} ${w}w`).join(\", \") || undefined\n : undefined;\n\n return (\n <div\n {...rest}\n className={className}\n style={{ position: \"relative\", overflow: \"hidden\", ...style }}\n >\n <img\n className={imgClassName}\n src={resolvedSrc}\n srcSet={srcSet}\n sizes={srcSet ? sizes : undefined}\n alt={resolvedAlt}\n aria-hidden={resolvedAlt === \"\" ? true : undefined}\n loading={loading}\n style={{\n position: \"absolute\",\n inset: 0,\n width: \"100%\",\n height: \"100%\",\n objectFit: \"cover\",\n objectPosition: `${focalPoint.x * 100}% ${focalPoint.y * 100}%`\n }}\n />\n {children != null ? (\n <div style={{ position: \"relative\", zIndex: 1 }}>{children}</div>\n ) : null}\n </div>\n );\n}\n"],"names":["DEFAULT_WIDTHS","BackgroundImage","image","children","className","style","imgClassName","alt","width","loader","widths","sizes","loading","rest","asset","normalizeToAsset","src","focalPoint","resolvedAlt","resolvedSrc","srcSet","w","undefined"],"mappings":";;AA+BA,MAAMA,iBAAiB;IAAC;IAAK;IAAK;IAAK;IAAM;IAAM;IAAM;CAAK;AAEvD,SAASC,gBAAgB,EAC5BC,KAAK,EACLC,QAAQ,EACRC,SAAS,EACTC,KAAK,EACLC,YAAY,EACZC,GAAG,EACHC,QAAQ,IAAI,EACZC,MAAM,EACNC,SAASV,cAAc,EACvBW,QAAQ,OAAO,EACfC,OAAO,EACP,GAAGC,MACgB;IACnB,MAAMC,QAAQC,iBAAiBb;IAC/B,MAAMc,MAAMF,OAAO,OAAO;IAC1B,MAAMG,aAAaH,OAAO,OAAO,cAAc;QAAE,GAAG;QAAK,GAAG;IAAI;IAChE,MAAMI,cAAcX,OAAOO,OAAO,OAAO,OAAO;IAEhD,MAAMK,cAAcV,SAASA,OAAO;QAAEO;QAAKR;IAAM,KAAKQ;IACtD,MAAMI,SAASX,SACTC,OAAO,GAAG,CAACW,CAAAA,IAAK,GAAGZ,OAAO;YAAEO;YAAK,OAAOK;QAAE,GAAG,CAAC,EAAEA,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,SAASC,SACpEA;IAEN,OAAO,WAAP,GACI,oBAAC;QACI,GAAGT,IAAI;QACR,WAAWT;QACX,OAAO;YAAE,UAAU;YAAY,UAAU;YAAU,GAAGC,KAAK;QAAC;qBAE5D,oBAAC;QACG,WAAWC;QACX,KAAKa;QACL,QAAQC;QACR,OAAOA,SAAST,QAAQW;QACxB,KAAKJ;QACL,eAAaA,AAAgB,OAAhBA,cAAqB,OAAOI;QACzC,SAASV;QACT,OAAO;YACH,UAAU;YACV,OAAO;YACP,OAAO;YACP,QAAQ;YACR,WAAW;YACX,gBAAgB,GAAGK,AAAe,MAAfA,WAAW,CAAC,CAAO,EAAE,EAAEA,AAAe,MAAfA,WAAW,CAAC,CAAO,CAAC,CAAC;QACnE;QAEHd,AAAY,QAAZA,WAAmB,WAAP,GACT,oBAAC;QAAI,OAAO;YAAE,UAAU;YAAY,QAAQ;QAAE;OAAIA,YAClD;AAGhB"}
@@ -0,0 +1,29 @@
1
+ import React from "react";
2
+ import type { AspectRatioInput, Asset } from "@webiny/website-builder-sdk";
3
+ export interface ImageComponentProps extends Omit<React.ImgHTMLAttributes<HTMLImageElement>, "src" | "width" | "height" | "style" | "alt"> {
4
+ image: Asset;
5
+ /** Target aspect ratio (e.g. `16 / 9` or `{ width, height }`). Omit for the crop's own ratio. */
6
+ aspectRatio?: AspectRatioInput;
7
+ /** Explicit alt text; falls back to the image's stored alt. */
8
+ alt?: string;
9
+ /** Class applied to the wrapper element. */
10
+ className?: string;
11
+ /** Class applied to the `<img>` element. */
12
+ imgClassName?: string;
13
+ /** Extra styles merged into the wrapper (e.g. `maxWidth`). */
14
+ style?: React.CSSProperties;
15
+ /**
16
+ * Optional responsive URL builder — e.g. `({ src, width }) => \`${src}?width=${width}\``.
17
+ * When provided, a `srcSet` is generated from `widths`. This is also the seam for a
18
+ * future server/CDN transform (crop params can be appended here).
19
+ */
20
+ loader?: (params: {
21
+ src: string;
22
+ width: number;
23
+ }) => string;
24
+ /** Candidate widths for the generated `srcSet` (defaults to a common set). */
25
+ widths?: number[];
26
+ /** The `sizes` attribute for responsive selection. */
27
+ sizes?: string;
28
+ }
29
+ export declare function Image({ image, aspectRatio, alt, className, imgClassName, style, loader, widths, sizes, ...imgProps }: ImageComponentProps): React.JSX.Element;
package/image/Image.js ADDED
@@ -0,0 +1,43 @@
1
+ import react from "react";
2
+ import { getImageProps } from "./getImageProps.js";
3
+ const DEFAULT_WIDTHS = [
4
+ 640,
5
+ 750,
6
+ 828,
7
+ 1080,
8
+ 1200,
9
+ 1920,
10
+ 2048
11
+ ];
12
+ function Image({ image, aspectRatio, alt, className, imgClassName, style, loader, widths = DEFAULT_WIDTHS, sizes, ...imgProps }) {
13
+ const { style: containerStyle, imgStyle, src, alt: resolvedAlt, width } = getImageProps(image, {
14
+ aspectRatio,
15
+ alt
16
+ });
17
+ const srcSet = loader ? widths.filter((w)=>!width || w <= width).map((w)=>`${loader({
18
+ src,
19
+ width: w
20
+ })} ${w}w`).join(", ") || void 0 : void 0;
21
+ const resolvedSrc = loader ? loader({
22
+ src,
23
+ width: width || widths[widths.length - 1]
24
+ }) : src;
25
+ return /*#__PURE__*/ react.createElement("div", {
26
+ className: className,
27
+ style: {
28
+ ...containerStyle,
29
+ ...style
30
+ }
31
+ }, /*#__PURE__*/ react.createElement("img", {
32
+ ...imgProps,
33
+ className: imgClassName,
34
+ src: resolvedSrc,
35
+ srcSet: srcSet,
36
+ sizes: sizes,
37
+ alt: resolvedAlt,
38
+ style: imgStyle
39
+ }));
40
+ }
41
+ export { Image };
42
+
43
+ //# sourceMappingURL=Image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image/Image.js","sources":["../../src/image/Image.tsx"],"sourcesContent":["import React from \"react\";\nimport type { AspectRatioInput, Asset } from \"@webiny/website-builder-sdk\";\nimport { getImageProps } from \"./getImageProps.js\";\n\nexport interface ImageComponentProps extends Omit<\n React.ImgHTMLAttributes<HTMLImageElement>,\n \"src\" | \"width\" | \"height\" | \"style\" | \"alt\"\n> {\n image: Asset;\n /** Target aspect ratio (e.g. `16 / 9` or `{ width, height }`). Omit for the crop's own ratio. */\n aspectRatio?: AspectRatioInput;\n /** Explicit alt text; falls back to the image's stored alt. */\n alt?: string;\n /** Class applied to the wrapper element. */\n className?: string;\n /** Class applied to the `<img>` element. */\n imgClassName?: string;\n /** Extra styles merged into the wrapper (e.g. `maxWidth`). */\n style?: React.CSSProperties;\n /**\n * Optional responsive URL builder — e.g. `({ src, width }) => \\`${src}?width=${width}\\``.\n * When provided, a `srcSet` is generated from `widths`. This is also the seam for a\n * future server/CDN transform (crop params can be appended here).\n */\n loader?: (params: { src: string; width: number }) => string;\n /** Candidate widths for the generated `srcSet` (defaults to a common set). */\n widths?: number[];\n /** The `sizes` attribute for responsive selection. */\n sizes?: string;\n}\n\nconst DEFAULT_WIDTHS = [640, 750, 828, 1080, 1200, 1920, 2048];\n\nexport function Image({\n image,\n aspectRatio,\n alt,\n className,\n imgClassName,\n style,\n loader,\n widths = DEFAULT_WIDTHS,\n sizes,\n ...imgProps\n}: ImageComponentProps) {\n const {\n style: containerStyle,\n imgStyle,\n src,\n alt: resolvedAlt,\n width\n } = getImageProps(image, { aspectRatio, alt });\n\n const srcSet = loader\n ? widths\n .filter(w => !width || w <= width)\n .map(w => `${loader({ src, width: w })} ${w}w`)\n .join(\", \") || undefined\n : undefined;\n\n const resolvedSrc = loader ? loader({ src, width: width || widths[widths.length - 1] }) : src;\n\n return (\n <div className={className} style={{ ...containerStyle, ...style }}>\n <img\n {...imgProps}\n className={imgClassName}\n src={resolvedSrc}\n srcSet={srcSet}\n sizes={sizes}\n alt={resolvedAlt}\n style={imgStyle}\n />\n </div>\n );\n}\n"],"names":["DEFAULT_WIDTHS","Image","image","aspectRatio","alt","className","imgClassName","style","loader","widths","sizes","imgProps","containerStyle","imgStyle","src","resolvedAlt","width","getImageProps","srcSet","w","undefined","resolvedSrc"],"mappings":";;AA+BA,MAAMA,iBAAiB;IAAC;IAAK;IAAK;IAAK;IAAM;IAAM;IAAM;CAAK;AAEvD,SAASC,MAAM,EAClBC,KAAK,EACLC,WAAW,EACXC,GAAG,EACHC,SAAS,EACTC,YAAY,EACZC,KAAK,EACLC,MAAM,EACNC,SAAST,cAAc,EACvBU,KAAK,EACL,GAAGC,UACe;IAClB,MAAM,EACF,OAAOC,cAAc,EACrBC,QAAQ,EACRC,GAAG,EACH,KAAKC,WAAW,EAChBC,KAAK,EACR,GAAGC,cAAcf,OAAO;QAAEC;QAAaC;IAAI;IAE5C,MAAMc,SAASV,SACTC,OACK,MAAM,CAACU,CAAAA,IAAK,CAACH,SAASG,KAAKH,OAC3B,GAAG,CAACG,CAAAA,IAAK,GAAGX,OAAO;YAAEM;YAAK,OAAOK;QAAE,GAAG,CAAC,EAAEA,EAAE,CAAC,CAAC,EAC7C,IAAI,CAAC,SAASC,SACnBA;IAEN,MAAMC,cAAcb,SAASA,OAAO;QAAEM;QAAK,OAAOE,SAASP,MAAM,CAACA,OAAO,MAAM,GAAG,EAAE;IAAC,KAAKK;IAE1F,OAAO,WAAP,GACI,oBAAC;QAAI,WAAWT;QAAW,OAAO;YAAE,GAAGO,cAAc;YAAE,GAAGL,KAAK;QAAC;qBAC5D,oBAAC;QACI,GAAGI,QAAQ;QACZ,WAAWL;QACX,KAAKe;QACL,QAAQH;QACR,OAAOR;QACP,KAAKK;QACL,OAAOF;;AAIvB"}
@@ -0,0 +1,42 @@
1
+ import type { CSSProperties } from "react";
2
+ import { type AspectRatioInput, type Asset } from "@webiny/website-builder-sdk";
3
+ export interface ImageProps {
4
+ /** Wrapper style: an aspect-ratio box that clips overflow. Spread onto a container. */
5
+ style: CSSProperties;
6
+ /** Image style: absolutely positioned to reveal exactly the cropped/focused region. */
7
+ imgStyle: CSSProperties;
8
+ /** The image URL. */
9
+ src: string;
10
+ /** Resolved alt text (explicit override, else the image's stored alt, else ""). */
11
+ alt: string;
12
+ /** Intrinsic (original) pixel dimensions of the asset. */
13
+ width: number;
14
+ height: number;
15
+ }
16
+ export interface ImageValue {
17
+ id: string;
18
+ name: string;
19
+ size: number;
20
+ mimeType: string;
21
+ src: string;
22
+ width: number;
23
+ height: number;
24
+ }
25
+ export interface GetImagePropsOptions {
26
+ /** Target aspect ratio. Omit to render at the crop's own aspect ratio. */
27
+ aspectRatio?: AspectRatioInput;
28
+ /** Explicit alt text; falls back to the image's stored `image.alt`. */
29
+ alt?: string;
30
+ }
31
+ /**
32
+ * Compute the props needed to render a Webiny image honoring its crop + focal point,
33
+ * using pure CSS (no image backend). Works with a plain `<img>`, SSR, and static
34
+ * export. Spread `style` onto a wrapper element and `imgStyle` onto the `<img>`.
35
+ *
36
+ * Accepts either the unified {@link Asset} shape or a legacy
37
+ * `ImageValue` (existing page snapshots) — both are normalized transparently.
38
+ *
39
+ * This is the escape hatch for custom rendering; most consumers can use the
40
+ * `<Image>` component instead.
41
+ */
42
+ export declare function getImageProps(input: Asset | ImageValue, options?: GetImagePropsOptions): ImageProps;