@prosekit/lit 0.0.0-next-20230709090937 → 0.0.0-next-20231120040948
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 +456 -0
- package/dist/chunk-55G7TJI3.js +48 -0
- package/dist/chunk-6P3YKUWI.js +9 -0
- package/dist/chunk-7WLKD2U6.js +184 -0
- package/dist/chunk-C4MW43I4.js +9 -0
- package/dist/chunk-GWGDLLFN.js +61 -0
- package/dist/{chunk-43BFWKM2.js → chunk-O5JP3B34.js} +15 -10
- package/dist/chunk-PCXKL6TA.js +109 -0
- package/dist/chunk-XBNMYITV.js +191 -0
- package/dist/prosekit-lit-autocomplete-empty.d.ts +3 -0
- package/dist/prosekit-lit-autocomplete-empty.js +44 -0
- package/dist/prosekit-lit-autocomplete-item.d.ts +3 -0
- package/dist/prosekit-lit-autocomplete-item.js +10 -0
- package/dist/prosekit-lit-autocomplete-list.d.ts +3 -0
- package/dist/prosekit-lit-autocomplete-list.js +12 -0
- package/dist/prosekit-lit-autocomplete-popover.d.ts +4 -0
- package/dist/prosekit-lit-autocomplete-popover.js +252 -0
- package/dist/prosekit-lit-combo-box-input.d.ts +3 -0
- package/dist/prosekit-lit-combo-box-input.js +72 -0
- package/dist/prosekit-lit-combo-box-item.d.ts +3 -0
- package/dist/prosekit-lit-combo-box-item.js +10 -0
- package/dist/prosekit-lit-combo-box-list.d.ts +3 -0
- package/dist/prosekit-lit-combo-box-list.js +48 -0
- package/dist/prosekit-lit-combo-box.d.ts +3 -0
- package/dist/prosekit-lit-combo-box.js +110 -0
- package/dist/prosekit-lit-inline-popover.d.ts +4 -0
- package/dist/prosekit-lit-inline-popover.js +154 -0
- package/dist/prosekit-lit-popover.d.ts +5 -0
- package/dist/prosekit-lit-popover.js +9 -0
- package/dist/prosekit-lit.d.ts +1 -2
- package/package.json +85 -38
- package/src/index.ts +0 -4
- package/dist/chunk-6FOWUXQ2.js +0 -26
- package/dist/chunk-7C2I5DWH.js +0 -122
- package/dist/chunk-WHIPWT4H.js +0 -122
- package/dist/options-7235df55.d.ts +0 -14
- package/dist/prosekit-lit-elements-menu-item.d.ts +0 -16
- package/dist/prosekit-lit-elements-menu-item.js +0 -37
- package/dist/prosekit-lit-elements-menu.d.ts +0 -50
- package/dist/prosekit-lit-elements-menu.js +0 -169
- package/dist/prosekit-lit-elements-popover-suggestion.d.ts +0 -59
- package/dist/prosekit-lit-elements-popover-suggestion.js +0 -218
- package/dist/prosekit-lit-elements-popover.d.ts +0 -65
- package/dist/prosekit-lit-elements-popover.js +0 -7
@@ -0,0 +1,61 @@
|
|
1
|
+
import {
|
2
|
+
commandListContext
|
3
|
+
} from "./chunk-6P3YKUWI.js";
|
4
|
+
import {
|
5
|
+
LightElement,
|
6
|
+
__decorateClass
|
7
|
+
} from "./chunk-O5JP3B34.js";
|
8
|
+
|
9
|
+
// src/components/autocomplete-item/component.ts
|
10
|
+
import { consume } from "@lit/context";
|
11
|
+
import "lit";
|
12
|
+
import { customElement, property, state } from "lit/decorators.js";
|
13
|
+
var propNames = ["value", "onSelect"];
|
14
|
+
var AutocompleteItem = class extends LightElement {
|
15
|
+
constructor() {
|
16
|
+
super(...arguments);
|
17
|
+
this.value = "";
|
18
|
+
this.selected = false;
|
19
|
+
}
|
20
|
+
get content() {
|
21
|
+
const text = this.value || this.textContent || "";
|
22
|
+
return text.trim().toLowerCase();
|
23
|
+
}
|
24
|
+
connectedCallback() {
|
25
|
+
super.connectedCallback();
|
26
|
+
this.role = "option";
|
27
|
+
}
|
28
|
+
willUpdate() {
|
29
|
+
var _a, _b;
|
30
|
+
const content = this.content;
|
31
|
+
this.selected = content === ((_a = this.listContext) == null ? void 0 : _a.selectedValue);
|
32
|
+
const score = ((_b = this.listContext) == null ? void 0 : _b.scores.get(content)) || 0;
|
33
|
+
this.setHidden(score <= 0);
|
34
|
+
}
|
35
|
+
updated(changedProperties) {
|
36
|
+
if (this.selected && changedProperties.has("selected") && !changedProperties.get("selected")) {
|
37
|
+
this.scrollIntoView({ block: "nearest" });
|
38
|
+
}
|
39
|
+
}
|
40
|
+
};
|
41
|
+
__decorateClass([
|
42
|
+
property({ type: String, reflect: true, attribute: "data-value" })
|
43
|
+
], AutocompleteItem.prototype, "value", 2);
|
44
|
+
__decorateClass([
|
45
|
+
property({ type: Boolean, reflect: true, attribute: "data-selected" })
|
46
|
+
], AutocompleteItem.prototype, "selected", 2);
|
47
|
+
__decorateClass([
|
48
|
+
property({ attribute: false })
|
49
|
+
], AutocompleteItem.prototype, "onSelect", 2);
|
50
|
+
__decorateClass([
|
51
|
+
consume({ context: commandListContext, subscribe: true }),
|
52
|
+
state({})
|
53
|
+
], AutocompleteItem.prototype, "listContext", 2);
|
54
|
+
AutocompleteItem = __decorateClass([
|
55
|
+
customElement("prosekit-autocomplete-item")
|
56
|
+
], AutocompleteItem);
|
57
|
+
|
58
|
+
export {
|
59
|
+
propNames,
|
60
|
+
AutocompleteItem
|
61
|
+
};
|
@@ -10,17 +10,22 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
10
10
|
return result;
|
11
11
|
};
|
12
12
|
|
13
|
-
// src/
|
14
|
-
import {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
13
|
+
// src/components/block-element/index.ts
|
14
|
+
import { LitElement } from "lit";
|
15
|
+
var LightElement = class extends LitElement {
|
16
|
+
createRenderRoot() {
|
17
|
+
return this;
|
18
|
+
}
|
19
|
+
setHidden(hidden) {
|
20
|
+
if (this.hidden !== hidden) {
|
21
|
+
this.hidden = hidden;
|
22
|
+
const display = this.style.display;
|
23
|
+
this.style.display = hidden ? "none" : display === "none" ? "" : display;
|
24
|
+
}
|
25
|
+
}
|
26
|
+
};
|
22
27
|
|
23
28
|
export {
|
24
29
|
__decorateClass,
|
25
|
-
|
30
|
+
LightElement
|
26
31
|
};
|
@@ -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,191 @@
|
|
1
|
+
import {
|
2
|
+
commandListContext
|
3
|
+
} from "./chunk-6P3YKUWI.js";
|
4
|
+
import {
|
5
|
+
ListManager
|
6
|
+
} from "./chunk-PCXKL6TA.js";
|
7
|
+
import {
|
8
|
+
LightElement,
|
9
|
+
__decorateClass
|
10
|
+
} from "./chunk-O5JP3B34.js";
|
11
|
+
|
12
|
+
// src/components/autocomplete-popover/context.ts
|
13
|
+
import { createContext } from "@lit/context";
|
14
|
+
var commandPopoverContext = createContext(
|
15
|
+
"prosekit-autocomplete-popover-context"
|
16
|
+
);
|
17
|
+
|
18
|
+
// src/components/autocomplete-list/component.ts
|
19
|
+
import { consume, provide } from "@lit/context";
|
20
|
+
import "@prosekit/core";
|
21
|
+
import "lit";
|
22
|
+
import { customElement, property, state } from "lit/decorators.js";
|
23
|
+
|
24
|
+
// src/utils/command-score.ts
|
25
|
+
import commandScoreModule from "@superhuman/command-score";
|
26
|
+
var commandScore = commandScoreModule;
|
27
|
+
|
28
|
+
// src/components/autocomplete-item/helpers.ts
|
29
|
+
function isAutocompleteItem(element) {
|
30
|
+
var _a;
|
31
|
+
return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-autocomplete-item";
|
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
|
+
}
|
46
|
+
|
47
|
+
// src/components/autocomplete-list/controller.ts
|
48
|
+
import {
|
49
|
+
defineKeymap,
|
50
|
+
withPriority,
|
51
|
+
Priority
|
52
|
+
} from "@prosekit/core";
|
53
|
+
import "lit";
|
54
|
+
var AutocompleteListController = class {
|
55
|
+
constructor(host, keymap) {
|
56
|
+
this.host = host;
|
57
|
+
this.keymap = keymap;
|
58
|
+
this.editor = null;
|
59
|
+
this.cleanup = null;
|
60
|
+
this.host.addController(this);
|
61
|
+
}
|
62
|
+
setEditor(editor) {
|
63
|
+
if (this.editor !== editor) {
|
64
|
+
this.editor = editor;
|
65
|
+
this.defineExtension();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
hostDisconnected() {
|
69
|
+
var _a;
|
70
|
+
(_a = this.cleanup) == null ? void 0 : _a.call(this);
|
71
|
+
this.cleanup = null;
|
72
|
+
}
|
73
|
+
defineExtension() {
|
74
|
+
var _a;
|
75
|
+
(_a = this.cleanup) == null ? void 0 : _a.call(this);
|
76
|
+
this.cleanup = null;
|
77
|
+
if (!this.editor || !this.keymap) {
|
78
|
+
return;
|
79
|
+
}
|
80
|
+
const extension = withPriority(defineKeymap(this.keymap), Priority.highest);
|
81
|
+
this.cleanup = this.editor.use(extension);
|
82
|
+
}
|
83
|
+
};
|
84
|
+
|
85
|
+
// src/components/autocomplete-list/component.ts
|
86
|
+
var propNames = ["editor"];
|
87
|
+
var AutocompleteList = class extends LightElement {
|
88
|
+
constructor() {
|
89
|
+
super(...arguments);
|
90
|
+
/** @hidden */
|
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: () => {
|
99
|
+
var _a, _b;
|
100
|
+
return (_b = (_a = this.popoverContext) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
|
101
|
+
},
|
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);
|
106
|
+
}
|
107
|
+
});
|
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
|
+
});
|
115
|
+
this.popoverContext = null;
|
116
|
+
this.context = {
|
117
|
+
scores: /* @__PURE__ */ new Map(),
|
118
|
+
selectedValue: ""
|
119
|
+
};
|
120
|
+
}
|
121
|
+
get active() {
|
122
|
+
var _a, _b;
|
123
|
+
return (_b = (_a = this.popoverContext) == null ? void 0 : _a.active) != null ? _b : false;
|
124
|
+
}
|
125
|
+
connectedCallback() {
|
126
|
+
super.connectedCallback();
|
127
|
+
this.listManager.selectFirstItem();
|
128
|
+
this.addEventListener("mousemove", (event) => {
|
129
|
+
this.listManager.handleMouseMove(event);
|
130
|
+
});
|
131
|
+
this.addEventListener("mouseover", (event) => {
|
132
|
+
this.listManager.handleMouseOver(event);
|
133
|
+
});
|
134
|
+
this.addEventListener("mousedown", (event) => {
|
135
|
+
this.listManager.handleMouseDown(event);
|
136
|
+
});
|
137
|
+
this.addEventListener("click", (event) => {
|
138
|
+
this.listManager.handleClick(event);
|
139
|
+
});
|
140
|
+
}
|
141
|
+
get items() {
|
142
|
+
return Array.from(
|
143
|
+
this.querySelectorAll("prosekit-autocomplete-item")
|
144
|
+
).filter(isAutocompleteItem);
|
145
|
+
}
|
146
|
+
selectFirstItem() {
|
147
|
+
this.listManager.selectFirstItem();
|
148
|
+
}
|
149
|
+
updateValue(selectedValue) {
|
150
|
+
if (this.context.selectedValue === selectedValue) {
|
151
|
+
return;
|
152
|
+
}
|
153
|
+
this.context = { ...this.context, selectedValue };
|
154
|
+
}
|
155
|
+
/** @hidden */
|
156
|
+
willUpdate(changedProperties) {
|
157
|
+
var _a, _b;
|
158
|
+
if (changedProperties.has("editor") && this.editor) {
|
159
|
+
this.controller.setEditor(this.editor);
|
160
|
+
}
|
161
|
+
const query = (_b = (_a = this.popoverContext) == null ? void 0 : _a.query) != null ? _b : "";
|
162
|
+
const scores = new Map(
|
163
|
+
this.items.map((item) => {
|
164
|
+
const content = item.content;
|
165
|
+
const score = commandScore(content, query);
|
166
|
+
return [content, score];
|
167
|
+
})
|
168
|
+
);
|
169
|
+
this.context = { ...this.context, scores };
|
170
|
+
}
|
171
|
+
};
|
172
|
+
__decorateClass([
|
173
|
+
property({ attribute: false })
|
174
|
+
], AutocompleteList.prototype, "editor", 2);
|
175
|
+
__decorateClass([
|
176
|
+
consume({ context: commandPopoverContext, subscribe: true }),
|
177
|
+
state()
|
178
|
+
], AutocompleteList.prototype, "popoverContext", 2);
|
179
|
+
__decorateClass([
|
180
|
+
provide({ context: commandListContext }),
|
181
|
+
state()
|
182
|
+
], AutocompleteList.prototype, "context", 2);
|
183
|
+
AutocompleteList = __decorateClass([
|
184
|
+
customElement("prosekit-autocomplete-list")
|
185
|
+
], AutocompleteList);
|
186
|
+
|
187
|
+
export {
|
188
|
+
commandPopoverContext,
|
189
|
+
propNames,
|
190
|
+
AutocompleteList
|
191
|
+
};
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import {
|
2
|
+
commandListContext
|
3
|
+
} from "./chunk-6P3YKUWI.js";
|
4
|
+
import {
|
5
|
+
LightElement,
|
6
|
+
__decorateClass
|
7
|
+
} from "./chunk-O5JP3B34.js";
|
8
|
+
|
9
|
+
// src/components/autocomplete-empty/index.ts
|
10
|
+
import { consume } from "@lit/context";
|
11
|
+
import "lit";
|
12
|
+
import { customElement, state } from "lit/decorators.js";
|
13
|
+
var propNames = [];
|
14
|
+
var AutocompleteEmpty = class extends LightElement {
|
15
|
+
connectedCallback() {
|
16
|
+
super.connectedCallback();
|
17
|
+
this.role = "option";
|
18
|
+
}
|
19
|
+
willUpdate(_changedProperties) {
|
20
|
+
var _a;
|
21
|
+
const scores = (_a = this.listContext) == null ? void 0 : _a.scores;
|
22
|
+
let hasMatch = false;
|
23
|
+
if (scores) {
|
24
|
+
for (const score of scores.values()) {
|
25
|
+
if (score > 0) {
|
26
|
+
hasMatch = true;
|
27
|
+
break;
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
this.setHidden(hasMatch);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
__decorateClass([
|
35
|
+
consume({ context: commandListContext, subscribe: true }),
|
36
|
+
state()
|
37
|
+
], AutocompleteEmpty.prototype, "listContext", 2);
|
38
|
+
AutocompleteEmpty = __decorateClass([
|
39
|
+
customElement("prosekit-autocomplete-empty")
|
40
|
+
], AutocompleteEmpty);
|
41
|
+
export {
|
42
|
+
AutocompleteEmpty,
|
43
|
+
propNames
|
44
|
+
};
|