@flexiui/svelte-rich-text 0.0.22 → 0.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- // bulletList: false,
83
- // listItem: false,
84
- // orderedList: false,
85
- // listKeymap: false,
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
- .chain()
491
- .focus()
492
- .setNodeLineHeight(e.target.value.toString())
493
- .run();
478
+ .commands
479
+ .setNodeLineHeight(lineHeight.toString())
494
480
 
495
481
  }
496
482
  </script>
@@ -828,14 +814,18 @@
828
814
  type="button"
829
815
  aria-label="Decrease font size"
830
816
  onclick={decrementFontSize}
831
- class="fl-font-size-editor-button">-</button
817
+ class="fl-font-size-editor-button">
818
+ <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>
819
+ </button
832
820
  >
833
821
  <input type="text" bind:value={fontSize} />
834
822
  <button
835
823
  type="button"
836
824
  aria-label="Increase font size"
837
825
  onclick={incrementFontSize}
838
- class="fl-font-size-editor-button">+</button
826
+ class="fl-font-size-editor-button">
827
+ <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>
828
+ </button
839
829
  >
840
830
  </div>
841
831
  </div>
@@ -1815,7 +1805,7 @@
1815
1805
  <span class="fl-range-element-value">
1816
1806
  {lineHeight.toFixed(2)}
1817
1807
  </span>
1818
- <input oninput={handleRangeInput} type="range" min="0.5" max="4" step="0.01" bind:value={lineHeight}>
1808
+ <input oninput={handleRangeInput} type="range" min="0.5" max="4" step="0.05" bind:value={lineHeight}>
1819
1809
  </div>
1820
1810
 
1821
1811
  {/if}
@@ -1,4 +1,4 @@
1
- import { Extension } from '@tiptap/core';
1
+ import { Extension } from "@tiptap/core";
2
2
  declare module '@tiptap/core' {
3
3
  interface Commands<ReturnType> {
4
4
  lineHeight: {
@@ -1,24 +1,17 @@
1
- import { Extension } from '@tiptap/core';
1
+ import { Extension } from "@tiptap/core";
2
2
  export const NodeLineHeight = Extension.create({
3
- name: 'nodeLineHeight',
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: this.options.types,
7
+ types: ["paragraph", "heading"],
14
8
  attributes: {
15
9
  lineHeight: {
16
- default: this.options.defaultLineHeight,
17
- parseHTML: element => element.style.lineHeight || this.options.defaultLineHeight,
10
+ default: null,
11
+ parseHTML: element => element.style.lineHeight || null,
18
12
  renderHTML: attributes => {
19
- if (!attributes.lineHeight || attributes.lineHeight === this.options.defaultLineHeight) {
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
- return this.options.types.every((type) => commands.updateAttributes(type, { lineHeight }));
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 this.options.types.every((type) => commands.resetAttributes(type, 'lineHeight'));
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 8px;
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: 18px;
418
- height: 18px;
425
+ width: 12px;
426
+ height: 12px;
419
427
  }
420
428
  }
421
429
 
422
430
  input {
423
- width: 32px;
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexiui/svelte-rich-text",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "description": "A lightweight and flexible rich text editor component for Svelte",
5
5
  "keywords": [
6
6
  "svelte",