uawdijnntqw1x1x1
IP : 216.73.216.86
Hostname : 6.87.74.97.host.secureserver.net
Kernel : Linux 6.87.74.97.host.secureserver.net 4.18.0-553.83.1.el8_10.x86_64 #1 SMP Mon Nov 10 04:22:44 EST 2025 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
emeraadmin
/
www
/
js
/
..
/
node_modules
/
array-slice
/
..
/
array-slice
/
..
/
..
/
4d695
/
dnd-core.tar
/
/
package.json000064400000003173151701466600007044 0ustar00{ "_from": "dnd-core@^11.1.3", "_id": "dnd-core@11.1.3", "_inBundle": false, "_integrity": "sha512-QugF55dNW+h+vzxVJ/LSJeTeUw9MCJ2cllhmVThVPEtF16ooBkxj0WBE5RB+AceFxMFo1rO6bJKXtqKl+JNnyA==", "_location": "/dnd-core", "_phantomChildren": {}, "_requested": { "type": "range", "registry": true, "raw": "dnd-core@^11.1.3", "name": "dnd-core", "escapedName": "dnd-core", "rawSpec": "^11.1.3", "saveSpec": null, "fetchSpec": "^11.1.3" }, "_requiredBy": [ "/react-dnd", "/react-dnd-html5-backend" ], "_resolved": "https://registry.npmjs.org/dnd-core/-/dnd-core-11.1.3.tgz", "_shasum": "f92099ba7245e49729d2433157031a6267afcc98", "_spec": "dnd-core@^11.1.3", "_where": "C:\\xampp\\htdocs\\emeraltd\\node_modules\\react-dnd", "bugs": { "url": "https://github.com/react-dnd/react-dnd/issues" }, "bundleDependencies": false, "dependencies": { "@react-dnd/asap": "^4.0.0", "@react-dnd/invariant": "^2.0.0", "redux": "^4.0.4" }, "deprecated": false, "description": "Drag and drop sans the GUI", "gitHead": "32f16c09f0e8560c2a439f3a7fc2e0e8aec3b973", "homepage": "https://github.com/react-dnd/react-dnd#readme", "license": "MIT", "main": "./dist/cjs/index.js", "module": "./dist/esm/index.js", "name": "dnd-core", "repository": { "type": "git", "url": "git+https://github.com/react-dnd/react-dnd.git" }, "scripts": { "build": "../../../scripts/build_package.sh", "clean": "../../../scripts/clean_package.sh", "start": "../../../scripts/watch_package.sh" }, "sideEffects": false, "types": "./lib/index.d.ts", "version": "11.1.3" } lib/contracts.d.ts000064400000000472151701466600010115 0ustar00import { DragSource, DropTarget, Identifier } from './interfaces'; export declare function validateSourceContract(source: DragSource): void; export declare function validateTargetContract(target: DropTarget): void; export declare function validateType(type: Identifier | Identifier[], allowArray?: boolean): void; lib/reducers/refCount.js000064400000000575151701466600011266 0ustar00import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry'; export function reduce(state = 0, action) { switch (action.type) { case ADD_SOURCE: case ADD_TARGET: return state + 1; case REMOVE_SOURCE: case REMOVE_TARGET: return state - 1; default: return state; } } lib/reducers/dirtyHandlerIds.d.ts000064400000000430151701466600013014 0ustar00import { Action } from '../interfaces'; export declare type State = string[]; export interface DirtyHandlerIdPayload { targetIds: string[]; prevTargetIds: string[]; } export declare function reduce(_state: State | undefined, action: Action<DirtyHandlerIdPayload>): State; lib/reducers/refCount.d.ts000064400000000243151701466600011512 0ustar00import { Action } from '../interfaces'; export declare type State = number; export declare function reduce(state: number | undefined, action: Action<any>): State; lib/reducers/index.js000064400000001527151701466600010606 0ustar00import { reduce as dragOffset } from './dragOffset'; import { reduce as dragOperation, } from './dragOperation'; import { reduce as refCount } from './refCount'; import { reduce as dirtyHandlerIds, } from './dirtyHandlerIds'; import { reduce as stateId } from './stateId'; import { get } from '../utils/js_utils'; export function reduce(state = {}, action) { return { dirtyHandlerIds: dirtyHandlerIds(state.dirtyHandlerIds, { type: action.type, payload: { ...action.payload, prevTargetIds: get(state, 'dragOperation.targetIds', []), }, }), dragOffset: dragOffset(state.dragOffset, action), refCount: refCount(state.refCount, action), dragOperation: dragOperation(state.dragOperation, action), stateId: stateId(state.stateId), }; } lib/reducers/dragOffset.d.ts000064400000000530151701466600012010 0ustar00import { XYCoord, Action } from '../interfaces'; export interface State { initialSourceClientOffset: XYCoord | null; initialClientOffset: XYCoord | null; clientOffset: XYCoord | null; } export declare function reduce(state: State | undefined, action: Action<{ sourceClientOffset: XYCoord; clientOffset: XYCoord; }>): State; lib/reducers/dragOffset.js000064400000001774151701466600011567 0ustar00import { INIT_COORDS, BEGIN_DRAG, HOVER, END_DRAG, DROP, } from '../actions/dragDrop'; import { areCoordsEqual } from '../utils/equality'; const initialState = { initialSourceClientOffset: null, initialClientOffset: null, clientOffset: null, }; export function reduce(state = initialState, action) { const { payload } = action; switch (action.type) { case INIT_COORDS: case BEGIN_DRAG: return { initialSourceClientOffset: payload.sourceClientOffset, initialClientOffset: payload.clientOffset, clientOffset: payload.clientOffset, }; case HOVER: if (areCoordsEqual(state.clientOffset, payload.clientOffset)) { return state; } return { ...state, clientOffset: payload.clientOffset, }; case END_DRAG: case DROP: return initialState; default: return state; } } lib/reducers/dirtyHandlerIds.js000064400000003007151701466600012563 0ustar00import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop'; import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry'; import { areArraysEqual } from '../utils/equality'; import { NONE, ALL } from '../utils/dirtiness'; import { xor } from '../utils/js_utils'; export function reduce( // eslint-disable-next-line @typescript-eslint/no-unused-vars _state = NONE, action) { switch (action.type) { case HOVER: break; case ADD_SOURCE: case ADD_TARGET: case REMOVE_TARGET: case REMOVE_SOURCE: return NONE; case BEGIN_DRAG: case PUBLISH_DRAG_SOURCE: case END_DRAG: case DROP: default: return ALL; } const { targetIds = [], prevTargetIds = [] } = action.payload; const result = xor(targetIds, prevTargetIds); const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds); if (!didChange) { return NONE; } // Check the target ids at the innermost position. If they are valid, add them // to the result const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; const innermostTargetId = targetIds[targetIds.length - 1]; if (prevInnermostTargetId !== innermostTargetId) { if (prevInnermostTargetId) { result.push(prevInnermostTargetId); } if (innermostTargetId) { result.push(innermostTargetId); } } return result; } lib/reducers/dragOperation.d.ts000064400000001030151701466600012516 0ustar00import { Identifier, Action } from '../interfaces'; export interface State { itemType: Identifier | Identifier[] | null; item: any; sourceId: string | null; targetIds: string[]; dropResult: any; didDrop: boolean; isSourcePublic: boolean | null; } export declare function reduce(state: State | undefined, action: Action<{ itemType: Identifier | Identifier[]; item: any; sourceId: string; targetId: string; targetIds: string[]; isSourcePublic: boolean; dropResult: any; }>): State; lib/reducers/index.d.ts000064400000001144151701466600011035 0ustar00import { State as DragOffsetState } from './dragOffset'; import { State as DragOperationState } from './dragOperation'; import { State as RefCountState } from './refCount'; import { State as DirtyHandlerIdsState } from './dirtyHandlerIds'; import { State as StateIdState } from './stateId'; import { Action } from 'interfaces'; export interface State { dirtyHandlerIds: DirtyHandlerIdsState; dragOffset: DragOffsetState; refCount: RefCountState; dragOperation: DragOperationState; stateId: StateIdState; } export declare function reduce(state: State | undefined, action: Action<any>): State; lib/reducers/stateId.js000064400000000074151701466600011070 0ustar00export function reduce(state = 0) { return state + 1; } lib/reducers/dragOperation.js000064400000003552151701466600012275 0ustar00import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop'; import { REMOVE_TARGET } from '../actions/registry'; import { without } from '../utils/js_utils'; const initialState = { itemType: null, item: null, sourceId: null, targetIds: [], dropResult: null, didDrop: false, isSourcePublic: null, }; export function reduce(state = initialState, action) { const { payload } = action; switch (action.type) { case BEGIN_DRAG: return { ...state, itemType: payload.itemType, item: payload.item, sourceId: payload.sourceId, isSourcePublic: payload.isSourcePublic, dropResult: null, didDrop: false, }; case PUBLISH_DRAG_SOURCE: return { ...state, isSourcePublic: true, }; case HOVER: return { ...state, targetIds: payload.targetIds, }; case REMOVE_TARGET: if (state.targetIds.indexOf(payload.targetId) === -1) { return state; } return { ...state, targetIds: without(state.targetIds, payload.targetId), }; case DROP: return { ...state, dropResult: payload.dropResult, didDrop: true, targetIds: [], }; case END_DRAG: return { ...state, itemType: null, item: null, sourceId: null, dropResult: null, didDrop: false, isSourcePublic: null, targetIds: [], }; default: return state; } } lib/reducers/stateId.d.ts000064400000000132151701466600011317 0ustar00export declare type State = number; export declare function reduce(state?: State): State; lib/factories.js000064400000000536151701466600007641 0ustar00import { DragDropManagerImpl } from './DragDropManagerImpl'; export function createDragDropManager(backendFactory, globalContext, backendOptions, debugMode) { const manager = new DragDropManagerImpl(debugMode); const backend = backendFactory(manager, globalContext, backendOptions); manager.receiveBackend(backend); return manager; } lib/factories.d.ts000064400000000346151701466600010074 0ustar00import { DragDropManager, BackendFactory } from './interfaces'; export declare function createDragDropManager(backendFactory: BackendFactory, globalContext: unknown, backendOptions: unknown, debugMode?: boolean): DragDropManager; lib/DragDropManagerImpl.js000064400000004751151701466600011504 0ustar00import { createStore } from 'redux'; import { reduce } from './reducers'; import { createDragDropActions } from './actions/dragDrop'; import { DragDropMonitorImpl } from './DragDropMonitorImpl'; import { HandlerRegistryImpl } from './HandlerRegistryImpl'; function makeStoreInstance(debugMode) { // TODO: if we ever make a react-native version of this, // we'll need to consider how to pull off dev-tooling const reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__; return createStore(reduce, debugMode && reduxDevTools && reduxDevTools({ name: 'dnd-core', instanceId: 'dnd-core', })); } export class DragDropManagerImpl { constructor(debugMode = false) { this.isSetUp = false; this.handleRefCountChange = () => { const shouldSetUp = this.store.getState().refCount > 0; if (this.backend) { if (shouldSetUp && !this.isSetUp) { this.backend.setup(); this.isSetUp = true; } else if (!shouldSetUp && this.isSetUp) { this.backend.teardown(); this.isSetUp = false; } } }; const store = makeStoreInstance(debugMode); this.store = store; this.monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store)); store.subscribe(this.handleRefCountChange); } receiveBackend(backend) { this.backend = backend; } getMonitor() { return this.monitor; } getBackend() { return this.backend; } getRegistry() { return this.monitor.registry; } getActions() { /* eslint-disable-next-line @typescript-eslint/no-this-alias */ const manager = this; const { dispatch } = this.store; function bindActionCreator(actionCreator) { return (...args) => { const action = actionCreator.apply(manager, args); if (typeof action !== 'undefined') { dispatch(action); } }; } const actions = createDragDropActions(this); return Object.keys(actions).reduce((boundActions, key) => { const action = actions[key]; boundActions[key] = bindActionCreator(action); return boundActions; }, {}); } dispatch(action) { this.store.dispatch(action); } } lib/HandlerRegistryImpl.js000064400000010675151701466600011617 0ustar00import { invariant } from '@react-dnd/invariant'; import { addSource, addTarget, removeSource, removeTarget, } from './actions/registry'; import { getNextUniqueId } from './utils/getNextUniqueId'; import { HandlerRole, } from './interfaces'; import { validateSourceContract, validateTargetContract, validateType, } from './contracts'; import { asap } from '@react-dnd/asap'; function getNextHandlerId(role) { const id = getNextUniqueId().toString(); switch (role) { case HandlerRole.SOURCE: return `S${id}`; case HandlerRole.TARGET: return `T${id}`; default: throw new Error(`Unknown Handler Role: ${role}`); } } function parseRoleFromHandlerId(handlerId) { switch (handlerId[0]) { case 'S': return HandlerRole.SOURCE; case 'T': return HandlerRole.TARGET; default: invariant(false, `Cannot parse handler ID: ${handlerId}`); } } function mapContainsValue(map, searchValue) { const entries = map.entries(); let isDone = false; do { const { done, value: [, value], } = entries.next(); if (value === searchValue) { return true; } isDone = !!done; } while (!isDone); return false; } export class HandlerRegistryImpl { constructor(store) { this.types = new Map(); this.dragSources = new Map(); this.dropTargets = new Map(); this.pinnedSourceId = null; this.pinnedSource = null; this.store = store; } addSource(type, source) { validateType(type); validateSourceContract(source); const sourceId = this.addHandler(HandlerRole.SOURCE, type, source); this.store.dispatch(addSource(sourceId)); return sourceId; } addTarget(type, target) { validateType(type, true); validateTargetContract(target); const targetId = this.addHandler(HandlerRole.TARGET, type, target); this.store.dispatch(addTarget(targetId)); return targetId; } containsHandler(handler) { return (mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler)); } getSource(sourceId, includePinned = false) { invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); const isPinned = includePinned && sourceId === this.pinnedSourceId; const source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId); return source; } getTarget(targetId) { invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); return this.dropTargets.get(targetId); } getSourceType(sourceId) { invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); return this.types.get(sourceId); } getTargetType(targetId) { invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); return this.types.get(targetId); } isSourceId(handlerId) { const role = parseRoleFromHandlerId(handlerId); return role === HandlerRole.SOURCE; } isTargetId(handlerId) { const role = parseRoleFromHandlerId(handlerId); return role === HandlerRole.TARGET; } removeSource(sourceId) { invariant(this.getSource(sourceId), 'Expected an existing source.'); this.store.dispatch(removeSource(sourceId)); asap(() => { this.dragSources.delete(sourceId); this.types.delete(sourceId); }); } removeTarget(targetId) { invariant(this.getTarget(targetId), 'Expected an existing target.'); this.store.dispatch(removeTarget(targetId)); this.dropTargets.delete(targetId); this.types.delete(targetId); } pinSource(sourceId) { const source = this.getSource(sourceId); invariant(source, 'Expected an existing source.'); this.pinnedSourceId = sourceId; this.pinnedSource = source; } unpinSource() { invariant(this.pinnedSource, 'No source is pinned at the time.'); this.pinnedSourceId = null; this.pinnedSource = null; } addHandler(role, type, handler) { const id = getNextHandlerId(role); this.types.set(id, type); if (role === HandlerRole.SOURCE) { this.dragSources.set(id, handler); } else if (role === HandlerRole.TARGET) { this.dropTargets.set(id, handler); } return id; } } lib/DragDropManagerImpl.d.ts000064400000001110151701466600011722 0ustar00import { Action } from 'redux'; import { Backend, DragDropActions, DragDropMonitor, DragDropManager, HandlerRegistry } from './interfaces'; export declare class DragDropManagerImpl implements DragDropManager { private store; private monitor; private backend; private isSetUp; constructor(debugMode?: boolean); receiveBackend(backend: Backend): void; getMonitor(): DragDropMonitor; getBackend(): Backend; getRegistry(): HandlerRegistry; getActions(): DragDropActions; dispatch(action: Action<any>): void; private handleRefCountChange; } lib/DragDropMonitorImpl.js000064400000012501151701466600011551 0ustar00import { invariant } from '@react-dnd/invariant'; import { matchesType } from './utils/matchesType'; import { getSourceClientOffset, getDifferenceFromInitialOffset, } from './utils/coords'; import { areDirty } from './utils/dirtiness'; export class DragDropMonitorImpl { constructor(store, registry) { this.store = store; this.registry = registry; } subscribeToStateChange(listener, options = { handlerIds: undefined }) { const { handlerIds } = options; invariant(typeof listener === 'function', 'listener must be a function.'); invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.'); let prevStateId = this.store.getState().stateId; const handleChange = () => { const state = this.store.getState(); const currentStateId = state.stateId; try { const canSkipListener = currentStateId === prevStateId || (currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds)); if (!canSkipListener) { listener(); } } finally { prevStateId = currentStateId; } }; return this.store.subscribe(handleChange); } subscribeToOffsetChange(listener) { invariant(typeof listener === 'function', 'listener must be a function.'); let previousState = this.store.getState().dragOffset; const handleChange = () => { const nextState = this.store.getState().dragOffset; if (nextState === previousState) { return; } previousState = nextState; listener(); }; return this.store.subscribe(handleChange); } canDragSource(sourceId) { if (!sourceId) { return false; } const source = this.registry.getSource(sourceId); invariant(source, 'Expected to find a valid source.'); if (this.isDragging()) { return false; } return source.canDrag(this, sourceId); } canDropOnTarget(targetId) { // undefined on initial render if (!targetId) { return false; } const target = this.registry.getTarget(targetId); invariant(target, 'Expected to find a valid target.'); if (!this.isDragging() || this.didDrop()) { return false; } const targetType = this.registry.getTargetType(targetId); const draggedItemType = this.getItemType(); return (matchesType(targetType, draggedItemType) && target.canDrop(this, targetId)); } isDragging() { return Boolean(this.getItemType()); } isDraggingSource(sourceId) { // undefined on initial render if (!sourceId) { return false; } const source = this.registry.getSource(sourceId, true); invariant(source, 'Expected to find a valid source.'); if (!this.isDragging() || !this.isSourcePublic()) { return false; } const sourceType = this.registry.getSourceType(sourceId); const draggedItemType = this.getItemType(); if (sourceType !== draggedItemType) { return false; } return source.isDragging(this, sourceId); } isOverTarget(targetId, options = { shallow: false }) { // undefined on initial render if (!targetId) { return false; } const { shallow } = options; if (!this.isDragging()) { return false; } const targetType = this.registry.getTargetType(targetId); const draggedItemType = this.getItemType(); if (draggedItemType && !matchesType(targetType, draggedItemType)) { return false; } const targetIds = this.getTargetIds(); if (!targetIds.length) { return false; } const index = targetIds.indexOf(targetId); if (shallow) { return index === targetIds.length - 1; } else { return index > -1; } } getItemType() { return this.store.getState().dragOperation.itemType; } getItem() { return this.store.getState().dragOperation.item; } getSourceId() { return this.store.getState().dragOperation.sourceId; } getTargetIds() { return this.store.getState().dragOperation.targetIds; } getDropResult() { return this.store.getState().dragOperation.dropResult; } didDrop() { return this.store.getState().dragOperation.didDrop; } isSourcePublic() { return Boolean(this.store.getState().dragOperation.isSourcePublic); } getInitialClientOffset() { return this.store.getState().dragOffset.initialClientOffset; } getInitialSourceClientOffset() { return this.store.getState().dragOffset.initialSourceClientOffset; } getClientOffset() { return this.store.getState().dragOffset.clientOffset; } getSourceClientOffset() { return getSourceClientOffset(this.store.getState().dragOffset); } getDifferenceFromInitialOffset() { return getDifferenceFromInitialOffset(this.store.getState().dragOffset); } } lib/utils/getNextUniqueId.js000064400000000127151701466600012100 0ustar00let nextUniqueId = 0; export function getNextUniqueId() { return nextUniqueId++; } lib/utils/coords.js000064400000002575151701466600010320 0ustar00/** * 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); } lib/utils/dirtiness.d.ts000064400000000523151701466600011256 0ustar00export 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; lib/utils/getNextUniqueId.d.ts000064400000000063151701466600012333 0ustar00export declare function getNextUniqueId(): number; lib/utils/matchesType.d.ts000064400000000254151701466600011541 0ustar00import { Identifier } from '../interfaces'; export declare function matchesType(targetType: Identifier | Identifier[] | null, draggedItemType: Identifier | null): boolean; lib/utils/equality.js000064400000001447151701466600010661 0ustar00export 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; } lib/utils/js_utils.d.ts000064400000001454151701466600011112 0ustar00/** * 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[]; lib/utils/coords.d.ts000064400000001760151701466600010547 0ustar00import { 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; lib/utils/matchesType.js000064400000000422151701466600011302 0ustar00export function matchesType(targetType, draggedItemType) { if (draggedItemType === null) { return targetType === null; } return Array.isArray(targetType) ? targetType.some((t) => t === draggedItemType) : targetType === draggedItemType; } lib/utils/js_utils.js000064400000002447151701466600010661 0ustar00// 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); } lib/utils/dirtiness.js000064400000001126151701466600011022 0ustar00import { 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; } lib/utils/equality.d.ts000064400000001156151701466600011112 0ustar00import { 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; lib/index.js000064400000000073151701466600006765 0ustar00export * from './interfaces'; export * from './factories'; lib/interfaces.d.ts000064400000015545151701466600010247 0ustar00export declare type Identifier = string | symbol; export declare type SourceType = Identifier; export declare type TargetType = Identifier | Identifier[]; export declare type Unsubscribe = () => void; export declare type Listener = () => void; export interface XYCoord { x: number; y: number; } export declare enum HandlerRole { SOURCE = "SOURCE", TARGET = "TARGET" } export interface Backend { setup(): void; teardown(): void; connectDragSource(sourceId: any, node?: any, options?: any): Unsubscribe; connectDragPreview(sourceId: any, node?: any, options?: any): Unsubscribe; connectDropTarget(targetId: any, node?: any, options?: any): Unsubscribe; profile(): Record<string, number>; } export interface DragDropMonitor { subscribeToStateChange(listener: Listener, options?: { handlerIds: Identifier[] | undefined; }): Unsubscribe; subscribeToOffsetChange(listener: Listener): Unsubscribe; canDragSource(sourceId: Identifier | undefined): boolean; canDropOnTarget(targetId: Identifier | undefined): boolean; /** * Returns true if a drag operation is in progress, and either the owner initiated the drag, or its isDragging() * is defined and returns true. */ isDragging(): boolean; isDraggingSource(sourceId: Identifier | undefined): boolean; isOverTarget(targetId: Identifier | undefined, options?: { shallow?: boolean; }): boolean; /** * Returns a string or an ES6 symbol identifying the type of the current dragged item. Returns null if no item is being dragged. */ getItemType(): Identifier | null; /** * Returns a plain object representing the currently dragged item. Every drag source must specify it by returning an object * from its beginDrag() method. Returns null if no item is being dragged. */ getItem(): any; getSourceId(): Identifier | null; getTargetIds(): Identifier[]; /** * Returns a plain object representing the last recorded drop result. The drop targets may optionally specify it by returning an * object from their drop() methods. When a chain of drop() is dispatched for the nested targets, bottom up, any parent that * explicitly returns its own result from drop() overrides the child drop result previously set by the child. Returns null if * called outside endDrag(). */ getDropResult(): any; /** * Returns true if some drop target has handled the drop event, false otherwise. Even if a target did not return a drop result, * didDrop() returns true. Use it inside endDrag() to test whether any drop target has handled the drop. Returns false if called * outside endDrag(). */ didDrop(): boolean; isSourcePublic(): boolean | null; /** * Returns the { x, y } client offset of the pointer at the time when the current drag operation has started. * Returns null if no item is being dragged. */ getInitialClientOffset(): XYCoord | null; /** * Returns the { x, y } client offset of the drag source component's root DOM node at the time when the current drag * operation has started. Returns null if no item is being dragged. */ getInitialSourceClientOffset(): XYCoord | null; /** * Returns the last recorded { x, y } client offset of the pointer while a drag operation is in progress. * Returns null if no item is being dragged. */ getClientOffset(): XYCoord | null; /** * Returns the projected { x, y } client offset of the drag source component's root DOM node, 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. */ getSourceClientOffset(): XYCoord | null; /** * Returns the { x, y } difference between the last recorded client offset of the pointer and the client offset when the current * drag operation has started. Returns null if no item is being dragged. */ getDifferenceFromInitialOffset(): XYCoord | null; } export interface HandlerRegistry { addSource(type: SourceType, source: DragSource): Identifier; addTarget(type: TargetType, target: DropTarget): Identifier; containsHandler(handler: DragSource | DropTarget): boolean; getSource(sourceId: Identifier, includePinned?: boolean): DragSource; getSourceType(sourceId: Identifier): SourceType; getTargetType(targetId: Identifier): TargetType; getTarget(targetId: Identifier): DropTarget; isSourceId(handlerId: Identifier): boolean; isTargetId(handlerId: Identifier): boolean; removeSource(sourceId: Identifier): void; removeTarget(targetId: Identifier): void; pinSource(sourceId: Identifier): void; unpinSource(): void; } export interface Action<Payload> { type: Identifier; payload: Payload; } export interface SentinelAction { type: Identifier; } export declare type ActionCreator<Payload> = (args: any[]) => Action<Payload>; export interface BeginDragOptions { publishSource?: boolean; clientOffset?: XYCoord; getSourceClientOffset?: (sourceId: Identifier) => XYCoord; } export interface InitCoordsPayload { clientOffset: XYCoord | null; sourceClientOffset: XYCoord | null; } export interface BeginDragPayload { itemType: Identifier; item: any; sourceId: Identifier; clientOffset: XYCoord | null; sourceClientOffset: XYCoord | null; isSourcePublic: boolean; } export interface HoverPayload { targetIds: Identifier[]; clientOffset: XYCoord | null; } export interface HoverOptions { clientOffset?: XYCoord; } export interface DropPayload { dropResult: any; } export interface TargetIdPayload { targetId: Identifier; } export interface SourceIdPayload { sourceId: Identifier; } export interface DragDropActions { beginDrag(sourceIds?: Identifier[], options?: any): Action<BeginDragPayload> | undefined; publishDragSource(): SentinelAction | undefined; hover(targetIds: Identifier[], options?: any): Action<HoverPayload>; drop(options?: any): void; endDrag(): SentinelAction; } export interface DragDropManager { getMonitor(): DragDropMonitor; getBackend(): Backend; getRegistry(): HandlerRegistry; getActions(): DragDropActions; dispatch(action: any): void; } export declare type BackendFactory = (manager: DragDropManager, globalContext?: any, configuration?: any) => Backend; export interface DragSource { beginDrag(monitor: DragDropMonitor, targetId: Identifier): void; endDrag(monitor: DragDropMonitor, targetId: Identifier): void; canDrag(monitor: DragDropMonitor, targetId: Identifier): boolean; isDragging(monitor: DragDropMonitor, targetId: Identifier): boolean; } export interface DropTarget { canDrop(monitor: DragDropMonitor, targetId: Identifier): boolean; hover(monitor: DragDropMonitor, targetId: Identifier): void; drop(monitor: DragDropMonitor, targetId: Identifier): any; } lib/DragDropMonitorImpl.d.ts000064400000002420151701466600012004 0ustar00import { Store } from 'redux'; import { State } from './reducers'; import { DragDropMonitor, Listener, Unsubscribe, XYCoord, HandlerRegistry, Identifier } from './interfaces'; export declare class DragDropMonitorImpl implements DragDropMonitor { private store; readonly registry: HandlerRegistry; constructor(store: Store<State>, registry: HandlerRegistry); subscribeToStateChange(listener: Listener, options?: { handlerIds: string[] | undefined; }): Unsubscribe; subscribeToOffsetChange(listener: Listener): Unsubscribe; canDragSource(sourceId: string | undefined): boolean; canDropOnTarget(targetId: string | undefined): boolean; isDragging(): boolean; isDraggingSource(sourceId: string | undefined): boolean; isOverTarget(targetId: string | undefined, options?: { shallow: boolean; }): boolean; getItemType(): Identifier; getItem(): any; getSourceId(): string | null; getTargetIds(): string[]; getDropResult(): any; didDrop(): boolean; isSourcePublic(): boolean; getInitialClientOffset(): XYCoord | null; getInitialSourceClientOffset(): XYCoord | null; getClientOffset(): XYCoord | null; getSourceClientOffset(): XYCoord | null; getDifferenceFromInitialOffset(): XYCoord | null; } lib/HandlerRegistryImpl.d.ts000064400000002115151701466600012041 0ustar00import { Store } from 'redux'; import { State } from './reducers'; import { DragSource, DropTarget, SourceType, TargetType, Identifier, HandlerRegistry } from './interfaces'; export declare class HandlerRegistryImpl implements HandlerRegistry { private types; private dragSources; private dropTargets; private pinnedSourceId; private pinnedSource; private store; constructor(store: Store<State>); addSource(type: SourceType, source: DragSource): string; addTarget(type: TargetType, target: DropTarget): string; containsHandler(handler: DragSource | DropTarget): boolean; getSource(sourceId: string, includePinned?: boolean): DragSource; getTarget(targetId: string): DropTarget; getSourceType(sourceId: string): Identifier; getTargetType(targetId: string): Identifier | Identifier[]; isSourceId(handlerId: string): boolean; isTargetId(handlerId: string): boolean; removeSource(sourceId: string): void; removeTarget(targetId: string): void; pinSource(sourceId: string): void; unpinSource(): void; private addHandler; } lib/actions/registry.js000064400000001404151701466600011165 0ustar00export const ADD_SOURCE = 'dnd-core/ADD_SOURCE'; export const ADD_TARGET = 'dnd-core/ADD_TARGET'; export const REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE'; export const REMOVE_TARGET = 'dnd-core/REMOVE_TARGET'; export function addSource(sourceId) { return { type: ADD_SOURCE, payload: { sourceId, }, }; } export function addTarget(targetId) { return { type: ADD_TARGET, payload: { targetId, }, }; } export function removeSource(sourceId) { return { type: REMOVE_SOURCE, payload: { sourceId, }, }; } export function removeTarget(targetId) { return { type: REMOVE_TARGET, payload: { targetId, }, }; } lib/actions/registry.d.ts000064400000001170151701466600011421 0ustar00import { Action, SourceIdPayload, TargetIdPayload } from '../interfaces'; export declare const ADD_SOURCE = "dnd-core/ADD_SOURCE"; export declare const ADD_TARGET = "dnd-core/ADD_TARGET"; export declare const REMOVE_SOURCE = "dnd-core/REMOVE_SOURCE"; export declare const REMOVE_TARGET = "dnd-core/REMOVE_TARGET"; export declare function addSource(sourceId: string): Action<SourceIdPayload>; export declare function addTarget(targetId: string): Action<TargetIdPayload>; export declare function removeSource(sourceId: string): Action<SourceIdPayload>; export declare function removeTarget(targetId: string): Action<TargetIdPayload>; lib/actions/dragDrop/local/setClientOffset.d.ts000064400000000341151701466600015505 0ustar00import { XYCoord } from '../../../interfaces'; import { AnyAction } from 'redux'; export declare function setClientOffset(clientOffset: XYCoord | null | undefined, sourceClientOffset?: XYCoord | null | undefined): AnyAction; lib/actions/dragDrop/local/setClientOffset.js000064400000000447151701466600015260 0ustar00import { INIT_COORDS } from '../types'; export function setClientOffset(clientOffset, sourceClientOffset) { return { type: INIT_COORDS, payload: { sourceClientOffset: sourceClientOffset || null, clientOffset: clientOffset || null, }, }; } lib/actions/dragDrop/endDrag.d.ts000064400000000233151701466600012656 0ustar00import { DragDropManager, SentinelAction } from '../../interfaces'; export declare function createEndDrag(manager: DragDropManager): () => SentinelAction; lib/actions/dragDrop/types.js000064400000000440151701466600012222 0ustar00export const INIT_COORDS = 'dnd-core/INIT_COORDS'; export const BEGIN_DRAG = 'dnd-core/BEGIN_DRAG'; export const PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE'; export const HOVER = 'dnd-core/HOVER'; export const DROP = 'dnd-core/DROP'; export const END_DRAG = 'dnd-core/END_DRAG'; lib/actions/dragDrop/publishDragSource.js000064400000000443151701466600014506 0ustar00import { PUBLISH_DRAG_SOURCE } from './types'; export function createPublishDragSource(manager) { return function publishDragSource() { const monitor = manager.getMonitor(); if (monitor.isDragging()) { return { type: PUBLISH_DRAG_SOURCE }; } }; } lib/actions/dragDrop/hover.d.ts000064400000000352151701466600012437 0ustar00import { Action, DragDropManager, HoverPayload, HoverOptions } from '../../interfaces'; export declare function createHover(manager: DragDropManager): (targetIdsArg: string[], { clientOffset }?: HoverOptions) => Action<HoverPayload>; lib/actions/dragDrop/endDrag.js000064400000001257151701466600012431 0ustar00import { invariant } from '@react-dnd/invariant'; import { END_DRAG } from './types'; export function createEndDrag(manager) { return function endDrag() { const monitor = manager.getMonitor(); const registry = manager.getRegistry(); verifyIsDragging(monitor); const sourceId = monitor.getSourceId(); if (sourceId != null) { const source = registry.getSource(sourceId, true); source.endDrag(monitor, sourceId); registry.unpinSource(); } return { type: END_DRAG }; }; } function verifyIsDragging(monitor) { invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.'); } lib/actions/dragDrop/index.js000064400000001040151701466600012162 0ustar00import { createBeginDrag } from './beginDrag'; import { createPublishDragSource } from './publishDragSource'; import { createHover } from './hover'; import { createDrop } from './drop'; import { createEndDrag } from './endDrag'; export * from './types'; export function createDragDropActions(manager) { return { beginDrag: createBeginDrag(manager), publishDragSource: createPublishDragSource(manager), hover: createHover(manager), drop: createDrop(manager), endDrag: createEndDrag(manager), }; } lib/actions/dragDrop/hover.js000064400000004350151701466600012205 0ustar00import { invariant } from '@react-dnd/invariant'; import { matchesType } from '../../utils/matchesType'; import { HOVER } from './types'; export function createHover(manager) { return function hover(targetIdsArg, { clientOffset } = {}) { verifyTargetIdsIsArray(targetIdsArg); const targetIds = targetIdsArg.slice(0); const monitor = manager.getMonitor(); const registry = manager.getRegistry(); checkInvariants(targetIds, monitor, registry); const draggedItemType = monitor.getItemType(); removeNonMatchingTargetIds(targetIds, registry, draggedItemType); hoverAllTargets(targetIds, monitor, registry); return { type: HOVER, payload: { targetIds, clientOffset: clientOffset || null, }, }; }; } function verifyTargetIdsIsArray(targetIdsArg) { invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.'); } function checkInvariants(targetIds, monitor, registry) { invariant(monitor.isDragging(), 'Cannot call hover while not dragging.'); invariant(!monitor.didDrop(), 'Cannot call hover after drop.'); for (let i = 0; i < targetIds.length; i++) { const targetId = targetIds[i]; invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.'); const target = registry.getTarget(targetId); invariant(target, 'Expected targetIds to be registered.'); } } function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) { // Remove those targetIds that don't match the targetType. This // fixes shallow isOver which would only be non-shallow because of // non-matching targets. for (let i = targetIds.length - 1; i >= 0; i--) { const targetId = targetIds[i]; const targetType = registry.getTargetType(targetId); if (!matchesType(targetType, draggedItemType)) { targetIds.splice(i, 1); } } } function hoverAllTargets(targetIds, monitor, registry) { // Finally call hover on all matching targets. targetIds.forEach(function (targetId) { const target = registry.getTarget(targetId); target.hover(monitor, targetId); }); } lib/actions/dragDrop/beginDrag.d.ts000064400000000417151701466600013200 0ustar00import { Action, DragDropManager, BeginDragPayload, BeginDragOptions, Identifier } from '../../interfaces'; export declare function createBeginDrag(manager: DragDropManager): (sourceIds?: Identifier[], options?: BeginDragOptions) => Action<BeginDragPayload> | undefined; lib/actions/dragDrop/publishDragSource.d.ts000064400000000261151701466600014740 0ustar00import { DragDropManager, SentinelAction } from '../../interfaces'; export declare function createPublishDragSource(manager: DragDropManager): () => SentinelAction | undefined; lib/actions/dragDrop/index.d.ts000064400000000270151701466600012422 0ustar00import { DragDropManager, DragDropActions } from '../../interfaces'; export * from './types'; export declare function createDragDropActions(manager: DragDropManager): DragDropActions; lib/actions/dragDrop/types.d.ts000064400000000520151701466600012455 0ustar00export declare const INIT_COORDS = "dnd-core/INIT_COORDS"; export declare const BEGIN_DRAG = "dnd-core/BEGIN_DRAG"; export declare const PUBLISH_DRAG_SOURCE = "dnd-core/PUBLISH_DRAG_SOURCE"; export declare const HOVER = "dnd-core/HOVER"; export declare const DROP = "dnd-core/DROP"; export declare const END_DRAG = "dnd-core/END_DRAG"; lib/actions/dragDrop/beginDrag.js000064400000005714151701466600012751 0ustar00import { invariant } from '@react-dnd/invariant'; import { setClientOffset } from './local/setClientOffset'; import { isObject } from '../../utils/js_utils'; import { BEGIN_DRAG, INIT_COORDS } from './types'; const ResetCoordinatesAction = { type: INIT_COORDS, payload: { clientOffset: null, sourceClientOffset: null, }, }; export function createBeginDrag(manager) { return function beginDrag(sourceIds = [], options = { publishSource: true, }) { const { publishSource = true, clientOffset, getSourceClientOffset, } = options; const monitor = manager.getMonitor(); const registry = manager.getRegistry(); // Initialize the coordinates using the client offset manager.dispatch(setClientOffset(clientOffset)); verifyInvariants(sourceIds, monitor, registry); // Get the draggable source const sourceId = getDraggableSource(sourceIds, monitor); if (sourceId === null) { manager.dispatch(ResetCoordinatesAction); return; } // Get the source client offset let sourceClientOffset = null; if (clientOffset) { if (!getSourceClientOffset) { throw new Error('getSourceClientOffset must be defined'); } verifyGetSourceClientOffsetIsFunction(getSourceClientOffset); sourceClientOffset = getSourceClientOffset(sourceId); } // Initialize the full coordinates manager.dispatch(setClientOffset(clientOffset, sourceClientOffset)); const source = registry.getSource(sourceId); const item = source.beginDrag(monitor, sourceId); verifyItemIsObject(item); registry.pinSource(sourceId); const itemType = registry.getSourceType(sourceId); return { type: BEGIN_DRAG, payload: { itemType, item, sourceId, clientOffset: clientOffset || null, sourceClientOffset: sourceClientOffset || null, isSourcePublic: !!publishSource, }, }; }; } function verifyInvariants(sourceIds, monitor, registry) { invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.'); sourceIds.forEach(function (sourceId) { invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.'); }); } function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) { invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); } function verifyItemIsObject(item) { invariant(isObject(item), 'Item must be an object.'); } function getDraggableSource(sourceIds, monitor) { let sourceId = null; for (let i = sourceIds.length - 1; i >= 0; i--) { if (monitor.canDragSource(sourceIds[i])) { sourceId = sourceIds[i]; break; } } return sourceId; } lib/actions/dragDrop/drop.d.ts000064400000000212151701466600012253 0ustar00import { DragDropManager } from '../../interfaces'; export declare function createDrop(manager: DragDropManager): (options?: {}) => void; lib/actions/dragDrop/drop.js000064400000003522151701466600012026 0ustar00import { invariant } from '@react-dnd/invariant'; import { DROP } from './types'; import { isObject } from '../../utils/js_utils'; export function createDrop(manager) { return function drop(options = {}) { const monitor = manager.getMonitor(); const registry = manager.getRegistry(); verifyInvariants(monitor); const targetIds = getDroppableTargets(monitor); // Multiple actions are dispatched here, which is why this doesn't return an action targetIds.forEach((targetId, index) => { const dropResult = determineDropResult(targetId, index, registry, monitor); const action = { type: DROP, payload: { dropResult: { ...options, ...dropResult, }, }, }; manager.dispatch(action); }); }; } function verifyInvariants(monitor) { invariant(monitor.isDragging(), 'Cannot call drop while not dragging.'); invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.'); } function determineDropResult(targetId, index, registry, monitor) { const target = registry.getTarget(targetId); let dropResult = target ? target.drop(monitor, targetId) : undefined; verifyDropResultType(dropResult); if (typeof dropResult === 'undefined') { dropResult = index === 0 ? {} : monitor.getDropResult(); } return dropResult; } function verifyDropResultType(dropResult) { invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.'); } function getDroppableTargets(monitor) { const targetIds = monitor .getTargetIds() .filter(monitor.canDropOnTarget, monitor); targetIds.reverse(); return targetIds; } lib/contracts.js000064400000002060151701466600007654 0ustar00import { invariant } from '@react-dnd/invariant'; export function validateSourceContract(source) { invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.'); invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.'); invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.'); } export function validateTargetContract(target) { invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.'); invariant(typeof target.hover === 'function', 'Expected hover to be a function.'); invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.'); } export function validateType(type, allowArray) { if (allowArray && Array.isArray(type)) { type.forEach((t) => validateType(t, false)); return; } invariant(typeof type === 'string' || typeof type === 'symbol', allowArray ? 'Type can only be a string, a symbol, or an array of either.' : 'Type can only be a string or a symbol.'); } lib/index.d.ts000064400000000073151701466600007221 0ustar00export * from './interfaces'; export * from './factories'; lib/interfaces.js000064400000000245151701466600010002 0ustar00export var HandlerRole; (function (HandlerRole) { HandlerRole["SOURCE"] = "SOURCE"; HandlerRole["TARGET"] = "TARGET"; })(HandlerRole || (HandlerRole = {})); LICENSE000064400000002067151701466600005564 0ustar00The MIT License (MIT) Copyright (c) 2015 Dan Abramov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. dist/cjs/reducers/refCount.js000064400000001070151701466600012231 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; var _registry = require("../actions/registry"); function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case _registry.ADD_SOURCE: case _registry.ADD_TARGET: return state + 1; case _registry.REMOVE_SOURCE: case _registry.REMOVE_TARGET: return state - 1; default: return state; } }dist/cjs/reducers/index.js000064400000004200151701466600011551 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; var _dragOffset = require("./dragOffset"); var _dragOperation = require("./dragOperation"); var _refCount = require("./refCount"); var _dirtyHandlerIds = require("./dirtyHandlerIds"); var _stateId = require("./stateId"); var _js_utils = require("../utils/js_utils"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var action = arguments.length > 1 ? arguments[1] : undefined; return { dirtyHandlerIds: (0, _dirtyHandlerIds.reduce)(state.dirtyHandlerIds, { type: action.type, payload: _objectSpread(_objectSpread({}, action.payload), {}, { prevTargetIds: (0, _js_utils.get)(state, 'dragOperation.targetIds', []) }) }), dragOffset: (0, _dragOffset.reduce)(state.dragOffset, action), refCount: (0, _refCount.reduce)(state.refCount, action), dragOperation: (0, _dragOperation.reduce)(state.dragOperation, action), stateId: (0, _stateId.reduce)(state.stateId) }; }dist/cjs/reducers/dragOffset.js000064400000004324151701466600012535 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; var _dragDrop = require("../actions/dragDrop"); var _equality = require("../utils/equality"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var initialState = { initialSourceClientOffset: null, initialClientOffset: null, clientOffset: null }; function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments.length > 1 ? arguments[1] : undefined; var payload = action.payload; switch (action.type) { case _dragDrop.INIT_COORDS: case _dragDrop.BEGIN_DRAG: return { initialSourceClientOffset: payload.sourceClientOffset, initialClientOffset: payload.clientOffset, clientOffset: payload.clientOffset }; case _dragDrop.HOVER: if ((0, _equality.areCoordsEqual)(state.clientOffset, payload.clientOffset)) { return state; } return _objectSpread(_objectSpread({}, state), {}, { clientOffset: payload.clientOffset }); case _dragDrop.END_DRAG: case _dragDrop.DROP: return initialState; default: return state; } }dist/cjs/reducers/dirtyHandlerIds.js000064400000003610151701466600013537 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; var _dragDrop = require("../actions/dragDrop"); var _registry = require("../actions/registry"); var _equality = require("../utils/equality"); var _dirtiness = require("../utils/dirtiness"); var _js_utils = require("../utils/js_utils"); function reduce() { var _state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _dirtiness.NONE; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case _dragDrop.HOVER: break; case _registry.ADD_SOURCE: case _registry.ADD_TARGET: case _registry.REMOVE_TARGET: case _registry.REMOVE_SOURCE: return _dirtiness.NONE; case _dragDrop.BEGIN_DRAG: case _dragDrop.PUBLISH_DRAG_SOURCE: case _dragDrop.END_DRAG: case _dragDrop.DROP: default: return _dirtiness.ALL; } var _action$payload = action.payload, _action$payload$targe = _action$payload.targetIds, targetIds = _action$payload$targe === void 0 ? [] : _action$payload$targe, _action$payload$prevT = _action$payload.prevTargetIds, prevTargetIds = _action$payload$prevT === void 0 ? [] : _action$payload$prevT; var result = (0, _js_utils.xor)(targetIds, prevTargetIds); var didChange = result.length > 0 || !(0, _equality.areArraysEqual)(targetIds, prevTargetIds); if (!didChange) { return _dirtiness.NONE; } // Check the target ids at the innermost position. If they are valid, add them // to the result var prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; var innermostTargetId = targetIds[targetIds.length - 1]; if (prevInnermostTargetId !== innermostTargetId) { if (prevInnermostTargetId) { result.push(prevInnermostTargetId); } if (innermostTargetId) { result.push(innermostTargetId); } } return result; }dist/cjs/reducers/stateId.js000064400000000350151701466600012041 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; return state + 1; }dist/cjs/reducers/dragOperation.js000064400000005767151701466600013263 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reduce = reduce; var _dragDrop = require("../actions/dragDrop"); var _registry = require("../actions/registry"); var _js_utils = require("../utils/js_utils"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } var initialState = { itemType: null, item: null, sourceId: null, targetIds: [], dropResult: null, didDrop: false, isSourcePublic: null }; function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments.length > 1 ? arguments[1] : undefined; var payload = action.payload; switch (action.type) { case _dragDrop.BEGIN_DRAG: return _objectSpread(_objectSpread({}, state), {}, { itemType: payload.itemType, item: payload.item, sourceId: payload.sourceId, isSourcePublic: payload.isSourcePublic, dropResult: null, didDrop: false }); case _dragDrop.PUBLISH_DRAG_SOURCE: return _objectSpread(_objectSpread({}, state), {}, { isSourcePublic: true }); case _dragDrop.HOVER: return _objectSpread(_objectSpread({}, state), {}, { targetIds: payload.targetIds }); case _registry.REMOVE_TARGET: if (state.targetIds.indexOf(payload.targetId) === -1) { return state; } return _objectSpread(_objectSpread({}, state), {}, { targetIds: (0, _js_utils.without)(state.targetIds, payload.targetId) }); case _dragDrop.DROP: return _objectSpread(_objectSpread({}, state), {}, { dropResult: payload.dropResult, didDrop: true, targetIds: [] }); case _dragDrop.END_DRAG: return _objectSpread(_objectSpread({}, state), {}, { itemType: null, item: null, sourceId: null, dropResult: null, didDrop: false, isSourcePublic: null, targetIds: [] }); default: return state; } }dist/cjs/factories.js000064400000000750151701466600010613 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDragDropManager = createDragDropManager; var _DragDropManagerImpl = require("./DragDropManagerImpl"); function createDragDropManager(backendFactory, globalContext, backendOptions, debugMode) { var manager = new _DragDropManagerImpl.DragDropManagerImpl(debugMode); var backend = backendFactory(manager, globalContext, backendOptions); manager.receiveBackend(backend); return manager; }dist/cjs/DragDropManagerImpl.js000064400000007520151701466600012455 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DragDropManagerImpl = void 0; var _redux = require("redux"); var _reducers = require("./reducers"); var _dragDrop = require("./actions/dragDrop"); var _DragDropMonitorImpl = require("./DragDropMonitorImpl"); var _HandlerRegistryImpl = require("./HandlerRegistryImpl"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function makeStoreInstance(debugMode) { // TODO: if we ever make a react-native version of this, // we'll need to consider how to pull off dev-tooling var reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__; return (0, _redux.createStore)(_reducers.reduce, debugMode && reduxDevTools && reduxDevTools({ name: 'dnd-core', instanceId: 'dnd-core' })); } var DragDropManagerImpl = /*#__PURE__*/function () { function DragDropManagerImpl() { var _this = this; var debugMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; _classCallCheck(this, DragDropManagerImpl); this.isSetUp = false; this.handleRefCountChange = function () { var shouldSetUp = _this.store.getState().refCount > 0; if (_this.backend) { if (shouldSetUp && !_this.isSetUp) { _this.backend.setup(); _this.isSetUp = true; } else if (!shouldSetUp && _this.isSetUp) { _this.backend.teardown(); _this.isSetUp = false; } } }; var store = makeStoreInstance(debugMode); this.store = store; this.monitor = new _DragDropMonitorImpl.DragDropMonitorImpl(store, new _HandlerRegistryImpl.HandlerRegistryImpl(store)); store.subscribe(this.handleRefCountChange); } _createClass(DragDropManagerImpl, [{ key: "receiveBackend", value: function receiveBackend(backend) { this.backend = backend; } }, { key: "getMonitor", value: function getMonitor() { return this.monitor; } }, { key: "getBackend", value: function getBackend() { return this.backend; } }, { key: "getRegistry", value: function getRegistry() { return this.monitor.registry; } }, { key: "getActions", value: function getActions() { /* eslint-disable-next-line @typescript-eslint/no-this-alias */ var manager = this; var dispatch = this.store.dispatch; function bindActionCreator(actionCreator) { return function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var action = actionCreator.apply(manager, args); if (typeof action !== 'undefined') { dispatch(action); } }; } var actions = (0, _dragDrop.createDragDropActions)(this); return Object.keys(actions).reduce(function (boundActions, key) { var action = actions[key]; boundActions[key] = bindActionCreator(action); return boundActions; }, {}); } }, { key: "dispatch", value: function dispatch(action) { this.store.dispatch(action); } }]); return DragDropManagerImpl; }(); exports.DragDropManagerImpl = DragDropManagerImpl;dist/cjs/HandlerRegistryImpl.js000064400000017602151701466600012570 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandlerRegistryImpl = void 0; var _invariant = require("@react-dnd/invariant"); var _registry = require("./actions/registry"); var _getNextUniqueId = require("./utils/getNextUniqueId"); var _interfaces = require("./interfaces"); var _contracts = require("./contracts"); var _asap = require("@react-dnd/asap"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function getNextHandlerId(role) { var id = (0, _getNextUniqueId.getNextUniqueId)().toString(); switch (role) { case _interfaces.HandlerRole.SOURCE: return "S".concat(id); case _interfaces.HandlerRole.TARGET: return "T".concat(id); default: throw new Error("Unknown Handler Role: ".concat(role)); } } function parseRoleFromHandlerId(handlerId) { switch (handlerId[0]) { case 'S': return _interfaces.HandlerRole.SOURCE; case 'T': return _interfaces.HandlerRole.TARGET; default: (0, _invariant.invariant)(false, "Cannot parse handler ID: ".concat(handlerId)); } } function mapContainsValue(map, searchValue) { var entries = map.entries(); var isDone = false; do { var _entries$next = entries.next(), done = _entries$next.done, _entries$next$value = _slicedToArray(_entries$next.value, 2), value = _entries$next$value[1]; if (value === searchValue) { return true; } isDone = !!done; } while (!isDone); return false; } var HandlerRegistryImpl = /*#__PURE__*/function () { function HandlerRegistryImpl(store) { _classCallCheck(this, HandlerRegistryImpl); this.types = new Map(); this.dragSources = new Map(); this.dropTargets = new Map(); this.pinnedSourceId = null; this.pinnedSource = null; this.store = store; } _createClass(HandlerRegistryImpl, [{ key: "addSource", value: function addSource(type, source) { (0, _contracts.validateType)(type); (0, _contracts.validateSourceContract)(source); var sourceId = this.addHandler(_interfaces.HandlerRole.SOURCE, type, source); this.store.dispatch((0, _registry.addSource)(sourceId)); return sourceId; } }, { key: "addTarget", value: function addTarget(type, target) { (0, _contracts.validateType)(type, true); (0, _contracts.validateTargetContract)(target); var targetId = this.addHandler(_interfaces.HandlerRole.TARGET, type, target); this.store.dispatch((0, _registry.addTarget)(targetId)); return targetId; } }, { key: "containsHandler", value: function containsHandler(handler) { return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler); } }, { key: "getSource", value: function getSource(sourceId) { var includePinned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; (0, _invariant.invariant)(this.isSourceId(sourceId), 'Expected a valid source ID.'); var isPinned = includePinned && sourceId === this.pinnedSourceId; var source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId); return source; } }, { key: "getTarget", value: function getTarget(targetId) { (0, _invariant.invariant)(this.isTargetId(targetId), 'Expected a valid target ID.'); return this.dropTargets.get(targetId); } }, { key: "getSourceType", value: function getSourceType(sourceId) { (0, _invariant.invariant)(this.isSourceId(sourceId), 'Expected a valid source ID.'); return this.types.get(sourceId); } }, { key: "getTargetType", value: function getTargetType(targetId) { (0, _invariant.invariant)(this.isTargetId(targetId), 'Expected a valid target ID.'); return this.types.get(targetId); } }, { key: "isSourceId", value: function isSourceId(handlerId) { var role = parseRoleFromHandlerId(handlerId); return role === _interfaces.HandlerRole.SOURCE; } }, { key: "isTargetId", value: function isTargetId(handlerId) { var role = parseRoleFromHandlerId(handlerId); return role === _interfaces.HandlerRole.TARGET; } }, { key: "removeSource", value: function removeSource(sourceId) { var _this = this; (0, _invariant.invariant)(this.getSource(sourceId), 'Expected an existing source.'); this.store.dispatch((0, _registry.removeSource)(sourceId)); (0, _asap.asap)(function () { _this.dragSources.delete(sourceId); _this.types.delete(sourceId); }); } }, { key: "removeTarget", value: function removeTarget(targetId) { (0, _invariant.invariant)(this.getTarget(targetId), 'Expected an existing target.'); this.store.dispatch((0, _registry.removeTarget)(targetId)); this.dropTargets.delete(targetId); this.types.delete(targetId); } }, { key: "pinSource", value: function pinSource(sourceId) { var source = this.getSource(sourceId); (0, _invariant.invariant)(source, 'Expected an existing source.'); this.pinnedSourceId = sourceId; this.pinnedSource = source; } }, { key: "unpinSource", value: function unpinSource() { (0, _invariant.invariant)(this.pinnedSource, 'No source is pinned at the time.'); this.pinnedSourceId = null; this.pinnedSource = null; } }, { key: "addHandler", value: function addHandler(role, type, handler) { var id = getNextHandlerId(role); this.types.set(id, type); if (role === _interfaces.HandlerRole.SOURCE) { this.dragSources.set(id, handler); } else if (role === _interfaces.HandlerRole.TARGET) { this.dropTargets.set(id, handler); } return id; } }]); return HandlerRegistryImpl; }(); exports.HandlerRegistryImpl = HandlerRegistryImpl;dist/cjs/DragDropMonitorImpl.js000064400000016515151701466600012536 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DragDropMonitorImpl = void 0; var _invariant = require("@react-dnd/invariant"); var _matchesType = require("./utils/matchesType"); var _coords = require("./utils/coords"); var _dirtiness = require("./utils/dirtiness"); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } var DragDropMonitorImpl = /*#__PURE__*/function () { function DragDropMonitorImpl(store, registry) { _classCallCheck(this, DragDropMonitorImpl); this.store = store; this.registry = registry; } _createClass(DragDropMonitorImpl, [{ key: "subscribeToStateChange", value: function subscribeToStateChange(listener) { var _this = this; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { handlerIds: undefined }; var handlerIds = options.handlerIds; (0, _invariant.invariant)(typeof listener === 'function', 'listener must be a function.'); (0, _invariant.invariant)(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.'); var prevStateId = this.store.getState().stateId; var handleChange = function handleChange() { var state = _this.store.getState(); var currentStateId = state.stateId; try { var canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !(0, _dirtiness.areDirty)(state.dirtyHandlerIds, handlerIds); if (!canSkipListener) { listener(); } } finally { prevStateId = currentStateId; } }; return this.store.subscribe(handleChange); } }, { key: "subscribeToOffsetChange", value: function subscribeToOffsetChange(listener) { var _this2 = this; (0, _invariant.invariant)(typeof listener === 'function', 'listener must be a function.'); var previousState = this.store.getState().dragOffset; var handleChange = function handleChange() { var nextState = _this2.store.getState().dragOffset; if (nextState === previousState) { return; } previousState = nextState; listener(); }; return this.store.subscribe(handleChange); } }, { key: "canDragSource", value: function canDragSource(sourceId) { if (!sourceId) { return false; } var source = this.registry.getSource(sourceId); (0, _invariant.invariant)(source, 'Expected to find a valid source.'); if (this.isDragging()) { return false; } return source.canDrag(this, sourceId); } }, { key: "canDropOnTarget", value: function canDropOnTarget(targetId) { // undefined on initial render if (!targetId) { return false; } var target = this.registry.getTarget(targetId); (0, _invariant.invariant)(target, 'Expected to find a valid target.'); if (!this.isDragging() || this.didDrop()) { return false; } var targetType = this.registry.getTargetType(targetId); var draggedItemType = this.getItemType(); return (0, _matchesType.matchesType)(targetType, draggedItemType) && target.canDrop(this, targetId); } }, { key: "isDragging", value: function isDragging() { return Boolean(this.getItemType()); } }, { key: "isDraggingSource", value: function isDraggingSource(sourceId) { // undefined on initial render if (!sourceId) { return false; } var source = this.registry.getSource(sourceId, true); (0, _invariant.invariant)(source, 'Expected to find a valid source.'); if (!this.isDragging() || !this.isSourcePublic()) { return false; } var sourceType = this.registry.getSourceType(sourceId); var draggedItemType = this.getItemType(); if (sourceType !== draggedItemType) { return false; } return source.isDragging(this, sourceId); } }, { key: "isOverTarget", value: function isOverTarget(targetId) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { shallow: false }; // undefined on initial render if (!targetId) { return false; } var shallow = options.shallow; if (!this.isDragging()) { return false; } var targetType = this.registry.getTargetType(targetId); var draggedItemType = this.getItemType(); if (draggedItemType && !(0, _matchesType.matchesType)(targetType, draggedItemType)) { return false; } var targetIds = this.getTargetIds(); if (!targetIds.length) { return false; } var index = targetIds.indexOf(targetId); if (shallow) { return index === targetIds.length - 1; } else { return index > -1; } } }, { key: "getItemType", value: function getItemType() { return this.store.getState().dragOperation.itemType; } }, { key: "getItem", value: function getItem() { return this.store.getState().dragOperation.item; } }, { key: "getSourceId", value: function getSourceId() { return this.store.getState().dragOperation.sourceId; } }, { key: "getTargetIds", value: function getTargetIds() { return this.store.getState().dragOperation.targetIds; } }, { key: "getDropResult", value: function getDropResult() { return this.store.getState().dragOperation.dropResult; } }, { key: "didDrop", value: function didDrop() { return this.store.getState().dragOperation.didDrop; } }, { key: "isSourcePublic", value: function isSourcePublic() { return Boolean(this.store.getState().dragOperation.isSourcePublic); } }, { key: "getInitialClientOffset", value: function getInitialClientOffset() { return this.store.getState().dragOffset.initialClientOffset; } }, { key: "getInitialSourceClientOffset", value: function getInitialSourceClientOffset() { return this.store.getState().dragOffset.initialSourceClientOffset; } }, { key: "getClientOffset", value: function getClientOffset() { return this.store.getState().dragOffset.clientOffset; } }, { key: "getSourceClientOffset", value: function getSourceClientOffset() { return (0, _coords.getSourceClientOffset)(this.store.getState().dragOffset); } }, { key: "getDifferenceFromInitialOffset", value: function getDifferenceFromInitialOffset() { return (0, _coords.getDifferenceFromInitialOffset)(this.store.getState().dragOffset); } }]); return DragDropMonitorImpl; }(); exports.DragDropMonitorImpl = DragDropMonitorImpl;dist/cjs/utils/getNextUniqueId.js000064400000000311151701466600013047 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getNextUniqueId = getNextUniqueId; var nextUniqueId = 0; function getNextUniqueId() { return nextUniqueId++; }dist/cjs/utils/coords.js000064400000003263151701466600011267 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.add = add; exports.subtract = subtract; exports.getSourceClientOffset = getSourceClientOffset; exports.getDifferenceFromInitialOffset = getDifferenceFromInitialOffset; /** * Coordinate addition * @param a The first coordinate * @param b The second coordinate */ 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 */ 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 */ function getSourceClientOffset(state) { var clientOffset = state.clientOffset, initialClientOffset = state.initialClientOffset, initialSourceClientOffset = state.initialSourceClientOffset; 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 */ function getDifferenceFromInitialOffset(state) { var clientOffset = state.clientOffset, initialClientOffset = state.initialClientOffset; if (!clientOffset || !initialClientOffset) { return null; } return subtract(clientOffset, initialClientOffset); }dist/cjs/utils/equality.js000064400000002070151701466600011626 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.areCoordsEqual = areCoordsEqual; exports.areArraysEqual = areArraysEqual; exports.strictEquality = void 0; var strictEquality = function strictEquality(a, b) { return a === b; }; /** * Determine if two cartesian coordinate offsets are equal * @param offsetA * @param offsetB */ exports.strictEquality = strictEquality; 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 */ function areArraysEqual(a, b) { var isEqual = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : strictEquality; if (a.length !== b.length) { return false; } for (var i = 0; i < a.length; ++i) { if (!isEqual(a[i], b[i])) { return false; } } return true; }dist/cjs/utils/matchesType.js000064400000000575151701466600012267 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.matchesType = matchesType; function matchesType(targetType, draggedItemType) { if (draggedItemType === null) { return targetType === null; } return Array.isArray(targetType) ? targetType.some(function (t) { return t === draggedItemType; }) : targetType === draggedItemType; }dist/cjs/utils/js_utils.js000064400000003616151701466600011634 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.get = get; exports.without = without; exports.isString = isString; exports.isObject = isObject; exports.xor = xor; exports.intersection = intersection; function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } // cheap lodash replacements /** * drop-in replacement for _.get * @param obj * @param path * @param defaultValue */ function get(obj, path, defaultValue) { return path.split('.').reduce(function (a, c) { return a && a[c] ? a[c] : defaultValue || null; }, obj); } /** * drop-in replacement for _.without */ function without(items, item) { return items.filter(function (i) { return i !== item; }); } /** * drop-in replacement for _.isString * @param input */ function isString(input) { return typeof input === 'string'; } /** * drop-in replacement for _.isString * @param input */ function isObject(input) { return _typeof(input) === 'object'; } /** * repalcement for _.xor * @param itemsA * @param itemsB */ function xor(itemsA, itemsB) { var map = new Map(); var insertItem = function insertItem(item) { map.set(item, map.has(item) ? map.get(item) + 1 : 1); }; itemsA.forEach(insertItem); itemsB.forEach(insertItem); var result = []; map.forEach(function (count, key) { if (count === 1) { result.push(key); } }); return result; } /** * replacement for _.intersection * @param itemsA * @param itemsB */ function intersection(itemsA, itemsB) { return itemsA.filter(function (t) { return itemsB.indexOf(t) > -1; }); }dist/cjs/utils/dirtiness.js000064400000001360151701466600011776 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.areDirty = areDirty; exports.ALL = exports.NONE = void 0; var _js_utils = require("./js_utils"); var NONE = []; exports.NONE = NONE; var ALL = []; exports.ALL = 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 */ function areDirty(dirtyIds, handlerIds) { if (dirtyIds === NONE) { return false; } if (dirtyIds === ALL || typeof handlerIds === 'undefined') { return true; } var commonIds = (0, _js_utils.intersection)(handlerIds, dirtyIds); return commonIds.length > 0; }dist/cjs/index.js000064400000001211151701466600007734 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _interfaces = require("./interfaces"); Object.keys(_interfaces).forEach(function (key) { if (key === "default" || key === "__esModule") return; Object.defineProperty(exports, key, { enumerable: true, get: function get() { return _interfaces[key]; } }); }); var _factories = require("./factories"); Object.keys(_factories).forEach(function (key) { if (key === "default" || key === "__esModule") return; Object.defineProperty(exports, key, { enumerable: true, get: function get() { return _factories[key]; } }); });dist/cjs/actions/registry.js000064400000002131151701466600012137 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.addSource = addSource; exports.addTarget = addTarget; exports.removeSource = removeSource; exports.removeTarget = removeTarget; exports.REMOVE_TARGET = exports.REMOVE_SOURCE = exports.ADD_TARGET = exports.ADD_SOURCE = void 0; var ADD_SOURCE = 'dnd-core/ADD_SOURCE'; exports.ADD_SOURCE = ADD_SOURCE; var ADD_TARGET = 'dnd-core/ADD_TARGET'; exports.ADD_TARGET = ADD_TARGET; var REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE'; exports.REMOVE_SOURCE = REMOVE_SOURCE; var REMOVE_TARGET = 'dnd-core/REMOVE_TARGET'; exports.REMOVE_TARGET = REMOVE_TARGET; function addSource(sourceId) { return { type: ADD_SOURCE, payload: { sourceId: sourceId } }; } function addTarget(targetId) { return { type: ADD_TARGET, payload: { targetId: targetId } }; } function removeSource(sourceId) { return { type: REMOVE_SOURCE, payload: { sourceId: sourceId } }; } function removeTarget(targetId) { return { type: REMOVE_TARGET, payload: { targetId: targetId } }; }dist/cjs/actions/dragDrop/local/setClientOffset.js000064400000000577151701466600016240 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.setClientOffset = setClientOffset; var _types = require("../types"); function setClientOffset(clientOffset, sourceClientOffset) { return { type: _types.INIT_COORDS, payload: { sourceClientOffset: sourceClientOffset || null, clientOffset: clientOffset || null } }; }dist/cjs/actions/dragDrop/types.js000064400000001174151701466600013203 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.END_DRAG = exports.DROP = exports.HOVER = exports.PUBLISH_DRAG_SOURCE = exports.BEGIN_DRAG = exports.INIT_COORDS = void 0; var INIT_COORDS = 'dnd-core/INIT_COORDS'; exports.INIT_COORDS = INIT_COORDS; var BEGIN_DRAG = 'dnd-core/BEGIN_DRAG'; exports.BEGIN_DRAG = BEGIN_DRAG; var PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE'; exports.PUBLISH_DRAG_SOURCE = PUBLISH_DRAG_SOURCE; var HOVER = 'dnd-core/HOVER'; exports.HOVER = HOVER; var DROP = 'dnd-core/DROP'; exports.DROP = DROP; var END_DRAG = 'dnd-core/END_DRAG'; exports.END_DRAG = END_DRAG;dist/cjs/actions/dragDrop/publishDragSource.js000064400000000630151701466600015460 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createPublishDragSource = createPublishDragSource; var _types = require("./types"); function createPublishDragSource(manager) { return function publishDragSource() { var monitor = manager.getMonitor(); if (monitor.isDragging()) { return { type: _types.PUBLISH_DRAG_SOURCE }; } }; }dist/cjs/actions/dragDrop/endDrag.js000064400000001406151701466600013401 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createEndDrag = createEndDrag; var _invariant = require("@react-dnd/invariant"); var _types = require("./types"); function createEndDrag(manager) { return function endDrag() { var monitor = manager.getMonitor(); var registry = manager.getRegistry(); verifyIsDragging(monitor); var sourceId = monitor.getSourceId(); if (sourceId != null) { var source = registry.getSource(sourceId, true); source.endDrag(monitor, sourceId); registry.unpinSource(); } return { type: _types.END_DRAG }; }; } function verifyIsDragging(monitor) { (0, _invariant.invariant)(monitor.isDragging(), 'Cannot call endDrag while not dragging.'); }dist/cjs/actions/dragDrop/index.js000064400000002052151701466600013142 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _exportNames = { createDragDropActions: true }; exports.createDragDropActions = createDragDropActions; var _beginDrag = require("./beginDrag"); var _publishDragSource = require("./publishDragSource"); var _hover = require("./hover"); var _drop = require("./drop"); var _endDrag = require("./endDrag"); var _types = require("./types"); Object.keys(_types).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; Object.defineProperty(exports, key, { enumerable: true, get: function get() { return _types[key]; } }); }); function createDragDropActions(manager) { return { beginDrag: (0, _beginDrag.createBeginDrag)(manager), publishDragSource: (0, _publishDragSource.createPublishDragSource)(manager), hover: (0, _hover.createHover)(manager), drop: (0, _drop.createDrop)(manager), endDrag: (0, _endDrag.createEndDrag)(manager) }; }dist/cjs/actions/dragDrop/hover.js000064400000004622151701466600013163 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createHover = createHover; var _invariant = require("@react-dnd/invariant"); var _matchesType = require("../../utils/matchesType"); var _types = require("./types"); function createHover(manager) { return function hover(targetIdsArg) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, clientOffset = _ref.clientOffset; verifyTargetIdsIsArray(targetIdsArg); var targetIds = targetIdsArg.slice(0); var monitor = manager.getMonitor(); var registry = manager.getRegistry(); checkInvariants(targetIds, monitor, registry); var draggedItemType = monitor.getItemType(); removeNonMatchingTargetIds(targetIds, registry, draggedItemType); hoverAllTargets(targetIds, monitor, registry); return { type: _types.HOVER, payload: { targetIds: targetIds, clientOffset: clientOffset || null } }; }; } function verifyTargetIdsIsArray(targetIdsArg) { (0, _invariant.invariant)(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.'); } function checkInvariants(targetIds, monitor, registry) { (0, _invariant.invariant)(monitor.isDragging(), 'Cannot call hover while not dragging.'); (0, _invariant.invariant)(!monitor.didDrop(), 'Cannot call hover after drop.'); for (var i = 0; i < targetIds.length; i++) { var targetId = targetIds[i]; (0, _invariant.invariant)(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.'); var target = registry.getTarget(targetId); (0, _invariant.invariant)(target, 'Expected targetIds to be registered.'); } } function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) { // Remove those targetIds that don't match the targetType. This // fixes shallow isOver which would only be non-shallow because of // non-matching targets. for (var i = targetIds.length - 1; i >= 0; i--) { var targetId = targetIds[i]; var targetType = registry.getTargetType(targetId); if (!(0, _matchesType.matchesType)(targetType, draggedItemType)) { targetIds.splice(i, 1); } } } function hoverAllTargets(targetIds, monitor, registry) { // Finally call hover on all matching targets. targetIds.forEach(function (targetId) { var target = registry.getTarget(targetId); target.hover(monitor, targetId); }); }dist/cjs/actions/dragDrop/beginDrag.js000064400000006374151701466600013730 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createBeginDrag = createBeginDrag; var _invariant = require("@react-dnd/invariant"); var _setClientOffset = require("./local/setClientOffset"); var _js_utils = require("../../utils/js_utils"); var _types = require("./types"); var ResetCoordinatesAction = { type: _types.INIT_COORDS, payload: { clientOffset: null, sourceClientOffset: null } }; function createBeginDrag(manager) { return function beginDrag() { var sourceIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { publishSource: true }; var _options$publishSourc = options.publishSource, publishSource = _options$publishSourc === void 0 ? true : _options$publishSourc, clientOffset = options.clientOffset, getSourceClientOffset = options.getSourceClientOffset; var monitor = manager.getMonitor(); var registry = manager.getRegistry(); // Initialize the coordinates using the client offset manager.dispatch((0, _setClientOffset.setClientOffset)(clientOffset)); verifyInvariants(sourceIds, monitor, registry); // Get the draggable source var sourceId = getDraggableSource(sourceIds, monitor); if (sourceId === null) { manager.dispatch(ResetCoordinatesAction); return; } // Get the source client offset var sourceClientOffset = null; if (clientOffset) { if (!getSourceClientOffset) { throw new Error('getSourceClientOffset must be defined'); } verifyGetSourceClientOffsetIsFunction(getSourceClientOffset); sourceClientOffset = getSourceClientOffset(sourceId); } // Initialize the full coordinates manager.dispatch((0, _setClientOffset.setClientOffset)(clientOffset, sourceClientOffset)); var source = registry.getSource(sourceId); var item = source.beginDrag(monitor, sourceId); verifyItemIsObject(item); registry.pinSource(sourceId); var itemType = registry.getSourceType(sourceId); return { type: _types.BEGIN_DRAG, payload: { itemType: itemType, item: item, sourceId: sourceId, clientOffset: clientOffset || null, sourceClientOffset: sourceClientOffset || null, isSourcePublic: !!publishSource } }; }; } function verifyInvariants(sourceIds, monitor, registry) { (0, _invariant.invariant)(!monitor.isDragging(), 'Cannot call beginDrag while dragging.'); sourceIds.forEach(function (sourceId) { (0, _invariant.invariant)(registry.getSource(sourceId), 'Expected sourceIds to be registered.'); }); } function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) { (0, _invariant.invariant)(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); } function verifyItemIsObject(item) { (0, _invariant.invariant)((0, _js_utils.isObject)(item), 'Item must be an object.'); } function getDraggableSource(sourceIds, monitor) { var sourceId = null; for (var i = sourceIds.length - 1; i >= 0; i--) { if (monitor.canDragSource(sourceIds[i])) { sourceId = sourceIds[i]; break; } } return sourceId; }dist/cjs/actions/dragDrop/drop.js000064400000005732151701466600013007 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDrop = createDrop; var _invariant = require("@react-dnd/invariant"); var _types = require("./types"); var _js_utils = require("../../utils/js_utils"); function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function createDrop(manager) { return function drop() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var monitor = manager.getMonitor(); var registry = manager.getRegistry(); verifyInvariants(monitor); var targetIds = getDroppableTargets(monitor); // Multiple actions are dispatched here, which is why this doesn't return an action targetIds.forEach(function (targetId, index) { var dropResult = determineDropResult(targetId, index, registry, monitor); var action = { type: _types.DROP, payload: { dropResult: _objectSpread(_objectSpread({}, options), dropResult) } }; manager.dispatch(action); }); }; } function verifyInvariants(monitor) { (0, _invariant.invariant)(monitor.isDragging(), 'Cannot call drop while not dragging.'); (0, _invariant.invariant)(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.'); } function determineDropResult(targetId, index, registry, monitor) { var target = registry.getTarget(targetId); var dropResult = target ? target.drop(monitor, targetId) : undefined; verifyDropResultType(dropResult); if (typeof dropResult === 'undefined') { dropResult = index === 0 ? {} : monitor.getDropResult(); } return dropResult; } function verifyDropResultType(dropResult) { (0, _invariant.invariant)(typeof dropResult === 'undefined' || (0, _js_utils.isObject)(dropResult), 'Drop result must either be an object or undefined.'); } function getDroppableTargets(monitor) { var targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor); targetIds.reverse(); return targetIds; }dist/cjs/contracts.js000064400000003346151701466600010640 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateSourceContract = validateSourceContract; exports.validateTargetContract = validateTargetContract; exports.validateType = validateType; var _invariant = require("@react-dnd/invariant"); function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function validateSourceContract(source) { (0, _invariant.invariant)(typeof source.canDrag === 'function', 'Expected canDrag to be a function.'); (0, _invariant.invariant)(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.'); (0, _invariant.invariant)(typeof source.endDrag === 'function', 'Expected endDrag to be a function.'); } function validateTargetContract(target) { (0, _invariant.invariant)(typeof target.canDrop === 'function', 'Expected canDrop to be a function.'); (0, _invariant.invariant)(typeof target.hover === 'function', 'Expected hover to be a function.'); (0, _invariant.invariant)(typeof target.drop === 'function', 'Expected beginDrag to be a function.'); } function validateType(type, allowArray) { if (allowArray && Array.isArray(type)) { type.forEach(function (t) { return validateType(t, false); }); return; } (0, _invariant.invariant)(typeof type === 'string' || _typeof(type) === 'symbol', allowArray ? 'Type can only be a string, a symbol, or an array of either.' : 'Type can only be a string or a symbol.'); }dist/cjs/interfaces.js000064400000000501151701466600010751 0ustar00"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandlerRole = void 0; var HandlerRole; exports.HandlerRole = HandlerRole; (function (HandlerRole) { HandlerRole["SOURCE"] = "SOURCE"; HandlerRole["TARGET"] = "TARGET"; })(HandlerRole || (exports.HandlerRole = HandlerRole = {}));dist/esm/reducers/refCount.js000064400000000730151701466600012240 0ustar00import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET } from '../actions/registry'; export function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case ADD_SOURCE: case ADD_TARGET: return state + 1; case REMOVE_SOURCE: case REMOVE_TARGET: return state - 1; default: return state; } }dist/esm/reducers/index.js000064400000003764151701466600011574 0ustar00function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { reduce as dragOffset } from './dragOffset'; import { reduce as dragOperation } from './dragOperation'; import { reduce as refCount } from './refCount'; import { reduce as dirtyHandlerIds } from './dirtyHandlerIds'; import { reduce as stateId } from './stateId'; import { get } from '../utils/js_utils'; export function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var action = arguments.length > 1 ? arguments[1] : undefined; return { dirtyHandlerIds: dirtyHandlerIds(state.dirtyHandlerIds, { type: action.type, payload: _objectSpread(_objectSpread({}, action.payload), {}, { prevTargetIds: get(state, 'dragOperation.targetIds', []) }) }), dragOffset: dragOffset(state.dragOffset, action), refCount: refCount(state.refCount, action), dragOperation: dragOperation(state.dragOperation, action), stateId: stateId(state.stateId) }; }dist/esm/reducers/dragOffset.js000064400000004131151701466600012536 0ustar00function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { INIT_COORDS, BEGIN_DRAG, HOVER, END_DRAG, DROP } from '../actions/dragDrop'; import { areCoordsEqual } from '../utils/equality'; var initialState = { initialSourceClientOffset: null, initialClientOffset: null, clientOffset: null }; export function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments.length > 1 ? arguments[1] : undefined; var payload = action.payload; switch (action.type) { case INIT_COORDS: case BEGIN_DRAG: return { initialSourceClientOffset: payload.sourceClientOffset, initialClientOffset: payload.clientOffset, clientOffset: payload.clientOffset }; case HOVER: if (areCoordsEqual(state.clientOffset, payload.clientOffset)) { return state; } return _objectSpread(_objectSpread({}, state), {}, { clientOffset: payload.clientOffset }); case END_DRAG: case DROP: return initialState; default: return state; } }dist/esm/reducers/dirtyHandlerIds.js000064400000003327151701466600013551 0ustar00import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP } from '../actions/dragDrop'; import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET } from '../actions/registry'; import { areArraysEqual } from '../utils/equality'; import { NONE, ALL } from '../utils/dirtiness'; import { xor } from '../utils/js_utils'; export function reduce() { var _state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NONE; var action = arguments.length > 1 ? arguments[1] : undefined; switch (action.type) { case HOVER: break; case ADD_SOURCE: case ADD_TARGET: case REMOVE_TARGET: case REMOVE_SOURCE: return NONE; case BEGIN_DRAG: case PUBLISH_DRAG_SOURCE: case END_DRAG: case DROP: default: return ALL; } var _action$payload = action.payload, _action$payload$targe = _action$payload.targetIds, targetIds = _action$payload$targe === void 0 ? [] : _action$payload$targe, _action$payload$prevT = _action$payload.prevTargetIds, prevTargetIds = _action$payload$prevT === void 0 ? [] : _action$payload$prevT; var result = xor(targetIds, prevTargetIds); var didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds); if (!didChange) { return NONE; } // Check the target ids at the innermost position. If they are valid, add them // to the result var prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; var innermostTargetId = targetIds[targetIds.length - 1]; if (prevInnermostTargetId !== innermostTargetId) { if (prevInnermostTargetId) { result.push(prevInnermostTargetId); } if (innermostTargetId) { result.push(innermostTargetId); } } return result; }dist/esm/reducers/stateId.js000064400000000205151701466600012045 0ustar00export function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; return state + 1; }dist/esm/reducers/dragOperation.js000064400000005567151701466600013266 0ustar00function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP } from '../actions/dragDrop'; import { REMOVE_TARGET } from '../actions/registry'; import { without } from '../utils/js_utils'; var initialState = { itemType: null, item: null, sourceId: null, targetIds: [], dropResult: null, didDrop: false, isSourcePublic: null }; export function reduce() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments.length > 1 ? arguments[1] : undefined; var payload = action.payload; switch (action.type) { case BEGIN_DRAG: return _objectSpread(_objectSpread({}, state), {}, { itemType: payload.itemType, item: payload.item, sourceId: payload.sourceId, isSourcePublic: payload.isSourcePublic, dropResult: null, didDrop: false }); case PUBLISH_DRAG_SOURCE: return _objectSpread(_objectSpread({}, state), {}, { isSourcePublic: true }); case HOVER: return _objectSpread(_objectSpread({}, state), {}, { targetIds: payload.targetIds }); case REMOVE_TARGET: if (state.targetIds.indexOf(payload.targetId) === -1) { return state; } return _objectSpread(_objectSpread({}, state), {}, { targetIds: without(state.targetIds, payload.targetId) }); case DROP: return _objectSpread(_objectSpread({}, state), {}, { dropResult: payload.dropResult, didDrop: true, targetIds: [] }); case END_DRAG: return _objectSpread(_objectSpread({}, state), {}, { itemType: null, item: null, sourceId: null, dropResult: null, didDrop: false, isSourcePublic: null, targetIds: [] }); default: return state; } }dist/esm/factories.js000064400000000521151701466600010614 0ustar00import { DragDropManagerImpl } from './DragDropManagerImpl'; export function createDragDropManager(backendFactory, globalContext, backendOptions, debugMode) { var manager = new DragDropManagerImpl(debugMode); var backend = backendFactory(manager, globalContext, backendOptions); manager.receiveBackend(backend); return manager; }dist/esm/DragDropManagerImpl.js000064400000007152151701466600012463 0ustar00function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } import { createStore } from 'redux'; import { reduce } from './reducers'; import { createDragDropActions } from './actions/dragDrop'; import { DragDropMonitorImpl } from './DragDropMonitorImpl'; import { HandlerRegistryImpl } from './HandlerRegistryImpl'; function makeStoreInstance(debugMode) { // TODO: if we ever make a react-native version of this, // we'll need to consider how to pull off dev-tooling var reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__; return createStore(reduce, debugMode && reduxDevTools && reduxDevTools({ name: 'dnd-core', instanceId: 'dnd-core' })); } export var DragDropManagerImpl = /*#__PURE__*/function () { function DragDropManagerImpl() { var _this = this; var debugMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; _classCallCheck(this, DragDropManagerImpl); this.isSetUp = false; this.handleRefCountChange = function () { var shouldSetUp = _this.store.getState().refCount > 0; if (_this.backend) { if (shouldSetUp && !_this.isSetUp) { _this.backend.setup(); _this.isSetUp = true; } else if (!shouldSetUp && _this.isSetUp) { _this.backend.teardown(); _this.isSetUp = false; } } }; var store = makeStoreInstance(debugMode); this.store = store; this.monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store)); store.subscribe(this.handleRefCountChange); } _createClass(DragDropManagerImpl, [{ key: "receiveBackend", value: function receiveBackend(backend) { this.backend = backend; } }, { key: "getMonitor", value: function getMonitor() { return this.monitor; } }, { key: "getBackend", value: function getBackend() { return this.backend; } }, { key: "getRegistry", value: function getRegistry() { return this.monitor.registry; } }, { key: "getActions", value: function getActions() { /* eslint-disable-next-line @typescript-eslint/no-this-alias */ var manager = this; var dispatch = this.store.dispatch; function bindActionCreator(actionCreator) { return function () { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var action = actionCreator.apply(manager, args); if (typeof action !== 'undefined') { dispatch(action); } }; } var actions = createDragDropActions(this); return Object.keys(actions).reduce(function (boundActions, key) { var action = actions[key]; boundActions[key] = bindActionCreator(action); return boundActions; }, {}); } }, { key: "dispatch", value: function dispatch(action) { this.store.dispatch(action); } }]); return DragDropManagerImpl; }();dist/esm/HandlerRegistryImpl.js000064400000016722151701466600012577 0ustar00function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } import { invariant } from '@react-dnd/invariant'; import { addSource as _addSource, addTarget as _addTarget, removeSource as _removeSource, removeTarget as _removeTarget } from './actions/registry'; import { getNextUniqueId } from './utils/getNextUniqueId'; import { HandlerRole } from './interfaces'; import { validateSourceContract, validateTargetContract, validateType } from './contracts'; import { asap } from '@react-dnd/asap'; function getNextHandlerId(role) { var id = getNextUniqueId().toString(); switch (role) { case HandlerRole.SOURCE: return "S".concat(id); case HandlerRole.TARGET: return "T".concat(id); default: throw new Error("Unknown Handler Role: ".concat(role)); } } function parseRoleFromHandlerId(handlerId) { switch (handlerId[0]) { case 'S': return HandlerRole.SOURCE; case 'T': return HandlerRole.TARGET; default: invariant(false, "Cannot parse handler ID: ".concat(handlerId)); } } function mapContainsValue(map, searchValue) { var entries = map.entries(); var isDone = false; do { var _entries$next = entries.next(), done = _entries$next.done, _entries$next$value = _slicedToArray(_entries$next.value, 2), value = _entries$next$value[1]; if (value === searchValue) { return true; } isDone = !!done; } while (!isDone); return false; } export var HandlerRegistryImpl = /*#__PURE__*/function () { function HandlerRegistryImpl(store) { _classCallCheck(this, HandlerRegistryImpl); this.types = new Map(); this.dragSources = new Map(); this.dropTargets = new Map(); this.pinnedSourceId = null; this.pinnedSource = null; this.store = store; } _createClass(HandlerRegistryImpl, [{ key: "addSource", value: function addSource(type, source) { validateType(type); validateSourceContract(source); var sourceId = this.addHandler(HandlerRole.SOURCE, type, source); this.store.dispatch(_addSource(sourceId)); return sourceId; } }, { key: "addTarget", value: function addTarget(type, target) { validateType(type, true); validateTargetContract(target); var targetId = this.addHandler(HandlerRole.TARGET, type, target); this.store.dispatch(_addTarget(targetId)); return targetId; } }, { key: "containsHandler", value: function containsHandler(handler) { return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler); } }, { key: "getSource", value: function getSource(sourceId) { var includePinned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); var isPinned = includePinned && sourceId === this.pinnedSourceId; var source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId); return source; } }, { key: "getTarget", value: function getTarget(targetId) { invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); return this.dropTargets.get(targetId); } }, { key: "getSourceType", value: function getSourceType(sourceId) { invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); return this.types.get(sourceId); } }, { key: "getTargetType", value: function getTargetType(targetId) { invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); return this.types.get(targetId); } }, { key: "isSourceId", value: function isSourceId(handlerId) { var role = parseRoleFromHandlerId(handlerId); return role === HandlerRole.SOURCE; } }, { key: "isTargetId", value: function isTargetId(handlerId) { var role = parseRoleFromHandlerId(handlerId); return role === HandlerRole.TARGET; } }, { key: "removeSource", value: function removeSource(sourceId) { var _this = this; invariant(this.getSource(sourceId), 'Expected an existing source.'); this.store.dispatch(_removeSource(sourceId)); asap(function () { _this.dragSources.delete(sourceId); _this.types.delete(sourceId); }); } }, { key: "removeTarget", value: function removeTarget(targetId) { invariant(this.getTarget(targetId), 'Expected an existing target.'); this.store.dispatch(_removeTarget(targetId)); this.dropTargets.delete(targetId); this.types.delete(targetId); } }, { key: "pinSource", value: function pinSource(sourceId) { var source = this.getSource(sourceId); invariant(source, 'Expected an existing source.'); this.pinnedSourceId = sourceId; this.pinnedSource = source; } }, { key: "unpinSource", value: function unpinSource() { invariant(this.pinnedSource, 'No source is pinned at the time.'); this.pinnedSourceId = null; this.pinnedSource = null; } }, { key: "addHandler", value: function addHandler(role, type, handler) { var id = getNextHandlerId(role); this.types.set(id, type); if (role === HandlerRole.SOURCE) { this.dragSources.set(id, handler); } else if (role === HandlerRole.TARGET) { this.dropTargets.set(id, handler); } return id; } }]); return HandlerRegistryImpl; }();dist/esm/DragDropMonitorImpl.js000064400000016144151701466600012541 0ustar00function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } import { invariant } from '@react-dnd/invariant'; import { matchesType } from './utils/matchesType'; import { getSourceClientOffset as _getSourceClientOffset, getDifferenceFromInitialOffset as _getDifferenceFromInitialOffset } from './utils/coords'; import { areDirty } from './utils/dirtiness'; export var DragDropMonitorImpl = /*#__PURE__*/function () { function DragDropMonitorImpl(store, registry) { _classCallCheck(this, DragDropMonitorImpl); this.store = store; this.registry = registry; } _createClass(DragDropMonitorImpl, [{ key: "subscribeToStateChange", value: function subscribeToStateChange(listener) { var _this = this; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { handlerIds: undefined }; var handlerIds = options.handlerIds; invariant(typeof listener === 'function', 'listener must be a function.'); invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.'); var prevStateId = this.store.getState().stateId; var handleChange = function handleChange() { var state = _this.store.getState(); var currentStateId = state.stateId; try { var canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds); if (!canSkipListener) { listener(); } } finally { prevStateId = currentStateId; } }; return this.store.subscribe(handleChange); } }, { key: "subscribeToOffsetChange", value: function subscribeToOffsetChange(listener) { var _this2 = this; invariant(typeof listener === 'function', 'listener must be a function.'); var previousState = this.store.getState().dragOffset; var handleChange = function handleChange() { var nextState = _this2.store.getState().dragOffset; if (nextState === previousState) { return; } previousState = nextState; listener(); }; return this.store.subscribe(handleChange); } }, { key: "canDragSource", value: function canDragSource(sourceId) { if (!sourceId) { return false; } var source = this.registry.getSource(sourceId); invariant(source, 'Expected to find a valid source.'); if (this.isDragging()) { return false; } return source.canDrag(this, sourceId); } }, { key: "canDropOnTarget", value: function canDropOnTarget(targetId) { // undefined on initial render if (!targetId) { return false; } var target = this.registry.getTarget(targetId); invariant(target, 'Expected to find a valid target.'); if (!this.isDragging() || this.didDrop()) { return false; } var targetType = this.registry.getTargetType(targetId); var draggedItemType = this.getItemType(); return matchesType(targetType, draggedItemType) && target.canDrop(this, targetId); } }, { key: "isDragging", value: function isDragging() { return Boolean(this.getItemType()); } }, { key: "isDraggingSource", value: function isDraggingSource(sourceId) { // undefined on initial render if (!sourceId) { return false; } var source = this.registry.getSource(sourceId, true); invariant(source, 'Expected to find a valid source.'); if (!this.isDragging() || !this.isSourcePublic()) { return false; } var sourceType = this.registry.getSourceType(sourceId); var draggedItemType = this.getItemType(); if (sourceType !== draggedItemType) { return false; } return source.isDragging(this, sourceId); } }, { key: "isOverTarget", value: function isOverTarget(targetId) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { shallow: false }; // undefined on initial render if (!targetId) { return false; } var shallow = options.shallow; if (!this.isDragging()) { return false; } var targetType = this.registry.getTargetType(targetId); var draggedItemType = this.getItemType(); if (draggedItemType && !matchesType(targetType, draggedItemType)) { return false; } var targetIds = this.getTargetIds(); if (!targetIds.length) { return false; } var index = targetIds.indexOf(targetId); if (shallow) { return index === targetIds.length - 1; } else { return index > -1; } } }, { key: "getItemType", value: function getItemType() { return this.store.getState().dragOperation.itemType; } }, { key: "getItem", value: function getItem() { return this.store.getState().dragOperation.item; } }, { key: "getSourceId", value: function getSourceId() { return this.store.getState().dragOperation.sourceId; } }, { key: "getTargetIds", value: function getTargetIds() { return this.store.getState().dragOperation.targetIds; } }, { key: "getDropResult", value: function getDropResult() { return this.store.getState().dragOperation.dropResult; } }, { key: "didDrop", value: function didDrop() { return this.store.getState().dragOperation.didDrop; } }, { key: "isSourcePublic", value: function isSourcePublic() { return Boolean(this.store.getState().dragOperation.isSourcePublic); } }, { key: "getInitialClientOffset", value: function getInitialClientOffset() { return this.store.getState().dragOffset.initialClientOffset; } }, { key: "getInitialSourceClientOffset", value: function getInitialSourceClientOffset() { return this.store.getState().dragOffset.initialSourceClientOffset; } }, { key: "getClientOffset", value: function getClientOffset() { return this.store.getState().dragOffset.clientOffset; } }, { key: "getSourceClientOffset", value: function getSourceClientOffset() { return _getSourceClientOffset(this.store.getState().dragOffset); } }, { key: "getDifferenceFromInitialOffset", value: function getDifferenceFromInitialOffset() { return _getDifferenceFromInitialOffset(this.store.getState().dragOffset); } }]); return DragDropMonitorImpl; }();dist/esm/utils/getNextUniqueId.js000064400000000124151701466600013056 0ustar00var nextUniqueId = 0; export function getNextUniqueId() { return nextUniqueId++; }dist/esm/utils/coords.js000064400000002713151701466600011273 0ustar00/** * 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) { var clientOffset = state.clientOffset, initialClientOffset = state.initialClientOffset, initialSourceClientOffset = state.initialSourceClientOffset; 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) { var clientOffset = state.clientOffset, initialClientOffset = state.initialClientOffset; if (!clientOffset || !initialClientOffset) { return null; } return subtract(clientOffset, initialClientOffset); }dist/esm/utils/equality.js000064400000001535151701466600011640 0ustar00export var strictEquality = function strictEquality(a, b) { return 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) { var isEqual = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : strictEquality; if (a.length !== b.length) { return false; } for (var i = 0; i < a.length; ++i) { if (!isEqual(a[i], b[i])) { return false; } } return true; }dist/esm/utils/matchesType.js000064400000000420151701466600012261 0ustar00export function matchesType(targetType, draggedItemType) { if (draggedItemType === null) { return targetType === null; } return Array.isArray(targetType) ? targetType.some(function (t) { return t === draggedItemType; }) : targetType === draggedItemType; }dist/esm/utils/js_utils.js000064400000003302151701466600011631 0ustar00function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } // cheap lodash replacements /** * drop-in replacement for _.get * @param obj * @param path * @param defaultValue */ export function get(obj, path, defaultValue) { return path.split('.').reduce(function (a, c) { return a && a[c] ? a[c] : defaultValue || null; }, obj); } /** * drop-in replacement for _.without */ export function without(items, item) { return items.filter(function (i) { return 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) { var map = new Map(); var insertItem = function insertItem(item) { map.set(item, map.has(item) ? map.get(item) + 1 : 1); }; itemsA.forEach(insertItem); itemsB.forEach(insertItem); var result = []; map.forEach(function (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(function (t) { return itemsB.indexOf(t) > -1; }); }dist/esm/utils/dirtiness.js000064400000001076151701466600012007 0ustar00import { intersection } from './js_utils'; export var NONE = []; export var 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; } var commonIds = intersection(handlerIds, dirtyIds); return commonIds.length > 0; }dist/esm/index.js000064400000000072151701466600007745 0ustar00export * from './interfaces'; export * from './factories';dist/esm/actions/registry.js000064400000001303151701466600012144 0ustar00export var ADD_SOURCE = 'dnd-core/ADD_SOURCE'; export var ADD_TARGET = 'dnd-core/ADD_TARGET'; export var REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE'; export var REMOVE_TARGET = 'dnd-core/REMOVE_TARGET'; export function addSource(sourceId) { return { type: ADD_SOURCE, payload: { sourceId: sourceId } }; } export function addTarget(targetId) { return { type: ADD_TARGET, payload: { targetId: targetId } }; } export function removeSource(sourceId) { return { type: REMOVE_SOURCE, payload: { sourceId: sourceId } }; } export function removeTarget(targetId) { return { type: REMOVE_TARGET, payload: { targetId: targetId } }; }dist/esm/actions/dragDrop/local/setClientOffset.js000064400000000410151701466600016227 0ustar00import { INIT_COORDS } from '../types'; export function setClientOffset(clientOffset, sourceClientOffset) { return { type: INIT_COORDS, payload: { sourceClientOffset: sourceClientOffset || null, clientOffset: clientOffset || null } }; }dist/esm/actions/dragDrop/types.js000064400000000423151701466600013204 0ustar00export var INIT_COORDS = 'dnd-core/INIT_COORDS'; export var BEGIN_DRAG = 'dnd-core/BEGIN_DRAG'; export var PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE'; export var HOVER = 'dnd-core/HOVER'; export var DROP = 'dnd-core/DROP'; export var END_DRAG = 'dnd-core/END_DRAG';dist/esm/actions/dragDrop/publishDragSource.js000064400000000431151701466600015464 0ustar00import { PUBLISH_DRAG_SOURCE } from './types'; export function createPublishDragSource(manager) { return function publishDragSource() { var monitor = manager.getMonitor(); if (monitor.isDragging()) { return { type: PUBLISH_DRAG_SOURCE }; } }; }dist/esm/actions/dragDrop/endDrag.js000064400000001177151701466600013413 0ustar00import { invariant } from '@react-dnd/invariant'; import { END_DRAG } from './types'; export function createEndDrag(manager) { return function endDrag() { var monitor = manager.getMonitor(); var registry = manager.getRegistry(); verifyIsDragging(monitor); var sourceId = monitor.getSourceId(); if (sourceId != null) { var source = registry.getSource(sourceId, true); source.endDrag(monitor, sourceId); registry.unpinSource(); } return { type: END_DRAG }; }; } function verifyIsDragging(monitor) { invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.'); }dist/esm/actions/dragDrop/index.js000064400000001006151701466600013145 0ustar00import { createBeginDrag } from './beginDrag'; import { createPublishDragSource } from './publishDragSource'; import { createHover } from './hover'; import { createDrop } from './drop'; import { createEndDrag } from './endDrag'; export * from './types'; export function createDragDropActions(manager) { return { beginDrag: createBeginDrag(manager), publishDragSource: createPublishDragSource(manager), hover: createHover(manager), drop: createDrop(manager), endDrag: createEndDrag(manager) }; }dist/esm/actions/dragDrop/hover.js000064400000004271151701466600013170 0ustar00import { invariant } from '@react-dnd/invariant'; import { matchesType } from '../../utils/matchesType'; import { HOVER } from './types'; export function createHover(manager) { return function hover(targetIdsArg) { var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, clientOffset = _ref.clientOffset; verifyTargetIdsIsArray(targetIdsArg); var targetIds = targetIdsArg.slice(0); var monitor = manager.getMonitor(); var registry = manager.getRegistry(); checkInvariants(targetIds, monitor, registry); var draggedItemType = monitor.getItemType(); removeNonMatchingTargetIds(targetIds, registry, draggedItemType); hoverAllTargets(targetIds, monitor, registry); return { type: HOVER, payload: { targetIds: targetIds, clientOffset: clientOffset || null } }; }; } function verifyTargetIdsIsArray(targetIdsArg) { invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.'); } function checkInvariants(targetIds, monitor, registry) { invariant(monitor.isDragging(), 'Cannot call hover while not dragging.'); invariant(!monitor.didDrop(), 'Cannot call hover after drop.'); for (var i = 0; i < targetIds.length; i++) { var targetId = targetIds[i]; invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.'); var target = registry.getTarget(targetId); invariant(target, 'Expected targetIds to be registered.'); } } function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) { // Remove those targetIds that don't match the targetType. This // fixes shallow isOver which would only be non-shallow because of // non-matching targets. for (var i = targetIds.length - 1; i >= 0; i--) { var targetId = targetIds[i]; var targetType = registry.getTargetType(targetId); if (!matchesType(targetType, draggedItemType)) { targetIds.splice(i, 1); } } } function hoverAllTargets(targetIds, monitor, registry) { // Finally call hover on all matching targets. targetIds.forEach(function (targetId) { var target = registry.getTarget(targetId); target.hover(monitor, targetId); }); }dist/esm/actions/dragDrop/beginDrag.js000064400000006013151701466600013723 0ustar00import { invariant } from '@react-dnd/invariant'; import { setClientOffset } from './local/setClientOffset'; import { isObject } from '../../utils/js_utils'; import { BEGIN_DRAG, INIT_COORDS } from './types'; var ResetCoordinatesAction = { type: INIT_COORDS, payload: { clientOffset: null, sourceClientOffset: null } }; export function createBeginDrag(manager) { return function beginDrag() { var sourceIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { publishSource: true }; var _options$publishSourc = options.publishSource, publishSource = _options$publishSourc === void 0 ? true : _options$publishSourc, clientOffset = options.clientOffset, getSourceClientOffset = options.getSourceClientOffset; var monitor = manager.getMonitor(); var registry = manager.getRegistry(); // Initialize the coordinates using the client offset manager.dispatch(setClientOffset(clientOffset)); verifyInvariants(sourceIds, monitor, registry); // Get the draggable source var sourceId = getDraggableSource(sourceIds, monitor); if (sourceId === null) { manager.dispatch(ResetCoordinatesAction); return; } // Get the source client offset var sourceClientOffset = null; if (clientOffset) { if (!getSourceClientOffset) { throw new Error('getSourceClientOffset must be defined'); } verifyGetSourceClientOffsetIsFunction(getSourceClientOffset); sourceClientOffset = getSourceClientOffset(sourceId); } // Initialize the full coordinates manager.dispatch(setClientOffset(clientOffset, sourceClientOffset)); var source = registry.getSource(sourceId); var item = source.beginDrag(monitor, sourceId); verifyItemIsObject(item); registry.pinSource(sourceId); var itemType = registry.getSourceType(sourceId); return { type: BEGIN_DRAG, payload: { itemType: itemType, item: item, sourceId: sourceId, clientOffset: clientOffset || null, sourceClientOffset: sourceClientOffset || null, isSourcePublic: !!publishSource } }; }; } function verifyInvariants(sourceIds, monitor, registry) { invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.'); sourceIds.forEach(function (sourceId) { invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.'); }); } function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) { invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); } function verifyItemIsObject(item) { invariant(isObject(item), 'Item must be an object.'); } function getDraggableSource(sourceIds, monitor) { var sourceId = null; for (var i = sourceIds.length - 1; i >= 0; i--) { if (monitor.canDragSource(sourceIds[i])) { sourceId = sourceIds[i]; break; } } return sourceId; }dist/esm/actions/dragDrop/drop.js000064400000005445151701466600013015 0ustar00function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } import { invariant } from '@react-dnd/invariant'; import { DROP } from './types'; import { isObject } from '../../utils/js_utils'; export function createDrop(manager) { return function drop() { var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var monitor = manager.getMonitor(); var registry = manager.getRegistry(); verifyInvariants(monitor); var targetIds = getDroppableTargets(monitor); // Multiple actions are dispatched here, which is why this doesn't return an action targetIds.forEach(function (targetId, index) { var dropResult = determineDropResult(targetId, index, registry, monitor); var action = { type: DROP, payload: { dropResult: _objectSpread(_objectSpread({}, options), dropResult) } }; manager.dispatch(action); }); }; } function verifyInvariants(monitor) { invariant(monitor.isDragging(), 'Cannot call drop while not dragging.'); invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.'); } function determineDropResult(targetId, index, registry, monitor) { var target = registry.getTarget(targetId); var dropResult = target ? target.drop(monitor, targetId) : undefined; verifyDropResultType(dropResult); if (typeof dropResult === 'undefined') { dropResult = index === 0 ? {} : monitor.getDropResult(); } return dropResult; } function verifyDropResultType(dropResult) { invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.'); } function getDroppableTargets(monitor) { var targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor); targetIds.reverse(); return targetIds; }dist/esm/contracts.js000064400000002640151701466600010641 0ustar00function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } import { invariant } from '@react-dnd/invariant'; export function validateSourceContract(source) { invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.'); invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.'); invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.'); } export function validateTargetContract(target) { invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.'); invariant(typeof target.hover === 'function', 'Expected hover to be a function.'); invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.'); } export function validateType(type, allowArray) { if (allowArray && Array.isArray(type)) { type.forEach(function (t) { return validateType(t, false); }); return; } invariant(typeof type === 'string' || _typeof(type) === 'symbol', allowArray ? 'Type can only be a string, a symbol, or an array of either.' : 'Type can only be a string or a symbol.'); }dist/esm/interfaces.js000064400000000241151701466600010757 0ustar00export var HandlerRole; (function (HandlerRole) { HandlerRole["SOURCE"] = "SOURCE"; HandlerRole["TARGET"] = "TARGET"; })(HandlerRole || (HandlerRole = {}));README.md000064400000004002151701466600006025 0ustar00[](https://www.npmjs.org/package/dnd-core) [](https://travis-ci.org/react-dnd/dnd-core) [](https://codeclimate.com/github/react-dnd/dnd-core) # dnd-core Drag and drop sans the GUI. This is a clean implementation of drag and drop primitives that does not depend on the browser. It powers [React DnD](https://github.com/react-dnd/react-dnd) internally. ## Wat? To give you a better idea: - There is no DOM here - We let you define drop target and drag source logic - We let you supply custom underlying implementations (console, DOM via jQuery, React, React Native, _whatever_) - We manage drag source and drop target interaction This was written to support some rather complicated scenarios that were too hard to implement in [React DnD](https://github.com/react-dnd/react-dnd) due to its current architecture: - [Mocking drag and drop interaction in tests](https://github.com/react-dnd/react-dnd/issues/55) - [Full support for arbitrary nesting and handling drag sources and drop targets](https://github.com/react-dnd/react-dnd/issues/87) - [Dragging multiple items at once](https://github.com/react-dnd/react-dnd/issues/14) - [Even when source is removed, letting another drag source “represent it” (e.g. card disappeared from one Kanban list, reappeared in another one)](https://github.com/react-dnd/react-dnd/pull/64#issuecomment-76118757) As it turns out, these problems are much easier to solve when DOM is thrown out of the window. ## What's the API like? [Tests](https://github.com/react-dnd/dnd-core/tree/master/test) should give you some idea. You register drag sources and drop targets, connect a backend (you can use barebones `TestBackend` or implement a fancy real one yourself), and your drag sources and drop targets magically begin to interact. 
/home/emeraadmin/www/js/../node_modules/array-slice/../array-slice/../../4d695/dnd-core.tar