@prosekit/lit 0.0.8 → 0.0.10
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/{chunk-J73E7P6J.js → chunk-3UDA5JEW.js} +2 -9
- package/dist/{chunk-37EPOFI5.js → chunk-AWQAU2JR.js} +5 -3
- package/dist/chunk-BMDOOASL.js +57 -0
- package/dist/chunk-DYEHERSG.js +9 -0
- package/dist/chunk-G5KPDHDH.js +120 -0
- package/dist/chunk-HMV7TD6T.js +9 -0
- package/dist/{chunk-HPMQEYGA.js → chunk-KGZID7N7.js} +61 -92
- package/dist/chunk-PCXKL6TA.js +109 -0
- package/dist/chunk-TRZW33VF.js +35 -0
- package/dist/index-2645d161.d.ts +10 -0
- package/dist/index-c461623f.d.ts +67 -0
- package/dist/index-f7e15683.d.ts +66 -0
- package/dist/options-7235df55.d.ts +14 -0
- package/dist/prosekit-lit-components-autocomplete-empty.js +5 -3
- package/dist/prosekit-lit-components-autocomplete-item.js +3 -2
- package/dist/prosekit-lit-components-autocomplete-list.d.ts +2 -10
- package/dist/prosekit-lit-components-autocomplete-list.js +5 -3
- package/dist/prosekit-lit-components-autocomplete-popover.d.ts +2 -12
- package/dist/prosekit-lit-components-autocomplete-popover.js +23 -139
- package/dist/prosekit-lit-components-code-block-popover.d.ts +19 -0
- package/dist/prosekit-lit-components-code-block-popover.js +141 -0
- package/dist/prosekit-lit-components-combo-box-input.d.ts +22 -0
- package/dist/prosekit-lit-components-combo-box-input.js +74 -0
- package/dist/prosekit-lit-components-combo-box-item.d.ts +4 -0
- package/dist/prosekit-lit-components-combo-box-item.js +11 -0
- package/dist/prosekit-lit-components-combo-box-list.d.ts +13 -0
- package/dist/prosekit-lit-components-combo-box-list.js +50 -0
- package/dist/prosekit-lit-components-combo-box.d.ts +20 -0
- package/dist/prosekit-lit-components-combo-box.js +111 -0
- package/package.json +49 -9
@@ -18,16 +18,9 @@ import { css } from "lit";
|
|
18
18
|
var componentStyles = css`:host{box-sizing:border-box}:host *,:host ::after,:host ::before{box-sizing:inherit}`;
|
19
19
|
|
20
20
|
// src/styles/block-component.styles.ts
|
21
|
-
var blockComponentStyles = css2`${componentStyles}:host{display:block}:host([hidden]){display:none}`;
|
22
|
-
|
23
|
-
// src/components/autocomplete-list/context.ts
|
24
|
-
import { createContext } from "@lit-labs/context";
|
25
|
-
var commandListContext = createContext(
|
26
|
-
"prosekit-autocomplete-list-context"
|
27
|
-
);
|
21
|
+
var blockComponentStyles = css2`${componentStyles}:host{display:block;border-style:solid;border-width:0}:host([hidden]){display:none}`;
|
28
22
|
|
29
23
|
export {
|
30
24
|
__decorateClass,
|
31
|
-
blockComponentStyles
|
32
|
-
commandListContext
|
25
|
+
blockComponentStyles
|
33
26
|
};
|
@@ -1,8 +1,10 @@
|
|
1
1
|
import {
|
2
|
-
__decorateClass,
|
3
|
-
blockComponentStyles,
|
4
2
|
commandListContext
|
5
|
-
} from "./chunk-
|
3
|
+
} from "./chunk-DYEHERSG.js";
|
4
|
+
import {
|
5
|
+
__decorateClass,
|
6
|
+
blockComponentStyles
|
7
|
+
} from "./chunk-3UDA5JEW.js";
|
6
8
|
|
7
9
|
// src/components/autocomplete-item/component.ts
|
8
10
|
import { consume } from "@lit-labs/context";
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import {
|
2
|
+
comboBoxContext
|
3
|
+
} from "./chunk-HMV7TD6T.js";
|
4
|
+
import {
|
5
|
+
LightBlockElement
|
6
|
+
} from "./chunk-TRZW33VF.js";
|
7
|
+
import {
|
8
|
+
__decorateClass,
|
9
|
+
blockComponentStyles
|
10
|
+
} from "./chunk-3UDA5JEW.js";
|
11
|
+
|
12
|
+
// src/components/combo-box-item/component.ts
|
13
|
+
import { consume } from "@lit-labs/context";
|
14
|
+
import "lit";
|
15
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
16
|
+
var propNames = [];
|
17
|
+
var ComboBoxItem = class extends LightBlockElement {
|
18
|
+
constructor() {
|
19
|
+
super(...arguments);
|
20
|
+
this.selected = false;
|
21
|
+
}
|
22
|
+
updated() {
|
23
|
+
var _a, _b, _c, _d;
|
24
|
+
const content = ((_a = this.textContent) != null ? _a : "").trim();
|
25
|
+
const query2 = ((_c = (_b = this.comboBoxContext) == null ? void 0 : _b.inputValue) != null ? _c : "").trim();
|
26
|
+
const match = content.toLowerCase().includes(query2.toLowerCase());
|
27
|
+
this.selected = match && content === ((_d = this.comboBoxContext) == null ? void 0 : _d.selectedValue);
|
28
|
+
this.ariaSelected = String(this.selected);
|
29
|
+
this.setHidden(!match);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
/** @hidden */
|
33
|
+
ComboBoxItem.styles = blockComponentStyles;
|
34
|
+
__decorateClass([
|
35
|
+
property({ attribute: false })
|
36
|
+
], ComboBoxItem.prototype, "editor", 2);
|
37
|
+
__decorateClass([
|
38
|
+
query("slot")
|
39
|
+
], ComboBoxItem.prototype, "defaultSlot", 2);
|
40
|
+
__decorateClass([
|
41
|
+
property({ type: Boolean, reflect: true, attribute: "data-selected" })
|
42
|
+
], ComboBoxItem.prototype, "selected", 2);
|
43
|
+
__decorateClass([
|
44
|
+
consume({ context: comboBoxContext, subscribe: true }),
|
45
|
+
state({})
|
46
|
+
], ComboBoxItem.prototype, "comboBoxContext", 2);
|
47
|
+
__decorateClass([
|
48
|
+
property({ attribute: false })
|
49
|
+
], ComboBoxItem.prototype, "onSelect", 2);
|
50
|
+
ComboBoxItem = __decorateClass([
|
51
|
+
customElement("prosekit-combo-box-item")
|
52
|
+
], ComboBoxItem);
|
53
|
+
|
54
|
+
export {
|
55
|
+
propNames,
|
56
|
+
ComboBoxItem
|
57
|
+
};
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import {
|
2
|
+
LightBlockElement
|
3
|
+
} from "./chunk-TRZW33VF.js";
|
4
|
+
import {
|
5
|
+
__decorateClass,
|
6
|
+
blockComponentStyles
|
7
|
+
} from "./chunk-3UDA5JEW.js";
|
8
|
+
|
9
|
+
// src/components/popover/options.ts
|
10
|
+
import "@floating-ui/dom";
|
11
|
+
|
12
|
+
// src/components/popover/index.ts
|
13
|
+
import {
|
14
|
+
autoUpdate,
|
15
|
+
computePosition
|
16
|
+
} from "@floating-ui/dom";
|
17
|
+
import "lit";
|
18
|
+
import { customElement, property } from "lit/decorators.js";
|
19
|
+
|
20
|
+
// src/utils/round-by-dpr.ts
|
21
|
+
function roundByDPR(value) {
|
22
|
+
const dpr = window.devicePixelRatio || 1;
|
23
|
+
return Math.round(value * dpr) / dpr;
|
24
|
+
}
|
25
|
+
|
26
|
+
// src/components/popover/default-popover-options.ts
|
27
|
+
import { offset, shift } from "@floating-ui/dom";
|
28
|
+
var defaultPopoverOptions = {
|
29
|
+
placement: "bottom",
|
30
|
+
middleware: [offset(4), shift({ padding: 8 })]
|
31
|
+
};
|
32
|
+
|
33
|
+
// src/components/popover/index.ts
|
34
|
+
var Popover = class extends LightBlockElement {
|
35
|
+
/** @hidden */
|
36
|
+
constructor() {
|
37
|
+
super();
|
38
|
+
this.active = false;
|
39
|
+
this.autoUpdate = false;
|
40
|
+
}
|
41
|
+
/** @hidden */
|
42
|
+
disconnectedCallback() {
|
43
|
+
this.cleanup();
|
44
|
+
}
|
45
|
+
/** @hidden */
|
46
|
+
updated() {
|
47
|
+
this.start();
|
48
|
+
this.setHidden(!this.active);
|
49
|
+
}
|
50
|
+
/** @hidden */
|
51
|
+
start() {
|
52
|
+
this.cleanup();
|
53
|
+
const reference = this.reference;
|
54
|
+
if (!reference)
|
55
|
+
return;
|
56
|
+
if (!this.active)
|
57
|
+
return;
|
58
|
+
if (this.autoUpdate) {
|
59
|
+
this.cleanupAutoUpdate = autoUpdate(
|
60
|
+
reference,
|
61
|
+
this,
|
62
|
+
() => void this.compute(),
|
63
|
+
this.autoUpdateOptions
|
64
|
+
);
|
65
|
+
} else {
|
66
|
+
void this.compute();
|
67
|
+
}
|
68
|
+
}
|
69
|
+
/** @hidden */
|
70
|
+
async compute() {
|
71
|
+
var _a, _b, _c;
|
72
|
+
const reference = this.reference;
|
73
|
+
if (!reference)
|
74
|
+
return;
|
75
|
+
if (!this.active)
|
76
|
+
return;
|
77
|
+
this.setHidden(false);
|
78
|
+
this.style.position = (_b = (_a = this.options) == null ? void 0 : _a.strategy) != null ? _b : "absolute";
|
79
|
+
const options = (_c = this.options) != null ? _c : defaultPopoverOptions;
|
80
|
+
const computed = await computePosition(reference, this, options);
|
81
|
+
const { x, y, strategy } = computed != null ? computed : { x: 0, y: 0, strategy: "absolute" };
|
82
|
+
this.style.top = "0";
|
83
|
+
this.style.left = "0";
|
84
|
+
this.style.position = strategy;
|
85
|
+
this.style.transform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`;
|
86
|
+
}
|
87
|
+
/** @hidden */
|
88
|
+
cleanup() {
|
89
|
+
var _a;
|
90
|
+
(_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
|
91
|
+
this.cleanupAutoUpdate = void 0;
|
92
|
+
}
|
93
|
+
};
|
94
|
+
/** @hidden */
|
95
|
+
Popover.styles = blockComponentStyles;
|
96
|
+
__decorateClass([
|
97
|
+
property({ type: Boolean, reflect: true })
|
98
|
+
], Popover.prototype, "active", 2);
|
99
|
+
__decorateClass([
|
100
|
+
property({ attribute: false })
|
101
|
+
], Popover.prototype, "reference", 2);
|
102
|
+
__decorateClass([
|
103
|
+
property({ attribute: false })
|
104
|
+
], Popover.prototype, "options", 2);
|
105
|
+
__decorateClass([
|
106
|
+
property({
|
107
|
+
type: Boolean,
|
108
|
+
reflect: true
|
109
|
+
})
|
110
|
+
], Popover.prototype, "autoUpdate", 2);
|
111
|
+
__decorateClass([
|
112
|
+
property({ type: Object })
|
113
|
+
], Popover.prototype, "autoUpdateOptions", 2);
|
114
|
+
Popover = __decorateClass([
|
115
|
+
customElement("prosekit-popover")
|
116
|
+
], Popover);
|
117
|
+
|
118
|
+
export {
|
119
|
+
Popover
|
120
|
+
};
|
@@ -1,8 +1,13 @@
|
|
1
1
|
import {
|
2
|
-
__decorateClass,
|
3
|
-
blockComponentStyles,
|
4
2
|
commandListContext
|
5
|
-
} from "./chunk-
|
3
|
+
} from "./chunk-DYEHERSG.js";
|
4
|
+
import {
|
5
|
+
ListManager
|
6
|
+
} from "./chunk-PCXKL6TA.js";
|
7
|
+
import {
|
8
|
+
__decorateClass,
|
9
|
+
blockComponentStyles
|
10
|
+
} from "./chunk-3UDA5JEW.js";
|
6
11
|
|
7
12
|
// src/components/autocomplete-popover/context.ts
|
8
13
|
import { createContext } from "@lit-labs/context";
|
@@ -13,7 +18,7 @@ var commandPopoverContext = createContext(
|
|
13
18
|
// src/components/autocomplete-list/component.ts
|
14
19
|
import { consume, provide } from "@lit-labs/context";
|
15
20
|
import "@prosekit/core";
|
16
|
-
import {
|
21
|
+
import { LitElement, html } from "lit";
|
17
22
|
import { customElement, property, query, state } from "lit/decorators.js";
|
18
23
|
|
19
24
|
// src/utils/command-score.ts
|
@@ -25,6 +30,19 @@ function isAutocompleteItem(element) {
|
|
25
30
|
var _a;
|
26
31
|
return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-autocomplete-item";
|
27
32
|
}
|
33
|
+
function queryClosestAutocompleteItem(element) {
|
34
|
+
if (!element) {
|
35
|
+
return null;
|
36
|
+
}
|
37
|
+
if (isAutocompleteItem(element)) {
|
38
|
+
return element;
|
39
|
+
}
|
40
|
+
const item = element.closest("prosekit-autocomplete-item");
|
41
|
+
if (isAutocompleteItem(item)) {
|
42
|
+
return item;
|
43
|
+
}
|
44
|
+
return null;
|
45
|
+
}
|
28
46
|
|
29
47
|
// src/components/autocomplete-list/controller.ts
|
30
48
|
import {
|
@@ -70,34 +88,30 @@ var AutocompleteList = class extends LitElement {
|
|
70
88
|
constructor() {
|
71
89
|
super(...arguments);
|
72
90
|
/** @hidden */
|
73
|
-
this.
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if (!this.active)
|
82
|
-
return false;
|
83
|
-
this.updateSelectedByChange(1);
|
84
|
-
return true;
|
85
|
-
},
|
86
|
-
Escape: () => {
|
91
|
+
this.listManager = new ListManager({
|
92
|
+
getItems: () => this.items,
|
93
|
+
getSelectedValue: () => this.context.selectedValue,
|
94
|
+
setSelectedValue: (value) => this.updateValue(value),
|
95
|
+
getItemValue: (item) => item.content,
|
96
|
+
queryClosestItem: queryClosestAutocompleteItem,
|
97
|
+
getActive: () => this.active,
|
98
|
+
onDismiss: () => {
|
87
99
|
var _a, _b;
|
88
|
-
|
89
|
-
return false;
|
90
|
-
(_b = (_a = this.popoverContext) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
|
91
|
-
return true;
|
100
|
+
return (_b = (_a = this.popoverContext) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
|
92
101
|
},
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
return true;
|
102
|
+
onSelect: (item) => {
|
103
|
+
var _a, _b, _c;
|
104
|
+
(_b = (_a = this.popoverContext) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
|
105
|
+
(_c = item == null ? void 0 : item.onSelect) == null ? void 0 : _c.call(item);
|
98
106
|
}
|
99
107
|
});
|
100
|
-
|
108
|
+
/** @hidden */
|
109
|
+
this.controller = new AutocompleteListController(this, {
|
110
|
+
ArrowUp: () => this.listManager.handleArrowUp(),
|
111
|
+
ArrowDown: () => this.listManager.handleArrowDown(),
|
112
|
+
Escape: () => this.listManager.handleEscape(),
|
113
|
+
Enter: () => this.listManager.handleEnter()
|
114
|
+
});
|
101
115
|
this.popoverContext = null;
|
102
116
|
this.context = {
|
103
117
|
scores: /* @__PURE__ */ new Map(),
|
@@ -110,30 +124,30 @@ var AutocompleteList = class extends LitElement {
|
|
110
124
|
return (_b = (_a = this.popoverContext) == null ? void 0 : _a.active) != null ? _b : false;
|
111
125
|
}
|
112
126
|
firstUpdated() {
|
113
|
-
this.selectFirstItem();
|
127
|
+
this.listManager.selectFirstItem();
|
128
|
+
this.addEventListener(
|
129
|
+
"mousemove",
|
130
|
+
(event) => this.listManager.handleMouseMove(event)
|
131
|
+
);
|
132
|
+
this.addEventListener(
|
133
|
+
"mouseover",
|
134
|
+
(event) => this.listManager.handleMouseOver(event)
|
135
|
+
);
|
136
|
+
this.addEventListener(
|
137
|
+
"mousedown",
|
138
|
+
(event) => this.listManager.handleMouseDown(event)
|
139
|
+
);
|
140
|
+
this.addEventListener(
|
141
|
+
"click",
|
142
|
+
(event) => this.listManager.handleClick(event)
|
143
|
+
);
|
114
144
|
}
|
115
145
|
get items() {
|
116
146
|
var _a, _b, _c;
|
117
147
|
return (_c = (_b = (_a = this.defaultSlot) == null ? void 0 : _a.assignedElements({ flatten: true })) == null ? void 0 : _b.filter(isAutocompleteItem)) != null ? _c : [];
|
118
148
|
}
|
119
|
-
get availableItems() {
|
120
|
-
var _a, _b;
|
121
|
-
return (_b = (_a = this.items) == null ? void 0 : _a.filter((item) => !item.hidden)) != null ? _b : [];
|
122
|
-
}
|
123
|
-
get firstItem() {
|
124
|
-
var _a;
|
125
|
-
return (_a = this.availableItems[0]) != null ? _a : null;
|
126
|
-
}
|
127
|
-
get selectedItem() {
|
128
|
-
var _a;
|
129
|
-
return (_a = this.availableItems.find(
|
130
|
-
(item) => item.content === this.context.selectedValue
|
131
|
-
)) != null ? _a : null;
|
132
|
-
}
|
133
149
|
selectFirstItem() {
|
134
|
-
|
135
|
-
const selected = (_b = (_a = this.firstItem) == null ? void 0 : _a.content) != null ? _b : "";
|
136
|
-
this.updateValue(selected);
|
150
|
+
this.listManager.selectFirstItem();
|
137
151
|
}
|
138
152
|
updateValue(selectedValue) {
|
139
153
|
if (this.context.selectedValue === selectedValue)
|
@@ -165,54 +179,9 @@ var AutocompleteList = class extends LitElement {
|
|
165
179
|
);
|
166
180
|
this.context = { ...this.context, scores };
|
167
181
|
}
|
168
|
-
updateSelectedByChange(change) {
|
169
|
-
const items = this.availableItems;
|
170
|
-
if (items.length === 0) {
|
171
|
-
return;
|
172
|
-
}
|
173
|
-
const selectedItem = this.selectedItem;
|
174
|
-
const selectedIndex = selectedItem ? items.indexOf(selectedItem) : -1;
|
175
|
-
let nextIndex = selectedIndex + change;
|
176
|
-
if (nextIndex < 0) {
|
177
|
-
nextIndex = 0;
|
178
|
-
} else if (nextIndex >= items.length) {
|
179
|
-
nextIndex = items.length - 1;
|
180
|
-
}
|
181
|
-
if (selectedIndex !== nextIndex) {
|
182
|
-
this.updateValue(items[nextIndex].content);
|
183
|
-
}
|
184
|
-
}
|
185
|
-
handleMouseMove() {
|
186
|
-
this.lastMouseMoveTime = Date.now();
|
187
|
-
}
|
188
|
-
handleMouseOver(event) {
|
189
|
-
if (this.lastMouseMoveTime + 500 < Date.now()) {
|
190
|
-
return;
|
191
|
-
}
|
192
|
-
const target = event.target;
|
193
|
-
if (isAutocompleteItem(target)) {
|
194
|
-
this.updateValue(target.content);
|
195
|
-
}
|
196
|
-
}
|
197
|
-
handleClick(event) {
|
198
|
-
event.preventDefault();
|
199
|
-
const target = event.target;
|
200
|
-
const item = target == null ? void 0 : target.closest("prosekit-autocomplete-item");
|
201
|
-
if (item && isAutocompleteItem(item)) {
|
202
|
-
this.handleSelect(item);
|
203
|
-
}
|
204
|
-
}
|
205
|
-
handleMouseDown(event) {
|
206
|
-
event.preventDefault();
|
207
|
-
}
|
208
|
-
handleSelect(item) {
|
209
|
-
var _a, _b, _c;
|
210
|
-
(_b = (_a = this.popoverContext) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
|
211
|
-
(_c = item == null ? void 0 : item.onSelect) == null ? void 0 : _c.call(item);
|
212
|
-
}
|
213
182
|
/** @hidden */
|
214
183
|
render() {
|
215
|
-
return html`<
|
184
|
+
return html`<slot></slot>`;
|
216
185
|
}
|
217
186
|
};
|
218
187
|
/** @hidden */
|
@@ -0,0 +1,109 @@
|
|
1
|
+
// src/manager/list-manager.ts
|
2
|
+
var ListManager = class {
|
3
|
+
constructor(options) {
|
4
|
+
this.lastMouseMoveTime = 0;
|
5
|
+
this.getItems = options.getItems;
|
6
|
+
this.getSelectedValue = options.getSelectedValue;
|
7
|
+
this.setSelectedValue = options.setSelectedValue;
|
8
|
+
this.getItemValue = options.getItemValue;
|
9
|
+
this.queryClosestItem = options.queryClosestItem;
|
10
|
+
this.getActive = options.getActive;
|
11
|
+
this.onDismiss = options.onDismiss;
|
12
|
+
this.onSelect = options.onSelect;
|
13
|
+
}
|
14
|
+
get items() {
|
15
|
+
return this.getItems();
|
16
|
+
}
|
17
|
+
get availableItems() {
|
18
|
+
var _a, _b;
|
19
|
+
return (_b = (_a = this.items) == null ? void 0 : _a.filter((item) => !item.hidden)) != null ? _b : [];
|
20
|
+
}
|
21
|
+
get firstItem() {
|
22
|
+
var _a;
|
23
|
+
return (_a = this.availableItems[0]) != null ? _a : null;
|
24
|
+
}
|
25
|
+
get selectedItem() {
|
26
|
+
var _a;
|
27
|
+
return (_a = this.availableItems.find(
|
28
|
+
(item) => this.getItemValue(item) === this.getSelectedValue()
|
29
|
+
)) != null ? _a : null;
|
30
|
+
}
|
31
|
+
updateSelectedByChange(change) {
|
32
|
+
const items = this.availableItems;
|
33
|
+
if (items.length === 0) {
|
34
|
+
return;
|
35
|
+
}
|
36
|
+
const selectedItem = this.selectedItem;
|
37
|
+
const selectedIndex = selectedItem ? items.indexOf(selectedItem) : -1;
|
38
|
+
let nextIndex = selectedIndex + change;
|
39
|
+
if (nextIndex < 0) {
|
40
|
+
nextIndex = 0;
|
41
|
+
} else if (nextIndex >= items.length) {
|
42
|
+
nextIndex = items.length - 1;
|
43
|
+
}
|
44
|
+
if (selectedIndex !== nextIndex) {
|
45
|
+
this.setSelectedValue(this.getItemValue(items[nextIndex]));
|
46
|
+
}
|
47
|
+
}
|
48
|
+
handleSelect(item) {
|
49
|
+
this.setSelectedValue(this.getItemValue(item));
|
50
|
+
}
|
51
|
+
selectFirstItem() {
|
52
|
+
const item = this.firstItem;
|
53
|
+
const value = item ? this.getItemValue(item) : "";
|
54
|
+
this.setSelectedValue(value);
|
55
|
+
}
|
56
|
+
handleMouseMove(_event) {
|
57
|
+
this.lastMouseMoveTime = Date.now();
|
58
|
+
}
|
59
|
+
handleMouseOver(event) {
|
60
|
+
if (this.lastMouseMoveTime + 500 < Date.now()) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
const target = event.target;
|
64
|
+
const item = target && this.queryClosestItem(target);
|
65
|
+
if (item) {
|
66
|
+
this.setSelectedValue(this.getItemValue(item));
|
67
|
+
}
|
68
|
+
}
|
69
|
+
handleMouseDown(event) {
|
70
|
+
event.preventDefault();
|
71
|
+
}
|
72
|
+
handleClick(event) {
|
73
|
+
event.preventDefault();
|
74
|
+
const target = event.target;
|
75
|
+
const item = target && this.queryClosestItem(target);
|
76
|
+
if (item) {
|
77
|
+
this.handleSelect(item);
|
78
|
+
this.onSelect(item);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
handleArrowUp() {
|
82
|
+
if (!this.getActive())
|
83
|
+
return false;
|
84
|
+
this.updateSelectedByChange(-1);
|
85
|
+
return true;
|
86
|
+
}
|
87
|
+
handleArrowDown() {
|
88
|
+
if (!this.getActive())
|
89
|
+
return false;
|
90
|
+
this.updateSelectedByChange(1);
|
91
|
+
return true;
|
92
|
+
}
|
93
|
+
handleEscape() {
|
94
|
+
if (!this.getActive())
|
95
|
+
return false;
|
96
|
+
this.onDismiss();
|
97
|
+
return true;
|
98
|
+
}
|
99
|
+
handleEnter() {
|
100
|
+
if (!this.getActive())
|
101
|
+
return false;
|
102
|
+
this.onSelect(this.selectedItem);
|
103
|
+
return true;
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
export {
|
108
|
+
ListManager
|
109
|
+
};
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import {
|
2
|
+
blockComponentStyles
|
3
|
+
} from "./chunk-3UDA5JEW.js";
|
4
|
+
|
5
|
+
// src/components/block-element/index.ts
|
6
|
+
import { LitElement } from "lit";
|
7
|
+
var BlockElement = class extends LitElement {
|
8
|
+
setHidden(hidden) {
|
9
|
+
if (this.hidden !== hidden) {
|
10
|
+
this.hidden = hidden;
|
11
|
+
const display = this.style.display;
|
12
|
+
this.style.display = hidden ? "none" : display === "none" ? "" : display;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
};
|
16
|
+
var LightBlockElement = class extends BlockElement {
|
17
|
+
createRenderRoot() {
|
18
|
+
return this;
|
19
|
+
}
|
20
|
+
};
|
21
|
+
var ShadowBlockElement = class extends BlockElement {
|
22
|
+
setHidden(hidden) {
|
23
|
+
if (this.hidden !== hidden) {
|
24
|
+
this.hidden = hidden;
|
25
|
+
const display = this.style.display;
|
26
|
+
this.style.display = hidden ? "none" : display === "none" ? "" : display;
|
27
|
+
}
|
28
|
+
}
|
29
|
+
};
|
30
|
+
/** @hidden */
|
31
|
+
ShadowBlockElement.styles = blockComponentStyles;
|
32
|
+
|
33
|
+
export {
|
34
|
+
LightBlockElement
|
35
|
+
};
|
@@ -0,0 +1,67 @@
|
|
1
|
+
import { Editor } from '@prosekit/core';
|
2
|
+
import { CSSResultGroup } from 'lit';
|
3
|
+
import { L as LightBlockElement } from './index-2645d161.js';
|
4
|
+
|
5
|
+
declare class ListManager<Item extends {
|
6
|
+
hidden: boolean;
|
7
|
+
} & HTMLElement> {
|
8
|
+
private lastMouseMoveTime;
|
9
|
+
private getItems;
|
10
|
+
private getSelectedValue;
|
11
|
+
private setSelectedValue;
|
12
|
+
private getItemValue;
|
13
|
+
private queryClosestItem;
|
14
|
+
private getActive;
|
15
|
+
private onDismiss;
|
16
|
+
private onSelect;
|
17
|
+
constructor(options: {
|
18
|
+
getItems: () => Item[];
|
19
|
+
getSelectedValue: () => string;
|
20
|
+
setSelectedValue: (value: string) => void;
|
21
|
+
getItemValue: (item: Item) => string;
|
22
|
+
queryClosestItem: (element: HTMLElement) => Item | null;
|
23
|
+
getActive: () => boolean;
|
24
|
+
onDismiss: () => void;
|
25
|
+
onSelect: (item?: Item | null) => void;
|
26
|
+
});
|
27
|
+
get items(): Item[];
|
28
|
+
get availableItems(): Item[];
|
29
|
+
get firstItem(): Item | null;
|
30
|
+
get selectedItem(): Item | null;
|
31
|
+
private updateSelectedByChange;
|
32
|
+
private handleSelect;
|
33
|
+
selectFirstItem(): void;
|
34
|
+
handleMouseMove(_event: MouseEvent): void;
|
35
|
+
handleMouseOver(event: MouseEvent): void;
|
36
|
+
handleMouseDown(event: MouseEvent): void;
|
37
|
+
handleClick(event: MouseEvent): void;
|
38
|
+
handleArrowUp(): boolean;
|
39
|
+
handleArrowDown(): boolean;
|
40
|
+
handleEscape(): boolean;
|
41
|
+
handleEnter(): boolean;
|
42
|
+
}
|
43
|
+
|
44
|
+
type ComboBoxContext = {
|
45
|
+
inputValue: string;
|
46
|
+
setInputValue: (val: string) => void;
|
47
|
+
selectedValue: string;
|
48
|
+
setSelectedValue: (val: string) => void;
|
49
|
+
listManager: ListManager<ComboBoxItem>;
|
50
|
+
};
|
51
|
+
|
52
|
+
declare const propNames: never[];
|
53
|
+
type ComboBoxItemProps = Record<string, never>;
|
54
|
+
declare class ComboBoxItem extends LightBlockElement {
|
55
|
+
/** @hidden */
|
56
|
+
static styles: CSSResultGroup;
|
57
|
+
editor?: Editor;
|
58
|
+
/** @hidden */
|
59
|
+
defaultSlot?: HTMLSlotElement;
|
60
|
+
selected: boolean;
|
61
|
+
comboBoxContext?: ComboBoxContext;
|
62
|
+
/** @hidden */
|
63
|
+
onSelect?: VoidFunction;
|
64
|
+
protected updated(): void;
|
65
|
+
}
|
66
|
+
|
67
|
+
export { ComboBoxContext as C, ComboBoxItem as a, ComboBoxItemProps as b, propNames as p };
|