@prosekit/react 0.4.13 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,38 @@
1
1
  import { useEditorContext } from "./editor-context-Cci4uqN_.js";
2
- import { createElement, forwardRef, useEffect, useLayoutEffect, useRef, useState } from "react";
3
- import { mergeRefs } from "react-merge-refs";
2
+ import { createElement, forwardRef, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
4
3
 
4
+ //#region src/components/merge-refs.ts
5
+ /**
6
+ * Assigns a value to a ref.
7
+ * @returns The ref cleanup callback, if any.
8
+ */
9
+ function assignRef(ref, value) {
10
+ if (typeof ref === "function") return ref(value);
11
+ else if (ref) ref.current = value;
12
+ }
13
+ /**
14
+ * Merges multiple refs into a single one.
15
+ */
16
+ function mergeRefs(refs) {
17
+ return (value) => {
18
+ const cleanups = [];
19
+ for (const ref of refs) {
20
+ const cleanup = assignRef(ref, value);
21
+ const isCleanup = typeof cleanup === "function";
22
+ cleanups.push(isCleanup ? cleanup : () => assignRef(ref, null));
23
+ }
24
+ return () => {
25
+ for (const cleanup of cleanups) cleanup();
26
+ };
27
+ };
28
+ }
29
+
30
+ //#endregion
5
31
  //#region src/components/create-component.ts
6
32
  const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
7
33
  function createComponent(tagName, displayName, propNames, eventNames) {
8
34
  const hasEditor = propNames.includes("editor");
9
- const lowerCaseEventNameMap = Object.fromEntries(eventNames.map((name) => [name.toLowerCase(), name]));
35
+ const lowerCaseEventNameMap = new Map(eventNames.map((name) => [name.toLowerCase(), name]));
10
36
  const Component = forwardRef((props, ref) => {
11
37
  const [el, setEl] = useState(null);
12
38
  const properties = {};
@@ -21,14 +47,14 @@ function createComponent(tagName, displayName, propNames, eventNames) {
21
47
  }
22
48
  if (name.startsWith("on")) {
23
49
  const lowerCaseEventName = name.slice(2).toLowerCase();
24
- const eventName = lowerCaseEventNameMap[lowerCaseEventName];
25
- const handler = value;
26
- if (eventName && handler) {
50
+ const eventName = lowerCaseEventNameMap.get(lowerCaseEventName);
51
+ if (eventName) {
27
52
  const extractDetail = eventName.endsWith("Change");
28
- const normalizedHandler = extractDetail ? (event) => {
29
- handler(event.detail);
30
- } : handler;
31
- eventHandlers[eventName] = normalizedHandler;
53
+ eventHandlers[eventName] = (event) => {
54
+ const handler = value;
55
+ if (typeof handler === "function") handler(extractDetail ? event.detail : event);
56
+ };
57
+ continue;
32
58
  }
33
59
  }
34
60
  if (name === "className") attributes["class"] = value;
@@ -54,9 +80,10 @@ function createComponent(tagName, displayName, propNames, eventNames) {
54
80
  for (const [name, handler] of Object.entries(fixedEventHandlers)) el.removeEventListener(name, handler);
55
81
  };
56
82
  }, [el]);
83
+ const mergedRef = useMemo(() => mergeRefs([ref, setEl]), [ref]);
57
84
  return createElement(tagName, {
58
85
  ...attributes,
59
- ref: mergeRefs([ref, setEl])
86
+ ref: mergedRef
60
87
  });
61
88
  });
62
89
  Component.displayName = displayName;
@@ -1,6 +1,5 @@
1
1
  //#region src/components/create-props.d.ts
2
2
  type CreateProps<Props extends { [PropName in keyof Props]: unknown }, Events extends { [EventName in keyof Events]: CustomEvent }> = Props & CreateEventProps<Events>;
3
3
  type CreateEventProps<Events extends { [EventName in keyof Events]: CustomEvent }> = { [EventName in keyof Events as `on${Capitalize<string & EventName>}`]: (event: EventName extends `${string}Change` ? Events[EventName]["detail"] : Events[EventName]) => void };
4
-
5
4
  //#endregion
6
5
  export { CreateProps };
@@ -1,17 +1,14 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { AutocompleteEmptyElement, AutocompleteEmptyEvents, AutocompleteEmptyProps as AutocompleteEmptyProps$1, AutocompleteItemElement, AutocompleteItemEvents, AutocompleteItemProps as AutocompleteItemProps$1, AutocompleteListElement, AutocompleteListEvents, AutocompleteListProps as AutocompleteListProps$1, AutocompletePopoverElement, AutocompletePopoverEvents, AutocompletePopoverProps as AutocompletePopoverProps$1 } from "@prosekit/web/autocomplete";
4
4
 
5
5
  //#region src/components/autocomplete/autocomplete-empty.gen.d.ts
6
- /**
7
- * Props for the {@link AutocompleteEmpty} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link AutocompleteEmpty} component.
11
9
  */
12
10
  interface AutocompleteEmptyProps extends Partial<CreateProps<AutocompleteEmptyProps$1, AutocompleteEmptyEvents>> {}
13
11
  declare const AutocompleteEmpty: ForwardRefExoticComponent<AutocompleteEmptyProps & RefAttributes<AutocompleteEmptyElement> & HTMLAttributes<AutocompleteEmptyElement>>;
14
-
15
12
  //#endregion
16
13
  //#region src/components/autocomplete/autocomplete-item.gen.d.ts
17
14
  /**
@@ -19,7 +16,6 @@ declare const AutocompleteEmpty: ForwardRefExoticComponent<AutocompleteEmptyProp
19
16
  */
20
17
  interface AutocompleteItemProps extends Partial<CreateProps<AutocompleteItemProps$1, AutocompleteItemEvents>> {}
21
18
  declare const AutocompleteItem: ForwardRefExoticComponent<AutocompleteItemProps & RefAttributes<AutocompleteItemElement> & HTMLAttributes<AutocompleteItemElement>>;
22
-
23
19
  //#endregion
24
20
  //#region src/components/autocomplete/autocomplete-list.gen.d.ts
25
21
  /**
@@ -27,7 +23,6 @@ declare const AutocompleteItem: ForwardRefExoticComponent<AutocompleteItemProps
27
23
  */
28
24
  interface AutocompleteListProps extends Partial<CreateProps<AutocompleteListProps$1, AutocompleteListEvents>> {}
29
25
  declare const AutocompleteList: ForwardRefExoticComponent<AutocompleteListProps & RefAttributes<AutocompleteListElement> & HTMLAttributes<AutocompleteListElement>>;
30
-
31
26
  //#endregion
32
27
  //#region src/components/autocomplete/autocomplete-popover.gen.d.ts
33
28
  /**
@@ -35,6 +30,5 @@ declare const AutocompleteList: ForwardRefExoticComponent<AutocompleteListProps
35
30
  */
36
31
  interface AutocompletePopoverProps extends Partial<CreateProps<AutocompletePopoverProps$1, AutocompletePopoverEvents>> {}
37
32
  declare const AutocompletePopover: ForwardRefExoticComponent<AutocompletePopoverProps & RefAttributes<AutocompletePopoverElement> & HTMLAttributes<AutocompletePopoverElement>>;
38
-
39
33
  //#endregion
40
34
  export { AutocompleteEmpty, AutocompleteEmptyProps, AutocompleteItem, AutocompleteItemProps, AutocompleteList, AutocompleteListProps, AutocompletePopover, AutocompletePopoverProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { autocompleteEmptyEvents, autocompleteEmptyProps, autocompleteItemEvents, autocompleteItemProps, autocompleteListEvents, autocompleteListProps, autocompletePopoverEvents, autocompletePopoverProps } from "@prosekit/web/autocomplete";
4
4
 
5
5
  //#region src/components/autocomplete/autocomplete-empty.gen.ts
@@ -1,17 +1,14 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { BlockHandleAddElement, BlockHandleAddEvents, BlockHandleAddProps as BlockHandleAddProps$1, BlockHandleDraggableElement, BlockHandleDraggableEvents, BlockHandleDraggableProps as BlockHandleDraggableProps$1, BlockHandlePopoverElement, BlockHandlePopoverEvents, BlockHandlePopoverProps as BlockHandlePopoverProps$1 } from "@prosekit/web/block-handle";
4
4
 
5
5
  //#region src/components/block-handle/block-handle-add.gen.d.ts
6
- /**
7
- * Props for the {@link BlockHandleAdd} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link BlockHandleAdd} component.
11
9
  */
12
10
  interface BlockHandleAddProps extends Partial<CreateProps<BlockHandleAddProps$1, BlockHandleAddEvents>> {}
13
11
  declare const BlockHandleAdd: ForwardRefExoticComponent<BlockHandleAddProps & RefAttributes<BlockHandleAddElement> & HTMLAttributes<BlockHandleAddElement>>;
14
-
15
12
  //#endregion
16
13
  //#region src/components/block-handle/block-handle-draggable.gen.d.ts
17
14
  /**
@@ -19,7 +16,6 @@ declare const BlockHandleAdd: ForwardRefExoticComponent<BlockHandleAddProps & Re
19
16
  */
20
17
  interface BlockHandleDraggableProps extends Partial<CreateProps<BlockHandleDraggableProps$1, BlockHandleDraggableEvents>> {}
21
18
  declare const BlockHandleDraggable: ForwardRefExoticComponent<BlockHandleDraggableProps & RefAttributes<BlockHandleDraggableElement> & HTMLAttributes<BlockHandleDraggableElement>>;
22
-
23
19
  //#endregion
24
20
  //#region src/components/block-handle/block-handle-popover.gen.d.ts
25
21
  /**
@@ -27,6 +23,5 @@ declare const BlockHandleDraggable: ForwardRefExoticComponent<BlockHandleDraggab
27
23
  */
28
24
  interface BlockHandlePopoverProps extends Partial<CreateProps<BlockHandlePopoverProps$1, BlockHandlePopoverEvents>> {}
29
25
  declare const BlockHandlePopover: ForwardRefExoticComponent<BlockHandlePopoverProps & RefAttributes<BlockHandlePopoverElement> & HTMLAttributes<BlockHandlePopoverElement>>;
30
-
31
26
  //#endregion
32
27
  export { BlockHandleAdd, BlockHandleAddProps, BlockHandleDraggable, BlockHandleDraggableProps, BlockHandlePopover, BlockHandlePopoverProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { blockHandleAddEvents, blockHandleAddProps, blockHandleDraggableEvents, blockHandleDraggableProps, blockHandlePopoverEvents, blockHandlePopoverProps } from "@prosekit/web/block-handle";
4
4
 
5
5
  //#region src/components/block-handle/block-handle-add.gen.ts
@@ -1,16 +1,13 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { InlinePopoverElement, InlinePopoverEvents, InlinePopoverProps as InlinePopoverProps$1 } from "@prosekit/web/inline-popover";
4
4
 
5
5
  //#region src/components/inline-popover/inline-popover.gen.d.ts
6
- /**
7
- * Props for the {@link InlinePopover} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link InlinePopover} component.
11
9
  */
12
10
  interface InlinePopoverProps extends Partial<CreateProps<InlinePopoverProps$1, InlinePopoverEvents>> {}
13
11
  declare const InlinePopover: ForwardRefExoticComponent<InlinePopoverProps & RefAttributes<InlinePopoverElement> & HTMLAttributes<InlinePopoverElement>>;
14
-
15
12
  //#endregion
16
13
  export { InlinePopover, InlinePopoverProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { inlinePopoverEvents, inlinePopoverProps } from "@prosekit/web/inline-popover";
4
4
 
5
5
  //#region src/components/inline-popover/inline-popover.gen.ts
@@ -1,17 +1,14 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { PopoverContentElement, PopoverContentEvents, PopoverContentProps as PopoverContentProps$1, PopoverRootElement, PopoverRootEvents, PopoverRootProps as PopoverRootProps$1, PopoverTriggerElement, PopoverTriggerEvents, PopoverTriggerProps as PopoverTriggerProps$1 } from "@prosekit/web/popover";
4
4
 
5
5
  //#region src/components/popover/popover-content.gen.d.ts
6
- /**
7
- * Props for the {@link PopoverContent} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link PopoverContent} component.
11
9
  */
12
10
  interface PopoverContentProps extends Partial<CreateProps<PopoverContentProps$1, PopoverContentEvents>> {}
13
11
  declare const PopoverContent: ForwardRefExoticComponent<PopoverContentProps & RefAttributes<PopoverContentElement> & HTMLAttributes<PopoverContentElement>>;
14
-
15
12
  //#endregion
16
13
  //#region src/components/popover/popover-root.gen.d.ts
17
14
  /**
@@ -19,7 +16,6 @@ declare const PopoverContent: ForwardRefExoticComponent<PopoverContentProps & Re
19
16
  */
20
17
  interface PopoverRootProps extends Partial<CreateProps<PopoverRootProps$1, PopoverRootEvents>> {}
21
18
  declare const PopoverRoot: ForwardRefExoticComponent<PopoverRootProps & RefAttributes<PopoverRootElement> & HTMLAttributes<PopoverRootElement>>;
22
-
23
19
  //#endregion
24
20
  //#region src/components/popover/popover-trigger.gen.d.ts
25
21
  /**
@@ -27,6 +23,5 @@ declare const PopoverRoot: ForwardRefExoticComponent<PopoverRootProps & RefAttri
27
23
  */
28
24
  interface PopoverTriggerProps extends Partial<CreateProps<PopoverTriggerProps$1, PopoverTriggerEvents>> {}
29
25
  declare const PopoverTrigger: ForwardRefExoticComponent<PopoverTriggerProps & RefAttributes<PopoverTriggerElement> & HTMLAttributes<PopoverTriggerElement>>;
30
-
31
26
  //#endregion
32
27
  export { PopoverContent, PopoverContentProps, PopoverRoot, PopoverRootProps, PopoverTrigger, PopoverTriggerProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { popoverContentEvents, popoverContentProps, popoverRootEvents, popoverRootProps, popoverTriggerEvents, popoverTriggerProps } from "@prosekit/web/popover";
4
4
 
5
5
  //#region src/components/popover/popover-content.gen.ts
@@ -1,17 +1,14 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { ResizableHandleElement, ResizableHandleEvents, ResizableHandleProps as ResizableHandleProps$1, ResizableRootElement, ResizableRootEvents, ResizableRootProps as ResizableRootProps$1 } from "@prosekit/web/resizable";
4
4
 
5
5
  //#region src/components/resizable/resizable-handle.gen.d.ts
6
- /**
7
- * Props for the {@link ResizableHandle} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link ResizableHandle} component.
11
9
  */
12
10
  interface ResizableHandleProps extends Partial<CreateProps<ResizableHandleProps$1, ResizableHandleEvents>> {}
13
11
  declare const ResizableHandle: ForwardRefExoticComponent<ResizableHandleProps & RefAttributes<ResizableHandleElement> & HTMLAttributes<ResizableHandleElement>>;
14
-
15
12
  //#endregion
16
13
  //#region src/components/resizable/resizable-root.gen.d.ts
17
14
  /**
@@ -19,6 +16,5 @@ declare const ResizableHandle: ForwardRefExoticComponent<ResizableHandleProps &
19
16
  */
20
17
  interface ResizableRootProps extends Partial<CreateProps<ResizableRootProps$1, ResizableRootEvents>> {}
21
18
  declare const ResizableRoot: ForwardRefExoticComponent<ResizableRootProps & RefAttributes<ResizableRootElement> & HTMLAttributes<ResizableRootElement>>;
22
-
23
19
  //#endregion
24
20
  export { ResizableHandle, ResizableHandleProps, ResizableRoot, ResizableRootProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { resizableHandleEvents, resizableHandleProps, resizableRootEvents, resizableRootProps } from "@prosekit/web/resizable";
4
4
 
5
5
  //#region src/components/resizable/resizable-handle.gen.ts
@@ -1,17 +1,14 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { TableHandleColumnRootElement, TableHandleColumnRootEvents, TableHandleColumnRootProps as TableHandleColumnRootProps$1, TableHandleColumnTriggerElement, TableHandleColumnTriggerEvents, TableHandleColumnTriggerProps as TableHandleColumnTriggerProps$1, TableHandlePopoverContentElement, TableHandlePopoverContentEvents, TableHandlePopoverContentProps as TableHandlePopoverContentProps$1, TableHandlePopoverItemElement, TableHandlePopoverItemEvents, TableHandlePopoverItemProps as TableHandlePopoverItemProps$1, TableHandleRootElement, TableHandleRootEvents, TableHandleRootProps as TableHandleRootProps$1, TableHandleRowRootElement, TableHandleRowRootEvents, TableHandleRowRootProps as TableHandleRowRootProps$1, TableHandleRowTriggerElement, TableHandleRowTriggerEvents, TableHandleRowTriggerProps as TableHandleRowTriggerProps$1 } from "@prosekit/web/table-handle";
4
4
 
5
5
  //#region src/components/table-handle/table-handle-column-root.gen.d.ts
6
- /**
7
- * Props for the {@link TableHandleColumnRoot} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link TableHandleColumnRoot} component.
11
9
  */
12
10
  interface TableHandleColumnRootProps extends Partial<CreateProps<TableHandleColumnRootProps$1, TableHandleColumnRootEvents>> {}
13
11
  declare const TableHandleColumnRoot: ForwardRefExoticComponent<TableHandleColumnRootProps & RefAttributes<TableHandleColumnRootElement> & HTMLAttributes<TableHandleColumnRootElement>>;
14
-
15
12
  //#endregion
16
13
  //#region src/components/table-handle/table-handle-column-trigger.gen.d.ts
17
14
  /**
@@ -19,7 +16,6 @@ declare const TableHandleColumnRoot: ForwardRefExoticComponent<TableHandleColumn
19
16
  */
20
17
  interface TableHandleColumnTriggerProps extends Partial<CreateProps<TableHandleColumnTriggerProps$1, TableHandleColumnTriggerEvents>> {}
21
18
  declare const TableHandleColumnTrigger: ForwardRefExoticComponent<TableHandleColumnTriggerProps & RefAttributes<TableHandleColumnTriggerElement> & HTMLAttributes<TableHandleColumnTriggerElement>>;
22
-
23
19
  //#endregion
24
20
  //#region src/components/table-handle/table-handle-popover-content.gen.d.ts
25
21
  /**
@@ -27,7 +23,6 @@ declare const TableHandleColumnTrigger: ForwardRefExoticComponent<TableHandleCol
27
23
  */
28
24
  interface TableHandlePopoverContentProps extends Partial<CreateProps<TableHandlePopoverContentProps$1, TableHandlePopoverContentEvents>> {}
29
25
  declare const TableHandlePopoverContent: ForwardRefExoticComponent<TableHandlePopoverContentProps & RefAttributes<TableHandlePopoverContentElement> & HTMLAttributes<TableHandlePopoverContentElement>>;
30
-
31
26
  //#endregion
32
27
  //#region src/components/table-handle/table-handle-popover-item.gen.d.ts
33
28
  /**
@@ -35,7 +30,6 @@ declare const TableHandlePopoverContent: ForwardRefExoticComponent<TableHandlePo
35
30
  */
36
31
  interface TableHandlePopoverItemProps extends Partial<CreateProps<TableHandlePopoverItemProps$1, TableHandlePopoverItemEvents>> {}
37
32
  declare const TableHandlePopoverItem: ForwardRefExoticComponent<TableHandlePopoverItemProps & RefAttributes<TableHandlePopoverItemElement> & HTMLAttributes<TableHandlePopoverItemElement>>;
38
-
39
33
  //#endregion
40
34
  //#region src/components/table-handle/table-handle-root.gen.d.ts
41
35
  /**
@@ -43,7 +37,6 @@ declare const TableHandlePopoverItem: ForwardRefExoticComponent<TableHandlePopov
43
37
  */
44
38
  interface TableHandleRootProps extends Partial<CreateProps<TableHandleRootProps$1, TableHandleRootEvents>> {}
45
39
  declare const TableHandleRoot: ForwardRefExoticComponent<TableHandleRootProps & RefAttributes<TableHandleRootElement> & HTMLAttributes<TableHandleRootElement>>;
46
-
47
40
  //#endregion
48
41
  //#region src/components/table-handle/table-handle-row-root.gen.d.ts
49
42
  /**
@@ -51,7 +44,6 @@ declare const TableHandleRoot: ForwardRefExoticComponent<TableHandleRootProps &
51
44
  */
52
45
  interface TableHandleRowRootProps extends Partial<CreateProps<TableHandleRowRootProps$1, TableHandleRowRootEvents>> {}
53
46
  declare const TableHandleRowRoot: ForwardRefExoticComponent<TableHandleRowRootProps & RefAttributes<TableHandleRowRootElement> & HTMLAttributes<TableHandleRowRootElement>>;
54
-
55
47
  //#endregion
56
48
  //#region src/components/table-handle/table-handle-row-trigger.gen.d.ts
57
49
  /**
@@ -59,6 +51,5 @@ declare const TableHandleRowRoot: ForwardRefExoticComponent<TableHandleRowRootPr
59
51
  */
60
52
  interface TableHandleRowTriggerProps extends Partial<CreateProps<TableHandleRowTriggerProps$1, TableHandleRowTriggerEvents>> {}
61
53
  declare const TableHandleRowTrigger: ForwardRefExoticComponent<TableHandleRowTriggerProps & RefAttributes<TableHandleRowTriggerElement> & HTMLAttributes<TableHandleRowTriggerElement>>;
62
-
63
54
  //#endregion
64
55
  export { TableHandleColumnRoot, TableHandleColumnRootProps, TableHandleColumnTrigger, TableHandleColumnTriggerProps, TableHandlePopoverContent, TableHandlePopoverContentProps, TableHandlePopoverItem, TableHandlePopoverItemProps, TableHandleRoot, TableHandleRootProps, TableHandleRowRoot, TableHandleRowRootProps, TableHandleRowTrigger, TableHandleRowTriggerProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { tableHandleColumnRootEvents, tableHandleColumnRootProps, tableHandleColumnTriggerEvents, tableHandleColumnTriggerProps, tableHandlePopoverContentEvents, tableHandlePopoverContentProps, tableHandlePopoverItemEvents, tableHandlePopoverItemProps, tableHandleRootEvents, tableHandleRootProps, tableHandleRowRootEvents, tableHandleRowRootProps, tableHandleRowTriggerEvents, tableHandleRowTriggerProps } from "@prosekit/web/table-handle";
4
4
 
5
5
  //#region src/components/table-handle/table-handle-column-root.gen.ts
@@ -1,17 +1,14 @@
1
- import { CreateProps } from "./create-props-B_K0wKYy.js";
1
+ import { CreateProps } from "./create-props-CkTwd_m_.js";
2
2
  import { ForwardRefExoticComponent, HTMLAttributes, RefAttributes } from "react";
3
3
  import { TooltipContentElement, TooltipContentEvents, TooltipContentProps as TooltipContentProps$1, TooltipRootElement, TooltipRootEvents, TooltipRootProps as TooltipRootProps$1, TooltipTriggerElement, TooltipTriggerEvents, TooltipTriggerProps as TooltipTriggerProps$1 } from "@prosekit/web/tooltip";
4
4
 
5
5
  //#region src/components/tooltip/tooltip-content.gen.d.ts
6
- /**
7
- * Props for the {@link TooltipContent} component.
8
- */
6
+
9
7
  /**
10
8
  * Props for the {@link TooltipContent} component.
11
9
  */
12
10
  interface TooltipContentProps extends Partial<CreateProps<TooltipContentProps$1, TooltipContentEvents>> {}
13
11
  declare const TooltipContent: ForwardRefExoticComponent<TooltipContentProps & RefAttributes<TooltipContentElement> & HTMLAttributes<TooltipContentElement>>;
14
-
15
12
  //#endregion
16
13
  //#region src/components/tooltip/tooltip-root.gen.d.ts
17
14
  /**
@@ -19,7 +16,6 @@ declare const TooltipContent: ForwardRefExoticComponent<TooltipContentProps & Re
19
16
  */
20
17
  interface TooltipRootProps extends Partial<CreateProps<TooltipRootProps$1, TooltipRootEvents>> {}
21
18
  declare const TooltipRoot: ForwardRefExoticComponent<TooltipRootProps & RefAttributes<TooltipRootElement> & HTMLAttributes<TooltipRootElement>>;
22
-
23
19
  //#endregion
24
20
  //#region src/components/tooltip/tooltip-trigger.gen.d.ts
25
21
  /**
@@ -27,6 +23,5 @@ declare const TooltipRoot: ForwardRefExoticComponent<TooltipRootProps & RefAttri
27
23
  */
28
24
  interface TooltipTriggerProps extends Partial<CreateProps<TooltipTriggerProps$1, TooltipTriggerEvents>> {}
29
25
  declare const TooltipTrigger: ForwardRefExoticComponent<TooltipTriggerProps & RefAttributes<TooltipTriggerElement> & HTMLAttributes<TooltipTriggerElement>>;
30
-
31
26
  //#endregion
32
27
  export { TooltipContent, TooltipContentProps, TooltipRoot, TooltipRootProps, TooltipTrigger, TooltipTriggerProps };
@@ -1,5 +1,5 @@
1
1
  import "./editor-context-Cci4uqN_.js";
2
- import { createComponent } from "./create-component-DATBjvTG.js";
2
+ import { createComponent } from "./create-component-CBvs05W1.js";
3
3
  import { tooltipContentEvents, tooltipContentProps, tooltipRootEvents, tooltipRootProps, tooltipTriggerEvents, tooltipTriggerProps } from "@prosekit/web/tooltip";
4
4
 
5
5
  //#region src/components/tooltip/tooltip-content.gen.ts
@@ -16,7 +16,6 @@ interface ProseKitProps {
16
16
  * @public
17
17
  */
18
18
  declare const ProseKit: ComponentType<ProseKitProps>;
19
-
20
19
  //#endregion
21
20
  //#region src/extensions/react-mark-view.d.ts
22
21
  /**
@@ -48,7 +47,6 @@ interface ReactMarkViewOptions extends CoreMarkViewUserOptions<ReactMarkViewComp
48
47
  * @public
49
48
  */
50
49
  declare function defineReactMarkView(options: ReactMarkViewOptions): Extension;
51
-
52
50
  //#endregion
53
51
  //#region src/extensions/react-node-view.d.ts
54
52
  /**
@@ -80,7 +78,6 @@ interface ReactNodeViewOptions extends CoreNodeViewUserOptions<ReactNodeViewComp
80
78
  * @public
81
79
  */
82
80
  declare function defineReactNodeView(options: ReactNodeViewOptions): Extension;
83
-
84
81
  //#endregion
85
82
  //#region src/hooks/use-extension.d.ts
86
83
  interface UseExtensionOptions {
@@ -98,7 +95,6 @@ interface UseExtensionOptions {
98
95
  * Add an extension to the editor.
99
96
  */
100
97
  declare function useExtension(extension: Extension | null, options?: UseExtensionOptions): void;
101
-
102
98
  //#endregion
103
99
  //#region src/hooks/use-doc-change.d.ts
104
100
  /**
@@ -107,7 +103,6 @@ declare function useExtension(extension: Extension | null, options?: UseExtensio
107
103
  * @public
108
104
  */
109
105
  declare function useDocChange(handler: (doc: ProseMirrorNode) => void, options?: UseExtensionOptions): void;
110
-
111
106
  //#endregion
112
107
  //#region src/hooks/use-editor.d.ts
113
108
  /**
@@ -120,15 +115,37 @@ declare function useEditor<E extends Extension = any>(options?: {
120
115
  * Whether to update the component when the editor is mounted or editor state
121
116
  * is updated.
122
117
  *
118
+ * Note this this option doesn't work with [React
119
+ * compiler](https://react.dev/learn/react-compiler) because the returned
120
+ * editor will be the same instance after state updates. If you're using React
121
+ * compiler, you should use {@link useEditorDerivedValue} instead.
122
+ *
123
123
  * @default false
124
124
  */
125
125
  update?: boolean;
126
126
  }): Editor<E>;
127
-
127
+ //#endregion
128
+ //#region src/hooks/use-editor-derived-value.d.ts
129
+ interface UseEditorDerivedOptions<E extends Extension = any> {
130
+ /**
131
+ * The editor to add the extension to. If not provided, it will use the
132
+ * editor from the nearest `ProseKit` component.
133
+ */
134
+ editor?: Editor<E>;
135
+ }
136
+ /**
137
+ * A hook that runs a function to derive a value from the editor instance after
138
+ * editor state changes.
139
+ *
140
+ * This is useful when you need to render something based on the editor state,
141
+ * for example, whether the selected text is wrapped in an italic mark.
142
+ *
143
+ * @public
144
+ */
145
+ declare function useEditorDerivedValue<E extends Extension, Derived>(derive: (editor: Editor<E>) => Derived, options?: UseEditorDerivedOptions<E>): Derived;
128
146
  //#endregion
129
147
  //#region src/hooks/use-keymap.d.ts
130
148
  declare function useKeymap(keymap: Keymap, options?: UseExtensionOptions): void;
131
-
132
149
  //#endregion
133
150
  //#region src/hooks/use-state-update.d.ts
134
151
  /**
@@ -137,7 +154,6 @@ declare function useKeymap(keymap: Keymap, options?: UseExtensionOptions): void;
137
154
  * @public
138
155
  */
139
156
  declare function useStateUpdate(handler: (state: EditorState) => void, options?: UseExtensionOptions): void;
140
-
141
157
  //#endregion
142
158
  //#region src/types.d.ts
143
159
  /**
@@ -146,6 +162,5 @@ declare function useStateUpdate(handler: (state: EditorState) => void, options?:
146
162
  type PropsWithClassName<P = unknown> = P & {
147
163
  className?: string | undefined;
148
164
  };
149
-
150
165
  //#endregion
151
- export { PropsWithClassName, ProseKit, ProseKitProps, ReactMarkViewComponent, ReactMarkViewOptions, ReactMarkViewProps, ReactNodeViewComponent, ReactNodeViewOptions, ReactNodeViewProps, UseExtensionOptions, defineReactMarkView, defineReactNodeView, useDocChange, useEditor, useExtension, useKeymap, useStateUpdate };
166
+ export { PropsWithClassName, ProseKit, ProseKitProps, ReactMarkViewComponent, ReactMarkViewOptions, ReactMarkViewProps, ReactNodeViewComponent, ReactNodeViewOptions, ReactNodeViewProps, UseEditorDerivedOptions, UseExtensionOptions, defineReactMarkView, defineReactNodeView, useDocChange, useEditor, useEditorDerivedValue, useExtension, useKeymap, useStateUpdate };
@@ -1,6 +1,6 @@
1
1
  import { EditorContextProvider, useEditorContext } from "./editor-context-Cci4uqN_.js";
2
2
  import { ProsemirrorAdapterProvider, useMarkViewContext, useMarkViewFactory, useNodeViewContext, useNodeViewFactory } from "@prosemirror-adapter/react";
3
- import { createElement, useEffect, useMemo, useReducer } from "react";
3
+ import { createElement, useEffect, useMemo, useReducer, useSyncExternalStore } from "react";
4
4
  import { EditorNotFoundError, ProseKitError, defineDocChangeHandler, defineKeymap, defineMarkViewComponent, defineMarkViewFactory, defineMountHandler, defineNodeViewComponent, defineNodeViewFactory, defineUpdateHandler, union, withPriority } from "@prosekit/core";
5
5
 
6
6
  //#region src/hooks/use-editor-extension.ts
@@ -170,6 +170,47 @@ function useForceUpdate() {
170
170
  return dispatch;
171
171
  }
172
172
 
173
+ //#endregion
174
+ //#region src/hooks/use-editor-derived-value.ts
175
+ /**
176
+ * A hook that runs a function to derive a value from the editor instance after
177
+ * editor state changes.
178
+ *
179
+ * This is useful when you need to render something based on the editor state,
180
+ * for example, whether the selected text is wrapped in an italic mark.
181
+ *
182
+ * @public
183
+ */
184
+ function useEditorDerivedValue(derive, options) {
185
+ const editorContext = useEditorContext();
186
+ const editor = options?.editor ?? editorContext;
187
+ if (!editor) throw new EditorNotFoundError();
188
+ const [subscribe, getSnapshot] = useMemo(() => {
189
+ return createEditorStore(editor, derive);
190
+ }, [editor, derive]);
191
+ return useSyncExternalStore(subscribe, getSnapshot);
192
+ }
193
+ function createEditorStore(editor, derive) {
194
+ let dirty = true;
195
+ let derived;
196
+ const subscribe = (onChange) => {
197
+ const handleChange = () => {
198
+ dirty = true;
199
+ onChange();
200
+ };
201
+ const extension = union(defineUpdateHandler(handleChange), defineMountHandler(handleChange));
202
+ return editor.use(extension);
203
+ };
204
+ const getSnapshot = () => {
205
+ if (dirty) {
206
+ dirty = false;
207
+ derived = derive(editor);
208
+ }
209
+ return derived;
210
+ };
211
+ return [subscribe, getSnapshot];
212
+ }
213
+
173
214
  //#endregion
174
215
  //#region src/hooks/use-keymap.ts
175
216
  function useKeymap(keymap, options) {
@@ -190,4 +231,4 @@ function useStateUpdate(handler, options) {
190
231
  }
191
232
 
192
233
  //#endregion
193
- export { ProseKit, defineReactMarkView, defineReactNodeView, useDocChange, useEditor, useExtension, useKeymap, useStateUpdate };
234
+ export { ProseKit, defineReactMarkView, defineReactNodeView, useDocChange, useEditor, useEditorDerivedValue, useExtension, useKeymap, useStateUpdate };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/react",
3
3
  "type": "module",
4
- "version": "0.4.13",
4
+ "version": "0.5.0",
5
5
  "private": false,
6
6
  "description": "React components and utilities for ProseKit",
7
7
  "author": {
@@ -65,10 +65,9 @@
65
65
  "dependencies": {
66
66
  "@prosemirror-adapter/core": "^0.4.0",
67
67
  "@prosemirror-adapter/react": "^0.4.1",
68
- "react-merge-refs": "^3.0.1",
69
68
  "@prosekit/core": "^0.8.1",
70
69
  "@prosekit/pm": "^0.1.10",
71
- "@prosekit/web": "^0.5.8"
70
+ "@prosekit/web": "^0.5.9"
72
71
  },
73
72
  "peerDependencies": {
74
73
  "react": ">= 18.2.0",
@@ -83,13 +82,13 @@
83
82
  }
84
83
  },
85
84
  "devDependencies": {
86
- "@types/react": "^19.1.3",
87
- "@types/react-dom": "^19.1.3",
85
+ "@types/react": "^19.1.6",
86
+ "@types/react-dom": "^19.1.5",
88
87
  "react": "^19.1.0",
89
88
  "react-dom": "^19.1.0",
90
- "tsdown": "^0.11.1",
89
+ "tsdown": "^0.12.5",
91
90
  "typescript": "~5.8.3",
92
- "vitest": "^3.1.3",
91
+ "vitest": "^3.1.4",
93
92
  "@prosekit/config-tsdown": "0.0.0",
94
93
  "@prosekit/config-vitest": "0.0.0"
95
94
  },