node_modules ignore

This commit is contained in:
oier committed 2025-05-08 23:43:47 +02:00
1 parent e19d52f172
commit 4574544c9f
65041 files changed
+10593536

No files matched your search

@@ -0,0 +1,33 @@
import type { DragDropManager, Identifier, Listener, Unsubscribe, XYCoord } from 'dnd-core';
import type { DragSourceMonitor } from '../types/index.js';
export declare class DragSourceMonitorImpl implements DragSourceMonitor {
private internalMonitor;
private sourceId;
constructor(manager: DragDropManager);
receiveHandlerId(sourceId: Identifier | null): void;
getHandlerId(): Identifier | null;
canDrag(): boolean;
isDragging(): boolean;
subscribeToStateChange(listener: Listener, options?: {
handlerIds?: Identifier[];
}): Unsubscribe;
isDraggingSource(sourceId: Identifier): boolean;
isOverTarget(targetId: Identifier, options?: {
shallow: boolean;
}): boolean;
getTargetIds(): Identifier[];
isSourcePublic(): boolean | null;
getSourceId(): Identifier | null;
subscribeToOffsetChange(listener: Listener): Unsubscribe;
canDragSource(sourceId: Identifier): boolean;
canDropOnTarget(targetId: Identifier): boolean;
getItemType(): Identifier | null;
getItem(): any;
getDropResult(): any;
didDrop(): boolean;
getInitialClientOffset(): XYCoord | null;
getInitialSourceClientOffset(): XYCoord | null;
getSourceClientOffset(): XYCoord | null;
getClientOffset(): XYCoord | null;
getDifferenceFromInitialOffset(): XYCoord | null;
}
+92
View File
@@ -0,0 +1,92 @@
import { invariant } from '@react-dnd/invariant';
let isCallingCanDrag = false;
let isCallingIsDragging = false;
export class DragSourceMonitorImpl {
receiveHandlerId(sourceId) {
this.sourceId = sourceId;
}
getHandlerId() {
return this.sourceId;
}
canDrag() {
invariant(!isCallingCanDrag, 'You may not call monitor.canDrag() inside your canDrag() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
try {
isCallingCanDrag = true;
return this.internalMonitor.canDragSource(this.sourceId);
} finally{
isCallingCanDrag = false;
}
}
isDragging() {
if (!this.sourceId) {
return false;
}
invariant(!isCallingIsDragging, 'You may not call monitor.isDragging() inside your isDragging() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
try {
isCallingIsDragging = true;
return this.internalMonitor.isDraggingSource(this.sourceId);
} finally{
isCallingIsDragging = false;
}
}
subscribeToStateChange(listener, options) {
return this.internalMonitor.subscribeToStateChange(listener, options);
}
isDraggingSource(sourceId) {
return this.internalMonitor.isDraggingSource(sourceId);
}
isOverTarget(targetId, options) {
return this.internalMonitor.isOverTarget(targetId, options);
}
getTargetIds() {
return this.internalMonitor.getTargetIds();
}
isSourcePublic() {
return this.internalMonitor.isSourcePublic();
}
getSourceId() {
return this.internalMonitor.getSourceId();
}
subscribeToOffsetChange(listener) {
return this.internalMonitor.subscribeToOffsetChange(listener);
}
canDragSource(sourceId) {
return this.internalMonitor.canDragSource(sourceId);
}
canDropOnTarget(targetId) {
return this.internalMonitor.canDropOnTarget(targetId);
}
getItemType() {
return this.internalMonitor.getItemType();
}
getItem() {
return this.internalMonitor.getItem();
}
getDropResult() {
return this.internalMonitor.getDropResult();
}
didDrop() {
return this.internalMonitor.didDrop();
}
getInitialClientOffset() {
return this.internalMonitor.getInitialClientOffset();
}
getInitialSourceClientOffset() {
return this.internalMonitor.getInitialSourceClientOffset();
}
getSourceClientOffset() {
return this.internalMonitor.getSourceClientOffset();
}
getClientOffset() {
return this.internalMonitor.getClientOffset();
}
getDifferenceFromInitialOffset() {
return this.internalMonitor.getDifferenceFromInitialOffset();
}
constructor(manager){
this.sourceId = null;
this.internalMonitor = manager.getMonitor();
}
}
//# sourceMappingURL=DragSourceMonitorImpl.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/DragSourceMonitorImpl.ts"],"sourcesContent":["import { invariant } from '@react-dnd/invariant'\nimport type {\n\tDragDropManager,\n\tDragDropMonitor,\n\tIdentifier,\n\tListener,\n\tUnsubscribe,\n\tXYCoord,\n} from 'dnd-core'\n\nimport type { DragSourceMonitor } from '../types/index.js'\n\nlet isCallingCanDrag = false\nlet isCallingIsDragging = false\n\nexport class DragSourceMonitorImpl implements DragSourceMonitor {\n\tprivate internalMonitor: DragDropMonitor\n\tprivate sourceId: Identifier | null = null\n\n\tpublic constructor(manager: DragDropManager) {\n\t\tthis.internalMonitor = manager.getMonitor()\n\t}\n\n\tpublic receiveHandlerId(sourceId: Identifier | null): void {\n\t\tthis.sourceId = sourceId\n\t}\n\n\tpublic getHandlerId(): Identifier | null {\n\t\treturn this.sourceId\n\t}\n\n\tpublic canDrag(): boolean {\n\t\tinvariant(\n\t\t\t!isCallingCanDrag,\n\t\t\t'You may not call monitor.canDrag() inside your canDrag() implementation. ' +\n\t\t\t\t'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor',\n\t\t)\n\n\t\ttry {\n\t\t\tisCallingCanDrag = true\n\t\t\treturn this.internalMonitor.canDragSource(this.sourceId as Identifier)\n\t\t} finally {\n\t\t\tisCallingCanDrag = false\n\t\t}\n\t}\n\n\tpublic isDragging(): boolean {\n\t\tif (!this.sourceId) {\n\t\t\treturn false\n\t\t}\n\t\tinvariant(\n\t\t\t!isCallingIsDragging,\n\t\t\t'You may not call monitor.isDragging() inside your isDragging() implementation. ' +\n\t\t\t\t'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor',\n\t\t)\n\n\t\ttry {\n\t\t\tisCallingIsDragging = true\n\t\t\treturn this.internalMonitor.isDraggingSource(this.sourceId)\n\t\t} finally {\n\t\t\tisCallingIsDragging = false\n\t\t}\n\t}\n\n\tpublic subscribeToStateChange(\n\t\tlistener: Listener,\n\t\toptions?: { handlerIds?: Identifier[] },\n\t): Unsubscribe {\n\t\treturn this.internalMonitor.subscribeToStateChange(listener, options)\n\t}\n\n\tpublic isDraggingSource(sourceId: Identifier): boolean {\n\t\treturn this.internalMonitor.isDraggingSource(sourceId)\n\t}\n\n\tpublic isOverTarget(\n\t\ttargetId: Identifier,\n\t\toptions?: { shallow: boolean },\n\t): boolean {\n\t\treturn this.internalMonitor.isOverTarget(targetId, options)\n\t}\n\n\tpublic getTargetIds(): Identifier[] {\n\t\treturn this.internalMonitor.getTargetIds()\n\t}\n\n\tpublic isSourcePublic(): boolean | null {\n\t\treturn this.internalMonitor.isSourcePublic()\n\t}\n\n\tpublic getSourceId(): Identifier | null {\n\t\treturn this.internalMonitor.getSourceId()\n\t}\n\n\tpublic subscribeToOffsetChange(listener: Listener): Unsubscribe {\n\t\treturn this.internalMonitor.subscribeToOffsetChange(listener)\n\t}\n\n\tpublic canDragSource(sourceId: Identifier): boolean {\n\t\treturn this.internalMonitor.canDragSource(sourceId)\n\t}\n\n\tpublic canDropOnTarget(targetId: Identifier): boolean {\n\t\treturn this.internalMonitor.canDropOnTarget(targetId)\n\t}\n\n\tpublic getItemType(): Identifier | null {\n\t\treturn this.internalMonitor.getItemType()\n\t}\n\n\tpublic getItem(): any {\n\t\treturn this.internalMonitor.getItem()\n\t}\n\n\tpublic getDropResult(): any {\n\t\treturn this.internalMonitor.getDropResult()\n\t}\n\n\tpublic didDrop(): boolean {\n\t\treturn this.internalMonitor.didDrop()\n\t}\n\n\tpublic getInitialClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getInitialClientOffset()\n\t}\n\n\tpublic getInitialSourceClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getInitialSourceClientOffset()\n\t}\n\n\tpublic getSourceClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getSourceClientOffset()\n\t}\n\n\tpublic getClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getClientOffset()\n\t}\n\n\tpublic getDifferenceFromInitialOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getDifferenceFromInitialOffset()\n\t}\n}\n"],"names":["invariant","isCallingCanDrag","isCallingIsDragging","DragSourceMonitorImpl","receiveHandlerId","sourceId","getHandlerId","canDrag","internalMonitor","canDragSource","isDragging","isDraggingSource","subscribeToStateChange","listener","options","isOverTarget","targetId","getTargetIds","isSourcePublic","getSourceId","subscribeToOffsetChange","canDropOnTarget","getItemType","getItem","getDropResult","didDrop","getInitialClientOffset","getInitialSourceClientOffset","getSourceClientOffset","getClientOffset","getDifferenceFromInitialOffset","manager","getMonitor"],"mappings":"AAAA,SAASA,SAAS,QAAQ,sBAAsB,CAAA;AAYhD,IAAIC,gBAAgB,GAAG,KAAK;AAC5B,IAAIC,mBAAmB,GAAG,KAAK;AAE/B,OAAO,MAAMC,qBAAqB;IAQjC,AAAOC,gBAAgB,CAACC,QAA2B,EAAQ;QAC1D,IAAI,CAACA,QAAQ,GAAGA,QAAQ;KACxB;IAED,AAAOC,YAAY,GAAsB;QACxC,OAAO,IAAI,CAACD,QAAQ,CAAA;KACpB;IAED,AAAOE,OAAO,GAAY;QACzBP,SAAS,CACR,CAACC,gBAAgB,EACjB,2EAA2E,GAC1E,8EAA8E,CAC/E;QAED,IAAI;YACHA,gBAAgB,GAAG,IAAI;YACvB,OAAO,IAAI,CAACO,eAAe,CAACC,aAAa,CAAC,IAAI,CAACJ,QAAQ,CAAe,CAAA;SACtE,QAAS;YACTJ,gBAAgB,GAAG,KAAK;SACxB;KACD;ILine truncated
@@ -0,0 +1,25 @@
import type { DragDropManager, Identifier, Listener, Unsubscribe, XYCoord } from 'dnd-core';
import type { DropTargetMonitor } from '../types/index.js';
export declare class DropTargetMonitorImpl implements DropTargetMonitor {
private internalMonitor;
private targetId;
constructor(manager: DragDropManager);
receiveHandlerId(targetId: Identifier | null): void;
getHandlerId(): Identifier | null;
subscribeToStateChange(listener: Listener, options?: {
handlerIds?: Identifier[];
}): Unsubscribe;
canDrop(): boolean;
isOver(options?: {
shallow?: boolean;
}): boolean;
getItemType(): Identifier | null;
getItem(): any;
getDropResult(): any;
didDrop(): boolean;
getInitialClientOffset(): XYCoord | null;
getInitialSourceClientOffset(): XYCoord | null;
getSourceClientOffset(): XYCoord | null;
getClientOffset(): XYCoord | null;
getDifferenceFromInitialOffset(): XYCoord | null;
}
+67
View File
@@ -0,0 +1,67 @@
import { invariant } from '@react-dnd/invariant';
let isCallingCanDrop = false;
export class DropTargetMonitorImpl {
receiveHandlerId(targetId) {
this.targetId = targetId;
}
getHandlerId() {
return this.targetId;
}
subscribeToStateChange(listener, options) {
return this.internalMonitor.subscribeToStateChange(listener, options);
}
canDrop() {
// Cut out early if the target id has not been set. This should prevent errors
// where the user has an older version of dnd-core like in
// https://github.com/react-dnd/react-dnd/issues/1310
if (!this.targetId) {
return false;
}
invariant(!isCallingCanDrop, 'You may not call monitor.canDrop() inside your canDrop() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor');
try {
isCallingCanDrop = true;
return this.internalMonitor.canDropOnTarget(this.targetId);
} finally{
isCallingCanDrop = false;
}
}
isOver(options) {
if (!this.targetId) {
return false;
}
return this.internalMonitor.isOverTarget(this.targetId, options);
}
getItemType() {
return this.internalMonitor.getItemType();
}
getItem() {
return this.internalMonitor.getItem();
}
getDropResult() {
return this.internalMonitor.getDropResult();
}
didDrop() {
return this.internalMonitor.didDrop();
}
getInitialClientOffset() {
return this.internalMonitor.getInitialClientOffset();
}
getInitialSourceClientOffset() {
return this.internalMonitor.getInitialSourceClientOffset();
}
getSourceClientOffset() {
return this.internalMonitor.getSourceClientOffset();
}
getClientOffset() {
return this.internalMonitor.getClientOffset();
}
getDifferenceFromInitialOffset() {
return this.internalMonitor.getDifferenceFromInitialOffset();
}
constructor(manager){
this.targetId = null;
this.internalMonitor = manager.getMonitor();
}
}
//# sourceMappingURL=DropTargetMonitorImpl.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/DropTargetMonitorImpl.ts"],"sourcesContent":["import { invariant } from '@react-dnd/invariant'\nimport type {\n\tDragDropManager,\n\tDragDropMonitor,\n\tIdentifier,\n\tListener,\n\tUnsubscribe,\n\tXYCoord,\n} from 'dnd-core'\n\nimport type { DropTargetMonitor } from '../types/index.js'\n\nlet isCallingCanDrop = false\n\nexport class DropTargetMonitorImpl implements DropTargetMonitor {\n\tprivate internalMonitor: DragDropMonitor\n\tprivate targetId: Identifier | null = null\n\n\tpublic constructor(manager: DragDropManager) {\n\t\tthis.internalMonitor = manager.getMonitor()\n\t}\n\n\tpublic receiveHandlerId(targetId: Identifier | null): void {\n\t\tthis.targetId = targetId\n\t}\n\n\tpublic getHandlerId(): Identifier | null {\n\t\treturn this.targetId\n\t}\n\n\tpublic subscribeToStateChange(\n\t\tlistener: Listener,\n\t\toptions?: { handlerIds?: Identifier[] },\n\t): Unsubscribe {\n\t\treturn this.internalMonitor.subscribeToStateChange(listener, options)\n\t}\n\n\tpublic canDrop(): boolean {\n\t\t// Cut out early if the target id has not been set. This should prevent errors\n\t\t// where the user has an older version of dnd-core like in\n\t\t// https://github.com/react-dnd/react-dnd/issues/1310\n\t\tif (!this.targetId) {\n\t\t\treturn false\n\t\t}\n\t\tinvariant(\n\t\t\t!isCallingCanDrop,\n\t\t\t'You may not call monitor.canDrop() inside your canDrop() implementation. ' +\n\t\t\t\t'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor',\n\t\t)\n\n\t\ttry {\n\t\t\tisCallingCanDrop = true\n\t\t\treturn this.internalMonitor.canDropOnTarget(this.targetId)\n\t\t} finally {\n\t\t\tisCallingCanDrop = false\n\t\t}\n\t}\n\n\tpublic isOver(options?: { shallow?: boolean }): boolean {\n\t\tif (!this.targetId) {\n\t\t\treturn false\n\t\t}\n\t\treturn this.internalMonitor.isOverTarget(this.targetId, options)\n\t}\n\n\tpublic getItemType(): Identifier | null {\n\t\treturn this.internalMonitor.getItemType()\n\t}\n\n\tpublic getItem(): any {\n\t\treturn this.internalMonitor.getItem()\n\t}\n\n\tpublic getDropResult(): any {\n\t\treturn this.internalMonitor.getDropResult()\n\t}\n\n\tpublic didDrop(): boolean {\n\t\treturn this.internalMonitor.didDrop()\n\t}\n\n\tpublic getInitialClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getInitialClientOffset()\n\t}\n\n\tpublic getInitialSourceClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getInitialSourceClientOffset()\n\t}\n\n\tpublic getSourceClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getSourceClientOffset()\n\t}\n\n\tpublic getClientOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getClientOffset()\n\t}\n\n\tpublic getDifferenceFromInitialOffset(): XYCoord | null {\n\t\treturn this.internalMonitor.getDifferenceFromInitialOffset()\n\t}\n}\n"],"names":["invariant","isCallingCanDrop","DropTargetMonitorImpl","receiveHandlerId","targetId","getHandlerId","subscribeToStateChange","listener","options","internalMonitor","canDrop","canDropOnTarget","isOver","isOverTarget","getItemType","getItem","getDropResult","didDrop","getInitialClientOffset","getInitialSourceClientOffset","getSourceClientOffset","getClientOffset","getDifferenceFromInitialOffset","manager","getMonitor"],"mappings":"AAAA,SAASA,SAAS,QAAQ,sBAAsB,CAAA;AAYhD,IAAIC,gBAAgB,GAAG,KAAK;AAE5B,OAAO,MAAMC,qBAAqB;IAQjC,AAAOC,gBAAgB,CAACC,QAA2B,EAAQ;QAC1D,IAAI,CAACA,QAAQ,GAAGA,QAAQ;KACxB;IAED,AAAOC,YAAY,GAAsB;QACxC,OAAO,IAAI,CAACD,QAAQ,CAAA;KACpB;IAED,AAAOE,sBAAsB,CAC5BC,QAAkB,EAClBC,OAAuC,EACzB;QACd,OAAO,IAAI,CAACC,eAAe,CAACH,sBAAsB,CAACC,QAAQ,EAAEC,OAAO,CAAC,CAAA;KACrE;IAED,AAAOE,OAAO,GAAY;QACzB,8EAA8E;QAC9E,0DAA0D;QAC1D,qDAAqD;QACrD,IAAI,CAAC,IAAI,CAACN,QAAQ,EAAE;YACnB,OAAO,KAAK,CAAA;SACZ;QACDJ,SAAS,CACR,CAACC,gBAAgB,EACjB,2EAA2E,GAC1E,8EAA8E,CAC/E;QAED,IAAI;YACHA,gBAAgB,GAAG,IAAI;YACvB,OAAO,IAAI,CAACQ,eAAe,CAACE,eAAe,CAAC,IAAI,CAACP,QAAQ,CAAC,CAAA;SAC1D,QAAS;YACTH,gBAAgB,GAAG,KAAK;SACxB;KACD;IAED,AAAOW,MAAM,CAACJ,OAA+B,EAAW;QACvD,IAAI,CAAC,IAAI,CAACJ,QAAQ,EAAE;YACnB,OAAO,KAAK,CAAA;SACZ;QACD,OAAO,IAAI,CAACK,eAAe,CAACI,YAAY,CAAC,IAAI,CAACT,QAAQ,EAAEI,OAAO,CAAC,CAAA;KAChE;IAED,AAAOM,WAAW,GAAsB;QACvC,OAAO,IAAI,CAACL,eAAe,CAACK,WAAW,EAAE,CAAA;KACzC;IAED,AAAOC,OAAO,GAAQ;QACrB,OAAO,IAAI,CAACN,eAAe,CAACM,OAAO,EAAE,CAAA;KACrC;IAED,AAAOC,aAAa,GAAQ;QAC3B,OAAO,IAAI,CAACP,eAAe,CAACO,aAAa,EAAE,CAAA;KAC3C;IAED,AAAOC,OAAO,GAAY;QACzB,OAAO,IAAI,CAACR,eAAe,CAACQ,OAAO,EAAE,CAAA;KACrC;IAED,AAAOC,sBAAsB,GAAmB;QAC/C,OAAO,IAAI,CAACT,eAAe,CAACS,sBAAsB,EAAE,CAAA;KACpD;IAED,AAAOC,4BAA4B,GAAmB;QACrD,OAAO,IAAI,CAACV,eAAe,CAACU,4BAA4B,EAAE,CAAA;KAC1D;IAED,AAAOC,qBAAqB,GAAmB;QAC9C,OAAO,IAAI,CAACX,eAAe,CAACW,qBAAqB,EAAE,CAAA;KACnD;IAED,AAAOC,eAAe,GAAmB;QACxC,OAAO,IAAI,CAACZ,eAAe,CAACY,eAAe,EAAE,CAAA;KAC7C;IAED,AAAOC,8BAA8B,GAAmB;QACvD,OAAO,IAAI,CAACb,eAAe,CAACa,8BAA8B,EAAE,CAAA;KAC5D;IAjFD,YAAmBC,OAAwB,CAAE;QAF7C,KAAQnB,QAAQ,GAAsB,IAAI,AAhB3C,CAgB2C;QAGzC,IAAI,CAACK,eAAe,GAAGc,OAAO,CAACC,UAAU,EAAE;KAC3C;CAgFD"}
+47
View File
@@ -0,0 +1,47 @@
import type { Backend, Identifier } from 'dnd-core';
import type { DragPreviewOptions, DragSourceOptions } from '../types/index.js';
export interface Connector {
hooks: any;
connectTarget: any;
receiveHandlerId(handlerId: Identifier | null): void;
reconnect(): void;
}
export declare class SourceConnector implements Connector {
hooks: any;
private handlerId;
private dragSourceRef;
private dragSourceNode;
private dragSourceOptionsInternal;
private dragSourceUnsubscribe;
private dragPreviewRef;
private dragPreviewNode;
private dragPreviewOptionsInternal;
private dragPreviewUnsubscribe;
private lastConnectedHandlerId;
private lastConnectedDragSource;
private lastConnectedDragSourceOptions;
private lastConnectedDragPreview;
private lastConnectedDragPreviewOptions;
private readonly backend;
constructor(backend: Backend);
receiveHandlerId(newHandlerId: Identifier | null): void;
get connectTarget(): any;
get dragSourceOptions(): DragSourceOptions | null;
set dragSourceOptions(options: DragSourceOptions | null);
get dragPreviewOptions(): DragPreviewOptions | null;
set dragPreviewOptions(options: DragPreviewOptions | null);
reconnect(): void;
private reconnectDragSource;
private reconnectDragPreview;
private didHandlerIdChange;
private didConnectedDragSourceChange;
private didConnectedDragPreviewChange;
private didDragSourceOptionsChange;
private didDragPreviewOptionsChange;
disconnectDragSource(): void;
disconnectDragPreview(): void;
private get dragSource();
private get dragPreview();
private clearDragSource;
private clearDragPreview;
}
+156
View File
@@ -0,0 +1,156 @@
import { shallowEqual } from '@react-dnd/shallowequal';
import { isRef } from './isRef.js';
import { wrapConnectorHooks } from './wrapConnectorHooks.js';
export class SourceConnector {
receiveHandlerId(newHandlerId) {
if (this.handlerId === newHandlerId) {
return;
}
this.handlerId = newHandlerId;
this.reconnect();
}
get connectTarget() {
return this.dragSource;
}
get dragSourceOptions() {
return this.dragSourceOptionsInternal;
}
set dragSourceOptions(options) {
this.dragSourceOptionsInternal = options;
}
get dragPreviewOptions() {
return this.dragPreviewOptionsInternal;
}
set dragPreviewOptions(options) {
this.dragPreviewOptionsInternal = options;
}
reconnect() {
const didChange = this.reconnectDragSource();
this.reconnectDragPreview(didChange);
}
reconnectDragSource() {
const dragSource = this.dragSource;
// if nothing has changed then don't resubscribe
const didChange = this.didHandlerIdChange() || this.didConnectedDragSourceChange() || this.didDragSourceOptionsChange();
if (didChange) {
this.disconnectDragSource();
}
if (!this.handlerId) {
return didChange;
}
if (!dragSource) {
this.lastConnectedDragSource = dragSource;
return didChange;
}
if (didChange) {
this.lastConnectedHandlerId = this.handlerId;
this.lastConnectedDragSource = dragSource;
this.lastConnectedDragSourceOptions = this.dragSourceOptions;
this.dragSourceUnsubscribe = this.backend.connectDragSource(this.handlerId, dragSource, this.dragSourceOptions);
}
return didChange;
}
reconnectDragPreview(forceDidChange = false) {
const dragPreview = this.dragPreview;
// if nothing has changed then don't resubscribe
const didChange = forceDidChange || this.didHandlerIdChange() || this.didConnectedDragPreviewChange() || this.didDragPreviewOptionsChange();
if (didChange) {
this.disconnectDragPreview();
}
if (!this.handlerId) {
return;
}
if (!dragPreview) {
this.lastConnectedDragPreview = dragPreview;
return;
}
if (didChange) {
this.lastConnectedHandlerId = this.handlerId;
this.lastConnectedDragPreview = dragPreview;
this.lastConnectedDragPreviewOptions = this.dragPreviewOptions;
this.dragPreviewUnsubscribe = this.backend.connectDragPreview(this.handlerId, dragPreview, this.dragPreviewOptions);
}
}
didHandlerIdChange() {
return this.lastConnectedHandlerId !== this.handlerId;
}
didConnectedDragSourceChange() {
return this.lastConnectedDragSource !== this.dragSource;
}
didConnectedDragPreviewChange() {
return this.lastConnectedDragPreview !== this.dragPreview;
}
didDragSourceOptionsChange() {
return !shallowEqual(this.lastConnectedDragSourceOptions, this.dragSourceOptions);
}
didDragPreviewOptionsChange() {
return !shallowEqual(this.lastConnectedDragPreviewOptions, this.dragPreviewOptions);
}
disconnectDragSource() {
if (this.dragSourceUnsubscribe) {
this.dragSourceUnsubscribe();
this.dragSourceUnsubscribe = undefined;
}
}
disconnectDragPreview() {
if (this.dragPreviewUnsubscribe) {
this.dragPreviewUnsubscribe();
this.dragPreviewUnsubscribe = undefined;
this.dragPreviewNode = null;
this.dragPreviewRef = null;
}
}
get dragSource() {
return this.dragSourceNode || this.dragSourceRef && this.dragSourceRef.current;
}
get dragPreview() {
return this.dragPreviewNode || this.dragPreviewRef && this.dragPreviewRef.current;
}
clearDragSource() {
this.dragSourceNode = null;
this.dragSourceRef = null;
}
clearDragPreview() {
this.dragPreviewNode = null;
this.dragPreviewRef = null;
}
constructor(backend){
this.hooks = wrapConnectorHooks({
dragSource: (node, options)=>{
this.clearDragSource();
this.dragSourceOptions = options || null;
if (isRef(node)) {
this.dragSourceRef = node;
} else {
this.dragSourceNode = node;
}
this.reconnectDragSource();
},
dragPreview: (node, options)=>{
this.clearDragPreview();
this.dragPreviewOptions = options || null;
if (isRef(node)) {
this.dragPreviewRef = node;
} else {
this.dragPreviewNode = node;
}
this.reconnectDragPreview();
}
});
this.handlerId = null;
// The drop target may either be attached via ref or connect function
this.dragSourceRef = null;
this.dragSourceOptionsInternal = null;
// The drag preview may either be attached via ref or connect function
this.dragPreviewRef = null;
this.dragPreviewOptionsInternal = null;
this.lastConnectedHandlerId = null;
this.lastConnectedDragSource = null;
this.lastConnectedDragSourceOptions = null;
this.lastConnectedDragPreview = null;
this.lastConnectedDragPreviewOptions = null;
this.backend = backend;
}
}
//# sourceMappingURL=SourceConnector.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/SourceConnector.ts"],"sourcesContent":["import { shallowEqual } from '@react-dnd/shallowequal'\nimport type { Backend, Identifier, Unsubscribe } from 'dnd-core'\nimport type { ReactElement, Ref, RefObject } from 'react'\n\nimport type { DragPreviewOptions, DragSourceOptions } from '../types/index.js'\nimport { isRef } from './isRef.js'\nimport { wrapConnectorHooks } from './wrapConnectorHooks.js'\n\nexport interface Connector {\n\thooks: any\n\tconnectTarget: any\n\treceiveHandlerId(handlerId: Identifier | null): void\n\treconnect(): void\n}\n\nexport class SourceConnector implements Connector {\n\tpublic hooks = wrapConnectorHooks({\n\t\tdragSource: (\n\t\t\tnode: Element | ReactElement | Ref<any>,\n\t\t\toptions?: DragSourceOptions,\n\t\t) => {\n\t\t\tthis.clearDragSource()\n\t\t\tthis.dragSourceOptions = options || null\n\t\t\tif (isRef(node)) {\n\t\t\t\tthis.dragSourceRef = node as RefObject<any>\n\t\t\t} else {\n\t\t\t\tthis.dragSourceNode = node\n\t\t\t}\n\t\t\tthis.reconnectDragSource()\n\t\t},\n\t\tdragPreview: (node: any, options?: DragPreviewOptions) => {\n\t\t\tthis.clearDragPreview()\n\t\t\tthis.dragPreviewOptions = options || null\n\t\t\tif (isRef(node)) {\n\t\t\t\tthis.dragPreviewRef = node\n\t\t\t} else {\n\t\t\t\tthis.dragPreviewNode = node\n\t\t\t}\n\t\t\tthis.reconnectDragPreview()\n\t\t},\n\t})\n\tprivate handlerId: Identifier | null = null\n\n\t// The drop target may either be attached via ref or connect function\n\tprivate dragSourceRef: RefObject<any> | null = null\n\tprivate dragSourceNode: any\n\tprivate dragSourceOptionsInternal: DragSourceOptions | null = null\n\tprivate dragSourceUnsubscribe: Unsubscribe | undefined\n\n\t// The drag preview may either be attached via ref or connect function\n\tprivate dragPreviewRef: RefObject<any> | null = null\n\tprivate dragPreviewNode: any\n\tprivate dragPreviewOptionsInternal: DragPreviewOptions | null = null\n\tprivate dragPreviewUnsubscribe: Unsubscribe | undefined\n\n\tprivate lastConnectedHandlerId: Identifier | null = null\n\tprivate lastConnectedDragSource: any = null\n\tprivate lastConnectedDragSourceOptions: any = null\n\tprivate lastConnectedDragPreview: any = null\n\tprivate lastConnectedDragPreviewOptions: any = null\n\n\tprivate readonly backend: Backend\n\n\tpublic constructor(backend: Backend) {\n\t\tthis.backend = backend\n\t}\n\n\tpublic receiveHandlerId(newHandlerId: Identifier | null): void {\n\t\tif (this.handlerId === newHandlerId) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.handlerId = newHandlerId\n\t\tthis.reconnect()\n\t}\n\n\tpublic get connectTarget(): any {\n\t\treturn this.dragSource\n\t}\n\n\tpublic get dragSourceOptions(): DragSourceOptions | null {\n\t\treturn this.dragSourceOptionsInternal\n\t}\n\tpublic set dragSourceOptions(options: DragSourceOptions | null) {\n\t\tthis.dragSourceOptionsInternal = options\n\t}\n\n\tpublic get dragPreviewOptions(): DragPreviewOptions | null {\n\t\treturn this.dragPreviewOptionsInternal\n\t}\n\n\tpublic set dragPreviewOptions(options: DragPreviewOptions | null) {\n\t\tthis.dragPreviewOptionsInternal = options\n\t}\n\n\tpublic reconnect(): void {\n\t\tconst didChange = this.reconnectDragSource()\n\t\tthis.reconnectDragPreview(didChange)\n\t}\n\n\tprivate reconnectDragSource(): boolean {\n\t\tconst dragSource = this.dragSource\n\t\t// if nothing has changed then don't resubscribe\n\t\tconst didChange =\n\t\t\tthis.didHandlerIdChange() ||\n\t\t\tthis.didConnectedDragSourceChange() ||\n\t\t\tthis.didDragSourceOptionsChange()\n\n\t\tif (didChange) {\n\t\t\tthis.disconnectDragSource()\n\t\t}\n\n\t\tif (!this.handlerId) {\n\t\t\treturn didChange\n\t\t}\n\t\tif (!dragSource) {\n\t\t\tthis.lastConnectedDragSource = dragSource\n\t\t\treturn didChange\n\t\t}\n\n\t\tif (didChange) {\n\t\t\tthis.lastConnectedHandlerId = this.handlerId\n\t\t\tthis.lastConnectedDragSource = dragSource\n\t\t\tthis.lastConnectedDragSourceOptions = this.dragSourceOptions\n\t\t\tthis.dragSourceUnsubscribe = this.backend.connectDragSource(\n\t\t\t\tthis.handlerId,\n\t\t\t\tdragSource,\n\t\t\t\tthis.dragSourceOptions,\n\t\t\t)\n\t\t}\n\t\treturn didChange\n\t}\n\n\tprivate reconnectDragPreview(forceDidChange = false): void {\n\t\tconst dragPreview = this.dragPreview\n\t\t// if nothing has changed then don't resubscribe\n\t\tconst didChange =\n\t\t\tforceDidChange ||\n\t\t\tthis.didHandlerIdChange() ||\n\t\t\tthis.didConnectedDragPreviewChange() ||\n\t\t\tthis.didDragPreviewOptionsChange()\n\n\t\tif (didChange) {\n\t\t\tthis.disconnectDragPreview()\n\t\t}\n\n\t\tif (!this.handlerId) {\n\t\t\treturn\n\t\t}\n\t\tif (!dragPreview) {\n\t\t\tthis.lastConnectedDragPreview = dragPreview\n\t\t\treturn\n\t\t}\n\n\t\tif (didChange) {\n\t\t\tthis.lastConnectedHandlerId = this.handlerId\n\t\t\tthis.lastConnectedDragPreview = dragPreview\n\t\t\tthis.lastConnectedDragPreviewOptions = this.dragPreviewOptions\n\t\t\tthis.dragPreviewUnsubscribe = this.backend.connectDragPreview(\n\t\t\t\tthis.hanLine truncated
+27
View File
@@ -0,0 +1,27 @@
import type { Backend, Identifier } from 'dnd-core';
import type { DropTargetOptions } from '../types/index.js';
import type { Connector } from './SourceConnector.js';
export declare class TargetConnector implements Connector {
hooks: any;
private handlerId;
private dropTargetRef;
private dropTargetNode;
private dropTargetOptionsInternal;
private unsubscribeDropTarget;
private lastConnectedHandlerId;
private lastConnectedDropTarget;
private lastConnectedDropTargetOptions;
private readonly backend;
constructor(backend: Backend);
get connectTarget(): any;
reconnect(): void;
receiveHandlerId(newHandlerId: Identifier | null): void;
get dropTargetOptions(): DropTargetOptions;
set dropTargetOptions(options: DropTargetOptions);
private didHandlerIdChange;
private didDropTargetChange;
private didOptionsChange;
disconnectDropTarget(): void;
private get dropTarget();
private clearDropTarget;
}
+88
View File
@@ -0,0 +1,88 @@
import { shallowEqual } from '@react-dnd/shallowequal';
import { isRef } from './isRef.js';
import { wrapConnectorHooks } from './wrapConnectorHooks.js';
export class TargetConnector {
get connectTarget() {
return this.dropTarget;
}
reconnect() {
// if nothing has changed then don't resubscribe
const didChange = this.didHandlerIdChange() || this.didDropTargetChange() || this.didOptionsChange();
if (didChange) {
this.disconnectDropTarget();
}
const dropTarget = this.dropTarget;
if (!this.handlerId) {
return;
}
if (!dropTarget) {
this.lastConnectedDropTarget = dropTarget;
return;
}
if (didChange) {
this.lastConnectedHandlerId = this.handlerId;
this.lastConnectedDropTarget = dropTarget;
this.lastConnectedDropTargetOptions = this.dropTargetOptions;
this.unsubscribeDropTarget = this.backend.connectDropTarget(this.handlerId, dropTarget, this.dropTargetOptions);
}
}
receiveHandlerId(newHandlerId) {
if (newHandlerId === this.handlerId) {
return;
}
this.handlerId = newHandlerId;
this.reconnect();
}
get dropTargetOptions() {
return this.dropTargetOptionsInternal;
}
set dropTargetOptions(options) {
this.dropTargetOptionsInternal = options;
}
didHandlerIdChange() {
return this.lastConnectedHandlerId !== this.handlerId;
}
didDropTargetChange() {
return this.lastConnectedDropTarget !== this.dropTarget;
}
didOptionsChange() {
return !shallowEqual(this.lastConnectedDropTargetOptions, this.dropTargetOptions);
}
disconnectDropTarget() {
if (this.unsubscribeDropTarget) {
this.unsubscribeDropTarget();
this.unsubscribeDropTarget = undefined;
}
}
get dropTarget() {
return this.dropTargetNode || this.dropTargetRef && this.dropTargetRef.current;
}
clearDropTarget() {
this.dropTargetRef = null;
this.dropTargetNode = null;
}
constructor(backend){
this.hooks = wrapConnectorHooks({
dropTarget: (node, options)=>{
this.clearDropTarget();
this.dropTargetOptions = options;
if (isRef(node)) {
this.dropTargetRef = node;
} else {
this.dropTargetNode = node;
}
this.reconnect();
}
});
this.handlerId = null;
// The drop target may either be attached via ref or connect function
this.dropTargetRef = null;
this.dropTargetOptionsInternal = null;
this.lastConnectedHandlerId = null;
this.lastConnectedDropTarget = null;
this.lastConnectedDropTargetOptions = null;
this.backend = backend;
}
}
//# sourceMappingURL=TargetConnector.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/TargetConnector.ts"],"sourcesContent":["import { shallowEqual } from '@react-dnd/shallowequal'\nimport type { Backend, Identifier, Unsubscribe } from 'dnd-core'\nimport type { RefObject } from 'react'\n\nimport type { DropTargetOptions } from '../types/index.js'\nimport { isRef } from './isRef.js'\nimport type { Connector } from './SourceConnector.js'\nimport { wrapConnectorHooks } from './wrapConnectorHooks.js'\n\nexport class TargetConnector implements Connector {\n\tpublic hooks = wrapConnectorHooks({\n\t\tdropTarget: (node: any, options: DropTargetOptions) => {\n\t\t\tthis.clearDropTarget()\n\t\t\tthis.dropTargetOptions = options\n\t\t\tif (isRef(node)) {\n\t\t\t\tthis.dropTargetRef = node\n\t\t\t} else {\n\t\t\t\tthis.dropTargetNode = node\n\t\t\t}\n\t\t\tthis.reconnect()\n\t\t},\n\t})\n\n\tprivate handlerId: Identifier | null = null\n\t// The drop target may either be attached via ref or connect function\n\tprivate dropTargetRef: RefObject<any> | null = null\n\tprivate dropTargetNode: any\n\tprivate dropTargetOptionsInternal: DropTargetOptions | null = null\n\tprivate unsubscribeDropTarget: Unsubscribe | undefined\n\n\tprivate lastConnectedHandlerId: Identifier | null = null\n\tprivate lastConnectedDropTarget: any = null\n\tprivate lastConnectedDropTargetOptions: DropTargetOptions | null = null\n\tprivate readonly backend: Backend\n\n\tpublic constructor(backend: Backend) {\n\t\tthis.backend = backend\n\t}\n\n\tpublic get connectTarget(): any {\n\t\treturn this.dropTarget\n\t}\n\n\tpublic reconnect(): void {\n\t\t// if nothing has changed then don't resubscribe\n\t\tconst didChange =\n\t\t\tthis.didHandlerIdChange() ||\n\t\t\tthis.didDropTargetChange() ||\n\t\t\tthis.didOptionsChange()\n\n\t\tif (didChange) {\n\t\t\tthis.disconnectDropTarget()\n\t\t}\n\n\t\tconst dropTarget = this.dropTarget\n\t\tif (!this.handlerId) {\n\t\t\treturn\n\t\t}\n\t\tif (!dropTarget) {\n\t\t\tthis.lastConnectedDropTarget = dropTarget\n\t\t\treturn\n\t\t}\n\n\t\tif (didChange) {\n\t\t\tthis.lastConnectedHandlerId = this.handlerId\n\t\t\tthis.lastConnectedDropTarget = dropTarget\n\t\t\tthis.lastConnectedDropTargetOptions = this.dropTargetOptions\n\n\t\t\tthis.unsubscribeDropTarget = this.backend.connectDropTarget(\n\t\t\t\tthis.handlerId,\n\t\t\t\tdropTarget,\n\t\t\t\tthis.dropTargetOptions,\n\t\t\t)\n\t\t}\n\t}\n\n\tpublic receiveHandlerId(newHandlerId: Identifier | null): void {\n\t\tif (newHandlerId === this.handlerId) {\n\t\t\treturn\n\t\t}\n\n\t\tthis.handlerId = newHandlerId\n\t\tthis.reconnect()\n\t}\n\n\tpublic get dropTargetOptions(): DropTargetOptions {\n\t\treturn this.dropTargetOptionsInternal\n\t}\n\tpublic set dropTargetOptions(options: DropTargetOptions) {\n\t\tthis.dropTargetOptionsInternal = options\n\t}\n\n\tprivate didHandlerIdChange(): boolean {\n\t\treturn this.lastConnectedHandlerId !== this.handlerId\n\t}\n\n\tprivate didDropTargetChange(): boolean {\n\t\treturn this.lastConnectedDropTarget !== this.dropTarget\n\t}\n\n\tprivate didOptionsChange(): boolean {\n\t\treturn !shallowEqual(\n\t\t\tthis.lastConnectedDropTargetOptions,\n\t\t\tthis.dropTargetOptions,\n\t\t)\n\t}\n\n\tpublic disconnectDropTarget() {\n\t\tif (this.unsubscribeDropTarget) {\n\t\t\tthis.unsubscribeDropTarget()\n\t\t\tthis.unsubscribeDropTarget = undefined\n\t\t}\n\t}\n\n\tprivate get dropTarget() {\n\t\treturn (\n\t\t\tthis.dropTargetNode || (this.dropTargetRef && this.dropTargetRef.current)\n\t\t)\n\t}\n\n\tprivate clearDropTarget() {\n\t\tthis.dropTargetRef = null\n\t\tthis.dropTargetNode = null\n\t}\n}\n"],"names":["shallowEqual","isRef","wrapConnectorHooks","TargetConnector","connectTarget","dropTarget","reconnect","didChange","didHandlerIdChange","didDropTargetChange","didOptionsChange","disconnectDropTarget","handlerId","lastConnectedDropTarget","lastConnectedHandlerId","lastConnectedDropTargetOptions","dropTargetOptions","unsubscribeDropTarget","backend","connectDropTarget","receiveHandlerId","newHandlerId","dropTargetOptionsInternal","options","undefined","dropTargetNode","dropTargetRef","current","clearDropTarget","hooks","node"],"mappings":"AAAA,SAASA,YAAY,QAAQ,yBAAyB,CAAA;AAKtD,SAASC,KAAK,QAAQ,YAAY,CAAA;AAElC,SAASC,kBAAkB,QAAQ,yBAAyB,CAAA;AAE5D,OAAO,MAAMC,eAAe;IA8B3B,IAAWC,aAAa,GAAQ;QAC/B,OAAO,IAAI,CAACC,UAAU,CAAA;KACtB;IAED,AAAOC,SAAS,GAAS;QACxB,gDAAgD;QAChD,MAAMC,SAAS,GACd,IAAI,CAACC,kBAAkB,EAAE,IACzB,IAAI,CAACC,mBAAmB,EAAE,IAC1B,IAAI,CAACC,gBAAgB,EAAE;QAExB,IAAIH,SAAS,EAAE;YACd,IAAI,CAACI,oBAAoB,EAAE;SAC3B;QAED,MAAMN,UAAU,GAAG,IAAI,CAACA,UAAU;QAClC,IAAI,CAAC,IAAI,CAACO,SAAS,EAAE;YACpB,OAAM;SACN;QACD,IAAI,CAACP,UAAU,EAAE;YAChB,IAAI,CAACQ,uBAAuB,GAAGR,UAAU;YACzC,OAAM;SACN;QAED,IAAIE,SAAS,EAAE;YACd,IAAI,CAACO,sBAAsB,GAAG,IAAI,CAACF,SAAS;YAC5C,IAAI,CAACC,uBAAuB,GAAGR,UAAU;YACzC,IAAI,CAACU,8BAA8B,GAAG,IAAI,CAACC,iBAAiB;YAE5D,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACC,OAAO,CAACC,iBAAiB,CAC1D,IAAI,CAACP,SAAS,EACdP,UAAU,EACV,IAAI,CAACW,iBAAiB,CACtB;SACD;KACD;IAED,AAAOI,gBAAgB,CAACC,YAA+B,EAAQLine truncated
+5
View File
@@ -0,0 +1,5 @@
export * from './DragSourceMonitorImpl.js';
export * from './DropTargetMonitorImpl.js';
export * from './registration.js';
export * from './SourceConnector.js';
export * from './TargetConnector.js';
+7
View File
@@ -0,0 +1,7 @@
export * from './DragSourceMonitorImpl.js';
export * from './DropTargetMonitorImpl.js';
export * from './registration.js';
export * from './SourceConnector.js';
export * from './TargetConnector.js';
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/index.ts"],"sourcesContent":["export * from './DragSourceMonitorImpl.js'\nexport * from './DropTargetMonitorImpl.js'\nexport * from './registration.js'\nexport * from './SourceConnector.js'\nexport * from './TargetConnector.js'\n"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AACjC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA"}
+4
View File
@@ -0,0 +1,4 @@
export interface Ref<T> {
current: T;
}
export declare function isRef(obj: unknown): boolean;
+6
View File
@@ -0,0 +1,6 @@
export function isRef(obj) {
return(// eslint-disable-next-line no-prototype-builtins
obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, 'current'));
}
//# sourceMappingURL=isRef.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/isRef.ts"],"sourcesContent":["export interface Ref<T> {\n\tcurrent: T\n}\n\nexport function isRef(obj: unknown): boolean {\n\treturn (\n\t\t// eslint-disable-next-line no-prototype-builtins\n\t\tobj !== null &&\n\t\ttypeof obj === 'object' &&\n\t\tObject.prototype.hasOwnProperty.call(obj, 'current')\n\t)\n}\n"],"names":["isRef","obj","Object","prototype","hasOwnProperty","call"],"mappings":"AAIA,OAAO,SAASA,KAAK,CAACC,GAAY,EAAW;IAC5C,OACC,iDAAiD;IACjDA,GAAG,KAAK,IAAI,IACZ,OAAOA,GAAG,KAAK,QAAQ,IACvBC,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,GAAG,EAAE,SAAS,CAAC,EACpD;CACD"}
+3
View File
@@ -0,0 +1,3 @@
import type { DragDropManager, DragSource, DropTarget, Identifier, SourceType, TargetType, Unsubscribe } from 'dnd-core';
export declare function registerTarget(type: TargetType, target: DropTarget, manager: DragDropManager): [Identifier, Unsubscribe];
export declare function registerSource(type: SourceType, source: DragSource, manager: DragDropManager): [Identifier, Unsubscribe];
+18
View File
@@ -0,0 +1,18 @@
export function registerTarget(type, target, manager) {
const registry = manager.getRegistry();
const targetId = registry.addTarget(type, target);
return [
targetId,
()=>registry.removeTarget(targetId)
];
}
export function registerSource(type, source, manager) {
const registry = manager.getRegistry();
const sourceId = registry.addSource(type, source);
return [
sourceId,
()=>registry.removeSource(sourceId)
];
}
//# sourceMappingURL=registration.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/registration.ts"],"sourcesContent":["import type {\n\tDragDropManager,\n\tDragSource,\n\tDropTarget,\n\tIdentifier,\n\tSourceType,\n\tTargetType,\n\tUnsubscribe,\n} from 'dnd-core'\n\nexport function registerTarget(\n\ttype: TargetType,\n\ttarget: DropTarget,\n\tmanager: DragDropManager,\n): [Identifier, Unsubscribe] {\n\tconst registry = manager.getRegistry()\n\tconst targetId = registry.addTarget(type, target)\n\n\treturn [targetId, () => registry.removeTarget(targetId)]\n}\n\nexport function registerSource(\n\ttype: SourceType,\n\tsource: DragSource,\n\tmanager: DragDropManager,\n): [Identifier, Unsubscribe] {\n\tconst registry = manager.getRegistry()\n\tconst sourceId = registry.addSource(type, source)\n\n\treturn [sourceId, () => registry.removeSource(sourceId)]\n}\n"],"names":["registerTarget","type","target","manager","registry","getRegistry","targetId","addTarget","removeTarget","registerSource","source","sourceId","addSource","removeSource"],"mappings":"AAUA,OAAO,SAASA,cAAc,CAC7BC,IAAgB,EAChBC,MAAkB,EAClBC,OAAwB,EACI;IAC5B,MAAMC,QAAQ,GAAGD,OAAO,CAACE,WAAW,EAAE;IACtC,MAAMC,QAAQ,GAAGF,QAAQ,CAACG,SAAS,CAACN,IAAI,EAAEC,MAAM,CAAC;IAEjD,OAAO;QAACI,QAAQ;QAAE,IAAMF,QAAQ,CAACI,YAAY,CAACF,QAAQ,CAAC;KAAC,CAAA;CACxD;AAED,OAAO,SAASG,cAAc,CAC7BR,IAAgB,EAChBS,MAAkB,EAClBP,OAAwB,EACI;IAC5B,MAAMC,QAAQ,GAAGD,OAAO,CAACE,WAAW,EAAE;IACtC,MAAMM,QAAQ,GAAGP,QAAQ,CAACQ,SAAS,CAACX,IAAI,EAAES,MAAM,CAAC;IAEjD,OAAO;QAACC,QAAQ;QAAE,IAAMP,QAAQ,CAACS,YAAY,CAACF,QAAQ,CAAC;KAAC,CAAA;CACxD"}
+1
View File
@@ -0,0 +1 @@
export declare function wrapConnectorHooks(hooks: any): any;
+73
View File
@@ -0,0 +1,73 @@
import { invariant } from '@react-dnd/invariant';
import { cloneElement, isValidElement } from 'react';
function throwIfCompositeComponentElement(element) {
// Custom components can no longer be wrapped directly in React DnD 2.0
// so that we don't need to depend on findDOMNode() from react-dom.
if (typeof element.type === 'string') {
return;
}
const displayName = element.type.displayName || element.type.name || 'the component';
throw new Error('Only native element nodes can now be passed to React DnD connectors.' + `You can either wrap ${displayName} into a <div>, or turn it into a ` + 'drag source or a drop target itself.');
}
function wrapHookToRecognizeElement(hook) {
return (elementOrNode = null, options = null)=>{
// When passed a node, call the hook straight away.
if (!isValidElement(elementOrNode)) {
const node = elementOrNode;
hook(node, options);
// return the node so it can be chained (e.g. when within callback refs
// <div ref={node => connectDragSource(connectDropTarget(node))}/>
return node;
}
// If passed a ReactElement, clone it and attach this function as a ref.
// This helps us achieve a neat API where user doesn't even know that refs
// are being used under the hood.
const element = elementOrNode;
throwIfCompositeComponentElement(element);
// When no options are passed, use the hook directly
const ref = options ? (node)=>hook(node, options)
: hook;
return cloneWithRef(element, ref);
};
}
export function wrapConnectorHooks(hooks) {
const wrappedHooks = {};
Object.keys(hooks).forEach((key)=>{
const hook = hooks[key];
// ref objects should be passed straight through without wrapping
if (key.endsWith('Ref')) {
wrappedHooks[key] = hooks[key];
} else {
const wrappedHook = wrapHookToRecognizeElement(hook);
wrappedHooks[key] = ()=>wrappedHook
;
}
});
return wrappedHooks;
}
function setRef(ref, node) {
if (typeof ref === 'function') {
ref(node);
} else {
ref.current = node;
}
}
function cloneWithRef(element, newRef) {
const previousRef = element.ref;
invariant(typeof previousRef !== 'string', 'Cannot connect React DnD to an element with an existing string ref. ' + 'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' + 'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs');
if (!previousRef) {
// When there is no ref on the element, use the new ref directly
return cloneElement(element, {
ref: newRef
});
} else {
return cloneElement(element, {
ref: (node)=>{
setRef(previousRef, node);
setRef(newRef, node);
}
});
}
}
//# sourceMappingURL=wrapConnectorHooks.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../src/internals/wrapConnectorHooks.ts"],"sourcesContent":["import { invariant } from '@react-dnd/invariant'\nimport type { ReactElement } from 'react'\nimport { cloneElement, isValidElement } from 'react'\n\nfunction throwIfCompositeComponentElement(element: ReactElement<any>) {\n\t// Custom components can no longer be wrapped directly in React DnD 2.0\n\t// so that we don't need to depend on findDOMNode() from react-dom.\n\tif (typeof element.type === 'string') {\n\t\treturn\n\t}\n\n\tconst displayName =\n\t\t(element.type as any).displayName || element.type.name || 'the component'\n\n\tthrow new Error(\n\t\t'Only native element nodes can now be passed to React DnD connectors.' +\n\t\t\t`You can either wrap ${displayName} into a <div>, or turn it into a ` +\n\t\t\t'drag source or a drop target itself.',\n\t)\n}\n\nfunction wrapHookToRecognizeElement(hook: (node: any, options: any) => void) {\n\treturn (elementOrNode = null, options = null) => {\n\t\t// When passed a node, call the hook straight away.\n\t\tif (!isValidElement(elementOrNode)) {\n\t\t\tconst node = elementOrNode\n\t\t\thook(node, options)\n\t\t\t// return the node so it can be chained (e.g. when within callback refs\n\t\t\t// <div ref={node => connectDragSource(connectDropTarget(node))}/>\n\t\t\treturn node\n\t\t}\n\n\t\t// If passed a ReactElement, clone it and attach this function as a ref.\n\t\t// This helps us achieve a neat API where user doesn't even know that refs\n\t\t// are being used under the hood.\n\t\tconst element: ReactElement | null = elementOrNode\n\t\tthrowIfCompositeComponentElement(element as any)\n\n\t\t// When no options are passed, use the hook directly\n\t\tconst ref = options ? (node: Element) => hook(node, options) : hook\n\t\treturn cloneWithRef(element, ref)\n\t}\n}\n\nexport function wrapConnectorHooks(hooks: any) {\n\tconst wrappedHooks: any = {}\n\n\tObject.keys(hooks).forEach((key) => {\n\t\tconst hook = hooks[key]\n\n\t\t// ref objects should be passed straight through without wrapping\n\t\tif (key.endsWith('Ref')) {\n\t\t\twrappedHooks[key] = hooks[key]\n\t\t} else {\n\t\t\tconst wrappedHook = wrapHookToRecognizeElement(hook)\n\t\t\twrappedHooks[key] = () => wrappedHook\n\t\t}\n\t})\n\n\treturn wrappedHooks\n}\n\nfunction setRef(ref: any, node: any) {\n\tif (typeof ref === 'function') {\n\t\tref(node)\n\t} else {\n\t\tref.current = node\n\t}\n}\n\nfunction cloneWithRef(element: any, newRef: any): ReactElement<any> {\n\tconst previousRef = element.ref\n\tinvariant(\n\t\ttypeof previousRef !== 'string',\n\t\t'Cannot connect React DnD to an element with an existing string ref. ' +\n\t\t\t'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' +\n\t\t\t'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs',\n\t)\n\n\tif (!previousRef) {\n\t\t// When there is no ref on the element, use the new ref directly\n\t\treturn cloneElement(element, {\n\t\t\tref: newRef,\n\t\t})\n\t} else {\n\t\treturn cloneElement(element, {\n\t\t\tref: (node: any) => {\n\t\t\t\tsetRef(previousRef, node)\n\t\t\t\tsetRef(newRef, node)\n\t\t\t},\n\t\t})\n\t}\n}\n"],"names":["invariant","cloneElement","isValidElement","throwIfCompositeComponentElement","element","type","displayName","name","Error","wrapHookToRecognizeElement","hook","elementOrNode","options","node","ref","cloneWithRef","wrapConnectorHooks","hooks","wrappedHooks","Object","keys","forEach","key","endsWith","wrappedHook","setRef","current","newRef","previousRef"],"mappings":"AAAA,SAASA,SAAS,QAAQ,sBAAsB,CAAA;AAEhD,SAASC,YAAY,EAAEC,cAAc,QAAQ,OAAO,CAAA;AAEpD,SAASC,gCAAgC,CAACC,OAA0B,EAAE;IACrE,uEAAuE;IACvE,mEAAmE;IACnE,IAAI,OAAOA,OAAO,CAACC,IAAI,KAAK,QAAQ,EAAE;QACrC,OAAM;KACN;IAED,MAAMC,WAAW,GAChB,AAACF,OAAO,CAACC,IAAI,CAASC,WAAW,IAAIF,OAAO,CAACC,IAAI,CAACE,IAAI,IAAI,eAAe;IAE1E,MAAM,IAAIC,KAAK,CACd,sEAAsE,GACrE,CAAC,oBAAoB,EAAEF,WAAW,CAAC,iCAAiC,CAAC,GACrE,sCAAsC,CACvC,CAAA;CACD;AAED,SAASG,0BAA0B,CAACC,IAAuC,EAAE;IAC5E,OAAO,CAACC,aAAa,GAAG,IAAI,EAAEC,OAAO,GAAG,IAAI,GAAK;QAChD,mDAAmD;QACnD,IAAI,CAACV,cAAc,CAACS,aAAa,CAAC,EAAE;YACnC,MAAME,IAAI,GAAGF,aAAa;YAC1BD,IAAI,CAACG,IAAI,EAAED,OAAO,CAAC;YACnB,uEAAuE;YACvE,kEAAkE;YAClE,OAAOC,IAAI,CAAA;SACX;QAED,wEAAwE;QACxE,0EAA0E;QAC1E,iCAAiC;QACjC,MAAMT,OAAO,GAAwBO,aAAa;QAClDR,gCAAgC,CAACC,OAAO,CAAQ;QAEhD,oDAAoD;QACpD,MAAMU,GAAG,GAAGF,OAAO,GAAG,CAACC,IAAa,GAAKH,IAAI,CAACG,IAAI,EAAED,OAAO,CAAC;QAAA,GAAGF,IAAI;QACnE,OAAOK,YAAY,CAACX,OAAO,EAAEU,GAAG,CAAC,CAAA;KACjC,CAAA;CACD;AAED,OAAO,SAASE,kBAAkB,CAACC,KAAU,EAAE;IAC9C,MAAMC,YAAY,GAAQ,EAAE;IAE5BC,MAAM,CAACC,IAAI,CAACH,KAAK,CAAC,CAACI,OAAO,CAAC,CAACC,GAAG,GAAK;QACnC,MAAMZ,IAAI,GAAGO,KAAK,CAACK,GAAG,CAAC;QAEvB,iEAAiE;QACjE,IAAIA,GAAG,CAACC,QAAQ,CAAC,KAAK,CAAC,EAAE;YACxBL,YAAY,CAACI,GAAG,CAAC,GAAGL,KAAK,CAACK,GAAG,CAAC;SAC9B,MAAM;YACN,MAAME,WAAW,GAAGf,0BAA0B,CAACC,IAAI,CAAC;YACpDQ,YAAY,CAACI,GAAG,CAAC,GAAG,IAAME,WAAW;YAAA;SACrC;KACD,CAAC;IAEF,OAAON,YAAY,CAAA;CACnB;AAED,SAASO,MAAM,CAACX,GAAQ,EAAED,IAAS,EAAE;IACpC,IAAI,OAALine truncated