@prosekit/lit 0.0.0-next-20230627094841 → 0.0.1

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,211 +0,0 @@
1
- import {
2
- popoverSuggestionContext
3
- } from "./chunk-TFM6CTEO.js";
4
- import "./chunk-VYMBIH4T.js";
5
- import {
6
- blockComponentStyles
7
- } from "./chunk-XEV4EE3R.js";
8
- import {
9
- __decorateClass
10
- } from "./chunk-S65R2BUY.js";
11
-
12
- // src/elements/popover-slash.ts
13
- import { html } from "lit";
14
- import { customElement } from "lit/decorators.js";
15
-
16
- // src/elements/popover-abs.ts
17
- import { provide } from "@lit-labs/context";
18
- import { LitElement } from "lit";
19
- import { property, state } from "lit/decorators.js";
20
-
21
- // src/controllers/suggestion-controller.ts
22
- import { ProseKitError } from "@prosekit/core";
23
- import { addSuggestion } from "@prosekit/extension-suggestion";
24
- var SuggestionController = class {
25
- constructor(host, editor, rules, onContext) {
26
- this.host = host;
27
- this.editor = editor;
28
- this.rules = rules;
29
- this.onContext = onContext;
30
- this.connected = false;
31
- this.reference = null;
32
- this.removeExtension = null;
33
- if (!editor) {
34
- throw new ProseKitError("Missing 'editor' property");
35
- }
36
- if (!rules) {
37
- throw new ProseKitError("Missing 'rules' property");
38
- }
39
- this.host.addController(this);
40
- }
41
- hostUpdated() {
42
- var _a;
43
- if (this.connected)
44
- return;
45
- this.connected = true;
46
- const editor = this.editor;
47
- if (!editor) {
48
- throw new ProseKitError("Missing 'editor' property");
49
- }
50
- if (!this.rules) {
51
- throw new ProseKitError("Missing 'rules' property");
52
- }
53
- const extension = addSuggestion({
54
- rules: this.rules,
55
- onMatch: ({ dismiss, deleteMatch, match, matchAfter }) => {
56
- var _a2, _b;
57
- const span = editor.view.dom.querySelector(
58
- ".prosemirror-prediction-match"
59
- );
60
- if (span) {
61
- this.reference = span;
62
- }
63
- const matchText = match[0] + ((_a2 = matchAfter == null ? void 0 : matchAfter[0]) != null ? _a2 : "");
64
- (_b = this.onContext) == null ? void 0 : _b.call(this, {
65
- active: true,
66
- query: matchText,
67
- onDismiss: () => {
68
- dismiss();
69
- },
70
- onSubmit: () => {
71
- deleteMatch();
72
- }
73
- });
74
- },
75
- onDeactivate: () => {
76
- var _a2;
77
- this.reference = null;
78
- (_a2 = this.onContext) == null ? void 0 : _a2.call(this, {
79
- active: false
80
- });
81
- }
82
- });
83
- (_a = this.removeExtension) == null ? void 0 : _a.call(this);
84
- this.removeExtension = editor.use(extension);
85
- }
86
- hostDisconnected() {
87
- var _a;
88
- this.connected = false;
89
- (_a = this.removeExtension) == null ? void 0 : _a.call(this);
90
- this.removeExtension = null;
91
- }
92
- };
93
-
94
- // src/elements/popover-abs.ts
95
- import { flip, inline, offset, shift, size } from "@floating-ui/dom";
96
- var defaultDetectOverflowOptions = {
97
- // Make sure the popover is always at least 8px away from the boundary
98
- padding: 8
99
- // boundary: document.body,
100
- };
101
- var defaultPopoverOptions = {
102
- placement: "bottom-end",
103
- middleware: [
104
- offset(({ rects }) => ({
105
- // Put the popover at the bottom right corner
106
- alignmentAxis: -rects.floating.width,
107
- // Move down the popover by 4px
108
- mainAxis: 4
109
- })),
110
- size({
111
- apply: ({ availableHeight, elements }) => {
112
- const style = {
113
- // Minimum acceptable height is 100px.
114
- // `flip` will then take over.
115
- maxHeight: `${Math.max(100, availableHeight)}px`,
116
- overflowY: "auto"
117
- };
118
- Object.assign(elements.floating.style, style);
119
- },
120
- ...defaultDetectOverflowOptions
121
- }),
122
- // Flip the popover to the top if it's overflowing the viewport
123
- flip({
124
- fallbackStrategy: "initialPlacement",
125
- fallbackAxisSideDirection: "start",
126
- crossAxis: false,
127
- ...defaultDetectOverflowOptions
128
- }),
129
- shift({
130
- ...defaultDetectOverflowOptions
131
- }),
132
- // Use the text caret as the reference point
133
- inline()
134
- ]
135
- };
136
- var PopoverAbstract = class extends LitElement {
137
- /** @hidden */
138
- constructor() {
139
- super();
140
- this.popoverOptions = defaultPopoverOptions;
141
- this.context = { active: false };
142
- }
143
- /** @hidden */
144
- firstUpdated() {
145
- setTimeout(() => {
146
- this.controller = new SuggestionController(
147
- this,
148
- this.editor,
149
- this.rules,
150
- (context) => {
151
- var _a;
152
- (_a = this.onContext) == null ? void 0 : _a.call(this, context);
153
- this.context = context;
154
- }
155
- );
156
- });
157
- }
158
- /** @hidden */
159
- get active() {
160
- var _a;
161
- return !!((_a = this.controller) == null ? void 0 : _a.reference);
162
- }
163
- };
164
- /** @hidden */
165
- PopoverAbstract.styles = blockComponentStyles;
166
- __decorateClass([
167
- property({ attribute: false })
168
- ], PopoverAbstract.prototype, "editor", 2);
169
- __decorateClass([
170
- property({ attribute: false })
171
- ], PopoverAbstract.prototype, "popoverOptions", 2);
172
- __decorateClass([
173
- provide({ context: popoverSuggestionContext }),
174
- state()
175
- ], PopoverAbstract.prototype, "context", 2);
176
- __decorateClass([
177
- property({ attribute: false })
178
- ], PopoverAbstract.prototype, "onContext", 2);
179
- __decorateClass([
180
- state()
181
- ], PopoverAbstract.prototype, "controller", 2);
182
-
183
- // src/elements/popover-slash.ts
184
- var PopoverSlash = class extends PopoverAbstract {
185
- constructor() {
186
- super(...arguments);
187
- this.rules = [
188
- {
189
- match: /\/.*$/iu,
190
- matchAfter: /^\S*/
191
- }
192
- ];
193
- }
194
- /** @hidden */
195
- render() {
196
- var _a, _b;
197
- return html`<prosekit-popover .active="${this.active}" .reference="${(_b = (_a = this.controller) == null ? void 0 : _a.reference) != null ? _b : void 0}" .options="${this.popoverOptions}"><slot @menu-dismiss="${() => {
198
- var _a2, _b2;
199
- return (_b2 = (_a2 = this.context) == null ? void 0 : _a2.onDismiss) == null ? void 0 : _b2.call(_a2);
200
- }}" @menu-select="${() => {
201
- var _a2, _b2;
202
- return (_b2 = (_a2 = this.context) == null ? void 0 : _a2.onSubmit) == null ? void 0 : _b2.call(_a2);
203
- }}"></slot></prosekit-popover>`;
204
- }
205
- };
206
- PopoverSlash = __decorateClass([
207
- customElement("prosekit-popover-slash")
208
- ], PopoverSlash);
209
- export {
210
- PopoverSlash
211
- };
@@ -1,36 +0,0 @@
1
- import {
2
- popoverSuggestionContext
3
- } from "./chunk-TFM6CTEO.js";
4
- import "./chunk-VYMBIH4T.js";
5
- import "./chunk-XEV4EE3R.js";
6
- import {
7
- __decorateClass
8
- } from "./chunk-S65R2BUY.js";
9
-
10
- // src/elements/popover-suggestion-consumer.ts
11
- import { consume } from "@lit-labs/context";
12
- import { LitElement, html } from "lit";
13
- import { customElement, property } from "lit/decorators.js";
14
- var PopoverSuggestionConsumer = class extends LitElement {
15
- updated() {
16
- var _a;
17
- if (this.contextA) {
18
- (_a = this.onContext) == null ? void 0 : _a.call(this, this.contextA);
19
- }
20
- }
21
- render() {
22
- return html`<slot></slot>`;
23
- }
24
- };
25
- __decorateClass([
26
- consume({ context: popoverSuggestionContext, subscribe: true })
27
- ], PopoverSuggestionConsumer.prototype, "contextA", 2);
28
- __decorateClass([
29
- property({ attribute: false })
30
- ], PopoverSuggestionConsumer.prototype, "onContext", 2);
31
- PopoverSuggestionConsumer = __decorateClass([
32
- customElement("prosekit-popover-suggestion-consumer")
33
- ], PopoverSuggestionConsumer);
34
- export {
35
- PopoverSuggestionConsumer
36
- };
@@ -1,119 +0,0 @@
1
- import {
2
- blockComponentStyles
3
- } from "./chunk-XEV4EE3R.js";
4
- import {
5
- __decorateClass
6
- } from "./chunk-S65R2BUY.js";
7
-
8
- // src/elements/popover2.ts
9
- import {
10
- autoUpdate,
11
- computePosition
12
- } from "@floating-ui/dom";
13
- import { LitElement, html } from "lit";
14
- import { customElement, property, query, state } from "lit/decorators.js";
15
- import { styleMap } from "lit/directives/style-map.js";
16
- var Popover2 = class extends LitElement {
17
- /** @hidden */
18
- constructor() {
19
- super();
20
- this.active = false;
21
- this.autoUpdate = false;
22
- }
23
- /** @hidden */
24
- disconnectedCallback() {
25
- this.cleanup();
26
- }
27
- /** @hidden */
28
- updated(changed) {
29
- if (!changed.has("computed")) {
30
- this.start();
31
- }
32
- }
33
- /** @hidden */
34
- start() {
35
- this.cleanup();
36
- const reference = this.reference;
37
- const floating = this.floating;
38
- if (!reference)
39
- return;
40
- if (this.autoUpdate) {
41
- this.cleanupAutoUpdate = autoUpdate(
42
- reference,
43
- floating,
44
- () => void this.compute(),
45
- this.autoUpdateOptions
46
- );
47
- } else {
48
- void this.compute();
49
- }
50
- }
51
- /** @hidden */
52
- async compute() {
53
- const reference = this.reference;
54
- const floating = this.floating;
55
- if (!reference)
56
- return;
57
- const options = this.options;
58
- this.computed = await computePosition(reference, floating, options);
59
- }
60
- /** @hidden */
61
- cleanup() {
62
- var _a;
63
- (_a = this.cleanupAutoUpdate) == null ? void 0 : _a.call(this);
64
- this.cleanupAutoUpdate = void 0;
65
- }
66
- /** @hidden */
67
- render() {
68
- var _a;
69
- const { x, y, strategy } = (_a = this.computed) != null ? _a : {
70
- x: 0,
71
- y: 0,
72
- strategy: "absolute"
73
- };
74
- const style = {
75
- top: "0",
76
- left: "0",
77
- position: strategy,
78
- transform: `translate(${roundByDPR(x)}px,${roundByDPR(y)}px)`,
79
- display: this.active ? void 0 : "none"
80
- };
81
- return html`<div class="floating" style="${styleMap(style)}"><slot></slot></div>`;
82
- }
83
- };
84
- /** @hidden */
85
- Popover2.styles = blockComponentStyles;
86
- __decorateClass([
87
- property({ type: Boolean, reflect: true })
88
- ], Popover2.prototype, "active", 2);
89
- __decorateClass([
90
- query(".floating")
91
- ], Popover2.prototype, "floating", 2);
92
- __decorateClass([
93
- property()
94
- ], Popover2.prototype, "reference", 2);
95
- __decorateClass([
96
- property()
97
- ], Popover2.prototype, "options", 2);
98
- __decorateClass([
99
- property({
100
- type: Boolean,
101
- reflect: true
102
- })
103
- ], Popover2.prototype, "autoUpdate", 2);
104
- __decorateClass([
105
- property({ type: Object })
106
- ], Popover2.prototype, "autoUpdateOptions", 2);
107
- __decorateClass([
108
- state()
109
- ], Popover2.prototype, "computed", 2);
110
- Popover2 = __decorateClass([
111
- customElement("prosekit-popover2")
112
- ], Popover2);
113
- function roundByDPR(value) {
114
- const dpr = window.devicePixelRatio || 1;
115
- return Math.round(value * dpr) / dpr;
116
- }
117
- export {
118
- Popover2
119
- };
@@ -1,213 +0,0 @@
1
- import {
2
- createVisibilityFilter
3
- } from "./chunk-6EHMW3VI.js";
4
- import "./chunk-WUZ77NLF.js";
5
- import {
6
- __decorateClass,
7
- blockComponentStyles
8
- } from "./chunk-43BFWKM2.js";
9
-
10
- // src/elements/slash-popover/slash-popover.ts
11
- import { LitElement as LitElement2, html as html2 } from "lit";
12
- import { customElement as customElement2, property as property2 } from "lit/decorators.js";
13
-
14
- // src/elements/picker/picker.ts
15
- import {
16
- flip,
17
- inline,
18
- offset,
19
- shift,
20
- size
21
- } from "@floating-ui/dom";
22
- import { ProseKitError } from "@prosekit/core";
23
- import { addSuggestion } from "@prosekit/extension-suggestion";
24
- import { LitElement, html } from "lit";
25
- import { customElement, property, query, state } from "lit/decorators.js";
26
-
27
- // src/elements/menu/is-menu.ts
28
- function isMenu(element) {
29
- var _a, _b;
30
- return ((_a = element == null ? void 0 : element.tagName) == null ? void 0 : _a.toLowerCase()) === "prosekit-menu" || ["menu"].includes((_b = element == null ? void 0 : element.getAttribute("role")) != null ? _b : "");
31
- }
32
-
33
- // src/elements/picker/picker.ts
34
- var Picker = class extends LitElement {
35
- constructor() {
36
- super(...arguments);
37
- this.popoverOptions = defaultPopoverOptions;
38
- }
39
- render() {
40
- return html`<prosekit-popover .active="${this.active}" .reference="${this.reference}" .options="${this.popoverOptions}"><slot @menu-dismiss="${() => {
41
- var _a;
42
- return (_a = this.handleDismiss) == null ? void 0 : _a.call(this);
43
- }}" @menu-select="${() => {
44
- var _a;
45
- return (_a = this.handleSubmit) == null ? void 0 : _a.call(this);
46
- }}"></slot></prosekit-popover>`;
47
- }
48
- firstUpdated(_changedProperties) {
49
- setTimeout(() => {
50
- const editor = this.editor;
51
- if (!editor) {
52
- throw new ProseKitError("Missing 'editor' property");
53
- }
54
- if (!this.rules) {
55
- throw new ProseKitError("Missing 'rules' property");
56
- }
57
- const extension = addSuggestion({
58
- rules: this.rules,
59
- onMatch: ({ dismiss, deleteMatch, match, matchAfter }) => {
60
- var _a;
61
- if (!this.editor)
62
- return;
63
- const editor2 = this.editor;
64
- const span = editor2.view.dom.querySelector(
65
- ".prosemirror-prediction-match"
66
- );
67
- if (span) {
68
- this.reference = span;
69
- }
70
- const matchText = match[0] + ((_a = matchAfter == null ? void 0 : matchAfter[0]) != null ? _a : "");
71
- const menu = this.queryMenu();
72
- if (menu)
73
- menu.query = matchText;
74
- this.handleDismiss = () => {
75
- dismiss();
76
- };
77
- this.handleSubmit = () => {
78
- deleteMatch();
79
- };
80
- },
81
- onDeactivate: () => {
82
- this.reference = void 0;
83
- }
84
- });
85
- this.removeExtension = editor.use(extension);
86
- }, 0);
87
- }
88
- disconnectedCallback() {
89
- super.disconnectedCallback();
90
- this.reference = void 0;
91
- if (this.removeExtension) {
92
- this.removeExtension();
93
- this.removeExtension = void 0;
94
- }
95
- }
96
- updated() {
97
- const menu = this.queryMenu();
98
- if (menu) {
99
- menu.active = this.active;
100
- }
101
- }
102
- get active() {
103
- return !!this.reference;
104
- }
105
- queryMenu({
106
- visible = null
107
- } = {}) {
108
- var _a, _b, _c, _d;
109
- const menus = (_c = (_b = (_a = this.defaultSlot) == null ? void 0 : _a.assignedElements({ flatten: true })) == null ? void 0 : _b.filter(isMenu)) == null ? void 0 : _c.filter(createVisibilityFilter(visible));
110
- return (_d = menus == null ? void 0 : menus[0]) != null ? _d : null;
111
- }
112
- };
113
- Picker.styles = blockComponentStyles;
114
- __decorateClass([
115
- property()
116
- ], Picker.prototype, "editor", 2);
117
- __decorateClass([
118
- property()
119
- ], Picker.prototype, "rules", 2);
120
- __decorateClass([
121
- property({ type: Object })
122
- ], Picker.prototype, "popoverOptions", 2);
123
- __decorateClass([
124
- state()
125
- ], Picker.prototype, "reference", 2);
126
- __decorateClass([
127
- state()
128
- ], Picker.prototype, "removeExtension", 2);
129
- __decorateClass([
130
- state()
131
- ], Picker.prototype, "handleDismiss", 2);
132
- __decorateClass([
133
- state()
134
- ], Picker.prototype, "handleSubmit", 2);
135
- __decorateClass([
136
- query("slot")
137
- ], Picker.prototype, "defaultSlot", 2);
138
- __decorateClass([
139
- query("popover")
140
- ], Picker.prototype, "popover", 2);
141
- Picker = __decorateClass([
142
- customElement("prosekit-picker")
143
- ], Picker);
144
- var defaultDetectOverflowOptions = {
145
- // Make sure the popover is always at least 8px away from the boundary
146
- padding: 8
147
- // boundary: document.body,
148
- };
149
- var defaultPopoverOptions = {
150
- placement: "bottom-end",
151
- middleware: [
152
- offset(({ rects }) => ({
153
- // Put the popover at the bottom right corner
154
- alignmentAxis: -rects.floating.width,
155
- // Move down the popover by 4px
156
- mainAxis: 4
157
- })),
158
- size({
159
- apply: ({ availableHeight, elements }) => {
160
- const style = {
161
- // Minimum acceptable height is 100px.
162
- // `flip` will then take over.
163
- maxHeight: `${Math.max(100, availableHeight)}px`,
164
- overflowY: "auto"
165
- };
166
- Object.assign(elements.floating.style, style);
167
- },
168
- ...defaultDetectOverflowOptions
169
- }),
170
- // Flip the popover to the top if it's overflowing the viewport
171
- flip({
172
- fallbackStrategy: "initialPlacement",
173
- fallbackAxisSideDirection: "start",
174
- crossAxis: false,
175
- ...defaultDetectOverflowOptions
176
- }),
177
- shift({
178
- ...defaultDetectOverflowOptions
179
- }),
180
- // Use the text caret as the reference point
181
- inline()
182
- ]
183
- };
184
-
185
- // src/elements/slash-popover/slash-popover.ts
186
- var SlashPopover = class extends LitElement2 {
187
- constructor() {
188
- super(...arguments);
189
- this.popoverOptions = defaultPopoverOptions;
190
- }
191
- render() {
192
- const rules = [
193
- {
194
- match: /\/.*$/iu,
195
- matchAfter: /^\S*/
196
- }
197
- ];
198
- return html2`<prosekit-picker .popoverOptions="${this.popoverOptions}" .editor="${this.editor}" .rules="${rules}"><slot></slot></prosekit-picker>`;
199
- }
200
- };
201
- SlashPopover.styles = blockComponentStyles;
202
- __decorateClass([
203
- property2()
204
- ], SlashPopover.prototype, "editor", 2);
205
- __decorateClass([
206
- property2({ type: Object })
207
- ], SlashPopover.prototype, "popoverOptions", 2);
208
- SlashPopover = __decorateClass([
209
- customElement2("prosekit-slash-popover")
210
- ], SlashPopover);
211
- export {
212
- SlashPopover
213
- };