@prosekit/lit 0.0.0-next-20230709094459 → 0.0.0-next-20231120040948

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.
Files changed (42) hide show
  1. package/dist/_tsup-dts-rollup.d.ts +456 -0
  2. package/dist/chunk-55G7TJI3.js +48 -0
  3. package/dist/chunk-6P3YKUWI.js +9 -0
  4. package/dist/chunk-7WLKD2U6.js +184 -0
  5. package/dist/chunk-C4MW43I4.js +9 -0
  6. package/dist/chunk-GWGDLLFN.js +61 -0
  7. package/dist/{chunk-6FOWUXQ2.js → chunk-O5JP3B34.js} +15 -10
  8. package/dist/chunk-PCXKL6TA.js +109 -0
  9. package/dist/chunk-XBNMYITV.js +191 -0
  10. package/dist/prosekit-lit-autocomplete-empty.d.ts +3 -0
  11. package/dist/prosekit-lit-autocomplete-empty.js +44 -0
  12. package/dist/prosekit-lit-autocomplete-item.d.ts +3 -0
  13. package/dist/prosekit-lit-autocomplete-item.js +10 -0
  14. package/dist/prosekit-lit-autocomplete-list.d.ts +3 -0
  15. package/dist/prosekit-lit-autocomplete-list.js +12 -0
  16. package/dist/prosekit-lit-autocomplete-popover.d.ts +4 -0
  17. package/dist/prosekit-lit-autocomplete-popover.js +252 -0
  18. package/dist/prosekit-lit-combo-box-input.d.ts +3 -0
  19. package/dist/prosekit-lit-combo-box-input.js +72 -0
  20. package/dist/prosekit-lit-combo-box-item.d.ts +3 -0
  21. package/dist/prosekit-lit-combo-box-item.js +10 -0
  22. package/dist/prosekit-lit-combo-box-list.d.ts +3 -0
  23. package/dist/prosekit-lit-combo-box-list.js +48 -0
  24. package/dist/prosekit-lit-combo-box.d.ts +3 -0
  25. package/dist/prosekit-lit-combo-box.js +110 -0
  26. package/dist/prosekit-lit-inline-popover.d.ts +4 -0
  27. package/dist/prosekit-lit-inline-popover.js +154 -0
  28. package/dist/prosekit-lit-popover.d.ts +5 -0
  29. package/dist/prosekit-lit-popover.js +9 -0
  30. package/dist/prosekit-lit.d.ts +1 -2
  31. package/package.json +85 -38
  32. package/src/index.ts +0 -4
  33. package/dist/chunk-WHIPWT4H.js +0 -122
  34. package/dist/options-7235df55.d.ts +0 -14
  35. package/dist/prosekit-lit-elements-menu-item.d.ts +0 -16
  36. package/dist/prosekit-lit-elements-menu-item.js +0 -37
  37. package/dist/prosekit-lit-elements-menu.d.ts +0 -50
  38. package/dist/prosekit-lit-elements-menu.js +0 -169
  39. package/dist/prosekit-lit-elements-popover-suggestion.d.ts +0 -59
  40. package/dist/prosekit-lit-elements-popover-suggestion.js +0 -218
  41. package/dist/prosekit-lit-elements-popover.d.ts +0 -65
  42. package/dist/prosekit-lit-elements-popover.js +0 -7
@@ -0,0 +1,252 @@
1
+ import {
2
+ commandPopoverContext
3
+ } from "./chunk-XBNMYITV.js";
4
+ import "./chunk-GWGDLLFN.js";
5
+ import "./chunk-6P3YKUWI.js";
6
+ import {
7
+ Popover
8
+ } from "./chunk-7WLKD2U6.js";
9
+ import "./chunk-PCXKL6TA.js";
10
+ import {
11
+ __decorateClass
12
+ } from "./chunk-O5JP3B34.js";
13
+
14
+ // src/components/autocomplete-popover/index.ts
15
+ import { provide } from "@lit/context";
16
+ import "@prosekit/core";
17
+ import { customElement, property, state } from "lit/decorators.js";
18
+
19
+ // src/components/autocomplete-list/helpers.ts
20
+ function isAutocompleteList(element) {
21
+ var _a;
22
+ return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-autocomplete-list";
23
+ }
24
+
25
+ // src/components/autocomplete-popover/controller.ts
26
+ import "@prosekit/core";
27
+ import {
28
+ AutocompleteRule,
29
+ defineAutocomplete
30
+ } from "@prosekit/extensions/autocomplete";
31
+ import "lit";
32
+
33
+ // src/components/autocomplete-popover/helpers.ts
34
+ function defaultQueryBuilder(match) {
35
+ return match[0].toLowerCase().replace(/[!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]/g, "").replace(/\s\s+/g, " ").trim();
36
+ }
37
+
38
+ // src/components/autocomplete-popover/controller.ts
39
+ var AutocompletePopoverController = class {
40
+ constructor(host, onChange) {
41
+ this.host = host;
42
+ this.onChange = onChange;
43
+ this.reference = null;
44
+ this.editor = null;
45
+ this.regex = null;
46
+ this.cleanup = null;
47
+ this.handleDismiss = null;
48
+ this.handleSubmit = null;
49
+ this.host.addController(this);
50
+ }
51
+ setEditor(editor) {
52
+ if (this.editor !== editor) {
53
+ this.editor = editor;
54
+ this.defineExtension();
55
+ this.host.requestUpdate();
56
+ }
57
+ }
58
+ setRegex(regex) {
59
+ if (this.regex !== regex) {
60
+ this.regex = regex;
61
+ this.defineExtension();
62
+ this.host.requestUpdate();
63
+ }
64
+ }
65
+ defineExtension() {
66
+ var _a;
67
+ const regex = this.regex;
68
+ const editor = this.editor;
69
+ if (!regex || !editor) {
70
+ return;
71
+ }
72
+ (_a = this.cleanup) == null ? void 0 : _a.call(this);
73
+ this.cleanup = null;
74
+ const handleEnter = (options) => {
75
+ const span = editor.view.dom.querySelector(
76
+ ".prosemirror-prediction-match"
77
+ );
78
+ if (span) {
79
+ this.reference = span;
80
+ }
81
+ const query = defaultQueryBuilder(options.match);
82
+ this.onChange(query != null ? query : "", !!this.reference);
83
+ this.handleDismiss = options.ignoreMatch;
84
+ this.handleSubmit = options.deleteMatch;
85
+ };
86
+ const handleLeave = () => {
87
+ this.reference = null;
88
+ this.host.requestUpdate();
89
+ this.onChange("", false);
90
+ this.handleDismiss = null;
91
+ this.handleSubmit = null;
92
+ };
93
+ const rule = new AutocompleteRule({
94
+ regex,
95
+ onEnter: handleEnter,
96
+ onLeave: handleLeave
97
+ });
98
+ const extension = defineAutocomplete(rule);
99
+ this.cleanup = editor.use(extension);
100
+ }
101
+ hostDisconnected() {
102
+ var _a;
103
+ (_a = this.cleanup) == null ? void 0 : _a.call(this);
104
+ this.cleanup = null;
105
+ }
106
+ };
107
+
108
+ // src/components/autocomplete-popover/default-popover-options.ts
109
+ import {
110
+ flip,
111
+ inline,
112
+ offset,
113
+ shift,
114
+ size
115
+ } from "@floating-ui/dom";
116
+ var defaultDetectOverflowOptions = {
117
+ // Make sure the popover is always at least 8px away from the boundary
118
+ padding: 8
119
+ };
120
+ var defaultPopoverOptions = {
121
+ // The main axis is the y axis, and we place the popover at the bottom of the
122
+ // reference element.
123
+ //
124
+ // The cross axis is the x axis, and we place the popover at the start of the
125
+ // reference element. The reference element and the popover are left-aligned.
126
+ placement: "bottom-start",
127
+ middleware: [
128
+ // Use the text caret as the reference point
129
+ inline(),
130
+ offset(() => ({
131
+ // Move down the popover by 4px
132
+ mainAxis: 4
133
+ })),
134
+ // Flip the popover to the top if it's overflowing the viewport
135
+ //
136
+ // When `flipAlignment` is true, which is the default, ensure `flip() `is
137
+ // placed before `shift()` in your middleware array.
138
+ //
139
+ // https://floating-ui.com/docs/flip#flipalignment
140
+ flip({
141
+ // Flip the popover to the top if necessary.
142
+ mainAxis: true,
143
+ // We don't want to flip the popover to the left or right, since `shift()`
144
+ // will handle this.
145
+ crossAxis: false,
146
+ ...defaultDetectOverflowOptions
147
+ }),
148
+ // We need to place `shift()` after `flip()`. See https://floating-ui.com/docs/flip#flipalignment
149
+ shift({
150
+ ...defaultDetectOverflowOptions
151
+ }),
152
+ size({
153
+ apply: ({ availableWidth, availableHeight, elements }) => {
154
+ elements.floating.style.setProperty(
155
+ "max-width",
156
+ `${Math.floor(availableWidth)}px`
157
+ );
158
+ elements.floating.style.setProperty(
159
+ "max-height",
160
+ `${Math.floor(availableHeight)}px`
161
+ );
162
+ },
163
+ ...defaultDetectOverflowOptions
164
+ })
165
+ ]
166
+ };
167
+
168
+ // src/components/autocomplete-popover/index.ts
169
+ var propNames = ["editor", "regex", "popoverOptions"];
170
+ var AutocompletePopover = class extends Popover {
171
+ constructor() {
172
+ super(...arguments);
173
+ /** @hidden */
174
+ this.controller = new AutocompletePopoverController(
175
+ this,
176
+ this.updateContext.bind(this)
177
+ );
178
+ this.popoverOptions = defaultPopoverOptions;
179
+ this.context = {
180
+ active: false,
181
+ query: "",
182
+ handleDismiss: () => {
183
+ var _a, _b;
184
+ return (_b = (_a = this.controller).handleDismiss) == null ? void 0 : _b.call(_a);
185
+ },
186
+ handleSubmit: () => {
187
+ var _a, _b;
188
+ return (_b = (_a = this.controller).handleSubmit) == null ? void 0 : _b.call(_a);
189
+ }
190
+ };
191
+ }
192
+ get list() {
193
+ const element = this.querySelector("prosekit-autocomplete-list");
194
+ return isAutocompleteList(element) ? element : null;
195
+ }
196
+ updateContext(query, active) {
197
+ if (this.context.query === query && this.context.active === active) {
198
+ return;
199
+ }
200
+ this.context = { ...this.context, query, active };
201
+ requestAnimationFrame(() => {
202
+ var _a;
203
+ (_a = this.list) == null ? void 0 : _a.selectFirstItem();
204
+ });
205
+ }
206
+ /** @hidden */
207
+ willUpdate(changedProperties) {
208
+ var _a, _b;
209
+ super.willUpdate(changedProperties);
210
+ if (this.editor) {
211
+ this.controller.setEditor(this.editor);
212
+ }
213
+ if (this.regex) {
214
+ this.controller.setRegex(this.regex);
215
+ }
216
+ this.active = !!((_a = this.controller) == null ? void 0 : _a.reference);
217
+ this.reference = (_b = this.controller.reference) != null ? _b : void 0;
218
+ this.options = this.popoverOptions;
219
+ }
220
+ /** @hidden */
221
+ hide() {
222
+ var _a;
223
+ super.hide();
224
+ if ((_a = this.controller) == null ? void 0 : _a.reference) {
225
+ this.controller.reference = null;
226
+ this.reference = void 0;
227
+ }
228
+ }
229
+ };
230
+ __decorateClass([
231
+ property({ attribute: false })
232
+ ], AutocompletePopover.prototype, "editor", 2);
233
+ __decorateClass([
234
+ property({ attribute: false })
235
+ ], AutocompletePopover.prototype, "regex", 2);
236
+ __decorateClass([
237
+ property({ attribute: false })
238
+ ], AutocompletePopover.prototype, "popoverOptions", 2);
239
+ __decorateClass([
240
+ provide({ context: commandPopoverContext }),
241
+ state()
242
+ ], AutocompletePopover.prototype, "context", 2);
243
+ __decorateClass([
244
+ property({ attribute: false })
245
+ ], AutocompletePopover.prototype, "onSelect", 2);
246
+ AutocompletePopover = __decorateClass([
247
+ customElement("prosekit-autocomplete-popover")
248
+ ], AutocompletePopover);
249
+ export {
250
+ AutocompletePopover,
251
+ propNames
252
+ };
@@ -0,0 +1,3 @@
1
+ export { propNames_alias_7 as propNames } from './_tsup-dts-rollup';
2
+ export { ComboBoxInputProps } from './_tsup-dts-rollup';
3
+ export { ComboBoxInput } from './_tsup-dts-rollup';
@@ -0,0 +1,72 @@
1
+ import {
2
+ comboBoxContext
3
+ } from "./chunk-C4MW43I4.js";
4
+ import {
5
+ LightElement,
6
+ __decorateClass
7
+ } from "./chunk-O5JP3B34.js";
8
+
9
+ // src/components/combo-box-input/index.ts
10
+ import { consume } from "@lit/context";
11
+ import { html } from "lit";
12
+ import { customElement, property, state } from "lit/decorators.js";
13
+ var propNames = ["placeholder"];
14
+ var ComboBoxInput = class extends LightElement {
15
+ constructor() {
16
+ super(...arguments);
17
+ this.placeholder = "";
18
+ this.comboBoxContext = null;
19
+ this.visible = false;
20
+ }
21
+ handleKeydown(event) {
22
+ var _a, _b, _c, _d, _e, _f, _g, _h;
23
+ if (event.code === "ArrowUp") {
24
+ (_b = (_a = this.comboBoxContext) == null ? void 0 : _a.listManager) == null ? void 0 : _b.handleArrowUp();
25
+ } else if (event.code === "ArrowDown") {
26
+ (_d = (_c = this.comboBoxContext) == null ? void 0 : _c.listManager) == null ? void 0 : _d.handleArrowDown();
27
+ } else if (event.code === "Escape") {
28
+ (_f = (_e = this.comboBoxContext) == null ? void 0 : _e.listManager) == null ? void 0 : _f.handleEscape();
29
+ } else if (event.code === "Enter") {
30
+ (_h = (_g = this.comboBoxContext) == null ? void 0 : _g.listManager) == null ? void 0 : _h.handleEnter();
31
+ }
32
+ }
33
+ handleInput(event) {
34
+ var _a, _b, _c;
35
+ const value = (_b = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.value) != null ? _b : "";
36
+ (_c = this.comboBoxContext) == null ? void 0 : _c.setInputValue(value);
37
+ }
38
+ firstUpdated() {
39
+ const resizeObserver = new ResizeObserver((entries) => {
40
+ const visible = entries.some(
41
+ (entry) => entry.contentRect.width > 0 && entry.contentRect.width > 0
42
+ );
43
+ if (this.visible !== visible && visible) {
44
+ setTimeout(() => {
45
+ var _a;
46
+ return (_a = this.querySelector("input")) == null ? void 0 : _a.focus();
47
+ }, 0);
48
+ }
49
+ this.visible = visible;
50
+ });
51
+ resizeObserver.observe(this);
52
+ }
53
+ /** @hidden */
54
+ render() {
55
+ var _a, _b;
56
+ return html`<input placeholder="${this.placeholder}" @keydown="${(event) => this.handleKeydown(event)}" @input="${(event) => this.handleInput(event)}" value="${(_b = (_a = this.comboBoxContext) == null ? void 0 : _a.inputValue) != null ? _b : ""}">`;
57
+ }
58
+ };
59
+ __decorateClass([
60
+ property({ attribute: true })
61
+ ], ComboBoxInput.prototype, "placeholder", 2);
62
+ __decorateClass([
63
+ consume({ context: comboBoxContext, subscribe: true }),
64
+ state()
65
+ ], ComboBoxInput.prototype, "comboBoxContext", 2);
66
+ ComboBoxInput = __decorateClass([
67
+ customElement("prosekit-combo-box-input")
68
+ ], ComboBoxInput);
69
+ export {
70
+ ComboBoxInput,
71
+ propNames
72
+ };
@@ -0,0 +1,3 @@
1
+ export { ComboBoxItem_alias_1 as ComboBoxItem } from './_tsup-dts-rollup';
2
+ export { ComboBoxItemProps_alias_1 as ComboBoxItemProps } from './_tsup-dts-rollup';
3
+ export { propNames_alias_9 as propNames } from './_tsup-dts-rollup';
@@ -0,0 +1,10 @@
1
+ import {
2
+ ComboBoxItem,
3
+ propNames
4
+ } from "./chunk-55G7TJI3.js";
5
+ import "./chunk-C4MW43I4.js";
6
+ import "./chunk-O5JP3B34.js";
7
+ export {
8
+ ComboBoxItem,
9
+ propNames
10
+ };
@@ -0,0 +1,3 @@
1
+ export { ComboBoxList_alias_1 as ComboBoxList } from './_tsup-dts-rollup';
2
+ export { ComboBoxListProps_alias_1 as ComboBoxListProps } from './_tsup-dts-rollup';
3
+ export { propNames_alias_11 as propNames } from './_tsup-dts-rollup';
@@ -0,0 +1,48 @@
1
+ import {
2
+ comboBoxContext
3
+ } from "./chunk-C4MW43I4.js";
4
+ import {
5
+ LightElement,
6
+ __decorateClass
7
+ } from "./chunk-O5JP3B34.js";
8
+
9
+ // src/components/combo-box-list/component.ts
10
+ import { consume } from "@lit/context";
11
+ import { customElement, state } from "lit/decorators.js";
12
+ var propNames = [];
13
+ var ComboBoxList = class extends LightElement {
14
+ constructor() {
15
+ super(...arguments);
16
+ this.comboBoxContext = null;
17
+ }
18
+ connectedCallback() {
19
+ super.connectedCallback();
20
+ this.addEventListener("mousemove", (event) => {
21
+ var _a;
22
+ (_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleMouseMove(event);
23
+ });
24
+ this.addEventListener("mouseover", (event) => {
25
+ var _a;
26
+ (_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleMouseOver(event);
27
+ });
28
+ this.addEventListener("mousedown", (event) => {
29
+ var _a;
30
+ (_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleMouseDown(event);
31
+ });
32
+ this.addEventListener("click", (event) => {
33
+ var _a;
34
+ (_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleClick(event);
35
+ });
36
+ }
37
+ };
38
+ __decorateClass([
39
+ consume({ context: comboBoxContext, subscribe: true }),
40
+ state()
41
+ ], ComboBoxList.prototype, "comboBoxContext", 2);
42
+ ComboBoxList = __decorateClass([
43
+ customElement("prosekit-combo-box-list")
44
+ ], ComboBoxList);
45
+ export {
46
+ ComboBoxList,
47
+ propNames
48
+ };
@@ -0,0 +1,3 @@
1
+ export { propNames_alias_6 as propNames } from './_tsup-dts-rollup';
2
+ export { ComboBoxProps } from './_tsup-dts-rollup';
3
+ export { ComboBox } from './_tsup-dts-rollup';
@@ -0,0 +1,110 @@
1
+ import {
2
+ Popover
3
+ } from "./chunk-7WLKD2U6.js";
4
+ import {
5
+ ListManager
6
+ } from "./chunk-PCXKL6TA.js";
7
+ import "./chunk-55G7TJI3.js";
8
+ import {
9
+ comboBoxContext
10
+ } from "./chunk-C4MW43I4.js";
11
+ import {
12
+ __decorateClass
13
+ } from "./chunk-O5JP3B34.js";
14
+
15
+ // src/components/combo-box/index.ts
16
+ import { provide } from "@lit/context";
17
+ import { customElement, property, state } from "lit/decorators.js";
18
+
19
+ // src/components/combo-box-item/helpers.ts
20
+ function isComboBoxItem(element) {
21
+ var _a;
22
+ return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-combo-box-item";
23
+ }
24
+ function queryClosestComboBoxItem(element) {
25
+ if (!element) {
26
+ return null;
27
+ }
28
+ if (isComboBoxItem(element)) {
29
+ return element;
30
+ }
31
+ const item = element.closest("prosekit-combo-box-item");
32
+ if (isComboBoxItem(item)) {
33
+ return item;
34
+ }
35
+ return null;
36
+ }
37
+
38
+ // src/components/combo-box/index.ts
39
+ var propNames = ["onDismiss"];
40
+ var ComboBox = class extends Popover {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.listManager = new ListManager({
44
+ getItems: () => {
45
+ return this.items;
46
+ },
47
+ getSelectedValue: () => {
48
+ var _a;
49
+ return ((_a = this.context.selectedValue) != null ? _a : "").trim();
50
+ },
51
+ setSelectedValue: (value) => {
52
+ return this.context.setSelectedValue(value);
53
+ },
54
+ getItemValue: (item) => {
55
+ var _a;
56
+ return ((_a = item.textContent) != null ? _a : "").trim();
57
+ },
58
+ queryClosestItem: queryClosestComboBoxItem,
59
+ getActive: () => {
60
+ return true;
61
+ },
62
+ onDismiss: () => {
63
+ var _a;
64
+ (_a = this.onDismiss) == null ? void 0 : _a.call(this);
65
+ },
66
+ onSelect: (item) => {
67
+ var _a, _b;
68
+ this.context.setSelectedValue("");
69
+ this.context.setInputValue("");
70
+ (_a = item == null ? void 0 : item.onSelect) == null ? void 0 : _a.call(item);
71
+ (_b = this.onDismiss) == null ? void 0 : _b.call(this);
72
+ }
73
+ });
74
+ this.context = {
75
+ inputValue: "",
76
+ setInputValue: (inputValue) => {
77
+ if (this.context.inputValue === inputValue) {
78
+ return;
79
+ }
80
+ this.context = { ...this.context, inputValue };
81
+ },
82
+ selectedValue: "",
83
+ setSelectedValue: (selectedValue) => {
84
+ if (this.context.selectedValue === selectedValue) {
85
+ return;
86
+ }
87
+ this.context = { ...this.context, selectedValue };
88
+ },
89
+ listManager: this.listManager
90
+ };
91
+ }
92
+ get items() {
93
+ const items = this.querySelectorAll("\u220Fprosekit-combo-box-item");
94
+ return Array.from(items).filter(isComboBoxItem);
95
+ }
96
+ };
97
+ __decorateClass([
98
+ property({ attribute: false })
99
+ ], ComboBox.prototype, "onDismiss", 2);
100
+ __decorateClass([
101
+ provide({ context: comboBoxContext }),
102
+ state()
103
+ ], ComboBox.prototype, "context", 2);
104
+ ComboBox = __decorateClass([
105
+ customElement("prosekit-combo-box")
106
+ ], ComboBox);
107
+ export {
108
+ ComboBox,
109
+ propNames
110
+ };
@@ -0,0 +1,4 @@
1
+ export { PopoverOptions_alias_1 as PopoverOptions } from './_tsup-dts-rollup';
2
+ export { propNames_alias_12 as propNames } from './_tsup-dts-rollup';
3
+ export { InlinePopoverProps } from './_tsup-dts-rollup';
4
+ export { InlinePopover } from './_tsup-dts-rollup';
@@ -0,0 +1,154 @@
1
+ import {
2
+ Popover
3
+ } from "./chunk-7WLKD2U6.js";
4
+ import {
5
+ __decorateClass
6
+ } from "./chunk-O5JP3B34.js";
7
+
8
+ // src/components/inline-popover/index.ts
9
+ import "@prosekit/core";
10
+ import { customElement, property } from "lit/decorators.js";
11
+
12
+ // src/components/inline-popover/controller.ts
13
+ import { defineUpdateHandler } from "@prosekit/core";
14
+ import "lit";
15
+
16
+ // src/components/inline-popover/helpers.ts
17
+ import { isNodeSelection, isTextSelection } from "@prosekit/core";
18
+ function getVirtualSelectionElement(view) {
19
+ if (typeof window === "undefined" || view.isDestroyed) {
20
+ return;
21
+ }
22
+ const selection = view.state.selection;
23
+ if (!selection.empty && (isTextSelection(selection) || isNodeSelection(selection))) {
24
+ return getDomRange();
25
+ }
26
+ }
27
+ function getDomRange() {
28
+ const selection = window.getSelection();
29
+ if (!selection || selection.isCollapsed) {
30
+ return;
31
+ }
32
+ const range = typeof selection.rangeCount === "number" && selection.rangeCount > 0 && selection.getRangeAt(0);
33
+ if (!range) {
34
+ return;
35
+ }
36
+ return range;
37
+ }
38
+
39
+ // src/components/inline-popover/controller.ts
40
+ var InlinePopoverController = class {
41
+ constructor(host) {
42
+ this.host = host;
43
+ this.mouseHovering = false;
44
+ this.host.addController(this);
45
+ }
46
+ setEditor(editor) {
47
+ if (this.editor !== editor) {
48
+ this.editor = editor;
49
+ this.defineExtension();
50
+ this.host.requestUpdate();
51
+ }
52
+ }
53
+ hostConnected() {
54
+ var _a;
55
+ const handleMouseDown = () => {
56
+ this.mouseHovering = true;
57
+ };
58
+ const handleMouseUp = () => {
59
+ this.mouseHovering = false;
60
+ this.update();
61
+ };
62
+ document.addEventListener("mousedown", handleMouseDown);
63
+ document.addEventListener("mouseup", handleMouseUp);
64
+ (_a = this.cleanupEventListener) == null ? void 0 : _a.call(this);
65
+ this.cleanupEventListener = () => {
66
+ document.removeEventListener("mousedown", handleMouseDown);
67
+ document.removeEventListener("mouseup", handleMouseUp);
68
+ };
69
+ }
70
+ hostDisconnected() {
71
+ var _a, _b;
72
+ (_a = this.cleanupExtension) == null ? void 0 : _a.call(this);
73
+ this.cleanupExtension = void 0;
74
+ (_b = this.cleanupEventListener) == null ? void 0 : _b.call(this);
75
+ this.cleanupEventListener = void 0;
76
+ }
77
+ update() {
78
+ const editor = this.editor;
79
+ if (!editor || this.mouseHovering) {
80
+ return;
81
+ }
82
+ const reference = getVirtualSelectionElement(editor.view);
83
+ if (this.reference !== reference) {
84
+ this.reference = reference;
85
+ this.host.requestUpdate();
86
+ }
87
+ }
88
+ defineExtension() {
89
+ var _a;
90
+ const editor = this.editor;
91
+ if (!editor) {
92
+ return;
93
+ }
94
+ const extension = defineUpdateHandler(() => this.update());
95
+ (_a = this.cleanupExtension) == null ? void 0 : _a.call(this);
96
+ this.cleanupExtension = editor.use(extension);
97
+ }
98
+ };
99
+
100
+ // src/components/inline-popover/default-popover-options.ts
101
+ import { inline, offset, shift } from "@floating-ui/dom";
102
+ var defaultPopoverOptions = {
103
+ placement: "top",
104
+ strategy: "absolute",
105
+ middleware: [
106
+ inline(),
107
+ offset(8),
108
+ shift({ mainAxis: true, crossAxis: true, padding: 8 })
109
+ ]
110
+ };
111
+
112
+ // src/components/inline-popover/index.ts
113
+ var propNames = ["editor", "popoverOptions"];
114
+ var InlinePopover = class extends Popover {
115
+ constructor() {
116
+ super();
117
+ /** @hidden */
118
+ this.controller = new InlinePopoverController(this);
119
+ this.popoverOptions = defaultPopoverOptions;
120
+ this.dismiss = "escape";
121
+ }
122
+ /** @hidden */
123
+ willUpdate() {
124
+ var _a, _b;
125
+ if (this.editor) {
126
+ this.controller.setEditor(this.editor);
127
+ }
128
+ this.active = !!((_a = this.controller) == null ? void 0 : _a.reference);
129
+ this.reference = (_b = this.controller.reference) != null ? _b : void 0;
130
+ this.options = this.popoverOptions;
131
+ }
132
+ /** @hidden */
133
+ hide() {
134
+ var _a;
135
+ super.hide();
136
+ if ((_a = this.controller) == null ? void 0 : _a.reference) {
137
+ this.controller.reference = void 0;
138
+ this.reference = void 0;
139
+ }
140
+ }
141
+ };
142
+ __decorateClass([
143
+ property({ attribute: false })
144
+ ], InlinePopover.prototype, "editor", 2);
145
+ __decorateClass([
146
+ property({ attribute: false })
147
+ ], InlinePopover.prototype, "popoverOptions", 2);
148
+ InlinePopover = __decorateClass([
149
+ customElement("prosekit-inline-popover")
150
+ ], InlinePopover);
151
+ export {
152
+ InlinePopover,
153
+ propNames
154
+ };
@@ -0,0 +1,5 @@
1
+ export { AutoUpdateOptions } from './_tsup-dts-rollup';
2
+ export { PopoverOptions_alias_2 as PopoverOptions } from './_tsup-dts-rollup';
3
+ export { propNames_alias_13 as propNames } from './_tsup-dts-rollup';
4
+ export { PopoverProps } from './_tsup-dts-rollup';
5
+ export { Popover } from './_tsup-dts-rollup';
@@ -0,0 +1,9 @@
1
+ import {
2
+ Popover,
3
+ propNames
4
+ } from "./chunk-7WLKD2U6.js";
5
+ import "./chunk-O5JP3B34.js";
6
+ export {
7
+ Popover,
8
+ propNames
9
+ };
@@ -1,2 +1 @@
1
-
2
- export { }
1
+ export {};