sygnal 2.0.1 → 2.2.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/README.md CHANGED
@@ -24,7 +24,7 @@ Sygnal provides a structured way to create Cycle.js components that accomplishes
24
24
  - Handle all stream plumbing between components
25
25
  - Support arbitrarily complex applications with deep component hierarchies
26
26
  - Reuse the best patterns from popular frameworks like React and Vue while avoiding the pitfalls
27
- - Support pure Javascript, Typescript, and JSX
27
+ - Support pure Javascript, Typescript, and JSX (including fragments)
28
28
  - Provide application state out of the box, and make it easy to use
29
29
  - Use reasonable defaults while providing access to low-level Cycle.js functionality wherever possible
30
30
  - Provide automatic debugging information
@@ -106,7 +106,22 @@ The results will be in the 'dist' folder, and you can serve it locally by runnin
106
106
  npm preview
107
107
  ```
108
108
 
109
- Alternatively, you can use any other bundler of your choice (Webpack, Babel, Rollup, etc.). To use JSX in your components while using alternative bundlers, you will need to install [snabbdom-pragma](https://www.npmjs.com/package/snabbdom-pragma) and configure your bundler to use it for transforming JSX (see [examples here](https://www.npmjs.com/package/snabbdom-pragma#usage "snabbdom-pragma bundler configuration examples")).
109
+ Alternatively, you can use any other bundler of your choice (Webpack, Babel, Rollup, etc.). To use JSX in your components while using alternative bundlers, you will need to configure your bundler to use Sygnal's JSX pragma. This is slightly different for each bundler, but looks generally like:
110
+
111
+ ```javascript
112
+ // this example is for Vite or esbuild, but most bundlers have options similar to this for handling JSX transpiling
113
+ {
114
+ ...,
115
+ esbuild: {
116
+ // add the import for Sygnal's JSX and Fragment handler to the top of each .jsx and .tsx page automatically
117
+ jsxInject: `import { jsx, Fragment } from 'sygnal/jsx'`,
118
+ // tell the transpiler to use Sygnal's 'jsx' funtion to render JSX elements
119
+ jsxFactory: `jsx`,
120
+ // tell the transpiler to use Sygnal's 'Fragment' funtion to render JSX fragments (<>...</>)
121
+ jsxFragment: 'Fragment'
122
+ },
123
+ }
124
+ ```
110
125
 
111
126
 
112
127
  ## Initialization
@@ -26,10 +26,21 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
26
26
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
27
 
28
28
  function collection(component, stateLense) {
29
- var combineList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ['DOM'];
30
- var globalList = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : ['EVENTS'];
31
- var stateSourceName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'STATE';
29
+ var opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
30
+ var _opts$combineList = opts.combineList,
31
+ combineList = _opts$combineList === void 0 ? ['DOM'] : _opts$combineList,
32
+ _opts$globalList = opts.globalList,
33
+ globalList = _opts$globalList === void 0 ? ['EVENTS'] : _opts$globalList,
34
+ _opts$stateSourceName = opts.stateSourceName,
35
+ stateSourceName = _opts$stateSourceName === void 0 ? 'STATE' : _opts$stateSourceName,
36
+ _opts$domSourceName = opts.domSourceName,
37
+ domSourceName = _opts$domSourceName === void 0 ? 'DOM' : _opts$domSourceName,
38
+ _opts$container = opts.container,
39
+ container = _opts$container === void 0 ? 'div' : _opts$container,
40
+ _opts$containerClass = opts.containerClass,
41
+ containerClass = _opts$containerClass === void 0 ? '' : _opts$containerClass;
32
42
  return function (sources) {
43
+ var key = Date.now();
33
44
  var collectionOpts = {
34
45
  item: component,
35
46
  itemKey: function itemKey(state, ind) {
@@ -46,7 +57,27 @@ function collection(component, stateLense) {
46
57
  stream = _ref2[1];
47
58
 
48
59
  if (combineList.includes(name)) {
49
- acc[name] = instances.pickCombine(name);
60
+ var combined = instances.pickCombine(name);
61
+
62
+ if (name === domSourceName && container) {
63
+ acc.DOM = combined.map(function (children) {
64
+ return {
65
+ sel: container,
66
+ data: {
67
+ props: {
68
+ className: containerClass
69
+ }
70
+ },
71
+ children: children,
72
+ key: key,
73
+ text: undefined,
74
+ elm: undefined
75
+ };
76
+ });
77
+ } else {
78
+ console.warn('Collections without wrapping containers will fail in unpredictable ways when used inside JSX fragments');
79
+ acc[name] = combined;
80
+ }
50
81
  } else {
51
82
  acc[name] = instances.pickMerge(name);
52
83
  }
package/dist/component.js CHANGED
@@ -10,6 +10,8 @@ var _isolate = _interopRequireDefault(require("@cycle/isolate"));
10
10
 
11
11
  var _collection = _interopRequireDefault(require("./collection.js"));
12
12
 
13
+ var _switchable = _interopRequireDefault(require("./switchable.js"));
14
+
13
15
  var _state2 = require("@cycle/state");
14
16
 
15
17
  var _xstream = _interopRequireWildcard(require("xstream"));
@@ -788,9 +790,42 @@ var Component = /*#__PURE__*/function () {
788
790
  }
789
791
  };
790
792
  sink$ = (0, _collection["default"])(_factory, lense)(sources);
791
- } else if (isSwitchable) {} else {
793
+ } else if (isSwitchable) {
792
794
  var _objectSpread3;
793
795
 
796
+ var stateField = data.props.state;
797
+
798
+ if (typeof stateField === 'string') {
799
+ var _stream = _this8.sources[_this8.stateSourceName].stream;
800
+ propState = new _state2.StateSource(_stream.map(function (val) {
801
+ if (_typeof(val) !== 'object') {
802
+ console.error("Switchable Error: Invalid or undefined state");
803
+ return;
804
+ }
805
+
806
+ var newVal = val[stateField];
807
+
808
+ if (typeof newVal === 'undefined') {
809
+ console.warn("Specified state field '".concat(stateField, "' for switchable element not found"));
810
+ return;
811
+ }
812
+
813
+ return newVal;
814
+ }));
815
+ } else {
816
+ propState = _this8.sources[_this8.stateSourceName];
817
+ }
818
+
819
+ var switchableComponents = data.props.of;
820
+
821
+ var _sources = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, _this8.stateSourceName, propState), _defineProperty(_objectSpread3, "props$", props$), _defineProperty(_objectSpread3, "children$", children$), _objectSpread3));
822
+
823
+ sink$ = (0, _switchable["default"])(switchableComponents, props$.map(function (props) {
824
+ return props.current;
825
+ }))(_sources);
826
+ } else {
827
+ var _objectSpread4;
828
+
794
829
  var _lense = function _lense(props) {
795
830
  var state = props.state;
796
831
  if (typeof state === 'undefined') return props;
@@ -804,9 +839,9 @@ var Component = /*#__PURE__*/function () {
804
839
 
805
840
  propState = new _state2.StateSource(props$.map(_lense));
806
841
 
807
- var _sources = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread3 = {}, _defineProperty(_objectSpread3, _this8.stateSourceName, propState), _defineProperty(_objectSpread3, "props$", props$), _defineProperty(_objectSpread3, "children$", children$), _objectSpread3));
842
+ var _sources2 = _objectSpread(_objectSpread({}, _this8.sources), {}, (_objectSpread4 = {}, _defineProperty(_objectSpread4, _this8.stateSourceName, propState), _defineProperty(_objectSpread4, "props$", props$), _defineProperty(_objectSpread4, "children$", children$), _objectSpread4));
808
843
 
809
- sink$ = factory(_sources);
844
+ sink$ = factory(_sources2);
810
845
  }
811
846
 
812
847
  var originalDOMSink = sink$[_this8.DOMSourceName];
@@ -1080,7 +1115,7 @@ function getComponents(currentElement, componentNames) {
1080
1115
  var sel = currentElement.sel;
1081
1116
  var isCollection = sel && sel.toLowerCase() === 'collection';
1082
1117
  var isSwitchable = sel && sel.toLowerCase() === 'switchable';
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';
1118
+ 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';
1084
1119
  var props = currentElement.data && currentElement.data.props || {};
1085
1120
  var children = currentElement.children || [];
1086
1121
  var found = {};
@@ -1094,20 +1129,17 @@ function getComponents(currentElement, componentNames) {
1094
1129
  if (!componentNames.includes(props.of)) throw new Error("Specified component for collection not found: ".concat(props.of));
1095
1130
  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"));
1096
1131
  currentElement.data.isCollection = true;
1097
- currentElement.data.component = props.component; // currentElement.data.componentArray = props.value
1098
1132
  } else if (isSwitchable) {
1099
- if (!props.components) throw new Error("Switchable element missing required 'components' property");
1100
- if (_typeof(props.components) !== 'object') throw new Error("Invalid 'components' property of switchable element: found ".concat(_typeof(props.components), " requires object mapping names to component factories"));
1101
- var switchableComponents = Object.values(props.components);
1133
+ if (!props.of) throw new Error("Switchable element missing required 'of' property");
1134
+ 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"));
1135
+ var switchableComponents = Object.values(props.of);
1102
1136
  if (!switchableComponents.every(function (comp) {
1103
1137
  return typeof comp === 'function';
1104
- })) throw new Error("One or more invalid component factories for switchable element is not a valid component factory");
1105
- if (!props.current || typeof props.current !== 'string') throw new Error("Missing or invalid 'current' property for switchable element: found ".concat(_typeof(props.current), " requires string"));
1106
- var switchableComponentNames = Object.keys(props.components);
1138
+ })) throw new Error("One or more components provided to switchable element is not a valid component factory");
1139
+ if (!props.current || typeof props.current !== 'string' && typeof props.current !== 'function') throw new Error("Missing or invalid 'current' property for switchable element: found '".concat(_typeof(props.current), "' requires string or function"));
1140
+ var switchableComponentNames = Object.keys(props.of);
1107
1141
  if (!switchableComponentNames.includes(props.current)) throw new Error("Component '".concat(props.current, "' not found in switchable element"));
1108
1142
  currentElement.data.isSwitchable = true;
1109
- currentElement.data.components = props.components;
1110
- currentElement.data.currentComponent = props.current;
1111
1143
  } else {}
1112
1144
 
1113
1145
  found[id] = currentElement;
@@ -1138,7 +1170,7 @@ function injectComponents(currentElement, components, componentNames) {
1138
1170
  if ((_currentElement$data4 = currentElement.data) !== null && _currentElement$data4 !== void 0 && _currentElement$data4.componentsInjected) return currentElement;
1139
1171
  if (!isNestedElement && currentElement.data) currentElement.data.componentsInjected = true;
1140
1172
  var sel = currentElement.sel || 'NO SELECTOR';
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';
1173
+ var isComponent = ['collection', 'switchable', '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
1174
  var isCollection = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data7 = currentElement.data) === null || _currentElement$data7 === void 0 ? void 0 : _currentElement$data7.isCollection;
1143
1175
  var isSwitchable = currentElement === null || currentElement === void 0 ? void 0 : (_currentElement$data8 = currentElement.data) === null || _currentElement$data8 === void 0 ? void 0 : _currentElement$data8.isSwitchable;
1144
1176
  var props = currentElement.data && currentElement.data.props || {};
@@ -1153,6 +1185,8 @@ function injectComponents(currentElement, components, componentNames) {
1153
1185
  delete currentElement.elm;
1154
1186
  currentElement.children = _component;
1155
1187
  return currentElement;
1188
+ } else if (isSwitchable) {
1189
+ return _component;
1156
1190
  } else {
1157
1191
  return _component;
1158
1192
  }
package/dist/extra/run.js CHANGED
@@ -25,10 +25,21 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
25
25
 
26
26
  function run(app) {
27
27
  var drivers = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
28
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
29
+ var _options$mountPoint = options.mountPoint,
30
+ mountPoint = _options$mountPoint === void 0 ? '#root' : _options$mountPoint,
31
+ _options$fragments = options.fragments,
32
+ fragments = _options$fragments === void 0 ? true : _options$fragments;
28
33
  var wrapped = (0, _state.withState)(app, 'STATE');
29
34
  var baseDrivers = {
30
35
  EVENTS: _eventDriver["default"],
31
- DOM: (0, _dom.makeDOMDriver)('#root'),
36
+ DOM: (0, _dom.makeDOMDriver)(mountPoint, {
37
+ snabbdomOptions: {
38
+ experimental: {
39
+ fragments: fragments
40
+ }
41
+ }
42
+ }),
32
43
  LOG: _logDriver["default"]
33
44
  };
34
45
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';
1
+ 'use strict'; // export sygnal core functions
2
2
 
3
3
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
4
 
@@ -13,7 +13,12 @@ var _exportNames = {
13
13
  processForm: true,
14
14
  run: true,
15
15
  classes: true,
16
- xs: true
16
+ xs: true,
17
+ debounce: true,
18
+ throttle: true,
19
+ delay: true,
20
+ dropRepeats: true,
21
+ sampleCombine: true
17
22
  };
18
23
  Object.defineProperty(exports, "ABORT", {
19
24
  enumerable: true,
@@ -39,6 +44,24 @@ Object.defineProperty(exports, "component", {
39
44
  return _component["default"];
40
45
  }
41
46
  });
47
+ Object.defineProperty(exports, "debounce", {
48
+ enumerable: true,
49
+ get: function get() {
50
+ return _debounce["default"];
51
+ }
52
+ });
53
+ Object.defineProperty(exports, "delay", {
54
+ enumerable: true,
55
+ get: function get() {
56
+ return _delay["default"];
57
+ }
58
+ });
59
+ Object.defineProperty(exports, "dropRepeats", {
60
+ enumerable: true,
61
+ get: function get() {
62
+ return _dropRepeats["default"];
63
+ }
64
+ });
42
65
  Object.defineProperty(exports, "processForm", {
43
66
  enumerable: true,
44
67
  get: function get() {
@@ -51,12 +74,24 @@ Object.defineProperty(exports, "run", {
51
74
  return _run["default"];
52
75
  }
53
76
  });
77
+ Object.defineProperty(exports, "sampleCombine", {
78
+ enumerable: true,
79
+ get: function get() {
80
+ return _sampleCombine["default"];
81
+ }
82
+ });
54
83
  Object.defineProperty(exports, "switchable", {
55
84
  enumerable: true,
56
85
  get: function get() {
57
86
  return _switchable["default"];
58
87
  }
59
88
  });
89
+ Object.defineProperty(exports, "throttle", {
90
+ enumerable: true,
91
+ get: function get() {
92
+ return _throttle["default"];
93
+ }
94
+ });
60
95
  Object.defineProperty(exports, "xs", {
61
96
  enumerable: true,
62
97
  get: function get() {
@@ -92,6 +127,16 @@ Object.keys(_dom).forEach(function (key) {
92
127
 
93
128
  var _xstream = _interopRequireDefault(require("xstream"));
94
129
 
130
+ var _debounce = _interopRequireDefault(require("xstream/extra/debounce"));
131
+
132
+ var _throttle = _interopRequireDefault(require("xstream/extra/throttle"));
133
+
134
+ var _delay = _interopRequireDefault(require("xstream/extra/delay"));
135
+
136
+ var _dropRepeats = _interopRequireDefault(require("xstream/extra/dropRepeats"));
137
+
138
+ var _sampleCombine = _interopRequireDefault(require("xstream/extra/sampleCombine"));
139
+
95
140
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
96
141
 
97
142
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
package/dist/jsx.js CHANGED
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "Fragment", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _snabbdom.Fragment;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "jsx", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -10,4 +16,6 @@ Object.defineProperty(exports, "jsx", {
10
16
  }
11
17
  });
12
18
 
13
- var _index = require("./pragma/index");
19
+ var _index = require("./pragma/index");
20
+
21
+ var _snabbdom = require("snabbdom");
@@ -121,17 +121,21 @@ var createElementWithModules = function createElementWithModules(modules) {
121
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
122
  }
123
123
 
124
+ for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
125
+ children[_key - 2] = arguments[_key];
126
+ }
127
+
124
128
  if (is.fun(sel)) {
129
+ if (sel.name === 'Fragment') {
130
+ return sel(data || {}, children);
131
+ }
132
+
125
133
  var factory = sel;
126
134
  sel = sel.name || 'sygnal-factory';
127
135
  data || (data = {});
128
136
  data.sygnalFactory = factory;
129
137
  }
130
138
 
131
- for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
132
- children[_key - 2] = arguments[_key];
133
- }
134
-
135
139
  var text = sanitizeText(children, modules);
136
140
  return considerSvg({
137
141
  sel: sel,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sygnal",
3
- "version": "2.0.1",
3
+ "version": "2.2.0",
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": {
@@ -36,6 +36,7 @@
36
36
  "@cycle/run": "^5.7.0",
37
37
  "@cycle/state": "^1.7.0",
38
38
  "extend": "^3.0.2",
39
+ "snabbdom": "^3.5.0",
39
40
  "xstream": "^11.14.0"
40
41
  },
41
42
  "devDependencies": {
Binary file
package/sygnal-1.2.1.tgz DELETED
Binary file
package/sygnal-2.0.0.tgz DELETED
Binary file