sygnal 1.2.0 → 2.0.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.
@@ -32,8 +32,8 @@ function collection(component, stateLense) {
32
32
  return function (sources) {
33
33
  var collectionOpts = {
34
34
  item: component,
35
- itemKey: function itemKey(state) {
36
- return state.id;
35
+ itemKey: function itemKey(state, ind) {
36
+ return typeof state.id !== 'undefined' ? state.id : ind;
37
37
  },
38
38
  itemScope: function itemScope(key) {
39
39
  return key;
package/dist/component.js CHANGED
@@ -738,7 +738,12 @@ var Component = /*#__PURE__*/function () {
738
738
  return acc;
739
739
  }
740
740
 
741
- var factory = _this8.components[componentName];
741
+ var factory = componentName === 'sygnal-factory' ? props.sygnalFactory : _this8.components[componentName] || props.sygnalFactory;
742
+
743
+ if (!factory && !isCollection && !isSwitchable) {
744
+ if (componentName === 'sygnal-factory') throw new Error("Component not found on element with Capitalized selector and nameless function: JSX transpilation replaces selectors starting with upper case letters with functions in-scope with the same name, Sygnal cannot see the name of the resulting component.");
745
+ throw new Error("Component not found: ".concat(componentName));
746
+ }
742
747
 
743
748
  var props$ = _xstream["default"].create().startWith(props);
744
749
 
@@ -750,13 +755,30 @@ var Component = /*#__PURE__*/function () {
750
755
  if (isCollection) {
751
756
  var _objectSpread2;
752
757
 
753
- propState = new _state2.StateSource(props$.map(function (val) {
754
- return val.value;
758
+ var stream, field;
759
+
760
+ if (typeof data.props["for"] === 'string') {
761
+ field = data.props["for"];
762
+ stream = _this8.sources[_this8.stateSourceName].stream;
763
+ } else {
764
+ field = 'for';
765
+ stream = props$;
766
+ }
767
+
768
+ propState = new _state2.StateSource(stream.map(function (val) {
769
+ var arr = val[field];
770
+
771
+ if (!Array.isArray(arr)) {
772
+ 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"));
773
+ return [];
774
+ }
775
+
776
+ return arr;
755
777
  }).remember());
756
778
 
757
779
  var sources = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, _this8.stateSourceName, propState), _defineProperty(_objectSpread2, "props$", props$), _defineProperty(_objectSpread2, "children$", children$), _objectSpread2));
758
780
 
759
- var _factory = _this8.components[data.component];
781
+ var _factory = _this8.components[data.props.of];
760
782
  var lense = {
761
783
  get: function get(state) {
762
784
  return state;
@@ -1049,7 +1071,7 @@ function makeLog(context) {
1049
1071
  }
1050
1072
 
1051
1073
  function getComponents(currentElement, componentNames) {
1052
- var _currentElement$data;
1074
+ var _currentElement$data, _currentElement$data2, _currentElement$data3;
1053
1075
 
1054
1076
  var isNestedElement = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1055
1077
  if (!currentElement) return {};
@@ -1058,7 +1080,7 @@ function getComponents(currentElement, componentNames) {
1058
1080
  var sel = currentElement.sel;
1059
1081
  var isCollection = sel && sel.toLowerCase() === 'collection';
1060
1082
  var isSwitchable = sel && sel.toLowerCase() === 'switchable';
1061
- var isComponent = sel && ['collection', 'swtichable'].concat(_toConsumableArray(componentNames)).includes(currentElement.sel);
1083
+ var isComponent = sel && ['collection', 'swtichable', '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';
1062
1084
  var props = currentElement.data && currentElement.data.props || {};
1063
1085
  var children = currentElement.children || [];
1064
1086
  var found = {};
@@ -1067,10 +1089,10 @@ function getComponents(currentElement, componentNames) {
1067
1089
  var id = getComponentIdFromElement(currentElement);
1068
1090
 
1069
1091
  if (isCollection) {
1070
- if (!props.component) throw new Error("Collection element missing required 'component' property");
1071
- if (typeof props.component !== 'string') throw new Error("Invalid 'component' property of collection element: found ".concat(_typeof(props.component), " requires string"));
1072
- if (!componentNames.includes(props.component)) throw new Error("Specified component for collection not found: ".concat(props.component));
1073
- if (!props.value || !Array.isArray(props.value)) console.warn("No valid array found in the 'value' property of collection ".concat(props.component, ": no collection components will be created"));
1092
+ if (!props.of) throw new Error("Collection element missing required 'component' property");
1093
+ if (typeof props.of !== 'string') throw new Error("Invalid 'component' property of collection element: found ".concat(_typeof(props.of), " requires string"));
1094
+ if (!componentNames.includes(props.of)) throw new Error("Specified component for collection not found: ".concat(props.of));
1095
+ if (!props["for"] || !(typeof props["for"] === 'string' || Array.isArray(props["for"]))) console.warn("No valid array found in the 'value' property of collection ".concat(props.of, ": no collection components will be created"));
1074
1096
  currentElement.data.isCollection = true;
1075
1097
  currentElement.data.component = props.component; // currentElement.data.componentArray = props.value
1076
1098
  } else if (isSwitchable) {
@@ -1109,16 +1131,16 @@ function getComponents(currentElement, componentNames) {
1109
1131
  }
1110
1132
 
1111
1133
  function injectComponents(currentElement, components, componentNames) {
1112
- var _currentElement$data2, _currentElement$data3, _currentElement$data4;
1134
+ var _currentElement$data4, _currentElement$data5, _currentElement$data6, _currentElement$data7, _currentElement$data8;
1113
1135
 
1114
1136
  var isNestedElement = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
1115
1137
  if (!currentElement) return;
1116
- if ((_currentElement$data2 = currentElement.data) !== null && _currentElement$data2 !== void 0 && _currentElement$data2.componentsInjected) return currentElement;
1138
+ if ((_currentElement$data4 = currentElement.data) !== null && _currentElement$data4 !== void 0 && _currentElement$data4.componentsInjected) return currentElement;
1117
1139
  if (!isNestedElement && currentElement.data) currentElement.data.componentsInjected = true;
1118
1140
  var sel = currentElement.sel || 'NO SELECTOR';
1119
- var isComponent = ['collection', 'swtichable'].concat(_toConsumableArray(componentNames)).includes(sel);
1120
- var isCollection = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data3 = currentElement.data) === null || _currentElement$data3 === void 0 ? void 0 : _currentElement$data3.isCollection;
1121
- var isSwitchable = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data4 = currentElement.data) === null || _currentElement$data4 === void 0 ? void 0 : _currentElement$data4.isSwitchable;
1141
+ var isComponent = ['collection', 'swtichable', 'sygnal-factory'].concat(_toConsumableArray(componentNames)).includes(sel) || typeof ((_currentElement$data5 = currentElement.data) === null || _currentElement$data5 === void 0 ? void 0 : (_currentElement$data6 = _currentElement$data5.props) === null || _currentElement$data6 === void 0 ? void 0 : _currentElement$data6.sygnalFactory) === 'function';
1142
+ var isCollection = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data7 = currentElement.data) === null || _currentElement$data7 === void 0 ? void 0 : _currentElement$data7.isCollection;
1143
+ var isSwitchable = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data8 = currentElement.data) === null || _currentElement$data8 === void 0 ? void 0 : _currentElement$data8.isSwitchable;
1122
1144
  var props = currentElement.data && currentElement.data.props || {};
1123
1145
  var children = currentElement.children || [];
1124
1146
 
@@ -45,7 +45,7 @@ var considerSvg = function considerSvg(vnode) {
45
45
  };
46
46
 
47
47
  var rewrites = {
48
- "for": 'attrs',
48
+ // for: 'attrs',
49
49
  role: 'attrs',
50
50
  tabindex: 'attrs',
51
51
  'aria-*': 'attrs',
@@ -116,9 +116,16 @@ var defaultModules = {
116
116
 
117
117
  var createElementWithModules = function createElementWithModules(modules) {
118
118
  return function (sel, data) {
119
+ if (typeof sel === 'undefined') {
120
+ sel = 'UNDEFINED';
121
+ cnosole.error('JSX Error: Capitalized HTML element without corresponding Sygnal factory. Components with names where the first letter is capital MUST be defined or included at the parent component\'s file scope.');
122
+ }
123
+
119
124
  if (is.fun(sel)) {
120
- sel = sel.name || 'unnamed';
121
- console.error('JSX Error: A capitalized tag name was used, but was transpiled to a nameless function. Either use a named function or a lower case tag name to avoid this problem');
125
+ var factory = sel;
126
+ sel = sel.name || 'sygnal-factory';
127
+ data || (data = {});
128
+ data.sygnalFactory = factory;
122
129
  }
123
130
 
124
131
  for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
@@ -129,7 +136,7 @@ var createElementWithModules = function createElementWithModules(modules) {
129
136
  return considerSvg({
130
137
  sel: sel,
131
138
  data: data ? sanitizeData(data, modules) : {},
132
- children: text ? undefined : sanitizeChildren(children),
139
+ children: typeof text !== 'undefined' ? undefined : sanitizeChildren(children),
133
140
  text: text,
134
141
  elm: undefined,
135
142
  key: data ? data.key : undefined
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sygnal",
3
- "version": "1.2.0",
3
+ "version": "2.0.1",
4
4
  "description": "An intuitive framework for building fast and small components or applications based on Cycle.js",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
Binary file
Binary file
package/sygnal-1.1.3.tgz DELETED
Binary file