@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.
Files changed (81) hide show
  1. package/dist/dito-admin.css +1 -1
  2. package/dist/dito-admin.es.js +3555 -2719
  3. package/dist/dito-admin.umd.js +5 -6
  4. package/package.json +84 -46
  5. package/src/DitoAdmin.js +1 -65
  6. package/src/DitoComponent.js +1 -1
  7. package/src/DitoContext.js +51 -0
  8. package/src/DitoTypeComponent.js +23 -1
  9. package/src/components/DitoAffixes.vue +6 -3
  10. package/src/components/DitoButtons.vue +14 -1
  11. package/src/components/DitoContainer.vue +19 -10
  12. package/src/components/DitoCreateButton.vue +11 -2
  13. package/src/components/DitoDialog.vue +21 -2
  14. package/src/components/DitoForm.vue +152 -84
  15. package/src/components/DitoLabel.vue +3 -2
  16. package/src/components/DitoPane.vue +55 -11
  17. package/src/components/DitoPanel.vue +34 -5
  18. package/src/components/DitoPanels.vue +2 -1
  19. package/src/components/DitoRoot.vue +6 -6
  20. package/src/components/DitoRouterView.vue +27 -0
  21. package/src/components/DitoSchema.vue +278 -145
  22. package/src/components/DitoSchemaInlined.vue +1 -1
  23. package/src/components/DitoTabs.vue +16 -18
  24. package/src/components/DitoTrail.vue +5 -4
  25. package/src/components/DitoTreeItem.vue +17 -6
  26. package/src/components/DitoView.vue +21 -3
  27. package/src/components/index.js +1 -0
  28. package/src/mixins/DitoMixin.js +53 -7
  29. package/src/mixins/ItemMixin.js +3 -6
  30. package/src/mixins/NumberMixin.js +47 -31
  31. package/src/mixins/OptionsMixin.js +132 -71
  32. package/src/mixins/ResourceMixin.js +5 -2
  33. package/src/mixins/RouteMixin.js +39 -1
  34. package/src/mixins/SortableMixin.js +0 -13
  35. package/src/mixins/SourceMixin.js +155 -96
  36. package/src/mixins/TextMixin.js +1 -1
  37. package/src/mixins/TypeMixin.js +37 -22
  38. package/src/mixins/ValidationMixin.js +9 -27
  39. package/src/mixins/ValidatorMixin.js +5 -7
  40. package/src/mixins/ValueMixin.js +5 -2
  41. package/src/types/DitoTypeButton.vue +1 -1
  42. package/src/types/DitoTypeCheckbox.vue +1 -1
  43. package/src/types/DitoTypeCheckboxes.vue +1 -1
  44. package/src/types/DitoTypeCode.vue +8 -1
  45. package/src/types/DitoTypeColor.vue +20 -34
  46. package/src/types/DitoTypeComponent.vue +1 -1
  47. package/src/types/DitoTypeComputed.vue +4 -27
  48. package/src/types/DitoTypeDate.vue +16 -5
  49. package/src/types/DitoTypeLabel.vue +1 -4
  50. package/src/types/DitoTypeList.vue +9 -5
  51. package/src/types/DitoTypeMarkup.vue +25 -13
  52. package/src/types/DitoTypeMultiselect.vue +37 -6
  53. package/src/types/DitoTypeNumber.vue +1 -1
  54. package/src/types/DitoTypeObject.vue +10 -7
  55. package/src/types/DitoTypePanel.vue +20 -6
  56. package/src/types/DitoTypeProgress.vue +1 -1
  57. package/src/types/DitoTypeRadio.vue +1 -1
  58. package/src/types/DitoTypeSection.vue +32 -4
  59. package/src/types/DitoTypeSelect.vue +1 -1
  60. package/src/types/DitoTypeSlider.vue +1 -1
  61. package/src/types/DitoTypeSwitch.vue +1 -1
  62. package/src/types/DitoTypeText.vue +13 -15
  63. package/src/types/DitoTypeTextarea.vue +1 -1
  64. package/src/types/DitoTypeTreeList.vue +5 -7
  65. package/src/types/DitoTypeUpload.vue +1 -2
  66. package/src/utils/DataSchemaResolver.js +154 -0
  67. package/src/utils/FormModel.js +615 -0
  68. package/src/utils/data.js +20 -0
  69. package/src/utils/filter.js +3 -2
  70. package/src/utils/options.js +3 -0
  71. package/src/utils/request.js +70 -0
  72. package/src/utils/schema/data.js +659 -0
  73. package/src/utils/schema/lookup.js +250 -0
  74. package/src/utils/schema/setup.js +354 -0
  75. package/src/utils/schema/structure.js +172 -0
  76. package/src/utils/schema/types.js +34 -0
  77. package/src/utils/schema/validation.js +142 -0
  78. package/src/utils/units.js +70 -3
  79. package/types/index.d.ts +174 -59
  80. package/src/mixins/DataMixin.js +0 -131
  81. 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
+ }