@vitus-labs/rocketstyle 0.45.0 → 0.48.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/lib/analysis/vitus-labs-rocketstyle.js.html +1 -1
- package/lib/analysis/vitus-labs-rocketstyle.module.js.html +1 -1
- package/package.json +10 -16
- package/lib/analysis/vitus-labs-rocketstyle.umd.js.html +0 -6444
- package/lib/analysis/vitus-labs-rocketstyle.umd.min.js.html +0 -6444
- package/lib/vitus-labs-rocketstyle.umd.js +0 -679
- package/lib/vitus-labs-rocketstyle.umd.js.map +0 -1
- package/lib/vitus-labs-rocketstyle.umd.min.js +0 -4
- package/lib/vitus-labs-rocketstyle.umd.min.js.map +0 -1
|
@@ -1,679 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@vitus-labs/core'), require('react'), require('hoist-non-react-statics')) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@vitus-labs/core', 'react', 'hoist-non-react-statics'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.vitusLabsRocketstyle = {}, global.core, global.React, global.hoistNonReactStatics));
|
|
5
|
-
})(this, (function (exports, core, React, hoistNonReactStatics) { 'use strict';
|
|
6
|
-
|
|
7
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
8
|
-
|
|
9
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
10
|
-
var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
|
|
11
|
-
|
|
12
|
-
const handleEvent = (e) => {
|
|
13
|
-
e.preventDefault();
|
|
14
|
-
e.stopPropagation();
|
|
15
|
-
};
|
|
16
|
-
const usePseudoState = (props) => {
|
|
17
|
-
const [hover, setHover] = React.useState(false);
|
|
18
|
-
const [focus, setFocus] = React.useState(false);
|
|
19
|
-
const [pressed, setPressed] = React.useState(false);
|
|
20
|
-
const onMouseEnter = React.useCallback((e) => {
|
|
21
|
-
handleEvent(e);
|
|
22
|
-
setHover(true);
|
|
23
|
-
if (props.onMouseEnter)
|
|
24
|
-
props.onMouseEnter(e);
|
|
25
|
-
}, [props.onMouseEnter]);
|
|
26
|
-
const onMouseLeave = React.useCallback((e) => {
|
|
27
|
-
handleEvent(e);
|
|
28
|
-
setHover(false);
|
|
29
|
-
setPressed(false);
|
|
30
|
-
if (props.onMouseLeave)
|
|
31
|
-
props.onMouseLeave(e);
|
|
32
|
-
}, [props.onMouseLeave]);
|
|
33
|
-
const onMouseDown = React.useCallback((e) => {
|
|
34
|
-
handleEvent(e);
|
|
35
|
-
setPressed(true);
|
|
36
|
-
if (props.onMouseDown)
|
|
37
|
-
props.onMouseDown(e);
|
|
38
|
-
}, [props.onMouseDown]);
|
|
39
|
-
const onMouseUp = React.useCallback((e) => {
|
|
40
|
-
handleEvent(e);
|
|
41
|
-
setPressed(false);
|
|
42
|
-
if (props.onMouseUp)
|
|
43
|
-
props.onMouseUp(e);
|
|
44
|
-
}, [props.onMouseUp]);
|
|
45
|
-
const onFocus = React.useCallback((e) => {
|
|
46
|
-
handleEvent(e);
|
|
47
|
-
setFocus(true);
|
|
48
|
-
if (props.onFocus)
|
|
49
|
-
props.onFocus(e);
|
|
50
|
-
}, [props.onFocus]);
|
|
51
|
-
const onBlur = React.useCallback((e) => {
|
|
52
|
-
handleEvent(e);
|
|
53
|
-
setFocus(false);
|
|
54
|
-
if (props.onBlur)
|
|
55
|
-
props.onBlur(e);
|
|
56
|
-
}, [props.onBlur]);
|
|
57
|
-
return {
|
|
58
|
-
state: {
|
|
59
|
-
hover,
|
|
60
|
-
focus,
|
|
61
|
-
pressed,
|
|
62
|
-
},
|
|
63
|
-
events: {
|
|
64
|
-
onMouseEnter,
|
|
65
|
-
onMouseLeave,
|
|
66
|
-
onMouseDown,
|
|
67
|
-
onMouseUp,
|
|
68
|
-
onFocus,
|
|
69
|
-
onBlur,
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/* eslint-disable import/prefer-default-export */
|
|
75
|
-
const chainOptions = (opts, defaultOpts = []) => {
|
|
76
|
-
const result = [...defaultOpts];
|
|
77
|
-
if (typeof opts === 'function')
|
|
78
|
-
result.push(opts);
|
|
79
|
-
else if (typeof opts === 'object')
|
|
80
|
-
result.push(() => opts);
|
|
81
|
-
return result;
|
|
82
|
-
};
|
|
83
|
-
const removeNullableValues = (obj) => Object.entries(obj)
|
|
84
|
-
.filter(([, v]) => v != null && v !== false)
|
|
85
|
-
.reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {});
|
|
86
|
-
|
|
87
|
-
const isValidKey = (value) => value !== undefined && value !== null && value !== false;
|
|
88
|
-
const isMultiKey = (value) => {
|
|
89
|
-
if (typeof value === 'object')
|
|
90
|
-
return [true, core.get(value, 'propName')];
|
|
91
|
-
return [false, value];
|
|
92
|
-
};
|
|
93
|
-
const calculateDimensionsMap = ({ themes, useBooleans, }) => {
|
|
94
|
-
const result = { keysMap: {}, keywords: {} };
|
|
95
|
-
if (core.isEmpty(themes))
|
|
96
|
-
return result;
|
|
97
|
-
return Object.entries(themes).reduce((accumulator, [key, value]) => {
|
|
98
|
-
const { keysMap, keywords } = accumulator;
|
|
99
|
-
keywords[key] = true;
|
|
100
|
-
Object.entries(value).forEach(([itemKey, itemValue]) => {
|
|
101
|
-
if (!isValidKey(itemValue))
|
|
102
|
-
return;
|
|
103
|
-
if (useBooleans) {
|
|
104
|
-
keywords[itemKey] = true;
|
|
105
|
-
}
|
|
106
|
-
core.set(keysMap, [key, itemKey], true);
|
|
107
|
-
});
|
|
108
|
-
return accumulator;
|
|
109
|
-
}, result);
|
|
110
|
-
};
|
|
111
|
-
const getKeys = (obj) => Object.keys(obj);
|
|
112
|
-
const getValues = (obj) => Object.values(obj);
|
|
113
|
-
const getDimensionsValues = (obj) => getValues(obj).map((item) => {
|
|
114
|
-
if (typeof item === 'object') {
|
|
115
|
-
return item.propName;
|
|
116
|
-
}
|
|
117
|
-
return item;
|
|
118
|
-
});
|
|
119
|
-
const getMultipleDimensions = (obj) => getValues(obj).reduce((accumulator, value) => {
|
|
120
|
-
if (typeof value === 'object') {
|
|
121
|
-
// eslint-disable-next-line no-param-reassign
|
|
122
|
-
if (value.multi === true)
|
|
123
|
-
accumulator[value.propName] = true;
|
|
124
|
-
}
|
|
125
|
-
return accumulator;
|
|
126
|
-
}, {});
|
|
127
|
-
|
|
128
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
129
|
-
// --------------------------------------------------------
|
|
130
|
-
// theme mode callback
|
|
131
|
-
// --------------------------------------------------------
|
|
132
|
-
const themeModeCb = (...params) => (mode) => {
|
|
133
|
-
if (!mode || mode === 'light')
|
|
134
|
-
return params[0];
|
|
135
|
-
return params[1];
|
|
136
|
-
};
|
|
137
|
-
const calculateDimensionThemes = (theme, options, cb) => {
|
|
138
|
-
const result = {};
|
|
139
|
-
if (core.isEmpty(options.dimensions))
|
|
140
|
-
return result;
|
|
141
|
-
return Object.entries(options.dimensions).reduce((accumulator, [key, value]) => {
|
|
142
|
-
const [, dimension] = isMultiKey(value);
|
|
143
|
-
const helper = options[key];
|
|
144
|
-
if (Array.isArray(helper) && helper.length > 0) {
|
|
145
|
-
const finalDimensionThemes = calculateChainOptions$1(helper, [
|
|
146
|
-
theme,
|
|
147
|
-
cb,
|
|
148
|
-
core.config.css,
|
|
149
|
-
]);
|
|
150
|
-
// eslint-disable-next-line no-param-reassign
|
|
151
|
-
accumulator[dimension] = removeNullableValues(finalDimensionThemes);
|
|
152
|
-
}
|
|
153
|
-
return accumulator;
|
|
154
|
-
}, result);
|
|
155
|
-
};
|
|
156
|
-
const calculateChainOptions$1 = (options, args) => {
|
|
157
|
-
const result = {};
|
|
158
|
-
if (core.isEmpty(options))
|
|
159
|
-
return result;
|
|
160
|
-
return options.reduce((acc, item) => core.merge(acc, item(...args)), result);
|
|
161
|
-
// using this does not allow overriding themes properly
|
|
162
|
-
// return removeAllEmptyValues(helper)
|
|
163
|
-
};
|
|
164
|
-
const calculateTheme = ({ rocketstate, themes, baseTheme, }) => {
|
|
165
|
-
// generate final theme which will be passed to styled component
|
|
166
|
-
let finalTheme = { ...baseTheme };
|
|
167
|
-
Object.entries(rocketstate).forEach(([key, value]) => {
|
|
168
|
-
const keyTheme = themes[key];
|
|
169
|
-
if (Array.isArray(value)) {
|
|
170
|
-
value.forEach((item) => {
|
|
171
|
-
finalTheme = core.merge({}, finalTheme, keyTheme[item]);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
finalTheme = core.merge({}, finalTheme, keyTheme[value]);
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
return finalTheme;
|
|
179
|
-
};
|
|
180
|
-
const calculateThemeMode = (themes, variant) => {
|
|
181
|
-
const callback = themeModeCb().toString();
|
|
182
|
-
const isModeCallback = (value) => value.toString() === callback;
|
|
183
|
-
const result = {};
|
|
184
|
-
Object.entries(themes).forEach(([key, value]) => {
|
|
185
|
-
if (typeof value === 'object' && value !== null) {
|
|
186
|
-
result[key] = calculateThemeMode(value, variant);
|
|
187
|
-
}
|
|
188
|
-
else if (typeof value === 'function' && isModeCallback(value)) {
|
|
189
|
-
result[key] = value(variant);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
result[key] = value;
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
return result;
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const useTheme = ({ theme, options, cb }) => {
|
|
199
|
-
const themes = calculateDimensionThemes(theme, options, cb);
|
|
200
|
-
const { keysMap, keywords } = calculateDimensionsMap({
|
|
201
|
-
themes,
|
|
202
|
-
useBooleans: options.useBooleans,
|
|
203
|
-
});
|
|
204
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
205
|
-
const __ROCKETSTYLE__ = {
|
|
206
|
-
dimensions: keysMap,
|
|
207
|
-
reservedPropNames: keywords,
|
|
208
|
-
baseTheme: calculateChainOptions$1(options.theme, [theme, cb, core.config.css]),
|
|
209
|
-
themes,
|
|
210
|
-
};
|
|
211
|
-
return __ROCKETSTYLE__;
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const Provider = ({ provider = core.Provider, ...props }) => {
|
|
215
|
-
const ctx = React.useContext(core.context);
|
|
216
|
-
const { theme, mode, inversed, provider: RocketstyleProvider, children, } = { ...props, ...ctx, provider };
|
|
217
|
-
const isDark = inversed ? mode !== 'dark' : mode === 'dark';
|
|
218
|
-
return (React__default["default"].createElement(RocketstyleProvider, { mode: mode, isDark: isDark, isLight: !isDark, theme: theme, provider: provider }, children));
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
const PSEUDO_KEYS = ['hover', 'active', 'focus', 'pressed'];
|
|
222
|
-
const THEME_MODES = {
|
|
223
|
-
light: true,
|
|
224
|
-
dark: true,
|
|
225
|
-
};
|
|
226
|
-
const THEME_MODES_INVERSED = {
|
|
227
|
-
dark: 'light',
|
|
228
|
-
light: 'dark',
|
|
229
|
-
};
|
|
230
|
-
const CONFIG_KEYS = [
|
|
231
|
-
'provider',
|
|
232
|
-
'consumer',
|
|
233
|
-
'DEBUG',
|
|
234
|
-
'name',
|
|
235
|
-
'component',
|
|
236
|
-
'inversed',
|
|
237
|
-
'passProps',
|
|
238
|
-
'styled',
|
|
239
|
-
];
|
|
240
|
-
const STYLING_KEYS = ['theme', 'attrs', 'styles'];
|
|
241
|
-
const STATIC_KEYS = [...STYLING_KEYS, 'compose'];
|
|
242
|
-
const ALL_RESERVED_KEYS = [
|
|
243
|
-
...Object.keys(THEME_MODES),
|
|
244
|
-
...CONFIG_KEYS,
|
|
245
|
-
...STATIC_KEYS,
|
|
246
|
-
];
|
|
247
|
-
|
|
248
|
-
const useThemeOptions = ({ inversed }) => {
|
|
249
|
-
const { theme, mode: ctxMode, isDark: ctxDark } = React.useContext(core.context);
|
|
250
|
-
const mode = inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode;
|
|
251
|
-
const isDark = inversed ? !ctxDark : ctxDark;
|
|
252
|
-
const isLight = !isDark;
|
|
253
|
-
return { theme, mode, isDark, isLight };
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const pickStyledProps = (props, keywords) => {
|
|
257
|
-
const result = {};
|
|
258
|
-
Object.entries(props).forEach(([key, value]) => {
|
|
259
|
-
if (keywords[key])
|
|
260
|
-
result[key] = value;
|
|
261
|
-
});
|
|
262
|
-
return result;
|
|
263
|
-
};
|
|
264
|
-
const calculateChainOptions = (options) => (args) => {
|
|
265
|
-
const result = {};
|
|
266
|
-
if (core.isEmpty(options))
|
|
267
|
-
return result;
|
|
268
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
269
|
-
// @ts-ignore
|
|
270
|
-
return options.reduce((acc, item) => Object.assign(acc, item(...args)), result);
|
|
271
|
-
};
|
|
272
|
-
const calculateStylingAttrs = ({ useBooleans, multiKeys }) => ({ props, dimensions }) => {
|
|
273
|
-
const result = {};
|
|
274
|
-
// (1) find dimension keys values & initialize
|
|
275
|
-
// object with possible options
|
|
276
|
-
Object.keys(dimensions).forEach((item) => {
|
|
277
|
-
const pickedProp = props[item];
|
|
278
|
-
const valueTypes = ['number', 'string'];
|
|
279
|
-
// if the property is mutli key, allow assign array as well
|
|
280
|
-
if (multiKeys && multiKeys[item] && Array.isArray(pickedProp)) {
|
|
281
|
-
result[item] = pickedProp;
|
|
282
|
-
}
|
|
283
|
-
// assign when it's only a string or number otherwise it's considered
|
|
284
|
-
// as invalid param
|
|
285
|
-
else if (valueTypes.includes(typeof pickedProp)) {
|
|
286
|
-
result[item] = pickedProp;
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
result[item] = undefined;
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
// (2) if booleans are being used let's find the rest
|
|
293
|
-
if (useBooleans) {
|
|
294
|
-
const propsKeys = Object.keys(props).reverse();
|
|
295
|
-
Object.entries(result).forEach(([key, value]) => {
|
|
296
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
297
|
-
// @ts-ignore
|
|
298
|
-
const isMultiKey = multiKeys[key];
|
|
299
|
-
// when value in result is not assigned yet
|
|
300
|
-
if (!value) {
|
|
301
|
-
let newDimensionValue;
|
|
302
|
-
const keywords = Object.keys(dimensions[key]);
|
|
303
|
-
if (isMultiKey) {
|
|
304
|
-
newDimensionValue = propsKeys.filter((key) => keywords.includes(key));
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
// reverse props to guarantee the last one will have
|
|
308
|
-
// a priority over previous ones
|
|
309
|
-
newDimensionValue = propsKeys.find((key) => {
|
|
310
|
-
if (keywords.includes(key) && props[key])
|
|
311
|
-
return key;
|
|
312
|
-
return false;
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
result[key] = newDimensionValue;
|
|
316
|
-
}
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
return result;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
/* eslint-disable no-underscore-dangle */
|
|
323
|
-
const rocketStyleHOC = ({ inversed, attrs }) => {
|
|
324
|
-
// --------------------------------------------------
|
|
325
|
-
// .attrs(...)
|
|
326
|
-
// first we need to calculate final props which are
|
|
327
|
-
// being returned by using `attr` chaining method
|
|
328
|
-
// --------------------------------------------------
|
|
329
|
-
const _calculateChainOptions = calculateChainOptions(attrs);
|
|
330
|
-
const Enhanced = (WrappedComponent) => React.forwardRef((props, ref) => {
|
|
331
|
-
const { theme, mode, isDark, isLight } = useThemeOptions({
|
|
332
|
-
inversed,
|
|
333
|
-
});
|
|
334
|
-
const calculatedAttrs = _calculateChainOptions([
|
|
335
|
-
props,
|
|
336
|
-
theme,
|
|
337
|
-
{
|
|
338
|
-
renderContent: core.renderContent,
|
|
339
|
-
mode,
|
|
340
|
-
isDark,
|
|
341
|
-
isLight,
|
|
342
|
-
},
|
|
343
|
-
]);
|
|
344
|
-
return (React__default["default"].createElement(WrappedComponent, { "$rocketstyleRef": ref, ...calculatedAttrs, ...props }));
|
|
345
|
-
});
|
|
346
|
-
return Enhanced;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
var localContext = React.createContext({});
|
|
350
|
-
|
|
351
|
-
const RocketStyleProviderComponent = (WrappedComponent) => React.forwardRef(({ onMouseEnter, onMouseLeave, onMouseUp, onMouseDown, onFocus, onBlur, $rocketstate, ...props }, ref) => {
|
|
352
|
-
// pseudo hook to detect states hover / pressed / focus
|
|
353
|
-
const pseudo = usePseudoState({
|
|
354
|
-
onMouseEnter,
|
|
355
|
-
onMouseLeave,
|
|
356
|
-
onMouseUp,
|
|
357
|
-
onMouseDown,
|
|
358
|
-
onFocus,
|
|
359
|
-
onBlur,
|
|
360
|
-
});
|
|
361
|
-
const updatedState = React.useMemo(() => ({
|
|
362
|
-
...$rocketstate,
|
|
363
|
-
pseudo: { ...$rocketstate.pseudo, ...pseudo.state },
|
|
364
|
-
}), [$rocketstate, pseudo]);
|
|
365
|
-
return (React__default["default"].createElement(localContext.Provider, { value: updatedState },
|
|
366
|
-
React__default["default"].createElement(WrappedComponent, { ...props, ...pseudo.events, ref: ref, "$rocketstate": updatedState })));
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
const calculateStyles = (styles, css) => {
|
|
370
|
-
if (!styles)
|
|
371
|
-
return [];
|
|
372
|
-
return styles.map((item) => item(css));
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
/* eslint-disable no-underscore-dangle */
|
|
376
|
-
const orOptions = (keys, opts, defaultOpts) => keys.reduce((acc, item) => ({ ...acc, [item]: opts[item] || defaultOpts[item] }), {});
|
|
377
|
-
const chainReservedOptions = (keys, opts, defaultOpts) => keys.reduce((acc, item) => ({
|
|
378
|
-
...acc,
|
|
379
|
-
[item]: chainOptions(opts[item], defaultOpts[item]),
|
|
380
|
-
}), {});
|
|
381
|
-
// --------------------------------------------------------
|
|
382
|
-
// helpers for create statics chainin methods on component
|
|
383
|
-
// --------------------------------------------------------
|
|
384
|
-
const createStaticsChainingEnhancers = ({ context, dimensionKeys, func, opts, }) => {
|
|
385
|
-
dimensionKeys.forEach((item) => {
|
|
386
|
-
// eslint-disable-next-line no-param-reassign
|
|
387
|
-
context[item] = (props) => func({ [item]: props }, opts);
|
|
388
|
-
});
|
|
389
|
-
};
|
|
390
|
-
// --------------------------------------------------------
|
|
391
|
-
// helpers for create statics on component
|
|
392
|
-
// --------------------------------------------------------
|
|
393
|
-
const createStaticsEnhancers = ({ context, opts }) => {
|
|
394
|
-
if (!core.isEmpty(opts)) {
|
|
395
|
-
Object.assign(context, opts);
|
|
396
|
-
}
|
|
397
|
-
};
|
|
398
|
-
const cloneAndEnhance = (opts, defaultOpts) => styleComponent({
|
|
399
|
-
...defaultOpts,
|
|
400
|
-
statics: { ...defaultOpts.statics, ...opts.statics },
|
|
401
|
-
compose: { ...defaultOpts.compose, ...opts.compose },
|
|
402
|
-
...orOptions(CONFIG_KEYS, opts, defaultOpts),
|
|
403
|
-
...chainReservedOptions([...defaultOpts.dimensionKeys, ...STYLING_KEYS], opts, defaultOpts),
|
|
404
|
-
});
|
|
405
|
-
// --------------------------------------------------------
|
|
406
|
-
// styleComponent
|
|
407
|
-
// helper function which allows function chaining
|
|
408
|
-
// always returns a valid React component with static functions
|
|
409
|
-
// assigned, so it can be even rendered as a valid component
|
|
410
|
-
// or styles can be extended via its statics
|
|
411
|
-
// --------------------------------------------------------
|
|
412
|
-
const styleComponent = (options) => {
|
|
413
|
-
const { component, styles } = options;
|
|
414
|
-
const { styled } = core.config;
|
|
415
|
-
// const _calculateChainOptions = calculateChainOptions(options.attrs)
|
|
416
|
-
const _calculateStylingAttrs = calculateStylingAttrs({
|
|
417
|
-
multiKeys: options.multiKeys,
|
|
418
|
-
useBooleans: options.useBooleans,
|
|
419
|
-
});
|
|
420
|
-
const componentName = options.name || options.component.displayName || options.component.name;
|
|
421
|
-
// create styled component with all options.styles if available
|
|
422
|
-
const STYLED_COMPONENT = component.IS_ROCKETSTYLE || options.styled === false
|
|
423
|
-
? component
|
|
424
|
-
: styled(component) `
|
|
425
|
-
${calculateStyles(styles, core.config.css)};
|
|
426
|
-
`;
|
|
427
|
-
// --------------------------------------------------------
|
|
428
|
-
// final component to be rendered
|
|
429
|
-
// --------------------------------------------------------
|
|
430
|
-
const RenderComponent = options.provider
|
|
431
|
-
? RocketStyleProviderComponent(STYLED_COMPONENT)
|
|
432
|
-
: STYLED_COMPONENT;
|
|
433
|
-
// --------------------------------------------------------
|
|
434
|
-
// hocs
|
|
435
|
-
// --------------------------------------------------------
|
|
436
|
-
const calculateHocsFuncs = Object.values(options.compose || {})
|
|
437
|
-
.filter((item) => typeof item === 'function')
|
|
438
|
-
.reverse();
|
|
439
|
-
const hocsFuncs = [rocketStyleHOC(options), ...calculateHocsFuncs];
|
|
440
|
-
// --------------------------------------------------------
|
|
441
|
-
// ENHANCED COMPONENT (returned component)
|
|
442
|
-
// --------------------------------------------------------
|
|
443
|
-
// .attrs() chaining option is calculated in HOC and passed as props already
|
|
444
|
-
const EnhancedComponent = React.forwardRef(({ $rocketstyleRef, // it's forwarded from HOC which is always on top of hocs
|
|
445
|
-
...props }, ref) => {
|
|
446
|
-
// --------------------------------------------------
|
|
447
|
-
// handle refs
|
|
448
|
-
// (1) one is passed from inner HOC - $rocketstyleRef
|
|
449
|
-
// (2) second one is used to be used directly (e.g. inside hocs)
|
|
450
|
-
// --------------------------------------------------
|
|
451
|
-
const internalRef = React.useRef(null);
|
|
452
|
-
if ($rocketstyleRef)
|
|
453
|
-
React.useImperativeHandle($rocketstyleRef, () => internalRef.current, [
|
|
454
|
-
$rocketstyleRef,
|
|
455
|
-
]);
|
|
456
|
-
if (ref)
|
|
457
|
-
React.useImperativeHandle(ref, () => internalRef.current, [ref]);
|
|
458
|
-
// --------------------------------------------------
|
|
459
|
-
// hover - focus - pressed state passed via context from parent component
|
|
460
|
-
// --------------------------------------------------
|
|
461
|
-
const rocketstyleCtx = options.consumer ? React.useContext(localContext) : {};
|
|
462
|
-
// --------------------------------------------------
|
|
463
|
-
// general theme and theme mode dark / light passed in context
|
|
464
|
-
// --------------------------------------------------
|
|
465
|
-
const { theme, mode } = useThemeOptions(options);
|
|
466
|
-
// --------------------------------------------------
|
|
467
|
-
// calculate themes for all possible styling dimensions
|
|
468
|
-
// .theme(...) + defined dimensions like .states(...), .sizes(...)
|
|
469
|
-
// --------------------------------------------------
|
|
470
|
-
const __ROCKETSTYLE__ = React.useMemo(() => useTheme({
|
|
471
|
-
theme,
|
|
472
|
-
options,
|
|
473
|
-
cb: themeModeCb,
|
|
474
|
-
}),
|
|
475
|
-
// recalculate this only when theme changes
|
|
476
|
-
[theme]);
|
|
477
|
-
const { reservedPropNames, themes: rocketThemes, dimensions, baseTheme: rocketBaseTheme, } = __ROCKETSTYLE__;
|
|
478
|
-
const { baseTheme, themes } = React.useMemo(() => calculateThemeMode({ themes: rocketThemes, baseTheme: rocketBaseTheme }, mode),
|
|
479
|
-
// recalculate this only when theme mode changes dark / light
|
|
480
|
-
[mode]);
|
|
481
|
-
// --------------------------------------------------
|
|
482
|
-
// calculate reserved Keys defined in dimensions as styling keys
|
|
483
|
-
// there is no need to calculate this each time - keys are based on
|
|
484
|
-
// dimensions definitions
|
|
485
|
-
// --------------------------------------------------
|
|
486
|
-
const RESERVED_STYLING_PROPS_KEYS = React.useMemo(() => Object.keys(reservedPropNames), []);
|
|
487
|
-
// --------------------------------------------------
|
|
488
|
-
// get final props which are (latest has the highest priority):
|
|
489
|
-
// (1) merged styling from context,
|
|
490
|
-
// (2) `attrs` chaining method, and from
|
|
491
|
-
// (3) passing them directly to component
|
|
492
|
-
// --------------------------------------------------
|
|
493
|
-
const { pseudo = {}, ...mergeProps } = {
|
|
494
|
-
...(options.consumer
|
|
495
|
-
? options.consumer((callback) => callback(rocketstyleCtx))
|
|
496
|
-
: {}),
|
|
497
|
-
...props,
|
|
498
|
-
};
|
|
499
|
-
// --------------------------------------------------
|
|
500
|
-
// rocketstate
|
|
501
|
-
// calculate final component state including pseudo state
|
|
502
|
-
// passed as $rocketstate prop
|
|
503
|
-
// --------------------------------------------------
|
|
504
|
-
const rocketstate = _calculateStylingAttrs({
|
|
505
|
-
props: pickStyledProps(mergeProps, reservedPropNames),
|
|
506
|
-
dimensions,
|
|
507
|
-
});
|
|
508
|
-
// --------------------------------------------------
|
|
509
|
-
// pseudo state
|
|
510
|
-
// calculate final component pseudo state including pseudo state
|
|
511
|
-
// from props and override by pseudo props from context
|
|
512
|
-
// --------------------------------------------------
|
|
513
|
-
const finalPseudo = {
|
|
514
|
-
...core.pick(props, PSEUDO_KEYS),
|
|
515
|
-
...pseudo,
|
|
516
|
-
};
|
|
517
|
-
const finalRocketstate = { ...rocketstate, pseudo: finalPseudo };
|
|
518
|
-
// --------------------------------------------------
|
|
519
|
-
// rocketstyle
|
|
520
|
-
// calculated (based on styling props) final theme which will be passed
|
|
521
|
-
// to our styled component
|
|
522
|
-
// passed as $rocketstyle prop
|
|
523
|
-
// --------------------------------------------------
|
|
524
|
-
const rocketstyle = calculateTheme({
|
|
525
|
-
rocketstate,
|
|
526
|
-
themes,
|
|
527
|
-
baseTheme,
|
|
528
|
-
});
|
|
529
|
-
// --------------------------------------------------
|
|
530
|
-
// final props
|
|
531
|
-
// final props passed to WrappedComponent
|
|
532
|
-
// excluding: styling props
|
|
533
|
-
// including: $rocketstyle, $rocketstate
|
|
534
|
-
// --------------------------------------------------
|
|
535
|
-
const finalProps = {
|
|
536
|
-
// this removes styling state from props and passes its state
|
|
537
|
-
// under rocketstate key only
|
|
538
|
-
...core.omit(mergeProps, [...RESERVED_STYLING_PROPS_KEYS, ...PSEUDO_KEYS]),
|
|
539
|
-
// if enforced to pass styling props, we pass them directly
|
|
540
|
-
...(options.passProps ? core.pick(mergeProps, options.passProps) : {}),
|
|
541
|
-
ref: ref || $rocketstyleRef ? internalRef : undefined,
|
|
542
|
-
// state props passed to styled component only, therefore the `$` symbol
|
|
543
|
-
$rocketstyle: rocketstyle,
|
|
544
|
-
$rocketstate: finalRocketstate,
|
|
545
|
-
};
|
|
546
|
-
// all the development stuff injected
|
|
547
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
548
|
-
finalProps['data-rocketstyle'] = componentName;
|
|
549
|
-
}
|
|
550
|
-
return React__default["default"].createElement(RenderComponent, { ...finalProps });
|
|
551
|
-
});
|
|
552
|
-
// ------------------------------------------------------
|
|
553
|
-
// This will hoist and generate dynamically next static methods
|
|
554
|
-
// for all dimensions available in configuration
|
|
555
|
-
// ------------------------------------------------------
|
|
556
|
-
const RocketComponent = core.compose(...hocsFuncs)(EnhancedComponent);
|
|
557
|
-
RocketComponent.IS_ROCKETSTYLE = true;
|
|
558
|
-
RocketComponent.displayName = componentName;
|
|
559
|
-
hoistNonReactStatics__default["default"](RocketComponent, options.component);
|
|
560
|
-
// ------------------------------------------------------
|
|
561
|
-
// enhance for chaining methods
|
|
562
|
-
// ------------------------------------------------------
|
|
563
|
-
createStaticsChainingEnhancers({
|
|
564
|
-
context: RocketComponent,
|
|
565
|
-
dimensionKeys: [...options.dimensionKeys, ...STATIC_KEYS],
|
|
566
|
-
func: cloneAndEnhance,
|
|
567
|
-
opts: options,
|
|
568
|
-
});
|
|
569
|
-
// ------------------------------------------------------
|
|
570
|
-
RocketComponent.IS_ROCKETSTYLE = true;
|
|
571
|
-
RocketComponent.displayName = componentName;
|
|
572
|
-
RocketComponent.is = {};
|
|
573
|
-
// ------------------------------------------------------
|
|
574
|
-
// ------------------------------------------------------
|
|
575
|
-
// enhance for statics
|
|
576
|
-
// ------------------------------------------------------
|
|
577
|
-
createStaticsEnhancers({
|
|
578
|
-
context: RocketComponent.is,
|
|
579
|
-
opts: options.statics,
|
|
580
|
-
});
|
|
581
|
-
RocketComponent.config = (opts = {}) => {
|
|
582
|
-
const result = core.pick(opts, CONFIG_KEYS);
|
|
583
|
-
return cloneAndEnhance(result, options);
|
|
584
|
-
};
|
|
585
|
-
RocketComponent.statics = (opts = {}) => cloneAndEnhance({ statics: opts }, options);
|
|
586
|
-
RocketComponent.getStaticDimensions = (theme) => {
|
|
587
|
-
const themes = useTheme({ theme, options, cb: themeModeCb });
|
|
588
|
-
return {
|
|
589
|
-
dimensions: themes.dimensions,
|
|
590
|
-
useBooleans: options.useBooleans,
|
|
591
|
-
multiKeys: options.multiKeys,
|
|
592
|
-
};
|
|
593
|
-
};
|
|
594
|
-
RocketComponent.getDefaultAttrs = (props, theme, mode) => {
|
|
595
|
-
const result = calculateChainOptions(options.attrs)([
|
|
596
|
-
props,
|
|
597
|
-
theme,
|
|
598
|
-
{
|
|
599
|
-
renderContent: core.renderContent,
|
|
600
|
-
mode,
|
|
601
|
-
isDark: mode === 'light',
|
|
602
|
-
isLight: mode === 'dark',
|
|
603
|
-
},
|
|
604
|
-
]);
|
|
605
|
-
return result;
|
|
606
|
-
};
|
|
607
|
-
return RocketComponent;
|
|
608
|
-
};
|
|
609
|
-
|
|
610
|
-
const DEFAULT_DIMENSIONS = {
|
|
611
|
-
states: 'state',
|
|
612
|
-
sizes: 'size',
|
|
613
|
-
variants: 'variant',
|
|
614
|
-
multiple: {
|
|
615
|
-
propName: 'multiple',
|
|
616
|
-
multi: true,
|
|
617
|
-
},
|
|
618
|
-
};
|
|
619
|
-
|
|
620
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
621
|
-
const rocketstyle = () => ({ dimensions = DEFAULT_DIMENSIONS, useBooleans = true } = {}) => ({ name, component }) => {
|
|
622
|
-
// --------------------------------------------------------
|
|
623
|
-
// handle ERRORS in development mode
|
|
624
|
-
// --------------------------------------------------------
|
|
625
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
626
|
-
const errors = {};
|
|
627
|
-
if (!component) {
|
|
628
|
-
errors.component = 'Parameter `component` is missing in params!';
|
|
629
|
-
}
|
|
630
|
-
if (!name) {
|
|
631
|
-
errors.name = 'Parameter `name` is missing in params!';
|
|
632
|
-
}
|
|
633
|
-
if (core.isEmpty(dimensions)) {
|
|
634
|
-
errors.dimensions = 'Parameter `dimensions` is missing in params!';
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
const definedDimensions = getKeys(dimensions);
|
|
638
|
-
const invalidDimension = ALL_RESERVED_KEYS.some((item) => definedDimensions.includes(item));
|
|
639
|
-
if (invalidDimension) {
|
|
640
|
-
errors.invalidDimensions = `Some of your \`dimensions\` is invalid and uses reserved static keys which are
|
|
641
|
-
${DEFAULT_DIMENSIONS.toString()}`;
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
if (!core.isEmpty(errors)) {
|
|
645
|
-
throw Error(JSON.stringify(errors));
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
return styleComponent({
|
|
649
|
-
name,
|
|
650
|
-
component,
|
|
651
|
-
useBooleans,
|
|
652
|
-
dimensions,
|
|
653
|
-
dimensionKeys: getKeys(dimensions),
|
|
654
|
-
dimensionValues: getDimensionsValues(dimensions),
|
|
655
|
-
multiKeys: getMultipleDimensions(dimensions),
|
|
656
|
-
});
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
const isRocketComponent = (component) => {
|
|
660
|
-
if (typeof component === 'object' &&
|
|
661
|
-
component !== null &&
|
|
662
|
-
component.IS_ROCKETSTYLE) {
|
|
663
|
-
return true;
|
|
664
|
-
}
|
|
665
|
-
return false;
|
|
666
|
-
};
|
|
667
|
-
|
|
668
|
-
Object.defineProperty(exports, 'context', {
|
|
669
|
-
enumerable: true,
|
|
670
|
-
get: function () { return core.context; }
|
|
671
|
-
});
|
|
672
|
-
exports.Provider = Provider;
|
|
673
|
-
exports["default"] = rocketstyle;
|
|
674
|
-
exports.isRocketComponent = isRocketComponent;
|
|
675
|
-
|
|
676
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
677
|
-
|
|
678
|
-
}));
|
|
679
|
-
//# sourceMappingURL=vitus-labs-rocketstyle.umd.js.map
|