Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add document owner property to touch backend #2848

Closed

Conversation

jcampbell05
Copy link
Contributor

@jcampbell05 jcampbell05 commented Nov 10, 2020

In certain projects such as the one I am working on elements are encapsulated so that they are in their own sandbox. In modern browsers you would do this with the ShadowDOM but since we have to support IE 11 we cannot use that API.

We could use a Polyfill but as we are an SDK that would add unneeded weight. Instead we encapsulate by mounting our element within an iframe.

Unfortunately that breaks some assumptions this library makes. The element is now owned by the document of the iframe and not the root document object meaning events can only be listened to from the document object for the iframe.

The library assumes that it will always be able to get these events from the global document for the window. In this PR I provide an ownerDocument option which allows the consuming project to provide it's own document object for the touch backend to attach its events to.

So within the encapsulated component you can pass in a ref to a div element's ownerDocument to the backend, like so:

const collection = () => {
    const container = useRef(null)
    return <div ref={container}>
         <DNDContext options={{ ownerDocument: container.current.ownerDocument} }/>
    <./div>
}

Similar changes will need to be made for the HTML5 backend but I wanted to keep this PR focused on one backend.

@darthtrevino
Copy link
Member

LGTM, does the HTML5 backend need a similar configuration?

@jcampbell05
Copy link
Contributor Author

jcampbell05 commented Nov 13, 2020

LGTM, does the HTML5 backend need a similar configuration?

Yes I believe it will but I haven't tested as I only needed the touch backend. I'll take a look at why tests are failing.

@jcampbell05
Copy link
Contributor Author

jcampbell05 commented Nov 13, 2020

In CI I am seeing a message about "some workspaces had changes but had no instructions on how they should be released" do you know how I can resolve this ?

@darthtrevino
Copy link
Member

darthtrevino commented Nov 13, 2020 via email

@jcampbell05
Copy link
Contributor Author

Try running ‘yarn version check —interactive’ to create a semver impact document

Just added a patch release strategy hopefully that helps

@darthtrevino
Copy link
Member

@jcampbell05 Can you grant me write access on your branch?

@jcampbell05
Copy link
Contributor Author

Can you grant me write access on your branch?
@jcampbell05 Can you grant me write access on your branch?

You will now have access

@darthtrevino
Copy link
Member

Hmm, I'm having trouble pushing. Can you look on the right side of the PR? There should be a checkbox that says "allow edits by maintainers" or something to that effect.

@jcampbell05
Copy link
Contributor Author

Hmm, I'm having trouble pushing. Can you look on the right side of the PR? There should be a checkbox that says "allow edits by maintainers" or something to that effect.

Doesn't show up unfortunately, I sent you an invite to my repo instead can you accept that and see

@darthtrevino darthtrevino mentioned this pull request Nov 13, 2020
darthtrevino added a commit that referenced this pull request Nov 13, 2020
* Allow client application to provide an ownerDocument that events can be attached to instead of defaulting to the root document.

* Prefer owner document over window document.

* Adds ability to specify a custom document for events to be attached to in touch backend.

* Patch release strategy.

* chore: cut semver document

* feat: add document to html5 and touch backend contexts

* chore: use minor version

Co-authored-by: james <[email protected]>
@darthtrevino
Copy link
Member

Merged with #2859

darthtrevino added a commit that referenced this pull request Feb 3, 2022
* Allow client application to provide an ownerDocument that events can be attached to instead of defaulting to the root document.

* Prefer owner document over window document.

* Adds ability to specify a custom document for events to be attached to in touch backend.

* Patch release strategy.

* chore: cut semver document

* feat: add document to html5 and touch backend contexts

* chore: use minor version

Co-authored-by: james <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants