@mirus/tiptap-editor 2.1.7 → 2.1.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mirus/tiptap-editor",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "description": "custom setup for the tiptap editor",
5
5
  "repository": "https://github.com/mirusresearch/tiptap-editor",
6
6
  "bugs": {
package/src/App.vue CHANGED
@@ -1,14 +1,52 @@
1
1
  <template>
2
- <tiptapEditor
3
- :value.sync="localtext"
4
- :warnings="warnings"
5
- :showMenu="showMenu"
6
- :maxCharacterCount="maxCharacterCount"
7
- :height="height"
8
- v-on:new-character-count="localcount = $event"
9
- id="unique_id"
10
- placeholder="write something will-ya!"
11
- />
2
+ <div>
3
+ <div class="dev-controls">
4
+ <button class="light-dark-button" @click="toggleLightMode">
5
+ <div v-if="isLightMode" class="button-content">
6
+ <svg
7
+ xmlns="http://www.w3.org/2000/svg"
8
+ fill="none"
9
+ viewBox="0 0 24 24"
10
+ stroke-width="1.5"
11
+ stroke="currentColor"
12
+ >
13
+ <path
14
+ stroke-linecap="round"
15
+ stroke-linejoin="round"
16
+ d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"
17
+ />
18
+ </svg>
19
+ <span>Light</span>
20
+ </div>
21
+ <div v-else class="button-content">
22
+ <svg
23
+ xmlns="http://www.w3.org/2000/svg"
24
+ fill="none"
25
+ viewBox="0 0 24 24"
26
+ stroke-width="1.5"
27
+ stroke="currentColor"
28
+ >
29
+ <path
30
+ stroke-linecap="round"
31
+ stroke-linejoin="round"
32
+ d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"
33
+ />
34
+ </svg>
35
+ <span>Dark</span>
36
+ </div>
37
+ </button>
38
+ </div>
39
+ <tiptapEditor
40
+ :value.sync="localtext"
41
+ :warnings="warnings"
42
+ :showMenu="showMenu"
43
+ :maxCharacterCount="maxCharacterCount"
44
+ :height="height"
45
+ v-on:new-character-count="localcount = $event"
46
+ id="unique_id"
47
+ placeholder="write something will-ya!"
48
+ />
49
+ </div>
12
50
  </template>
13
51
 
14
52
  <script>
@@ -19,6 +57,7 @@ export default {
19
57
  components: { tiptapEditor },
20
58
  data() {
21
59
  return {
60
+ isLightMode: true,
22
61
  maxCharacterCount: 250, //default null for infinity
23
62
  height: '200px', // default it 300px
24
63
  showMenu: true, // false to hide
@@ -59,5 +98,48 @@ export default {
59
98
  localcount: null,
60
99
  };
61
100
  },
101
+ methods: {
102
+ toggleLightMode() {
103
+ this.isLightMode = !this.isLightMode;
104
+ const htmlElement = document.documentElement;
105
+ if (htmlElement) {
106
+ if (htmlElement.getAttribute('color-scheme') === 'dark') {
107
+ htmlElement.setAttribute('color-scheme', 'light');
108
+ } else {
109
+ htmlElement.setAttribute('color-scheme', 'dark');
110
+ }
111
+ }
112
+ },
113
+ },
62
114
  };
63
115
  </script>
116
+
117
+ <style>
118
+ .light-dark-button {
119
+ background: #f4f4f5;
120
+ margin-bottom: 8px;
121
+ border-radius: 8px;
122
+ border: 0;
123
+ padding: 8px 12px 8px 12px;
124
+ cursor: pointer;
125
+
126
+ svg {
127
+ height: 1rem;
128
+ width: 1rem;
129
+ }
130
+ }
131
+
132
+ .button-content {
133
+ display: flex;
134
+ justify-content: center;
135
+ align-items: center;
136
+ gap: 4px;
137
+ }
138
+
139
+ html[color-scheme='dark'] {
140
+ button {
141
+ background: #1f2937;
142
+ color: #d1d5db;
143
+ }
144
+ }
145
+ </style>
@@ -66,7 +66,7 @@
66
66
  : 'character-count__graph'
67
67
  "
68
68
  >
69
- <circle r="10" cx="10" cy="10" fill="#e9ecef" />
69
+ <circle r="10" cx="10" cy="10" class="character-count__outer-circle" />
70
70
  <circle
71
71
  r="5"
72
72
  cx="10"
@@ -77,7 +77,7 @@
77
77
  :stroke-dasharray="`calc(${characterCountPercentage}px * 31.4 / 100) 31.4`"
78
78
  transform="rotate(-90) translate(-20)"
79
79
  />
80
- <circle r="6" cx="10" cy="10" fill="white" />
80
+ <circle r="6" cx="10" cy="10" class="character-count__inner-circle" />
81
81
  </svg>
82
82
  <div class="character-count__text" aria-live="polite">
83
83
  {{ currentCharacterCount }} / {{ maxCharacterCount }} characters
@@ -321,9 +321,10 @@ export default {
321
321
  getOffsetAdjustment(warning) {
322
322
  // compliance check offsets count all HTML entities as one character, whereas the editor value does not. compensate for
323
323
  // this by adding to the offset until it matches (or equals the length of the editor text as a failsafe break from the loop)
324
+ const normalizedString = this.value.normalize('NFKC').replace(/&nbsp;/g, ' ');
324
325
  while (
325
- this.value.substr(warning.offset, warning.value.length) !== warning.value &&
326
- warning.offset <= this.value.length
326
+ normalizedString.substr(warning.offset, warning.value.length) !== warning.value &&
327
+ warning.offset <= normalizedString.length
327
328
  ) {
328
329
  warning.offset++;
329
330
  }
@@ -474,7 +475,7 @@ export default {
474
475
  // border-bottom: 1px solid #e5e7eb;
475
476
  padding: 4px;
476
477
  border-radius: 4px;
477
- background-color: #f4f4f5;
478
+ background: #f4f4f5;
478
479
  display: flex;
479
480
 
480
481
  button {
@@ -520,7 +521,7 @@ export default {
520
521
  font-size: 16px;
521
522
  outline: 0;
522
523
  overflow-y: auto;
523
- padding: 10px;
524
+ padding: 6px 2px 4px 2px;
524
525
 
525
526
  .underline-red {
526
527
  border-bottom: 3px red solid;
@@ -544,8 +545,8 @@ export default {
544
545
 
545
546
  .ProseMirror {
546
547
  height: 100%;
547
- padding: 2px;
548
- border-radius: 7px;
548
+ padding: 2px 8px 2px 8px;
549
+ border-radius: 4px;
549
550
 
550
551
  &:focus {
551
552
  outline: 2px solid #3b82f6;
@@ -572,5 +573,73 @@ export default {
572
573
  color: #fb7373;
573
574
  }
574
575
  }
576
+
577
+ &__inner-circle {
578
+ fill: #f4f4f5;
579
+ }
580
+
581
+ &__outer-circle {
582
+ fill: #ffffff;
583
+ }
584
+ }
585
+
586
+ html[color-scheme='dark'] {
587
+ .tiptap-editor {
588
+ border: 2px solid #374151;
589
+ background: #111827;
590
+ color: #d1d5db;
591
+
592
+ .menubar {
593
+ background: #1f2937;
594
+ color: #d1d5db;
595
+
596
+ button {
597
+ color: #d1d5db;
598
+
599
+ &:focus {
600
+ outline: 2px solid #3b82f6;
601
+ transition: all 0.08s ease-in-out;
602
+ }
603
+
604
+ &.is-active {
605
+ background-color: #374151;
606
+ }
607
+
608
+ &.is-active:focus {
609
+ background-color: #4b5563;
610
+ }
611
+
612
+ &:not(.is-active):hover {
613
+ background-color: #374151;
614
+ }
615
+
616
+ &:not(.is-active):focus {
617
+ background-color: #374151;
618
+ }
619
+
620
+ svg {
621
+ width: 12px;
622
+ }
623
+ }
624
+ }
625
+ }
626
+
627
+ .character-count {
628
+ &__graph {
629
+ color: #a8c2f7;
630
+
631
+ &--warning {
632
+ color: #fb7373;
633
+ }
634
+ }
635
+
636
+ &__inner-circle {
637
+ fill: #1f2937;
638
+ }
639
+
640
+ &__outer-circle {
641
+ fill: #111827;
642
+ }
643
+ }
575
644
  }
576
645
  </style>
package/src/warnings.js CHANGED
@@ -62,8 +62,9 @@ function lint(doc, position, prev, getErrorWords) {
62
62
  doc.descendants((node, pos) => {
63
63
  if (node.isText) {
64
64
  // Scan text nodes for bad words
65
+ const normalizedText = node.text.normalize('NFKC').replace(/&nbsp;/g, ' ');
65
66
  let m;
66
- while ((m = badWordsRegex.exec(node.text))) {
67
+ while ((m = badWordsRegex.exec(normalizedText))) {
67
68
  const matchingErrorWords = words.filter((word) => word.value === m[0]);
68
69
  const indexOfMatchedWord = pos + m.index;
69
70
  let errorHasOffsetData = false;