@flowerforce/flower-core 3.0.0 → 3.0.1-beta.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.
package/dist/index.cjs.js CHANGED
@@ -1,15 +1,32 @@
1
1
  'use strict';
2
2
 
3
- var lodash = require('lodash');
3
+ var _get = require('lodash/get');
4
+ var isBuffer = require('lodash/isBuffer');
4
5
  var tinyEmitter = require('tiny-emitter');
6
+ var _set = require('lodash/set');
7
+ var _unset = require('lodash/unset');
8
+ var _last = require('lodash/last');
9
+ var _slice = require('lodash/slice');
10
+ var _cloneDeep = require('lodash/cloneDeep');
11
+ var lastIndexOf = require('lodash/lastIndexOf');
12
+ var find = require('lodash/find');
13
+ var keyBy = require('lodash/keyBy');
14
+ var has = require('lodash/has');
15
+ var omit = require('lodash/omit');
16
+ var isEmpty = require('lodash/isEmpty');
17
+ var isPlainObject = require('lodash/isPlainObject');
18
+ var mapKeys = require('lodash/mapKeys');
19
+ var mapValues = require('lodash/mapValues');
20
+ var _trimStart = require('lodash/trimStart');
21
+ var _intersection = require('lodash/intersection');
5
22
 
6
23
  const keyIdentity = key => key;
7
24
  const flatten = (target, opts) => {
8
25
  const options = opts ?? {};
9
- const safe = lodash.get(options, 'safe', false);
10
- const maxDepth = lodash.get(options, 'maxDepth', 0);
11
- const delimiter = lodash.get(options, 'delimiter', '.');
12
- const transformKey = lodash.get(options, 'transformKey', keyIdentity);
26
+ const safe = _get(options, 'safe', false);
27
+ const maxDepth = _get(options, 'maxDepth', 0);
28
+ const delimiter = _get(options, 'delimiter', '.');
29
+ const transformKey = _get(options, 'transformKey', keyIdentity);
13
30
  const output = {};
14
31
  const step = (object, prev, currentDepth) => {
15
32
  const depth = currentDepth || 1;
@@ -17,7 +34,7 @@ const flatten = (target, opts) => {
17
34
  const value = object[key];
18
35
  const isarray = safe && Array.isArray(value);
19
36
  const type = Object.prototype.toString.call(value);
20
- const isbuffer = lodash.isBuffer(value);
37
+ const isbuffer = isBuffer(value);
21
38
  const isobject = type === '[object Object]' || type === '[object Array]';
22
39
  const newKey = prev ? prev + delimiter + transformKey(key) : transformKey(key);
23
40
  if (!isarray && !isbuffer && isobject && Object.keys(value).length && (!maxDepth || depth < maxDepth)) {
@@ -31,12 +48,12 @@ const flatten = (target, opts) => {
31
48
  };
32
49
  const unflatten = (target, opts) => {
33
50
  const options = opts ?? {};
34
- const object = lodash.get(options, 'object', false);
35
- const overwrite = lodash.get(options, 'overwrite', false);
36
- const delimiter = lodash.get(options, 'delimiter', '.');
37
- const transformKey = lodash.get(options, 'transformKey', keyIdentity);
51
+ const object = _get(options, 'object', false);
52
+ const overwrite = _get(options, 'overwrite', false);
53
+ const delimiter = _get(options, 'delimiter', '.');
54
+ const transformKey = _get(options, 'transformKey', keyIdentity);
38
55
  const result = {};
39
- const isbuffer = lodash.isBuffer(target);
56
+ const isbuffer = isBuffer(target);
40
57
  if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
41
58
  return target;
42
59
  }
@@ -79,7 +96,7 @@ const unflatten = (target, opts) => {
79
96
  let key2 = getkey(split[0]);
80
97
  let recipient = result;
81
98
  while (key2 !== undefined) {
82
- const recipient_key_1 = key1 && lodash.get(recipient, key1);
99
+ const recipient_key_1 = key1 && _get(recipient, key1);
83
100
  const type = Object.prototype.toString.call(recipient_key_1);
84
101
  const isobject = type === '[object Object]' || type === '[object Array]';
85
102
  if (!overwrite && !isobject && typeof recipient_key_1 !== 'undefined') {
@@ -88,7 +105,7 @@ const unflatten = (target, opts) => {
88
105
  if (overwrite && !isobject || !overwrite && recipient_key_1 == null) {
89
106
  recipient[key1] = typeof key2 === 'number' && !object ? [] : {};
90
107
  }
91
- recipient = key1 && lodash.get(recipient, key1);
108
+ recipient = key1 && _get(recipient, key1);
92
109
  if (split.length > 0) {
93
110
  key1 = getkey(split.shift());
94
111
  key2 = getkey(split[0]);
@@ -105,24 +122,6 @@ const flat = {
105
122
 
106
123
  const Emitter = new tinyEmitter.TinyEmitter();
107
124
 
108
- const operators = {
109
- $exists: (a, b) => !rulesMatcherUtils.isEmpty(a) === b,
110
- $eq: (a, b) => a === b,
111
- $ne: (a, b) => a !== b,
112
- $gt: (a, b) => rulesMatcherUtils.forceNumber(a) > parseFloat(b),
113
- $gte: (a, b) => rulesMatcherUtils.forceNumber(a) >= parseFloat(b),
114
- $lt: (a, b) => rulesMatcherUtils.forceNumber(a) < parseFloat(b),
115
- $lte: (a, b) => rulesMatcherUtils.forceNumber(a) <= parseFloat(b),
116
- $strGt: (a, b) => String(a || '').length > parseFloat(b),
117
- $strGte: (a, b) => String(a || '').length >= parseFloat(b),
118
- $strLt: (a, b) => String(a || '').length < parseFloat(b),
119
- $strLte: (a, b) => String(a || '').length <= parseFloat(b),
120
- $in: (a, b) => rulesMatcherUtils.forceArray(b).some(c => lodash.intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
121
- $nin: (a, b) => !rulesMatcherUtils.forceArray(b).some(c => lodash.intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
122
- $all: (a, b) => rulesMatcherUtils.forceArray(b).every(c => lodash.intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
123
- $regex: (a, b, opt) => rulesMatcherUtils.forceArray(b).some(c => c instanceof RegExp ? c.test(a) : new RegExp(c, opt).test(a))
124
- };
125
-
126
125
  const EMPTY_STRING_REGEXP = /^\s*$/;
127
126
  const rulesMatcherUtils = {
128
127
  isNumber: el => {
@@ -136,16 +135,16 @@ const rulesMatcherUtils = {
136
135
  const path = Object.keys(val)[0];
137
136
  const valueBlock = val;
138
137
  const pathWithPrefix = rulesMatcherUtils.getPath(path, prefix);
139
- const valueForKey = lodash.get(data, pathWithPrefix, undefined);
138
+ const valueForKey = _get(data, pathWithPrefix, undefined);
140
139
  const {
141
140
  name
142
- } = lodash.get(valueBlock, [path], {}) || {};
141
+ } = _get(valueBlock, [path], {}) || {};
143
142
  const {
144
143
  op,
145
144
  value,
146
145
  opt
147
146
  } = rulesMatcherUtils.getDefaultRule(valueBlock[path]);
148
- const valueRef = value && String(value).indexOf('$ref:') === 0 ? lodash.get(data, rulesMatcherUtils.getPath(value.replace('$ref:', ''), prefix), undefined) : value;
147
+ const valueRef = value && String(value).indexOf('$ref:') === 0 ? _get(data, rulesMatcherUtils.getPath(value.replace('$ref:', ''), prefix), undefined) : value;
149
148
  if (!operators[op]) {
150
149
  throw new Error(`Error missing operator:${op}`);
151
150
  }
@@ -262,7 +261,7 @@ const rulesMatcherUtils = {
262
261
  forceArray: a => Array.isArray(a) ? a : [a],
263
262
  getPath: (path, prefix) => {
264
263
  if (path.indexOf('^') === 0) {
265
- return lodash.trimStart(path, '^');
264
+ return _trimStart(path, '^');
266
265
  }
267
266
  if (path.indexOf('$') === 0) {
268
267
  return path;
@@ -301,6 +300,23 @@ const rulesMatcherUtils = {
301
300
  return Object.keys(keys);
302
301
  }
303
302
  };
303
+ const operators = {
304
+ $exists: (a, b) => !rulesMatcherUtils.isEmpty(a) === b,
305
+ $eq: (a, b) => a === b,
306
+ $ne: (a, b) => a !== b,
307
+ $gt: (a, b) => rulesMatcherUtils.forceNumber(a) > parseFloat(b),
308
+ $gte: (a, b) => rulesMatcherUtils.forceNumber(a) >= parseFloat(b),
309
+ $lt: (a, b) => rulesMatcherUtils.forceNumber(a) < parseFloat(b),
310
+ $lte: (a, b) => rulesMatcherUtils.forceNumber(a) <= parseFloat(b),
311
+ $strGt: (a, b) => String(a || '').length > parseFloat(b),
312
+ $strGte: (a, b) => String(a || '').length >= parseFloat(b),
313
+ $strLt: (a, b) => String(a || '').length < parseFloat(b),
314
+ $strLte: (a, b) => String(a || '').length <= parseFloat(b),
315
+ $in: (a, b) => rulesMatcherUtils.forceArray(b).some(c => _intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
316
+ $nin: (a, b) => !rulesMatcherUtils.forceArray(b).some(c => _intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
317
+ $all: (a, b) => rulesMatcherUtils.forceArray(b).every(c => _intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
318
+ $regex: (a, b, opt) => rulesMatcherUtils.forceArray(b).some(c => c instanceof RegExp ? c.test(a) : new RegExp(c, opt).test(a))
319
+ };
304
320
 
305
321
  const rulesMatcher = (rules, formValue = {}, apply = true, options) => {
306
322
  if (!rules) return [apply];
@@ -312,7 +328,6 @@ const rulesMatcher = (rules, formValue = {}, apply = true, options) => {
312
328
  };
313
329
  const MatchRules = {
314
330
  rulesMatcher,
315
- operators,
316
331
  utils: rulesMatcherUtils
317
332
  };
318
333
 
@@ -359,21 +374,21 @@ const CoreUtils = {
359
374
  if (Array.isArray(obj)) {
360
375
  return obj.map(item => CoreUtils.mapKeysDeepLodash(item, cb, true));
361
376
  }
362
- if (!lodash.isPlainObject(obj)) {
377
+ if (!isPlainObject(obj)) {
363
378
  return obj;
364
379
  }
365
- const result = lodash.mapKeys(obj, cb);
366
- return lodash.mapValues(result, value => CoreUtils.mapKeysDeepLodash(value, cb, true));
380
+ const result = mapKeys(obj, cb);
381
+ return mapValues(result, value => CoreUtils.mapKeysDeepLodash(value, cb, true));
367
382
  },
368
- generateNodes: nodes => lodash.keyBy(nodes.map(s => lodash.omit(s, 'nextRules')), 'nodeId'),
383
+ generateNodes: nodes => keyBy(nodes.map(s => omit(s, 'nextRules')), 'nodeId'),
369
384
  makeObjectRules: nodes => nodes.reduce((acc, inc) => ({
370
385
  ...acc,
371
386
  [inc.nodeId]: inc.nextRules
372
387
  }), {}),
373
- hasNode: (state, name, node) => lodash.has(state, [name, 'nodes', node]),
388
+ hasNode: (state, name, node) => has(state, [name, 'nodes', node]),
374
389
  isEmptyRules: rules => {
375
- if (lodash.isEmpty(rules)) return true;
376
- if (lodash.isEmpty(lodash.get(rules, 'rules'))) return true;
390
+ if (isEmpty(rules)) return true;
391
+ if (isEmpty(_get(rules, 'rules'))) return true;
377
392
  if (Object.keys(flattenRules(rules)).every(key => key.endsWith('$and') || key.endsWith('$or'))) {
378
393
  return true;
379
394
  }
@@ -398,14 +413,14 @@ const CoreUtils = {
398
413
  return {
399
414
  nodeId: e.props.id,
400
415
  nodeType: e.type.displayName || e.props.as || 'FlowerNode',
401
- nodeTitle: lodash.get(e.props, 'data.title'),
416
+ nodeTitle: _get(e.props, 'data.title'),
402
417
  children,
403
418
  nextRules,
404
419
  retain: e.props.retain,
405
420
  disabled: e.props.disabled
406
421
  };
407
422
  }),
408
- cleanPath: (name, char = '^') => lodash.trimStart(name, char),
423
+ cleanPath: (name, char = '^') => _trimStart(name, char),
409
424
  getPath: idValue => {
410
425
  if (!idValue) {
411
426
  return {
@@ -429,7 +444,7 @@ const CoreUtils = {
429
444
  };
430
445
  },
431
446
  allEqual: (arr, arr2) => arr.length === arr2.length && arr.every(v => arr2.includes(v)),
432
- findValidRule: (nextRules, value, prefix) => lodash.find(nextRules, rule => {
447
+ findValidRule: (nextRules, value, prefix) => find(nextRules, rule => {
433
448
  if (typeof rule.rules === 'string') {
434
449
  return false;
435
450
  }
@@ -454,16 +469,16 @@ const FlowerStateUtils = {
454
469
  ...acc,
455
470
  [k]: v.data
456
471
  }), {}),
457
- selectFlowerFormNode: (name, id) => state => lodash.get(state, [name, 'form', id]),
472
+ selectFlowerFormNode: (name, id) => state => _get(state, [name, 'form', id]),
458
473
  makeSelectCurrentNextRules: name => state => {
459
- const nextRules = lodash.get(state, [name, 'nextRules']);
474
+ const nextRules = _get(state, [name, 'nextRules']);
460
475
  const currentNodeId = FlowerStateUtils.makeSelectCurrentNodeId(name)(state);
461
- return lodash.get(nextRules, [currentNodeId]);
476
+ return _get(nextRules, [currentNodeId]);
462
477
  },
463
478
  makeSelectCurrentNodeId: name => state => {
464
- const subState = lodash.get(state, [name]);
465
- const startId = lodash.get(state, ['startId']);
466
- return lodash.get(subState, ['current']) || startId;
479
+ const subState = _get(state, [name]);
480
+ const startId = _get(state, ['startId']);
481
+ return _get(subState, ['current']) || startId;
467
482
  },
468
483
  makeSelectNodeErrors: (name, currentNodeId) => state => {
469
484
  const form = FlowerStateUtils.selectFlowerFormNode(name, currentNodeId)(state);
@@ -489,29 +504,29 @@ const FlowerCoreReducers = {
489
504
  }) => {
490
505
  if (hasNode(state, payload.name, payload.node)) {
491
506
  state[payload.name].history.push(payload.node);
492
- lodash.set(state, [payload.name, 'current'], payload.node);
507
+ _set(state, [payload.name, 'current'], payload.node);
493
508
  }
494
509
  return state;
495
510
  },
496
511
  historyPrevToNode: (state, {
497
512
  payload
498
513
  }) => {
499
- const history = lodash.get(state[typeof payload === 'string' ? payload : payload.name], ['history'], []);
500
- const lastIndex = lodash.lastIndexOf(history, typeof payload === 'string' ? payload : payload.node);
514
+ const history = _get(state[typeof payload === 'string' ? payload : payload.name], ['history'], []);
515
+ const lastIndex = lastIndexOf(history, typeof payload === 'string' ? payload : payload.node);
501
516
  if (lastIndex >= 0) {
502
- const newHistory = lodash.slice(history, 0, lastIndex + 1);
503
- lodash.set(state, [typeof payload === 'string' ? payload : payload.name, 'history'], newHistory);
504
- lodash.set(state, [typeof payload === 'string' ? payload : payload.name, 'current'], typeof payload === 'string' ? payload : payload.node);
517
+ const newHistory = _slice(history, 0, lastIndex + 1);
518
+ _set(state, [typeof payload === 'string' ? payload : payload.name, 'history'], newHistory);
519
+ _set(state, [typeof payload === 'string' ? payload : payload.name, 'current'], typeof payload === 'string' ? payload : payload.node);
505
520
  }
506
521
  return state;
507
522
  },
508
523
  setFormTouched: (state, {
509
524
  payload
510
525
  }) => {
511
- if (!lodash.get(state, [typeof payload === 'string' ? payload : payload.flowName, 'nodes', typeof payload === 'string' ? payload : payload.currentNode])) {
526
+ if (!_get(state, [typeof payload === 'string' ? payload : payload.flowName, 'nodes', typeof payload === 'string' ? payload : payload.currentNode])) {
512
527
  return state;
513
528
  }
514
- lodash.set(state, [typeof payload === 'string' ? payload : payload.flowName, 'form', typeof payload === 'string' ? payload : payload.currentNode, 'touched'], true);
529
+ _set(state, [typeof payload === 'string' ? payload : payload.flowName, 'form', typeof payload === 'string' ? payload : payload.currentNode, 'touched'], true);
515
530
  return state;
516
531
  },
517
532
  forceAddHistory: (state, {
@@ -530,37 +545,37 @@ const FlowerCoreReducers = {
530
545
  historyPop: (state, {
531
546
  payload
532
547
  }) => {
533
- const container = lodash.get(state, [payload.name]);
534
- const startId = lodash.get(container, ['startId']);
535
- const history = lodash.get(container, ['history']);
536
- const originHistory = [...lodash.get(container, ['history'], [])];
548
+ const container = _get(state, [payload.name]);
549
+ const startId = _get(container, ['startId']);
550
+ const history = _get(container, ['history']);
551
+ const originHistory = [..._get(container, ['history'], [])];
537
552
  if (originHistory.length < 2) {
538
- lodash.set(state, [payload.name, 'current'], startId);
539
- lodash.set(state, [payload.name, 'history'], [startId]);
553
+ _set(state, [payload.name, 'current'], startId);
554
+ _set(state, [payload.name, 'history'], [startId]);
540
555
  return state;
541
556
  }
542
557
  history.pop();
543
558
  const total = originHistory.length - 2;
544
559
  for (let index = total; index > 0; index--) {
545
560
  const curr = originHistory[index];
546
- const nodeType = lodash.get(container, ['nodes', curr, 'nodeType']);
547
- const nodeDisabled = lodash.get(container, ['nodes', curr, 'disabled']);
561
+ const nodeType = _get(container, ['nodes', curr, 'nodeType']);
562
+ const nodeDisabled = _get(container, ['nodes', curr, 'disabled']);
548
563
  if (nodeDisabled || nodeType === 'FlowerAction' || nodeType === 'FlowerServer' || !nodeType) {
549
564
  history.pop();
550
565
  } else {
551
566
  break;
552
567
  }
553
568
  }
554
- const lastId = lodash.last(history);
555
- lodash.set(state, [payload.name, 'current'], lastId);
569
+ const lastId = _last(history);
570
+ _set(state, [payload.name, 'current'], lastId);
556
571
  return state;
557
572
  },
558
573
  restoreHistory: (state, {
559
574
  payload
560
575
  }) => {
561
- const startId = lodash.get(state, [payload.name, 'startId']);
562
- lodash.set(state, [payload.name, 'current'], startId);
563
- lodash.set(state, [payload.name, 'history'], [startId]);
576
+ const startId = _get(state, [payload.name, 'startId']);
577
+ _set(state, [payload.name, 'current'], startId);
578
+ _set(state, [payload.name, 'history'], [startId]);
564
579
  return state;
565
580
  },
566
581
  replaceNode: (state, {
@@ -572,8 +587,8 @@ const FlowerCoreReducers = {
572
587
  node
573
588
  } = payload;
574
589
  if (hasNode(state, name || flowName || '', node)) {
575
- lodash.set(state, [name || flowName || '', 'current'], node);
576
- lodash.set(state, [name || flowName || '', 'history'], [node]);
590
+ _set(state, [name || flowName || '', 'current'], node);
591
+ _set(state, [name || flowName || '', 'history'], [node]);
577
592
  }
578
593
  return state;
579
594
  },
@@ -586,9 +601,9 @@ const FlowerCoreReducers = {
586
601
  node
587
602
  } = payload;
588
603
  if (hasNode(state, name || flowName || '', node)) {
589
- lodash.set(state, [name || flowName || '', 'startId'], node);
590
- lodash.set(state, [name || flowName || '', 'current'], node);
591
- lodash.set(state, [name || flowName || '', 'history'], [node]);
604
+ _set(state, [name || flowName || '', 'startId'], node);
605
+ _set(state, [name || flowName || '', 'current'], node);
606
+ _set(state, [name || flowName || '', 'history'], [node]);
592
607
  }
593
608
  return state;
594
609
  },
@@ -600,24 +615,24 @@ const FlowerCoreReducers = {
600
615
  flowName
601
616
  } = payload;
602
617
  if (!name && !flowName) return state;
603
- lodash.set(state, [name || flowName || '', 'history'], []);
618
+ _set(state, [name || flowName || '', 'history'], []);
604
619
  return state;
605
620
  },
606
621
  destroy: (state, {
607
622
  payload
608
623
  }) => {
609
- lodash.set(state, [payload.name], {});
624
+ _set(state, [payload.name], {});
610
625
  },
611
626
  initNodes: (state, {
612
627
  payload
613
628
  }) => {
614
- if (payload.persist && lodash.get(state, [payload.name, 'persist'])) return;
615
- const startId = payload.startId || lodash.get(payload, 'nodes.0.nodeId');
629
+ if (payload.persist && _get(state, [payload.name, 'persist'])) return;
630
+ const startId = payload.startId || _get(payload, 'nodes.0.nodeId');
616
631
  if (!startId) {
617
632
  console.warn('Flower is empty');
618
633
  return;
619
634
  }
620
- lodash.set(state, payload.name, {
635
+ _set(state, payload.name, {
621
636
  persist: payload.persist,
622
637
  startId,
623
638
  current: startId,
@@ -631,31 +646,31 @@ const FlowerCoreReducers = {
631
646
  payload
632
647
  }) => {
633
648
  if (hasNode(state, payload.name, payload.node)) {
634
- const startId = lodash.get(state, [payload.name, 'startId']);
649
+ const startId = _get(state, [payload.name, 'startId']);
635
650
  if (payload.node === startId) {
636
- lodash.set(state, [payload.name, 'current'], startId);
637
- lodash.set(state, [payload.name, 'history'], [startId]);
651
+ _set(state, [payload.name, 'current'], startId);
652
+ _set(state, [payload.name, 'history'], [startId]);
638
653
  } else {
639
- lodash.set(state, [payload.name, 'current'], payload.node);
654
+ _set(state, [payload.name, 'current'], payload.node);
640
655
  }
641
656
  }
642
657
  },
643
658
  formAddErrors: (state, {
644
659
  payload
645
660
  }) => {
646
- lodash.set(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id], payload.errors);
661
+ _set(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id], payload.errors);
647
662
  },
648
663
  formRemoveErrors: (state, {
649
664
  payload
650
665
  }) => {
651
- lodash.unset(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id]);
652
- lodash.unset(state, [payload.name, 'form', payload.currentNode, 'isValidating']);
666
+ _unset(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id]);
667
+ _unset(state, [payload.name, 'form', payload.currentNode, 'isValidating']);
653
668
  },
654
669
  addData: (state, {
655
670
  payload
656
671
  }) => {
657
- const prevData = lodash.get(state, [payload.flowName, 'data']);
658
- lodash.set(state, [payload.flowName, 'data'], {
672
+ const prevData = _get(state, [payload.flowName, 'data']);
673
+ _set(state, [payload.flowName, 'data'], {
659
674
  ...prevData,
660
675
  ...payload.value
661
676
  });
@@ -664,23 +679,23 @@ const FlowerCoreReducers = {
664
679
  payload
665
680
  }) => {
666
681
  if (payload.id && payload.id.length) {
667
- lodash.set(state, [payload.flowName, 'data', ...payload.id], payload.value);
682
+ _set(state, [payload.flowName, 'data', ...payload.id], payload.value);
668
683
  }
669
684
  },
670
685
  replaceData: (state, {
671
686
  payload
672
687
  }) => {
673
- lodash.set(state, [payload.flowName, 'data'], payload.value);
688
+ _set(state, [payload.flowName, 'data'], payload.value);
674
689
  },
675
690
  unsetData: (state, {
676
691
  payload
677
692
  }) => {
678
- lodash.unset(state, [payload.flowName, 'data', ...payload.id]);
693
+ _unset(state, [payload.flowName, 'data', ...payload.id]);
679
694
  },
680
695
  setFormIsValidating: (state, {
681
696
  payload
682
697
  }) => {
683
- lodash.set(state, [payload.name, 'form', payload.currentNode, 'isValidating'], payload.isValidating);
698
+ _set(state, [payload.name, 'form', payload.currentNode, 'isValidating'], payload.isValidating);
684
699
  },
685
700
  node: (state, {
686
701
  payload
@@ -691,8 +706,8 @@ const FlowerCoreReducers = {
691
706
  } = payload;
692
707
  const node = payload.nodeId || payload.node || '';
693
708
  const flowName = name || payload.flowName || '';
694
- const startNode = lodash.get(state, [payload.name, 'startId']);
695
- const currentNodeId = lodash.get(state, [payload.name, 'current'], startNode);
709
+ const startNode = _get(state, [payload.name, 'startId']);
710
+ const currentNodeId = _get(state, [payload.name, 'current'], startNode);
696
711
  FlowerCoreReducers.setFormTouched(state, {
697
712
  type: 'setFormTouched',
698
713
  payload: {
@@ -700,7 +715,7 @@ const FlowerCoreReducers = {
700
715
  currentNode: currentNodeId
701
716
  }
702
717
  });
703
- if (global.window && lodash.get(global.window, '__FLOWER_DEVTOOLS__') && history) {
718
+ if (global.window && _get(global.window, '__FLOWER_DEVTOOLS__') && history) {
704
719
  FlowerCoreReducers.forceAddHistory(state, {
705
720
  type: 'forceAddHistory',
706
721
  payload: {
@@ -746,7 +761,7 @@ const FlowerCoreReducers = {
746
761
  const currentNodeId = FlowerStateUtils.makeSelectCurrentNodeId(flowName)(state);
747
762
  const currentNextRules = FlowerStateUtils.makeSelectCurrentNextRules(flowName)(state);
748
763
  const form = FlowerStateUtils.makeSelectNodeErrors(flowName, currentNodeId)(state);
749
- const clonedData = lodash.cloneDeep(FlowerStateUtils.getAllData(state));
764
+ const clonedData = _cloneDeep(FlowerStateUtils.getAllData(state));
750
765
  const stateWithNodeData = {
751
766
  $in: data,
752
767
  $form: form,
@@ -777,7 +792,7 @@ const FlowerCoreReducers = {
777
792
  return;
778
793
  }
779
794
  const validRule = findValidRule(currentNextRules, stateWithNodeData, flowName);
780
- const nextNumberNode = lodash.get(validRule, 'nodeId');
795
+ const nextNumberNode = _get(validRule, 'nodeId');
781
796
  if (!nextNumberNode) {
782
797
  return;
783
798
  }
@@ -821,16 +836,16 @@ const FlowerCoreReducers = {
821
836
 
822
837
  const FlowerCoreStateSelectors = {
823
838
  selectGlobal: state => state && state.flower,
824
- selectFlower: name => state => lodash.get(state, [name]),
825
- selectFlowerFormNode: id => state => lodash.get(state, ['form', id]),
826
- selectFlowerHistory: flower => lodash.get(flower, ['history'], []),
827
- makeSelectNodesIds: flower => lodash.get(flower, ['nodes']),
828
- makeSelectStartNodeId: flower => lodash.get(flower, ['startId']),
829
- getDataByFlow: flower => lodash.get(flower, ['data']) ?? {},
830
- getDataFromState: id => data => id === '*' ? data : lodash.get(data, id),
839
+ selectFlower: name => state => _get(state, [name]),
840
+ selectFlowerFormNode: id => state => _get(state, ['form', id]),
841
+ selectFlowerHistory: flower => _get(flower, ['history'], []),
842
+ makeSelectNodesIds: flower => _get(flower, ['nodes']),
843
+ makeSelectStartNodeId: flower => _get(flower, ['startId']),
844
+ getDataByFlow: flower => _get(flower, ['data']) ?? {},
845
+ getDataFromState: id => data => id === '*' ? data : _get(data, id),
831
846
  makeSelectNodeFormTouched: form => form && form.touched,
832
- makeSelectCurrentNodeId: (flower, startNodeId) => lodash.get(flower, ['current']) || startNodeId,
833
- makeSelectCurrentNodeDisabled: (nodes, current) => !!lodash.get(nodes, [current, 'disabled']),
847
+ makeSelectCurrentNodeId: (flower, startNodeId) => _get(flower, ['current']) || startNodeId,
848
+ makeSelectCurrentNodeDisabled: (nodes, current) => !!_get(nodes, [current, 'disabled']),
834
849
  makeSelectPrevNodeRetain: (nodes, history, current) => {
835
850
  if (!nodes) return;
836
851
  const prevFlowerNode = [...history].reverse().find(el => {
@@ -874,14 +889,14 @@ const FlowerCoreStateSelectors = {
874
889
  $form: form
875
890
  };
876
891
  const state = Object.assign(newState, id ? {
877
- $self: lodash.get(newState, [flowName, ...id.split('.')])
892
+ $self: _get(newState, [flowName, ...id.split('.')])
878
893
  } : {});
879
894
  if (!rules) return false;
880
895
  if (!keys) return false;
881
896
  const res = keys.reduce((acc, inc) => {
882
897
  const k = inc;
883
898
  return Object.assign(acc, {
884
- [k]: lodash.get(state, k)
899
+ [k]: _get(state, k)
885
900
  });
886
901
  }, {});
887
902
  const [disabled] = MatchRules.rulesMatcher(rules, {
package/dist/index.esm.js CHANGED
@@ -1,13 +1,30 @@
1
- import { get, isBuffer, intersection, trimStart, isPlainObject, mapKeys, mapValues, keyBy, omit, has, isEmpty, find, set, lastIndexOf, slice, last, unset, cloneDeep } from 'lodash';
1
+ import _get from 'lodash/get';
2
+ import isBuffer from 'lodash/isBuffer';
2
3
  import { TinyEmitter } from 'tiny-emitter';
4
+ import _set from 'lodash/set';
5
+ import _unset from 'lodash/unset';
6
+ import _last from 'lodash/last';
7
+ import _slice from 'lodash/slice';
8
+ import _cloneDeep from 'lodash/cloneDeep';
9
+ import lastIndexOf from 'lodash/lastIndexOf';
10
+ import find from 'lodash/find';
11
+ import keyBy from 'lodash/keyBy';
12
+ import has from 'lodash/has';
13
+ import omit from 'lodash/omit';
14
+ import isEmpty from 'lodash/isEmpty';
15
+ import isPlainObject from 'lodash/isPlainObject';
16
+ import mapKeys from 'lodash/mapKeys';
17
+ import mapValues from 'lodash/mapValues';
18
+ import _trimStart from 'lodash/trimStart';
19
+ import _intersection from 'lodash/intersection';
3
20
 
4
21
  const keyIdentity = key => key;
5
22
  const flatten = (target, opts) => {
6
23
  const options = opts ?? {};
7
- const safe = get(options, 'safe', false);
8
- const maxDepth = get(options, 'maxDepth', 0);
9
- const delimiter = get(options, 'delimiter', '.');
10
- const transformKey = get(options, 'transformKey', keyIdentity);
24
+ const safe = _get(options, 'safe', false);
25
+ const maxDepth = _get(options, 'maxDepth', 0);
26
+ const delimiter = _get(options, 'delimiter', '.');
27
+ const transformKey = _get(options, 'transformKey', keyIdentity);
11
28
  const output = {};
12
29
  const step = (object, prev, currentDepth) => {
13
30
  const depth = currentDepth || 1;
@@ -29,10 +46,10 @@ const flatten = (target, opts) => {
29
46
  };
30
47
  const unflatten = (target, opts) => {
31
48
  const options = opts ?? {};
32
- const object = get(options, 'object', false);
33
- const overwrite = get(options, 'overwrite', false);
34
- const delimiter = get(options, 'delimiter', '.');
35
- const transformKey = get(options, 'transformKey', keyIdentity);
49
+ const object = _get(options, 'object', false);
50
+ const overwrite = _get(options, 'overwrite', false);
51
+ const delimiter = _get(options, 'delimiter', '.');
52
+ const transformKey = _get(options, 'transformKey', keyIdentity);
36
53
  const result = {};
37
54
  const isbuffer = isBuffer(target);
38
55
  if (isbuffer || Object.prototype.toString.call(target) !== '[object Object]') {
@@ -77,7 +94,7 @@ const unflatten = (target, opts) => {
77
94
  let key2 = getkey(split[0]);
78
95
  let recipient = result;
79
96
  while (key2 !== undefined) {
80
- const recipient_key_1 = key1 && get(recipient, key1);
97
+ const recipient_key_1 = key1 && _get(recipient, key1);
81
98
  const type = Object.prototype.toString.call(recipient_key_1);
82
99
  const isobject = type === '[object Object]' || type === '[object Array]';
83
100
  if (!overwrite && !isobject && typeof recipient_key_1 !== 'undefined') {
@@ -86,7 +103,7 @@ const unflatten = (target, opts) => {
86
103
  if (overwrite && !isobject || !overwrite && recipient_key_1 == null) {
87
104
  recipient[key1] = typeof key2 === 'number' && !object ? [] : {};
88
105
  }
89
- recipient = key1 && get(recipient, key1);
106
+ recipient = key1 && _get(recipient, key1);
90
107
  if (split.length > 0) {
91
108
  key1 = getkey(split.shift());
92
109
  key2 = getkey(split[0]);
@@ -103,24 +120,6 @@ const flat = {
103
120
 
104
121
  const Emitter = new TinyEmitter();
105
122
 
106
- const operators = {
107
- $exists: (a, b) => !rulesMatcherUtils.isEmpty(a) === b,
108
- $eq: (a, b) => a === b,
109
- $ne: (a, b) => a !== b,
110
- $gt: (a, b) => rulesMatcherUtils.forceNumber(a) > parseFloat(b),
111
- $gte: (a, b) => rulesMatcherUtils.forceNumber(a) >= parseFloat(b),
112
- $lt: (a, b) => rulesMatcherUtils.forceNumber(a) < parseFloat(b),
113
- $lte: (a, b) => rulesMatcherUtils.forceNumber(a) <= parseFloat(b),
114
- $strGt: (a, b) => String(a || '').length > parseFloat(b),
115
- $strGte: (a, b) => String(a || '').length >= parseFloat(b),
116
- $strLt: (a, b) => String(a || '').length < parseFloat(b),
117
- $strLte: (a, b) => String(a || '').length <= parseFloat(b),
118
- $in: (a, b) => rulesMatcherUtils.forceArray(b).some(c => intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
119
- $nin: (a, b) => !rulesMatcherUtils.forceArray(b).some(c => intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
120
- $all: (a, b) => rulesMatcherUtils.forceArray(b).every(c => intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
121
- $regex: (a, b, opt) => rulesMatcherUtils.forceArray(b).some(c => c instanceof RegExp ? c.test(a) : new RegExp(c, opt).test(a))
122
- };
123
-
124
123
  const EMPTY_STRING_REGEXP = /^\s*$/;
125
124
  const rulesMatcherUtils = {
126
125
  isNumber: el => {
@@ -134,16 +133,16 @@ const rulesMatcherUtils = {
134
133
  const path = Object.keys(val)[0];
135
134
  const valueBlock = val;
136
135
  const pathWithPrefix = rulesMatcherUtils.getPath(path, prefix);
137
- const valueForKey = get(data, pathWithPrefix, undefined);
136
+ const valueForKey = _get(data, pathWithPrefix, undefined);
138
137
  const {
139
138
  name
140
- } = get(valueBlock, [path], {}) || {};
139
+ } = _get(valueBlock, [path], {}) || {};
141
140
  const {
142
141
  op,
143
142
  value,
144
143
  opt
145
144
  } = rulesMatcherUtils.getDefaultRule(valueBlock[path]);
146
- const valueRef = value && String(value).indexOf('$ref:') === 0 ? get(data, rulesMatcherUtils.getPath(value.replace('$ref:', ''), prefix), undefined) : value;
145
+ const valueRef = value && String(value).indexOf('$ref:') === 0 ? _get(data, rulesMatcherUtils.getPath(value.replace('$ref:', ''), prefix), undefined) : value;
147
146
  if (!operators[op]) {
148
147
  throw new Error(`Error missing operator:${op}`);
149
148
  }
@@ -260,7 +259,7 @@ const rulesMatcherUtils = {
260
259
  forceArray: a => Array.isArray(a) ? a : [a],
261
260
  getPath: (path, prefix) => {
262
261
  if (path.indexOf('^') === 0) {
263
- return trimStart(path, '^');
262
+ return _trimStart(path, '^');
264
263
  }
265
264
  if (path.indexOf('$') === 0) {
266
265
  return path;
@@ -299,6 +298,23 @@ const rulesMatcherUtils = {
299
298
  return Object.keys(keys);
300
299
  }
301
300
  };
301
+ const operators = {
302
+ $exists: (a, b) => !rulesMatcherUtils.isEmpty(a) === b,
303
+ $eq: (a, b) => a === b,
304
+ $ne: (a, b) => a !== b,
305
+ $gt: (a, b) => rulesMatcherUtils.forceNumber(a) > parseFloat(b),
306
+ $gte: (a, b) => rulesMatcherUtils.forceNumber(a) >= parseFloat(b),
307
+ $lt: (a, b) => rulesMatcherUtils.forceNumber(a) < parseFloat(b),
308
+ $lte: (a, b) => rulesMatcherUtils.forceNumber(a) <= parseFloat(b),
309
+ $strGt: (a, b) => String(a || '').length > parseFloat(b),
310
+ $strGte: (a, b) => String(a || '').length >= parseFloat(b),
311
+ $strLt: (a, b) => String(a || '').length < parseFloat(b),
312
+ $strLte: (a, b) => String(a || '').length <= parseFloat(b),
313
+ $in: (a, b) => rulesMatcherUtils.forceArray(b).some(c => _intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
314
+ $nin: (a, b) => !rulesMatcherUtils.forceArray(b).some(c => _intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
315
+ $all: (a, b) => rulesMatcherUtils.forceArray(b).every(c => _intersection(rulesMatcherUtils.forceArray(a), rulesMatcherUtils.forceArray(c)).length),
316
+ $regex: (a, b, opt) => rulesMatcherUtils.forceArray(b).some(c => c instanceof RegExp ? c.test(a) : new RegExp(c, opt).test(a))
317
+ };
302
318
 
303
319
  const rulesMatcher = (rules, formValue = {}, apply = true, options) => {
304
320
  if (!rules) return [apply];
@@ -310,7 +326,6 @@ const rulesMatcher = (rules, formValue = {}, apply = true, options) => {
310
326
  };
311
327
  const MatchRules = {
312
328
  rulesMatcher,
313
- operators,
314
329
  utils: rulesMatcherUtils
315
330
  };
316
331
 
@@ -371,7 +386,7 @@ const CoreUtils = {
371
386
  hasNode: (state, name, node) => has(state, [name, 'nodes', node]),
372
387
  isEmptyRules: rules => {
373
388
  if (isEmpty(rules)) return true;
374
- if (isEmpty(get(rules, 'rules'))) return true;
389
+ if (isEmpty(_get(rules, 'rules'))) return true;
375
390
  if (Object.keys(flattenRules(rules)).every(key => key.endsWith('$and') || key.endsWith('$or'))) {
376
391
  return true;
377
392
  }
@@ -396,14 +411,14 @@ const CoreUtils = {
396
411
  return {
397
412
  nodeId: e.props.id,
398
413
  nodeType: e.type.displayName || e.props.as || 'FlowerNode',
399
- nodeTitle: get(e.props, 'data.title'),
414
+ nodeTitle: _get(e.props, 'data.title'),
400
415
  children,
401
416
  nextRules,
402
417
  retain: e.props.retain,
403
418
  disabled: e.props.disabled
404
419
  };
405
420
  }),
406
- cleanPath: (name, char = '^') => trimStart(name, char),
421
+ cleanPath: (name, char = '^') => _trimStart(name, char),
407
422
  getPath: idValue => {
408
423
  if (!idValue) {
409
424
  return {
@@ -452,16 +467,16 @@ const FlowerStateUtils = {
452
467
  ...acc,
453
468
  [k]: v.data
454
469
  }), {}),
455
- selectFlowerFormNode: (name, id) => state => get(state, [name, 'form', id]),
470
+ selectFlowerFormNode: (name, id) => state => _get(state, [name, 'form', id]),
456
471
  makeSelectCurrentNextRules: name => state => {
457
- const nextRules = get(state, [name, 'nextRules']);
472
+ const nextRules = _get(state, [name, 'nextRules']);
458
473
  const currentNodeId = FlowerStateUtils.makeSelectCurrentNodeId(name)(state);
459
- return get(nextRules, [currentNodeId]);
474
+ return _get(nextRules, [currentNodeId]);
460
475
  },
461
476
  makeSelectCurrentNodeId: name => state => {
462
- const subState = get(state, [name]);
463
- const startId = get(state, ['startId']);
464
- return get(subState, ['current']) || startId;
477
+ const subState = _get(state, [name]);
478
+ const startId = _get(state, ['startId']);
479
+ return _get(subState, ['current']) || startId;
465
480
  },
466
481
  makeSelectNodeErrors: (name, currentNodeId) => state => {
467
482
  const form = FlowerStateUtils.selectFlowerFormNode(name, currentNodeId)(state);
@@ -487,29 +502,29 @@ const FlowerCoreReducers = {
487
502
  }) => {
488
503
  if (hasNode(state, payload.name, payload.node)) {
489
504
  state[payload.name].history.push(payload.node);
490
- set(state, [payload.name, 'current'], payload.node);
505
+ _set(state, [payload.name, 'current'], payload.node);
491
506
  }
492
507
  return state;
493
508
  },
494
509
  historyPrevToNode: (state, {
495
510
  payload
496
511
  }) => {
497
- const history = get(state[typeof payload === 'string' ? payload : payload.name], ['history'], []);
512
+ const history = _get(state[typeof payload === 'string' ? payload : payload.name], ['history'], []);
498
513
  const lastIndex = lastIndexOf(history, typeof payload === 'string' ? payload : payload.node);
499
514
  if (lastIndex >= 0) {
500
- const newHistory = slice(history, 0, lastIndex + 1);
501
- set(state, [typeof payload === 'string' ? payload : payload.name, 'history'], newHistory);
502
- set(state, [typeof payload === 'string' ? payload : payload.name, 'current'], typeof payload === 'string' ? payload : payload.node);
515
+ const newHistory = _slice(history, 0, lastIndex + 1);
516
+ _set(state, [typeof payload === 'string' ? payload : payload.name, 'history'], newHistory);
517
+ _set(state, [typeof payload === 'string' ? payload : payload.name, 'current'], typeof payload === 'string' ? payload : payload.node);
503
518
  }
504
519
  return state;
505
520
  },
506
521
  setFormTouched: (state, {
507
522
  payload
508
523
  }) => {
509
- if (!get(state, [typeof payload === 'string' ? payload : payload.flowName, 'nodes', typeof payload === 'string' ? payload : payload.currentNode])) {
524
+ if (!_get(state, [typeof payload === 'string' ? payload : payload.flowName, 'nodes', typeof payload === 'string' ? payload : payload.currentNode])) {
510
525
  return state;
511
526
  }
512
- set(state, [typeof payload === 'string' ? payload : payload.flowName, 'form', typeof payload === 'string' ? payload : payload.currentNode, 'touched'], true);
527
+ _set(state, [typeof payload === 'string' ? payload : payload.flowName, 'form', typeof payload === 'string' ? payload : payload.currentNode, 'touched'], true);
513
528
  return state;
514
529
  },
515
530
  forceAddHistory: (state, {
@@ -528,37 +543,37 @@ const FlowerCoreReducers = {
528
543
  historyPop: (state, {
529
544
  payload
530
545
  }) => {
531
- const container = get(state, [payload.name]);
532
- const startId = get(container, ['startId']);
533
- const history = get(container, ['history']);
534
- const originHistory = [...get(container, ['history'], [])];
546
+ const container = _get(state, [payload.name]);
547
+ const startId = _get(container, ['startId']);
548
+ const history = _get(container, ['history']);
549
+ const originHistory = [..._get(container, ['history'], [])];
535
550
  if (originHistory.length < 2) {
536
- set(state, [payload.name, 'current'], startId);
537
- set(state, [payload.name, 'history'], [startId]);
551
+ _set(state, [payload.name, 'current'], startId);
552
+ _set(state, [payload.name, 'history'], [startId]);
538
553
  return state;
539
554
  }
540
555
  history.pop();
541
556
  const total = originHistory.length - 2;
542
557
  for (let index = total; index > 0; index--) {
543
558
  const curr = originHistory[index];
544
- const nodeType = get(container, ['nodes', curr, 'nodeType']);
545
- const nodeDisabled = get(container, ['nodes', curr, 'disabled']);
559
+ const nodeType = _get(container, ['nodes', curr, 'nodeType']);
560
+ const nodeDisabled = _get(container, ['nodes', curr, 'disabled']);
546
561
  if (nodeDisabled || nodeType === 'FlowerAction' || nodeType === 'FlowerServer' || !nodeType) {
547
562
  history.pop();
548
563
  } else {
549
564
  break;
550
565
  }
551
566
  }
552
- const lastId = last(history);
553
- set(state, [payload.name, 'current'], lastId);
567
+ const lastId = _last(history);
568
+ _set(state, [payload.name, 'current'], lastId);
554
569
  return state;
555
570
  },
556
571
  restoreHistory: (state, {
557
572
  payload
558
573
  }) => {
559
- const startId = get(state, [payload.name, 'startId']);
560
- set(state, [payload.name, 'current'], startId);
561
- set(state, [payload.name, 'history'], [startId]);
574
+ const startId = _get(state, [payload.name, 'startId']);
575
+ _set(state, [payload.name, 'current'], startId);
576
+ _set(state, [payload.name, 'history'], [startId]);
562
577
  return state;
563
578
  },
564
579
  replaceNode: (state, {
@@ -570,8 +585,8 @@ const FlowerCoreReducers = {
570
585
  node
571
586
  } = payload;
572
587
  if (hasNode(state, name || flowName || '', node)) {
573
- set(state, [name || flowName || '', 'current'], node);
574
- set(state, [name || flowName || '', 'history'], [node]);
588
+ _set(state, [name || flowName || '', 'current'], node);
589
+ _set(state, [name || flowName || '', 'history'], [node]);
575
590
  }
576
591
  return state;
577
592
  },
@@ -584,9 +599,9 @@ const FlowerCoreReducers = {
584
599
  node
585
600
  } = payload;
586
601
  if (hasNode(state, name || flowName || '', node)) {
587
- set(state, [name || flowName || '', 'startId'], node);
588
- set(state, [name || flowName || '', 'current'], node);
589
- set(state, [name || flowName || '', 'history'], [node]);
602
+ _set(state, [name || flowName || '', 'startId'], node);
603
+ _set(state, [name || flowName || '', 'current'], node);
604
+ _set(state, [name || flowName || '', 'history'], [node]);
590
605
  }
591
606
  return state;
592
607
  },
@@ -598,24 +613,24 @@ const FlowerCoreReducers = {
598
613
  flowName
599
614
  } = payload;
600
615
  if (!name && !flowName) return state;
601
- set(state, [name || flowName || '', 'history'], []);
616
+ _set(state, [name || flowName || '', 'history'], []);
602
617
  return state;
603
618
  },
604
619
  destroy: (state, {
605
620
  payload
606
621
  }) => {
607
- set(state, [payload.name], {});
622
+ _set(state, [payload.name], {});
608
623
  },
609
624
  initNodes: (state, {
610
625
  payload
611
626
  }) => {
612
- if (payload.persist && get(state, [payload.name, 'persist'])) return;
613
- const startId = payload.startId || get(payload, 'nodes.0.nodeId');
627
+ if (payload.persist && _get(state, [payload.name, 'persist'])) return;
628
+ const startId = payload.startId || _get(payload, 'nodes.0.nodeId');
614
629
  if (!startId) {
615
630
  console.warn('Flower is empty');
616
631
  return;
617
632
  }
618
- set(state, payload.name, {
633
+ _set(state, payload.name, {
619
634
  persist: payload.persist,
620
635
  startId,
621
636
  current: startId,
@@ -629,31 +644,31 @@ const FlowerCoreReducers = {
629
644
  payload
630
645
  }) => {
631
646
  if (hasNode(state, payload.name, payload.node)) {
632
- const startId = get(state, [payload.name, 'startId']);
647
+ const startId = _get(state, [payload.name, 'startId']);
633
648
  if (payload.node === startId) {
634
- set(state, [payload.name, 'current'], startId);
635
- set(state, [payload.name, 'history'], [startId]);
649
+ _set(state, [payload.name, 'current'], startId);
650
+ _set(state, [payload.name, 'history'], [startId]);
636
651
  } else {
637
- set(state, [payload.name, 'current'], payload.node);
652
+ _set(state, [payload.name, 'current'], payload.node);
638
653
  }
639
654
  }
640
655
  },
641
656
  formAddErrors: (state, {
642
657
  payload
643
658
  }) => {
644
- set(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id], payload.errors);
659
+ _set(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id], payload.errors);
645
660
  },
646
661
  formRemoveErrors: (state, {
647
662
  payload
648
663
  }) => {
649
- unset(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id]);
650
- unset(state, [payload.name, 'form', payload.currentNode, 'isValidating']);
664
+ _unset(state, [payload.name, 'form', payload.currentNode, 'errors', payload.id]);
665
+ _unset(state, [payload.name, 'form', payload.currentNode, 'isValidating']);
651
666
  },
652
667
  addData: (state, {
653
668
  payload
654
669
  }) => {
655
- const prevData = get(state, [payload.flowName, 'data']);
656
- set(state, [payload.flowName, 'data'], {
670
+ const prevData = _get(state, [payload.flowName, 'data']);
671
+ _set(state, [payload.flowName, 'data'], {
657
672
  ...prevData,
658
673
  ...payload.value
659
674
  });
@@ -662,23 +677,23 @@ const FlowerCoreReducers = {
662
677
  payload
663
678
  }) => {
664
679
  if (payload.id && payload.id.length) {
665
- set(state, [payload.flowName, 'data', ...payload.id], payload.value);
680
+ _set(state, [payload.flowName, 'data', ...payload.id], payload.value);
666
681
  }
667
682
  },
668
683
  replaceData: (state, {
669
684
  payload
670
685
  }) => {
671
- set(state, [payload.flowName, 'data'], payload.value);
686
+ _set(state, [payload.flowName, 'data'], payload.value);
672
687
  },
673
688
  unsetData: (state, {
674
689
  payload
675
690
  }) => {
676
- unset(state, [payload.flowName, 'data', ...payload.id]);
691
+ _unset(state, [payload.flowName, 'data', ...payload.id]);
677
692
  },
678
693
  setFormIsValidating: (state, {
679
694
  payload
680
695
  }) => {
681
- set(state, [payload.name, 'form', payload.currentNode, 'isValidating'], payload.isValidating);
696
+ _set(state, [payload.name, 'form', payload.currentNode, 'isValidating'], payload.isValidating);
682
697
  },
683
698
  node: (state, {
684
699
  payload
@@ -689,8 +704,8 @@ const FlowerCoreReducers = {
689
704
  } = payload;
690
705
  const node = payload.nodeId || payload.node || '';
691
706
  const flowName = name || payload.flowName || '';
692
- const startNode = get(state, [payload.name, 'startId']);
693
- const currentNodeId = get(state, [payload.name, 'current'], startNode);
707
+ const startNode = _get(state, [payload.name, 'startId']);
708
+ const currentNodeId = _get(state, [payload.name, 'current'], startNode);
694
709
  FlowerCoreReducers.setFormTouched(state, {
695
710
  type: 'setFormTouched',
696
711
  payload: {
@@ -698,7 +713,7 @@ const FlowerCoreReducers = {
698
713
  currentNode: currentNodeId
699
714
  }
700
715
  });
701
- if (global.window && get(global.window, '__FLOWER_DEVTOOLS__') && history) {
716
+ if (global.window && _get(global.window, '__FLOWER_DEVTOOLS__') && history) {
702
717
  FlowerCoreReducers.forceAddHistory(state, {
703
718
  type: 'forceAddHistory',
704
719
  payload: {
@@ -744,7 +759,7 @@ const FlowerCoreReducers = {
744
759
  const currentNodeId = FlowerStateUtils.makeSelectCurrentNodeId(flowName)(state);
745
760
  const currentNextRules = FlowerStateUtils.makeSelectCurrentNextRules(flowName)(state);
746
761
  const form = FlowerStateUtils.makeSelectNodeErrors(flowName, currentNodeId)(state);
747
- const clonedData = cloneDeep(FlowerStateUtils.getAllData(state));
762
+ const clonedData = _cloneDeep(FlowerStateUtils.getAllData(state));
748
763
  const stateWithNodeData = {
749
764
  $in: data,
750
765
  $form: form,
@@ -775,7 +790,7 @@ const FlowerCoreReducers = {
775
790
  return;
776
791
  }
777
792
  const validRule = findValidRule(currentNextRules, stateWithNodeData, flowName);
778
- const nextNumberNode = get(validRule, 'nodeId');
793
+ const nextNumberNode = _get(validRule, 'nodeId');
779
794
  if (!nextNumberNode) {
780
795
  return;
781
796
  }
@@ -819,16 +834,16 @@ const FlowerCoreReducers = {
819
834
 
820
835
  const FlowerCoreStateSelectors = {
821
836
  selectGlobal: state => state && state.flower,
822
- selectFlower: name => state => get(state, [name]),
823
- selectFlowerFormNode: id => state => get(state, ['form', id]),
824
- selectFlowerHistory: flower => get(flower, ['history'], []),
825
- makeSelectNodesIds: flower => get(flower, ['nodes']),
826
- makeSelectStartNodeId: flower => get(flower, ['startId']),
827
- getDataByFlow: flower => get(flower, ['data']) ?? {},
828
- getDataFromState: id => data => id === '*' ? data : get(data, id),
837
+ selectFlower: name => state => _get(state, [name]),
838
+ selectFlowerFormNode: id => state => _get(state, ['form', id]),
839
+ selectFlowerHistory: flower => _get(flower, ['history'], []),
840
+ makeSelectNodesIds: flower => _get(flower, ['nodes']),
841
+ makeSelectStartNodeId: flower => _get(flower, ['startId']),
842
+ getDataByFlow: flower => _get(flower, ['data']) ?? {},
843
+ getDataFromState: id => data => id === '*' ? data : _get(data, id),
829
844
  makeSelectNodeFormTouched: form => form && form.touched,
830
- makeSelectCurrentNodeId: (flower, startNodeId) => get(flower, ['current']) || startNodeId,
831
- makeSelectCurrentNodeDisabled: (nodes, current) => !!get(nodes, [current, 'disabled']),
845
+ makeSelectCurrentNodeId: (flower, startNodeId) => _get(flower, ['current']) || startNodeId,
846
+ makeSelectCurrentNodeDisabled: (nodes, current) => !!_get(nodes, [current, 'disabled']),
832
847
  makeSelectPrevNodeRetain: (nodes, history, current) => {
833
848
  if (!nodes) return;
834
849
  const prevFlowerNode = [...history].reverse().find(el => {
@@ -872,14 +887,14 @@ const FlowerCoreStateSelectors = {
872
887
  $form: form
873
888
  };
874
889
  const state = Object.assign(newState, id ? {
875
- $self: get(newState, [flowName, ...id.split('.')])
890
+ $self: _get(newState, [flowName, ...id.split('.')])
876
891
  } : {});
877
892
  if (!rules) return false;
878
893
  if (!keys) return false;
879
894
  const res = keys.reduce((acc, inc) => {
880
895
  const k = inc;
881
896
  return Object.assign(acc, {
882
- [k]: get(state, k)
897
+ [k]: _get(state, k)
883
898
  });
884
899
  }, {});
885
900
  const [disabled] = MatchRules.rulesMatcher(rules, {
@@ -1,5 +1,4 @@
1
1
  export declare const MatchRules: {
2
2
  rulesMatcher: (rules?: Record<string, any> | Record<string, any>[], formValue?: Record<string, any>, apply?: boolean, options?: Record<string, any>) => boolean[];
3
- operators: import("./rules-matcher/interface").Operators;
4
3
  utils: import("./rules-matcher/interface").RulesMatcherUtils;
5
4
  };
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@flowerforce/flower-core",
3
- "version": "3.0.0",
3
+ "version": "3.0.1-beta.1",
4
4
  "description": "Core functions for flowerJS",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/flowerforce/flower.git"
8
+ },
9
+ "homepage": "https://www.flowerjs.it",
5
10
  "publishConfig": {
6
11
  "access": "public"
7
12
  },
@@ -1,3 +0,0 @@
1
- import { Operators } from './interface';
2
- declare const operators: Operators;
3
- export default operators;