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 +1 -1
- package/src/index.ts +9 -0
- package/src/types/types.ts +8 -1
- package/src/utils/GlobalConfig.ts +10 -0
- package/src/utils/UrlBuilder.ts +25 -3
package/package.json
CHANGED
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
|
}
|
package/src/types/types.ts
CHANGED
|
@@ -196,4 +196,11 @@ export type Props = {
|
|
|
196
196
|
config: SparkGridConfig
|
|
197
197
|
}
|
|
198
198
|
|
|
199
|
-
export type InstallOptions =
|
|
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
|
+
}
|
package/src/utils/UrlBuilder.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
+
}
|