loadOnDemandプロパティをtrueに設定すると、動的読み込み機能を有効に設定できます。また、pageSizeプロパティで一度読み込むコメントの数を設定できます。
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'), {
loadOnDemand: true,
pageSize: 2,
editorConfig: {
editorType: InputMan.GcCommentEditorType.GcRichTextEditor,
height: 150,
menubar: [],
},
userInfo: {
id: '1',
name: '森上 偉久馬',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar1.png',
},
loadComments: (args) => {
const { pageNumber, pageSize } = args;
const startIndex = pageNumber * pageSize;
const endIndex = startIndex + pageSize;
const topLevelComments = postedComments.filter(comment => !comment.parentCommentId)
let paginatedComments = topLevelComments.slice(startIndex, endIndex);
paginatedComments = paginatedComments.concat(postedComments.filter(comment => paginatedComments.find(c => comment.parentCommentId === c.id)))
return {
comments: paginatedComments,
hasMore: endIndex < topLevelComments.length,
};
},
});
<!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/ondemand/img/avatar1.png',
},
content: `<b>このサンプルでは動的読み込み機能を有効にしています。</b>
<p>一度に読み込むコメントの数を「2」に設定しているので、最後のコメントまでスクロールさせると、2個ずつコメントが動的に追加されます。</p>`,
postTime: new Date(2024, 1, 1, 8, 0, 0),
updateTime: new Date(2024, 1, 1, 8, 0, 0),
},
{
id: '2',
userInfo: {
id: '4',
name: '川村 匡',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar4.png',
},
content: '川村です。こちらは動的読み込みのコメントです。',
postTime: new Date(2024, 4, 20, 8, 1, 1),
updateTime: new Date(2024, 4, 20, 8, 1, 1),
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
},
{
id: '3',
userInfo: {
id: '1',
name: '森上 偉久馬',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar1.png',
},
content: '森上です。こちらは動的読み込みのコメントです。',
postTime: new Date(2024, 6, 15, 8, 1, 26),
updateTime: new Date(2024, 6, 15, 8, 1, 26),
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
},
{
id: '4',
userInfo: {
id: '6',
name: '成宮 真紀',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar6.png',
},
content: '成宮です。こちらは動的読み込みのコメントです。',
postTime: new Date(2024, 6, 15, 8, 1, 26),
updateTime: new Date(2024, 6, 15, 8, 1, 26),
reactions: [
{
reactionChar: '👍',
count: 1,
},
],
},
{
id: '5',
userInfo: {
id: '2',
name: '葛城 孝史',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar2.png',
},
content: '葛城です。こちらは動的読み込みのコメントです。',
postTime: new Date(2024, 6, 15, 8, 1, 26),
updateTime: new Date(2024, 6, 15, 8, 1, 26),
parentCommentId: '2',
reactions: [
{
reactionChar: '🔥',
count: 1,
},
],
},
{
id: '6',
userInfo: {
id: '2',
name: '葛城 孝史',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar2.png',
},
content: '葛城です。こちらは動的読み込みのコメントです。',
postTime: new Date(2024, 6, 15, 8, 1, 26),
updateTime: new Date(2024, 6, 15, 8, 1, 26),
reactions: [
{
reactionChar: '🔥',
count: 1,
},
],
},
{
id: '7',
userInfo: {
id: '2',
name: '葛城 孝史',
avatar: '$IMDEMOROOT$/ja/samples/comment/ondemand/img/avatar2.png',
},
content: '葛城です。こちらは動的読み込みのコメントです。',
postTime: new Date(2024, 6, 15, 8, 1, 26),
updateTime: new Date(2024, 6, 15, 8, 1, 26),
reactions: [
{
reactionChar: '🔥',
count: 1,
},
],
},
];
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'
},
}
});