-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* getDirtyPaths can now be customized by Slate users (#4012) * Moved getDirtyPaths() into the editor object so it can be customized via plugin * docs: Update document in Chinese (#4017) Co-authored-by: liuchengshuai001 <liuchengshuai001@ke.com> * Removed unused import * Use shadowRoot if available * Removed optional chaining * Added workaround for chrom bug in ShadowDOM * Added shadow DOM example * Add a shadow DOM example Shadow DOM brings different behaviours for selection and active elements. This adds an example where the editor is found within a shadow DOM, in fact, the editor is two levels deep in nested shadow DOMs. The handling of selections means that this editor doesn't work properly so Slate will need to be made aware of the shadow DOM in order to fix this. * User DocumentOrShadowRoot for selection and active elements If the editor is within a ShadowDom, the selections and active element APIs are implemented on the ShadowRoot for Chrome. Other browsers still use the Document's version of these APIs for the shadow DOM. Instead of defaulting to `window.document`, find the appropriate root to use for the editor in question. * Add compatibility for Chrome's isCollapsed bug Chrome will always return true for isCollapsed on a selection from the shadow DOM. Work around this by instead computing this property on Chrome. https://bugs.chromium.org/p/chromium/issues/detail?id=447523 * Removed duplicated example * Fixed possible null value * Use existing PlainTextExample * Re-added local Editor to have clear initialValue * Optimize shadowRoot checkup * Remove getDocumentOrShadowRoot util in favor of findDocumentOrShadowRoot * Re-added getDocumentOrShadowRoot * Put selectionchange listener on window.document * Resetted changes from main branch * Create tiny-walls-deliver.md * Update tiny-walls-deliver.md * Update tiny-walls-deliver.md Co-authored-by: Tommy Dong <contact@tomdong.io> Co-authored-by: Jacob <40483898+jacob-lcs@users.noreply.github.com> Co-authored-by: liuchengshuai001 <liuchengshuai001@ke.com> Co-authored-by: Andrew Scull <andrew.scull@live.com> Co-authored-by: Ian Storm Taylor <ian@ianstormtaylor.com>
- Loading branch information
1 parent
42d99af
commit 0473d0b
Showing
7 changed files
with
120 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'slate-react': patch | ||
--- | ||
|
||
Fixes Slate to work with the Shadow DOM. |
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import ReactDOM from 'react-dom' | ||
import React, { useState, useMemo, useRef, useEffect } from 'react' | ||
import { createEditor } from 'slate' | ||
import { Slate, Editable, withReact } from 'slate-react' | ||
import { withHistory } from 'slate-history' | ||
|
||
const ShadowDOM = () => { | ||
const container = useRef(null) | ||
|
||
useEffect(() => { | ||
if (container.current.shadowRoot) return | ||
|
||
// Create a shadow DOM | ||
const outerShadowRoot = container.current.attachShadow({ mode: 'open' }) | ||
const host = document.createElement('div') | ||
outerShadowRoot.appendChild(host) | ||
|
||
// Create a nested shadow DOM | ||
const innerShadowRoot = host.attachShadow({ mode: 'open' }) | ||
const reactRoot = document.createElement('div') | ||
innerShadowRoot.appendChild(reactRoot) | ||
|
||
// Render the editor within the nested shadow DOM | ||
ReactDOM.render(<ShadowEditor />, reactRoot) | ||
}) | ||
|
||
return <div ref={container} /> | ||
} | ||
|
||
const ShadowEditor = () => { | ||
const [value, setValue] = useState(initialValue) | ||
const editor = useMemo(() => withHistory(withReact(createEditor())), []) | ||
|
||
return ( | ||
<Slate editor={editor} value={value} onChange={value => setValue(value)}> | ||
<Editable placeholder="Enter some plain text..." /> | ||
</Slate> | ||
) | ||
} | ||
|
||
const initialValue = [ | ||
{ | ||
children: [{ text: 'This Editor is rendered within a nested Shadow DOM.' }], | ||
}, | ||
] | ||
|
||
export default ShadowDOM |
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