From e5acb34a81f6824bbb23899a331d81f9ba578b85 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 16 Apr 2020 22:11:45 +0100 Subject: [PATCH] Fixed mobiledoc-kit automatically upgrading document version refs https://github.com/TryGhost/Ghost-Admin/commit/6f5c2a95572b1e6360fe62d10fb4778b6fa40cdc - we previously set a fixed mobiledoc spec version in blank documents but when the editor was serializing to a json string after editing it was bumping the spec version - makes the specific version a constant to be used when serializing any mobiledoc --- .../addon/components/koenig-basic-html-input.js | 17 ++--------------- .../addon/components/koenig-editor.js | 6 +++--- .../koenig-text-replacement-html-input.js | 17 ++--------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js index 0a0cd23b03..0d6dadc446 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js @@ -5,6 +5,7 @@ import layout from '../templates/components/koenig-basic-html-input'; import parserPlugins from '../options/basic-html-parser-plugins'; import registerKeyCommands, {BASIC_KEY_COMMANDS} from '../options/key-commands'; import validator from 'validator'; +import {BLANK_DOC, MOBILEDOC_VERSION} from './koenig-editor'; import {DRAG_DISABLED_DATA_ATTR} from '../lib/dnd/constants'; import {arrayToMap, toggleSpecialFormatEditState} from './koenig-editor'; import {assign} from '@ember/polyfills'; @@ -16,20 +17,6 @@ import {run} from '@ember/runloop'; const UNDO_DEPTH = 50; -// blank doc contains a single empty paragraph so that there's some content for -// the cursor to start in -const BLANK_DOC = { - version: '0.3.1', - markups: [], - atoms: [], - cards: [], - sections: [ - [1, 'p', [ - [0, [], 0, ''] - ]] - ] -}; - // TODO: extract core to share functionality between this and `{{koenig-editor}}` export default Component.extend({ @@ -201,7 +188,7 @@ export default Component.extend({ // update mobiledoc reference to match initial editor state from parsed // html. We use this value to compare on re-renders in case we need to // re-parse from html - this.mobiledoc = editor.serialize(); + this.mobiledoc = editor.serialize(MOBILEDOC_VERSION); this._lastMobiledoc = this.mobiledoc; this.set('editor', editor); diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js index 9249648010..8f2dd48d6d 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-editor.js @@ -43,8 +43,9 @@ export const TESTING_EXPANDO_PROPERTY = '__mobiledoc_kit_editor'; // blank doc contains a single empty paragraph so that there's some content for // the cursor to start in +export const MOBILEDOC_VERSION = '0.3.1'; export const BLANK_DOC = { - version: '0.3.1', + version: MOBILEDOC_VERSION, markups: [], atoms: [], cards: [], @@ -683,8 +684,7 @@ export default Component.extend({ /* mobiledoc event handlers --------------------------------------------- */ postDidChange(editor) { - let serializeVersion = this.serializeVersion; - let updatedMobiledoc = editor.serialize(serializeVersion); + let updatedMobiledoc = editor.serialize(MOBILEDOC_VERSION); this._localMobiledoc = updatedMobiledoc; // trigger closure action diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-text-replacement-html-input.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-text-replacement-html-input.js index 7face184d8..2f51d0be51 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-text-replacement-html-input.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-text-replacement-html-input.js @@ -5,6 +5,7 @@ import defaultAtoms from '../options/atoms'; import layout from '../templates/components/koenig-text-replacement-html-input'; import registerKeyCommands, {TEXT_REPLACEMENT_KEY_COMMANDS} from '../options/key-commands'; import validator from 'validator'; +import {BLANK_DOC, MOBILEDOC_VERSION} from './koenig-editor'; import {DRAG_DISABLED_DATA_ATTR} from '../lib/dnd/constants'; import {arrayToMap, toggleSpecialFormatEditState} from './koenig-editor'; import {assign} from '@ember/polyfills'; @@ -18,20 +19,6 @@ import {run} from '@ember/runloop'; const UNDO_DEPTH = 50; -// blank doc contains a single empty paragraph so that there's some content for -// the cursor to start in -const BLANK_DOC = { - version: '0.3.1', - markups: [], - atoms: [], - cards: [], - sections: [ - [1, 'p', [ - [0, [], 0, ''] - ]] - ] -}; - // markups that should not be continued when typing and reverted to their // text expansion style when backspacing over final char of markup export const SPECIAL_MARKUPS = { @@ -208,7 +195,7 @@ export default Component.extend({ // update mobiledoc reference to match initial editor state from parsed // html. We use this value to compare on re-renders in case we need to // re-parse from html - this.mobiledoc = editor.serialize(); + this.mobiledoc = editor.serialize(MOBILEDOC_VERSION); this._lastMobiledoc = this.mobiledoc; this.set('editor', editor);