@prosekit/web 0.2.3 → 0.3.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.
@@ -11,6 +11,7 @@ import { Editor } from '@prosekit/core';
11
11
  import type { EditorView } from '@prosekit/pm/view';
12
12
  import { Extension } from '@prosekit/core';
13
13
  import { FocusChangeHandler } from '@prosekit/core';
14
+ import { Keymap } from '@prosekit/core';
14
15
  import { ListboxProps } from '@aria-ui/listbox';
15
16
  import { Options } from 'tsup';
16
17
  import type { OverlayPositionerProps } from '@aria-ui/overlay';
@@ -321,6 +322,7 @@ declare const defaultInlinePopoverProps: Readonly<{
321
322
  defaultOpen: true;
322
323
  open: false;
323
324
  onOpenChange: null;
325
+ dismissOnEscape: true;
324
326
  placement: "top";
325
327
  offset: 12;
326
328
  shift: true;
@@ -445,17 +447,26 @@ declare interface InlinePopoverProps extends Omit<OverlayPositionerProps, 'place
445
447
  /**
446
448
  * Whether the popover is open.
447
449
  *
448
- * Notice that the popover will be always hidden if the inline selection is empty.
450
+ * Notice that the popover will be always hidden if the inline selection is
451
+ * empty.
449
452
  *
450
453
  * @default false
451
454
  */
452
455
  open: boolean;
453
456
  /**
454
- * Event handler called when the open state changed caused by user interaction (i.e. select or unselect inline content).
457
+ * Event handler called when the open state changed caused by user interaction
458
+ * (i.e. select or unselect inline content).
455
459
  *
456
460
  * @default null
457
461
  */
458
462
  onOpenChange: ((open: boolean) => void) | null;
463
+ /**
464
+ * Whether the inline popover should be dismissed when the editor receives an
465
+ * Escape key press.
466
+ *
467
+ * @default true
468
+ */
469
+ dismissOnEscape: boolean;
459
470
  /**
460
471
  * The placement of the popover, relative to the selected inline content.
461
472
  *
@@ -694,6 +705,8 @@ export declare function useFirstRendering(host: ConnectableElement): ReadonlySig
694
705
 
695
706
  export declare function useInlinePopover(host: ConnectableElement, state: SignalState<InlinePopoverProps>): void;
696
707
 
708
+ export declare function useKeymap(host: ConnectableElement, editor: ReadonlySignal<Editor | null>, keymap: Keymap): void;
709
+
697
710
  export { usePopoverContent }
698
711
 
699
712
  export { usePopoverRoot }
@@ -16,6 +16,7 @@ var defaultInlinePopoverProps = Object.freeze({
16
16
  defaultOpen: !0,
17
17
  open: !1,
18
18
  onOpenChange: null,
19
+ dismissOnEscape: !0,
19
20
  placement: "top",
20
21
  offset: 12,
21
22
  shift: !0,
@@ -55,6 +56,13 @@ function useEditorUpdateEvent(host, editor, handler) {
55
56
  useEditorExtension(host, editor, extension);
56
57
  }
57
58
 
59
+ // src/hooks/use-keymap.ts
60
+ import { defineKeymap } from "@prosekit/core";
61
+ function useKeymap(host, editor, keymap) {
62
+ let extension = defineKeymap(keymap);
63
+ return useEditorExtension(host, editor, extension);
64
+ }
65
+
58
66
  // src/components/inline-popover/inline-popover/virtual-selection-element.ts
59
67
  import { isTextSelection } from "@prosekit/core";
60
68
 
@@ -114,6 +122,11 @@ function useInlinePopover(host, state) {
114
122
  }), useEffect(host, () => {
115
123
  let hasReferenceValue = hasReference.get(), defaultOpenValue = defaultOpen.peek();
116
124
  hasReferenceValue && defaultOpenValue ? open.set(!0) : hasReferenceValue || open.set(!1);
125
+ }), useKeymap(host, editor, {
126
+ Escape: () => {
127
+ var _a;
128
+ return !state.dismissOnEscape.get() || !open.get() ? !1 : (open.set(!1), (_a = onOpenChange.peek()) == null || _a(!1), !0);
129
+ }
117
130
  }), useOverlayPositionerState(host, overlayState, { reference }), useAttribute(host, "data-state", () => open.get() ? "open" : "closed"), usePresence(host, open);
118
131
  }
119
132
  function useInlinePopoverReference(host, editor) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/web",
3
3
  "type": "module",
4
- "version": "0.2.3",
4
+ "version": "0.3.0",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -75,8 +75,8 @@
75
75
  "@floating-ui/dom": "^1.6.7",
76
76
  "@zag-js/dom-query": "^0.60.0",
77
77
  "@prosekit/core": "^0.7.1",
78
- "@prosekit/pm": "^0.1.5",
79
- "@prosekit/extensions": "^0.7.1"
78
+ "@prosekit/extensions": "^0.7.1",
79
+ "@prosekit/pm": "^0.1.5"
80
80
  },
81
81
  "devDependencies": {
82
82
  "tsup": "^8.1.0",