@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
@@ -1,6 +1,7 @@
|
|
1
1
|
import {
|
2
|
-
Popover
|
3
|
-
|
2
|
+
Popover,
|
3
|
+
popoverPropsNames
|
4
|
+
} from "./chunk-OZUEYWYU.js";
|
4
5
|
import {
|
5
6
|
defineCustomElement
|
6
7
|
} from "./chunk-S32IZIQF.js";
|
@@ -8,9 +9,66 @@ import {
|
|
8
9
|
// src/components/inline-popover/index.ts
|
9
10
|
import "@prosekit/core";
|
10
11
|
|
11
|
-
// src/
|
12
|
+
// src/controllers/use-editor-focus-event.ts
|
13
|
+
import {
|
14
|
+
defineFocusChangeHandler
|
15
|
+
} from "@prosekit/core";
|
16
|
+
|
17
|
+
// src/controllers/use-editor-extension.ts
|
18
|
+
import "@prosekit/core";
|
19
|
+
function useEditorExtension(host, extension) {
|
20
|
+
let cleanup;
|
21
|
+
let editor;
|
22
|
+
const update = () => {
|
23
|
+
cleanup == null ? void 0 : cleanup();
|
24
|
+
cleanup = editor == null ? void 0 : editor.use(extension);
|
25
|
+
};
|
26
|
+
const hostConnected = () => {
|
27
|
+
editor = host.editor;
|
28
|
+
update();
|
29
|
+
};
|
30
|
+
const hostUpdated = () => {
|
31
|
+
const newEditor = host.editor;
|
32
|
+
if (editor !== newEditor) {
|
33
|
+
editor = newEditor;
|
34
|
+
update();
|
35
|
+
}
|
36
|
+
};
|
37
|
+
const hostDisconnected = () => {
|
38
|
+
cleanup == null ? void 0 : cleanup();
|
39
|
+
cleanup = void 0;
|
40
|
+
};
|
41
|
+
host.addController({
|
42
|
+
hostConnected,
|
43
|
+
hostDisconnected,
|
44
|
+
hostUpdated
|
45
|
+
});
|
46
|
+
}
|
47
|
+
|
48
|
+
// src/controllers/use-editor-focus-event.ts
|
49
|
+
function useEditorFocusChangeEvent(host, handler) {
|
50
|
+
const extension = defineFocusChangeHandler(handler);
|
51
|
+
useEditorExtension(host, extension);
|
52
|
+
}
|
53
|
+
|
54
|
+
// src/controllers/use-editor-update-event.ts
|
12
55
|
import { defineUpdateHandler } from "@prosekit/core";
|
13
|
-
|
56
|
+
function useEditorUpdateEvent(host, handler) {
|
57
|
+
const extension = defineUpdateHandler(handler);
|
58
|
+
useEditorExtension(host, extension);
|
59
|
+
}
|
60
|
+
|
61
|
+
// src/controllers/use-pointer-down-event.ts
|
62
|
+
function usePointerDownEvent(host, handler) {
|
63
|
+
host.addController({
|
64
|
+
hostConnected: () => {
|
65
|
+
host.addEventListener("pointerdown", handler);
|
66
|
+
},
|
67
|
+
hostDisconnected: () => {
|
68
|
+
host.removeEventListener("pointerdown", handler);
|
69
|
+
}
|
70
|
+
});
|
71
|
+
}
|
14
72
|
|
15
73
|
// src/components/inline-popover/helpers.ts
|
16
74
|
import { isNodeSelection, isTextSelection } from "@prosekit/core";
|
@@ -28,7 +86,14 @@ function getVirtualSelectionElement(view) {
|
|
28
86
|
}
|
29
87
|
const selection = view.state.selection;
|
30
88
|
if (!selection.empty && !isInCodeBlock(selection) && (isTextSelection(selection) || isNodeSelection(selection))) {
|
31
|
-
|
89
|
+
const range = getDomRange();
|
90
|
+
if (!range)
|
91
|
+
return;
|
92
|
+
return {
|
93
|
+
contextElement: view.dom,
|
94
|
+
getBoundingClientRect: () => range.getBoundingClientRect(),
|
95
|
+
getClientRects: () => range.getClientRects()
|
96
|
+
};
|
32
97
|
}
|
33
98
|
}
|
34
99
|
function getDomRange() {
|
@@ -43,115 +108,69 @@ function getDomRange() {
|
|
43
108
|
return range;
|
44
109
|
}
|
45
110
|
|
46
|
-
// src/components/inline-popover/
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
if (
|
55
|
-
|
56
|
-
this.defineExtension();
|
57
|
-
this.host.requestUpdate();
|
111
|
+
// src/components/inline-popover/use-inline-popover.ts
|
112
|
+
function useInlinePopover(host, onReferenceChange) {
|
113
|
+
let interacting = false;
|
114
|
+
let reference;
|
115
|
+
usePointerDownEvent(host, () => {
|
116
|
+
interacting = true;
|
117
|
+
});
|
118
|
+
useEditorFocusChangeEvent(host, (focus) => {
|
119
|
+
if (focus) {
|
120
|
+
interacting = false;
|
58
121
|
}
|
59
|
-
}
|
60
|
-
|
61
|
-
|
62
|
-
const handlePointerDown = () => {
|
63
|
-
this.interacting = true;
|
64
|
-
};
|
65
|
-
this.host.addEventListener("pointerdown", handlePointerDown);
|
66
|
-
const cleanupDismissable = trackDismissableElement(this.host, {
|
67
|
-
defer: true,
|
68
|
-
pointerBlocking: false,
|
69
|
-
onDismiss: () => {
|
70
|
-
this.interacting = false;
|
71
|
-
}
|
72
|
-
});
|
73
|
-
(_a = this.cleanupEventListener) == null ? void 0 : _a.call(this);
|
74
|
-
this.cleanupEventListener = () => {
|
75
|
-
this.host.removeEventListener("pointerdown", handlePointerDown);
|
76
|
-
cleanupDismissable();
|
77
|
-
};
|
78
|
-
}
|
79
|
-
hostDisconnected() {
|
80
|
-
var _a, _b;
|
81
|
-
(_a = this.cleanupExtension) == null ? void 0 : _a.call(this);
|
82
|
-
this.cleanupExtension = void 0;
|
83
|
-
(_b = this.cleanupEventListener) == null ? void 0 : _b.call(this);
|
84
|
-
this.cleanupEventListener = void 0;
|
85
|
-
}
|
86
|
-
update() {
|
87
|
-
const editor = this.editor;
|
88
|
-
if (!editor || this.interacting) {
|
122
|
+
});
|
123
|
+
useEditorUpdateEvent(host, (view) => {
|
124
|
+
if (interacting) {
|
89
125
|
return;
|
90
126
|
}
|
91
|
-
const
|
92
|
-
if (
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
}
|
97
|
-
defineExtension() {
|
98
|
-
var _a;
|
99
|
-
const editor = this.editor;
|
100
|
-
if (!editor) {
|
101
|
-
return;
|
127
|
+
const ref = getVirtualSelectionElement(view);
|
128
|
+
if (reference !== ref) {
|
129
|
+
reference = ref;
|
130
|
+
onReferenceChange(reference);
|
131
|
+
host.requestUpdate();
|
102
132
|
}
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
};
|
108
|
-
|
109
|
-
// src/components/inline-popover/default-popover-options.ts
|
110
|
-
import { inline, offset, shift } from "@floating-ui/dom";
|
111
|
-
var defaultPopoverOptions = {
|
112
|
-
placement: "top",
|
113
|
-
strategy: "absolute",
|
114
|
-
middleware: [
|
115
|
-
inline(),
|
116
|
-
offset(8),
|
117
|
-
shift({ mainAxis: true, crossAxis: true, padding: 8 })
|
118
|
-
]
|
119
|
-
};
|
133
|
+
});
|
134
|
+
const getReference = () => reference;
|
135
|
+
return getReference;
|
136
|
+
}
|
120
137
|
|
121
138
|
// src/components/inline-popover/index.ts
|
122
|
-
var propNames = ["editor",
|
139
|
+
var propNames = ["editor", ...popoverPropsNames];
|
123
140
|
var InlinePopover = class extends Popover {
|
141
|
+
/**
|
142
|
+
* @hidden
|
143
|
+
*/
|
124
144
|
constructor() {
|
125
|
-
super(
|
126
|
-
this.
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
145
|
+
super();
|
146
|
+
this.positioning = {
|
147
|
+
strategy: "fixed",
|
148
|
+
placement: "top",
|
149
|
+
offset: 12,
|
150
|
+
flip: false,
|
151
|
+
hide: true,
|
152
|
+
shift: true,
|
153
|
+
overlap: true,
|
154
|
+
fitViewport: false,
|
155
|
+
inline: true
|
156
|
+
};
|
157
|
+
useInlinePopover(this, (reference) => {
|
158
|
+
this.reference = reference;
|
159
|
+
});
|
132
160
|
}
|
133
161
|
/**
|
134
162
|
* @hidden
|
135
163
|
*/
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
this.controller.setEditor(this.editor);
|
140
|
-
}
|
141
|
-
this.active = !!((_a = this.controller) == null ? void 0 : _a.reference);
|
142
|
-
this.reference = (_b = this.controller.reference) != null ? _b : void 0;
|
143
|
-
this.options = this.popoverOptions;
|
164
|
+
updated(changedProperties) {
|
165
|
+
super.updated(changedProperties);
|
166
|
+
this.open = !!this.reference;
|
144
167
|
}
|
145
168
|
/**
|
146
169
|
* @hidden
|
147
170
|
*/
|
148
171
|
hide() {
|
149
|
-
var _a;
|
150
172
|
super.hide();
|
151
|
-
|
152
|
-
this.controller.reference = void 0;
|
153
|
-
this.reference = void 0;
|
154
|
-
}
|
173
|
+
this.reference = void 0;
|
155
174
|
}
|
156
175
|
};
|
157
176
|
/**
|
@@ -159,8 +178,7 @@ var InlinePopover = class extends Popover {
|
|
159
178
|
*/
|
160
179
|
InlinePopover.properties = {
|
161
180
|
...Popover.properties,
|
162
|
-
editor: { attribute: false }
|
163
|
-
popoverOptions: { attribute: false }
|
181
|
+
editor: { attribute: false }
|
164
182
|
};
|
165
183
|
defineCustomElement("prosekit-inline-popover", InlinePopover);
|
166
184
|
export {
|
@@ -1,5 +1,6 @@
|
|
1
1
|
export { AutoUpdateOptions } from './_tsup-dts-rollup';
|
2
|
-
export {
|
2
|
+
export { PositioningOptions_alias_2 as PositioningOptions } from './_tsup-dts-rollup';
|
3
|
+
export { popoverPropsNames } from './_tsup-dts-rollup';
|
3
4
|
export { propNames_alias_13 as propNames } from './_tsup-dts-rollup';
|
4
5
|
export { PopoverProps } from './_tsup-dts-rollup';
|
5
6
|
export { Popover } from './_tsup-dts-rollup';
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@prosekit/lit",
|
3
3
|
"type": "module",
|
4
|
-
"version": "0.
|
4
|
+
"version": "0.2.0",
|
5
5
|
"private": false,
|
6
6
|
"author": {
|
7
7
|
"name": "ocavue",
|
@@ -95,13 +95,15 @@
|
|
95
95
|
"dist"
|
96
96
|
],
|
97
97
|
"dependencies": {
|
98
|
-
"@floating-ui/dom": "^1.5.
|
98
|
+
"@floating-ui/dom": "^1.5.3",
|
99
99
|
"@lit/context": "^1.1.0",
|
100
100
|
"@prosekit/core": "^0.2.4",
|
101
|
-
"@prosekit/extensions": "^0.2.
|
101
|
+
"@prosekit/extensions": "^0.2.4",
|
102
102
|
"@prosekit/pm": "^0.1.1",
|
103
103
|
"@superhuman/command-score": "^0.5.0",
|
104
104
|
"@zag-js/dismissable": "^0.32.0",
|
105
|
+
"@zag-js/dom-query": "^0.32.0",
|
106
|
+
"@zag-js/utils": "^0.32.0",
|
105
107
|
"lit": "^3.1.1"
|
106
108
|
},
|
107
109
|
"devDependencies": {
|
@@ -109,7 +111,7 @@
|
|
109
111
|
"minify-literals": "^1.0.8",
|
110
112
|
"tsup": "^8.0.1",
|
111
113
|
"typescript": "^5.3.3",
|
112
|
-
"vitest": "^1.
|
114
|
+
"vitest": "^1.2.0"
|
113
115
|
},
|
114
116
|
"scripts": {
|
115
117
|
"build:tsup": "tsup",
|
package/dist/chunk-CUH6G34Q.js
DELETED
@@ -1,224 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
LightElement,
|
3
|
-
defineCustomElement
|
4
|
-
} from "./chunk-S32IZIQF.js";
|
5
|
-
|
6
|
-
// src/components/popover/index.ts
|
7
|
-
import {
|
8
|
-
autoUpdate,
|
9
|
-
computePosition
|
10
|
-
} from "@floating-ui/dom";
|
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;
|
15
|
-
|
16
|
-
// src/utils/round-by-dpr.ts
|
17
|
-
function roundByDPR(value) {
|
18
|
-
const dpr = window.devicePixelRatio || 1;
|
19
|
-
return Math.round(value * dpr) / dpr;
|
20
|
-
}
|
21
|
-
|
22
|
-
// src/components/popover/default-popover-options.ts
|
23
|
-
import {
|
24
|
-
offset,
|
25
|
-
shift,
|
26
|
-
size
|
27
|
-
} from "@floating-ui/dom";
|
28
|
-
|
29
|
-
// src/components/popover/options.ts
|
30
|
-
import "@floating-ui/dom";
|
31
|
-
|
32
|
-
// src/components/popover/default-popover-options.ts
|
33
|
-
var defaultDetectOverflowOptions = {
|
34
|
-
padding: 8,
|
35
|
-
boundary
|
36
|
-
};
|
37
|
-
var defaultPopoverOptions = {
|
38
|
-
placement: "bottom",
|
39
|
-
middleware: [
|
40
|
-
offset({ mainAxis: 2, crossAxis: 0 }),
|
41
|
-
shift({ ...defaultDetectOverflowOptions }),
|
42
|
-
size({
|
43
|
-
apply: ({ availableWidth, availableHeight, elements }) => {
|
44
|
-
elements.floating.style.setProperty(
|
45
|
-
"max-width",
|
46
|
-
`${Math.floor(availableWidth)}px`
|
47
|
-
);
|
48
|
-
elements.floating.style.setProperty(
|
49
|
-
"max-height",
|
50
|
-
`${Math.floor(availableHeight)}px`
|
51
|
-
);
|
52
|
-
},
|
53
|
-
...defaultDetectOverflowOptions
|
54
|
-
})
|
55
|
-
]
|
56
|
-
};
|
57
|
-
|
58
|
-
// src/components/popover/index.ts
|
59
|
-
var propNames = [
|
60
|
-
"active",
|
61
|
-
"reference",
|
62
|
-
"options",
|
63
|
-
"autoUpdate",
|
64
|
-
"autoUpdateOptions"
|
65
|
-
];
|
66
|
-
var Popover = class extends LightElement {
|
67
|
-
constructor() {
|
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
|
-
*/
|
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
|
-
*/
|
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
|
-
*/
|
97
|
-
this.dismiss = "on";
|
98
|
-
this.handleDocumentMouseDown = (event) => {
|
99
|
-
const path = event.composedPath();
|
100
|
-
if (!path.includes(this)) {
|
101
|
-
this.hide();
|
102
|
-
}
|
103
|
-
};
|
104
|
-
this.handleDocumentKeyDown = (event) => {
|
105
|
-
if (event.key === "Escape" && this.active) {
|
106
|
-
event.stopPropagation();
|
107
|
-
this.hide();
|
108
|
-
return;
|
109
|
-
}
|
110
|
-
};
|
111
|
-
}
|
112
|
-
/**
|
113
|
-
* @hidden
|
114
|
-
*/
|
115
|
-
connectedCallback() {
|
116
|
-
super.connectedCallback();
|
117
|
-
const clickEnabled = this.dismiss === "on" || this.dismiss === "click";
|
118
|
-
const escapeEnabled = this.dismiss === "on" || this.dismiss === "escape";
|
119
|
-
const handleMouseDown = clickEnabled ? this.handleDocumentMouseDown.bind(this) : null;
|
120
|
-
const handleKeyDown = escapeEnabled ? this.handleDocumentKeyDown.bind(this) : null;
|
121
|
-
handleMouseDown && document.addEventListener("mousedown", handleMouseDown);
|
122
|
-
handleKeyDown && document.addEventListener("keydown", handleKeyDown);
|
123
|
-
this.disposeEventListeners = () => {
|
124
|
-
handleMouseDown && document.removeEventListener("mousedown", handleMouseDown);
|
125
|
-
handleKeyDown && document.removeEventListener("keydown", handleKeyDown);
|
126
|
-
};
|
127
|
-
}
|
128
|
-
/**
|
129
|
-
* @hidden
|
130
|
-
*/
|
131
|
-
disconnectedCallback() {
|
132
|
-
var _a, _b;
|
133
|
-
super.disconnectedCallback();
|
134
|
-
(_a = this.disposeAutoUpdate) == null ? void 0 : _a.call(this);
|
135
|
-
this.disposeAutoUpdate = void 0;
|
136
|
-
(_b = this.disposeEventListeners) == null ? void 0 : _b.call(this);
|
137
|
-
this.disposeEventListeners = void 0;
|
138
|
-
}
|
139
|
-
/**
|
140
|
-
* @hidden
|
141
|
-
*/
|
142
|
-
updated(changedProperties) {
|
143
|
-
var _a;
|
144
|
-
super.updated(changedProperties);
|
145
|
-
if (popoverAvailable && this.isConnected) {
|
146
|
-
this.popover = "manual";
|
147
|
-
(_a = this.togglePopover) == null ? void 0 : _a.call(this, this.active);
|
148
|
-
}
|
149
|
-
this.start();
|
150
|
-
this.setHidden(!this.active);
|
151
|
-
}
|
152
|
-
/**
|
153
|
-
* @hidden
|
154
|
-
*/
|
155
|
-
start() {
|
156
|
-
var _a;
|
157
|
-
(_a = this.disposeAutoUpdate) == null ? void 0 : _a.call(this);
|
158
|
-
this.disposeAutoUpdate = void 0;
|
159
|
-
const reference = this.reference;
|
160
|
-
if (!reference)
|
161
|
-
return;
|
162
|
-
if (!this.active)
|
163
|
-
return;
|
164
|
-
if (this.autoUpdate) {
|
165
|
-
this.disposeAutoUpdate = autoUpdate(
|
166
|
-
reference,
|
167
|
-
this,
|
168
|
-
() => void this.compute(),
|
169
|
-
this.autoUpdateOptions
|
170
|
-
);
|
171
|
-
} else {
|
172
|
-
void this.compute();
|
173
|
-
}
|
174
|
-
}
|
175
|
-
/**
|
176
|
-
* @hidden
|
177
|
-
*/
|
178
|
-
async compute() {
|
179
|
-
var _a, _b, _c;
|
180
|
-
const reference = this.reference;
|
181
|
-
if (!reference)
|
182
|
-
return;
|
183
|
-
if (!this.active)
|
184
|
-
return;
|
185
|
-
this.setHidden(false);
|
186
|
-
this.style.setProperty("margin", "0");
|
187
|
-
this.style.setProperty("top", "0");
|
188
|
-
this.style.setProperty("left", "0");
|
189
|
-
this.style.setProperty("position", (_b = (_a = this.options) == null ? void 0 : _a.strategy) != null ? _b : "absolute");
|
190
|
-
const options = (_c = this.options) != null ? _c : defaultPopoverOptions;
|
191
|
-
const computed = await computePosition(reference, this, options);
|
192
|
-
const { x, y, strategy } = computed != null ? computed : { x: 0, y: 0, strategy: "absolute" };
|
193
|
-
this.style.setProperty("opacity", "1");
|
194
|
-
this.style.setProperty("position", strategy);
|
195
|
-
this.style.setProperty(
|
196
|
-
"transform",
|
197
|
-
`translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`
|
198
|
-
);
|
199
|
-
}
|
200
|
-
/**
|
201
|
-
* @hidden
|
202
|
-
*/
|
203
|
-
hide() {
|
204
|
-
this.active = false;
|
205
|
-
}
|
206
|
-
};
|
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);
|
219
|
-
|
220
|
-
export {
|
221
|
-
boundary,
|
222
|
-
propNames,
|
223
|
-
Popover
|
224
|
-
};
|