fix: instead add emitter in Cell (#1718)

* fix: instead add emitter in Cell

* chore: better state handling

Co-authored-by: Tobias Linsefors <T-Wizard@users.noreply.github.com>

* chore: createEmitter properly

---------

Co-authored-by: Tobias Linsefors <T-Wizard@users.noreply.github.com>
This commit is contained in:
Tobias Åström
2025-04-08 11:50:57 +02:00
committed by GitHub
parent d2be3f7baa
commit f22b3af41c
2 changed files with 7 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
/* eslint-disable react/jsx-props-no-spreading */
import React, { forwardRef, useImperativeHandle, useEffect, useState, useContext, useReducer, useRef } from 'react';
import EventEmitter from 'node-event-emitter';
import { Grid, Paper } from '@mui/material';
import { useTheme } from '@nebula.js/ui/theme';
@@ -312,6 +313,10 @@ const loadType = async ({
}
};
function createEmitter() {
return new EventEmitter();
}
const Cell = forwardRef(
(
{
@@ -337,6 +342,7 @@ const Cell = forwardRef(
keyboardNavigation,
disableCellPadding = false,
} = useContext(InstanceContext);
const [internalEmitter] = useState(emitter || createEmitter);
const theme = useTheme();
const [cellRef, cellRect, cellNode] = useRect();
const [state, dispatch] = useReducer(contentReducer, initialState(initialError));
@@ -436,7 +442,7 @@ const Cell = forwardRef(
selections,
nebbie,
focusHandler: focusHandler.current,
emitter,
emitter: internalEmitter,
onMount,
navigation,
});

View File

@@ -1,5 +1,4 @@
import React, { useEffect, useState, useContext, useMemo, forwardRef, useImperativeHandle, useRef } from 'react';
import EventEmitter from 'node-event-emitter';
import useLayout from '../hooks/useLayout';
import getObject from '../object/get-object';
import Cell from './Cell';
@@ -28,8 +27,6 @@ function getCellRenderer(cell, halo, initialSnOptions, initialSnPlugins, initial
style.padding = '4px';
}
const emitter = new EventEmitter();
return (
<div style={style} key={cell.model.id}>
<Cell
@@ -41,7 +38,6 @@ function getCellRenderer(cell, halo, initialSnOptions, initialSnPlugins, initial
initialSnPlugins={initialSnPlugins}
initialError={initialError}
onMount={onMount}
emitter={emitter}
navigation={navigation}
onError={onError}
/>