Best JavaScript code snippet using playwright-internal
dragndrop.js
Source:dragndrop.js
1//@flow2import * as FsWriteActions from "../filesystem/write/fs-write-actions";3import _ from "lodash";4export function getFilePathArray(event: SyntheticDragEvent): Array<string> {5 return Object.keys(event.dataTransfer.files).map(6 key => event.dataTransfer.files[key].path7 );8}9/**10 * Copy or Moves (event modifier key) the files of the drag event11 * to the given Folder if possible12 */13export function executeFileDropOnDisk(14 event: SyntheticDragEvent,15 targetPath: string16): void {17 if (shouldAcceptDrop(event, [constants.TYPE_FILE])) {18 let pathArray = getFilePathArray(event);19 if (event.altKey) {20 FsWriteActions.copy(pathArray, targetPath);21 } else {22 FsWriteActions.move(pathArray, targetPath);23 }24 }25}26/**27 * Check if dataTransfer.types is in the given values28 * https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/types29 */30export function shouldAcceptDrop(31 event: SyntheticDragEvent,32 acceptableTypes: string | Array<string>33): boolean {34 if (typeof acceptableTypes == "string") {35 acceptableTypes = [acceptableTypes];36 }37 return _.intersection(event.dataTransfer.types, acceptableTypes).length > 0;38}39/**40 * Is the mouse cursor close to the upper or lower edge of the drop target41 */42function getCursorPosition(event: any): string {43 if (44 event.clientY - event.currentTarget.getBoundingClientRect().top >45 event.currentTarget.offsetHeight / 246 ) {47 return constants.CURSOR_POSITION_BOTTOM;48 } else {49 return constants.CURSOR_POSITION_TOP;50 }51}52/**53 * Drag & Drop events are anoying...54 * This function will return drag & drop listeners which will handle the anoying things55 * and then call the given callbacks in a clean way56 *57 * you have to event.preventDefault(); in the dragHover callback if you want to get drop58 * Or not, if you want to pass the drop to children (used by navbar-items)59 */60export function getEnhancedDropZoneListener(options: {61 acceptableTypes: string | Array<string>,62 possibleEffects: string,63 dragHover: (event: SyntheticDragEvent, cursorPosition: string) => void,64 dragOut: (event: SyntheticDragEvent) => void,65 drop: (event: SyntheticDragEvent, cursorPosition: string) => void66}): {67 onDragOver: Function,68 onDragLeave: Function,69 onDrop: Function70} {71 const {72 acceptableTypes,73 possibleEffects,74 dragHover,75 dragOut,76 drop77 } = options;78 return {79 onDragOver: (event: SyntheticDragEvent) => {80 if (shouldAcceptDrop(event, acceptableTypes)) {81 if (event.isDefaultPrevented()) {82 dragOut(event);83 return;84 }85 event.dataTransfer.dropEffect = getDropEffectByModifierKey(86 possibleEffects,87 event88 );89 const cursorPosition = getCursorPosition(event);90 dragHover(event, cursorPosition);91 }92 },93 onDragLeave: (event: any) => {94 const x = event.clientX,95 y = event.clientY,96 top = event.currentTarget.offsetTop,97 bottom = top + event.currentTarget.offsetHeight,98 left = event.currentTarget.offsetLeft,99 right = left + event.currentTarget.offsetWidth;100 if (y <= top || y >= bottom || x <= left || x >= right) {101 dragOut(event);102 }103 },104 onDrop: (event: SyntheticDragEvent) => {105 if (shouldAcceptDrop(event, acceptableTypes)) {106 dragOut(event);107 drop(event, getCursorPosition(event));108 }109 }110 };111}112/**113 * Drag & Drop events are anoying...114 * This function will return drag & drop listeners which will handle the anoying things115 * and then call the given callbacks in a clean way116 *117 * you have to event.preventDefault(); in the hoverEventProcessor callback if you want to get drop118 * Or not, if you want to pass the drop to children (used by navbar-items)119 */120export function getPerformantDropZoneListener(options: {121 acceptableTypes: string | Array<string>,122 possibleEffects: string, // see constants.effects123 // The EventProcess handels the event (preventDefault, stopPropagation etc.)124 // And can return a render callback wich is called with performance improvments125 hoverEventProcessor: (126 event: SyntheticDragEvent127 ) => (cursorPosition: string) => any,128 outEventProcessor: (event: SyntheticDragEvent) => () => any,129 drop: (event: SyntheticDragEvent, cursorPosition: string) => void130}): {131 onDragOver: Function,132 onDragLeave: Function,133 onDrop: Function134} {135 const {136 acceptableTypes,137 possibleEffects,138 hoverEventProcessor,139 outEventProcessor,140 drop141 } = options;142 const clear = event => {143 const outRender = outEventProcessor(event);144 enterTimeStamp = 0;145 if (outRender && hover) {146 hover = false;147 requestAnimationFrame(() => {148 if (hover == false) {149 // Check if still out, (maybe onDragOver way called since the requestAnimationFrame)150 outRender();151 }152 });153 }154 };155 let enterTimeStamp = 0;156 let hover = false;157 return {158 onDragOver: (event: SyntheticDragEvent) => {159 if (shouldAcceptDrop(event, acceptableTypes)) {160 if (event.isDefaultPrevented()) {161 // Child Element is catching the drop162 // call out to163 clear(event);164 return;165 }166 event.dataTransfer.dropEffect = getDropEffectByModifierKey(167 possibleEffects,168 event169 );170 const hoverRender = hoverEventProcessor(event);171 if (enterTimeStamp == 0) {172 // First Hover Event. Lets wait for the next events, before render173 enterTimeStamp = event.timeStamp;174 return;175 }176 if (hoverRender && enterTimeStamp + 25 < event.timeStamp) {177 // Waited long enough, lets render178 enterTimeStamp = event.timeStamp;179 hover = true;180 const cursorPosition = getCursorPosition(event);181 requestAnimationFrame(() => {182 if (hover) {183 // Check if still hover, (maybe onDragLeave way called since the requestAnimationFrame)184 hoverRender(cursorPosition);185 }186 });187 }188 }189 },190 onDragLeave: (event: any) => {191 const x = event.clientX,192 y = event.clientY,193 top = event.currentTarget.offsetTop,194 bottom = top + event.currentTarget.offsetHeight,195 left = event.currentTarget.offsetLeft,196 right = left + event.currentTarget.offsetWidth;197 if (y <= top || y >= bottom || x <= left || x >= right) {198 clear(event);199 }200 },201 onDrop: (event: SyntheticDragEvent) => {202 if (shouldAcceptDrop(event, acceptableTypes)) {203 clear(event);204 drop(event, getCursorPosition(event));205 }206 }207 };208}209export const constants = {210 TYPE_FILE: "Files",211 CURSOR_POSITION_TOP: "CURSOR_POSITION_TOP",212 CURSOR_POSITION_BOTTOM: "CURSOR_POSITION_BOTTOM",213 effects: {214 // https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/effectAllowed215 NONE: "none",216 COPY: "copy",217 COPY_LINK: "copyLink",218 COPY_MOVE: "copyMove",219 LINK: "link",220 LINK_MOVE: "linkMove",221 MOVE: "move",222 ALL: "all"223 }224};225/**226 * dragEvent: dropEffect by modifier key227 * https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer/dropEffect228 */229export function getDropEffectByModifierKey(230 possibleEffects: string,231 event: SyntheticDragEvent232) {233 const { effects } = constants;234 // Handle special electron issue235 // The only allowed effect for File Drags is allways COPY236 // https://github.com/electron/electron/issues/7207237 if (shouldAcceptDrop(event, [constants.TYPE_FILE])) {238 return effects.COPY;239 }240 switch (possibleEffects) {241 case effects.COPY:242 return effects.COPY;243 case effects.MOVE:244 return effects.MOVE;245 case effects.LINK:246 return effects.LINK;247 case effects.NONE:248 return effects.NONE;249 case effects.COPY_MOVE:250 return event.altKey ? effects.COPY : effects.MOVE;251 case effects.COPY_LINK:252 return event.altKey ? effects.COPY : effects.LINK;253 case effects.LINK_MOVE:254 return event.ctrlKey || event.metaKey ? effects.LINK : effects.MOVE;255 case effects.ALL:256 if (event.ctrlKey || event.metaKey) {257 return effects.LINK;258 } else if (event.altKey) {259 return effects.COPY;260 } else {261 return effects.MOVE;262 }263 default:264 throw "No Valid allowed-drop-effect";265 }...
DragDropProvider.js
Source:DragDropProvider.js
1// @flow2import React, { Component } from 'react'3type Props = {4 // all events5 cbDragDrop?: any,6 // standard events7 cbDragStart?: any,8 cbDrag?: any,9 cbDragEnd?: any,10 cbDragOver?: any,11 cbDragEnter?: any,12 cbDragLeave?: any,13 cbDrop?: any,14 // children15 children?: any,16};17type State = {}18type typeDrag = {19 dragid?: string,20}21class DragDropProvider extends Component<Props, State> {22 constructor(props) {23 super(props)24 this.onDragStart = this.onDragStart.bind(this)25 this.onDragEnd = this.onDragEnd.bind(this)26 this.onDragOver = this.onDragOver.bind(this)27 this.onDragEnter = this.onDragEnter.bind(this)28 this.onDragLeave = this.onDragLeave.bind(this)29 this.onDrop = this.onDrop.bind(this)30 this.onDrag = this.onDrag.bind(this)31 this.onAllEventDragDrop = this.onAllEventDragDrop.bind(this)32 this.currentDragElementId = null33 this.currentDropId = null34 }35 /**36 * All events in one method37 * @param {string} method38 * @param {string} eventElementId39 * @param {event} e40 */41 onAllEventDragDrop(method: string, eventElementId: string, e: SyntheticDragEvent<*>): void {42 const {cbDragDrop} = this.props43 if (cbDragDrop) {44 cbDragDrop(method, eventElementId, e, this.currentDragElementId)45 }46 }47 onDragStart(e: SyntheticDragEvent<HTMLElement>) {48 const {cbDragStart} = this.props49 const dataset: typeDrag = e.currentTarget.dataset50 e.dataTransfer.effectAllowed = 'move'51 if (dataset && dataset.dragid) {52 this.currentDragElementId = dataset.dragid53 this.currentMethod = 'DragStart'54 if (cbDragStart) {55 cbDragStart(this.currentMethod, this.currentDragElementId, e)56 }57 this.onAllEventDragDrop(this.currentMethod, this.currentDragElementId, e)58 } else {59 this.currentDragElementId = null60 }61 }62 onDragEnd(e: SyntheticDragEvent<HTMLElement>) {63 const {cbDragEnd} = this.props64 const dataset: typeDrag = e.currentTarget.dataset65 if (dataset && dataset.dragid) {66 this.currentMethod = 'DragEnd'67 if (cbDragEnd) {68 cbDragEnd(this.currentMethod, dataset.dragid, e, this.currentDragElementId)69 }70 this.onAllEventDragDrop(this.currentMethod, dataset.dragid, e)71 }72 this.currentDragElementId = null73 this.currentDropId = null74 }75 /**76 * On Drag over77 * @param {SyntheticDragEvent<*>} e78 */79 onDragOver(e: SyntheticDragEvent<*>) {80 const {cbDragOver} = this.props81 const dataset: typeDrag = e.currentTarget.dataset82 e.preventDefault()83 if (dataset && dataset.dragid) {84 this.currentMethod = 'DragOver'85 if (dataset.dragid) {86 if (cbDragOver) {87 cbDragOver(this.currentMethod, dataset.dragid, e, this.currentDragElementId)88 }89 this.onAllEventDragDrop(this.currentMethod, dataset.dragid, e)90 }91 this.currentDropId = dataset.dragid92 }93 }94 /**95 * On Drag enter96 * @param {SyntheticDragEvent<*>} e97 */98 onDragEnter(e: SyntheticDragEvent<*>) {99 const {cbDragEnter} = this.props100 const dataset: typeDrag = e.currentTarget.dataset101 e.preventDefault()102 if (dataset && dataset.dragid) {103 this.currentMethod = 'DragEnter'104 this.currentDropId = dataset.dragid105 if (cbDragEnter) {106 cbDragEnter(this.currentMethod, dataset.dragid, e, this.currentDragElementId)107 }108 this.onAllEventDragDrop(this.currentMethod, dataset.dragid, e)109 }110 }111 /**112 * On Drag leave113 * @param {SyntheticDragEvent<*>} e114 */115 onDragLeave(e: SyntheticDragEvent<*>) {116 const {cbDragLeave} = this.props117 const dataset: typeDrag = e.currentTarget.dataset118 e.preventDefault()119 if (dataset && dataset.dragid) {120 this.currentMethod = 'DragLeave'121 this.currentDropId = dataset.dragid122 if (cbDragLeave && dataset.dragid) {123 cbDragLeave(this.currentMethod, dataset.dragid, e, this.currentDragElementId)124 }125 this.onAllEventDragDrop(this.currentMethod, dataset.dragid, e)126 }127 }128 /**129 * On Drop130 * @param {SyntheticDragEvent<*>} e131 */132 onDrop(e: SyntheticDragEvent<*>) {133 const {cbDrop} = this.props134 const dataset: typeDrag = e.currentTarget.dataset135 if (dataset && dataset.dragid) {136 this.currentMethod = 'Drop'137 if (cbDrop && dataset.dragid) {138 cbDrop(this.currentMethod, dataset.dragid, e, this.currentDragElementId)139 }140 this.onAllEventDragDrop(this.currentMethod, dataset.dragid, e)141 }142 }143 /**144 * On Drag145 * @param {SyntheticDragEvent<*>} e146 */147 onDrag(e: SyntheticDragEvent<*>) {148 const {cbDrag} = this.props149 const dataset: typeDrag = e.currentTarget.dataset150 if (dataset && dataset.dragid) {151 this.currentMethod = 'Drag'152 if (cbDrag && dataset.dragid) {153 cbDrag(this.currentMethod, dataset.dragid, e, this.currentDragElementId)154 }155 this.onAllEventDragDrop(this.currentMethod, dataset.dragid, e)156 }157 }158 render() {159 const {children} = this.props160 return (161 <div>162 {children}163 </div>164 )165 }166}...
DragAndDropContext.js
Source:DragAndDropContext.js
1// @flow2'use strict';3import {Utils} from "../../core";4import SyntheticDragEvent from 'react-dom/lib/SyntheticDragEvent';5import DragAndDropItem from "./DragAndDropItem";6/** * @param {DragAndDropItem} item */7let item: ?DragAndDropItem;8export default class DragAndDropContext {9 constructor() {10 Object.preventExtensions(this);11 }12 /**13 *14 * @param {DragAndDropItem} _item15 */16 static setCurrent(_item) {17 item = _item;18 }19 /**20 *21 * @param {DragAndDropItem}item22 * @param {number}index23 */24 onMoved(item: DragAndDropItem, index: number) {25 alert("Przenioesiono " + Utils.toString(item) + " na pozycjÄ " + index);26 }27 getItemIndex(element: HTMLElement) {28 // $FlowFixMe29 const children: NodeList = element.parentNode.children;30 for (let i = 0; i < children.length; i++)31 if (children[i] === element)32 return i;33 return null;34 }35 setStatus(text: string, timeout: ?number = null) {36 // new Notify(this, "info", text, timeout).send();37 }38 dragEnd(e: SyntheticDragEvent, drop: boolean) {39 if (!item || !e) return;40 if (!item.placeholder || !item.placeholder.parentNode)41 return;42 if (drop) {43 const index = this.getItemIndex(item.placeholder);44 if (index == null)45 throw new Error("Item not found");46 this.onMoved(item, index);47 }48 item.placeholder.parentNode.removeChild(item.placeholder);49 this.setStatus("");50 }51 /*52 ondrag:53 ondragend54 ondragenter55 ondragleave56 ondragover57 ondragstart58 ondrop59 null60 */61 /**62 *63 * @param {DragAndDrop} item64 * @param {SyntheticDragEvent} e65 */66 dragOver(e: SyntheticDragEvent) {67 if (!item || !e) return;68 item.dstContext = this;69 e.preventDefault(); // zezwól na przetwarzanie70 const curr = e.currentTarget;71 if (curr === item.element)72 return;73 let next = curr.nextSibling;74 while (next && next === item.placeholder)75 next = item.placeholder.nextSibling;76 let before = ( e.clientY - curr.offsetTop) - (curr.clientHeight / 2) > 0;77 if (item.placeholder.parentNode)78 item.placeholder.parentNode.removeChild(item.placeholder);79 if (!next)80 curr.parentNode.appendChild(item.placeholder);81 else if (before)82 next.parentNode.insertBefore(item.placeholder, next);83 else84 next.parentNode.insertBefore(item.placeholder, curr);85 //this.setStatus(`PrzeciÄ
gam "${this.getItemName(this.srcItem) || ""}" za "${this.getItemName(item) || ""}"`);86 }87 createPlaceholder(item: DragAndDropItem, e: SyntheticDragEvent) {88 const div: HTMLElement = document.createElement("div");89 // $FlowFixMe90 div.textContent = this.getItemName(item);91 div.style.padding = "4px 8px";92 div.style.border = "2px dashed red";93 div.style.textAlign = "center";94 const dnd = this;95 // $FlowFixMe96 div.ondragover = (e) => {97 e.preventDefault(); // zezwól na przetwarzanie98 }99 // $FlowFixMe100 div.dragdrop = (e) => {101 dnd.dragEnd(e, true);102 }103 return div;104 }105 getItemName(item: DragAndDropItem) {106 if (item && typeof item.toString === "function")107 return item.toString();108 return null;109 }110}111document.addEventListener("dragend", (e: SyntheticDragEvent) => {112 "use strict";113 setTimeout(() => {114 if (item && item.srcContext)115 item.srcContext.dragEnd(e, false);116 if (item && item.dstContext && item.dstContext !== item.srcContext)117 item.dstContext.dragEnd(e, false);118 item = null;119 }, 1);...
types.js
Source:types.js
1/*2Copyright (c) 2018-2020 Uber Technologies, Inc.3This source code is licensed under the MIT license found in the4LICENSE file in the root directory of this source tree.5*/6// @flow7import type {OverrideT} from '../helpers/overrides.js';8export type StylePropsT = {|9 $afterFileDrop: boolean,10 $isDisabled: boolean,11 $isDragActive: boolean,12 $isDragAccept: boolean,13 $isDragReject: boolean,14 $isFocused: boolean,15|};16export type OverridesT = {|17 Root?: OverrideT,18 FileDragAndDrop?: OverrideT,19 ContentMessage?: OverrideT,20 ContentSeparator?: OverrideT,21 HiddenInput?: OverrideT,22 ProgressMessage?: OverrideT,23 ErrorMessage?: OverrideT,24 ButtonComponent?: OverrideT,25 Spinner?: OverrideT,26|};27export type PropsT = {|28 // react-dropzone: https://github.com/react-dropzone/react-dropzone/blob/master/typings/react-dropzone.d.ts29 accept?: string | string[],30 /** Disallow clicking on the dropzone container to open file dialog */31 disableClick?: boolean,32 disabled?: boolean,33 getDataTransferItems?: GetDataTransferItemsT,34 maxSize?: number,35 minSize?: number,36 multiple?: boolean,37 name?: string,38 onClick?: (event: SyntheticMouseEvent<HTMLElement>) => mixed,39 onFocus?: (event: SyntheticFocusEvent<HTMLElement>) => mixed,40 onBlur?: (event: SyntheticFocusEvent<HTMLElement>) => mixed,41 onKeyDown?: (event: SyntheticKeyboardEvent<HTMLElement>) => mixed,42 onDragStart?: (event: SyntheticDragEvent<HTMLElement>) => mixed,43 onDragEnter?: (event: SyntheticDragEvent<HTMLElement>) => mixed,44 onDragOver?: (event: SyntheticDragEvent<HTMLElement>) => mixed,45 onDragLeave?: (event: SyntheticDragEvent<HTMLElement>) => mixed,46 onDrop?: DropFilesEventHandlerT,47 onDropAccepted?: DropFileEventHandlerT,48 onDropRejected?: DropFileEventHandlerT,49 onFileDialogCancel?: () => mixed,50 preventDropOnDocument?: boolean,51 'aria-describedby'?: string,52 // Error message to be displayed53 errorMessage?: string,54 onCancel?: () => mixed,55 onRetry?: () => mixed,56 overrides?: OverridesT,57 progressAmount?: number,58 progressMessage?: string,59|};60export type DropFilesEventHandlerT = (61 accepted: File[],62 rejected: File[],63 event: SyntheticDragEvent<HTMLElement>,64) => mixed;65type DropFileEventHandlerT = (66 acceptedOrRejected: File[],67 event: SyntheticDragEvent<HTMLElement>,68) => mixed;69type DataTransferEventT =70 | SyntheticDragEvent<HTMLElement>71 | SyntheticInputEvent<HTMLInputElement>72 | SyntheticDragEvent<*>73 | SyntheticEvent<*>;74type GetDataTransferItemsT = (75 event: DataTransferEventT,...
test_react-dropzone_v4.x.x.js
Source:test_react-dropzone_v4.x.x.js
1import React from "react";2import Dropzone, { type ChildrenProps, type DropzoneFile } from "react-dropzone";3<Dropzone />;4<Dropzone>5 <div />6</Dropzone>;7<Dropzone8 accept="image/jpeg, image/png, application/pdf"9 disableClick={true}10 disabled={true}11 disablePreview={true}12 preventDropOnDocument={true}13 inputProps={{ className: "input-class" }}14 multiple={true}15 name="name"16 maxSize={1000}17 minSize={100}18 className="className"19 activeClassName="active"20 acceptClassName="accept"21 rejectClassName="reject"22 disabledClassName="disabled"23 style={{ height: '50px' }}24 activeStyle={{ height: '60px' }}25 acceptStyle={{ height: '70px' }}26 rejectStyle={{ height: '80px' }}27 disabledStyle={{ height: '90px' }}28 onClick={(event: SyntheticMouseEvent<>) => {}}29 onDrop={(acceptedFiles: Array<DropzoneFile>, rejectedFiles: Array<DropzoneFile>, event: SyntheticDragEvent<>) => {}}30 onDropAccepted={(acceptedFiles: Array<DropzoneFile>, event: SyntheticDragEvent<>) => {}}31 onDropRejected={(rejectedFiles: Array<DropzoneFile>, event: SyntheticDragEvent<>) => {}}32 onDragStart={(event: SyntheticDragEvent<>) => {}}33 onDragEnter={(event: SyntheticDragEvent<>) => {}}34 onDragOver={(event: SyntheticDragEvent<>) => {}}35 onDragLeave={(event: SyntheticDragEvent<>) => {}}36 onFileDialogCancel={() => {}}37 ref={(ref: ?Dropzone) => {38 if (ref) ref.open();39 }}40>41 {42 ({43 draggedFiles,44 acceptedFiles,45 rejectedFiles,46 isDragActive,47 isDragAccept,48 isDragReject,49 }: ChildrenProps) => (50 <div />51 )52 }53</Dropzone>;54<Dropzone55 accept="image/jpeg, image/png, application/pdf"56 onClick={() => {}}57 onDrop={(acceptedFiles: Array<DropzoneFile>) => {}}58 onDropAccepted={(acceptedFiles: Array<DropzoneFile>) => {}}59 onDropRejected={(rejectedFiles: Array<DropzoneFile>) => {}}60 onDragStart={() => {}}61 onDragEnter={() => {}}62 onDragOver={() => {}}63 onDragLeave={() => {}}64>65 {66 ({67 isDragActive,68 }: { isDragActive: boolean, ... }) => (69 <div />70 )71 }72</Dropzone>;73// $FlowExpectedError - Wrong type for function handler74<Dropzone onDrop={(event: SyntheticDragEvent<>) => {}} />;75<Dropzone>76 {77 ({78 acceptedFiles,79 // $FlowExpectedError - Wrong type for children function80 }: { acceptedFiles: Array<string> }) => (81 <div />82 )83 }84</Dropzone>;85<Dropzone>86 {87 // $FlowExpectedError - Wrong return type for children function88 () => ({})89 }...
react-dropzone_v4.x.x.js
Source:react-dropzone_v4.x.x.js
1// flow-typed signature: b7af14fb84f1e89e79e941a6bcd03d152// flow-typed version: 80022b0008/react-dropzone_v4.x.x/flow_>=v0.53.x3declare module "react-dropzone" {4 declare type ChildrenProps = {5 draggedFiles: Array<File>,6 acceptedFiles: Array<File>,7 rejectedFiles: Array<File>,8 isDragActive: boolean,9 isDragAccept: boolean,10 isDragReject: boolean,11 }12 declare type DropzoneFile = File & {13 preview?: string;14 }15 declare type DropzoneProps = {16 accept?: string,17 children?: React$Node | (ChildrenProps) => React$Node,18 disableClick?: boolean,19 disabled?: boolean,20 disablePreview?: boolean,21 preventDropOnDocument?: boolean,22 inputProps?: Object,23 multiple?: boolean,24 name?: string,25 maxSize?: number,26 minSize?: number,27 className?: string,28 activeClassName?: string,29 acceptClassName?: string,30 rejectClassName?: string,31 disabledClassName?: string,32 style?: Object,33 activeStyle?: Object,34 acceptStyle?: Object,35 rejectStyle?: Object,36 disabledStyle?: Object,37 onClick?: (event: SyntheticMouseEvent<>) => mixed,38 onDrop?: (acceptedFiles: Array<DropzoneFile>, rejectedFiles: Array<DropzoneFile>, event: SyntheticDragEvent<>) => mixed,39 onDropAccepted?: (acceptedFiles: Array<DropzoneFile>, event: SyntheticDragEvent<>) => mixed,40 onDropRejected?: (rejectedFiles: Array<DropzoneFile>, event: SyntheticDragEvent<>) => mixed,41 onDragStart?: (event: SyntheticDragEvent<>) => mixed,42 onDragEnter?: (event: SyntheticDragEvent<>) => mixed,43 onDragOver?: (event: SyntheticDragEvent<>) => mixed,44 onDragLeave?: (event: SyntheticDragEvent<>) => mixed,45 onFileDialogCancel?: () => mixed,46 };47 declare class Dropzone extends React$Component<DropzoneProps> {48 open(): void;49 }50 declare module.exports: typeof Dropzone;...
DragAndDropItem.js
Source:DragAndDropItem.js
1// @flow2'use strict';3import SyntheticDragEvent from 'react-dom/lib/SyntheticDragEvent';4import DragAndDropContext from "./DragAndDropContext";5export default class DragAndDropItem {6 srcContext: DragAndDropContext;7 dstContext: ?DragAndDropContext = null;8 item: any;9 element: HTMLElement;10 itemIndex: number;11 placeholder: HTMLElement;12 dataTransfer: DataTransfer;13 /**14 *15 * @param {DragAndDropContext} context16 * @param item17 * @param {number} itemIndex18 * @param {SyntheticDragEvent} e19 */20 constructor(context: DragAndDropContext, item: any, itemIndex: number, e: SyntheticDragEvent) {21 "use strict";22 this.srcContext = context;23 this.item = item;24 this.element = e.currentTarget;25 this.itemIndex = itemIndex;26 this.placeholder = context.createPlaceholder(item, e);27 this.dataTransfer = e.dataTransfer;28 DragAndDropContext.setCurrent(this);29 Object.preventExtensions(this);30 context.setStatus(`Rozpoczynam przeciÄ
ganie "${context.getItemName(item) || ""}"`);31 e.dataTransfer.effectAllowed = 'move';32 e.dataTransfer.setData("text", "");33 }34 toString() {35 return this.srcContext.getItemName(this.item);36 }...
SyntheticDragEvent.js
Source:SyntheticDragEvent.js
...22 * @param {string} dispatchMarker Marker identifying the event target.23 * @param {object} nativeEvent Native browser event.24 * @extends {SyntheticUIEvent}25 */26function SyntheticDragEvent(dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget) {27 return SyntheticMouseEvent.call(this, dispatchConfig, dispatchMarker, nativeEvent, nativeEventTarget);28}29SyntheticMouseEvent.augmentClass(SyntheticDragEvent, DragEventInterface);...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.mouse.move(100, 100);7 await page.mouse.down();8 await page.mouse.move(200, 200);9 await page.mouse.up();10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const context = await browser.newContext();16 const page = await context.newPage();17 await page.mouse.move(100, 100);18 await page.mouse.down();19 await page.mouse.move(200, 200);20 await page.mouse.up();21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const context = await browser.newContext();27 const page = await context.newPage();28 await page.mouse.move(100, 100);29 await page.mouse.down();30 await page.mouse.move(200, 200);31 await page.mouse.up();32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const context = await browser.newContext();38 const page = await context.newPage();39 await page.mouse.move(100, 100);40 await page.mouse.down();41 await page.mouse.move(200, 200);42 await page.mouse.up();43 await browser.close();44})();45const { chromium } = require('playwright');46(async () => {47 const browser = await chromium.launch();48 const context = await browser.newContext();49 const page = await context.newPage();
Using AI Code Generation
1const { chromium } = require('playwright');2const { SyntheticDragEvent } = require('playwright/lib/internal/syntheticEvents');3(async () => {4 const browser = await chromium.launch({ headless: false });5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.waitForSelector('text=Drag me');8 const element = await page.$('text=Drag me');9 await element.dispatchEvent(new SyntheticDragEvent('dragstart'));10 await element.dispatchEvent(new SyntheticDragEvent('dragend'));11 await page.waitForTimeout(5000);12 await browser.close();13})();14const { chromium } = require('playwright');15const { SyntheticDragEvent } = require('playwright/lib/internal/syntheticEvents');16(async () => {17 const browser = await chromium.launch({ headless: false });18 const context = await browser.newContext();19 const page = await context.newPage();20 await page.waitForSelector('text=Drag me');21 const element = await page.$('text=Drag me');22 await element.dispatchEvent(new SyntheticDragEvent('dragstart'));23 await element.dispatchEvent(new SyntheticDragEvent('dragend'));24 await page.waitForTimeout(5000);25 await browser.close();26})();27const { chromium } = require('playwright');28const { SyntheticDragEvent } = require('playwright/lib/internal/syntheticEvents');29(async () => {30 const browser = await chromium.launch({ headless: false });31 const context = await browser.newContext();32 const page = await context.newPage();33 await page.waitForSelector('text=Drag me');34 const element = await page.$('text=Drag me');35 await element.dispatchEvent(new SyntheticDragEvent('dragstart'));36 await element.dispatchEvent(new SyntheticDragEvent('dragend'));37 await page.waitForTimeout(5000);38 await browser.close();39})();40const { chromium } = require('playwright');41const { SyntheticDragEvent } = require('playwright/lib/internal
Using AI Code Generation
1const { SyntheticDragEvent } = require('playwright/lib/server/syntheticEvents');2const { dragAndDrop } = require('playwright/lib/server/syntheticDrag');3const { ElementHandle } = require('playwright/lib/server/dom');4const { Frame } = require('playwright/lib/server/frame');5const { Page } = require('playwright/lib/server/page');6const { BrowserContext } = require('playwright/lib/server/browserContext');7const { Browser } = require('playwright/lib/server/browser');8const { helper } = require('playwright/lib/server/helper');9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch({ headless: false });12 const context = await browser.newContext();13 const page = await context.newPage();14 await page.waitForTimeout(1000);15 const frame = page.frames()[1];16 const dragSource = await frame.$('#drag1');17 const dragTarget = await frame.$('#div2');18 await dragAndDrop(page, dragSource, dragTarget);19 await page.waitForTimeout(5000);20 await browser.close();21})();22const { SyntheticDragEvent } = require('./syntheticEvents');23const { ElementHandle } = require('../server/dom');24const { Frame } = require('../server/frame');25const { Page } = require('../server/page');26const { helper } = require('../server/helper');27 * @param {!Page} page28 * @param {!ElementHandle} source29 * @param {!ElementHandle} target30module.exports.dragAndDrop = async function(page, source, target) {31 await page._delegate.dragAndDrop(source, target);32};33const { helper } = require('./helper');34const { ElementHandle } = require('./dom');35const { Frame } = require('./frame');36const { Page } = require('./page');37const { SyntheticDragEvent } = require('./syntheticEvents');38 * @param {!ElementHandle} source39 * @param {!ElementHandle} target40Page.prototype.dragAndDrop = async function(source, target)
Using AI Code Generation
1const { SyntheticDragEvent } = require('playwright-1.17.1/lib/server/syntheticEvents');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.waitForSelector('#iframeResult');7 const [frame] = await page.$$('iframe');8 const element = await frame.$('#drag1');9 const target = await frame.$('#div1');10 await element.dispatchEvent(new SyntheticDragEvent('dragstart'));11 await target.dispatchEvent(new SyntheticDragEvent('dragenter'));12 await target.dispatchEvent(new SyntheticDragEvent('dragover'));13 await target.dispatchEvent(new SyntheticDragEvent('drop'));14 await element.dispatchEvent(new SyntheticDragEvent('dragend'));15 await browser.close();16})();17const { SyntheticDragEvent } = require('playwright/lib/server/syntheticEvents');18const { SyntheticDragEvent } = require('playwright-1.17.1/lib/server/syntheticEvents');19const { SyntheticDragEvent } = require('playwright/lib/server/syntheticEvents');20const { SyntheticDragEvent } = require('playwright-1.17.1/lib/server/syntheticEvents');21const { SyntheticDragEvent } = require('playwright/lib/server/syntheticEvents');
Using AI Code Generation
1const { test, expect } = require('@playwright/test');2const { SyntheticDragEvent } = require('playwright/lib/internal/syntheticEvents');3const { parseSelector } = require('playwright/lib/internal/selectorParser');4const { parseSelector } = require('playwright/lib/internal/selectorParser');5const { parseSelector } = require('playwright/lib/internal/selectorParser');6test('Drag and Drop', async ({ page }) => {7 const [source, target] = await Promise.all([8 page.$('#drag1'),9 page.$('#div2'),10 ]);11 await source.dispatchEvent(12 new SyntheticDragEvent('dragstart', {13 dataTransfer: { files: [] },14 })15 );16 await target.dispatchEvent(17 new SyntheticDragEvent('drop', {18 dataTransfer: { files: [] },19 })20 );21 await target.dispatchEvent(22 new SyntheticDragEvent('dragend', {23 dataTransfer: { files: [] },24 })25 );26});27import { test, expect } from '@play
Using AI Code Generation
1const { SyntheticDragEvent } = require('playwright/lib/internal/protocol/protocol');2const event = new SyntheticDragEvent({x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});3await page.dispatchEvent(event);4await page.dispatchEvent({type: 'dragstart', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});5await page.dispatchEvent({type: 'drop', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});6await page.dispatchEvent({type: 'dragstart', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});7await page.dispatchEvent({type: 'drop', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});8await page.dispatchEvent({type: 'dragstart', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});9await page.dispatchEvent({type: 'drop', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});10await page.dispatchEvent({type: 'dragstart', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});11await page.dispatchEvent({type: 'drop', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});12await page.dispatchEvent({type: 'dragstart', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file2']}});13await page.dispatchEvent({type: 'drop', x: 100, y: 100, modifiers: 0, dataTransfer: {files: ['file1', 'file
Using AI Code Generation
1const { SyntheticDragEvent } = require("playwright/lib/server/supplements/recorder/frames");2const drag = new SyntheticDragEvent();3await drag.init(page, 'div');4await drag.dispatch('dragstart', 0, 0);5await drag.dispatch('drag', 100, 0);6await drag.dispatch('drop', 100, 0);7await page.mouse.move(50, 50);8await page.mouse.down();9await page.mouse.move(100, 100);10await page.mouse.up();11await page.mouse.move(50, 50);12await page.mouse.down();13await page.mouse.move(100, 100);14await page.mouse.up();15await page.evaluate(() => {16 const element = document.querySelector('div');17 const rect = element.getBoundingClientRect();18 element.dispatchEvent(new MouseEvent('mousedown', { clientX: rect.left, clientY: rect.top }));19 element.dispatchEvent(new MouseEvent('mousemove', { clientX: rect.left + 100, clientY: rect.top + 100 }));20 element.dispatchEvent(new MouseEvent('mouseup', { clientX: rect.left + 100, clientY: rect.top + 100 }));21});22Error: Protocol error (DOM.dispatchEvent): Cannot find context with specified id
Using AI Code Generation
1const drag = require('playwright/lib/webkit/webkit');2const dragEvent = drag.syntheticDragEvent;3const dropEvent = drag.syntheticDropEvent;4const dragData = drag.syntheticDragData;5const dragEnterEvent = dragEvent('dragenter', {6 dataTransfer: dragData({7 { kind: 'string', type: 'text/plain', data: 'test' },8 }),9});10const dropEvent = dropEvent('drop', {11 dataTransfer: dragData({12 { kind: 'string', type: 'text/plain', data: 'test' },13 }),14});15await page.dispatchEvent('#target', dragEnterEvent);16await page.dispatchEvent('#target', dropEvent);17await page.dispatchEvent('#target', [dragEnterEvent, dropEvent]);18await page.dispatchEvent('#target', [dragEnterEvent, dropEvent], 1000);19await page.dispatchEvent('#target', [dragEnterEvent, dropEvent], 1000, { x: 100, y: 100 });20await page.dispatchEvent('#target', [dragEnterEvent, dropEvent], 1000, { x: 100, y: 100 });21const dragEnterEvent = dragEvent('dragenter', {22 dataTransfer: dragData({23 { kind: 'string', type: 'text/plain', data: 'test' },24 }),25}, { x: 100, y: 100 });26const dropEvent = dropEvent('drop', {27 dataTransfer: dragData({28 { kind: 'string', type: 'text/plain', data: 'test' },29 }),30}, { x: 100, y: 100 });31await page.dispatchEvent('#target', dragEnterEvent);32await page.dispatchEvent('#target', dropEvent);
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!