@bsuite/page-builder 0.1.0 → 0.2.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.
- package/dist/buildResponsiveLayouts.d.ts +15 -0
- package/dist/buildResponsiveLayouts.d.ts.map +1 -0
- package/dist/buildResponsiveLayouts.js +47 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/usePageGridLayout.d.ts.map +1 -1
- package/dist/usePageGridLayout.js +3 -3
- package/package.json +6 -5
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { GridLayouts } from './types.js';
|
|
2
|
+
export declare const RESPONSIVE_BREAKPOINTS: readonly ["lg", "md", "sm", "xs", "xxs"];
|
|
3
|
+
export type ResponsiveBreakpoint = (typeof RESPONSIVE_BREAKPOINTS)[number];
|
|
4
|
+
export interface BuildResponsiveLayoutsOptions {
|
|
5
|
+
cols?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Ensure a GridLayouts object has entries for all responsive breakpoints
|
|
9
|
+
* (lg, md, sm, xs, xxs). Missing smaller breakpoints (sm/xs/xxs) are derived
|
|
10
|
+
* from `lg` as a single-column vertical stack so that consumer-supplied
|
|
11
|
+
* lg-only layouts no longer squash on phone viewports. Missing `md` is
|
|
12
|
+
* mirrored from `lg`. Consumer-supplied breakpoints are preserved verbatim.
|
|
13
|
+
*/
|
|
14
|
+
export declare function buildResponsiveLayouts(layouts: GridLayouts, { cols }?: BuildResponsiveLayoutsOptions): GridLayouts;
|
|
15
|
+
//# sourceMappingURL=buildResponsiveLayouts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildResponsiveLayouts.d.ts","sourceRoot":"","sources":["../src/buildResponsiveLayouts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,eAAO,MAAM,sBAAsB,0CAA2C,CAAC;AAC/E,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE3E,MAAM,WAAW,6BAA6B;IAC5C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAkBD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,WAAW,EACpB,EAAE,IAAS,EAAE,GAAE,6BAAkC,GAChD,WAAW,CAyBb"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export const RESPONSIVE_BREAKPOINTS = ['lg', 'md', 'sm', 'xs', 'xxs'];
|
|
2
|
+
function stackToSingleColumn(items, cols) {
|
|
3
|
+
const sorted = [...items].sort((a, b) => (a.y !== b.y ? a.y - b.y : a.x - b.x));
|
|
4
|
+
let nextY = 0;
|
|
5
|
+
return sorted.map((item) => {
|
|
6
|
+
const stacked = {
|
|
7
|
+
...item,
|
|
8
|
+
x: 0,
|
|
9
|
+
y: nextY,
|
|
10
|
+
w: cols,
|
|
11
|
+
...(item.minW !== undefined && { minW: Math.min(item.minW, cols) }),
|
|
12
|
+
};
|
|
13
|
+
nextY += item.h;
|
|
14
|
+
return stacked;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Ensure a GridLayouts object has entries for all responsive breakpoints
|
|
19
|
+
* (lg, md, sm, xs, xxs). Missing smaller breakpoints (sm/xs/xxs) are derived
|
|
20
|
+
* from `lg` as a single-column vertical stack so that consumer-supplied
|
|
21
|
+
* lg-only layouts no longer squash on phone viewports. Missing `md` is
|
|
22
|
+
* mirrored from `lg`. Consumer-supplied breakpoints are preserved verbatim.
|
|
23
|
+
*/
|
|
24
|
+
export function buildResponsiveLayouts(layouts, { cols = 12 } = {}) {
|
|
25
|
+
const lg = layouts.lg ?? [];
|
|
26
|
+
const result = { lg };
|
|
27
|
+
for (const bp of RESPONSIVE_BREAKPOINTS) {
|
|
28
|
+
if (bp === 'lg')
|
|
29
|
+
continue;
|
|
30
|
+
const supplied = layouts[bp];
|
|
31
|
+
if (supplied) {
|
|
32
|
+
result[bp] = supplied;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (bp === 'md') {
|
|
36
|
+
result[bp] = lg;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
result[bp] = stackToSingleColumn(lg, cols);
|
|
40
|
+
}
|
|
41
|
+
for (const bp of Object.keys(layouts)) {
|
|
42
|
+
if (!(bp in result)) {
|
|
43
|
+
result[bp] = layouts[bp];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { PageGridLayout } from './PageGridLayout.js';
|
|
2
2
|
export { usePageGridLayout, DEFAULT_EDITOR_EVENT_NAMES } from './usePageGridLayout.js';
|
|
3
3
|
export { rescaleLayout } from './rescaleLayout.js';
|
|
4
|
+
export { buildResponsiveLayouts, RESPONSIVE_BREAKPOINTS, } from './buildResponsiveLayouts.js';
|
|
5
|
+
export type { BuildResponsiveLayoutsOptions, ResponsiveBreakpoint, } from './buildResponsiveLayouts.js';
|
|
4
6
|
export { useLocalPreference, defaultPreferenceAdapter } from './preferences.js';
|
|
5
7
|
export type { EntityWidgetDetail, EntityWidgetFactoryOptions, GridLayoutItem, GridLayouts, PageGridLayoutProps, PageGridPreferenceAdapter, PageGridPreferenceFactory, UsePageGridLayoutOptions, UsePageGridLayoutResult, WidgetMeta, } from './types.js';
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAChF,YAAY,EACV,kBAAkB,EAClB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,UAAU,GACX,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,GACvB,MAAM,6BAA6B,CAAC;AACrC,YAAY,EACV,6BAA6B,EAC7B,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAChF,YAAY,EACV,kBAAkB,EAClB,0BAA0B,EAC1B,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,uBAAuB,EACvB,UAAU,GACX,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { PageGridLayout } from './PageGridLayout.js';
|
|
2
2
|
export { usePageGridLayout, DEFAULT_EDITOR_EVENT_NAMES } from './usePageGridLayout.js';
|
|
3
3
|
export { rescaleLayout } from './rescaleLayout.js';
|
|
4
|
+
export { buildResponsiveLayouts, RESPONSIVE_BREAKPOINTS, } from './buildResponsiveLayouts.js';
|
|
4
5
|
export { useLocalPreference, defaultPreferenceAdapter } from './preferences.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePageGridLayout.d.ts","sourceRoot":"","sources":["../src/usePageGridLayout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePageGridLayout.d.ts","sourceRoot":"","sources":["../src/usePageGridLayout.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAGV,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,0BAA0B,2IAM7B,CAAC;AAEX,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,cAAc,EACd,WAAgB,EAChB,aAAiB,EACjB,WAAkB,EAClB,gBAA6C,EAC7C,iBAA4C,GAC7C,EAAE,wBAAwB,GAAG,uBAAuB,CA6NpD"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { startTransition, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
2
2
|
import { noCompactor, verticalCompactor } from 'react-grid-layout';
|
|
3
|
+
import { buildResponsiveLayouts } from './buildResponsiveLayouts.js';
|
|
3
4
|
import { defaultPreferenceAdapter } from './preferences.js';
|
|
4
5
|
import { rescaleLayout } from './rescaleLayout.js';
|
|
5
6
|
export const DEFAULT_EDITOR_EVENT_NAMES = [
|
|
@@ -87,9 +88,8 @@ export function usePageGridLayout({ pageKey, defaultLayouts, defaultCols = 12, l
|
|
|
87
88
|
return changed ? merged : savedLayout;
|
|
88
89
|
}, [savedLayout, defaultLayouts]);
|
|
89
90
|
const currentLayouts = useMemo(() => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return rawLayouts;
|
|
91
|
+
const rescaled = baseCols !== layoutCols ? rescaleLayout(rawLayouts, baseCols, layoutCols) : rawLayouts;
|
|
92
|
+
return buildResponsiveLayouts(rescaled, { cols: layoutCols });
|
|
93
93
|
}, [rawLayouts, baseCols, layoutCols]);
|
|
94
94
|
useEffect(() => {
|
|
95
95
|
if (baseCols !== layoutCols) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsuite/page-builder",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Shared BSuite responsive page-builder grid and layout persistence primitives",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/GaryOcean428/bsuite.git",
|
|
12
|
+
"url": "git+https://github.com/GaryOcean428/bsuite.git",
|
|
13
13
|
"directory": "packages/page-builder"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
@@ -55,12 +55,13 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@testing-library/jest-dom": "^6.9.1",
|
|
57
57
|
"@testing-library/react": "^16.3.2",
|
|
58
|
-
"@types/react": "^
|
|
58
|
+
"@types/react": "^19.2.14",
|
|
59
|
+
"@types/react-dom": "^19.2.3",
|
|
59
60
|
"@vitejs/plugin-react": "^5.2.0",
|
|
60
61
|
"jsdom": "^28.1.0",
|
|
61
62
|
"lucide-react": "^0.576.0",
|
|
62
|
-
"react": "^
|
|
63
|
-
"react-dom": "^
|
|
63
|
+
"react": "^19.2.4",
|
|
64
|
+
"react-dom": "^19.2.4",
|
|
64
65
|
"react-grid-layout": "^2.2.2",
|
|
65
66
|
"react-resizable": "^3.0.5",
|
|
66
67
|
"typescript": "~5.7.3",
|