spark-grid-vue3 0.0.71 → 0.0.72

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": "spark-grid-vue3",
3
- "version": "0.0.71",
3
+ "version": "0.0.72",
4
4
  "description": "",
5
5
  "files": [
6
6
  "src"
package/src/index.ts CHANGED
@@ -1,9 +1,18 @@
1
1
  import type { App } from "vue";
2
2
  import SparkGridComponent from "./SparkGrid.vue";
3
3
  import type { InstallOptions } from "./types";
4
+ import { GlobalConfig } from "./utils/GlobalConfig";
4
5
 
5
6
  export const ArcanaDataTable: any = {
6
7
  install(app: App, options: InstallOptions) {
8
+ if (options?.baseUrl) {
9
+ GlobalConfig.baseUrl = options.baseUrl
10
+ }
11
+
12
+ if (options?.eventProxy) {
13
+ GlobalConfig.eventProxy = options.eventProxy
14
+ }
15
+
7
16
  app.component("ArcanaDataTable", SparkGridComponent)
8
17
  app.component("SparkGrid", SparkGridComponent)
9
18
  }
@@ -196,4 +196,11 @@ export type Props = {
196
196
  config: SparkGridConfig
197
197
  }
198
198
 
199
- export type InstallOptions = Record<string, never>
199
+ export type InstallOptions = {
200
+ baseUrl?: string
201
+ eventProxy?: {
202
+ emit: (...args: any[]) => void
203
+ on: (...args: any[]) => void
204
+ off: (...args: any[]) => void
205
+ }
206
+ }
@@ -0,0 +1,10 @@
1
+ export type EventProxy = {
2
+ emit: (...args: any[]) => void
3
+ on: (...args: any[]) => void
4
+ off: (...args: any[]) => void
5
+ }
6
+
7
+ export const GlobalConfig: {
8
+ baseUrl?: string
9
+ eventProxy?: EventProxy
10
+ } = {}
@@ -1,4 +1,5 @@
1
1
  import type { DataTableComponent } from "../types/types"
2
+ import { GlobalConfig } from "./GlobalConfig"
2
3
 
3
4
  export class UrlBuilder {
4
5
  static getParams(grid: DataTableComponent): any {
@@ -30,9 +31,30 @@ export class UrlBuilder {
30
31
  if (typeof grid.config.url == "function") {
31
32
  let urlFunction = grid.config.url()
32
33
 
33
- return urlFunction instanceof Promise ? await urlFunction : urlFunction
34
+ const resolved = urlFunction instanceof Promise ? await urlFunction : urlFunction
35
+ return UrlBuilder.applyBaseUrl(resolved)
34
36
  }
35
37
 
36
- return grid.config.url ?? ''
38
+ return UrlBuilder.applyBaseUrl(grid.config.url ?? '')
37
39
  }
38
- }
40
+
41
+ static applyBaseUrl(url: string): string {
42
+ const baseUrl = GlobalConfig.baseUrl
43
+ if (!baseUrl) {
44
+ return url
45
+ }
46
+
47
+ if (!url) {
48
+ return baseUrl
49
+ }
50
+
51
+ if (url.startsWith("http://") || url.startsWith("https://")) {
52
+ return url
53
+ }
54
+
55
+ const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl
56
+ const normalizedUrl = url.startsWith("/") ? url : `/${url}`
57
+
58
+ return `${normalizedBase}${normalizedUrl}`
59
+ }
60
+ }