diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-05 18:08:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-05 18:08:47 +0300 |
commit | dad16033c2b7cfd54ffe20ca5cc1d844e9e41be6 (patch) | |
tree | 8010601f9b7066e07166d997624b723ea4c3f816 /app/assets/javascripts/content_editor/services/content_editor.js | |
parent | 3c86701bc89302550abb9bbaa060132fdcd52480 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/content_editor/services/content_editor.js')
-rw-r--r-- | app/assets/javascripts/content_editor/services/content_editor.js | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/app/assets/javascripts/content_editor/services/content_editor.js b/app/assets/javascripts/content_editor/services/content_editor.js index 21843c482a8..b993851a92f 100644 --- a/app/assets/javascripts/content_editor/services/content_editor.js +++ b/app/assets/javascripts/content_editor/services/content_editor.js @@ -3,12 +3,13 @@ import { LOADING_CONTENT_EVENT, LOADING_SUCCESS_EVENT, LOADING_ERROR_EVENT } fro /* eslint-disable no-underscore-dangle */ export class ContentEditor { - constructor({ tiptapEditor, serializer, deserializer, eventHub, languageLoader }) { + constructor({ tiptapEditor, serializer, deserializer, assetResolver, eventHub, languageLoader }) { this._tiptapEditor = tiptapEditor; this._serializer = serializer; this._deserializer = deserializer; this._eventHub = eventHub; this._languageLoader = languageLoader; + this._assetResolver = assetResolver; } get tiptapEditor() { @@ -34,22 +35,27 @@ export class ContentEditor { this._eventHub.dispose(); } + deserialize(serializedContent) { + const { _tiptapEditor: editor, _deserializer: deserializer } = this; + + return deserializer.deserialize({ + schema: editor.schema, + content: serializedContent, + }); + } + + resolveAssetUrl(canonicalSrc) { + return this._assetResolver.resolveUrl(canonicalSrc); + } + async setSerializedContent(serializedContent) { - const { - _tiptapEditor: editor, - _deserializer: deserializer, - _eventHub: eventHub, - _languageLoader: languageLoader, - } = this; + const { _tiptapEditor: editor, _eventHub: eventHub, _languageLoader: languageLoader } = this; const { doc, tr } = editor.state; const selection = TextSelection.create(doc, 0, doc.content.size); try { eventHub.$emit(LOADING_CONTENT_EVENT); - const result = await deserializer.deserialize({ - schema: editor.schema, - content: serializedContent, - }); + const result = await this.deserialize(serializedContent); if (Object.keys(result).length !== 0) { const { document, languages } = result; |