@explorer-1/vue 0.3.8 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @explorer-1/vue
2
2
 
3
+ ## 0.3.9
4
+
5
+ ### Patch Changes
6
+
7
+ - 604b717: Fixing url handling in BlockCsrTable, adding option to disable trailing slash in BaseLink.
8
+
3
9
  ## 0.3.8
4
10
 
5
11
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorer-1/vue",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -50,6 +50,11 @@ export default defineComponent({
50
50
  type: String,
51
51
  default: undefined
52
52
  },
53
+ /** Links are normalized to add a trailing slash (handles links to files, query params etc.). Set to false to disable. */
54
+ addSlash: {
55
+ type: Boolean,
56
+ default: true
57
+ },
53
58
  title: {
54
59
  type: String,
55
60
  default: undefined
@@ -196,46 +201,49 @@ export default defineComponent({
196
201
  eventBus.emit('linkClicked')
197
202
  },
198
203
  addTrailingSlash(path: string) {
199
- let filteredPath = path
200
- if (path && typeof path === 'string') {
201
- const isFilePath = () => {
202
- const afterLastSlash = path.split('/').pop()
203
- if (afterLastSlash && afterLastSlash.includes('.')) {
204
- return true
205
- }
206
- return false
207
- }
208
- const isQueryPath = path.includes('?')
209
- const isAnchorPath = path.includes('#')
210
- if (
211
- !isQueryPath &&
212
- !isAnchorPath &&
213
- !isFilePath() &&
214
- path !== '/' &&
215
- !path.endsWith('/') &&
216
- !path.startsWith('/preview')
217
- ) {
218
- // add a trailing slash if there isn't one
219
- filteredPath += '/'
220
- } else if (isQueryPath) {
221
- if (!path.includes('/?')) {
222
- // also add a trailing slash to paths with query params
223
- const urlParts = filteredPath.split('?')
224
- const pathWithSlash = `${urlParts[0]}/`
225
- const queryParams = urlParts[1]
226
- filteredPath = pathWithSlash + '?' + queryParams
204
+ if (this.addSlash) {
205
+ let filteredPath = path
206
+ if (path && typeof path === 'string') {
207
+ const isFilePath = () => {
208
+ const afterLastSlash = path.split('/').pop()
209
+ if (afterLastSlash && afterLastSlash.includes('.')) {
210
+ return true
211
+ }
212
+ return false
227
213
  }
228
- } else if (isAnchorPath) {
229
- if (!path.includes('/#')) {
230
- // also add a trailing slash to paths with anchors
231
- const urlParts = filteredPath.split('#')
232
- const pathWithSlash = `${urlParts[0]}/`
233
- const anchor = urlParts[1]
234
- filteredPath = pathWithSlash + '#' + anchor
214
+ const isQueryPath = path.includes('?')
215
+ const isAnchorPath = path.includes('#')
216
+ if (
217
+ !isQueryPath &&
218
+ !isAnchorPath &&
219
+ !isFilePath() &&
220
+ path !== '/' &&
221
+ !path.endsWith('/') &&
222
+ !path.startsWith('/preview')
223
+ ) {
224
+ // add a trailing slash if there isn't one
225
+ filteredPath += '/'
226
+ } else if (isQueryPath) {
227
+ if (!path.includes('/?')) {
228
+ // also add a trailing slash to paths with query params
229
+ const urlParts = filteredPath.split('?')
230
+ const pathWithSlash = `${urlParts[0]}/`
231
+ const queryParams = urlParts[1]
232
+ filteredPath = pathWithSlash + '?' + queryParams
233
+ }
234
+ } else if (isAnchorPath) {
235
+ if (!path.includes('/#')) {
236
+ // also add a trailing slash to paths with anchors
237
+ const urlParts = filteredPath.split('#')
238
+ const pathWithSlash = `${urlParts[0]}/`
239
+ const anchor = urlParts[1]
240
+ filteredPath = pathWithSlash + '#' + anchor
241
+ }
235
242
  }
236
243
  }
244
+ return filteredPath
237
245
  }
238
- return filteredPath
246
+ return path
239
247
  }
240
248
  }
241
249
  })
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { reactive } from 'vue'
2
+ import { computed, onMounted } from 'vue'
3
3
  import BaseLink from './../BaseLink/BaseLink.vue'
4
4
 
5
5
  interface CsrAttachmentProps {
@@ -15,14 +15,26 @@ interface CsrAttachmentProps {
15
15
  const props = withDefaults(defineProps<CsrAttachmentProps>(), {
16
16
  params: undefined
17
17
  })
18
- const { params } = reactive(props)
18
+
19
+ const encodedAttachmentUrl = computed(() => {
20
+ let url = ''
21
+ if (props.params.data?.Attachment && props.params.attachmentPrefix) {
22
+ url = props.params.attachmentPrefix + props.params.data.Attachment
23
+ }
24
+ return encodeURI(url)
25
+ })
26
+
27
+ onMounted(() => {
28
+ console.log(encodedAttachmentUrl.value)
29
+ })
19
30
  </script>
20
31
  <template>
21
32
  <BaseLink
22
- v-if="params?.data?.Attachment"
23
- :href="params.attachmentPrefix + params.data.Attachment"
33
+ v-if="props.params?.data?.Attachment"
34
+ :href="encodedAttachmentUrl"
24
35
  variant="default"
25
36
  target="_blank"
37
+ :add-slash="false"
26
38
  >Download</BaseLink
27
39
  >
28
40
  </template>