@prosekit/lit 0.1.3 → 0.1.4
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.
- package/dist/_tsup-dts-rollup.d.ts +305 -59
- package/dist/{chunk-6P3YKUWI.js → chunk-5CI65R73.js} +2 -2
- package/dist/chunk-L6FOAZFL.js +51 -0
- package/dist/chunk-MLUELLVA.js +60 -0
- package/dist/{chunk-IDDQA3VV.js → chunk-PW3MTUZM.js} +1 -0
- package/dist/chunk-S32IZIQF.js +33 -0
- package/dist/{chunk-66YTZIW6.js → chunk-TGJAVLMZ.js} +46 -40
- package/dist/{chunk-7WLKD2U6.js → chunk-Z3PEQ6MW.js} +81 -41
- package/dist/prosekit-lit-autocomplete-empty.js +14 -14
- package/dist/prosekit-lit-autocomplete-item.js +3 -3
- package/dist/prosekit-lit-autocomplete-list.js +5 -5
- package/dist/prosekit-lit-autocomplete-popover.js +53 -50
- package/dist/prosekit-lit-combo-box-input.js +39 -26
- package/dist/prosekit-lit-combo-box-item.js +2 -2
- package/dist/prosekit-lit-combo-box-list.js +12 -16
- package/dist/prosekit-lit-combo-box.js +60 -44
- package/dist/prosekit-lit-inline-popover.js +23 -18
- package/dist/prosekit-lit-popover.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-55G7TJI3.js +0 -48
- package/dist/chunk-M6MY5WGM.js +0 -62
- package/dist/chunk-O5JP3B34.js +0 -31
@@ -0,0 +1,33 @@
|
|
1
|
+
// src/utils/define-custom-element.ts
|
2
|
+
function defineCustomElement(name, constructor, options) {
|
3
|
+
if (typeof customElements === "undefined") {
|
4
|
+
return;
|
5
|
+
}
|
6
|
+
customElements.define(name, constructor, options);
|
7
|
+
}
|
8
|
+
|
9
|
+
// src/components/block-element/index.ts
|
10
|
+
import { LitElement } from "lit";
|
11
|
+
var LightElement = class extends LitElement {
|
12
|
+
/**
|
13
|
+
* @hidden
|
14
|
+
*/
|
15
|
+
constructor() {
|
16
|
+
super();
|
17
|
+
}
|
18
|
+
createRenderRoot() {
|
19
|
+
return this;
|
20
|
+
}
|
21
|
+
setHidden(hidden) {
|
22
|
+
if (this.hidden !== hidden) {
|
23
|
+
this.hidden = hidden;
|
24
|
+
const display = this.style.display;
|
25
|
+
this.style.display = hidden ? "none" : display === "none" ? "" : display;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
export {
|
31
|
+
defineCustomElement,
|
32
|
+
LightElement
|
33
|
+
};
|
@@ -1,25 +1,24 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
} from "./chunk-
|
2
|
+
autocompleteListContext
|
3
|
+
} from "./chunk-5CI65R73.js";
|
4
4
|
import {
|
5
5
|
ListManager
|
6
|
-
} from "./chunk-
|
6
|
+
} from "./chunk-PW3MTUZM.js";
|
7
7
|
import {
|
8
8
|
LightElement,
|
9
|
-
|
10
|
-
} from "./chunk-
|
9
|
+
defineCustomElement
|
10
|
+
} from "./chunk-S32IZIQF.js";
|
11
11
|
|
12
12
|
// src/components/autocomplete-popover/context.ts
|
13
13
|
import { createContext } from "@lit/context";
|
14
|
-
var
|
14
|
+
var autocompletePopoverContext = createContext(
|
15
15
|
"prosekit-autocomplete-popover-context"
|
16
16
|
);
|
17
17
|
|
18
18
|
// src/components/autocomplete-list/component.ts
|
19
|
-
import {
|
19
|
+
import { ContextConsumer, ContextProvider } from "@lit/context";
|
20
20
|
import "@prosekit/core";
|
21
21
|
import "lit";
|
22
|
-
import { customElement, property, state } from "lit/decorators.js";
|
23
22
|
|
24
23
|
// src/utils/command-score.ts
|
25
24
|
import commandScoreModule from "@superhuman/command-score";
|
@@ -87,41 +86,51 @@ var propNames = ["editor"];
|
|
87
86
|
var AutocompleteList = class extends LightElement {
|
88
87
|
constructor() {
|
89
88
|
super(...arguments);
|
90
|
-
/**
|
89
|
+
/**
|
90
|
+
* @hidden
|
91
|
+
*/
|
91
92
|
this.listManager = new ListManager({
|
92
93
|
getItems: () => this.items,
|
93
|
-
getSelectedValue: () => this.context.selectedValue,
|
94
|
+
getSelectedValue: () => this.context.value.selectedValue,
|
94
95
|
setSelectedValue: (value, reason) => this.updateValue(value, reason),
|
95
96
|
getItemValue: (item) => item.content,
|
96
97
|
queryClosestItem: queryClosestAutocompleteItem,
|
97
98
|
getActive: () => this.active,
|
98
99
|
onDismiss: () => {
|
99
100
|
var _a, _b;
|
100
|
-
return (_b = (_a = this.popoverContext) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
|
101
|
+
return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
|
101
102
|
},
|
102
103
|
onSelect: (item) => {
|
103
104
|
var _a, _b, _c;
|
104
|
-
(_b = (_a = this.popoverContext) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
|
105
|
+
(_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
|
105
106
|
(_c = item == null ? void 0 : item.onSelect) == null ? void 0 : _c.call(item);
|
106
107
|
}
|
107
108
|
});
|
108
|
-
/**
|
109
|
+
/**
|
110
|
+
* @hidden
|
111
|
+
*/
|
109
112
|
this.controller = new AutocompleteListController(this, {
|
110
113
|
ArrowUp: () => this.listManager.handleArrowUp(),
|
111
114
|
ArrowDown: () => this.listManager.handleArrowDown(),
|
112
115
|
Escape: () => this.listManager.handleEscape(),
|
113
116
|
Enter: () => this.listManager.handleEnter()
|
114
117
|
});
|
115
|
-
this.popoverContext =
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
this.popoverContext = new ContextConsumer(this, {
|
119
|
+
context: autocompletePopoverContext,
|
120
|
+
subscribe: true
|
121
|
+
});
|
122
|
+
this.context = new ContextProvider(this, {
|
123
|
+
context: autocompleteListContext,
|
124
|
+
initialValue: {
|
125
|
+
scores: /* @__PURE__ */ new Map(),
|
126
|
+
selectedValue: "",
|
127
|
+
selectedReason: "keyboard"
|
128
|
+
}
|
129
|
+
});
|
121
130
|
}
|
122
131
|
get active() {
|
123
132
|
var _a, _b;
|
124
|
-
return (_b = (_a = this.popoverContext) == null ? void 0 : _a.active) != null ? _b : false;
|
133
|
+
return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.active) != null ? _b : false;
|
125
134
|
}
|
126
135
|
connectedCallback() {
|
127
136
|
super.connectedCallback();
|
@@ -148,18 +157,21 @@ var AutocompleteList = class extends LightElement {
|
|
148
157
|
this.listManager.selectFirstItem();
|
149
158
|
}
|
150
159
|
updateValue(selectedValue, selectedReason) {
|
151
|
-
|
160
|
+
const context = this.context.value;
|
161
|
+
if (context.selectedValue === selectedValue) {
|
152
162
|
return;
|
153
163
|
}
|
154
|
-
this.context
|
164
|
+
this.context.setValue({ ...context, selectedValue, selectedReason });
|
155
165
|
}
|
156
|
-
/**
|
166
|
+
/**
|
167
|
+
* @hidden
|
168
|
+
*/
|
157
169
|
willUpdate(changedProperties) {
|
158
170
|
var _a, _b;
|
159
171
|
if (changedProperties.has("editor") && this.editor) {
|
160
172
|
this.controller.setEditor(this.editor);
|
161
173
|
}
|
162
|
-
const query = (_b = (_a = this.popoverContext) == null ? void 0 : _a.query) != null ? _b : "";
|
174
|
+
const query = (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.query) != null ? _b : "";
|
163
175
|
const scores = new Map(
|
164
176
|
this.items.map((item) => {
|
165
177
|
const content = item.content;
|
@@ -167,26 +179,20 @@ var AutocompleteList = class extends LightElement {
|
|
167
179
|
return [content, score];
|
168
180
|
})
|
169
181
|
);
|
170
|
-
|
182
|
+
const context = this.context.value;
|
183
|
+
this.context.setValue({ ...context, scores });
|
171
184
|
}
|
172
185
|
};
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
__decorateClass([
|
181
|
-
provide({ context: commandListContext }),
|
182
|
-
state()
|
183
|
-
], AutocompleteList.prototype, "context", 2);
|
184
|
-
AutocompleteList = __decorateClass([
|
185
|
-
customElement("prosekit-autocomplete-list")
|
186
|
-
], AutocompleteList);
|
186
|
+
/**
|
187
|
+
* @hidden
|
188
|
+
*/
|
189
|
+
AutocompleteList.properties = {
|
190
|
+
editor: { attribute: false }
|
191
|
+
};
|
192
|
+
defineCustomElement("prosekit-autocomplete-list", AutocompleteList);
|
187
193
|
|
188
194
|
export {
|
189
|
-
|
195
|
+
autocompletePopoverContext,
|
190
196
|
propNames,
|
191
197
|
AutocompleteList
|
192
198
|
};
|
@@ -1,14 +1,17 @@
|
|
1
1
|
import {
|
2
2
|
LightElement,
|
3
|
-
|
4
|
-
} from "./chunk-
|
3
|
+
defineCustomElement
|
4
|
+
} from "./chunk-S32IZIQF.js";
|
5
5
|
|
6
6
|
// src/components/popover/index.ts
|
7
7
|
import {
|
8
8
|
autoUpdate,
|
9
9
|
computePosition
|
10
10
|
} from "@floating-ui/dom";
|
11
|
-
|
11
|
+
|
12
|
+
// src/utils/popover-api.ts
|
13
|
+
var popoverAvailable = typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("popover");
|
14
|
+
var boundary = popoverAvailable && typeof document !== "undefined" && document.body || void 0;
|
12
15
|
|
13
16
|
// src/utils/round-by-dpr.ts
|
14
17
|
function roundByDPR(value) {
|
@@ -17,17 +20,25 @@ function roundByDPR(value) {
|
|
17
20
|
}
|
18
21
|
|
19
22
|
// src/components/popover/default-popover-options.ts
|
20
|
-
import {
|
23
|
+
import {
|
24
|
+
offset,
|
25
|
+
shift,
|
26
|
+
size
|
27
|
+
} from "@floating-ui/dom";
|
21
28
|
|
22
29
|
// src/components/popover/options.ts
|
23
30
|
import "@floating-ui/dom";
|
24
31
|
|
25
32
|
// src/components/popover/default-popover-options.ts
|
33
|
+
var defaultDetectOverflowOptions = {
|
34
|
+
padding: 8,
|
35
|
+
boundary
|
36
|
+
};
|
26
37
|
var defaultPopoverOptions = {
|
27
38
|
placement: "bottom",
|
28
39
|
middleware: [
|
29
40
|
offset({ mainAxis: 8, crossAxis: 8 }),
|
30
|
-
shift({
|
41
|
+
shift({ ...defaultDetectOverflowOptions }),
|
31
42
|
size({
|
32
43
|
apply: ({ availableWidth, availableHeight, elements }) => {
|
33
44
|
elements.floating.style.setProperty(
|
@@ -39,7 +50,7 @@ var defaultPopoverOptions = {
|
|
39
50
|
`${Math.floor(availableHeight)}px`
|
40
51
|
);
|
41
52
|
},
|
42
|
-
|
53
|
+
...defaultDetectOverflowOptions
|
43
54
|
})
|
44
55
|
]
|
45
56
|
};
|
@@ -53,11 +64,36 @@ var propNames = [
|
|
53
64
|
"autoUpdateOptions"
|
54
65
|
];
|
55
66
|
var Popover = class extends LightElement {
|
56
|
-
/** @hidden */
|
57
67
|
constructor() {
|
58
|
-
super();
|
68
|
+
super(...arguments);
|
69
|
+
/**
|
70
|
+
* Controls the visibility of the popover element. When set to `true`, the
|
71
|
+
* popover is displayed and positioned relative to its reference element. When
|
72
|
+
* set to `false`, the popover is hidden and its positioning logic is
|
73
|
+
* deactivated.
|
74
|
+
*/
|
59
75
|
this.active = false;
|
76
|
+
/**
|
77
|
+
* Controls whether the popover position is automatically updated when the
|
78
|
+
* reference element changes position. When set to `true`, the popover
|
79
|
+
* position is updated automatically. When set to `false`, the popover
|
80
|
+
* position is only updated when the given properties are changed.
|
81
|
+
*
|
82
|
+
* @default false
|
83
|
+
*/
|
60
84
|
this.autoUpdate = false;
|
85
|
+
/**
|
86
|
+
* Controls whether the popover should be dismissed based on user interaction.
|
87
|
+
*
|
88
|
+
* Available options:
|
89
|
+
*
|
90
|
+
* - "off": The popover is not dismissed.
|
91
|
+
* - "on": The popover is dismissed when the user clicks outside of the popover or presses the escape key.
|
92
|
+
* - "click": The popover is dismissed when the user clicks outside of the popover.
|
93
|
+
* - "escape": The popover is dismissed when the user presses the escape key.
|
94
|
+
*
|
95
|
+
* @default "on"
|
96
|
+
*/
|
61
97
|
this.dismiss = "on";
|
62
98
|
this.handleDocumentMouseDown = (event) => {
|
63
99
|
const path = event.composedPath();
|
@@ -73,7 +109,9 @@ var Popover = class extends LightElement {
|
|
73
109
|
}
|
74
110
|
};
|
75
111
|
}
|
76
|
-
/**
|
112
|
+
/**
|
113
|
+
* @hidden
|
114
|
+
*/
|
77
115
|
connectedCallback() {
|
78
116
|
super.connectedCallback();
|
79
117
|
const clickEnabled = this.dismiss === "on" || this.dismiss === "click";
|
@@ -87,7 +125,9 @@ var Popover = class extends LightElement {
|
|
87
125
|
handleKeyDown && document.removeEventListener("keydown", handleKeyDown);
|
88
126
|
};
|
89
127
|
}
|
90
|
-
/**
|
128
|
+
/**
|
129
|
+
* @hidden
|
130
|
+
*/
|
91
131
|
disconnectedCallback() {
|
92
132
|
var _a, _b;
|
93
133
|
super.disconnectedCallback();
|
@@ -96,13 +136,22 @@ var Popover = class extends LightElement {
|
|
96
136
|
(_b = this.disposeEventListeners) == null ? void 0 : _b.call(this);
|
97
137
|
this.disposeEventListeners = void 0;
|
98
138
|
}
|
99
|
-
/**
|
139
|
+
/**
|
140
|
+
* @hidden
|
141
|
+
*/
|
100
142
|
updated(changedProperties) {
|
143
|
+
var _a;
|
101
144
|
super.updated(changedProperties);
|
145
|
+
if (popoverAvailable) {
|
146
|
+
this.popover = "manual";
|
147
|
+
(_a = this.togglePopover) == null ? void 0 : _a.call(this, this.active);
|
148
|
+
}
|
102
149
|
this.start();
|
103
150
|
this.setHidden(!this.active);
|
104
151
|
}
|
105
|
-
/**
|
152
|
+
/**
|
153
|
+
* @hidden
|
154
|
+
*/
|
106
155
|
start() {
|
107
156
|
var _a;
|
108
157
|
(_a = this.disposeAutoUpdate) == null ? void 0 : _a.call(this);
|
@@ -123,7 +172,9 @@ var Popover = class extends LightElement {
|
|
123
172
|
void this.compute();
|
124
173
|
}
|
125
174
|
}
|
126
|
-
/**
|
175
|
+
/**
|
176
|
+
* @hidden
|
177
|
+
*/
|
127
178
|
async compute() {
|
128
179
|
var _a, _b, _c;
|
129
180
|
const reference = this.reference;
|
@@ -132,6 +183,7 @@ var Popover = class extends LightElement {
|
|
132
183
|
if (!this.active)
|
133
184
|
return;
|
134
185
|
this.setHidden(false);
|
186
|
+
this.style.setProperty("margin", "0");
|
135
187
|
this.style.setProperty("top", "0");
|
136
188
|
this.style.setProperty("left", "0");
|
137
189
|
this.style.setProperty("position", (_b = (_a = this.options) == null ? void 0 : _a.strategy) != null ? _b : "absolute");
|
@@ -145,40 +197,28 @@ var Popover = class extends LightElement {
|
|
145
197
|
`translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`
|
146
198
|
);
|
147
199
|
}
|
148
|
-
/**
|
200
|
+
/**
|
201
|
+
* @hidden
|
202
|
+
*/
|
149
203
|
hide() {
|
150
204
|
this.active = false;
|
151
205
|
}
|
152
206
|
};
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
reflect: true
|
166
|
-
})
|
167
|
-
], Popover.prototype, "autoUpdate", 2);
|
168
|
-
__decorateClass([
|
169
|
-
property({ type: Object })
|
170
|
-
], Popover.prototype, "autoUpdateOptions", 2);
|
171
|
-
__decorateClass([
|
172
|
-
property({
|
173
|
-
type: String,
|
174
|
-
reflect: true
|
175
|
-
})
|
176
|
-
], Popover.prototype, "dismiss", 2);
|
177
|
-
Popover = __decorateClass([
|
178
|
-
customElement("prosekit-popover")
|
179
|
-
], Popover);
|
207
|
+
/**
|
208
|
+
* @hidden
|
209
|
+
*/
|
210
|
+
Popover.properties = {
|
211
|
+
active: { type: Boolean, reflect: true },
|
212
|
+
reference: { attribute: false },
|
213
|
+
options: { attribute: false },
|
214
|
+
autoUpdate: { type: Boolean, reflect: true },
|
215
|
+
autoUpdateOptions: { type: Object },
|
216
|
+
dismiss: { type: String, reflect: true }
|
217
|
+
};
|
218
|
+
defineCustomElement("prosekit-popover", Popover);
|
180
219
|
|
181
220
|
export {
|
221
|
+
boundary,
|
182
222
|
propNames,
|
183
223
|
Popover
|
184
224
|
};
|
@@ -1,24 +1,30 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
} from "./chunk-
|
2
|
+
autocompleteListContext
|
3
|
+
} from "./chunk-5CI65R73.js";
|
4
4
|
import {
|
5
5
|
LightElement,
|
6
|
-
|
7
|
-
} from "./chunk-
|
6
|
+
defineCustomElement
|
7
|
+
} from "./chunk-S32IZIQF.js";
|
8
8
|
|
9
9
|
// src/components/autocomplete-empty/index.ts
|
10
|
-
import {
|
10
|
+
import { ContextConsumer } from "@lit/context";
|
11
11
|
import "lit";
|
12
|
-
import { customElement, state } from "lit/decorators.js";
|
13
12
|
var propNames = [];
|
14
13
|
var AutocompleteEmpty = class extends LightElement {
|
14
|
+
constructor() {
|
15
|
+
super(...arguments);
|
16
|
+
this.listContext = new ContextConsumer(this, {
|
17
|
+
context: autocompleteListContext,
|
18
|
+
subscribe: true
|
19
|
+
});
|
20
|
+
}
|
15
21
|
connectedCallback() {
|
16
22
|
super.connectedCallback();
|
17
23
|
this.role = "option";
|
18
24
|
}
|
19
25
|
willUpdate(_changedProperties) {
|
20
26
|
var _a;
|
21
|
-
const scores = (_a = this.listContext) == null ? void 0 : _a.scores;
|
27
|
+
const scores = (_a = this.listContext.value) == null ? void 0 : _a.scores;
|
22
28
|
let hasMatch = false;
|
23
29
|
if (scores) {
|
24
30
|
for (const score of scores.values()) {
|
@@ -31,13 +37,7 @@ var AutocompleteEmpty = class extends LightElement {
|
|
31
37
|
this.setHidden(hasMatch);
|
32
38
|
}
|
33
39
|
};
|
34
|
-
|
35
|
-
consume({ context: commandListContext, subscribe: true }),
|
36
|
-
state()
|
37
|
-
], AutocompleteEmpty.prototype, "listContext", 2);
|
38
|
-
AutocompleteEmpty = __decorateClass([
|
39
|
-
customElement("prosekit-autocomplete-empty")
|
40
|
-
], AutocompleteEmpty);
|
40
|
+
defineCustomElement("prosekit-autocomplete-empty", AutocompleteEmpty);
|
41
41
|
export {
|
42
42
|
AutocompleteEmpty,
|
43
43
|
propNames
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import {
|
2
2
|
AutocompleteItem,
|
3
3
|
propNames
|
4
|
-
} from "./chunk-
|
5
|
-
import "./chunk-
|
6
|
-
import "./chunk-
|
4
|
+
} from "./chunk-MLUELLVA.js";
|
5
|
+
import "./chunk-5CI65R73.js";
|
6
|
+
import "./chunk-S32IZIQF.js";
|
7
7
|
export {
|
8
8
|
AutocompleteItem,
|
9
9
|
propNames
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import {
|
2
2
|
AutocompleteList,
|
3
3
|
propNames
|
4
|
-
} from "./chunk-
|
5
|
-
import "./chunk-
|
6
|
-
import "./chunk-
|
7
|
-
import "./chunk-
|
8
|
-
import "./chunk-
|
4
|
+
} from "./chunk-TGJAVLMZ.js";
|
5
|
+
import "./chunk-MLUELLVA.js";
|
6
|
+
import "./chunk-5CI65R73.js";
|
7
|
+
import "./chunk-PW3MTUZM.js";
|
8
|
+
import "./chunk-S32IZIQF.js";
|
9
9
|
export {
|
10
10
|
AutocompleteList,
|
11
11
|
propNames
|
@@ -1,20 +1,20 @@
|
|
1
1
|
import {
|
2
|
-
|
3
|
-
} from "./chunk-
|
4
|
-
import "./chunk-
|
5
|
-
import "./chunk-
|
2
|
+
autocompletePopoverContext
|
3
|
+
} from "./chunk-TGJAVLMZ.js";
|
4
|
+
import "./chunk-MLUELLVA.js";
|
5
|
+
import "./chunk-5CI65R73.js";
|
6
6
|
import {
|
7
|
-
Popover
|
8
|
-
|
9
|
-
|
7
|
+
Popover,
|
8
|
+
boundary
|
9
|
+
} from "./chunk-Z3PEQ6MW.js";
|
10
|
+
import "./chunk-PW3MTUZM.js";
|
10
11
|
import {
|
11
|
-
|
12
|
-
} from "./chunk-
|
12
|
+
defineCustomElement
|
13
|
+
} from "./chunk-S32IZIQF.js";
|
13
14
|
|
14
15
|
// src/components/autocomplete-popover/index.ts
|
15
|
-
import {
|
16
|
+
import { ContextProvider } from "@lit/context";
|
16
17
|
import "@prosekit/core";
|
17
|
-
import { customElement, property, state } from "lit/decorators.js";
|
18
18
|
|
19
19
|
// src/components/autocomplete-list/helpers.ts
|
20
20
|
function isAutocompleteList(element) {
|
@@ -114,8 +114,8 @@ import {
|
|
114
114
|
size
|
115
115
|
} from "@floating-ui/dom";
|
116
116
|
var defaultDetectOverflowOptions = {
|
117
|
-
|
118
|
-
|
117
|
+
padding: 8,
|
118
|
+
boundary
|
119
119
|
};
|
120
120
|
var defaultPopoverOptions = {
|
121
121
|
// The main axis is the y axis, and we place the popover at the bottom of the
|
@@ -127,10 +127,10 @@ var defaultPopoverOptions = {
|
|
127
127
|
middleware: [
|
128
128
|
// Use the text caret as the reference point
|
129
129
|
inline(),
|
130
|
-
offset(
|
130
|
+
offset({
|
131
131
|
// Move down the popover by 4px
|
132
132
|
mainAxis: 4
|
133
|
-
})
|
133
|
+
}),
|
134
134
|
// Flip the popover to the top if it's overflowing the viewport
|
135
135
|
//
|
136
136
|
// When `flipAlignment` is true, which is the default, ensure `flip() `is
|
@@ -170,40 +170,49 @@ var propNames = ["editor", "regex", "popoverOptions"];
|
|
170
170
|
var AutocompletePopover = class extends Popover {
|
171
171
|
constructor() {
|
172
172
|
super(...arguments);
|
173
|
-
/**
|
173
|
+
/**
|
174
|
+
* @hidden
|
175
|
+
*/
|
174
176
|
this.controller = new AutocompletePopoverController(
|
175
177
|
this,
|
176
178
|
this.updateContext.bind(this)
|
177
179
|
);
|
178
180
|
this.popoverOptions = defaultPopoverOptions;
|
179
|
-
this.context = {
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
181
|
+
this.context = new ContextProvider(this, {
|
182
|
+
context: autocompletePopoverContext,
|
183
|
+
initialValue: {
|
184
|
+
active: false,
|
185
|
+
query: "",
|
186
|
+
handleDismiss: () => {
|
187
|
+
var _a, _b;
|
188
|
+
return (_b = (_a = this.controller).handleDismiss) == null ? void 0 : _b.call(_a);
|
189
|
+
},
|
190
|
+
handleSubmit: () => {
|
191
|
+
var _a, _b;
|
192
|
+
return (_b = (_a = this.controller).handleSubmit) == null ? void 0 : _b.call(_a);
|
193
|
+
}
|
189
194
|
}
|
190
|
-
};
|
195
|
+
});
|
191
196
|
}
|
192
197
|
get list() {
|
193
198
|
const element = this.querySelector("prosekit-autocomplete-list");
|
194
199
|
return isAutocompleteList(element) ? element : null;
|
195
200
|
}
|
196
201
|
updateContext(query, active) {
|
197
|
-
|
202
|
+
const context = this.context.value;
|
203
|
+
if (context.query === query && context.active === active) {
|
198
204
|
return;
|
199
205
|
}
|
200
|
-
this.context
|
206
|
+
this.context.setValue({ ...context, query, active });
|
207
|
+
this.requestUpdate();
|
201
208
|
requestAnimationFrame(() => {
|
202
209
|
var _a;
|
203
210
|
(_a = this.list) == null ? void 0 : _a.selectFirstItem();
|
204
211
|
});
|
205
212
|
}
|
206
|
-
/**
|
213
|
+
/**
|
214
|
+
* @hidden
|
215
|
+
*/
|
207
216
|
willUpdate(changedProperties) {
|
208
217
|
var _a, _b;
|
209
218
|
super.willUpdate(changedProperties);
|
@@ -217,7 +226,9 @@ var AutocompletePopover = class extends Popover {
|
|
217
226
|
this.reference = (_b = this.controller.reference) != null ? _b : void 0;
|
218
227
|
this.options = this.popoverOptions;
|
219
228
|
}
|
220
|
-
/**
|
229
|
+
/**
|
230
|
+
* @hidden
|
231
|
+
*/
|
221
232
|
hide() {
|
222
233
|
var _a;
|
223
234
|
super.hide();
|
@@ -227,25 +238,17 @@ var AutocompletePopover = class extends Popover {
|
|
227
238
|
}
|
228
239
|
}
|
229
240
|
};
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
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);
|
241
|
+
/**
|
242
|
+
* @hidden
|
243
|
+
*/
|
244
|
+
AutocompletePopover.properties = {
|
245
|
+
...Popover.properties,
|
246
|
+
editor: { attribute: false },
|
247
|
+
regex: { attribute: false },
|
248
|
+
popoverOptions: { attribute: false },
|
249
|
+
onSelect: { attribute: false }
|
250
|
+
};
|
251
|
+
defineCustomElement("prosekit-autocomplete-popover", AutocompletePopover);
|
249
252
|
export {
|
250
253
|
AutocompletePopover,
|
251
254
|
propNames
|