lib-pixelbuild 0.1.1 → 0.1.2

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.
@@ -36,5 +36,5 @@ export function PageBuilder({ website, page, editionMode }) {
36
36
  marginBottom: mergedStyles.marginBottom,
37
37
  borderRadius: mergedStyles.borderRadius,
38
38
  minHeight: page.sections.length === 0 ? '200px' : undefined,
39
- }, children: [_jsx(SectionRenderer, { sections: page.sections }), page.sections.length === 0 && editionMode && (_jsx("div", { style: { padding: '40px', textAlign: 'center', color: '#94a3b8' }, children: "Nenhuma se\u00E7\u00E3o configurada. Use o editor de layout para adicionar conte\u00FAdo." }))] })] }));
39
+ }, children: [_jsx(SectionRenderer, { sections: page.sections, editionMode: editionMode }), page.sections.length === 0 && editionMode && (_jsx("div", { style: { padding: '40px', textAlign: 'center', color: '#94a3b8' }, children: "Nenhuma se\u00E7\u00E3o configurada. Use o editor de layout para adicionar conte\u00FAdo." }))] })] }));
40
40
  }
@@ -1,5 +1,6 @@
1
1
  import type { ComponentType } from '../types/ComponentType.js';
2
2
  import 'keen-slider/keen-slider.min.css';
3
- export declare function SliderComponent({ component }: {
3
+ export declare function SliderComponent({ component, editionMode }: {
4
4
  readonly component: ComponentType;
5
+ readonly editionMode?: boolean;
5
6
  }): import("react").JSX.Element;
@@ -5,7 +5,11 @@ import { ElementFactory } from '../factories/ElementFactory.js';
5
5
  import { orderBySort } from '../utils/orderBySort.js';
6
6
  import 'keen-slider/keen-slider.min.css';
7
7
  const elementFactory = new ElementFactory();
8
- export function SliderComponent({ component }) {
8
+ function StaticSliderComponent({ component }) {
9
+ const firstSlide = orderBySort(component.elements)[0];
10
+ return (_jsx("div", { style: Object.assign({ position: 'relative', overflow: 'hidden' }, component.styles), children: firstSlide && elementFactory.build(firstSlide) }));
11
+ }
12
+ function InteractiveSliderComponent({ component }) {
9
13
  const properties = component.properties;
10
14
  const slides = orderBySort(component.elements);
11
15
  const [currentSlide, setCurrentSlide] = useState(0);
@@ -32,3 +36,8 @@ export function SliderComponent({ component }) {
32
36
  const showDots = Boolean(properties.showDots) && loaded && slides.length > 1;
33
37
  return (_jsxs("div", { style: Object.assign({ position: 'relative' }, component.styles), children: [_jsx("div", { ref: ref, className: "keen-slider", children: slides.map((element) => (_jsx("div", { className: "keen-slider__slide", children: elementFactory.build(element) }, element.id))) }), showArrows && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "aria-label": "Slide anterior", onClick: () => { var _a; return (_a = instanceRef.current) === null || _a === void 0 ? void 0 : _a.prev(); }, style: { position: 'absolute', left: 0, top: '50%', transform: 'translateY(-50%)' }, children: '<' }), _jsx("button", { type: "button", "aria-label": "Proximo slide", onClick: () => { var _a; return (_a = instanceRef.current) === null || _a === void 0 ? void 0 : _a.next(); }, style: { position: 'absolute', right: 0, top: '50%', transform: 'translateY(-50%)' }, children: '>' })] })), showDots && (_jsx("div", { "aria-label": "Navegacao do slider", style: { display: 'flex', justifyContent: 'center', gap: 4 }, children: slides.map((element, index) => (_jsx("button", { type: "button", "aria-label": `Ir para o slide ${index + 1}`, "aria-current": currentSlide === index ? 'true' : undefined, onClick: () => { var _a; return (_a = instanceRef.current) === null || _a === void 0 ? void 0 : _a.moveToIdx(index); }, children: index + 1 }, element.id))) }))] }));
34
38
  }
39
+ export function SliderComponent({ component, editionMode = false }) {
40
+ if (editionMode)
41
+ return _jsx(StaticSliderComponent, { component: component });
42
+ return _jsx(InteractiveSliderComponent, { component: component });
43
+ }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
2
  import type { ComponentType } from '../types/ComponentType.js';
3
3
  export declare class ComponentFactory {
4
- build(component: ComponentType): React.ReactElement | null;
4
+ build(component: ComponentType, editionMode?: boolean): React.ReactElement | null;
5
5
  }
@@ -8,7 +8,7 @@ import { SliderComponent } from '../components/SliderComponent.js';
8
8
  import { CardComponent } from '../components/CardComponent.js';
9
9
  import { MapComponent } from '../components/MapComponent.js';
10
10
  export class ComponentFactory {
11
- build(component) {
11
+ build(component, editionMode = false) {
12
12
  switch (component.componentType) {
13
13
  case ComponentTypeEnum.Text:
14
14
  case ComponentTypeEnum.TextWithImage:
@@ -19,7 +19,7 @@ export class ComponentFactory {
19
19
  case ComponentTypeEnum.Slider:
20
20
  case ComponentTypeEnum.Gallery:
21
21
  case ComponentTypeEnum.Testimonials:
22
- return _jsx(SliderComponent, { component: component }, component.id);
22
+ return _jsx(SliderComponent, { component: component, editionMode: editionMode }, component.id);
23
23
  case ComponentTypeEnum.Form:
24
24
  return _jsx(FormComponent, { component: component }, component.id);
25
25
  case ComponentTypeEnum.Card:
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { SectionType } from '../types/SectionType.js';
3
- export declare function SectionRenderer({ sections }: {
3
+ export declare function SectionRenderer({ sections, editionMode }: {
4
4
  readonly sections: SectionType[];
5
+ readonly editionMode?: boolean;
5
6
  }): React.JSX.Element;
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React from 'react';
3
3
  import { Container, Row, Col } from 'react-bootstrap';
4
4
  import { ComponentFactory } from '../factories/ComponentFactory.js';
@@ -12,8 +12,30 @@ function colWidthValue(width, offset) {
12
12
  }
13
13
  return width;
14
14
  }
15
- function renderSection(section) {
16
- const content = (_jsx(Row, { id: `section-${section.id}`, style: section.sectionType === 'row' ? section.styles : undefined, children: section.columns.map(renderColumn) }));
15
+ function columnContent(column, editionMode) {
16
+ return (_jsxs(_Fragment, { children: [orderBySort(column.components.filter((component) => component.enabled)).map((component) => componentFactory.build(component, editionMode)), orderBySort(column.childSections).map((childSection) => (_jsx(React.Fragment, { children: renderSection(childSection, editionMode) }, childSection.id)))] }));
17
+ }
18
+ function gridClass(id) {
19
+ return `pixelbuild-grid-${String(id).replace(/[^a-zA-Z0-9_-]/g, '_')}`;
20
+ }
21
+ function renderGrid(section, editionMode) {
22
+ const grid = gridClass(section.id);
23
+ const columns = section.columns.filter((column) => column.components.some((component) => component.enabled) || column.childSections.length > 0);
24
+ const css = columns.map((column) => {
25
+ const properties = column.properties || {};
26
+ const row = Math.max(0, Number(properties.row) || 0);
27
+ const rowSpan = Math.max(1, Number(properties.rowSpan) || 1);
28
+ const xs = column.width.xs || 12;
29
+ const sm = column.width.sm || xs;
30
+ const md = column.width.md || sm;
31
+ const columnClass = gridClass(column.id);
32
+ return `.${grid} .${columnClass}{grid-column:span ${xs};grid-row:auto;min-width:0}@media (min-width:576px){.${grid} .${columnClass}{grid-column:span ${sm}}}@media (min-width:768px){.${grid} .${columnClass}{grid-column:span ${md};grid-row:${row + 1}/span ${rowSpan}}}`;
33
+ }).join('');
34
+ return (_jsxs(_Fragment, { children: [_jsx("style", { children: `.${grid}{display:grid;grid-template-columns:repeat(12,minmax(0,1fr));gap:1rem}${css}` }), _jsx("div", { id: `section-${section.id}`, 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: columnContent(column, editionMode) }, column.id))) })] }));
35
+ }
36
+ function renderSection(section, editionMode) {
37
+ const usesGrid = 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; });
38
+ const content = usesGrid ? renderGrid(section, editionMode) : (_jsx(Row, { id: `section-${section.id}`, style: section.sectionType === 'row' ? section.styles : undefined, children: section.columns.map((column) => renderColumn(column, editionMode)) }));
17
39
  if (section.sectionType === 'container-fluid') {
18
40
  return _jsx(Container, { fluid: true, style: section.styles, children: content });
19
41
  }
@@ -22,12 +44,12 @@ function renderSection(section) {
22
44
  }
23
45
  return _jsx(Container, { fluid: true, children: content });
24
46
  }
25
- function renderColumn(column) {
26
- return (_jsxs(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: [orderBySort(column.components.filter((component) => component.enabled)).map((component) => componentFactory.build(component)), orderBySort(column.childSections).map((childSection) => (_jsx(React.Fragment, { children: renderSection(childSection) }, childSection.id)))] }, column.id));
47
+ function renderColumn(column, editionMode) {
48
+ 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: columnContent(column, editionMode) }, column.id));
27
49
  }
28
- export function SectionRenderer({ sections }) {
50
+ export function SectionRenderer({ sections, editionMode = false }) {
29
51
  if (!sections || sections.length === 0) {
30
52
  return null;
31
53
  }
32
- return (_jsx(_Fragment, { children: orderBySort(sections).map((section) => (_jsx(React.Fragment, { children: renderSection(section) }, section.id))) }));
54
+ return (_jsx(_Fragment, { children: orderBySort(sections).map((section) => (_jsx(React.Fragment, { children: renderSection(section, editionMode) }, section.id))) }));
33
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lib-pixelbuild",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "engines": {
5
5
  "node": "^24.18.0",
6
6
  "npm": ">=10"