@vitus-labs/rocketstories 0.54.0 → 0.57.0-alpha.1

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.
@@ -13,51 +13,86 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
13
13
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
14
14
  var hoistNonReactStatics__default = /*#__PURE__*/_interopDefaultLegacy(hoistNonReactStatics);
15
15
 
16
+ const PSEUDO_KEYS = ['hover', 'active', 'focus', 'pressed'];
17
+ const THEME_MODES = {
18
+ light: true,
19
+ dark: true,
20
+ };
21
+ const THEME_MODES_INVERSED = {
22
+ dark: 'light',
23
+ light: 'dark',
24
+ };
25
+ const CONFIG_KEYS = [
26
+ 'provider',
27
+ 'consumer',
28
+ 'DEBUG',
29
+ 'name',
30
+ 'component',
31
+ 'inversed',
32
+ 'passProps',
33
+ 'styled',
34
+ ];
35
+ const STYLING_KEYS = ['theme', 'attrs', 'styles'];
36
+ const STATIC_KEYS = [...STYLING_KEYS, 'compose'];
37
+ const ALL_RESERVED_KEYS = [
38
+ ...Object.keys(THEME_MODES),
39
+ ...CONFIG_KEYS,
40
+ ...STATIC_KEYS,
41
+ ];
42
+
43
+ const context$1 = React.createContext({});
44
+ const useLocalContext = (consumer) => {
45
+ const ctx = consumer ? React.useContext(context$1) : {};
46
+ const result = consumer ? consumer((callback) => callback(ctx)) : {};
47
+ return { pseudo: {}, ...result };
48
+ };
49
+ const LocalProvider = context$1.Provider;
50
+
16
51
  const handleEvent = (e) => {
17
52
  e.preventDefault();
18
53
  e.stopPropagation();
19
54
  };
20
- const usePseudoState = (props) => {
55
+ const usePseudoState = ({ onBlur, onFocus, onMouseDown, onMouseEnter, onMouseLeave, onMouseUp, }) => {
21
56
  const [hover, setHover] = React.useState(false);
22
57
  const [focus, setFocus] = React.useState(false);
23
58
  const [pressed, setPressed] = React.useState(false);
24
- const onMouseEnter = React.useCallback((e) => {
59
+ const handleOnMouseEnter = React.useCallback((e) => {
25
60
  handleEvent(e);
26
61
  setHover(true);
27
- if (props.onMouseEnter)
28
- props.onMouseEnter(e);
29
- }, [props.onMouseEnter]);
30
- const onMouseLeave = React.useCallback((e) => {
62
+ if (onMouseEnter)
63
+ onMouseEnter(e);
64
+ }, [onMouseEnter]);
65
+ const handleOnMouseLeave = React.useCallback((e) => {
31
66
  handleEvent(e);
32
67
  setHover(false);
33
68
  setPressed(false);
34
- if (props.onMouseLeave)
35
- props.onMouseLeave(e);
36
- }, [props.onMouseLeave]);
37
- const onMouseDown = React.useCallback((e) => {
69
+ if (onMouseLeave)
70
+ onMouseLeave(e);
71
+ }, [onMouseLeave]);
72
+ const handleOnMouseDown = React.useCallback((e) => {
38
73
  handleEvent(e);
39
74
  setPressed(true);
40
- if (props.onMouseDown)
41
- props.onMouseDown(e);
42
- }, [props.onMouseDown]);
43
- const onMouseUp = React.useCallback((e) => {
75
+ if (onMouseDown)
76
+ onMouseDown(e);
77
+ }, [onMouseDown]);
78
+ const handleOnMouseUp = React.useCallback((e) => {
44
79
  handleEvent(e);
45
80
  setPressed(false);
46
- if (props.onMouseUp)
47
- props.onMouseUp(e);
48
- }, [props.onMouseUp]);
49
- const onFocus = React.useCallback((e) => {
81
+ if (onMouseUp)
82
+ onMouseUp(e);
83
+ }, [onMouseUp]);
84
+ const handleOnFocus = React.useCallback((e) => {
50
85
  handleEvent(e);
51
86
  setFocus(true);
52
- if (props.onFocus)
53
- props.onFocus(e);
54
- }, [props.onFocus]);
55
- const onBlur = React.useCallback((e) => {
87
+ if (onFocus)
88
+ onFocus(e);
89
+ }, [onFocus]);
90
+ const handleOnBlur = React.useCallback((e) => {
56
91
  handleEvent(e);
57
92
  setFocus(false);
58
- if (props.onBlur)
59
- props.onBlur(e);
60
- }, [props.onBlur]);
93
+ if (onBlur)
94
+ onBlur(e);
95
+ }, [onBlur]);
61
96
  return {
62
97
  state: {
63
98
  hover,
@@ -65,206 +100,69 @@ const usePseudoState = (props) => {
65
100
  pressed,
66
101
  },
67
102
  events: {
68
- onMouseEnter,
69
- onMouseLeave,
70
- onMouseDown,
71
- onMouseUp,
72
- onFocus,
73
- onBlur,
103
+ onMouseEnter: handleOnMouseEnter,
104
+ onMouseLeave: handleOnMouseLeave,
105
+ onMouseDown: handleOnMouseDown,
106
+ onMouseUp: handleOnMouseUp,
107
+ onFocus: handleOnFocus,
108
+ onBlur: handleOnBlur,
74
109
  },
75
110
  };
76
111
  };
77
112
 
78
- /* eslint-disable import/prefer-default-export */
79
- const chainOptions = (opts, defaultOpts = []) => {
80
- const result = [...defaultOpts];
81
- if (typeof opts === 'function')
82
- result.push(opts);
83
- else if (typeof opts === 'object')
84
- result.push(() => opts);
85
- return result;
86
- };
87
- const removeNullableValues = (obj) => Object.entries(obj)
88
- .filter(([, v]) => v != null && v !== false)
89
- .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {});
90
-
91
- const isValidKey = (value) => value !== undefined && value !== null && value !== false;
92
- const isMultiKey = (value) => {
93
- if (typeof value === 'object')
94
- return [true, core.get(value, 'propName')];
95
- return [false, value];
96
- };
97
- const calculateDimensionsMap = ({ themes, useBooleans, }) => {
98
- const result = { keysMap: {}, keywords: {} };
99
- if (core.isEmpty(themes))
100
- return result;
101
- return Object.entries(themes).reduce((accumulator, [key, value]) => {
102
- const { keysMap, keywords } = accumulator;
103
- keywords[key] = true;
104
- Object.entries(value).forEach(([itemKey, itemValue]) => {
105
- if (!isValidKey(itemValue))
106
- return;
107
- if (useBooleans) {
108
- keywords[itemKey] = true;
109
- }
110
- core.set(keysMap, [key, itemKey], true);
111
- });
112
- return accumulator;
113
- }, result);
114
- };
115
- const getKeys = (obj) => Object.keys(obj);
116
- const getValues = (obj) => Object.values(obj);
117
- const getDimensionsValues = (obj) => getValues(obj).map((item) => {
118
- if (typeof item === 'object') {
119
- return item.propName;
120
- }
121
- return item;
122
- });
123
- const getMultipleDimensions = (obj) => getValues(obj).reduce((accumulator, value) => {
124
- if (typeof value === 'object') {
125
- // eslint-disable-next-line no-param-reassign
126
- if (value.multi === true)
127
- accumulator[value.propName] = true;
128
- }
129
- return accumulator;
130
- }, {});
131
-
132
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
133
- // --------------------------------------------------------
134
- // theme mode callback
135
- // --------------------------------------------------------
136
- const themeModeCb = (...params) => (mode) => {
137
- if (!mode || mode === 'light')
138
- return params[0];
139
- return params[1];
140
- };
141
- const calculateDimensionThemes = (theme, options, cb) => {
142
- const result = {};
143
- if (core.isEmpty(options.dimensions))
144
- return result;
145
- return Object.entries(options.dimensions).reduce((accumulator, [key, value]) => {
146
- const [, dimension] = isMultiKey(value);
147
- const helper = options[key];
148
- if (Array.isArray(helper) && helper.length > 0) {
149
- const finalDimensionThemes = calculateChainOptions$1(helper, [
150
- theme,
151
- cb,
152
- core.config.css,
153
- ]);
154
- // eslint-disable-next-line no-param-reassign
155
- accumulator[dimension] = removeNullableValues(finalDimensionThemes);
156
- }
157
- return accumulator;
158
- }, result);
159
- };
160
- const calculateChainOptions$1 = (options, args) => {
161
- const result = {};
162
- if (core.isEmpty(options))
163
- return result;
164
- return options.reduce((acc, item) => core.merge(acc, item(...args)), result);
165
- // using this does not allow overriding themes properly
166
- // return removeAllEmptyValues(helper)
167
- };
168
- const calculateTheme = ({ rocketstate, themes, baseTheme, }) => {
169
- // generate final theme which will be passed to styled component
170
- let finalTheme = { ...baseTheme };
171
- Object.entries(rocketstate).forEach(([key, value]) => {
172
- const keyTheme = themes[key];
173
- if (Array.isArray(value)) {
174
- value.forEach((item) => {
175
- finalTheme = core.merge({}, finalTheme, keyTheme[item]);
176
- });
177
- }
178
- else {
179
- finalTheme = core.merge({}, finalTheme, keyTheme[value]);
180
- }
181
- });
182
- return finalTheme;
183
- };
184
- const calculateThemeMode = (themes, variant) => {
185
- const callback = themeModeCb().toString();
186
- const isModeCallback = (value) => value.toString() === callback;
187
- const result = {};
188
- Object.entries(themes).forEach(([key, value]) => {
189
- if (typeof value === 'object' && value !== null) {
190
- result[key] = calculateThemeMode(value, variant);
191
- }
192
- else if (typeof value === 'function' && isModeCallback(value)) {
193
- result[key] = value(variant);
194
- }
195
- else {
196
- result[key] = value;
197
- }
198
- });
199
- return result;
200
- };
201
-
202
- const useTheme = ({ theme, options, cb }) => {
203
- const themes = calculateDimensionThemes(theme, options, cb);
204
- const { keysMap, keywords } = calculateDimensionsMap({
205
- themes,
206
- useBooleans: options.useBooleans,
207
- });
208
- // eslint-disable-next-line no-underscore-dangle
209
- const __ROCKETSTYLE__ = {
210
- dimensions: keysMap,
211
- reservedPropNames: keywords,
212
- baseTheme: calculateChainOptions$1(options.theme, [theme, cb, core.config.css]),
213
- themes,
214
- };
215
- return __ROCKETSTYLE__;
113
+ const useRocketstyleRef = ({ $rocketstyleRef, ref }) => {
114
+ const internalRef = React.useRef(null);
115
+ React.useImperativeHandle($rocketstyleRef, () => internalRef.current);
116
+ React.useImperativeHandle(ref, () => internalRef.current);
117
+ return internalRef;
216
118
  };
217
119
 
218
- const PSEUDO_KEYS = ['hover', 'active', 'focus', 'pressed'];
219
- const THEME_MODES = {
220
- light: true,
221
- dark: true,
222
- };
223
- const THEME_MODES_INVERSED = {
224
- dark: 'light',
225
- light: 'dark',
226
- };
227
- const CONFIG_KEYS = [
228
- 'provider',
229
- 'consumer',
230
- 'DEBUG',
231
- 'name',
232
- 'component',
233
- 'inversed',
234
- 'passProps',
235
- 'styled',
236
- ];
237
- const STYLING_KEYS = ['theme', 'attrs', 'styles'];
238
- const STATIC_KEYS = [...STYLING_KEYS, 'compose'];
239
- const ALL_RESERVED_KEYS = [
240
- ...Object.keys(THEME_MODES),
241
- ...CONFIG_KEYS,
242
- ...STATIC_KEYS,
243
- ];
244
-
245
- const useThemeOptions = ({ inversed }) => {
246
- const { theme, mode: ctxMode, isDark: ctxDark } = React.useContext(core.context);
120
+ const useThemeAttrs = ({ inversed }) => {
121
+ const { theme, mode: ctxMode = 'light', isDark: ctxDark, } = React.useContext(core.context) || {};
247
122
  const mode = inversed ? THEME_MODES_INVERSED[ctxMode] : ctxMode;
248
123
  const isDark = inversed ? !ctxDark : ctxDark;
249
124
  const isLight = !isDark;
250
125
  return { theme, mode, isDark, isLight };
251
126
  };
252
127
 
253
- const pickStyledProps = (props, keywords) => {
254
- const result = {};
255
- Object.entries(props).forEach(([key, value]) => {
256
- if (keywords[key])
257
- result[key] = value;
128
+ const RocketStyleProviderComponent = (WrappedComponent) => React.forwardRef(({ onMouseEnter, onMouseLeave, onMouseUp, onMouseDown, onFocus, onBlur, $rocketstate, ...props }, ref) => {
129
+ // pseudo hook to detect states hover / pressed / focus
130
+ const pseudo = usePseudoState({
131
+ onMouseEnter,
132
+ onMouseLeave,
133
+ onMouseUp,
134
+ onMouseDown,
135
+ onFocus,
136
+ onBlur,
258
137
  });
259
- return result;
260
- };
138
+ const updatedState = React.useMemo(() => ({
139
+ ...$rocketstate,
140
+ pseudo: { ...$rocketstate.pseudo, ...pseudo.state },
141
+ }), [$rocketstate, pseudo]);
142
+ return (React__default["default"].createElement(LocalProvider, { value: updatedState },
143
+ React__default["default"].createElement(WrappedComponent, { ...props, ...pseudo.events, ref: ref, "$rocketstate": updatedState })));
144
+ });
145
+
146
+ class ThemeManager {
147
+ baseTheme = new WeakMap();
148
+ dimensionsThemes = new WeakMap();
149
+ modeBaseTheme = { light: new WeakMap(), dark: new WeakMap() };
150
+ modeDimensionTheme = { light: new WeakMap(), dark: new WeakMap() };
151
+ }
152
+
153
+ /* eslint-disable no-param-reassign */
154
+ const pickStyledAttrs = (props, keywords) => Object.keys(props).reduce((acc, key) => {
155
+ if (keywords[key])
156
+ acc[key] = props[key];
157
+ return acc;
158
+ }, {});
261
159
  const calculateChainOptions = (options) => (args) => {
262
160
  const result = {};
263
161
  if (core.isEmpty(options))
264
162
  return result;
265
163
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
266
164
  // @ts-ignore
267
- return options.reduce((acc, item) => Object.assign(acc, item(...args)), result);
165
+ return options.reduce((acc, item) => Object.assign(acc, item(...args)), {});
268
166
  };
269
167
  const calculateStylingAttrs = ({ useBooleans, multiKeys }) => ({ props, dimensions }) => {
270
168
  const result = {};
@@ -325,14 +223,14 @@ const rocketStyleHOC = ({ inversed, attrs }) => {
325
223
  // --------------------------------------------------
326
224
  const _calculateChainOptions = calculateChainOptions(attrs);
327
225
  const Enhanced = (WrappedComponent) => React.forwardRef((props, ref) => {
328
- const { theme, mode, isDark, isLight } = useThemeOptions({
226
+ const { theme, mode, isDark, isLight } = useThemeAttrs({
329
227
  inversed,
330
228
  });
331
229
  const calculatedAttrs = _calculateChainOptions([
332
230
  props,
333
231
  theme,
334
232
  {
335
- renderContent: core.renderContent,
233
+ render: core.render,
336
234
  mode,
337
235
  isDark,
338
236
  isLight,
@@ -343,61 +241,178 @@ const rocketStyleHOC = ({ inversed, attrs }) => {
343
241
  return Enhanced;
344
242
  };
345
243
 
346
- var localContext = React.createContext({});
347
-
348
- const RocketStyleProviderComponent = (WrappedComponent) => React.forwardRef(({ onMouseEnter, onMouseLeave, onMouseUp, onMouseDown, onFocus, onBlur, $rocketstate, ...props }, ref) => {
349
- // pseudo hook to detect states hover / pressed / focus
350
- const pseudo = usePseudoState({
351
- onMouseEnter,
352
- onMouseLeave,
353
- onMouseUp,
354
- onMouseDown,
355
- onFocus,
356
- onBlur,
244
+ const createStaticsChainingEnhancers = ({ context, dimensionKeys, func, options, }) => {
245
+ const keys = [...dimensionKeys, ...STATIC_KEYS];
246
+ keys.forEach((item) => {
247
+ // eslint-disable-next-line no-param-reassign
248
+ context[item] = (props) => func({ [item]: props }, options);
357
249
  });
358
- const updatedState = React.useMemo(() => ({
359
- ...$rocketstate,
360
- pseudo: { ...$rocketstate.pseudo, ...pseudo.state },
361
- }), [$rocketstate, pseudo]);
362
- return (React__default["default"].createElement(localContext.Provider, { value: updatedState },
363
- React__default["default"].createElement(WrappedComponent, { ...props, ...pseudo.events, ref: ref, "$rocketstate": updatedState })));
364
- });
365
-
366
- const calculateStyles = (styles, css) => {
367
- if (!styles)
368
- return [];
369
- return styles.map((item) => item(css));
250
+ };
251
+ const createStaticsEnhancers = ({ context, options, }) => {
252
+ if (!core.isEmpty(options)) {
253
+ Object.assign(context, options);
254
+ }
370
255
  };
371
256
 
372
- /* eslint-disable no-underscore-dangle */
373
- const orOptions = (keys, opts, defaultOpts) => keys.reduce((acc, item) => ({ ...acc, [item]: opts[item] || defaultOpts[item] }), {});
374
- const chainReservedOptions = (keys, opts, defaultOpts) => keys.reduce((acc, item) => ({
375
- ...acc,
376
- [item]: chainOptions(opts[item], defaultOpts[item]),
377
- }), {});
257
+ /* eslint-disable import/prefer-default-export */
258
+ const removeNullableValues = (obj) => Object.entries(obj)
259
+ .filter(([, v]) => v != null && v !== false)
260
+ .reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {});
378
261
  // --------------------------------------------------------
379
- // helpers for create statics chainin methods on component
262
+ // Remove All Empty Values
380
263
  // --------------------------------------------------------
381
- const createStaticsChainingEnhancers = ({ context, dimensionKeys, func, opts, }) => {
382
- dimensionKeys.forEach((item) => {
383
- // eslint-disable-next-line no-param-reassign
384
- context[item] = (props) => func({ [item]: props }, opts);
385
- });
264
+ // type RemoveAllEmptyValues = (obj: Record<string, any>) => Record<string, any>
265
+ // export const removeAllEmptyValues: RemoveAllEmptyValues = (obj) =>
266
+ // Object.entries(obj)
267
+ // .filter(([, v]) => v != null)
268
+ // .reduce(
269
+ // (acc, [k, v]) => ({
270
+ // ...acc,
271
+ // [k]: typeof v === 'object' ? removeAllEmptyValues(v) : v,
272
+ // }),
273
+ // {}
274
+ // )
275
+
276
+ const isValidKey = (value) => value !== undefined && value !== null && value !== false;
277
+ const isMultiKey = (value) => {
278
+ if (typeof value === 'object' && value !== null)
279
+ return [true, core.get(value, 'propName')];
280
+ return [false, value];
281
+ };
282
+ const getDimensionsMap = ({ themes, useBooleans }) => {
283
+ const result = {
284
+ keysMap: {},
285
+ keywords: {},
286
+ };
287
+ if (core.isEmpty(themes))
288
+ return result;
289
+ return Object.entries(themes).reduce((accumulator, [key, value]) => {
290
+ const { keysMap, keywords } = accumulator;
291
+ keywords[key] = true;
292
+ Object.entries(value).forEach(([itemKey, itemValue]) => {
293
+ if (!isValidKey(itemValue))
294
+ return;
295
+ if (useBooleans) {
296
+ keywords[itemKey] = true;
297
+ }
298
+ core.set(keysMap, [key, itemKey], true);
299
+ });
300
+ return accumulator;
301
+ }, result);
386
302
  };
303
+ const getKeys = (obj) => Object.keys(obj);
304
+ const getValues = (obj) => Object.values(obj);
305
+ const getDimensionsValues = (obj) => getValues(obj).map((item) => {
306
+ if (typeof item === 'object') {
307
+ return item.propName;
308
+ }
309
+ return item;
310
+ });
311
+ const getMultipleDimensions = (obj) => getValues(obj).reduce((accumulator, value) => {
312
+ if (typeof value === 'object') {
313
+ // eslint-disable-next-line no-param-reassign
314
+ if (value.multi === true)
315
+ accumulator[value.propName] = true;
316
+ }
317
+ return accumulator;
318
+ }, {});
319
+
320
+ /* eslint-disable no-param-reassign */
387
321
  // --------------------------------------------------------
388
- // helpers for create statics on component
322
+ // Theme Mode Callback
389
323
  // --------------------------------------------------------
390
- const createStaticsEnhancers = ({ context, opts }) => {
391
- if (!core.isEmpty(opts)) {
392
- Object.assign(context, opts);
324
+ const themeModeCallback = (light, dark) => (mode) => {
325
+ if (!mode || mode === 'light')
326
+ return light;
327
+ return dark;
328
+ };
329
+ themeModeCallback.isMode = true;
330
+ const isModeCallback = (value) => typeof value === 'function' && value.isMode;
331
+ const getThemeFromChain = (options, theme) => {
332
+ const result = {};
333
+ if (!options || core.isEmpty(options))
334
+ return result;
335
+ return options.reduce((acc, item) => core.merge(acc, item(theme, themeModeCallback, core.config.css)), result);
336
+ };
337
+ const getDimensionThemes = (theme, options) => {
338
+ const result = {};
339
+ if (core.isEmpty(options.dimensions))
340
+ return result;
341
+ return Object.entries(options.dimensions).reduce((acc, [key, value]) => {
342
+ const [, dimension] = isMultiKey(value);
343
+ const helper = options[key];
344
+ if (Array.isArray(helper) && helper.length > 0) {
345
+ const finalDimensionThemes = getThemeFromChain(helper, theme);
346
+ // eslint-disable-next-line no-param-reassign
347
+ acc[dimension] = removeNullableValues(finalDimensionThemes);
348
+ }
349
+ return acc;
350
+ }, result);
351
+ };
352
+ const getTheme$1 = ({ rocketstate, themes, baseTheme }) => {
353
+ // generate final theme which will be passed to styled component
354
+ let finalTheme = { ...baseTheme };
355
+ Object.entries(rocketstate).forEach(([key, value]) => {
356
+ const keyTheme = themes[key];
357
+ if (Array.isArray(value)) {
358
+ value.forEach((item) => {
359
+ finalTheme = core.merge({}, finalTheme, keyTheme[item]);
360
+ });
361
+ }
362
+ else {
363
+ finalTheme = core.merge({}, finalTheme, keyTheme[value]);
364
+ }
365
+ });
366
+ return finalTheme;
367
+ };
368
+ const getThemeByMode = (object, mode) => Object.keys(object).reduce((acc, key) => {
369
+ const value = object[key];
370
+ if (typeof value === 'object' && value !== null) {
371
+ acc[key] = getThemeByMode(value, mode);
372
+ }
373
+ else if (isModeCallback(value)) {
374
+ acc[key] = value(mode);
375
+ }
376
+ else {
377
+ acc[key] = value;
393
378
  }
379
+ return acc;
380
+ }, {});
381
+
382
+ const chainOptions = (opts, defaultOpts = []) => {
383
+ const result = [...defaultOpts];
384
+ if (typeof opts === 'function')
385
+ result.push(opts);
386
+ else if (typeof opts === 'object')
387
+ result.push(() => opts);
388
+ return result;
394
389
  };
395
- const cloneAndEnhance = (opts, defaultOpts) => styleComponent({
390
+ const chainOrOptions = (keys, opts, defaultOpts) => keys.reduce((acc, item) => ({ ...acc, [item]: opts[item] || defaultOpts[item] }), {});
391
+ const chainReservedKeyOptions = (keys, opts, defaultOpts) => keys.reduce((acc, item) => ({
392
+ ...acc,
393
+ [item]: chainOptions(opts[item], defaultOpts[item]),
394
+ }), {});
395
+
396
+ const calculateHocsFuncs = (options = {}) => Object.values(options)
397
+ .filter((item) => typeof item === 'function')
398
+ .reverse();
399
+
400
+ /* eslint-disable import/prefer-default-export */
401
+ const calculateStyles = (styles) => {
402
+ if (!styles)
403
+ return [];
404
+ return styles.map((item) => item(core.config.css));
405
+ };
406
+
407
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
408
+ const cloneAndEnhance = (opts, defaultOpts) =>
409
+ // @ts-ignore
410
+ rocketComponent({
396
411
  ...defaultOpts,
397
412
  statics: { ...defaultOpts.statics, ...opts.statics },
398
413
  compose: { ...defaultOpts.compose, ...opts.compose },
399
- ...orOptions(CONFIG_KEYS, opts, defaultOpts),
400
- ...chainReservedOptions([...defaultOpts.dimensionKeys, ...STYLING_KEYS], opts, defaultOpts),
414
+ ...chainOrOptions(CONFIG_KEYS, opts, defaultOpts),
415
+ ...chainReservedKeyOptions([...defaultOpts.dimensionKeys, ...STYLING_KEYS], opts, defaultOpts),
401
416
  });
402
417
  // --------------------------------------------------------
403
418
  // styleComponent
@@ -406,7 +421,8 @@ const cloneAndEnhance = (opts, defaultOpts) => styleComponent({
406
421
  // assigned, so it can be even rendered as a valid component
407
422
  // or styles can be extended via its statics
408
423
  // --------------------------------------------------------
409
- const styleComponent = (options) => {
424
+ // @ts-ignore
425
+ const rocketComponent = (options) => {
410
426
  const { component, styles } = options;
411
427
  const { styled } = core.config;
412
428
  // const _calculateChainOptions = calculateChainOptions(options.attrs)
@@ -416,112 +432,149 @@ const styleComponent = (options) => {
416
432
  });
417
433
  const componentName = options.name || options.component.displayName || options.component.name;
418
434
  // create styled component with all options.styles if available
419
- const STYLED_COMPONENT = component.IS_ROCKETSTYLE || options.styled === false
435
+ const STYLED_COMPONENT = component.IS_ROCKETSTYLE || options.styled !== true
420
436
  ? component
421
437
  : styled(component) `
422
- ${calculateStyles(styles, core.config.css)};
438
+ ${calculateStyles(styles)};
423
439
  `;
424
440
  // --------------------------------------------------------
425
- // final component to be rendered
441
+ // COMPONENT - Final component to be rendered
426
442
  // --------------------------------------------------------
427
443
  const RenderComponent = options.provider
428
444
  ? RocketStyleProviderComponent(STYLED_COMPONENT)
429
445
  : STYLED_COMPONENT;
430
446
  // --------------------------------------------------------
431
- // hocs
447
+ // THEME - Cahed & Calculated theme(s)
432
448
  // --------------------------------------------------------
433
- const calculateHocsFuncs = Object.values(options.compose || {})
434
- .filter((item) => typeof item === 'function')
435
- .reverse();
436
- const hocsFuncs = [rocketStyleHOC(options), ...calculateHocsFuncs];
449
+ const ThemeManager$1 = new ThemeManager();
450
+ // --------------------------------------------------------
451
+ // COMPOSE - high-order components
452
+ // --------------------------------------------------------
453
+ const hocsFuncs = [
454
+ rocketStyleHOC(options),
455
+ ...calculateHocsFuncs(options.compose),
456
+ ];
437
457
  // --------------------------------------------------------
438
458
  // ENHANCED COMPONENT (returned component)
439
459
  // --------------------------------------------------------
440
460
  // .attrs() chaining option is calculated in HOC and passed as props already
441
- const EnhancedComponent = React.forwardRef(({ $rocketstyleRef, // it's forwarded from HOC which is always on top of hocs
461
+ const EnhancedComponent = React.forwardRef(({ $rocketstyleRef, // it's forwarded from HOC which is always on top of all hocs
442
462
  ...props }, ref) => {
443
463
  // --------------------------------------------------
444
464
  // handle refs
445
465
  // (1) one is passed from inner HOC - $rocketstyleRef
446
466
  // (2) second one is used to be used directly (e.g. inside hocs)
447
467
  // --------------------------------------------------
448
- const internalRef = React.useRef(null);
449
- if ($rocketstyleRef)
450
- React.useImperativeHandle($rocketstyleRef, () => internalRef.current, [
451
- $rocketstyleRef,
452
- ]);
453
- if (ref)
454
- React.useImperativeHandle(ref, () => internalRef.current, [ref]);
468
+ const internalRef = useRocketstyleRef({ $rocketstyleRef, ref });
455
469
  // --------------------------------------------------
456
470
  // hover - focus - pressed state passed via context from parent component
457
471
  // --------------------------------------------------
458
- const rocketstyleCtx = options.consumer ? React.useContext(localContext) : {};
472
+ const localCtx = useLocalContext(options.consumer);
459
473
  // --------------------------------------------------
460
474
  // general theme and theme mode dark / light passed in context
461
475
  // --------------------------------------------------
462
- const { theme, mode } = useThemeOptions(options);
476
+ const { theme, mode } = useThemeAttrs(options);
463
477
  // --------------------------------------------------
464
- // calculate themes for all possible styling dimensions
465
- // .theme(...) + defined dimensions like .states(...), .sizes(...)
478
+ // calculate themes for all defined styling dimensions
479
+ // .theme(...) + defined dimensions like .states(...), .sizes(...), etc.
466
480
  // --------------------------------------------------
467
- const __ROCKETSTYLE__ = React.useMemo(() => useTheme({
468
- theme,
469
- options,
470
- cb: themeModeCb,
471
- }),
472
- // recalculate this only when theme changes
481
+ // --------------------------------------------------
482
+ // BASE / DEFAULT THEME Object
483
+ // --------------------------------------------------
484
+ const baseTheme = React.useMemo(() => {
485
+ const helper = ThemeManager$1.baseTheme;
486
+ if (!helper.has(theme)) {
487
+ helper.set(theme, getThemeFromChain(options.theme, theme));
488
+ }
489
+ return helper.get(theme);
490
+ },
491
+ // recalculate this only when theme mode changes dark / light
492
+ [theme]);
493
+ // --------------------------------------------------
494
+ // DIMENSION(S) THEMES Object
495
+ // --------------------------------------------------
496
+ const themes = React.useMemo(() => {
497
+ const helper = ThemeManager$1.dimensionsThemes;
498
+ if (!helper.has(theme)) {
499
+ helper.set(theme, getDimensionThemes(theme, options));
500
+ }
501
+ return helper.get(theme);
502
+ },
503
+ // recalculate this only when theme object changes
473
504
  [theme]);
474
- const { reservedPropNames, themes: rocketThemes, dimensions, baseTheme: rocketBaseTheme, } = __ROCKETSTYLE__;
475
- const { baseTheme, themes } = React.useMemo(() => calculateThemeMode({ themes: rocketThemes, baseTheme: rocketBaseTheme }, mode),
505
+ // --------------------------------------------------
506
+ // BASE / DEFAULT MODE THEME Object
507
+ // --------------------------------------------------
508
+ const currentModeBaseTheme = React.useMemo(() => {
509
+ const helper = ThemeManager$1.modeBaseTheme[mode];
510
+ if (!helper.has(baseTheme)) {
511
+ helper.set(baseTheme, getThemeByMode(baseTheme, mode));
512
+ }
513
+ return helper.get(baseTheme);
514
+ },
515
+ // recalculate this only when theme mode changes dark / light
516
+ [mode, baseTheme]);
517
+ // --------------------------------------------------
518
+ // DIMENSION(S) MODE THEMES Object
519
+ // --------------------------------------------------
520
+ const currentModeThemes = React.useMemo(() => {
521
+ const helper = ThemeManager$1.modeDimensionTheme[mode];
522
+ if (!helper.has(themes)) {
523
+ helper.set(themes, getThemeByMode(themes, mode));
524
+ }
525
+ return helper.get(themes);
526
+ },
476
527
  // recalculate this only when theme mode changes dark / light
477
- [mode]);
528
+ [mode, themes]);
478
529
  // --------------------------------------------------
479
530
  // calculate reserved Keys defined in dimensions as styling keys
480
531
  // there is no need to calculate this each time - keys are based on
481
532
  // dimensions definitions
482
533
  // --------------------------------------------------
483
- const RESERVED_STYLING_PROPS_KEYS = React.useMemo(() => Object.keys(reservedPropNames), []);
534
+ const { keysMap: dimensions, keywords: reservedPropNames } = React.useMemo(() => getDimensionsMap({
535
+ themes,
536
+ useBooleans: options.useBooleans,
537
+ }), [themes]);
538
+ const RESERVED_STYLING_PROPS_KEYS = React.useMemo(() => Object.keys(reservedPropNames), [reservedPropNames]);
484
539
  // --------------------------------------------------
485
540
  // get final props which are (latest has the highest priority):
486
541
  // (1) merged styling from context,
487
542
  // (2) `attrs` chaining method, and from
488
543
  // (3) passing them directly to component
489
544
  // --------------------------------------------------
490
- const { pseudo = {}, ...mergeProps } = {
491
- ...(options.consumer
492
- ? options.consumer((callback) => callback(rocketstyleCtx))
493
- : {}),
545
+ const { pseudo, ...mergeProps } = {
546
+ ...localCtx,
494
547
  ...props,
495
548
  };
496
549
  // --------------------------------------------------
550
+ // pseudo rocket state
551
+ // calculate final component pseudo state including pseudo state
552
+ // from props and override by pseudo props from context
553
+ // --------------------------------------------------
554
+ const pseudoRocketstate = {
555
+ ...pseudo,
556
+ ...core.pick(props, PSEUDO_KEYS),
557
+ };
558
+ // --------------------------------------------------
497
559
  // rocketstate
498
560
  // calculate final component state including pseudo state
499
561
  // passed as $rocketstate prop
500
562
  // --------------------------------------------------
501
563
  const rocketstate = _calculateStylingAttrs({
502
- props: pickStyledProps(mergeProps, reservedPropNames),
564
+ props: pickStyledAttrs(mergeProps, reservedPropNames),
503
565
  dimensions,
504
566
  });
505
- // --------------------------------------------------
506
- // pseudo state
507
- // calculate final component pseudo state including pseudo state
508
- // from props and override by pseudo props from context
509
- // --------------------------------------------------
510
- const finalPseudo = {
511
- ...core.pick(props, PSEUDO_KEYS),
512
- ...pseudo,
513
- };
514
- const finalRocketstate = { ...rocketstate, pseudo: finalPseudo };
567
+ const finalRocketstate = { ...rocketstate, pseudo: pseudoRocketstate };
515
568
  // --------------------------------------------------
516
569
  // rocketstyle
517
570
  // calculated (based on styling props) final theme which will be passed
518
571
  // to our styled component
519
572
  // passed as $rocketstyle prop
520
573
  // --------------------------------------------------
521
- const rocketstyle = calculateTheme({
574
+ const rocketstyle = getTheme$1({
522
575
  rocketstate,
523
- themes,
524
- baseTheme,
576
+ themes: currentModeThemes,
577
+ baseTheme: currentModeBaseTheme,
525
578
  });
526
579
  // --------------------------------------------------
527
580
  // final props
@@ -559,9 +612,9 @@ const styleComponent = (options) => {
559
612
  // ------------------------------------------------------
560
613
  createStaticsChainingEnhancers({
561
614
  context: RocketComponent,
562
- dimensionKeys: [...options.dimensionKeys, ...STATIC_KEYS],
615
+ dimensionKeys: options.dimensionKeys,
563
616
  func: cloneAndEnhance,
564
- opts: options,
617
+ options,
565
618
  });
566
619
  // ------------------------------------------------------
567
620
  RocketComponent.IS_ROCKETSTYLE = true;
@@ -573,34 +626,37 @@ const styleComponent = (options) => {
573
626
  // ------------------------------------------------------
574
627
  createStaticsEnhancers({
575
628
  context: RocketComponent.is,
576
- opts: options.statics,
629
+ options: options.statics,
577
630
  });
631
+ // @ts-ignore
578
632
  RocketComponent.config = (opts = {}) => {
579
633
  const result = core.pick(opts, CONFIG_KEYS);
580
634
  return cloneAndEnhance(result, options);
581
635
  };
582
- RocketComponent.statics = (opts = {}) => cloneAndEnhance({ statics: opts }, options);
636
+ RocketComponent.statics = (opts) => cloneAndEnhance({ statics: opts }, options);
583
637
  RocketComponent.getStaticDimensions = (theme) => {
584
- const themes = useTheme({ theme, options, cb: themeModeCb });
638
+ const themes = getDimensionThemes(theme, options);
639
+ const { keysMap, keywords } = getDimensionsMap({
640
+ themes,
641
+ useBooleans: options.useBooleans,
642
+ });
585
643
  return {
586
- dimensions: themes.dimensions,
644
+ dimensions: keysMap,
645
+ keywords,
587
646
  useBooleans: options.useBooleans,
588
647
  multiKeys: options.multiKeys,
589
648
  };
590
649
  };
591
- RocketComponent.getDefaultAttrs = (props, theme, mode) => {
592
- const result = calculateChainOptions(options.attrs)([
593
- props,
594
- theme,
595
- {
596
- renderContent: core.renderContent,
597
- mode,
598
- isDark: mode === 'light',
599
- isLight: mode === 'dark',
600
- },
601
- ]);
602
- return result;
603
- };
650
+ RocketComponent.getDefaultAttrs = (props, theme, mode) => calculateChainOptions(options.attrs)([
651
+ props,
652
+ theme,
653
+ {
654
+ render: core.render,
655
+ mode,
656
+ isDark: mode === 'light',
657
+ isLight: mode === 'dark',
658
+ },
659
+ ]);
604
660
  return RocketComponent;
605
661
  };
606
662
 
@@ -614,8 +670,8 @@ const DEFAULT_DIMENSIONS = {
614
670
  },
615
671
  };
616
672
 
617
- /* eslint-disable @typescript-eslint/ban-types */
618
- const rocketstyle$1 = () => ({ dimensions = DEFAULT_DIMENSIONS, useBooleans = true } = {}) => ({ name, component }) => {
673
+ // @ts-nocheck
674
+ const rocketstyle$1 = ({ dimensions = DEFAULT_DIMENSIONS, useBooleans = true } = {}) => ({ name, component }) => {
619
675
  // --------------------------------------------------------
620
676
  // handle ERRORS in development mode
621
677
  // --------------------------------------------------------
@@ -642,7 +698,7 @@ const rocketstyle$1 = () => ({ dimensions = DEFAULT_DIMENSIONS, useBooleans = tr
642
698
  throw Error(JSON.stringify(errors));
643
699
  }
644
700
  }
645
- return styleComponent({
701
+ return rocketComponent({
646
702
  name,
647
703
  component,
648
704
  useBooleans,
@@ -650,6 +706,7 @@ const rocketstyle$1 = () => ({ dimensions = DEFAULT_DIMENSIONS, useBooleans = tr
650
706
  dimensionKeys: getKeys(dimensions),
651
707
  dimensionValues: getDimensionsValues(dimensions),
652
708
  multiKeys: getMultipleDimensions(dimensions),
709
+ styled: true,
653
710
  });
654
711
  };
655
712
 
@@ -657,8 +714,7 @@ const isRocketComponent = (component) => {
657
714
  if (component &&
658
715
  typeof component === 'object' &&
659
716
  component !== null &&
660
- // eslint-disable-next-line dot-notation
661
- component['IS_ROCKETSTYLE'] === true) {
717
+ Object.prototype.hasOwnProperty.call(component, 'IS_ROCKETSTYLE')) {
662
718
  return true;
663
719
  }
664
720
  return false;
@@ -671,7 +727,7 @@ const Wrapper = core.config.styled.div `
671
727
  const component$2 = () => React__default["default"].createElement(Wrapper, null, "Nothing here");
672
728
  component$2.displayName = '@vitus-labs/rocketstories/Empty';
673
729
 
674
- var element$1 = rocketstyle$1()()({
730
+ var element$1 = rocketstyle$1()({
675
731
  component: elements.Element,
676
732
  name: 'element',
677
733
  })
@@ -1358,7 +1414,7 @@ const disableDimensionControls = (dimensions, dimensionName) => {
1358
1414
  const context = React.createContext({});
1359
1415
  const useContext = () => React.useContext(context);
1360
1416
  const ContextProvider = context.Provider;
1361
- const Provider = ({ children, ...props }) => (React__default["default"].createElement(ContextProvider, { value: props }, children));
1417
+ const Provider = ({ children, ...props }) => React__default["default"].createElement(ContextProvider, { value: props }, children);
1362
1418
 
1363
1419
  const component$1 = ({ title, ...props }) => {
1364
1420
  const { component } = useContext();
@@ -1661,7 +1717,7 @@ const createRocketStories = (options) => {
1661
1717
  };
1662
1718
  };
1663
1719
 
1664
- const init = ({ decorators = [], storyOptions = {} }) => (component) => rocketstories(component, { decorators, storyOptions });
1720
+ const init = ({ decorators = [], storyOptions = {}, ...rest }) => (component) => rocketstories(component, { decorators, storyOptions, ...rest });
1665
1721
  //@ts-ignore
1666
1722
  const rocketstories = (component, options = {}) => {
1667
1723
  const { decorators = [], storyOptions = {} } = options;