deepseek-1.x-dev/js/ckeditor5_plugins/insert_prompts/src/insert_prompts-edit.js

js/ckeditor5_plugins/insert_prompts/src/insert_prompts-edit.js
import { Plugin } from 'ckeditor5/src/core';
import { Widget } from 'ckeditor5/src/widget';
import InsertPromptCommand from "./InsertPromptCommand";

// cSpell:ignore DateICalEditing InsertICalCommand
export default class InsertPromptEdit extends Plugin {
  static get requires() {
    return [Widget];
  }

  init() {
    this._defineSchema();
    this._defineConverters();
    this._defineCommands();
  }

  _defineSchema() {
    // Schemas are registered via the central `editor` object.
    const schema = this.editor.model.schema;

    schema.register('insertPrompt', {
      // Behaves like a self-contained object (e.g. an image).
      isObject: true,
      // Allow in places where other prompts are allowed (e.g. directly in the root).
      allowWhere: '$text',
      isInline: true,
      allowAttributes: ['class'],
    });
  }

  /**
   * Converters determine how CKEditor 5 models are converted into markup and
   * vice-versa.
   */
  _defineConverters() {
    // Converters are registered via the central editor object.
    const { conversion } = this.editor;
    // Data Downcast Converters: converts stored model data into HTML.
    // These trigger when content is saved.
    //
    // Instances of <urlICalendar> are saved as
    // <div class="insert-prompts">{{prompt content}}</div>.
    conversion.for('downcast').elementToElement({
      model: 'insertPrompt',
      view: {
        name: 'div',
        classes: 'insert-prompt',
      },
    });

    // Upcast Converters: determine how existing HTML is interpreted by the
    // editor. These trigger when an editor instance loads.
    //
    // If <div class="insert-prompt"> is present in the existing markup
    // processed by CKEditor, then CKEditor recognizes and loads it as a
    // <insertPrompts> model.
    conversion.for('upcast').elementToElement({
      model: 'insertPrompt',
      view: {
        name: 'div',
        classes: 'insert-prompts',
      },
    });
  }

  _defineCommands() {
    const editor = this.editor;
    editor.commands.add(
      'InsertPromptCommand',
      new InsertPromptCommand(this.editor),
    );
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc