@dxos/react-ui-editor 0.3.11-main.668f0ff → 0.3.11-main.9bacd9f

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,61 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { type Extension } from '@codemirror/state';
6
- import { hoverTooltip } from '@codemirror/view';
7
-
8
- import { tooltipContent } from '@dxos/react-ui-theme';
9
-
10
- const markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
11
-
12
- export type TooltipOptions = {
13
- onHover: (el: Element, url: string) => void;
14
- regexp?: RegExp;
15
- };
16
-
17
- /**
18
- * https://codemirror.net/examples/tooltip
19
- * https://codemirror.net/docs/ref/#view.hoverTooltip
20
- * https://github.com/codemirror/view/blob/main/src/tooltip.ts
21
- */
22
- export const tooltip = ({ onHover, regexp = markdownLinkRegexp }: TooltipOptions): Extension =>
23
- hoverTooltip((view, pos) => {
24
- const { from, text } = view.state.doc.lineAt(pos);
25
- const p = pos - from;
26
-
27
- let idx = 0;
28
- let match;
29
- do {
30
- match = text.substring(idx).match(regexp);
31
- if (!match) {
32
- match = undefined;
33
- break;
34
- }
35
-
36
- idx = text.indexOf(match[0]);
37
- if (p >= idx && p < idx + match[0].length) {
38
- break;
39
- }
40
-
41
- idx += match[0].length;
42
- } while (true);
43
-
44
- if (!match) {
45
- return null;
46
- }
47
-
48
- const [, , url] = match ?? [];
49
-
50
- return {
51
- pos: idx + from,
52
- end: idx + from + match[0].length,
53
- above: true,
54
- create: () => {
55
- const el = document.createElement('div');
56
- el.className = tooltipContent({}, 'pli-2 plb-1');
57
- onHover(el, url);
58
- return { dom: el, offset: { x: 0, y: 4 } };
59
- },
60
- };
61
- });