diff --git a/src/components/DomEvents.js b/src/components/DomEvents.js index fee839dc..d3227fc7 100644 --- a/src/components/DomEvents.js +++ b/src/components/DomEvents.js @@ -5,14 +5,8 @@ import MarkupEditor from './MarkupEditor'; import usePlayground from '../hooks/usePlayground'; import state from '../lib/state'; import { eventMap } from '@testing-library/dom/dist/event-map'; -import { VirtualScrollable } from './Scrollable'; import throttle from 'lodash.throttle'; -import AutoSizer from 'react-virtualized-auto-sizer'; -import IconButton from './IconButton'; -import TrashcanIcon from './icons/TrashcanIcon'; -import CopyButton from './CopyButton'; -import EmptyStreetImg from '../images/EmptyStreetImg'; -import StickyList from './StickyList'; +import DomEventsTable from './DomEventsTable'; function onStateChange({ markup, query, result }) { state.save({ markup, query }); @@ -85,29 +79,6 @@ function addLoggingEvents(node, log) { return eventListeners; } -function EventRecord({ index, style, data }) { - const { id, event, target } = data[index]; - - return ( -
-
{id}
- -
{event.EventType}
-
{event.name}
- -
{target.tagName}
-
- {target.toString()} -
-
- ); -} - const noop = () => {}; function DomEvents() { const [{ markup, result }, dispatch] = usePlayground({ @@ -117,7 +88,6 @@ function DomEvents() { const buffer = useRef([]); const previewRef = useRef(); - const listRef = useRef(); const [eventCount, setEventCount] = useState(0); const [eventListeners, setEventListeners] = useState([]); @@ -127,11 +97,6 @@ function DomEvents() { setEventCount(0); }; - const getTextToCopy = () => - buffer.current - .map((log) => `${log.target.toString()} - ${log.event.EventType}`) - .join('\n'); - const flush = useCallback( throttle(() => setEventCount(buffer.current.length), 16, { leading: false, @@ -177,56 +142,11 @@ function DomEvents() {
-
-
-
-
#
- -
type
-
name
- -
element
-
- selector -
- - - - -
-
-
- -
- {eventCount === 0 ? ( -
- -
- ) : ( - - {({ width, height }) => ( - - {EventRecord} - - )} - - )} -
-
-
+
); } diff --git a/src/components/DomEventsTable.js b/src/components/DomEventsTable.js new file mode 100644 index 00000000..e91e7df6 --- /dev/null +++ b/src/components/DomEventsTable.js @@ -0,0 +1,95 @@ +import React, { useRef } from 'react'; +import IconButton from './IconButton'; +import TrashcanIcon from './icons/TrashcanIcon'; +import EmptyStreetImg from '../images/EmptyStreetImg'; +import StickyList from './StickyList'; +import { VirtualScrollable } from './Scrollable'; +import AutoSizer from 'react-virtualized-auto-sizer'; +import CopyButton from './CopyButton'; + + +function EventRecord({ index, style, data }) { + const { id, event, target } = data[index]; + + return ( +
+
{id}
+ +
{event.EventType}
+
{event.name}
+ +
{target.tagName}
+
+ {target.toString()} +
+
+ ); +} + +const DomEventsTable = ({ reset, data, eventCount }) => { + const listRef = useRef(); + + const getTextToCopy = () => + data + .map((log) => `${log.target.toString()} - ${log.event.EventType}`) + .join('\n'); + + return ( +
+
+
+
#
+ +
type
+
name
+ +
element
+
+ selector +
+ + + + +
+
+
+ +
+ {eventCount === 0 ? ( +
+ +
+ ) : ( + + {({ width, height }) => ( + + {EventRecord} + + )} + + )} +
+
+
+ ); +}; +export default DomEventsTable;