Git Product home page Git Product logo

Comments (16)

bzbarsky avatar bzbarsky commented on July 20, 2024 1

I should also add that the example in the spec at https://w3c.github.io/clipboard-apis/#clipboard-event-interfaces says:

var pasteEvent = new ClipboardEvent('paste');
pasteEvent.clipboardData.items.add('My string', 'text/plain');

which would throw if the spec were actually implemented as currently written...

from clipboard-apis.

garykac avatar garykac commented on July 20, 2024 1

We have a need for a DataTransfer constructor for the async Clipboard API.

For this use case, the DataTransfer would be created with an empty drag-data-store and with Read/Write access. Items would be added into the store after the DataTransfer was created.

[1] Clipboard API proposal: https://github.com/garykac/clipboard/blob/master/clipboard.md
[2] Async Clipboard API: https://w3c.github.io/clipboard-apis/#clipboard-interface

from clipboard-apis.

bzbarsky avatar bzbarsky commented on July 20, 2024

Looks like what Firefox ships is what was defined in https://www.w3.org/TR/2015/WD-clipboard-apis-20150421/ and then it got changed to the current thing by the time https://www.w3.org/TR/2015/WD-clipboard-apis-20151215/ got published.

from clipboard-apis.

RByers avatar RByers commented on July 20, 2024

Thanks for raising this Boris. A common use case for Event constructors is to clone / wrap an event with a few changes (eg. I see event delegation libraries do this sometimes). That use case would still be possible with this as spec'd today, right?

In general I think DOM folks (@annevk, @smaug---- IIRC) have said we want event constructors to follow a pretty rigid pattern of just taking the Event attributes directly and not having any smarts / conversions. If we agree to that pattern then I suggest we proceed with shipping the constructor as speced now in blink, and explore adding ways to create DataTransfer objects (possibly low priority though). WDYT?

from clipboard-apis.

bzbarsky avatar bzbarsky commented on July 20, 2024

That use case would still be possible, right?

That's correct.

The rest of the questions are probably better directed at @smaug----

from clipboard-apis.

RByers avatar RByers commented on July 20, 2024

The rest of the questions are probably better directed at @smaug----

Thanks. Let me know if you think this issue should delay blink shipping the ClipboardEvent constructor though. There's no real urgency there except that we're doing a systematic pass at fixing lots of minor spec conformance issues to enable some tooling that auto-flags spec conformance issues.

from clipboard-apis.

bzbarsky avatar bzbarsky commented on July 20, 2024

The real question is whether there are sites depending on the Firefox behavior. I'd expect not, so shipping this in Blink is probably fine. We should just define some constructor bits for DataTransfer to make this all sane. @annevk @domenic

from clipboard-apis.

foolip avatar foolip commented on July 20, 2024

The weirdness with DataTransfer was previously discussed in #10 and it ended up looking like DragEvent, which also has a pretty useless constructor.

A DataTransfer constructor would be useful for tests of ClipboardEvent and DragEvent, I agree.

+@LoonyBean

from clipboard-apis.

smaug---- avatar smaug---- commented on July 20, 2024

I agree that DataTransfer having a ctor could be useful for testing. And even without that passing dataTransfer from trusted drag event to clipboard event might simplify some scripts.

from clipboard-apis.

domenic avatar domenic commented on July 20, 2024

@smaug---- can you help explain how such a constructor would work, over in whatwg/html#2190 ?

from clipboard-apis.

smaug---- avatar smaug---- commented on July 20, 2024

Not sure what to explain there. While handling some dnd event, one may want to dispatch untrusted clipboard event (and initialize the dataTransfer using the object from dnd).

from clipboard-apis.

domenic avatar domenic commented on July 20, 2024

@smaug---- how do you initialize the DataTransfer object "using the object from the dnd"? If we are talking about the same "object", then that object is a spec abstract data structure (the "drag data store"), and there's no way to copy it over.

from clipboard-apis.

smaug---- avatar smaug---- commented on July 20, 2024

There is no copying. DragEvents have
readonly attribute DataTransfer? dataTransfer;
and ClipboardEvents have
readonly attribute DataTransfer? clipboardData;

One can reuse the same DataTransfer object in ClipboardEvents.

something like
`
element.ondrop = function(e) {
element.dispatchEvent(new ClipboardEvent("paste", {clipboardData: e.dataTransfer}));
}

element.onpaste = function(e) {
// handle paste and drop...
}
`

Or are we talking about different things here?

from clipboard-apis.

domenic avatar domenic commented on July 20, 2024

Yes, we appear to be talking about different things. I am responding to your claim that

I agree that DataTransfer having a ctor could be useful

by asking how such a constructor could work. But your example does not include any usage of the DataTransfer constructor, so now I am confused why you think a constructor would be useful.

from clipboard-apis.

garykac avatar garykac commented on July 20, 2024

A constructor was added to DataTransfer in whatwg/html@688a102

from clipboard-apis.

foolip avatar foolip commented on July 20, 2024

Looks like there aren't any tests for new ClipboardEvent that use the new constructor, I filed web-platform-tests/wpt#7857.

from clipboard-apis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.