Skip to content

[query] <description>Plugin events not work on readOnly mode #527

@wt0528

Description

@wt0528

Has this bug been raised before?

  • I have checked "open" AND "closed" issues and this is not a duplicate

Description

Background: I use YooptaPlugin.extend to receive click events, to expand and collapse the content.

  1. 'readOnly' is true

  2. extend 'HeadingOne' plugin, and set a onClick event. like this:
    export const HeadingOnePlugin = HeadingOne.extend({ events: { onKeyDown, onClick: handleHeadingClick, }, options: { HTMLAttributes: { className: 'yoopta-heading-collapsible', }, }, });

  3. The onClick event not work, because all events are ignored in useEventHandlers:
    Yoopta-Editor\packages\core\editor\src\plugins\hooks.ts
    `export const useEventHandlers = (
    events: PluginEvents | undefined,
    editor: YooEditor,
    block: YooptaBlockData,
    slate: SlateEditor,
    ) => {
    return useMemo(() => {
    if (!events || editor.readOnly) return {};
    const { onBeforeCreate, onDestroy, onCreate, ...eventHandlers } = events || {};

    const eventHandlersOptions: PluginEventHandlerOptions = {
    hotkeys: HOTKEYS,
    currentBlock: block,
    defaultBlock: Blocks.buildBlockData({ id: generateId() }),
    };
    const eventHandlersMap = {};

    Object.keys(eventHandlers).forEach((eventType) => {
    eventHandlersMap[eventType] = function handler(event) {
    if (eventHandlers[eventType]) {
    const handler = eventHandlers[eventType](editor, slate, eventHandlersOptions);
    handler(event);
    }
    };
    });

    return eventHandlersMap;
    }, [events, editor, block]);
    };`

expect: other events besides these three onBeforeCreate, onDestroy, onCreate ,should not be ignored
Could i have some way to get the onClick event on this case?thanks.

Do you want to work on this issue?

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions