cec-nuxt-lib 0.2.4 → 0.3.0

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/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "cec-nuxt-lib",
3
3
  "configKey": "cec-nuxt-lib",
4
- "version": "0.2.4"
4
+ "version": "0.3.0"
5
5
  }
@@ -3,15 +3,15 @@ import { useState } from '#app';
3
3
  import { useRuntimeConfig } from '#app';
4
4
  import { useRoute } from 'vue-router';
5
5
 
6
+ const classicPath = useState('classicPath');
6
7
  const config = useRuntimeConfig();
8
+ const path = useState('path');
7
9
  const route = useRoute();
8
- const classicPath = useState('classicPath');
9
10
  const baseUrl = config.app.baseURL;
10
11
 
11
12
  // Helper functions
12
13
  const makeLink = (i, routes) => {
13
- let temp = routes.slice(0, i).join('/');
14
- return temp.length ? temp : '/';
14
+ return routes.slice(0, i + 1).join('/');
15
15
  };
16
16
 
17
17
  const toTitleCase = (str) => {
@@ -20,19 +20,34 @@ const toTitleCase = (str) => {
20
20
  : `${str[0].toUpperCase()}${str.slice(1).replace(/[-_]/g, ' ')}`;
21
21
  };
22
22
 
23
- // Construct links and labels for breadcrumb
24
- let rLength = route.path.split('/').length;
25
- let cLength = classicPath.value.split('/').length;
26
- let routes = route.path
27
- .split('/')
28
- .filter((e, i) => !(i === rLength - 1 && !e.length));
29
- let classic = classicPath.value
30
- .split('/')
31
- .filter((e, i) => !(i === cLength - 1 && !e.length));
23
+ const makeArr = (str) => {
24
+ return str.split('/').reduce((acc, e, i) => {
25
+ if (!i || (i && e.length)) {
26
+ return [...acc, e];
27
+ }
28
+ return acc;
29
+ }, []);
30
+ };
31
+
32
+ const trimPath = (str) => str.replace(/\/$/, '');
33
+
34
+ // Make arrays of the items in the paths
35
+ let routeTrim = trimPath(route.path);
36
+ let pathTrim = trimPath(path.value);
37
+ let routes = makeArr(routeTrim);
38
+ let paths = makeArr(pathTrim);
39
+
40
+ // Use the route path if it includes the node's path
41
+ if (!routeTrim.toLowerCase().startsWith(pathTrim.toLowerCase())) {
42
+ routes = [...paths, ...routes.filter((e) => e.length)];
43
+ }
44
+
45
+ // Get the classic path for legacy links
46
+ let classic = trimPath(classicPath.value).split('/');
32
47
  const length = classic.length;
33
48
  let hrefs =
34
- baseUrl.length > 1
35
- ? `${classicPath.value}${route.path !== '/' ? route.path : ''}`.split('/')
49
+ baseUrl.length > 1 && route.path !== '/'
50
+ ? `${classicPath.value}${routeTrim}`.split('/')
36
51
  : routes.reduce((acc, e, i) => {
37
52
  return classic[i] ? [...acc, classic[i]] : [...acc, e];
38
53
  }, []);
@@ -48,9 +63,7 @@ const links = hrefs.map((e, i) => (!i ? 'Home' : toTitleCase(e)));
48
63
  <li class="breadcrumb-item" v-for="(l, i) in links" :key="i">
49
64
  <span v-if="i === links.length - 1">{{ l }}</span>
50
65
  <template v-else-if="i + 1 >= length">
51
- <NuxtLink :to="makeLink(length - i, routes)">{{
52
- l
53
- }}</NuxtLink>
66
+ <NuxtLink :to="makeLink(i, routes)">{{ l }}</NuxtLink>
54
67
  </template>
55
68
  <a v-else :href="'/' + hrefs.slice(1, i + 1).join('/')">
56
69
  {{ l }}</a
File without changes
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.2.4",
2
+ "version": "0.3.0",
3
3
  "name": "cec-nuxt-lib",
4
4
  "description": "Nuxt components and assets",
5
5
  "license": "MIT",
@@ -28,15 +28,16 @@
28
28
  "link": "npm link"
29
29
  },
30
30
  "dependencies": {
31
+ "@contensis/canvas-html": "^1.2.0",
31
32
  "@nuxt/kit": "^3.11.2"
32
33
  },
33
34
  "devDependencies": {
34
- "@types/node": "^20.12.4",
35
35
  "@nuxt/devtools": "latest",
36
36
  "@nuxt/eslint-config": "^0.2.0",
37
37
  "@nuxt/module-builder": "^0.5.5",
38
38
  "@nuxt/schema": "^3.11.2",
39
39
  "@nuxt/test-utils": "^3.12.0",
40
+ "@types/node": "^20.12.4",
40
41
  "changelogen": "^0.5.5",
41
42
  "eslint": "^8.57.0",
42
43
  "nuxt": "^3.13.2",