This commit is contained in:
29
node_modules/dnd-core/lib/utils/coords.d.ts
generated
vendored
Normal file
29
node_modules/dnd-core/lib/utils/coords.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { State } from '../reducers/dragOffset';
|
||||
import { XYCoord } from '..';
|
||||
/**
|
||||
* Coordinate addition
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export declare function add(a: XYCoord, b: XYCoord): XYCoord;
|
||||
/**
|
||||
* Coordinate subtraction
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export declare function subtract(a: XYCoord, b: XYCoord): XYCoord;
|
||||
/**
|
||||
* Returns the cartesian distance of the drag source component's position, based on its position
|
||||
* at the time when the current drag operation has started, and the movement difference.
|
||||
*
|
||||
* Returns null if no item is being dragged.
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export declare function getSourceClientOffset(state: State): XYCoord | null;
|
||||
/**
|
||||
* Determines the x,y offset between the client offset and the initial client offset
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export declare function getDifferenceFromInitialOffset(state: State): XYCoord | null;
|
||||
49
node_modules/dnd-core/lib/utils/coords.js
generated
vendored
Normal file
49
node_modules/dnd-core/lib/utils/coords.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Coordinate addition
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export function add(a, b) {
|
||||
return {
|
||||
x: a.x + b.x,
|
||||
y: a.y + b.y,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Coordinate subtraction
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export function subtract(a, b) {
|
||||
return {
|
||||
x: a.x - b.x,
|
||||
y: a.y - b.y,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns the cartesian distance of the drag source component's position, based on its position
|
||||
* at the time when the current drag operation has started, and the movement difference.
|
||||
*
|
||||
* Returns null if no item is being dragged.
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export function getSourceClientOffset(state) {
|
||||
const { clientOffset, initialClientOffset, initialSourceClientOffset } = state;
|
||||
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) {
|
||||
return null;
|
||||
}
|
||||
return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset);
|
||||
}
|
||||
/**
|
||||
* Determines the x,y offset between the client offset and the initial client offset
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export function getDifferenceFromInitialOffset(state) {
|
||||
const { clientOffset, initialClientOffset } = state;
|
||||
if (!clientOffset || !initialClientOffset) {
|
||||
return null;
|
||||
}
|
||||
return subtract(clientOffset, initialClientOffset);
|
||||
}
|
||||
9
node_modules/dnd-core/lib/utils/dirtiness.d.ts
generated
vendored
Normal file
9
node_modules/dnd-core/lib/utils/dirtiness.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export declare const NONE: string[];
|
||||
export declare const ALL: string[];
|
||||
/**
|
||||
* Determines if the given handler IDs are dirty or not.
|
||||
*
|
||||
* @param dirtyIds The set of dirty handler ids
|
||||
* @param handlerIds The set of handler ids to check
|
||||
*/
|
||||
export declare function areDirty(dirtyIds: string[], handlerIds: string[] | undefined): boolean;
|
||||
21
node_modules/dnd-core/lib/utils/dirtiness.js
generated
vendored
Normal file
21
node_modules/dnd-core/lib/utils/dirtiness.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { intersection } from './js_utils';
|
||||
export const NONE = [];
|
||||
export const ALL = [];
|
||||
NONE.__IS_NONE__ = true;
|
||||
ALL.__IS_ALL__ = true;
|
||||
/**
|
||||
* Determines if the given handler IDs are dirty or not.
|
||||
*
|
||||
* @param dirtyIds The set of dirty handler ids
|
||||
* @param handlerIds The set of handler ids to check
|
||||
*/
|
||||
export function areDirty(dirtyIds, handlerIds) {
|
||||
if (dirtyIds === NONE) {
|
||||
return false;
|
||||
}
|
||||
if (dirtyIds === ALL || typeof handlerIds === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
const commonIds = intersection(handlerIds, dirtyIds);
|
||||
return commonIds.length > 0;
|
||||
}
|
||||
15
node_modules/dnd-core/lib/utils/equality.d.ts
generated
vendored
Normal file
15
node_modules/dnd-core/lib/utils/equality.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { XYCoord } from '../interfaces';
|
||||
export declare type EqualityCheck<T> = (a: T, b: T) => boolean;
|
||||
export declare const strictEquality: <T>(a: T, b: T) => boolean;
|
||||
/**
|
||||
* Determine if two cartesian coordinate offsets are equal
|
||||
* @param offsetA
|
||||
* @param offsetB
|
||||
*/
|
||||
export declare function areCoordsEqual(offsetA: XYCoord | null | undefined, offsetB: XYCoord | null | undefined): boolean;
|
||||
/**
|
||||
* Determines if two arrays of items are equal
|
||||
* @param a The first array of items
|
||||
* @param b The second array of items
|
||||
*/
|
||||
export declare function areArraysEqual<T>(a: T[], b: T[], isEqual?: EqualityCheck<T>): boolean;
|
||||
33
node_modules/dnd-core/lib/utils/equality.js
generated
vendored
Normal file
33
node_modules/dnd-core/lib/utils/equality.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export const strictEquality = (a, b) => a === b;
|
||||
/**
|
||||
* Determine if two cartesian coordinate offsets are equal
|
||||
* @param offsetA
|
||||
* @param offsetB
|
||||
*/
|
||||
export function areCoordsEqual(offsetA, offsetB) {
|
||||
if (!offsetA && !offsetB) {
|
||||
return true;
|
||||
}
|
||||
else if (!offsetA || !offsetB) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return offsetA.x === offsetB.x && offsetA.y === offsetB.y;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines if two arrays of items are equal
|
||||
* @param a The first array of items
|
||||
* @param b The second array of items
|
||||
*/
|
||||
export function areArraysEqual(a, b, isEqual = strictEquality) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (!isEqual(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
1
node_modules/dnd-core/lib/utils/getNextUniqueId.d.ts
generated
vendored
Normal file
1
node_modules/dnd-core/lib/utils/getNextUniqueId.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function getNextUniqueId(): number;
|
||||
4
node_modules/dnd-core/lib/utils/getNextUniqueId.js
generated
vendored
Normal file
4
node_modules/dnd-core/lib/utils/getNextUniqueId.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
let nextUniqueId = 0;
|
||||
export function getNextUniqueId() {
|
||||
return nextUniqueId++;
|
||||
}
|
||||
33
node_modules/dnd-core/lib/utils/js_utils.d.ts
generated
vendored
Normal file
33
node_modules/dnd-core/lib/utils/js_utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* drop-in replacement for _.get
|
||||
* @param obj
|
||||
* @param path
|
||||
* @param defaultValue
|
||||
*/
|
||||
export declare function get<T>(obj: any, path: string, defaultValue: T): T;
|
||||
/**
|
||||
* drop-in replacement for _.without
|
||||
*/
|
||||
export declare function without<T>(items: T[], item: T): T[];
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export declare function isString(input: any): boolean;
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export declare function isObject(input: any): boolean;
|
||||
/**
|
||||
* repalcement for _.xor
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export declare function xor<T extends string | number>(itemsA: T[], itemsB: T[]): T[];
|
||||
/**
|
||||
* replacement for _.intersection
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export declare function intersection<T>(itemsA: T[], itemsB: T[]): T[];
|
||||
60
node_modules/dnd-core/lib/utils/js_utils.js
generated
vendored
Normal file
60
node_modules/dnd-core/lib/utils/js_utils.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
// cheap lodash replacements
|
||||
/**
|
||||
* drop-in replacement for _.get
|
||||
* @param obj
|
||||
* @param path
|
||||
* @param defaultValue
|
||||
*/
|
||||
export function get(obj, path, defaultValue) {
|
||||
return path
|
||||
.split('.')
|
||||
.reduce((a, c) => (a && a[c] ? a[c] : defaultValue || null), obj);
|
||||
}
|
||||
/**
|
||||
* drop-in replacement for _.without
|
||||
*/
|
||||
export function without(items, item) {
|
||||
return items.filter((i) => i !== item);
|
||||
}
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export function isString(input) {
|
||||
return typeof input === 'string';
|
||||
}
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export function isObject(input) {
|
||||
return typeof input === 'object';
|
||||
}
|
||||
/**
|
||||
* repalcement for _.xor
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export function xor(itemsA, itemsB) {
|
||||
const map = new Map();
|
||||
const insertItem = (item) => {
|
||||
map.set(item, map.has(item) ? map.get(item) + 1 : 1);
|
||||
};
|
||||
itemsA.forEach(insertItem);
|
||||
itemsB.forEach(insertItem);
|
||||
const result = [];
|
||||
map.forEach((count, key) => {
|
||||
if (count === 1) {
|
||||
result.push(key);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* replacement for _.intersection
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export function intersection(itemsA, itemsB) {
|
||||
return itemsA.filter((t) => itemsB.indexOf(t) > -1);
|
||||
}
|
||||
2
node_modules/dnd-core/lib/utils/matchesType.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/utils/matchesType.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Identifier } from '../interfaces';
|
||||
export declare function matchesType(targetType: Identifier | Identifier[] | null, draggedItemType: Identifier | null): boolean;
|
||||
8
node_modules/dnd-core/lib/utils/matchesType.js
generated
vendored
Normal file
8
node_modules/dnd-core/lib/utils/matchesType.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export function matchesType(targetType, draggedItemType) {
|
||||
if (draggedItemType === null) {
|
||||
return targetType === null;
|
||||
}
|
||||
return Array.isArray(targetType)
|
||||
? targetType.some((t) => t === draggedItemType)
|
||||
: targetType === draggedItemType;
|
||||
}
|
||||
Reference in New Issue
Block a user