Skip to content

Commit

Permalink
Add polyfill for ResizeObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemclean committed Jan 30, 2023
1 parent 936b21f commit 7e2267d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/slate-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dist/"
],
"dependencies": {
"@juggle/resize-observer": "^3.4.0",
"@types/is-hotkey": "^0.1.1",
"@types/lodash": "^4.14.149",
"direction": "^1.0.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/slate-react/src/components/leaf.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useRef, useEffect } from 'react'
import { Element, Text } from 'slate'
import { ResizeObserver as ResizeObserverPolyfill } from '@juggle/resize-observer'
import String from './string'
import {
PLACEHOLDER_SYMBOL,
Expand Down Expand Up @@ -60,6 +61,7 @@ const Leaf = (props: {
placeholderResizeObserver.current.observe(placeholderEl)
} else if (placeholderEl) {
// Create a new observer and observe the placeholder element.
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill
placeholderResizeObserver.current = new ResizeObserver(([{ target }]) => {
const styleElement = EDITOR_TO_STYLE_ELEMENT.get(editor)
if (styleElement) {
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,13 @@ __metadata:
languageName: node
linkType: hard

"@juggle/resize-observer@npm:^3.4.0":
version: 3.4.0
resolution: "@juggle/resize-observer@npm:3.4.0"
checksum: 2505028c05cc2e17639fcad06218b1c4b60f932a4ebb4b41ab546ef8c157031ae377e3f560903801f6d01706dbefd4943b6c4704bf19ed86dfa1c62f1473a570
languageName: node
linkType: hard

"@lerna/add@npm:3.21.0":
version: 3.21.0
resolution: "@lerna/add@npm:3.21.0"
Expand Down Expand Up @@ -13904,6 +13911,7 @@ resolve@^2.0.0-next.3:
resolution: "slate-react@workspace:packages/slate-react"
dependencies:
"@babel/runtime": ^7.7.4
"@juggle/resize-observer": ^3.4.0
"@types/is-hotkey": ^0.1.1
"@types/jest": ^27.4.1
"@types/jsdom": ^16.2.14
Expand Down

0 comments on commit 7e2267d

Please sign in to comment.