-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress towards triggering drag programmatically.
- Loading branch information
1 parent
e7c2206
commit c87be25
Showing
11 changed files
with
167 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#plugin-attribute-drag { | ||
background-color: red; | ||
height: 50px; | ||
position: absolute; | ||
top: 0px; | ||
width: 50px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from "react" | ||
import { useDraggableAttribute } from "../../hooks/use-drag-drop" | ||
import { uiState } from "../../models/ui-state" | ||
import { getDataSetFromId } from "../../models/shared/shared-data-utils" | ||
import { appState } from "../../models/app-state" | ||
|
||
import "./plugin-attribute-drag.scss" | ||
|
||
export function PluginAttributeDrag() { | ||
const dataSet = getDataSetFromId(appState.document, uiState.draggingDatasetId) | ||
const { attributes, listeners, setNodeRef } = useDraggableAttribute({ | ||
attributeId: uiState.draggingAttributeId, | ||
dataSet, | ||
prefix: "plugin" | ||
}) | ||
return ( | ||
<div | ||
id="plugin-attribute-drag" | ||
ref={setNodeRef} | ||
{...attributes} | ||
{...listeners} | ||
/> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,42 @@ | ||
// import { PointerEventHandlers, SensorProps } from "@dnd-kit/core" | ||
// import { AbstractPointerSensor, AbstractPointerSensorOptions } from "@dnd-kit/core/dist/sensors" | ||
// import { getOwnerDocument } from "@dnd-kit/utilities" | ||
|
||
// const events: PointerEventHandlers = { | ||
// move: { name: "pointermove" }, | ||
// end: { name: "pointerup" }, | ||
// } | ||
|
||
// export interface PluginSensorOptions extends AbstractPointerSensorOptions {} | ||
|
||
// export type PluginSensorProps = SensorProps<PluginSensorOptions>; | ||
|
||
// export class PluginSensor extends AbstractPointerSensor { | ||
// constructor(props: PluginSensorProps) { | ||
// const { event } = props | ||
// // Pointer events stop firing if the target is unmounted while dragging | ||
// // Therefore we attach listeners to the owner document instead | ||
// const listenerTarget = getOwnerDocument(event.target) | ||
|
||
// super(props, events, listenerTarget) | ||
// } | ||
|
||
// static activators = [ | ||
// { | ||
// eventName: 'onPointerDown' as const, | ||
// handler: ( | ||
// event: Event, | ||
// { onActivation }: PluginSensorOptions | ||
// ) => { | ||
// // if (!event.isPrimary || event.button !== 0) { | ||
// // return false | ||
// // } | ||
|
||
// onActivation?.({ event }) | ||
|
||
// return true | ||
// }, | ||
// }, | ||
// ]; | ||
// } | ||
import { AbstractPointerSensor, AbstractPointerSensorOptions, PointerEventHandlers, SensorProps } from "@dnd-kit/core" | ||
// import { SyntheticEventName } from "@dnd-kit/core/dist/types"; | ||
import { getOwnerDocument } from "@dnd-kit/utilities" | ||
|
||
const events: PointerEventHandlers = { | ||
move: { name: "pointermove" }, | ||
end: { name: "pointerup" }, | ||
} | ||
|
||
export interface PluginSensorOptions extends AbstractPointerSensorOptions {} | ||
|
||
export type PluginSensorProps = SensorProps<PluginSensorOptions>; | ||
|
||
export class PluginSensor extends AbstractPointerSensor { | ||
constructor(props: PluginSensorProps) { | ||
const { event } = props | ||
// Pointer events stop firing if the target is unmounted while dragging | ||
// Therefore we attach listeners to the owner document instead | ||
const listenerTarget = getOwnerDocument(event.target) | ||
|
||
super(props, events, listenerTarget) | ||
} | ||
|
||
static activators = [ | ||
{ | ||
eventName: 'onDragStart' as const, | ||
handler: ( | ||
event: Event, | ||
{ onActivation }: PluginSensorOptions | ||
) => { | ||
// if (!event || event.button !== 0) { | ||
// return false | ||
// } | ||
|
||
onActivation?.({ event }) | ||
|
||
console.log(`--- starting drag`) | ||
return true | ||
}, | ||
} | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters