@flexiui/svelte-rich-text 0.0.67 → 0.0.68

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.
@@ -51,6 +51,15 @@
51
51
  function canCreateSubheading(editor) {
52
52
  return !hasH1AfterCursor(editor);
53
53
  }
54
+
55
+ const headingActions = {
56
+ "1": () => $editor.chain().focus().toggleH1().run(),
57
+ "2": () => $editor.chain().focus().toggleH2().run(),
58
+ "3": () => $editor.chain().focus().toggleH3().run(),
59
+ "4": () => $editor.chain().focus().toggleH4().run(),
60
+ "5": () => $editor.chain().focus().toggleH5().run(),
61
+ "6": () => $editor.chain().focus().toggleH6().run(),
62
+ };
54
63
  </script>
55
64
 
56
65
  {#if level === 1}
@@ -65,7 +74,7 @@
65
74
  {@html icons[level]}
66
75
  </button>
67
76
  {:else}
68
- <button
77
+ <!-- <button
69
78
  type="button"
70
79
  onclick={() => $editor.chain().focus().toggleHeading({ level }).run()}
71
80
  class:is-active={$editor.isActive("heading", { level })}
@@ -74,5 +83,17 @@
74
83
  disabled={!canCreateSubheading($editor)}
75
84
  >
76
85
  {@html icons[level]}
86
+ </button> -->
87
+ <button
88
+ type="button"
89
+ onclick={() => {
90
+ headingActions[level]();
91
+ }}
92
+ class:is-active={$editor.isActive("h"+level)}
93
+ class:accent-soft={accenSoft}
94
+ aria-label={`Heading ${level}`}
95
+ disabled={!canCreateSubheading($editor)}
96
+ >
97
+ {@html icons[level]}
77
98
  </button>
78
99
  {/if}
@@ -12,7 +12,7 @@
12
12
  <button
13
13
  type="button"
14
14
  onclick={handleClick}
15
- class:is-active={$editor.isActive("heading") || $editor.isActive("h1")}
15
+ class:is-active={$editor.isActive("heading") || $editor.isActive("h1") || $editor.isActive("h2") || $editor.isActive("h3") || $editor.isActive("h4") || $editor.isActive("h5") || $editor.isActive("h6")}
16
16
  class:accent-soft={accentSoft}
17
17
  aria-label={ariaLabel}
18
18
  >
@@ -24,21 +24,30 @@
24
24
  {/each}
25
25
  {:else if $editor.isActive("h1")}
26
26
  {@html HEADINGS[0].icon}
27
- {/if}
27
+ {:else if $editor.isActive("h2")}
28
+ {@html HEADINGS[1].icon}
29
+ {:else if $editor.isActive("h3")}
30
+ {@html HEADINGS[2].icon}
31
+ {:else if $editor.isActive("h4")}
32
+ {@html HEADINGS[3].icon}
33
+ {:else if $editor.isActive("h5")}
34
+ {@html HEADINGS[4].icon}
35
+ {:else if $editor.isActive("h6")}
36
+ {@html HEADINGS[5].icon}
28
37
 
29
- {#if !$editor.isActive("heading") && !$editor.isActive("h1")}
30
- <svg
31
- width="24"
32
- height="24"
33
- class="tiptap-button-icon"
34
- viewBox="0 0 24 24"
35
- fill="currentColor"
36
- xmlns="http://www.w3.org/2000/svg"
37
- ><path
38
- d="M6 3C6.55228 3 7 3.44772 7 4V11H17V4C17 3.44772 17.4477 3 18 3C18.5523 3 19 3.44772 19 4V20C19 20.5523 18.5523 21 18 21C17.4477 21 17 20.5523 17 20V13H7V20C7 20.5523 6.55228 21 6 21C5.44772 21 5 20.5523 5 20V4C5 3.44772 5.44772 3 6 3Z"
38
+ {:else}
39
+ <svg
40
+ width="24"
41
+ height="24"
42
+ class="tiptap-button-icon"
43
+ viewBox="0 0 24 24"
39
44
  fill="currentColor"
40
- ></path></svg
41
- >
45
+ xmlns="http://www.w3.org/2000/svg"
46
+ ><path
47
+ d="M6 3C6.55228 3 7 3.44772 7 4V11H17V4C17 3.44772 17.4477 3 18 3C18.5523 3 19 3.44772 19 4V20C19 20.5523 18.5523 21 18 21C17.4477 21 17 20.5523 17 20V13H7V20C7 20.5523 6.55228 21 6 21C5.44772 21 5 20.5523 5 20V4C5 3.44772 5.44772 3 6 3Z"
48
+ fill="currentColor"
49
+ ></path></svg
50
+ >
42
51
  {/if}
43
52
 
44
53
  <svg
@@ -1,5 +1,5 @@
1
1
  import { Extension } from "@tiptap/core";
2
- const allowedTypes = ["paragraph", "heading", "h1"];
2
+ const allowedTypes = ["paragraph", "heading", "h1", "h2", "h3", "h4", "h5", "h6"];
3
3
  export const NodeFontSize = Extension.create({
4
4
  name: "nodeFontSize",
5
5
  addGlobalAttributes() {
@@ -1,5 +1,5 @@
1
1
  import { Extension } from "@tiptap/core";
2
- const allowedTypes = ["paragraph", "heading", "h1"];
2
+ const allowedTypes = ["paragraph", "heading", "h1", "h2", "h3", "h4", "h5", "h6"];
3
3
  export const NodeLineHeight = Extension.create({
4
4
  name: "nodeLineHeight",
5
5
  addGlobalAttributes() {
@@ -16,7 +16,7 @@ export const SemanticHeadings = Extension.create({
16
16
  let h1Count = 0;
17
17
  // Recolectar todos los headings en orden
18
18
  doc.descendants((node, pos) => {
19
- if (node.type.name === 'heading') {
19
+ if (node.type.name === 'heading' || node.type.name === 'h1' || node.type.name === 'h2' || node.type.name === 'h3' || node.type.name === 'h4' || node.type.name === 'h5' || node.type.name === 'h6') {
20
20
  headings.push({
21
21
  level: node.attrs.level,
22
22
  pos: pos
@@ -68,7 +68,7 @@ export const SemanticHeadings = Extension.create({
68
68
  let hasH1 = false;
69
69
  // Buscar el último heading y verificar si ya existe h1
70
70
  doc.descendants((node) => {
71
- if (node.type.name === 'heading') {
71
+ if (node.type.name === 'heading' || node.type.name === 'h1' || node.type.name === 'h2' || node.type.name === 'h3' || node.type.name === 'h4' || node.type.name === 'h5' || node.type.name === 'h6') {
72
72
  lastHeadingLevel = node.attrs.level;
73
73
  if (node.attrs.level === 1) {
74
74
  hasH1 = true;
@@ -97,7 +97,7 @@ export const SemanticHeadings = Extension.create({
97
97
  let lastHeadingLevel = null;
98
98
  let hasH1 = false;
99
99
  doc.descendants((node) => {
100
- if (node.type.name === 'heading') {
100
+ if (node.type.name === 'heading' || node.type.name === 'h1' || node.type.name === 'h2' || node.type.name === 'h3' || node.type.name === 'h4' || node.type.name === 'h5' || node.type.name === 'h6') {
101
101
  lastHeadingLevel = node.attrs.level;
102
102
  if (node.attrs.level === 1) {
103
103
  hasH1 = true;
@@ -34,6 +34,12 @@ export function createExtensions({ customExtensions = [], editable = true, } = {
34
34
  ListKit,
35
35
  TextAlign.configure({
36
36
  types: [
37
+ "h1",
38
+ "h2",
39
+ "h3",
40
+ "h4",
41
+ "h5",
42
+ "h6",
37
43
  "heading",
38
44
  "paragraph",
39
45
  "bulletList",
@@ -3,6 +3,21 @@ declare module '@tiptap/core' {
3
3
  h1: {
4
4
  toggleH1: () => ReturnType;
5
5
  };
6
+ h2: {
7
+ toggleH2: () => ReturnType;
8
+ };
9
+ h3: {
10
+ toggleH3: () => ReturnType;
11
+ };
12
+ h4: {
13
+ toggleH4: () => ReturnType;
14
+ };
15
+ h5: {
16
+ toggleH5: () => ReturnType;
17
+ };
18
+ h6: {
19
+ toggleH6: () => ReturnType;
20
+ };
6
21
  }
7
22
  }
8
23
  export declare function getRichTextExtensions(options?: {
@@ -17,7 +17,7 @@ import { CustomTableHeader } from "./extensions/Table/CustomTableHeader";
17
17
  import { EnhancedLink } from "./extensions/EnhancedLink";
18
18
  import { SemanticHeadings } from "./extensions/SemanticHeadings";
19
19
  import { Heading } from "@tiptap/extension-heading";
20
- const DocHeading = Heading.extend({
20
+ const H1 = Heading.extend({
21
21
  name: "h1",
22
22
  addCommands() {
23
23
  return {
@@ -27,11 +27,66 @@ const DocHeading = Heading.extend({
27
27
  };
28
28
  },
29
29
  }).configure({ levels: [1] });
30
+ const H2 = Heading.extend({
31
+ name: "h2",
32
+ addCommands() {
33
+ return {
34
+ toggleH2: () => ({ commands }) => {
35
+ return commands.toggleNode('h2', 'paragraph');
36
+ },
37
+ };
38
+ },
39
+ }).configure({ levels: [2] });
40
+ const H3 = Heading.extend({
41
+ name: "h3",
42
+ addCommands() {
43
+ return {
44
+ toggleH3: () => ({ commands }) => {
45
+ return commands.toggleNode('h3', 'paragraph');
46
+ },
47
+ };
48
+ },
49
+ }).configure({ levels: [3] });
50
+ const H4 = Heading.extend({
51
+ name: "h4",
52
+ addCommands() {
53
+ return {
54
+ toggleH4: () => ({ commands }) => {
55
+ return commands.toggleNode('h4', 'paragraph');
56
+ },
57
+ };
58
+ },
59
+ }).configure({ levels: [4] });
60
+ const H5 = Heading.extend({
61
+ name: "h5",
62
+ addCommands() {
63
+ return {
64
+ toggleH5: () => ({ commands }) => {
65
+ return commands.toggleNode('h5', 'paragraph');
66
+ },
67
+ };
68
+ },
69
+ }).configure({ levels: [5] });
70
+ const H6 = Heading.extend({
71
+ name: "h6",
72
+ addCommands() {
73
+ return {
74
+ toggleH6: () => ({ commands }) => {
75
+ return commands.toggleNode('h6', 'paragraph');
76
+ },
77
+ };
78
+ },
79
+ }).configure({ levels: [6] });
30
80
  export function getRichTextExtensions(options) {
31
81
  const { editable = false, trailingNode = true, customExtensions = [] } = options ?? {};
32
82
  return [
33
- DocHeading,
34
- Heading.configure({ levels: [2, 3, 4, 5, 6] }),
83
+ H1,
84
+ H2,
85
+ H3,
86
+ H4,
87
+ H5,
88
+ H6,
89
+ // Heading.configure({ levels: [2, 3, 4, 5, 6] }),
35
90
  Highlight.configure({ multicolor: true }),
36
91
  TextStyleKit.configure({
37
92
  // fontSize: false
@@ -53,6 +108,11 @@ export function getRichTextExtensions(options) {
53
108
  TextAlign.configure({
54
109
  types: [
55
110
  "h1",
111
+ "h2",
112
+ "h3",
113
+ "h4",
114
+ "h5",
115
+ "h6",
56
116
  "heading",
57
117
  "paragraph",
58
118
  "bulletList",
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const exampleJSONContent = [
2
2
  {
3
- type: "heading",
3
+ type: "h1",
4
4
  attrs: { level: 1 },
5
5
  content: [{ type: "text", text: "Hi there," }],
6
6
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flexiui/svelte-rich-text",
3
- "version": "0.0.67",
3
+ "version": "0.0.68",
4
4
  "description": "A lightweight and flexible rich text editor component for Svelte",
5
5
  "keywords": [
6
6
  "svelte",