@enact/core
Advanced tools
Comparing version 4.6.2 to 4.7.0
@@ -5,2 +5,8 @@ # Change Log | ||
## [4.7.0] - 2023-04-25 | ||
### Deprecated | ||
- `windowsPhone` platform in `core/platform.platforms` to be removed in 5.0.0 | ||
## [4.6.2] - 2023-03-09 | ||
@@ -18,3 +24,3 @@ | ||
- `core/dispatcher` to set the default target for event listeners properly when built with the snapshot option | ||
- `core/dispatcher` to set the default target for event listeners properly when built with the snapshot option | ||
@@ -21,0 +27,0 @@ ## [4.0.12] - 2022-09-16 |
@@ -818,30 +818,30 @@ "use strict"; | ||
var forwardCustomWithPrevent = handle.forwardCustomWithPrevent = named(function (name, adapter) { | ||
var prevented = false; | ||
var adapterWithPrevent = function adapterWithPrevent(ev) { | ||
return function (ev) { | ||
for (var _len8 = arguments.length, args = new Array(_len8 > 1 ? _len8 - 1 : 0), _key8 = 1; _key8 < _len8; _key8++) { | ||
args[_key8 - 1] = arguments[_key8]; | ||
} | ||
var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null; | ||
var existingPreventDefault = null; | ||
var prevented = false; | ||
var adapterWithPrevent = function adapterWithPrevent() { | ||
var customEventPayload = adapter ? adapter.apply(void 0, [ev].concat(args)) : null; | ||
var existingPreventDefault = null; | ||
// Handle either no adapter or a non-object return from the adapter | ||
if (!customEventPayload || typeof customEventPayload !== 'object') { | ||
customEventPayload = {}; | ||
} | ||
if (typeof customEventPayload.preventDefault === 'function') { | ||
existingPreventDefault = customEventPayload.preventDefault; | ||
} else if (typeof ev.preventDefault === 'function') { | ||
existingPreventDefault = ev.preventDefault.bind(ev); | ||
} | ||
customEventPayload.preventDefault = function () { | ||
prevented = true; | ||
if (typeof existingPreventDefault === 'function') { | ||
existingPreventDefault(); | ||
// Handle either no adapter or a non-object return from the adapter | ||
if (!customEventPayload || typeof customEventPayload !== 'object') { | ||
customEventPayload = {}; | ||
} | ||
if (typeof customEventPayload.preventDefault === 'function') { | ||
existingPreventDefault = customEventPayload.preventDefault; | ||
} else if (typeof (ev === null || ev === void 0 ? void 0 : ev.preventDefault) === 'function') { | ||
existingPreventDefault = ev.preventDefault.bind(ev); | ||
} | ||
customEventPayload.preventDefault = function () { | ||
prevented = true; | ||
if (typeof existingPreventDefault === 'function') { | ||
existingPreventDefault(ev); | ||
} | ||
}; | ||
return customEventPayload; | ||
}; | ||
return customEventPayload; | ||
return forwardCustom(name, adapterWithPrevent).apply(void 0, [ev].concat(args)) && !prevented; | ||
}; | ||
return handle(forwardCustom(name, adapterWithPrevent), function () { | ||
return !prevented; | ||
}); | ||
}, 'forwardCustomWithPrevent'); | ||
@@ -848,0 +848,0 @@ |
@@ -449,2 +449,101 @@ "use strict"; | ||
}); | ||
describe('#forwardCustomWithPrevent', function () { | ||
test('should pass an object with `type` and `preventDefault` when no adapter is provided', function () { | ||
var handler = jest.fn(); | ||
(0, _handle.forwardCustomWithPrevent)('onCustomEvent')(null, { | ||
onCustomEvent: handler | ||
}); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toEqual(expect.objectContaining({ | ||
type: 'onCustomEvent', | ||
preventDefault: expect.any(Function) | ||
})); | ||
}); | ||
test('should add `type` and `preventDefault` to object returned by adapter', function () { | ||
var handler = jest.fn(); | ||
var adapter = function adapter() { | ||
return { | ||
index: 0 | ||
}; | ||
}; | ||
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(null, { | ||
onCustomEvent: handler | ||
}); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toEqual(expect.objectContaining({ | ||
type: 'onCustomEvent', | ||
preventDefault: expect.any(Function), | ||
index: 0 | ||
})); | ||
}); | ||
test('should create an event payload if the adapter returns nothing', function () { | ||
var handler = jest.fn(); | ||
var adapter = function adapter() { | ||
return null; | ||
}; | ||
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(null, { | ||
onCustomEvent: handler | ||
}); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toEqual(expect.objectContaining({ | ||
type: 'onCustomEvent', | ||
preventDefault: expect.any(Function) | ||
})); | ||
}); | ||
test('should pass an object with `preventDefault` and `stopPropagation` when event has them', function () { | ||
var ev = { | ||
preventDefault: jest.fn(), | ||
stopPropagation: function stopPropagation() {} | ||
}; | ||
var handler = jest.fn(); | ||
var adapter = function adapter() { | ||
return null; | ||
}; | ||
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter)(ev, { | ||
onCustomEvent: handler | ||
}); | ||
var actual = handler.mock.calls[0][0]; | ||
expect(actual).toEqual(expect.objectContaining({ | ||
type: 'onCustomEvent', | ||
preventDefault: expect.any(Function), | ||
stopPropagation: expect.any(Function) | ||
})); | ||
actual.preventDefault(); | ||
expect(ev.preventDefault).toHaveBeenCalled(); | ||
}); | ||
test('should pass event, props, and context args to adapter', function () { | ||
var adapter = jest.fn(); | ||
var args = [1, | ||
// ev, | ||
2, | ||
// props, | ||
3 // context | ||
]; | ||
(0, _handle.forwardCustomWithPrevent)('onCustomEvent', adapter).apply(void 0, args); | ||
var expected = args; | ||
var actual = adapter.mock.calls[0]; | ||
expect(actual).toEqual(expected); | ||
}); | ||
test('should call the next handler when `preventDefault` from provided props hasn\'t been called', function () { | ||
var event = 'onMyClick'; | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)(event), handler); | ||
callback(); | ||
expect(handler).toHaveBeenCalledTimes(1); | ||
}); | ||
test('should not call the next handler when `preventDefault` from provided props has been called', function () { | ||
var event = 'onMyClick'; | ||
var handler = jest.fn(); | ||
var callback = (0, _handle.handle)((0, _handle.forwardCustomWithPrevent)(event), handler); | ||
// should stop chain when `preventDefault()` has been called | ||
callback({}, { | ||
'onMyClick': function onMyClick(ev) { | ||
return ev.preventDefault(); | ||
} | ||
}); | ||
expect(handler).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
@@ -12,3 +12,3 @@ "use strict"; | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable enact/display-name */ | ||
describe('hoc', function () { | ||
@@ -15,0 +15,0 @@ var data; |
@@ -26,4 +26,8 @@ "use strict"; | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
// Gets a property from `provider` | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } /** | ||
* Provides the `ApiDecorator` higher-order component | ||
* | ||
* @module core/internal/ApiDecorator | ||
* @private | ||
*/ // Gets a property from `provider` | ||
var get = function get(provider, name) { | ||
@@ -30,0 +34,0 @@ return function () { |
@@ -23,15 +23,51 @@ // Type definitions for core/kind | ||
export interface StylesBlock { | ||
css: { [key: string]: string }; | ||
className?: string; | ||
/** | ||
* The CSS of the component | ||
*/ | ||
css: { [key: string]: string } | ||
/** | ||
* The className of the component | ||
*/; | ||
className?: string /** | ||
* Specifies which class names are overridable. | ||
If this value is `true` , all of the class names of the component CSS will become public. | ||
*/; | ||
publicClassNames?: boolean | string | string[]; | ||
} | ||
export interface KindConfig { | ||
name?: string; | ||
functional?: boolean; | ||
propTypes?: { [key: string]: Function }; | ||
defaultProps?: { [key: string]: any }; | ||
contextType?: object; | ||
styles?: StylesBlock; | ||
handlers?: { [key: string]: HandlerFunction }; | ||
computed?: { [key: string]: ComputedPropFunction }; | ||
/** | ||
* The name of the component | ||
*/ | ||
name?: string | ||
/** | ||
* Boolean controlling whether the returned component should be a functional component | ||
*/; | ||
functional?: boolean | ||
/** | ||
* Specifies expected props | ||
*/; | ||
propTypes?: { [key: string]: Function } | ||
/** | ||
* Sets the default props | ||
*/; | ||
defaultProps?: { [key: string]: any } | ||
/** | ||
* Specifies context type | ||
*/; | ||
contextType?: object | ||
/** | ||
* Configures styles with the static className to merge with user className | ||
*/; | ||
styles?: StylesBlock /** | ||
* Adds event handlers that are cached between calls to prevent recreating each call. | ||
Any handlers are added to the props passed to `render()` . See . | ||
*/; | ||
handlers?: { [key: string]: HandlerFunction } | ||
/** | ||
* Adds some computed properties, these are added to props passed to `render()` | ||
*/; | ||
computed?: { [key: string]: ComputedPropFunction } | ||
/** | ||
* The render function | ||
*/; | ||
render: RenderFunction; | ||
@@ -47,3 +83,3 @@ } | ||
name: 'Button', | ||
// Return a functional component suitable for use with React hooks | ||
// Return a functional component | ||
functional: true, | ||
@@ -50,0 +86,0 @@ // expect color and onClick properties but neither required |
@@ -27,3 +27,8 @@ "use strict"; | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /** | ||
* Provides the {@link core/kind.kind} method to create components | ||
* | ||
* @module core/kind | ||
* @exports kind | ||
*/ | ||
// Because contextType is optional and hooks must be called in the same order, we need a fallback | ||
@@ -63,5 +68,6 @@ // context when none is specified. This likely has some overhead so we may want to deprecate and | ||
* @memberof core/kind | ||
* @property {Object.<string, string>} css | ||
* @property {String} [className] | ||
* @property {Boolean|String|String[]} [publicClassNames] | ||
* @property {Object.<string, string>} css The CSS of the component | ||
* @property {String} [className] The className of the component | ||
* @property {Boolean|String|String[]} [publicClassNames] Specifies which class names are overridable. | ||
* If this value is `true`, all of the class names of the component CSS will become public. | ||
*/ | ||
@@ -72,11 +78,12 @@ | ||
* @memberof core/kind | ||
* @property {String} [name] | ||
* @property {Boolean} [functional] | ||
* @property {Object.<string, Function>} [propTypes] | ||
* @property {Object.<string, any>} [defaultProps] | ||
* @property {Object} [contextType] | ||
* @property {StylesBlock} [styles] | ||
* @property {Object.<string, HandlerFunction>} [handlers] | ||
* @property {Object.<string, ComputedPropFunction>} [computed] | ||
* @property {RenderFunction} render | ||
* @property {String} [name] The name of the component | ||
* @property {Boolean} [functional] Boolean controlling whether the returned component should be a functional component | ||
* @property {Object.<string, Function>} [propTypes] Specifies expected props | ||
* @property {Object.<string, any>} [defaultProps] Sets the default props | ||
* @property {Object} [contextType] Specifies context type | ||
* @property {StylesBlock} [styles] Configures styles with the static className to merge with user className | ||
* @property {Object.<string, HandlerFunction>} [handlers] Adds event handlers that are cached between calls to prevent recreating each call. | ||
* Any handlers are added to the props passed to `render()`. See {@link core/handle.handle}. | ||
* @property {Object.<string, ComputedPropFunction>} [computed] Adds some computed properties, these are added to props passed to `render()` | ||
* @property {RenderFunction} render The render function | ||
*/ | ||
@@ -92,3 +99,3 @@ | ||
* name: 'Button', | ||
* // Return a functional component suitable for use with React hooks | ||
* // Return a functional component | ||
* functional: true, | ||
@@ -95,0 +102,0 @@ * // expect color and onClick properties but neither required |
{ | ||
"name": "@enact/core", | ||
"version": "4.6.2", | ||
"version": "4.7.0", | ||
"description": "Enact is an open source JavaScript framework containing everything you need to create a fast, scalable mobile or web application.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -8,2 +8,3 @@ "use strict"; | ||
var _uniq = _interopRequireDefault(require("ramda/src/uniq")); | ||
var _deprecate = _interopRequireDefault(require("../internal/deprecate")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
@@ -20,3 +21,10 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } | ||
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /** | ||
* Utilities for detecting basic platform capabilities. | ||
* | ||
* @module core/platform | ||
* @exports detect | ||
* @exports platform | ||
* @public | ||
*/ | ||
var hasGesture = function hasGesture() { | ||
@@ -243,2 +251,8 @@ return Boolean('ongesturestart' in window || 'onmsgesturestart' in window && (window.navigator.msMaxTouchPoints > 1 || window.navigator.maxTouchPoints > 1)); | ||
} | ||
if (plat.platformName === 'windowsPhone') { | ||
(0, _deprecate["default"])({ | ||
name: 'Windows Phone platform', | ||
until: '5.0.0' | ||
}); | ||
} | ||
return plat; | ||
@@ -245,0 +259,0 @@ }; |
@@ -109,2 +109,12 @@ "use strict"; | ||
}); | ||
describe('parseUserAgent for Windows Phone', function () { | ||
var windowsPhone = 'Mozilla/5.0 (Windows Phone 8.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4103.84 Mobile Safari/537.36'; | ||
test('should return platformName `windowsPhone`', function () { | ||
var expected = { | ||
platformName: 'windowsPhone' | ||
}; | ||
var actual = (0, _platform.parseUserAgent)(windowsPhone); | ||
expect(actual).toMatchObject(expected); | ||
}); | ||
}); | ||
describe('parseUserAgent for User-Agent Reduction', function () { | ||
@@ -111,0 +121,0 @@ var testVersion = '113'; |
118
util/Job.js
@@ -166,2 +166,120 @@ "use strict"; | ||
*/ | ||
/** | ||
* Starts the job in `timeout` milliseconds | ||
* | ||
* @method | ||
* @param {Number} timeout The number of milliseconds to wait before starting the job. | ||
* This supersedes the timeout set at construction. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Stops the job. | ||
* | ||
* @method | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Executes the job immediately, then prevents any other calls to `throttle()` from running | ||
* until the `timeout` configured at construction passes. | ||
* | ||
* @method | ||
* @param {...*} args Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Executes the job immediately, then prevents any other calls to `throttle()` from running for | ||
* `timeout` milliseconds. | ||
* | ||
* @method | ||
* @param {Number} timeout The number of milliseconds to wait before allowing the job to | ||
* be ran again. This supersedes the timeout set at construction. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Executes job when the CPU is idle. | ||
* | ||
* @method | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Executes job when the CPU is idle, or when the timeout is reached, whichever occurs first. | ||
* | ||
* @method | ||
* @param {Number} timeout The number of milliseconds to wait before executing the | ||
* job. This guarantees that the job is run, if a positive value | ||
* is specified. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Executes job before the next repaint. | ||
* | ||
* @method | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Executes job before the next repaint after a given amount of timeout. | ||
* | ||
* @method | ||
* @param {Number} timeout The number of milliseconds to wait before running `requestAnimationFrame`. | ||
* @param {...*} [args] Any args passed are forwarded to the callback | ||
* | ||
* @returns {undefined} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
/** | ||
* Starts the job when `promise` resolves. | ||
* | ||
* The job execution is tied to the resolution of the last `Promise` passed. Like other methods | ||
* on `Job`, calling `promise()` again with a new `Promise` will block execution of the job | ||
* until that new `Promise` resolves. Any previous `Promise`s will still resolve normally but | ||
* will not trigger job execution. | ||
* | ||
* Unlike other methods on `Job`, `promise()` returns a `Promise` which is the result of calling | ||
* `then()` on the passed `promise`. That `Promise` resolves with either the result of job | ||
* execution or `undefined` if `Promise` was superseded by a subsequent `Promise` passed as | ||
* described above. | ||
* | ||
* @method | ||
* @param {Promise} promise The promise that must resolve before the job is executed | ||
* | ||
* @returns {Promise} | ||
* @memberof core/util.Job.prototype | ||
* @public | ||
*/ | ||
}]); | ||
@@ -168,0 +286,0 @@ return Job; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
301042
7211