File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright © 2024 Cloudnode OÜ
3+ *
4+ * This file is part of @cldn/components.
5+ *
6+ * \@cldn/components is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
7+ * General Public License as published by the Free Software Foundation, either version 3 of the License,
8+ * or (at your option) any later version.
9+ *
10+ * \@cldn/components is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
11+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
12+ * for more details.
13+ *
14+ * You should have received a copy of the GNU Lesser General Public License along with @cldn/components.
15+ * If not, see <https://www.gnu.org/licenses/>.
16+ */
17+ import { NodeComponent } from "./NodeComponent.js" ;
18+
19+ /**
20+ * A text node component
21+ */
22+ export class TextComponent extends NodeComponent < Text > {
23+ /**
24+ * Create component
25+ * @param text Text node instance or text content string
26+ */
27+ public constructor ( text : Text | string ) {
28+ super ( typeof text === "string" ? document . createTextNode ( text ) : text ) ;
29+ }
30+
31+ /**
32+ * @deprecated Cannot add children to a TextComponent
33+ *
34+ * @throws {@link !DOMException } Always
35+ */
36+ public override append ( ...components : NodeComponent < any > [ ] ) : typeof this {
37+ throw new DOMException ( `TextComponent.append: Cannot add children to a ${ this . constructor . name } ` ) ;
38+ }
39+
40+ /**
41+ * Get the text content
42+ */
43+ public override toString ( ) {
44+ return this . node . textContent ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments