refactor: post rendered content changed to be provided by editor (#449)

Signed-off-by: Ryan Wang <i@ryanc.cc>
pull/452/head
Ryan Wang 2022-02-21 22:55:15 +08:00 committed by GitHub
parent 7f6234e7f7
commit 30f09aca8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 17 deletions

View File

@ -24,7 +24,7 @@
"@codemirror/basic-setup": "^0.19.1", "@codemirror/basic-setup": "^0.19.1",
"@codemirror/lang-html": "^0.19.4", "@codemirror/lang-html": "^0.19.4",
"@codemirror/lang-java": "^0.19.1", "@codemirror/lang-java": "^0.19.1",
"@halo-dev/admin-api": "^1.0.0-alpha.48", "@halo-dev/admin-api": "^1.0.0-alpha.49",
"@halo-dev/editor": "^3.0.0-alpha.1", "@halo-dev/editor": "^3.0.0-alpha.1",
"ant-design-vue": "^1.7.8", "ant-design-vue": "^1.7.8",
"dayjs": "^1.10.7", "dayjs": "^1.10.7",

View File

@ -6,7 +6,7 @@ specifiers:
'@codemirror/basic-setup': ^0.19.1 '@codemirror/basic-setup': ^0.19.1
'@codemirror/lang-html': ^0.19.4 '@codemirror/lang-html': ^0.19.4
'@codemirror/lang-java': ^0.19.1 '@codemirror/lang-java': ^0.19.1
'@halo-dev/admin-api': ^1.0.0-alpha.48 '@halo-dev/admin-api': ^1.0.0-alpha.49
'@halo-dev/editor': ^3.0.0-alpha.1 '@halo-dev/editor': ^3.0.0-alpha.1
'@vue/cli-plugin-babel': ~5.0.0-rc.2 '@vue/cli-plugin-babel': ~5.0.0-rc.2
'@vue/cli-plugin-eslint': ~5.0.0-rc.2 '@vue/cli-plugin-eslint': ~5.0.0-rc.2
@ -51,7 +51,7 @@ dependencies:
'@codemirror/basic-setup': 0.19.1 '@codemirror/basic-setup': 0.19.1
'@codemirror/lang-html': 0.19.4 '@codemirror/lang-html': 0.19.4
'@codemirror/lang-java': 0.19.1 '@codemirror/lang-java': 0.19.1
'@halo-dev/admin-api': 1.0.0-alpha.48 '@halo-dev/admin-api': 1.0.0-alpha.49
'@halo-dev/editor': 3.0.0-alpha.1 '@halo-dev/editor': 3.0.0-alpha.1
ant-design-vue: 1.7.8_9065e7474e033a8e4b95615fc8e6c36c ant-design-vue: 1.7.8_9065e7474e033a8e4b95615fc8e6c36c
dayjs: 1.10.7 dayjs: 1.10.7
@ -1568,11 +1568,11 @@ packages:
- supports-color - supports-color
dev: true dev: true
/@halo-dev/admin-api/1.0.0-alpha.48: /@halo-dev/admin-api/1.0.0-alpha.49:
resolution: {integrity: sha512-TmNrskgq8BbiufmA/lSGDK7jJPzReUdsM6hTBRcItxzByLLFH0+1WSdSb4dkAppZV7BA/AfY0ilfDNFpqTOfvQ==} resolution: {integrity: sha512-549LNmiVDyjLfg9uvVYYCCJmfge8+hrNDk4Q9M0BUT9XB9xeQcV0S06Tz2MKR/3IAZhq8h2V3g5gIqaY7N9e9A==}
engines: {node: '>=12'} engines: {node: '>=12'}
dependencies: dependencies:
'@halo-dev/rest-api-client': 1.0.0-alpha.48 '@halo-dev/rest-api-client': 1.0.0-alpha.49
tslib: 2.3.1 tslib: 2.3.1
transitivePeerDependencies: transitivePeerDependencies:
- debug - debug
@ -1607,18 +1607,18 @@ packages:
vue: 2.6.14 vue: 2.6.14
dev: false dev: false
/@halo-dev/logger/1.0.0-alpha.48: /@halo-dev/logger/1.0.0-alpha.49:
resolution: {integrity: sha512-1Gl8YP+XqMrRJlfMVIm9zc/nQMDKIMaOAo4tIpxmJIBpR17h/lc5PPW3NH3vWMN0JNpT4wys2MFL8LQ1H9WZKA==} resolution: {integrity: sha512-gshHffq0ntrPjAHCwRt6J3NJYvQfnlZsRgbBjnFyI5TQOSB5uFZ2dcxRAc75wDLTRFi2Brpsdm//odRe7PWGpg==}
engines: {node: '>=12.0.0'} engines: {node: '>=12.0.0'}
dependencies: dependencies:
tslib: 2.3.1 tslib: 2.3.1
dev: false dev: false
/@halo-dev/rest-api-client/1.0.0-alpha.48: /@halo-dev/rest-api-client/1.0.0-alpha.49:
resolution: {integrity: sha512-HFKQOfV5I9L72SENanUQ4wQFlF2ZJFgpr0czZ2nHqcrgMSVa4GSNK7dKGCbU819NPZcKyfGXcD5sa9htqwQ9Cg==} resolution: {integrity: sha512-tv2y4EvfJt55iAuUASKjqVv3Qt6xhh4oTG/qO+vr+Z+DEcMos+iX/fpeZwHW5/LmR0wdercBncOEP1qgOX9L0g==}
engines: {node: '>=12'} engines: {node: '>=12'}
dependencies: dependencies:
'@halo-dev/logger': 1.0.0-alpha.48 '@halo-dev/logger': 1.0.0-alpha.49
axios: 0.24.0 axios: 0.24.0
form-data: 4.0.0 form-data: 4.0.0
js-base64: 3.7.2 js-base64: 3.7.2

View File

@ -120,7 +120,12 @@ export default {
if (this.postToStage.id) { if (this.postToStage.id) {
// Update the post content // Update the post content
try { try {
const { data } = await apiClient.post.updateDraftById(this.postToStage.id, this.postToStage.originalContent) const { data } = await apiClient.post.updateDraftById(
this.postToStage.id,
this.postToStage.originalContent,
this.postToStage.content,
true
)
this.postToStage.inProgress = data.inProgress this.postToStage.inProgress = data.inProgress
this.handleRestoreSavedStatus() this.handleRestoreSavedStatus()
this.$message.success({ this.$message.success({
@ -141,6 +146,8 @@ export default {
} }
// Create the post // Create the post
try { try {
this.postToStage.keepRaw = true
const { data } = await apiClient.post.create(this.postToStage) const { data } = await apiClient.post.create(this.postToStage)
this.postToStage = data this.postToStage = data
this.handleRestoreSavedStatus() this.handleRestoreSavedStatus()
@ -162,7 +169,12 @@ export default {
this.previewSaving = true this.previewSaving = true
if (this.postToStage.id) { if (this.postToStage.id) {
// Update the post content // Update the post content
const { data } = await apiClient.post.updateDraftById(this.postToStage.id, this.postToStage.originalContent) const { data } = await apiClient.post.updateDraftById(
this.postToStage.id,
this.postToStage.originalContent,
this.postToStage.content,
true
)
this.postToStage.inProgress = data.inProgress this.postToStage.inProgress = data.inProgress
} else { } else {
await this.handleCreatePost() await this.handleCreatePost()
@ -187,9 +199,10 @@ export default {
handleRestoreSavedStatus() { handleRestoreSavedStatus() {
this.contentChanges = 0 this.contentChanges = 0
}, },
onContentChange({ originalContent }) { onContentChange({ originalContent, renderContent }) {
this.contentChanges++ this.contentChanges++
this.postToStage.originalContent = originalContent this.postToStage.originalContent = originalContent
this.postToStage.content = renderContent
}, },
onPostSavedCallback() { onPostSavedCallback() {
this.contentChanges = 0 this.contentChanges = 0

View File

@ -298,6 +298,7 @@ export default {
} }
this.form.model.status = preStatus this.form.model.status = preStatus
this.form.model.keepRaw = true
const { id, status } = this.form.model const { id, status } = this.form.model
try { try {
this.form[status === 'PUBLISHED' ? 'saving' : 'draftSaving'] = true this.form[status === 'PUBLISHED' ? 'saving' : 'draftSaving'] = true

View File

@ -123,7 +123,9 @@ export default {
try { try {
const { data } = await apiClient.sheet.updateDraftById( const { data } = await apiClient.sheet.updateDraftById(
this.sheetToStage.id, this.sheetToStage.id,
this.sheetToStage.originalContent this.sheetToStage.originalContent,
this.sheetToStage.content,
true
) )
this.sheetToStage.inProgress = data.inProgress this.sheetToStage.inProgress = data.inProgress
this.handleRestoreSavedStatus() this.handleRestoreSavedStatus()
@ -144,6 +146,7 @@ export default {
this.sheetToStage.title = datetimeFormat(new Date(), 'YYYY-MM-DD-HH-mm-ss') this.sheetToStage.title = datetimeFormat(new Date(), 'YYYY-MM-DD-HH-mm-ss')
} }
try { try {
this.sheetToStage.keepRaw = true
const { data } = await apiClient.sheet.create(this.sheetToStage) const { data } = await apiClient.sheet.create(this.sheetToStage)
this.sheetToStage = data this.sheetToStage = data
this.handleRestoreSavedStatus() this.handleRestoreSavedStatus()
@ -164,7 +167,12 @@ export default {
this.previewSaving = true this.previewSaving = true
if (this.sheetToStage.id) { if (this.sheetToStage.id) {
// Update the sheet content // Update the sheet content
const { data } = await apiClient.sheet.updateDraftById(this.sheetToStage.id, this.sheetToStage.originalContent) const { data } = await apiClient.sheet.updateDraftById(
this.sheetToStage.id,
this.sheetToStage.originalContent,
this.sheetToStage.content,
true
)
this.sheetToStage.inProgress = data.inProgress this.sheetToStage.inProgress = data.inProgress
} else { } else {
await this.handleCreateSheet() await this.handleCreateSheet()
@ -189,9 +197,10 @@ export default {
handleRestoreSavedStatus() { handleRestoreSavedStatus() {
this.contentChanges = 0 this.contentChanges = 0
}, },
onContentChange({ originalContent }) { onContentChange({ originalContent, renderContent }) {
this.contentChanges++ this.contentChanges++
this.sheetToStage.originalContent = originalContent this.sheetToStage.originalContent = originalContent
this.sheetToStage.content = renderContent
}, },
onSheetSavedCallback() { onSheetSavedCallback() {
this.contentChanges = 0 this.contentChanges = 0

View File

@ -258,6 +258,7 @@ export default {
return return
} }
this.form.model.status = preStatus this.form.model.status = preStatus
this.form.model.keepRaw = true
const { id, status } = this.form.model const { id, status } = this.form.model
try { try {
this.form[status === 'PUBLISHED' ? 'saving' : 'draftSaving'] = true this.form[status === 'PUBLISHED' ? 'saving' : 'draftSaving'] = true