@bolttech/form-engine 3.0.2-beta.7 → 3.1.0-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/index.esm.js +194 -149
- package/package.json +2 -2
package/index.esm.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { FormGroup, FormCore } from '@bolttech/form-engine-core';
|
|
3
|
-
import { createContext, useContext, useRef, useMemo, useState, useEffect, useCallback, Suspense, Children } from 'react';
|
|
3
|
+
import { createContext, useContext, useRef, useMemo, useState, useEffect, useCallback, Suspense, Children, Fragment as Fragment$1 } from 'react';
|
|
4
4
|
|
|
5
5
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
6
6
|
|
|
@@ -1468,6 +1468,73 @@ if (DESCRIPTORS$1 && values.name !== 'values') try {
|
|
|
1468
1468
|
defineProperty$1(values, 'name', { value: 'values' });
|
|
1469
1469
|
} catch (error) { /* empty */ }
|
|
1470
1470
|
|
|
1471
|
+
var DESCRIPTORS = descriptors;
|
|
1472
|
+
var uncurryThis$5 = functionUncurryThis;
|
|
1473
|
+
var call$2 = functionCall;
|
|
1474
|
+
var fails$6 = fails$h;
|
|
1475
|
+
var objectKeys = objectKeys$2;
|
|
1476
|
+
var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols;
|
|
1477
|
+
var propertyIsEnumerableModule = objectPropertyIsEnumerable;
|
|
1478
|
+
var toObject$1 = toObject$4;
|
|
1479
|
+
var IndexedObject = indexedObject;
|
|
1480
|
+
|
|
1481
|
+
// eslint-disable-next-line es/no-object-assign -- safe
|
|
1482
|
+
var $assign = Object.assign;
|
|
1483
|
+
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
|
|
1484
|
+
var defineProperty = Object.defineProperty;
|
|
1485
|
+
var concat = uncurryThis$5([].concat);
|
|
1486
|
+
|
|
1487
|
+
// `Object.assign` method
|
|
1488
|
+
// https://tc39.es/ecma262/#sec-object.assign
|
|
1489
|
+
var objectAssign = !$assign || fails$6(function () {
|
|
1490
|
+
// should have correct order of operations (Edge bug)
|
|
1491
|
+
if (DESCRIPTORS && $assign({ b: 1 }, $assign(defineProperty({}, 'a', {
|
|
1492
|
+
enumerable: true,
|
|
1493
|
+
get: function () {
|
|
1494
|
+
defineProperty(this, 'b', {
|
|
1495
|
+
value: 3,
|
|
1496
|
+
enumerable: false
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
}), { b: 2 })).b !== 1) return true;
|
|
1500
|
+
// should work with symbols and should have deterministic property order (V8 bug)
|
|
1501
|
+
var A = {};
|
|
1502
|
+
var B = {};
|
|
1503
|
+
// eslint-disable-next-line es/no-symbol -- safe
|
|
1504
|
+
var symbol = Symbol('assign detection');
|
|
1505
|
+
var alphabet = 'abcdefghijklmnopqrst';
|
|
1506
|
+
A[symbol] = 7;
|
|
1507
|
+
alphabet.split('').forEach(function (chr) { B[chr] = chr; });
|
|
1508
|
+
return $assign({}, A)[symbol] !== 7 || objectKeys($assign({}, B)).join('') !== alphabet;
|
|
1509
|
+
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
|
|
1510
|
+
var T = toObject$1(target);
|
|
1511
|
+
var argumentsLength = arguments.length;
|
|
1512
|
+
var index = 1;
|
|
1513
|
+
var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
|
|
1514
|
+
var propertyIsEnumerable = propertyIsEnumerableModule.f;
|
|
1515
|
+
while (argumentsLength > index) {
|
|
1516
|
+
var S = IndexedObject(arguments[index++]);
|
|
1517
|
+
var keys = getOwnPropertySymbols ? concat(objectKeys(S), getOwnPropertySymbols(S)) : objectKeys(S);
|
|
1518
|
+
var length = keys.length;
|
|
1519
|
+
var j = 0;
|
|
1520
|
+
var key;
|
|
1521
|
+
while (length > j) {
|
|
1522
|
+
key = keys[j++];
|
|
1523
|
+
if (!DESCRIPTORS || call$2(propertyIsEnumerable, S, key)) T[key] = S[key];
|
|
1524
|
+
}
|
|
1525
|
+
} return T;
|
|
1526
|
+
} : $assign;
|
|
1527
|
+
|
|
1528
|
+
var $$3 = _export;
|
|
1529
|
+
var assign = objectAssign;
|
|
1530
|
+
|
|
1531
|
+
// `Object.assign` method
|
|
1532
|
+
// https://tc39.es/ecma262/#sec-object.assign
|
|
1533
|
+
// eslint-disable-next-line es/no-object-assign -- required for testing
|
|
1534
|
+
$$3({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }, {
|
|
1535
|
+
assign: assign
|
|
1536
|
+
});
|
|
1537
|
+
|
|
1471
1538
|
// iterable DOM collections
|
|
1472
1539
|
// flag - `iterable` interface - 'entries', 'keys', 'values', 'forEach' methods
|
|
1473
1540
|
var domIterables = {
|
|
@@ -1605,9 +1672,9 @@ var toString$3 = function (argument) {
|
|
|
1605
1672
|
return $String(argument);
|
|
1606
1673
|
};
|
|
1607
1674
|
|
|
1608
|
-
var uncurryThis$
|
|
1675
|
+
var uncurryThis$4 = functionUncurryThis;
|
|
1609
1676
|
|
|
1610
|
-
var arraySlice$1 = uncurryThis$
|
|
1677
|
+
var arraySlice$1 = uncurryThis$4([].slice);
|
|
1611
1678
|
|
|
1612
1679
|
var arraySlice = arraySlice$1;
|
|
1613
1680
|
|
|
@@ -1651,11 +1718,11 @@ var sort = function (array, comparefn) {
|
|
|
1651
1718
|
|
|
1652
1719
|
var arraySort = sort;
|
|
1653
1720
|
|
|
1654
|
-
var fails$
|
|
1721
|
+
var fails$5 = fails$h;
|
|
1655
1722
|
|
|
1656
1723
|
var arrayMethodIsStrict$1 = function (METHOD_NAME, argument) {
|
|
1657
1724
|
var method = [][METHOD_NAME];
|
|
1658
|
-
return !!method && fails$
|
|
1725
|
+
return !!method && fails$5(function () {
|
|
1659
1726
|
// eslint-disable-next-line no-useless-call -- required for testing
|
|
1660
1727
|
method.call(null, argument || function () { return 1; }, 1);
|
|
1661
1728
|
});
|
|
@@ -1677,14 +1744,14 @@ var webkit = userAgent.match(/AppleWebKit\/(\d+)\./);
|
|
|
1677
1744
|
|
|
1678
1745
|
var engineWebkitVersion = !!webkit && +webkit[1];
|
|
1679
1746
|
|
|
1680
|
-
var $$
|
|
1681
|
-
var uncurryThis$
|
|
1747
|
+
var $$2 = _export;
|
|
1748
|
+
var uncurryThis$3 = functionUncurryThis;
|
|
1682
1749
|
var aCallable = aCallable$3;
|
|
1683
|
-
var toObject
|
|
1750
|
+
var toObject = toObject$4;
|
|
1684
1751
|
var lengthOfArrayLike = lengthOfArrayLike$2;
|
|
1685
1752
|
var deletePropertyOrThrow = deletePropertyOrThrow$1;
|
|
1686
1753
|
var toString$2 = toString$3;
|
|
1687
|
-
var fails$
|
|
1754
|
+
var fails$4 = fails$h;
|
|
1688
1755
|
var internalSort = arraySort;
|
|
1689
1756
|
var arrayMethodIsStrict = arrayMethodIsStrict$1;
|
|
1690
1757
|
var FF = engineFfVersion;
|
|
@@ -1693,21 +1760,21 @@ var V8 = engineV8Version;
|
|
|
1693
1760
|
var WEBKIT = engineWebkitVersion;
|
|
1694
1761
|
|
|
1695
1762
|
var test = [];
|
|
1696
|
-
var nativeSort = uncurryThis$
|
|
1697
|
-
var push = uncurryThis$
|
|
1763
|
+
var nativeSort = uncurryThis$3(test.sort);
|
|
1764
|
+
var push = uncurryThis$3(test.push);
|
|
1698
1765
|
|
|
1699
1766
|
// IE8-
|
|
1700
|
-
var FAILS_ON_UNDEFINED = fails$
|
|
1767
|
+
var FAILS_ON_UNDEFINED = fails$4(function () {
|
|
1701
1768
|
test.sort(undefined);
|
|
1702
1769
|
});
|
|
1703
1770
|
// V8 bug
|
|
1704
|
-
var FAILS_ON_NULL = fails$
|
|
1771
|
+
var FAILS_ON_NULL = fails$4(function () {
|
|
1705
1772
|
test.sort(null);
|
|
1706
1773
|
});
|
|
1707
1774
|
// Old WebKit
|
|
1708
1775
|
var STRICT_METHOD = arrayMethodIsStrict('sort');
|
|
1709
1776
|
|
|
1710
|
-
var STABLE_SORT = !fails$
|
|
1777
|
+
var STABLE_SORT = !fails$4(function () {
|
|
1711
1778
|
// feature detection can be too slow, so check engines versions
|
|
1712
1779
|
if (V8) return V8 < 70;
|
|
1713
1780
|
if (FF && FF > 3) return;
|
|
@@ -1755,11 +1822,11 @@ var getSortCompare = function (comparefn) {
|
|
|
1755
1822
|
|
|
1756
1823
|
// `Array.prototype.sort` method
|
|
1757
1824
|
// https://tc39.es/ecma262/#sec-array.prototype.sort
|
|
1758
|
-
$$
|
|
1825
|
+
$$2({ target: 'Array', proto: true, forced: FORCED }, {
|
|
1759
1826
|
sort: function sort(comparefn) {
|
|
1760
1827
|
if (comparefn !== undefined) aCallable(comparefn);
|
|
1761
1828
|
|
|
1762
|
-
var array = toObject
|
|
1829
|
+
var array = toObject(this);
|
|
1763
1830
|
|
|
1764
1831
|
if (STABLE_SORT) return comparefn === undefined ? nativeSort(array) : nativeSort(array, comparefn);
|
|
1765
1832
|
|
|
@@ -1783,73 +1850,6 @@ $$3({ target: 'Array', proto: true, forced: FORCED }, {
|
|
|
1783
1850
|
}
|
|
1784
1851
|
});
|
|
1785
1852
|
|
|
1786
|
-
var DESCRIPTORS = descriptors;
|
|
1787
|
-
var uncurryThis$3 = functionUncurryThis;
|
|
1788
|
-
var call$2 = functionCall;
|
|
1789
|
-
var fails$4 = fails$h;
|
|
1790
|
-
var objectKeys = objectKeys$2;
|
|
1791
|
-
var getOwnPropertySymbolsModule = objectGetOwnPropertySymbols;
|
|
1792
|
-
var propertyIsEnumerableModule = objectPropertyIsEnumerable;
|
|
1793
|
-
var toObject = toObject$4;
|
|
1794
|
-
var IndexedObject = indexedObject;
|
|
1795
|
-
|
|
1796
|
-
// eslint-disable-next-line es/no-object-assign -- safe
|
|
1797
|
-
var $assign = Object.assign;
|
|
1798
|
-
// eslint-disable-next-line es/no-object-defineproperty -- required for testing
|
|
1799
|
-
var defineProperty = Object.defineProperty;
|
|
1800
|
-
var concat = uncurryThis$3([].concat);
|
|
1801
|
-
|
|
1802
|
-
// `Object.assign` method
|
|
1803
|
-
// https://tc39.es/ecma262/#sec-object.assign
|
|
1804
|
-
var objectAssign = !$assign || fails$4(function () {
|
|
1805
|
-
// should have correct order of operations (Edge bug)
|
|
1806
|
-
if (DESCRIPTORS && $assign({ b: 1 }, $assign(defineProperty({}, 'a', {
|
|
1807
|
-
enumerable: true,
|
|
1808
|
-
get: function () {
|
|
1809
|
-
defineProperty(this, 'b', {
|
|
1810
|
-
value: 3,
|
|
1811
|
-
enumerable: false
|
|
1812
|
-
});
|
|
1813
|
-
}
|
|
1814
|
-
}), { b: 2 })).b !== 1) return true;
|
|
1815
|
-
// should work with symbols and should have deterministic property order (V8 bug)
|
|
1816
|
-
var A = {};
|
|
1817
|
-
var B = {};
|
|
1818
|
-
// eslint-disable-next-line es/no-symbol -- safe
|
|
1819
|
-
var symbol = Symbol('assign detection');
|
|
1820
|
-
var alphabet = 'abcdefghijklmnopqrst';
|
|
1821
|
-
A[symbol] = 7;
|
|
1822
|
-
alphabet.split('').forEach(function (chr) { B[chr] = chr; });
|
|
1823
|
-
return $assign({}, A)[symbol] !== 7 || objectKeys($assign({}, B)).join('') !== alphabet;
|
|
1824
|
-
}) ? function assign(target, source) { // eslint-disable-line no-unused-vars -- required for `.length`
|
|
1825
|
-
var T = toObject(target);
|
|
1826
|
-
var argumentsLength = arguments.length;
|
|
1827
|
-
var index = 1;
|
|
1828
|
-
var getOwnPropertySymbols = getOwnPropertySymbolsModule.f;
|
|
1829
|
-
var propertyIsEnumerable = propertyIsEnumerableModule.f;
|
|
1830
|
-
while (argumentsLength > index) {
|
|
1831
|
-
var S = IndexedObject(arguments[index++]);
|
|
1832
|
-
var keys = getOwnPropertySymbols ? concat(objectKeys(S), getOwnPropertySymbols(S)) : objectKeys(S);
|
|
1833
|
-
var length = keys.length;
|
|
1834
|
-
var j = 0;
|
|
1835
|
-
var key;
|
|
1836
|
-
while (length > j) {
|
|
1837
|
-
key = keys[j++];
|
|
1838
|
-
if (!DESCRIPTORS || call$2(propertyIsEnumerable, S, key)) T[key] = S[key];
|
|
1839
|
-
}
|
|
1840
|
-
} return T;
|
|
1841
|
-
} : $assign;
|
|
1842
|
-
|
|
1843
|
-
var $$2 = _export;
|
|
1844
|
-
var assign = objectAssign;
|
|
1845
|
-
|
|
1846
|
-
// `Object.assign` method
|
|
1847
|
-
// https://tc39.es/ecma262/#sec-object.assign
|
|
1848
|
-
// eslint-disable-next-line es/no-object-assign -- required for testing
|
|
1849
|
-
$$2({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }, {
|
|
1850
|
-
assign: assign
|
|
1851
|
-
});
|
|
1852
|
-
|
|
1853
1853
|
var anObject$1 = anObject$6;
|
|
1854
1854
|
|
|
1855
1855
|
// `RegExp.prototype.flags` getter implementation
|
|
@@ -2523,69 +2523,52 @@ function Form({
|
|
|
2523
2523
|
debugMode,
|
|
2524
2524
|
formGroupInstance
|
|
2525
2525
|
} = useFormGroupContext({});
|
|
2526
|
-
const [
|
|
2527
|
-
const
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
key: schemaIndex,
|
|
2547
|
-
formInstance
|
|
2548
|
-
});
|
|
2549
|
-
let subMounted;
|
|
2550
|
-
if (onFormMount) {
|
|
2551
|
-
subMounted = formInstance.subscribeOnMount(onFormMount);
|
|
2552
|
-
}
|
|
2553
|
-
formInstance === null || formInstance === void 0 ? void 0 : formInstance.mounted();
|
|
2554
|
-
/*
|
|
2555
|
-
@TODO check if form instance is killed each time it is unmounted
|
|
2556
|
-
the management of multiple forms needs to be planned
|
|
2557
|
-
*/
|
|
2558
|
-
return () => {
|
|
2559
|
-
subMounted === null || subMounted === void 0 ? void 0 : subMounted.unsubscribe();
|
|
2560
|
-
removeForm({
|
|
2561
|
-
key: schemaIndex
|
|
2562
|
-
});
|
|
2563
|
-
};
|
|
2564
|
-
}, []);
|
|
2526
|
+
const [schemaIndex, setSchemaIndex] = useState(`${index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange'}-ssr`);
|
|
2527
|
+
const [formInstance, setFormInstance] = useState(new FormCore({
|
|
2528
|
+
schema: Object.assign(Object.assign({}, schema), {
|
|
2529
|
+
index: schemaIndex
|
|
2530
|
+
}),
|
|
2531
|
+
initialValues: initialValues || (schema === null || schema === void 0 ? void 0 : schema.initialValues),
|
|
2532
|
+
iVars: iVars || (schema === null || schema === void 0 ? void 0 : schema.iVars),
|
|
2533
|
+
action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
|
|
2534
|
+
method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
|
|
2535
|
+
index: schemaIndex,
|
|
2536
|
+
mappers,
|
|
2537
|
+
config: config || formGroupInstance.config
|
|
2538
|
+
}));
|
|
2539
|
+
if (schemaIndex === 'defaultChange' || schemaIndex === 'defaultChange-ssr') {
|
|
2540
|
+
console.warn('please, add an unique id to the form, otherwise multiple forms will break');
|
|
2541
|
+
}
|
|
2542
|
+
if (!formGroupInstance.forms.has(schemaIndex)) addForm({
|
|
2543
|
+
key: schemaIndex,
|
|
2544
|
+
formInstance
|
|
2545
|
+
});
|
|
2565
2546
|
/**
|
|
2566
2547
|
* logic to transform AsFormFields onto JSON schema
|
|
2567
2548
|
* and JSON schema onto FieldWrappers, refreshes when
|
|
2568
2549
|
* the react tree changes it's children
|
|
2569
2550
|
*/
|
|
2570
|
-
|
|
2571
|
-
var _a;
|
|
2572
|
-
const
|
|
2551
|
+
const tree = useMemo(() => {
|
|
2552
|
+
var _a, _b;
|
|
2553
|
+
const parsedSchema = BuildAsFormFieldTree({
|
|
2573
2554
|
children
|
|
2574
2555
|
});
|
|
2575
|
-
|
|
2576
|
-
key:
|
|
2577
|
-
}).refreshFields(
|
|
2578
|
-
const fields = (
|
|
2579
|
-
key:
|
|
2580
|
-
})) === null ||
|
|
2556
|
+
parsedSchema && ((_a = getForm({
|
|
2557
|
+
key: schemaIndex
|
|
2558
|
+
})) === null || _a === void 0 ? void 0 : _a.refreshFields(parsedSchema));
|
|
2559
|
+
const fields = (_b = getForm({
|
|
2560
|
+
key: schemaIndex
|
|
2561
|
+
})) === null || _b === void 0 ? void 0 : _b.fields;
|
|
2581
2562
|
if (fields) {
|
|
2582
2563
|
const buildTree = BuildTree({
|
|
2583
2564
|
fields,
|
|
2584
|
-
formIndex:
|
|
2565
|
+
formIndex: schemaIndex
|
|
2585
2566
|
});
|
|
2586
|
-
|
|
2567
|
+
return jsx(Fragment$1, {
|
|
2568
|
+
children: buildTree
|
|
2569
|
+
}, schemaIndex);
|
|
2587
2570
|
}
|
|
2588
|
-
}, [children]);
|
|
2571
|
+
}, [children, schemaIndex, getForm]);
|
|
2589
2572
|
/**
|
|
2590
2573
|
* iVars change tracker to update iVars onto form instance
|
|
2591
2574
|
*/
|
|
@@ -2602,6 +2585,46 @@ function Form({
|
|
|
2602
2585
|
key: schemaIndex
|
|
2603
2586
|
}).setInitialValues(initialValues);
|
|
2604
2587
|
}, [initialValues]);
|
|
2588
|
+
/**
|
|
2589
|
+
* logic to mount and manage form removal
|
|
2590
|
+
*/
|
|
2591
|
+
useEffect(() => {
|
|
2592
|
+
const newIndex = index || (schema === null || schema === void 0 ? void 0 : schema.index) || 'defaultChange';
|
|
2593
|
+
const newInstance = new FormCore({
|
|
2594
|
+
schema,
|
|
2595
|
+
initialValues: initialValues || (schema === null || schema === void 0 ? void 0 : schema.initialValues),
|
|
2596
|
+
iVars: iVars || (schema === null || schema === void 0 ? void 0 : schema.iVars),
|
|
2597
|
+
action: action || (schema === null || schema === void 0 ? void 0 : schema.action),
|
|
2598
|
+
method: method || (schema === null || schema === void 0 ? void 0 : schema.method),
|
|
2599
|
+
index: newIndex,
|
|
2600
|
+
mappers,
|
|
2601
|
+
config: config || formGroupInstance.config
|
|
2602
|
+
});
|
|
2603
|
+
setSchemaIndex(newIndex);
|
|
2604
|
+
setFormInstance(newInstance);
|
|
2605
|
+
addForm({
|
|
2606
|
+
key: newIndex,
|
|
2607
|
+
formInstance: newInstance
|
|
2608
|
+
});
|
|
2609
|
+
let subMounted;
|
|
2610
|
+
if (onFormMount) {
|
|
2611
|
+
subMounted = newInstance.subscribeOnMount(onFormMount);
|
|
2612
|
+
}
|
|
2613
|
+
newInstance.mounted();
|
|
2614
|
+
/*
|
|
2615
|
+
@TODO check if form instance is killed each time it is unmounted
|
|
2616
|
+
the management of multiple forms needs to be planned
|
|
2617
|
+
*/
|
|
2618
|
+
return () => {
|
|
2619
|
+
subMounted === null || subMounted === void 0 ? void 0 : subMounted.unsubscribe();
|
|
2620
|
+
removeForm({
|
|
2621
|
+
key: newIndex
|
|
2622
|
+
});
|
|
2623
|
+
if (formGroupInstance.forms.has(`${newIndex}-ssr`)) removeForm({
|
|
2624
|
+
key: `${newIndex}-ssr`
|
|
2625
|
+
});
|
|
2626
|
+
};
|
|
2627
|
+
}, []);
|
|
2605
2628
|
/**
|
|
2606
2629
|
* hook usage to keep event bindings updated on callback functions passed as props
|
|
2607
2630
|
*/
|
|
@@ -2872,11 +2895,29 @@ $({ target: 'RegExp', proto: true, forced: /./.exec !== exec }, {
|
|
|
2872
2895
|
* @returns {ReactElement}
|
|
2873
2896
|
*/
|
|
2874
2897
|
const AsFormFieldBuilder = props => {
|
|
2898
|
+
var _a;
|
|
2875
2899
|
const context = useFormGroupContext({});
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2900
|
+
const [fieldName, setFieldName] = useState(`${props.name}-ssr`);
|
|
2901
|
+
if (!((_a = context.formGroupInstance) === null || _a === void 0 ? void 0 : _a.forms.has(props.formIndex))) context.addFormWithIndex(props.formIndex);
|
|
2902
|
+
const formInstance = context.formGroupInstance.forms.get(props.formIndex);
|
|
2903
|
+
if (!(formInstance === null || formInstance === void 0 ? void 0 : formInstance.fields.has(fieldName))) {
|
|
2904
|
+
const fieldSchema = Object.assign(Object.assign(Object.assign({}, props), {
|
|
2905
|
+
name: fieldName
|
|
2906
|
+
}), {
|
|
2907
|
+
component: props.mapper.componentName,
|
|
2908
|
+
children: undefined
|
|
2909
|
+
});
|
|
2910
|
+
formInstance === null || formInstance === void 0 ? void 0 : formInstance.addField({
|
|
2911
|
+
fieldSchema,
|
|
2912
|
+
mapperElement: props.mapper
|
|
2913
|
+
});
|
|
2914
|
+
const field = formInstance === null || formInstance === void 0 ? void 0 : formInstance.getField({
|
|
2915
|
+
key: fieldName
|
|
2916
|
+
});
|
|
2917
|
+
if (typeof (props === null || props === void 0 ? void 0 : props.visibility) !== 'undefined' && field) {
|
|
2918
|
+
field.visibility = props.visibility;
|
|
2919
|
+
}
|
|
2920
|
+
}
|
|
2880
2921
|
/**
|
|
2881
2922
|
* initializer to create or add a form instance to the formGroup by it's formId
|
|
2882
2923
|
* and add the field to the form instance
|
|
@@ -2884,6 +2925,7 @@ const AsFormFieldBuilder = props => {
|
|
|
2884
2925
|
*/
|
|
2885
2926
|
useEffect(() => {
|
|
2886
2927
|
var _a;
|
|
2928
|
+
setFieldName(props.name);
|
|
2887
2929
|
if (!((_a = context.formGroupInstance) === null || _a === void 0 ? void 0 : _a.forms.has(props.formIndex))) {
|
|
2888
2930
|
context.addFormWithIndex(props.formIndex);
|
|
2889
2931
|
}
|
|
@@ -2902,19 +2944,22 @@ const AsFormFieldBuilder = props => {
|
|
|
2902
2944
|
if (typeof (props === null || props === void 0 ? void 0 : props.visibility) !== 'undefined' && field) {
|
|
2903
2945
|
field.visibility = props.visibility;
|
|
2904
2946
|
}
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2947
|
+
return () => {
|
|
2948
|
+
formInstance === null || formInstance === void 0 ? void 0 : formInstance.removeField({
|
|
2949
|
+
key: props.name
|
|
2950
|
+
});
|
|
2951
|
+
if (formInstance === null || formInstance === void 0 ? void 0 : formInstance.fields.has(`${props.name}-ssr`)) formInstance === null || formInstance === void 0 ? void 0 : formInstance.removeField({
|
|
2952
|
+
key: `${props.name}-ssr`
|
|
2953
|
+
});
|
|
2954
|
+
};
|
|
2955
|
+
}, [fieldName]);
|
|
2910
2956
|
/**
|
|
2911
2957
|
* expensive function to allow both external props and templating work
|
|
2912
2958
|
* evaluate if templating will be done onto form-engine or not
|
|
2913
2959
|
*/
|
|
2914
2960
|
useEffect(() => {
|
|
2915
2961
|
var _a;
|
|
2916
|
-
|
|
2917
|
-
const field = (_a = context.formGroupInstance.forms.get(props.formIndex)) === null || _a === void 0 ? void 0 : _a.fields.get(props.name);
|
|
2962
|
+
const field = (_a = context.formGroupInstance.forms.get(props.formIndex)) === null || _a === void 0 ? void 0 : _a.fields.get(fieldName);
|
|
2918
2963
|
const fieldProps = field === null || field === void 0 ? void 0 : field.props;
|
|
2919
2964
|
if (props.props) {
|
|
2920
2965
|
Object.keys(props.props).forEach(propKey => {
|
|
@@ -2929,7 +2974,7 @@ const AsFormFieldBuilder = props => {
|
|
|
2929
2974
|
});
|
|
2930
2975
|
}
|
|
2931
2976
|
field === null || field === void 0 ? void 0 : field.propsSubject$.next(Object.assign(Object.assign({}, fieldProps), props.props));
|
|
2932
|
-
}, [props.props]);
|
|
2977
|
+
}, [props.props, fieldName]);
|
|
2933
2978
|
/**
|
|
2934
2979
|
* allows to control field selected value on each event
|
|
2935
2980
|
*/
|
|
@@ -2946,13 +2991,13 @@ const AsFormFieldBuilder = props => {
|
|
|
2946
2991
|
});
|
|
2947
2992
|
return () => sub === null || sub === void 0 ? void 0 : sub.unsubscribe();
|
|
2948
2993
|
}, [props.onSelected]);
|
|
2949
|
-
return
|
|
2994
|
+
return jsx(FieldWrapper, {
|
|
2950
2995
|
formIndex: props.formIndex,
|
|
2951
|
-
name:
|
|
2996
|
+
name: fieldName,
|
|
2952
2997
|
props: props.props,
|
|
2953
2998
|
context: !context.active ? context : null,
|
|
2954
2999
|
children: props.children && props.children
|
|
2955
|
-
}
|
|
3000
|
+
}, fieldName);
|
|
2956
3001
|
};
|
|
2957
3002
|
|
|
2958
3003
|
function useFormGroup({
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bolttech/form-engine",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0-beta.1",
|
|
4
4
|
"description": "A react adapter for bolttech form engine",
|
|
5
5
|
"module": "./index.esm.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./index.esm.js",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@bolttech/form-engine-core": "0.0
|
|
9
|
+
"@bolttech/form-engine-core": "1.0.0-beta.1",
|
|
10
10
|
"react": "18.2.0",
|
|
11
11
|
"rxjs": "7.8.1"
|
|
12
12
|
},
|