@flexiui/svelte-rich-text 0.0.21 → 0.0.23
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/dist/RichText.svelte +26 -38
- package/dist/extensions/NodeLineHeight.d.ts +1 -1
- package/dist/extensions/NodeLineHeight.js +26 -17
- package/dist/styles.css +14 -5
- package/package.json +1 -1
package/dist/RichText.svelte
CHANGED
|
@@ -13,8 +13,6 @@
|
|
|
13
13
|
|
|
14
14
|
import { createEditor, Editor, EditorContent } from "svelte-tiptap";
|
|
15
15
|
|
|
16
|
-
import { Paragraph } from "@tiptap/extension-paragraph";
|
|
17
|
-
import { Heading } from "@tiptap/extension-heading";
|
|
18
16
|
import StarterKit from "@tiptap/starter-kit";
|
|
19
17
|
import Highlight from "@tiptap/extension-highlight";
|
|
20
18
|
import TextAlign from "@tiptap/extension-text-align";
|
|
@@ -79,20 +77,12 @@
|
|
|
79
77
|
// Disable an included extension
|
|
80
78
|
trailingNode: false,
|
|
81
79
|
link: false,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
80
|
+
bulletList: false,
|
|
81
|
+
listItem: false,
|
|
82
|
+
orderedList: false,
|
|
83
|
+
listKeymap: false,
|
|
86
84
|
}),
|
|
87
|
-
Underline,
|
|
88
85
|
EnhancedLink,
|
|
89
|
-
Link.configure({
|
|
90
|
-
openOnClick: false,
|
|
91
|
-
HTMLAttributes: {
|
|
92
|
-
target: "_self",
|
|
93
|
-
rel: "noopener noreferrer",
|
|
94
|
-
},
|
|
95
|
-
}),
|
|
96
86
|
ListKit,
|
|
97
87
|
TextAlign.configure({
|
|
98
88
|
types: [
|
|
@@ -234,7 +224,6 @@
|
|
|
234
224
|
},
|
|
235
225
|
handleKeyDown: (view, event) => {
|
|
236
226
|
if (event.key === "Enter" && !event.ctrlKey) {
|
|
237
|
-
console.log("Enter");
|
|
238
227
|
enterPressed = true;
|
|
239
228
|
|
|
240
229
|
setTimeout(() => {
|
|
@@ -246,8 +235,8 @@
|
|
|
246
235
|
const nodeBefore = pos.node(pos.depth);
|
|
247
236
|
const parentNode = pos.node(pos.depth - 1);
|
|
248
237
|
|
|
249
|
-
console.log("Node type:", nodeBefore.type.name);
|
|
250
|
-
console.log("Parent node type:", parentNode?.type.name);
|
|
238
|
+
// console.log("Node type:", nodeBefore.type.name);
|
|
239
|
+
// console.log("Parent node type:", parentNode?.type.name);
|
|
251
240
|
|
|
252
241
|
// Solo ejecutar si estamos en un párrafo Y el padre no es una lista
|
|
253
242
|
const isInList = parentNode?.type.name === "listItem" ||
|
|
@@ -265,14 +254,14 @@
|
|
|
265
254
|
if (element instanceof HTMLElement) {
|
|
266
255
|
const computedSize = window.getComputedStyle(element).fontSize;
|
|
267
256
|
const computedLineHeight = window.getComputedStyle(element).lineHeight;
|
|
268
|
-
console.log({ computedSize, computedLineHeight });
|
|
257
|
+
// console.log({ computedSize, computedLineHeight });
|
|
269
258
|
|
|
270
259
|
const lineHeightPx = parseFloat(computedLineHeight.replace("px", ""))
|
|
271
260
|
const fontSizePx = parseFloat(computedSize.replace("px", ""))
|
|
272
261
|
|
|
273
262
|
const lineHeightUnitless = lineHeightPx / fontSizePx;
|
|
274
263
|
|
|
275
|
-
console.log(lineHeightUnitless.toFixed(2)); // ej: "x.xx"
|
|
264
|
+
// console.log(lineHeightUnitless.toFixed(2)); // ej: "x.xx"
|
|
276
265
|
|
|
277
266
|
fontSize = Math.round(Number(computedSize.replace("px", "")));
|
|
278
267
|
$editor.chain().focus().unsetFontSize().run();
|
|
@@ -289,7 +278,7 @@
|
|
|
289
278
|
editor = editor;
|
|
290
279
|
|
|
291
280
|
if (enterPressed) {
|
|
292
|
-
console.log("Enter pressed");
|
|
281
|
+
// console.log("Enter pressed");
|
|
293
282
|
return;
|
|
294
283
|
}
|
|
295
284
|
|
|
@@ -308,19 +297,19 @@
|
|
|
308
297
|
if (element instanceof HTMLElement) {
|
|
309
298
|
const computedSize = window.getComputedStyle(element).fontSize;
|
|
310
299
|
const computedLineHeight = window.getComputedStyle(element).lineHeight;
|
|
311
|
-
console.log("Get element font size:", computedSize);
|
|
312
|
-
console.log("Get element line height:", computedLineHeight);
|
|
300
|
+
// console.log("Get element font size:", computedSize);
|
|
301
|
+
// console.log("Get element line height:", computedLineHeight);
|
|
313
302
|
const lineHeightPx = parseFloat(computedLineHeight.replace("px", ""))
|
|
314
303
|
const fontSizePx = parseFloat(computedSize.replace("px", ""))
|
|
315
304
|
const lineHeightUnitless = lineHeightPx / fontSizePx;
|
|
316
305
|
|
|
317
|
-
console.log(lineHeightUnitless.toFixed(2)); // ej: "x.xx"
|
|
306
|
+
// console.log(lineHeightUnitless.toFixed(2)); // ej: "x.xx"
|
|
318
307
|
|
|
319
308
|
// O desde Tiptap
|
|
320
309
|
const tiptapSize = editor.getAttributes("textStyle").fontSize;
|
|
321
310
|
const tiptapLineHeight = editor.getAttributes("textStyle").lineHeight;
|
|
322
|
-
console.log("Tiptap font size:", tiptapSize ? tiptapSize : "default");
|
|
323
|
-
console.log("Tiptap line height:", tiptapLineHeight ? tiptapLineHeight : "default");
|
|
311
|
+
// console.log("Tiptap font size:", tiptapSize ? tiptapSize : "default");
|
|
312
|
+
// console.log("Tiptap line height:", tiptapLineHeight ? tiptapLineHeight : "default");
|
|
324
313
|
|
|
325
314
|
if (tiptapSize) {
|
|
326
315
|
fontSize = Number(tiptapSize.replace("px", ""));
|
|
@@ -483,14 +472,11 @@
|
|
|
483
472
|
}
|
|
484
473
|
|
|
485
474
|
function handleRangeInput(e: any) {
|
|
486
|
-
|
|
487
|
-
|
|
475
|
+
|
|
488
476
|
|
|
489
477
|
$editor
|
|
490
|
-
.
|
|
491
|
-
.
|
|
492
|
-
.setNodeLineHeight(e.target.value.toString())
|
|
493
|
-
.run();
|
|
478
|
+
.commands
|
|
479
|
+
.setNodeLineHeight(lineHeight.toString())
|
|
494
480
|
|
|
495
481
|
}
|
|
496
482
|
</script>
|
|
@@ -822,20 +808,22 @@
|
|
|
822
808
|
</div>
|
|
823
809
|
|
|
824
810
|
<!-- Font size editor -->
|
|
825
|
-
<div role="group" class="fl-rich-text-toolbar-group
|
|
826
|
-
<div class="fl-font-size-editor
|
|
811
|
+
<div role="group" class="fl-rich-text-toolbar-group">
|
|
812
|
+
<div class="fl-font-size-editor">
|
|
827
813
|
<button
|
|
828
|
-
type="button"
|
|
829
814
|
aria-label="Decrease font size"
|
|
830
815
|
onclick={decrementFontSize}
|
|
831
|
-
class="fl-font-size-editor-button"
|
|
816
|
+
class="fl-font-size-editor-button">
|
|
817
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-minus"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M5 12l14 0" /></svg>
|
|
818
|
+
</button
|
|
832
819
|
>
|
|
833
820
|
<input type="text" bind:value={fontSize} />
|
|
834
821
|
<button
|
|
835
|
-
type="button"
|
|
836
822
|
aria-label="Increase font size"
|
|
837
823
|
onclick={incrementFontSize}
|
|
838
|
-
class="fl-font-size-editor-button"
|
|
824
|
+
class="fl-font-size-editor-button">
|
|
825
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-plus"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M12 5l0 14" /><path d="M5 12l14 0" /></svg>
|
|
826
|
+
</button
|
|
839
827
|
>
|
|
840
828
|
</div>
|
|
841
829
|
</div>
|
|
@@ -1815,7 +1803,7 @@
|
|
|
1815
1803
|
<span class="fl-range-element-value">
|
|
1816
1804
|
{lineHeight.toFixed(2)}
|
|
1817
1805
|
</span>
|
|
1818
|
-
<input oninput={handleRangeInput} type="range" min="0.5" max="4" step="0.
|
|
1806
|
+
<input oninput={handleRangeInput} type="range" min="0.5" max="4" step="0.05" bind:value={lineHeight}>
|
|
1819
1807
|
</div>
|
|
1820
1808
|
|
|
1821
1809
|
{/if}
|
|
@@ -1,24 +1,17 @@
|
|
|
1
|
-
import { Extension } from
|
|
1
|
+
import { Extension } from "@tiptap/core";
|
|
2
2
|
export const NodeLineHeight = Extension.create({
|
|
3
|
-
name:
|
|
4
|
-
addOptions() {
|
|
5
|
-
return {
|
|
6
|
-
types: ['paragraph', 'heading'], // Aplica a párrafos y encabezados
|
|
7
|
-
defaultLineHeight: 'normal',
|
|
8
|
-
};
|
|
9
|
-
},
|
|
3
|
+
name: "nodeLineHeight",
|
|
10
4
|
addGlobalAttributes() {
|
|
11
5
|
return [
|
|
12
6
|
{
|
|
13
|
-
types:
|
|
7
|
+
types: ["paragraph", "heading"],
|
|
14
8
|
attributes: {
|
|
15
9
|
lineHeight: {
|
|
16
|
-
default:
|
|
17
|
-
parseHTML: element => element.style.lineHeight ||
|
|
10
|
+
default: null,
|
|
11
|
+
parseHTML: element => element.style.lineHeight || null,
|
|
18
12
|
renderHTML: attributes => {
|
|
19
|
-
if (!attributes.lineHeight
|
|
13
|
+
if (!attributes.lineHeight)
|
|
20
14
|
return {};
|
|
21
|
-
}
|
|
22
15
|
return {
|
|
23
16
|
style: `line-height: ${attributes.lineHeight}`,
|
|
24
17
|
};
|
|
@@ -30,12 +23,28 @@ export const NodeLineHeight = Extension.create({
|
|
|
30
23
|
},
|
|
31
24
|
addCommands() {
|
|
32
25
|
return {
|
|
33
|
-
setNodeLineHeight: (lineHeight) => ({ commands }) => {
|
|
34
|
-
|
|
26
|
+
setNodeLineHeight: (lineHeight) => ({ state, commands }) => {
|
|
27
|
+
const { $from } = state.selection;
|
|
28
|
+
for (let d = $from.depth; d > 0; d--) {
|
|
29
|
+
const node = $from.node(d);
|
|
30
|
+
if (node.type.name === "paragraph") {
|
|
31
|
+
return commands.updateAttributes("paragraph", {
|
|
32
|
+
lineHeight,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
if (node.type.name === "heading") {
|
|
36
|
+
return commands.updateAttributes("heading", {
|
|
37
|
+
lineHeight,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
35
42
|
},
|
|
36
43
|
unsetNodeLineHeight: () => ({ commands }) => {
|
|
37
|
-
return
|
|
44
|
+
return commands.updateAttributes("paragraph", {
|
|
45
|
+
lineHeight: null,
|
|
46
|
+
});
|
|
38
47
|
},
|
|
39
48
|
};
|
|
40
|
-
}
|
|
49
|
+
}
|
|
41
50
|
});
|
package/dist/styles.css
CHANGED
|
@@ -398,9 +398,10 @@
|
|
|
398
398
|
display: flex;
|
|
399
399
|
align-items: center;
|
|
400
400
|
gap: 4px;
|
|
401
|
-
padding: 0
|
|
401
|
+
padding: 0 6px;
|
|
402
402
|
border-radius: 8px;
|
|
403
403
|
background: rgba(255, 255, 255, 0.1);
|
|
404
|
+
min-height: 32px;
|
|
404
405
|
|
|
405
406
|
& button {
|
|
406
407
|
background: transparent;
|
|
@@ -410,23 +411,31 @@
|
|
|
410
411
|
justify-content: center;
|
|
411
412
|
padding: 2px;
|
|
412
413
|
backdrop-filter: blur(5px);
|
|
413
|
-
border-radius: 8px;
|
|
414
414
|
cursor: pointer;
|
|
415
|
+
min-height: 18px;
|
|
416
|
+
min-width: 18px;
|
|
417
|
+
border-radius: 100%;
|
|
418
|
+
background: #474747;
|
|
419
|
+
|
|
420
|
+
&:hover {
|
|
421
|
+
background: rgb(104, 104, 104);
|
|
422
|
+
}
|
|
415
423
|
|
|
416
424
|
& svg {
|
|
417
|
-
width:
|
|
418
|
-
height:
|
|
425
|
+
width: 12px;
|
|
426
|
+
height: 12px;
|
|
419
427
|
}
|
|
420
428
|
}
|
|
421
429
|
|
|
422
430
|
input {
|
|
423
|
-
width:
|
|
431
|
+
width: 28px;
|
|
424
432
|
text-align: center;
|
|
425
433
|
border: none;
|
|
426
434
|
background: transparent;
|
|
427
435
|
color: var(--text-color);
|
|
428
436
|
font-size: 14px;
|
|
429
437
|
padding: 0;
|
|
438
|
+
outline: none;
|
|
430
439
|
}
|
|
431
440
|
}
|
|
432
441
|
|