リッチテキストエディタの利用

このサンプルではコメントエディタにリッチテキストエディタを使用しています。コメントエディタにフォーカスするとリッチテキストエディタが表示されます。

コメントコンポーネントのコメントエディタ機能について解説します。 コメントエディタの設定 editorConfigインターフェースを利用して、コメントエディタを設定することができます。コマンドからコメントエディタを設定する場合は、CreateEditorコマンドを使用します。 editorTypeプロパティGcCommentEditorType.GcMultilineTextBoxに設定すると、コメントエディタにリッチテキストエディタが適用されます。リッチテキストエディタを利用するには、以下のモジュールをインポートする必要があります。 モジュールファイル:@mescius/inputman.richtexteditor CSSファイル:@mescius/inputman.richtexteditor/CSS/gc.inputman.richtexteditor.css また、editorConfigインターフェースにリッチテキストエディタのツールバーやメニューバーの表示項目、各プラグインの利用などを設定することができます。以下は設定例です。
import "./styles.css"; import "@mescius/inputman.comment/CSS/gc.inputman.comment.css"; import "@mescius/inputman.richtexteditor/CSS/gc.inputman.richtexteditor.css"; import { InputMan } from "@mescius/inputman.comment"; import * as RichTextEditorControl from "@mescius/inputman.richtexteditor"; import { postedComments } from './data'; const gcComment = new InputMan.GcComment(document.getElementById('gcComment'), { editorConfig: { editorType: InputMan.GcCommentEditorType.GcRichTextEditor, height: 150, menubar: [ RichTextEditorControl.InputMan.GcRichTextEditorMenuBarItem.Edit, ], }, commentMode: InputMan.GcCommentMode.ThreadMode, userInfo: { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar1.png', }, loadComments: (args) => { return { comments: postedComments }; }, });
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <meta name="description" content="コメントコンポーネント 使い方" lang="ja" xml:lang="ja" /> <title>コメントコンポーネント - コメントエディタ - リッチテキストエディタの利用</title> <!-- SystemJS --> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> window.onload = function() { System.import('./src/app'); } </script> </head> <body> <div id="gcComment"></div> </body> </html>
body { box-sizing: content-box !important; height: 551px !important; }
export const postedComments = [ { id: '1', userInfo: { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar1.png', }, content: `<b>このサンプルではコメントエディタにリッチテキストエディタを設定しています。</b> <p>コメントエディタにフォーカスするとリッチテキストエディタが使用されるフォームが表示されます。</p>`, postTime: new Date(2024, 1, 1, 8, 0, 0), updateTime: new Date(2024, 1, 1, 8, 0, 0), reactions: [ { reactionChar: '👍', count: 2, }, ], }, { id: '2', userInfo: { id: '2', name: '葛城 孝史', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar2.png', }, content: 'いいですね。ぜひリッチテキストエディタの様々な機能を試してみたいです!', postTime: new Date(2024, 4, 20, 8, 1, 1), updateTime: new Date(2024, 4, 20, 8, 1, 1), reactions: [ { reactionChar: '👍', count: 3, currentUserReacted: true, }, ], }, { id: '3', userInfo: { id: '6', name: '成宮 真紀', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar6.png', }, content: 'ツールバーやメニューバーのカスタマイズもできますので、必要に応じて表示項目を変更できますよ。', postTime: new Date(2024, 7, 16, 8, 1, 59), updateTime: new Date(2024, 7, 16, 8, 1, 59), parentCommentId: '2', }, { id: '4', userInfo: { id: '5', name: '松沢 誠一', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar5.png', }, content: 'すみません。僕の画面に表示されないですが、どうすればいいでしょうか?', postTime: new Date(2024, 6, 15, 8, 1, 59), updateTime: new Date(2024, 6, 15, 8, 1, 59), parentCommentId: '2', reactions: [ { reactionChar: '🤔', count: 2, }, { reactionChar: '😯', count: 1 }, ], }, { id: '5', userInfo: { id: '2', name: '葛城 孝史', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar2.png', }, content: 'コメントエディタにリッチテキストエディタを設定するには、リッチテキストエディタのモジュールをインポートする必要がありますよ。', postTime: new Date(2024, 6, 15, 8, 1, 59), updateTime: new Date(2024, 6, 15, 8, 1, 59), parentCommentId: '4', reactions: [ { reactionChar: '�', count: 1 } ], }, { id: '6', userInfo: { id: '5', name: '松沢 誠一', avatar: '$IMDEMOROOT$/ja/samples/comment/commentEditor/richTextEditor/img/avatar5.png', }, content: 'ありがとうございます!', postTime: new Date(2024, 6, 15, 8, 1, 59), updateTime: new Date(2024, 6, 15, 8, 1, 59), parentCommentId: '5' }, ];
System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/inputman': 'npm:@mescius/inputman/index.js', '@mescius/inputman/CSS': 'npm:@mescius/inputman/CSS', '@mescius/inputman.richtexteditor': 'npm:@mescius/inputman.richtexteditor/index.js', '@mescius/inputman.richtexteditor/CSS': 'npm:@mescius/inputman.richtexteditor/CSS', '@mescius/inputman.comment': 'npm:@mescius/inputman.comment/index.js', '@mescius/inputman.comment/CSS': 'npm:@mescius/inputman.comment/CSS', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build': 'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, } });