@schukai/monster 4.97.0 → 4.98.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,242 @@
1
+ /**
2
+ * Copyright © Volker Schukai and all contributing authors, {{copyRightYear}}. All rights reserved.
3
+ * Node module: @schukai/monster
4
+ *
5
+ * This source code is licensed under the GNU Affero General Public License version 3 (AGPLv3).
6
+ * The full text of the license can be found at: https://www.gnu.org/licenses/agpl-3.0.en.html
7
+ *
8
+ * For those who do not wish to adhere to the AGPLv3, a commercial license is available.
9
+ * Acquiring a commercial license allows you to use this software without complying with the AGPLv3 terms.
10
+ * For more information about purchasing a commercial license, please contact Volker Schukai.
11
+ *
12
+ * SPDX-License-Identifier: AGPL-3.0
13
+ */
14
+
15
+ import { Base } from "../../../types/base.mjs";
16
+ import { equipWithInternal } from "../../../types/internal.mjs";
17
+ import { instanceSymbol } from "../../../constants.mjs";
18
+ import { Observer } from "../../../types/observer.mjs";
19
+ import { isArray, isInstance } from "../../../types/is.mjs";
20
+
21
+ export { Entry };
22
+
23
+ /**
24
+ * The Entry class represents a single entry in a discussion thread.
25
+ *
26
+ * @copyright Volker Schukai
27
+ * @summary A single entry in a discussion thread.
28
+ */
29
+ class Entry extends Base {
30
+ constructor({
31
+ id,
32
+ title,
33
+ message,
34
+ user,
35
+ date,
36
+ children,
37
+ hiddenChildren,
38
+ actions,
39
+ collapsed,
40
+ replyCount,
41
+ } = {}) {
42
+ super();
43
+
44
+ /**
45
+ * - attachInternalObserver
46
+ * - detachInternalObserver
47
+ * - containsInternalObserver
48
+ * - setInternal
49
+ * - setInternals
50
+ * - getInternal
51
+ */
52
+ equipWithInternal.call(this);
53
+
54
+ if (id) this.id = id;
55
+ if (title) this.title = title;
56
+ if (message) this.message = message;
57
+ if (user) this.user = user;
58
+ if (date) this.date = date;
59
+ if (children) this.children = children;
60
+ if (hiddenChildren) this.hiddenChildren = hiddenChildren;
61
+ if (actions) this.actions = actions;
62
+ if (collapsed !== undefined) this.collapsed = collapsed;
63
+ if (replyCount !== undefined) this.replyCount = replyCount;
64
+
65
+ this.attachInternalObserver(
66
+ new Observer(() => {
67
+ // updateStruct.call(self);
68
+ }),
69
+ );
70
+ }
71
+
72
+ /**
73
+ * This method is called by the `instanceof` operator.
74
+ * @return {symbol}
75
+ */
76
+ static get [instanceSymbol]() {
77
+ return Symbol.for("@schukai/component-state/thread/entry");
78
+ }
79
+
80
+ /**
81
+ *
82
+ * @return {object}
83
+ */
84
+ get internalDefaults() {
85
+ return {
86
+ id: null,
87
+ title: null,
88
+ message: null,
89
+ user: null,
90
+ date: null,
91
+ children: [],
92
+ hiddenChildren: [],
93
+ actions: null,
94
+ collapsed: null,
95
+ replyCount: 0,
96
+ };
97
+ }
98
+
99
+ /**
100
+ * @return {string}
101
+ */
102
+ get id() {
103
+ return this.getInternal("id");
104
+ }
105
+
106
+ /**
107
+ * @param {string} value
108
+ */
109
+ set id(value) {
110
+ this.setInternal("id", value);
111
+ }
112
+
113
+ /**
114
+ * @return {string}
115
+ */
116
+ get title() {
117
+ return this.getInternal("title");
118
+ }
119
+
120
+ /**
121
+ * @param {string} value
122
+ */
123
+ set title(value) {
124
+ this.setInternal("title", value);
125
+ }
126
+
127
+ /**
128
+ * @return {string}
129
+ */
130
+ get message() {
131
+ return this.getInternal("message");
132
+ }
133
+
134
+ /**
135
+ * @param {string} value
136
+ */
137
+ set message(value) {
138
+ this.setInternal("message", value);
139
+ }
140
+
141
+ /**
142
+ * @return {string}
143
+ */
144
+ get user() {
145
+ return this.getInternal("user");
146
+ }
147
+
148
+ /**
149
+ * @param {string} value
150
+ */
151
+ set user(value) {
152
+ this.setInternal("user", value);
153
+ }
154
+
155
+ /**
156
+ * @return {Date}
157
+ */
158
+ get date() {
159
+ return this.getInternal("date");
160
+ }
161
+
162
+ /**
163
+ * @param {string|Date} value
164
+ */
165
+ set date(value) {
166
+ if (!isInstance(value, Date)) {
167
+ value = new Date(value);
168
+ }
169
+ this.setInternal("date", value);
170
+ }
171
+
172
+ /**
173
+ * @return {Array}
174
+ */
175
+ get children() {
176
+ return this.getInternal("children");
177
+ }
178
+
179
+ /**
180
+ * @param {Array} value
181
+ */
182
+ set children(value) {
183
+ this.setInternal("children", isArray(value) ? value : []);
184
+ }
185
+
186
+ /**
187
+ * @return {Array}
188
+ */
189
+ get hiddenChildren() {
190
+ return this.getInternal("hiddenChildren");
191
+ }
192
+
193
+ /**
194
+ * @param {Array} value
195
+ */
196
+ set hiddenChildren(value) {
197
+ this.setInternal("hiddenChildren", isArray(value) ? value : []);
198
+ }
199
+
200
+ /**
201
+ * @return {string}
202
+ */
203
+ get actions() {
204
+ return this.getInternal("actions");
205
+ }
206
+
207
+ /**
208
+ * @param {string} value
209
+ */
210
+ set actions(value) {
211
+ this.setInternal("actions", value);
212
+ }
213
+
214
+ /**
215
+ * @return {boolean}
216
+ */
217
+ get collapsed() {
218
+ return this.getInternal("collapsed");
219
+ }
220
+
221
+ /**
222
+ * @param {boolean} value
223
+ */
224
+ set collapsed(value) {
225
+ this.setInternal("collapsed", Boolean(value));
226
+ }
227
+
228
+ /**
229
+ * @return {number}
230
+ */
231
+ get replyCount() {
232
+ return this.getInternal("replyCount");
233
+ }
234
+
235
+ /**
236
+ * @param {number} value
237
+ */
238
+ set replyCount(value) {
239
+ const next = Number.isFinite(value) ? value : Number(value) || 0;
240
+ this.setInternal("replyCount", next);
241
+ }
242
+ }