@damarkuncoro/layout-engine-react 0.1.0 → 0.1.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/README.md +16 -1
- package/lib/cjs/index.d.ts +50 -0
- package/lib/cjs/index.js +192 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/renderReact.js +38 -0
- package/lib/cjs/viewport.d.ts +11 -0
- package/lib/cjs/viewport.js +35 -0
- package/lib/esm/index.d.ts +50 -0
- package/lib/esm/index.js +119 -0
- package/lib/esm/renderReact.d.ts +6 -0
- package/lib/esm/viewport.d.ts +11 -0
- package/lib/esm/viewport.js +27 -0
- package/package.json +25 -15
- package/dist/index.d.ts +0 -18
- package/dist/index.js +0 -28
- /package/{dist → lib/cjs}/renderReact.d.ts +0 -0
- /package/{dist → lib/esm}/renderReact.js +0 -0
package/README.md
CHANGED
|
@@ -10,11 +10,25 @@ npm install @damarkuncoro/layout-engine-react
|
|
|
10
10
|
|
|
11
11
|
Pastikan `react` dan `react-dom` tersedia.
|
|
12
12
|
|
|
13
|
+
## Import ESM & CJS
|
|
14
|
+
|
|
15
|
+
- ESM (direkomendasikan):
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { Box, Stack, SidebarLayout } from "@damarkuncoro/layout-engine-react"
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
- CJS:
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
const { Box, Stack, SidebarLayout } = require("@damarkuncoro/layout-engine-react")
|
|
25
|
+
```
|
|
26
|
+
|
|
13
27
|
## Penggunaan
|
|
14
28
|
|
|
15
29
|
```jsx
|
|
16
30
|
import React from "react"
|
|
17
|
-
import { SidebarLayout, Stack, Box } from "layout-engine-react"
|
|
31
|
+
import { SidebarLayout, Stack, Box } from "@damarkuncoro/layout-engine-react"
|
|
18
32
|
|
|
19
33
|
export default function App() {
|
|
20
34
|
const sidebar = Box({ children: "Sidebar" })
|
|
@@ -31,6 +45,7 @@ export default function App() {
|
|
|
31
45
|
- Komponen: Box, Flex, Stack, Grid, SidebarLayout, DashboardLayout.
|
|
32
46
|
- Otomatisasi key untuk child React agar aman dari warning.
|
|
33
47
|
- ESM-only, tipe tersedia.
|
|
48
|
+
- Output library tersedia di `lib/esm` (ESM) dan `lib/cjs` (CJS).
|
|
34
49
|
|
|
35
50
|
## Lisensi
|
|
36
51
|
MIT
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as H from "@damarkuncoro/layout-engine";
|
|
2
|
+
import { useViewport, BreakpointsProvider, useResponsive } from "./viewport.js";
|
|
3
|
+
export type { CSSLength, LayoutProps, HeadlessNode, SidebarLayoutContract, HeaderLayoutContract, DashboardLayoutContract, SplitLayoutContract, AuthLayoutContract, LandingLayoutContract, FlexProps, StackProps, GridProps, ContainerProps, ResponsiveValue, BreakpointKey, Theme, ColorScheme } from "@damarkuncoro/layout-engine";
|
|
4
|
+
export type { BlogPostPresetProps, BlogListPresetProps, ProductGridPresetProps, ProductDetailPresetProps, CartPresetProps, StatsGridPresetProps, DataTablePresetProps, DashboardWidgetPresetProps, SettingsPagePresetProps, SettingsSectionPresetProps, DocsPagePresetProps, ProfilePagePresetProps } from "@damarkuncoro/layout-engine";
|
|
5
|
+
export { resolveResponsive, breakpoints, theme, themeLight, themeDark, getTheme, getSystemColorScheme } from "@damarkuncoro/layout-engine";
|
|
6
|
+
export declare function StatsGridPreset(props: H.StatsGridPresetProps): any;
|
|
7
|
+
export declare function ProductGridPreset(props: H.ProductGridPresetProps): any;
|
|
8
|
+
export declare function ProductDetailPreset(props: H.ProductDetailPresetProps): any;
|
|
9
|
+
export declare function BlogPostPreset(props: H.BlogPostPresetProps): any;
|
|
10
|
+
export declare function BlogListPreset(props: H.BlogListPresetProps): any;
|
|
11
|
+
export declare function CartPreset(props: H.CartPresetProps): any;
|
|
12
|
+
export declare function DataTablePreset(props: H.DataTablePresetProps): any;
|
|
13
|
+
export declare function DashboardWidgetPreset(props: H.DashboardWidgetPresetProps): any;
|
|
14
|
+
export declare function SettingsPagePreset(props: H.SettingsPagePresetProps): any;
|
|
15
|
+
export declare function SettingsSectionPreset(props: H.SettingsSectionPresetProps): any;
|
|
16
|
+
export declare function DocsPagePreset(props: H.DocsPagePresetProps): any;
|
|
17
|
+
export declare function ProfilePagePreset(props: H.ProfilePagePresetProps): any;
|
|
18
|
+
export declare function Box(props: H.LayoutProps & {
|
|
19
|
+
children?: any;
|
|
20
|
+
}): any;
|
|
21
|
+
export declare function Flex(props: H.FlexProps & {
|
|
22
|
+
children?: any;
|
|
23
|
+
}): any;
|
|
24
|
+
export declare function Stack(props: H.StackProps & {
|
|
25
|
+
children?: any;
|
|
26
|
+
}): any;
|
|
27
|
+
export declare function Grid(props: H.GridProps & {
|
|
28
|
+
children?: any;
|
|
29
|
+
}): any;
|
|
30
|
+
export declare function Container(props: H.ContainerProps & {
|
|
31
|
+
children?: any;
|
|
32
|
+
}): any;
|
|
33
|
+
export declare function Spacer(props: {
|
|
34
|
+
size?: any;
|
|
35
|
+
}): any;
|
|
36
|
+
export declare function Center(props: any): any;
|
|
37
|
+
export declare function SidebarLayout(props: any): any;
|
|
38
|
+
export declare function SidebarLayoutAutoVW(props: any): any;
|
|
39
|
+
export declare function HeaderLayout(props: H.HeaderLayoutContract): any;
|
|
40
|
+
export declare function SplitLayout(props: H.SplitLayoutContract): any;
|
|
41
|
+
export declare function DashboardLayout(props: H.DashboardLayoutContract): any;
|
|
42
|
+
export declare function AuthLayout(props: H.AuthLayoutContract): any;
|
|
43
|
+
export declare function LandingLayout(props: H.LandingLayoutContract): any;
|
|
44
|
+
export declare function HeaderContentFooter(props: {
|
|
45
|
+
header: any;
|
|
46
|
+
content: any;
|
|
47
|
+
footer: any;
|
|
48
|
+
}): any;
|
|
49
|
+
export { renderNodeToReact } from "./renderReact.js";
|
|
50
|
+
export { useViewport, BreakpointsProvider, useResponsive };
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.useResponsive = exports.BreakpointsProvider = exports.useViewport = exports.renderNodeToReact = exports.getSystemColorScheme = exports.getTheme = exports.themeDark = exports.themeLight = exports.theme = exports.breakpoints = exports.resolveResponsive = void 0;
|
|
37
|
+
exports.StatsGridPreset = StatsGridPreset;
|
|
38
|
+
exports.ProductGridPreset = ProductGridPreset;
|
|
39
|
+
exports.ProductDetailPreset = ProductDetailPreset;
|
|
40
|
+
exports.BlogPostPreset = BlogPostPreset;
|
|
41
|
+
exports.BlogListPreset = BlogListPreset;
|
|
42
|
+
exports.CartPreset = CartPreset;
|
|
43
|
+
exports.DataTablePreset = DataTablePreset;
|
|
44
|
+
exports.DashboardWidgetPreset = DashboardWidgetPreset;
|
|
45
|
+
exports.SettingsPagePreset = SettingsPagePreset;
|
|
46
|
+
exports.SettingsSectionPreset = SettingsSectionPreset;
|
|
47
|
+
exports.DocsPagePreset = DocsPagePreset;
|
|
48
|
+
exports.ProfilePagePreset = ProfilePagePreset;
|
|
49
|
+
exports.Box = Box;
|
|
50
|
+
exports.Flex = Flex;
|
|
51
|
+
exports.Stack = Stack;
|
|
52
|
+
exports.Grid = Grid;
|
|
53
|
+
exports.Container = Container;
|
|
54
|
+
exports.Spacer = Spacer;
|
|
55
|
+
exports.Center = Center;
|
|
56
|
+
exports.SidebarLayout = SidebarLayout;
|
|
57
|
+
exports.SidebarLayoutAutoVW = SidebarLayoutAutoVW;
|
|
58
|
+
exports.HeaderLayout = HeaderLayout;
|
|
59
|
+
exports.SplitLayout = SplitLayout;
|
|
60
|
+
exports.DashboardLayout = DashboardLayout;
|
|
61
|
+
exports.AuthLayout = AuthLayout;
|
|
62
|
+
exports.LandingLayout = LandingLayout;
|
|
63
|
+
exports.HeaderContentFooter = HeaderContentFooter;
|
|
64
|
+
const H = __importStar(require("@damarkuncoro/layout-engine"));
|
|
65
|
+
const renderReact_js_1 = require("./renderReact.js");
|
|
66
|
+
const viewport_js_1 = require("./viewport.js");
|
|
67
|
+
Object.defineProperty(exports, "useViewport", { enumerable: true, get: function () { return viewport_js_1.useViewport; } });
|
|
68
|
+
Object.defineProperty(exports, "BreakpointsProvider", { enumerable: true, get: function () { return viewport_js_1.BreakpointsProvider; } });
|
|
69
|
+
Object.defineProperty(exports, "useResponsive", { enumerable: true, get: function () { return viewport_js_1.useResponsive; } });
|
|
70
|
+
var layout_engine_1 = require("@damarkuncoro/layout-engine");
|
|
71
|
+
Object.defineProperty(exports, "resolveResponsive", { enumerable: true, get: function () { return layout_engine_1.resolveResponsive; } });
|
|
72
|
+
Object.defineProperty(exports, "breakpoints", { enumerable: true, get: function () { return layout_engine_1.breakpoints; } });
|
|
73
|
+
Object.defineProperty(exports, "theme", { enumerable: true, get: function () { return layout_engine_1.theme; } });
|
|
74
|
+
Object.defineProperty(exports, "themeLight", { enumerable: true, get: function () { return layout_engine_1.themeLight; } });
|
|
75
|
+
Object.defineProperty(exports, "themeDark", { enumerable: true, get: function () { return layout_engine_1.themeDark; } });
|
|
76
|
+
Object.defineProperty(exports, "getTheme", { enumerable: true, get: function () { return layout_engine_1.getTheme; } });
|
|
77
|
+
Object.defineProperty(exports, "getSystemColorScheme", { enumerable: true, get: function () { return layout_engine_1.getSystemColorScheme; } });
|
|
78
|
+
// Preset wrappers (convert headless nodes to React elements)
|
|
79
|
+
function StatsGridPreset(props) {
|
|
80
|
+
const node = H.StatsGridPreset(props);
|
|
81
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
82
|
+
}
|
|
83
|
+
function ProductGridPreset(props) {
|
|
84
|
+
const node = H.ProductGridPreset(props);
|
|
85
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
86
|
+
}
|
|
87
|
+
function ProductDetailPreset(props) {
|
|
88
|
+
const node = H.ProductDetailPreset(props);
|
|
89
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
90
|
+
}
|
|
91
|
+
function BlogPostPreset(props) {
|
|
92
|
+
const node = H.BlogPostPreset(props);
|
|
93
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
94
|
+
}
|
|
95
|
+
function BlogListPreset(props) {
|
|
96
|
+
const node = H.BlogListPreset(props);
|
|
97
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
98
|
+
}
|
|
99
|
+
function CartPreset(props) {
|
|
100
|
+
const node = H.CartPreset(props);
|
|
101
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
102
|
+
}
|
|
103
|
+
function DataTablePreset(props) {
|
|
104
|
+
const node = H.DataTablePreset(props);
|
|
105
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
106
|
+
}
|
|
107
|
+
function DashboardWidgetPreset(props) {
|
|
108
|
+
const node = H.DashboardWidgetPreset(props);
|
|
109
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
110
|
+
}
|
|
111
|
+
function SettingsPagePreset(props) {
|
|
112
|
+
const node = H.SettingsPagePreset(props);
|
|
113
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
114
|
+
}
|
|
115
|
+
function SettingsSectionPreset(props) {
|
|
116
|
+
const node = H.SettingsSectionPreset(props);
|
|
117
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
118
|
+
}
|
|
119
|
+
function DocsPagePreset(props) {
|
|
120
|
+
const node = H.DocsPagePreset(props);
|
|
121
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
122
|
+
}
|
|
123
|
+
function ProfilePagePreset(props) {
|
|
124
|
+
const node = H.ProfilePagePreset(props);
|
|
125
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
126
|
+
}
|
|
127
|
+
function Box(props) {
|
|
128
|
+
const node = H.Box(props);
|
|
129
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
130
|
+
}
|
|
131
|
+
function Flex(props) {
|
|
132
|
+
const node = H.Flex(props);
|
|
133
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
134
|
+
}
|
|
135
|
+
function Stack(props) {
|
|
136
|
+
const node = H.Stack(props);
|
|
137
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
138
|
+
}
|
|
139
|
+
function Grid(props) {
|
|
140
|
+
const node = H.Grid(props);
|
|
141
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
142
|
+
}
|
|
143
|
+
function Container(props) {
|
|
144
|
+
const node = H.Container(props);
|
|
145
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
146
|
+
}
|
|
147
|
+
function Spacer(props) {
|
|
148
|
+
const node = H.Spacer(props);
|
|
149
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
150
|
+
}
|
|
151
|
+
function Center(props) {
|
|
152
|
+
const node = H.Center(props);
|
|
153
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
154
|
+
}
|
|
155
|
+
function SidebarLayout(props) {
|
|
156
|
+
const node = H.SidebarLayout(props);
|
|
157
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
158
|
+
}
|
|
159
|
+
function SidebarLayoutAutoVW(props) {
|
|
160
|
+
var _a;
|
|
161
|
+
const vw = (0, viewport_js_1.useViewport)();
|
|
162
|
+
const node = H.SidebarLayout({ viewportWidth: (_a = props === null || props === void 0 ? void 0 : props.viewportWidth) !== null && _a !== void 0 ? _a : vw, ...props });
|
|
163
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
164
|
+
}
|
|
165
|
+
function HeaderLayout(props) {
|
|
166
|
+
const node = H.HeaderLayout(props);
|
|
167
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
168
|
+
}
|
|
169
|
+
function SplitLayout(props) {
|
|
170
|
+
var _a;
|
|
171
|
+
const vw = (0, viewport_js_1.useViewport)();
|
|
172
|
+
const node = H.SplitLayout({ viewportWidth: (_a = props === null || props === void 0 ? void 0 : props.viewportWidth) !== null && _a !== void 0 ? _a : vw, ...props });
|
|
173
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
174
|
+
}
|
|
175
|
+
function DashboardLayout(props) {
|
|
176
|
+
const node = H.DashboardLayout(props);
|
|
177
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
178
|
+
}
|
|
179
|
+
function AuthLayout(props) {
|
|
180
|
+
const node = H.AuthLayout(props);
|
|
181
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
182
|
+
}
|
|
183
|
+
function LandingLayout(props) {
|
|
184
|
+
const node = H.LandingLayout(props);
|
|
185
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
186
|
+
}
|
|
187
|
+
function HeaderContentFooter(props) {
|
|
188
|
+
const node = H.HeaderContentFooter(props);
|
|
189
|
+
return (0, renderReact_js_1.renderNodeToReact)(node);
|
|
190
|
+
}
|
|
191
|
+
var renderReact_js_2 = require("./renderReact.js");
|
|
192
|
+
Object.defineProperty(exports, "renderNodeToReact", { enumerable: true, get: function () { return renderReact_js_2.renderNodeToReact; } });
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.renderNodeToReact = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const toChild = (c) => {
|
|
9
|
+
if (c === null || c === undefined || c === false)
|
|
10
|
+
return null;
|
|
11
|
+
if (Array.isArray(c))
|
|
12
|
+
return c.map((item, idx) => {
|
|
13
|
+
const v = toChild(item);
|
|
14
|
+
if (react_1.default.isValidElement(v)) {
|
|
15
|
+
if (v.key == null) {
|
|
16
|
+
return react_1.default.cloneElement(v, { key: idx });
|
|
17
|
+
}
|
|
18
|
+
return v;
|
|
19
|
+
}
|
|
20
|
+
return react_1.default.createElement(react_1.default.Fragment, { key: idx }, v);
|
|
21
|
+
});
|
|
22
|
+
if (typeof c === "object" && c.type && c.props)
|
|
23
|
+
return (0, exports.renderNodeToReact)(c);
|
|
24
|
+
return c;
|
|
25
|
+
};
|
|
26
|
+
const renderNodeToReact = (node) => {
|
|
27
|
+
const { type, props } = node;
|
|
28
|
+
const { children, className, style, ...rest } = props || {};
|
|
29
|
+
// Merge className and style like standard React
|
|
30
|
+
const mergedProps = { ...rest };
|
|
31
|
+
if (className)
|
|
32
|
+
mergedProps.className = className;
|
|
33
|
+
if (style)
|
|
34
|
+
mergedProps.style = { ...style };
|
|
35
|
+
const child = toChild(children);
|
|
36
|
+
return react_1.default.createElement(type, mergedProps, child);
|
|
37
|
+
};
|
|
38
|
+
exports.renderNodeToReact = renderNodeToReact;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare function BreakpointsProvider(props: {
|
|
3
|
+
initialWidth?: number;
|
|
4
|
+
breakpoints?: Record<string, number>;
|
|
5
|
+
children?: any;
|
|
6
|
+
}): React.FunctionComponentElement<React.ProviderProps<{
|
|
7
|
+
width: number;
|
|
8
|
+
breakpoints: Record<string, number>;
|
|
9
|
+
}>>;
|
|
10
|
+
export declare function useViewport(): number;
|
|
11
|
+
export declare function useResponsive<T>(value: any): T | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BreakpointsProvider = BreakpointsProvider;
|
|
7
|
+
exports.useViewport = useViewport;
|
|
8
|
+
exports.useResponsive = useResponsive;
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const layout_engine_1 = require("@damarkuncoro/layout-engine");
|
|
11
|
+
const Ctx = react_1.default.createContext({
|
|
12
|
+
width: 1024,
|
|
13
|
+
breakpoints: layout_engine_1.breakpoints
|
|
14
|
+
});
|
|
15
|
+
function BreakpointsProvider(props) {
|
|
16
|
+
var _a;
|
|
17
|
+
const [width, setWidth] = react_1.default.useState((_a = props.initialWidth) !== null && _a !== void 0 ? _a : (typeof window !== "undefined" ? window.innerWidth : 1024));
|
|
18
|
+
react_1.default.useEffect(() => {
|
|
19
|
+
if (props.initialWidth != null)
|
|
20
|
+
return;
|
|
21
|
+
const onResize = () => setWidth(window.innerWidth);
|
|
22
|
+
window.addEventListener("resize", onResize);
|
|
23
|
+
return () => window.removeEventListener("resize", onResize);
|
|
24
|
+
}, [props.initialWidth]);
|
|
25
|
+
const value = react_1.default.useMemo(() => { var _a; return ({ width, breakpoints: (_a = props.breakpoints) !== null && _a !== void 0 ? _a : layout_engine_1.breakpoints }); }, [width, props.breakpoints]);
|
|
26
|
+
return react_1.default.createElement(Ctx.Provider, { value }, props.children);
|
|
27
|
+
}
|
|
28
|
+
function useViewport() {
|
|
29
|
+
const ctx = react_1.default.useContext(Ctx);
|
|
30
|
+
return ctx.width;
|
|
31
|
+
}
|
|
32
|
+
function useResponsive(value) {
|
|
33
|
+
const w = useViewport();
|
|
34
|
+
return (0, layout_engine_1.resolveResponsive)(value, w);
|
|
35
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as H from "@damarkuncoro/layout-engine";
|
|
2
|
+
import { useViewport, BreakpointsProvider, useResponsive } from "./viewport.js";
|
|
3
|
+
export type { CSSLength, LayoutProps, HeadlessNode, SidebarLayoutContract, HeaderLayoutContract, DashboardLayoutContract, SplitLayoutContract, AuthLayoutContract, LandingLayoutContract, FlexProps, StackProps, GridProps, ContainerProps, ResponsiveValue, BreakpointKey, Theme, ColorScheme } from "@damarkuncoro/layout-engine";
|
|
4
|
+
export type { BlogPostPresetProps, BlogListPresetProps, ProductGridPresetProps, ProductDetailPresetProps, CartPresetProps, StatsGridPresetProps, DataTablePresetProps, DashboardWidgetPresetProps, SettingsPagePresetProps, SettingsSectionPresetProps, DocsPagePresetProps, ProfilePagePresetProps } from "@damarkuncoro/layout-engine";
|
|
5
|
+
export { resolveResponsive, breakpoints, theme, themeLight, themeDark, getTheme, getSystemColorScheme } from "@damarkuncoro/layout-engine";
|
|
6
|
+
export declare function StatsGridPreset(props: H.StatsGridPresetProps): any;
|
|
7
|
+
export declare function ProductGridPreset(props: H.ProductGridPresetProps): any;
|
|
8
|
+
export declare function ProductDetailPreset(props: H.ProductDetailPresetProps): any;
|
|
9
|
+
export declare function BlogPostPreset(props: H.BlogPostPresetProps): any;
|
|
10
|
+
export declare function BlogListPreset(props: H.BlogListPresetProps): any;
|
|
11
|
+
export declare function CartPreset(props: H.CartPresetProps): any;
|
|
12
|
+
export declare function DataTablePreset(props: H.DataTablePresetProps): any;
|
|
13
|
+
export declare function DashboardWidgetPreset(props: H.DashboardWidgetPresetProps): any;
|
|
14
|
+
export declare function SettingsPagePreset(props: H.SettingsPagePresetProps): any;
|
|
15
|
+
export declare function SettingsSectionPreset(props: H.SettingsSectionPresetProps): any;
|
|
16
|
+
export declare function DocsPagePreset(props: H.DocsPagePresetProps): any;
|
|
17
|
+
export declare function ProfilePagePreset(props: H.ProfilePagePresetProps): any;
|
|
18
|
+
export declare function Box(props: H.LayoutProps & {
|
|
19
|
+
children?: any;
|
|
20
|
+
}): any;
|
|
21
|
+
export declare function Flex(props: H.FlexProps & {
|
|
22
|
+
children?: any;
|
|
23
|
+
}): any;
|
|
24
|
+
export declare function Stack(props: H.StackProps & {
|
|
25
|
+
children?: any;
|
|
26
|
+
}): any;
|
|
27
|
+
export declare function Grid(props: H.GridProps & {
|
|
28
|
+
children?: any;
|
|
29
|
+
}): any;
|
|
30
|
+
export declare function Container(props: H.ContainerProps & {
|
|
31
|
+
children?: any;
|
|
32
|
+
}): any;
|
|
33
|
+
export declare function Spacer(props: {
|
|
34
|
+
size?: any;
|
|
35
|
+
}): any;
|
|
36
|
+
export declare function Center(props: any): any;
|
|
37
|
+
export declare function SidebarLayout(props: any): any;
|
|
38
|
+
export declare function SidebarLayoutAutoVW(props: any): any;
|
|
39
|
+
export declare function HeaderLayout(props: H.HeaderLayoutContract): any;
|
|
40
|
+
export declare function SplitLayout(props: H.SplitLayoutContract): any;
|
|
41
|
+
export declare function DashboardLayout(props: H.DashboardLayoutContract): any;
|
|
42
|
+
export declare function AuthLayout(props: H.AuthLayoutContract): any;
|
|
43
|
+
export declare function LandingLayout(props: H.LandingLayoutContract): any;
|
|
44
|
+
export declare function HeaderContentFooter(props: {
|
|
45
|
+
header: any;
|
|
46
|
+
content: any;
|
|
47
|
+
footer: any;
|
|
48
|
+
}): any;
|
|
49
|
+
export { renderNodeToReact } from "./renderReact.js";
|
|
50
|
+
export { useViewport, BreakpointsProvider, useResponsive };
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as H from "@damarkuncoro/layout-engine";
|
|
2
|
+
import { renderNodeToReact } from "./renderReact.js";
|
|
3
|
+
import { useViewport, BreakpointsProvider, useResponsive } from "./viewport.js";
|
|
4
|
+
export { resolveResponsive, breakpoints, theme, themeLight, themeDark, getTheme, getSystemColorScheme } from "@damarkuncoro/layout-engine";
|
|
5
|
+
// Preset wrappers (convert headless nodes to React elements)
|
|
6
|
+
export function StatsGridPreset(props) {
|
|
7
|
+
const node = H.StatsGridPreset(props);
|
|
8
|
+
return renderNodeToReact(node);
|
|
9
|
+
}
|
|
10
|
+
export function ProductGridPreset(props) {
|
|
11
|
+
const node = H.ProductGridPreset(props);
|
|
12
|
+
return renderNodeToReact(node);
|
|
13
|
+
}
|
|
14
|
+
export function ProductDetailPreset(props) {
|
|
15
|
+
const node = H.ProductDetailPreset(props);
|
|
16
|
+
return renderNodeToReact(node);
|
|
17
|
+
}
|
|
18
|
+
export function BlogPostPreset(props) {
|
|
19
|
+
const node = H.BlogPostPreset(props);
|
|
20
|
+
return renderNodeToReact(node);
|
|
21
|
+
}
|
|
22
|
+
export function BlogListPreset(props) {
|
|
23
|
+
const node = H.BlogListPreset(props);
|
|
24
|
+
return renderNodeToReact(node);
|
|
25
|
+
}
|
|
26
|
+
export function CartPreset(props) {
|
|
27
|
+
const node = H.CartPreset(props);
|
|
28
|
+
return renderNodeToReact(node);
|
|
29
|
+
}
|
|
30
|
+
export function DataTablePreset(props) {
|
|
31
|
+
const node = H.DataTablePreset(props);
|
|
32
|
+
return renderNodeToReact(node);
|
|
33
|
+
}
|
|
34
|
+
export function DashboardWidgetPreset(props) {
|
|
35
|
+
const node = H.DashboardWidgetPreset(props);
|
|
36
|
+
return renderNodeToReact(node);
|
|
37
|
+
}
|
|
38
|
+
export function SettingsPagePreset(props) {
|
|
39
|
+
const node = H.SettingsPagePreset(props);
|
|
40
|
+
return renderNodeToReact(node);
|
|
41
|
+
}
|
|
42
|
+
export function SettingsSectionPreset(props) {
|
|
43
|
+
const node = H.SettingsSectionPreset(props);
|
|
44
|
+
return renderNodeToReact(node);
|
|
45
|
+
}
|
|
46
|
+
export function DocsPagePreset(props) {
|
|
47
|
+
const node = H.DocsPagePreset(props);
|
|
48
|
+
return renderNodeToReact(node);
|
|
49
|
+
}
|
|
50
|
+
export function ProfilePagePreset(props) {
|
|
51
|
+
const node = H.ProfilePagePreset(props);
|
|
52
|
+
return renderNodeToReact(node);
|
|
53
|
+
}
|
|
54
|
+
export function Box(props) {
|
|
55
|
+
const node = H.Box(props);
|
|
56
|
+
return renderNodeToReact(node);
|
|
57
|
+
}
|
|
58
|
+
export function Flex(props) {
|
|
59
|
+
const node = H.Flex(props);
|
|
60
|
+
return renderNodeToReact(node);
|
|
61
|
+
}
|
|
62
|
+
export function Stack(props) {
|
|
63
|
+
const node = H.Stack(props);
|
|
64
|
+
return renderNodeToReact(node);
|
|
65
|
+
}
|
|
66
|
+
export function Grid(props) {
|
|
67
|
+
const node = H.Grid(props);
|
|
68
|
+
return renderNodeToReact(node);
|
|
69
|
+
}
|
|
70
|
+
export function Container(props) {
|
|
71
|
+
const node = H.Container(props);
|
|
72
|
+
return renderNodeToReact(node);
|
|
73
|
+
}
|
|
74
|
+
export function Spacer(props) {
|
|
75
|
+
const node = H.Spacer(props);
|
|
76
|
+
return renderNodeToReact(node);
|
|
77
|
+
}
|
|
78
|
+
export function Center(props) {
|
|
79
|
+
const node = H.Center(props);
|
|
80
|
+
return renderNodeToReact(node);
|
|
81
|
+
}
|
|
82
|
+
export function SidebarLayout(props) {
|
|
83
|
+
const node = H.SidebarLayout(props);
|
|
84
|
+
return renderNodeToReact(node);
|
|
85
|
+
}
|
|
86
|
+
export function SidebarLayoutAutoVW(props) {
|
|
87
|
+
var _a;
|
|
88
|
+
const vw = useViewport();
|
|
89
|
+
const node = H.SidebarLayout({ viewportWidth: (_a = props === null || props === void 0 ? void 0 : props.viewportWidth) !== null && _a !== void 0 ? _a : vw, ...props });
|
|
90
|
+
return renderNodeToReact(node);
|
|
91
|
+
}
|
|
92
|
+
export function HeaderLayout(props) {
|
|
93
|
+
const node = H.HeaderLayout(props);
|
|
94
|
+
return renderNodeToReact(node);
|
|
95
|
+
}
|
|
96
|
+
export function SplitLayout(props) {
|
|
97
|
+
var _a;
|
|
98
|
+
const vw = useViewport();
|
|
99
|
+
const node = H.SplitLayout({ viewportWidth: (_a = props === null || props === void 0 ? void 0 : props.viewportWidth) !== null && _a !== void 0 ? _a : vw, ...props });
|
|
100
|
+
return renderNodeToReact(node);
|
|
101
|
+
}
|
|
102
|
+
export function DashboardLayout(props) {
|
|
103
|
+
const node = H.DashboardLayout(props);
|
|
104
|
+
return renderNodeToReact(node);
|
|
105
|
+
}
|
|
106
|
+
export function AuthLayout(props) {
|
|
107
|
+
const node = H.AuthLayout(props);
|
|
108
|
+
return renderNodeToReact(node);
|
|
109
|
+
}
|
|
110
|
+
export function LandingLayout(props) {
|
|
111
|
+
const node = H.LandingLayout(props);
|
|
112
|
+
return renderNodeToReact(node);
|
|
113
|
+
}
|
|
114
|
+
export function HeaderContentFooter(props) {
|
|
115
|
+
const node = H.HeaderContentFooter(props);
|
|
116
|
+
return renderNodeToReact(node);
|
|
117
|
+
}
|
|
118
|
+
export { renderNodeToReact } from "./renderReact.js";
|
|
119
|
+
export { useViewport, BreakpointsProvider, useResponsive };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export declare function BreakpointsProvider(props: {
|
|
3
|
+
initialWidth?: number;
|
|
4
|
+
breakpoints?: Record<string, number>;
|
|
5
|
+
children?: any;
|
|
6
|
+
}): React.FunctionComponentElement<React.ProviderProps<{
|
|
7
|
+
width: number;
|
|
8
|
+
breakpoints: Record<string, number>;
|
|
9
|
+
}>>;
|
|
10
|
+
export declare function useViewport(): number;
|
|
11
|
+
export declare function useResponsive<T>(value: any): T | undefined;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { resolveResponsive, breakpoints as defaultBps } from "@damarkuncoro/layout-engine";
|
|
3
|
+
const Ctx = React.createContext({
|
|
4
|
+
width: 1024,
|
|
5
|
+
breakpoints: defaultBps
|
|
6
|
+
});
|
|
7
|
+
export function BreakpointsProvider(props) {
|
|
8
|
+
var _a;
|
|
9
|
+
const [width, setWidth] = React.useState((_a = props.initialWidth) !== null && _a !== void 0 ? _a : (typeof window !== "undefined" ? window.innerWidth : 1024));
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (props.initialWidth != null)
|
|
12
|
+
return;
|
|
13
|
+
const onResize = () => setWidth(window.innerWidth);
|
|
14
|
+
window.addEventListener("resize", onResize);
|
|
15
|
+
return () => window.removeEventListener("resize", onResize);
|
|
16
|
+
}, [props.initialWidth]);
|
|
17
|
+
const value = React.useMemo(() => { var _a; return ({ width, breakpoints: (_a = props.breakpoints) !== null && _a !== void 0 ? _a : defaultBps }); }, [width, props.breakpoints]);
|
|
18
|
+
return React.createElement(Ctx.Provider, { value }, props.children);
|
|
19
|
+
}
|
|
20
|
+
export function useViewport() {
|
|
21
|
+
const ctx = React.useContext(Ctx);
|
|
22
|
+
return ctx.width;
|
|
23
|
+
}
|
|
24
|
+
export function useResponsive(value) {
|
|
25
|
+
const w = useViewport();
|
|
26
|
+
return resolveResponsive(value, w);
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@damarkuncoro/layout-engine-react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "React adapter for layout-engine (headless → React components)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"main": "
|
|
8
|
-
"module": "
|
|
9
|
-
"types": "
|
|
7
|
+
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
9
|
+
"types": "./lib/esm/index.d.ts",
|
|
10
10
|
"sideEffects": false,
|
|
11
11
|
"files": [
|
|
12
|
-
"
|
|
12
|
+
"lib"
|
|
13
13
|
],
|
|
14
14
|
"keywords": [
|
|
15
15
|
"layout",
|
|
@@ -23,23 +23,33 @@
|
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
|
-
"types": "./
|
|
27
|
-
"import": "./
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"build": "tsc -p tsconfig.json",
|
|
32
|
-
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
26
|
+
"types": "./lib/esm/index.d.ts",
|
|
27
|
+
"import": "./lib/esm/index.js",
|
|
28
|
+
"require": "./lib/cjs/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
33
31
|
},
|
|
34
32
|
"peerDependencies": {
|
|
35
33
|
"react": "^18.0.0",
|
|
36
34
|
"react-dom": "^18.0.0"
|
|
37
35
|
},
|
|
38
36
|
"dependencies": {
|
|
39
|
-
"@damarkuncoro/layout-engine": "^0.1.
|
|
37
|
+
"@damarkuncoro/layout-engine": "^0.1.1"
|
|
40
38
|
},
|
|
41
39
|
"devDependencies": {
|
|
42
40
|
"typescript": "^5.4.0",
|
|
43
|
-
"@damarkuncoro/layout-engine": "file:../layout-engine"
|
|
41
|
+
"@damarkuncoro/layout-engine": "file:../layout-engine",
|
|
42
|
+
"@types/react": "^18.2.0",
|
|
43
|
+
"@types/react-dom": "^18.2.0"
|
|
44
|
+
},
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build:esm": "tsc -p tsconfig.esm.json",
|
|
50
|
+
"build:cjs": "tsc -p tsconfig.cjs.json",
|
|
51
|
+
"postbuild:cjs": "node scripts/ensure-cjs.js",
|
|
52
|
+
"build": "npm run build:esm && npm run build:cjs && npm run postbuild:cjs",
|
|
53
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
44
54
|
}
|
|
45
|
-
}
|
|
55
|
+
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as H from "layout-engine";
|
|
2
|
-
export type { CSSLength, LayoutProps, HeadlessNode, SidebarLayoutContract, DashboardLayoutContract, FlexProps, StackProps, GridProps, ResponsiveValue, BreakpointKey } from "layout-engine";
|
|
3
|
-
export { resolveResponsive, breakpoints } from "layout-engine";
|
|
4
|
-
export declare function Box(props: H.LayoutProps & {
|
|
5
|
-
children?: any;
|
|
6
|
-
}): any;
|
|
7
|
-
export declare function Flex(props: H.FlexProps & {
|
|
8
|
-
children?: any;
|
|
9
|
-
}): any;
|
|
10
|
-
export declare function Stack(props: H.StackProps & {
|
|
11
|
-
children?: any;
|
|
12
|
-
}): any;
|
|
13
|
-
export declare function Grid(props: H.GridProps & {
|
|
14
|
-
children?: any;
|
|
15
|
-
}): any;
|
|
16
|
-
export declare function SidebarLayout(props: any): any;
|
|
17
|
-
export declare function DashboardLayout(props: H.DashboardLayoutContract): any;
|
|
18
|
-
export { renderNodeToReact } from "./renderReact.js";
|
package/dist/index.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import * as H from "layout-engine";
|
|
2
|
-
import { renderNodeToReact } from "./renderReact.js";
|
|
3
|
-
export { resolveResponsive, breakpoints } from "layout-engine";
|
|
4
|
-
export function Box(props) {
|
|
5
|
-
const node = H.Box(props);
|
|
6
|
-
return renderNodeToReact(node);
|
|
7
|
-
}
|
|
8
|
-
export function Flex(props) {
|
|
9
|
-
const node = H.Flex(props);
|
|
10
|
-
return renderNodeToReact(node);
|
|
11
|
-
}
|
|
12
|
-
export function Stack(props) {
|
|
13
|
-
const node = H.Stack(props);
|
|
14
|
-
return renderNodeToReact(node);
|
|
15
|
-
}
|
|
16
|
-
export function Grid(props) {
|
|
17
|
-
const node = H.Grid(props);
|
|
18
|
-
return renderNodeToReact(node);
|
|
19
|
-
}
|
|
20
|
-
export function SidebarLayout(props) {
|
|
21
|
-
const node = H.SidebarLayout(props);
|
|
22
|
-
return renderNodeToReact(node);
|
|
23
|
-
}
|
|
24
|
-
export function DashboardLayout(props) {
|
|
25
|
-
const node = H.DashboardLayout(props);
|
|
26
|
-
return renderNodeToReact(node);
|
|
27
|
-
}
|
|
28
|
-
export { renderNodeToReact } from "./renderReact.js";
|
|
File without changes
|
|
File without changes
|