silk-compose 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.
- package/README.md +124 -0
- package/dist/index.d.ts +97 -0
- package/dist/silk.css +1 -0
- package/dist/silk.js +1764 -0
- package/package.json +77 -0
package/dist/silk.js
ADDED
|
@@ -0,0 +1,1764 @@
|
|
|
1
|
+
import { jsx as t, Fragment as te, jsxs as y } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect as x, createContext as Se, useContext as we, useState as C, useRef as F, useCallback as w, useLayoutEffect as he, useMemo as _e } from "react";
|
|
3
|
+
import { LexicalComposer as Me } from "@lexical/react/LexicalComposer";
|
|
4
|
+
import { useLexicalComposerContext as _ } from "@lexical/react/LexicalComposerContext";
|
|
5
|
+
import { OnChangePlugin as Ee } from "@lexical/react/LexicalOnChangePlugin";
|
|
6
|
+
import { HorizontalRulePlugin as Le } from "@lexical/react/LexicalHorizontalRulePlugin";
|
|
7
|
+
import { TabIndentationPlugin as Te } from "@lexical/react/LexicalTabIndentationPlugin";
|
|
8
|
+
import { $createHeadingNode as le, $createQuoteNode as De, HeadingNode as Ie, QuoteNode as Oe } from "@lexical/rich-text";
|
|
9
|
+
import { CodeNode as pe, $isCodeNode as ne, $createCodeNode as Re, CodeHighlightNode as Fe } from "@lexical/code";
|
|
10
|
+
import { INSERT_UNORDERED_LIST_COMMAND as Ae, INSERT_ORDERED_LIST_COMMAND as $e, registerList as Pe, ListNode as ze, ListItemNode as Be } from "@lexical/list";
|
|
11
|
+
import { $createHorizontalRuleNode as He, HorizontalRuleNode as Ue } from "@lexical/react/LexicalHorizontalRuleNode";
|
|
12
|
+
import { TOGGLE_LINK_COMMAND as We, $toggleLink as ae, $createLinkNode as Ke, $isLinkNode as ce, LinkNode as Ge } from "@lexical/link";
|
|
13
|
+
import { $getNodeByKey as H, ElementNode as Ve, $createParagraphNode as G, COMMAND_PRIORITY_LOW as $, $getSelection as E, $isRangeSelection as L, $setSelection as Ye, $createTextNode as je, createCommand as Je, $isParagraphNode as me, SELECTION_CHANGE_COMMAND as ge, FORMAT_TEXT_COMMAND as Qe, $getNearestNodeFromDOMNode as Xe, $applyNodeReplacement as qe, DecoratorNode as Ze, CLICK_COMMAND as et, KEY_BACKSPACE_COMMAND as tt, KEY_DELETE_COMMAND as nt, PASTE_COMMAND as ot, COMMAND_PRIORITY_HIGH as X, DROP_COMMAND as it, DRAGOVER_COMMAND as rt, $isNodeSelection as st, $getRoot as de } from "lexical";
|
|
14
|
+
import { useLexicalNodeSelection as lt } from "@lexical/react/useLexicalNodeSelection";
|
|
15
|
+
import { $getSelectionStyleValueForProperty as q, $patchStyleText as Z, $setBlocksType as at } from "@lexical/selection";
|
|
16
|
+
import { RichTextPlugin as ct } from "@lexical/react/LexicalRichTextPlugin";
|
|
17
|
+
import { ContentEditable as dt } from "@lexical/react/LexicalContentEditable";
|
|
18
|
+
import { LexicalErrorBoundary as ut } from "@lexical/react/LexicalErrorBoundary";
|
|
19
|
+
import { HistoryPlugin as ft } from "@lexical/react/LexicalHistoryPlugin";
|
|
20
|
+
import { registerDragonSupport as ht } from "@lexical/dragon";
|
|
21
|
+
import { registerCodeHighlighting as pt, ShikiTokenizer as mt, getCodeLanguageOptions as gt } from "@lexical/code-shiki";
|
|
22
|
+
import { ListPlugin as kt } from "@lexical/react/LexicalListPlugin";
|
|
23
|
+
import { registerMarkdownShortcuts as bt, TEXT_FORMAT_TRANSFORMERS as yt, UNORDERED_LIST as vt, ORDERED_LIST as Nt } from "@lexical/markdown";
|
|
24
|
+
import { createPortal as Ct } from "react-dom";
|
|
25
|
+
import { useBasicTypeaheadTriggerMatch as xt, LexicalTypeaheadMenuPlugin as St, MenuOption as wt } from "@lexical/react/LexicalTypeaheadMenuPlugin";
|
|
26
|
+
function _t() {
|
|
27
|
+
return /* @__PURE__ */ t(ft, {});
|
|
28
|
+
}
|
|
29
|
+
function Mt() {
|
|
30
|
+
return /* @__PURE__ */ t("div", { style: { position: "relative" }, children: /* @__PURE__ */ t(
|
|
31
|
+
ct,
|
|
32
|
+
{
|
|
33
|
+
contentEditable: /* @__PURE__ */ t(dt, { className: "silk-content-editable" }),
|
|
34
|
+
placeholder: /* @__PURE__ */ t("div", { className: "silk-placeholder", children: "Start writing…" }),
|
|
35
|
+
ErrorBoundary: ut
|
|
36
|
+
}
|
|
37
|
+
) });
|
|
38
|
+
}
|
|
39
|
+
function Et() {
|
|
40
|
+
const [e] = _();
|
|
41
|
+
return x(() => ht(e), [e]), null;
|
|
42
|
+
}
|
|
43
|
+
const ke = Se({
|
|
44
|
+
current: null
|
|
45
|
+
});
|
|
46
|
+
function oe() {
|
|
47
|
+
return we(ke);
|
|
48
|
+
}
|
|
49
|
+
function Lt() {
|
|
50
|
+
return gt().map(([e, n]) => ({ value: e, label: n }));
|
|
51
|
+
}
|
|
52
|
+
const Tt = 32;
|
|
53
|
+
function Dt({
|
|
54
|
+
language: e,
|
|
55
|
+
codeNodeKey: n,
|
|
56
|
+
codeElem: i
|
|
57
|
+
}) {
|
|
58
|
+
var p;
|
|
59
|
+
const [o] = _(), s = oe(), [r, f] = C(!1), [a, c] = C(() => o.isEditable()), l = F(null), [h, b] = C({ top: 0, left: 0, width: 0 });
|
|
60
|
+
x(() => o.registerEditableListener(c), [o]);
|
|
61
|
+
const m = w(() => {
|
|
62
|
+
const d = s.current;
|
|
63
|
+
if (!d) return;
|
|
64
|
+
const k = i.getBoundingClientRect(), g = d.getBoundingClientRect();
|
|
65
|
+
b({
|
|
66
|
+
top: k.top - g.top - Tt,
|
|
67
|
+
left: k.left - g.left,
|
|
68
|
+
width: k.width
|
|
69
|
+
});
|
|
70
|
+
}, [i, s]);
|
|
71
|
+
he(() => {
|
|
72
|
+
m();
|
|
73
|
+
const d = new ResizeObserver(m);
|
|
74
|
+
return d.observe(i), () => d.disconnect();
|
|
75
|
+
}, [i, m]), x(() => o.registerUpdateListener(() => {
|
|
76
|
+
m();
|
|
77
|
+
}), [o, m]);
|
|
78
|
+
const S = Lt(), u = ((p = S.find((d) => d.value === e)) == null ? void 0 : p.label) ?? e ?? "Plain Text", v = w(
|
|
79
|
+
(d) => {
|
|
80
|
+
o.update(() => {
|
|
81
|
+
const k = H(n);
|
|
82
|
+
ne(k) && k.setLanguage(d);
|
|
83
|
+
}), f(!1);
|
|
84
|
+
},
|
|
85
|
+
[o, n]
|
|
86
|
+
);
|
|
87
|
+
return x(() => {
|
|
88
|
+
if (!r) return;
|
|
89
|
+
const d = (k) => {
|
|
90
|
+
l.current && !l.current.contains(k.target) && f(!1);
|
|
91
|
+
};
|
|
92
|
+
return document.addEventListener("mousedown", d), () => document.removeEventListener("mousedown", d);
|
|
93
|
+
}, [r]), /* @__PURE__ */ y(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
ref: l,
|
|
97
|
+
className: "silk-code-header",
|
|
98
|
+
style: {
|
|
99
|
+
position: "absolute",
|
|
100
|
+
top: h.top,
|
|
101
|
+
left: h.left,
|
|
102
|
+
width: h.width,
|
|
103
|
+
pointerEvents: "auto"
|
|
104
|
+
},
|
|
105
|
+
children: [
|
|
106
|
+
/* @__PURE__ */ y(
|
|
107
|
+
"button",
|
|
108
|
+
{
|
|
109
|
+
className: "silk-code-language-select",
|
|
110
|
+
onClick: () => a && f(!r),
|
|
111
|
+
style: { cursor: a ? "pointer" : "default" },
|
|
112
|
+
onMouseDown: (d) => d.preventDefault(),
|
|
113
|
+
type: "button",
|
|
114
|
+
children: [
|
|
115
|
+
u,
|
|
116
|
+
a && /* @__PURE__ */ t("span", { className: "silk-code-language-chevron", "aria-hidden": !0, children: "▾" })
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
),
|
|
120
|
+
r && a && /* @__PURE__ */ t("div", { className: "silk-code-language-dropdown", children: S.map((d) => /* @__PURE__ */ t(
|
|
121
|
+
"button",
|
|
122
|
+
{
|
|
123
|
+
className: `silk-code-language-option${e === d.value ? " silk-code-language-option--active" : ""}`,
|
|
124
|
+
onClick: () => v(d.value),
|
|
125
|
+
onMouseDown: (k) => k.preventDefault(),
|
|
126
|
+
type: "button",
|
|
127
|
+
children: d.label
|
|
128
|
+
},
|
|
129
|
+
d.value
|
|
130
|
+
)) })
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function It() {
|
|
136
|
+
const [e] = _(), [n, i] = C(
|
|
137
|
+
/* @__PURE__ */ new Map()
|
|
138
|
+
);
|
|
139
|
+
return x(() => pt(e, {
|
|
140
|
+
...mt,
|
|
141
|
+
defaultTheme: "dark-plus"
|
|
142
|
+
}), [e]), x(() => {
|
|
143
|
+
const o = /* @__PURE__ */ new Set(), s = () => {
|
|
144
|
+
e.getEditorState().read(() => {
|
|
145
|
+
const a = /* @__PURE__ */ new Map();
|
|
146
|
+
for (const c of o) {
|
|
147
|
+
const l = H(c);
|
|
148
|
+
if (ne(l)) {
|
|
149
|
+
const h = e.getElementByKey(c);
|
|
150
|
+
h && a.set(c, {
|
|
151
|
+
language: l.getLanguage() ?? "typescript",
|
|
152
|
+
elem: h
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
i(a);
|
|
157
|
+
});
|
|
158
|
+
}, r = e.registerMutationListener(
|
|
159
|
+
pe,
|
|
160
|
+
(a) => {
|
|
161
|
+
for (const [c, l] of a)
|
|
162
|
+
l === "destroyed" ? o.delete(c) : o.add(c);
|
|
163
|
+
s();
|
|
164
|
+
},
|
|
165
|
+
{ skipInitialization: !1 }
|
|
166
|
+
), f = e.registerUpdateListener(({ dirtyElements: a }) => {
|
|
167
|
+
let c = !1;
|
|
168
|
+
for (const l of o)
|
|
169
|
+
if (a.has(l)) {
|
|
170
|
+
c = !0;
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
c && s();
|
|
174
|
+
});
|
|
175
|
+
return () => {
|
|
176
|
+
r(), f();
|
|
177
|
+
};
|
|
178
|
+
}, [e]), /* @__PURE__ */ t(te, { children: Array.from(n.entries()).map(([o, { language: s, elem: r }]) => /* @__PURE__ */ t(
|
|
179
|
+
Dt,
|
|
180
|
+
{
|
|
181
|
+
language: s,
|
|
182
|
+
codeNodeKey: o,
|
|
183
|
+
codeElem: r
|
|
184
|
+
},
|
|
185
|
+
o
|
|
186
|
+
)) });
|
|
187
|
+
}
|
|
188
|
+
class W extends Ve {
|
|
189
|
+
static getType() {
|
|
190
|
+
return "note";
|
|
191
|
+
}
|
|
192
|
+
static clone(n) {
|
|
193
|
+
return new W(n.__noteType, n.__key);
|
|
194
|
+
}
|
|
195
|
+
constructor(n = "info", i) {
|
|
196
|
+
super(i), this.__noteType = n;
|
|
197
|
+
}
|
|
198
|
+
createDOM(n) {
|
|
199
|
+
const i = document.createElement("div");
|
|
200
|
+
return i.className = `silk-note silk-note--${this.__noteType}`, i;
|
|
201
|
+
}
|
|
202
|
+
updateDOM(n, i) {
|
|
203
|
+
return n.__noteType !== this.__noteType && (i.className = `silk-note silk-note--${this.__noteType}`), !1;
|
|
204
|
+
}
|
|
205
|
+
setNoteType(n) {
|
|
206
|
+
const i = this.getWritable();
|
|
207
|
+
return i.__noteType = n, i;
|
|
208
|
+
}
|
|
209
|
+
getNoteType() {
|
|
210
|
+
return this.getLatest().__noteType;
|
|
211
|
+
}
|
|
212
|
+
insertNewAfter(n, i) {
|
|
213
|
+
const o = n.anchor.getNode(), s = this.getLastDescendant();
|
|
214
|
+
if (s === null || o === s || o === this && n.anchor.offset === this.getChildrenSize()) {
|
|
215
|
+
const r = G();
|
|
216
|
+
return this.insertAfter(r, i), r;
|
|
217
|
+
}
|
|
218
|
+
return super.insertNewAfter(n, i);
|
|
219
|
+
}
|
|
220
|
+
collapseAtStart() {
|
|
221
|
+
const n = G(), i = this.getChildren();
|
|
222
|
+
return i.length > 0 && i.forEach((o) => n.append(o)), this.replace(n), !0;
|
|
223
|
+
}
|
|
224
|
+
static importJSON(n) {
|
|
225
|
+
return be(n.noteType);
|
|
226
|
+
}
|
|
227
|
+
exportJSON() {
|
|
228
|
+
return {
|
|
229
|
+
...super.exportJSON(),
|
|
230
|
+
noteType: this.__noteType
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function be(e = "info") {
|
|
235
|
+
return new W(e);
|
|
236
|
+
}
|
|
237
|
+
function ye(e) {
|
|
238
|
+
return e instanceof W;
|
|
239
|
+
}
|
|
240
|
+
const ie = Je("SHOW_LINK_DIALOG");
|
|
241
|
+
function Ot() {
|
|
242
|
+
const [e] = _(), [n, i] = C(!1), [o, s] = C(""), [r, f] = C(""), [a, c] = C(!1), l = F(null), h = F(null);
|
|
243
|
+
x(() => {
|
|
244
|
+
const u = e.registerCommand(
|
|
245
|
+
We,
|
|
246
|
+
(p) => (ae(p, {
|
|
247
|
+
target: "_blank",
|
|
248
|
+
rel: "noopener noreferrer"
|
|
249
|
+
}), !0),
|
|
250
|
+
$
|
|
251
|
+
), v = e.registerCommand(
|
|
252
|
+
ie,
|
|
253
|
+
(p) => {
|
|
254
|
+
const d = E();
|
|
255
|
+
if (L(d)) {
|
|
256
|
+
h.current = d.clone();
|
|
257
|
+
const k = d.isCollapsed();
|
|
258
|
+
c(!k), k || f(d.getTextContent());
|
|
259
|
+
}
|
|
260
|
+
return (p == null ? void 0 : p.text) !== void 0 && f(p.text), i(!0), !0;
|
|
261
|
+
},
|
|
262
|
+
$
|
|
263
|
+
);
|
|
264
|
+
return () => {
|
|
265
|
+
u(), v();
|
|
266
|
+
};
|
|
267
|
+
}, [e]), x(() => {
|
|
268
|
+
n && setTimeout(() => {
|
|
269
|
+
var u;
|
|
270
|
+
return (u = l.current) == null ? void 0 : u.focus();
|
|
271
|
+
}, 0);
|
|
272
|
+
}, [n]);
|
|
273
|
+
const b = w(() => {
|
|
274
|
+
i(!1), s(""), f(""), c(!1), h.current = null, e.focus();
|
|
275
|
+
}, [e]), m = w(() => {
|
|
276
|
+
o && (e.update(() => {
|
|
277
|
+
if (h.current && Ye(h.current.clone()), a)
|
|
278
|
+
ae(o, {
|
|
279
|
+
target: "_blank",
|
|
280
|
+
rel: "noopener noreferrer"
|
|
281
|
+
});
|
|
282
|
+
else {
|
|
283
|
+
const u = Ke(o, {
|
|
284
|
+
target: "_blank",
|
|
285
|
+
rel: "noopener noreferrer"
|
|
286
|
+
}), v = je(r || o);
|
|
287
|
+
u.append(v);
|
|
288
|
+
const p = E();
|
|
289
|
+
L(p) && p.insertNodes([u]);
|
|
290
|
+
}
|
|
291
|
+
}), b());
|
|
292
|
+
}, [e, o, r, a, b]), S = w(
|
|
293
|
+
(u) => {
|
|
294
|
+
u.key === "Enter" && (u.preventDefault(), m()), u.key === "Escape" && b();
|
|
295
|
+
},
|
|
296
|
+
[m, b]
|
|
297
|
+
);
|
|
298
|
+
return n ? /* @__PURE__ */ t(
|
|
299
|
+
"div",
|
|
300
|
+
{
|
|
301
|
+
className: "silk-link-dialog-backdrop",
|
|
302
|
+
onMouseDown: (u) => {
|
|
303
|
+
u.target === u.currentTarget && b();
|
|
304
|
+
},
|
|
305
|
+
children: /* @__PURE__ */ y("div", { className: "silk-link-dialog", onKeyDown: S, children: [
|
|
306
|
+
/* @__PURE__ */ y("div", { className: "silk-link-dialog-field", children: [
|
|
307
|
+
/* @__PURE__ */ t("label", { className: "silk-link-dialog-label", children: "URL" }),
|
|
308
|
+
/* @__PURE__ */ t(
|
|
309
|
+
"input",
|
|
310
|
+
{
|
|
311
|
+
ref: l,
|
|
312
|
+
className: "silk-link-dialog-input",
|
|
313
|
+
type: "text",
|
|
314
|
+
value: o,
|
|
315
|
+
onChange: (u) => s(u.target.value),
|
|
316
|
+
placeholder: "https://example.com"
|
|
317
|
+
}
|
|
318
|
+
)
|
|
319
|
+
] }),
|
|
320
|
+
/* @__PURE__ */ y("div", { className: "silk-link-dialog-field", children: [
|
|
321
|
+
/* @__PURE__ */ t("label", { className: "silk-link-dialog-label", children: "Display text" }),
|
|
322
|
+
/* @__PURE__ */ t(
|
|
323
|
+
"input",
|
|
324
|
+
{
|
|
325
|
+
className: `silk-link-dialog-input${a ? " silk-link-dialog-input--readonly" : ""}`,
|
|
326
|
+
type: "text",
|
|
327
|
+
value: r,
|
|
328
|
+
onChange: (u) => f(u.target.value),
|
|
329
|
+
placeholder: "Link text",
|
|
330
|
+
readOnly: a
|
|
331
|
+
}
|
|
332
|
+
)
|
|
333
|
+
] }),
|
|
334
|
+
/* @__PURE__ */ y("div", { className: "silk-link-dialog-actions", children: [
|
|
335
|
+
/* @__PURE__ */ t(
|
|
336
|
+
"button",
|
|
337
|
+
{
|
|
338
|
+
className: "silk-link-dialog-cancel",
|
|
339
|
+
onClick: b,
|
|
340
|
+
type: "button",
|
|
341
|
+
children: "Cancel"
|
|
342
|
+
}
|
|
343
|
+
),
|
|
344
|
+
/* @__PURE__ */ t(
|
|
345
|
+
"button",
|
|
346
|
+
{
|
|
347
|
+
className: "silk-link-dialog-insert",
|
|
348
|
+
onClick: m,
|
|
349
|
+
disabled: !o,
|
|
350
|
+
type: "button",
|
|
351
|
+
children: "Insert"
|
|
352
|
+
}
|
|
353
|
+
)
|
|
354
|
+
] })
|
|
355
|
+
] })
|
|
356
|
+
}
|
|
357
|
+
) : null;
|
|
358
|
+
}
|
|
359
|
+
const Rt = 18;
|
|
360
|
+
function O({
|
|
361
|
+
children: e,
|
|
362
|
+
size: n = Rt,
|
|
363
|
+
className: i
|
|
364
|
+
}) {
|
|
365
|
+
return /* @__PURE__ */ t(
|
|
366
|
+
"svg",
|
|
367
|
+
{
|
|
368
|
+
width: n,
|
|
369
|
+
height: n,
|
|
370
|
+
viewBox: "0 0 24 24",
|
|
371
|
+
fill: "none",
|
|
372
|
+
stroke: "currentColor",
|
|
373
|
+
strokeWidth: 2,
|
|
374
|
+
strokeLinecap: "round",
|
|
375
|
+
strokeLinejoin: "round",
|
|
376
|
+
className: i,
|
|
377
|
+
children: e
|
|
378
|
+
}
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
function Ft(e) {
|
|
382
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
383
|
+
/* @__PURE__ */ t("path", { d: "M4 12h8" }),
|
|
384
|
+
/* @__PURE__ */ t("path", { d: "M4 18V6" }),
|
|
385
|
+
/* @__PURE__ */ t("path", { d: "M12 18V6" }),
|
|
386
|
+
/* @__PURE__ */ t("path", { d: "M17 12l3-2v8" })
|
|
387
|
+
] });
|
|
388
|
+
}
|
|
389
|
+
function At(e) {
|
|
390
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
391
|
+
/* @__PURE__ */ t("path", { d: "M4 12h8" }),
|
|
392
|
+
/* @__PURE__ */ t("path", { d: "M4 18V6" }),
|
|
393
|
+
/* @__PURE__ */ t("path", { d: "M12 18V6" }),
|
|
394
|
+
/* @__PURE__ */ t("path", { d: "M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1" })
|
|
395
|
+
] });
|
|
396
|
+
}
|
|
397
|
+
function $t(e) {
|
|
398
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
399
|
+
/* @__PURE__ */ t("polyline", { points: "16 18 22 12 16 6" }),
|
|
400
|
+
/* @__PURE__ */ t("polyline", { points: "8 6 2 12 8 18" })
|
|
401
|
+
] });
|
|
402
|
+
}
|
|
403
|
+
function ve(e) {
|
|
404
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
405
|
+
/* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "10" }),
|
|
406
|
+
/* @__PURE__ */ t("line", { x1: "12", y1: "16", x2: "12", y2: "12" }),
|
|
407
|
+
/* @__PURE__ */ t("line", { x1: "12", y1: "8", x2: "12.01", y2: "8" })
|
|
408
|
+
] });
|
|
409
|
+
}
|
|
410
|
+
function Pt(e) {
|
|
411
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
412
|
+
/* @__PURE__ */ t("path", { d: "M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z" }),
|
|
413
|
+
/* @__PURE__ */ t(
|
|
414
|
+
"text",
|
|
415
|
+
{
|
|
416
|
+
x: "12",
|
|
417
|
+
y: "17",
|
|
418
|
+
textAnchor: "middle",
|
|
419
|
+
fill: "currentColor",
|
|
420
|
+
stroke: "none",
|
|
421
|
+
fontSize: "12",
|
|
422
|
+
fontWeight: "700",
|
|
423
|
+
fontFamily: "Inter, sans-serif",
|
|
424
|
+
children: "?"
|
|
425
|
+
}
|
|
426
|
+
)
|
|
427
|
+
] });
|
|
428
|
+
}
|
|
429
|
+
function zt(e) {
|
|
430
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
431
|
+
/* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "10" }),
|
|
432
|
+
/* @__PURE__ */ t("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
433
|
+
/* @__PURE__ */ t("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
434
|
+
] });
|
|
435
|
+
}
|
|
436
|
+
function Bt(e) {
|
|
437
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
438
|
+
/* @__PURE__ */ t("path", { d: "M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71" }),
|
|
439
|
+
/* @__PURE__ */ t("path", { d: "M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71" })
|
|
440
|
+
] });
|
|
441
|
+
}
|
|
442
|
+
function Ht(e) {
|
|
443
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
444
|
+
/* @__PURE__ */ t("line", { x1: "10", y1: "6", x2: "21", y2: "6" }),
|
|
445
|
+
/* @__PURE__ */ t("line", { x1: "10", y1: "12", x2: "21", y2: "12" }),
|
|
446
|
+
/* @__PURE__ */ t("line", { x1: "10", y1: "18", x2: "21", y2: "18" }),
|
|
447
|
+
/* @__PURE__ */ t("path", { d: "M4 6h1v4" }),
|
|
448
|
+
/* @__PURE__ */ t("path", { d: "M4 10h2" }),
|
|
449
|
+
/* @__PURE__ */ t("path", { d: "M6 18H4c0-1 2-2 2-3s-1-1.5-2-1" })
|
|
450
|
+
] });
|
|
451
|
+
}
|
|
452
|
+
function Ut(e) {
|
|
453
|
+
return /* @__PURE__ */ y(O, { ...e, children: [
|
|
454
|
+
/* @__PURE__ */ t("line", { x1: "8", y1: "6", x2: "21", y2: "6" }),
|
|
455
|
+
/* @__PURE__ */ t("line", { x1: "8", y1: "12", x2: "21", y2: "12" }),
|
|
456
|
+
/* @__PURE__ */ t("line", { x1: "8", y1: "18", x2: "21", y2: "18" }),
|
|
457
|
+
/* @__PURE__ */ t("line", { x1: "3", y1: "6", x2: "3.01", y2: "6" }),
|
|
458
|
+
/* @__PURE__ */ t("line", { x1: "3", y1: "12", x2: "3.01", y2: "12" }),
|
|
459
|
+
/* @__PURE__ */ t("line", { x1: "3", y1: "18", x2: "3.01", y2: "18" })
|
|
460
|
+
] });
|
|
461
|
+
}
|
|
462
|
+
function Wt(e) {
|
|
463
|
+
return /* @__PURE__ */ t(O, { ...e, children: /* @__PURE__ */ t("line", { x1: "2", y1: "12", x2: "22", y2: "12" }) });
|
|
464
|
+
}
|
|
465
|
+
function J(e) {
|
|
466
|
+
const n = E();
|
|
467
|
+
if (!L(n)) return;
|
|
468
|
+
const o = n.anchor.getNode().getTopLevelElementOrThrow(), s = e(), r = G();
|
|
469
|
+
return o.insertAfter(s), s.insertAfter(r), me(o) && o.getTextContentSize() === 0 && o.remove(), { node: s, trailing: r };
|
|
470
|
+
}
|
|
471
|
+
const Kt = [
|
|
472
|
+
{
|
|
473
|
+
name: "Heading 1",
|
|
474
|
+
icon: /* @__PURE__ */ t(Ft, {}),
|
|
475
|
+
description: "Large section heading",
|
|
476
|
+
execute: () => {
|
|
477
|
+
const e = J(() => le("h1"));
|
|
478
|
+
e == null || e.node.selectStart();
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
{
|
|
482
|
+
name: "Heading 2",
|
|
483
|
+
icon: /* @__PURE__ */ t(At, {}),
|
|
484
|
+
description: "Medium section heading",
|
|
485
|
+
execute: () => {
|
|
486
|
+
const e = J(() => le("h2"));
|
|
487
|
+
e == null || e.node.selectStart();
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
name: "Code Block",
|
|
492
|
+
icon: /* @__PURE__ */ t($t, {}),
|
|
493
|
+
description: "Code with syntax highlighting",
|
|
494
|
+
execute: () => {
|
|
495
|
+
const e = J(() => Re("typescript"));
|
|
496
|
+
e == null || e.node.selectStart();
|
|
497
|
+
}
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
name: "Note",
|
|
501
|
+
icon: /* @__PURE__ */ t(ve, {}),
|
|
502
|
+
description: "Info, warning, or error callout",
|
|
503
|
+
execute: () => {
|
|
504
|
+
const e = E();
|
|
505
|
+
if (!L(e)) return;
|
|
506
|
+
const i = e.anchor.getNode().getTopLevelElementOrThrow(), o = be("info"), s = G();
|
|
507
|
+
o.append(s);
|
|
508
|
+
const r = G();
|
|
509
|
+
i.insertAfter(o), o.insertAfter(r), me(i) && i.getTextContentSize() === 0 && i.remove(), s.selectStart();
|
|
510
|
+
}
|
|
511
|
+
},
|
|
512
|
+
{
|
|
513
|
+
name: "Bulleted List",
|
|
514
|
+
icon: /* @__PURE__ */ t(Ut, {}),
|
|
515
|
+
description: "Unordered bulleted list",
|
|
516
|
+
execute: (e) => {
|
|
517
|
+
e.dispatchCommand(Ae, void 0);
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
name: "Numbered List",
|
|
522
|
+
icon: /* @__PURE__ */ t(Ht, {}),
|
|
523
|
+
description: "Ordered numbered list",
|
|
524
|
+
execute: (e) => {
|
|
525
|
+
e.dispatchCommand($e, void 0);
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
name: "Divider",
|
|
530
|
+
icon: /* @__PURE__ */ t(Wt, {}),
|
|
531
|
+
description: "Horizontal line separator",
|
|
532
|
+
execute: () => {
|
|
533
|
+
const e = J(() => He());
|
|
534
|
+
e == null || e.trailing.selectStart();
|
|
535
|
+
}
|
|
536
|
+
},
|
|
537
|
+
{
|
|
538
|
+
name: "Link",
|
|
539
|
+
icon: /* @__PURE__ */ t(Bt, {}),
|
|
540
|
+
description: "Insert a masked link",
|
|
541
|
+
execute: (e) => {
|
|
542
|
+
e.dispatchCommand(ie, void 0);
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
];
|
|
546
|
+
class Gt extends wt {
|
|
547
|
+
constructor(n) {
|
|
548
|
+
super(n.name), this.entry = n;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
function Vt({
|
|
552
|
+
option: e,
|
|
553
|
+
isSelected: n,
|
|
554
|
+
onClick: i,
|
|
555
|
+
onMouseEnter: o
|
|
556
|
+
}) {
|
|
557
|
+
return /* @__PURE__ */ y(
|
|
558
|
+
"button",
|
|
559
|
+
{
|
|
560
|
+
className: `silk-slash-menu-item${n ? " silk-slash-menu-item--active" : ""}`,
|
|
561
|
+
ref: (s) => e.setRefElement(s),
|
|
562
|
+
onMouseDown: (s) => {
|
|
563
|
+
s.preventDefault(), i();
|
|
564
|
+
},
|
|
565
|
+
onMouseEnter: o,
|
|
566
|
+
type: "button",
|
|
567
|
+
children: [
|
|
568
|
+
/* @__PURE__ */ t("span", { className: "silk-slash-menu-icon", children: e.entry.icon }),
|
|
569
|
+
/* @__PURE__ */ y("div", { className: "silk-slash-menu-text", children: [
|
|
570
|
+
/* @__PURE__ */ t("span", { className: "silk-slash-menu-name", children: e.entry.name }),
|
|
571
|
+
/* @__PURE__ */ t("span", { className: "silk-slash-menu-description", children: e.entry.description })
|
|
572
|
+
] })
|
|
573
|
+
]
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
function Yt() {
|
|
578
|
+
const [e] = _(), [n, i] = C(() => e.isEditable()), [o, s] = C(null);
|
|
579
|
+
x(() => e.registerEditableListener(i), [e]);
|
|
580
|
+
const r = xt("/", {
|
|
581
|
+
minLength: 0,
|
|
582
|
+
allowWhitespace: !0
|
|
583
|
+
}), f = _e(() => {
|
|
584
|
+
if (o === null) return [];
|
|
585
|
+
const l = o.toLowerCase();
|
|
586
|
+
return Kt.filter(
|
|
587
|
+
(b) => b.name.toLowerCase().includes(l) || b.description.toLowerCase().includes(l)
|
|
588
|
+
).map((b) => new Gt(b));
|
|
589
|
+
}, [o]), a = w(
|
|
590
|
+
(l, h, b) => {
|
|
591
|
+
h && h.remove(), l.entry.execute(e), b();
|
|
592
|
+
},
|
|
593
|
+
[e]
|
|
594
|
+
), c = w(
|
|
595
|
+
(l, h, b) => l.current == null || h.options.length === 0 ? null : Ct(
|
|
596
|
+
/* @__PURE__ */ t("div", { className: "silk-slash-menu", children: h.options.map((m, S) => /* @__PURE__ */ t(
|
|
597
|
+
Vt,
|
|
598
|
+
{
|
|
599
|
+
option: m,
|
|
600
|
+
isSelected: h.selectedIndex === S,
|
|
601
|
+
onClick: () => h.selectOptionAndCleanUp(m),
|
|
602
|
+
onMouseEnter: () => h.setHighlightedIndex(S)
|
|
603
|
+
},
|
|
604
|
+
m.key
|
|
605
|
+
)) }),
|
|
606
|
+
l.current
|
|
607
|
+
),
|
|
608
|
+
[]
|
|
609
|
+
);
|
|
610
|
+
return n ? /* @__PURE__ */ t(
|
|
611
|
+
St,
|
|
612
|
+
{
|
|
613
|
+
options: f,
|
|
614
|
+
onQueryChange: s,
|
|
615
|
+
onSelectOption: a,
|
|
616
|
+
triggerFn: r,
|
|
617
|
+
menuRenderFn: c,
|
|
618
|
+
anchorClassName: "silk-slash-anchor"
|
|
619
|
+
}
|
|
620
|
+
) : null;
|
|
621
|
+
}
|
|
622
|
+
const jt = [
|
|
623
|
+
{ value: "info", label: "Info", Icon: ve },
|
|
624
|
+
{ value: "warning", label: "Question", Icon: Pt },
|
|
625
|
+
{ value: "error", label: "Error", Icon: zt }
|
|
626
|
+
];
|
|
627
|
+
function Jt({
|
|
628
|
+
noteType: e,
|
|
629
|
+
nodeKey: n,
|
|
630
|
+
elem: i
|
|
631
|
+
}) {
|
|
632
|
+
const [o] = _(), s = oe(), [r, f] = C(() => o.isEditable()), [a, c] = C(!1), l = F(null), [h, b] = C({ top: 0, left: 0 });
|
|
633
|
+
x(() => o.registerEditableListener(f), [o]);
|
|
634
|
+
const m = w(() => {
|
|
635
|
+
const u = s.current;
|
|
636
|
+
if (!u) return;
|
|
637
|
+
const v = i.getBoundingClientRect(), p = u.getBoundingClientRect();
|
|
638
|
+
b({
|
|
639
|
+
top: v.top - p.top + 13,
|
|
640
|
+
left: v.left - p.left + 17
|
|
641
|
+
});
|
|
642
|
+
}, [i, s]);
|
|
643
|
+
he(() => {
|
|
644
|
+
m();
|
|
645
|
+
const u = new ResizeObserver(m);
|
|
646
|
+
return u.observe(i), () => u.disconnect();
|
|
647
|
+
}, [i, m]), x(() => o.registerUpdateListener(() => m()), [o, m]);
|
|
648
|
+
const S = w(
|
|
649
|
+
(u) => {
|
|
650
|
+
o.update(() => {
|
|
651
|
+
const v = H(n);
|
|
652
|
+
ye(v) && v.setNoteType(u);
|
|
653
|
+
}), c(!1);
|
|
654
|
+
},
|
|
655
|
+
[o, n]
|
|
656
|
+
);
|
|
657
|
+
return x(() => {
|
|
658
|
+
if (!a) return;
|
|
659
|
+
const u = (v) => {
|
|
660
|
+
l.current && !l.current.contains(v.target) && c(!1);
|
|
661
|
+
};
|
|
662
|
+
return document.addEventListener("mousedown", u), () => document.removeEventListener("mousedown", u);
|
|
663
|
+
}, [a]), r ? /* @__PURE__ */ y(
|
|
664
|
+
"div",
|
|
665
|
+
{
|
|
666
|
+
ref: l,
|
|
667
|
+
style: {
|
|
668
|
+
position: "absolute",
|
|
669
|
+
top: h.top,
|
|
670
|
+
left: h.left,
|
|
671
|
+
zIndex: 1
|
|
672
|
+
},
|
|
673
|
+
children: [
|
|
674
|
+
/* @__PURE__ */ t(
|
|
675
|
+
"button",
|
|
676
|
+
{
|
|
677
|
+
className: `silk-note-icon-trigger silk-note-icon-trigger--${e}`,
|
|
678
|
+
onClick: () => c(!a),
|
|
679
|
+
onMouseDown: (u) => u.preventDefault(),
|
|
680
|
+
type: "button",
|
|
681
|
+
"aria-label": "Change note type"
|
|
682
|
+
}
|
|
683
|
+
),
|
|
684
|
+
a && /* @__PURE__ */ t("div", { className: "silk-note-icon-dropdown", children: jt.map((u) => /* @__PURE__ */ y(
|
|
685
|
+
"button",
|
|
686
|
+
{
|
|
687
|
+
className: `silk-note-type-option silk-note-type-option--${u.value}${e === u.value ? " silk-note-type-option--active" : ""}`,
|
|
688
|
+
onClick: () => S(u.value),
|
|
689
|
+
onMouseDown: (v) => v.preventDefault(),
|
|
690
|
+
type: "button",
|
|
691
|
+
children: [
|
|
692
|
+
/* @__PURE__ */ t(u.Icon, { size: 14 }),
|
|
693
|
+
u.label
|
|
694
|
+
]
|
|
695
|
+
},
|
|
696
|
+
u.value
|
|
697
|
+
)) })
|
|
698
|
+
]
|
|
699
|
+
}
|
|
700
|
+
) : null;
|
|
701
|
+
}
|
|
702
|
+
function Qt() {
|
|
703
|
+
const [e] = _(), [n, i] = C(
|
|
704
|
+
/* @__PURE__ */ new Map()
|
|
705
|
+
);
|
|
706
|
+
return x(() => {
|
|
707
|
+
const o = /* @__PURE__ */ new Set(), s = () => {
|
|
708
|
+
e.getEditorState().read(() => {
|
|
709
|
+
const a = /* @__PURE__ */ new Map();
|
|
710
|
+
for (const c of o) {
|
|
711
|
+
const l = H(c);
|
|
712
|
+
if (ye(l)) {
|
|
713
|
+
const h = e.getElementByKey(c);
|
|
714
|
+
h && a.set(c, {
|
|
715
|
+
noteType: l.getNoteType(),
|
|
716
|
+
elem: h
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
i(a);
|
|
721
|
+
});
|
|
722
|
+
}, r = e.registerMutationListener(
|
|
723
|
+
W,
|
|
724
|
+
(a) => {
|
|
725
|
+
for (const [c, l] of a)
|
|
726
|
+
l === "destroyed" ? o.delete(c) : o.add(c);
|
|
727
|
+
s();
|
|
728
|
+
},
|
|
729
|
+
{ skipInitialization: !1 }
|
|
730
|
+
), f = e.registerUpdateListener(({ dirtyElements: a }) => {
|
|
731
|
+
let c = !1;
|
|
732
|
+
for (const l of o)
|
|
733
|
+
if (a.has(l)) {
|
|
734
|
+
c = !0;
|
|
735
|
+
break;
|
|
736
|
+
}
|
|
737
|
+
c && s();
|
|
738
|
+
});
|
|
739
|
+
return () => {
|
|
740
|
+
r(), f();
|
|
741
|
+
};
|
|
742
|
+
}, [e]), /* @__PURE__ */ t(te, { children: Array.from(n.entries()).map(([o, { noteType: s, elem: r }]) => /* @__PURE__ */ t(
|
|
743
|
+
Jt,
|
|
744
|
+
{
|
|
745
|
+
noteType: s,
|
|
746
|
+
nodeKey: o,
|
|
747
|
+
elem: r
|
|
748
|
+
},
|
|
749
|
+
o
|
|
750
|
+
)) });
|
|
751
|
+
}
|
|
752
|
+
const Xt = [
|
|
753
|
+
...yt,
|
|
754
|
+
vt,
|
|
755
|
+
Nt
|
|
756
|
+
];
|
|
757
|
+
function qt() {
|
|
758
|
+
const [e] = _();
|
|
759
|
+
return x(() => bt(e, Xt), [e]), null;
|
|
760
|
+
}
|
|
761
|
+
const Ne = [
|
|
762
|
+
{ value: null, label: "Default" },
|
|
763
|
+
{ value: "#9c9a94", label: "Muted" },
|
|
764
|
+
{ value: "#ac3521", label: "Alert" },
|
|
765
|
+
{ value: "#5a6340", label: "Emphasis" },
|
|
766
|
+
{ value: "#7e572e", label: "Accent" },
|
|
767
|
+
{ value: "#4a5568", label: "Secondary" }
|
|
768
|
+
], U = [
|
|
769
|
+
{ value: null, label: "Inter", css: '"Inter", sans-serif' },
|
|
770
|
+
{
|
|
771
|
+
value: '"SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace',
|
|
772
|
+
label: "SF Mono",
|
|
773
|
+
css: '"SF Mono", monospace'
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
value: '"Space Grotesk", "Inter", sans-serif',
|
|
777
|
+
label: "Space Grotesk",
|
|
778
|
+
css: '"Space Grotesk", sans-serif'
|
|
779
|
+
}
|
|
780
|
+
];
|
|
781
|
+
function Zt(e) {
|
|
782
|
+
return e ? e.includes("SF Mono") || e.includes("Fira Code") ? U[1].value : e.includes("Space Grotesk") ? U[2].value : null : null;
|
|
783
|
+
}
|
|
784
|
+
const re = 10, se = 36, ue = 16;
|
|
785
|
+
function Ce() {
|
|
786
|
+
const [e] = _(), [n, i] = C(/* @__PURE__ */ new Set()), [o, s] = C(ue), [r, f] = C(null), [a, c] = C(
|
|
787
|
+
null
|
|
788
|
+
), l = w(() => {
|
|
789
|
+
e.getEditorState().read(() => {
|
|
790
|
+
const p = E();
|
|
791
|
+
if (!L(p)) return;
|
|
792
|
+
const d = /* @__PURE__ */ new Set();
|
|
793
|
+
p.hasFormat("bold") && d.add("bold"), p.hasFormat("italic") && d.add("italic"), p.hasFormat("underline") && d.add("underline"), p.hasFormat("code") && d.add("code"), i(d);
|
|
794
|
+
const k = q(
|
|
795
|
+
p,
|
|
796
|
+
"font-size",
|
|
797
|
+
""
|
|
798
|
+
);
|
|
799
|
+
s(k ? parseInt(k, 10) : ue);
|
|
800
|
+
const g = q(
|
|
801
|
+
p,
|
|
802
|
+
"color",
|
|
803
|
+
""
|
|
804
|
+
);
|
|
805
|
+
f(g || null);
|
|
806
|
+
const M = q(
|
|
807
|
+
p,
|
|
808
|
+
"font-family",
|
|
809
|
+
""
|
|
810
|
+
);
|
|
811
|
+
c(Zt(M || null));
|
|
812
|
+
});
|
|
813
|
+
}, [e]);
|
|
814
|
+
x(() => e.registerCommand(
|
|
815
|
+
ge,
|
|
816
|
+
() => (l(), !1),
|
|
817
|
+
$
|
|
818
|
+
), [e, l]), x(() => e.registerUpdateListener(() => l()), [e, l]);
|
|
819
|
+
const h = w(
|
|
820
|
+
(p) => {
|
|
821
|
+
e.dispatchCommand(Qe, p);
|
|
822
|
+
},
|
|
823
|
+
[e]
|
|
824
|
+
), b = w(
|
|
825
|
+
(p) => {
|
|
826
|
+
const d = Math.max(
|
|
827
|
+
re,
|
|
828
|
+
Math.min(se, o + p)
|
|
829
|
+
);
|
|
830
|
+
e.update(() => {
|
|
831
|
+
const k = E();
|
|
832
|
+
L(k) && Z(k, { "font-size": `${d}px` });
|
|
833
|
+
});
|
|
834
|
+
},
|
|
835
|
+
[e, o]
|
|
836
|
+
), m = w(
|
|
837
|
+
(p) => {
|
|
838
|
+
e.update(() => {
|
|
839
|
+
const d = E();
|
|
840
|
+
L(d) && Z(d, { color: p });
|
|
841
|
+
});
|
|
842
|
+
},
|
|
843
|
+
[e]
|
|
844
|
+
), S = w(
|
|
845
|
+
(p) => {
|
|
846
|
+
e.update(() => {
|
|
847
|
+
const d = E();
|
|
848
|
+
L(d) && Z(d, { "font-family": p });
|
|
849
|
+
});
|
|
850
|
+
},
|
|
851
|
+
[e]
|
|
852
|
+
), u = w(() => {
|
|
853
|
+
e.getEditorState().read(() => {
|
|
854
|
+
const p = E();
|
|
855
|
+
if (L(p)) {
|
|
856
|
+
const d = p.getTextContent();
|
|
857
|
+
e.dispatchCommand(ie, { text: d });
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
}, [e]), v = w(() => {
|
|
861
|
+
e.update(() => {
|
|
862
|
+
const p = E();
|
|
863
|
+
L(p) && at(p, () => De());
|
|
864
|
+
});
|
|
865
|
+
}, [e]);
|
|
866
|
+
return {
|
|
867
|
+
formats: n,
|
|
868
|
+
fontSize: o,
|
|
869
|
+
currentColor: r,
|
|
870
|
+
currentFontFamily: a,
|
|
871
|
+
toggleFormat: h,
|
|
872
|
+
changeFontSize: b,
|
|
873
|
+
applyColor: m,
|
|
874
|
+
applyFontFamily: S,
|
|
875
|
+
openLinkDialog: u,
|
|
876
|
+
insertQuote: v
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
const en = 8;
|
|
880
|
+
function tn() {
|
|
881
|
+
var Y;
|
|
882
|
+
const [e] = _(), n = oe(), i = F(null), [o, s] = C(!1), [r, f] = C({ top: 0, left: 0 }), [a, c] = C(!1), [l, h] = C(!1), {
|
|
883
|
+
formats: b,
|
|
884
|
+
fontSize: m,
|
|
885
|
+
currentColor: S,
|
|
886
|
+
currentFontFamily: u,
|
|
887
|
+
toggleFormat: v,
|
|
888
|
+
changeFontSize: p,
|
|
889
|
+
applyColor: d,
|
|
890
|
+
applyFontFamily: k,
|
|
891
|
+
openLinkDialog: g
|
|
892
|
+
} = Ce(), M = w(() => {
|
|
893
|
+
if (!e.isEditable()) {
|
|
894
|
+
s(!1);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
let A = !1;
|
|
898
|
+
if (e.getEditorState().read(() => {
|
|
899
|
+
const K = E();
|
|
900
|
+
!L(K) || K.isCollapsed() || K.getNodes().some((xe) => {
|
|
901
|
+
let j = xe.getParent();
|
|
902
|
+
for (; j; ) {
|
|
903
|
+
if (ne(j)) return !0;
|
|
904
|
+
j = j.getParent();
|
|
905
|
+
}
|
|
906
|
+
return !1;
|
|
907
|
+
}) || (A = !0);
|
|
908
|
+
}), !A) {
|
|
909
|
+
s(!1);
|
|
910
|
+
return;
|
|
911
|
+
}
|
|
912
|
+
const P = window.getSelection();
|
|
913
|
+
if (!P || P.rangeCount === 0) {
|
|
914
|
+
s(!1);
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
const z = P.getRangeAt(0).getBoundingClientRect(), B = n.current;
|
|
918
|
+
if (!B) {
|
|
919
|
+
s(!1);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
const D = B.getBoundingClientRect(), R = i.current, T = (R == null ? void 0 : R.offsetWidth) ?? 300;
|
|
923
|
+
let I = z.left - D.left + z.width / 2;
|
|
924
|
+
I = Math.max(T / 2 + 4, I), I = Math.min(D.width - T / 2 - 4, I), f({
|
|
925
|
+
top: z.top - D.top - en,
|
|
926
|
+
left: I
|
|
927
|
+
}), s(!0);
|
|
928
|
+
}, [e, n]);
|
|
929
|
+
return x(() => e.registerCommand(
|
|
930
|
+
ge,
|
|
931
|
+
() => (M(), !1),
|
|
932
|
+
$
|
|
933
|
+
), [e, M]), x(() => e.registerUpdateListener(() => M()), [e, M]), x(() => {
|
|
934
|
+
if (!a && !l) return;
|
|
935
|
+
const N = (A) => {
|
|
936
|
+
i.current && !i.current.contains(A.target) && (c(!1), h(!1));
|
|
937
|
+
};
|
|
938
|
+
return document.addEventListener("mousedown", N), () => document.removeEventListener("mousedown", N);
|
|
939
|
+
}, [a, l]), o ? /* @__PURE__ */ y(
|
|
940
|
+
"div",
|
|
941
|
+
{
|
|
942
|
+
ref: i,
|
|
943
|
+
className: "silk-floating-toolbar",
|
|
944
|
+
style: {
|
|
945
|
+
top: r.top,
|
|
946
|
+
left: r.left,
|
|
947
|
+
transform: "translate(-50%, -100%)"
|
|
948
|
+
},
|
|
949
|
+
onMouseDown: (N) => N.preventDefault(),
|
|
950
|
+
children: [
|
|
951
|
+
/* @__PURE__ */ t(
|
|
952
|
+
"button",
|
|
953
|
+
{
|
|
954
|
+
className: `silk-ft-btn${b.has("bold") ? " silk-ft-btn--active" : ""}`,
|
|
955
|
+
onClick: () => v("bold"),
|
|
956
|
+
type: "button",
|
|
957
|
+
title: "Bold",
|
|
958
|
+
children: /* @__PURE__ */ t("strong", { children: "B" })
|
|
959
|
+
}
|
|
960
|
+
),
|
|
961
|
+
/* @__PURE__ */ t(
|
|
962
|
+
"button",
|
|
963
|
+
{
|
|
964
|
+
className: `silk-ft-btn${b.has("italic") ? " silk-ft-btn--active" : ""}`,
|
|
965
|
+
onClick: () => v("italic"),
|
|
966
|
+
type: "button",
|
|
967
|
+
title: "Italic",
|
|
968
|
+
children: /* @__PURE__ */ t("em", { children: "I" })
|
|
969
|
+
}
|
|
970
|
+
),
|
|
971
|
+
/* @__PURE__ */ t(
|
|
972
|
+
"button",
|
|
973
|
+
{
|
|
974
|
+
className: `silk-ft-btn${b.has("underline") ? " silk-ft-btn--active" : ""}`,
|
|
975
|
+
onClick: () => v("underline"),
|
|
976
|
+
type: "button",
|
|
977
|
+
title: "Underline",
|
|
978
|
+
children: /* @__PURE__ */ t("span", { style: { textDecoration: "underline" }, children: "U" })
|
|
979
|
+
}
|
|
980
|
+
),
|
|
981
|
+
/* @__PURE__ */ t(
|
|
982
|
+
"button",
|
|
983
|
+
{
|
|
984
|
+
className: `silk-ft-btn silk-ft-btn--mono${b.has("code") ? " silk-ft-btn--active" : ""}`,
|
|
985
|
+
onClick: () => v("code"),
|
|
986
|
+
type: "button",
|
|
987
|
+
title: "Inline code",
|
|
988
|
+
children: "</>"
|
|
989
|
+
}
|
|
990
|
+
),
|
|
991
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
992
|
+
/* @__PURE__ */ t(
|
|
993
|
+
"button",
|
|
994
|
+
{
|
|
995
|
+
className: "silk-ft-btn",
|
|
996
|
+
onClick: g,
|
|
997
|
+
type: "button",
|
|
998
|
+
title: "Insert link",
|
|
999
|
+
children: /* @__PURE__ */ y(
|
|
1000
|
+
"svg",
|
|
1001
|
+
{
|
|
1002
|
+
width: "15",
|
|
1003
|
+
height: "15",
|
|
1004
|
+
viewBox: "0 0 24 24",
|
|
1005
|
+
fill: "none",
|
|
1006
|
+
stroke: "currentColor",
|
|
1007
|
+
strokeWidth: 2,
|
|
1008
|
+
strokeLinecap: "round",
|
|
1009
|
+
strokeLinejoin: "round",
|
|
1010
|
+
children: [
|
|
1011
|
+
/* @__PURE__ */ t("path", { d: "M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71" }),
|
|
1012
|
+
/* @__PURE__ */ t("path", { d: "M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71" })
|
|
1013
|
+
]
|
|
1014
|
+
}
|
|
1015
|
+
)
|
|
1016
|
+
}
|
|
1017
|
+
),
|
|
1018
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1019
|
+
/* @__PURE__ */ y("div", { className: "silk-ft-font-size", children: [
|
|
1020
|
+
/* @__PURE__ */ t(
|
|
1021
|
+
"button",
|
|
1022
|
+
{
|
|
1023
|
+
className: "silk-ft-btn silk-ft-btn--sm",
|
|
1024
|
+
onClick: () => p(-1),
|
|
1025
|
+
disabled: m <= re,
|
|
1026
|
+
type: "button",
|
|
1027
|
+
title: "Decrease font size",
|
|
1028
|
+
children: "−"
|
|
1029
|
+
}
|
|
1030
|
+
),
|
|
1031
|
+
/* @__PURE__ */ t("span", { className: "silk-ft-font-size-value", children: m }),
|
|
1032
|
+
/* @__PURE__ */ t(
|
|
1033
|
+
"button",
|
|
1034
|
+
{
|
|
1035
|
+
className: "silk-ft-btn silk-ft-btn--sm",
|
|
1036
|
+
onClick: () => p(1),
|
|
1037
|
+
disabled: m >= se,
|
|
1038
|
+
type: "button",
|
|
1039
|
+
title: "Increase font size",
|
|
1040
|
+
children: "+"
|
|
1041
|
+
}
|
|
1042
|
+
)
|
|
1043
|
+
] }),
|
|
1044
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1045
|
+
/* @__PURE__ */ y("div", { className: "silk-ft-color-wrap", children: [
|
|
1046
|
+
/* @__PURE__ */ t(
|
|
1047
|
+
"button",
|
|
1048
|
+
{
|
|
1049
|
+
className: `silk-ft-btn silk-ft-btn--color${a ? " silk-ft-btn--active" : ""}`,
|
|
1050
|
+
onClick: () => {
|
|
1051
|
+
c(!a), h(!1);
|
|
1052
|
+
},
|
|
1053
|
+
type: "button",
|
|
1054
|
+
title: "Text color",
|
|
1055
|
+
children: /* @__PURE__ */ t(
|
|
1056
|
+
"span",
|
|
1057
|
+
{
|
|
1058
|
+
className: "silk-ft-color-indicator",
|
|
1059
|
+
style: { borderBottomColor: S || "#1a1a1a" },
|
|
1060
|
+
children: "A"
|
|
1061
|
+
}
|
|
1062
|
+
)
|
|
1063
|
+
}
|
|
1064
|
+
),
|
|
1065
|
+
a && /* @__PURE__ */ t("div", { className: "silk-ft-color-grid", children: Ne.map((N) => /* @__PURE__ */ t(
|
|
1066
|
+
"button",
|
|
1067
|
+
{
|
|
1068
|
+
className: `silk-ft-color-swatch${S === N.value || !S && N.value === null ? " silk-ft-color-swatch--active" : ""}`,
|
|
1069
|
+
onClick: () => {
|
|
1070
|
+
d(N.value), c(!1);
|
|
1071
|
+
},
|
|
1072
|
+
type: "button",
|
|
1073
|
+
title: N.label,
|
|
1074
|
+
style: N.value ? { backgroundColor: N.value } : void 0,
|
|
1075
|
+
children: N.value === null && /* @__PURE__ */ y(
|
|
1076
|
+
"svg",
|
|
1077
|
+
{
|
|
1078
|
+
width: "14",
|
|
1079
|
+
height: "14",
|
|
1080
|
+
viewBox: "0 0 24 24",
|
|
1081
|
+
fill: "none",
|
|
1082
|
+
stroke: "currentColor",
|
|
1083
|
+
strokeWidth: 2,
|
|
1084
|
+
children: [
|
|
1085
|
+
/* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1086
|
+
/* @__PURE__ */ t("line", { x1: "4", y1: "4", x2: "20", y2: "20" })
|
|
1087
|
+
]
|
|
1088
|
+
}
|
|
1089
|
+
)
|
|
1090
|
+
},
|
|
1091
|
+
N.value ?? "default"
|
|
1092
|
+
)) })
|
|
1093
|
+
] }),
|
|
1094
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1095
|
+
/* @__PURE__ */ y("div", { className: "silk-ft-font-wrap", children: [
|
|
1096
|
+
/* @__PURE__ */ t(
|
|
1097
|
+
"button",
|
|
1098
|
+
{
|
|
1099
|
+
className: `silk-ft-btn${l ? " silk-ft-btn--active" : ""}`,
|
|
1100
|
+
onClick: () => {
|
|
1101
|
+
h(!l), c(!1);
|
|
1102
|
+
},
|
|
1103
|
+
type: "button",
|
|
1104
|
+
title: "Font family",
|
|
1105
|
+
style: {
|
|
1106
|
+
fontFamily: ((Y = U.find((N) => N.value === u)) == null ? void 0 : Y.css) ?? '"Inter", sans-serif',
|
|
1107
|
+
fontSize: 12,
|
|
1108
|
+
fontWeight: 500
|
|
1109
|
+
},
|
|
1110
|
+
children: "Aa"
|
|
1111
|
+
}
|
|
1112
|
+
),
|
|
1113
|
+
l && /* @__PURE__ */ t("div", { className: "silk-ft-font-dropdown", children: U.map((N) => /* @__PURE__ */ t(
|
|
1114
|
+
"button",
|
|
1115
|
+
{
|
|
1116
|
+
className: `silk-ft-font-option${u === N.value ? " silk-ft-font-option--active" : ""}`,
|
|
1117
|
+
onClick: () => {
|
|
1118
|
+
k(N.value), h(!1);
|
|
1119
|
+
},
|
|
1120
|
+
onMouseDown: (A) => A.preventDefault(),
|
|
1121
|
+
type: "button",
|
|
1122
|
+
style: { fontFamily: N.css },
|
|
1123
|
+
children: N.label
|
|
1124
|
+
},
|
|
1125
|
+
N.label
|
|
1126
|
+
)) })
|
|
1127
|
+
] })
|
|
1128
|
+
]
|
|
1129
|
+
}
|
|
1130
|
+
) : null;
|
|
1131
|
+
}
|
|
1132
|
+
function nn() {
|
|
1133
|
+
var k;
|
|
1134
|
+
const [e] = _(), [n, i] = C(() => e.isEditable()), o = F(null), [s, r] = C(!1), [f, a] = C(!1), {
|
|
1135
|
+
formats: c,
|
|
1136
|
+
fontSize: l,
|
|
1137
|
+
currentColor: h,
|
|
1138
|
+
currentFontFamily: b,
|
|
1139
|
+
toggleFormat: m,
|
|
1140
|
+
changeFontSize: S,
|
|
1141
|
+
applyColor: u,
|
|
1142
|
+
applyFontFamily: v,
|
|
1143
|
+
openLinkDialog: p,
|
|
1144
|
+
insertQuote: d
|
|
1145
|
+
} = Ce();
|
|
1146
|
+
return x(() => e.registerEditableListener(i), [e]), x(() => {
|
|
1147
|
+
if (!s && !f) return;
|
|
1148
|
+
const g = (M) => {
|
|
1149
|
+
o.current && !o.current.contains(M.target) && (r(!1), a(!1));
|
|
1150
|
+
};
|
|
1151
|
+
return document.addEventListener("mousedown", g), () => document.removeEventListener("mousedown", g);
|
|
1152
|
+
}, [s, f]), /* @__PURE__ */ y(
|
|
1153
|
+
"div",
|
|
1154
|
+
{
|
|
1155
|
+
ref: o,
|
|
1156
|
+
className: "silk-toolbar",
|
|
1157
|
+
style: n ? void 0 : { display: "none" },
|
|
1158
|
+
onMouseDown: (g) => g.preventDefault(),
|
|
1159
|
+
children: [
|
|
1160
|
+
/* @__PURE__ */ t(
|
|
1161
|
+
"button",
|
|
1162
|
+
{
|
|
1163
|
+
className: `silk-ft-btn${c.has("bold") ? " silk-ft-btn--active" : ""}`,
|
|
1164
|
+
onClick: () => m("bold"),
|
|
1165
|
+
type: "button",
|
|
1166
|
+
title: "Bold",
|
|
1167
|
+
children: /* @__PURE__ */ t("strong", { children: "B" })
|
|
1168
|
+
}
|
|
1169
|
+
),
|
|
1170
|
+
/* @__PURE__ */ t(
|
|
1171
|
+
"button",
|
|
1172
|
+
{
|
|
1173
|
+
className: `silk-ft-btn${c.has("italic") ? " silk-ft-btn--active" : ""}`,
|
|
1174
|
+
onClick: () => m("italic"),
|
|
1175
|
+
type: "button",
|
|
1176
|
+
title: "Italic",
|
|
1177
|
+
children: /* @__PURE__ */ t("em", { children: "I" })
|
|
1178
|
+
}
|
|
1179
|
+
),
|
|
1180
|
+
/* @__PURE__ */ t(
|
|
1181
|
+
"button",
|
|
1182
|
+
{
|
|
1183
|
+
className: `silk-ft-btn${c.has("underline") ? " silk-ft-btn--active" : ""}`,
|
|
1184
|
+
onClick: () => m("underline"),
|
|
1185
|
+
type: "button",
|
|
1186
|
+
title: "Underline",
|
|
1187
|
+
children: /* @__PURE__ */ t("span", { style: { textDecoration: "underline" }, children: "U" })
|
|
1188
|
+
}
|
|
1189
|
+
),
|
|
1190
|
+
/* @__PURE__ */ t(
|
|
1191
|
+
"button",
|
|
1192
|
+
{
|
|
1193
|
+
className: `silk-ft-btn silk-ft-btn--mono${c.has("code") ? " silk-ft-btn--active" : ""}`,
|
|
1194
|
+
onClick: () => m("code"),
|
|
1195
|
+
type: "button",
|
|
1196
|
+
title: "Inline code",
|
|
1197
|
+
children: "</>"
|
|
1198
|
+
}
|
|
1199
|
+
),
|
|
1200
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1201
|
+
/* @__PURE__ */ t(
|
|
1202
|
+
"button",
|
|
1203
|
+
{
|
|
1204
|
+
className: "silk-ft-btn",
|
|
1205
|
+
onClick: p,
|
|
1206
|
+
type: "button",
|
|
1207
|
+
title: "Insert link",
|
|
1208
|
+
children: /* @__PURE__ */ y(
|
|
1209
|
+
"svg",
|
|
1210
|
+
{
|
|
1211
|
+
width: "15",
|
|
1212
|
+
height: "15",
|
|
1213
|
+
viewBox: "0 0 24 24",
|
|
1214
|
+
fill: "none",
|
|
1215
|
+
stroke: "currentColor",
|
|
1216
|
+
strokeWidth: 2,
|
|
1217
|
+
strokeLinecap: "round",
|
|
1218
|
+
strokeLinejoin: "round",
|
|
1219
|
+
children: [
|
|
1220
|
+
/* @__PURE__ */ t("path", { d: "M10 13a5 5 0 007.54.54l3-3a5 5 0 00-7.07-7.07l-1.72 1.71" }),
|
|
1221
|
+
/* @__PURE__ */ t("path", { d: "M14 11a5 5 0 00-7.54-.54l-3 3a5 5 0 007.07 7.07l1.71-1.71" })
|
|
1222
|
+
]
|
|
1223
|
+
}
|
|
1224
|
+
)
|
|
1225
|
+
}
|
|
1226
|
+
),
|
|
1227
|
+
/* @__PURE__ */ t(
|
|
1228
|
+
"button",
|
|
1229
|
+
{
|
|
1230
|
+
className: "silk-ft-btn",
|
|
1231
|
+
onClick: d,
|
|
1232
|
+
type: "button",
|
|
1233
|
+
title: "Block quote",
|
|
1234
|
+
children: /* @__PURE__ */ y(
|
|
1235
|
+
"svg",
|
|
1236
|
+
{
|
|
1237
|
+
width: "15",
|
|
1238
|
+
height: "15",
|
|
1239
|
+
viewBox: "0 0 24 24",
|
|
1240
|
+
fill: "none",
|
|
1241
|
+
stroke: "currentColor",
|
|
1242
|
+
strokeWidth: 2,
|
|
1243
|
+
strokeLinecap: "round",
|
|
1244
|
+
children: [
|
|
1245
|
+
/* @__PURE__ */ t("line", { x1: "3", y1: "6", x2: "3", y2: "18" }),
|
|
1246
|
+
/* @__PURE__ */ t("line", { x1: "8", y1: "8", x2: "21", y2: "8" }),
|
|
1247
|
+
/* @__PURE__ */ t("line", { x1: "8", y1: "12", x2: "18", y2: "12" }),
|
|
1248
|
+
/* @__PURE__ */ t("line", { x1: "8", y1: "16", x2: "15", y2: "16" })
|
|
1249
|
+
]
|
|
1250
|
+
}
|
|
1251
|
+
)
|
|
1252
|
+
}
|
|
1253
|
+
),
|
|
1254
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1255
|
+
/* @__PURE__ */ y("div", { className: "silk-ft-font-size", children: [
|
|
1256
|
+
/* @__PURE__ */ t(
|
|
1257
|
+
"button",
|
|
1258
|
+
{
|
|
1259
|
+
className: "silk-ft-btn silk-ft-btn--sm",
|
|
1260
|
+
onClick: () => S(-1),
|
|
1261
|
+
disabled: l <= re,
|
|
1262
|
+
type: "button",
|
|
1263
|
+
title: "Decrease font size",
|
|
1264
|
+
children: "−"
|
|
1265
|
+
}
|
|
1266
|
+
),
|
|
1267
|
+
/* @__PURE__ */ t("span", { className: "silk-ft-font-size-value", children: l }),
|
|
1268
|
+
/* @__PURE__ */ t(
|
|
1269
|
+
"button",
|
|
1270
|
+
{
|
|
1271
|
+
className: "silk-ft-btn silk-ft-btn--sm",
|
|
1272
|
+
onClick: () => S(1),
|
|
1273
|
+
disabled: l >= se,
|
|
1274
|
+
type: "button",
|
|
1275
|
+
title: "Increase font size",
|
|
1276
|
+
children: "+"
|
|
1277
|
+
}
|
|
1278
|
+
)
|
|
1279
|
+
] }),
|
|
1280
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1281
|
+
/* @__PURE__ */ y("div", { className: "silk-ft-color-wrap", children: [
|
|
1282
|
+
/* @__PURE__ */ t(
|
|
1283
|
+
"button",
|
|
1284
|
+
{
|
|
1285
|
+
className: `silk-ft-btn silk-ft-btn--color${s ? " silk-ft-btn--active" : ""}`,
|
|
1286
|
+
onClick: () => {
|
|
1287
|
+
r(!s), a(!1);
|
|
1288
|
+
},
|
|
1289
|
+
type: "button",
|
|
1290
|
+
title: "Text color",
|
|
1291
|
+
children: /* @__PURE__ */ t(
|
|
1292
|
+
"span",
|
|
1293
|
+
{
|
|
1294
|
+
className: "silk-ft-color-indicator",
|
|
1295
|
+
style: { borderBottomColor: h || "#1a1a1a" },
|
|
1296
|
+
children: "A"
|
|
1297
|
+
}
|
|
1298
|
+
)
|
|
1299
|
+
}
|
|
1300
|
+
),
|
|
1301
|
+
s && /* @__PURE__ */ t("div", { className: "silk-ft-color-grid", children: Ne.map((g) => /* @__PURE__ */ t(
|
|
1302
|
+
"button",
|
|
1303
|
+
{
|
|
1304
|
+
className: `silk-ft-color-swatch${h === g.value || !h && g.value === null ? " silk-ft-color-swatch--active" : ""}`,
|
|
1305
|
+
onClick: () => {
|
|
1306
|
+
u(g.value), r(!1);
|
|
1307
|
+
},
|
|
1308
|
+
type: "button",
|
|
1309
|
+
title: g.label,
|
|
1310
|
+
style: g.value ? { backgroundColor: g.value } : void 0,
|
|
1311
|
+
children: g.value === null && /* @__PURE__ */ y(
|
|
1312
|
+
"svg",
|
|
1313
|
+
{
|
|
1314
|
+
width: "14",
|
|
1315
|
+
height: "14",
|
|
1316
|
+
viewBox: "0 0 24 24",
|
|
1317
|
+
fill: "none",
|
|
1318
|
+
stroke: "currentColor",
|
|
1319
|
+
strokeWidth: 2,
|
|
1320
|
+
children: [
|
|
1321
|
+
/* @__PURE__ */ t("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1322
|
+
/* @__PURE__ */ t("line", { x1: "4", y1: "4", x2: "20", y2: "20" })
|
|
1323
|
+
]
|
|
1324
|
+
}
|
|
1325
|
+
)
|
|
1326
|
+
},
|
|
1327
|
+
g.value ?? "default"
|
|
1328
|
+
)) })
|
|
1329
|
+
] }),
|
|
1330
|
+
/* @__PURE__ */ t("div", { className: "silk-ft-sep" }),
|
|
1331
|
+
/* @__PURE__ */ y("div", { className: "silk-ft-font-wrap", children: [
|
|
1332
|
+
/* @__PURE__ */ t(
|
|
1333
|
+
"button",
|
|
1334
|
+
{
|
|
1335
|
+
className: `silk-ft-btn${f ? " silk-ft-btn--active" : ""}`,
|
|
1336
|
+
onClick: () => {
|
|
1337
|
+
a(!f), r(!1);
|
|
1338
|
+
},
|
|
1339
|
+
type: "button",
|
|
1340
|
+
title: "Font family",
|
|
1341
|
+
style: {
|
|
1342
|
+
fontFamily: ((k = U.find((g) => g.value === b)) == null ? void 0 : k.css) ?? '"Inter", sans-serif',
|
|
1343
|
+
fontSize: 12,
|
|
1344
|
+
fontWeight: 500
|
|
1345
|
+
},
|
|
1346
|
+
children: "Aa"
|
|
1347
|
+
}
|
|
1348
|
+
),
|
|
1349
|
+
f && /* @__PURE__ */ t("div", { className: "silk-ft-font-dropdown", children: U.map((g) => /* @__PURE__ */ t(
|
|
1350
|
+
"button",
|
|
1351
|
+
{
|
|
1352
|
+
className: `silk-ft-font-option${b === g.value ? " silk-ft-font-option--active" : ""}`,
|
|
1353
|
+
onClick: () => {
|
|
1354
|
+
v(g.value), a(!1);
|
|
1355
|
+
},
|
|
1356
|
+
onMouseDown: (M) => M.preventDefault(),
|
|
1357
|
+
type: "button",
|
|
1358
|
+
style: { fontFamily: g.css },
|
|
1359
|
+
children: g.label
|
|
1360
|
+
},
|
|
1361
|
+
g.label
|
|
1362
|
+
)) })
|
|
1363
|
+
] })
|
|
1364
|
+
]
|
|
1365
|
+
}
|
|
1366
|
+
);
|
|
1367
|
+
}
|
|
1368
|
+
function on() {
|
|
1369
|
+
const [e] = _();
|
|
1370
|
+
return x(() => {
|
|
1371
|
+
const n = e.getRootElement();
|
|
1372
|
+
if (!n) return;
|
|
1373
|
+
const i = (o) => {
|
|
1374
|
+
if (e.isEditable() && !(o.metaKey || o.ctrlKey)) return;
|
|
1375
|
+
const f = o.target.closest("a");
|
|
1376
|
+
!f || !n.contains(f) || e.getEditorState().read(() => {
|
|
1377
|
+
const a = Xe(f);
|
|
1378
|
+
if (!a) return;
|
|
1379
|
+
const c = a.getParent(), l = ce(a) ? a : ce(c) ? c : null;
|
|
1380
|
+
if (l) {
|
|
1381
|
+
const h = l.getURL();
|
|
1382
|
+
h && (o.preventDefault(), window.open(h, "_blank", "noopener,noreferrer"));
|
|
1383
|
+
}
|
|
1384
|
+
});
|
|
1385
|
+
};
|
|
1386
|
+
return n.addEventListener("click", i), () => n.removeEventListener("click", i);
|
|
1387
|
+
}, [e]), null;
|
|
1388
|
+
}
|
|
1389
|
+
function rn() {
|
|
1390
|
+
const [e] = _();
|
|
1391
|
+
return x(() => Pe(e), [e]), /* @__PURE__ */ t(kt, {});
|
|
1392
|
+
}
|
|
1393
|
+
const sn = ["nw", "ne", "sw", "se"];
|
|
1394
|
+
function ln({
|
|
1395
|
+
src: e,
|
|
1396
|
+
altText: n,
|
|
1397
|
+
width: i,
|
|
1398
|
+
height: o,
|
|
1399
|
+
nodeKey: s
|
|
1400
|
+
}) {
|
|
1401
|
+
const [r] = _(), f = F(null), a = F(null), [c, l, h] = lt(s), [b, m] = C(!1), S = w(
|
|
1402
|
+
(d) => f.current && f.current.contains(d.target) ? (h(), l(!0), !0) : !1,
|
|
1403
|
+
[h, l]
|
|
1404
|
+
), u = w(
|
|
1405
|
+
(d) => c && !b ? (d.preventDefault(), r.update(() => {
|
|
1406
|
+
const k = H(s);
|
|
1407
|
+
k && k.remove();
|
|
1408
|
+
}), !0) : !1,
|
|
1409
|
+
[r, c, b, s]
|
|
1410
|
+
);
|
|
1411
|
+
x(() => {
|
|
1412
|
+
const d = r.registerCommand(
|
|
1413
|
+
et,
|
|
1414
|
+
S,
|
|
1415
|
+
$
|
|
1416
|
+
), k = r.registerCommand(
|
|
1417
|
+
tt,
|
|
1418
|
+
u,
|
|
1419
|
+
$
|
|
1420
|
+
), g = r.registerCommand(
|
|
1421
|
+
nt,
|
|
1422
|
+
u,
|
|
1423
|
+
$
|
|
1424
|
+
);
|
|
1425
|
+
return () => {
|
|
1426
|
+
d(), k(), g();
|
|
1427
|
+
};
|
|
1428
|
+
}, [r, S, u]);
|
|
1429
|
+
const v = w(
|
|
1430
|
+
(d, k) => {
|
|
1431
|
+
k.preventDefault(), k.stopPropagation(), m(!0);
|
|
1432
|
+
const g = a.current;
|
|
1433
|
+
if (!g) return;
|
|
1434
|
+
const M = k.clientX, Y = k.clientY, N = g.offsetWidth, A = g.offsetHeight, P = N / A, Q = (B) => {
|
|
1435
|
+
let D = B.clientX - M;
|
|
1436
|
+
const R = B.clientY - Y;
|
|
1437
|
+
(d === "nw" || d === "sw") && (D = -D);
|
|
1438
|
+
let T;
|
|
1439
|
+
if (Math.abs(D) > Math.abs(R))
|
|
1440
|
+
T = Math.max(100, N + D);
|
|
1441
|
+
else {
|
|
1442
|
+
const K = d === "nw" || d === "ne" ? -R : R;
|
|
1443
|
+
T = Math.max(100, N + K * P);
|
|
1444
|
+
}
|
|
1445
|
+
const I = T / P;
|
|
1446
|
+
g.style.width = `${Math.round(T)}px`, g.style.height = `${Math.round(I)}px`;
|
|
1447
|
+
}, z = (B) => {
|
|
1448
|
+
document.removeEventListener("mousemove", Q), document.removeEventListener("mouseup", z), m(!1);
|
|
1449
|
+
const D = g.offsetWidth, R = g.offsetHeight;
|
|
1450
|
+
r.update(() => {
|
|
1451
|
+
const T = H(s);
|
|
1452
|
+
if (T && an(T)) {
|
|
1453
|
+
const I = T.getWritable();
|
|
1454
|
+
I.__width = D, I.__height = R;
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
document.addEventListener("mousemove", Q), document.addEventListener("mouseup", z);
|
|
1459
|
+
},
|
|
1460
|
+
[r, s]
|
|
1461
|
+
), p = r.isEditable();
|
|
1462
|
+
return /* @__PURE__ */ y(
|
|
1463
|
+
"div",
|
|
1464
|
+
{
|
|
1465
|
+
ref: f,
|
|
1466
|
+
className: `silk-image-container${c ? " silk-image-container--selected" : ""}`,
|
|
1467
|
+
children: [
|
|
1468
|
+
/* @__PURE__ */ t(
|
|
1469
|
+
"img",
|
|
1470
|
+
{
|
|
1471
|
+
ref: a,
|
|
1472
|
+
src: e,
|
|
1473
|
+
alt: n,
|
|
1474
|
+
width: i,
|
|
1475
|
+
height: o,
|
|
1476
|
+
className: "silk-image",
|
|
1477
|
+
draggable: !1
|
|
1478
|
+
}
|
|
1479
|
+
),
|
|
1480
|
+
c && p && /* @__PURE__ */ t(te, { children: sn.map((d) => /* @__PURE__ */ t(
|
|
1481
|
+
"div",
|
|
1482
|
+
{
|
|
1483
|
+
className: `silk-image-handle silk-image-handle--${d}`,
|
|
1484
|
+
onMouseDown: (k) => v(d, k)
|
|
1485
|
+
},
|
|
1486
|
+
d
|
|
1487
|
+
)) })
|
|
1488
|
+
]
|
|
1489
|
+
}
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
class V extends Ze {
|
|
1493
|
+
static getType() {
|
|
1494
|
+
return "image";
|
|
1495
|
+
}
|
|
1496
|
+
static clone(n) {
|
|
1497
|
+
return new V(
|
|
1498
|
+
n.__src,
|
|
1499
|
+
n.__altText,
|
|
1500
|
+
n.__width,
|
|
1501
|
+
n.__height,
|
|
1502
|
+
n.__key
|
|
1503
|
+
);
|
|
1504
|
+
}
|
|
1505
|
+
constructor(n, i, o, s, r) {
|
|
1506
|
+
super(r), this.__src = n, this.__altText = i, this.__width = o, this.__height = s;
|
|
1507
|
+
}
|
|
1508
|
+
createDOM() {
|
|
1509
|
+
const n = document.createElement("div");
|
|
1510
|
+
return n.className = "silk-image-wrapper", n;
|
|
1511
|
+
}
|
|
1512
|
+
updateDOM() {
|
|
1513
|
+
return !1;
|
|
1514
|
+
}
|
|
1515
|
+
isInline() {
|
|
1516
|
+
return !1;
|
|
1517
|
+
}
|
|
1518
|
+
isKeyboardSelectable() {
|
|
1519
|
+
return !0;
|
|
1520
|
+
}
|
|
1521
|
+
static importJSON(n) {
|
|
1522
|
+
return ee(
|
|
1523
|
+
n.src,
|
|
1524
|
+
n.altText,
|
|
1525
|
+
n.width,
|
|
1526
|
+
n.height
|
|
1527
|
+
);
|
|
1528
|
+
}
|
|
1529
|
+
exportJSON() {
|
|
1530
|
+
return {
|
|
1531
|
+
...super.exportJSON(),
|
|
1532
|
+
src: this.__src,
|
|
1533
|
+
altText: this.__altText,
|
|
1534
|
+
width: this.__width,
|
|
1535
|
+
height: this.__height
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
exportDOM() {
|
|
1539
|
+
const n = document.createElement("img");
|
|
1540
|
+
return n.src = this.__src, n.alt = this.__altText, this.__width && (n.width = this.__width), this.__height && (n.height = this.__height), { element: n };
|
|
1541
|
+
}
|
|
1542
|
+
static importDOM() {
|
|
1543
|
+
return {
|
|
1544
|
+
img: () => ({
|
|
1545
|
+
conversion: (n) => {
|
|
1546
|
+
const i = n;
|
|
1547
|
+
return {
|
|
1548
|
+
node: ee(
|
|
1549
|
+
i.src,
|
|
1550
|
+
i.alt || "",
|
|
1551
|
+
i.naturalWidth || void 0,
|
|
1552
|
+
i.naturalHeight || void 0
|
|
1553
|
+
)
|
|
1554
|
+
};
|
|
1555
|
+
},
|
|
1556
|
+
priority: 0
|
|
1557
|
+
})
|
|
1558
|
+
};
|
|
1559
|
+
}
|
|
1560
|
+
decorate(n) {
|
|
1561
|
+
return /* @__PURE__ */ t(
|
|
1562
|
+
ln,
|
|
1563
|
+
{
|
|
1564
|
+
src: this.__src,
|
|
1565
|
+
altText: this.__altText,
|
|
1566
|
+
width: this.__width,
|
|
1567
|
+
height: this.__height,
|
|
1568
|
+
nodeKey: this.__key
|
|
1569
|
+
}
|
|
1570
|
+
);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
function ee(e, n = "", i, o) {
|
|
1574
|
+
return qe(new V(e, n, i, o));
|
|
1575
|
+
}
|
|
1576
|
+
function an(e) {
|
|
1577
|
+
return e instanceof V;
|
|
1578
|
+
}
|
|
1579
|
+
function fe(e) {
|
|
1580
|
+
return e.type.startsWith("image/");
|
|
1581
|
+
}
|
|
1582
|
+
function cn(e) {
|
|
1583
|
+
return new Promise((n, i) => {
|
|
1584
|
+
const o = new FileReader();
|
|
1585
|
+
o.onload = () => n(o.result), o.onerror = () => i(o.error), o.readAsDataURL(e);
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
function dn() {
|
|
1589
|
+
const [e] = _();
|
|
1590
|
+
return x(() => {
|
|
1591
|
+
const n = (r) => {
|
|
1592
|
+
for (const f of r)
|
|
1593
|
+
cn(f).then((a) => {
|
|
1594
|
+
e.update(() => {
|
|
1595
|
+
const c = ee(a, f.name), l = E();
|
|
1596
|
+
if (L(l))
|
|
1597
|
+
l.focus.getNode().getTopLevelElementOrThrow().insertAfter(c);
|
|
1598
|
+
else if (st(l)) {
|
|
1599
|
+
const h = l.getNodes(), m = h[h.length - 1].getTopLevelElement();
|
|
1600
|
+
m ? m.insertAfter(c) : de().append(c);
|
|
1601
|
+
} else
|
|
1602
|
+
de().append(c);
|
|
1603
|
+
});
|
|
1604
|
+
});
|
|
1605
|
+
}, i = e.registerCommand(
|
|
1606
|
+
ot,
|
|
1607
|
+
(r) => {
|
|
1608
|
+
var c;
|
|
1609
|
+
const f = (c = r.clipboardData) == null ? void 0 : c.files;
|
|
1610
|
+
if (!f || f.length === 0) return !1;
|
|
1611
|
+
const a = Array.from(f).filter(fe);
|
|
1612
|
+
return a.length === 0 ? !1 : (r.preventDefault(), n(a), !0);
|
|
1613
|
+
},
|
|
1614
|
+
X
|
|
1615
|
+
), o = e.registerCommand(
|
|
1616
|
+
it,
|
|
1617
|
+
(r) => {
|
|
1618
|
+
var c;
|
|
1619
|
+
const f = (c = r.dataTransfer) == null ? void 0 : c.files;
|
|
1620
|
+
if (!f || f.length === 0) return !1;
|
|
1621
|
+
const a = Array.from(f).filter(fe);
|
|
1622
|
+
return a.length === 0 ? !1 : (r.preventDefault(), n(a), !0);
|
|
1623
|
+
},
|
|
1624
|
+
X
|
|
1625
|
+
), s = e.registerCommand(
|
|
1626
|
+
rt,
|
|
1627
|
+
(r) => {
|
|
1628
|
+
var a;
|
|
1629
|
+
const f = (a = r.dataTransfer) == null ? void 0 : a.types;
|
|
1630
|
+
return f && f.includes("Files") ? (r.preventDefault(), !0) : !1;
|
|
1631
|
+
},
|
|
1632
|
+
X
|
|
1633
|
+
);
|
|
1634
|
+
return () => {
|
|
1635
|
+
i(), o(), s();
|
|
1636
|
+
};
|
|
1637
|
+
}, [e]), null;
|
|
1638
|
+
}
|
|
1639
|
+
const un = {
|
|
1640
|
+
root: "silk-root",
|
|
1641
|
+
paragraph: "silk-paragraph",
|
|
1642
|
+
link: "silk-link",
|
|
1643
|
+
hr: "silk-hr",
|
|
1644
|
+
list: {
|
|
1645
|
+
ul: "silk-list-ul",
|
|
1646
|
+
ol: "silk-list-ol",
|
|
1647
|
+
listitem: "silk-list-item",
|
|
1648
|
+
nested: {
|
|
1649
|
+
listitem: "silk-list-item-nested"
|
|
1650
|
+
},
|
|
1651
|
+
listitemChecked: "silk-list-item-checked",
|
|
1652
|
+
listitemUnchecked: "silk-list-item-unchecked"
|
|
1653
|
+
},
|
|
1654
|
+
image: "silk-image-wrapper",
|
|
1655
|
+
text: {
|
|
1656
|
+
bold: "silk-text-bold",
|
|
1657
|
+
italic: "silk-text-italic",
|
|
1658
|
+
underline: "silk-text-underline",
|
|
1659
|
+
strikethrough: "silk-text-strikethrough",
|
|
1660
|
+
code: "silk-text-code"
|
|
1661
|
+
}
|
|
1662
|
+
}, fn = {
|
|
1663
|
+
heading: {
|
|
1664
|
+
h1: "silk-heading-h1",
|
|
1665
|
+
h2: "silk-heading-h2",
|
|
1666
|
+
h3: "silk-heading-h3"
|
|
1667
|
+
},
|
|
1668
|
+
quote: "silk-quote"
|
|
1669
|
+
}, hn = {
|
|
1670
|
+
code: "silk-code-block"
|
|
1671
|
+
};
|
|
1672
|
+
function pn(...e) {
|
|
1673
|
+
const n = {};
|
|
1674
|
+
for (const i of e)
|
|
1675
|
+
for (const [o, s] of Object.entries(i)) {
|
|
1676
|
+
const r = n[o];
|
|
1677
|
+
r && typeof r == "object" && typeof s == "object" && !Array.isArray(r) && !Array.isArray(s) ? n[o] = { ...r, ...s } : n[o] = s;
|
|
1678
|
+
}
|
|
1679
|
+
return n;
|
|
1680
|
+
}
|
|
1681
|
+
function mn(e, n) {
|
|
1682
|
+
const i = [un];
|
|
1683
|
+
return e.richText !== !1 && i.push(fn), e.code !== !1 && i.push(hn), n && i.push(n), pn(...i);
|
|
1684
|
+
}
|
|
1685
|
+
function gn(e) {
|
|
1686
|
+
const n = [];
|
|
1687
|
+
return e.richText !== !1 && n.push(Ie, Oe), e.code !== !1 && n.push(pe, Fe), e.lists !== !1 && n.push(ze, Be), n.push(W, Ue, Ge, V), n;
|
|
1688
|
+
}
|
|
1689
|
+
function kn({ editable: e }) {
|
|
1690
|
+
const [n] = _();
|
|
1691
|
+
return x(() => {
|
|
1692
|
+
n.setEditable(e);
|
|
1693
|
+
}, [n, e]), null;
|
|
1694
|
+
}
|
|
1695
|
+
const bn = {
|
|
1696
|
+
history: !0,
|
|
1697
|
+
richText: !0,
|
|
1698
|
+
dragon: !0,
|
|
1699
|
+
code: !0,
|
|
1700
|
+
lists: !0
|
|
1701
|
+
};
|
|
1702
|
+
function Vn({
|
|
1703
|
+
features: e,
|
|
1704
|
+
namespace: n = "silk-editor",
|
|
1705
|
+
className: i,
|
|
1706
|
+
theme: o,
|
|
1707
|
+
editable: s = !0,
|
|
1708
|
+
onError: r,
|
|
1709
|
+
onChange: f,
|
|
1710
|
+
initialEditorState: a
|
|
1711
|
+
}) {
|
|
1712
|
+
const c = F(null), l = {
|
|
1713
|
+
...bn,
|
|
1714
|
+
...e
|
|
1715
|
+
}, h = mn(l, o), b = gn(l), m = w(
|
|
1716
|
+
(u) => {
|
|
1717
|
+
f && f(JSON.stringify(u.toJSON()));
|
|
1718
|
+
},
|
|
1719
|
+
[f]
|
|
1720
|
+
);
|
|
1721
|
+
return /* @__PURE__ */ t(Me, { initialConfig: {
|
|
1722
|
+
namespace: n,
|
|
1723
|
+
theme: h,
|
|
1724
|
+
nodes: b,
|
|
1725
|
+
editable: s,
|
|
1726
|
+
editorState: a ?? void 0,
|
|
1727
|
+
onError: r ?? ((u) => console.error(u))
|
|
1728
|
+
}, children: /* @__PURE__ */ t(ke.Provider, { value: c, children: /* @__PURE__ */ y(
|
|
1729
|
+
"div",
|
|
1730
|
+
{
|
|
1731
|
+
ref: c,
|
|
1732
|
+
className: `silk-editor-container${i ? ` ${i}` : ""}`,
|
|
1733
|
+
children: [
|
|
1734
|
+
/* @__PURE__ */ t(nn, {}),
|
|
1735
|
+
l.richText && /* @__PURE__ */ t(Mt, {}),
|
|
1736
|
+
l.history && /* @__PURE__ */ t(_t, {}),
|
|
1737
|
+
l.dragon && /* @__PURE__ */ t(Et, {}),
|
|
1738
|
+
l.code && /* @__PURE__ */ t(It, {}),
|
|
1739
|
+
l.lists && /* @__PURE__ */ t(rn, {}),
|
|
1740
|
+
/* @__PURE__ */ t(Te, {}),
|
|
1741
|
+
/* @__PURE__ */ t(Le, {}),
|
|
1742
|
+
/* @__PURE__ */ t(Qt, {}),
|
|
1743
|
+
/* @__PURE__ */ t(Ot, {}),
|
|
1744
|
+
/* @__PURE__ */ t(qt, {}),
|
|
1745
|
+
/* @__PURE__ */ t(on, {}),
|
|
1746
|
+
/* @__PURE__ */ t(dn, {}),
|
|
1747
|
+
/* @__PURE__ */ t(kn, { editable: s }),
|
|
1748
|
+
f && /* @__PURE__ */ t(Ee, { onChange: m, ignoreSelectionChange: !0 }),
|
|
1749
|
+
/* @__PURE__ */ t(Yt, {}),
|
|
1750
|
+
/* @__PURE__ */ t(tn, {})
|
|
1751
|
+
]
|
|
1752
|
+
}
|
|
1753
|
+
) }) });
|
|
1754
|
+
}
|
|
1755
|
+
export {
|
|
1756
|
+
ee as $createImageNode,
|
|
1757
|
+
be as $createNoteNode,
|
|
1758
|
+
an as $isImageNode,
|
|
1759
|
+
ye as $isNoteNode,
|
|
1760
|
+
V as ImageNode,
|
|
1761
|
+
W as NoteNode,
|
|
1762
|
+
Vn as SilkEditor,
|
|
1763
|
+
Vn as default
|
|
1764
|
+
};
|