@enact/core 4.5.0-rc.1 → 4.5.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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  The following is a curated list of changes in the Enact core module, newest changes on the top.
4
4
 
5
+ ## [4.5.1] - 2022-08-03
6
+
7
+ No significant changes.
8
+
9
+ ## [4.5.0] - 2022-07-19
10
+
11
+ No significant changes.
12
+
13
+ ## [4.5.0-rc.2] - 2022-07-06
14
+
15
+ ### Changed
16
+
17
+ - `core/handle.forwardCustom` handler to include `preventDefault` and `stopPropagation` methods in the forwarded event payload
18
+
5
19
  ## [4.5.0-rc.1] - 2022-06-23
6
20
 
7
21
  No significant changes.
package/handle/handle.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.stopImmediate = exports.stop = exports.returnsTrue = exports.preventDefault = exports.oneOf = exports.not = exports.log = exports.handle = exports.forwardWithPrevent = exports.forwardCustom = exports.forward = exports.forProp = exports.forKeyCode = exports.forKey = exports.forEventProp = exports["default"] = exports.callOnEvent = exports.call = exports.adaptEvent = void 0;
6
+ exports.stopImmediate = exports.stop = exports.returnsTrue = exports.preventDefault = exports.oneOf = exports.not = exports.log = exports.handle = exports.forwardWithPrevent = exports.forwardCustomWithPrevent = exports.forwardCustom = exports.forward = exports.forProp = exports.forKeyCode = exports.forKey = exports.forEventProp = exports["default"] = exports.callOnEvent = exports.call = exports.adaptEvent = void 0;
7
7
 
8
8
  var _cond = _interopRequireDefault(require("ramda/src/cond"));
9
9
 
@@ -475,7 +475,7 @@ var _preventDefault = handle.preventDefault = callOnEvent('preventDefault');
475
475
  * @param {Object} ev Event payload
476
476
  * @param {Object} props Props object
477
477
  *
478
- * @returns {Boolean} Returns `true` if default action is prevented
478
+ * @returns {Boolean} Returns `false` if default action is prevented
479
479
  * @curried
480
480
  * @memberof core/handle
481
481
  * @private
@@ -795,17 +795,110 @@ var adaptEvent = handle.adaptEvent = (0, _curry["default"])(function (adapter, h
795
795
  exports.adaptEvent = adaptEvent;
796
796
 
797
797
  var forwardCustom = handle.forwardCustom = function (name, adapter) {
798
- return handle(adaptEvent(function () {
799
- var ev = adapter ? adapter.apply(void 0, arguments) : null; // Handle either no adapter or a non-object return from the adapter
798
+ return handle(adaptEvent(function (ev) {
799
+ for (var _len7 = arguments.length, args = new Array(_len7 > 1 ? _len7 - 1 : 0), _key7 = 1; _key7 < _len7; _key7++) {
800
+ args[_key7 - 1] = arguments[_key7];
801
+ }
802
+
803
+ var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null; // Handle either no adapter or a non-object return from the adapter
804
+
805
+ if (!customEventPayload || typeof customEventPayload !== 'object') {
806
+ customEventPayload = {};
807
+ }
800
808
 
801
- if (!ev || typeof ev !== 'object') {
802
- ev = {};
809
+ customEventPayload.type = name;
810
+
811
+ if (typeof customEventPayload.preventDefault !== 'function' && typeof (ev === null || ev === void 0 ? void 0 : ev.preventDefault) === 'function') {
812
+ customEventPayload.preventDefault = ev.preventDefault.bind(ev);
813
+ }
814
+
815
+ if (typeof customEventPayload.stopPropagation !== 'function' && typeof (ev === null || ev === void 0 ? void 0 : ev.stopPropagation) === 'function') {
816
+ customEventPayload.stopPropagation = ev.stopPropagation.bind(ev);
803
817
  }
804
818
 
805
- ev.type = name;
806
- return ev;
819
+ return customEventPayload;
807
820
  }, forward(name))).named('forwardCustom');
808
821
  };
822
+ /**
823
+ * Creates a handler that will forward the event to a function at `name` on `props` with capability
824
+ * to prevent default behavior. If the specified prop is `undefined` or is not a function, it is
825
+ * ignored. The created handler returns `false` when `event.preventDefault()` has been called in a handler.
826
+ *
827
+ * If `adapter` is not specified, a new event payload will be generated with a `type` member with
828
+ * the `name` of the custom event. If `adapter` is specified, the `type` member is added to the
829
+ * value returned by `adapter`.
830
+ *
831
+ * The `adapter` function receives the same arguments as any handler. The value returned from
832
+ * `adapter` is passed as the first argument to `handler` with the remaining arguments kept the
833
+ * same. This is often useful to generate a custom event payload before forwarding on to a callback.
834
+ *
835
+ * Example:
836
+ * ```
837
+ * import {forwardCustomWithPrevent, handle} from '@enact/core/handle';
838
+ *
839
+ * // calls the onChange callback with the event: {type: 'onChange'}
840
+ * const forwardChangePreventDefault = handle(
841
+ * forwardCustomWithPrevent('onChange'),
842
+ * (ev) => console.log('default action', ev)
843
+ * );
844
+ *
845
+ * // calls the onChange callback with the event: {type: 'onChange', index}
846
+ * const forwardChangeWithIndexPreventDefault = handle(
847
+ * forwardCustomWithPrevent('onChange', (ev, {index}) => ({index})),
848
+ * (ev) => console.log('default action', ev)
849
+ * );
850
+ * ```
851
+ *
852
+ * @method forwardCustomWithPrevent
853
+ * @param {String} name Name of method on the `props`
854
+ * @param {EventAdapter} [adapter] Function to adapt the event payload
855
+ *
856
+ * @returns {HandlerFunction} Returns an [event handler]{@link core/handle.EventHandler}
857
+ * (suitable for passing to handle or used directly within
858
+ * `handlers` in [kind]{@link core/kind}) that will forward the
859
+ * custom event and will return `false` if default action is prevented
860
+ * @memberof core/handle
861
+ * @private
862
+ */
863
+
864
+
865
+ exports.forwardCustom = forwardCustom;
866
+ var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function (name, adapter) {
867
+ var prevented = false;
868
+
869
+ var adapterWithPrevent = function adapterWithPrevent(ev) {
870
+ for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) {
871
+ args[_key8 - 1] = arguments[_key8];
872
+ }
873
+
874
+ var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null;
875
+ var existingPreventDefault = null; // Handle either no adapter or a non-object return from the adapter
876
+
877
+ if (!customEventPayload || typeof customEventPayload !== 'object') {
878
+ customEventPayload = {};
879
+ }
880
+
881
+ if (typeof customEventPayload.preventDefault === 'function') {
882
+ existingPreventDefault = customEventPayload.preventDefault;
883
+ } else if (typeof ev.preventDefault === 'function') {
884
+ existingPreventDefault = ev.preventDefault.bind(ev);
885
+ }
886
+
887
+ customEventPayload.preventDefault = function () {
888
+ prevented = true;
889
+
890
+ if (typeof existingPreventDefault === 'function') {
891
+ existingPreventDefault();
892
+ }
893
+ };
894
+
895
+ return customEventPayload;
896
+ };
897
+
898
+ return handle(forwardCustom(name, adapterWithPrevent), function () {
899
+ return !prevented;
900
+ });
901
+ }, 'forwardCustomWithPrevent');
809
902
  /**
810
903
  * Accepts a handler and returns the logical complement of the value returned from the handler.
811
904
  *
@@ -832,8 +925,7 @@ var forwardCustom = handle.forwardCustom = function (name, adapter) {
832
925
  * @public
833
926
  */
834
927
 
835
-
836
- exports.forwardCustom = forwardCustom;
928
+ exports.forwardCustomWithPrevent = forwardCustomWithPrevent;
837
929
 
838
930
  var not = handle.not = function (handler) {
839
931
  return function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enact/core",
3
- "version": "4.5.0-rc.1",
3
+ "version": "4.5.1",
4
4
  "description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -29,9 +29,9 @@
29
29
  "invariant": "^2.2.4",
30
30
  "prop-types": "^15.8.1",
31
31
  "ramda": "^0.28.0",
32
- "react": "^18.0.0",
33
- "react-dom": "^18.0.0",
34
- "react-is": "^18.0.0",
32
+ "react": "^18.2.0",
33
+ "react-dom": "^18.2.0",
34
+ "react-is": "^18.2.0",
35
35
  "warning": "^4.0.3"
36
36
  }
37
37
  }