@prosekit/lit 0.1.9 → 0.2.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 +221 -179
- package/dist/chunk-OZUEYWYU.js +365 -0
- package/dist/prosekit-lit-autocomplete-popover.d.ts +1 -1
- package/dist/prosekit-lit-autocomplete-popover.js +12 -70
- package/dist/prosekit-lit-combo-box.js +1 -1
- package/dist/prosekit-lit-inline-popover.d.ts +1 -1
- package/dist/prosekit-lit-inline-popover.js +116 -98
- package/dist/prosekit-lit-popover.d.ts +2 -1
- package/dist/prosekit-lit-popover.js +4 -3
- package/package.json +6 -4
- package/dist/chunk-CUH6G34Q.js +0 -224
@@ -0,0 +1,365 @@
|
|
1
|
+
import {
|
2
|
+
LightElement,
|
3
|
+
defineCustomElement
|
4
|
+
} from "./chunk-S32IZIQF.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
|
+
useDismissable(this, {
|
268
|
+
onPointerDownOutside: (event) => {
|
269
|
+
var _a, _b;
|
270
|
+
(_b = (_a = this.positioning) == null ? void 0 : _a.onPointerDownOutside) == null ? void 0 : _b.call(_a, event);
|
271
|
+
if (!event.defaultPrevented) {
|
272
|
+
this.requestUpdate();
|
273
|
+
}
|
274
|
+
},
|
275
|
+
onEscapeKeyDown: (event) => {
|
276
|
+
var _a, _b;
|
277
|
+
(_b = (_a = this.positioning) == null ? void 0 : _a.onEscapeKeyDown) == null ? void 0 : _b.call(_a, event);
|
278
|
+
if (!event.defaultPrevented) {
|
279
|
+
this.requestUpdate();
|
280
|
+
}
|
281
|
+
},
|
282
|
+
getReference: () => {
|
283
|
+
return this.reference;
|
284
|
+
}
|
285
|
+
});
|
286
|
+
useEffect(
|
287
|
+
this,
|
288
|
+
() => {
|
289
|
+
var _a;
|
290
|
+
return (_a = this.open) != null ? _a : false;
|
291
|
+
},
|
292
|
+
(open) => {
|
293
|
+
var _a;
|
294
|
+
return (_a = this.onOpenChange) == null ? void 0 : _a.call(this, open);
|
295
|
+
}
|
296
|
+
);
|
297
|
+
usePopover(
|
298
|
+
this,
|
299
|
+
() => {
|
300
|
+
var _a;
|
301
|
+
return (_a = this.reference) != null ? _a : null;
|
302
|
+
},
|
303
|
+
() => {
|
304
|
+
var _a;
|
305
|
+
return (_a = this.positioning) != null ? _a : null;
|
306
|
+
}
|
307
|
+
);
|
308
|
+
}
|
309
|
+
/**
|
310
|
+
* @hidden
|
311
|
+
*/
|
312
|
+
connectedCallback() {
|
313
|
+
super.connectedCallback();
|
314
|
+
this.tabIndex = -1;
|
315
|
+
this.role = "dialog";
|
316
|
+
this.updatePopoverAttribute();
|
317
|
+
this.updateDateAttributes();
|
318
|
+
}
|
319
|
+
updatePopoverAttribute() {
|
320
|
+
var _a;
|
321
|
+
if (!popoverAvailable) {
|
322
|
+
return;
|
323
|
+
}
|
324
|
+
this.setAttribute("popover", "manual");
|
325
|
+
(_a = this.showPopover) == null ? void 0 : _a.call(this);
|
326
|
+
this.style.setProperty("margin", "unset");
|
327
|
+
}
|
328
|
+
updateDateAttributes() {
|
329
|
+
this.setAttribute("data-state", this.open ? "open" : "closed");
|
330
|
+
if (this.open) {
|
331
|
+
this.setAttribute("data-expanded", "");
|
332
|
+
} else {
|
333
|
+
this.removeAttribute("data-expanded");
|
334
|
+
}
|
335
|
+
}
|
336
|
+
/**
|
337
|
+
* @hidden
|
338
|
+
*/
|
339
|
+
updated(changedProperties) {
|
340
|
+
super.updated(changedProperties);
|
341
|
+
this.setHidden(!this.open);
|
342
|
+
this.updateDateAttributes();
|
343
|
+
}
|
344
|
+
/**
|
345
|
+
* @hidden
|
346
|
+
*/
|
347
|
+
hide() {
|
348
|
+
this.open = false;
|
349
|
+
}
|
350
|
+
};
|
351
|
+
/**
|
352
|
+
* @hidden
|
353
|
+
*/
|
354
|
+
Popover.properties = {
|
355
|
+
reference: { attribute: false },
|
356
|
+
open: { type: Boolean, reflect: false, attribute: false },
|
357
|
+
onOpenChange: { attribute: false },
|
358
|
+
positioning: { type: Object, reflect: false, attribute: false }
|
359
|
+
};
|
360
|
+
defineCustomElement("prosekit-popover", Popover);
|
361
|
+
|
362
|
+
export {
|
363
|
+
popoverPropsNames,
|
364
|
+
Popover
|
365
|
+
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export {
|
1
|
+
export { PositioningOptions } from './_tsup-dts-rollup';
|
2
2
|
export { propNames_alias_5 as propNames } from './_tsup-dts-rollup';
|
3
3
|
export { AutocompletePopoverProps } from './_tsup-dts-rollup';
|
4
4
|
export { AutocompletePopover } from './_tsup-dts-rollup';
|
@@ -4,9 +4,8 @@ import {
|
|
4
4
|
import "./chunk-MLUELLVA.js";
|
5
5
|
import "./chunk-5CI65R73.js";
|
6
6
|
import {
|
7
|
-
Popover
|
8
|
-
|
9
|
-
} from "./chunk-CUH6G34Q.js";
|
7
|
+
Popover
|
8
|
+
} from "./chunk-OZUEYWYU.js";
|
10
9
|
import "./chunk-GZRUCYLP.js";
|
11
10
|
import {
|
12
11
|
defineCustomElement
|
@@ -105,68 +104,8 @@ var AutocompletePopoverController = class {
|
|
105
104
|
}
|
106
105
|
};
|
107
106
|
|
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
|
-
padding: 8,
|
118
|
-
boundary
|
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
107
|
// src/components/autocomplete-popover/index.ts
|
169
|
-
var propNames = ["editor", "regex", "
|
108
|
+
var propNames = ["editor", "regex", "positioning"];
|
170
109
|
var AutocompletePopover = class extends Popover {
|
171
110
|
constructor() {
|
172
111
|
super(...arguments);
|
@@ -177,7 +116,12 @@ var AutocompletePopover = class extends Popover {
|
|
177
116
|
this,
|
178
117
|
this.updateContext.bind(this)
|
179
118
|
);
|
180
|
-
this.
|
119
|
+
this.positioning = {
|
120
|
+
strategy: "fixed",
|
121
|
+
placement: "bottom-start",
|
122
|
+
flip: false,
|
123
|
+
inline: true
|
124
|
+
};
|
181
125
|
this.context = new ContextProvider(this, {
|
182
126
|
context: autocompletePopoverContext,
|
183
127
|
initialValue: {
|
@@ -222,9 +166,8 @@ var AutocompletePopover = class extends Popover {
|
|
222
166
|
if (this.regex) {
|
223
167
|
this.controller.setRegex(this.regex);
|
224
168
|
}
|
225
|
-
this.
|
169
|
+
this.open = !!((_a = this.controller) == null ? void 0 : _a.reference);
|
226
170
|
this.reference = (_b = this.controller.reference) != null ? _b : void 0;
|
227
|
-
this.options = this.popoverOptions;
|
228
171
|
}
|
229
172
|
/**
|
230
173
|
* @hidden
|
@@ -243,10 +186,9 @@ var AutocompletePopover = class extends Popover {
|
|
243
186
|
*/
|
244
187
|
AutocompletePopover.properties = {
|
245
188
|
...Popover.properties,
|
246
|
-
editor: { attribute: false },
|
189
|
+
editor: { type: Object, reflect: false, attribute: false },
|
247
190
|
regex: { attribute: false },
|
248
|
-
|
249
|
-
onSelect: { attribute: false }
|
191
|
+
positioning: { type: Object, reflect: false, attribute: false }
|
250
192
|
};
|
251
193
|
defineCustomElement("prosekit-autocomplete-popover", AutocompletePopover);
|
252
194
|
export {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export {
|
1
|
+
export { PositioningOptions_alias_1 as PositioningOptions } from './_tsup-dts-rollup';
|
2
2
|
export { propNames_alias_12 as propNames } from './_tsup-dts-rollup';
|
3
3
|
export { InlinePopoverProps } from './_tsup-dts-rollup';
|
4
4
|
export { InlinePopover } from './_tsup-dts-rollup';
|