@gtkx/react 0.15.0 → 0.16.0

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.
Files changed (186) hide show
  1. package/README.md +1 -0
  2. package/dist/errors.js +3 -0
  3. package/dist/factory.d.ts +3 -2
  4. package/dist/factory.js +1 -1
  5. package/dist/generated/internal.d.ts +28 -1
  6. package/dist/generated/internal.js +93 -18
  7. package/dist/generated/jsx.d.ts +1489 -1300
  8. package/dist/generated/jsx.js +475 -0
  9. package/dist/host-config.d.ts +3 -1
  10. package/dist/host-config.js +31 -11
  11. package/dist/jsx.d.ts +107 -166
  12. package/dist/jsx.js +58 -69
  13. package/dist/node.d.ts +3 -1
  14. package/dist/node.js +5 -3
  15. package/dist/nodes/abstract/positional-child.d.ts +9 -0
  16. package/dist/nodes/abstract/positional-child.js +29 -0
  17. package/dist/nodes/abstract/positional-parent.d.ts +18 -0
  18. package/dist/nodes/abstract/positional-parent.js +48 -0
  19. package/dist/nodes/abstract/virtual-container.d.ts +17 -0
  20. package/dist/nodes/abstract/virtual-container.js +59 -0
  21. package/dist/nodes/abstract/virtual-single-child.d.ts +18 -0
  22. package/dist/nodes/abstract/virtual-single-child.js +54 -0
  23. package/dist/nodes/action-row-child.d.ts +0 -13
  24. package/dist/nodes/action-row-child.js +14 -12
  25. package/dist/nodes/action-row.d.ts +6 -1
  26. package/dist/nodes/action-row.js +4 -37
  27. package/dist/nodes/adjustable.d.ts +23 -0
  28. package/dist/nodes/adjustable.js +62 -0
  29. package/dist/nodes/alert-dialog-response.d.ts +1 -0
  30. package/dist/nodes/alert-dialog-response.js +86 -0
  31. package/dist/nodes/animation/animation-controller.d.ts +17 -0
  32. package/dist/nodes/animation/animation-controller.js +107 -0
  33. package/dist/nodes/animation/animation-factory.d.ts +15 -0
  34. package/dist/nodes/animation/animation-factory.js +25 -0
  35. package/dist/nodes/animation/animation-node.d.ts +9 -0
  36. package/dist/nodes/animation/animation-node.js +126 -0
  37. package/dist/nodes/animation/animation-style-sheet.d.ts +16 -0
  38. package/dist/nodes/animation/animation-style-sheet.js +74 -0
  39. package/dist/nodes/animation/index.d.ts +4 -0
  40. package/dist/nodes/animation/index.js +1 -0
  41. package/dist/nodes/animation/property-mapper.d.ts +11 -0
  42. package/dist/nodes/animation/property-mapper.js +36 -0
  43. package/dist/nodes/animation/transform-state.d.ts +11 -0
  44. package/dist/nodes/animation/transform-state.js +57 -0
  45. package/dist/nodes/animation/widget-registry.d.ts +5 -0
  46. package/dist/nodes/animation/widget-registry.js +42 -0
  47. package/dist/nodes/application.js +17 -7
  48. package/dist/nodes/autowrapped.js +37 -43
  49. package/dist/nodes/calendar.js +17 -43
  50. package/dist/nodes/color-dialog-button.d.ts +1 -0
  51. package/dist/nodes/color-dialog-button.js +70 -0
  52. package/dist/nodes/column-view-column.d.ts +3 -3
  53. package/dist/nodes/column-view-column.js +1 -1
  54. package/dist/nodes/column-view.js +36 -39
  55. package/dist/nodes/dialog.d.ts +11 -0
  56. package/dist/nodes/dialog.js +20 -0
  57. package/dist/nodes/drawing-area.js +24 -7
  58. package/dist/nodes/event-controller.d.ts +1 -0
  59. package/dist/nodes/event-controller.js +96 -0
  60. package/dist/nodes/expander-row-child.d.ts +0 -14
  61. package/dist/nodes/expander-row-child.js +14 -12
  62. package/dist/nodes/expander-row.d.ts +6 -1
  63. package/dist/nodes/expander-row.js +11 -48
  64. package/dist/nodes/fixed-child.js +48 -36
  65. package/dist/nodes/font-dialog-button.d.ts +1 -0
  66. package/dist/nodes/font-dialog-button.js +90 -0
  67. package/dist/nodes/grid-child.js +39 -45
  68. package/dist/nodes/grid.d.ts +1 -0
  69. package/dist/nodes/grid.js +41 -0
  70. package/dist/nodes/index.d.ts +17 -9
  71. package/dist/nodes/index.js +17 -9
  72. package/dist/nodes/internal/base-item-renderer.d.ts +29 -0
  73. package/dist/nodes/internal/base-item-renderer.js +88 -0
  74. package/dist/nodes/internal/base-store.d.ts +9 -0
  75. package/dist/nodes/internal/base-store.js +20 -0
  76. package/dist/nodes/internal/child-attachment.d.ts +26 -0
  77. package/dist/nodes/internal/child-attachment.js +48 -0
  78. package/dist/nodes/internal/deferred-action.d.ts +8 -0
  79. package/dist/nodes/internal/deferred-action.js +19 -0
  80. package/dist/nodes/internal/list-item-renderer.d.ts +14 -15
  81. package/dist/nodes/internal/list-item-renderer.js +51 -77
  82. package/dist/nodes/internal/list-store.d.ts +7 -6
  83. package/dist/nodes/internal/list-store.js +20 -24
  84. package/dist/nodes/internal/predicates.d.ts +25 -2
  85. package/dist/nodes/internal/predicates.js +53 -41
  86. package/dist/nodes/internal/selection-model.d.ts +30 -0
  87. package/dist/nodes/internal/selection-model.js +91 -0
  88. package/dist/nodes/internal/signal-store.d.ts +5 -4
  89. package/dist/nodes/internal/signal-store.js +30 -28
  90. package/dist/nodes/internal/simple-list-store.js +6 -9
  91. package/dist/nodes/internal/text-buffer-controller.d.ts +43 -0
  92. package/dist/nodes/internal/text-buffer-controller.js +287 -0
  93. package/dist/nodes/internal/text-tag-styles.d.ts +43 -0
  94. package/dist/nodes/internal/text-tag-styles.js +52 -0
  95. package/dist/nodes/internal/tree-list-item-renderer.d.ts +15 -14
  96. package/dist/nodes/internal/tree-list-item-renderer.js +85 -96
  97. package/dist/nodes/internal/tree-store.d.ts +10 -9
  98. package/dist/nodes/internal/tree-store.js +31 -35
  99. package/dist/nodes/internal/utils.d.ts +7 -4
  100. package/dist/nodes/internal/utils.js +50 -5
  101. package/dist/nodes/level-bar.js +19 -54
  102. package/dist/nodes/list-item.d.ts +6 -3
  103. package/dist/nodes/list-item.js +7 -4
  104. package/dist/nodes/list-view.js +15 -11
  105. package/dist/nodes/menu.d.ts +3 -3
  106. package/dist/nodes/menu.js +3 -3
  107. package/dist/nodes/models/list.d.ts +11 -13
  108. package/dist/nodes/models/list.js +16 -73
  109. package/dist/nodes/models/menu.d.ts +8 -7
  110. package/dist/nodes/models/menu.js +43 -50
  111. package/dist/nodes/models/tree-list.d.ts +6 -12
  112. package/dist/nodes/models/tree-list.js +30 -93
  113. package/dist/nodes/navigation-page.d.ts +1 -0
  114. package/dist/nodes/navigation-page.js +27 -32
  115. package/dist/nodes/navigation-view.js +17 -28
  116. package/dist/nodes/notebook-page-tab.d.ts +3 -3
  117. package/dist/nodes/notebook-page-tab.js +11 -14
  118. package/dist/nodes/notebook-page.d.ts +7 -5
  119. package/dist/nodes/notebook-page.js +45 -25
  120. package/dist/nodes/notebook.js +2 -2
  121. package/dist/nodes/overlay-child.js +90 -30
  122. package/dist/nodes/pack-child.d.ts +0 -13
  123. package/dist/nodes/pack-child.js +14 -12
  124. package/dist/nodes/pack.d.ts +6 -1
  125. package/dist/nodes/pack.js +4 -37
  126. package/dist/nodes/popover-menu.js +2 -2
  127. package/dist/nodes/scale.js +15 -45
  128. package/dist/nodes/scrolled-window.js +7 -6
  129. package/dist/nodes/search-bar.d.ts +1 -0
  130. package/dist/nodes/search-bar.js +40 -0
  131. package/dist/nodes/shortcut-controller.d.ts +1 -37
  132. package/dist/nodes/shortcut-controller.js +24 -8
  133. package/dist/nodes/shortcut.d.ts +5 -4
  134. package/dist/nodes/shortcut.js +11 -5
  135. package/dist/nodes/simple-list-view.js +2 -3
  136. package/dist/nodes/slot.d.ts +6 -9
  137. package/dist/nodes/slot.js +27 -42
  138. package/dist/nodes/source-view.js +80 -29
  139. package/dist/nodes/stack-page.js +20 -22
  140. package/dist/nodes/stack.js +19 -5
  141. package/dist/nodes/text-anchor.d.ts +41 -0
  142. package/dist/nodes/text-anchor.js +59 -0
  143. package/dist/nodes/text-content.d.ts +10 -0
  144. package/dist/nodes/text-content.js +1 -0
  145. package/dist/nodes/text-paintable.d.ts +17 -0
  146. package/dist/nodes/text-paintable.js +34 -0
  147. package/dist/nodes/text-segment.d.ts +15 -0
  148. package/dist/nodes/text-segment.js +29 -0
  149. package/dist/nodes/text-tag.d.ts +136 -0
  150. package/dist/nodes/text-tag.js +202 -0
  151. package/dist/nodes/text-view.d.ts +30 -0
  152. package/dist/nodes/text-view.js +49 -21
  153. package/dist/nodes/toggle-group.js +24 -32
  154. package/dist/nodes/toggle.d.ts +1 -15
  155. package/dist/nodes/toggle.js +40 -32
  156. package/dist/nodes/toolbar-child.js +14 -16
  157. package/dist/nodes/tree-list-item.d.ts +7 -5
  158. package/dist/nodes/tree-list-item.js +24 -36
  159. package/dist/nodes/tree-list-view.js +7 -6
  160. package/dist/nodes/virtual.d.ts +1 -1
  161. package/dist/nodes/widget.d.ts +2 -16
  162. package/dist/nodes/widget.js +105 -294
  163. package/dist/nodes/window.d.ts +9 -3
  164. package/dist/nodes/window.js +29 -15
  165. package/dist/registry.d.ts +1 -1
  166. package/dist/render.js +8 -6
  167. package/dist/scheduler.d.ts +11 -1
  168. package/dist/scheduler.js +16 -4
  169. package/dist/types.d.ts +2 -136
  170. package/package.json +3 -3
  171. package/dist/nodes/adjustment.d.ts +0 -48
  172. package/dist/nodes/adjustment.js +0 -70
  173. package/dist/nodes/calendar-mark.d.ts +0 -15
  174. package/dist/nodes/calendar-mark.js +0 -29
  175. package/dist/nodes/internal/constants.d.ts +0 -1
  176. package/dist/nodes/internal/constants.js +0 -24
  177. package/dist/nodes/level-bar-offset.d.ts +0 -13
  178. package/dist/nodes/level-bar-offset.js +0 -35
  179. package/dist/nodes/scale-mark.d.ts +0 -17
  180. package/dist/nodes/scale-mark.js +0 -38
  181. package/dist/nodes/source-buffer.d.ts +0 -73
  182. package/dist/nodes/source-buffer.js +0 -149
  183. package/dist/nodes/text-buffer.d.ts +0 -43
  184. package/dist/nodes/text-buffer.js +0 -81
  185. package/dist/nodes/virtual-child.d.ts +0 -18
  186. package/dist/nodes/virtual-child.js +0 -62
@@ -1,149 +0,0 @@
1
- import { batch } from "@gtkx/ffi";
2
- import * as Gtk from "@gtkx/ffi/gtk";
3
- import * as GtkSource from "@gtkx/ffi/gtksource";
4
- import { registerNodeClass } from "../registry.js";
5
- import { signalStore } from "./internal/signal-store.js";
6
- import { VirtualNode } from "./virtual.js";
7
- export class SourceBufferNode extends VirtualNode {
8
- static priority = 1;
9
- sourceView;
10
- buffer;
11
- static matches(type) {
12
- return type === "SourceBuffer";
13
- }
14
- setSourceView(sourceView) {
15
- this.sourceView = sourceView;
16
- this.setupBuffer();
17
- }
18
- resolveLanguage(language) {
19
- if (typeof language === "string") {
20
- const langManager = GtkSource.LanguageManager.getDefault();
21
- return langManager.getLanguage(language);
22
- }
23
- return language;
24
- }
25
- resolveStyleScheme(scheme) {
26
- if (typeof scheme === "string") {
27
- const schemeManager = GtkSource.StyleSchemeManager.getDefault();
28
- return schemeManager.getScheme(scheme);
29
- }
30
- return scheme;
31
- }
32
- setupBuffer() {
33
- if (!this.sourceView)
34
- return;
35
- this.buffer = new GtkSource.Buffer();
36
- this.sourceView.setBuffer(this.buffer);
37
- if (this.props.enableUndo !== undefined) {
38
- this.buffer.setEnableUndo(this.props.enableUndo);
39
- }
40
- if (this.props.text !== undefined) {
41
- this.buffer.setText(this.props.text, -1);
42
- }
43
- this.applySourceProps();
44
- this.updateSignalHandlers();
45
- }
46
- applySourceProps() {
47
- if (!this.buffer)
48
- return;
49
- if (this.props.language !== undefined) {
50
- const language = this.resolveLanguage(this.props.language);
51
- this.buffer.setLanguage(language);
52
- }
53
- if (this.props.styleScheme !== undefined) {
54
- const scheme = this.resolveStyleScheme(this.props.styleScheme);
55
- this.buffer.setStyleScheme(scheme);
56
- }
57
- const highlightSyntax = this.props.highlightSyntax ?? this.props.language !== undefined;
58
- this.buffer.setHighlightSyntax(highlightSyntax);
59
- const highlightMatchingBrackets = this.props.highlightMatchingBrackets ?? true;
60
- this.buffer.setHighlightMatchingBrackets(highlightMatchingBrackets);
61
- if (this.props.implicitTrailingNewline !== undefined) {
62
- this.buffer.setImplicitTrailingNewline(this.props.implicitTrailingNewline);
63
- }
64
- }
65
- getBufferText() {
66
- const buffer = this.buffer;
67
- if (!buffer)
68
- return "";
69
- const startIter = new Gtk.TextIter();
70
- const endIter = new Gtk.TextIter();
71
- batch(() => {
72
- buffer.getStartIter(startIter);
73
- buffer.getEndIter(endIter);
74
- });
75
- return buffer.getText(startIter, endIter, true);
76
- }
77
- updateSignalHandlers() {
78
- if (!this.buffer)
79
- return;
80
- const buffer = this.buffer;
81
- const { onTextChanged, onCanUndoChanged, onCanRedoChanged, onCursorMoved, onHighlightUpdated } = this.props;
82
- signalStore.set(this, buffer, "changed", onTextChanged ? () => onTextChanged(this.getBufferText()) : null);
83
- signalStore.set(this, buffer, "notify::can-undo", onCanUndoChanged ? () => onCanUndoChanged(buffer.getCanUndo()) : null);
84
- signalStore.set(this, buffer, "notify::can-redo", onCanRedoChanged ? () => onCanRedoChanged(buffer.getCanRedo()) : null);
85
- signalStore.set(this, buffer, "cursor-moved", onCursorMoved ?? null);
86
- signalStore.set(this, buffer, "highlight-updated", onHighlightUpdated
87
- ? (_buffer, start, end) => onHighlightUpdated(start, end)
88
- : null);
89
- }
90
- updateProps(oldProps, newProps) {
91
- super.updateProps(oldProps, newProps);
92
- if (!this.buffer)
93
- return;
94
- if (!oldProps || oldProps.enableUndo !== newProps.enableUndo) {
95
- if (newProps.enableUndo !== undefined) {
96
- this.buffer.setEnableUndo(newProps.enableUndo);
97
- }
98
- }
99
- if (!oldProps || oldProps.text !== newProps.text) {
100
- if (newProps.text !== undefined) {
101
- const currentText = this.getBufferText();
102
- if (currentText !== newProps.text) {
103
- this.buffer.setText(newProps.text, -1);
104
- }
105
- }
106
- }
107
- if (!oldProps || oldProps.language !== newProps.language) {
108
- if (newProps.language !== undefined) {
109
- const language = this.resolveLanguage(newProps.language);
110
- this.buffer.setLanguage(language);
111
- }
112
- }
113
- if (!oldProps || oldProps.styleScheme !== newProps.styleScheme) {
114
- if (newProps.styleScheme !== undefined) {
115
- const scheme = this.resolveStyleScheme(newProps.styleScheme);
116
- this.buffer.setStyleScheme(scheme);
117
- }
118
- }
119
- if (!oldProps ||
120
- oldProps.highlightSyntax !== newProps.highlightSyntax ||
121
- oldProps.language !== newProps.language) {
122
- const highlightSyntax = newProps.highlightSyntax ?? newProps.language !== undefined;
123
- this.buffer.setHighlightSyntax(highlightSyntax);
124
- }
125
- if (!oldProps || oldProps.highlightMatchingBrackets !== newProps.highlightMatchingBrackets) {
126
- const highlightMatchingBrackets = newProps.highlightMatchingBrackets ?? true;
127
- this.buffer.setHighlightMatchingBrackets(highlightMatchingBrackets);
128
- }
129
- if (!oldProps || oldProps.implicitTrailingNewline !== newProps.implicitTrailingNewline) {
130
- if (newProps.implicitTrailingNewline !== undefined) {
131
- this.buffer.setImplicitTrailingNewline(newProps.implicitTrailingNewline);
132
- }
133
- }
134
- if (!oldProps ||
135
- oldProps.onTextChanged !== newProps.onTextChanged ||
136
- oldProps.onCanUndoChanged !== newProps.onCanUndoChanged ||
137
- oldProps.onCanRedoChanged !== newProps.onCanRedoChanged ||
138
- oldProps.onCursorMoved !== newProps.onCursorMoved ||
139
- oldProps.onHighlightUpdated !== newProps.onHighlightUpdated) {
140
- this.updateSignalHandlers();
141
- }
142
- }
143
- unmount() {
144
- this.buffer = undefined;
145
- this.sourceView = undefined;
146
- super.unmount();
147
- }
148
- }
149
- registerNodeClass(SourceBufferNode);
@@ -1,43 +0,0 @@
1
- import * as Gtk from "@gtkx/ffi/gtk";
2
- import { VirtualNode } from "./virtual.js";
3
- /**
4
- * Props for the TextBuffer virtual element.
5
- *
6
- * Used to declaratively configure the text buffer for a GtkTextView.
7
- * For GtkSourceView with syntax highlighting, use {@link SourceBufferProps} instead.
8
- *
9
- * @example
10
- * ```tsx
11
- * <GtkTextView>
12
- * <x.TextBuffer
13
- * text="Hello, World!"
14
- * enableUndo
15
- * onTextChanged={(text) => console.log("Text:", text)}
16
- * />
17
- * </GtkTextView>
18
- * ```
19
- */
20
- export type TextBufferProps = {
21
- /** Text content */
22
- text?: string;
23
- /** Whether to enable undo/redo */
24
- enableUndo?: boolean;
25
- /** Callback when the text content changes */
26
- onTextChanged?: (text: string) => void;
27
- /** Callback when can-undo state changes */
28
- onCanUndoChanged?: (canUndo: boolean) => void;
29
- /** Callback when can-redo state changes */
30
- onCanRedoChanged?: (canRedo: boolean) => void;
31
- };
32
- export declare class TextBufferNode extends VirtualNode<TextBufferProps> {
33
- static priority: number;
34
- private textView?;
35
- private buffer?;
36
- static matches(type: string): boolean;
37
- setTextView(textView: Gtk.TextView): void;
38
- private setupBuffer;
39
- private getBufferText;
40
- private updateSignalHandlers;
41
- updateProps(oldProps: TextBufferProps | null, newProps: TextBufferProps): void;
42
- unmount(): void;
43
- }
@@ -1,81 +0,0 @@
1
- import { batch } from "@gtkx/ffi";
2
- import * as Gtk from "@gtkx/ffi/gtk";
3
- import { registerNodeClass } from "../registry.js";
4
- import { signalStore } from "./internal/signal-store.js";
5
- import { VirtualNode } from "./virtual.js";
6
- export class TextBufferNode extends VirtualNode {
7
- static priority = 1;
8
- textView;
9
- buffer;
10
- static matches(type) {
11
- return type === "TextBuffer";
12
- }
13
- setTextView(textView) {
14
- this.textView = textView;
15
- this.setupBuffer();
16
- }
17
- setupBuffer() {
18
- if (!this.textView)
19
- return;
20
- this.buffer = new Gtk.TextBuffer();
21
- this.textView.setBuffer(this.buffer);
22
- if (this.props.enableUndo !== undefined) {
23
- this.buffer.setEnableUndo(this.props.enableUndo);
24
- }
25
- if (this.props.text !== undefined) {
26
- this.buffer.setText(this.props.text, -1);
27
- }
28
- this.updateSignalHandlers();
29
- }
30
- getBufferText() {
31
- const buffer = this.buffer;
32
- if (!buffer)
33
- return "";
34
- const startIter = new Gtk.TextIter();
35
- const endIter = new Gtk.TextIter();
36
- batch(() => {
37
- buffer.getStartIter(startIter);
38
- buffer.getEndIter(endIter);
39
- });
40
- return buffer.getText(startIter, endIter, true);
41
- }
42
- updateSignalHandlers() {
43
- if (!this.buffer)
44
- return;
45
- const buffer = this.buffer;
46
- const { onTextChanged, onCanUndoChanged, onCanRedoChanged } = this.props;
47
- signalStore.set(this, buffer, "changed", onTextChanged ? () => onTextChanged(this.getBufferText()) : null);
48
- signalStore.set(this, buffer, "notify::can-undo", onCanUndoChanged ? () => onCanUndoChanged(buffer.getCanUndo()) : null);
49
- signalStore.set(this, buffer, "notify::can-redo", onCanRedoChanged ? () => onCanRedoChanged(buffer.getCanRedo()) : null);
50
- }
51
- updateProps(oldProps, newProps) {
52
- super.updateProps(oldProps, newProps);
53
- if (!this.buffer)
54
- return;
55
- if (!oldProps || oldProps.enableUndo !== newProps.enableUndo) {
56
- if (newProps.enableUndo !== undefined) {
57
- this.buffer.setEnableUndo(newProps.enableUndo);
58
- }
59
- }
60
- if (!oldProps || oldProps.text !== newProps.text) {
61
- if (newProps.text !== undefined) {
62
- const currentText = this.getBufferText();
63
- if (currentText !== newProps.text) {
64
- this.buffer.setText(newProps.text, -1);
65
- }
66
- }
67
- }
68
- if (!oldProps ||
69
- oldProps.onTextChanged !== newProps.onTextChanged ||
70
- oldProps.onCanUndoChanged !== newProps.onCanUndoChanged ||
71
- oldProps.onCanRedoChanged !== newProps.onCanRedoChanged) {
72
- this.updateSignalHandlers();
73
- }
74
- }
75
- unmount() {
76
- this.buffer = undefined;
77
- this.textView = undefined;
78
- super.unmount();
79
- }
80
- }
81
- registerNodeClass(TextBufferNode);
@@ -1,18 +0,0 @@
1
- import type * as Gtk from "@gtkx/ffi/gtk";
2
- import type { Node } from "../node.js";
3
- import { VirtualNode } from "./virtual.js";
4
- type ChildParentWidget = Gtk.Widget & {
5
- remove(child: Gtk.Widget): void;
6
- };
7
- export declare abstract class VirtualChildNode<P extends ChildParentWidget = ChildParentWidget> extends VirtualNode {
8
- protected parent?: P;
9
- protected children: Gtk.Widget[];
10
- setParent(newParent?: P): void;
11
- protected abstract getPositionLabel(): string;
12
- protected abstract attachChild(parent: P, widget: Gtk.Widget): void;
13
- unmount(): void;
14
- appendChild(child: Node): void;
15
- insertBefore(child: Node): void;
16
- removeChild(child: Node): void;
17
- }
18
- export {};
@@ -1,62 +0,0 @@
1
- import { isObjectEqual } from "@gtkx/ffi";
2
- import { CommitPriority, scheduleAfterCommit } from "../scheduler.js";
3
- import { VirtualNode } from "./virtual.js";
4
- import { WidgetNode } from "./widget.js";
5
- export class VirtualChildNode extends VirtualNode {
6
- parent;
7
- children = [];
8
- setParent(newParent) {
9
- this.parent = newParent;
10
- }
11
- unmount() {
12
- const parent = this.parent;
13
- const childrenToRemove = [...this.children];
14
- if (parent && childrenToRemove.length > 0) {
15
- scheduleAfterCommit(() => {
16
- for (const widget of childrenToRemove) {
17
- const currentParent = widget.getParent();
18
- if (currentParent && isObjectEqual(currentParent, parent)) {
19
- parent.remove(widget);
20
- }
21
- }
22
- }, CommitPriority.HIGH);
23
- }
24
- this.children = [];
25
- this.parent = undefined;
26
- super.unmount();
27
- }
28
- appendChild(child) {
29
- if (!(child instanceof WidgetNode)) {
30
- throw new Error(`Cannot append '${child.typeName}' to '${this.typeName}': expected Widget`);
31
- }
32
- const widget = child.container;
33
- this.children.push(widget);
34
- scheduleAfterCommit(() => {
35
- if (this.parent) {
36
- this.attachChild(this.parent, widget);
37
- }
38
- });
39
- }
40
- insertBefore(child) {
41
- this.appendChild(child);
42
- }
43
- removeChild(child) {
44
- if (!(child instanceof WidgetNode)) {
45
- throw new Error(`Cannot remove '${child.typeName}' from '${this.typeName}': expected Widget`);
46
- }
47
- const widget = child.container;
48
- const parent = this.parent;
49
- const index = this.children.indexOf(widget);
50
- if (index !== -1) {
51
- this.children.splice(index, 1);
52
- }
53
- scheduleAfterCommit(() => {
54
- if (parent) {
55
- const currentParent = widget.getParent();
56
- if (currentParent && isObjectEqual(currentParent, parent)) {
57
- parent.remove(widget);
58
- }
59
- }
60
- }, CommitPriority.HIGH);
61
- }
62
- }