sygnal 2.2.0 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collection.js +7 -7
- package/dist/component.js +68 -43
- package/dist/pragma/index.js +1 -1
- package/package.json +1 -1
- package/sygnal-2.1.1.tgz +0 -0
package/dist/collection.js
CHANGED
|
@@ -37,8 +37,7 @@ function collection(component, stateLense) {
|
|
|
37
37
|
domSourceName = _opts$domSourceName === void 0 ? 'DOM' : _opts$domSourceName,
|
|
38
38
|
_opts$container = opts.container,
|
|
39
39
|
container = _opts$container === void 0 ? 'div' : _opts$container,
|
|
40
|
-
|
|
41
|
-
containerClass = _opts$containerClass === void 0 ? '' : _opts$containerClass;
|
|
40
|
+
containerClass = opts.containerClass;
|
|
42
41
|
return function (sources) {
|
|
43
42
|
var key = Date.now();
|
|
44
43
|
var collectionOpts = {
|
|
@@ -61,13 +60,14 @@ function collection(component, stateLense) {
|
|
|
61
60
|
|
|
62
61
|
if (name === domSourceName && container) {
|
|
63
62
|
acc.DOM = combined.map(function (children) {
|
|
63
|
+
var data = containerClass ? {
|
|
64
|
+
props: {
|
|
65
|
+
className: containerClass
|
|
66
|
+
}
|
|
67
|
+
} : {};
|
|
64
68
|
return {
|
|
65
69
|
sel: container,
|
|
66
|
-
data:
|
|
67
|
-
props: {
|
|
68
|
-
className: containerClass
|
|
69
|
-
}
|
|
70
|
-
},
|
|
70
|
+
data: data,
|
|
71
71
|
children: children,
|
|
72
72
|
key: key,
|
|
73
73
|
text: undefined,
|
package/dist/component.js
CHANGED
|
@@ -751,24 +751,16 @@ var Component = /*#__PURE__*/function () {
|
|
|
751
751
|
|
|
752
752
|
var children$ = _xstream["default"].create().startWith(children);
|
|
753
753
|
|
|
754
|
-
var
|
|
754
|
+
var stateSource;
|
|
755
755
|
var sink$;
|
|
756
756
|
|
|
757
757
|
if (isCollection) {
|
|
758
|
-
var
|
|
758
|
+
var _objectSpread3;
|
|
759
759
|
|
|
760
|
-
var
|
|
760
|
+
var field, lense;
|
|
761
761
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
stream = _this8.sources[_this8.stateSourceName].stream;
|
|
765
|
-
} else {
|
|
766
|
-
field = 'for';
|
|
767
|
-
stream = props$;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
propState = new _state2.StateSource(stream.map(function (val) {
|
|
771
|
-
var arr = val[field];
|
|
762
|
+
var stateGetter = function stateGetter(state) {
|
|
763
|
+
var arr = state[field];
|
|
772
764
|
|
|
773
765
|
if (!Array.isArray(arr)) {
|
|
774
766
|
console.warn("Collection of ".concat(data.props.of, " does not have a valid array in the 'for' property: expects either an array or a string of the name of an array property on the state"));
|
|
@@ -776,28 +768,45 @@ var Component = /*#__PURE__*/function () {
|
|
|
776
768
|
}
|
|
777
769
|
|
|
778
770
|
return arr;
|
|
779
|
-
}
|
|
771
|
+
};
|
|
780
772
|
|
|
781
|
-
|
|
773
|
+
if (typeof props["for"] === 'string') {
|
|
774
|
+
field = props["for"];
|
|
775
|
+
stateSource = _this8.sources[_this8.stateSourceName];
|
|
776
|
+
lense = {
|
|
777
|
+
get: stateGetter,
|
|
778
|
+
set: function set(state, arr) {
|
|
779
|
+
return _objectSpread(_objectSpread({}, state), {}, _defineProperty({}, field, arr));
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
} else {
|
|
783
|
+
field = 'for';
|
|
784
|
+
stateSource = new _state2.StateSource(props$.remember());
|
|
785
|
+
lense = {
|
|
786
|
+
get: stateGetter,
|
|
787
|
+
set: function set(state, arr) {
|
|
788
|
+
return state;
|
|
789
|
+
}
|
|
790
|
+
};
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
var sources = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, _this8.stateSourceName, stateSource), _defineProperty(_objectSpread3, "props$", props$), _defineProperty(_objectSpread3, "children$", children$), _objectSpread3));
|
|
794
|
+
|
|
795
|
+
var _factory = typeof data.props.of === 'function' ? data.props.of : _this8.components[data.props.of];
|
|
782
796
|
|
|
783
|
-
var _factory = _this8.components[data.props.of];
|
|
784
|
-
var lense = {
|
|
785
|
-
get: function get(state) {
|
|
786
|
-
return state;
|
|
787
|
-
},
|
|
788
|
-
set: function set(state) {
|
|
789
|
-
return state;
|
|
790
|
-
}
|
|
791
|
-
};
|
|
792
797
|
sink$ = (0, _collection["default"])(_factory, lense)(sources);
|
|
798
|
+
|
|
799
|
+
if (_typeof(sink$) !== 'object') {
|
|
800
|
+
throw new Error('Invalid sinks returned from component factory of collection element');
|
|
801
|
+
}
|
|
793
802
|
} else if (isSwitchable) {
|
|
794
|
-
var
|
|
803
|
+
var _objectSpread4;
|
|
795
804
|
|
|
796
805
|
var stateField = data.props.state;
|
|
797
806
|
|
|
798
807
|
if (typeof stateField === 'string') {
|
|
799
|
-
var
|
|
800
|
-
|
|
808
|
+
var stream = _this8.sources[_this8.stateSourceName].stream;
|
|
809
|
+
stateSource = new _state2.StateSource(stream.map(function (val) {
|
|
801
810
|
if (_typeof(val) !== 'object') {
|
|
802
811
|
console.error("Switchable Error: Invalid or undefined state");
|
|
803
812
|
return;
|
|
@@ -813,18 +822,22 @@ var Component = /*#__PURE__*/function () {
|
|
|
813
822
|
return newVal;
|
|
814
823
|
}));
|
|
815
824
|
} else {
|
|
816
|
-
|
|
825
|
+
stateSource = _this8.sources[_this8.stateSourceName];
|
|
817
826
|
}
|
|
818
827
|
|
|
819
828
|
var switchableComponents = data.props.of;
|
|
820
829
|
|
|
821
|
-
var _sources = _objectSpread(_objectSpread({}, _this8.sources), {}, (
|
|
830
|
+
var _sources = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, _this8.stateSourceName, stateSource), _defineProperty(_objectSpread4, "props$", props$), _defineProperty(_objectSpread4, "children$", children$), _objectSpread4));
|
|
822
831
|
|
|
823
832
|
sink$ = (0, _switchable["default"])(switchableComponents, props$.map(function (props) {
|
|
824
833
|
return props.current;
|
|
825
834
|
}))(_sources);
|
|
835
|
+
|
|
836
|
+
if (_typeof(sink$) !== 'object') {
|
|
837
|
+
throw new Error('Invalid sinks returned from component factory of switchable element');
|
|
838
|
+
}
|
|
826
839
|
} else {
|
|
827
|
-
var
|
|
840
|
+
var _objectSpread5;
|
|
828
841
|
|
|
829
842
|
var _lense = function _lense(props) {
|
|
830
843
|
var state = props.state;
|
|
@@ -837,15 +850,21 @@ var Component = /*#__PURE__*/function () {
|
|
|
837
850
|
return _objectSpread(_objectSpread({}, copy), state);
|
|
838
851
|
};
|
|
839
852
|
|
|
840
|
-
|
|
853
|
+
stateSource = new _state2.StateSource(props$.map(_lense));
|
|
841
854
|
|
|
842
|
-
var _sources2 = _objectSpread(_objectSpread({}, _this8.sources), {}, (
|
|
855
|
+
var _sources2 = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread5 = {}, _defineProperty(_objectSpread5, _this8.stateSourceName, stateSource), _defineProperty(_objectSpread5, "props$", props$), _defineProperty(_objectSpread5, "children$", children$), _objectSpread5));
|
|
843
856
|
|
|
844
857
|
sink$ = factory(_sources2);
|
|
858
|
+
|
|
859
|
+
if (_typeof(sink$) !== 'object') {
|
|
860
|
+
var name = componentName === 'sygnal-factory' ? 'custom element' : componentName;
|
|
861
|
+
throw new Error('Invalid sinks returned from component factory:', name);
|
|
862
|
+
}
|
|
845
863
|
}
|
|
846
864
|
|
|
847
|
-
var originalDOMSink = sink$[_this8.DOMSourceName];
|
|
848
|
-
|
|
865
|
+
var originalDOMSink = sink$[_this8.DOMSourceName].remember();
|
|
866
|
+
|
|
867
|
+
sink$[_this8.DOMSourceName] = stateSource.stream.map(function (state) {
|
|
849
868
|
return originalDOMSink.compose((0, _debounce["default"])(10));
|
|
850
869
|
}).flatten();
|
|
851
870
|
acc[id] = {
|
|
@@ -1117,6 +1136,7 @@ function getComponents(currentElement, componentNames) {
|
|
|
1117
1136
|
var isSwitchable = sel && sel.toLowerCase() === 'switchable';
|
|
1118
1137
|
var isComponent = sel && ['collection', 'switchable', 'sygnal-factory'].concat(_toConsumableArray(componentNames)).includes(currentElement.sel) || typeof ((_currentElement$data2 = currentElement.data) === null || _currentElement$data2 === void 0 ? void 0 : (_currentElement$data3 = _currentElement$data2.props) === null || _currentElement$data3 === void 0 ? void 0 : _currentElement$data3.sygnalFactory) === 'function';
|
|
1119
1138
|
var props = currentElement.data && currentElement.data.props || {};
|
|
1139
|
+
var attrs = currentElement.data && currentElement.data.attrs || {};
|
|
1120
1140
|
var children = currentElement.children || [];
|
|
1121
1141
|
var found = {};
|
|
1122
1142
|
|
|
@@ -1124,11 +1144,16 @@ function getComponents(currentElement, componentNames) {
|
|
|
1124
1144
|
var id = getComponentIdFromElement(currentElement);
|
|
1125
1145
|
|
|
1126
1146
|
if (isCollection) {
|
|
1147
|
+
var _currentElement$data4;
|
|
1148
|
+
|
|
1127
1149
|
if (!props.of) throw new Error("Collection element missing required 'component' property");
|
|
1128
|
-
if (typeof props.of !== 'string') throw new Error("Invalid 'component' property of collection element: found ".concat(_typeof(props.of), " requires string"));
|
|
1129
|
-
if (!componentNames.includes(props.of)) throw new Error("Specified component for collection not found: ".concat(props.of));
|
|
1130
|
-
if (!
|
|
1150
|
+
if (typeof props.of !== 'string' && typeof props.of !== 'function') throw new Error("Invalid 'component' property of collection element: found ".concat(_typeof(props.of), " requires string or component factory function"));
|
|
1151
|
+
if (typeof props.of !== 'function' && !componentNames.includes(props.of)) throw new Error("Specified component for collection not found: ".concat(props.of));
|
|
1152
|
+
if (!attrs["for"] || !(typeof attrs["for"] === 'string' || Array.isArray(attrs["for"]))) console.warn("No valid array found in the 'value' property of collection ".concat(props.of, ": no collection components will be created"));
|
|
1131
1153
|
currentElement.data.isCollection = true;
|
|
1154
|
+
(_currentElement$data4 = currentElement.data).props || (_currentElement$data4.props = {});
|
|
1155
|
+
currentElement.data.props["for"] = attrs["for"];
|
|
1156
|
+
currentElement.data.attrs = undefined;
|
|
1132
1157
|
} else if (isSwitchable) {
|
|
1133
1158
|
if (!props.of) throw new Error("Switchable element missing required 'of' property");
|
|
1134
1159
|
if (_typeof(props.of) !== 'object') throw new Error("Invalid 'components' property of switchable element: found ".concat(_typeof(props.of), " requires object mapping names to component factories"));
|
|
@@ -1163,16 +1188,16 @@ function getComponents(currentElement, componentNames) {
|
|
|
1163
1188
|
}
|
|
1164
1189
|
|
|
1165
1190
|
function injectComponents(currentElement, components, componentNames) {
|
|
1166
|
-
var _currentElement$
|
|
1191
|
+
var _currentElement$data5, _currentElement$data6, _currentElement$data7, _currentElement$data8, _currentElement$data9;
|
|
1167
1192
|
|
|
1168
1193
|
var isNestedElement = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
1169
1194
|
if (!currentElement) return;
|
|
1170
|
-
if ((_currentElement$
|
|
1195
|
+
if ((_currentElement$data5 = currentElement.data) !== null && _currentElement$data5 !== void 0 && _currentElement$data5.componentsInjected) return currentElement;
|
|
1171
1196
|
if (!isNestedElement && currentElement.data) currentElement.data.componentsInjected = true;
|
|
1172
1197
|
var sel = currentElement.sel || 'NO SELECTOR';
|
|
1173
|
-
var isComponent = ['collection', 'switchable', 'sygnal-factory'].concat(_toConsumableArray(componentNames)).includes(sel) || typeof ((_currentElement$
|
|
1174
|
-
var isCollection = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$
|
|
1175
|
-
var isSwitchable = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$
|
|
1198
|
+
var isComponent = ['collection', 'switchable', 'sygnal-factory'].concat(_toConsumableArray(componentNames)).includes(sel) || typeof ((_currentElement$data6 = currentElement.data) === null || _currentElement$data6 === void 0 ? void 0 : (_currentElement$data7 = _currentElement$data6.props) === null || _currentElement$data7 === void 0 ? void 0 : _currentElement$data7.sygnalFactory) === 'function';
|
|
1199
|
+
var isCollection = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data8 = currentElement.data) === null || _currentElement$data8 === void 0 ? void 0 : _currentElement$data8.isCollection;
|
|
1200
|
+
var isSwitchable = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data9 = currentElement.data) === null || _currentElement$data9 === void 0 ? void 0 : _currentElement$data9.isSwitchable;
|
|
1176
1201
|
var props = currentElement.data && currentElement.data.props || {};
|
|
1177
1202
|
var children = currentElement.children || [];
|
|
1178
1203
|
|
|
@@ -1183,7 +1208,7 @@ function injectComponents(currentElement, components, componentNames) {
|
|
|
1183
1208
|
if (isCollection) {
|
|
1184
1209
|
currentElement.sel = 'div';
|
|
1185
1210
|
delete currentElement.elm;
|
|
1186
|
-
currentElement.children = _component;
|
|
1211
|
+
currentElement.children = Array.isArray(_component) ? _component : [_component];
|
|
1187
1212
|
return currentElement;
|
|
1188
1213
|
} else if (isSwitchable) {
|
|
1189
1214
|
return _component;
|
package/dist/pragma/index.js
CHANGED
package/package.json
CHANGED
package/sygnal-2.1.1.tgz
DELETED
|
Binary file
|