@prosekit/lit 0.0.0-next-20230627094841
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.
- package/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/chunk-43BFWKM2.js +26 -0
- package/dist/chunk-5VENWR7M.js +118 -0
- package/dist/chunk-6EHMW3VI.js +19 -0
- package/dist/chunk-7C2I5DWH.js +122 -0
- package/dist/chunk-CFFBSSAU.js +121 -0
- package/dist/chunk-EZ4YICBQ.js +108 -0
- package/dist/chunk-JFOZX34E.js +109 -0
- package/dist/chunk-NMFTOM6J.js +189 -0
- package/dist/chunk-S65R2BUY.js +15 -0
- package/dist/chunk-TFM6CTEO.js +9 -0
- package/dist/chunk-VYMBIH4T.js +120 -0
- package/dist/chunk-WUZ77NLF.js +108 -0
- package/dist/chunk-XEV4EE3R.js +13 -0
- package/dist/chunk-Y34HGIIF.js +20 -0
- package/dist/chunk-YS57RXAX.js +124 -0
- package/dist/prosekit-lit-elements-menu-item.js +37 -0
- package/dist/prosekit-lit-elements-menu.js +169 -0
- package/dist/prosekit-lit-elements-picker.js +11 -0
- package/dist/prosekit-lit-elements-popover-slash.js +211 -0
- package/dist/prosekit-lit-elements-popover-suggestion-consumer.js +36 -0
- package/dist/prosekit-lit-elements-popover-suggestion.js +218 -0
- package/dist/prosekit-lit-elements-popover.js +7 -0
- package/dist/prosekit-lit-elements-popover2.js +119 -0
- package/dist/prosekit-lit-elements-slash-popover.js +213 -0
- package/dist/prosekit-lit.js +0 -0
- package/package.json +80 -0
- package/src/index.ts +5 -0
@@ -0,0 +1,119 @@
|
|
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
|
+
};
|
@@ -0,0 +1,213 @@
|
|
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
|
+
};
|
File without changes
|
package/package.json
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
{
|
2
|
+
"name": "@prosekit/lit",
|
3
|
+
"type": "module",
|
4
|
+
"version": "0.0.0-next-20230627094841",
|
5
|
+
"private": false,
|
6
|
+
"author": {
|
7
|
+
"name": "ocavue",
|
8
|
+
"email": "ocavue@gmail.com"
|
9
|
+
},
|
10
|
+
"license": "MIT",
|
11
|
+
"funding": "https://github.com/sponsors/ocavue",
|
12
|
+
"homepage": "https://github.com/ocavue/prosekit#readme",
|
13
|
+
"repository": {
|
14
|
+
"type": "git",
|
15
|
+
"url": "git+https://github.com/ocavue/prosekit.git",
|
16
|
+
"directory": "packages/lit"
|
17
|
+
},
|
18
|
+
"bugs": {
|
19
|
+
"url": "https://github.com/ocavue/prosekit/issues"
|
20
|
+
},
|
21
|
+
"keywords": [
|
22
|
+
"ProseMirror"
|
23
|
+
],
|
24
|
+
"sideEffects": true,
|
25
|
+
"main": "./dist/prosekit-lit.js",
|
26
|
+
"module": "./dist/prosekit-lit.js",
|
27
|
+
"exports": {
|
28
|
+
".": {
|
29
|
+
"types": "./dist/prosekit-lit.d.ts",
|
30
|
+
"import": "./dist/prosekit-lit.js",
|
31
|
+
"default": "./dist/prosekit-lit.js"
|
32
|
+
},
|
33
|
+
"./elements/menu": {
|
34
|
+
"types": "./dist/prosekit-lit-elements-menu.d.ts",
|
35
|
+
"import": "./dist/prosekit-lit-elements-menu.js",
|
36
|
+
"default": "./dist/prosekit-lit-elements-menu.js"
|
37
|
+
},
|
38
|
+
"./elements/menu-item": {
|
39
|
+
"types": "./dist/prosekit-lit-elements-menu-item.d.ts",
|
40
|
+
"import": "./dist/prosekit-lit-elements-menu-item.js",
|
41
|
+
"default": "./dist/prosekit-lit-elements-menu-item.js"
|
42
|
+
},
|
43
|
+
"./elements/popover": {
|
44
|
+
"types": "./dist/prosekit-lit-elements-popover.d.ts",
|
45
|
+
"import": "./dist/prosekit-lit-elements-popover.js",
|
46
|
+
"default": "./dist/prosekit-lit-elements-popover.js"
|
47
|
+
},
|
48
|
+
"./elements/popover-suggestion": {
|
49
|
+
"types": "./dist/prosekit-lit-elements-popover-suggestion.d.ts",
|
50
|
+
"import": "./dist/prosekit-lit-elements-popover-suggestion.js",
|
51
|
+
"default": "./dist/prosekit-lit-elements-popover-suggestion.js"
|
52
|
+
}
|
53
|
+
},
|
54
|
+
"files": [
|
55
|
+
"dist"
|
56
|
+
],
|
57
|
+
"dependencies": {
|
58
|
+
"@floating-ui/dom": "^1.4.2",
|
59
|
+
"@lit/reactive-element": "^2.0.0-pre.0",
|
60
|
+
"@prosekit/core": "0.0.0-next-20230627094841",
|
61
|
+
"@prosekit/extension-suggestion": "0.0.0-next-20230627094841",
|
62
|
+
"@prosekit/pm": "0.0.0-next-20230627094841",
|
63
|
+
"lit": "^3.0.0-pre.0",
|
64
|
+
"lit-element": "^4.0.0-pre.0",
|
65
|
+
"lit-html": "^3.0.0-pre.0"
|
66
|
+
},
|
67
|
+
"devDependencies": {
|
68
|
+
"minify-literals": "^1.0.5",
|
69
|
+
"tsup": "^7.1.0",
|
70
|
+
"typescript": "^5.1.3",
|
71
|
+
"vitest": "^0.32.2",
|
72
|
+
"vue": "^3.3.4",
|
73
|
+
"@prosekit/dev": "0.0.0"
|
74
|
+
},
|
75
|
+
"scripts": {
|
76
|
+
"build:tsup": "tsup",
|
77
|
+
"build:tsc": "tsc -b tsconfig.json"
|
78
|
+
},
|
79
|
+
"types": "./dist/prosekit-lit.d.ts"
|
80
|
+
}
|