@prosekit/lit 0.0.22 → 0.0.24

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.
@@ -1,15 +1,12 @@
1
1
  import { AutoUpdateOptions } from '@floating-ui/dom';
2
- import { CommandArgs } from '@prosekit/core';
3
2
  import { ComputePositionConfig } from '@floating-ui/dom';
4
3
  import { CSSResult } from 'lit';
5
4
  import { Editor } from '@prosekit/core';
6
- import { Extension } from '@prosekit/core';
7
- import { ExtensionTyping } from '@prosekit/core';
5
+ import type { EditorView } from '@prosekit/pm/view';
8
6
  import { Keymap } from '@prosekit/core';
9
7
  import { LitElement } from 'lit';
10
8
  import { Options } from 'tsup';
11
9
  import { PropertyValues } from 'lit';
12
- import type { ProseMirrorNode } from '@prosekit/pm/model';
13
10
  import { ReactiveController } from 'lit';
14
11
  import { ReactiveControllerHost } from 'lit';
15
12
  import { TemplateResult } from 'lit';
@@ -142,28 +139,6 @@ export { AutoUpdateOptions }
142
139
 
143
140
  export declare const blockComponentStyles: CSSResult;
144
141
 
145
- export declare class CodeBlockPopover extends Popover implements Partial<CodeBlockPopoverProps> {
146
- editor?: Editor;
147
- /** @hidden */
148
- private controller;
149
- protected updated(): void;
150
- }
151
-
152
- export declare class CodeBlockPopoverController implements ReactiveController {
153
- private host;
154
- reference: Element | null;
155
- private editor;
156
- private cleanup;
157
- constructor(host: ReactiveControllerHost);
158
- setEditor(editor: Editor): void;
159
- private defineExtension;
160
- hostDisconnected(): void;
161
- }
162
-
163
- export declare interface CodeBlockPopoverProps {
164
- editor: Editor;
165
- }
166
-
167
142
  export declare class ComboBox extends Popover {
168
143
  onDismiss?: VoidFunction;
169
144
  private listManager;
@@ -255,22 +230,48 @@ export declare const default_alias_1: UserProjectConfigExport;
255
230
  */
256
231
  export declare const defaultPopoverOptions: PopoverOptions;
257
232
 
233
+ /**
234
+ * Default popover options.
235
+ */
258
236
  export declare const defaultPopoverOptions_alias_1: PopoverOptions;
259
237
 
238
+ export declare const defaultPopoverOptions_alias_2: PopoverOptions;
239
+
260
240
  export declare function defaultQueryBuilder(match: RegExpExecArray): string;
261
241
 
262
- /**
263
- * Returns a ProseKit extension that call `onSelect` when the text selection is
264
- * insert into a code block, and `onDismiss` when it is not.
265
- */
266
- export declare function defineCodeBlockSelect(options: {
267
- onSelect: (info: {
268
- pos: number;
269
- node: ProseMirrorNode;
270
- dom: HTMLElement;
271
- }) => void;
272
- onDismiss: () => void;
273
- }): Extension<ExtensionTyping<string, string, CommandArgs>>;
242
+ export declare function getVirtualSelectionElement(view: EditorView): Range | undefined;
243
+
244
+ export declare class InlinePopover extends Popover implements Partial<InlinePopoverProps> {
245
+ /** @hidden */
246
+ private controller;
247
+ editor?: Editor;
248
+ popoverOptions: PopoverOptions;
249
+ constructor();
250
+ /** @hidden */
251
+ willUpdate(): void;
252
+ /** @hidden */
253
+ hide(): void;
254
+ }
255
+
256
+ export declare class InlinePopoverController implements ReactiveController {
257
+ private host;
258
+ reference?: VirtualElement;
259
+ private editor?;
260
+ private cleanupExtension?;
261
+ private cleanupEventListener?;
262
+ private mouseHovering;
263
+ constructor(host: ReactiveControllerHost);
264
+ setEditor(editor: Editor): void;
265
+ hostConnected(): void;
266
+ hostDisconnected(): void;
267
+ private update;
268
+ private defineExtension;
269
+ }
270
+
271
+ export declare interface InlinePopoverProps {
272
+ editor: Editor;
273
+ popoverOptions?: PopoverOptions;
274
+ }
274
275
 
275
276
  export declare function isAutocompleteItem(element?: Element | null): element is AutocompleteItem;
276
277
 
@@ -361,6 +362,19 @@ export declare class Popover extends LightElement implements Partial<PopoverProp
361
362
  * the Floating UI documentation. This property is only used when the `autoUpdate` property is set to `true`.
362
363
  */
363
364
  autoUpdateOptions?: AutoUpdateOptions;
365
+ /**
366
+ * Controls whether the popover should be dismissed based on user interaction.
367
+ *
368
+ * Available options:
369
+ *
370
+ * - "off": The popover is not dismissed.
371
+ * - "on": The popover is dismissed when the user clicks outside of the popover or presses the escape key.
372
+ * - "click": The popover is dismissed when the user clicks outside of the popover.
373
+ * - "escape": The popover is dismissed when the user presses the escape key.
374
+ *
375
+ * @default "on"
376
+ */
377
+ dismiss: string;
364
378
  /** @hidden */
365
379
  private disposeAutoUpdate?;
366
380
  /** @hidden */
@@ -394,6 +408,7 @@ declare type PopoverOptions = ComputePositionConfig;
394
408
  export { PopoverOptions }
395
409
  export { PopoverOptions as PopoverOptions_alias_1 }
396
410
  export { PopoverOptions as PopoverOptions_alias_2 }
411
+ export { PopoverOptions as PopoverOptions_alias_3 }
397
412
 
398
413
  export declare interface PopoverProps {
399
414
  active: boolean;
@@ -414,22 +429,22 @@ export { propNames_3 as propNames_alias_3 }
414
429
  export { propNames_3 as propNames_alias_4 }
415
430
 
416
431
  declare const propNames_4: never[];
417
- export { propNames_4 as propNames_alias_10 }
432
+ export { propNames_4 as propNames_alias_8 }
418
433
  export { propNames_4 as propNames_alias_9 }
419
434
 
420
435
  declare const propNames_5: never[];
436
+ export { propNames_5 as propNames_alias_10 }
421
437
  export { propNames_5 as propNames_alias_11 }
422
- export { propNames_5 as propNames_alias_12 }
438
+
439
+ export declare const propNames_alias_12: readonly ["editor", "popoverOptions"];
423
440
 
424
441
  export declare const propNames_alias_13: readonly ["active", "reference", "options", "autoUpdate", "autoUpdateOptions"];
425
442
 
426
443
  export declare const propNames_alias_5: readonly ["editor", "regex", "popoverOptions"];
427
444
 
428
- export declare const propNames_alias_6: readonly ["editor"];
429
-
430
- export declare const propNames_alias_7: readonly ["onDismiss"];
445
+ export declare const propNames_alias_6: readonly ["onDismiss"];
431
446
 
432
- export declare const propNames_alias_8: readonly ["placeholder"];
447
+ export declare const propNames_alias_7: readonly ["placeholder"];
433
448
 
434
449
  export declare function queryClosestAutocompleteItem(element?: Element | null): AutocompleteItem | null;
435
450
 
@@ -17,7 +17,7 @@ function roundByDPR(value) {
17
17
  }
18
18
 
19
19
  // src/components/popover/default-popover-options.ts
20
- import { offset, shift } from "@floating-ui/dom";
20
+ import { offset, shift, size } from "@floating-ui/dom";
21
21
 
22
22
  // src/components/popover/options.ts
23
23
  import "@floating-ui/dom";
@@ -25,7 +25,23 @@ import "@floating-ui/dom";
25
25
  // src/components/popover/default-popover-options.ts
26
26
  var defaultPopoverOptions = {
27
27
  placement: "bottom",
28
- middleware: [offset(4), shift({ padding: 8 })]
28
+ middleware: [
29
+ offset({ mainAxis: 8, crossAxis: 8 }),
30
+ shift({ padding: 8 }),
31
+ size({
32
+ apply: ({ availableWidth, availableHeight, elements }) => {
33
+ elements.floating.style.setProperty(
34
+ "--prosekit-popover-available-width",
35
+ `${Math.floor(availableWidth)}px`
36
+ );
37
+ elements.floating.style.setProperty(
38
+ "--prosekit-popover-available-height",
39
+ `${Math.floor(availableHeight)}px`
40
+ );
41
+ },
42
+ padding: 8
43
+ })
44
+ ]
29
45
  };
30
46
 
31
47
  // src/components/popover/index.ts
@@ -42,6 +58,7 @@ var Popover = class extends LightElement {
42
58
  super();
43
59
  this.active = false;
44
60
  this.autoUpdate = false;
61
+ this.dismiss = "on";
45
62
  this.handleDocumentMouseDown = (event) => {
46
63
  const path = event.composedPath();
47
64
  if (!path.includes(this)) {
@@ -59,13 +76,15 @@ var Popover = class extends LightElement {
59
76
  /** @hidden */
60
77
  connectedCallback() {
61
78
  super.connectedCallback();
62
- const handleMouseDown = this.handleDocumentMouseDown.bind(this);
63
- const handleKeyDown = this.handleDocumentKeyDown.bind(this);
64
- document.addEventListener("mousedown", handleMouseDown);
65
- document.addEventListener("keydown", handleKeyDown);
79
+ const clickEnabled = this.dismiss === "on" || this.dismiss === "click";
80
+ const escapeEnabled = this.dismiss === "on" || this.dismiss === "escape";
81
+ const handleMouseDown = clickEnabled ? this.handleDocumentMouseDown.bind(this) : null;
82
+ const handleKeyDown = escapeEnabled ? this.handleDocumentKeyDown.bind(this) : null;
83
+ handleMouseDown && document.addEventListener("mousedown", handleMouseDown);
84
+ handleKeyDown && document.addEventListener("keydown", handleKeyDown);
66
85
  this.disposeEventListeners = () => {
67
- document.removeEventListener("mousedown", handleMouseDown);
68
- document.removeEventListener("keydown", handleKeyDown);
86
+ handleMouseDown && document.removeEventListener("mousedown", handleMouseDown);
87
+ handleKeyDown && document.removeEventListener("keydown", handleKeyDown);
69
88
  };
70
89
  }
71
90
  /** @hidden */
@@ -112,14 +131,18 @@ var Popover = class extends LightElement {
112
131
  if (!this.active)
113
132
  return;
114
133
  this.setHidden(false);
115
- this.style.position = (_b = (_a = this.options) == null ? void 0 : _a.strategy) != null ? _b : "absolute";
134
+ this.style.setProperty("top", "0");
135
+ this.style.setProperty("left", "0");
136
+ this.style.setProperty("position", (_b = (_a = this.options) == null ? void 0 : _a.strategy) != null ? _b : "absolute");
116
137
  const options = (_c = this.options) != null ? _c : defaultPopoverOptions;
117
138
  const computed = await computePosition(reference, this, options);
118
139
  const { x, y, strategy } = computed != null ? computed : { x: 0, y: 0, strategy: "absolute" };
119
- this.style.top = "0";
120
- this.style.left = "0";
121
- this.style.position = strategy;
122
- this.style.transform = `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`;
140
+ this.style.setProperty("opacity", "1");
141
+ this.style.setProperty("position", strategy);
142
+ this.style.setProperty(
143
+ "transform",
144
+ `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`
145
+ );
123
146
  }
124
147
  /** @hidden */
125
148
  hide() {
@@ -144,6 +167,12 @@ __decorateClass([
144
167
  __decorateClass([
145
168
  property({ type: Object })
146
169
  ], Popover.prototype, "autoUpdateOptions", 2);
170
+ __decorateClass([
171
+ property({
172
+ type: String,
173
+ reflect: true
174
+ })
175
+ ], Popover.prototype, "dismiss", 2);
147
176
  Popover = __decorateClass([
148
177
  customElement("prosekit-popover")
149
178
  ], Popover);
@@ -3,10 +3,10 @@ import {
3
3
  } from "./chunk-KJJEZNYD.js";
4
4
  import "./chunk-XOVIMVFL.js";
5
5
  import "./chunk-6P3YKUWI.js";
6
- import "./chunk-PCXKL6TA.js";
7
6
  import {
8
7
  Popover
9
- } from "./chunk-P336E72L.js";
8
+ } from "./chunk-HNKGDXIJ.js";
9
+ import "./chunk-PCXKL6TA.js";
10
10
  import {
11
11
  __decorateClass
12
12
  } from "./chunk-ZN7DMIEB.js";
@@ -123,24 +123,14 @@ var defaultDetectOverflowOptions = {
123
123
  var defaultPopoverOptions = {
124
124
  placement: "bottom-end",
125
125
  middleware: [
126
+ // Use the text caret as the reference point
127
+ inline(),
126
128
  offset(({ rects }) => ({
127
129
  // Put the popover at the bottom right corner
128
130
  alignmentAxis: -rects.floating.width,
129
131
  // Move down the popover by 4px
130
132
  mainAxis: 4
131
133
  })),
132
- size({
133
- apply: ({ availableHeight, elements }) => {
134
- const style = {
135
- // Minimum acceptable height is 100px.
136
- // `flip` will then take over.
137
- maxHeight: `${Math.max(100, availableHeight)}px`,
138
- overflowY: "auto"
139
- };
140
- Object.assign(elements.floating.style, style);
141
- },
142
- ...defaultDetectOverflowOptions
143
- }),
144
134
  // Flip the popover to the top if it's overflowing the viewport
145
135
  flip({
146
136
  fallbackStrategy: "initialPlacement",
@@ -148,11 +138,22 @@ var defaultPopoverOptions = {
148
138
  crossAxis: false,
149
139
  ...defaultDetectOverflowOptions
150
140
  }),
151
- shift({
141
+ size({
142
+ apply: ({ availableWidth, availableHeight, elements }) => {
143
+ elements.floating.style.setProperty(
144
+ "--prosekit-popover-available-width",
145
+ `${Math.floor(availableWidth)}px`
146
+ );
147
+ elements.floating.style.setProperty(
148
+ "--prosekit-popover-available-height",
149
+ `${Math.floor(availableHeight)}px`
150
+ );
151
+ },
152
152
  ...defaultDetectOverflowOptions
153
153
  }),
154
- // Use the text caret as the reference point
155
- inline()
154
+ shift({
155
+ ...defaultDetectOverflowOptions
156
+ })
156
157
  ]
157
158
  };
158
159
 
@@ -1,3 +1,3 @@
1
- export { propNames_alias_8 as propNames } from './_tsup-dts-rollup';
1
+ export { propNames_alias_7 as propNames } from './_tsup-dts-rollup';
2
2
  export { ComboBoxInputProps } from './_tsup-dts-rollup';
3
3
  export { ComboBoxInput } from './_tsup-dts-rollup';
@@ -1,3 +1,3 @@
1
1
  export { ComboBoxItem_alias_1 as ComboBoxItem } from './_tsup-dts-rollup';
2
2
  export { ComboBoxItemProps_alias_1 as ComboBoxItemProps } from './_tsup-dts-rollup';
3
- export { propNames_alias_10 as propNames } from './_tsup-dts-rollup';
3
+ export { propNames_alias_9 as propNames } from './_tsup-dts-rollup';
@@ -1,3 +1,3 @@
1
1
  export { ComboBoxList_alias_1 as ComboBoxList } from './_tsup-dts-rollup';
2
2
  export { ComboBoxListProps_alias_1 as ComboBoxListProps } from './_tsup-dts-rollup';
3
- export { propNames_alias_12 as propNames } from './_tsup-dts-rollup';
3
+ export { propNames_alias_11 as propNames } from './_tsup-dts-rollup';
@@ -1,3 +1,3 @@
1
- export { propNames_alias_7 as propNames } from './_tsup-dts-rollup';
1
+ export { propNames_alias_6 as propNames } from './_tsup-dts-rollup';
2
2
  export { ComboBoxProps } from './_tsup-dts-rollup';
3
3
  export { ComboBox } from './_tsup-dts-rollup';
@@ -1,10 +1,10 @@
1
- import "./chunk-XTIVRSSC.js";
1
+ import {
2
+ Popover
3
+ } from "./chunk-HNKGDXIJ.js";
2
4
  import {
3
5
  ListManager
4
6
  } from "./chunk-PCXKL6TA.js";
5
- import {
6
- Popover
7
- } from "./chunk-P336E72L.js";
7
+ import "./chunk-XTIVRSSC.js";
8
8
  import {
9
9
  comboBoxContext
10
10
  } from "./chunk-C4MW43I4.js";
@@ -0,0 +1,4 @@
1
+ export { PopoverOptions_alias_1 as PopoverOptions } from './_tsup-dts-rollup';
2
+ export { propNames_alias_12 as propNames } from './_tsup-dts-rollup';
3
+ export { InlinePopoverProps } from './_tsup-dts-rollup';
4
+ export { InlinePopover } from './_tsup-dts-rollup';
@@ -0,0 +1,155 @@
1
+ import {
2
+ Popover
3
+ } from "./chunk-HNKGDXIJ.js";
4
+ import {
5
+ __decorateClass
6
+ } from "./chunk-ZN7DMIEB.js";
7
+
8
+ // src/components/inline-popover/index.ts
9
+ import "@prosekit/core";
10
+ import { customElement, property } from "lit/decorators.js";
11
+
12
+ // src/components/inline-popover/controller.ts
13
+ import { defineUpdateHandler } from "@prosekit/core";
14
+ import "lit";
15
+
16
+ // src/components/inline-popover/helpers.ts
17
+ import { isTextSelection } from "@prosekit/core";
18
+ function getVirtualSelectionElement(view) {
19
+ if (typeof window === "undefined" || view.isDestroyed) {
20
+ return;
21
+ }
22
+ const selection = view.state.selection;
23
+ if (selection.empty && !isTextSelection(selection)) {
24
+ return;
25
+ }
26
+ return getDomRange();
27
+ }
28
+ function getDomRange() {
29
+ const selection = window.getSelection();
30
+ if (!selection || selection.isCollapsed) {
31
+ return;
32
+ }
33
+ const range = typeof selection.rangeCount === "number" && selection.rangeCount > 0 && selection.getRangeAt(0);
34
+ if (!range) {
35
+ return;
36
+ }
37
+ return range;
38
+ }
39
+
40
+ // src/components/inline-popover/controller.ts
41
+ var InlinePopoverController = class {
42
+ constructor(host) {
43
+ this.host = host;
44
+ this.mouseHovering = false;
45
+ this.host.addController(this);
46
+ }
47
+ setEditor(editor) {
48
+ if (this.editor !== editor) {
49
+ this.editor = editor;
50
+ this.defineExtension();
51
+ this.host.requestUpdate();
52
+ }
53
+ }
54
+ hostConnected() {
55
+ var _a;
56
+ const handleMouseDown = () => {
57
+ this.mouseHovering = true;
58
+ };
59
+ const handleMouseUp = () => {
60
+ this.mouseHovering = false;
61
+ this.update();
62
+ };
63
+ document.addEventListener("mousedown", handleMouseDown);
64
+ document.addEventListener("mouseup", handleMouseUp);
65
+ (_a = this.cleanupEventListener) == null ? void 0 : _a.call(this);
66
+ this.cleanupEventListener = () => {
67
+ document.removeEventListener("mousedown", handleMouseDown);
68
+ document.removeEventListener("mouseup", handleMouseUp);
69
+ };
70
+ }
71
+ hostDisconnected() {
72
+ var _a, _b;
73
+ (_a = this.cleanupExtension) == null ? void 0 : _a.call(this);
74
+ this.cleanupExtension = void 0;
75
+ (_b = this.cleanupEventListener) == null ? void 0 : _b.call(this);
76
+ this.cleanupEventListener = void 0;
77
+ }
78
+ update() {
79
+ const editor = this.editor;
80
+ if (!editor || this.mouseHovering) {
81
+ return;
82
+ }
83
+ const reference = getVirtualSelectionElement(editor.view);
84
+ if (this.reference !== reference) {
85
+ this.reference = reference;
86
+ this.host.requestUpdate();
87
+ }
88
+ }
89
+ defineExtension() {
90
+ var _a;
91
+ const editor = this.editor;
92
+ if (!editor) {
93
+ return;
94
+ }
95
+ const extension = defineUpdateHandler(() => this.update());
96
+ (_a = this.cleanupExtension) == null ? void 0 : _a.call(this);
97
+ this.cleanupExtension = editor.use(extension);
98
+ }
99
+ };
100
+
101
+ // src/components/inline-popover/default-popover-options.ts
102
+ import { inline, offset, shift } from "@floating-ui/dom";
103
+ var defaultPopoverOptions = {
104
+ placement: "top",
105
+ strategy: "absolute",
106
+ middleware: [
107
+ inline(),
108
+ offset(8),
109
+ shift({ mainAxis: true, crossAxis: true, padding: 8 })
110
+ ]
111
+ };
112
+
113
+ // src/components/inline-popover/index.ts
114
+ var propNames = ["editor", "popoverOptions"];
115
+ var InlinePopover = class extends Popover {
116
+ constructor() {
117
+ super();
118
+ /** @hidden */
119
+ this.controller = new InlinePopoverController(this);
120
+ this.popoverOptions = defaultPopoverOptions;
121
+ this.dismiss = "escape";
122
+ }
123
+ /** @hidden */
124
+ willUpdate() {
125
+ var _a, _b;
126
+ if (this.editor) {
127
+ this.controller.setEditor(this.editor);
128
+ }
129
+ this.active = !!((_a = this.controller) == null ? void 0 : _a.reference);
130
+ this.reference = (_b = this.controller.reference) != null ? _b : void 0;
131
+ this.options = this.popoverOptions;
132
+ }
133
+ /** @hidden */
134
+ hide() {
135
+ var _a;
136
+ super.hide();
137
+ if ((_a = this.controller) == null ? void 0 : _a.reference) {
138
+ this.controller.reference = void 0;
139
+ this.reference = void 0;
140
+ }
141
+ }
142
+ };
143
+ __decorateClass([
144
+ property({ attribute: false })
145
+ ], InlinePopover.prototype, "editor", 2);
146
+ __decorateClass([
147
+ property({ attribute: false })
148
+ ], InlinePopover.prototype, "popoverOptions", 2);
149
+ InlinePopover = __decorateClass([
150
+ customElement("prosekit-inline-popover")
151
+ ], InlinePopover);
152
+ export {
153
+ InlinePopover,
154
+ propNames
155
+ };
@@ -1,5 +1,5 @@
1
1
  export { AutoUpdateOptions } from './_tsup-dts-rollup';
2
- export { PopoverOptions_alias_1 as PopoverOptions } from './_tsup-dts-rollup';
2
+ export { PopoverOptions_alias_2 as PopoverOptions } from './_tsup-dts-rollup';
3
3
  export { propNames_alias_13 as propNames } from './_tsup-dts-rollup';
4
4
  export { PopoverProps } from './_tsup-dts-rollup';
5
5
  export { Popover } from './_tsup-dts-rollup';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  Popover,
3
3
  propNames
4
- } from "./chunk-P336E72L.js";
4
+ } from "./chunk-HNKGDXIJ.js";
5
5
  import "./chunk-ZN7DMIEB.js";
6
6
  export {
7
7
  Popover,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prosekit/lit",
3
3
  "type": "module",
4
- "version": "0.0.22",
4
+ "version": "0.0.24",
5
5
  "private": false,
6
6
  "author": {
7
7
  "name": "ocavue",
@@ -50,11 +50,6 @@
50
50
  "import": "./dist/prosekit-lit-autocomplete-popover.js",
51
51
  "default": "./dist/prosekit-lit-autocomplete-popover.js"
52
52
  },
53
- "./code-block-popover": {
54
- "types": "./dist/prosekit-lit-code-block-popover.d.ts",
55
- "import": "./dist/prosekit-lit-code-block-popover.js",
56
- "default": "./dist/prosekit-lit-code-block-popover.js"
57
- },
58
53
  "./combo-box": {
59
54
  "types": "./dist/prosekit-lit-combo-box.d.ts",
60
55
  "import": "./dist/prosekit-lit-combo-box.js",
@@ -75,6 +70,11 @@
75
70
  "import": "./dist/prosekit-lit-combo-box-list.js",
76
71
  "default": "./dist/prosekit-lit-combo-box-list.js"
77
72
  },
73
+ "./inline-popover": {
74
+ "types": "./dist/prosekit-lit-inline-popover.d.ts",
75
+ "import": "./dist/prosekit-lit-inline-popover.js",
76
+ "default": "./dist/prosekit-lit-inline-popover.js"
77
+ },
78
78
  "./popover": {
79
79
  "types": "./dist/prosekit-lit-popover.d.ts",
80
80
  "import": "./dist/prosekit-lit-popover.js",
@@ -87,8 +87,8 @@
87
87
  "dependencies": {
88
88
  "@floating-ui/dom": "^1.5.3",
89
89
  "@lit/context": "^1.0.1",
90
- "@prosekit/core": "^0.0.18",
91
- "@prosekit/extensions": "^0.0.20",
90
+ "@prosekit/core": "^0.0.20",
91
+ "@prosekit/extensions": "^0.0.22",
92
92
  "@prosekit/pm": "^0.0.7",
93
93
  "@superhuman/command-score": "^0.5.0",
94
94
  "lit": "^3.0.2"
@@ -99,7 +99,7 @@
99
99
  "tsup": "^7.2.0",
100
100
  "typescript": "^5.2.2",
101
101
  "vitest": "^0.34.6",
102
- "vue": "^3.3.7"
102
+ "vue": "^3.3.8"
103
103
  },
104
104
  "scripts": {
105
105
  "build:tsup": "tsup",
@@ -123,9 +123,6 @@
123
123
  "autocomplete-popover": [
124
124
  "./dist/prosekit-lit-autocomplete-popover.d.ts"
125
125
  ],
126
- "code-block-popover": [
127
- "./dist/prosekit-lit-code-block-popover.d.ts"
128
- ],
129
126
  "combo-box": [
130
127
  "./dist/prosekit-lit-combo-box.d.ts"
131
128
  ],
@@ -138,6 +135,9 @@
138
135
  "combo-box-list": [
139
136
  "./dist/prosekit-lit-combo-box-list.d.ts"
140
137
  ],
138
+ "inline-popover": [
139
+ "./dist/prosekit-lit-inline-popover.d.ts"
140
+ ],
141
141
  "popover": [
142
142
  "./dist/prosekit-lit-popover.d.ts"
143
143
  ]
@@ -1,3 +0,0 @@
1
- export { propNames_alias_6 as propNames } from './_tsup-dts-rollup';
2
- export { CodeBlockPopoverProps } from './_tsup-dts-rollup';
3
- export { CodeBlockPopover } from './_tsup-dts-rollup';
@@ -1,140 +0,0 @@
1
- import {
2
- Popover
3
- } from "./chunk-P336E72L.js";
4
- import {
5
- __decorateClass
6
- } from "./chunk-ZN7DMIEB.js";
7
-
8
- // src/components/code-block-popover/index.ts
9
- import { offset } from "@floating-ui/dom";
10
- import { customElement, property } from "lit/decorators.js";
11
-
12
- // src/components/code-block-popover/controller.ts
13
- import "@prosekit/core";
14
- import "lit";
15
-
16
- // src/components/code-block-popover/code-block-select.ts
17
- import { definePlugin } from "@prosekit/core";
18
- import { ProseMirrorPlugin } from "@prosekit/pm/state";
19
- function defineCodeBlockSelect(options) {
20
- let prevState = null;
21
- const plugin = new ProseMirrorPlugin({
22
- view: () => {
23
- return {
24
- update: (view) => {
25
- const currState = getState(view);
26
- if ((prevState == null ? void 0 : prevState.pos) !== (currState == null ? void 0 : currState.pos) || (prevState == null ? void 0 : prevState.dom) !== (currState == null ? void 0 : currState.dom)) {
27
- if (currState) {
28
- options.onSelect(currState);
29
- } else {
30
- options.onDismiss();
31
- }
32
- }
33
- prevState = currState;
34
- }
35
- };
36
- }
37
- });
38
- return definePlugin(plugin);
39
- }
40
- function getState(view) {
41
- const { $from, $to } = view.state.selection;
42
- if ($from.sameParent($to)) {
43
- const node = $from.parent;
44
- if (isCodeBlock(node)) {
45
- const pos = $from.before();
46
- const dom = view.nodeDOM(pos);
47
- if (dom) {
48
- return { pos, node, dom };
49
- }
50
- }
51
- }
52
- return null;
53
- }
54
- function isCodeBlock(node) {
55
- return node.type.spec.code && node.isTextblock;
56
- }
57
-
58
- // src/components/code-block-popover/controller.ts
59
- var CodeBlockPopoverController = class {
60
- constructor(host) {
61
- this.host = host;
62
- this.reference = null;
63
- this.editor = null;
64
- this.cleanup = null;
65
- this.host.addController(this);
66
- }
67
- setEditor(editor) {
68
- if (this.editor !== editor) {
69
- this.editor = editor;
70
- this.defineExtension();
71
- this.host.requestUpdate();
72
- }
73
- }
74
- defineExtension() {
75
- var _a;
76
- const editor = this.editor;
77
- if (!editor)
78
- return;
79
- const extension = defineCodeBlockSelect({
80
- onSelect: ({ dom }) => {
81
- if (this.reference !== dom) {
82
- this.reference = dom;
83
- this.host.requestUpdate();
84
- }
85
- },
86
- onDismiss: () => {
87
- if (this.reference !== null) {
88
- this.reference = null;
89
- this.host.requestUpdate();
90
- }
91
- }
92
- });
93
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
94
- this.cleanup = editor.use(extension);
95
- }
96
- hostDisconnected() {
97
- var _a;
98
- (_a = this.cleanup) == null ? void 0 : _a.call(this);
99
- this.cleanup = null;
100
- }
101
- };
102
-
103
- // src/components/code-block-popover/index.ts
104
- var propNames = ["editor"];
105
- var CodeBlockPopover = class extends Popover {
106
- constructor() {
107
- super(...arguments);
108
- /** @hidden */
109
- this.controller = new CodeBlockPopoverController(this);
110
- }
111
- updated() {
112
- var _a, _b;
113
- if (this.editor) {
114
- this.controller.setEditor(this.editor);
115
- }
116
- this.reference = (_b = (_a = this.controller) == null ? void 0 : _a.reference) != null ? _b : void 0;
117
- this.active = !!this.reference;
118
- this.options = popoverOptions;
119
- super.updated();
120
- }
121
- };
122
- __decorateClass([
123
- property({ attribute: false, type: Object })
124
- ], CodeBlockPopover.prototype, "editor", 2);
125
- CodeBlockPopover = __decorateClass([
126
- customElement("prosekit-code-block-popover")
127
- ], CodeBlockPopover);
128
- var popoverOptions = {
129
- placement: "top-start",
130
- strategy: "absolute",
131
- middleware: [
132
- offset((options) => {
133
- return -options.rects.floating.height;
134
- })
135
- ]
136
- };
137
- export {
138
- CodeBlockPopover,
139
- propNames
140
- };