@prosekit/lit 0.2.7 → 0.3.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.
Files changed (46) hide show
  1. package/dist/_tsup-dts-rollup.d.ts +27 -1088
  2. package/dist/prosekit-lit-autocomplete.d.ts +4 -0
  3. package/dist/prosekit-lit-autocomplete.js +11 -0
  4. package/dist/prosekit-lit-block-handle.d.ts +2 -0
  5. package/dist/prosekit-lit-block-handle.js +7 -0
  6. package/dist/prosekit-lit-inline-popover.d.ts +0 -3
  7. package/dist/prosekit-lit-inline-popover.js +2 -190
  8. package/dist/prosekit-lit-popover.d.ts +3 -6
  9. package/dist/prosekit-lit-popover.js +7 -8
  10. package/dist/prosekit-lit-resizable.d.ts +2 -3
  11. package/dist/prosekit-lit-resizable.js +5 -108
  12. package/dist/prosekit-lit-tooltip.d.ts +3 -0
  13. package/dist/prosekit-lit-tooltip.js +9 -0
  14. package/package.json +24 -95
  15. package/dist/chunk-3AZDRLDR.js +0 -39
  16. package/dist/chunk-3TPE2GKD.js +0 -51
  17. package/dist/chunk-5CI65R73.js +0 -9
  18. package/dist/chunk-C4MW43I4.js +0 -9
  19. package/dist/chunk-CPC45JQ7.js +0 -202
  20. package/dist/chunk-I5EMQRE4.js +0 -60
  21. package/dist/chunk-MZAHIYA5.js +0 -114
  22. package/dist/chunk-S72UTR5M.js +0 -9
  23. package/dist/chunk-WEUGKLVB.js +0 -9
  24. package/dist/chunk-XHBZNZ2L.js +0 -369
  25. package/dist/prosekit-lit-autocomplete-empty.d.ts +0 -3
  26. package/dist/prosekit-lit-autocomplete-empty.js +0 -44
  27. package/dist/prosekit-lit-autocomplete-item.d.ts +0 -3
  28. package/dist/prosekit-lit-autocomplete-item.js +0 -10
  29. package/dist/prosekit-lit-autocomplete-list.d.ts +0 -3
  30. package/dist/prosekit-lit-autocomplete-list.js +0 -12
  31. package/dist/prosekit-lit-autocomplete-popover.d.ts +0 -4
  32. package/dist/prosekit-lit-autocomplete-popover.js +0 -199
  33. package/dist/prosekit-lit-block-popover.d.ts +0 -3
  34. package/dist/prosekit-lit-block-popover.js +0 -169
  35. package/dist/prosekit-lit-combo-box-input.d.ts +0 -3
  36. package/dist/prosekit-lit-combo-box-input.js +0 -92
  37. package/dist/prosekit-lit-combo-box-item.d.ts +0 -3
  38. package/dist/prosekit-lit-combo-box-item.js +0 -10
  39. package/dist/prosekit-lit-combo-box-list.d.ts +0 -3
  40. package/dist/prosekit-lit-combo-box-list.js +0 -44
  41. package/dist/prosekit-lit-combo-box.d.ts +0 -3
  42. package/dist/prosekit-lit-combo-box.js +0 -130
  43. package/dist/prosekit-lit-drag-handle.d.ts +0 -3
  44. package/dist/prosekit-lit-drag-handle.js +0 -94
  45. package/dist/prosekit-lit-resizable-handle.d.ts +0 -3
  46. package/dist/prosekit-lit-resizable-handle.js +0 -159
@@ -1,202 +0,0 @@
1
- import {
2
- autocompleteListContext
3
- } from "./chunk-5CI65R73.js";
4
- import {
5
- ListManager
6
- } from "./chunk-MZAHIYA5.js";
7
- import {
8
- LightElement,
9
- defineCustomElement
10
- } from "./chunk-3AZDRLDR.js";
11
-
12
- // src/components/autocomplete-popover/context.ts
13
- import { createContext } from "@lit/context";
14
- var autocompletePopoverContext = createContext(
15
- "prosekit-autocomplete-popover-context"
16
- );
17
-
18
- // src/components/autocomplete-list/component.ts
19
- import { ContextConsumer, ContextProvider } from "@lit/context";
20
- import "@prosekit/core";
21
- import "lit";
22
-
23
- // src/utils/command-score.ts
24
- import commandScoreModule from "@superhuman/command-score";
25
- var commandScore = commandScoreModule;
26
-
27
- // src/components/autocomplete-item/helpers.ts
28
- function isAutocompleteItem(element) {
29
- var _a;
30
- return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-autocomplete-item";
31
- }
32
- function queryClosestAutocompleteItem(element) {
33
- if (!element) {
34
- return null;
35
- }
36
- if (isAutocompleteItem(element)) {
37
- return element;
38
- }
39
- const item = element.closest("prosekit-autocomplete-item");
40
- if (isAutocompleteItem(item)) {
41
- return item;
42
- }
43
- return null;
44
- }
45
-
46
- // src/components/autocomplete-list/controller.ts
47
- import {
48
- defineKeymap,
49
- withPriority,
50
- Priority
51
- } from "@prosekit/core";
52
- import "lit";
53
- var AutocompleteListController = class {
54
- constructor(host, keymap) {
55
- this.host = host;
56
- this.keymap = keymap;
57
- this.editor = null;
58
- this.cleanup = null;
59
- this.host.addController(this);
60
- }
61
- setEditor(editor) {
62
- if (this.editor !== editor) {
63
- this.editor = editor;
64
- this.defineExtension();
65
- }
66
- }
67
- hostDisconnected() {
68
- var _a;
69
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
70
- this.cleanup = null;
71
- }
72
- defineExtension() {
73
- var _a;
74
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
75
- this.cleanup = null;
76
- if (!this.editor || !this.keymap) {
77
- return;
78
- }
79
- const extension = withPriority(defineKeymap(this.keymap), Priority.highest);
80
- this.cleanup = this.editor.use(extension);
81
- }
82
- };
83
-
84
- // src/components/autocomplete-list/component.ts
85
- var propNames = ["editor"];
86
- var AutocompleteList = class extends LightElement {
87
- constructor() {
88
- super(...arguments);
89
- /**
90
- * @hidden
91
- */
92
- this.listManager = new ListManager({
93
- getItems: () => this.items,
94
- getSelectedValue: () => this.context.value.selectedValue,
95
- setSelectedValue: (value, reason) => this.updateValue(value, reason),
96
- getItemValue: (item) => item.content,
97
- queryClosestItem: queryClosestAutocompleteItem,
98
- getActive: () => this.active,
99
- onDismiss: () => {
100
- var _a, _b;
101
- return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleDismiss) == null ? void 0 : _b.call(_a);
102
- },
103
- onSelect: (item) => {
104
- var _a, _b;
105
- if (item == null ? void 0 : item.onSelect) {
106
- (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.handleSubmit) == null ? void 0 : _b.call(_a);
107
- item.onSelect();
108
- return true;
109
- }
110
- return false;
111
- }
112
- });
113
- /**
114
- * @hidden
115
- */
116
- this.controller = new AutocompleteListController(this, {
117
- ArrowUp: () => this.listManager.handleArrowUp(),
118
- ArrowDown: () => this.listManager.handleArrowDown(),
119
- Escape: () => this.listManager.handleEscape(),
120
- Enter: () => this.listManager.handleEnter()
121
- });
122
- this.popoverContext = new ContextConsumer(this, {
123
- context: autocompletePopoverContext,
124
- subscribe: true
125
- });
126
- this.context = new ContextProvider(this, {
127
- context: autocompleteListContext,
128
- initialValue: {
129
- scores: /* @__PURE__ */ new Map(),
130
- selectedValue: "",
131
- selectedReason: "keyboard"
132
- }
133
- });
134
- }
135
- get active() {
136
- var _a, _b;
137
- return (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.active) != null ? _b : false;
138
- }
139
- connectedCallback() {
140
- super.connectedCallback();
141
- this.listManager.selectFirstItem();
142
- this.addEventListener("mousemove", (event) => {
143
- this.listManager.handleMouseMove(event);
144
- });
145
- this.addEventListener("mouseover", (event) => {
146
- this.listManager.handleMouseOver(event);
147
- });
148
- this.addEventListener("mousedown", (event) => {
149
- this.listManager.handleMouseDown(event);
150
- });
151
- this.addEventListener("click", (event) => {
152
- this.listManager.handleClick(event);
153
- });
154
- }
155
- get items() {
156
- return Array.from(
157
- this.querySelectorAll("prosekit-autocomplete-item")
158
- ).filter(isAutocompleteItem);
159
- }
160
- selectFirstItem() {
161
- this.listManager.selectFirstItem();
162
- }
163
- updateValue(selectedValue, selectedReason) {
164
- const context = this.context.value;
165
- if (context.selectedValue === selectedValue) {
166
- return;
167
- }
168
- this.context.setValue({ ...context, selectedValue, selectedReason });
169
- }
170
- /**
171
- * @hidden
172
- */
173
- willUpdate(changedProperties) {
174
- var _a, _b;
175
- if (changedProperties.has("editor") && this.editor) {
176
- this.controller.setEditor(this.editor);
177
- }
178
- const query = (_b = (_a = this.popoverContext.value) == null ? void 0 : _a.query) != null ? _b : "";
179
- const scores = new Map(
180
- this.items.map((item) => {
181
- const content = item.content;
182
- const score = commandScore(content, query);
183
- return [content, score];
184
- })
185
- );
186
- const context = this.context.value;
187
- this.context.setValue({ ...context, scores });
188
- }
189
- };
190
- /**
191
- * @hidden
192
- */
193
- AutocompleteList.properties = {
194
- editor: { attribute: false }
195
- };
196
- defineCustomElement("prosekit-autocomplete-list", AutocompleteList);
197
-
198
- export {
199
- autocompletePopoverContext,
200
- propNames,
201
- AutocompleteList
202
- };
@@ -1,60 +0,0 @@
1
- import {
2
- autocompleteListContext
3
- } from "./chunk-5CI65R73.js";
4
- import {
5
- LightElement,
6
- defineCustomElement
7
- } from "./chunk-3AZDRLDR.js";
8
-
9
- // src/components/autocomplete-item/component.ts
10
- import { ContextConsumer } from "@lit/context";
11
- import "lit";
12
- var propNames = ["value", "onSelect"];
13
- var AutocompleteItem = class extends LightElement {
14
- constructor() {
15
- super(...arguments);
16
- this.listContext = new ContextConsumer(this, {
17
- context: autocompleteListContext,
18
- subscribe: true
19
- });
20
- this.value = "";
21
- this.selected = false;
22
- }
23
- get content() {
24
- const text = this.value || this.textContent || "";
25
- return text.trim().toLowerCase();
26
- }
27
- connectedCallback() {
28
- super.connectedCallback();
29
- this.role = "option";
30
- }
31
- willUpdate() {
32
- var _a, _b;
33
- const content = this.content;
34
- const score = ((_a = this.listContext.value) == null ? void 0 : _a.scores.get(content)) || 0;
35
- const hidden = score <= 0;
36
- this.selected = !hidden && content === ((_b = this.listContext.value) == null ? void 0 : _b.selectedValue);
37
- this.setHidden(hidden);
38
- }
39
- updated(changedProperties) {
40
- var _a;
41
- this.ariaSelected = String(this.selected);
42
- if (this.selected && changedProperties.has("selected") && !changedProperties.get("selected") && ((_a = this.listContext.value) == null ? void 0 : _a.selectedReason) === "keyboard") {
43
- this.scrollIntoView({ block: "nearest" });
44
- }
45
- }
46
- };
47
- /**
48
- * @hidden
49
- */
50
- AutocompleteItem.properties = {
51
- value: { type: String, reflect: true, attribute: "data-value" },
52
- selected: { type: Boolean, reflect: true, attribute: "data-selected" },
53
- onSelect: { attribute: false }
54
- };
55
- defineCustomElement("prosekit-autocomplete-item", AutocompleteItem);
56
-
57
- export {
58
- propNames,
59
- AutocompleteItem
60
- };
@@ -1,114 +0,0 @@
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 active() {
18
- return this.getActive();
19
- }
20
- get availableItems() {
21
- var _a, _b;
22
- return (_b = (_a = this.items) == null ? void 0 : _a.filter((item) => !item.hidden)) != null ? _b : [];
23
- }
24
- get firstItem() {
25
- var _a;
26
- return (_a = this.availableItems[0]) != null ? _a : null;
27
- }
28
- get selectedItem() {
29
- var _a;
30
- return (_a = this.availableItems.find(
31
- (item) => this.getItemValue(item) === this.getSelectedValue()
32
- )) != null ? _a : null;
33
- }
34
- updateSelectedByChange(change) {
35
- const items = this.availableItems;
36
- if (items.length === 0) {
37
- return;
38
- }
39
- const selectedItem = this.selectedItem;
40
- const selectedIndex = selectedItem ? items.indexOf(selectedItem) : -1;
41
- let nextIndex = selectedIndex + change;
42
- if (nextIndex < 0) {
43
- nextIndex = 0;
44
- } else if (nextIndex >= items.length) {
45
- nextIndex = items.length - 1;
46
- }
47
- if (selectedIndex !== nextIndex) {
48
- this.setSelectedValue(this.getItemValue(items[nextIndex]), "keyboard");
49
- }
50
- }
51
- handleSelect(item, reason) {
52
- this.setSelectedValue(this.getItemValue(item), reason);
53
- }
54
- selectFirstItem() {
55
- if (!this.active)
56
- return;
57
- const item = this.firstItem;
58
- const value = item ? this.getItemValue(item) : "";
59
- this.setSelectedValue(value, "keyboard");
60
- item == null ? void 0 : item.scrollIntoView({ block: "nearest" });
61
- }
62
- handleMouseMove(_event) {
63
- this.lastMouseMoveTime = Date.now();
64
- }
65
- handleMouseOver(event) {
66
- if (this.lastMouseMoveTime + 500 < Date.now()) {
67
- return;
68
- }
69
- const target = event.target;
70
- const item = target && this.queryClosestItem(target);
71
- if (item) {
72
- this.setSelectedValue(this.getItemValue(item), "mouse");
73
- }
74
- }
75
- handleMouseDown(event) {
76
- event.preventDefault();
77
- }
78
- handleClick(event) {
79
- event.preventDefault();
80
- const target = event.target;
81
- const item = target && this.queryClosestItem(target);
82
- if (item) {
83
- this.handleSelect(item, "mouse");
84
- this.onSelect(item);
85
- }
86
- }
87
- handleArrowUp() {
88
- if (!this.active)
89
- return false;
90
- this.updateSelectedByChange(-1);
91
- return true;
92
- }
93
- handleArrowDown() {
94
- if (!this.active)
95
- return false;
96
- this.updateSelectedByChange(1);
97
- return true;
98
- }
99
- handleEscape() {
100
- if (!this.active)
101
- return false;
102
- this.onDismiss();
103
- return true;
104
- }
105
- handleEnter() {
106
- if (!this.active)
107
- return false;
108
- return this.onSelect(this.selectedItem);
109
- }
110
- };
111
-
112
- export {
113
- ListManager
114
- };
@@ -1,9 +0,0 @@
1
- // src/components/block-popover/context.ts
2
- import { createContext } from "@lit/context";
3
- var blockPopoverContext = createContext(
4
- "prosekit-block-popover-context"
5
- );
6
-
7
- export {
8
- blockPopoverContext
9
- };
@@ -1,9 +0,0 @@
1
- // src/components/resizable/context.ts
2
- import { createContext } from "@lit/context";
3
- var resizableContext = createContext(
4
- "prosekit-resizable-context"
5
- );
6
-
7
- export {
8
- resizableContext
9
- };