picasso-plugin-hammer
Advanced tools
Comparing version 0.35.1 to 0.36.0
@@ -6,2 +6,6 @@ # Change Log | ||
# [0.36.0](https://github.com/qlik-oss/picasso.js/compare/v0.35.1...v0.36.0) (2021-04-08) | ||
**Note:** Version bump only for package picasso-plugin-hammer | ||
## [0.35.1](https://github.com/qlik-oss/picasso.js/compare/v0.35.0...v0.35.1) (2021-04-07) | ||
@@ -8,0 +12,0 @@ |
/* | ||
* picasso-plugin-hammer v0.35.1 | ||
* picasso-plugin-hammer v0.36.0 | ||
* Copyright (c) 2021 QlikTech International AB | ||
@@ -4,0 +4,0 @@ * Released under the MIT license. |
/* | ||
* picasso-plugin-hammer v0.35.1 | ||
* picasso-plugin-hammer v0.36.0 | ||
* Copyright (c) 2021 QlikTech International AB | ||
@@ -8,3 +8,220 @@ * Released under the MIT license. | ||
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e="undefined"!=typeof globalThis?globalThis:e||self).picassoHammer=n()}(this,function(){"use strict";var n={click:"Tap",Click:"Tap",tap:"Tap",pan:"Pan",swipe:"Swipe",rotate:"Rotate",press:"Press",pinch:"Pinch"};function d(e){return n[e]||e}function t(l){return function(n,t,o){var i,r,s,f,u=[],a=!0;function c(){"function"==typeof i.enable&&(i.enable=i.enable.bind(r)()),i.enable&&(i.gestures.forEach(function(n){n.options=n.options||{},void 0===n.options.enable&&(n.options.enable=!0),"function"==typeof n.options.enable&&(n.options.enable=n.options.enable.bind(r));var e=d(n.type);l&&l[e]&&(n.options.event=n.options.event||n.type.toLowerCase(),(s=s||new l.Manager(o)).add(new l[e](n.options)),Object.keys(n.events).forEach(function(e){n.events[e]=n.events[e].bind(r),s.on(e,n.events[e])}),u.push(n))}),i.gestures.forEach(function(e){var n=d(e.type);l&&l[n]&&(e.recognizeWith&&s.get(e.options.event).recognizeWith(e.recognizeWith.split(" ").filter(function(e){return""!==e})),e.requireFailure&&s.get(e.options.event).requireFailure(e.requireFailure.split(" ").filter(function(e){return""!==e})))}))}function p(){u.forEach(function(n){Object.keys(n.events).forEach(function(e){s.off(e,n.events[e])}),s.remove(n.options.event)}),u=[]}return{get key(){return f},set:function(e){f=(e=e).key,r={chart:n,mediator:t,settings:i=e},i.gestures=i.gestures||[],void 0===i.enable&&(i.enable=!0),p(),a&&c()},off:function(){a=!1,p()},on:function(){a=!0,0===u.length&&c()},destroy:function(){p(),s&&s.destroy(),i=r=s=null}}}}return function(n){if(!("function"==typeof n.interaction))return function(e){e.interaction("hammer",t(n))};n.interaction("hammer",t(Hammer))}}); | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.picassoHammer = factory()); | ||
}(this, (function () { 'use strict'; | ||
var translateKnownTypes = { | ||
click: 'Tap', | ||
Click: 'Tap', | ||
tap: 'Tap', | ||
pan: 'Pan', | ||
swipe: 'Swipe', | ||
rotate: 'Rotate', | ||
press: 'Press', | ||
pinch: 'Pinch' | ||
}; | ||
/** | ||
* Helper function for translating typical non-hammer gesture to a hammer gesture. Currently only supporting 'click' | ||
* @param {String} type Gesture type | ||
* @private | ||
*/ | ||
function getGestureType(type) { | ||
return translateKnownTypes[type] || type; | ||
} | ||
/** | ||
* Manages event handlers for HammerJS. | ||
* @param {Hammer} Hammered - The Hammer instance | ||
*/ | ||
function hammered(Hammered) { | ||
return function hammer(chart, mediator, element) { | ||
var settings; | ||
var instance; | ||
var mc; | ||
var key; | ||
var hammerGestures = []; | ||
var isOn = true; | ||
/** | ||
* Set default settings | ||
* @private | ||
*/ | ||
function setDefaultSettings(newSettings) { | ||
key = newSettings.key; //eslint-disable-line | ||
settings = newSettings; | ||
instance = { | ||
chart: chart, | ||
mediator: mediator, | ||
settings: settings | ||
}; | ||
settings.gestures = settings.gestures || []; | ||
if (settings.enable === undefined) { | ||
settings.enable = true; | ||
} | ||
} | ||
/** | ||
* @private | ||
* add hammer recognizers based on settings | ||
*/ | ||
function addRecognizers() { | ||
if (typeof settings.enable === 'function') { | ||
settings.enable = settings.enable.bind(instance)(); | ||
} | ||
if (!settings.enable) { | ||
return; // interaction is disabled | ||
} | ||
settings.gestures.forEach(function (gesture) { | ||
gesture.options = gesture.options || {}; // handle action enable | ||
if (gesture.options.enable === undefined) { | ||
gesture.options.enable = true; | ||
} | ||
if (typeof gesture.options.enable === 'function') { | ||
gesture.options.enable = gesture.options.enable.bind(instance); | ||
} // setup hammer gestures | ||
var type = getGestureType(gesture.type); | ||
if (Hammered && Hammered[type]) { | ||
gesture.options.event = gesture.options.event || gesture.type.toLowerCase(); | ||
mc = mc || new Hammered.Manager(element); | ||
mc.add(new Hammered[type](gesture.options)); | ||
Object.keys(gesture.events).forEach(function (eventName) { | ||
gesture.events[eventName] = gesture.events[eventName].bind(instance); | ||
mc.on(eventName, gesture.events[eventName]); | ||
}); | ||
hammerGestures.push(gesture); | ||
} | ||
}); // setup mixing hammer gestures | ||
settings.gestures.forEach(function (gesture) { | ||
var type = getGestureType(gesture.type); | ||
if (Hammered && Hammered[type]) { | ||
if (gesture.recognizeWith) { | ||
mc.get(gesture.options.event).recognizeWith(gesture.recognizeWith.split(' ').filter(function (e) { | ||
return e !== ''; | ||
})); | ||
} | ||
if (gesture.requireFailure) { | ||
mc.get(gesture.options.event).requireFailure(gesture.requireFailure.split(' ').filter(function (e) { | ||
return e !== ''; | ||
})); | ||
} | ||
} | ||
}); | ||
} | ||
/** | ||
* @private | ||
* removes all added hammer recognizers and native events | ||
*/ | ||
function removeAddedEvents() { | ||
// remove hammer recognizers and registered events | ||
hammerGestures.forEach(function (gesture) { | ||
Object.keys(gesture.events).forEach(function (eventName) { | ||
mc.off(eventName, gesture.events[eventName]); | ||
}); | ||
mc.remove(gesture.options.event); | ||
}); | ||
hammerGestures = []; | ||
} | ||
return { | ||
/** | ||
* Getter for the key. | ||
*/ | ||
get key() { | ||
return key; | ||
}, | ||
/** | ||
* Updates this with new settings | ||
* @typedef settings | ||
* @type {object} | ||
* @property {string} [type] - The interaction type. Is 'hammer' for this component | ||
* @property {boolean|function} [enable] - Should the interaction be enabled or not. | ||
* This is only run when adding event handlers. In effect at startup, update or during on/off. | ||
* It does not run during every event loop. | ||
* @property {object} [events] - The keys in this object is the names of native events | ||
* that should be added to the chart element and they should all point to function which | ||
* will be the corresponding event handler. | ||
*/ | ||
set: function set(newSettings) { | ||
setDefaultSettings(newSettings); | ||
removeAddedEvents(); | ||
if (isOn) { | ||
addRecognizers(); | ||
} | ||
}, | ||
/** | ||
* Turns off interactions | ||
*/ | ||
off: function off() { | ||
isOn = false; | ||
removeAddedEvents(); | ||
}, | ||
/** | ||
* Turns off interactions | ||
*/ | ||
on: function on() { | ||
isOn = true; | ||
if (hammerGestures.length === 0) { | ||
addRecognizers(); | ||
} | ||
}, | ||
/** | ||
* Destroys and unbinds all event handlers | ||
*/ | ||
destroy: function destroy() { | ||
removeAddedEvents(); | ||
if (mc) { | ||
mc.destroy(); | ||
} | ||
mc = null; | ||
instance = null; | ||
settings = null; | ||
} | ||
}; | ||
}; | ||
} | ||
/* global Hammer */ | ||
function initialize(picassoOrHammer) { | ||
var isPicasso = typeof picassoOrHammer.interaction === 'function'; | ||
if (!isPicasso) { | ||
return function (picasso) { | ||
picasso.interaction('hammer', hammered(picassoOrHammer)); | ||
}; | ||
} | ||
picassoOrHammer.interaction('hammer', hammered(Hammer)); | ||
return undefined; | ||
} | ||
return initialize; | ||
}))); | ||
//# sourceMappingURL=picasso-hammer.js.map |
{ | ||
"name": "picasso-plugin-hammer", | ||
"version": "0.35.1", | ||
"version": "0.36.0", | ||
"description": "Hammer JS interaction plugin for picasso.js", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"scripts": { | ||
"build": "cross-env NODE_ENV=production rollup --config ../../rollup.config.js", | ||
"build": "rollup --config ../../rollup.config.js", | ||
"build:watch": "yarn run build -w", | ||
@@ -24,5 +24,5 @@ "lint": "eslint src", | ||
"devDependencies": { | ||
"test-utils": "^0.35.1" | ||
"test-utils": "^0.36.0" | ||
}, | ||
"gitHead": "dfdc0950d8719e9bf2513c5e1699650c68a6b514" | ||
"gitHead": "a70256245ebbd5a0b9a858dcd8ceb1a6ffd0da93" | ||
} |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
48352
372
1