mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-02 08:13:34 +03:00
2236d2ef24
refs TryGhost/Team#2904 <!-- Leave the line below if you'd like GitHub Copilot to generate a summary from your commit --> <!-- copilot:summary --> ### <samp>🤖 Generated by Copilot at 2ba5e2a</samp> This pull request adds the lexical editor feature to the Ghost admin app, which allows users to create and edit snippets in a natural language format. It modifies the `snippet` model, adapter, and controller, and the `lexical-editor` template and component to support the new feature.
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import Component from '@glimmer/component';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default class UpdateSnippetModal extends Component {
|
|
@service notifications;
|
|
|
|
@task({drop: true})
|
|
*updateSnippetTask() {
|
|
const {snippet, updatedProperties: {mobiledoc, lexical}} = this.args.data;
|
|
|
|
try {
|
|
if (mobiledoc) {
|
|
snippet.mobiledoc = mobiledoc;
|
|
}
|
|
if (lexical) {
|
|
snippet.lexical = lexical;
|
|
}
|
|
|
|
yield snippet.save();
|
|
|
|
this.notifications.closeAlerts('snippet.save');
|
|
this.notifications.showNotification(
|
|
`Snippet "${snippet.name}" updated`,
|
|
{type: 'success'}
|
|
);
|
|
|
|
return snippet;
|
|
} catch (error) {
|
|
if (!snippet.errors.isEmpty) {
|
|
this.notifications.showAlert(
|
|
`Snippet save failed: ${snippet.errors.messages.join('. ')}`,
|
|
{type: 'error', key: 'snippet.save'}
|
|
);
|
|
}
|
|
snippet.rollbackAttributes();
|
|
throw error;
|
|
} finally {
|
|
this.args.close();
|
|
}
|
|
}
|
|
}
|