@prosekit/lit 0.2.7 → 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.
- package/dist/_tsup-dts-rollup.d.ts +27 -1088
- package/dist/prosekit-lit-autocomplete.d.ts +4 -0
- package/dist/prosekit-lit-autocomplete.js +11 -0
- package/dist/prosekit-lit-block-handle.d.ts +2 -0
- package/dist/prosekit-lit-block-handle.js +7 -0
- package/dist/prosekit-lit-inline-popover.d.ts +0 -3
- package/dist/prosekit-lit-inline-popover.js +2 -190
- package/dist/prosekit-lit-popover.d.ts +3 -6
- package/dist/prosekit-lit-popover.js +7 -8
- package/dist/prosekit-lit-resizable.d.ts +2 -3
- package/dist/prosekit-lit-resizable.js +5 -108
- package/dist/prosekit-lit-tooltip.d.ts +3 -0
- package/dist/prosekit-lit-tooltip.js +9 -0
- package/package.json +24 -95
- package/dist/chunk-3AZDRLDR.js +0 -39
- package/dist/chunk-3TPE2GKD.js +0 -51
- package/dist/chunk-5CI65R73.js +0 -9
- package/dist/chunk-C4MW43I4.js +0 -9
- package/dist/chunk-CPC45JQ7.js +0 -202
- package/dist/chunk-I5EMQRE4.js +0 -60
- package/dist/chunk-MZAHIYA5.js +0 -114
- package/dist/chunk-S72UTR5M.js +0 -9
- package/dist/chunk-WEUGKLVB.js +0 -9
- package/dist/chunk-XHBZNZ2L.js +0 -369
- package/dist/prosekit-lit-autocomplete-empty.d.ts +0 -3
- package/dist/prosekit-lit-autocomplete-empty.js +0 -44
- package/dist/prosekit-lit-autocomplete-item.d.ts +0 -3
- package/dist/prosekit-lit-autocomplete-item.js +0 -10
- package/dist/prosekit-lit-autocomplete-list.d.ts +0 -3
- package/dist/prosekit-lit-autocomplete-list.js +0 -12
- package/dist/prosekit-lit-autocomplete-popover.d.ts +0 -4
- package/dist/prosekit-lit-autocomplete-popover.js +0 -199
- package/dist/prosekit-lit-block-popover.d.ts +0 -3
- package/dist/prosekit-lit-block-popover.js +0 -169
- package/dist/prosekit-lit-combo-box-input.d.ts +0 -3
- package/dist/prosekit-lit-combo-box-input.js +0 -92
- package/dist/prosekit-lit-combo-box-item.d.ts +0 -3
- package/dist/prosekit-lit-combo-box-item.js +0 -10
- package/dist/prosekit-lit-combo-box-list.d.ts +0 -3
- package/dist/prosekit-lit-combo-box-list.js +0 -44
- package/dist/prosekit-lit-combo-box.d.ts +0 -3
- package/dist/prosekit-lit-combo-box.js +0 -130
- package/dist/prosekit-lit-drag-handle.d.ts +0 -3
- package/dist/prosekit-lit-drag-handle.js +0 -94
- package/dist/prosekit-lit-resizable-handle.d.ts +0 -3
- package/dist/prosekit-lit-resizable-handle.js +0 -159
package/dist/chunk-XHBZNZ2L.js
DELETED
@@ -1,369 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
LightElement,
|
3
|
-
defineCustomElement
|
4
|
-
} from "./chunk-3AZDRLDR.js";
|
5
|
-
|
6
|
-
// src/components/popover/index.ts
|
7
|
-
import "@floating-ui/dom";
|
8
|
-
|
9
|
-
// src/controllers/use-dismissable.ts
|
10
|
-
import { trackDismissableElement } from "@zag-js/dismissable";
|
11
|
-
|
12
|
-
// src/utils/get-reference-context-element.ts
|
13
|
-
import { isHTMLElement } from "@zag-js/dom-query";
|
14
|
-
function getReferenceContextElement(reference) {
|
15
|
-
if (!reference) {
|
16
|
-
return null;
|
17
|
-
}
|
18
|
-
if (isHTMLElement(reference)) {
|
19
|
-
return reference;
|
20
|
-
}
|
21
|
-
const contextElement = reference.contextElement;
|
22
|
-
if (isHTMLElement(contextElement)) {
|
23
|
-
return contextElement;
|
24
|
-
}
|
25
|
-
return null;
|
26
|
-
}
|
27
|
-
|
28
|
-
// src/controllers/use-dismissable.ts
|
29
|
-
function useDismissable(host, {
|
30
|
-
onEscapeKeyDown,
|
31
|
-
onPointerDownOutside,
|
32
|
-
onDismiss,
|
33
|
-
getReference
|
34
|
-
}) {
|
35
|
-
let cleanup;
|
36
|
-
const hostConnected = () => {
|
37
|
-
cleanup == null ? void 0 : cleanup();
|
38
|
-
cleanup = trackDismissableElement(host, {
|
39
|
-
defer: false,
|
40
|
-
pointerBlocking: false,
|
41
|
-
exclude: () => {
|
42
|
-
return getReferenceContextElement(getReference == null ? void 0 : getReference());
|
43
|
-
},
|
44
|
-
onDismiss: () => {
|
45
|
-
onDismiss == null ? void 0 : onDismiss();
|
46
|
-
},
|
47
|
-
onEscapeKeyDown: (event) => {
|
48
|
-
onEscapeKeyDown(event);
|
49
|
-
},
|
50
|
-
onPointerDownOutside: (event) => {
|
51
|
-
onPointerDownOutside(event);
|
52
|
-
}
|
53
|
-
});
|
54
|
-
};
|
55
|
-
const hostDisconnected = () => {
|
56
|
-
cleanup == null ? void 0 : cleanup();
|
57
|
-
cleanup = void 0;
|
58
|
-
};
|
59
|
-
host.addController({ hostConnected, hostDisconnected });
|
60
|
-
}
|
61
|
-
|
62
|
-
// src/controllers/use-effect.ts
|
63
|
-
function useEffect(host, getValue, onChange) {
|
64
|
-
let value = getValue();
|
65
|
-
const hostUpdated = () => {
|
66
|
-
const v = getValue();
|
67
|
-
if (v !== value) {
|
68
|
-
value = v;
|
69
|
-
onChange(value);
|
70
|
-
}
|
71
|
-
};
|
72
|
-
host.addController({ hostUpdated });
|
73
|
-
}
|
74
|
-
|
75
|
-
// src/utils/popover-api.ts
|
76
|
-
var popoverAvailable = typeof HTMLElement !== "undefined" && HTMLElement.prototype.hasOwnProperty("popover");
|
77
|
-
var defaultBoundary = popoverAvailable && typeof document !== "undefined" && document.body || void 0;
|
78
|
-
|
79
|
-
// src/components/popover/get-placement.ts
|
80
|
-
import {
|
81
|
-
autoUpdate,
|
82
|
-
computePosition,
|
83
|
-
flip,
|
84
|
-
hide,
|
85
|
-
inline,
|
86
|
-
offset,
|
87
|
-
shift,
|
88
|
-
size
|
89
|
-
} from "@floating-ui/dom";
|
90
|
-
import { getWindow } from "@zag-js/dom-query";
|
91
|
-
import { runIfFn } from "@zag-js/utils";
|
92
|
-
function dpr(win, value) {
|
93
|
-
const dpr2 = win.devicePixelRatio || 1;
|
94
|
-
return Math.round(value * dpr2) / dpr2;
|
95
|
-
}
|
96
|
-
function _boundary(opts) {
|
97
|
-
return runIfFn(opts.boundary);
|
98
|
-
}
|
99
|
-
function _offset(opts) {
|
100
|
-
if (opts.offset == null)
|
101
|
-
return;
|
102
|
-
return offset(opts.offset);
|
103
|
-
}
|
104
|
-
function _flip(opts) {
|
105
|
-
if (!opts.flip)
|
106
|
-
return;
|
107
|
-
return flip({
|
108
|
-
boundary: _boundary(opts),
|
109
|
-
padding: opts.overflowPadding,
|
110
|
-
altBoundary: true,
|
111
|
-
fallbackPlacements: opts.flip === true ? void 0 : opts.flip
|
112
|
-
});
|
113
|
-
}
|
114
|
-
function _shift(opts) {
|
115
|
-
if (!opts.shift)
|
116
|
-
return;
|
117
|
-
return shift({
|
118
|
-
boundary: _boundary(opts),
|
119
|
-
padding: opts.overflowPadding,
|
120
|
-
altBoundary: true,
|
121
|
-
mainAxis: opts.shift,
|
122
|
-
crossAxis: opts.overlap
|
123
|
-
});
|
124
|
-
}
|
125
|
-
function _size(opts) {
|
126
|
-
return size({
|
127
|
-
boundary: _boundary(opts),
|
128
|
-
padding: opts.overflowPadding,
|
129
|
-
altBoundary: true,
|
130
|
-
apply({ elements, rects, availableHeight, availableWidth }) {
|
131
|
-
const floating = elements.floating;
|
132
|
-
const referenceWidth = Math.round(rects.reference.width);
|
133
|
-
availableWidth = Math.floor(availableWidth);
|
134
|
-
availableHeight = Math.floor(availableHeight);
|
135
|
-
floating.style.setProperty("--reference-width", `${referenceWidth}px`);
|
136
|
-
floating.style.setProperty("--available-width", `${availableWidth}px`);
|
137
|
-
floating.style.setProperty("--available-height", `${availableHeight}px`);
|
138
|
-
}
|
139
|
-
});
|
140
|
-
}
|
141
|
-
function _inline(opts) {
|
142
|
-
if (!opts.inline)
|
143
|
-
return;
|
144
|
-
return inline();
|
145
|
-
}
|
146
|
-
function _hide(opts) {
|
147
|
-
if (!opts.hide)
|
148
|
-
return;
|
149
|
-
return hide({
|
150
|
-
padding: opts.overflowPadding,
|
151
|
-
elementContext: "reference"
|
152
|
-
});
|
153
|
-
}
|
154
|
-
function getPlacement(reference, floating, options) {
|
155
|
-
if (!floating || !reference)
|
156
|
-
return;
|
157
|
-
const middleware = [
|
158
|
-
_offset(options),
|
159
|
-
_flip(options),
|
160
|
-
_shift(options),
|
161
|
-
_size(options),
|
162
|
-
_inline(options),
|
163
|
-
_hide(options)
|
164
|
-
];
|
165
|
-
const { placement, strategy } = options;
|
166
|
-
const update = async () => {
|
167
|
-
var _a, _b, _c;
|
168
|
-
if (!reference || !floating)
|
169
|
-
return;
|
170
|
-
const pos = await computePosition(reference, floating, {
|
171
|
-
placement,
|
172
|
-
middleware,
|
173
|
-
strategy
|
174
|
-
});
|
175
|
-
const hidden = ((_a = pos.middlewareData.hide) == null ? void 0 : _a.escaped) || ((_b = pos.middlewareData.hide) == null ? void 0 : _b.referenceHidden);
|
176
|
-
(_c = options.onComplete) == null ? void 0 : _c.call(options, pos);
|
177
|
-
const win = getWindow(floating);
|
178
|
-
const x = dpr(win, pos.x);
|
179
|
-
const y = dpr(win, pos.y);
|
180
|
-
floating.style.setProperty("--x", `${x}px`);
|
181
|
-
floating.style.setProperty("--y", `${y}px`);
|
182
|
-
floating.style.setProperty("opacity", hidden ? "0" : "1");
|
183
|
-
const contentEl = floating.firstElementChild;
|
184
|
-
if (contentEl) {
|
185
|
-
const zIndex = win.getComputedStyle(contentEl).zIndex;
|
186
|
-
floating.style.setProperty("--z-index", zIndex);
|
187
|
-
}
|
188
|
-
};
|
189
|
-
const autoUpdateOptions = typeof options.autoUpdate === "boolean" ? void 0 : options.autoUpdate;
|
190
|
-
const cancelAutoUpdate = options.autoUpdate ? autoUpdate(reference, floating, update, autoUpdateOptions) : void 0;
|
191
|
-
void update();
|
192
|
-
return () => {
|
193
|
-
var _a;
|
194
|
-
cancelAutoUpdate == null ? void 0 : cancelAutoUpdate();
|
195
|
-
(_a = options.onCleanup) == null ? void 0 : _a.call(options);
|
196
|
-
};
|
197
|
-
}
|
198
|
-
|
199
|
-
// src/components/popover/options.ts
|
200
|
-
var defaultOptions = {
|
201
|
-
strategy: "absolute",
|
202
|
-
placement: "bottom",
|
203
|
-
autoUpdate: true,
|
204
|
-
overflowPadding: 10,
|
205
|
-
flip: true,
|
206
|
-
shift: true,
|
207
|
-
overlap: false,
|
208
|
-
inline: false,
|
209
|
-
hide: true,
|
210
|
-
sameWidth: false,
|
211
|
-
fitViewport: false,
|
212
|
-
offset: 8,
|
213
|
-
boundary: defaultBoundary
|
214
|
-
};
|
215
|
-
|
216
|
-
// src/components/popover/set-floating-styles.ts
|
217
|
-
function setFloatingStyles(element, options) {
|
218
|
-
const { placement, sameWidth, fitViewport, strategy = "absolute" } = options;
|
219
|
-
element.style.position = strategy;
|
220
|
-
element.style.isolation = "isolate";
|
221
|
-
element.style.minWidth = sameWidth ? "" : "max-content";
|
222
|
-
element.style.width = sameWidth ? "var(--reference-width)" : "";
|
223
|
-
element.style.maxWidth = fitViewport ? "var(--available-width)" : "";
|
224
|
-
element.style.maxHeight = fitViewport ? "var(--available-height)" : "";
|
225
|
-
element.style.top = "0px";
|
226
|
-
element.style.left = "0px";
|
227
|
-
element.style.transform = placement ? "translate3d(var(--x), var(--y), 0)" : "translate3d(0, -100vh, 0)";
|
228
|
-
element.style.zIndex = "var(--z-index)";
|
229
|
-
}
|
230
|
-
|
231
|
-
// src/components/popover/use-popover.ts
|
232
|
-
function usePopover(host, getReference, getPositioning) {
|
233
|
-
let cleanup;
|
234
|
-
const hostUpdated = () => {
|
235
|
-
const reference = getReference();
|
236
|
-
const positioning = { ...defaultOptions, ...getPositioning() };
|
237
|
-
cleanup == null ? void 0 : cleanup();
|
238
|
-
cleanup = getPlacement(reference, host, {
|
239
|
-
...positioning,
|
240
|
-
onComplete: (data) => {
|
241
|
-
var _a;
|
242
|
-
(_a = positioning == null ? void 0 : positioning.onComplete) == null ? void 0 : _a.call(positioning, data);
|
243
|
-
setFloatingStyles(host, { ...positioning, placement: data.placement });
|
244
|
-
}
|
245
|
-
});
|
246
|
-
};
|
247
|
-
const hostDisconnected = () => {
|
248
|
-
cleanup == null ? void 0 : cleanup();
|
249
|
-
cleanup = void 0;
|
250
|
-
};
|
251
|
-
host.addController({ hostUpdated, hostDisconnected });
|
252
|
-
}
|
253
|
-
|
254
|
-
// src/components/popover/index.ts
|
255
|
-
var popoverPropsNames = [
|
256
|
-
"open",
|
257
|
-
"onOpenChange",
|
258
|
-
"reference",
|
259
|
-
"positioning"
|
260
|
-
];
|
261
|
-
var Popover = class extends LightElement {
|
262
|
-
/**
|
263
|
-
* @hidden
|
264
|
-
*/
|
265
|
-
constructor() {
|
266
|
-
super();
|
267
|
-
this.elevated = true;
|
268
|
-
useDismissable(this, {
|
269
|
-
onPointerDownOutside: (event) => {
|
270
|
-
var _a, _b;
|
271
|
-
(_b = (_a = this.positioning) == null ? void 0 : _a.onPointerDownOutside) == null ? void 0 : _b.call(_a, event);
|
272
|
-
if (!event.defaultPrevented) {
|
273
|
-
this.requestUpdate();
|
274
|
-
}
|
275
|
-
},
|
276
|
-
onEscapeKeyDown: (event) => {
|
277
|
-
var _a, _b;
|
278
|
-
(_b = (_a = this.positioning) == null ? void 0 : _a.onEscapeKeyDown) == null ? void 0 : _b.call(_a, event);
|
279
|
-
if (!event.defaultPrevented) {
|
280
|
-
this.requestUpdate();
|
281
|
-
}
|
282
|
-
},
|
283
|
-
getReference: () => {
|
284
|
-
return this.reference;
|
285
|
-
}
|
286
|
-
});
|
287
|
-
useEffect(
|
288
|
-
this,
|
289
|
-
() => {
|
290
|
-
var _a;
|
291
|
-
return (_a = this.open) != null ? _a : false;
|
292
|
-
},
|
293
|
-
(open) => {
|
294
|
-
var _a;
|
295
|
-
return (_a = this.onOpenChange) == null ? void 0 : _a.call(this, open);
|
296
|
-
}
|
297
|
-
);
|
298
|
-
usePopover(
|
299
|
-
this,
|
300
|
-
() => {
|
301
|
-
var _a;
|
302
|
-
return (_a = this.reference) != null ? _a : null;
|
303
|
-
},
|
304
|
-
() => {
|
305
|
-
var _a;
|
306
|
-
return (_a = this.positioning) != null ? _a : null;
|
307
|
-
}
|
308
|
-
);
|
309
|
-
}
|
310
|
-
/**
|
311
|
-
* @hidden
|
312
|
-
*/
|
313
|
-
connectedCallback() {
|
314
|
-
super.connectedCallback();
|
315
|
-
this.tabIndex = -1;
|
316
|
-
this.role = "dialog";
|
317
|
-
this.updatePopoverAttribute();
|
318
|
-
this.updateDateAttributes();
|
319
|
-
}
|
320
|
-
updatePopoverAttribute() {
|
321
|
-
var _a;
|
322
|
-
if (!popoverAvailable) {
|
323
|
-
return;
|
324
|
-
}
|
325
|
-
if (!this.elevated)
|
326
|
-
return;
|
327
|
-
this.setAttribute("popover", "manual");
|
328
|
-
(_a = this.showPopover) == null ? void 0 : _a.call(this);
|
329
|
-
this.style.setProperty("margin", "unset");
|
330
|
-
}
|
331
|
-
updateDateAttributes() {
|
332
|
-
this.setAttribute("data-state", this.open ? "open" : "closed");
|
333
|
-
if (this.open) {
|
334
|
-
this.setAttribute("data-expanded", "");
|
335
|
-
} else {
|
336
|
-
this.removeAttribute("data-expanded");
|
337
|
-
}
|
338
|
-
}
|
339
|
-
/**
|
340
|
-
* @hidden
|
341
|
-
*/
|
342
|
-
updated(changedProperties) {
|
343
|
-
super.updated(changedProperties);
|
344
|
-
this.setHidden(!this.open);
|
345
|
-
this.updateDateAttributes();
|
346
|
-
}
|
347
|
-
/**
|
348
|
-
* @hidden
|
349
|
-
*/
|
350
|
-
hide() {
|
351
|
-
this.open = false;
|
352
|
-
}
|
353
|
-
};
|
354
|
-
/**
|
355
|
-
* @hidden
|
356
|
-
*/
|
357
|
-
Popover.properties = {
|
358
|
-
reference: { attribute: false },
|
359
|
-
open: { type: Boolean, reflect: false, attribute: false },
|
360
|
-
onOpenChange: { attribute: false },
|
361
|
-
positioning: { type: Object, reflect: false, attribute: false },
|
362
|
-
elevated: { type: Boolean, reflect: false, attribute: false }
|
363
|
-
};
|
364
|
-
defineCustomElement("prosekit-popover", Popover);
|
365
|
-
|
366
|
-
export {
|
367
|
-
popoverPropsNames,
|
368
|
-
Popover
|
369
|
-
};
|
@@ -1,44 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
autocompleteListContext
|
3
|
-
} from "./chunk-5CI65R73.js";
|
4
|
-
import {
|
5
|
-
LightElement,
|
6
|
-
defineCustomElement
|
7
|
-
} from "./chunk-3AZDRLDR.js";
|
8
|
-
|
9
|
-
// src/components/autocomplete-empty/index.ts
|
10
|
-
import { ContextConsumer } from "@lit/context";
|
11
|
-
import "lit";
|
12
|
-
var propNames = [];
|
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
|
-
}
|
21
|
-
connectedCallback() {
|
22
|
-
super.connectedCallback();
|
23
|
-
this.role = "option";
|
24
|
-
}
|
25
|
-
willUpdate(_changedProperties) {
|
26
|
-
var _a;
|
27
|
-
const scores = (_a = this.listContext.value) == null ? void 0 : _a.scores;
|
28
|
-
let hasMatch = false;
|
29
|
-
if (scores) {
|
30
|
-
for (const score of scores.values()) {
|
31
|
-
if (score > 0) {
|
32
|
-
hasMatch = true;
|
33
|
-
break;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
}
|
37
|
-
this.setHidden(hasMatch);
|
38
|
-
}
|
39
|
-
};
|
40
|
-
defineCustomElement("prosekit-autocomplete-empty", AutocompleteEmpty);
|
41
|
-
export {
|
42
|
-
AutocompleteEmpty,
|
43
|
-
propNames
|
44
|
-
};
|
@@ -1,199 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
autocompletePopoverContext
|
3
|
-
} from "./chunk-CPC45JQ7.js";
|
4
|
-
import "./chunk-I5EMQRE4.js";
|
5
|
-
import "./chunk-5CI65R73.js";
|
6
|
-
import "./chunk-MZAHIYA5.js";
|
7
|
-
import {
|
8
|
-
Popover
|
9
|
-
} from "./chunk-XHBZNZ2L.js";
|
10
|
-
import {
|
11
|
-
defineCustomElement
|
12
|
-
} from "./chunk-3AZDRLDR.js";
|
13
|
-
|
14
|
-
// src/components/autocomplete-popover/index.ts
|
15
|
-
import { ContextProvider } from "@lit/context";
|
16
|
-
import "@prosekit/core";
|
17
|
-
|
18
|
-
// src/components/autocomplete-list/helpers.ts
|
19
|
-
function isAutocompleteList(element) {
|
20
|
-
var _a;
|
21
|
-
return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-autocomplete-list";
|
22
|
-
}
|
23
|
-
|
24
|
-
// src/components/autocomplete-popover/controller.ts
|
25
|
-
import "@prosekit/core";
|
26
|
-
import {
|
27
|
-
AutocompleteRule,
|
28
|
-
defineAutocomplete
|
29
|
-
} from "@prosekit/extensions/autocomplete";
|
30
|
-
import "lit";
|
31
|
-
|
32
|
-
// src/components/autocomplete-popover/helpers.ts
|
33
|
-
function defaultQueryBuilder(match) {
|
34
|
-
return match[0].toLowerCase().replace(/[!"#$%&'()*+,-./:;<=>?@[\\\]^_`{|}~]/g, "").replace(/\s\s+/g, " ").trim();
|
35
|
-
}
|
36
|
-
|
37
|
-
// src/components/autocomplete-popover/controller.ts
|
38
|
-
var AutocompletePopoverController = class {
|
39
|
-
constructor(host, onChange) {
|
40
|
-
this.host = host;
|
41
|
-
this.onChange = onChange;
|
42
|
-
this.reference = null;
|
43
|
-
this.editor = null;
|
44
|
-
this.regex = null;
|
45
|
-
this.cleanup = null;
|
46
|
-
this.handleDismiss = null;
|
47
|
-
this.handleSubmit = null;
|
48
|
-
this.host.addController(this);
|
49
|
-
}
|
50
|
-
setEditor(editor) {
|
51
|
-
if (this.editor !== editor) {
|
52
|
-
this.editor = editor;
|
53
|
-
this.defineExtension();
|
54
|
-
this.host.requestUpdate();
|
55
|
-
}
|
56
|
-
}
|
57
|
-
setRegex(regex) {
|
58
|
-
if (this.regex !== regex) {
|
59
|
-
this.regex = regex;
|
60
|
-
this.defineExtension();
|
61
|
-
this.host.requestUpdate();
|
62
|
-
}
|
63
|
-
}
|
64
|
-
defineExtension() {
|
65
|
-
var _a;
|
66
|
-
const regex = this.regex;
|
67
|
-
const editor = this.editor;
|
68
|
-
if (!regex || !editor) {
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
(_a = this.cleanup) == null ? void 0 : _a.call(this);
|
72
|
-
this.cleanup = null;
|
73
|
-
const handleEnter = (options) => {
|
74
|
-
const span = editor.view.dom.querySelector(
|
75
|
-
".prosemirror-prediction-match"
|
76
|
-
);
|
77
|
-
if (span) {
|
78
|
-
this.reference = span;
|
79
|
-
}
|
80
|
-
const query = defaultQueryBuilder(options.match);
|
81
|
-
this.onChange(query != null ? query : "", !!this.reference);
|
82
|
-
this.handleDismiss = options.ignoreMatch;
|
83
|
-
this.handleSubmit = options.deleteMatch;
|
84
|
-
};
|
85
|
-
const handleLeave = () => {
|
86
|
-
this.reference = null;
|
87
|
-
this.host.requestUpdate();
|
88
|
-
this.onChange("", false);
|
89
|
-
this.handleDismiss = null;
|
90
|
-
this.handleSubmit = null;
|
91
|
-
};
|
92
|
-
const rule = new AutocompleteRule({
|
93
|
-
regex,
|
94
|
-
onEnter: handleEnter,
|
95
|
-
onLeave: handleLeave
|
96
|
-
});
|
97
|
-
const extension = defineAutocomplete(rule);
|
98
|
-
this.cleanup = editor.use(extension);
|
99
|
-
}
|
100
|
-
hostDisconnected() {
|
101
|
-
var _a;
|
102
|
-
(_a = this.cleanup) == null ? void 0 : _a.call(this);
|
103
|
-
this.cleanup = null;
|
104
|
-
}
|
105
|
-
};
|
106
|
-
|
107
|
-
// src/components/autocomplete-popover/index.ts
|
108
|
-
var propNames = ["editor", "regex", "positioning"];
|
109
|
-
var AutocompletePopover = class extends Popover {
|
110
|
-
constructor() {
|
111
|
-
super(...arguments);
|
112
|
-
/**
|
113
|
-
* @hidden
|
114
|
-
*/
|
115
|
-
this.controller = new AutocompletePopoverController(
|
116
|
-
this,
|
117
|
-
this.updateContext.bind(this)
|
118
|
-
);
|
119
|
-
this.positioning = {
|
120
|
-
strategy: "fixed",
|
121
|
-
placement: "bottom-start",
|
122
|
-
fitViewport: true,
|
123
|
-
flip: false,
|
124
|
-
inline: true
|
125
|
-
};
|
126
|
-
this.context = new ContextProvider(this, {
|
127
|
-
context: autocompletePopoverContext,
|
128
|
-
initialValue: {
|
129
|
-
active: false,
|
130
|
-
query: "",
|
131
|
-
handleDismiss: () => {
|
132
|
-
var _a, _b;
|
133
|
-
return (_b = (_a = this.controller).handleDismiss) == null ? void 0 : _b.call(_a);
|
134
|
-
},
|
135
|
-
handleSubmit: () => {
|
136
|
-
var _a, _b;
|
137
|
-
return (_b = (_a = this.controller).handleSubmit) == null ? void 0 : _b.call(_a);
|
138
|
-
}
|
139
|
-
}
|
140
|
-
});
|
141
|
-
}
|
142
|
-
get list() {
|
143
|
-
const element = this.querySelector("prosekit-autocomplete-list");
|
144
|
-
return isAutocompleteList(element) ? element : null;
|
145
|
-
}
|
146
|
-
updateContext(query, active) {
|
147
|
-
const context = this.context.value;
|
148
|
-
if (context.query !== query || context.active !== active) {
|
149
|
-
this.context.setValue({ ...context, query, active });
|
150
|
-
} else if (!active) {
|
151
|
-
return;
|
152
|
-
}
|
153
|
-
this.requestUpdate();
|
154
|
-
requestAnimationFrame(() => {
|
155
|
-
var _a;
|
156
|
-
(_a = this.list) == null ? void 0 : _a.selectFirstItem();
|
157
|
-
});
|
158
|
-
}
|
159
|
-
/**
|
160
|
-
* @hidden
|
161
|
-
*/
|
162
|
-
willUpdate(changedProperties) {
|
163
|
-
var _a, _b;
|
164
|
-
super.willUpdate(changedProperties);
|
165
|
-
if (this.editor) {
|
166
|
-
this.controller.setEditor(this.editor);
|
167
|
-
}
|
168
|
-
if (this.regex) {
|
169
|
-
this.controller.setRegex(this.regex);
|
170
|
-
}
|
171
|
-
this.open = !!((_a = this.controller) == null ? void 0 : _a.reference);
|
172
|
-
this.reference = (_b = this.controller.reference) != null ? _b : void 0;
|
173
|
-
}
|
174
|
-
/**
|
175
|
-
* @hidden
|
176
|
-
*/
|
177
|
-
hide() {
|
178
|
-
var _a;
|
179
|
-
super.hide();
|
180
|
-
if ((_a = this.controller) == null ? void 0 : _a.reference) {
|
181
|
-
this.controller.reference = null;
|
182
|
-
this.reference = void 0;
|
183
|
-
}
|
184
|
-
}
|
185
|
-
};
|
186
|
-
/**
|
187
|
-
* @hidden
|
188
|
-
*/
|
189
|
-
AutocompletePopover.properties = {
|
190
|
-
...Popover.properties,
|
191
|
-
editor: { type: Object, reflect: false, attribute: false },
|
192
|
-
regex: { attribute: false },
|
193
|
-
positioning: { type: Object, reflect: false, attribute: false }
|
194
|
-
};
|
195
|
-
defineCustomElement("prosekit-autocomplete-popover", AutocompletePopover);
|
196
|
-
export {
|
197
|
-
AutocompletePopover,
|
198
|
-
propNames
|
199
|
-
};
|