@semcore/core 2.7.2 → 2.7.3-prerelease.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/CHANGELOG.md +7 -1
- package/lib/cjs/Component.js.map +1 -1
- package/lib/cjs/enhancement/hoistProps.js +2 -0
- package/lib/cjs/enhancement/hoistProps.js.map +1 -1
- package/lib/es6/Component.js.map +1 -1
- package/lib/es6/enhancement/hoistProps.js +2 -0
- package/lib/es6/enhancement/hoistProps.js.map +1 -1
- package/lib/types/Component.d.ts +8 -5
- package/lib/types/enhancement/hoistProps.d.ts +1 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
CHANGELOG.md standards are inspired by [keepachangelog.com](https://keepachangelog.com/en/1.0.0/).
|
|
4
4
|
|
|
5
|
-
## [2.7.
|
|
5
|
+
## [2.7.3-prerelease.0] - 2023-10-02
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Improved core component typings flexibility
|
|
10
|
+
|
|
11
|
+
## [2.7.2] - 2023-09-20
|
|
6
12
|
|
|
7
13
|
### Fixed
|
|
8
14
|
|
package/lib/cjs/Component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Component.js","names":["_react","require","RootComponent","_PureComponent","_inherits2","_super","_createSuper2","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","call","apply","concat","_defineProperty2","_assertThisInitialized2","undefined","_createClass2","key","get","PureComponent","Component","exports","Intergalactic","_Intergalactic","InternalTypings","_InternalTypings"],"sources":["../../src/Component.tsx"],"sourcesContent":["import React, {\n AllHTMLAttributes,\n ForwardRefExoticComponent,\n PureComponent,\n ReactNode,\n RefObject,\n} from 'react';\nimport { IStyledProps } from './styled';\n\n/** @deprecated */\ntype KnownKeys<T> = {\n [K in keyof T]: string extends K ? never : number extends K ? never : K;\n} extends { [_ in keyof T]: infer U }\n ? U\n : never;\n\n/** @deprecated */\nexport type HandlersType<UCProps> = { [K in keyof UCProps]?: <T = unknown>(arg: T) => void };\n/** @deprecated */\nexport type ChildrenType<Props = {}, Ctx = {}, UCProps = {}> =\n | ((props: Props & Ctx, handlers: HandlersType<UCProps>) => ReactNode)\n | ReactNode;\n\n/** @deprecated */\nexport type RootComponentHandler = (...args: any[]) => void | false;\n\n/** @deprecated */\nexport interface IRootComponentHandlers {\n [key: string]: RootComponentHandler;\n}\n\n/** @deprecated */\nexport interface IRootComponentProps<Props = {}, Ctx = {}> {\n forwardRef?: RefObject<any>;\n Children?: any;\n children?: ChildrenType<Props, Ctx>;\n styles?: IStyledProps['styles'];\n}\n\n/** @deprecated */\nexport type IComponentProps<Props = {}, Ctx = {}> = Props & IRootComponentProps<Props, Ctx>;\n\n/** @deprecated */\nexport type IFunctionProps<Props = {}, Ctx = {}> = IComponentProps<Props, Ctx> &\n Omit<AllHTMLAttributes<any>, keyof IComponentProps<Props, Ctx>> & { Root?: Root };\n\n/** @deprecated */\nexport type PropsWithRenderFnChildren<Props = {}, Ctx = {}, UCProps = {}> = Omit<\n Pick<Props, KnownKeys<Props>>,\n 'children'\n> & {\n children?: ChildrenType<Props, Ctx, UCProps>;\n [key: string]: unknown;\n};\n\n/** @deprecated */\nexport type CProps<Props, Ctx = {}, UCProps = {}> = Props & {\n children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactNode) | React.ReactNode;\n};\n/** @deprecated */\nexport type ReturnEl = React.ReactElement | null;\n\nexport interface IRootNodeProps {\n render: React.ElementType | string;\n tag?: React.ElementType | string;\n\n [key: string]: any;\n}\n\ntype Root = ForwardRefExoticComponent<IRootNodeProps>;\n\n/**\n * @deprecated since version ^1.8.0\n */\nexport type PropGetter<T extends (...args: any) => any> = <P>(props?: P) => ReturnType<T> & P;\n/**\n * @deprecated since version ^1.8.0\n */\n/** @deprecated */\nexport type PropGetterReturn<T extends (...args: any) => any> = Partial<ReturnType<T>>;\n/** @deprecated */\nexport type PropGetterFn = <T extends {}>(props?: T) => T & { [key: string]: unknown };\n/** @deprecated */\nexport type Merge<Props, HTMLProps> = Props & Omit<HTMLProps, keyof Props>;\n/** @deprecated */\nexport type MergeGetters<G1 extends (...args: any) => any, G2 extends (...args: any) => any> = <P>(\n props?: P,\n) => Merge<ReturnType<G1>, ReturnType<G2>> & P;\n\ndeclare const Root: Root;\n\nexport { Root };\n\n/** @deprecated */\nabstract class RootComponent<Props = {}, Context = {}, State = {}> extends PureComponent<\n Props & IRootComponentProps<Props, Context>,\n State\n> {\n get handlers(): Readonly<IRootComponentHandlers> {\n return {};\n }\n\n get asProps() {\n return {} as Readonly<\n Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>\n >;\n }\n\n Root: Root = undefined as any;\n}\n\nexport const Component = RootComponent;\n/** @deprecated */\nexport type Component<\n Props = {},\n Context = {},\n State = {},\n Handlers extends IRootComponentHandlers = IRootComponentHandlers,\n> = React.ComponentClass<Props, State> & {\n handlers: Readonly<Handlers>;\n\n asProps: Readonly<Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>>;\n\n Root: Root;\n};\n\nexport namespace Intergalactic {\n type ReactFCProps<C extends React.FC> = C extends React.FC<infer Props> ? Omit<Props, 'tag'> : {};\n type ReactComponentProps<C extends React.ComponentClass> = C extends React.ComponentClass<\n infer Props\n >\n ? Omit<Props, 'tag'>\n : never;\n type ReactFCLike = (props: any) => any;\n type ReactFCLikeProps<C extends ReactFCLike> = C extends (props: infer Props) => any ? Props : {};\n type ComponentChildren<\n Props,\n Context,\n RenderingResult = InternalTypings.ReturnResult,\n AdditionalContext extends any[] = never[],\n > =\n | ((props: MergeProps<Context, Props>, ...args: AdditionalContext) => RenderingResult)\n | InternalTypings.ReturnResult;\n type ComponentBasicProps<Tag extends InternalTypings.ComponentTag> = {\n ref?: React.Ref<InternalTypings.ComponentHtmlElement<Tag> | null>;\n /** @private DO NOT USE IT. Low-level api that prevents specified props from being applied as DOM attribute. */\n __excludeProps?: string[];\n };\n type MergeProps<HighPriorityProps, LowPriorityProps> = {\n [K in keyof LowPriorityProps]: K extends keyof HighPriorityProps\n ? HighPriorityProps[K]\n : LowPriorityProps[K];\n } & HighPriorityProps;\n /** @private */\n export namespace InternalTypings {\n export type ComponentPropsNesting<Tag extends InternalTypings.ComponentTag> = Omit<\n MergeProps<\n Tag extends React.FC\n ? ReactFCProps<Tag>\n : Tag extends React.ComponentClass\n ? ReactComponentProps<Tag>\n : Tag extends ReactFCLike\n ? ReactFCLikeProps<Tag>\n : Tag extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[Tag]\n : {},\n Tag extends { __nestedProps: infer NestedProps } ? NestedProps : {}\n >,\n 'children' | 'tag'\n >;\n export type ReturnResult =\n | React.ReactElement\n | React.ReactNode\n | React.ReactNode[]\n | string\n | null;\n export type ComponentTag =\n | keyof JSX.IntrinsicElements\n | React.ComponentClass\n | React.FC\n | ReactFCLike;\n export type ComponentProps<\n Tag extends ComponentTag,\n BaseTag extends ComponentTag | never,\n Props,\n Context = never,\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n Omit<Props, 'children'> & { children: React.ReactNode },\n Context,\n ReturnResult,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<\n Omit<Props, 'tag' | 'children'>,\n MergeProps<ComponentPropsNesting<Tag>, ComponentPropsNesting<BaseTag>>\n >;\n export type PropsRenderingResultComponentProps<\n Tag extends ComponentTag,\n Props,\n Context = {},\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n Omit<Props, 'children'> & { children: React.ReactNode },\n Context,\n Partial<\n Omit<MergeProps<Props, ComponentPropsNesting<Tag>>, 'children' | 'tag' | 'ref'> & {\n children?: React.ReactNode;\n }\n >,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<Omit<Props, 'tag' | 'children'>, ComponentPropsNesting<Tag>>;\n export type ComponentRenderingResults = React.ReactElement;\n export type ComponentAdditive<BaseTag extends ComponentTag> = {\n __nestedProps: ComponentPropsNesting<BaseTag>;\n };\n export type InferJsxIntrinsicElement<T extends React.DetailedHTMLProps<any, any>> =\n T extends React.DetailedHTMLProps<infer _, infer Element> ? Element : HTMLElement;\n type InferElementFromRef<T> = T extends React.Ref<infer Element> ? Element : never;\n type InferRefElementFromProps<T> = 'ref' extends keyof T\n ? InferElementFromRef<T['ref']>\n : HTMLElement;\n export type ComponentHtmlElement<Tag extends ComponentTag> =\n Tag extends keyof JSX.IntrinsicElements\n ? InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>\n : Tag extends { __nestedProps: infer NestedProps }\n ? InferRefElementFromProps<NestedProps>\n : HTMLElement;\n }\n export type Component<\n BaseTag extends InternalTypings.ComponentTag = never,\n BaseProps = {},\n Context = {},\n AdditionalContext extends any[] = never[],\n > = (<Tag extends InternalTypings.ComponentTag = BaseTag, Props extends BaseProps = BaseProps>(\n props: InternalTypings.ComponentProps<Tag, BaseTag, Props, Context, AdditionalContext>,\n ) => InternalTypings.ComponentRenderingResults) &\n InternalTypings.ComponentAdditive<BaseTag>;\n export type Tag = InternalTypings.ComponentTag;\n export type DomProps<Tag extends keyof JSX.IntrinsicElements> =\n InternalTypings.InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AA6FA;AAAA,IACeC,aAAa,0BAAAC,cAAA;EAAA,IAAAC,UAAA,aAAAF,aAAA,EAAAC,cAAA;EAAA,IAAAE,MAAA,OAAAC,aAAA,aAAAJ,aAAA;EAAA,SAAAA,cAAA;IAAA,IAAAK,KAAA;IAAA,IAAAC,gBAAA,mBAAAN,aAAA;IAAA,SAAAO,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAP,KAAA,GAAAF,MAAA,CAAAU,IAAA,CAAAC,KAAA,CAAAX,MAAA,SAAAY,MAAA,CAAAL,IAAA;IAAA,IAAAM,gBAAA,iBAAAC,uBAAA,aAAAZ,KAAA,WAcba,SAAS;IAAA,OAAAb,KAAA;EAAA;EAAA,IAAAc,aAAA,aAAAnB,aAAA;IAAAoB,GAAA;IAAAC,GAAA,EAVtB,SAAAA,IAAA,EAAiD;MAC/C,OAAO,CAAC,CAAC;IACX;EAAC;IAAAD,GAAA;IAAAC,GAAA,EAED,SAAAA,IAAA,EAAc;MACZ,OAAO,CAAC,CAAC;IAGX;EAAC;EAAA,OAAArB,aAAA;AAAA,EAZwEsB,oBAAa;AAiBjF,IAAMC,SAAS,GAAGvB,aAAa;AACtC;AAAAwB,OAAA,CAAAD,SAAA,GAAAA,SAAA;AAAA,IAAAE,aAAA;AAAAD,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAAA,WAAAC,cAAA;EAAA,IAAAC,eAAA;EAAA,WAAAC,gBAAA,MA0CmBD,eAAe,KAAfA,eAAe,GAAAD,cAAA,CAAfC,eAAe,KAAAD,cAAA,CAAfC,eAAe;AAAA,GA5BjBF,aAAa,KAAAD,OAAA,CAAAC,aAAA,GAAbA,aAAa"}
|
|
1
|
+
{"version":3,"file":"Component.js","names":["_react","require","RootComponent","_PureComponent","_inherits2","_super","_createSuper2","_this","_classCallCheck2","_len","arguments","length","args","Array","_key","call","apply","concat","_defineProperty2","_assertThisInitialized2","undefined","_createClass2","key","get","PureComponent","Component","exports","Intergalactic","_Intergalactic","InternalTypings","_InternalTypings"],"sources":["../../src/Component.tsx"],"sourcesContent":["import React, {\n AllHTMLAttributes,\n ForwardRefExoticComponent,\n PureComponent,\n ReactNode,\n RefObject,\n} from 'react';\nimport { IStyledProps } from './styled';\n\n/** @deprecated */\ntype KnownKeys<T> = {\n [K in keyof T]: string extends K ? never : number extends K ? never : K;\n} extends { [_ in keyof T]: infer U }\n ? U\n : never;\n\n/** @deprecated */\nexport type HandlersType<UCProps> = { [K in keyof UCProps]?: <T = unknown>(arg: T) => void };\n/** @deprecated */\nexport type ChildrenType<Props = {}, Ctx = {}, UCProps = {}> =\n | ((props: Props & Ctx, handlers: HandlersType<UCProps>) => ReactNode)\n | ReactNode;\n\n/** @deprecated */\nexport type RootComponentHandler = (...args: any[]) => void | false;\n\n/** @deprecated */\nexport interface IRootComponentHandlers {\n [key: string]: RootComponentHandler;\n}\n\n/** @deprecated */\nexport interface IRootComponentProps<Props = {}, Ctx = {}> {\n forwardRef?: RefObject<any>;\n Children?: any;\n children?: ChildrenType<Props, Ctx>;\n styles?: IStyledProps['styles'];\n}\n\n/** @deprecated */\nexport type IComponentProps<Props = {}, Ctx = {}> = Props & IRootComponentProps<Props, Ctx>;\n\n/** @deprecated */\nexport type IFunctionProps<Props = {}, Ctx = {}> = IComponentProps<Props, Ctx> &\n Omit<AllHTMLAttributes<any>, keyof IComponentProps<Props, Ctx>> & { Root?: Root };\n\n/** @deprecated */\nexport type PropsWithRenderFnChildren<Props = {}, Ctx = {}, UCProps = {}> = Omit<\n Pick<Props, KnownKeys<Props>>,\n 'children'\n> & {\n children?: ChildrenType<Props, Ctx, UCProps>;\n [key: string]: unknown;\n};\n\n/** @deprecated */\nexport type CProps<Props, Ctx = {}, UCProps = {}> = Props & {\n children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactNode) | React.ReactNode;\n};\n/** @deprecated */\nexport type ReturnEl = React.ReactElement | null;\n\nexport interface IRootNodeProps {\n render: React.ElementType | string;\n tag?: React.ElementType | string;\n\n [key: string]: any;\n}\n\ntype Root = ForwardRefExoticComponent<IRootNodeProps>;\n\n/**\n * @deprecated since version ^1.8.0\n */\nexport type PropGetter<T extends (...args: any) => any> = <P>(props?: P) => ReturnType<T> & P;\n/**\n * @deprecated since version ^1.8.0\n */\n/** @deprecated */\nexport type PropGetterReturn<T extends (...args: any) => any> = Partial<ReturnType<T>>;\n/** @deprecated */\nexport type PropGetterFn = <T extends {}>(props?: T) => T & { [key: string]: unknown };\n/** @deprecated */\nexport type Merge<Props, HTMLProps> = Props & Omit<HTMLProps, keyof Props>;\n/** @deprecated */\nexport type MergeGetters<G1 extends (...args: any) => any, G2 extends (...args: any) => any> = <P>(\n props?: P,\n) => Merge<ReturnType<G1>, ReturnType<G2>> & P;\n\ndeclare const Root: Root;\n\nexport { Root };\n\n/** @deprecated */\nabstract class RootComponent<Props = {}, Context = {}, State = {}> extends PureComponent<\n Props & IRootComponentProps<Props, Context>,\n State\n> {\n get handlers(): Readonly<IRootComponentHandlers> {\n return {};\n }\n\n get asProps() {\n return {} as Readonly<\n Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>\n >;\n }\n\n Root: Root = undefined as any;\n}\n\nexport const Component = RootComponent;\n/** @deprecated */\nexport type Component<\n Props = {},\n Context = {},\n State = {},\n Handlers extends IRootComponentHandlers = IRootComponentHandlers,\n> = React.ComponentClass<Props, State> & {\n handlers: Readonly<Handlers>;\n\n asProps: Readonly<Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>>;\n\n Root: Root;\n};\n\nexport namespace Intergalactic {\n type ReactFCProps<C extends React.FC> = C extends React.FC<infer Props> ? Omit<Props, 'tag'> : {};\n type ReactComponentProps<C extends React.ComponentClass> = C extends React.ComponentClass<\n infer Props\n >\n ? Omit<Props, 'tag'>\n : never;\n type ReactFCLike = (props: any) => any;\n type ReactFCLikeProps<C extends ReactFCLike> = C extends (props: infer Props) => any ? Props : {};\n type ComponentChildren<\n Props,\n Context,\n RenderingResult = InternalTypings.ReturnResult,\n AdditionalContext extends any[] = never[],\n > =\n | ((props: MergeProps<Context, Props>, ...args: AdditionalContext) => RenderingResult)\n | InternalTypings.ReturnResult;\n type ComponentBasicProps<Tag extends InternalTypings.ComponentTag> = {\n ref?: React.Ref<InternalTypings.ComponentHtmlElement<Tag> | null>;\n /** @private DO NOT USE IT. Low-level api that prevents specified props from being applied as DOM attribute. */\n __excludeProps?: string[];\n };\n type MergeProps<HighPriorityProps, LowPriorityProps> = {\n [K in keyof LowPriorityProps]: K extends keyof HighPriorityProps\n ? HighPriorityProps[K]\n : LowPriorityProps[K];\n } & HighPriorityProps;\n type RemoveFields<Type, Keys> = {\n [Property in keyof Type as Exclude<Property, Keys>]: Type[Property];\n };\n /** @private */\n export namespace InternalTypings {\n export type ComponentPropsNesting<Tag extends InternalTypings.ComponentTag> = Omit<\n MergeProps<\n Tag extends React.FC\n ? ReactFCProps<Tag>\n : Tag extends React.ComponentClass\n ? ReactComponentProps<Tag>\n : Tag extends ReactFCLike\n ? ReactFCLikeProps<Tag>\n : Tag extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[Tag]\n : {},\n Tag extends { __nestedProps: infer NestedProps } ? NestedProps : {}\n >,\n 'children' | 'tag'\n >;\n export type ReturnResult =\n | React.ReactElement\n | React.ReactNode\n | React.ReactNode[]\n | string\n | null;\n export type ComponentTag =\n | keyof JSX.IntrinsicElements\n | React.ComponentClass\n | React.FC\n | ReactFCLike;\n export type ComponentProps<\n Tag extends ComponentTag,\n BaseTag extends ComponentTag | never,\n Props,\n Context = never,\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n RemoveFields<Props, 'children'> & { children: React.ReactNode },\n Context,\n ReturnResult,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<\n RemoveFields<Props, 'tag' | 'children'>,\n MergeProps<ComponentPropsNesting<Tag>, ComponentPropsNesting<BaseTag>>\n >;\n export type PropsRenderingResultComponentProps<\n Tag extends ComponentTag,\n Props,\n Context = {},\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n RemoveFields<Props, 'children'> & { children: React.ReactNode },\n Context,\n Partial<\n RemoveFields<\n MergeProps<Props, ComponentPropsNesting<Tag>>,\n 'children' | 'tag' | 'ref'\n > & {\n children?: React.ReactNode;\n }\n >,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<RemoveFields<Props, 'tag' | 'children'>, ComponentPropsNesting<Tag>>;\n export type ComponentRenderingResults = React.ReactElement;\n export type ComponentAdditive<BaseTag extends ComponentTag> = {\n __nestedProps: ComponentPropsNesting<BaseTag>;\n };\n export type InferJsxIntrinsicElement<T extends React.DetailedHTMLProps<any, any>> =\n T extends React.DetailedHTMLProps<infer _, infer Element> ? Element : HTMLElement;\n type InferElementFromRef<T> = T extends React.Ref<infer Element> ? Element : never;\n type InferRefElementFromProps<T> = 'ref' extends keyof T\n ? InferElementFromRef<T['ref']>\n : HTMLElement;\n export type ComponentHtmlElement<Tag extends ComponentTag> =\n Tag extends keyof JSX.IntrinsicElements\n ? InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>\n : Tag extends { __nestedProps: infer NestedProps }\n ? InferRefElementFromProps<NestedProps>\n : HTMLElement;\n }\n export type Component<\n BaseTag extends InternalTypings.ComponentTag = never,\n BaseProps = {},\n Context = {},\n AdditionalContext extends any[] = never[],\n > = (<Tag extends InternalTypings.ComponentTag = BaseTag, Props extends BaseProps = BaseProps>(\n props: InternalTypings.ComponentProps<Tag, BaseTag, Props, Context, AdditionalContext>,\n ) => InternalTypings.ComponentRenderingResults) &\n InternalTypings.ComponentAdditive<BaseTag>;\n export type Tag = InternalTypings.ComponentTag;\n export type DomProps<Tag extends keyof JSX.IntrinsicElements> =\n InternalTypings.InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AA6FA;AAAA,IACeC,aAAa,0BAAAC,cAAA;EAAA,IAAAC,UAAA,aAAAF,aAAA,EAAAC,cAAA;EAAA,IAAAE,MAAA,OAAAC,aAAA,aAAAJ,aAAA;EAAA,SAAAA,cAAA;IAAA,IAAAK,KAAA;IAAA,IAAAC,gBAAA,mBAAAN,aAAA;IAAA,SAAAO,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAP,KAAA,GAAAF,MAAA,CAAAU,IAAA,CAAAC,KAAA,CAAAX,MAAA,SAAAY,MAAA,CAAAL,IAAA;IAAA,IAAAM,gBAAA,iBAAAC,uBAAA,aAAAZ,KAAA,WAcba,SAAS;IAAA,OAAAb,KAAA;EAAA;EAAA,IAAAc,aAAA,aAAAnB,aAAA;IAAAoB,GAAA;IAAAC,GAAA,EAVtB,SAAAA,IAAA,EAAiD;MAC/C,OAAO,CAAC,CAAC;IACX;EAAC;IAAAD,GAAA;IAAAC,GAAA,EAED,SAAAA,IAAA,EAAc;MACZ,OAAO,CAAC,CAAC;IAGX;EAAC;EAAA,OAAArB,aAAA;AAAA,EAZwEsB,oBAAa;AAiBjF,IAAMC,SAAS,GAAGvB,aAAa;AACtC;AAAAwB,OAAA,CAAAD,SAAA,GAAAA,SAAA;AAAA,IAAAE,aAAA;AAAAD,OAAA,CAAAC,aAAA,GAAAA,aAAA;AAAA,WAAAC,cAAA;EAAA,IAAAC,eAAA;EAAA,WAAAC,gBAAA,MA6CmBD,eAAe,KAAfA,eAAe,GAAAD,cAAA,CAAfC,eAAe,KAAAD,cAAA,CAAfC,eAAe;AAAA,GA/BjBF,aAAa,KAAAD,OAAA,CAAAC,aAAA,GAAbA,aAAa"}
|
|
@@ -33,6 +33,8 @@ function flatChildComponent(childComponents) {
|
|
|
33
33
|
return acc;
|
|
34
34
|
}, []);
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
/** @deprecated Doesn't work in ssr and sometimes breakes rulles of hooks. We should never use it. */
|
|
36
38
|
function Enhancement(childComponents, Context) {
|
|
37
39
|
return {
|
|
38
40
|
condition: function condition(Component) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hoistProps.js","names":["_react","_interopRequireDefault","require","_assignProps","_useEnhancedEffect","_pick","HOIST_CONTEXT","Symbol","exports","HOIST_SELF","HOIST_SET","flatChildComponent","childComponents","Object","values","reduce","acc","Component","Array","isArray","concat","_toConsumableArray2","push","Enhancement","Context","condition","some","_Component$hoistProps","Boolean","hoistProps","length","init","props","WrapperComponent","isFunction","_this","React","useState","obj","forceUpdate","context","_objectSpread3","_defineProperty2","asProps","assignProps","wrapperProps","_WrapperComponent$hoi","useContext","renameProps","propName","_propName$split","split","_propName$split2","_slicedToArray2","name","rename","entries","pick","keys","_ref","_ref2","value","useEnhancedEffect","_default"],"sources":["../../../src/enhancement/hoistProps.tsx"],"sourcesContent":["import React from 'react';\n// @ts-ignore\nimport assignProps from '@semcore/utils/lib/assignProps';\n// @ts-ignore\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n// @ts-ignore\nimport pick from '@semcore/utils/lib/pick';\n\nexport const HOIST_CONTEXT = Symbol('HOIST_CONTEXT');\nconst HOIST_SELF = Symbol('HOIST_SELF');\nconst HOIST_SET = Symbol('HOIST_SET');\n\nfunction flatChildComponent(childComponents: any) {\n return Object.values(childComponents).reduce<unknown[]>((acc, Component) => {\n if (Array.isArray(Component)) {\n acc = [...acc, Component[0], ...flatChildComponent(Component[1])];\n } else {\n acc.push(Component);\n }\n return acc;\n }, []);\n}\n\nfunction Enhancement(childComponents: any, Context: any) {\n return {\n condition: function (Component: any) {\n return [Component, ...flatChildComponent(childComponents)].some((Component) =>\n Boolean(Component.hoistProps?.length),\n );\n },\n init: function (this: any, props: any, WrapperComponent: any, isFunction: boolean) {\n if (isFunction) {\n // TODO: might breake rules of hooks (by lsroman)\n this[HOIST_SELF] = React.useState({});\n } else {\n this[HOIST_SELF] = [\n {},\n (obj: any) => {\n this[HOIST_SELF][0] = obj;\n this.forceUpdate();\n },\n ];\n }\n // For optimization render\n this[HOIST_SET] = (obj: any) => {\n this[HOIST_SELF][1](obj);\n };\n },\n context: function (this: any, context: any) {\n // TODO: need to optimizte container initialization (by lsroman)\n // WrapperComponent.hoistProps\n return {\n ...context,\n [HOIST_CONTEXT]: this[HOIST_SET],\n };\n },\n asProps: function (this: any, props: any) {\n // TODO: need to check for no props overwriting (by lsroman)\n return assignProps(this[HOIST_SELF][0], props);\n },\n wrapperProps: function (props: any, WrapperComponent: any) {\n if (WrapperComponent.hoistProps?.length) {\n const context: any = React.useContext(Context);\n const renameProps: any = WrapperComponent.hoistProps.reduce((acc: any, propName: any) => {\n const [name, rename] = propName.split(':');\n acc[name] = rename || name;\n return acc;\n }, {});\n const hoistProps = Object.entries(pick(props, Object.keys(renameProps))).reduce(\n (acc: any, [name, value]) => {\n acc[renameProps[name]] = value;\n return acc;\n },\n {},\n );\n\n useEnhancedEffect(() => {\n if (context[HOIST_CONTEXT]) {\n context[HOIST_CONTEXT](hoistProps);\n }\n }, Object.values(hoistProps));\n }\n return props;\n },\n };\n}\n\nexport default Enhancement;\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,kBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AALA;;AAEA;;AAEA;;AAGO,IAAMI,aAAa,GAAGC,MAAM,CAAC,eAAe,CAAC;AAACC,OAAA,CAAAF,aAAA,GAAAA,aAAA;AACrD,IAAMG,UAAU,GAAGF,MAAM,CAAC,YAAY,CAAC;AACvC,IAAMG,SAAS,GAAGH,MAAM,CAAC,WAAW,CAAC;AAErC,SAASI,kBAAkBA,CAACC,eAAoB,EAAE;EAChD,OAAOC,MAAM,CAACC,MAAM,CAACF,eAAe,CAAC,CAACG,MAAM,CAAY,UAACC,GAAG,EAAEC,SAAS,EAAK;IAC1E,IAAIC,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,EAAE;MAC5BD,GAAG,MAAAI,MAAA,KAAAC,mBAAA,aAAOL,GAAG,IAAEC,SAAS,CAAC,CAAC,CAAC,OAAAI,mBAAA,aAAKV,kBAAkB,CAACM,SAAS,CAAC,CAAC,CAAC,CAAC,EAAC;IACnE,CAAC,MAAM;MACLD,GAAG,CAACM,IAAI,CAACL,SAAS,CAAC;IACrB;IACA,OAAOD,GAAG;EACZ,CAAC,EAAE,EAAE,CAAC;AACR;
|
|
1
|
+
{"version":3,"file":"hoistProps.js","names":["_react","_interopRequireDefault","require","_assignProps","_useEnhancedEffect","_pick","HOIST_CONTEXT","Symbol","exports","HOIST_SELF","HOIST_SET","flatChildComponent","childComponents","Object","values","reduce","acc","Component","Array","isArray","concat","_toConsumableArray2","push","Enhancement","Context","condition","some","_Component$hoistProps","Boolean","hoistProps","length","init","props","WrapperComponent","isFunction","_this","React","useState","obj","forceUpdate","context","_objectSpread3","_defineProperty2","asProps","assignProps","wrapperProps","_WrapperComponent$hoi","useContext","renameProps","propName","_propName$split","split","_propName$split2","_slicedToArray2","name","rename","entries","pick","keys","_ref","_ref2","value","useEnhancedEffect","_default"],"sources":["../../../src/enhancement/hoistProps.tsx"],"sourcesContent":["import React from 'react';\n// @ts-ignore\nimport assignProps from '@semcore/utils/lib/assignProps';\n// @ts-ignore\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n// @ts-ignore\nimport pick from '@semcore/utils/lib/pick';\n\nexport const HOIST_CONTEXT = Symbol('HOIST_CONTEXT');\nconst HOIST_SELF = Symbol('HOIST_SELF');\nconst HOIST_SET = Symbol('HOIST_SET');\n\nfunction flatChildComponent(childComponents: any) {\n return Object.values(childComponents).reduce<unknown[]>((acc, Component) => {\n if (Array.isArray(Component)) {\n acc = [...acc, Component[0], ...flatChildComponent(Component[1])];\n } else {\n acc.push(Component);\n }\n return acc;\n }, []);\n}\n\n/** @deprecated Doesn't work in ssr and sometimes breakes rulles of hooks. We should never use it. */\nfunction Enhancement(childComponents: any, Context: any) {\n return {\n condition: function (Component: any) {\n return [Component, ...flatChildComponent(childComponents)].some((Component) =>\n Boolean(Component.hoistProps?.length),\n );\n },\n init: function (this: any, props: any, WrapperComponent: any, isFunction: boolean) {\n if (isFunction) {\n // TODO: might breake rules of hooks (by lsroman)\n this[HOIST_SELF] = React.useState({});\n } else {\n this[HOIST_SELF] = [\n {},\n (obj: any) => {\n this[HOIST_SELF][0] = obj;\n this.forceUpdate();\n },\n ];\n }\n // For optimization render\n this[HOIST_SET] = (obj: any) => {\n this[HOIST_SELF][1](obj);\n };\n },\n context: function (this: any, context: any) {\n // TODO: need to optimizte container initialization (by lsroman)\n // WrapperComponent.hoistProps\n return {\n ...context,\n [HOIST_CONTEXT]: this[HOIST_SET],\n };\n },\n asProps: function (this: any, props: any) {\n // TODO: need to check for no props overwriting (by lsroman)\n return assignProps(this[HOIST_SELF][0], props);\n },\n wrapperProps: function (props: any, WrapperComponent: any) {\n if (WrapperComponent.hoistProps?.length) {\n const context: any = React.useContext(Context);\n const renameProps: any = WrapperComponent.hoistProps.reduce((acc: any, propName: any) => {\n const [name, rename] = propName.split(':');\n acc[name] = rename || name;\n return acc;\n }, {});\n const hoistProps = Object.entries(pick(props, Object.keys(renameProps))).reduce(\n (acc: any, [name, value]) => {\n acc[renameProps[name]] = value;\n return acc;\n },\n {},\n );\n\n useEnhancedEffect(() => {\n if (context[HOIST_CONTEXT]) {\n context[HOIST_CONTEXT](hoistProps);\n }\n }, Object.values(hoistProps));\n }\n return props;\n },\n };\n}\n\nexport default Enhancement;\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEA,IAAAE,kBAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA,IAAAG,KAAA,GAAAJ,sBAAA,CAAAC,OAAA;AALA;;AAEA;;AAEA;;AA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M,GAAAH,gBAAA;UACnBpC,GAAG,CAACsC,IAAI,CAAC,GAAGC,MAAM,IAAID,IAAI;UAC1B,OAAOtC,GAAG;QACZ,CAAC,EAAE,CAAC,CAAC,CAAC;QACN,IAAMa,UAAU,GAAGhB,MAAM,CAAC2C,OAAO,CAAC,IAAAC,gBAAI,EAACzB,KAAK,EAAEnB,MAAM,CAAC6C,IAAI,CAACV,WAAW,CAAC,CAAC,CAAC,CAACjC,MAAM,CAC7E,UAACC,GAAQ,EAAA2C,IAAA,EAAoB;UAAA,IAAAC,KAAA,OAAAP,eAAA,aAAAM,IAAA;YAAjBL,IAAI,GAAAM,KAAA;YAAEC,KAAK,GAAAD,KAAA;UACrB5C,GAAG,CAACgC,WAAW,CAACM,IAAI,CAAC,CAAC,GAAGO,KAAK;UAC9B,OAAO7C,GAAG;QACZ,CAAC,EACD,CAAC,CAAC,CACH;QAED,IAAA8C,6BAAiB,EAAC,YAAM;UACtB,IAAItB,OAAO,CAAClC,aAAa,CAAC,EAAE;YAC1BkC,OAAO,CAAClC,aAAa,CAAC,CAACuB,UAAU,CAAC;UACpC;QACF,CAAC,EAAEhB,MAAM,CAACC,MAAM,CAACe,UAAU,CAAC,CAAC;MAC/B;MACA,OAAOG,KAAK;IACd;EACF,CAAC;AACH;AAAC,IAAA+B,QAAA,GAEcxC,WAAW;AAAAf,OAAA,cAAAuD,QAAA"}
|
package/lib/es6/Component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Component.js","names":["PureComponent","RootComponent","_PureComponent","_inherits","_super","_createSuper","_this","_classCallCheck","_len","arguments","length","args","Array","_key","call","apply","concat","_defineProperty","_assertThisInitialized","undefined","_createClass","key","get","Component","Intergalactic","_Intergalactic","InternalTypings","_InternalTypings"],"sources":["../../src/Component.tsx"],"sourcesContent":["import React, {\n AllHTMLAttributes,\n ForwardRefExoticComponent,\n PureComponent,\n ReactNode,\n RefObject,\n} from 'react';\nimport { IStyledProps } from './styled';\n\n/** @deprecated */\ntype KnownKeys<T> = {\n [K in keyof T]: string extends K ? never : number extends K ? never : K;\n} extends { [_ in keyof T]: infer U }\n ? U\n : never;\n\n/** @deprecated */\nexport type HandlersType<UCProps> = { [K in keyof UCProps]?: <T = unknown>(arg: T) => void };\n/** @deprecated */\nexport type ChildrenType<Props = {}, Ctx = {}, UCProps = {}> =\n | ((props: Props & Ctx, handlers: HandlersType<UCProps>) => ReactNode)\n | ReactNode;\n\n/** @deprecated */\nexport type RootComponentHandler = (...args: any[]) => void | false;\n\n/** @deprecated */\nexport interface IRootComponentHandlers {\n [key: string]: RootComponentHandler;\n}\n\n/** @deprecated */\nexport interface IRootComponentProps<Props = {}, Ctx = {}> {\n forwardRef?: RefObject<any>;\n Children?: any;\n children?: ChildrenType<Props, Ctx>;\n styles?: IStyledProps['styles'];\n}\n\n/** @deprecated */\nexport type IComponentProps<Props = {}, Ctx = {}> = Props & IRootComponentProps<Props, Ctx>;\n\n/** @deprecated */\nexport type IFunctionProps<Props = {}, Ctx = {}> = IComponentProps<Props, Ctx> &\n Omit<AllHTMLAttributes<any>, keyof IComponentProps<Props, Ctx>> & { Root?: Root };\n\n/** @deprecated */\nexport type PropsWithRenderFnChildren<Props = {}, Ctx = {}, UCProps = {}> = Omit<\n Pick<Props, KnownKeys<Props>>,\n 'children'\n> & {\n children?: ChildrenType<Props, Ctx, UCProps>;\n [key: string]: unknown;\n};\n\n/** @deprecated */\nexport type CProps<Props, Ctx = {}, UCProps = {}> = Props & {\n children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactNode) | React.ReactNode;\n};\n/** @deprecated */\nexport type ReturnEl = React.ReactElement | null;\n\nexport interface IRootNodeProps {\n render: React.ElementType | string;\n tag?: React.ElementType | string;\n\n [key: string]: any;\n}\n\ntype Root = ForwardRefExoticComponent<IRootNodeProps>;\n\n/**\n * @deprecated since version ^1.8.0\n */\nexport type PropGetter<T extends (...args: any) => any> = <P>(props?: P) => ReturnType<T> & P;\n/**\n * @deprecated since version ^1.8.0\n */\n/** @deprecated */\nexport type PropGetterReturn<T extends (...args: any) => any> = Partial<ReturnType<T>>;\n/** @deprecated */\nexport type PropGetterFn = <T extends {}>(props?: T) => T & { [key: string]: unknown };\n/** @deprecated */\nexport type Merge<Props, HTMLProps> = Props & Omit<HTMLProps, keyof Props>;\n/** @deprecated */\nexport type MergeGetters<G1 extends (...args: any) => any, G2 extends (...args: any) => any> = <P>(\n props?: P,\n) => Merge<ReturnType<G1>, ReturnType<G2>> & P;\n\ndeclare const Root: Root;\n\nexport { Root };\n\n/** @deprecated */\nabstract class RootComponent<Props = {}, Context = {}, State = {}> extends PureComponent<\n Props & IRootComponentProps<Props, Context>,\n State\n> {\n get handlers(): Readonly<IRootComponentHandlers> {\n return {};\n }\n\n get asProps() {\n return {} as Readonly<\n Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>\n >;\n }\n\n Root: Root = undefined as any;\n}\n\nexport const Component = RootComponent;\n/** @deprecated */\nexport type Component<\n Props = {},\n Context = {},\n State = {},\n Handlers extends IRootComponentHandlers = IRootComponentHandlers,\n> = React.ComponentClass<Props, State> & {\n handlers: Readonly<Handlers>;\n\n asProps: Readonly<Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>>;\n\n Root: Root;\n};\n\nexport namespace Intergalactic {\n type ReactFCProps<C extends React.FC> = C extends React.FC<infer Props> ? Omit<Props, 'tag'> : {};\n type ReactComponentProps<C extends React.ComponentClass> = C extends React.ComponentClass<\n infer Props\n >\n ? Omit<Props, 'tag'>\n : never;\n type ReactFCLike = (props: any) => any;\n type ReactFCLikeProps<C extends ReactFCLike> = C extends (props: infer Props) => any ? Props : {};\n type ComponentChildren<\n Props,\n Context,\n RenderingResult = InternalTypings.ReturnResult,\n AdditionalContext extends any[] = never[],\n > =\n | ((props: MergeProps<Context, Props>, ...args: AdditionalContext) => RenderingResult)\n | InternalTypings.ReturnResult;\n type ComponentBasicProps<Tag extends InternalTypings.ComponentTag> = {\n ref?: React.Ref<InternalTypings.ComponentHtmlElement<Tag> | null>;\n /** @private DO NOT USE IT. Low-level api that prevents specified props from being applied as DOM attribute. */\n __excludeProps?: string[];\n };\n type MergeProps<HighPriorityProps, LowPriorityProps> = {\n [K in keyof LowPriorityProps]: K extends keyof HighPriorityProps\n ? HighPriorityProps[K]\n : LowPriorityProps[K];\n } & HighPriorityProps;\n /** @private */\n export namespace InternalTypings {\n export type ComponentPropsNesting<Tag extends InternalTypings.ComponentTag> = Omit<\n MergeProps<\n Tag extends React.FC\n ? ReactFCProps<Tag>\n : Tag extends React.ComponentClass\n ? ReactComponentProps<Tag>\n : Tag extends ReactFCLike\n ? ReactFCLikeProps<Tag>\n : Tag extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[Tag]\n : {},\n Tag extends { __nestedProps: infer NestedProps } ? NestedProps : {}\n >,\n 'children' | 'tag'\n >;\n export type ReturnResult =\n | React.ReactElement\n | React.ReactNode\n | React.ReactNode[]\n | string\n | null;\n export type ComponentTag =\n | keyof JSX.IntrinsicElements\n | React.ComponentClass\n | React.FC\n | ReactFCLike;\n export type ComponentProps<\n Tag extends ComponentTag,\n BaseTag extends ComponentTag | never,\n Props,\n Context = never,\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n Omit<Props, 'children'> & { children: React.ReactNode },\n Context,\n ReturnResult,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<\n Omit<Props, 'tag' | 'children'>,\n MergeProps<ComponentPropsNesting<Tag>, ComponentPropsNesting<BaseTag>>\n >;\n export type PropsRenderingResultComponentProps<\n Tag extends ComponentTag,\n Props,\n Context = {},\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n Omit<Props, 'children'> & { children: React.ReactNode },\n Context,\n Partial<\n Omit<MergeProps<Props, ComponentPropsNesting<Tag>>, 'children' | 'tag' | 'ref'> & {\n children?: React.ReactNode;\n }\n >,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<Omit<Props, 'tag' | 'children'>, ComponentPropsNesting<Tag>>;\n export type ComponentRenderingResults = React.ReactElement;\n export type ComponentAdditive<BaseTag extends ComponentTag> = {\n __nestedProps: ComponentPropsNesting<BaseTag>;\n };\n export type InferJsxIntrinsicElement<T extends React.DetailedHTMLProps<any, any>> =\n T extends React.DetailedHTMLProps<infer _, infer Element> ? Element : HTMLElement;\n type InferElementFromRef<T> = T extends React.Ref<infer Element> ? Element : never;\n type InferRefElementFromProps<T> = 'ref' extends keyof T\n ? InferElementFromRef<T['ref']>\n : HTMLElement;\n export type ComponentHtmlElement<Tag extends ComponentTag> =\n Tag extends keyof JSX.IntrinsicElements\n ? InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>\n : Tag extends { __nestedProps: infer NestedProps }\n ? InferRefElementFromProps<NestedProps>\n : HTMLElement;\n }\n export type Component<\n BaseTag extends InternalTypings.ComponentTag = never,\n BaseProps = {},\n Context = {},\n AdditionalContext extends any[] = never[],\n > = (<Tag extends InternalTypings.ComponentTag = BaseTag, Props extends BaseProps = BaseProps>(\n props: InternalTypings.ComponentProps<Tag, BaseTag, Props, Context, AdditionalContext>,\n ) => InternalTypings.ComponentRenderingResults) &\n InternalTypings.ComponentAdditive<BaseTag>;\n export type Tag = InternalTypings.ComponentTag;\n export type DomProps<Tag extends keyof JSX.IntrinsicElements> =\n InternalTypings.InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>;\n}\n"],"mappings":";;;;;;AAAA,SAGEA,aAAa,QAGR,OAAO;AAuFd;AAAA,IACeC,aAAa,0BAAAC,cAAA;EAAAC,SAAA,CAAAF,aAAA,EAAAC,cAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAJ,aAAA;EAAA,SAAAA,cAAA;IAAA,IAAAK,KAAA;IAAAC,eAAA,OAAAN,aAAA;IAAA,SAAAO,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAP,KAAA,GAAAF,MAAA,CAAAU,IAAA,CAAAC,KAAA,CAAAX,MAAA,SAAAY,MAAA,CAAAL,IAAA;IAAAM,eAAA,CAAAC,sBAAA,CAAAZ,KAAA,WAcba,SAAS;IAAA,OAAAb,KAAA;EAAA;EAAAc,YAAA,CAAAnB,aAAA;IAAAoB,GAAA;IAAAC,GAAA,EAVtB,SAAAA,IAAA,EAAiD;MAC/C,OAAO,CAAC,CAAC;IACX;EAAC;IAAAD,GAAA;IAAAC,GAAA,EAED,SAAAA,IAAA,EAAc;MACZ,OAAO,CAAC,CAAC;IAGX;EAAC;EAAA,OAAArB,aAAA;AAAA,EAZwED,aAAa;AAiBxF,OAAO,IAAMuB,SAAS,GAAGtB,aAAa;AACtC;;AAcA,WAAAuB,aAAA;AA0HC,WAAAC,cAAA;EAAA,IAAAC,eAAA;EAAA,WAAAC,gBAAA,MA9FkBD,eAAe,KAAfA,eAAe,GAAAD,cAAA,CAAfC,eAAe,KAAAD,cAAA,CAAfC,eAAe;AAAA,GA5BjBF,aAAa,KAAbA,aAAa"}
|
|
1
|
+
{"version":3,"file":"Component.js","names":["PureComponent","RootComponent","_PureComponent","_inherits","_super","_createSuper","_this","_classCallCheck","_len","arguments","length","args","Array","_key","call","apply","concat","_defineProperty","_assertThisInitialized","undefined","_createClass","key","get","Component","Intergalactic","_Intergalactic","InternalTypings","_InternalTypings"],"sources":["../../src/Component.tsx"],"sourcesContent":["import React, {\n AllHTMLAttributes,\n ForwardRefExoticComponent,\n PureComponent,\n ReactNode,\n RefObject,\n} from 'react';\nimport { IStyledProps } from './styled';\n\n/** @deprecated */\ntype KnownKeys<T> = {\n [K in keyof T]: string extends K ? never : number extends K ? never : K;\n} extends { [_ in keyof T]: infer U }\n ? U\n : never;\n\n/** @deprecated */\nexport type HandlersType<UCProps> = { [K in keyof UCProps]?: <T = unknown>(arg: T) => void };\n/** @deprecated */\nexport type ChildrenType<Props = {}, Ctx = {}, UCProps = {}> =\n | ((props: Props & Ctx, handlers: HandlersType<UCProps>) => ReactNode)\n | ReactNode;\n\n/** @deprecated */\nexport type RootComponentHandler = (...args: any[]) => void | false;\n\n/** @deprecated */\nexport interface IRootComponentHandlers {\n [key: string]: RootComponentHandler;\n}\n\n/** @deprecated */\nexport interface IRootComponentProps<Props = {}, Ctx = {}> {\n forwardRef?: RefObject<any>;\n Children?: any;\n children?: ChildrenType<Props, Ctx>;\n styles?: IStyledProps['styles'];\n}\n\n/** @deprecated */\nexport type IComponentProps<Props = {}, Ctx = {}> = Props & IRootComponentProps<Props, Ctx>;\n\n/** @deprecated */\nexport type IFunctionProps<Props = {}, Ctx = {}> = IComponentProps<Props, Ctx> &\n Omit<AllHTMLAttributes<any>, keyof IComponentProps<Props, Ctx>> & { Root?: Root };\n\n/** @deprecated */\nexport type PropsWithRenderFnChildren<Props = {}, Ctx = {}, UCProps = {}> = Omit<\n Pick<Props, KnownKeys<Props>>,\n 'children'\n> & {\n children?: ChildrenType<Props, Ctx, UCProps>;\n [key: string]: unknown;\n};\n\n/** @deprecated */\nexport type CProps<Props, Ctx = {}, UCProps = {}> = Props & {\n children?: ((props: Props & Ctx, handlers: UCProps) => React.ReactNode) | React.ReactNode;\n};\n/** @deprecated */\nexport type ReturnEl = React.ReactElement | null;\n\nexport interface IRootNodeProps {\n render: React.ElementType | string;\n tag?: React.ElementType | string;\n\n [key: string]: any;\n}\n\ntype Root = ForwardRefExoticComponent<IRootNodeProps>;\n\n/**\n * @deprecated since version ^1.8.0\n */\nexport type PropGetter<T extends (...args: any) => any> = <P>(props?: P) => ReturnType<T> & P;\n/**\n * @deprecated since version ^1.8.0\n */\n/** @deprecated */\nexport type PropGetterReturn<T extends (...args: any) => any> = Partial<ReturnType<T>>;\n/** @deprecated */\nexport type PropGetterFn = <T extends {}>(props?: T) => T & { [key: string]: unknown };\n/** @deprecated */\nexport type Merge<Props, HTMLProps> = Props & Omit<HTMLProps, keyof Props>;\n/** @deprecated */\nexport type MergeGetters<G1 extends (...args: any) => any, G2 extends (...args: any) => any> = <P>(\n props?: P,\n) => Merge<ReturnType<G1>, ReturnType<G2>> & P;\n\ndeclare const Root: Root;\n\nexport { Root };\n\n/** @deprecated */\nabstract class RootComponent<Props = {}, Context = {}, State = {}> extends PureComponent<\n Props & IRootComponentProps<Props, Context>,\n State\n> {\n get handlers(): Readonly<IRootComponentHandlers> {\n return {};\n }\n\n get asProps() {\n return {} as Readonly<\n Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>\n >;\n }\n\n Root: Root = undefined as any;\n}\n\nexport const Component = RootComponent;\n/** @deprecated */\nexport type Component<\n Props = {},\n Context = {},\n State = {},\n Handlers extends IRootComponentHandlers = IRootComponentHandlers,\n> = React.ComponentClass<Props, State> & {\n handlers: Readonly<Handlers>;\n\n asProps: Readonly<Merge<Props & IRootComponentProps<Props, Context>, AllHTMLAttributes<any>>>;\n\n Root: Root;\n};\n\nexport namespace Intergalactic {\n type ReactFCProps<C extends React.FC> = C extends React.FC<infer Props> ? Omit<Props, 'tag'> : {};\n type ReactComponentProps<C extends React.ComponentClass> = C extends React.ComponentClass<\n infer Props\n >\n ? Omit<Props, 'tag'>\n : never;\n type ReactFCLike = (props: any) => any;\n type ReactFCLikeProps<C extends ReactFCLike> = C extends (props: infer Props) => any ? Props : {};\n type ComponentChildren<\n Props,\n Context,\n RenderingResult = InternalTypings.ReturnResult,\n AdditionalContext extends any[] = never[],\n > =\n | ((props: MergeProps<Context, Props>, ...args: AdditionalContext) => RenderingResult)\n | InternalTypings.ReturnResult;\n type ComponentBasicProps<Tag extends InternalTypings.ComponentTag> = {\n ref?: React.Ref<InternalTypings.ComponentHtmlElement<Tag> | null>;\n /** @private DO NOT USE IT. Low-level api that prevents specified props from being applied as DOM attribute. */\n __excludeProps?: string[];\n };\n type MergeProps<HighPriorityProps, LowPriorityProps> = {\n [K in keyof LowPriorityProps]: K extends keyof HighPriorityProps\n ? HighPriorityProps[K]\n : LowPriorityProps[K];\n } & HighPriorityProps;\n type RemoveFields<Type, Keys> = {\n [Property in keyof Type as Exclude<Property, Keys>]: Type[Property];\n };\n /** @private */\n export namespace InternalTypings {\n export type ComponentPropsNesting<Tag extends InternalTypings.ComponentTag> = Omit<\n MergeProps<\n Tag extends React.FC\n ? ReactFCProps<Tag>\n : Tag extends React.ComponentClass\n ? ReactComponentProps<Tag>\n : Tag extends ReactFCLike\n ? ReactFCLikeProps<Tag>\n : Tag extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[Tag]\n : {},\n Tag extends { __nestedProps: infer NestedProps } ? NestedProps : {}\n >,\n 'children' | 'tag'\n >;\n export type ReturnResult =\n | React.ReactElement\n | React.ReactNode\n | React.ReactNode[]\n | string\n | null;\n export type ComponentTag =\n | keyof JSX.IntrinsicElements\n | React.ComponentClass\n | React.FC\n | ReactFCLike;\n export type ComponentProps<\n Tag extends ComponentTag,\n BaseTag extends ComponentTag | never,\n Props,\n Context = never,\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n RemoveFields<Props, 'children'> & { children: React.ReactNode },\n Context,\n ReturnResult,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<\n RemoveFields<Props, 'tag' | 'children'>,\n MergeProps<ComponentPropsNesting<Tag>, ComponentPropsNesting<BaseTag>>\n >;\n export type PropsRenderingResultComponentProps<\n Tag extends ComponentTag,\n Props,\n Context = {},\n AdditionalContext extends any[] = never[],\n > = {\n tag?: Tag;\n children?: ComponentChildren<\n RemoveFields<Props, 'children'> & { children: React.ReactNode },\n Context,\n Partial<\n RemoveFields<\n MergeProps<Props, ComponentPropsNesting<Tag>>,\n 'children' | 'tag' | 'ref'\n > & {\n children?: React.ReactNode;\n }\n >,\n AdditionalContext\n >;\n } & ComponentBasicProps<Tag> &\n MergeProps<RemoveFields<Props, 'tag' | 'children'>, ComponentPropsNesting<Tag>>;\n export type ComponentRenderingResults = React.ReactElement;\n export type ComponentAdditive<BaseTag extends ComponentTag> = {\n __nestedProps: ComponentPropsNesting<BaseTag>;\n };\n export type InferJsxIntrinsicElement<T extends React.DetailedHTMLProps<any, any>> =\n T extends React.DetailedHTMLProps<infer _, infer Element> ? Element : HTMLElement;\n type InferElementFromRef<T> = T extends React.Ref<infer Element> ? Element : never;\n type InferRefElementFromProps<T> = 'ref' extends keyof T\n ? InferElementFromRef<T['ref']>\n : HTMLElement;\n export type ComponentHtmlElement<Tag extends ComponentTag> =\n Tag extends keyof JSX.IntrinsicElements\n ? InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>\n : Tag extends { __nestedProps: infer NestedProps }\n ? InferRefElementFromProps<NestedProps>\n : HTMLElement;\n }\n export type Component<\n BaseTag extends InternalTypings.ComponentTag = never,\n BaseProps = {},\n Context = {},\n AdditionalContext extends any[] = never[],\n > = (<Tag extends InternalTypings.ComponentTag = BaseTag, Props extends BaseProps = BaseProps>(\n props: InternalTypings.ComponentProps<Tag, BaseTag, Props, Context, AdditionalContext>,\n ) => InternalTypings.ComponentRenderingResults) &\n InternalTypings.ComponentAdditive<BaseTag>;\n export type Tag = InternalTypings.ComponentTag;\n export type DomProps<Tag extends keyof JSX.IntrinsicElements> =\n InternalTypings.InferJsxIntrinsicElement<JSX.IntrinsicElements[Tag]>;\n}\n"],"mappings":";;;;;;AAAA,SAGEA,aAAa,QAGR,OAAO;AAuFd;AAAA,IACeC,aAAa,0BAAAC,cAAA;EAAAC,SAAA,CAAAF,aAAA,EAAAC,cAAA;EAAA,IAAAE,MAAA,GAAAC,YAAA,CAAAJ,aAAA;EAAA,SAAAA,cAAA;IAAA,IAAAK,KAAA;IAAAC,eAAA,OAAAN,aAAA;IAAA,SAAAO,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAC,IAAA,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAAF,IAAA,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAAP,KAAA,GAAAF,MAAA,CAAAU,IAAA,CAAAC,KAAA,CAAAX,MAAA,SAAAY,MAAA,CAAAL,IAAA;IAAAM,eAAA,CAAAC,sBAAA,CAAAZ,KAAA,WAcba,SAAS;IAAA,OAAAb,KAAA;EAAA;EAAAc,YAAA,CAAAnB,aAAA;IAAAoB,GAAA;IAAAC,GAAA,EAVtB,SAAAA,IAAA,EAAiD;MAC/C,OAAO,CAAC,CAAC;IACX;EAAC;IAAAD,GAAA;IAAAC,GAAA,EAED,SAAAA,IAAA,EAAc;MACZ,OAAO,CAAC,CAAC;IAGX;EAAC;EAAA,OAAArB,aAAA;AAAA,EAZwED,aAAa;AAiBxF,OAAO,IAAMuB,SAAS,GAAGtB,aAAa;AACtC;;AAcA,WAAAuB,aAAA;AAgIC,WAAAC,cAAA;EAAA,IAAAC,eAAA;EAAA,WAAAC,gBAAA,MAjGkBD,eAAe,KAAfA,eAAe,GAAAD,cAAA,CAAfC,eAAe,KAAAD,cAAA,CAAfC,eAAe;AAAA,GA/BjBF,aAAa,KAAbA,aAAa"}
|
|
@@ -22,6 +22,8 @@ function flatChildComponent(childComponents) {
|
|
|
22
22
|
return acc;
|
|
23
23
|
}, []);
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
/** @deprecated Doesn't work in ssr and sometimes breakes rulles of hooks. We should never use it. */
|
|
25
27
|
function Enhancement(childComponents, Context) {
|
|
26
28
|
return {
|
|
27
29
|
condition: function condition(Component) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hoistProps.js","names":["React","assignProps","useEnhancedEffect","pick","HOIST_CONTEXT","Symbol","HOIST_SELF","HOIST_SET","flatChildComponent","childComponents","Object","values","reduce","acc","Component","Array","isArray","concat","_toConsumableArray","push","Enhancement","Context","condition","some","_Component$hoistProps","Boolean","hoistProps","length","init","props","WrapperComponent","isFunction","_this","useState","obj","forceUpdate","context","_objectSpread","_defineProperty","asProps","wrapperProps","_WrapperComponent$hoi","useContext","renameProps","propName","_propName$split","split","_propName$split2","_slicedToArray","name","rename","entries","keys","_ref","_ref2","value"],"sources":["../../../src/enhancement/hoistProps.tsx"],"sourcesContent":["import React from 'react';\n// @ts-ignore\nimport assignProps from '@semcore/utils/lib/assignProps';\n// @ts-ignore\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n// @ts-ignore\nimport pick from '@semcore/utils/lib/pick';\n\nexport const HOIST_CONTEXT = Symbol('HOIST_CONTEXT');\nconst HOIST_SELF = Symbol('HOIST_SELF');\nconst HOIST_SET = Symbol('HOIST_SET');\n\nfunction flatChildComponent(childComponents: any) {\n return Object.values(childComponents).reduce<unknown[]>((acc, Component) => {\n if (Array.isArray(Component)) {\n acc = [...acc, Component[0], ...flatChildComponent(Component[1])];\n } else {\n acc.push(Component);\n }\n return acc;\n }, []);\n}\n\nfunction Enhancement(childComponents: any, Context: any) {\n return {\n condition: function (Component: any) {\n return [Component, ...flatChildComponent(childComponents)].some((Component) =>\n Boolean(Component.hoistProps?.length),\n );\n },\n init: function (this: any, props: any, WrapperComponent: any, isFunction: boolean) {\n if (isFunction) {\n // TODO: might breake rules of hooks (by lsroman)\n this[HOIST_SELF] = React.useState({});\n } else {\n this[HOIST_SELF] = [\n {},\n (obj: any) => {\n this[HOIST_SELF][0] = obj;\n this.forceUpdate();\n },\n ];\n }\n // For optimization render\n this[HOIST_SET] = (obj: any) => {\n this[HOIST_SELF][1](obj);\n };\n },\n context: function (this: any, context: any) {\n // TODO: need to optimizte container initialization (by lsroman)\n // WrapperComponent.hoistProps\n return {\n ...context,\n [HOIST_CONTEXT]: this[HOIST_SET],\n };\n },\n asProps: function (this: any, props: any) {\n // TODO: need to check for no props overwriting (by lsroman)\n return assignProps(this[HOIST_SELF][0], props);\n },\n wrapperProps: function (props: any, WrapperComponent: any) {\n if (WrapperComponent.hoistProps?.length) {\n const context: any = React.useContext(Context);\n const renameProps: any = WrapperComponent.hoistProps.reduce((acc: any, propName: any) => {\n const [name, rename] = propName.split(':');\n acc[name] = rename || name;\n return acc;\n }, {});\n const hoistProps = Object.entries(pick(props, Object.keys(renameProps))).reduce(\n (acc: any, [name, value]) => {\n acc[renameProps[name]] = value;\n return acc;\n },\n {},\n );\n\n useEnhancedEffect(() => {\n if (context[HOIST_CONTEXT]) {\n context[HOIST_CONTEXT](hoistProps);\n }\n }, Object.values(hoistProps));\n }\n return props;\n },\n };\n}\n\nexport default Enhancement;\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB;AACA,OAAOC,WAAW,MAAM,gCAAgC;AACxD;AACA,OAAOC,iBAAiB,MAAM,0CAA0C;AACxE;AACA,OAAOC,IAAI,MAAM,yBAAyB;AAE1C,OAAO,IAAMC,aAAa,GAAGC,MAAM,CAAC,eAAe,CAAC;AACpD,IAAMC,UAAU,GAAGD,MAAM,CAAC,YAAY,CAAC;AACvC,IAAME,SAAS,GAAGF,MAAM,CAAC,WAAW,CAAC;AAErC,SAASG,kBAAkBA,CAACC,eAAoB,EAAE;EAChD,OAAOC,MAAM,CAACC,MAAM,CAACF,eAAe,CAAC,CAACG,MAAM,CAAY,UAACC,GAAG,EAAEC,SAAS,EAAK;IAC1E,IAAIC,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,EAAE;MAC5BD,GAAG,MAAAI,MAAA,CAAAC,kBAAA,CAAOL,GAAG,IAAEC,SAAS,CAAC,CAAC,CAAC,GAAAI,kBAAA,CAAKV,kBAAkB,CAACM,SAAS,CAAC,CAAC,CAAC,CAAC,EAAC;IACnE,CAAC,MAAM;MACLD,GAAG,CAACM,IAAI,CAACL,SAAS,CAAC;IACrB;IACA,OAAOD,GAAG;EACZ,CAAC,EAAE,EAAE,CAAC;AACR;
|
|
1
|
+
{"version":3,"file":"hoistProps.js","names":["React","assignProps","useEnhancedEffect","pick","HOIST_CONTEXT","Symbol","HOIST_SELF","HOIST_SET","flatChildComponent","childComponents","Object","values","reduce","acc","Component","Array","isArray","concat","_toConsumableArray","push","Enhancement","Context","condition","some","_Component$hoistProps","Boolean","hoistProps","length","init","props","WrapperComponent","isFunction","_this","useState","obj","forceUpdate","context","_objectSpread","_defineProperty","asProps","wrapperProps","_WrapperComponent$hoi","useContext","renameProps","propName","_propName$split","split","_propName$split2","_slicedToArray","name","rename","entries","keys","_ref","_ref2","value"],"sources":["../../../src/enhancement/hoistProps.tsx"],"sourcesContent":["import React from 'react';\n// @ts-ignore\nimport assignProps from '@semcore/utils/lib/assignProps';\n// @ts-ignore\nimport useEnhancedEffect from '@semcore/utils/lib/use/useEnhancedEffect';\n// @ts-ignore\nimport pick from '@semcore/utils/lib/pick';\n\nexport const HOIST_CONTEXT = Symbol('HOIST_CONTEXT');\nconst HOIST_SELF = Symbol('HOIST_SELF');\nconst HOIST_SET = Symbol('HOIST_SET');\n\nfunction flatChildComponent(childComponents: any) {\n return Object.values(childComponents).reduce<unknown[]>((acc, Component) => {\n if (Array.isArray(Component)) {\n acc = [...acc, Component[0], ...flatChildComponent(Component[1])];\n } else {\n acc.push(Component);\n }\n return acc;\n }, []);\n}\n\n/** @deprecated Doesn't work in ssr and sometimes breakes rulles of hooks. We should never use it. */\nfunction Enhancement(childComponents: any, Context: any) {\n return {\n condition: function (Component: any) {\n return [Component, ...flatChildComponent(childComponents)].some((Component) =>\n Boolean(Component.hoistProps?.length),\n );\n },\n init: function (this: any, props: any, WrapperComponent: any, isFunction: boolean) {\n if (isFunction) {\n // TODO: might breake rules of hooks (by lsroman)\n this[HOIST_SELF] = React.useState({});\n } else {\n this[HOIST_SELF] = [\n {},\n (obj: any) => {\n this[HOIST_SELF][0] = obj;\n this.forceUpdate();\n },\n ];\n }\n // For optimization render\n this[HOIST_SET] = (obj: any) => {\n this[HOIST_SELF][1](obj);\n };\n },\n context: function (this: any, context: any) {\n // TODO: need to optimizte container initialization (by lsroman)\n // WrapperComponent.hoistProps\n return {\n ...context,\n [HOIST_CONTEXT]: this[HOIST_SET],\n };\n },\n asProps: function (this: any, props: any) {\n // TODO: need to check for no props overwriting (by lsroman)\n return assignProps(this[HOIST_SELF][0], props);\n },\n wrapperProps: function (props: any, WrapperComponent: any) {\n if (WrapperComponent.hoistProps?.length) {\n const context: any = React.useContext(Context);\n const renameProps: any = WrapperComponent.hoistProps.reduce((acc: any, propName: any) => {\n const [name, rename] = propName.split(':');\n acc[name] = rename || name;\n return acc;\n }, {});\n const hoistProps = Object.entries(pick(props, Object.keys(renameProps))).reduce(\n (acc: any, [name, value]) => {\n acc[renameProps[name]] = value;\n return acc;\n },\n {},\n );\n\n useEnhancedEffect(() => {\n if (context[HOIST_CONTEXT]) {\n context[HOIST_CONTEXT](hoistProps);\n }\n }, Object.values(hoistProps));\n }\n return props;\n },\n };\n}\n\nexport default Enhancement;\n"],"mappings":";;;;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB;AACA,OAAOC,WAAW,MAAM,gCAAgC;AACxD;AACA,OAAOC,iBAAiB,MAAM,0CAA0C;AACxE;AACA,OAAOC,IAAI,MAAM,yBAAyB;AAE1C,OAAO,IAAMC,aAAa,GAAGC,MAAM,CAAC,eAAe,CAAC;AACpD,IAAMC,UAAU,GAAGD,MAAM,CAAC,YAAY,CAAC;AACvC,IAAME,SAAS,GAAGF,MAAM,CAAC,WAAW,CAAC;AAErC,SAASG,kBAAkBA,CAACC,eAAoB,EAAE;EAChD,OAAOC,MAAM,CAACC,MAAM,CAACF,eAAe,CAAC,CAACG,MAAM,CAAY,UAACC,GAAG,EAAEC,SAAS,EAAK;IAC1E,IAAIC,KAAK,CAACC,OAAO,CAACF,SAAS,CAAC,EAAE;MAC5BD,GAAG,MAAAI,MAAA,CAAAC,kBAAA,CAAOL,GAAG,IAAEC,SAAS,CAAC,CAAC,CAAC,GAAAI,kBAAA,CAAKV,kBAAkB,CAACM,SAAS,CAAC,CAAC,CA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CACH;QAEDX,iBAAiB,CAAC,YAAM;UACtB,IAAIkC,OAAO,CAAChC,aAAa,CAAC,EAAE;YAC1BgC,OAAO,CAAChC,aAAa,CAAC,CAACsB,UAAU,CAAC;UACpC;QACF,CAAC,EAAEhB,MAAM,CAACC,MAAM,CAACe,UAAU,CAAC,CAAC;MAC/B;MACA,OAAOG,KAAK;IACd;EACF,CAAC;AACH;AAEA,eAAeT,WAAW"}
|
package/lib/types/Component.d.ts
CHANGED
|
@@ -94,6 +94,9 @@ export declare namespace Intergalactic {
|
|
|
94
94
|
type MergeProps<HighPriorityProps, LowPriorityProps> = {
|
|
95
95
|
[K in keyof LowPriorityProps]: K extends keyof HighPriorityProps ? HighPriorityProps[K] : LowPriorityProps[K];
|
|
96
96
|
} & HighPriorityProps;
|
|
97
|
+
type RemoveFields<Type, Keys> = {
|
|
98
|
+
[Property in keyof Type as Exclude<Property, Keys>]: Type[Property];
|
|
99
|
+
};
|
|
97
100
|
/** @private */
|
|
98
101
|
export namespace InternalTypings {
|
|
99
102
|
export type ComponentPropsNesting<Tag extends InternalTypings.ComponentTag> = Omit<MergeProps<Tag extends React.FC ? ReactFCProps<Tag> : Tag extends React.ComponentClass ? ReactComponentProps<Tag> : Tag extends ReactFCLike ? ReactFCLikeProps<Tag> : Tag extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[Tag] : {}, Tag extends {
|
|
@@ -103,18 +106,18 @@ export declare namespace Intergalactic {
|
|
|
103
106
|
export type ComponentTag = keyof JSX.IntrinsicElements | React.ComponentClass | React.FC | ReactFCLike;
|
|
104
107
|
export type ComponentProps<Tag extends ComponentTag, BaseTag extends ComponentTag | never, Props, Context = never, AdditionalContext extends any[] = never[]> = {
|
|
105
108
|
tag?: Tag;
|
|
106
|
-
children?: ComponentChildren<
|
|
109
|
+
children?: ComponentChildren<RemoveFields<Props, 'children'> & {
|
|
107
110
|
children: React.ReactNode;
|
|
108
111
|
}, Context, ReturnResult, AdditionalContext>;
|
|
109
|
-
} & ComponentBasicProps<Tag> & MergeProps<
|
|
112
|
+
} & ComponentBasicProps<Tag> & MergeProps<RemoveFields<Props, 'tag' | 'children'>, MergeProps<ComponentPropsNesting<Tag>, ComponentPropsNesting<BaseTag>>>;
|
|
110
113
|
export type PropsRenderingResultComponentProps<Tag extends ComponentTag, Props, Context = {}, AdditionalContext extends any[] = never[]> = {
|
|
111
114
|
tag?: Tag;
|
|
112
|
-
children?: ComponentChildren<
|
|
115
|
+
children?: ComponentChildren<RemoveFields<Props, 'children'> & {
|
|
113
116
|
children: React.ReactNode;
|
|
114
|
-
}, Context, Partial<
|
|
117
|
+
}, Context, Partial<RemoveFields<MergeProps<Props, ComponentPropsNesting<Tag>>, 'children' | 'tag' | 'ref'> & {
|
|
115
118
|
children?: React.ReactNode;
|
|
116
119
|
}>, AdditionalContext>;
|
|
117
|
-
} & ComponentBasicProps<Tag> & MergeProps<
|
|
120
|
+
} & ComponentBasicProps<Tag> & MergeProps<RemoveFields<Props, 'tag' | 'children'>, ComponentPropsNesting<Tag>>;
|
|
118
121
|
export type ComponentRenderingResults = React.ReactElement;
|
|
119
122
|
export type ComponentAdditive<BaseTag extends ComponentTag> = {
|
|
120
123
|
__nestedProps: ComponentPropsNesting<BaseTag>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const HOIST_CONTEXT: unique symbol;
|
|
2
|
+
/** @deprecated Doesn't work in ssr and sometimes breakes rulles of hooks. We should never use it. */
|
|
2
3
|
declare function Enhancement(childComponents: any, Context: any): {
|
|
3
4
|
condition: (Component: any) => boolean;
|
|
4
5
|
init: (this: any, props: any, WrapperComponent: any, isFunction: boolean) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semcore/core",
|
|
3
3
|
"description": "Semrush Core Component",
|
|
4
|
-
"version": "2.7.
|
|
4
|
+
"version": "2.7.3-prerelease.0",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/es6/index.js",
|
|
7
7
|
"typings": "lib/types/index.d.ts",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"author": "UI-kit team <ui-kit-team@semrush.com>",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@reshadow/core": "0.0.1",
|
|
13
|
-
"@semcore/utils": "4.
|
|
12
|
+
"@reshadow/core": "0.0.1-alpha.74",
|
|
13
|
+
"@semcore/utils": "4.8.0-prerelease.0",
|
|
14
14
|
"classnames": "2.2.6",
|
|
15
15
|
"hoist-non-react-statics": "3.3.2"
|
|
16
16
|
},
|