layers-design-system 2.0.10 → 2.0.11

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,7 +1,7 @@
1
1
  {
2
2
  "name": "layers-design-system",
3
3
  "main": "src/main.js",
4
- "version": "2.0.10",
4
+ "version": "2.0.11",
5
5
  "scripts": {
6
6
  "start": "vue-cli-service serve ./src/main-docs.js",
7
7
  "build": "vue-cli-service build --target lib ./src/main.js",
@@ -26,6 +26,7 @@
26
26
  "@tiptap/extension-text": "2.0.0-beta.13",
27
27
  "@tiptap/extension-underline": "2.0.0-beta.16",
28
28
  "@tiptap/vue-2": "2.0.0-beta.60",
29
+ "autolinker": "^4.0.0",
29
30
  "currency.js": "1.2.2",
30
31
  "dayjs": "^1.11.7",
31
32
  "dompurify": "2.3.3",
@@ -33,7 +34,6 @@
33
34
  "layers-utils": "1.0.4",
34
35
  "mustache": "4.2.0",
35
36
  "tiptap": "1.32.2",
36
- "url-regex-safe": "2.0.2",
37
37
  "vant": "2.12.30",
38
38
  "vue": "2.6.14",
39
39
  "vue-router": "3.5.2",
@@ -41,7 +41,6 @@
41
41
  "vuetify": "2.5.10"
42
42
  },
43
43
  "devDependencies": {
44
- "sass-loader": "7.3.1",
45
44
  "@vue/cli-plugin-babel": "4.5.14",
46
45
  "@vue/cli-plugin-eslint": "4.5.14",
47
46
  "@vue/cli-service": "4.5.14",
@@ -50,6 +49,7 @@
50
49
  "eslint-plugin-vue": "5.2.3",
51
50
  "hard-source-webpack-plugin": "0.13.1",
52
51
  "sass": "1.43.2",
52
+ "sass-loader": "7.3.1",
53
53
  "vue-cli-plugin-element": "1.0.1",
54
54
  "vue-cli-plugin-vuetify": "2.4.3",
55
55
  "vue-template-compiler": "2.6.14",
@@ -27,8 +27,8 @@
27
27
  </template>
28
28
 
29
29
  <script>
30
- import urlRegex from 'url-regex-safe'
31
- import { addProtocol } from './helpers/manageLinks'
30
+ import Autolinker from 'autolinker'
31
+ import { addProtocol } from './helpers/addProtocol'
32
32
 
33
33
  export default {
34
34
  props: {
@@ -57,7 +57,10 @@ export default {
57
57
  },
58
58
 
59
59
  isLinkValid(link) {
60
- return urlRegex({ exact: true }).test(link)
60
+ const validating = Autolinker.link(link, {
61
+ email: false,
62
+ })
63
+ return validating.includes('href')
61
64
  },
62
65
  },
63
66
 
@@ -0,0 +1,5 @@
1
+ export function addProtocol(link) {
2
+ return link.startsWith('http://') || link.startsWith('https://')
3
+ ? link
4
+ : 'https://' + link
5
+ }
@@ -87,9 +87,10 @@ import LinkBox from './LinkBox'
87
87
  import FloatingLink from './FloatingLink.vue'
88
88
 
89
89
  //Helpers
90
- import { getTagA, mountLink } from './helpers/manageLinks.js'
90
+ import { getTagA } from './helpers/addProtocol.js'
91
91
  import removeEmptyTags from './helpers/removeEmptyTags.js'
92
92
  import DOMPurify from 'dompurify'
93
+ import Autolinker from 'autolinker'
93
94
 
94
95
  export default {
95
96
  tagName: 'l-text-editor',
@@ -237,7 +238,7 @@ export default {
237
238
  finalText() {
238
239
  const textEditorHTML = this.editor.getHTML()
239
240
  const textEditorHTMLSpaced = this.addSpaceToFinalParagraphTag(textEditorHTML)
240
- const textEditorHTMLWithLinks = mountLink(textEditorHTMLSpaced)
241
+ const textEditorHTMLWithLinks = Autolinker.link(textEditorHTMLSpaced)
241
242
 
242
243
  return DOMPurify.sanitize(removeEmptyTags(textEditorHTMLWithLinks), {
243
244
  ADD_ATTR: ['target'],
@@ -1,60 +0,0 @@
1
- const urlRegex = require('url-regex-safe')
2
-
3
- const customUrlRegex = new RegExp(
4
- '((href=")?)' +
5
- urlRegex({
6
- localhost: false,
7
- apostrophes: false,
8
- returnString: true,
9
- }) +
10
- ' ((</a>)?)',
11
- 'g'
12
- )
13
-
14
- function mountTagA(url) {
15
- const href = addProtocol(url)
16
- return getTagA(removeAnchorTag(href), url)
17
- }
18
-
19
- export function getTagA(href, insertedText) {
20
- return `<a target="_blank" rel="noopener noreferrer nofollow" class="color-link"
21
- style="text-decoration: underline" href="${href}">${insertedText}</a>`
22
- }
23
-
24
- function removeAnchorTag(string) {
25
- return string.replace("</a>", "")
26
- }
27
-
28
- export function addProtocol(link) {
29
- return link.startsWith('http://') || link.startsWith('https://')
30
- ? link
31
- : 'https://' + link
32
- }
33
-
34
- export function mountLink(text) {
35
- // Regular expression to match email addresses
36
- const emailRegex = /(\b[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b)/g;
37
-
38
- // Replace each email address in text with a mailto link
39
- let finalText = text.replace(emailRegex, (email) => {
40
- const href = `mailto:${email}`;
41
- return getTagA(href, email);
42
- });
43
- let match;
44
-
45
- // Loop through the text to find and replace URLs
46
- while ((match = customUrlRegex.exec(finalText)) !== null) {
47
- const url = match[0];
48
-
49
- // Skip URLs that are parto of email addresses or already within anchor tags
50
- if (finalText[match.index - 1] === '@' || url.startsWith('href="') || url.endsWith('</a>')) {
51
- continue;
52
- }
53
- const finalIndex = match.index + url.length;
54
- const finalUrl = mountTagA(url);
55
-
56
- // Replace the URL with the formatted ancho tag
57
- finalText = finalText.substring(0, match.index) + finalUrl + finalText.substring(finalIndex);
58
- }
59
- return finalText;
60
- }