@vitus-labs/attrs 0.79.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/LICENSE +21 -0
- package/README.md +1 -0
- package/lib/analysis/vitus-labs-attrs.js.html +6638 -0
- package/lib/analysis/vitus-labs-attrs.module.js.html +6638 -0
- package/lib/index.d.ts +323 -0
- package/lib/types/attrs.d.ts +4 -0
- package/lib/types/attrs.d.ts.map +1 -0
- package/lib/types/hoc/attrsHoc.d.ts +6 -0
- package/lib/types/hoc/attrsHoc.d.ts.map +1 -0
- package/lib/types/hoc/index.d.ts +3 -0
- package/lib/types/hoc/index.d.ts.map +1 -0
- package/lib/types/hooks/index.d.ts +3 -0
- package/lib/types/hooks/index.d.ts.map +1 -0
- package/lib/types/hooks/useRef.d.ts +8 -0
- package/lib/types/hooks/useRef.d.ts.map +1 -0
- package/lib/types/index.d.ts +12 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/init.d.ts +9 -0
- package/lib/types/init.d.ts.map +1 -0
- package/lib/types/isAttrsComponent.d.ts +4 -0
- package/lib/types/isAttrsComponent.d.ts.map +1 -0
- package/lib/types/types/AttrsComponent.d.ts +268 -0
- package/lib/types/types/AttrsComponent.d.ts.map +1 -0
- package/lib/types/types/InitAttrsComponent.d.ts +6 -0
- package/lib/types/types/InitAttrsComponent.d.ts.map +1 -0
- package/lib/types/types/attrs.d.ts +2 -0
- package/lib/types/types/attrs.d.ts.map +1 -0
- package/lib/types/types/config.d.ts +10 -0
- package/lib/types/types/config.d.ts.map +1 -0
- package/lib/types/types/configuration.d.ts +21 -0
- package/lib/types/types/configuration.d.ts.map +1 -0
- package/lib/types/types/hoc.d.ts +4 -0
- package/lib/types/types/hoc.d.ts.map +1 -0
- package/lib/types/types/utils.d.ts +22 -0
- package/lib/types/types/utils.d.ts.map +1 -0
- package/lib/types/utils/attrs.d.ts +9 -0
- package/lib/types/utils/attrs.d.ts.map +1 -0
- package/lib/types/utils/chaining.d.ts +6 -0
- package/lib/types/utils/chaining.d.ts.map +1 -0
- package/lib/types/utils/collection.d.ts +4 -0
- package/lib/types/utils/collection.d.ts.map +1 -0
- package/lib/types/utils/compose.d.ts +4 -0
- package/lib/types/utils/compose.d.ts.map +1 -0
- package/lib/types/utils/statics.d.ts +7 -0
- package/lib/types/utils/statics.d.ts.map +1 -0
- package/lib/vitus-labs-attrs.js +223 -0
- package/lib/vitus-labs-attrs.js.map +1 -0
- package/lib/vitus-labs-attrs.module.js +212 -0
- package/lib/vitus-labs-attrs.module.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { isEmpty, compose, pick } from '@vitus-labs/core';
|
|
2
|
+
import React, { useRef, useImperativeHandle, forwardRef } from 'react';
|
|
3
|
+
import hoistNonReactStatics from 'hoist-non-react-statics';
|
|
4
|
+
|
|
5
|
+
const useRocketstyleRef = ({ $attrsRef, ref }) => {
|
|
6
|
+
const internalRef = useRef(null);
|
|
7
|
+
useImperativeHandle($attrsRef, () => internalRef.current);
|
|
8
|
+
useImperativeHandle(ref, () => internalRef.current);
|
|
9
|
+
return internalRef;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-param-reassign */
|
|
13
|
+
const removeUndefinedProps = (props) => Object.keys(props).reduce((acc, key) => {
|
|
14
|
+
const currentValue = props[key];
|
|
15
|
+
if (currentValue !== undefined)
|
|
16
|
+
return { ...acc, [key]: currentValue };
|
|
17
|
+
return acc;
|
|
18
|
+
}, {});
|
|
19
|
+
const calculateChainOptions = (options) => (args) => {
|
|
20
|
+
const result = {};
|
|
21
|
+
if (!options || isEmpty(options))
|
|
22
|
+
return result;
|
|
23
|
+
return options.reduce((acc, item) => Object.assign(acc, item(...args)), {});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/* eslint-disable no-underscore-dangle */
|
|
27
|
+
const attrsHOC = ({ attrs, priorityAttrs }) => {
|
|
28
|
+
// --------------------------------------------------
|
|
29
|
+
// .attrs(...)
|
|
30
|
+
// first we need to calculate final props which are
|
|
31
|
+
// being returned by using `attr` chaining method
|
|
32
|
+
// --------------------------------------------------
|
|
33
|
+
const calculateAttrs = calculateChainOptions(attrs);
|
|
34
|
+
const calculatePriorityAttrs = calculateChainOptions(priorityAttrs);
|
|
35
|
+
const Enhanced = (WrappedComponent) => forwardRef((props, ref) => {
|
|
36
|
+
// --------------------------------------------------
|
|
37
|
+
// remove undefined props not to override potential default props
|
|
38
|
+
// only props with value (e.g. `null`) should override default props
|
|
39
|
+
// --------------------------------------------------
|
|
40
|
+
const filteredProps = removeUndefinedProps(props);
|
|
41
|
+
const prioritizedAttrs = calculatePriorityAttrs([filteredProps]);
|
|
42
|
+
const finalAttrs = calculateAttrs([
|
|
43
|
+
{
|
|
44
|
+
...prioritizedAttrs,
|
|
45
|
+
...filteredProps,
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
return (React.createElement(WrappedComponent, { "$attrsRef": ref, ...prioritizedAttrs, ...finalAttrs, ...filteredProps }));
|
|
49
|
+
});
|
|
50
|
+
return Enhanced;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const createStaticsEnhancers = ({ context, options, }) => {
|
|
54
|
+
if (!isEmpty(options)) {
|
|
55
|
+
Object.assign(context, options);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const chainOptions = (opts, defaultOpts = []) => {
|
|
60
|
+
const result = [...defaultOpts];
|
|
61
|
+
if (typeof opts === 'function')
|
|
62
|
+
result.push(opts);
|
|
63
|
+
else if (typeof opts === 'object')
|
|
64
|
+
result.push(() => opts);
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const calculateHocsFuncs = (options = {}) => Object.values(options)
|
|
69
|
+
.filter((item) => typeof item === 'function')
|
|
70
|
+
.reverse();
|
|
71
|
+
|
|
72
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
73
|
+
const cloneAndEnhance = (defaultOpts, opts) =>
|
|
74
|
+
// @ts-ignore
|
|
75
|
+
rocketComponent({
|
|
76
|
+
...defaultOpts,
|
|
77
|
+
attrs: chainOptions(opts.attrs, defaultOpts.attrs),
|
|
78
|
+
priorityAttrs: chainOptions(opts.priorityAttrs, defaultOpts.priorityAttrs),
|
|
79
|
+
statics: { ...defaultOpts.statics, ...opts.statics },
|
|
80
|
+
compose: { ...defaultOpts.compose, ...opts.compose },
|
|
81
|
+
});
|
|
82
|
+
// --------------------------------------------------------
|
|
83
|
+
// styleComponent
|
|
84
|
+
// helper function which allows function chaining
|
|
85
|
+
// always returns a valid React component with static functions
|
|
86
|
+
// assigned, so it can be even rendered as a valid component
|
|
87
|
+
// or styles can be extended via its statics
|
|
88
|
+
// --------------------------------------------------------
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
const rocketComponent = (options) => {
|
|
91
|
+
const componentName = options.name || options.component.displayName || options.component.name;
|
|
92
|
+
// --------------------------------------------------------
|
|
93
|
+
// COMPONENT - Final component to be rendered
|
|
94
|
+
// --------------------------------------------------------
|
|
95
|
+
const RenderComponent = options.component;
|
|
96
|
+
// --------------------------------------------------------
|
|
97
|
+
// COMPOSE - high-order components
|
|
98
|
+
// --------------------------------------------------------
|
|
99
|
+
const hocsFuncs = [attrsHOC(options), ...calculateHocsFuncs(options.compose)];
|
|
100
|
+
// --------------------------------------------------------
|
|
101
|
+
// ENHANCED COMPONENT (returned component)
|
|
102
|
+
// --------------------------------------------------------
|
|
103
|
+
// .attrs() chaining option is calculated in HOC and passed as props already
|
|
104
|
+
const EnhancedComponent = forwardRef(({ $attrsRef, // it's forwarded from HOC which is always on top of all hocs
|
|
105
|
+
...props }, ref) => {
|
|
106
|
+
// --------------------------------------------------
|
|
107
|
+
// handle refs
|
|
108
|
+
// (1) one is passed from inner HOC - $rocketstyleRef
|
|
109
|
+
// (2) second one is used to be used directly (e.g. inside hocs)
|
|
110
|
+
// --------------------------------------------------
|
|
111
|
+
const internalRef = useRocketstyleRef({ $attrsRef, ref });
|
|
112
|
+
// --------------------------------------------------
|
|
113
|
+
// final props
|
|
114
|
+
// final props passed to WrappedComponent
|
|
115
|
+
// excluding: styling props
|
|
116
|
+
// including: $rocketstyle, $rocketstate
|
|
117
|
+
// --------------------------------------------------
|
|
118
|
+
const finalProps = {
|
|
119
|
+
// this removes styling state from props and passes its state
|
|
120
|
+
// under rocketstate key only
|
|
121
|
+
...props,
|
|
122
|
+
ref: ref || $attrsRef ? internalRef : undefined,
|
|
123
|
+
};
|
|
124
|
+
// all the development stuff injected
|
|
125
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
126
|
+
finalProps['data-attrs'] = componentName;
|
|
127
|
+
}
|
|
128
|
+
return React.createElement(RenderComponent, { ...finalProps });
|
|
129
|
+
});
|
|
130
|
+
// ------------------------------------------------------
|
|
131
|
+
// This will hoist and generate dynamically next static methods
|
|
132
|
+
// for all dimensions available in configuration
|
|
133
|
+
// ------------------------------------------------------
|
|
134
|
+
const RocketComponent = compose(...hocsFuncs)(EnhancedComponent);
|
|
135
|
+
RocketComponent.IS_ATTRS = true;
|
|
136
|
+
RocketComponent.displayName = componentName;
|
|
137
|
+
hoistNonReactStatics(RocketComponent, options.component);
|
|
138
|
+
// ------------------------------------------------------
|
|
139
|
+
RocketComponent.IS_ATTRS = true;
|
|
140
|
+
RocketComponent.displayName = componentName;
|
|
141
|
+
RocketComponent.meta = {};
|
|
142
|
+
// ------------------------------------------------------
|
|
143
|
+
// ------------------------------------------------------
|
|
144
|
+
// enhance for statics
|
|
145
|
+
// ------------------------------------------------------
|
|
146
|
+
createStaticsEnhancers({
|
|
147
|
+
context: RocketComponent.meta,
|
|
148
|
+
options: options.statics,
|
|
149
|
+
});
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
RocketComponent.attrs = (attrs, { priority } = {}) => {
|
|
152
|
+
if (priority) {
|
|
153
|
+
return cloneAndEnhance(options, {
|
|
154
|
+
priorityAttrs: attrs,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return cloneAndEnhance(options, {
|
|
158
|
+
attrs: attrs,
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
// @ts-ignore
|
|
162
|
+
RocketComponent.config = (opts = {}) => {
|
|
163
|
+
const result = pick(opts);
|
|
164
|
+
return cloneAndEnhance(options, result);
|
|
165
|
+
};
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
RocketComponent.statics = (opts) =>
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
cloneAndEnhance(options, { statics: opts });
|
|
170
|
+
RocketComponent.getDefaultAttrs = (props) => calculateChainOptions(options.attrs)([props]);
|
|
171
|
+
return RocketComponent;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// @ts-ignore
|
|
175
|
+
const attrs = ({ name, component }) => {
|
|
176
|
+
// --------------------------------------------------------
|
|
177
|
+
// handle ERRORS in development mode
|
|
178
|
+
// --------------------------------------------------------
|
|
179
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
180
|
+
const errors = {};
|
|
181
|
+
if (!component) {
|
|
182
|
+
errors.component = 'Parameter `component` is missing in params!';
|
|
183
|
+
}
|
|
184
|
+
if (!name) {
|
|
185
|
+
errors.name = 'Parameter `name` is missing in params!';
|
|
186
|
+
}
|
|
187
|
+
if (!isEmpty(errors)) {
|
|
188
|
+
throw Error(JSON.stringify(errors));
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return rocketComponent({
|
|
192
|
+
name,
|
|
193
|
+
component,
|
|
194
|
+
attrs: [],
|
|
195
|
+
priorityAttrs: [],
|
|
196
|
+
compose: {},
|
|
197
|
+
statics: {},
|
|
198
|
+
});
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const isAttrsComponent = (component) => {
|
|
202
|
+
if (component &&
|
|
203
|
+
typeof component === 'object' &&
|
|
204
|
+
component !== null &&
|
|
205
|
+
Object.prototype.hasOwnProperty.call(component, 'IS_ATTRS')) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export { attrs, attrs as default, isAttrsComponent };
|
|
212
|
+
//# sourceMappingURL=vitus-labs-attrs.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vitus-labs-attrs.module.js","sources":["../src/hooks/useRef.ts","../src/utils/attrs.ts","../src/hoc/attrsHoc.tsx","../src/utils/statics.ts","../src/utils/chaining.ts","../src/utils/compose.ts","../src/attrs.tsx","../src/init.ts","../src/isAttrsComponent.tsx"],"sourcesContent":["import { useRef, useImperativeHandle, ForwardedRef } from 'react'\n\ntype UseAttrsRef = (props: {\n $attrsRef?: ForwardedRef<unknown>\n ref?: ForwardedRef<unknown>\n}) => ForwardedRef<unknown>\n\nconst useRocketstyleRef: UseAttrsRef = ({ $attrsRef, ref }) => {\n const internalRef = useRef(null)\n\n useImperativeHandle($attrsRef, () => internalRef.current)\n useImperativeHandle(ref, () => internalRef.current)\n\n return internalRef\n}\n\nexport default useRocketstyleRef\n","/* eslint-disable no-param-reassign */\nimport { isEmpty } from '@vitus-labs/core'\n\n// --------------------------------------------------------\n// Remove undefined props\n// --------------------------------------------------------\ntype RemoveUndefinedProps = <T extends Record<string, any>>(\n props: T\n) => { [I in keyof T as T[I] extends undefined ? never : I]: T[I] }\n\nexport const removeUndefinedProps: RemoveUndefinedProps = (props) =>\n Object.keys(props).reduce((acc, key) => {\n const currentValue = props[key]\n if (currentValue !== undefined) return { ...acc, [key]: currentValue }\n return acc\n }, {} as any)\n\n// --------------------------------------------------------\n// combine values\n// --------------------------------------------------------\ntype OptionFunc<A> = (...arg: Array<A>) => Record<string, unknown>\ntype CalculateChainOptions = <A>(\n options?: Array<OptionFunc<A>>\n) => (args: Array<A>) => ReturnType<OptionFunc<A>>\n\nexport const calculateChainOptions: CalculateChainOptions =\n (options) => (args) => {\n const result = {}\n if (!options || isEmpty(options)) return result\n\n return options.reduce((acc, item) => Object.assign(acc, item(...args)), {})\n }\n","/* eslint-disable no-underscore-dangle */\nimport React, {\n forwardRef,\n ForwardRefExoticComponent,\n ComponentType,\n} from 'react'\nimport { calculateChainOptions, removeUndefinedProps } from '~/utils/attrs'\nimport type { Configuration } from '~/types/configuration'\n\nexport type RocketStyleHOC = ({\n attrs,\n priorityAttrs,\n}: Pick<Configuration, 'attrs' | 'priorityAttrs'>) => (\n WrappedComponent: ComponentType<any>\n) => ForwardRefExoticComponent<any>\n\nconst attrsHOC: RocketStyleHOC = ({ attrs, priorityAttrs }) => {\n // --------------------------------------------------\n // .attrs(...)\n // first we need to calculate final props which are\n // being returned by using `attr` chaining method\n // --------------------------------------------------\n const calculateAttrs = calculateChainOptions(attrs)\n const calculatePriorityAttrs = calculateChainOptions(priorityAttrs)\n\n const Enhanced = (WrappedComponent: ComponentType<any>) =>\n forwardRef<any, any>((props, ref) => {\n // --------------------------------------------------\n // remove undefined props not to override potential default props\n // only props with value (e.g. `null`) should override default props\n // --------------------------------------------------\n const filteredProps = removeUndefinedProps(props)\n\n const prioritizedAttrs = calculatePriorityAttrs([filteredProps])\n\n const finalAttrs = calculateAttrs([\n {\n ...prioritizedAttrs,\n ...filteredProps,\n },\n ])\n\n return (\n <WrappedComponent\n $attrsRef={ref}\n {...prioritizedAttrs}\n {...finalAttrs}\n {...filteredProps}\n />\n )\n })\n\n return Enhanced\n}\n\nexport default attrsHOC\n","import { isEmpty } from '@vitus-labs/core'\n\n// --------------------------------------------------------\n// helpers for create statics on component\n// --------------------------------------------------------\ntype CreateStaticsEnhancers = (params: {\n context: Record<string, any>\n options: Record<string, any>\n}) => void\n\nexport const createStaticsEnhancers: CreateStaticsEnhancers = ({\n context,\n options,\n}) => {\n if (!isEmpty(options)) {\n Object.assign(context, options)\n }\n}\n","type Func = (...args: any) => Record<string, unknown>\ntype Obj = Record<string, unknown>\n\n// --------------------------------------------------------\n// Chain Options\n// --------------------------------------------------------\ntype ChainOptions = (\n opts: Obj | Func | undefined,\n defaultOpts: Func[]\n) => Func[]\n\nexport const chainOptions: ChainOptions = (opts, defaultOpts = []) => {\n const result = [...defaultOpts]\n\n if (typeof opts === 'function') result.push(opts)\n else if (typeof opts === 'object') result.push(() => opts)\n\n return result\n}\n","/* eslint-disable import/prefer-default-export */\ntype CalculateHocsFuncs = (\n options: Record<string, any>\n) => ((arg: any) => any)[]\n\nexport const calculateHocsFuncs: CalculateHocsFuncs = (options = {}) =>\n Object.values(options)\n .filter((item) => typeof item === 'function')\n .reverse()\n","/* eslint-disable @typescript-eslint/ban-ts-comment */\n/* eslint-disable no-underscore-dangle */\nimport React, { forwardRef } from 'react'\nimport hoistNonReactStatics from 'hoist-non-react-statics'\nimport { pick, compose } from '@vitus-labs/core'\nimport { useRef } from '~/hooks'\nimport { attrsHoc } from '~/hoc'\nimport { createStaticsEnhancers } from '~/utils/statics'\nimport { chainOptions } from '~/utils/chaining'\nimport { calculateHocsFuncs } from '~/utils/compose'\nimport { calculateChainOptions } from '~/utils/attrs'\nimport type { AttrsComponent, ExoticComponent } from '~/types/AttrsComponent'\nimport type { InitAttrsComponent } from '~/types/InitAttrsComponent'\nimport type {\n Configuration,\n ExtendedConfiguration,\n} from '~/types/configuration'\n\n// --------------------------------------------------------\n// cloneAndEnhance\n// helper function which allows function chaining\n// always returns rocketComponent with static functions\n// assigned\n// --------------------------------------------------------\ntype CloneAndEnhance = (\n defaultOpts: Configuration,\n opts: Partial<ExtendedConfiguration>\n) => ReturnType<typeof rocketComponent>\n\nconst cloneAndEnhance: CloneAndEnhance = (defaultOpts, opts) =>\n // @ts-ignore\n rocketComponent({\n ...defaultOpts,\n attrs: chainOptions(opts.attrs, defaultOpts.attrs),\n priorityAttrs: chainOptions(opts.priorityAttrs, defaultOpts.priorityAttrs),\n statics: { ...defaultOpts.statics, ...opts.statics },\n compose: { ...defaultOpts.compose, ...opts.compose },\n })\n\n// --------------------------------------------------------\n// styleComponent\n// helper function which allows function chaining\n// always returns a valid React component with static functions\n// assigned, so it can be even rendered as a valid component\n// or styles can be extended via its statics\n// --------------------------------------------------------\n// @ts-ignore\nconst rocketComponent: InitAttrsComponent = (options) => {\n const componentName =\n options.name || options.component.displayName || options.component.name\n\n // --------------------------------------------------------\n // COMPONENT - Final component to be rendered\n // --------------------------------------------------------\n const RenderComponent = options.component\n\n // --------------------------------------------------------\n // COMPOSE - high-order components\n // --------------------------------------------------------\n const hocsFuncs = [attrsHoc(options), ...calculateHocsFuncs(options.compose)]\n\n // --------------------------------------------------------\n // ENHANCED COMPONENT (returned component)\n // --------------------------------------------------------\n // .attrs() chaining option is calculated in HOC and passed as props already\n const EnhancedComponent: ExoticComponent = forwardRef(\n (\n {\n $attrsRef, // it's forwarded from HOC which is always on top of all hocs\n ...props\n },\n ref\n ) => {\n // --------------------------------------------------\n // handle refs\n // (1) one is passed from inner HOC - $rocketstyleRef\n // (2) second one is used to be used directly (e.g. inside hocs)\n // --------------------------------------------------\n const internalRef = useRef({ $attrsRef, ref })\n\n // --------------------------------------------------\n // final props\n // final props passed to WrappedComponent\n // excluding: styling props\n // including: $rocketstyle, $rocketstate\n // --------------------------------------------------\n const finalProps: Record<string, any> = {\n // this removes styling state from props and passes its state\n // under rocketstate key only\n ...props,\n ref: ref || $attrsRef ? internalRef : undefined,\n }\n\n // all the development stuff injected\n if (process.env.NODE_ENV !== 'production') {\n finalProps['data-attrs'] = componentName\n }\n\n return <RenderComponent {...finalProps} />\n }\n )\n\n // ------------------------------------------------------\n // This will hoist and generate dynamically next static methods\n // for all dimensions available in configuration\n // ------------------------------------------------------\n const RocketComponent: AttrsComponent = compose(...hocsFuncs)(\n EnhancedComponent\n )\n RocketComponent.IS_ATTRS = true\n RocketComponent.displayName = componentName\n\n hoistNonReactStatics(RocketComponent, options.component)\n\n // ------------------------------------------------------\n RocketComponent.IS_ATTRS = true\n RocketComponent.displayName = componentName\n RocketComponent.meta = {}\n // ------------------------------------------------------\n\n // ------------------------------------------------------\n // enhance for statics\n // ------------------------------------------------------\n createStaticsEnhancers({\n context: RocketComponent.meta,\n options: options.statics,\n })\n\n // @ts-ignore\n RocketComponent.attrs = (attrs, { priority } = {}) => {\n if (priority) {\n return cloneAndEnhance(options, {\n priorityAttrs: attrs as ExtendedConfiguration['attrs'],\n })\n }\n\n return cloneAndEnhance(options, {\n attrs: attrs as ExtendedConfiguration['attrs'],\n })\n }\n\n // @ts-ignore\n RocketComponent.config = (opts = {}) => {\n const result = pick(opts)\n\n return cloneAndEnhance(options, result)\n }\n\n // @ts-ignore\n RocketComponent.statics = (opts) =>\n // @ts-ignore\n cloneAndEnhance(options, { statics: opts })\n\n RocketComponent.getDefaultAttrs = (props) =>\n calculateChainOptions(options.attrs)([props])\n\n return RocketComponent\n}\n\nexport default rocketComponent\n","import { isEmpty } from '@vitus-labs/core'\nimport attrsComponent from '~/attrs'\nimport type { ElementType } from '~/types/utils'\nimport type { InitAttrsComponent } from '~/types/InitAttrsComponent'\n\nexport type Attrs = <C extends ElementType<any>>({\n name,\n component,\n}: {\n name: string\n component: C\n}) => ReturnType<InitAttrsComponent<C>>\n\n// @ts-ignore\nconst attrs: Attrs = ({ name, component }) => {\n // --------------------------------------------------------\n // handle ERRORS in development mode\n // --------------------------------------------------------\n if (process.env.NODE_ENV !== 'production') {\n type Errors = Partial<{\n component: string\n name: string\n }>\n\n const errors: Errors = {}\n if (!component) {\n errors.component = 'Parameter `component` is missing in params!'\n }\n\n if (!name) {\n errors.name = 'Parameter `name` is missing in params!'\n }\n\n if (!isEmpty(errors)) {\n throw Error(JSON.stringify(errors))\n }\n }\n\n return attrsComponent({\n name,\n component,\n attrs: [],\n priorityAttrs: [],\n compose: {},\n statics: {},\n })\n}\n\nexport default attrs\n","export type IsAttrsComponent = <T>(component: T) => boolean\n\nconst isAttrsComponent: IsAttrsComponent = (component) => {\n if (\n component &&\n typeof component === 'object' &&\n component !== null &&\n Object.prototype.hasOwnProperty.call(component, 'IS_ATTRS')\n ) {\n return true\n }\n\n return false\n}\n\nexport default isAttrsComponent\n"],"names":["attrsHoc","useRef","att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CAAC,SAAS,KAAI;AACvD,IAAA,IACE,SAAS;QACT,OAAO,SAAS,KAAK,QAAQ;AAC7B,QAAA,SAAS,KAAK,IAAI;QAClB,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,EAC3D;AACA,QAAA,OAAO,IAAI,CAAA;AACZ,KAAA;AAED,IAAA,OAAO,KAAK,CAAA;AACd;;;;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vitus-labs/attrs",
|
|
3
|
+
"version": "0.79.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Vit Bokisch <vit@bokisch.cz>",
|
|
6
|
+
"maintainers": [
|
|
7
|
+
"Vit Bokisch <vit@bokisch.cz>"
|
|
8
|
+
],
|
|
9
|
+
"main": "lib/vitus-labs-attrs.js",
|
|
10
|
+
"module": "lib/vitus-labs-attrs.module.js",
|
|
11
|
+
"types": "lib/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"lib/"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://github.com/vitus-labs/ui-system/tree/master/packages/attrs",
|
|
16
|
+
"description": "Attrs hoc chaining for React components",
|
|
17
|
+
"keywords": [
|
|
18
|
+
"flexible",
|
|
19
|
+
"extensible",
|
|
20
|
+
"powerful",
|
|
21
|
+
"system",
|
|
22
|
+
"react",
|
|
23
|
+
"reusability",
|
|
24
|
+
"extensible"
|
|
25
|
+
],
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/vitus-labs/ui-system.git"
|
|
32
|
+
},
|
|
33
|
+
"bugs": {
|
|
34
|
+
"url": "https://github.com/vitus-labs/ui-system/issues"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "yarn vl_stories",
|
|
38
|
+
"prepublish": "yarn build",
|
|
39
|
+
"build": "yarn vl_build",
|
|
40
|
+
"build:watch": "yarn vl_build-watch",
|
|
41
|
+
"lint:css": "stylelint src/*.ts src/*.tsx",
|
|
42
|
+
"lint:ts": "eslint src/*",
|
|
43
|
+
"lint": "yarn lint:css && yarn lint:ts",
|
|
44
|
+
"test": "jest --runInBand",
|
|
45
|
+
"test:coverage": "jest --runInBand --coverage",
|
|
46
|
+
"test:watch": "jest --runInBand --watch",
|
|
47
|
+
"cover": "coveralls < .coverage/lcov.info"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@vitus-labs/core": "*",
|
|
51
|
+
"react": ">= 16.8"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"hoist-non-react-statics": "^3.3.2"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@vitus-labs/core": "^0.79.0",
|
|
58
|
+
"@vitus-labs/tools-babel": "^0.45.0",
|
|
59
|
+
"@vitus-labs/tools-rollup": "^0.45.0",
|
|
60
|
+
"@vitus-labs/tools-storybook": "^0.45.0",
|
|
61
|
+
"@vitus-labs/tools-types": "^0.45.0",
|
|
62
|
+
"@vitus-labs/tools-typescript": "^0.45.0"
|
|
63
|
+
},
|
|
64
|
+
"gitHead": "dda2a8b8d07026cd6b7781721ca5b992172246ba"
|
|
65
|
+
}
|