@interactjs/reflow
Advanced tools
Comparing version 1.10.23 to 1.10.24
{ | ||
"name": "@interactjs/reflow", | ||
"version": "1.10.23", | ||
"version": "1.10.24", | ||
"main": "index", | ||
@@ -13,7 +13,7 @@ "module": "index", | ||
"peerDependencies": { | ||
"@interactjs/core": "1.10.23", | ||
"@interactjs/utils": "1.10.23" | ||
"@interactjs/core": "1.10.24", | ||
"@interactjs/utils": "1.10.24" | ||
}, | ||
"optionalDependencies": { | ||
"@interactjs/interact": "1.10.23" | ||
"@interactjs/interact": "1.10.24" | ||
}, | ||
@@ -28,3 +28,3 @@ "publishConfig": { | ||
"license": "MIT", | ||
"gitHead": "9ba48631" | ||
"gitHead": "86c64a3f" | ||
} |
@@ -14,3 +14,19 @@ import type { Interactable } from '@interactjs/core/Interactable'; | ||
interface Interactable { | ||
reflow: <T extends ActionName>(action: ActionProps<T>) => ReturnType<typeof doReflow>; | ||
/** | ||
* ```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 | ||
*/ | ||
reflow<T extends ActionName>(action: ActionProps<T>): ReturnType<typeof doReflow>; | ||
} | ||
@@ -29,5 +45,4 @@ } | ||
} | ||
export declare function install(scope: Scope): void; | ||
declare function doReflow<T extends ActionName>(interactable: Interactable, action: ActionProps<T>, scope: Scope): Promise<Interactable>; | ||
declare const reflow: Plugin; | ||
export default reflow; |
@@ -5,25 +5,7 @@ import * as arr from "../utils/arr.js"; | ||
import { tlbrToXywh } from "../utils/rect.js"; | ||
export function install(scope) { | ||
function install(scope) { | ||
const { | ||
/** @lends Interactable */ | ||
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 | ||
*/ | ||
Interactable.prototype.reflow = function (action) { | ||
@@ -33,16 +15,13 @@ return doReflow(this, action, scope); | ||
} | ||
function doReflow(interactable, action, scope) { | ||
const elements = interactable.getAllElements(); // tslint:disable-next-line variable-name | ||
const elements = interactable.getAllElements(); | ||
// tslint:disable-next-line variable-name | ||
const Promise = scope.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 => { | ||
@@ -52,6 +31,4 @@ return interaction.interacting() && interaction.interactable === interactable && interaction.element === element && interaction.prepared.name === action.name; | ||
let reflowPromise; | ||
if (runningInteraction) { | ||
runningInteraction.move(); | ||
if (promises) { | ||
@@ -78,3 +55,2 @@ reflowPromise = runningInteraction._reflowPromise || new Promise(resolve => { | ||
} | ||
if (promises) { | ||
@@ -84,6 +60,4 @@ promises.push(reflowPromise); | ||
} | ||
return promises && Promise.all(promises).then(() => interactable); | ||
} | ||
function startReflow(scope, interactable, element, action, event) { | ||
@@ -106,5 +80,3 @@ const interaction = scope.interactions.new({ | ||
copyAction(interaction.prepared, action); | ||
interaction._doPhase(signalArg); | ||
const { | ||
@@ -118,3 +90,2 @@ Promise | ||
interaction.start(action, interactable, element); | ||
if (interaction._interacting) { | ||
@@ -125,10 +96,7 @@ interaction.move(signalArg); | ||
interaction.stop(); | ||
interaction._reflowResolve(); | ||
} | ||
interaction.removePointer(event, event); | ||
return reflowPromise; | ||
} | ||
const reflow = { | ||
@@ -146,3 +114,2 @@ id: 'reflow', | ||
} | ||
arr.remove(scope.interactions.list, interaction); | ||
@@ -149,0 +116,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import*as e from"../utils/arr.prod.js";import{copyAction as t}from"../utils/misc.prod.js";import*as o from"../utils/pointerUtils.prod.js";import{tlbrToXywh as r}from"../utils/rect.prod.js";export function install(t){const{Interactable:i}=t;t.actions.phases.reflow=!0,i.prototype.reflow=function(i){return((t,i,s)=>{const l=t.getAllElements(),a=s.window.Promise,p=a?[]:null;for(const c of l){const l=t.getRect(c);if(!l)break;const f=e.find(s.interactions.list,(e=>e.interacting()&&e.interactable===t&&e.element===c&&e.prepared.name===i.name));let m;if(f)f.move(),p&&(m=f._reflowPromise||new a((e=>{f._reflowResolve=e})));else{const e=r(l),a={page:{x:e.x,y:e.y},client:{x:e.x,y:e.y},timeStamp:s.now()},p=o.coordsToEvent(a);m=n(s,t,c,i,p)}p&&p.push(m)}return p&&a.all(p).then((()=>t))})(this,i,t)}}function n(e,r,n,i,s){const l=e.interactions.new({pointerType:"reflow"}),a={interaction:l,event:s,pointer:s,eventTarget:n,phase:"reflow"};l.interactable=r,l.element=n,l.prevEvent=s,l.updatePointer(s,s,n,!0),o.setZeroCoords(l.coords.delta),t(l.prepared,i),l._doPhase(a);const{Promise:p}=e.window,c=p?new p((e=>{l._reflowResolve=e})):void 0;return l._reflowPromise=c,l.start(i,r,n),l._interacting?(l.move(a),l.end(s)):(l.stop(),l._reflowResolve()),l.removePointer(s,s),c}const i={id:"reflow",install:install,listeners:{"interactions:stop"({interaction:t},o){"reflow"===t.pointerType&&(t._reflowResolve&&t._reflowResolve(),e.remove(o.interactions.list,t))}}};export default i; | ||
import*as e from"../utils/arr.prod.js";import{copyAction as t}from"../utils/misc.prod.js";import*as o from"../utils/pointerUtils.prod.js";import{tlbrToXywh as r}from"../utils/rect.prod.js";function n(e,r,n,i,s){const l=e.interactions.new({pointerType:"reflow"}),a={interaction:l,event:s,pointer:s,eventTarget:n,phase:"reflow"};l.interactable=r,l.element=n,l.prevEvent=s,l.updatePointer(s,s,n,!0),o.setZeroCoords(l.coords.delta),t(l.prepared,i),l._doPhase(a);const{Promise:p}=e.window,c=p?new p((e=>{l._reflowResolve=e})):void 0;return l._reflowPromise=c,l.start(i,r,n),l._interacting?(l.move(a),l.end(s)):(l.stop(),l._reflowResolve()),l.removePointer(s,s),c}const i={id:"reflow",install(t){const{Interactable:i}=t;t.actions.phases.reflow=!0,i.prototype.reflow=function(i){return((t,i,s)=>{const l=t.getAllElements(),a=s.window.Promise,p=a?[]:null;for(const c of l){const l=t.getRect(c);if(!l)break;const f=e.find(s.interactions.list,(e=>e.interacting()&&e.interactable===t&&e.element===c&&e.prepared.name===i.name));let m;if(f)f.move(),p&&(m=f._reflowPromise||new a((e=>{f._reflowResolve=e})));else{const e=r(l),a={page:{x:e.x,y:e.y},client:{x:e.x,y:e.y},timeStamp:s.now()},p=o.coordsToEvent(a);m=n(s,t,c,i,p)}p&&p.push(m)}return p&&a.all(p).then((()=>t))})(this,i,t)}},listeners:{"interactions:stop"({interaction:t},o){"reflow"===t.pointerType&&(t._reflowResolve&&t._reflowResolve(),e.remove(o.interactions.list,t))}}};export default i; | ||
//# sourceMappingURL=plugin.prod.js.map |
Sorry, the diff of this file is not supported yet
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
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
28025
169