@prosekit/lit
Advanced tools
Comparing version
@@ -13,7 +13,6 @@ import { AutoUpdateOptions } from '@floating-ui/dom'; | ||
import { TemplateResult } from 'lit'; | ||
import { UserProjectConfigExport } from 'vitest/dist/config.js'; | ||
import { VirtualElement } from '@floating-ui/dom'; | ||
export declare class AutocompleteEmpty extends LightElement implements AutocompleteEmptyProps { | ||
listContext?: AutocompleteListContext; | ||
private listContext; | ||
connectedCallback(): void; | ||
@@ -32,7 +31,24 @@ protected willUpdate(_changedProperties: PropertyValues<this>): void; | ||
declare class AutocompleteItem extends LightElement implements Partial<AutocompleteItemProps> { | ||
private listContext; | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
value: { | ||
type: StringConstructor; | ||
reflect: true; | ||
attribute: string; | ||
}; | ||
selected: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
attribute: string; | ||
}; | ||
onSelect: { | ||
attribute: false; | ||
}; | ||
}; | ||
value: string; | ||
selected: boolean; | ||
/** @hidden */ | ||
onSelect?: VoidFunction; | ||
listContext?: AutocompleteListContext; | ||
get content(): string; | ||
@@ -54,10 +70,22 @@ connectedCallback(): void; | ||
declare class AutocompleteList extends LightElement implements Partial<AutocompleteListProps> { | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
private listManager; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
private controller; | ||
private popoverContext; | ||
private get active(); | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
editor: { | ||
attribute: false; | ||
}; | ||
}; | ||
editor?: Editor; | ||
popoverContext: AutocompletePopoverContext | null; | ||
context: AutocompleteListContext; | ||
private context; | ||
connectedCallback(): void; | ||
@@ -67,3 +95,5 @@ private get items(); | ||
private updateValue; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
willUpdate(changedProperties: PropertyValues<this>): void; | ||
@@ -80,2 +110,6 @@ } | ||
export declare const autocompleteListContext: { | ||
__context__: AutocompleteListContext; | ||
}; | ||
export declare class AutocompleteListController implements ReactiveController { | ||
@@ -99,15 +133,58 @@ private host; | ||
export declare class AutocompletePopover extends Popover implements Partial<AutocompletePopoverProps> { | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
private controller; | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
editor: { | ||
attribute: false; | ||
}; | ||
regex: { | ||
attribute: false; | ||
}; | ||
popoverOptions: { | ||
attribute: false; | ||
}; | ||
onSelect: { | ||
attribute: false; | ||
}; | ||
active: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
attribute: false; | ||
}; | ||
options: { | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
autoUpdateOptions: { | ||
type: ObjectConstructor; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
editor?: Editor; | ||
regex?: RegExp; | ||
popoverOptions: PopoverOptions; | ||
context: AutocompletePopoverContext; | ||
/** @hidden */ | ||
onSelect?: VoidFunction; | ||
private context; | ||
private get list(); | ||
private updateContext; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
willUpdate(changedProperties: PropertyValues<this>): void; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
hide(): void; | ||
@@ -123,2 +200,6 @@ } | ||
export declare const autocompletePopoverContext: { | ||
__context__: AutocompletePopoverContext; | ||
}; | ||
export declare class AutocompletePopoverController implements ReactiveController { | ||
@@ -150,6 +231,49 @@ private host; | ||
/** | ||
* If the browser supports the Popover API, we use the body as the boundary | ||
* since we don't need to worry about the popover overflowing the parent | ||
* element. | ||
*/ | ||
export declare const boundary: HTMLElement | undefined; | ||
export declare class ComboBox extends Popover { | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
onDismiss: { | ||
attribute: false; | ||
}; | ||
active: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
attribute: false; | ||
}; | ||
options: { | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
autoUpdateOptions: { | ||
type: ObjectConstructor; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
onDismiss?: VoidFunction; | ||
private listManager; | ||
context: ComboBoxContext; | ||
/** | ||
* @hidden | ||
*/ | ||
hide(): void; | ||
private context; | ||
private getContext; | ||
private setInputValue; | ||
private setSelectedValue; | ||
get items(): ComboBoxItem[]; | ||
@@ -162,3 +286,3 @@ } | ||
selectedValue: string; | ||
setSelectedValue: (val: string) => void; | ||
selectedReason: 'mouse' | 'keyboard'; | ||
listManager: ListManager<ComboBoxItem>; | ||
@@ -172,9 +296,22 @@ } | ||
export declare class ComboBoxInput extends LightElement { | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
placeholder: { | ||
attribute: true; | ||
}; | ||
}; | ||
placeholder: string; | ||
comboBoxContext: ComboBoxContext | null; | ||
private comboBoxContext; | ||
private visible; | ||
private handleKeydown; | ||
private handleInput; | ||
/** | ||
* @hidden | ||
*/ | ||
protected firstUpdated(): void; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
render(): TemplateResult<1>; | ||
@@ -188,8 +325,26 @@ } | ||
declare class ComboBoxItem extends LightElement { | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
editor: { | ||
attribute: false; | ||
}; | ||
selected: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
attribute: string; | ||
}; | ||
onSelect: { | ||
attribute: false; | ||
}; | ||
}; | ||
editor?: Editor; | ||
selected: boolean; | ||
comboBoxContext?: ComboBoxContext; | ||
/** @hidden */ | ||
onSelect?: VoidFunction; | ||
protected updated(): void; | ||
private comboBoxContext; | ||
/** | ||
* @hidden | ||
*/ | ||
protected updated(changedProperties: PropertyValues<this>): void; | ||
} | ||
@@ -206,3 +361,3 @@ export { ComboBoxItem } | ||
declare class ComboBoxList extends LightElement { | ||
comboBoxContext: ComboBoxContext | null; | ||
private comboBoxContext; | ||
connectedCallback(): void; | ||
@@ -223,10 +378,2 @@ } | ||
export declare const commandListContext: { | ||
__context__: AutocompleteListContext; | ||
}; | ||
export declare const commandPopoverContext: { | ||
__context__: AutocompletePopoverContext; | ||
}; | ||
declare type CommandScore = (item: string, query: string) => number; | ||
@@ -240,3 +387,7 @@ | ||
export declare const default_alias_1: UserProjectConfigExport; | ||
export declare const default_alias_1: { | ||
test: { | ||
environment: "jsdom"; | ||
}; | ||
}; | ||
@@ -257,13 +408,53 @@ /** | ||
export declare function defineCustomElement(name: string, constructor: CustomElementConstructor, options?: ElementDefinitionOptions): void; | ||
export declare function getVirtualSelectionElement(view: EditorView): Range | undefined; | ||
export declare class InlinePopover extends Popover implements Partial<InlinePopoverProps> { | ||
/** @hidden */ | ||
private controller; | ||
/** | ||
* @hidden | ||
*/ | ||
static properties: { | ||
editor: { | ||
attribute: false; | ||
}; | ||
popoverOptions: { | ||
attribute: false; | ||
}; | ||
active: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
attribute: false; | ||
}; | ||
options: { | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
autoUpdateOptions: { | ||
type: ObjectConstructor; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
editor?: Editor; | ||
popoverOptions: PopoverOptions; | ||
constructor(); | ||
/** @hidden */ | ||
dismiss: "escape"; | ||
/** | ||
* @hidden | ||
*/ | ||
private controller; | ||
/** | ||
* @hidden | ||
*/ | ||
willUpdate(): void; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
hide(): void; | ||
@@ -301,2 +492,6 @@ } | ||
export declare class LightElement extends LitElement { | ||
/** | ||
* @hidden | ||
*/ | ||
constructor(); | ||
createRenderRoot(): this; | ||
@@ -349,7 +544,32 @@ setHidden(hidden: boolean): void; | ||
export declare class Popover extends LightElement implements Partial<PopoverProps> { | ||
/** @hidden */ | ||
constructor(); | ||
/** | ||
* Controls the visibility of the popover element. When set to `true`, the popover is displayed and positioned | ||
* relative to its reference element. When set to `false`, the popover is hidden and its positioning logic is | ||
* @hidden | ||
*/ | ||
static properties: { | ||
active: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
reference: { | ||
attribute: false; | ||
}; | ||
options: { | ||
attribute: false; | ||
}; | ||
autoUpdate: { | ||
type: BooleanConstructor; | ||
reflect: true; | ||
}; | ||
autoUpdateOptions: { | ||
type: ObjectConstructor; | ||
}; | ||
dismiss: { | ||
type: StringConstructor; | ||
reflect: true; | ||
}; | ||
}; | ||
/** | ||
* Controls the visibility of the popover element. When set to `true`, the | ||
* popover is displayed and positioned relative to its reference element. When | ||
* set to `false`, the popover is hidden and its positioning logic is | ||
* deactivated. | ||
@@ -359,9 +579,11 @@ */ | ||
/** | ||
* The element that the popover is anchored to. This can be either a DOM element or an object that implements the | ||
* virtual element interface from Floating UI. | ||
* The element that the popover is anchored to. This can be either a DOM | ||
* element or an object that implements the virtual element interface from | ||
* Floating UI. | ||
*/ | ||
reference?: Element | VirtualElement; | ||
/** | ||
* The options that are passed to the `computePosition` function from Floating UI. These options are used to | ||
* configure the positioning of the popover element relative to its reference element. For more information on the | ||
* The options that are passed to the `computePosition` function from Floating | ||
* UI. These options are used to configure the positioning of the popover | ||
* element relative to its reference element. For more information on the | ||
* available options, please refer to the Floating UI documentation. | ||
@@ -371,5 +593,6 @@ */ | ||
/** | ||
* Controls whether the popover position is automatically updated when the reference element changes position. When | ||
* set to `true`, the popover position is updated automatically. When set to `false`, the popover position is only | ||
* updated when the given properties are changed. | ||
* Controls whether the popover position is automatically updated when the | ||
* reference element changes position. When set to `true`, the popover | ||
* position is updated automatically. When set to `false`, the popover | ||
* position is only updated when the given properties are changed. | ||
* | ||
@@ -380,5 +603,7 @@ * @default false | ||
/** | ||
* The options that are passed to the `autoUpdate` function from Floating UI. These options are used to configure the | ||
* automatic update behavior of the popover position. For more information on the available options, please refer to | ||
* the Floating UI documentation. This property is only used when the `autoUpdate` property is set to `true`. | ||
* The options that are passed to the `autoUpdate` function from Floating UI. | ||
* These options are used to configure the automatic update behavior of the | ||
* popover position. For more information on the available options, please | ||
* refer to the Floating UI documentation. This property is only used when the | ||
* `autoUpdate` property is set to `true`. | ||
*/ | ||
@@ -398,18 +623,34 @@ autoUpdateOptions?: AutoUpdateOptions; | ||
*/ | ||
dismiss: string; | ||
/** @hidden */ | ||
dismiss: 'off' | 'on' | 'click' | 'escape'; | ||
/** | ||
* @hidden | ||
*/ | ||
private disposeAutoUpdate?; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
private disposeEventListeners?; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
connectedCallback(): void; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
disconnectedCallback(): void; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
protected updated(changedProperties: PropertyValues<this>): void; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
private start; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
private compute; | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
hide(): void; | ||
@@ -421,2 +662,7 @@ private handleDocumentMouseDown; | ||
/** | ||
* Whether the browser supports the [Popover API](https://developer.mozilla.org/en-US/docs/Web/API/Popover_API). | ||
*/ | ||
export declare const popoverAvailable: boolean; | ||
/** | ||
* The `PopoverOptions` interface defines the options that can be passed to the | ||
@@ -423,0 +669,0 @@ * `computePosition` function from Floating UI. These options are used to |
import { | ||
commandListContext | ||
} from "./chunk-6P3YKUWI.js"; | ||
autocompleteListContext | ||
} from "./chunk-5CI65R73.js"; | ||
import { | ||
LightElement, | ||
__decorateClass | ||
} from "./chunk-O5JP3B34.js"; | ||
defineCustomElement | ||
} from "./chunk-S32IZIQF.js"; | ||
// src/components/autocomplete-empty/index.ts | ||
import { consume } from "@lit/context"; | ||
import { ContextConsumer } from "@lit/context"; | ||
import "lit"; | ||
import { customElement, state } from "lit/decorators.js"; | ||
var propNames = []; | ||
var AutocompleteEmpty = class extends LightElement { | ||
constructor() { | ||
super(...arguments); | ||
this.listContext = new ContextConsumer(this, { | ||
context: autocompleteListContext, | ||
subscribe: true | ||
}); | ||
} | ||
connectedCallback() { | ||
@@ -21,3 +27,3 @@ super.connectedCallback(); | ||
var _a; | ||
const scores = (_a = this.listContext) == null ? void 0 : _a.scores; | ||
const scores = (_a = this.listContext.value) == null ? void 0 : _a.scores; | ||
let hasMatch = false; | ||
@@ -35,9 +41,3 @@ if (scores) { | ||
}; | ||
__decorateClass([ | ||
consume({ context: commandListContext, subscribe: true }), | ||
state() | ||
], AutocompleteEmpty.prototype, "listContext", 2); | ||
AutocompleteEmpty = __decorateClass([ | ||
customElement("prosekit-autocomplete-empty") | ||
], AutocompleteEmpty); | ||
defineCustomElement("prosekit-autocomplete-empty", AutocompleteEmpty); | ||
export { | ||
@@ -44,0 +44,0 @@ AutocompleteEmpty, |
import { | ||
AutocompleteItem, | ||
propNames | ||
} from "./chunk-M6MY5WGM.js"; | ||
import "./chunk-6P3YKUWI.js"; | ||
import "./chunk-O5JP3B34.js"; | ||
} from "./chunk-MLUELLVA.js"; | ||
import "./chunk-5CI65R73.js"; | ||
import "./chunk-S32IZIQF.js"; | ||
export { | ||
@@ -8,0 +8,0 @@ AutocompleteItem, |
import { | ||
AutocompleteList, | ||
propNames | ||
} from "./chunk-66YTZIW6.js"; | ||
import "./chunk-M6MY5WGM.js"; | ||
import "./chunk-6P3YKUWI.js"; | ||
import "./chunk-IDDQA3VV.js"; | ||
import "./chunk-O5JP3B34.js"; | ||
} from "./chunk-TGJAVLMZ.js"; | ||
import "./chunk-MLUELLVA.js"; | ||
import "./chunk-5CI65R73.js"; | ||
import "./chunk-PW3MTUZM.js"; | ||
import "./chunk-S32IZIQF.js"; | ||
export { | ||
@@ -10,0 +10,0 @@ AutocompleteList, |
import { | ||
commandPopoverContext | ||
} from "./chunk-66YTZIW6.js"; | ||
import "./chunk-M6MY5WGM.js"; | ||
import "./chunk-6P3YKUWI.js"; | ||
autocompletePopoverContext | ||
} from "./chunk-TGJAVLMZ.js"; | ||
import "./chunk-MLUELLVA.js"; | ||
import "./chunk-5CI65R73.js"; | ||
import { | ||
Popover | ||
} from "./chunk-7WLKD2U6.js"; | ||
import "./chunk-IDDQA3VV.js"; | ||
Popover, | ||
boundary | ||
} from "./chunk-Z3PEQ6MW.js"; | ||
import "./chunk-PW3MTUZM.js"; | ||
import { | ||
__decorateClass | ||
} from "./chunk-O5JP3B34.js"; | ||
defineCustomElement | ||
} from "./chunk-S32IZIQF.js"; | ||
// src/components/autocomplete-popover/index.ts | ||
import { provide } from "@lit/context"; | ||
import { ContextProvider } from "@lit/context"; | ||
import "@prosekit/core"; | ||
import { customElement, property, state } from "lit/decorators.js"; | ||
@@ -117,4 +117,4 @@ // src/components/autocomplete-list/helpers.ts | ||
var defaultDetectOverflowOptions = { | ||
// Make sure the popover is always at least 8px away from the boundary | ||
padding: 8 | ||
padding: 8, | ||
boundary | ||
}; | ||
@@ -131,6 +131,6 @@ var defaultPopoverOptions = { | ||
inline(), | ||
offset(() => ({ | ||
offset({ | ||
// Move down the popover by 4px | ||
mainAxis: 4 | ||
})), | ||
}), | ||
// Flip the popover to the top if it's overflowing the viewport | ||
@@ -175,3 +175,5 @@ // | ||
super(...arguments); | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
this.controller = new AutocompletePopoverController( | ||
@@ -182,14 +184,17 @@ this, | ||
this.popoverOptions = defaultPopoverOptions; | ||
this.context = { | ||
active: false, | ||
query: "", | ||
handleDismiss: () => { | ||
var _a, _b; | ||
return (_b = (_a = this.controller).handleDismiss) == null ? void 0 : _b.call(_a); | ||
}, | ||
handleSubmit: () => { | ||
var _a, _b; | ||
return (_b = (_a = this.controller).handleSubmit) == null ? void 0 : _b.call(_a); | ||
this.context = new ContextProvider(this, { | ||
context: autocompletePopoverContext, | ||
initialValue: { | ||
active: false, | ||
query: "", | ||
handleDismiss: () => { | ||
var _a, _b; | ||
return (_b = (_a = this.controller).handleDismiss) == null ? void 0 : _b.call(_a); | ||
}, | ||
handleSubmit: () => { | ||
var _a, _b; | ||
return (_b = (_a = this.controller).handleSubmit) == null ? void 0 : _b.call(_a); | ||
} | ||
} | ||
}; | ||
}); | ||
} | ||
@@ -201,6 +206,8 @@ get list() { | ||
updateContext(query, active) { | ||
if (this.context.query === query && this.context.active === active) { | ||
const context = this.context.value; | ||
if (context.query === query && context.active === active) { | ||
return; | ||
} | ||
this.context = { ...this.context, query, active }; | ||
this.context.setValue({ ...context, query, active }); | ||
this.requestUpdate(); | ||
requestAnimationFrame(() => { | ||
@@ -211,3 +218,5 @@ var _a; | ||
} | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
willUpdate(changedProperties) { | ||
@@ -226,3 +235,5 @@ var _a, _b; | ||
} | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
hide() { | ||
@@ -237,21 +248,13 @@ var _a; | ||
}; | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], AutocompletePopover.prototype, "editor", 2); | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], AutocompletePopover.prototype, "regex", 2); | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], AutocompletePopover.prototype, "popoverOptions", 2); | ||
__decorateClass([ | ||
provide({ context: commandPopoverContext }), | ||
state() | ||
], AutocompletePopover.prototype, "context", 2); | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], AutocompletePopover.prototype, "onSelect", 2); | ||
AutocompletePopover = __decorateClass([ | ||
customElement("prosekit-autocomplete-popover") | ||
], AutocompletePopover); | ||
/** | ||
* @hidden | ||
*/ | ||
AutocompletePopover.properties = { | ||
...Popover.properties, | ||
editor: { attribute: false }, | ||
regex: { attribute: false }, | ||
popoverOptions: { attribute: false }, | ||
onSelect: { attribute: false } | ||
}; | ||
defineCustomElement("prosekit-autocomplete-popover", AutocompletePopover); | ||
export { | ||
@@ -258,0 +261,0 @@ AutocompletePopover, |
@@ -6,9 +6,8 @@ import { | ||
LightElement, | ||
__decorateClass | ||
} from "./chunk-O5JP3B34.js"; | ||
defineCustomElement | ||
} from "./chunk-S32IZIQF.js"; | ||
// src/components/combo-box-input/index.ts | ||
import { consume } from "@lit/context"; | ||
import { ContextConsumer } from "@lit/context"; | ||
import { html } from "lit"; | ||
import { customElement, property, state } from "lit/decorators.js"; | ||
var propNames = ["placeholder"]; | ||
@@ -19,3 +18,6 @@ var ComboBoxInput = class extends LightElement { | ||
this.placeholder = ""; | ||
this.comboBoxContext = null; | ||
this.comboBoxContext = new ContextConsumer(this, { | ||
context: comboBoxContext, | ||
subscribe: true | ||
}); | ||
this.visible = false; | ||
@@ -25,10 +27,19 @@ } | ||
var _a, _b, _c, _d, _e, _f, _g, _h; | ||
if (event.code === "ArrowUp") { | ||
(_b = (_a = this.comboBoxContext) == null ? void 0 : _a.listManager) == null ? void 0 : _b.handleArrowUp(); | ||
} else if (event.code === "ArrowDown") { | ||
(_d = (_c = this.comboBoxContext) == null ? void 0 : _c.listManager) == null ? void 0 : _d.handleArrowDown(); | ||
} else if (event.code === "Escape") { | ||
(_f = (_e = this.comboBoxContext) == null ? void 0 : _e.listManager) == null ? void 0 : _f.handleEscape(); | ||
} else if (event.code === "Enter") { | ||
(_h = (_g = this.comboBoxContext) == null ? void 0 : _g.listManager) == null ? void 0 : _h.handleEnter(); | ||
switch (event.code) { | ||
case "ArrowUp": | ||
(_b = (_a = this.comboBoxContext.value) == null ? void 0 : _a.listManager) == null ? void 0 : _b.handleArrowUp(); | ||
event.preventDefault(); | ||
return; | ||
case "ArrowDown": | ||
(_d = (_c = this.comboBoxContext.value) == null ? void 0 : _c.listManager) == null ? void 0 : _d.handleArrowDown(); | ||
event.preventDefault(); | ||
return; | ||
case "Escape": | ||
(_f = (_e = this.comboBoxContext.value) == null ? void 0 : _e.listManager) == null ? void 0 : _f.handleEscape(); | ||
event.preventDefault(); | ||
return; | ||
case "Enter": | ||
(_h = (_g = this.comboBoxContext.value) == null ? void 0 : _g.listManager) == null ? void 0 : _h.handleEnter(); | ||
event.preventDefault(); | ||
return; | ||
} | ||
@@ -39,4 +50,7 @@ } | ||
const value = (_b = (_a = event == null ? void 0 : event.target) == null ? void 0 : _a.value) != null ? _b : ""; | ||
(_c = this.comboBoxContext) == null ? void 0 : _c.setInputValue(value); | ||
(_c = this.comboBoxContext.value) == null ? void 0 : _c.setInputValue(value); | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
firstUpdated() { | ||
@@ -57,18 +71,17 @@ const resizeObserver = new ResizeObserver((entries) => { | ||
} | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
render() { | ||
var _a, _b; | ||
return html`<input placeholder="${this.placeholder}" @keydown="${(event) => this.handleKeydown(event)}" @input="${(event) => this.handleInput(event)}" value="${(_b = (_a = this.comboBoxContext) == null ? void 0 : _a.inputValue) != null ? _b : ""}">`; | ||
return html`<input placeholder="${this.placeholder}" @keydown="${(event) => this.handleKeydown(event)}" @input="${(event) => this.handleInput(event)}" .value="${(_b = (_a = this.comboBoxContext.value) == null ? void 0 : _a.inputValue) != null ? _b : ""}">`; | ||
} | ||
}; | ||
__decorateClass([ | ||
property({ attribute: true }) | ||
], ComboBoxInput.prototype, "placeholder", 2); | ||
__decorateClass([ | ||
consume({ context: comboBoxContext, subscribe: true }), | ||
state() | ||
], ComboBoxInput.prototype, "comboBoxContext", 2); | ||
ComboBoxInput = __decorateClass([ | ||
customElement("prosekit-combo-box-input") | ||
], ComboBoxInput); | ||
/** | ||
* @hidden | ||
*/ | ||
ComboBoxInput.properties = { | ||
placeholder: { attribute: true } | ||
}; | ||
defineCustomElement("prosekit-combo-box-input", ComboBoxInput); | ||
export { | ||
@@ -75,0 +88,0 @@ ComboBoxInput, |
import { | ||
ComboBoxItem, | ||
propNames | ||
} from "./chunk-55G7TJI3.js"; | ||
} from "./chunk-L6FOAZFL.js"; | ||
import "./chunk-C4MW43I4.js"; | ||
import "./chunk-O5JP3B34.js"; | ||
import "./chunk-S32IZIQF.js"; | ||
export { | ||
@@ -8,0 +8,0 @@ ComboBoxItem, |
@@ -6,8 +6,7 @@ import { | ||
LightElement, | ||
__decorateClass | ||
} from "./chunk-O5JP3B34.js"; | ||
defineCustomElement | ||
} from "./chunk-S32IZIQF.js"; | ||
// src/components/combo-box-list/component.ts | ||
import { consume } from "@lit/context"; | ||
import { customElement, state } from "lit/decorators.js"; | ||
import { ContextConsumer } from "@lit/context"; | ||
var propNames = []; | ||
@@ -17,3 +16,6 @@ var ComboBoxList = class extends LightElement { | ||
super(...arguments); | ||
this.comboBoxContext = null; | ||
this.comboBoxContext = new ContextConsumer(this, { | ||
context: comboBoxContext, | ||
subscribe: true | ||
}); | ||
} | ||
@@ -24,25 +26,19 @@ connectedCallback() { | ||
var _a; | ||
(_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleMouseMove(event); | ||
(_a = this.comboBoxContext.value) == null ? void 0 : _a.listManager.handleMouseMove(event); | ||
}); | ||
this.addEventListener("mouseover", (event) => { | ||
var _a; | ||
(_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleMouseOver(event); | ||
(_a = this.comboBoxContext.value) == null ? void 0 : _a.listManager.handleMouseOver(event); | ||
}); | ||
this.addEventListener("mousedown", (event) => { | ||
var _a; | ||
(_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleMouseDown(event); | ||
(_a = this.comboBoxContext.value) == null ? void 0 : _a.listManager.handleMouseDown(event); | ||
}); | ||
this.addEventListener("click", (event) => { | ||
var _a; | ||
(_a = this.comboBoxContext) == null ? void 0 : _a.listManager.handleClick(event); | ||
(_a = this.comboBoxContext.value) == null ? void 0 : _a.listManager.handleClick(event); | ||
}); | ||
} | ||
}; | ||
__decorateClass([ | ||
consume({ context: comboBoxContext, subscribe: true }), | ||
state() | ||
], ComboBoxList.prototype, "comboBoxContext", 2); | ||
ComboBoxList = __decorateClass([ | ||
customElement("prosekit-combo-box-list") | ||
], ComboBoxList); | ||
defineCustomElement("prosekit-combo-box-list", ComboBoxList); | ||
export { | ||
@@ -49,0 +45,0 @@ ComboBoxList, |
import { | ||
Popover | ||
} from "./chunk-7WLKD2U6.js"; | ||
} from "./chunk-Z3PEQ6MW.js"; | ||
import { | ||
ListManager | ||
} from "./chunk-IDDQA3VV.js"; | ||
import "./chunk-55G7TJI3.js"; | ||
} from "./chunk-PW3MTUZM.js"; | ||
import "./chunk-L6FOAZFL.js"; | ||
import { | ||
@@ -12,8 +12,7 @@ comboBoxContext | ||
import { | ||
__decorateClass | ||
} from "./chunk-O5JP3B34.js"; | ||
defineCustomElement | ||
} from "./chunk-S32IZIQF.js"; | ||
// src/components/combo-box/index.ts | ||
import { provide } from "@lit/context"; | ||
import { customElement, property, state } from "lit/decorators.js"; | ||
import { ContextProvider } from "@lit/context"; | ||
@@ -50,6 +49,6 @@ // src/components/combo-box-item/helpers.ts | ||
var _a; | ||
return ((_a = this.context.selectedValue) != null ? _a : "").trim(); | ||
return ((_a = this.getContext().selectedValue) != null ? _a : "").trim(); | ||
}, | ||
setSelectedValue: (value) => { | ||
return this.context.setSelectedValue(value); | ||
setSelectedValue: (value, reason) => { | ||
return this.setSelectedValue(value, reason); | ||
}, | ||
@@ -65,46 +64,63 @@ getItemValue: (item) => { | ||
onDismiss: () => { | ||
var _a; | ||
(_a = this.onDismiss) == null ? void 0 : _a.call(this); | ||
this.hide(); | ||
}, | ||
onSelect: (item) => { | ||
var _a, _b; | ||
this.context.setSelectedValue(""); | ||
this.context.setInputValue(""); | ||
var _a; | ||
this.setSelectedValue("", "keyboard"); | ||
(_a = item == null ? void 0 : item.onSelect) == null ? void 0 : _a.call(item); | ||
(_b = this.onDismiss) == null ? void 0 : _b.call(this); | ||
this.hide(); | ||
} | ||
}); | ||
this.context = { | ||
inputValue: "", | ||
setInputValue: (inputValue) => { | ||
if (this.context.inputValue === inputValue) { | ||
return; | ||
} | ||
this.context = { ...this.context, inputValue }; | ||
}, | ||
selectedValue: "", | ||
setSelectedValue: (selectedValue) => { | ||
if (this.context.selectedValue === selectedValue) { | ||
return; | ||
} | ||
this.context = { ...this.context, selectedValue }; | ||
}, | ||
listManager: this.listManager | ||
}; | ||
this.context = new ContextProvider(this, { | ||
context: comboBoxContext, | ||
initialValue: { | ||
inputValue: "", | ||
setInputValue: (inputValue) => { | ||
this.setInputValue(inputValue); | ||
}, | ||
selectedValue: "", | ||
selectedReason: "keyboard", | ||
listManager: this.listManager | ||
} | ||
}); | ||
} | ||
/** | ||
* @hidden | ||
*/ | ||
hide() { | ||
var _a; | ||
super.hide(); | ||
this.setInputValue(""); | ||
(_a = this.onDismiss) == null ? void 0 : _a.call(this); | ||
} | ||
getContext() { | ||
return this.context.value; | ||
} | ||
setInputValue(inputValue) { | ||
const context = this.context.value; | ||
if (context.inputValue === inputValue) { | ||
return; | ||
} | ||
this.context.setValue({ ...context, inputValue }); | ||
} | ||
setSelectedValue(selectedValue, selectedReason) { | ||
const context = this.context.value; | ||
if (context.selectedValue === selectedValue) { | ||
return; | ||
} | ||
this.context.setValue({ ...context, selectedValue, selectedReason }); | ||
} | ||
get items() { | ||
const items = this.querySelectorAll("\u220Fprosekit-combo-box-item"); | ||
const items = this.querySelectorAll("prosekit-combo-box-item"); | ||
return Array.from(items).filter(isComboBoxItem); | ||
} | ||
}; | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], ComboBox.prototype, "onDismiss", 2); | ||
__decorateClass([ | ||
provide({ context: comboBoxContext }), | ||
state() | ||
], ComboBox.prototype, "context", 2); | ||
ComboBox = __decorateClass([ | ||
customElement("prosekit-combo-box") | ||
], ComboBox); | ||
/** | ||
* @hidden | ||
*/ | ||
ComboBox.properties = { | ||
...Popover.properties, | ||
onDismiss: { attribute: false } | ||
}; | ||
defineCustomElement("prosekit-combo-box", ComboBox); | ||
export { | ||
@@ -111,0 +127,0 @@ ComboBox, |
import { | ||
Popover | ||
} from "./chunk-7WLKD2U6.js"; | ||
} from "./chunk-Z3PEQ6MW.js"; | ||
import { | ||
__decorateClass | ||
} from "./chunk-O5JP3B34.js"; | ||
defineCustomElement | ||
} from "./chunk-S32IZIQF.js"; | ||
// src/components/inline-popover/index.ts | ||
import "@prosekit/core"; | ||
import { customElement, property } from "lit/decorators.js"; | ||
@@ -116,9 +115,13 @@ // src/components/inline-popover/controller.ts | ||
constructor() { | ||
super(); | ||
/** @hidden */ | ||
this.controller = new InlinePopoverController(this); | ||
super(...arguments); | ||
this.popoverOptions = defaultPopoverOptions; | ||
this.dismiss = "escape"; | ||
/** | ||
* @hidden | ||
*/ | ||
this.controller = new InlinePopoverController(this); | ||
} | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
willUpdate() { | ||
@@ -133,3 +136,5 @@ var _a, _b; | ||
} | ||
/** @hidden */ | ||
/** | ||
* @hidden | ||
*/ | ||
hide() { | ||
@@ -144,11 +149,11 @@ var _a; | ||
}; | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], InlinePopover.prototype, "editor", 2); | ||
__decorateClass([ | ||
property({ attribute: false }) | ||
], InlinePopover.prototype, "popoverOptions", 2); | ||
InlinePopover = __decorateClass([ | ||
customElement("prosekit-inline-popover") | ||
], InlinePopover); | ||
/** | ||
* @hidden | ||
*/ | ||
InlinePopover.properties = { | ||
...Popover.properties, | ||
editor: { attribute: false }, | ||
popoverOptions: { attribute: false } | ||
}; | ||
defineCustomElement("prosekit-inline-popover", InlinePopover); | ||
export { | ||
@@ -155,0 +160,0 @@ InlinePopover, |
import { | ||
Popover, | ||
propNames | ||
} from "./chunk-7WLKD2U6.js"; | ||
import "./chunk-O5JP3B34.js"; | ||
} from "./chunk-Z3PEQ6MW.js"; | ||
import "./chunk-S32IZIQF.js"; | ||
export { | ||
@@ -7,0 +7,0 @@ Popover, |
{ | ||
"name": "@prosekit/lit", | ||
"type": "module", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"private": false, | ||
@@ -98,7 +98,7 @@ "author": { | ||
"@prosekit/dev": "*", | ||
"minify-literals": "^1.0.7", | ||
"minify-literals": "^1.0.8", | ||
"tsup": "^8.0.1", | ||
"typescript": "^5.3.2", | ||
"vitest": "^0.34.6", | ||
"vue": "^3.3.9" | ||
"typescript": "^5.3.3", | ||
"vitest": "^1.0.2", | ||
"vue": "^3.3.11" | ||
}, | ||
@@ -105,0 +105,0 @@ "scripts": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
67406
8.91%2079
18.53%1
Infinity%