@ditojs/admin 3.0.0 → 3.1.1
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.es.js +2043 -1956
- package/dist/dito-admin.umd.js +5 -6
- package/package.json +8 -6
- package/src/DitoAdmin.js +1 -65
- package/src/DitoTypeComponent.js +17 -0
- package/src/components/DitoButtons.vue +14 -1
- package/src/components/DitoDialog.vue +1 -1
- package/src/components/DitoForm.vue +3 -8
- package/src/components/DitoPanel.vue +3 -2
- package/src/components/DitoRoot.vue +1 -8
- package/src/components/DitoRouterView.vue +27 -0
- package/src/components/DitoView.vue +2 -7
- package/src/components/index.js +1 -0
- package/src/mixins/DitoMixin.js +28 -17
- package/src/mixins/OptionsMixin.js +14 -4
- package/src/mixins/ResourceMixin.js +4 -2
- package/src/mixins/RouteMixin.js +1 -1
- package/src/mixins/SourceMixin.js +13 -1
- package/src/types/DitoTypeMultiselect.vue +23 -12
- package/src/types/DitoTypePanel.vue +2 -1
- package/src/types/DitoTypeTreeList.vue +5 -11
- package/src/utils/DataSchemaResolver.js +13 -0
- package/src/utils/FormModel.js +91 -32
- package/src/utils/request.js +70 -0
- package/src/utils/schema/data.js +102 -37
- package/src/utils/schema/lookup.js +9 -25
- package/src/utils/schema/validation.js +2 -4
- package/types/index.d.ts +25 -0
- package/src/utils/DataSchemaResolver.test.js +0 -132
- package/src/utils/FormModel.test.js +0 -808
- package/src/utils/data.test.js +0 -28
- package/src/utils/schema/data.test.js +0 -471
- package/src/utils/schema/lookup.test.js +0 -61
- package/src/utils/schema/structure.test.js +0 -57
- package/src/utils/schema/validation.test.js +0 -395
- package/src/utils/units.test.js +0 -71
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { vi } from 'vitest'
|
|
2
|
-
import { reactive, nextTick } from 'vue'
|
|
3
|
-
import { DataSchemaResolver } from './DataSchemaResolver.js'
|
|
4
|
-
|
|
5
|
-
function createResolver(dataSchema, context = {}) {
|
|
6
|
-
const pendingLoads = []
|
|
7
|
-
const resolver = new DataSchemaResolver(dataSchema, {
|
|
8
|
-
createContext: () => context,
|
|
9
|
-
onLoadStart: promise => pendingLoads.push(promise)
|
|
10
|
-
})
|
|
11
|
-
const waitForPendingLoads = () => Promise.all(pendingLoads)
|
|
12
|
-
return { resolver, pendingLoads, waitForPendingLoads }
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('DataSchemaResolver', () => {
|
|
16
|
-
it('resolves data schemas that are values', () => {
|
|
17
|
-
const options = ['Small', 'Large']
|
|
18
|
-
const { resolver } = createResolver(options)
|
|
19
|
-
expect(resolver.value).toBe(options)
|
|
20
|
-
expect(resolver.isLoading).toBe(false)
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('resolves `data` values and functions', () => {
|
|
24
|
-
const item = reactive({ title: 'Hello' })
|
|
25
|
-
const { resolver } = createResolver(
|
|
26
|
-
{ data: ({ item }) => item.title.toUpperCase() },
|
|
27
|
-
{ item }
|
|
28
|
-
)
|
|
29
|
-
expect(resolver.value).toBe('HELLO')
|
|
30
|
-
item.title = 'Bye'
|
|
31
|
-
expect(resolver.value).toBe('BYE')
|
|
32
|
-
expect(createResolver({ data: 'Static' }).resolver.value).toBe('Static')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('resolves `dataPath` relative to the data path of the context', () => {
|
|
36
|
-
const rootItem = reactive({ sizes: ['S', 'M'], item: {} })
|
|
37
|
-
const { resolver } = createResolver(
|
|
38
|
-
{ dataPath: '../../sizes' },
|
|
39
|
-
{ rootItem, dataPath: 'item/size' }
|
|
40
|
-
)
|
|
41
|
-
expect(resolver.value).toBe(rootItem.sizes)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('evaluates and loads nothing before it is read', async () => {
|
|
45
|
-
const data = vi.fn(() => async () => ['A'])
|
|
46
|
-
const { resolver, pendingLoads } = createResolver({ data })
|
|
47
|
-
await nextTick()
|
|
48
|
-
expect(data).not.toHaveBeenCalled()
|
|
49
|
-
expect(pendingLoads).toHaveLength(0)
|
|
50
|
-
expect(resolver.value).toBe(undefined)
|
|
51
|
-
expect(data).toHaveBeenCalledTimes(1)
|
|
52
|
-
expect(pendingLoads).toHaveLength(1)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('loads values asynchronously, keeping their object identity', async () => {
|
|
56
|
-
const options = [{ id: 1 }]
|
|
57
|
-
const { resolver, waitForPendingLoads } = createResolver({
|
|
58
|
-
data: async () => options
|
|
59
|
-
})
|
|
60
|
-
expect(resolver.value).toBe(undefined)
|
|
61
|
-
expect(resolver.isLoading).toBe(true)
|
|
62
|
-
await waitForPendingLoads()
|
|
63
|
-
expect(resolver.value).toBe(options)
|
|
64
|
-
expect(resolver.isLoading).toBe(false)
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it('loads again only when the dependencies of `data()` change', async () => {
|
|
68
|
-
const item = reactive({ category: 'news', title: 'Hello' })
|
|
69
|
-
const load = vi.fn(async category => [`${category}-1`])
|
|
70
|
-
const { resolver, waitForPendingLoads } = createResolver(
|
|
71
|
-
{
|
|
72
|
-
data: ({ item }) => {
|
|
73
|
-
const { category } = item
|
|
74
|
-
return async () => load(category)
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
{ item }
|
|
78
|
-
)
|
|
79
|
-
resolver.value
|
|
80
|
-
await waitForPendingLoads()
|
|
81
|
-
expect(resolver.value).toEqual(['news-1'])
|
|
82
|
-
item.title = 'Changed'
|
|
83
|
-
expect(resolver.value).toEqual(['news-1'])
|
|
84
|
-
item.category = 'sports'
|
|
85
|
-
expect(resolver.value).toBe(undefined)
|
|
86
|
-
await waitForPendingLoads()
|
|
87
|
-
expect(resolver.value).toEqual(['sports-1'])
|
|
88
|
-
expect(load).toHaveBeenCalledTimes(2)
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it('discards the values of outdated loads', async () => {
|
|
92
|
-
const item = reactive({ category: 'news' })
|
|
93
|
-
const resolvers = {}
|
|
94
|
-
const { resolver, waitForPendingLoads } = createResolver(
|
|
95
|
-
{
|
|
96
|
-
data: ({ item }) => {
|
|
97
|
-
const { category } = item
|
|
98
|
-
return () =>
|
|
99
|
-
new Promise(resolve => {
|
|
100
|
-
resolvers[category] = () => resolve(category)
|
|
101
|
-
})
|
|
102
|
-
}
|
|
103
|
-
},
|
|
104
|
-
{ item }
|
|
105
|
-
)
|
|
106
|
-
resolver.value
|
|
107
|
-
item.category = 'sports'
|
|
108
|
-
resolver.value
|
|
109
|
-
await nextTick()
|
|
110
|
-
resolvers.sports()
|
|
111
|
-
resolvers.news()
|
|
112
|
-
await waitForPendingLoads()
|
|
113
|
-
expect(resolver.value).toBe('sports')
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
it('keeps the error of the last load in `lastLoadError`', async () => {
|
|
117
|
-
vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
118
|
-
const error = new Error('Failed')
|
|
119
|
-
const { resolver, waitForPendingLoads } = createResolver({
|
|
120
|
-
data: async () => {
|
|
121
|
-
throw error
|
|
122
|
-
}
|
|
123
|
-
})
|
|
124
|
-
resolver.value
|
|
125
|
-
await waitForPendingLoads()
|
|
126
|
-
expect(resolver.value).toBe(undefined)
|
|
127
|
-
expect(resolver.isLoading).toBe(false)
|
|
128
|
-
expect(resolver.lastLoadError).toBe(error)
|
|
129
|
-
expect(console.error).toHaveBeenCalledWith(error)
|
|
130
|
-
vi.restoreAllMocks()
|
|
131
|
-
})
|
|
132
|
-
})
|