lib-pixelbuild 0.2.2 → 0.3.1

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 (72) hide show
  1. package/dist/builders/PageBuilder.js +42 -29
  2. package/dist/components/ButtonsComponent.js +6 -5
  3. package/dist/components/CardComponent.js +13 -7
  4. package/dist/components/FormComponent.js +3 -2
  5. package/dist/components/IconComponent.d.ts +5 -0
  6. package/dist/components/IconComponent.js +12 -0
  7. package/dist/components/ImageComponent.js +4 -3
  8. package/dist/components/ListComponent.js +1 -2
  9. package/dist/components/LoadingComponent.js +2 -2
  10. package/dist/components/MapComponent.js +10 -11
  11. package/dist/components/SliderComponent.d.ts +1 -1
  12. package/dist/components/SliderComponent.js +8 -10
  13. package/dist/components/SocialIconsComponent.js +3 -4
  14. package/dist/components/TextComponent.js +3 -2
  15. package/dist/components/VideoComponent.d.ts +4 -0
  16. package/dist/components/VideoComponent.js +34 -0
  17. package/dist/constants/ComponentEnum.d.ts +1 -0
  18. package/dist/constants/ComponentEnum.js +1 -0
  19. package/dist/designSystem/baseCss.d.ts +8 -0
  20. package/dist/designSystem/baseCss.js +406 -0
  21. package/dist/designSystem/buildSiteCss.d.ts +8 -0
  22. package/dist/designSystem/buildSiteCss.js +11 -0
  23. package/dist/designSystem/index.d.ts +6 -0
  24. package/dist/designSystem/index.js +5 -0
  25. package/dist/designSystem/theme.d.ts +9 -0
  26. package/dist/designSystem/theme.js +11 -0
  27. package/dist/designSystem/themeVars.d.ts +8 -0
  28. package/dist/designSystem/themeVars.js +9 -0
  29. package/dist/designSystem/tokens.d.ts +82 -0
  30. package/dist/designSystem/tokens.js +144 -0
  31. package/dist/elements/AlertElement.js +4 -4
  32. package/dist/elements/ButtonElement.js +5 -3
  33. package/dist/elements/ElementColWrapper.js +2 -2
  34. package/dist/elements/IconMap.js +2 -2
  35. package/dist/elements/InputElement.js +10 -9
  36. package/dist/elements/TextElement.js +4 -0
  37. package/dist/factories/ComponentFactory.d.ts +2 -1
  38. package/dist/factories/ComponentFactory.js +28 -11
  39. package/dist/index.d.ts +16 -3
  40. package/dist/index.js +14 -1
  41. package/dist/layouts/Footer.js +16 -5
  42. package/dist/layouts/Header.js +20 -10
  43. package/dist/layouts/SiteLayout.js +3 -2
  44. package/dist/renderers/BlockRenderer.d.ts +8 -0
  45. package/dist/renderers/BlockRenderer.js +68 -0
  46. package/dist/types/{SectionColumnType.d.ts → BlockType.d.ts} +2 -6
  47. package/dist/types/ComponentType.d.ts +3 -0
  48. package/dist/types/PageType.d.ts +2 -2
  49. package/dist/types/WebsiteType.d.ts +5 -0
  50. package/dist/ui/PbAlert.d.ts +10 -0
  51. package/dist/ui/PbAlert.js +8 -0
  52. package/dist/ui/PbButton.d.ts +20 -0
  53. package/dist/ui/PbButton.js +20 -0
  54. package/dist/ui/PbCol.d.ts +14 -0
  55. package/dist/ui/PbCol.js +43 -0
  56. package/dist/ui/PbContainer.d.ts +7 -0
  57. package/dist/ui/PbContainer.js +17 -0
  58. package/dist/ui/PbRow.d.ts +7 -0
  59. package/dist/ui/PbRow.js +17 -0
  60. package/dist/ui/PbSpinner.d.ts +3 -0
  61. package/dist/ui/PbSpinner.js +5 -0
  62. package/dist/ui/index.d.ts +6 -0
  63. package/dist/ui/index.js +6 -0
  64. package/dist/utils/imageCustomization.js +1 -3
  65. package/dist/utils/responsiveStyles.d.ts +2 -2
  66. package/dist/utils/responsiveStyles.js +10 -19
  67. package/package.json +1 -6
  68. package/dist/renderers/SectionRenderer.d.ts +0 -6
  69. package/dist/renderers/SectionRenderer.js +0 -88
  70. package/dist/types/SectionType.d.ts +0 -10
  71. package/dist/types/SectionType.js +0 -1
  72. /package/dist/types/{SectionColumnType.js → BlockType.js} +0 -0
@@ -1,14 +1,10 @@
1
1
  import type { StylesType } from './StylesType.js';
2
- import type { ColumnWidthType } from './ColumnWidthType.js';
3
2
  import type { ComponentType } from './ComponentType.js';
4
- import type { SectionType } from './SectionType.js';
5
- export interface SectionColumnType {
3
+ export interface BlockType {
6
4
  id: number;
7
- width: ColumnWidthType;
8
- offset: ColumnWidthType;
5
+ sectionType: 'container' | 'container-fluid';
9
6
  sort: number;
10
7
  properties: Record<string, unknown>;
11
8
  styles: StylesType;
12
9
  components: ComponentType[];
13
- childSections: SectionType[];
14
10
  }
@@ -1,5 +1,6 @@
1
1
  import type { StylesType } from './StylesType.js';
2
2
  import type { ElementType } from './ElementType.js';
3
+ import type { ColumnWidthType } from './ColumnWidthType.js';
3
4
  export interface ComponentType {
4
5
  id: number;
5
6
  componentType: string;
@@ -7,5 +8,7 @@ export interface ComponentType {
7
8
  enabled: boolean;
8
9
  properties: Record<string, unknown>;
9
10
  styles: StylesType;
11
+ width: ColumnWidthType;
12
+ offset: ColumnWidthType;
10
13
  elements: ElementType[];
11
14
  }
@@ -1,5 +1,5 @@
1
1
  import type { StylesType } from './StylesType.js';
2
- import type { SectionType } from './SectionType.js';
2
+ import type { BlockType } from './BlockType.js';
3
3
  export interface PageType {
4
4
  id: number;
5
5
  websiteId: number;
@@ -13,5 +13,5 @@ export interface PageType {
13
13
  menuType: 'link' | 'dropdown';
14
14
  properties: Record<string, unknown>;
15
15
  styles: StylesType;
16
- sections: SectionType[];
16
+ blocks: BlockType[];
17
17
  }
@@ -3,6 +3,9 @@ import type { StylesType } from './StylesType.js';
3
3
  import type { HeaderType } from './HeaderType.js';
4
4
  import type { FooterType } from './FooterType.js';
5
5
  import type { WebsitePropertiesType } from './WebsitePropertiesType.js';
6
+ import type { PartialDesignTokens } from '../designSystem/tokens.js';
7
+ /** Estilos padrão por tipo de componente (ex.: todos os botões, títulos...). */
8
+ export type ComponentDefaults = Record<string, Partial<StylesType>>;
6
9
  export interface WebsiteType {
7
10
  id: number;
8
11
  name: string;
@@ -13,6 +16,8 @@ export interface WebsiteType {
13
16
  footer: FooterType;
14
17
  properties: WebsitePropertiesType;
15
18
  styles: StylesType;
19
+ designSystem?: PartialDesignTokens;
20
+ componentDefaults?: ComponentDefaults;
16
21
  enabled: boolean;
17
22
  maintenance?: boolean;
18
23
  publishedAt: string | null;
@@ -0,0 +1,10 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ /**
3
+ * Alerta próprio do design system. Substitui o `Alert` do react-bootstrap.
4
+ */
5
+ export declare function PbAlert({ variant, title, style, children }: {
6
+ readonly variant?: string;
7
+ readonly title?: ReactNode;
8
+ readonly style?: CSSProperties;
9
+ readonly children?: ReactNode;
10
+ }): import("react").JSX.Element;
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Alerta próprio do design system. Substitui o `Alert` do react-bootstrap.
4
+ */
5
+ export function PbAlert({ variant = 'info', title, style, children }) {
6
+ const classes = ['pb-alert', variant ? `pb-alert-${variant}` : 'pb-alert-info'].filter(Boolean).join(' ');
7
+ return (_jsxs("div", { className: classes, role: "alert", style: style, children: [title && _jsx("div", { className: "pb-alert-title", children: title }), children] }));
8
+ }
@@ -0,0 +1,20 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ export type PbButtonVariant = 'primary' | 'secondary' | 'success' | 'danger' | 'warning' | 'info' | 'light' | 'dark' | 'outline-primary' | 'outline-secondary' | 'link';
3
+ /**
4
+ * Botão próprio do design system. Substitui o `Button` do react-bootstrap,
5
+ * mantendo o comportamento de link (`href`) e botão de formulário.
6
+ */
7
+ export declare function PbButton({ as, href, target, rel, type, variant, size, disabled, onClick, className, style, children }: {
8
+ readonly as?: string;
9
+ readonly href?: string;
10
+ readonly target?: string;
11
+ readonly rel?: string;
12
+ readonly type?: 'button' | 'submit' | 'reset';
13
+ readonly variant?: string;
14
+ readonly size?: 'sm' | 'lg';
15
+ readonly disabled?: boolean;
16
+ readonly onClick?: (event: React.MouseEvent<HTMLElement>) => void;
17
+ readonly className?: string;
18
+ readonly style?: CSSProperties;
19
+ readonly children?: ReactNode;
20
+ }): import("react").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Botão próprio do design system. Substitui o `Button` do react-bootstrap,
4
+ * mantendo o comportamento de link (`href`) e botão de formulário.
5
+ */
6
+ export function PbButton({ as, href, target, rel, type, variant = 'primary', size, disabled, onClick, className, style, children }) {
7
+ const isAnchor = Boolean(href) || as === 'a';
8
+ const classes = [
9
+ 'pb-button',
10
+ variant ? `pb-button-${variant}` : 'pb-button-primary',
11
+ size ? `pb-button-${size}` : '',
12
+ className || ''
13
+ ]
14
+ .filter(Boolean)
15
+ .join(' ');
16
+ if (isAnchor) {
17
+ return (_jsx("a", { href: href, target: target, rel: rel || 'noopener noreferrer', className: classes, style: style, onClick: onClick, children: children }));
18
+ }
19
+ return (_jsx("button", { type: type || 'button', disabled: disabled, className: classes, style: style, onClick: onClick, children: children }));
20
+ }
@@ -0,0 +1,14 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ import type { ColumnWidthType } from '../types/ColumnWidthType.js';
3
+ /**
4
+ * Célula do grid de 12 colunas. Responde por breakpoint gerando um `<style>`
5
+ * próprio quando `width`/`offset` variam entre dispositivos.
6
+ */
7
+ export declare function PbCol({ colId, width, offset, style, className, children, ...rest }: {
8
+ readonly colId?: number | string;
9
+ readonly width?: ColumnWidthType;
10
+ readonly offset?: ColumnWidthType;
11
+ readonly style?: CSSProperties;
12
+ readonly className?: string;
13
+ readonly children?: ReactNode;
14
+ } & Record<string, unknown>): import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ const BREAKPOINTS = [
14
+ { key: 'sm', min: 576 },
15
+ { key: 'md', min: 768 },
16
+ { key: 'lg', min: 992 },
17
+ { key: 'xl', min: 1200 }
18
+ ];
19
+ function gridColumn(span, offset) {
20
+ const start = offset && offset > 0 ? offset + 1 : undefined;
21
+ return start ? `${start} / span ${span}` : `span ${span}`;
22
+ }
23
+ /**
24
+ * Célula do grid de 12 colunas. Responde por breakpoint gerando um `<style>`
25
+ * próprio quando `width`/`offset` variam entre dispositivos.
26
+ */
27
+ export function PbCol(_a) {
28
+ var { colId, width, offset, style, className, children } = _a, rest = __rest(_a, ["colId", "width", "offset", "style", "className", "children"]);
29
+ const w = width || {};
30
+ const off = offset || {};
31
+ const base = w.xs || 12;
32
+ const cls = `pb-col pb-col-${colId !== null && colId !== void 0 ? colId : 'static'}`;
33
+ const inline = Object.assign({ gridColumn: gridColumn(base, off.xs), minWidth: 0 }, style);
34
+ const rules = [];
35
+ for (const bp of BREAKPOINTS) {
36
+ const span = w[bp.key];
37
+ const offSpan = off[bp.key];
38
+ if (span || offSpan) {
39
+ rules.push(`@media (min-width:${bp.min}px){.${cls}{grid-column:${gridColumn(span || base, offSpan)}}}`);
40
+ }
41
+ }
42
+ return (_jsxs(_Fragment, { children: [rules.length > 0 && _jsx("style", { children: rules.join('') }), _jsx("div", Object.assign({ className: `${cls} ${className || ''}`.trim(), style: inline }, rest, { children: children }))] }));
43
+ }
@@ -0,0 +1,7 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ export declare function PbContainer({ fluid, style, className, children, ...rest }: {
3
+ readonly fluid?: boolean;
4
+ readonly style?: CSSProperties;
5
+ readonly className?: string;
6
+ readonly children?: ReactNode;
7
+ } & Record<string, unknown>): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ export function PbContainer(_a) {
14
+ var { fluid, style, className, children } = _a, rest = __rest(_a, ["fluid", "style", "className", "children"]);
15
+ const classes = ['pb-container', fluid ? 'pb-container-fluid' : '', className || ''].filter(Boolean).join(' ');
16
+ return (_jsx("div", Object.assign({ className: classes, style: style }, rest, { children: children })));
17
+ }
@@ -0,0 +1,7 @@
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ export declare function PbRow({ id, style, className, children, ...rest }: {
3
+ readonly id?: string;
4
+ readonly style?: CSSProperties;
5
+ readonly className?: string;
6
+ readonly children?: ReactNode;
7
+ } & Record<string, unknown>): import("react").JSX.Element;
@@ -0,0 +1,17 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ export function PbRow(_a) {
14
+ var { id, style, className, children } = _a, rest = __rest(_a, ["id", "style", "className", "children"]);
15
+ const classes = ['pb-row', className || ''].filter(Boolean).join(' ');
16
+ return (_jsx("div", Object.assign({ id: id, className: classes, style: style }, rest, { children: children })));
17
+ }
@@ -0,0 +1,3 @@
1
+ export declare function PbSpinner({ size }: {
2
+ readonly size?: 'sm';
3
+ }): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ export function PbSpinner({ size }) {
3
+ const classes = ['pb-spinner', size === 'sm' ? 'pb-spinner-sm' : ''].filter(Boolean).join(' ');
4
+ return _jsx("span", { className: classes, "aria-hidden": "true" });
5
+ }
@@ -0,0 +1,6 @@
1
+ export { PbContainer } from './PbContainer.js';
2
+ export { PbRow } from './PbRow.js';
3
+ export { PbCol } from './PbCol.js';
4
+ export { PbButton } from './PbButton.js';
5
+ export { PbSpinner } from './PbSpinner.js';
6
+ export { PbAlert } from './PbAlert.js';
@@ -0,0 +1,6 @@
1
+ export { PbContainer } from './PbContainer.js';
2
+ export { PbRow } from './PbRow.js';
3
+ export { PbCol } from './PbCol.js';
4
+ export { PbButton } from './PbButton.js';
5
+ export { PbSpinner } from './PbSpinner.js';
6
+ export { PbAlert } from './PbAlert.js';
@@ -4,8 +4,6 @@ export function resolveImageElement(component, element) {
4
4
  }
5
5
  const properties = component.properties || {};
6
6
  const useShared = properties.imageCustomization !== 'separate';
7
- const imageStyles = useShared
8
- ? properties.imageStyles || {}
9
- : element.styles;
7
+ const imageStyles = useShared ? properties.imageStyles || {} : element.styles;
10
8
  return Object.assign(Object.assign({}, element), { styles: Object.assign({ width: '100%' }, imageStyles) });
11
9
  }
@@ -1,6 +1,6 @@
1
- import type { SectionType } from '../types/SectionType.js';
1
+ import type { BlockType } from '../types/BlockType.js';
2
2
  import type { StylesType } from '../types/StylesType.js';
3
3
  declare const BREAKPOINT_MIN_WIDTHS: Record<string, number>;
4
4
  export declare function buildResponsiveCssForStyles(selector: string, styles: StylesType | undefined): string;
5
- export declare function buildResponsiveCss(sections: SectionType[]): string;
5
+ export declare function buildResponsiveCss(blocks: BlockType[]): string;
6
6
  export { BREAKPOINT_MIN_WIDTHS };
@@ -2,14 +2,14 @@ const BREAKPOINT_MIN_WIDTHS = {
2
2
  sm: 576,
3
3
  md: 768,
4
4
  lg: 992,
5
- xl: 1200,
5
+ xl: 1200
6
6
  };
7
7
  const SKIP_KEYS = new Set([
8
8
  'responsive',
9
9
  'customCss',
10
10
  'fluid',
11
11
  'backgroundGradientColorStart',
12
- 'backgroundGradientColorEnd',
12
+ 'backgroundGradientColorEnd'
13
13
  ]);
14
14
  function kebabCase(key) {
15
15
  return key.replace(/([A-Z])/g, '-$1').toLowerCase();
@@ -56,26 +56,17 @@ function buildRules(selector, responsive) {
56
56
  export function buildResponsiveCssForStyles(selector, styles) {
57
57
  return buildRules(selector, styles === null || styles === void 0 ? void 0 : styles.responsive).join('');
58
58
  }
59
- export function buildResponsiveCss(sections) {
59
+ export function buildResponsiveCss(blocks) {
60
+ var _a, _b, _c;
60
61
  const rules = [];
61
- const visitSection = (section) => {
62
- var _a, _b, _c, _d;
63
- rules.push(...buildRules(`#section-${section.id}`, (_a = section.styles) === null || _a === void 0 ? void 0 : _a.responsive));
64
- for (const column of section.columns) {
65
- rules.push(...buildRules(`#column-${column.id}`, (_b = column.styles) === null || _b === void 0 ? void 0 : _b.responsive));
66
- for (const component of column.components) {
67
- rules.push(...buildRules(`[data-pb-component="${component.id}"]`, (_c = component.styles) === null || _c === void 0 ? void 0 : _c.responsive));
68
- for (const element of component.elements) {
69
- rules.push(...buildRules(`[data-pb-element="${element.id}"]`, (_d = element.styles) === null || _d === void 0 ? void 0 : _d.responsive));
70
- }
71
- }
72
- for (const childSection of column.childSections) {
73
- visitSection(childSection);
62
+ for (const block of blocks) {
63
+ rules.push(...buildRules(`[data-pb-block="${block.id}"]`, (_a = block.styles) === null || _a === void 0 ? void 0 : _a.responsive));
64
+ for (const component of block.components) {
65
+ rules.push(...buildRules(`[data-pb-component="${component.id}"]`, (_b = component.styles) === null || _b === void 0 ? void 0 : _b.responsive));
66
+ for (const element of component.elements) {
67
+ rules.push(...buildRules(`[data-pb-element="${element.id}"]`, (_c = element.styles) === null || _c === void 0 ? void 0 : _c.responsive));
74
68
  }
75
69
  }
76
- };
77
- for (const section of sections) {
78
- visitSection(section);
79
70
  }
80
71
  return rules.join('');
81
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib-pixelbuild",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
4
4
  "engines": {
5
5
  "node": "^24.0.0",
6
6
  "npm": ">=10"
@@ -66,12 +66,10 @@
66
66
  "@testing-library/user-event": "^14.6.1",
67
67
  "@types/node": "^24.0.13",
68
68
  "@types/react": "^18.3.3",
69
- "@types/react-bootstrap": "^1.0.1",
70
69
  "@types/react-dom": "^18.3.0",
71
70
  "@typescript-eslint/eslint-plugin": "^8.35.0",
72
71
  "@typescript-eslint/parser": "^8.35.0",
73
72
  "@vitejs/plugin-react": "^6.0.4",
74
- "bootstrap": "^5.3.7",
75
73
  "dompurify": "^3.2.6",
76
74
  "eslint": "^10.8.0",
77
75
  "eslint-plugin-react-hooks": "^7.1.1",
@@ -82,7 +80,6 @@
82
80
  "lint-staged": "^15.5.2",
83
81
  "prettier": "^3.6.2",
84
82
  "react": "^18.2.0",
85
- "react-bootstrap": "^2.10.10",
86
83
  "react-dom": "^18.2.0",
87
84
  "react-ga4": "^2.1.0",
88
85
  "react-helmet-async": "^2.0.5",
@@ -102,10 +99,8 @@
102
99
  ]
103
100
  },
104
101
  "peerDependencies": {
105
- "bootstrap": "^5.0.0",
106
102
  "dompurify": "^3.2.6",
107
103
  "react": "^18.0.0",
108
- "react-bootstrap": "^2.10.10",
109
104
  "react-dom": "^18.0.0",
110
105
  "react-ga4": "^2.1.0",
111
106
  "react-helmet-async": "^2.0.5",
@@ -1,6 +0,0 @@
1
- import type { SectionType } from '../types/SectionType.js';
2
- declare const SectionRenderer: import("react").NamedExoticComponent<{
3
- readonly sections: SectionType[];
4
- readonly editionMode?: boolean;
5
- }>;
6
- export { SectionRenderer };
@@ -1,88 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { memo, useMemo } from 'react';
3
- import { Container, Row, Col } from 'react-bootstrap';
4
- import { ComponentFactory } from '../factories/ComponentFactory.js';
5
- import { orderBySort } from '../utils/orderBySort.js';
6
- import { buildResponsiveCss } from '../utils/responsiveStyles.js';
7
- const componentFactory = new ComponentFactory();
8
- function colWidthValue(width, offset) {
9
- if (width === undefined && offset === undefined)
10
- return undefined;
11
- if (offset !== undefined) {
12
- return { span: width !== null && width !== void 0 ? width : 12, offset };
13
- }
14
- return width;
15
- }
16
- const ColumnContent = memo(function ColumnContent({ column, editionMode }) {
17
- const components = useMemo(() => orderBySort(column.components.filter((c) => c.enabled)), [column.components]);
18
- const childSections = useMemo(() => orderBySort(column.childSections), [column.childSections]);
19
- if (editionMode && components.length === 0 && childSections.length === 0) {
20
- return (_jsxs("div", { "data-pixelbuild-empty-column": column.id, style: {
21
- minHeight: 80,
22
- display: 'flex',
23
- alignItems: 'center',
24
- justifyContent: 'center',
25
- gap: 6,
26
- border: '1.5px dashed #c4d0dc',
27
- color: '#94a3b8',
28
- fontSize: 13,
29
- cursor: 'pointer',
30
- textAlign: 'center',
31
- }, children: [_jsx("span", { style: { fontSize: 18, lineHeight: 1 }, children: "+" }), "Adicionar componente"] }));
32
- }
33
- return (_jsxs(_Fragment, { children: [components.map((component) => componentFactory.build(component, editionMode)), childSections.map((childSection) => (_jsx(SectionContent, { section: childSection, editionMode: editionMode }, childSection.id)))] }));
34
- });
35
- function gridClass(id) {
36
- return `pixelbuild-grid-${String(id).replace(/[^a-zA-Z0-9_-]/g, '_')}`;
37
- }
38
- const GridRenderer = memo(function GridRenderer({ section, editionMode }) {
39
- const grid = gridClass(section.id);
40
- const columns = section.columns;
41
- const css = useMemo(() => {
42
- const rules = columns
43
- .map((column) => {
44
- const properties = column.properties || {};
45
- const row = Math.max(0, Number(properties.row) || 0);
46
- const rowSpan = Math.max(1, Number(properties.rowSpan) || 1);
47
- const xs = column.width.xs || 12;
48
- const sm = column.width.sm || xs;
49
- const md = column.width.md || sm;
50
- const columnClass = gridClass(column.id);
51
- return [
52
- `.${grid} .${columnClass}{grid-column:span ${xs};grid-row:auto;min-width:0}`,
53
- `@media (min-width:576px){.${grid} .${columnClass}{grid-column:span ${sm}}}`,
54
- `@media (min-width:768px){.${grid} .${columnClass}{grid-column:span ${md};grid-row:${row + 1}/span ${rowSpan}}}`
55
- ].join('');
56
- })
57
- .join('');
58
- return `.${grid}{display:grid;grid-template-columns:repeat(12,minmax(0,1fr));gap:1rem}${rules}`;
59
- }, [grid, columns]);
60
- return (_jsxs(_Fragment, { children: [_jsx("style", { children: css }), _jsx("div", { id: `section-${section.id}`, "data-pb-section": section.sectionType === 'row' ? section.id : undefined, className: grid, style: section.sectionType === 'row' ? section.styles : undefined, children: columns.map((column) => (_jsx("div", { id: `column-${column.id}`, className: gridClass(column.id), style: column.styles, children: _jsx(ColumnContent, { column: column, editionMode: editionMode }) }, column.id))) })] }));
61
- });
62
- const SectionContent = memo(function SectionContent({ section, editionMode }) {
63
- const usesGrid = useMemo(() => section.columns.some((column) => { var _a, _b; return ((_a = column.properties) === null || _a === void 0 ? void 0 : _a.row) !== undefined || Number((_b = column.properties) === null || _b === void 0 ? void 0 : _b.rowSpan) > 1; }), [section.columns]);
64
- const content = useMemo(() => {
65
- if (usesGrid) {
66
- return _jsx(GridRenderer, { section: section, editionMode: editionMode });
67
- }
68
- return (_jsx(Row, { id: `section-${section.id}`, "data-pb-section": section.sectionType === 'row' ? section.id : undefined, style: section.sectionType === 'row' ? section.styles : undefined, children: section.columns.map((column) => (_jsx(ColumnRenderer, { column: column, editionMode: editionMode }, column.id))) }));
69
- }, [usesGrid, section, editionMode]);
70
- if (section.sectionType === 'container-fluid') {
71
- return (_jsx(Container, { fluid: true, "data-pb-section": section.id, style: section.styles, children: content }));
72
- }
73
- if (section.sectionType === 'container') {
74
- return (_jsx(Container, { "data-pb-section": section.id, style: section.styles, children: content }));
75
- }
76
- return _jsx(Container, { fluid: true, children: content });
77
- });
78
- const ColumnRenderer = memo(function ColumnRenderer({ column, editionMode }) {
79
- return (_jsx(Col, { id: `column-${column.id}`, xs: colWidthValue(column.width.xs, column.offset.xs), sm: colWidthValue(column.width.sm, column.offset.sm), md: colWidthValue(column.width.md, column.offset.md), lg: colWidthValue(column.width.lg, column.offset.lg), xl: colWidthValue(column.width.xl, column.offset.xl), style: column.styles, children: _jsx(ColumnContent, { column: column, editionMode: editionMode }) }, column.id));
80
- });
81
- const SectionRenderer = memo(function SectionRenderer({ sections, editionMode = false }) {
82
- const sorted = useMemo(() => orderBySort(sections || []), [sections]);
83
- if (sorted.length === 0) {
84
- return null;
85
- }
86
- return (_jsxs(_Fragment, { children: [_jsx("style", { children: buildResponsiveCss(sorted) }), sorted.map((section) => (_jsx(SectionContent, { section: section, editionMode: editionMode }, section.id)))] }));
87
- });
88
- export { SectionRenderer };
@@ -1,10 +0,0 @@
1
- import type { StylesType } from './StylesType.js';
2
- import type { SectionColumnType } from './SectionColumnType.js';
3
- export interface SectionType {
4
- id: number;
5
- sectionType: 'container' | 'container-fluid' | 'row';
6
- sort: number;
7
- properties: Record<string, unknown>;
8
- styles: StylesType;
9
- columns: SectionColumnType[];
10
- }
@@ -1 +0,0 @@
1
- export {};