@prosekit/lit 0.0.0-next-20230627094841
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/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/chunk-43BFWKM2.js +26 -0
- package/dist/chunk-5VENWR7M.js +118 -0
- package/dist/chunk-6EHMW3VI.js +19 -0
- package/dist/chunk-7C2I5DWH.js +122 -0
- package/dist/chunk-CFFBSSAU.js +121 -0
- package/dist/chunk-EZ4YICBQ.js +108 -0
- package/dist/chunk-JFOZX34E.js +109 -0
- package/dist/chunk-NMFTOM6J.js +189 -0
- package/dist/chunk-S65R2BUY.js +15 -0
- package/dist/chunk-TFM6CTEO.js +9 -0
- package/dist/chunk-VYMBIH4T.js +120 -0
- package/dist/chunk-WUZ77NLF.js +108 -0
- package/dist/chunk-XEV4EE3R.js +13 -0
- package/dist/chunk-Y34HGIIF.js +20 -0
- package/dist/chunk-YS57RXAX.js +124 -0
- package/dist/prosekit-lit-elements-menu-item.js +37 -0
- package/dist/prosekit-lit-elements-menu.js +169 -0
- package/dist/prosekit-lit-elements-picker.js +11 -0
- package/dist/prosekit-lit-elements-popover-slash.js +211 -0
- package/dist/prosekit-lit-elements-popover-suggestion-consumer.js +36 -0
- package/dist/prosekit-lit-elements-popover-suggestion.js +218 -0
- package/dist/prosekit-lit-elements-popover.js +7 -0
- package/dist/prosekit-lit-elements-popover2.js +119 -0
- package/dist/prosekit-lit-elements-slash-popover.js +213 -0
- package/dist/prosekit-lit.js +0 -0
- package/package.json +80 -0
- package/src/index.ts +5 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2023 ocavue
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
File without changes
|
@@ -0,0 +1,26 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
6
|
+
if (decorator = decorators[i])
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
8
|
+
if (kind && result)
|
9
|
+
__defProp(target, key, result);
|
10
|
+
return result;
|
11
|
+
};
|
12
|
+
|
13
|
+
// src/styles/block-component.styles.ts
|
14
|
+
import { css as css2 } from "lit";
|
15
|
+
|
16
|
+
// src/styles/component.styles.ts
|
17
|
+
import { css } from "lit";
|
18
|
+
var componentStyles = css`:host{box-sizing:border-box}:host *,:host ::after,:host ::before{box-sizing:inherit}`;
|
19
|
+
|
20
|
+
// src/styles/block-component.styles.ts
|
21
|
+
var blockComponentStyles = css2`${componentStyles}:host{display:block}`;
|
22
|
+
|
23
|
+
export {
|
24
|
+
__decorateClass,
|
25
|
+
blockComponentStyles
|
26
|
+
};
|
@@ -0,0 +1,118 @@
|
|
1
|
+
import {
|
2
|
+
__decorateClass,
|
3
|
+
blockComponentStyles
|
4
|
+
} from "./chunk-43BFWKM2.js";
|
5
|
+
|
6
|
+
// src/elements/popover.ts
|
7
|
+
import {
|
8
|
+
autoUpdate,
|
9
|
+
computePosition
|
10
|
+
} from "@floating-ui/dom";
|
11
|
+
import { LitElement, html } from "lit";
|
12
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
13
|
+
import { styleMap } from "lit/directives/style-map.js";
|
14
|
+
var Popover = class extends LitElement {
|
15
|
+
/** @hidden */
|
16
|
+
constructor() {
|
17
|
+
super();
|
18
|
+
this.active = false;
|
19
|
+
this.autoUpdate = false;
|
20
|
+
}
|
21
|
+
/** @hidden */
|
22
|
+
disconnectedCallback() {
|
23
|
+
this.cleanup();
|
24
|
+
}
|
25
|
+
/** @hidden */
|
26
|
+
updated(changed) {
|
27
|
+
if (!changed.has("computed")) {
|
28
|
+
this.start();
|
29
|
+
}
|
30
|
+
}
|
31
|
+
/** @hidden */
|
32
|
+
start() {
|
33
|
+
this.cleanup();
|
34
|
+
const reference = this.reference;
|
35
|
+
const floating = this.floating;
|
36
|
+
if (!reference)
|
37
|
+
return;
|
38
|
+
if (this.autoUpdate) {
|
39
|
+
this.cleanupAutoUpdate = autoUpdate(
|
40
|
+
reference,
|
41
|
+
floating,
|
42
|
+
() => void this.compute(),
|
43
|
+
this.autoUpdateOptions
|
44
|
+
);
|
45
|
+
} else {
|
46
|
+
void this.compute();
|
47
|
+
}
|
48
|
+
}
|
49
|
+
/** @hidden */
|
50
|
+
async compute() {
|
51
|
+
const reference = this.reference;
|
52
|
+
const floating = this.floating;
|
53
|
+
if (!reference)
|
54
|
+
return;
|
55
|
+
const options = this.options;
|
56
|
+
this.computed = await computePosition(reference, floating, options);
|
57
|
+
}
|
58
|
+
/** @hidden */
|
59
|
+
cleanup() {
|
60
|
+
var _a;
|
61
|
+
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
62
|
+
this.cleanupAutoUpdate = void 0;
|
63
|
+
}
|
64
|
+
/** @hidden */
|
65
|
+
render() {
|
66
|
+
var _a;
|
67
|
+
const { x, y, strategy } = (_a = this.computed) != null ? _a : {
|
68
|
+
x: 0,
|
69
|
+
y: 0,
|
70
|
+
strategy: "absolute"
|
71
|
+
};
|
72
|
+
const style = {
|
73
|
+
top: "0",
|
74
|
+
left: "0",
|
75
|
+
position: strategy,
|
76
|
+
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
77
|
+
display: this.active ? void 0 : "none"
|
78
|
+
};
|
79
|
+
return html`<div class="floating" style="${styleMap(style)}"><slot></slot></div>`;
|
80
|
+
}
|
81
|
+
};
|
82
|
+
/** @hidden */
|
83
|
+
Popover.styles = blockComponentStyles;
|
84
|
+
__decorateClass([
|
85
|
+
property({ type: Boolean, reflect: true })
|
86
|
+
], Popover.prototype, "active", 2);
|
87
|
+
__decorateClass([
|
88
|
+
query(".floating")
|
89
|
+
], Popover.prototype, "floating", 2);
|
90
|
+
__decorateClass([
|
91
|
+
property()
|
92
|
+
], Popover.prototype, "reference", 2);
|
93
|
+
__decorateClass([
|
94
|
+
property()
|
95
|
+
], Popover.prototype, "options", 2);
|
96
|
+
__decorateClass([
|
97
|
+
property({
|
98
|
+
type: Boolean,
|
99
|
+
reflect: true
|
100
|
+
})
|
101
|
+
], Popover.prototype, "autoUpdate", 2);
|
102
|
+
__decorateClass([
|
103
|
+
property({ type: Object })
|
104
|
+
], Popover.prototype, "autoUpdateOptions", 2);
|
105
|
+
__decorateClass([
|
106
|
+
state()
|
107
|
+
], Popover.prototype, "computed", 2);
|
108
|
+
Popover = __decorateClass([
|
109
|
+
customElement("prosekit-popover")
|
110
|
+
], Popover);
|
111
|
+
function roundByDPR(value) {
|
112
|
+
const dpr = window.devicePixelRatio || 1;
|
113
|
+
return Math.round(value * dpr) / dpr;
|
114
|
+
}
|
115
|
+
|
116
|
+
export {
|
117
|
+
Popover
|
118
|
+
};
|
@@ -0,0 +1,19 @@
|
|
1
|
+
// src/utils/visibility.ts
|
2
|
+
function isVisibleElement(element) {
|
3
|
+
return !element.hidden;
|
4
|
+
}
|
5
|
+
function isHiddenElement(element) {
|
6
|
+
return element.hidden;
|
7
|
+
}
|
8
|
+
function createVisibilityFilter(visible) {
|
9
|
+
if (visible === true)
|
10
|
+
return isVisibleElement;
|
11
|
+
if (visible === false)
|
12
|
+
return isHiddenElement;
|
13
|
+
return () => true;
|
14
|
+
}
|
15
|
+
|
16
|
+
export {
|
17
|
+
isVisibleElement,
|
18
|
+
createVisibilityFilter
|
19
|
+
};
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import {
|
2
|
+
__decorateClass,
|
3
|
+
blockComponentStyles
|
4
|
+
} from "./chunk-43BFWKM2.js";
|
5
|
+
|
6
|
+
// src/elements/popover/popover.ts
|
7
|
+
import {
|
8
|
+
autoUpdate,
|
9
|
+
computePosition
|
10
|
+
} from "@floating-ui/dom";
|
11
|
+
import { LitElement, html } from "lit";
|
12
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
13
|
+
import { styleMap } from "lit/directives/style-map.js";
|
14
|
+
|
15
|
+
// src/utils/round-by-dpr.ts
|
16
|
+
function roundByDPR(value) {
|
17
|
+
const dpr = window.devicePixelRatio || 1;
|
18
|
+
return Math.round(value * dpr) / dpr;
|
19
|
+
}
|
20
|
+
|
21
|
+
// src/elements/popover/popover.ts
|
22
|
+
var Popover = class extends LitElement {
|
23
|
+
/** @hidden */
|
24
|
+
constructor() {
|
25
|
+
super();
|
26
|
+
this.active = false;
|
27
|
+
this.autoUpdate = false;
|
28
|
+
}
|
29
|
+
/** @hidden */
|
30
|
+
disconnectedCallback() {
|
31
|
+
this.cleanup();
|
32
|
+
}
|
33
|
+
/** @hidden */
|
34
|
+
updated(changed) {
|
35
|
+
if (!changed.has("computed")) {
|
36
|
+
this.start();
|
37
|
+
}
|
38
|
+
}
|
39
|
+
/** @hidden */
|
40
|
+
start() {
|
41
|
+
this.cleanup();
|
42
|
+
const reference = this.reference;
|
43
|
+
const floating = this.floating;
|
44
|
+
if (!reference)
|
45
|
+
return;
|
46
|
+
if (this.autoUpdate) {
|
47
|
+
this.cleanupAutoUpdate = autoUpdate(
|
48
|
+
reference,
|
49
|
+
floating,
|
50
|
+
() => void this.compute(),
|
51
|
+
this.autoUpdateOptions
|
52
|
+
);
|
53
|
+
} else {
|
54
|
+
void this.compute();
|
55
|
+
}
|
56
|
+
}
|
57
|
+
/** @hidden */
|
58
|
+
async compute() {
|
59
|
+
const reference = this.reference;
|
60
|
+
const floating = this.floating;
|
61
|
+
if (!reference)
|
62
|
+
return;
|
63
|
+
const options = this.options;
|
64
|
+
this.computed = await computePosition(reference, floating, options);
|
65
|
+
}
|
66
|
+
/** @hidden */
|
67
|
+
cleanup() {
|
68
|
+
var _a;
|
69
|
+
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
70
|
+
this.cleanupAutoUpdate = void 0;
|
71
|
+
}
|
72
|
+
/** @hidden */
|
73
|
+
render() {
|
74
|
+
var _a;
|
75
|
+
const { x, y, strategy } = (_a = this.computed) != null ? _a : {
|
76
|
+
x: 0,
|
77
|
+
y: 0,
|
78
|
+
strategy: "absolute"
|
79
|
+
};
|
80
|
+
const style = {
|
81
|
+
top: "0",
|
82
|
+
left: "0",
|
83
|
+
position: strategy,
|
84
|
+
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
85
|
+
display: this.active ? void 0 : "none"
|
86
|
+
};
|
87
|
+
return html`<div class="floating" style="${styleMap(style)}"><slot></slot></div>`;
|
88
|
+
}
|
89
|
+
};
|
90
|
+
/** @hidden */
|
91
|
+
Popover.styles = blockComponentStyles;
|
92
|
+
__decorateClass([
|
93
|
+
property({ type: Boolean, reflect: true })
|
94
|
+
], Popover.prototype, "active", 2);
|
95
|
+
__decorateClass([
|
96
|
+
query(".floating")
|
97
|
+
], Popover.prototype, "floating", 2);
|
98
|
+
__decorateClass([
|
99
|
+
property()
|
100
|
+
], Popover.prototype, "reference", 2);
|
101
|
+
__decorateClass([
|
102
|
+
property()
|
103
|
+
], Popover.prototype, "options", 2);
|
104
|
+
__decorateClass([
|
105
|
+
property({
|
106
|
+
type: Boolean,
|
107
|
+
reflect: true
|
108
|
+
})
|
109
|
+
], Popover.prototype, "autoUpdate", 2);
|
110
|
+
__decorateClass([
|
111
|
+
property({ type: Object })
|
112
|
+
], Popover.prototype, "autoUpdateOptions", 2);
|
113
|
+
__decorateClass([
|
114
|
+
state()
|
115
|
+
], Popover.prototype, "computed", 2);
|
116
|
+
Popover = __decorateClass([
|
117
|
+
customElement("prosekit-popover")
|
118
|
+
], Popover);
|
119
|
+
|
120
|
+
export {
|
121
|
+
Popover
|
122
|
+
};
|
@@ -0,0 +1,121 @@
|
|
1
|
+
import {
|
2
|
+
__decorateClass,
|
3
|
+
blockComponentStyles
|
4
|
+
} from "./chunk-43BFWKM2.js";
|
5
|
+
|
6
|
+
// src/elements/popover.ts
|
7
|
+
import {
|
8
|
+
autoUpdate,
|
9
|
+
computePosition
|
10
|
+
} from "@floating-ui/dom";
|
11
|
+
import { LitElement, html } from "lit";
|
12
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
13
|
+
import { styleMap } from "lit/directives/style-map.js";
|
14
|
+
var Popover = class extends LitElement {
|
15
|
+
constructor() {
|
16
|
+
super(...arguments);
|
17
|
+
this.active = false;
|
18
|
+
this.autoUpdate = false;
|
19
|
+
}
|
20
|
+
/** @hidden */
|
21
|
+
disconnectedCallback() {
|
22
|
+
this.cleanup();
|
23
|
+
}
|
24
|
+
/** @hidden */
|
25
|
+
updated(changed) {
|
26
|
+
if (!changed.has("computed")) {
|
27
|
+
this.start();
|
28
|
+
}
|
29
|
+
}
|
30
|
+
/** @hidden */
|
31
|
+
start() {
|
32
|
+
this.cleanup();
|
33
|
+
const reference = this.reference;
|
34
|
+
const floating = this.floating;
|
35
|
+
if (!reference)
|
36
|
+
return;
|
37
|
+
if (this.autoUpdate) {
|
38
|
+
this.cleanupAutoUpdate = autoUpdate(
|
39
|
+
reference,
|
40
|
+
floating,
|
41
|
+
() => void this.compute(),
|
42
|
+
this.autoUpdateOptions
|
43
|
+
);
|
44
|
+
} else {
|
45
|
+
void this.compute();
|
46
|
+
}
|
47
|
+
}
|
48
|
+
/** @hidden */
|
49
|
+
async compute() {
|
50
|
+
const reference = this.reference;
|
51
|
+
const floating = this.floating;
|
52
|
+
if (!reference)
|
53
|
+
return;
|
54
|
+
const options = this.options;
|
55
|
+
this.computed = await computePosition(reference, floating, options);
|
56
|
+
}
|
57
|
+
/** @hidden */
|
58
|
+
cleanup() {
|
59
|
+
var _a;
|
60
|
+
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
61
|
+
this.cleanupAutoUpdate = void 0;
|
62
|
+
}
|
63
|
+
/** @hidden */
|
64
|
+
render() {
|
65
|
+
var _a;
|
66
|
+
const { x, y, strategy } = (_a = this.computed) != null ? _a : {
|
67
|
+
x: 0,
|
68
|
+
y: 0,
|
69
|
+
strategy: "absolute"
|
70
|
+
};
|
71
|
+
const style = {
|
72
|
+
top: "0",
|
73
|
+
left: "0",
|
74
|
+
position: strategy,
|
75
|
+
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
76
|
+
display: this.active ? void 0 : "none"
|
77
|
+
};
|
78
|
+
return html`<div class="floating" style="${styleMap(style)}"><slot></slot></div>`;
|
79
|
+
}
|
80
|
+
};
|
81
|
+
/** @hidden */
|
82
|
+
// private constructor(...args) {
|
83
|
+
// super(...args)
|
84
|
+
// }
|
85
|
+
/** @hidden */
|
86
|
+
Popover.styles = blockComponentStyles;
|
87
|
+
__decorateClass([
|
88
|
+
property({ type: Boolean, reflect: true })
|
89
|
+
], Popover.prototype, "active", 2);
|
90
|
+
__decorateClass([
|
91
|
+
query(".floating")
|
92
|
+
], Popover.prototype, "floating", 2);
|
93
|
+
__decorateClass([
|
94
|
+
property()
|
95
|
+
], Popover.prototype, "reference", 2);
|
96
|
+
__decorateClass([
|
97
|
+
property()
|
98
|
+
], Popover.prototype, "options", 2);
|
99
|
+
__decorateClass([
|
100
|
+
property({
|
101
|
+
type: Boolean,
|
102
|
+
reflect: true
|
103
|
+
})
|
104
|
+
], Popover.prototype, "autoUpdate", 2);
|
105
|
+
__decorateClass([
|
106
|
+
property({ type: Object })
|
107
|
+
], Popover.prototype, "autoUpdateOptions", 2);
|
108
|
+
__decorateClass([
|
109
|
+
state()
|
110
|
+
], Popover.prototype, "computed", 2);
|
111
|
+
Popover = __decorateClass([
|
112
|
+
customElement("prosekit-popover")
|
113
|
+
], Popover);
|
114
|
+
function roundByDPR(value) {
|
115
|
+
const dpr = window.devicePixelRatio || 1;
|
116
|
+
return Math.round(value * dpr) / dpr;
|
117
|
+
}
|
118
|
+
|
119
|
+
export {
|
120
|
+
Popover
|
121
|
+
};
|
@@ -0,0 +1,108 @@
|
|
1
|
+
import {
|
2
|
+
__decorateClass,
|
3
|
+
blockComponentStyles
|
4
|
+
} from "./chunk-43BFWKM2.js";
|
5
|
+
|
6
|
+
// src/elements/popover.ts
|
7
|
+
import {
|
8
|
+
autoUpdate,
|
9
|
+
computePosition
|
10
|
+
} from "@floating-ui/dom";
|
11
|
+
import { LitElement, html } from "lit";
|
12
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
13
|
+
import { styleMap } from "lit/directives/style-map.js";
|
14
|
+
var Popover = class extends LitElement {
|
15
|
+
constructor() {
|
16
|
+
super(...arguments);
|
17
|
+
this.active = false;
|
18
|
+
this.reference = null;
|
19
|
+
this.autoUpdate = false;
|
20
|
+
}
|
21
|
+
disconnectedCallback() {
|
22
|
+
this.cleanup();
|
23
|
+
}
|
24
|
+
updated(changed) {
|
25
|
+
if (!changed.has("computed")) {
|
26
|
+
this.start();
|
27
|
+
}
|
28
|
+
}
|
29
|
+
start() {
|
30
|
+
this.cleanup();
|
31
|
+
const reference = this.reference;
|
32
|
+
const floating = this.floating;
|
33
|
+
if (!reference)
|
34
|
+
return;
|
35
|
+
if (this.autoUpdate) {
|
36
|
+
this.cleanupAutoUpdate = autoUpdate(
|
37
|
+
reference,
|
38
|
+
floating,
|
39
|
+
() => void this.compute(),
|
40
|
+
this.autoUpdateOptions
|
41
|
+
);
|
42
|
+
} else {
|
43
|
+
void this.compute();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
async compute() {
|
47
|
+
const reference = this.reference;
|
48
|
+
const floating = this.floating;
|
49
|
+
if (!reference)
|
50
|
+
return;
|
51
|
+
const options = this.options;
|
52
|
+
this.computed = await computePosition(reference, floating, options);
|
53
|
+
}
|
54
|
+
render() {
|
55
|
+
var _a;
|
56
|
+
const { x, y, strategy } = (_a = this.computed) != null ? _a : {
|
57
|
+
x: 0,
|
58
|
+
y: 0,
|
59
|
+
strategy: "absolute"
|
60
|
+
};
|
61
|
+
const style = {
|
62
|
+
top: "0",
|
63
|
+
left: "0",
|
64
|
+
position: strategy,
|
65
|
+
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
66
|
+
display: this.active ? void 0 : "none"
|
67
|
+
};
|
68
|
+
return html`<div class="floating" style="${styleMap(style)}"><slot></slot></div>`;
|
69
|
+
}
|
70
|
+
cleanup() {
|
71
|
+
var _a;
|
72
|
+
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
73
|
+
this.cleanupAutoUpdate = void 0;
|
74
|
+
}
|
75
|
+
};
|
76
|
+
Popover.styles = blockComponentStyles;
|
77
|
+
__decorateClass([
|
78
|
+
property({ type: Boolean, reflect: true })
|
79
|
+
], Popover.prototype, "active", 2);
|
80
|
+
__decorateClass([
|
81
|
+
query(".floating")
|
82
|
+
], Popover.prototype, "floating", 2);
|
83
|
+
__decorateClass([
|
84
|
+
property()
|
85
|
+
], Popover.prototype, "reference", 2);
|
86
|
+
__decorateClass([
|
87
|
+
property({ type: Object })
|
88
|
+
], Popover.prototype, "options", 2);
|
89
|
+
__decorateClass([
|
90
|
+
property({ type: Boolean, reflect: true })
|
91
|
+
], Popover.prototype, "autoUpdate", 2);
|
92
|
+
__decorateClass([
|
93
|
+
property({ type: Object })
|
94
|
+
], Popover.prototype, "autoUpdateOptions", 2);
|
95
|
+
__decorateClass([
|
96
|
+
state()
|
97
|
+
], Popover.prototype, "computed", 2);
|
98
|
+
Popover = __decorateClass([
|
99
|
+
customElement("prosekit-popover")
|
100
|
+
], Popover);
|
101
|
+
function roundByDPR(value) {
|
102
|
+
const dpr = window.devicePixelRatio || 1;
|
103
|
+
return Math.round(value * dpr) / dpr;
|
104
|
+
}
|
105
|
+
|
106
|
+
export {
|
107
|
+
Popover
|
108
|
+
};
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import {
|
2
|
+
__decorateClass,
|
3
|
+
blockComponentStyles
|
4
|
+
} from "./chunk-43BFWKM2.js";
|
5
|
+
|
6
|
+
// src/elements/popover/popover.ts
|
7
|
+
import {
|
8
|
+
autoUpdate,
|
9
|
+
computePosition
|
10
|
+
} from "@floating-ui/dom";
|
11
|
+
import "@shoelace-style/shoelace/dist/components/popup/popup.js";
|
12
|
+
import { LitElement, html } from "lit";
|
13
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
14
|
+
import { styleMap } from "lit/directives/style-map.js";
|
15
|
+
var Popover = class extends LitElement {
|
16
|
+
constructor() {
|
17
|
+
super(...arguments);
|
18
|
+
this.active = false;
|
19
|
+
this.reference = null;
|
20
|
+
this.autoUpdate = false;
|
21
|
+
}
|
22
|
+
disconnectedCallback() {
|
23
|
+
this.cleanup();
|
24
|
+
}
|
25
|
+
updated(changed) {
|
26
|
+
if (!changed.has("computed")) {
|
27
|
+
this.start();
|
28
|
+
}
|
29
|
+
}
|
30
|
+
start() {
|
31
|
+
this.cleanup();
|
32
|
+
const reference = this.reference;
|
33
|
+
const floating = this.floating;
|
34
|
+
if (!reference)
|
35
|
+
return;
|
36
|
+
if (this.autoUpdate) {
|
37
|
+
this.cleanupAutoUpdate = autoUpdate(
|
38
|
+
reference,
|
39
|
+
floating,
|
40
|
+
() => void this.compute(),
|
41
|
+
this.autoUpdateOptions
|
42
|
+
);
|
43
|
+
} else {
|
44
|
+
void this.compute();
|
45
|
+
}
|
46
|
+
}
|
47
|
+
async compute() {
|
48
|
+
const reference = this.reference;
|
49
|
+
const floating = this.floating;
|
50
|
+
if (!reference)
|
51
|
+
return;
|
52
|
+
const options = this.options;
|
53
|
+
this.computed = await computePosition(reference, floating, options);
|
54
|
+
}
|
55
|
+
render() {
|
56
|
+
var _a;
|
57
|
+
const { x, y, strategy } = (_a = this.computed) != null ? _a : {
|
58
|
+
x: 0,
|
59
|
+
y: 0,
|
60
|
+
strategy: "absolute"
|
61
|
+
};
|
62
|
+
const style = {
|
63
|
+
top: "0",
|
64
|
+
left: "0",
|
65
|
+
position: strategy,
|
66
|
+
transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
|
67
|
+
display: this.active ? void 0 : "none"
|
68
|
+
};
|
69
|
+
return html`<div class="floating" style="${styleMap(style)}"><slot></slot></div>`;
|
70
|
+
}
|
71
|
+
cleanup() {
|
72
|
+
var _a;
|
73
|
+
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
74
|
+
this.cleanupAutoUpdate = void 0;
|
75
|
+
}
|
76
|
+
};
|
77
|
+
Popover.styles = blockComponentStyles;
|
78
|
+
__decorateClass([
|
79
|
+
property({ type: Boolean, reflect: true })
|
80
|
+
], Popover.prototype, "active", 2);
|
81
|
+
__decorateClass([
|
82
|
+
query(".floating")
|
83
|
+
], Popover.prototype, "floating", 2);
|
84
|
+
__decorateClass([
|
85
|
+
property()
|
86
|
+
], Popover.prototype, "reference", 2);
|
87
|
+
__decorateClass([
|
88
|
+
property({ type: Object })
|
89
|
+
], Popover.prototype, "options", 2);
|
90
|
+
__decorateClass([
|
91
|
+
property({ type: Boolean, reflect: true })
|
92
|
+
], Popover.prototype, "autoUpdate", 2);
|
93
|
+
__decorateClass([
|
94
|
+
property({ type: Object })
|
95
|
+
], Popover.prototype, "autoUpdateOptions", 2);
|
96
|
+
__decorateClass([
|
97
|
+
state()
|
98
|
+
], Popover.prototype, "computed", 2);
|
99
|
+
Popover = __decorateClass([
|
100
|
+
customElement("prosekit-popover")
|
101
|
+
], Popover);
|
102
|
+
function roundByDPR(value) {
|
103
|
+
const dpr = window.devicePixelRatio || 1;
|
104
|
+
return Math.round(value * dpr) / dpr;
|
105
|
+
}
|
106
|
+
|
107
|
+
export {
|
108
|
+
Popover
|
109
|
+
};
|