@live-change/frontend-auto-form 0.9.169 → 0.9.173
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/front/src/logic/editorData.js +14 -8
- package/package.json +13 -13
|
@@ -3,6 +3,8 @@ import { usePath, live, useApi } from '@live-change/vue3-ssr'
|
|
|
3
3
|
import { ref, computed, inject, watch, getCurrentInstance } from 'vue'
|
|
4
4
|
import { synchronized, defaultData } from '@live-change/vue3-components'
|
|
5
5
|
|
|
6
|
+
import deepmerge from 'deepmerge';
|
|
7
|
+
|
|
6
8
|
import { propertiesValidationErrors } from './validation.js'
|
|
7
9
|
|
|
8
10
|
import { cyrb128 } from './utils.js'
|
|
@@ -37,7 +39,6 @@ export default function editorData(options) {
|
|
|
37
39
|
onSaveError = () => {},
|
|
38
40
|
onCreated = (createResult) => {},
|
|
39
41
|
|
|
40
|
-
|
|
41
42
|
appContext = getCurrentInstance().appContext,
|
|
42
43
|
|
|
43
44
|
toast = useToast(options.appContext || getCurrentInstance().appContext),
|
|
@@ -45,6 +46,7 @@ export default function editorData(options) {
|
|
|
45
46
|
api = useApi(options.appContext || getCurrentInstance().appContext),
|
|
46
47
|
workingZone = inject('workingZone'),
|
|
47
48
|
|
|
49
|
+
initialData = {},
|
|
48
50
|
} = options
|
|
49
51
|
|
|
50
52
|
if(!identifiers) throw new Error('identifiers must be defined')
|
|
@@ -55,7 +57,7 @@ export default function editorData(options) {
|
|
|
55
57
|
const {
|
|
56
58
|
crudMethods = model.crud,
|
|
57
59
|
identifiersNames = model.identifiers,
|
|
58
|
-
editableProperties = model.editableProperties ?? Object.keys(model.properties)
|
|
60
|
+
editableProperties = model.editableProperties ?? Object.keys(model.properties),
|
|
59
61
|
} = options
|
|
60
62
|
|
|
61
63
|
if(!crudMethods) throw new Error('crud methods must be defined in model or options')
|
|
@@ -67,13 +69,17 @@ export default function editorData(options) {
|
|
|
67
69
|
for(const identifier of identifiersNames) {
|
|
68
70
|
if(typeof identifier === 'object') {
|
|
69
71
|
if(identifier.field === 'id') idKey = identifier.name
|
|
70
|
-
draftIdParts.push(
|
|
72
|
+
draftIdParts.push(identifier.field)
|
|
71
73
|
} else {
|
|
72
74
|
draftIdParts.push(identifier)
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
|
-
let draftId =
|
|
76
|
-
|
|
77
|
+
let draftId = options.draftId || (
|
|
78
|
+
idKey
|
|
79
|
+
? (identifiers[idKey])
|
|
80
|
+
: (draftIdParts.map(key => JSON.stringify(identifiers[key])).join('_'))
|
|
81
|
+
)
|
|
82
|
+
if(!draftId) draftId = 'new'
|
|
77
83
|
if(draftId.length > 16) {
|
|
78
84
|
draftId = cyrb128(draftId).slice(0, 16)
|
|
79
85
|
}
|
|
@@ -111,7 +117,7 @@ export default function editorData(options) {
|
|
|
111
117
|
editableProperties.map(prop => [prop, draftData.value.data[prop]])
|
|
112
118
|
.concat([[timeField, draftData.value.data[timeField]]])
|
|
113
119
|
))
|
|
114
|
-
const source = computed(() => editableDraftData.value || editableSavedData.value || defaultData(model))
|
|
120
|
+
const source = computed(() => editableDraftData.value || editableSavedData.value || deepmerge(defaultData(model), initialData))
|
|
115
121
|
|
|
116
122
|
const propertiesServerErrors = ref({})
|
|
117
123
|
const lastUploadedData = ref(null)
|
|
@@ -214,7 +220,7 @@ export default function editorData(options) {
|
|
|
214
220
|
if(workingZone)
|
|
215
221
|
workingZone.addPromise('discardDraft:'+serviceName+':'+modelName, discardPromise)
|
|
216
222
|
await discardPromise
|
|
217
|
-
synchronizedData.value.value = editableSavedData.value || defaultData(model)
|
|
223
|
+
synchronizedData.value.value = editableSavedData.value || deepmerge(defaultData(model), initialData)
|
|
218
224
|
if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: resetToast, life: 1500 })
|
|
219
225
|
onReset()
|
|
220
226
|
}
|
|
@@ -266,7 +272,7 @@ export default function editorData(options) {
|
|
|
266
272
|
propertiesServerErrors.value, appContext))
|
|
267
273
|
|
|
268
274
|
async function reset() {
|
|
269
|
-
synchronizedData.value.value = editableSavedData.value || defaultData(model)
|
|
275
|
+
synchronizedData.value.value = editableSavedData.value || deepmerge(defaultData(model), initialData)
|
|
270
276
|
if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: resetToast, life: 1500 })
|
|
271
277
|
onReset()
|
|
272
278
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/frontend-auto-form",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.173",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"memDev": "node server/start.js memDev --enableSessions --initScript ./init.js --dbAccess",
|
|
6
6
|
"localDevInit": "rm tmp.db; lcli localDev --enableSessions --initScript ./init.js",
|
|
@@ -22,16 +22,16 @@
|
|
|
22
22
|
"type": "module",
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@fortawesome/fontawesome-free": "^6.7.2",
|
|
25
|
-
"@live-change/cli": "^0.9.
|
|
26
|
-
"@live-change/dao": "^0.9.
|
|
27
|
-
"@live-change/dao-vue3": "^0.9.
|
|
28
|
-
"@live-change/dao-websocket": "^0.9.
|
|
29
|
-
"@live-change/framework": "^0.9.
|
|
30
|
-
"@live-change/image-frontend": "^0.9.
|
|
31
|
-
"@live-change/image-service": "^0.9.
|
|
32
|
-
"@live-change/session-service": "^0.9.
|
|
33
|
-
"@live-change/vue3-components": "^0.9.
|
|
34
|
-
"@live-change/vue3-ssr": "^0.9.
|
|
25
|
+
"@live-change/cli": "^0.9.173",
|
|
26
|
+
"@live-change/dao": "^0.9.173",
|
|
27
|
+
"@live-change/dao-vue3": "^0.9.173",
|
|
28
|
+
"@live-change/dao-websocket": "^0.9.173",
|
|
29
|
+
"@live-change/framework": "^0.9.173",
|
|
30
|
+
"@live-change/image-frontend": "^0.9.173",
|
|
31
|
+
"@live-change/image-service": "^0.9.173",
|
|
32
|
+
"@live-change/session-service": "^0.9.173",
|
|
33
|
+
"@live-change/vue3-components": "^0.9.173",
|
|
34
|
+
"@live-change/vue3-ssr": "^0.9.173",
|
|
35
35
|
"@vueuse/core": "^12.3.0",
|
|
36
36
|
"codeceptjs-assert": "^0.0.5",
|
|
37
37
|
"compression": "^1.7.5",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue3-scroll-border": "0.1.7"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@live-change/codeceptjs-helper": "^0.9.
|
|
55
|
+
"@live-change/codeceptjs-helper": "^0.9.173",
|
|
56
56
|
"codeceptjs": "^3.6.10",
|
|
57
57
|
"generate-password": "1.7.1",
|
|
58
58
|
"playwright": "1.49.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"author": "Michał Łaszczewski <michal@laszczewski.pl>",
|
|
64
64
|
"license": "ISC",
|
|
65
65
|
"description": "",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "1d70f7baf204d8f9848f53f5023db91016c6093f"
|
|
67
67
|
}
|