@live-change/frontend-auto-form 0.9.171 → 0.9.174
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 +12 -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')
|
|
@@ -72,9 +74,11 @@ export default function editorData(options) {
|
|
|
72
74
|
draftIdParts.push(identifier)
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
|
-
let draftId =
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
let draftId = options.draftId || (
|
|
78
|
+
idKey
|
|
79
|
+
? (identifiers[idKey])
|
|
80
|
+
: (draftIdParts.map(key => JSON.stringify(identifiers[key])).join('_'))
|
|
81
|
+
)
|
|
78
82
|
if(!draftId) draftId = 'new'
|
|
79
83
|
if(draftId.length > 16) {
|
|
80
84
|
draftId = cyrb128(draftId).slice(0, 16)
|
|
@@ -113,7 +117,7 @@ export default function editorData(options) {
|
|
|
113
117
|
editableProperties.map(prop => [prop, draftData.value.data[prop]])
|
|
114
118
|
.concat([[timeField, draftData.value.data[timeField]]])
|
|
115
119
|
))
|
|
116
|
-
const source = computed(() => editableDraftData.value || editableSavedData.value || defaultData(model))
|
|
120
|
+
const source = computed(() => editableDraftData.value || editableSavedData.value || deepmerge(defaultData(model), initialData))
|
|
117
121
|
|
|
118
122
|
const propertiesServerErrors = ref({})
|
|
119
123
|
const lastUploadedData = ref(null)
|
|
@@ -216,7 +220,7 @@ export default function editorData(options) {
|
|
|
216
220
|
if(workingZone)
|
|
217
221
|
workingZone.addPromise('discardDraft:'+serviceName+':'+modelName, discardPromise)
|
|
218
222
|
await discardPromise
|
|
219
|
-
synchronizedData.value.value = editableSavedData.value || defaultData(model)
|
|
223
|
+
synchronizedData.value.value = editableSavedData.value || deepmerge(defaultData(model), initialData)
|
|
220
224
|
if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: resetToast, life: 1500 })
|
|
221
225
|
onReset()
|
|
222
226
|
}
|
|
@@ -268,7 +272,7 @@ export default function editorData(options) {
|
|
|
268
272
|
propertiesServerErrors.value, appContext))
|
|
269
273
|
|
|
270
274
|
async function reset() {
|
|
271
|
-
synchronizedData.value.value = editableSavedData.value || defaultData(model)
|
|
275
|
+
synchronizedData.value.value = editableSavedData.value || deepmerge(defaultData(model), initialData)
|
|
272
276
|
if(toast && discardedDraftToast) toast.add({ severity: 'info', summary: resetToast, life: 1500 })
|
|
273
277
|
onReset()
|
|
274
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.174",
|
|
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.174",
|
|
26
|
+
"@live-change/dao": "^0.9.174",
|
|
27
|
+
"@live-change/dao-vue3": "^0.9.174",
|
|
28
|
+
"@live-change/dao-websocket": "^0.9.174",
|
|
29
|
+
"@live-change/framework": "^0.9.174",
|
|
30
|
+
"@live-change/image-frontend": "^0.9.174",
|
|
31
|
+
"@live-change/image-service": "^0.9.174",
|
|
32
|
+
"@live-change/session-service": "^0.9.174",
|
|
33
|
+
"@live-change/vue3-components": "^0.9.174",
|
|
34
|
+
"@live-change/vue3-ssr": "^0.9.174",
|
|
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.174",
|
|
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": "6ebdadad702526df240bd3aa7ac3d97324a0308a"
|
|
67
67
|
}
|