lib-pixelbuild 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/builders/PageBuilder.js +1 -1
- package/dist/components/SliderComponent.d.ts +2 -1
- package/dist/components/SliderComponent.js +42 -3
- package/dist/factories/ComponentFactory.d.ts +1 -1
- package/dist/factories/ComponentFactory.js +2 -2
- package/dist/renderers/SectionRenderer.d.ts +2 -1
- package/dist/renderers/SectionRenderer.js +29 -7
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -1,3 +1,14 @@
|
|
|
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
|
+
};
|
|
1
12
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import { useEffect, useState } from 'react';
|
|
3
14
|
import { useKeenSlider } from 'keen-slider/react.js';
|
|
@@ -5,7 +16,20 @@ import { ElementFactory } from '../factories/ElementFactory.js';
|
|
|
5
16
|
import { orderBySort } from '../utils/orderBySort.js';
|
|
6
17
|
import 'keen-slider/keen-slider.min.css';
|
|
7
18
|
const elementFactory = new ElementFactory();
|
|
8
|
-
|
|
19
|
+
function cleanSlideStyles(element) {
|
|
20
|
+
const _b = element.styles, { height: _h, objectFit: _o } = _b, rest = __rest(_b, ["height", "objectFit"]);
|
|
21
|
+
return Object.assign(Object.assign({}, element), { styles: rest });
|
|
22
|
+
}
|
|
23
|
+
function cleanComponentStyles(styles) {
|
|
24
|
+
const { minHeight: _m, display: _d, alignItems: _a, justifyContent: _j, flexDirection: _f } = styles, rest = __rest(styles, ["minHeight", "display", "alignItems", "justifyContent", "flexDirection"]);
|
|
25
|
+
return rest;
|
|
26
|
+
}
|
|
27
|
+
function StaticSliderComponent({ component }) {
|
|
28
|
+
const firstSlide = orderBySort(component.elements)[0];
|
|
29
|
+
const slide = firstSlide ? cleanSlideStyles(firstSlide) : null;
|
|
30
|
+
return (_jsx("div", { style: Object.assign({ position: 'relative', overflow: 'hidden' }, cleanComponentStyles(component.styles)), children: slide && elementFactory.build(slide) }));
|
|
31
|
+
}
|
|
32
|
+
function InteractiveSliderComponent({ component }) {
|
|
9
33
|
const properties = component.properties;
|
|
10
34
|
const slides = orderBySort(component.elements);
|
|
11
35
|
const [currentSlide, setCurrentSlide] = useState(0);
|
|
@@ -25,10 +49,25 @@ export function SliderComponent({ component }) {
|
|
|
25
49
|
if (!properties.autoplay || slides.length < 2)
|
|
26
50
|
return;
|
|
27
51
|
const interval = Number(properties.interval) > 0 ? Number(properties.interval) : 5000;
|
|
28
|
-
const timer = window.setInterval(() => { var
|
|
52
|
+
const timer = window.setInterval(() => { var _b; return (_b = instanceRef.current) === null || _b === void 0 ? void 0 : _b.next(); }, interval);
|
|
29
53
|
return () => window.clearInterval(timer);
|
|
30
54
|
}, [instanceRef, properties.autoplay, properties.interval, slides.length]);
|
|
55
|
+
const fixedHeight = Number(properties.height) > 0 ? Number(properties.height) : 0;
|
|
31
56
|
const showArrows = Boolean(properties.showArrows) && loaded && slides.length > 1;
|
|
32
57
|
const showDots = Boolean(properties.showDots) && loaded && slides.length > 1;
|
|
33
|
-
|
|
58
|
+
const sliderStyle = fixedHeight
|
|
59
|
+
? { height: fixedHeight }
|
|
60
|
+
: { alignItems: 'flex-start' };
|
|
61
|
+
const slideStyle = fixedHeight
|
|
62
|
+
? { minHeight: '100%', height: '100%' }
|
|
63
|
+
: { minHeight: 'auto' };
|
|
64
|
+
return (_jsxs("div", { style: Object.assign({ position: 'relative' }, cleanComponentStyles(component.styles)), children: [_jsx("div", { ref: ref, className: "keen-slider", style: sliderStyle, children: slides.map((element) => {
|
|
65
|
+
const sanitized = fixedHeight ? element : cleanSlideStyles(element);
|
|
66
|
+
return (_jsx("div", { className: "keen-slider__slide", style: slideStyle, children: elementFactory.build(sanitized) }, element.id));
|
|
67
|
+
}) }), showArrows && (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", "aria-label": "Slide anterior", onClick: () => { var _b; return (_b = instanceRef.current) === null || _b === void 0 ? void 0 : _b.prev(); }, style: { position: 'absolute', left: 0, top: '50%', transform: 'translateY(-50%)' }, children: '<' }), _jsx("button", { type: "button", "aria-label": "Proximo slide", onClick: () => { var _b; return (_b = instanceRef.current) === null || _b === void 0 ? void 0 : _b.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 _b; return (_b = instanceRef.current) === null || _b === void 0 ? void 0 : _b.moveToIdx(index); }, children: index + 1 }, element.id))) }))] }));
|
|
68
|
+
}
|
|
69
|
+
export function SliderComponent({ component, editionMode = false }) {
|
|
70
|
+
if (editionMode)
|
|
71
|
+
return _jsx(StaticSliderComponent, { component: component });
|
|
72
|
+
return _jsx(InteractiveSliderComponent, { component: component });
|
|
34
73
|
}
|
|
@@ -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,
|
|
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
|
|
16
|
-
|
|
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 (
|
|
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
|
}
|