@prosekit/web 0.3.3 → 0.3.5

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.
@@ -22,7 +22,6 @@ import { PopoverTriggerProps } from '@aria-ui/popover';
22
22
  import type { ProseMirrorNode } from '@prosekit/pm/model';
23
23
  import { ReadonlySignal } from '@aria-ui/core';
24
24
  import type { ReferenceElement } from '@floating-ui/dom';
25
- import type { Selection as Selection_2 } from '@prosekit/pm/state';
26
25
  import { SignalState } from '@aria-ui/core';
27
26
  import type { TooltipContentProps } from '@aria-ui/tooltip';
28
27
  import { TooltipRootProps } from '@aria-ui/tooltip';
@@ -414,7 +413,7 @@ Commands: never;
414
413
 
415
414
  export declare type ElementHoverHandler = (reference: VirtualElement | null, element: HTMLElement | null, node: ProseMirrorNode | null, pos: number | null) => void;
416
415
 
417
- export declare function getVirtualSelectionElement(view: EditorView): ReferenceElement | null;
416
+ export declare function getVirtualSelectionElement(view: EditorView): ReferenceElement | undefined;
418
417
 
419
418
  declare class InlinePopoverElement extends InlinePopoverElement_base {
420
419
  }
@@ -503,8 +502,6 @@ export { InlinePopoverProps as InlinePopoverProps_alias_1 }
503
502
 
504
503
  export declare function isFinitePositiveNumber(value: unknown): value is number;
505
504
 
506
- export declare function isInCodeBlock(selection: Selection_2): boolean | undefined;
507
-
508
505
  export declare function omit<T extends Record<string, unknown>, K extends keyof T>(object: T, keys: K[]): Omit<T, K>;
509
506
 
510
507
  /**
@@ -64,38 +64,33 @@ function useKeymap(host, editor, keymap) {
64
64
  }
65
65
 
66
66
  // src/components/inline-popover/inline-popover/virtual-selection-element.ts
67
- import { isTextSelection } from "@prosekit/core";
68
-
69
- // src/utils/is-in-code-block.ts
70
- function isInCodeBlock(selection) {
71
- const type = selection.$from.parent.type;
72
- return type.spec.code && type.isBlock;
73
- }
74
-
75
- // src/components/inline-popover/inline-popover/virtual-selection-element.ts
67
+ import {
68
+ containsInlineNode,
69
+ isInCodeBlock,
70
+ isTextSelection
71
+ } from "@prosekit/core";
76
72
  function getVirtualSelectionElement(view) {
77
73
  if (typeof window === "undefined" || view.isDestroyed) {
78
- return null;
74
+ return;
79
75
  }
80
76
  const selection = view.state.selection;
81
- if (!selection.empty && !isInCodeBlock(selection) && isTextSelection(selection)) {
82
- const decoration = getInlineDecoration(view);
83
- if (decoration) {
84
- return decoration;
85
- }
86
- const range = getDomRange();
87
- if (range) {
88
- return {
89
- contextElement: view.dom,
90
- getBoundingClientRect: () => range.getBoundingClientRect(),
91
- getClientRects: () => range.getClientRects()
92
- };
93
- }
77
+ if (!selection.empty && !isInCodeBlock(selection) && isTextSelection(selection) && containsInlineNode(view.state.doc, selection.from, selection.to)) {
78
+ return getDomDecoration(view) || getInlineDecoration(view);
79
+ }
80
+ }
81
+ function getDomDecoration(view) {
82
+ const range = getDomRange(view);
83
+ if (range) {
84
+ return {
85
+ contextElement: view.dom,
86
+ getBoundingClientRect: () => range.getBoundingClientRect(),
87
+ getClientRects: () => range.getClientRects()
88
+ };
94
89
  }
95
- return null;
96
90
  }
97
- function getDomRange() {
98
- const selection = window.getSelection();
91
+ function getDomRange(view) {
92
+ const win = view.dom.ownerDocument.defaultView;
93
+ const selection = win == null ? void 0 : win.getSelection();
99
94
  if (!selection || selection.isCollapsed) {
100
95
  return;
101
96
  }
@@ -170,7 +165,7 @@ function useInlinePopoverReference(host, editor) {
170
165
  if (isPopoverFocused) {
171
166
  return;
172
167
  }
173
- reference.set(getVirtualSelectionElement(view));
168
+ reference.set(getVirtualSelectionElement(view) || null);
174
169
  });
175
170
  return reference;
176
171
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/web",
3
3
  "type": "module",
4
- "version": "0.3.3",
4
+ "version": "0.3.5",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -73,15 +73,15 @@
73
73
  "@aria-ui/presence": "^0.0.13",
74
74
  "@aria-ui/tooltip": "^0.0.21",
75
75
  "@floating-ui/dom": "^1.6.7",
76
- "@zag-js/dom-query": "^0.61.0",
77
- "@prosekit/core": "^0.7.3",
78
- "@prosekit/extensions": "^0.7.3",
79
- "@prosekit/pm": "^0.1.6"
76
+ "@zag-js/dom-query": "^0.61.1",
77
+ "@prosekit/core": "^0.7.5",
78
+ "@prosekit/extensions": "^0.7.5",
79
+ "@prosekit/pm": "^0.1.7"
80
80
  },
81
81
  "devDependencies": {
82
- "tsup": "^8.1.0",
82
+ "tsup": "^8.1.2",
83
83
  "typescript": "^5.5.3",
84
- "vitest": "^2.0.2",
84
+ "vitest": "^2.0.3",
85
85
  "@prosekit/dev": "0.0.0"
86
86
  },
87
87
  "scripts": {