@meonode/mui 1.0.5 → 1.0.7
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/core.d.ts +61 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +50 -0
- package/dist/exports.d.ts +1531 -0
- package/dist/exports.d.ts.map +1 -0
- package/dist/exports.js +9 -0
- package/dist/main.d.ts +2 -214
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +1 -134
- package/package.json +22 -16
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { NodeInstance, NodeProps } from '@meonode/ui';
|
|
3
|
+
import { OverridableComponent, OverridableTypeMap, OverrideProps } from '@mui/material/OverridableComponent';
|
|
4
|
+
/**
|
|
5
|
+
* Determines if an object is likely to be a Material-UI theme object by comparing its structure
|
|
6
|
+
* to a reference theme.
|
|
7
|
+
* @param obj The object to evaluate as a potential MUI theme
|
|
8
|
+
* @returns `true` if the object appears to be a MUI theme, `false` otherwise
|
|
9
|
+
* @remarks
|
|
10
|
+
* The function uses a heuristic approach by:
|
|
11
|
+
* 1. Creating a reference theme using MUI's extendTheme()
|
|
12
|
+
* 2. Comparing the keys of the input object with the reference theme
|
|
13
|
+
* 3. Calculating a similarity score based on matching keys
|
|
14
|
+
* 4. Considering it a theme if at least 25% of reference keys are present
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const customTheme = {
|
|
18
|
+
* palette: { primary: { main: '#000' } },
|
|
19
|
+
* typography: { fontSize: 14 }
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* if (isProbablyMuiTheme(customTheme)) {
|
|
23
|
+
* // Handle theme object
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
* @throws Will not throw, but returns false for null, non-objects, or invalid inputs
|
|
27
|
+
*/
|
|
28
|
+
export declare function isProbablyMuiTheme(obj: unknown): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* A utility type that extends an OverridableTypeMap to include a polymorphic `component` prop.
|
|
31
|
+
* This allows the component to be overridden with a different React element type.
|
|
32
|
+
* @template TMap - The base OverridableTypeMap to extend.
|
|
33
|
+
* @template TComponent - The React element type to use for the `component` prop.
|
|
34
|
+
*/
|
|
35
|
+
type WithPolymorphic<TMap extends OverridableTypeMap, TComponent extends React.ElementType> = TMap & {
|
|
36
|
+
props: TMap['props'] & Partial<{
|
|
37
|
+
component: TComponent;
|
|
38
|
+
}>;
|
|
39
|
+
defaultComponent: TMap['defaultComponent'];
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Creates a function that generates a `NodeInstance` for a Material-UI component
|
|
43
|
+
* with support for polymorphic behavior.
|
|
44
|
+
* @template TMap - The OverridableTypeMap for the Material-UI component.
|
|
45
|
+
* @template TDefaultComponent - The default React element type for the component.
|
|
46
|
+
* @param element The Material-UI component to wrap.
|
|
47
|
+
* @returns A function that takes props and returns a `NodeInstance` for the component.
|
|
48
|
+
*/
|
|
49
|
+
export default function createMuiNode<TMap extends OverridableTypeMap, TDefaultComponent extends React.ElementType = TMap['defaultComponent']>(element: OverridableComponent<TMap>): <T extends React.ElementType = TDefaultComponent>(props?: NodeProps<OverridableComponent<WithPolymorphic<TMap, T>>> & Omit<OverrideProps<WithPolymorphic<TMap, T>, T>, keyof NodeProps<OverridableComponent<WithPolymorphic<TMap, T>>>>) => NodeInstance<OverridableComponent<WithPolymorphic<TMap, T>>>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a function that generates a `NodeInstance` for a generic React element.
|
|
52
|
+
* @template TElement - The React element type to wrap.
|
|
53
|
+
* @param element The React element to wrap.
|
|
54
|
+
* @returns A function that takes props and returns a `NodeInstance` for the element.
|
|
55
|
+
*/
|
|
56
|
+
export default function createMuiNode<TElement extends React.ElementType>(element: TElement): (props?: NodeProps<TElement>) => NodeInstance<TElement>;
|
|
57
|
+
/**
|
|
58
|
+
* Exports the `createMuiNode` function for external use.
|
|
59
|
+
*/
|
|
60
|
+
export { createMuiNode };
|
|
61
|
+
//# sourceMappingURL=core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE1D,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAE5G;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAWxD;AAED;;;;;GAKG;AACH,KAAK,eAAe,CAAC,IAAI,SAAS,kBAAkB,EAAE,UAAU,SAAS,KAAK,CAAC,WAAW,IAAI,IAAI,GAAG;IACnG,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;QAAE,SAAS,EAAE,UAAU,CAAA;KAAE,CAAC,CAAA;IACzD,gBAAgB,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAA;CAC3C,CAAA;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,SAAS,kBAAkB,EAAE,iBAAiB,SAAS,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,kBAAkB,CAAC,EAC3I,OAAO,EAAE,oBAAoB,CAAC,IAAI,CAAC,GAClC,CAAC,CAAC,SAAS,KAAK,CAAC,WAAW,GAAG,iBAAiB,EACjD,KAAK,CAAC,EAAE,SAAS,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GAC/D,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,SAAS,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,KAChH,YAAY,CAAC,oBAAoB,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;AAEjE;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,QAAQ,SAAS,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,QAAQ,GAAG,CAAC,KAAK,CAAC,EAAE,SAAS,CAAC,QAAQ,CAAC,KAAK,YAAY,CAAC,QAAQ,CAAC,CAAA;AAoBrJ;;GAEG;AACH,OAAO,EAAE,aAAa,EAAE,CAAA"}
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}import*as Mui from"@mui/material";import{Node}from"@meonode/ui";/**
|
|
2
|
+
* Determines if an object is likely to be a Material-UI theme object by comparing its structure
|
|
3
|
+
* to a reference theme.
|
|
4
|
+
* @param obj The object to evaluate as a potential MUI theme
|
|
5
|
+
* @returns `true` if the object appears to be a MUI theme, `false` otherwise
|
|
6
|
+
* @remarks
|
|
7
|
+
* The function uses a heuristic approach by:
|
|
8
|
+
* 1. Creating a reference theme using MUI's extendTheme()
|
|
9
|
+
* 2. Comparing the keys of the input object with the reference theme
|
|
10
|
+
* 3. Calculating a similarity score based on matching keys
|
|
11
|
+
* 4. Considering it a theme if at least 25% of reference keys are present
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const customTheme = {
|
|
15
|
+
* palette: { primary: { main: '#000' } },
|
|
16
|
+
* typography: { fontSize: 14 }
|
|
17
|
+
* };
|
|
18
|
+
*
|
|
19
|
+
* if (isProbablyMuiTheme(customTheme)) {
|
|
20
|
+
* // Handle theme object
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
* @throws Will not throw, but returns false for null, non-objects, or invalid inputs
|
|
24
|
+
*/export function isProbablyMuiTheme(a){if("object"!==_typeof(a)||null===a)return!1;var b=Mui.extendTheme(),c=Object.keys(b),d=Object.keys(a),e=d.filter(function(a){return c.includes(a)}),f=e.length/c.length;return .25<=f}/**
|
|
25
|
+
* A utility type that extends an OverridableTypeMap to include a polymorphic `component` prop.
|
|
26
|
+
* This allows the component to be overridden with a different React element type.
|
|
27
|
+
* @template TMap - The base OverridableTypeMap to extend.
|
|
28
|
+
* @template TComponent - The React element type to use for the `component` prop.
|
|
29
|
+
*//**
|
|
30
|
+
* Creates a function that generates a `NodeInstance` for a Material-UI component
|
|
31
|
+
* with support for polymorphic behavior.
|
|
32
|
+
* @template TMap - The OverridableTypeMap for the Material-UI component.
|
|
33
|
+
* @template TDefaultComponent - The default React element type for the component.
|
|
34
|
+
* @param element The Material-UI component to wrap.
|
|
35
|
+
* @returns A function that takes props and returns a `NodeInstance` for the component.
|
|
36
|
+
*//**
|
|
37
|
+
* Creates a function that generates a `NodeInstance` for a generic React element.
|
|
38
|
+
* @template TElement - The React element type to wrap.
|
|
39
|
+
* @param element The React element to wrap.
|
|
40
|
+
* @returns A function that takes props and returns a `NodeInstance` for the element.
|
|
41
|
+
*//**
|
|
42
|
+
* Creates a function that generates a `NodeInstance` for any given element.
|
|
43
|
+
* @param element The element to wrap.
|
|
44
|
+
* @returns A function that takes props and returns a `NodeInstance` for the element.
|
|
45
|
+
* @remarks
|
|
46
|
+
* - If the `theme` prop is not a valid Material-UI theme, it is renamed to `nodetheme`.
|
|
47
|
+
* - This ensures compatibility with the `Node` function.
|
|
48
|
+
*/export default function createMuiNode(a){return function(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return isProbablyMuiTheme(null===b||void 0===b?void 0:b.theme)||(b.nodetheme=b.theme,delete b.theme),Node(a,b)}}/**
|
|
49
|
+
* Exports the `createMuiNode` function for external use.
|
|
50
|
+
*/export{createMuiNode};
|