@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
@@ -0,0 +1,169 @@
|
|
1
|
+
import {
|
2
|
+
__decorateClass,
|
3
|
+
blockComponentStyles
|
4
|
+
} from "./chunk-43BFWKM2.js";
|
5
|
+
|
6
|
+
// src/elements/menu.ts
|
7
|
+
import { ProseKitError, addKeymap } from "@prosekit/core";
|
8
|
+
import { LitElement, html } from "lit";
|
9
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
10
|
+
|
11
|
+
// src/utils/is-menu-item.ts
|
12
|
+
function isMenuItem(element) {
|
13
|
+
var _a, _b;
|
14
|
+
return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-menu-item" || ["menuitem", "menuitemcheckbox", "menuitemradio"].includes(
|
15
|
+
(_b = element == null ? void 0 : element.getAttribute("role")) != null ? _b : ""
|
16
|
+
);
|
17
|
+
}
|
18
|
+
|
19
|
+
// src/utils/visibility.ts
|
20
|
+
function isVisibleElement(element) {
|
21
|
+
return !element.hidden;
|
22
|
+
}
|
23
|
+
|
24
|
+
// src/elements/menu.ts
|
25
|
+
var Menu = class extends LitElement {
|
26
|
+
/** @hidden */
|
27
|
+
constructor() {
|
28
|
+
super();
|
29
|
+
/** @hidden */
|
30
|
+
this.cleanup = [];
|
31
|
+
}
|
32
|
+
/** @hidden */
|
33
|
+
firstUpdated() {
|
34
|
+
if (!this.editor) {
|
35
|
+
throw new ProseKitError("Property editor is required");
|
36
|
+
}
|
37
|
+
const extension = addKeymap({
|
38
|
+
ArrowUp: () => this.handleArrowUp(),
|
39
|
+
ArrowDown: () => this.handleArrowDown(),
|
40
|
+
Escape: () => this.handleEscape(),
|
41
|
+
Enter: () => this.handleEnter()
|
42
|
+
});
|
43
|
+
this.cleanup.push(this.editor.use(extension));
|
44
|
+
}
|
45
|
+
updated(_changedProperties) {
|
46
|
+
this.ensureFocusedItem();
|
47
|
+
}
|
48
|
+
/** @hidden */
|
49
|
+
disconnectedCallback() {
|
50
|
+
super.disconnectedCallback();
|
51
|
+
this.cleanup.forEach((fn) => fn());
|
52
|
+
}
|
53
|
+
ensureFocusedItem() {
|
54
|
+
const items = this.queryVisibleMenuItems();
|
55
|
+
if (this.focusedItem && items.includes(this.focusedItem)) {
|
56
|
+
return;
|
57
|
+
}
|
58
|
+
this.focusItem(items[0]);
|
59
|
+
}
|
60
|
+
/** @hidden */
|
61
|
+
handleArrowUp() {
|
62
|
+
const items = this.queryVisibleMenuItems();
|
63
|
+
let prevIndex = this.focusedItem ? items.indexOf(this.focusedItem) : 0;
|
64
|
+
if (prevIndex === -1) {
|
65
|
+
prevIndex = 0;
|
66
|
+
}
|
67
|
+
const nextIndex = (prevIndex + items.length - 1) % items.length;
|
68
|
+
this.focusItem(items[nextIndex]);
|
69
|
+
return true;
|
70
|
+
}
|
71
|
+
/** @hidden */
|
72
|
+
handleArrowDown() {
|
73
|
+
const items = this.queryVisibleMenuItems();
|
74
|
+
const prevIndex = this.focusedItem ? items.indexOf(this.focusedItem) : -1;
|
75
|
+
const nextIndex = (prevIndex + items.length + 1) % items.length;
|
76
|
+
this.focusItem(items[nextIndex]);
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
/** @hidden */
|
80
|
+
handleEscape() {
|
81
|
+
const event = new CustomEvent("menu-dismiss", {
|
82
|
+
bubbles: true,
|
83
|
+
composed: false
|
84
|
+
});
|
85
|
+
this.dispatchEvent(event);
|
86
|
+
this.blurItem();
|
87
|
+
return true;
|
88
|
+
}
|
89
|
+
/** @hidden */
|
90
|
+
handleMouseOver(event) {
|
91
|
+
const target = event.target;
|
92
|
+
if (isMenuItem(target) && isVisibleElement(target)) {
|
93
|
+
this.focusItem(target);
|
94
|
+
}
|
95
|
+
return true;
|
96
|
+
}
|
97
|
+
/** @hidden */
|
98
|
+
handleEnter() {
|
99
|
+
if (this.focusedItem) {
|
100
|
+
this.handleSelect(this.focusedItem);
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
/** @hidden */
|
106
|
+
handleClick(event) {
|
107
|
+
const target = event.target;
|
108
|
+
if (isMenuItem(target) && isVisibleElement(target)) {
|
109
|
+
this.handleSelect(target);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
/** @hidden */
|
113
|
+
handleSelect(menuItem) {
|
114
|
+
var _a;
|
115
|
+
(_a = menuItem.onSelect) == null ? void 0 : _a.call(menuItem);
|
116
|
+
const event = new CustomEvent("menu-select", {
|
117
|
+
bubbles: true,
|
118
|
+
composed: false
|
119
|
+
});
|
120
|
+
this.dispatchEvent(event);
|
121
|
+
this.blurItem();
|
122
|
+
}
|
123
|
+
/** @hidden */
|
124
|
+
focusItem(item) {
|
125
|
+
this.blurItem();
|
126
|
+
if (!item) {
|
127
|
+
return;
|
128
|
+
}
|
129
|
+
item.focused = true;
|
130
|
+
this.focusedItem = item;
|
131
|
+
}
|
132
|
+
/** @hidden */
|
133
|
+
blurItem() {
|
134
|
+
if (this.focusedItem) {
|
135
|
+
this.focusedItem.focused = false;
|
136
|
+
this.focusedItem = void 0;
|
137
|
+
}
|
138
|
+
}
|
139
|
+
/** @hidden */
|
140
|
+
queryAllMenuItems() {
|
141
|
+
var _a, _b, _c;
|
142
|
+
return (_c = (_b = (_a = this.defaultSlot) == null ? void 0 : _a.assignedElements({ flatten: true })) == null ? void 0 : _b.filter(isMenuItem)) != null ? _c : [];
|
143
|
+
}
|
144
|
+
/** @hidden */
|
145
|
+
queryVisibleMenuItems() {
|
146
|
+
return this.queryAllMenuItems().filter(isVisibleElement);
|
147
|
+
}
|
148
|
+
/** @hidden */
|
149
|
+
render() {
|
150
|
+
return html`<div role="menu" @mouseover="${this.handleMouseOver.bind(this)}" @click="${this.handleClick.bind(this)}"><slot></slot></div>`;
|
151
|
+
}
|
152
|
+
};
|
153
|
+
/** @hidden */
|
154
|
+
Menu.styles = blockComponentStyles;
|
155
|
+
__decorateClass([
|
156
|
+
property({ attribute: false })
|
157
|
+
], Menu.prototype, "editor", 2);
|
158
|
+
__decorateClass([
|
159
|
+
state()
|
160
|
+
], Menu.prototype, "focusedItem", 2);
|
161
|
+
__decorateClass([
|
162
|
+
query("slot")
|
163
|
+
], Menu.prototype, "defaultSlot", 2);
|
164
|
+
Menu = __decorateClass([
|
165
|
+
customElement("prosekit-menu")
|
166
|
+
], Menu);
|
167
|
+
export {
|
168
|
+
Menu
|
169
|
+
};
|
@@ -0,0 +1,211 @@
|
|
1
|
+
import {
|
2
|
+
popoverSuggestionContext
|
3
|
+
} from "./chunk-TFM6CTEO.js";
|
4
|
+
import "./chunk-VYMBIH4T.js";
|
5
|
+
import {
|
6
|
+
blockComponentStyles
|
7
|
+
} from "./chunk-XEV4EE3R.js";
|
8
|
+
import {
|
9
|
+
__decorateClass
|
10
|
+
} from "./chunk-S65R2BUY.js";
|
11
|
+
|
12
|
+
// src/elements/popover-slash.ts
|
13
|
+
import { html } from "lit";
|
14
|
+
import { customElement } from "lit/decorators.js";
|
15
|
+
|
16
|
+
// src/elements/popover-abs.ts
|
17
|
+
import { provide } from "@lit-labs/context";
|
18
|
+
import { LitElement } from "lit";
|
19
|
+
import { property, state } from "lit/decorators.js";
|
20
|
+
|
21
|
+
// src/controllers/suggestion-controller.ts
|
22
|
+
import { ProseKitError } from "@prosekit/core";
|
23
|
+
import { addSuggestion } from "@prosekit/extension-suggestion";
|
24
|
+
var SuggestionController = class {
|
25
|
+
constructor(host, editor, rules, onContext) {
|
26
|
+
this.host = host;
|
27
|
+
this.editor = editor;
|
28
|
+
this.rules = rules;
|
29
|
+
this.onContext = onContext;
|
30
|
+
this.connected = false;
|
31
|
+
this.reference = null;
|
32
|
+
this.removeExtension = null;
|
33
|
+
if (!editor) {
|
34
|
+
throw new ProseKitError("Missing 'editor' property");
|
35
|
+
}
|
36
|
+
if (!rules) {
|
37
|
+
throw new ProseKitError("Missing 'rules' property");
|
38
|
+
}
|
39
|
+
this.host.addController(this);
|
40
|
+
}
|
41
|
+
hostUpdated() {
|
42
|
+
var _a;
|
43
|
+
if (this.connected)
|
44
|
+
return;
|
45
|
+
this.connected = true;
|
46
|
+
const editor = this.editor;
|
47
|
+
if (!editor) {
|
48
|
+
throw new ProseKitError("Missing 'editor' property");
|
49
|
+
}
|
50
|
+
if (!this.rules) {
|
51
|
+
throw new ProseKitError("Missing 'rules' property");
|
52
|
+
}
|
53
|
+
const extension = addSuggestion({
|
54
|
+
rules: this.rules,
|
55
|
+
onMatch: ({ dismiss, deleteMatch, match, matchAfter }) => {
|
56
|
+
var _a2, _b;
|
57
|
+
const span = editor.view.dom.querySelector(
|
58
|
+
".prosemirror-prediction-match"
|
59
|
+
);
|
60
|
+
if (span) {
|
61
|
+
this.reference = span;
|
62
|
+
}
|
63
|
+
const matchText = match[0] + ((_a2 = matchAfter == null ? void 0 : matchAfter[0]) != null ? _a2 : "");
|
64
|
+
(_b = this.onContext) == null ? void 0 : _b.call(this, {
|
65
|
+
active: true,
|
66
|
+
query: matchText,
|
67
|
+
onDismiss: () => {
|
68
|
+
dismiss();
|
69
|
+
},
|
70
|
+
onSubmit: () => {
|
71
|
+
deleteMatch();
|
72
|
+
}
|
73
|
+
});
|
74
|
+
},
|
75
|
+
onDeactivate: () => {
|
76
|
+
var _a2;
|
77
|
+
this.reference = null;
|
78
|
+
(_a2 = this.onContext) == null ? void 0 : _a2.call(this, {
|
79
|
+
active: false
|
80
|
+
});
|
81
|
+
}
|
82
|
+
});
|
83
|
+
(_a = this.removeExtension) == null ? void 0 : _a.call(this);
|
84
|
+
this.removeExtension = editor.use(extension);
|
85
|
+
}
|
86
|
+
hostDisconnected() {
|
87
|
+
var _a;
|
88
|
+
this.connected = false;
|
89
|
+
(_a = this.removeExtension) == null ? void 0 : _a.call(this);
|
90
|
+
this.removeExtension = null;
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
// src/elements/popover-abs.ts
|
95
|
+
import { flip, inline, offset, shift, size } from "@floating-ui/dom";
|
96
|
+
var defaultDetectOverflowOptions = {
|
97
|
+
// Make sure the popover is always at least 8px away from the boundary
|
98
|
+
padding: 8
|
99
|
+
// boundary: document.body,
|
100
|
+
};
|
101
|
+
var defaultPopoverOptions = {
|
102
|
+
placement: "bottom-end",
|
103
|
+
middleware: [
|
104
|
+
offset(({ rects }) => ({
|
105
|
+
// Put the popover at the bottom right corner
|
106
|
+
alignmentAxis: -rects.floating.width,
|
107
|
+
// Move down the popover by 4px
|
108
|
+
mainAxis: 4
|
109
|
+
})),
|
110
|
+
size({
|
111
|
+
apply: ({ availableHeight, elements }) => {
|
112
|
+
const style = {
|
113
|
+
// Minimum acceptable height is 100px.
|
114
|
+
// `flip` will then take over.
|
115
|
+
maxHeight: `${Math.max(100, availableHeight)}px`,
|
116
|
+
overflowY: "auto"
|
117
|
+
};
|
118
|
+
Object.assign(elements.floating.style, style);
|
119
|
+
},
|
120
|
+
...defaultDetectOverflowOptions
|
121
|
+
}),
|
122
|
+
// Flip the popover to the top if it's overflowing the viewport
|
123
|
+
flip({
|
124
|
+
fallbackStrategy: "initialPlacement",
|
125
|
+
fallbackAxisSideDirection: "start",
|
126
|
+
crossAxis: false,
|
127
|
+
...defaultDetectOverflowOptions
|
128
|
+
}),
|
129
|
+
shift({
|
130
|
+
...defaultDetectOverflowOptions
|
131
|
+
}),
|
132
|
+
// Use the text caret as the reference point
|
133
|
+
inline()
|
134
|
+
]
|
135
|
+
};
|
136
|
+
var PopoverAbstract = class extends LitElement {
|
137
|
+
/** @hidden */
|
138
|
+
constructor() {
|
139
|
+
super();
|
140
|
+
this.popoverOptions = defaultPopoverOptions;
|
141
|
+
this.context = { active: false };
|
142
|
+
}
|
143
|
+
/** @hidden */
|
144
|
+
firstUpdated() {
|
145
|
+
setTimeout(() => {
|
146
|
+
this.controller = new SuggestionController(
|
147
|
+
this,
|
148
|
+
this.editor,
|
149
|
+
this.rules,
|
150
|
+
(context) => {
|
151
|
+
var _a;
|
152
|
+
(_a = this.onContext) == null ? void 0 : _a.call(this, context);
|
153
|
+
this.context = context;
|
154
|
+
}
|
155
|
+
);
|
156
|
+
});
|
157
|
+
}
|
158
|
+
/** @hidden */
|
159
|
+
get active() {
|
160
|
+
var _a;
|
161
|
+
return !!((_a = this.controller) == null ? void 0 : _a.reference);
|
162
|
+
}
|
163
|
+
};
|
164
|
+
/** @hidden */
|
165
|
+
PopoverAbstract.styles = blockComponentStyles;
|
166
|
+
__decorateClass([
|
167
|
+
property({ attribute: false })
|
168
|
+
], PopoverAbstract.prototype, "editor", 2);
|
169
|
+
__decorateClass([
|
170
|
+
property({ attribute: false })
|
171
|
+
], PopoverAbstract.prototype, "popoverOptions", 2);
|
172
|
+
__decorateClass([
|
173
|
+
provide({ context: popoverSuggestionContext }),
|
174
|
+
state()
|
175
|
+
], PopoverAbstract.prototype, "context", 2);
|
176
|
+
__decorateClass([
|
177
|
+
property({ attribute: false })
|
178
|
+
], PopoverAbstract.prototype, "onContext", 2);
|
179
|
+
__decorateClass([
|
180
|
+
state()
|
181
|
+
], PopoverAbstract.prototype, "controller", 2);
|
182
|
+
|
183
|
+
// src/elements/popover-slash.ts
|
184
|
+
var PopoverSlash = class extends PopoverAbstract {
|
185
|
+
constructor() {
|
186
|
+
super(...arguments);
|
187
|
+
this.rules = [
|
188
|
+
{
|
189
|
+
match: /\/.*$/iu,
|
190
|
+
matchAfter: /^\S*/
|
191
|
+
}
|
192
|
+
];
|
193
|
+
}
|
194
|
+
/** @hidden */
|
195
|
+
render() {
|
196
|
+
var _a, _b;
|
197
|
+
return html`<prosekit-popover .active="${this.active}" .reference="${(_b = (_a = this.controller) == null ? void 0 : _a.reference) != null ? _b : void 0}" .options="${this.popoverOptions}"><slot @menu-dismiss="${() => {
|
198
|
+
var _a2, _b2;
|
199
|
+
return (_b2 = (_a2 = this.context) == null ? void 0 : _a2.onDismiss) == null ? void 0 : _b2.call(_a2);
|
200
|
+
}}" @menu-select="${() => {
|
201
|
+
var _a2, _b2;
|
202
|
+
return (_b2 = (_a2 = this.context) == null ? void 0 : _a2.onSubmit) == null ? void 0 : _b2.call(_a2);
|
203
|
+
}}"></slot></prosekit-popover>`;
|
204
|
+
}
|
205
|
+
};
|
206
|
+
PopoverSlash = __decorateClass([
|
207
|
+
customElement("prosekit-popover-slash")
|
208
|
+
], PopoverSlash);
|
209
|
+
export {
|
210
|
+
PopoverSlash
|
211
|
+
};
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import {
|
2
|
+
popoverSuggestionContext
|
3
|
+
} from "./chunk-TFM6CTEO.js";
|
4
|
+
import "./chunk-VYMBIH4T.js";
|
5
|
+
import "./chunk-XEV4EE3R.js";
|
6
|
+
import {
|
7
|
+
__decorateClass
|
8
|
+
} from "./chunk-S65R2BUY.js";
|
9
|
+
|
10
|
+
// src/elements/popover-suggestion-consumer.ts
|
11
|
+
import { consume } from "@lit-labs/context";
|
12
|
+
import { LitElement, html } from "lit";
|
13
|
+
import { customElement, property } from "lit/decorators.js";
|
14
|
+
var PopoverSuggestionConsumer = class extends LitElement {
|
15
|
+
updated() {
|
16
|
+
var _a;
|
17
|
+
if (this.contextA) {
|
18
|
+
(_a = this.onContext) == null ? void 0 : _a.call(this, this.contextA);
|
19
|
+
}
|
20
|
+
}
|
21
|
+
render() {
|
22
|
+
return html`<slot></slot>`;
|
23
|
+
}
|
24
|
+
};
|
25
|
+
__decorateClass([
|
26
|
+
consume({ context: popoverSuggestionContext, subscribe: true })
|
27
|
+
], PopoverSuggestionConsumer.prototype, "contextA", 2);
|
28
|
+
__decorateClass([
|
29
|
+
property({ attribute: false })
|
30
|
+
], PopoverSuggestionConsumer.prototype, "onContext", 2);
|
31
|
+
PopoverSuggestionConsumer = __decorateClass([
|
32
|
+
customElement("prosekit-popover-suggestion-consumer")
|
33
|
+
], PopoverSuggestionConsumer);
|
34
|
+
export {
|
35
|
+
PopoverSuggestionConsumer
|
36
|
+
};
|
@@ -0,0 +1,218 @@
|
|
1
|
+
import "./chunk-7C2I5DWH.js";
|
2
|
+
import {
|
3
|
+
__decorateClass,
|
4
|
+
blockComponentStyles
|
5
|
+
} from "./chunk-43BFWKM2.js";
|
6
|
+
|
7
|
+
// src/elements/popover-suggestion/options.ts
|
8
|
+
import {
|
9
|
+
flip,
|
10
|
+
inline,
|
11
|
+
offset,
|
12
|
+
shift,
|
13
|
+
size
|
14
|
+
} from "@floating-ui/dom";
|
15
|
+
var defaultDetectOverflowOptions = {
|
16
|
+
// Make sure the popover is always at least 8px away from the boundary
|
17
|
+
padding: 8
|
18
|
+
};
|
19
|
+
var defaultPopoverOptions = {
|
20
|
+
placement: "bottom-end",
|
21
|
+
middleware: [
|
22
|
+
offset(({ rects }) => ({
|
23
|
+
// Put the popover at the bottom right corner
|
24
|
+
alignmentAxis: -rects.floating.width,
|
25
|
+
// Move down the popover by 4px
|
26
|
+
mainAxis: 4
|
27
|
+
})),
|
28
|
+
size({
|
29
|
+
apply: ({ availableHeight, elements }) => {
|
30
|
+
const style = {
|
31
|
+
// Minimum acceptable height is 100px.
|
32
|
+
// `flip` will then take over.
|
33
|
+
maxHeight: `${Math.max(100, availableHeight)}px`,
|
34
|
+
overflowY: "auto"
|
35
|
+
};
|
36
|
+
Object.assign(elements.floating.style, style);
|
37
|
+
},
|
38
|
+
...defaultDetectOverflowOptions
|
39
|
+
}),
|
40
|
+
// Flip the popover to the top if it's overflowing the viewport
|
41
|
+
flip({
|
42
|
+
fallbackStrategy: "initialPlacement",
|
43
|
+
fallbackAxisSideDirection: "start",
|
44
|
+
crossAxis: false,
|
45
|
+
...defaultDetectOverflowOptions
|
46
|
+
}),
|
47
|
+
shift({
|
48
|
+
...defaultDetectOverflowOptions
|
49
|
+
}),
|
50
|
+
// Use the text caret as the reference point
|
51
|
+
inline()
|
52
|
+
]
|
53
|
+
};
|
54
|
+
|
55
|
+
// src/elements/popover-suggestion/popover-suggestion.ts
|
56
|
+
import { html, LitElement } from "lit";
|
57
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
58
|
+
|
59
|
+
// src/utils/is-menu.ts
|
60
|
+
function isMenu(element) {
|
61
|
+
var _a, _b;
|
62
|
+
return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-menu" || ["menu"].includes((_b = element == null ? void 0 : element.getAttribute("role")) != null ? _b : "");
|
63
|
+
}
|
64
|
+
|
65
|
+
// src/elements/popover-suggestion/controller.ts
|
66
|
+
import { ProseKitError } from "@prosekit/core";
|
67
|
+
import { addSuggestion } from "@prosekit/extension-suggestion";
|
68
|
+
var PopoverSuggestionController = class {
|
69
|
+
constructor(host, editor, rules, onContext) {
|
70
|
+
this.host = host;
|
71
|
+
this.editor = editor;
|
72
|
+
this.rules = rules;
|
73
|
+
this.onContext = onContext;
|
74
|
+
this.connected = false;
|
75
|
+
this.reference = null;
|
76
|
+
this.removeExtension = null;
|
77
|
+
if (!editor) {
|
78
|
+
throw new ProseKitError("Missing 'editor' property");
|
79
|
+
}
|
80
|
+
if (!rules) {
|
81
|
+
throw new ProseKitError("Missing 'rules' property");
|
82
|
+
}
|
83
|
+
this.host.addController(this);
|
84
|
+
}
|
85
|
+
hostUpdated() {
|
86
|
+
var _a;
|
87
|
+
if (this.connected)
|
88
|
+
return;
|
89
|
+
this.connected = true;
|
90
|
+
const editor = this.editor;
|
91
|
+
if (!editor) {
|
92
|
+
throw new ProseKitError("Missing 'editor' property");
|
93
|
+
}
|
94
|
+
if (!this.rules) {
|
95
|
+
throw new ProseKitError("Missing 'rules' property");
|
96
|
+
}
|
97
|
+
const extension = addSuggestion({
|
98
|
+
rules: this.rules,
|
99
|
+
onMatch: ({ dismiss, deleteMatch, match, matchAfter }) => {
|
100
|
+
var _a2, _b;
|
101
|
+
const span = editor.view.dom.querySelector(
|
102
|
+
".prosemirror-prediction-match"
|
103
|
+
);
|
104
|
+
if (span) {
|
105
|
+
this.reference = span;
|
106
|
+
}
|
107
|
+
const matchText = match[0] + ((_a2 = matchAfter == null ? void 0 : matchAfter[0]) != null ? _a2 : "");
|
108
|
+
(_b = this.onContext) == null ? void 0 : _b.call(this, {
|
109
|
+
active: true,
|
110
|
+
query: matchText,
|
111
|
+
onDismiss: () => {
|
112
|
+
dismiss();
|
113
|
+
},
|
114
|
+
onSubmit: () => {
|
115
|
+
deleteMatch();
|
116
|
+
}
|
117
|
+
});
|
118
|
+
},
|
119
|
+
onDeactivate: () => {
|
120
|
+
this.reference = null;
|
121
|
+
setTimeout(() => {
|
122
|
+
var _a2;
|
123
|
+
(_a2 = this.onContext) == null ? void 0 : _a2.call(this, {
|
124
|
+
active: false
|
125
|
+
});
|
126
|
+
});
|
127
|
+
}
|
128
|
+
});
|
129
|
+
(_a = this.removeExtension) == null ? void 0 : _a.call(this);
|
130
|
+
this.removeExtension = editor.use(extension);
|
131
|
+
}
|
132
|
+
hostDisconnected() {
|
133
|
+
var _a;
|
134
|
+
this.connected = false;
|
135
|
+
(_a = this.removeExtension) == null ? void 0 : _a.call(this);
|
136
|
+
this.removeExtension = null;
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
// src/elements/popover-suggestion/popover-suggestion.ts
|
141
|
+
var PopoverSuggestion = class extends LitElement {
|
142
|
+
/** @hidden */
|
143
|
+
constructor() {
|
144
|
+
super();
|
145
|
+
this.popoverOptions = defaultPopoverOptions;
|
146
|
+
this.context = { active: false };
|
147
|
+
}
|
148
|
+
/** @hidden */
|
149
|
+
firstUpdated() {
|
150
|
+
setTimeout(() => {
|
151
|
+
this.controller = new PopoverSuggestionController(
|
152
|
+
this,
|
153
|
+
this.editor,
|
154
|
+
this.rules,
|
155
|
+
(context) => {
|
156
|
+
var _a;
|
157
|
+
(_a = this.onContext) == null ? void 0 : _a.call(this, context);
|
158
|
+
this.context = context;
|
159
|
+
requestAnimationFrame(() => {
|
160
|
+
var _a2, _b;
|
161
|
+
(_b = (_a2 = this.queryMenu()) == null ? void 0 : _a2.ensureFocusedItem) == null ? void 0 : _b.call(_a2);
|
162
|
+
});
|
163
|
+
}
|
164
|
+
);
|
165
|
+
});
|
166
|
+
}
|
167
|
+
/** @hidden */
|
168
|
+
get active() {
|
169
|
+
var _a;
|
170
|
+
return !!((_a = this.controller) == null ? void 0 : _a.reference);
|
171
|
+
}
|
172
|
+
/** @hidden */
|
173
|
+
queryMenu() {
|
174
|
+
var _a, _b, _c;
|
175
|
+
return (_c = (_b = (_a = this.defaultSlot) == null ? void 0 : _a.assignedElements({ flatten: true })) == null ? void 0 : _b.find(isMenu)) != null ? _c : null;
|
176
|
+
}
|
177
|
+
/** @hidden */
|
178
|
+
render() {
|
179
|
+
var _a, _b;
|
180
|
+
return html`<prosekit-popover .active="${this.active}" .reference="${(_b = (_a = this.controller) == null ? void 0 : _a.reference) != null ? _b : void 0}" .options="${this.popoverOptions}"><slot @menu-dismiss="${() => {
|
181
|
+
var _a2, _b2;
|
182
|
+
return (_b2 = (_a2 = this.context) == null ? void 0 : _a2.onDismiss) == null ? void 0 : _b2.call(_a2);
|
183
|
+
}}" @menu-select="${() => {
|
184
|
+
var _a2, _b2;
|
185
|
+
return (_b2 = (_a2 = this.context) == null ? void 0 : _a2.onSubmit) == null ? void 0 : _b2.call(_a2);
|
186
|
+
}}"></slot></prosekit-popover>`;
|
187
|
+
}
|
188
|
+
};
|
189
|
+
/** @hidden */
|
190
|
+
PopoverSuggestion.styles = blockComponentStyles;
|
191
|
+
__decorateClass([
|
192
|
+
property({ attribute: false })
|
193
|
+
], PopoverSuggestion.prototype, "editor", 2);
|
194
|
+
__decorateClass([
|
195
|
+
property({ attribute: false })
|
196
|
+
], PopoverSuggestion.prototype, "popoverOptions", 2);
|
197
|
+
__decorateClass([
|
198
|
+
property({ attribute: false })
|
199
|
+
], PopoverSuggestion.prototype, "rules", 2);
|
200
|
+
__decorateClass([
|
201
|
+
state()
|
202
|
+
], PopoverSuggestion.prototype, "context", 2);
|
203
|
+
__decorateClass([
|
204
|
+
property({ attribute: false })
|
205
|
+
], PopoverSuggestion.prototype, "onContext", 2);
|
206
|
+
__decorateClass([
|
207
|
+
state()
|
208
|
+
], PopoverSuggestion.prototype, "controller", 2);
|
209
|
+
__decorateClass([
|
210
|
+
query("slot")
|
211
|
+
], PopoverSuggestion.prototype, "defaultSlot", 2);
|
212
|
+
PopoverSuggestion = __decorateClass([
|
213
|
+
customElement("prosekit-popover-suggestion")
|
214
|
+
], PopoverSuggestion);
|
215
|
+
export {
|
216
|
+
PopoverSuggestion,
|
217
|
+
defaultPopoverOptions
|
218
|
+
};
|