@interactjs/reflow
Advanced tools
Comparing version 1.9.10 to 1.9.11
@@ -1,23 +0,1 @@ | ||
import Interactable from '@interactjs/core/Interactable'; | ||
import { ActionProps } from '@interactjs/core/Interaction'; | ||
import Scope from '@interactjs/core/scope'; | ||
declare module '@interactjs/core/Interactable' { | ||
interface Interactable { | ||
reflow: (action: ActionProps) => ReturnType<typeof reflow>; | ||
} | ||
} | ||
declare module '@interactjs/core/Interaction' { | ||
interface Interaction { | ||
_reflowPromise: Promise<void>; | ||
_reflowResolve: () => void; | ||
} | ||
} | ||
declare module '@interactjs/core/InteractEvent' { | ||
interface PhaseMap { | ||
reflow?: true; | ||
} | ||
} | ||
export declare function install(scope: Scope): void; | ||
declare function reflow<T extends Interact.ActionName>(interactable: Interactable, action: ActionProps<T>, scope: Scope): Promise<Interactable>; | ||
declare const _default: import("@interactjs/core/scope").Plugin; | ||
export default _default; | ||
export {}; |
143
index.js
@@ -1,139 +0,16 @@ | ||
import Interactable from "../core/Interactable.js"; | ||
import { Interaction } from "../core/Interaction.js"; | ||
import { arr, extend, is, pointer as pointerUtils, rect as rectUtils, win } from "../utils/index.js"; | ||
export function install(scope) { | ||
const { | ||
/** @lends Interactable */ | ||
// eslint-disable-next-line no-shadow | ||
Interactable | ||
} = scope; | ||
scope.actions.phases.reflow = true; | ||
/** | ||
* ```js | ||
* const interactable = interact(target) | ||
* const drag = { name: drag, axis: 'x' } | ||
* const resize = { name: resize, edges: { left: true, bottom: true } | ||
* | ||
* interactable.reflow(drag) | ||
* interactable.reflow(resize) | ||
* ``` | ||
* | ||
* Start an action sequence to re-apply modifiers, check drops, etc. | ||
* | ||
* @param { Object } action The action to begin | ||
* @param { string } action.name The name of the action | ||
* @returns { Promise } A promise that resolves to the `Interactable` when actions on all targets have ended | ||
*/ | ||
/* eslint-disable import/order, no-console, eol-last */ | ||
import interact, { init } from "../interact/index.js"; | ||
import plugin from "./plugin.js"; | ||
Interactable.prototype.reflow = function (action) { | ||
return reflow(this, action, scope); | ||
}; | ||
} | ||
if (typeof window === 'object' && !!window) { | ||
init(window); | ||
} // eslint-disable-next-line no-undef | ||
function reflow(interactable, action, scope) { | ||
const elements = is.string(interactable.target) ? arr.from(interactable._context.querySelectorAll(interactable.target)) : [interactable.target]; // tslint:disable-next-line variable-name | ||
const Promise = win.window.Promise; | ||
const promises = Promise ? [] : null; | ||
for (const element of elements) { | ||
const rect = interactable.getRect(element); | ||
if (!rect) { | ||
break; | ||
} | ||
const runningInteraction = arr.find(scope.interactions.list, interaction => { | ||
return interaction.interacting() && interaction.interactable === interactable && interaction.element === element && interaction.prepared.name === action.name; | ||
}); | ||
let reflowPromise; | ||
if (runningInteraction) { | ||
runningInteraction.move(); | ||
if (promises) { | ||
reflowPromise = runningInteraction._reflowPromise || new Promise(resolve => { | ||
runningInteraction._reflowResolve = resolve; | ||
}); | ||
} | ||
} else { | ||
const xywh = rectUtils.tlbrToXywh(rect); | ||
const coords = { | ||
page: { | ||
x: xywh.x, | ||
y: xywh.y | ||
}, | ||
client: { | ||
x: xywh.x, | ||
y: xywh.y | ||
}, | ||
timeStamp: scope.now() | ||
}; | ||
const event = pointerUtils.coordsToEvent(coords); | ||
reflowPromise = startReflow(scope, interactable, element, action, event); | ||
} | ||
if (promises) { | ||
promises.push(reflowPromise); | ||
} | ||
} | ||
return promises && Promise.all(promises).then(() => interactable); | ||
if (("development" !== 'production' || true) && !interact.__warnedUseImport) { | ||
interact.__warnedUseImport = true; | ||
console.warn('[interact.js] The "@interactjs/*/index" packages are not quite stable yet. Use them with caution.'); | ||
} | ||
function startReflow(scope, interactable, element, action, event) { | ||
const interaction = scope.interactions.new({ | ||
pointerType: 'reflow' | ||
}); | ||
const signalArg = { | ||
interaction, | ||
event, | ||
pointer: event, | ||
eventTarget: element, | ||
phase: 'reflow' | ||
}; | ||
interaction.interactable = interactable; | ||
interaction.element = element; | ||
interaction.prepared = extend({}, action); | ||
interaction.prevEvent = event; | ||
interaction.updatePointer(event, event, element, true); | ||
interaction._doPhase(signalArg); | ||
const reflowPromise = win.window.Promise ? new win.window.Promise(resolve => { | ||
interaction._reflowResolve = resolve; | ||
}) : null; | ||
interaction._reflowPromise = reflowPromise; | ||
interaction.start(action, interactable, element); | ||
if (interaction._interacting) { | ||
interaction.move(signalArg); | ||
interaction.end(event); | ||
} else { | ||
interaction.stop(); | ||
} | ||
interaction.removePointer(event, event); | ||
interaction.pointerIsDown = false; | ||
return reflowPromise; | ||
} | ||
export default { | ||
id: 'reflow', | ||
install, | ||
listeners: { | ||
// remove completed reflow interactions | ||
'interactions:stop': ({ | ||
interaction | ||
}, scope) => { | ||
if (interaction.pointerType === 'reflow') { | ||
if (interaction._reflowResolve) { | ||
interaction._reflowResolve(); | ||
} | ||
arr.remove(scope.interactions.list, interaction); | ||
} | ||
} | ||
} | ||
}; | ||
interact.use(plugin); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import e from"../core/Interactable.min.js";import{Interaction as t}from"../core/Interaction.min.js";import{arr as n,extend as o,is as r,pointer as i,rect as s,win as l}from"../utils/index.min.js";export function install(e){const{Interactable:t}=e;e.actions.phases.reflow=!0,t.prototype.reflow=function(t){return function(e,t,o){const c=r.string(e.target)?n.from(e._context.querySelectorAll(e.target)):[e.target],p=l.window.Promise,f=p?[]:null;for(const r of c){const l=e.getRect(r);if(!l)break;const c=n.find(o.interactions.list,n=>n.interacting()&&n.interactable===e&&n.element===r&&n.prepared.name===t.name);let m;if(c)c.move(),f&&(m=c._reflowPromise||new p(e=>{c._reflowResolve=e}));else{const n=s.tlbrToXywh(l),c={page:{x:n.x,y:n.y},client:{x:n.x,y:n.y},timeStamp:o.now()},p=i.coordsToEvent(c);m=a(o,e,r,t,p)}f&&f.push(m)}return f&&p.all(f).then(()=>e)}(this,t,e)}}function a(e,t,n,r,i){const s=e.interactions.new({pointerType:"reflow"}),a={interaction:s,event:i,pointer:i,eventTarget:n,phase:"reflow"};s.interactable=t,s.element=n,s.prepared=o({},r),s.prevEvent=i,s.updatePointer(i,i,n,!0),s._doPhase(a);const c=l.window.Promise?new l.window.Promise(e=>{s._reflowResolve=e}):null;return s._reflowPromise=c,s.start(r,t,n),s._interacting?(s.move(a),s.end(i)):s.stop(),s.removePointer(i,i),s.pointerIsDown=!1,c}export default{id:"reflow",install:install,listeners:{"interactions:stop"({interaction:e},t){"reflow"===e.pointerType&&(e._reflowResolve&&e._reflowResolve(),n.remove(t.interactions.list,e))}}}; | ||
import e,{init as t}from"../interact/index.min.js";import n from"./plugin.min.js";"object"==typeof window&&window&&t(window),e.__warnedUseImport||(e.__warnedUseImport=!0,console.warn('[interact.js] The "@interactjs/*/index" packages are not quite stable yet. Use them with caution.')),e.use(n); | ||
//# sourceMappingURL=index.min.js.map |
{ | ||
"name": "@interactjs/reflow", | ||
"version": "1.9.10", | ||
"version": "1.9.11", | ||
"license": "MIT", | ||
"peerDependencies": { | ||
"@interactjs/core": "1.9.10", | ||
"@interactjs/utils": "1.9.10" | ||
"@interactjs/core": "1.9.11", | ||
"@interactjs/utils": "1.9.11" | ||
}, | ||
@@ -13,3 +13,3 @@ "devDependencies": { | ||
"optionalDependencies": { | ||
"@interactjs/interact": "1.9.10" | ||
"@interactjs/interact": "1.9.11" | ||
}, | ||
@@ -19,3 +19,3 @@ "publishConfig": { | ||
}, | ||
"gitHead": "0a55a5d5" | ||
"gitHead": "6b07bf54" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
29364
171
1