@live-change/frontend-auto-form 0.9.4 → 0.9.6
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.
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup>
|
|
6
|
+
|
|
7
|
+
import { ref, computed, onMounted, defineProps, defineEmits, toRefs } from 'vue'
|
|
8
|
+
|
|
9
|
+
const props = defineProps({
|
|
10
|
+
editor: {
|
|
11
|
+
type: Object,
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
discardDraft: {
|
|
15
|
+
type: Boolean,
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
options: {
|
|
19
|
+
type: Object,
|
|
20
|
+
default: () => ({})
|
|
21
|
+
},
|
|
22
|
+
i18n: {
|
|
23
|
+
type: String,
|
|
24
|
+
default: ''
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
const { editor, discardDraft, options, i18n } = toRefs(props)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<style scoped>
|
|
34
|
+
|
|
35
|
+
</style>
|
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
v-model="editor.value.value"
|
|
7
7
|
:rootValue="editor.value.value"
|
|
8
8
|
:i18n="i18n" />
|
|
9
|
-
<
|
|
10
|
-
save buttons
|
|
11
|
-
</div>
|
|
9
|
+
<EditorButtons :editor="editor" discard-draft />
|
|
12
10
|
</div>
|
|
13
11
|
</div>
|
|
14
12
|
</template>
|
|
@@ -16,6 +14,7 @@
|
|
|
16
14
|
<script setup>
|
|
17
15
|
|
|
18
16
|
import AutoEditor from '../form/AutoEditor.vue'
|
|
17
|
+
import EditorButtons from './EditorButtons.vue'
|
|
19
18
|
|
|
20
19
|
import { ref, computed, onMounted, defineProps, defineEmits, toRefs } from 'vue'
|
|
21
20
|
|
|
@@ -61,23 +60,33 @@
|
|
|
61
60
|
import { computedAsync } from "@vueuse/core"
|
|
62
61
|
|
|
63
62
|
const editor = computedAsync(async () => {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
63
|
+
try {
|
|
64
|
+
const ed = await editorData({
|
|
65
|
+
service: service.value,
|
|
66
|
+
model: model.value,
|
|
67
|
+
identifiers: identifiers.value,
|
|
68
|
+
draft: draft.value,
|
|
69
|
+
autoSave: true,
|
|
70
|
+
...options.value,
|
|
71
|
+
onSaved: (...args) => emit('saved', ...args),
|
|
72
|
+
onDraftSaved: (...args) => emit('draftSaved', ...args),
|
|
73
|
+
onDraftDiscarded: (...args) => emit('draftDiscarded', ...args),
|
|
74
|
+
onSaveError: (...args) => emit('saveError', ...args),
|
|
75
|
+
onCreated: (...args) => emit('created', ...args),
|
|
76
|
+
})
|
|
77
|
+
//console.log("ED", ed)
|
|
78
|
+
return ed
|
|
79
|
+
} catch(e) {
|
|
80
|
+
console.error("EDITOR ERROR", e)
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
79
83
|
})
|
|
80
84
|
|
|
85
|
+
const isNew = computed(() => editor.value.saved.value)
|
|
86
|
+
|
|
87
|
+
/// TODO: detect when we should change identifiers
|
|
88
|
+
// const savedIdentifiers
|
|
89
|
+
|
|
81
90
|
</script>
|
|
82
91
|
|
|
83
92
|
<style scoped>
|
|
@@ -37,6 +37,7 @@ export default function editorData(options) {
|
|
|
37
37
|
workingZone = inject('workingZone')
|
|
38
38
|
|
|
39
39
|
} = options
|
|
40
|
+
|
|
40
41
|
if(!identifiers) throw new Error('identifiers must be defined')
|
|
41
42
|
if(!serviceName || !modelName) throw new Error('service and model must be defined')
|
|
42
43
|
|
|
@@ -45,10 +46,11 @@ export default function editorData(options) {
|
|
|
45
46
|
const {
|
|
46
47
|
crudMethods = model.crud,
|
|
47
48
|
identifiersNames = model.identifiers,
|
|
48
|
-
editableProperties = model.editableProperties
|
|
49
|
+
editableProperties = model.editableProperties ?? Object.keys(model.properties)
|
|
49
50
|
} = options
|
|
51
|
+
|
|
50
52
|
if(!crudMethods) throw new Error('crud methods must be defined in model or options')
|
|
51
|
-
if(!
|
|
53
|
+
if(!identifiersNames) throw new Error('identifiers names must be defined in model or options')
|
|
52
54
|
if(!editableProperties) throw new Error('editableProperties must be defined in model or options')
|
|
53
55
|
|
|
54
56
|
let idKey = null
|
|
@@ -65,14 +67,14 @@ export default function editorData(options) {
|
|
|
65
67
|
draftIdParts.push(identifier)
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const isNew = (idKey ? (!identifiers[idKey]) : (!draftIdParts.some(key => !identifiers[key])))
|
|
71
|
+
const draftId = (idKey ? identifiers[idKey]
|
|
72
|
+
: draftIdParts.map(key => JSON.stringify(identifiers[key])).join('_')) ?? 'new'
|
|
71
73
|
const draftIdentifiers = {
|
|
72
74
|
actionType: serviceName, action: crudMethods.read, targetType: modelName, target: draftId
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
const savedDataPath = path[serviceName][crudMethods.read](identifiers)
|
|
77
|
+
const savedDataPath = isNew ? null : path[serviceName][crudMethods.read](identifiers)
|
|
76
78
|
const draftDataPath = (draft && path.draft.myDraft(draftIdentifiers)) || null
|
|
77
79
|
|
|
78
80
|
const updateAction = api.actions[serviceName][crudMethods.update]
|
|
@@ -84,6 +86,7 @@ export default function editorData(options) {
|
|
|
84
86
|
return Promise.all([
|
|
85
87
|
live(savedDataPath), live(draftDataPath)
|
|
86
88
|
]).then(([savedData, draftData]) => {
|
|
89
|
+
|
|
87
90
|
const editableSavedData = computed(() => savedData.value && Object.fromEntries(
|
|
88
91
|
editableProperties.map(prop => [prop, savedData.value[prop]])
|
|
89
92
|
.concat([[timeField, savedData.value[timeField]]])
|
|
@@ -179,6 +182,8 @@ export default function editorData(options) {
|
|
|
179
182
|
draftChanged: synchronizedData.changed,
|
|
180
183
|
saveDraft: synchronizedData.save,
|
|
181
184
|
savingDraft: synchronizedData.saving,
|
|
185
|
+
saved: savedData,
|
|
186
|
+
draft: draftData,
|
|
182
187
|
sourceChanged /// needed for draft discard on concurrent save
|
|
183
188
|
}
|
|
184
189
|
} else {
|
|
@@ -207,6 +212,7 @@ export default function editorData(options) {
|
|
|
207
212
|
changed: synchronizedData.changed,
|
|
208
213
|
save: synchronizedData.save,
|
|
209
214
|
saving: synchronizedData.saving,
|
|
215
|
+
saved: savedData,
|
|
210
216
|
model,
|
|
211
217
|
}
|
|
212
218
|
|
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.6",
|
|
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.5.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.6",
|
|
26
|
+
"@live-change/dao": "^0.9.6",
|
|
27
|
+
"@live-change/dao-vue3": "^0.9.6",
|
|
28
|
+
"@live-change/dao-websocket": "^0.9.6",
|
|
29
|
+
"@live-change/framework": "^0.9.6",
|
|
30
|
+
"@live-change/image-frontend": "^0.9.6",
|
|
31
|
+
"@live-change/image-service": "^0.9.6",
|
|
32
|
+
"@live-change/session-service": "^0.9.6",
|
|
33
|
+
"@live-change/vue3-components": "^0.9.6",
|
|
34
|
+
"@live-change/vue3-ssr": "^0.9.6",
|
|
35
35
|
"@vueuse/core": "^10.11.0",
|
|
36
36
|
"codeceptjs-assert": "^0.0.5",
|
|
37
37
|
"compression": "^1.7.4",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"vue3-scroll-border": "0.1.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@live-change/codeceptjs-helper": "^0.9.
|
|
55
|
+
"@live-change/codeceptjs-helper": "^0.9.6",
|
|
56
56
|
"codeceptjs": "^3.6.5",
|
|
57
57
|
"generate-password": "1.7.1",
|
|
58
58
|
"playwright": "1.48.1",
|
|
@@ -63,5 +63,5 @@
|
|
|
63
63
|
"author": "Michał Łaszczewski <michal@laszczewski.pl>",
|
|
64
64
|
"license": "ISC",
|
|
65
65
|
"description": "",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "96dafb43cced09c59326ee3318d6f45b1b614d6f"
|
|
67
67
|
}
|