@nodeblocks/frontend-footer-block 0.0.3 → 0.2.0
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/context.d.ts +12 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/footer.d.ts +19 -20
- package/dist/footer.d.ts.map +1 -1
- package/dist/index.cjs.js +143 -33
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +142 -32
- package/dist/index.esm.js.map +1 -1
- package/dist/lib.d.ts +72 -16
- package/dist/lib.d.ts.map +1 -1
- package/package.json +11 -7
- package/readme.md +9 -2
- package/dist/blocks.d.ts +0 -19
- package/dist/blocks.d.ts.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
type FooterContextValue = {
|
|
3
|
+
logoSrc: string;
|
|
4
|
+
copyright: ReactNode;
|
|
5
|
+
content: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare const FooterProvider: ({ children, ...value }: FooterContextValue & {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare const useFooterContext: () => FooterContextValue;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAc,MAAM,OAAO,CAAC;AAE7D,KAAK,kBAAkB,GAAG;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,SAAS,CAAC;IACrB,OAAO,EAAE,SAAS,CAAC;CACpB,CAAC;AAIF,eAAO,MAAM,cAAc,GAAI,wBAG5B,kBAAkB,GAAG;IACtB,QAAQ,EAAE,SAAS,CAAC;CACrB,4CAEA,CAAC;AAEF,eAAO,MAAM,gBAAgB,0BAO5B,CAAC"}
|
package/dist/footer.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { ComponentProps, ReactNode } from 'react';
|
|
2
|
+
import './footer.css';
|
|
3
|
+
import { BlocksOverride } from './lib';
|
|
4
|
+
import { Box, Stack } from '@mui/material';
|
|
5
|
+
declare const Footer: {
|
|
6
|
+
<CustomBlocks extends Record<string, ReactNode> = {}>({ logoSrc, content, copyright, className, children, ...props }: Omit<ComponentProps<typeof Stack>, "content" | "children"> & {
|
|
7
|
+
logoSrc: string;
|
|
8
|
+
copyright: ReactNode;
|
|
9
|
+
content: ReactNode;
|
|
10
|
+
children?: BlocksOverride<typeof defaultBlocks, CustomBlocks>;
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
Logo(props: Partial<ComponentProps<typeof Box>>): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
Content(props: Partial<ComponentProps<typeof Box>>): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
Copyright(props: Partial<ComponentProps<typeof Box>>): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
};
|
|
16
|
+
declare const defaultBlocks: {
|
|
17
|
+
logo: import("react").ReactElement<Partial<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>>>, (props: Partial<ComponentProps<typeof Box>>) => import("react/jsx-runtime").JSX.Element>;
|
|
18
|
+
content: import("react").ReactElement<Partial<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>>>, (props: Partial<ComponentProps<typeof Box>>) => import("react/jsx-runtime").JSX.Element>;
|
|
19
|
+
copyright: import("react").ReactElement<Partial<import("@mui/system").BoxOwnProps<import("@mui/material").Theme> & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("@mui/system").BoxOwnProps<import("@mui/material").Theme>>>, (props: Partial<ComponentProps<typeof Box>>) => import("react/jsx-runtime").JSX.Element>;
|
|
14
20
|
};
|
|
15
|
-
declare const Footer: ({ logoSrc, items, className, children, copyright }: {
|
|
16
|
-
className: string;
|
|
17
|
-
logoSrc: string;
|
|
18
|
-
copyright: React.ReactNode | string;
|
|
19
|
-
items: Array<React.ReactNode>;
|
|
20
|
-
children?: FooterChildren;
|
|
21
|
-
}) => import("react/jsx-runtime").JSX.Element;
|
|
22
21
|
export default Footer;
|
|
23
22
|
//# sourceMappingURL=footer.d.ts.map
|
package/dist/footer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../src/footer.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"footer.d.ts","sourceRoot":"","sources":["../src/footer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAY,SAAS,EAAE,MAAM,OAAO,CAAC;AAC5D,OAAO,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAAuE,MAAM,OAAO,CAAC;AAE5G,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAE3C,QAAA,MAAM,MAAM;KAAI,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,uEAO3D,IAAI,CAAC,cAAc,CAAC,OAAO,KAAK,CAAC,EAAE,SAAS,GAAG,UAAU,CAAC,GAAG;QAC9D,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,SAAS,CAAC;QACrB,OAAO,EAAE,SAAS,CAAC;QACnB,QAAQ,CAAC,EAAE,cAAc,CAAC,OAAO,aAAa,EAAE,YAAY,CAAC,CAAC;KAC/D;gBAqCqB,OAAO,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;mBAehC,OAAO,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;qBAUjC,OAAO,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;CA3B7D,CAAC;AAqCF,QAAA,MAAM,aAAa;4SAnCG,OAAO,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;+SAehC,OAAO,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;iTAUjC,OAAO,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,CAAC;CAc5D,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,34 +1,14 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return {
|
|
11
|
-
...results,
|
|
12
|
-
blocks: Object.fromEntries(Object.entries(defaultBlocks).map(([key, defaultComponent]) => [
|
|
13
|
-
key,
|
|
14
|
-
customBlocks[key] || defaultComponent,
|
|
15
|
-
])),
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Utility function to join class names together, ignoring undefined or nil values.
|
|
20
|
-
* @param classes - The class names to join.
|
|
21
|
-
* @returns The joined class names.
|
|
22
|
-
*/
|
|
23
|
-
function classNames(...classes) {
|
|
24
|
-
return classes.flat().filter(Boolean).join(' ');
|
|
25
|
-
}
|
|
3
|
+
if (typeof global === 'undefined') {
|
|
4
|
+
var global = window;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
'use strict';
|
|
26
8
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
FooterCopyright: ({ children }) => (jsxRuntime.jsx("p", { className: "nbb-footer-copyright", children: children })),
|
|
31
|
-
};
|
|
9
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
10
|
+
var react = require('react');
|
|
11
|
+
var material = require('@mui/material');
|
|
32
12
|
|
|
33
13
|
function styleInject(css, ref) {
|
|
34
14
|
if ( ref === void 0 ) ref = {};
|
|
@@ -57,14 +37,144 @@ function styleInject(css, ref) {
|
|
|
57
37
|
}
|
|
58
38
|
}
|
|
59
39
|
|
|
60
|
-
var css_248z = "
|
|
40
|
+
var css_248z = ".nbb-footer img {\n display: block;\n}\n\n.nbb-footer a {\n color: inherit;\n}\n.nbb-footer a:hover {\n text-decoration: underline;\n}\n";
|
|
61
41
|
styleInject(css_248z);
|
|
62
42
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
43
|
+
/**
|
|
44
|
+
* Creates a strongly typed `defaultBlocks` object, allowing for types to propagate into block override objects.
|
|
45
|
+
*
|
|
46
|
+
* @param components - A map of default block keys to component functions.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* const defaultBlocks = createDefaultBlocks({
|
|
50
|
+
* title: Title,
|
|
51
|
+
* description: Description,
|
|
52
|
+
* form: Form,
|
|
53
|
+
* });
|
|
54
|
+
*/
|
|
55
|
+
function createDefaultBlocks(components) {
|
|
56
|
+
return Object.fromEntries(Object.entries(components).map(([key, Component]) => [key, react.createElement(Component, { key })]));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A component for rendering {@link BlocksOverride|`BlocksOverride`} results.
|
|
60
|
+
* Exposes the evaluated `blocks` and `blockOrder` as arguments to the `children` function.
|
|
61
|
+
*
|
|
62
|
+
* @param props
|
|
63
|
+
* @param props.blocksOverride - The {@link BlocksOverride|`BlocksOverride`} (i.e. `children` of outer component).
|
|
64
|
+
* @param props.defaultBlocks - The default blocks of outer component.
|
|
65
|
+
* @param props.children - A function returning the JSX to render.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* <BlocksOverrideComponent
|
|
69
|
+
* defaultBlocks={defaultFormBlocks}
|
|
70
|
+
* blocksOverride={children}
|
|
71
|
+
* >
|
|
72
|
+
* {({ blocks, blockOrder }) =>
|
|
73
|
+
* blockOrder.map((key) => (
|
|
74
|
+
* <Fragment key={String(key)}>{blocks[key]}</Fragment>
|
|
75
|
+
* ))
|
|
76
|
+
* }
|
|
77
|
+
* </BlocksOverrideComponent>
|
|
78
|
+
*/
|
|
79
|
+
function BlocksOverrideComponent({ blocksOverride, defaultBlocks, defaultBlockOrder, children, }) {
|
|
80
|
+
if (blocksOverride === undefined) {
|
|
81
|
+
return children({
|
|
82
|
+
// TODO: Remove this assertion
|
|
83
|
+
blocks: defaultBlocks,
|
|
84
|
+
blockOrder: defaultBlockOrder,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (typeof blocksOverride === 'function') {
|
|
88
|
+
const { blocks, blockOrder } = blocksOverride({
|
|
89
|
+
defaultBlocks,
|
|
90
|
+
defaultBlockOrder,
|
|
91
|
+
});
|
|
92
|
+
return children({ blocks, blockOrder });
|
|
93
|
+
}
|
|
94
|
+
return blocksOverride;
|
|
95
|
+
}
|
|
96
|
+
function deepMerge(obj1, obj2) {
|
|
97
|
+
const result = { ...obj1 };
|
|
98
|
+
for (const key in obj2) {
|
|
99
|
+
if (obj2.hasOwnProperty(key)) {
|
|
100
|
+
const val1 = result[key];
|
|
101
|
+
const val2 = obj2[key];
|
|
102
|
+
if (Array.isArray(val1) || Array.isArray(val2)) {
|
|
103
|
+
// If either is an array, replace entirely with obj2's value
|
|
104
|
+
result[key] = val2;
|
|
105
|
+
}
|
|
106
|
+
else if (typeof val1 === 'object' && val1 !== null && typeof val2 === 'object' && val2 !== null) {
|
|
107
|
+
result[key] = deepMerge(val1, val2);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
result[key] = val2;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Utility function to join class names together, ignoring undefined or nil values.
|
|
118
|
+
* @param classes - The class names to join.
|
|
119
|
+
* @returns The joined class names.
|
|
120
|
+
*/
|
|
121
|
+
function classNames(...classes) {
|
|
122
|
+
return classes.flat().filter(Boolean).join(' ');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const FooterContext = react.createContext(undefined);
|
|
126
|
+
const FooterProvider = ({ children, ...value }) => {
|
|
127
|
+
return jsxRuntime.jsx(FooterContext.Provider, { value: value, children: children });
|
|
128
|
+
};
|
|
129
|
+
const useFooterContext = () => {
|
|
130
|
+
const context = react.useContext(FooterContext);
|
|
131
|
+
if (!context) {
|
|
132
|
+
throw new Error('useFooterContext must be used within a FooterProvider');
|
|
133
|
+
}
|
|
134
|
+
return context;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const Footer = ({ logoSrc, content, copyright, className, children, ...props }) => {
|
|
138
|
+
const { sx: sxProp, ...restProps } = props;
|
|
139
|
+
const sx = [
|
|
140
|
+
{
|
|
141
|
+
backgroundColor: 'primary.main',
|
|
142
|
+
color: 'primary.contrastText',
|
|
143
|
+
py: 3,
|
|
144
|
+
px: 2,
|
|
145
|
+
typography: 'body2',
|
|
146
|
+
},
|
|
147
|
+
...(Array.isArray(sxProp) ? sxProp : [sxProp]),
|
|
148
|
+
];
|
|
149
|
+
return (jsxRuntime.jsx(material.Stack, { component: "footer", className: classNames('nbb-footer', className), spacing: 2, sx: sx, ...restProps, children: jsxRuntime.jsx(FooterProvider, { logoSrc,
|
|
150
|
+
content,
|
|
151
|
+
copyright, children: jsxRuntime.jsx(BlocksOverrideComponent, { defaultBlocks: defaultBlocks, defaultBlockOrder: Object.keys(defaultBlocks), blocksOverride: children, children: ({ blocks: { ...blocks }, blockOrder }) => blockOrder
|
|
152
|
+
.filter((key) => key in blocks)
|
|
153
|
+
.map((key) => jsxRuntime.jsx(react.Fragment, { children: blocks[key] }, String(key))) }) }) }));
|
|
154
|
+
};
|
|
155
|
+
Footer.Logo = (props) => {
|
|
156
|
+
const { className, logoSrc, sx: sxProp, ...restProps } = deepMerge(useFooterContext(), props);
|
|
157
|
+
const sx = [
|
|
158
|
+
{
|
|
159
|
+
pb: 0.5,
|
|
160
|
+
},
|
|
161
|
+
...(Array.isArray(sxProp) ? sxProp : [sxProp]),
|
|
162
|
+
];
|
|
163
|
+
return (jsxRuntime.jsx(material.Box, { className: classNames('nbb-footer-logo', className), sx: sx, ...restProps, children: jsxRuntime.jsx("img", { src: logoSrc, alt: 'Footer logo' }) }));
|
|
164
|
+
};
|
|
165
|
+
Footer.Content = (props) => {
|
|
166
|
+
const { className, children, content } = deepMerge(useFooterContext(), props);
|
|
167
|
+
return (jsxRuntime.jsx(material.Box, { className: classNames('nbb-footer-content', className), ...props, children: content || children }));
|
|
168
|
+
};
|
|
169
|
+
Footer.Copyright = (props) => {
|
|
170
|
+
const { className, children, copyright } = deepMerge(useFooterContext(), props);
|
|
171
|
+
return (jsxRuntime.jsx(material.Box, { className: classNames('nbb-footer-copyright', className), ...props, children: copyright || children }));
|
|
67
172
|
};
|
|
173
|
+
const defaultBlocks = createDefaultBlocks({
|
|
174
|
+
logo: Footer.Logo,
|
|
175
|
+
content: Footer.Content,
|
|
176
|
+
copyright: Footer.Copyright,
|
|
177
|
+
});
|
|
68
178
|
|
|
69
179
|
exports.Footer = Footer;
|
|
70
180
|
//# sourceMappingURL=index.cjs.js.map
|
package/dist/index.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.js","sources":["../src/lib.ts","../src/blocks.tsx","../node_modules/style-inject/dist/style-inject.es.js","../src/footer.tsx"],"sourcesContent":["import { DefaultBlocks, DefaultOptions } from './blocks';\n\n/**\n * Sets the blocks by merging default blocks with custom blocks provided by the children function.\n *\n * @param defaultBlocks - The default blocks to be used.\n * @param children - An optional function that returns custom blocks and arguments.\n * @param args - Additional unknown arguments.\n * @returns An object containing the merged blocks and additional arguments.\n */\n\n\ntype ChildrenProps = {\n defaultBlocks: DefaultBlocks;\n};\n\nexport function setBlocks(\n defaultBlocks: DefaultBlocks,\n defaultOptions: DefaultOptions,\n children?: (props: ChildrenProps) => DefaultOptions & {\n blocks: { [x: string]: any };\n },\n) {\n const results = children\n ? children({ defaultBlocks, ...defaultOptions })\n : { blocks: {}, ...defaultOptions };\n const {\n blocks: customBlocks = {}\n } = results;\n return {\n ...results,\n blocks: Object.fromEntries(\n Object.entries(defaultBlocks).map(([key, defaultComponent]) => [\n key,\n customBlocks[key] || defaultComponent,\n ])\n ),\n };\n}\n\ntype ClassName = string | ClassName[] | undefined | null;\n\n/**\n * Utility function to join class names together, ignoring undefined or nil values.\n * @param classes - The class names to join.\n * @returns The joined class names.\n */\nexport function classNames(...classes: ClassName[]): string {\n return classes.flat().filter(Boolean).join(' ');\n}\n","import React from 'react';\n\nexport type DefaultBlocks = {\n FooterLogo: React.FC<{ src: string; alt?: string }>;\n FooterText: React.FC<{ children: React.ReactNode }>;\n FooterCopyright: React.FC<{ children: React.ReactNode }>;\n};\n\nexport type DefaultOptions = {\n hideTitle?: boolean;\n};\n\nexport const defaultOptions: DefaultOptions = {\n hideTitle: false,\n};\n\nfunction FooterTitle({ children }: { children: React.ReactNode }) {\n return <h2 className=\"nbb-footer-title\">{children}</h2>;\n}\n\nfunction FooterText({ children }: { children: React.ReactNode }) {\n return <p className=\"nbb-footer-text\">{children}</p>;\n}\n\nfunction FooterCopyright({ children }: { children: React.ReactNode }) {\n return <p className=\"nbb-footer-copyright\">{children}</p>;\n}\n\n\n\nexport const defaultBlocks: DefaultBlocks = {\n FooterLogo: ({ src, alt }) => (\n <img className=\"nbb-footer-logo\" src={src} alt={alt || 'Footer logo'} />\n ),\n FooterText: ({ children }) => <p className=\"nbb-footer-text\">{children}</p>,\n FooterCopyright: ({ children }) => (\n <p className=\"nbb-footer-copyright\">{children}</p>\n ),\n};","function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React from \"react\";\nimport { setBlocks, classNames } from \"./lib\";\nimport { defaultBlocks, DefaultBlocks } from \"./blocks\";\nimport \"./footer.css\";\n\nexport type FooterChildren = (props: {\n defaultBlocks: DefaultBlocks,\n settings?: { [key: string]: any }\n}\n) => {\n blocks: Partial<DefaultBlocks>;\n settings?: { [key: string]: any };\n};\n\nconst Footer = ({\n logoSrc,\n items = [],\n className,\n children, copyright }:\n {\n className: string;\n logoSrc: string;\n copyright: React.ReactNode | string;\n items: Array<React.ReactNode>;\n children?: FooterChildren;\n}) => {\n const { blocks } = setBlocks(defaultBlocks, {}, children);\n const { FooterLogo, FooterText, FooterCopyright } = blocks;\n\n return (\n <footer className={classNames(\"nbb-footer\", className)}>\n <FooterLogo src={logoSrc} />\n {items.map((item, index) => (\n <FooterText key={index}>{item}</FooterText>\n ))}\n <FooterCopyright>{copyright}</FooterCopyright>\n </footer>\n );\n};\n\nexport default Footer;\n"],"names":["_jsx","_jsxs"],"mappings":";;;;SAgBgB,SAAS,CACvB,aAA4B,EAC5B,cAA8B,EAC9B,QAEC,EAAA;IAED,MAAM,OAAO,GAAG;UACZ,QAAQ,CAAC,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE;UAC7C,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,cAAc,EAAE;IACrC,MAAM,EACJ,MAAM,EAAE,YAAY,GAAG,EAAE,EAC1B,GAAG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AAqB,CAC5C,CAAC,EACFA,cAAC,CAAA,eAAe,cAAE,SAAS,EAAA,CAAmB,CACvC,EAAA,CAAA;AAEb;;;;","x_google_ignoreList":[2]}
|
|
1
|
+
{"version":3,"file":"index.cjs.js","sources":["../node_modules/style-inject/dist/style-inject.es.js","../src/lib.ts","../src/context.tsx","../src/footer.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import { ComponentProps, createElement, FunctionComponent, ReactElement, ReactNode } from 'react';\n\n/**\n * The function to be passed into a block component as `children` to selectively override default blocks, or just a `ReactNode`.\n *\n * @example\n * <Block>\n * {({ defaultBlocks: { header, ...defaultBlocks }, defaultBlockOrder }) => ({\n * blocks: {\n * ...defaultBlocks,\n * header: {\n * ...header,\n * props: {\n * ...header.props,\n * label: \"Custom Label\"\n * }\n * },\n * subheader: <CustomComponent />\n * },\n * blockOrder: [\"header\", \"subheader\", \"body\", \"footer\"]\n * })}\n * </Block>\n */\nexport type BlocksOverride<DefaultBlocks, CustomBlocks> =\n | (({\n defaultBlocks,\n defaultBlockOrder,\n }: {\n defaultBlocks: DefaultBlocks;\n defaultBlockOrder: readonly (keyof DefaultBlocks)[];\n }) => {\n blocks: Partial<DefaultBlocks> & CustomBlocks;\n // NOTE: This specific combination allows proper autocomplete.\n blockOrder: readonly (keyof DefaultBlocks)[] | readonly (keyof CustomBlocks)[];\n })\n | ReactNode;\n\n/**\n * Creates a strongly typed `defaultBlocks` object, allowing for types to propagate into block override objects.\n *\n * @param components - A map of default block keys to component functions.\n *\n * @example\n * const defaultBlocks = createDefaultBlocks({\n * title: Title,\n * description: Description,\n * form: Form,\n * });\n */\nexport function createDefaultBlocks<T extends Record<string, FunctionComponent<any>>>(\n components: T\n): {\n [K in keyof T]: ReactElement<ComponentProps<T[K]>, T[K]>;\n} {\n return Object.fromEntries(\n Object.entries(components).map(([key, Component]) => [key, createElement(Component, { key })])\n ) as {\n [K in keyof T]: ReactElement<ComponentProps<T[K]>, T[K]>;\n };\n}\n\n/**\n * A component for rendering {@link BlocksOverride|`BlocksOverride`} results.\n * Exposes the evaluated `blocks` and `blockOrder` as arguments to the `children` function.\n *\n * @param props\n * @param props.blocksOverride - The {@link BlocksOverride|`BlocksOverride`} (i.e. `children` of outer component).\n * @param props.defaultBlocks - The default blocks of outer component.\n * @param props.children - A function returning the JSX to render.\n *\n * @example\n * <BlocksOverrideComponent\n * defaultBlocks={defaultFormBlocks}\n * blocksOverride={children}\n * >\n * {({ blocks, blockOrder }) =>\n * blockOrder.map((key) => (\n * <Fragment key={String(key)}>{blocks[key]}</Fragment>\n * ))\n * }\n * </BlocksOverrideComponent>\n */\nexport function BlocksOverrideComponent<\n DefaultBlocks extends Record<string, ReactNode>,\n CustomBlocks extends Record<string, ReactNode>,\n>({\n blocksOverride,\n defaultBlocks,\n defaultBlockOrder,\n children,\n}: {\n blocksOverride: BlocksOverride<DefaultBlocks, CustomBlocks>;\n defaultBlocks: DefaultBlocks;\n defaultBlockOrder: (keyof DefaultBlocks)[];\n children: ({\n blocks,\n blockOrder,\n }: {\n // TODO: Possibly find an alternative to Partial<CustomBlocks>\n blocks: Partial<DefaultBlocks> & Partial<CustomBlocks>;\n blockOrder: readonly (keyof DefaultBlocks | keyof CustomBlocks)[];\n }) => ReactNode;\n}) {\n if (blocksOverride === undefined) {\n return children({\n // TODO: Remove this assertion\n blocks: defaultBlocks as DefaultBlocks & Partial<CustomBlocks>,\n blockOrder: defaultBlockOrder,\n });\n }\n\n if (typeof blocksOverride === 'function') {\n const { blocks, blockOrder } = blocksOverride({\n defaultBlocks,\n defaultBlockOrder,\n });\n\n return children({ blocks, blockOrder });\n }\n\n return blocksOverride;\n}\n\ntype MergeTypes<Object1, Object2> = {\n [K in keyof Object1 | keyof Object2]: K extends keyof Object1\n ? Object1[K]\n : K extends keyof Object2\n ? Object2[K]\n : never;\n};\n\nexport function deepMerge<A extends Record<string, any>, B extends Record<string, any>>(obj1: A, obj2: B) {\n const result: Record<string, any> = { ...obj1 };\n\n for (const key in obj2) {\n if (obj2.hasOwnProperty(key)) {\n const val1 = result[key];\n const val2 = obj2[key];\n\n if (Array.isArray(val1) || Array.isArray(val2)) {\n // If either is an array, replace entirely with obj2's value\n result[key] = val2;\n } else if (typeof val1 === 'object' && val1 !== null && typeof val2 === 'object' && val2 !== null) {\n result[key] = deepMerge(val1, val2);\n } else {\n result[key] = val2;\n }\n }\n }\n\n return result as MergeTypes<B, A>;\n}\n\ntype ClassName = string | ClassName[] | undefined | null;\n\n/**\n * Utility function to join class names together, ignoring undefined or nil values.\n * @param classes - The class names to join.\n * @returns The joined class names.\n */\nexport function classNames(...classes: ClassName[]): string {\n return classes.flat().filter(Boolean).join(' ');\n}\n","import { createContext, ReactNode, useContext } from 'react';\n\ntype FooterContextValue = {\n logoSrc: string;\n copyright: ReactNode;\n content: ReactNode;\n};\n\nconst FooterContext = createContext<FooterContextValue | undefined>(undefined);\n\nexport const FooterProvider = ({\n children,\n ...value\n}: FooterContextValue & {\n children: ReactNode;\n}) => {\n return <FooterContext.Provider value={value}>{children}</FooterContext.Provider>;\n};\n\nexport const useFooterContext = () => {\n const context = useContext<FooterContextValue | undefined>(FooterContext);\n\n if (!context) {\n throw new Error('useFooterContext must be used within a FooterProvider');\n }\n return context;\n};\n","import { ComponentProps, Fragment, ReactNode } from 'react';\nimport './footer.css';\nimport { BlocksOverride, BlocksOverrideComponent, classNames, createDefaultBlocks, deepMerge } from './lib';\nimport { FooterProvider, useFooterContext } from './context';\nimport { Box, Stack } from '@mui/material';\n\nconst Footer = <CustomBlocks extends Record<string, ReactNode> = {}>({\n logoSrc,\n content,\n copyright,\n className,\n children,\n ...props\n}: Omit<ComponentProps<typeof Stack>, 'content' | 'children'> & {\n logoSrc: string;\n copyright: ReactNode;\n content: ReactNode;\n children?: BlocksOverride<typeof defaultBlocks, CustomBlocks>;\n}) => {\n const { sx: sxProp, ...restProps } = props;\n const sx = [\n {\n backgroundColor: 'primary.main',\n color: 'primary.contrastText',\n py: 3,\n px: 2,\n typography: 'body2',\n },\n ...(Array.isArray(sxProp) ? sxProp : [sxProp]),\n ];\n return (\n <Stack component=\"footer\" className={classNames('nbb-footer', className)} spacing={2} sx={sx} {...restProps}>\n <FooterProvider\n {...{\n logoSrc,\n content,\n copyright,\n }}\n >\n <BlocksOverrideComponent\n defaultBlocks={defaultBlocks}\n defaultBlockOrder={Object.keys(defaultBlocks) as (keyof typeof defaultBlocks)[]}\n blocksOverride={children}\n >\n {({ blocks: { ...blocks }, blockOrder }) =>\n blockOrder\n .filter((key) => key in blocks)\n .map<ReactNode>((key) => <Fragment key={String(key)}>{blocks[key]}</Fragment>)\n }\n </BlocksOverrideComponent>\n </FooterProvider>\n </Stack>\n );\n};\n\nFooter.Logo = (props: Partial<ComponentProps<typeof Box>>) => {\n const { className, logoSrc, sx: sxProp, ...restProps } = deepMerge(useFooterContext(), props);\n const sx = [\n {\n pb: 0.5,\n },\n ...(Array.isArray(sxProp) ? sxProp : [sxProp]),\n ];\n return (\n <Box className={classNames('nbb-footer-logo', className)} sx={sx} {...restProps}>\n <img src={logoSrc} alt={'Footer logo'} />\n </Box>\n );\n};\n\nFooter.Content = (props: Partial<ComponentProps<typeof Box>>) => {\n const { className, children, content } = deepMerge(useFooterContext(), props);\n\n return (\n <Box className={classNames('nbb-footer-content', className)} {...props}>\n {content || children}\n </Box>\n );\n};\n\nFooter.Copyright = (props: Partial<ComponentProps<typeof Box>>) => {\n const { className, children, copyright } = deepMerge(useFooterContext(), props);\n\n return (\n <Box className={classNames('nbb-footer-copyright', className)} {...props}>\n {copyright || children}\n </Box>\n );\n};\n\nconst defaultBlocks = createDefaultBlocks({\n logo: Footer.Logo,\n content: Footer.Content,\n copyright: Footer.Copyright,\n});\n\nexport default Footer;\n"],"names":["createElement","createContext","_jsx","useContext","Stack","Fragment","Box"],"mappings":";;;;;;;;;;;;AAAA,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;AAC/B,EAAE,KAAK,GAAG,KAAK,MAAM,GAAG,GAAG,GAAG,EAAE;AAChC,EAAE,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ;;AAE7B,EAAE,IAAY,OAAO,QAAQ,KAAK,WAAW,EAAE,EAAE,OAAO,CAAC;;AAEzD,EAAE,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtE,EAAE,IAAI,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC;AAC7C,EAAE,KAAK,CAAC,IAAI,GAAG,UAAU;;AAEzB,EAAE,IAAI,QAAQ,KAAK,KAAK,EAAE;AAC1B,IAAI,IAAI,IAAI,CAAC,UAAU,EAAE;AACzB,MAAM,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,UAAU,CAAC;AAC/C,IAAI,CAAC,MAAM;AACX,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;AAC7B,IAAI;AACJ,EAAE,CAAC,MAAM;AACT,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC;AAC3B,EAAE;;AAEF,EAAE,IAAI,KAAK,CAAC,UAAU,EAAE;AACxB,IAAI,KAAK,CAAC,UAAU,CAAC,OAAO,GAAG,GAAG;AAClC,EAAE,CAAC,MAAM;AACT,IAAI,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AACnD,EAAE;AACF;;;;;ACYA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ACvB,SAAS,EAAE,MAAM,CAAC,SAAS;AAC5B,CAAA,CAAC;;;;","x_google_ignoreList":[0]}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
1
|
|
|
3
|
-
function setBlocks(defaultBlocks, defaultOptions, children) {
|
|
4
|
-
const results = children
|
|
5
|
-
? children({ defaultBlocks, ...defaultOptions })
|
|
6
|
-
: { blocks: {}, ...defaultOptions };
|
|
7
|
-
const { blocks: customBlocks = {} } = results;
|
|
8
|
-
return {
|
|
9
|
-
...results,
|
|
10
|
-
blocks: Object.fromEntries(Object.entries(defaultBlocks).map(([key, defaultComponent]) => [
|
|
11
|
-
key,
|
|
12
|
-
customBlocks[key] || defaultComponent,
|
|
13
|
-
])),
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Utility function to join class names together, ignoring undefined or nil values.
|
|
18
|
-
* @param classes - The class names to join.
|
|
19
|
-
* @returns The joined class names.
|
|
20
|
-
*/
|
|
21
|
-
function classNames(...classes) {
|
|
22
|
-
return classes.flat().filter(Boolean).join(' ');
|
|
23
|
-
}
|
|
24
2
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
};
|
|
3
|
+
if (typeof global === 'undefined') {
|
|
4
|
+
var global = window;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
import { jsx } from 'react/jsx-runtime';
|
|
8
|
+
import { createElement, createContext, useContext, Fragment } from 'react';
|
|
9
|
+
import { Stack, Box } from '@mui/material';
|
|
30
10
|
|
|
31
11
|
function styleInject(css, ref) {
|
|
32
12
|
if ( ref === void 0 ) ref = {};
|
|
@@ -55,14 +35,144 @@ function styleInject(css, ref) {
|
|
|
55
35
|
}
|
|
56
36
|
}
|
|
57
37
|
|
|
58
|
-
var css_248z = "
|
|
38
|
+
var css_248z = ".nbb-footer img {\n display: block;\n}\n\n.nbb-footer a {\n color: inherit;\n}\n.nbb-footer a:hover {\n text-decoration: underline;\n}\n";
|
|
59
39
|
styleInject(css_248z);
|
|
60
40
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Creates a strongly typed `defaultBlocks` object, allowing for types to propagate into block override objects.
|
|
43
|
+
*
|
|
44
|
+
* @param components - A map of default block keys to component functions.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const defaultBlocks = createDefaultBlocks({
|
|
48
|
+
* title: Title,
|
|
49
|
+
* description: Description,
|
|
50
|
+
* form: Form,
|
|
51
|
+
* });
|
|
52
|
+
*/
|
|
53
|
+
function createDefaultBlocks(components) {
|
|
54
|
+
return Object.fromEntries(Object.entries(components).map(([key, Component]) => [key, createElement(Component, { key })]));
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A component for rendering {@link BlocksOverride|`BlocksOverride`} results.
|
|
58
|
+
* Exposes the evaluated `blocks` and `blockOrder` as arguments to the `children` function.
|
|
59
|
+
*
|
|
60
|
+
* @param props
|
|
61
|
+
* @param props.blocksOverride - The {@link BlocksOverride|`BlocksOverride`} (i.e. `children` of outer component).
|
|
62
|
+
* @param props.defaultBlocks - The default blocks of outer component.
|
|
63
|
+
* @param props.children - A function returning the JSX to render.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* <BlocksOverrideComponent
|
|
67
|
+
* defaultBlocks={defaultFormBlocks}
|
|
68
|
+
* blocksOverride={children}
|
|
69
|
+
* >
|
|
70
|
+
* {({ blocks, blockOrder }) =>
|
|
71
|
+
* blockOrder.map((key) => (
|
|
72
|
+
* <Fragment key={String(key)}>{blocks[key]}</Fragment>
|
|
73
|
+
* ))
|
|
74
|
+
* }
|
|
75
|
+
* </BlocksOverrideComponent>
|
|
76
|
+
*/
|
|
77
|
+
function BlocksOverrideComponent({ blocksOverride, defaultBlocks, defaultBlockOrder, children, }) {
|
|
78
|
+
if (blocksOverride === undefined) {
|
|
79
|
+
return children({
|
|
80
|
+
// TODO: Remove this assertion
|
|
81
|
+
blocks: defaultBlocks,
|
|
82
|
+
blockOrder: defaultBlockOrder,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (typeof blocksOverride === 'function') {
|
|
86
|
+
const { blocks, blockOrder } = blocksOverride({
|
|
87
|
+
defaultBlocks,
|
|
88
|
+
defaultBlockOrder,
|
|
89
|
+
});
|
|
90
|
+
return children({ blocks, blockOrder });
|
|
91
|
+
}
|
|
92
|
+
return blocksOverride;
|
|
93
|
+
}
|
|
94
|
+
function deepMerge(obj1, obj2) {
|
|
95
|
+
const result = { ...obj1 };
|
|
96
|
+
for (const key in obj2) {
|
|
97
|
+
if (obj2.hasOwnProperty(key)) {
|
|
98
|
+
const val1 = result[key];
|
|
99
|
+
const val2 = obj2[key];
|
|
100
|
+
if (Array.isArray(val1) || Array.isArray(val2)) {
|
|
101
|
+
// If either is an array, replace entirely with obj2's value
|
|
102
|
+
result[key] = val2;
|
|
103
|
+
}
|
|
104
|
+
else if (typeof val1 === 'object' && val1 !== null && typeof val2 === 'object' && val2 !== null) {
|
|
105
|
+
result[key] = deepMerge(val1, val2);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
result[key] = val2;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Utility function to join class names together, ignoring undefined or nil values.
|
|
116
|
+
* @param classes - The class names to join.
|
|
117
|
+
* @returns The joined class names.
|
|
118
|
+
*/
|
|
119
|
+
function classNames(...classes) {
|
|
120
|
+
return classes.flat().filter(Boolean).join(' ');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const FooterContext = createContext(undefined);
|
|
124
|
+
const FooterProvider = ({ children, ...value }) => {
|
|
125
|
+
return jsx(FooterContext.Provider, { value: value, children: children });
|
|
126
|
+
};
|
|
127
|
+
const useFooterContext = () => {
|
|
128
|
+
const context = useContext(FooterContext);
|
|
129
|
+
if (!context) {
|
|
130
|
+
throw new Error('useFooterContext must be used within a FooterProvider');
|
|
131
|
+
}
|
|
132
|
+
return context;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const Footer = ({ logoSrc, content, copyright, className, children, ...props }) => {
|
|
136
|
+
const { sx: sxProp, ...restProps } = props;
|
|
137
|
+
const sx = [
|
|
138
|
+
{
|
|
139
|
+
backgroundColor: 'primary.main',
|
|
140
|
+
color: 'primary.contrastText',
|
|
141
|
+
py: 3,
|
|
142
|
+
px: 2,
|
|
143
|
+
typography: 'body2',
|
|
144
|
+
},
|
|
145
|
+
...(Array.isArray(sxProp) ? sxProp : [sxProp]),
|
|
146
|
+
];
|
|
147
|
+
return (jsx(Stack, { component: "footer", className: classNames('nbb-footer', className), spacing: 2, sx: sx, ...restProps, children: jsx(FooterProvider, { logoSrc,
|
|
148
|
+
content,
|
|
149
|
+
copyright, children: jsx(BlocksOverrideComponent, { defaultBlocks: defaultBlocks, defaultBlockOrder: Object.keys(defaultBlocks), blocksOverride: children, children: ({ blocks: { ...blocks }, blockOrder }) => blockOrder
|
|
150
|
+
.filter((key) => key in blocks)
|
|
151
|
+
.map((key) => jsx(Fragment, { children: blocks[key] }, String(key))) }) }) }));
|
|
152
|
+
};
|
|
153
|
+
Footer.Logo = (props) => {
|
|
154
|
+
const { className, logoSrc, sx: sxProp, ...restProps } = deepMerge(useFooterContext(), props);
|
|
155
|
+
const sx = [
|
|
156
|
+
{
|
|
157
|
+
pb: 0.5,
|
|
158
|
+
},
|
|
159
|
+
...(Array.isArray(sxProp) ? sxProp : [sxProp]),
|
|
160
|
+
];
|
|
161
|
+
return (jsx(Box, { className: classNames('nbb-footer-logo', className), sx: sx, ...restProps, children: jsx("img", { src: logoSrc, alt: 'Footer logo' }) }));
|
|
162
|
+
};
|
|
163
|
+
Footer.Content = (props) => {
|
|
164
|
+
const { className, children, content } = deepMerge(useFooterContext(), props);
|
|
165
|
+
return (jsx(Box, { className: classNames('nbb-footer-content', className), ...props, children: content || children }));
|
|
166
|
+
};
|
|
167
|
+
Footer.Copyright = (props) => {
|
|
168
|
+
const { className, children, copyright } = deepMerge(useFooterContext(), props);
|
|
169
|
+
return (jsx(Box, { className: classNames('nbb-footer-copyright', className), ...props, children: copyright || children }));
|
|
65
170
|
};
|
|
171
|
+
const defaultBlocks = createDefaultBlocks({
|
|
172
|
+
logo: Footer.Logo,
|
|
173
|
+
content: Footer.Content,
|
|
174
|
+
copyright: Footer.Copyright,
|
|
175
|
+
});
|
|
66
176
|
|
|
67
177
|
export { Footer };
|
|
68
178
|
//# sourceMappingURL=index.esm.js.map
|
package/dist/index.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":["../src/lib.ts","../src/blocks.tsx","../node_modules/style-inject/dist/style-inject.es.js","../src/footer.tsx"],"sourcesContent":["import { DefaultBlocks, DefaultOptions } from './blocks';\n\n/**\n * Sets the blocks by merging default blocks with custom blocks provided by the children function.\n *\n * @param defaultBlocks - The default blocks to be used.\n * @param children - An optional function that returns custom blocks and arguments.\n * @param args - Additional unknown arguments.\n * @returns An object containing the merged blocks and additional arguments.\n */\n\n\ntype ChildrenProps = {\n defaultBlocks: DefaultBlocks;\n};\n\nexport function setBlocks(\n defaultBlocks: DefaultBlocks,\n defaultOptions: DefaultOptions,\n children?: (props: ChildrenProps) => DefaultOptions & {\n blocks: { [x: string]: any };\n },\n) {\n const results = children\n ? children({ defaultBlocks, ...defaultOptions })\n : { blocks: {}, ...defaultOptions };\n const {\n blocks: customBlocks = {}\n } = results;\n return {\n ...results,\n blocks: Object.fromEntries(\n Object.entries(defaultBlocks).map(([key, defaultComponent]) => [\n key,\n customBlocks[key] || defaultComponent,\n ])\n ),\n };\n}\n\ntype ClassName = string | ClassName[] | undefined | null;\n\n/**\n * Utility function to join class names together, ignoring undefined or nil values.\n * @param classes - The class names to join.\n * @returns The joined class names.\n */\nexport function classNames(...classes: ClassName[]): string {\n return classes.flat().filter(Boolean).join(' ');\n}\n","import React from 'react';\n\nexport type DefaultBlocks = {\n FooterLogo: React.FC<{ src: string; alt?: string }>;\n FooterText: React.FC<{ children: React.ReactNode }>;\n FooterCopyright: React.FC<{ children: React.ReactNode }>;\n};\n\nexport type DefaultOptions = {\n hideTitle?: boolean;\n};\n\nexport const defaultOptions: DefaultOptions = {\n hideTitle: false,\n};\n\nfunction FooterTitle({ children }: { children: React.ReactNode }) {\n return <h2 className=\"nbb-footer-title\">{children}</h2>;\n}\n\nfunction FooterText({ children }: { children: React.ReactNode }) {\n return <p className=\"nbb-footer-text\">{children}</p>;\n}\n\nfunction FooterCopyright({ children }: { children: React.ReactNode }) {\n return <p className=\"nbb-footer-copyright\">{children}</p>;\n}\n\n\n\nexport const defaultBlocks: DefaultBlocks = {\n FooterLogo: ({ src, alt }) => (\n <img className=\"nbb-footer-logo\" src={src} alt={alt || 'Footer logo'} />\n ),\n FooterText: ({ children }) => <p className=\"nbb-footer-text\">{children}</p>,\n FooterCopyright: ({ children }) => (\n <p className=\"nbb-footer-copyright\">{children}</p>\n ),\n};","function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import React from \"react\";\nimport { setBlocks, classNames } from \"./lib\";\nimport { defaultBlocks, DefaultBlocks } from \"./blocks\";\nimport \"./footer.css\";\n\nexport type FooterChildren = (props: {\n defaultBlocks: DefaultBlocks,\n settings?: { [key: string]: any }\n}\n) => {\n blocks: Partial<DefaultBlocks>;\n settings?: { [key: string]: any };\n};\n\nconst Footer = ({\n logoSrc,\n items = [],\n className,\n children, copyright }:\n {\n className: string;\n logoSrc: string;\n copyright: React.ReactNode | string;\n items: Array<React.ReactNode>;\n children?: FooterChildren;\n}) => {\n const { blocks } = setBlocks(defaultBlocks, {}, children);\n const { FooterLogo, FooterText, FooterCopyright } = blocks;\n\n return (\n <footer className={classNames(\"nbb-footer\", className)}>\n <FooterLogo src={logoSrc} />\n {items.map((item, index) => (\n <FooterText key={index}>{item}</FooterText>\n ))}\n <FooterCopyright>{copyright}</FooterCopyright>\n </footer>\n );\n};\n\nexport default Footer;\n"],"names":["_jsx","_jsxs"],"mappings":";;SAgBgB,SAAS,CACvB,aAA4B,EAC5B,cAA8B,EAC9B,QAEC,EAAA;IAED,MAAM,OAAO,GAAG;UACZ,QAAQ,CAAC,EAAE,aAAa,EAAE,GAAG,cAAc,EAAE;UAC7C,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,cAAc,EAAE;IACrC,MAAM,EACJ,MAAM,EAAE,YAAY,GAAG,EAAE,EAC1B,GAAG,OAAO;IACX,OAAO;AACL,QAAA,GAAG,OAAO;QACV,MAAM,EAAE,MAAM,CAAC,WAAW,CACxB,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,gBAAgB,CAAC,KAAK;YAC7D,GAAG;AACH,YAAA,YAAY,CAAC,GAAG,CAAC,IAAI,gBAAgB;AACtC,SAAA,CAAC,CACH;KACF;AACH;AAIA;;;;AAIG;AACa,SAAA,UAAU,CAAC,GAAG,OAAoB,EAAA;AAChD,IAAA,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;AACjD;;ACnBO,MAAM,aAAa,GAAkB;IAC1C,UAAU,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MACvBA,GAAK,CA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,CAAC,UAAU,CAAC,OAAO,GAAG,GAAG;AAClC,GAAG,MAAM;AACT,IAAI,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;AACnD;AACA;;;;;ACXA,MAAM,MAAM,GAAG,CAAC,EACd,OAAO,EACP,KAAK,GAAG,EAAE,EACV,SAAS,EACT,QAAQ,EAAE,SAAS,EAOpB,KAAI;AACH,IAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC,aAAa,EAAE,EAAE,EAAE,QAAQ,CAAC;IACzD,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,MAAM;IAE1D,QACEC,iBAAQ,SAAS,EAAE,UAAU,CAAC,YAAY,EAAE,SAAS,CAAC,EAAA,QAAA,EAAA,CACpDD,IAAC,UAAU,EAAA,EAAC,GAAG,EAAE,OAAO,GAAI,EAC3B,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,MACrBA,GAAC,CAAA,UAAU,EAAc,EAAA,QAAA,EAAA,IAAI,EAAZ,EAAA,KAAK,CAAqB,CAC5C,CAAC,EACFA,GAAC,CAAA,eAAe,cAAE,SAAS,EAAA,CAAmB,CACvC,EAAA,CAAA;AAEb;;;;","x_google_ignoreList":[2]}
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../node_modules/style-inject/dist/style-inject.es.js","../src/lib.ts","../src/context.tsx","../src/footer.tsx"],"sourcesContent":["function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","import { ComponentProps, createElement, FunctionComponent, ReactElement, ReactNode } from 'react';\n\n/**\n * The function to be passed into a block component as `children` to selectively override default blocks, or just a `ReactNode`.\n *\n * @example\n * <Block>\n * {({ defaultBlocks: { header, ...defaultBlocks }, defaultBlockOrder }) => ({\n * blocks: {\n * ...defaultBlocks,\n * header: {\n * ...header,\n * props: {\n * ...header.props,\n * label: \"Custom Label\"\n * }\n * },\n * subheader: <CustomComponent />\n * },\n * blockOrder: [\"header\", \"subheader\", \"body\", \"footer\"]\n * })}\n * </Block>\n */\nexport type BlocksOverride<DefaultBlocks, CustomBlocks> =\n | (({\n defaultBlocks,\n defaultBlockOrder,\n }: {\n defaultBlocks: DefaultBlocks;\n defaultBlockOrder: readonly (keyof DefaultBlocks)[];\n }) => {\n blocks: Partial<DefaultBlocks> & CustomBlocks;\n // NOTE: This specific combination allows proper autocomplete.\n blockOrder: readonly (keyof DefaultBlocks)[] | readonly (keyof CustomBlocks)[];\n })\n | ReactNode;\n\n/**\n * Creates a strongly typed `defaultBlocks` object, allowing for types to propagate into block override objects.\n *\n * @param components - A map of default block keys to component functions.\n *\n * @example\n * const defaultBlocks = createDefaultBlocks({\n * title: Title,\n * description: Description,\n * form: Form,\n * });\n */\nexport function createDefaultBlocks<T extends Record<string, FunctionComponent<any>>>(\n components: T\n): {\n [K in keyof T]: ReactElement<ComponentProps<T[K]>, T[K]>;\n} {\n return Object.fromEntries(\n Object.entries(components).map(([key, Component]) => [key, createElement(Component, { key })])\n ) as {\n [K in keyof T]: ReactElement<ComponentProps<T[K]>, T[K]>;\n };\n}\n\n/**\n * A component for rendering {@link BlocksOverride|`BlocksOverride`} results.\n * Exposes the evaluated `blocks` and `blockOrder` as arguments to the `children` function.\n *\n * @param props\n * @param props.blocksOverride - The {@link BlocksOverride|`BlocksOverride`} (i.e. `children` of outer component).\n * @param props.defaultBlocks - The default blocks of outer component.\n * @param props.children - A function returning the JSX to render.\n *\n * @example\n * <BlocksOverrideComponent\n * defaultBlocks={defaultFormBlocks}\n * blocksOverride={children}\n * >\n * {({ blocks, blockOrder }) =>\n * blockOrder.map((key) => (\n * <Fragment key={String(key)}>{blocks[key]}</Fragment>\n * ))\n * }\n * </BlocksOverrideComponent>\n */\nexport function BlocksOverrideComponent<\n DefaultBlocks extends Record<string, ReactNode>,\n CustomBlocks extends Record<string, ReactNode>,\n>({\n blocksOverride,\n defaultBlocks,\n defaultBlockOrder,\n children,\n}: {\n blocksOverride: BlocksOverride<DefaultBlocks, CustomBlocks>;\n defaultBlocks: DefaultBlocks;\n defaultBlockOrder: (keyof DefaultBlocks)[];\n children: ({\n blocks,\n blockOrder,\n }: {\n // TODO: Possibly find an alternative to Partial<CustomBlocks>\n blocks: Partial<DefaultBlocks> & Partial<CustomBlocks>;\n blockOrder: readonly (keyof DefaultBlocks | keyof CustomBlocks)[];\n }) => ReactNode;\n}) {\n if (blocksOverride === undefined) {\n return children({\n // TODO: Remove this assertion\n blocks: defaultBlocks as DefaultBlocks & Partial<CustomBlocks>,\n blockOrder: defaultBlockOrder,\n });\n }\n\n if (typeof blocksOverride === 'function') {\n const { blocks, blockOrder } = blocksOverride({\n defaultBlocks,\n defaultBlockOrder,\n });\n\n return children({ blocks, blockOrder });\n }\n\n return blocksOverride;\n}\n\ntype MergeTypes<Object1, Object2> = {\n [K in keyof Object1 | keyof Object2]: K extends keyof Object1\n ? Object1[K]\n : K extends keyof Object2\n ? Object2[K]\n : never;\n};\n\nexport function deepMerge<A extends Record<string, any>, B extends Record<string, any>>(obj1: A, obj2: B) {\n const result: Record<string, any> = { ...obj1 };\n\n for (const key in obj2) {\n if (obj2.hasOwnProperty(key)) {\n const val1 = result[key];\n const val2 = obj2[key];\n\n if (Array.isArray(val1) || Array.isArray(val2)) {\n // If either is an array, replace entirely with obj2's value\n result[key] = val2;\n } else if (typeof val1 === 'object' && val1 !== null && typeof val2 === 'object' && val2 !== null) {\n result[key] = deepMerge(val1, val2);\n } else {\n result[key] = val2;\n }\n }\n }\n\n return result as MergeTypes<B, A>;\n}\n\ntype ClassName = string | ClassName[] | undefined | null;\n\n/**\n * Utility function to join class names together, ignoring undefined or nil values.\n * @param classes - The class names to join.\n * @returns The joined class names.\n */\nexport function classNames(...classes: ClassName[]): string {\n return classes.flat().filter(Boolean).join(' ');\n}\n","import { createContext, ReactNode, useContext } from 'react';\n\ntype FooterContextValue = {\n logoSrc: string;\n copyright: ReactNode;\n content: ReactNode;\n};\n\nconst FooterContext = createContext<FooterContextValue | undefined>(undefined);\n\nexport const FooterProvider = ({\n children,\n ...value\n}: FooterContextValue & {\n children: ReactNode;\n}) => {\n return <FooterContext.Provider value={value}>{children}</FooterContext.Provider>;\n};\n\nexport const useFooterContext = () => {\n const context = useContext<FooterContextValue | undefined>(FooterContext);\n\n if (!context) {\n throw new Error('useFooterContext must be used within a FooterProvider');\n }\n return context;\n};\n","import { ComponentProps, Fragment, ReactNode } from 'react';\nimport './footer.css';\nimport { BlocksOverride, BlocksOverrideComponent, classNames, createDefaultBlocks, deepMerge } from './lib';\nimport { FooterProvider, useFooterContext } from './context';\nimport { Box, Stack } from '@mui/material';\n\nconst Footer = <CustomBlocks extends Record<string, ReactNode> = {}>({\n logoSrc,\n content,\n copyright,\n className,\n children,\n ...props\n}: Omit<ComponentProps<typeof Stack>, 'content' | 'children'> & {\n logoSrc: string;\n copyright: ReactNode;\n content: ReactNode;\n children?: BlocksOverride<typeof defaultBlocks, CustomBlocks>;\n}) => {\n const { sx: sxProp, ...restProps } = props;\n const sx = [\n {\n backgroundColor: 'primary.main',\n color: 'primary.contrastText',\n py: 3,\n px: 2,\n typography: 'body2',\n },\n ...(Array.isArray(sxProp) ? sxProp : [sxProp]),\n ];\n return (\n <Stack component=\"footer\" className={classNames('nbb-footer', className)} spacing={2} sx={sx} {...restProps}>\n <FooterProvider\n {...{\n logoSrc,\n content,\n copyright,\n }}\n >\n <BlocksOverrideComponent\n defaultBlocks={defaultBlocks}\n defaultBlockOrder={Object.keys(defaultBlocks) as (keyof typeof defaultBlocks)[]}\n blocksOverride={children}\n >\n {({ blocks: { ...blocks }, blockOrder }) =>\n blockOrder\n .filter((key) => key in blocks)\n .map<ReactNode>((key) => <Fragment key={String(key)}>{blocks[key]}</Fragment>)\n }\n </BlocksOverrideComponent>\n </FooterProvider>\n </Stack>\n );\n};\n\nFooter.Logo = (props: Partial<ComponentProps<typeof Box>>) => {\n const { className, logoSrc, sx: sxProp, ...restProps } = deepMerge(useFooterContext(), props);\n const sx = [\n {\n pb: 0.5,\n },\n ...(Array.isArray(sxProp) ? sxProp : [sxProp]),\n ];\n return (\n <Box className={classNames('nbb-footer-logo', className)} sx={sx} {...restProps}>\n <img src={logoSrc} alt={'Footer logo'} />\n </Box>\n );\n};\n\nFooter.Content = (props: Partial<ComponentProps<typeof Box>>) => {\n const { className, children, content } = deepMerge(useFooterContext(), props);\n\n return (\n <Box className={classNames('nbb-footer-content', className)} {...props}>\n {content || children}\n </Box>\n );\n};\n\nFooter.Copyright = (props: Partial<ComponentProps<typeof Box>>) => {\n const { className, children, copyright } = deepMerge(useFooterContext(), props);\n\n return (\n <Box className={classNames('nbb-footer-copyright', className)} {...props}>\n {copyright || children}\n </Box>\n );\n};\n\nconst defaultBlocks = createDefaultBlocks({\n logo: Footer.Logo,\n content: Footer.Content,\n copyright: Footer.Copyright,\n});\n\nexport default Footer;\n"],"names":["_jsx"],"mappings":";;;;;;;;;;AAAA,SAAS,WAAW,CAAC,GAAG,EAAE,GAAG,EAAE;AAC/B,EAAE,KAAK,GAAG,KAAK,MAAM,GAAG,GAAG,GAAG,EAAE;AAChC,EAAE,IAAI,QAAQ,GAAG,GAAG,CAAC,QAAQ;;AAE7B,EAAE,IAAY,OAAO,QAAQ,KAAK,WAAW,EAAE,EAAE,OAAO,CAAC;;AAEzD,EAAE,IAAI,IAAI,GAAG,QAAQ,CAAC,IAAI,IAAI,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtE,EA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,SAAS,CAAC,gBAAgB,EAAE,EAAE,KAAK,CAAC;IAE7E,QACEA,IAAC,GAAG,EAAA,EAAC,SAAS,EAAE,UAAU,CAAC,oBAAoB,EAAE,SAAS,CAAC,EAAA,GAAM,KAAK,EAAA,QAAA,EACnE,OAAO,IAAI,QAAQ,EAAA,CAChB;AAEV,CAAC;AAED,MAAM,CAAC,SAAS,GAAG,CAAC,KAA0C,KAAI;AAChE,IAAA,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,SAAS,CAAC,gBAAgB,EAAE,EAAE,KAAK,CAAC;IAE/E,QACEA,IAAC,GAAG,EAAA,EAAC,SAAS,EAAE,UAAU,CAAC,sBAAsB,EAAE,SAAS,CAAC,EAAA,GAAM,KAAK,EAAA,QAAA,EACrE,SAAS,IAAI,QAAQ,EAAA,CAClB;AAEV,CAAC;AAED,MAAM,aAAa,GAAG,mBAAmB,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC,IAAI;IACjB,OAAO,EAAE,MAAM,CAAC,OAAO;IACvB,SAAS,EAAE,MAAM,CAAC,SAAS;AAC5B,CAAA,CAAC;;;;","x_google_ignoreList":[0]}
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,25 +1,81 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentProps, FunctionComponent, ReactElement, ReactNode } from 'react';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* The function to be passed into a block component as `children` to selectively override default blocks, or just a `ReactNode`.
|
|
4
4
|
*
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* @example
|
|
6
|
+
* <Block>
|
|
7
|
+
* {({ defaultBlocks: { header, ...defaultBlocks }, defaultBlockOrder }) => ({
|
|
8
|
+
* blocks: {
|
|
9
|
+
* ...defaultBlocks,
|
|
10
|
+
* header: {
|
|
11
|
+
* ...header,
|
|
12
|
+
* props: {
|
|
13
|
+
* ...header.props,
|
|
14
|
+
* label: "Custom Label"
|
|
15
|
+
* }
|
|
16
|
+
* },
|
|
17
|
+
* subheader: <CustomComponent />
|
|
18
|
+
* },
|
|
19
|
+
* blockOrder: ["header", "subheader", "body", "footer"]
|
|
20
|
+
* })}
|
|
21
|
+
* </Block>
|
|
9
22
|
*/
|
|
10
|
-
type
|
|
23
|
+
export type BlocksOverride<DefaultBlocks, CustomBlocks> = (({ defaultBlocks, defaultBlockOrder, }: {
|
|
11
24
|
defaultBlocks: DefaultBlocks;
|
|
25
|
+
defaultBlockOrder: readonly (keyof DefaultBlocks)[];
|
|
26
|
+
}) => {
|
|
27
|
+
blocks: Partial<DefaultBlocks> & CustomBlocks;
|
|
28
|
+
blockOrder: readonly (keyof DefaultBlocks)[] | readonly (keyof CustomBlocks)[];
|
|
29
|
+
}) | ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a strongly typed `defaultBlocks` object, allowing for types to propagate into block override objects.
|
|
32
|
+
*
|
|
33
|
+
* @param components - A map of default block keys to component functions.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* const defaultBlocks = createDefaultBlocks({
|
|
37
|
+
* title: Title,
|
|
38
|
+
* description: Description,
|
|
39
|
+
* form: Form,
|
|
40
|
+
* });
|
|
41
|
+
*/
|
|
42
|
+
export declare function createDefaultBlocks<T extends Record<string, FunctionComponent<any>>>(components: T): {
|
|
43
|
+
[K in keyof T]: ReactElement<ComponentProps<T[K]>, T[K]>;
|
|
12
44
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
45
|
+
/**
|
|
46
|
+
* A component for rendering {@link BlocksOverride|`BlocksOverride`} results.
|
|
47
|
+
* Exposes the evaluated `blocks` and `blockOrder` as arguments to the `children` function.
|
|
48
|
+
*
|
|
49
|
+
* @param props
|
|
50
|
+
* @param props.blocksOverride - The {@link BlocksOverride|`BlocksOverride`} (i.e. `children` of outer component).
|
|
51
|
+
* @param props.defaultBlocks - The default blocks of outer component.
|
|
52
|
+
* @param props.children - A function returning the JSX to render.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* <BlocksOverrideComponent
|
|
56
|
+
* defaultBlocks={defaultFormBlocks}
|
|
57
|
+
* blocksOverride={children}
|
|
58
|
+
* >
|
|
59
|
+
* {({ blocks, blockOrder }) =>
|
|
60
|
+
* blockOrder.map((key) => (
|
|
61
|
+
* <Fragment key={String(key)}>{blocks[key]}</Fragment>
|
|
62
|
+
* ))
|
|
63
|
+
* }
|
|
64
|
+
* </BlocksOverrideComponent>
|
|
65
|
+
*/
|
|
66
|
+
export declare function BlocksOverrideComponent<DefaultBlocks extends Record<string, ReactNode>, CustomBlocks extends Record<string, ReactNode>>({ blocksOverride, defaultBlocks, defaultBlockOrder, children, }: {
|
|
67
|
+
blocksOverride: BlocksOverride<DefaultBlocks, CustomBlocks>;
|
|
68
|
+
defaultBlocks: DefaultBlocks;
|
|
69
|
+
defaultBlockOrder: (keyof DefaultBlocks)[];
|
|
70
|
+
children: ({ blocks, blockOrder, }: {
|
|
71
|
+
blocks: Partial<DefaultBlocks> & Partial<CustomBlocks>;
|
|
72
|
+
blockOrder: readonly (keyof DefaultBlocks | keyof CustomBlocks)[];
|
|
73
|
+
}) => ReactNode;
|
|
74
|
+
}): ReactNode;
|
|
75
|
+
type MergeTypes<Object1, Object2> = {
|
|
76
|
+
[K in keyof Object1 | keyof Object2]: K extends keyof Object1 ? Object1[K] : K extends keyof Object2 ? Object2[K] : never;
|
|
22
77
|
};
|
|
78
|
+
export declare function deepMerge<A extends Record<string, any>, B extends Record<string, any>>(obj1: A, obj2: B): MergeTypes<B, A>;
|
|
23
79
|
type ClassName = string | ClassName[] | undefined | null;
|
|
24
80
|
/**
|
|
25
81
|
* Utility function to join class names together, ignoring undefined or nil values.
|
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAiB,iBAAiB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,cAAc,CAAC,aAAa,EAAE,YAAY,IAClD,CAAC,CAAC,EACA,aAAa,EACb,iBAAiB,GAClB,EAAE;IACD,aAAa,EAAE,aAAa,CAAC;IAC7B,iBAAiB,EAAE,SAAS,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC;CACrD,KAAK;IACJ,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,YAAY,CAAC;IAE9C,UAAU,EAAE,SAAS,CAAC,MAAM,aAAa,CAAC,EAAE,GAAG,SAAS,CAAC,MAAM,YAAY,CAAC,EAAE,CAAC;CAChF,CAAC,GACF,SAAS,CAAC;AAEd;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,GAAG,CAAC,CAAC,EAClF,UAAU,EAAE,CAAC,GACZ;KACA,CAAC,IAAI,MAAM,CAAC,GAAG,YAAY,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;CACzD,CAMA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,uBAAuB,CACrC,aAAa,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC/C,YAAY,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EAC9C,EACA,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,QAAQ,GACT,EAAE;IACD,cAAc,EAAE,cAAc,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;IAC5D,aAAa,EAAE,aAAa,CAAC;IAC7B,iBAAiB,EAAE,CAAC,MAAM,aAAa,CAAC,EAAE,CAAC;IAC3C,QAAQ,EAAE,CAAC,EACT,MAAM,EACN,UAAU,GACX,EAAE;QAED,MAAM,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;QACvD,UAAU,EAAE,SAAS,CAAC,MAAM,aAAa,GAAG,MAAM,YAAY,CAAC,EAAE,CAAC;KACnE,KAAK,SAAS,CAAC;CACjB,aAmBA;AAED,KAAK,UAAU,CAAC,OAAO,EAAE,OAAO,IAAI;KACjC,CAAC,IAAI,MAAM,OAAO,GAAG,MAAM,OAAO,GAAG,CAAC,SAAS,MAAM,OAAO,GACzD,OAAO,CAAC,CAAC,CAAC,GACV,CAAC,SAAS,MAAM,OAAO,GACrB,OAAO,CAAC,CAAC,CAAC,GACV,KAAK;CACZ,CAAC;AAEF,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,GAmBrF,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,CAClC;AAED,KAAK,SAAS,GAAG,MAAM,GAAG,SAAS,EAAE,GAAG,SAAS,GAAG,IAAI,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,OAAO,EAAE,SAAS,EAAE,GAAG,MAAM,CAE1D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodeblocks/frontend-footer-block",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"main": "dist/index.cjs.js",
|
|
5
5
|
"module": "dist/index.esm.js",
|
|
6
6
|
"browser": "dist/index.iife.js",
|
|
@@ -11,21 +11,25 @@
|
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rollup -c",
|
|
14
|
-
"watch": "rollup -c --watch"
|
|
14
|
+
"watch": "rm -rf dist && cross-env NODE_ENV=development rollup -c --watch"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"react": "
|
|
18
|
-
"react-dom": "
|
|
17
|
+
"react": ">=18 <20",
|
|
18
|
+
"react-dom": ">=18 <20",
|
|
19
|
+
"@mui/material": "^7.3.4",
|
|
20
|
+
"@emotion/react": "^11.14.0",
|
|
21
|
+
"@emotion/styled": "^11.14.1"
|
|
19
22
|
},
|
|
20
23
|
"devDependencies": {
|
|
21
|
-
"@rollup/plugin-commonjs": "^28.0.
|
|
24
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
22
25
|
"@rollup/plugin-json": "^6.1.0",
|
|
23
26
|
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
24
27
|
"@rollup/plugin-typescript": "^12.1.1",
|
|
25
|
-
"@types/react": "
|
|
26
|
-
"@types/react-dom": "
|
|
28
|
+
"@types/react": "19.2.7",
|
|
29
|
+
"@types/react-dom": "19.2.3",
|
|
27
30
|
"rollup": "^4.28.0",
|
|
28
31
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
32
|
+
"rollup-plugin-polyfill-node": "^0.13.0",
|
|
29
33
|
"rollup-plugin-postcss": "^4.0.2",
|
|
30
34
|
"rollup-plugin-serve": "^1.1.1",
|
|
31
35
|
"tslib": "^2.8.1",
|
package/readme.md
CHANGED
|
@@ -3,24 +3,29 @@
|
|
|
3
3
|
Welcome to the Nodeblocks Frontend Starter Kit! 🎉 This kit is designed to make building frontend libraries in React super easy, helping you streamline your development workflow with minimal fuss. Let's dive in! 🤿
|
|
4
4
|
|
|
5
5
|
### ✨ Features
|
|
6
|
+
|
|
6
7
|
- **🚀 Bundling with Rollup:** Get a clean, minimalistic approach to bundling your JavaScript files for smoother frontend development.
|
|
7
8
|
- **💙 TypeScript Support:** We've included a pre-configured `tsconfig.json` to ensure your TypeScript setup is strict, efficient, and ready to go.
|
|
8
9
|
- **⚙️ Peer Dependencies:** Keep bundle sizes lean with React and React DOM set as peer dependencies.
|
|
9
10
|
- **🎨 CSS Support:** Easily import and process CSS files, giving you more control over your styles.
|
|
10
11
|
|
|
11
12
|
### 🛠️ How to Use
|
|
13
|
+
|
|
12
14
|
1. **Clone this repository** 🌀:
|
|
15
|
+
|
|
13
16
|
```bash
|
|
14
17
|
git clone <repository-url>
|
|
15
18
|
cd <repository-directory>
|
|
16
19
|
```
|
|
17
20
|
|
|
18
21
|
2. **Install dependencies** 📦:
|
|
22
|
+
|
|
19
23
|
```bash
|
|
20
24
|
npm install
|
|
21
25
|
```
|
|
22
26
|
|
|
23
27
|
3. **Start development** 🛠️:
|
|
28
|
+
|
|
24
29
|
```bash
|
|
25
30
|
npm run watch
|
|
26
31
|
```
|
|
@@ -48,10 +53,12 @@ This ensures Nodeblocks libraries integrate seamlessly with different workflows.
|
|
|
48
53
|
npm link
|
|
49
54
|
```
|
|
50
55
|
2. In the test project you want to run:
|
|
56
|
+
|
|
51
57
|
```bash
|
|
52
58
|
npm i
|
|
53
59
|
npm link @basaldev/frontend-starter-kit
|
|
54
60
|
```
|
|
55
|
-
(Note that in real life your library would not be called frontend-starter-kit.)
|
|
56
61
|
|
|
57
|
-
|
|
62
|
+
(Note that in real life your library would not be called frontend-starter-kit.)
|
|
63
|
+
|
|
64
|
+
3. Then you can follow your usual workflow either with **Create React App** (`npm start`) or with Vite (`npm run dev`). This will give you a development environment where whenever you change your library it will be available in your test project.
|
package/dist/blocks.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
export type DefaultBlocks = {
|
|
3
|
-
FooterLogo: React.FC<{
|
|
4
|
-
src: string;
|
|
5
|
-
alt?: string;
|
|
6
|
-
}>;
|
|
7
|
-
FooterText: React.FC<{
|
|
8
|
-
children: React.ReactNode;
|
|
9
|
-
}>;
|
|
10
|
-
FooterCopyright: React.FC<{
|
|
11
|
-
children: React.ReactNode;
|
|
12
|
-
}>;
|
|
13
|
-
};
|
|
14
|
-
export type DefaultOptions = {
|
|
15
|
-
hideTitle?: boolean;
|
|
16
|
-
};
|
|
17
|
-
export declare const defaultOptions: DefaultOptions;
|
|
18
|
-
export declare const defaultBlocks: DefaultBlocks;
|
|
19
|
-
//# sourceMappingURL=blocks.d.ts.map
|
package/dist/blocks.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../src/blocks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpD,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE,CAAC,CAAC;IACpD,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,cAE5B,CAAC;AAgBF,eAAO,MAAM,aAAa,EAAE,aAQ3B,CAAC"}
|