@gtkx/react 0.6.1 → 0.8.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.
- package/dist/batch.d.ts +4 -1
- package/dist/batch.js +19 -10
- package/dist/codegen/jsx-generator.d.ts +4 -4
- package/dist/codegen/jsx-generator.js +24 -27
- package/dist/container-interfaces.d.ts +19 -6
- package/dist/container-interfaces.js +26 -6
- package/dist/errors.d.ts +8 -0
- package/dist/errors.js +38 -0
- package/dist/factory.js +9 -3
- package/dist/generated/jsx.d.ts +38 -26
- package/dist/generated/jsx.js +12 -2
- package/dist/index.js +3 -1
- package/dist/node.d.ts +5 -0
- package/dist/node.js +62 -6
- package/dist/nodes/action-bar.d.ts +2 -6
- package/dist/nodes/action-bar.js +3 -12
- package/dist/nodes/column-view.d.ts +19 -44
- package/dist/nodes/column-view.js +70 -243
- package/dist/nodes/combo-row.d.ts +5 -0
- package/dist/nodes/combo-row.js +6 -0
- package/dist/nodes/drop-down.d.ts +9 -0
- package/dist/nodes/drop-down.js +12 -0
- package/dist/nodes/flow-box.d.ts +4 -3
- package/dist/nodes/flow-box.js +26 -10
- package/dist/nodes/grid.d.ts +15 -15
- package/dist/nodes/grid.js +21 -64
- package/dist/nodes/header-bar.d.ts +34 -11
- package/dist/nodes/header-bar.js +55 -24
- package/dist/nodes/indexed-child-container.d.ts +16 -0
- package/dist/nodes/indexed-child-container.js +22 -0
- package/dist/nodes/list-box.d.ts +4 -3
- package/dist/nodes/list-box.js +33 -6
- package/dist/nodes/list-item-factory.d.ts +19 -0
- package/dist/nodes/list-item-factory.js +58 -0
- package/dist/nodes/list-view.d.ts +24 -0
- package/dist/nodes/list-view.js +46 -0
- package/dist/nodes/menu.d.ts +25 -19
- package/dist/nodes/menu.js +30 -59
- package/dist/nodes/notebook.d.ts +13 -14
- package/dist/nodes/notebook.js +18 -56
- package/dist/nodes/paged-stack.d.ts +39 -0
- package/dist/nodes/paged-stack.js +54 -0
- package/dist/nodes/selectable-list.d.ts +41 -0
- package/dist/nodes/selectable-list.js +228 -0
- package/dist/nodes/stack-page-props.d.ts +11 -0
- package/dist/nodes/stack-page-props.js +23 -0
- package/dist/nodes/stack.d.ts +14 -28
- package/dist/nodes/stack.js +30 -142
- package/dist/nodes/string-list-container.d.ts +41 -0
- package/dist/nodes/string-list-container.js +90 -0
- package/dist/nodes/string-list-item.d.ts +15 -0
- package/dist/nodes/string-list-item.js +48 -0
- package/dist/nodes/string-list-store.d.ts +13 -0
- package/dist/nodes/string-list-store.js +44 -0
- package/dist/nodes/text-view.d.ts +1 -1
- package/dist/nodes/text-view.js +1 -5
- package/dist/nodes/toggle-button.d.ts +1 -1
- package/dist/nodes/toggle-button.js +1 -3
- package/dist/nodes/view-stack.d.ts +9 -0
- package/dist/nodes/view-stack.js +28 -0
- package/dist/nodes/virtual-item.d.ts +20 -0
- package/dist/nodes/virtual-item.js +57 -0
- package/dist/nodes/virtual-slot.d.ts +25 -0
- package/dist/nodes/virtual-slot.js +71 -0
- package/dist/nodes/widget.d.ts +0 -3
- package/dist/nodes/widget.js +0 -28
- package/dist/nodes/window.d.ts +1 -1
- package/dist/nodes/window.js +9 -15
- package/dist/predicates.d.ts +8 -0
- package/dist/predicates.js +8 -0
- package/dist/props.d.ts +7 -5
- package/dist/props.js +11 -9
- package/dist/reconciler/host-config.d.ts +19 -0
- package/dist/reconciler/host-config.js +89 -0
- package/dist/reconciler.d.ts +2 -26
- package/dist/reconciler.js +15 -106
- package/dist/render.d.ts +3 -4
- package/dist/render.js +6 -4
- package/dist/types.d.ts +22 -19
- package/package.json +6 -5
- package/dist/nodes/dropdown.d.ts +0 -39
- package/dist/nodes/dropdown.js +0 -103
- package/dist/nodes/list.d.ts +0 -43
- package/dist/nodes/list.js +0 -153
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type * as Gtk from "@gtkx/ffi/gtk";
|
|
2
2
|
import type { ReactElement, ReactNode } from "react";
|
|
3
3
|
/**
|
|
4
4
|
* Props for slot components that accept children.
|
|
@@ -8,13 +8,25 @@ export type SlotProps = {
|
|
|
8
8
|
children?: ReactNode;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
|
-
* Props passed to list item components.
|
|
11
|
+
* Props passed to list item components (ListView, GridView, ColumnView).
|
|
12
12
|
* @typeParam I - The type of the data item
|
|
13
13
|
*/
|
|
14
14
|
export type ListItemProps<I = unknown> = {
|
|
15
|
+
/** Unique identifier for this item. Used for selection. */
|
|
16
|
+
id: string;
|
|
15
17
|
/** The data item to render. */
|
|
16
18
|
item: I;
|
|
17
19
|
};
|
|
20
|
+
/**
|
|
21
|
+
* Props for string list items (DropDown, ComboRow).
|
|
22
|
+
* Similar to HTML select option elements.
|
|
23
|
+
*/
|
|
24
|
+
export type StringListItemProps = {
|
|
25
|
+
/** Unique identifier for this item. Used for selection. */
|
|
26
|
+
id: string;
|
|
27
|
+
/** Display text shown in the dropdown. */
|
|
28
|
+
label: string;
|
|
29
|
+
};
|
|
18
30
|
export type GridChildProps = SlotProps & {
|
|
19
31
|
column?: number;
|
|
20
32
|
row?: number;
|
|
@@ -34,14 +46,6 @@ export type ListViewRenderProps<T = unknown> = {
|
|
|
34
46
|
/** Render function called for each item in the list. */
|
|
35
47
|
renderItem: RenderItemFn<T>;
|
|
36
48
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Comparison function for sorting items by column.
|
|
39
|
-
* Returns negative if a < b, 0 if a === b, positive if a > b.
|
|
40
|
-
* @param a - First item to compare
|
|
41
|
-
* @param b - Second item to compare
|
|
42
|
-
* @param columnId - The ID of the column being sorted
|
|
43
|
-
*/
|
|
44
|
-
export type ColumnSortFn<T, C extends string = string> = (a: T, b: T, columnId: C) => number;
|
|
45
49
|
/**
|
|
46
50
|
* Props for individual columns in a ColumnView.
|
|
47
51
|
* @typeParam T - The type of the data items displayed in the column
|
|
@@ -66,18 +70,17 @@ export type ColumnViewColumnProps<T = unknown> = {
|
|
|
66
70
|
};
|
|
67
71
|
/**
|
|
68
72
|
* Props for the ColumnView root component.
|
|
69
|
-
*
|
|
73
|
+
* Sorting is handled by the parent component - sort your items before rendering
|
|
74
|
+
* and pass them as ColumnView.Item children in the desired order.
|
|
70
75
|
* @typeParam C - The union type of column IDs
|
|
71
76
|
*/
|
|
72
|
-
export type ColumnViewRootProps<
|
|
73
|
-
/** The ID of the currently sorted column, or null if unsorted. */
|
|
77
|
+
export type ColumnViewRootProps<C extends string = string> = {
|
|
78
|
+
/** The ID of the currently sorted column, or null if unsorted. Controls the sort indicator UI. */
|
|
74
79
|
sortColumn?: C | null;
|
|
75
|
-
/** The current sort direction. */
|
|
76
|
-
sortOrder?: SortType;
|
|
77
|
-
/** Callback fired when the user
|
|
78
|
-
onSortChange?: (column: C | null, order: SortType) => void;
|
|
79
|
-
/** Custom comparison function for sorting items. */
|
|
80
|
-
sortFn?: ColumnSortFn<T, C>;
|
|
80
|
+
/** The current sort direction. Controls the sort indicator UI. */
|
|
81
|
+
sortOrder?: Gtk.SortType;
|
|
82
|
+
/** Callback fired when the user clicks a column header to change sort. */
|
|
83
|
+
onSortChange?: (column: C | null, order: Gtk.SortType) => void;
|
|
81
84
|
};
|
|
82
85
|
export type NotebookPageProps = SlotProps & {
|
|
83
86
|
label: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gtkx/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Build GTK4 desktop applications with React and TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"gtk",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
21
|
"url": "https://github.com/eugeniodepalo/gtkx.git",
|
|
22
|
-
"directory": "packages/
|
|
22
|
+
"directory": "packages/react"
|
|
23
23
|
},
|
|
24
24
|
"license": "MPL-2.0",
|
|
25
25
|
"author": "Eugenio Depalo <eugeniodepalo@gmail.com>",
|
|
@@ -35,11 +35,12 @@
|
|
|
35
35
|
"dist"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"react-reconciler": "0.33.0",
|
|
39
|
-
"@gtkx/ffi": "0.
|
|
38
|
+
"react-reconciler": "^0.33.0",
|
|
39
|
+
"@gtkx/ffi": "0.8.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@gtkx/gir": "0.
|
|
42
|
+
"@gtkx/gir": "0.8.0",
|
|
43
|
+
"@gtkx/native": "0.8.0"
|
|
43
44
|
},
|
|
44
45
|
"peerDependencies": {
|
|
45
46
|
"react": "^19"
|
package/dist/nodes/dropdown.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import { type ItemContainer } from "../container-interfaces.js";
|
|
3
|
-
import type { Props } from "../factory.js";
|
|
4
|
-
import { Node } from "../node.js";
|
|
5
|
-
type ItemLabelFn = (item: unknown) => string;
|
|
6
|
-
interface DropDownState {
|
|
7
|
-
store: DropDownStore;
|
|
8
|
-
onSelectionChanged?: (item: unknown, index: number) => void;
|
|
9
|
-
}
|
|
10
|
-
declare class DropDownStore {
|
|
11
|
-
private stringList;
|
|
12
|
-
private items;
|
|
13
|
-
private labelFn;
|
|
14
|
-
constructor(labelFn: ItemLabelFn);
|
|
15
|
-
getModel(): Gtk.StringList;
|
|
16
|
-
append(item: unknown): void;
|
|
17
|
-
remove(item: unknown): void;
|
|
18
|
-
getItem(index: number): unknown;
|
|
19
|
-
get length(): number;
|
|
20
|
-
}
|
|
21
|
-
export declare class DropDownNode extends Node<Gtk.DropDown, DropDownState> implements ItemContainer<unknown> {
|
|
22
|
-
static matches(type: string): boolean;
|
|
23
|
-
initialize(props: Props): void;
|
|
24
|
-
addItem(item: unknown): void;
|
|
25
|
-
insertItemBefore(item: unknown, _beforeItem: unknown): void;
|
|
26
|
-
removeItem(item: unknown): void;
|
|
27
|
-
protected consumedProps(): Set<string>;
|
|
28
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
29
|
-
}
|
|
30
|
-
export declare class DropDownItemNode extends Node<never> {
|
|
31
|
-
static matches(type: string): boolean;
|
|
32
|
-
protected isVirtual(): boolean;
|
|
33
|
-
private item;
|
|
34
|
-
initialize(props: Props): void;
|
|
35
|
-
getItem(): unknown;
|
|
36
|
-
attachToParent(parent: Node): void;
|
|
37
|
-
detachFromParent(parent: Node): void;
|
|
38
|
-
}
|
|
39
|
-
export {};
|
package/dist/nodes/dropdown.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { getInterface } from "@gtkx/ffi";
|
|
2
|
-
import * as Gio from "@gtkx/ffi/gio";
|
|
3
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
|
-
import { isItemContainer } from "../container-interfaces.js";
|
|
5
|
-
import { Node } from "../node.js";
|
|
6
|
-
class DropDownStore {
|
|
7
|
-
stringList;
|
|
8
|
-
items = [];
|
|
9
|
-
labelFn;
|
|
10
|
-
constructor(labelFn) {
|
|
11
|
-
this.stringList = new Gtk.StringList([]);
|
|
12
|
-
this.labelFn = labelFn;
|
|
13
|
-
}
|
|
14
|
-
getModel() {
|
|
15
|
-
return this.stringList;
|
|
16
|
-
}
|
|
17
|
-
append(item) {
|
|
18
|
-
const label = this.labelFn(item);
|
|
19
|
-
this.stringList.append(label);
|
|
20
|
-
this.items.push(item);
|
|
21
|
-
}
|
|
22
|
-
remove(item) {
|
|
23
|
-
const index = this.items.indexOf(item);
|
|
24
|
-
if (index !== -1) {
|
|
25
|
-
this.stringList.remove(index);
|
|
26
|
-
this.items.splice(index, 1);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
getItem(index) {
|
|
30
|
-
return this.items[index];
|
|
31
|
-
}
|
|
32
|
-
get length() {
|
|
33
|
-
return this.items.length;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
export class DropDownNode extends Node {
|
|
37
|
-
static matches(type) {
|
|
38
|
-
return type === "DropDown.Root";
|
|
39
|
-
}
|
|
40
|
-
initialize(props) {
|
|
41
|
-
const labelFn = props.itemLabel ?? ((item) => String(item));
|
|
42
|
-
const store = new DropDownStore(labelFn);
|
|
43
|
-
const onSelectionChanged = props.onSelectionChanged;
|
|
44
|
-
this.state = { store, onSelectionChanged };
|
|
45
|
-
super.initialize(props);
|
|
46
|
-
this.widget.setModel(getInterface(store.getModel(), Gio.ListModel));
|
|
47
|
-
if (onSelectionChanged) {
|
|
48
|
-
const handler = () => {
|
|
49
|
-
const index = this.widget.getSelected();
|
|
50
|
-
const item = this.state.store.getItem(index);
|
|
51
|
-
this.state.onSelectionChanged?.(item, index);
|
|
52
|
-
};
|
|
53
|
-
this.connectSignal(this.widget, "notify::selected", handler);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
addItem(item) {
|
|
57
|
-
this.state.store.append(item);
|
|
58
|
-
}
|
|
59
|
-
insertItemBefore(item, _beforeItem) {
|
|
60
|
-
this.addItem(item);
|
|
61
|
-
}
|
|
62
|
-
removeItem(item) {
|
|
63
|
-
this.state.store.remove(item);
|
|
64
|
-
}
|
|
65
|
-
consumedProps() {
|
|
66
|
-
const consumed = super.consumedProps();
|
|
67
|
-
consumed.add("itemLabel");
|
|
68
|
-
consumed.add("onSelectionChanged");
|
|
69
|
-
return consumed;
|
|
70
|
-
}
|
|
71
|
-
updateProps(oldProps, newProps) {
|
|
72
|
-
if (oldProps.onSelectionChanged !== newProps.onSelectionChanged) {
|
|
73
|
-
this.state.onSelectionChanged = newProps.onSelectionChanged;
|
|
74
|
-
}
|
|
75
|
-
super.updateProps(oldProps, newProps);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
export class DropDownItemNode extends Node {
|
|
79
|
-
static matches(type) {
|
|
80
|
-
return type === "DropDown.Item";
|
|
81
|
-
}
|
|
82
|
-
isVirtual() {
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
item;
|
|
86
|
-
initialize(props) {
|
|
87
|
-
super.initialize(props);
|
|
88
|
-
this.item = props.item;
|
|
89
|
-
}
|
|
90
|
-
getItem() {
|
|
91
|
-
return this.item;
|
|
92
|
-
}
|
|
93
|
-
attachToParent(parent) {
|
|
94
|
-
if (!isItemContainer(parent))
|
|
95
|
-
return;
|
|
96
|
-
parent.addItem(this.item);
|
|
97
|
-
}
|
|
98
|
-
detachFromParent(parent) {
|
|
99
|
-
if (!isItemContainer(parent))
|
|
100
|
-
return;
|
|
101
|
-
parent.removeItem(this.item);
|
|
102
|
-
}
|
|
103
|
-
}
|
package/dist/nodes/list.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
2
|
-
import type Reconciler from "react-reconciler";
|
|
3
|
-
import { type ItemContainer } from "../container-interfaces.js";
|
|
4
|
-
import type { Props } from "../factory.js";
|
|
5
|
-
import { Node } from "../node.js";
|
|
6
|
-
import type { RenderItemFn } from "../types.js";
|
|
7
|
-
interface ListItemInfo {
|
|
8
|
-
box: Gtk.Box;
|
|
9
|
-
fiberRoot: Reconciler.FiberRoot;
|
|
10
|
-
}
|
|
11
|
-
interface ListViewState {
|
|
12
|
-
stringList: Gtk.StringList;
|
|
13
|
-
selectionModel: Gtk.SingleSelection;
|
|
14
|
-
factory: Gtk.SignalListItemFactory;
|
|
15
|
-
renderItem: RenderItemFn<unknown>;
|
|
16
|
-
listItemCache: Map<number, ListItemInfo>;
|
|
17
|
-
items: unknown[];
|
|
18
|
-
committedLength: number;
|
|
19
|
-
}
|
|
20
|
-
export declare class ListViewNode extends Node<Gtk.ListView | Gtk.GridView, ListViewState> implements ItemContainer<unknown> {
|
|
21
|
-
static matches(type: string): boolean;
|
|
22
|
-
initialize(props: Props): void;
|
|
23
|
-
private initializeStateWithPlaceholders;
|
|
24
|
-
private createGtkModels;
|
|
25
|
-
private connectFactorySignals;
|
|
26
|
-
private syncStringList;
|
|
27
|
-
addItem(item: unknown): void;
|
|
28
|
-
insertItemBefore(item: unknown, beforeItem: unknown): void;
|
|
29
|
-
removeItem(item: unknown): void;
|
|
30
|
-
protected consumedProps(): Set<string>;
|
|
31
|
-
updateProps(oldProps: Props, newProps: Props): void;
|
|
32
|
-
}
|
|
33
|
-
export declare class ListItemNode extends Node {
|
|
34
|
-
static matches(type: string): boolean;
|
|
35
|
-
protected isVirtual(): boolean;
|
|
36
|
-
private item;
|
|
37
|
-
initialize(props: Props): void;
|
|
38
|
-
getItem(): unknown;
|
|
39
|
-
attachToParent(parent: Node): void;
|
|
40
|
-
attachToParentBefore(parent: Node, before: Node): void;
|
|
41
|
-
detachFromParent(parent: Node): void;
|
|
42
|
-
}
|
|
43
|
-
export {};
|
package/dist/nodes/list.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { getInterface, getObject, getObjectId } from "@gtkx/ffi";
|
|
2
|
-
import * as Gio from "@gtkx/ffi/gio";
|
|
3
|
-
import * as Gtk from "@gtkx/ffi/gtk";
|
|
4
|
-
import { scheduleFlush } from "../batch.js";
|
|
5
|
-
import { isItemContainer } from "../container-interfaces.js";
|
|
6
|
-
import { createFiberRoot } from "../fiber-root.js";
|
|
7
|
-
import { Node } from "../node.js";
|
|
8
|
-
import { reconciler } from "../reconciler.js";
|
|
9
|
-
export class ListViewNode extends Node {
|
|
10
|
-
static matches(type) {
|
|
11
|
-
return type === "ListView.Root" || type === "GridView.Root";
|
|
12
|
-
}
|
|
13
|
-
initialize(props) {
|
|
14
|
-
this.initializeStateWithPlaceholders(props);
|
|
15
|
-
super.initialize(props);
|
|
16
|
-
this.createGtkModels();
|
|
17
|
-
this.connectFactorySignals();
|
|
18
|
-
this.widget.setModel(this.state.selectionModel);
|
|
19
|
-
this.widget.setFactory(this.state.factory);
|
|
20
|
-
}
|
|
21
|
-
initializeStateWithPlaceholders(props) {
|
|
22
|
-
this.state = {
|
|
23
|
-
stringList: null,
|
|
24
|
-
selectionModel: null,
|
|
25
|
-
factory: null,
|
|
26
|
-
renderItem: props.renderItem,
|
|
27
|
-
listItemCache: new Map(),
|
|
28
|
-
items: [],
|
|
29
|
-
committedLength: 0,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
createGtkModels() {
|
|
33
|
-
const stringList = new Gtk.StringList([]);
|
|
34
|
-
const selectionModel = new Gtk.SingleSelection(getInterface(stringList, Gio.ListModel));
|
|
35
|
-
const factory = new Gtk.SignalListItemFactory();
|
|
36
|
-
this.state.stringList = stringList;
|
|
37
|
-
this.state.selectionModel = selectionModel;
|
|
38
|
-
this.state.factory = factory;
|
|
39
|
-
}
|
|
40
|
-
connectFactorySignals() {
|
|
41
|
-
const factory = this.state.factory;
|
|
42
|
-
factory.connect("setup", (_self, listItemObj) => {
|
|
43
|
-
const listItem = getObject(listItemObj.id);
|
|
44
|
-
const id = getObjectId(listItemObj.id);
|
|
45
|
-
const box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
|
|
46
|
-
listItem.setChild(box);
|
|
47
|
-
const fiberRoot = createFiberRoot(box);
|
|
48
|
-
this.state.listItemCache.set(id, { box, fiberRoot });
|
|
49
|
-
const element = this.state.renderItem(null);
|
|
50
|
-
reconciler.getInstance().updateContainer(element, fiberRoot, null, () => { });
|
|
51
|
-
});
|
|
52
|
-
factory.connect("bind", (_self, listItemObj) => {
|
|
53
|
-
const listItem = getObject(listItemObj.id);
|
|
54
|
-
const id = getObjectId(listItemObj.id);
|
|
55
|
-
const info = this.state.listItemCache.get(id);
|
|
56
|
-
if (!info)
|
|
57
|
-
return;
|
|
58
|
-
const position = listItem.getPosition();
|
|
59
|
-
const item = this.state.items[position];
|
|
60
|
-
const element = this.state.renderItem(item);
|
|
61
|
-
reconciler.getInstance().updateContainer(element, info.fiberRoot, null, () => { });
|
|
62
|
-
});
|
|
63
|
-
factory.connect("unbind", (_self, listItemObj) => {
|
|
64
|
-
const id = getObjectId(listItemObj.id);
|
|
65
|
-
const info = this.state.listItemCache.get(id);
|
|
66
|
-
if (!info)
|
|
67
|
-
return;
|
|
68
|
-
reconciler.getInstance().updateContainer(null, info.fiberRoot, null, () => { });
|
|
69
|
-
});
|
|
70
|
-
factory.connect("teardown", (_self, listItemObj) => {
|
|
71
|
-
const id = getObjectId(listItemObj.id);
|
|
72
|
-
const info = this.state.listItemCache.get(id);
|
|
73
|
-
if (info) {
|
|
74
|
-
reconciler.getInstance().updateContainer(null, info.fiberRoot, null, () => { });
|
|
75
|
-
this.state.listItemCache.delete(id);
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
syncStringList = () => {
|
|
80
|
-
const newLength = this.state.items.length;
|
|
81
|
-
if (newLength === this.state.committedLength)
|
|
82
|
-
return;
|
|
83
|
-
const placeholders = Array.from({ length: newLength }, () => "");
|
|
84
|
-
this.state.stringList.splice(0, this.state.committedLength, placeholders);
|
|
85
|
-
this.state.committedLength = newLength;
|
|
86
|
-
};
|
|
87
|
-
addItem(item) {
|
|
88
|
-
this.state.items.push(item);
|
|
89
|
-
scheduleFlush(this.syncStringList);
|
|
90
|
-
}
|
|
91
|
-
insertItemBefore(item, beforeItem) {
|
|
92
|
-
const beforeIndex = this.state.items.indexOf(beforeItem);
|
|
93
|
-
if (beforeIndex === -1) {
|
|
94
|
-
this.state.items.push(item);
|
|
95
|
-
}
|
|
96
|
-
else {
|
|
97
|
-
this.state.items.splice(beforeIndex, 0, item);
|
|
98
|
-
}
|
|
99
|
-
scheduleFlush(this.syncStringList);
|
|
100
|
-
}
|
|
101
|
-
removeItem(item) {
|
|
102
|
-
const index = this.state.items.indexOf(item);
|
|
103
|
-
if (index !== -1) {
|
|
104
|
-
this.state.items.splice(index, 1);
|
|
105
|
-
scheduleFlush(this.syncStringList);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
consumedProps() {
|
|
109
|
-
const consumed = super.consumedProps();
|
|
110
|
-
consumed.add("renderItem");
|
|
111
|
-
return consumed;
|
|
112
|
-
}
|
|
113
|
-
updateProps(oldProps, newProps) {
|
|
114
|
-
if (oldProps.renderItem !== newProps.renderItem) {
|
|
115
|
-
this.state.renderItem = newProps.renderItem;
|
|
116
|
-
}
|
|
117
|
-
super.updateProps(oldProps, newProps);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
export class ListItemNode extends Node {
|
|
121
|
-
static matches(type) {
|
|
122
|
-
return type === "ListView.Item" || type === "GridView.Item";
|
|
123
|
-
}
|
|
124
|
-
isVirtual() {
|
|
125
|
-
return true;
|
|
126
|
-
}
|
|
127
|
-
item;
|
|
128
|
-
initialize(props) {
|
|
129
|
-
this.item = props.item;
|
|
130
|
-
super.initialize(props);
|
|
131
|
-
}
|
|
132
|
-
getItem() {
|
|
133
|
-
return this.item;
|
|
134
|
-
}
|
|
135
|
-
attachToParent(parent) {
|
|
136
|
-
if (isItemContainer(parent)) {
|
|
137
|
-
parent.addItem(this.item);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
attachToParentBefore(parent, before) {
|
|
141
|
-
if (isItemContainer(parent) && before instanceof ListItemNode) {
|
|
142
|
-
parent.insertItemBefore(this.item, before.getItem());
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
this.attachToParent(parent);
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
detachFromParent(parent) {
|
|
149
|
-
if (isItemContainer(parent)) {
|
|
150
|
-
parent.removeItem(this.item);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|