@prosekit/lit 0.0.9 → 0.0.11

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 (32) hide show
  1. package/dist/_tsup-dts-rollup.d.ts +469 -0
  2. package/dist/{chunk-J73E7P6J.js → chunk-3UDA5JEW.js} +2 -9
  3. package/dist/{chunk-37EPOFI5.js → chunk-AWQAU2JR.js} +5 -3
  4. package/dist/chunk-BMDOOASL.js +57 -0
  5. package/dist/chunk-DYEHERSG.js +9 -0
  6. package/dist/chunk-G5KPDHDH.js +120 -0
  7. package/dist/chunk-HMV7TD6T.js +9 -0
  8. package/dist/{chunk-HPMQEYGA.js → chunk-KGZID7N7.js} +61 -92
  9. package/dist/chunk-PCXKL6TA.js +109 -0
  10. package/dist/chunk-TRZW33VF.js +35 -0
  11. package/dist/prosekit-lit-components-autocomplete-empty.d.ts +3 -17
  12. package/dist/prosekit-lit-components-autocomplete-empty.js +5 -3
  13. package/dist/prosekit-lit-components-autocomplete-item.d.ts +3 -32
  14. package/dist/prosekit-lit-components-autocomplete-item.js +3 -2
  15. package/dist/prosekit-lit-components-autocomplete-list.d.ts +3 -43
  16. package/dist/prosekit-lit-components-autocomplete-list.js +5 -3
  17. package/dist/prosekit-lit-components-autocomplete-popover.d.ts +4 -47
  18. package/dist/prosekit-lit-components-autocomplete-popover.js +23 -139
  19. package/dist/prosekit-lit-components-code-block-popover.d.ts +3 -0
  20. package/dist/prosekit-lit-components-code-block-popover.js +141 -0
  21. package/dist/prosekit-lit-components-combo-box-input.d.ts +3 -0
  22. package/dist/prosekit-lit-components-combo-box-input.js +74 -0
  23. package/dist/prosekit-lit-components-combo-box-item.d.ts +3 -0
  24. package/dist/prosekit-lit-components-combo-box-item.js +11 -0
  25. package/dist/prosekit-lit-components-combo-box-list.d.ts +3 -0
  26. package/dist/prosekit-lit-components-combo-box-list.js +50 -0
  27. package/dist/prosekit-lit-components-combo-box.d.ts +3 -0
  28. package/dist/prosekit-lit-components-combo-box.js +111 -0
  29. package/dist/prosekit-lit.d.ts +1 -2
  30. package/package.json +47 -7
  31. package/dist/context-19474449.d.ts +0 -7
  32. package/dist/context-436a56d3.d.ts +0 -8
@@ -1,8 +1,13 @@
1
1
  import {
2
- __decorateClass,
3
- blockComponentStyles,
4
2
  commandListContext
5
- } from "./chunk-J73E7P6J.js";
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 { html, LitElement } from "lit";
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.controller = new AutocompleteListController(this, {
74
- ArrowUp: () => {
75
- if (!this.active)
76
- return false;
77
- this.updateSelectedByChange(-1);
78
- return true;
79
- },
80
- ArrowDown: () => {
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
- if (!this.active)
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
- Enter: () => {
94
- if (!this.active)
95
- return false;
96
- this.handleSelect(this.selectedItem);
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
- this.lastMouseMoveTime = 0;
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
- var _a, _b;
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`<div role="listbox" aria-label="Suggestions" @mousemove="${this.handleMouseMove.bind(this)}" @mouseover="${this.handleMouseOver.bind(this)}" @click="${this.handleClick.bind(this)}" @mousedown="${this.handleMouseDown.bind(this)}"><slot></slot></div>`;
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
+ };
@@ -1,17 +1,3 @@
1
- import * as lit from 'lit';
2
- import { LitElement, CSSResultGroup, PropertyValues } from 'lit';
3
- import { A as AutocompleteListContext } from './context-19474449.js';
4
-
5
- declare const propNames: readonly [];
6
- interface AutocompleteEmptyProps {
7
- }
8
- declare class AutocompleteEmpty extends LitElement implements AutocompleteEmptyProps {
9
- /** @hidden */
10
- static styles: CSSResultGroup;
11
- listContext?: AutocompleteListContext;
12
- protected willUpdate(_changedProperties: PropertyValues<this>): void;
13
- /** @hidden */
14
- render(): lit.TemplateResult<1> | null;
15
- }
16
-
17
- export { AutocompleteEmpty, AutocompleteEmptyProps, propNames };
1
+ export { propNames } from './_tsup-dts-rollup';
2
+ export { AutocompleteEmptyProps } from './_tsup-dts-rollup';
3
+ export { AutocompleteEmpty } from './_tsup-dts-rollup';
@@ -1,8 +1,10 @@
1
1
  import {
2
- __decorateClass,
3
- blockComponentStyles,
4
2
  commandListContext
5
- } from "./chunk-J73E7P6J.js";
3
+ } from "./chunk-DYEHERSG.js";
4
+ import {
5
+ __decorateClass,
6
+ blockComponentStyles
7
+ } from "./chunk-3UDA5JEW.js";
6
8
 
7
9
  // src/components/autocomplete-empty/index.ts
8
10
  import { consume } from "@lit-labs/context";
@@ -1,32 +1,3 @@
1
- import * as lit from 'lit';
2
- import { LitElement, CSSResultGroup, PropertyValues } from 'lit';
3
- import { A as AutocompleteListContext } from './context-19474449.js';
4
-
5
- declare const propNames: readonly ["value", "onSelect"];
6
- interface AutocompleteItemProps {
7
- value?: string;
8
- onSelect: VoidFunction;
9
- }
10
- /**
11
- * Command menu item. Becomes active on pointer enter or through keyboard
12
- * navigation. Preferably pass a `value`, otherwise the value will be inferred
13
- * from the rendered item's `textContent`.
14
- */
15
- declare class AutocompleteItem extends LitElement implements Partial<AutocompleteItemProps> {
16
- /** @hidden */
17
- static styles: CSSResultGroup;
18
- value: string;
19
- selected: boolean;
20
- /** @hidden */
21
- onSelect?: VoidFunction;
22
- /** @hidden */
23
- defaultSlot?: HTMLSlotElement;
24
- listContext?: AutocompleteListContext;
25
- get content(): string;
26
- protected willUpdate(changedProperties: PropertyValues<this>): void;
27
- protected updated(changedProperties: PropertyValues<this>): void;
28
- /** @hidden */
29
- render(): lit.TemplateResult<1> | null;
30
- }
31
-
32
- export { AutocompleteItem, AutocompleteItemProps, propNames };
1
+ export { AutocompleteItemProps_alias_1 as AutocompleteItemProps } from './_tsup-dts-rollup';
2
+ export { AutocompleteItem_alias_1 as AutocompleteItem } from './_tsup-dts-rollup';
3
+ export { propNames_alias_2 as propNames } from './_tsup-dts-rollup';
@@ -1,8 +1,9 @@
1
1
  import {
2
2
  AutocompleteItem,
3
3
  propNames
4
- } from "./chunk-37EPOFI5.js";
5
- import "./chunk-J73E7P6J.js";
4
+ } from "./chunk-AWQAU2JR.js";
5
+ import "./chunk-DYEHERSG.js";
6
+ import "./chunk-3UDA5JEW.js";
6
7
  export {
7
8
  AutocompleteItem,
8
9
  propNames
@@ -1,43 +1,3 @@
1
- import * as lit from 'lit';
2
- import { LitElement, CSSResultGroup, PropertyValues } from 'lit';
3
- import { Editor } from '@prosekit/core';
4
- import { A as AutocompletePopoverContext } from './context-436a56d3.js';
5
- import { A as AutocompleteListContext } from './context-19474449.js';
6
-
7
- declare const propNames: readonly ["editor"];
8
- interface AutocompleteListProps {
9
- editor: Editor;
10
- }
11
- declare class AutocompleteList extends LitElement implements Partial<AutocompleteListProps> {
12
- /** @hidden */
13
- static styles: CSSResultGroup;
14
- /** @hidden */
15
- private controller;
16
- private get active();
17
- private lastMouseMoveTime;
18
- editor?: Editor;
19
- popoverContext: AutocompletePopoverContext | null;
20
- context: AutocompleteListContext;
21
- protected firstUpdated(): void;
22
- private get items();
23
- private get availableItems();
24
- private get firstItem();
25
- private get selectedItem();
26
- selectFirstItem(): void;
27
- private updateValue;
28
- private registerValue;
29
- /** @hidden */
30
- defaultSlot?: HTMLSlotElement;
31
- /** @hidden */
32
- willUpdate(changedProperties: PropertyValues<this>): void;
33
- private updateSelectedByChange;
34
- private handleMouseMove;
35
- private handleMouseOver;
36
- private handleClick;
37
- private handleMouseDown;
38
- private handleSelect;
39
- /** @hidden */
40
- render(): lit.TemplateResult<1>;
41
- }
42
-
43
- export { AutocompleteList, AutocompleteListProps, propNames };
1
+ export { AutocompleteList_alias_1 as AutocompleteList } from './_tsup-dts-rollup';
2
+ export { AutocompleteListProps_alias_1 as AutocompleteListProps } from './_tsup-dts-rollup';
3
+ export { propNames_alias_4 as propNames } from './_tsup-dts-rollup';
@@ -1,9 +1,11 @@
1
1
  import {
2
2
  AutocompleteList,
3
3
  propNames
4
- } from "./chunk-HPMQEYGA.js";
5
- import "./chunk-37EPOFI5.js";
6
- import "./chunk-J73E7P6J.js";
4
+ } from "./chunk-KGZID7N7.js";
5
+ import "./chunk-AWQAU2JR.js";
6
+ import "./chunk-DYEHERSG.js";
7
+ import "./chunk-PCXKL6TA.js";
8
+ import "./chunk-3UDA5JEW.js";
7
9
  export {
8
10
  AutocompleteList,
9
11
  propNames
@@ -1,47 +1,4 @@
1
- import * as lit from 'lit';
2
- import { LitElement, CSSResultGroup } from 'lit';
3
- import { ComputePositionConfig } from '@floating-ui/dom';
4
- import { Editor } from '@prosekit/core';
5
- import { A as AutocompletePopoverContext } from './context-436a56d3.js';
6
-
7
- /**
8
- * The `PopoverOptions` interface defines the options that can be passed to the
9
- * `computePosition` function from Floating UI. These options are used to
10
- * configure the positioning of the popover element relative to its reference
11
- * element. For more information on the available options, please refer to the
12
- * Floating UI documentation.
13
- *
14
- * https://floating-ui.com/docs/computeposition#options
15
- */
16
- type PopoverOptions = ComputePositionConfig;
17
-
18
- declare const propNames: readonly ["editor", "regex", "popoverOptions"];
19
- interface AutocompletePopoverProps {
20
- editor: Editor;
21
- regex: RegExp;
22
- popoverOptions?: PopoverOptions;
23
- }
24
- declare class AutocompletePopover extends LitElement implements Partial<AutocompletePopoverProps> {
25
- /** @hidden */
26
- static styles: CSSResultGroup;
27
- /** @hidden */
28
- private controller;
29
- editor?: Editor;
30
- regex?: RegExp;
31
- popoverOptions: PopoverOptions;
32
- context: AutocompletePopoverContext;
33
- /** @hidden */
34
- onSelect?: VoidFunction;
35
- private get list();
36
- private updateContext;
37
- /** @hidden */
38
- defaultSlot?: HTMLSlotElement;
39
- /** @hidden */
40
- protected get active(): boolean;
41
- /** @hidden */
42
- willUpdate(): void;
43
- /** @hidden */
44
- render(): lit.TemplateResult<1>;
45
- }
46
-
47
- export { AutocompletePopover, AutocompletePopoverProps, PopoverOptions, propNames };
1
+ export { PopoverOptions } from './_tsup-dts-rollup';
2
+ export { propNames_alias_5 as propNames } from './_tsup-dts-rollup';
3
+ export { AutocompletePopoverProps } from './_tsup-dts-rollup';
4
+ export { AutocompletePopover } from './_tsup-dts-rollup';