イベント

InputManJSのコメントコンポーネントでは、各種イベントがあります。以下のサンプルではアクションに応じて発生したイベントを確認できます。

InputManJSでは、コメントコンポーネントへのアクションに応じてさまざまなイベントが発生します。 コメントコンポーネントで発生するイベントは、以下の通りです。 イベント名 説明 AfterExecuteCommand GcCommentでコマンドが実行した後に発生します AfterFirstLoad GcCommentが初回コメントを読み込んだ後に発生します BeforeExecuteCommand GcCommentでコマンドが実行する前に発生します BeforeFirstLoad GcCommentが初回コメントを読み込む前に発生します CreateEditor commentEditorが作成される前に発生します EditorCreated commentEditorが作成された後に発生します PreprocessError dataSourceのconfig設定とGcCommentのデータフェッチにエラーが発生するときに発生します
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 { users, postedComments } from './data'; const gcComment = new InputMan.GcComment(document.getElementById('gcComment'), { addCommentEditorPosition: InputMan.GcCommentEditorPosition.Top, editorConfig: { editorType: InputMan.GcCommentEditorType.GcRichTextEditor, baseUrl: '$IMDEMOROOT$/lib/purejs/node_modules/@mescius/inputman.richtexteditor/JS', plugins: [RichTextEditorControl.InputMan.GcRichTextEditorPluginItem.All], height: 150, menubar: [], toolbar: [ RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.BlockQuote, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.SeparateLine, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.FontSize, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.FontFamily, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.SeparateLine, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Copy, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Cut, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.Paste, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.SeparateLine, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.HTMLCode, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.BulList, RichTextEditorControl.InputMan.GcRichTextEditorToolbarItem.NumList, ] }, commentMode: InputMan.GcCommentMode.ThreadMode, userInfo: { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar1.png', }, loadComments: (args) => { return { comments: postedComments }; }, loadUsersInfoHandler: (context) => { if (context.loadType === InputMan.LoadUserType.FilterText) { return users.filter((u) => u.name.includes(context.value)); } else if (context.loadType === InputMan.LoadUserType.ById) { return users.filter((u) => u.id === context.value); } }, }); // イベントハンドラ gcComment.addEventListener(InputMan.GcCommentEvent.AfterExecuteCommand, (args) => { log('AfterExecuteCommand: ' + args.command); }); gcComment.addEventListener(InputMan.GcCommentEvent.AfterFirstLoad, (args) => { log('AfterFirstLoad'); }); gcComment.addEventListener(InputMan.GcCommentEvent.BeforeExecuteCommand, (args) => { log('BeforeExecuteCommand: ' + args.command); }); gcComment.addEventListener(InputMan.GcCommentEvent.BeforeFirstLoad, (args) => { log('BeforeFirstLoad'); }); gcComment.addEventListener(InputMan.GcCommentEvent.CreateEditor, (args) => { log('CreateEditor: ' + args.createEditorReason); }); gcComment.addEventListener(InputMan.GcCommentEvent.EditorCreated, (args) => { log('EditorCreated: ' + args.createEditorReason); }); gcComment.addEventListener(InputMan.GcCommentEvent.PreprocessError, (args) => { log('PreprocessError: ' + args.error); }); // テキストボックスにログを出力 const log = (message) => { const textarea = document.getElementById('log'); textarea.value += message + '\n'; textarea.scrollTop = textarea.scrollHeight; }
<!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><br><br> イベント<br> <textarea id="log" rows="10" cols="60"></textarea> </body> </html>
body { box-sizing: content-box !important; height: 551px !important; } .gcim__gccomment[data-comment-mode="chatmode"] .gcim__gccomment-commentcontainer .comment[data-post-by-current-user="true"] { --backcolor: #e1f0fa; } .gcim__gccomment[data-comment-mode="chatmode"] .gcim__gccomment-commentcontainer .comment[data-post-by-current-user="false"] { --backcolor: #faf3e6; } .gcim__gccomment[data-comment-mode="chatmode"] .gcim__gccomment-commentcontainer .comment .commentControl::before { content: unset; }
export const postedComments = [ { id: '1', userInfo: { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar1.png', }, content: 'このサンプルではコメントコンポーネントへのアクションに応じてさまざまなイベントを確認できます。', postTime: new Date(), updateTime: new Date(), reactions: [ { reactionChar: '👍', count: 2, } ] }, { id: '2', userInfo: { id: '2', name: '葛城 孝史', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar2.png' }, content: 'コマンドが実行する前や実行した後に発生したイベントが出力されます。', postTime: new Date(), updateTime: new Date(), }, ]; export const users = [ { id: '1', name: '森上 偉久馬', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar1.png', }, { id: '2', name: '葛城 孝史', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar2.png', }, { id: '3', name: '加藤 泰江', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar3.png', }, { id: '4', name: '川村 匡', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar4.png', }, { id: '5', name: '松沢 誠一', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar5.png', }, { id: '6', name: '成宮 真紀', avatar: '$IMDEMOROOT$/ja/samples/comment/event/img/avatar6.png', }, ];
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' }, } });