@ditojs/admin 2.100.0 → 3.1.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/dito-admin.css +1 -1
- package/dist/dito-admin.es.js +3555 -2719
- package/dist/dito-admin.umd.js +5 -6
- package/package.json +84 -46
- package/src/DitoAdmin.js +1 -65
- package/src/DitoComponent.js +1 -1
- package/src/DitoContext.js +51 -0
- package/src/DitoTypeComponent.js +23 -1
- package/src/components/DitoAffixes.vue +6 -3
- package/src/components/DitoButtons.vue +14 -1
- package/src/components/DitoContainer.vue +19 -10
- package/src/components/DitoCreateButton.vue +11 -2
- package/src/components/DitoDialog.vue +21 -2
- package/src/components/DitoForm.vue +152 -84
- package/src/components/DitoLabel.vue +3 -2
- package/src/components/DitoPane.vue +55 -11
- package/src/components/DitoPanel.vue +34 -5
- package/src/components/DitoPanels.vue +2 -1
- package/src/components/DitoRoot.vue +6 -6
- package/src/components/DitoRouterView.vue +27 -0
- package/src/components/DitoSchema.vue +278 -145
- package/src/components/DitoSchemaInlined.vue +1 -1
- package/src/components/DitoTabs.vue +16 -18
- package/src/components/DitoTrail.vue +5 -4
- package/src/components/DitoTreeItem.vue +17 -6
- package/src/components/DitoView.vue +21 -3
- package/src/components/index.js +1 -0
- package/src/mixins/DitoMixin.js +53 -7
- package/src/mixins/ItemMixin.js +3 -6
- package/src/mixins/NumberMixin.js +47 -31
- package/src/mixins/OptionsMixin.js +132 -71
- package/src/mixins/ResourceMixin.js +5 -2
- package/src/mixins/RouteMixin.js +39 -1
- package/src/mixins/SortableMixin.js +0 -13
- package/src/mixins/SourceMixin.js +155 -96
- package/src/mixins/TextMixin.js +1 -1
- package/src/mixins/TypeMixin.js +37 -22
- package/src/mixins/ValidationMixin.js +9 -27
- package/src/mixins/ValidatorMixin.js +5 -7
- package/src/mixins/ValueMixin.js +5 -2
- package/src/types/DitoTypeButton.vue +1 -1
- package/src/types/DitoTypeCheckbox.vue +1 -1
- package/src/types/DitoTypeCheckboxes.vue +1 -1
- package/src/types/DitoTypeCode.vue +8 -1
- package/src/types/DitoTypeColor.vue +20 -34
- package/src/types/DitoTypeComponent.vue +1 -1
- package/src/types/DitoTypeComputed.vue +4 -27
- package/src/types/DitoTypeDate.vue +16 -5
- package/src/types/DitoTypeLabel.vue +1 -4
- package/src/types/DitoTypeList.vue +9 -5
- package/src/types/DitoTypeMarkup.vue +25 -13
- package/src/types/DitoTypeMultiselect.vue +37 -6
- package/src/types/DitoTypeNumber.vue +1 -1
- package/src/types/DitoTypeObject.vue +10 -7
- package/src/types/DitoTypePanel.vue +20 -6
- package/src/types/DitoTypeProgress.vue +1 -1
- package/src/types/DitoTypeRadio.vue +1 -1
- package/src/types/DitoTypeSection.vue +32 -4
- package/src/types/DitoTypeSelect.vue +1 -1
- package/src/types/DitoTypeSlider.vue +1 -1
- package/src/types/DitoTypeSwitch.vue +1 -1
- package/src/types/DitoTypeText.vue +13 -15
- package/src/types/DitoTypeTextarea.vue +1 -1
- package/src/types/DitoTypeTreeList.vue +5 -7
- package/src/types/DitoTypeUpload.vue +1 -2
- package/src/utils/DataSchemaResolver.js +154 -0
- package/src/utils/FormModel.js +615 -0
- package/src/utils/data.js +20 -0
- package/src/utils/filter.js +3 -2
- package/src/utils/options.js +3 -0
- package/src/utils/request.js +70 -0
- package/src/utils/schema/data.js +659 -0
- package/src/utils/schema/lookup.js +250 -0
- package/src/utils/schema/setup.js +354 -0
- package/src/utils/schema/structure.js +172 -0
- package/src/utils/schema/types.js +34 -0
- package/src/utils/schema/validation.js +142 -0
- package/src/utils/units.js +70 -3
- package/types/index.d.ts +174 -59
- package/src/mixins/DataMixin.js +0 -131
- package/src/utils/schema.js +0 -1121
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { isAbsoluteUrl } from '@ditojs/utils'
|
|
2
|
+
import { formatQuery } from './route.js'
|
|
3
|
+
|
|
4
|
+
export class RequestError extends Error {
|
|
5
|
+
constructor(response) {
|
|
6
|
+
super(
|
|
7
|
+
`Request failed with status code: ${response.status} (${
|
|
8
|
+
response.statusText
|
|
9
|
+
})`
|
|
10
|
+
)
|
|
11
|
+
this.response = response
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export async function request(api, {
|
|
16
|
+
url,
|
|
17
|
+
method = 'get',
|
|
18
|
+
query = null,
|
|
19
|
+
headers = null,
|
|
20
|
+
data = null,
|
|
21
|
+
signal = null,
|
|
22
|
+
timeout = api.timeout ?? null
|
|
23
|
+
}) {
|
|
24
|
+
const isApiUrl = api.isApiUrl(url)
|
|
25
|
+
// Abort requests that take longer than the timeout, if there is one, so that
|
|
26
|
+
// nothing waits for them forever, e.g. submitting for pending loads:
|
|
27
|
+
const signals = [signal, timeout && AbortSignal.timeout(timeout)]
|
|
28
|
+
signal = AbortSignal.any(signals.filter(Boolean))
|
|
29
|
+
|
|
30
|
+
const response = await fetch(api.getApiUrl({ url, query }), {
|
|
31
|
+
method: method.toUpperCase(),
|
|
32
|
+
...(data && { body: JSON.stringify(data) }),
|
|
33
|
+
headers: {
|
|
34
|
+
...(isApiUrl && api.headers),
|
|
35
|
+
...headers
|
|
36
|
+
},
|
|
37
|
+
credentials:
|
|
38
|
+
isApiUrl && api.cors?.credentials
|
|
39
|
+
? 'include'
|
|
40
|
+
: 'same-origin',
|
|
41
|
+
signal
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
if (response.headers.get('Content-Type')?.includes('application/json')) {
|
|
45
|
+
response.data = await response.json()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new RequestError(response)
|
|
50
|
+
}
|
|
51
|
+
return response
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function isApiUrl(api, url) {
|
|
55
|
+
return !isAbsoluteUrl(url) || url.startsWith(api.url)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function getApiUrl(api, { url, query }) {
|
|
59
|
+
if (!url.startsWith(api.url) && !isAbsoluteUrl(url)) {
|
|
60
|
+
url = combineUrls(api.url, url)
|
|
61
|
+
}
|
|
62
|
+
// Support optional query parameters, to be are added to the URL.
|
|
63
|
+
const search = formatQuery(query)
|
|
64
|
+
return search ? `${url}${url.includes('?') ? '&' : '?'}${search}` : url
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function combineUrls(baseUrl, relativeUrl) {
|
|
68
|
+
// Use same approach as axios `combineURLs()` to join baseUrl & relativeUrl:
|
|
69
|
+
return `${baseUrl.replace(/\/+$/, '')}/${relativeUrl.replace(/^\/+/, '')}`
|
|
70
|
+
}
|