@gtkx/react 1.0.0-rc.2 → 1.0.0-rc.4

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 (173) hide show
  1. package/README.md +4 -5
  2. package/dist/adw/config.d.ts +1 -0
  3. package/dist/adw/config.d.ts.map +1 -1
  4. package/dist/adw/config.js +1 -0
  5. package/dist/adw/config.js.map +1 -1
  6. package/dist/adw/dialog.d.ts +1 -0
  7. package/dist/adw/dialog.d.ts.map +1 -1
  8. package/dist/adw/dialog.js +1 -0
  9. package/dist/adw/dialog.js.map +1 -1
  10. package/dist/adw/element-behaviors.js +8 -39
  11. package/dist/adw/element-behaviors.js.map +1 -1
  12. package/dist/adw/element-config.d.ts +7 -4
  13. package/dist/adw/element-config.d.ts.map +1 -1
  14. package/dist/adw/element-config.js +32 -41
  15. package/dist/adw/element-config.js.map +1 -1
  16. package/dist/adw/index.d.ts +1 -0
  17. package/dist/adw/index.d.ts.map +1 -1
  18. package/dist/adw/index.js +1 -0
  19. package/dist/adw/index.js.map +1 -1
  20. package/dist/adw/prop-types.d.ts +1 -1
  21. package/dist/adw/prop-types.d.ts.map +1 -1
  22. package/dist/adw/prop-types.js.map +1 -1
  23. package/dist/bootstrap.js +1 -1
  24. package/dist/bootstrap.js.map +1 -1
  25. package/dist/components/application.d.ts +1 -0
  26. package/dist/components/application.d.ts.map +1 -1
  27. package/dist/components/application.js +1 -0
  28. package/dist/components/application.js.map +1 -1
  29. package/dist/components/element.d.ts +0 -1
  30. package/dist/components/element.d.ts.map +1 -1
  31. package/dist/components/element.js +0 -1
  32. package/dist/components/element.js.map +1 -1
  33. package/dist/components/window.d.ts +1 -0
  34. package/dist/components/window.d.ts.map +1 -1
  35. package/dist/components/window.js +14 -2
  36. package/dist/components/window.js.map +1 -1
  37. package/dist/config.d.ts +5 -2
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +3 -1
  40. package/dist/config.js.map +1 -1
  41. package/dist/element-behaviors.js +0 -1
  42. package/dist/element-behaviors.js.map +1 -1
  43. package/dist/element-config.d.ts +4 -3
  44. package/dist/element-config.d.ts.map +1 -1
  45. package/dist/element-config.js +12 -8
  46. package/dist/element-config.js.map +1 -1
  47. package/dist/hooks/use-bind-setting.d.ts +8 -7
  48. package/dist/hooks/use-bind-setting.d.ts.map +1 -1
  49. package/dist/hooks/use-bind-setting.js +2 -7
  50. package/dist/hooks/use-bind-setting.js.map +1 -1
  51. package/dist/hooks/use-parent-window.d.ts +3 -1
  52. package/dist/hooks/use-parent-window.d.ts.map +1 -1
  53. package/dist/hooks/use-parent-window.js +3 -1
  54. package/dist/hooks/use-parent-window.js.map +1 -1
  55. package/dist/hooks/use-property.d.ts +2 -2
  56. package/dist/hooks/use-property.d.ts.map +1 -1
  57. package/dist/hooks/use-property.js +1 -2
  58. package/dist/hooks/use-property.js.map +1 -1
  59. package/dist/hooks/use-setting.d.ts +2 -3
  60. package/dist/hooks/use-setting.d.ts.map +1 -1
  61. package/dist/hooks/use-setting.js +2 -3
  62. package/dist/hooks/use-setting.js.map +1 -1
  63. package/dist/hooks/use-signal.d.ts +17 -7
  64. package/dist/hooks/use-signal.d.ts.map +1 -1
  65. package/dist/hooks/use-signal.js +10 -8
  66. package/dist/hooks/use-signal.js.map +1 -1
  67. package/dist/index.d.ts +10 -2
  68. package/dist/index.d.ts.map +1 -1
  69. package/dist/index.js +8 -0
  70. package/dist/index.js.map +1 -1
  71. package/dist/internal.d.ts +5 -3
  72. package/dist/internal.d.ts.map +1 -1
  73. package/dist/internal.js +3 -3
  74. package/dist/internal.js.map +1 -1
  75. package/dist/prop-types.d.ts +60 -0
  76. package/dist/prop-types.d.ts.map +1 -1
  77. package/dist/prop-types.js.map +1 -1
  78. package/dist/reconciler/apply-props.d.ts.map +1 -1
  79. package/dist/reconciler/apply-props.js +12 -6
  80. package/dist/reconciler/apply-props.js.map +1 -1
  81. package/dist/reconciler/behaviors.d.ts +0 -15
  82. package/dist/reconciler/behaviors.d.ts.map +1 -1
  83. package/dist/reconciler/behaviors.js +12 -22
  84. package/dist/reconciler/behaviors.js.map +1 -1
  85. package/dist/reconciler/host-config.d.ts +1 -1
  86. package/dist/reconciler/host-config.d.ts.map +1 -1
  87. package/dist/reconciler/host-config.js +2 -6
  88. package/dist/reconciler/host-config.js.map +1 -1
  89. package/dist/reconciler/instance.js +1 -1
  90. package/dist/reconciler/instance.js.map +1 -1
  91. package/dist/reconciler/metadata.d.ts +1 -1
  92. package/dist/reconciler/metadata.d.ts.map +1 -1
  93. package/dist/reconciler/metadata.js +7 -7
  94. package/dist/reconciler/metadata.js.map +1 -1
  95. package/dist/reconciler/node.d.ts +2 -2
  96. package/dist/reconciler/node.d.ts.map +1 -1
  97. package/dist/reconciler/node.js +1 -1
  98. package/dist/reconciler/node.js.map +1 -1
  99. package/dist/reconciler/placement.d.ts.map +1 -1
  100. package/dist/reconciler/placement.js +28 -12
  101. package/dist/reconciler/placement.js.map +1 -1
  102. package/dist/reconciler/registry.d.ts +56 -29
  103. package/dist/reconciler/registry.d.ts.map +1 -1
  104. package/dist/reconciler/registry.js +27 -26
  105. package/dist/reconciler/registry.js.map +1 -1
  106. package/dist/reconciler/root-element.d.ts +0 -1
  107. package/dist/reconciler/root-element.d.ts.map +1 -1
  108. package/dist/reconciler/root-element.js +0 -1
  109. package/dist/reconciler/root-element.js.map +1 -1
  110. package/dist/reconciler/root.d.ts +8 -22
  111. package/dist/reconciler/root.d.ts.map +1 -1
  112. package/dist/reconciler/root.js +5 -23
  113. package/dist/reconciler/root.js.map +1 -1
  114. package/dist/reconciler/signals.d.ts +3 -4
  115. package/dist/reconciler/signals.d.ts.map +1 -1
  116. package/dist/reconciler/signals.js +14 -26
  117. package/dist/reconciler/signals.js.map +1 -1
  118. package/dist/reconciler/text.d.ts.map +1 -1
  119. package/dist/reconciler/text.js +18 -13
  120. package/dist/reconciler/text.js.map +1 -1
  121. package/dist/utils/accessible-metadata.d.ts +0 -7
  122. package/dist/utils/accessible-metadata.d.ts.map +1 -1
  123. package/dist/utils/accessible-metadata.js +0 -7
  124. package/dist/utils/accessible-metadata.js.map +1 -1
  125. package/dist/utils/accessible-props.d.ts +49 -1
  126. package/dist/utils/accessible-props.d.ts.map +1 -1
  127. package/dist/utils/accessible-props.js.map +1 -1
  128. package/dist/utils/ref-prop.d.ts +0 -6
  129. package/dist/utils/ref-prop.d.ts.map +1 -1
  130. package/dist/utils/ref-prop.js +0 -6
  131. package/dist/utils/ref-prop.js.map +1 -1
  132. package/dist/utils/settings.d.ts +6 -0
  133. package/dist/utils/settings.d.ts.map +1 -1
  134. package/dist/utils/settings.js.map +1 -1
  135. package/env.d.ts +11 -4
  136. package/package.json +5 -5
  137. package/src/adw/config.ts +1 -0
  138. package/src/adw/dialog.tsx +1 -0
  139. package/src/adw/element-behaviors.ts +8 -39
  140. package/src/adw/element-config.ts +33 -41
  141. package/src/adw/index.ts +1 -0
  142. package/src/adw/prop-types.ts +1 -1
  143. package/src/bootstrap.ts +1 -1
  144. package/src/components/application.tsx +1 -0
  145. package/src/components/element.tsx +0 -1
  146. package/src/components/window.tsx +16 -2
  147. package/src/config.ts +5 -2
  148. package/src/element-behaviors.ts +0 -1
  149. package/src/element-config.ts +12 -8
  150. package/src/hooks/use-bind-setting.ts +8 -7
  151. package/src/hooks/use-parent-window.ts +3 -1
  152. package/src/hooks/use-property.ts +2 -2
  153. package/src/hooks/use-setting.ts +2 -3
  154. package/src/hooks/use-signal.ts +20 -10
  155. package/src/index.ts +10 -2
  156. package/src/internal.ts +5 -3
  157. package/src/prop-types.ts +86 -5
  158. package/src/reconciler/apply-props.ts +12 -6
  159. package/src/reconciler/behaviors.ts +14 -23
  160. package/src/reconciler/host-config.ts +3 -8
  161. package/src/reconciler/instance.ts +1 -1
  162. package/src/reconciler/metadata.ts +8 -8
  163. package/src/reconciler/node.ts +3 -3
  164. package/src/reconciler/placement.ts +33 -13
  165. package/src/reconciler/registry.ts +70 -41
  166. package/src/reconciler/root-element.ts +0 -1
  167. package/src/reconciler/root.ts +9 -26
  168. package/src/reconciler/signals.ts +16 -37
  169. package/src/reconciler/text.ts +21 -14
  170. package/src/utils/accessible-metadata.ts +0 -7
  171. package/src/utils/accessible-props.ts +49 -1
  172. package/src/utils/ref-prop.ts +0 -6
  173. package/src/utils/settings.ts +6 -0
@@ -5,8 +5,9 @@ import { drain, indexBeforeOrEnd } from "@gtkx/utils";
5
5
  import type { ContentChild, ContentKind, ElementNode, ParentNode, TextNode } from "./node.js";
6
6
  import type { Props } from "./registry.js";
7
7
  import { ELEMENT_KIND, TEXT_KIND } from "./node.js";
8
+ import { applyWrite } from "./signals.js";
8
9
 
9
- type OffsetResult = { found: boolean; offset: number };
10
+ type OffsetResult = { wasFound: boolean; offset: number };
10
11
 
11
12
  type BufferBuild = {
12
13
  buffer: Gtk.TextBuffer;
@@ -75,14 +76,14 @@ const isTagElement = (node: ContentChild): node is ElementNode =>
75
76
 
76
77
  const stepOffset = (node: ContentChild, target: TextNode, offset: number): OffsetResult => {
77
78
  if (node === target) {
78
- return { found: true, offset };
79
+ return { wasFound: true, offset };
79
80
  }
80
81
 
81
82
  if (isTagElement(node)) {
82
83
  return getOffset(node.content, target, offset);
83
84
  }
84
85
 
85
- return { found: false, offset: offset + contentTextLength(node) };
86
+ return { wasFound: false, offset: offset + contentTextLength(node) };
86
87
  };
87
88
 
88
89
  const getOffset = (nodes: ContentChild[], target: TextNode, start: number): OffsetResult => {
@@ -91,14 +92,14 @@ const getOffset = (nodes: ContentChild[], target: TextNode, start: number): Offs
91
92
  for (const node of nodes) {
92
93
  const step = stepOffset(node, target, offset);
93
94
 
94
- if (step.found) {
95
+ if (step.wasFound) {
95
96
  return step;
96
97
  }
97
98
 
98
99
  offset = step.offset;
99
100
  }
100
101
 
101
- return { found: false, offset };
102
+ return { wasFound: false, offset };
102
103
  };
103
104
 
104
105
  const enclosingTagNodes = (node: TextNode): ElementNode[] => {
@@ -319,13 +320,15 @@ const rebuildBuffer = (node: ElementNode): void => {
319
320
  return;
320
321
  }
321
322
 
322
- buffer.setText("", -1);
323
- const build: BufferBuild = { buffer, view: node.bufferView, marks: [] };
324
- insertContent(build, node.content);
323
+ applyWrite(() => {
324
+ buffer.setText("", -1);
325
+ const build: BufferBuild = { buffer, view: node.bufferView, marks: [] };
326
+ insertContent(build, node.content);
325
327
 
326
- for (const mark of build.marks) {
327
- placeMark(buffer, mark.node, mark.offset);
328
- }
328
+ for (const mark of build.marks) {
329
+ placeMark(buffer, mark.node, mark.offset);
330
+ }
331
+ });
329
332
  };
330
333
 
331
334
  const rebuildLabel = (node: ElementNode): void => {
@@ -376,13 +379,17 @@ const didUpdateTextSurgically = (host: ElementNode, node: TextNode, oldText: str
376
379
 
377
380
  const located = getOffset(host.content, node, 0);
378
381
 
379
- if (!located.found) {
382
+ if (!located.wasFound) {
380
383
  return false;
381
384
  }
382
385
 
383
386
  const start = located.offset;
384
- buffer.delete(buffer.getIterAtOffset(start), buffer.getIterAtOffset(start + charLength(oldText)));
385
- buffer.insert(buffer.getIterAtOffset(start), newText, -1);
387
+
388
+ applyWrite(() => {
389
+ buffer.delete(buffer.getIterAtOffset(start), buffer.getIterAtOffset(start + charLength(oldText)));
390
+ buffer.insert(buffer.getIterAtOffset(start), newText, -1);
391
+ });
392
+
386
393
  const startIter = buffer.getIterAtOffset(start);
387
394
  const endIter = buffer.getIterAtOffset(start + charLength(newText));
388
395
  applyEnclosingTags(buffer, node, startIter, endIter);
@@ -15,13 +15,6 @@ const deleteAccessibleMetadata = (widget: object, name: string): void => {
15
15
  metadataStore.get(widget)?.delete(name);
16
16
  };
17
17
 
18
- /**
19
- * Returns the last value applied for an accessible prop on a widget, or null when none was applied.
20
- *
21
- * @param widget The widget to read from.
22
- * @param name The accessible prop name.
23
- * @returns The last applied value, or null.
24
- */
25
18
  const getAccessibleMetadata = (widget: object, name: string): unknown => {
26
19
  const value = metadataStore.get(widget)?.get(name);
27
20
 
@@ -6,55 +6,103 @@ import { deleteAccessibleMetadata, setAccessibleMetadata } from "./accessible-me
6
6
  /**
7
7
  * Accessibility props available on every widget. Each member maps to a GTK4 accessible attribute
8
8
  * (a `Gtk.AccessibleProperty`, `Gtk.AccessibleState`, or `Gtk.AccessibleRelation`) and is applied
9
- * to the widget's accessible interface; setting a member to `undefined` resets that attribute to its default.
9
+ * to the widget's accessible interface. Setting a member to `null` or `undefined`, or dropping it from the
10
+ * props, resets that attribute to its default.
10
11
  */
11
12
  type AccessibleProps = {
13
+ /** How the widget completes the text being typed into it. */
12
14
  accessibleAutocomplete?: Gtk.AccessibleAutocomplete | null | undefined;
15
+ /** Longer description announced after the label. */
13
16
  accessibleDescription?: string | null | undefined;
17
+ /** Whether activating the widget opens a popup. */
14
18
  accessibleHasPopup?: boolean | null | undefined;
19
+ /** Keyboard shortcuts that activate the widget. */
15
20
  accessibleKeyShortcuts?: string | null | undefined;
21
+ /** Short name announced for the widget. */
16
22
  accessibleLabel?: string | null | undefined;
23
+ /** Depth of the widget within a hierarchy of headings, list items, or tree rows. */
17
24
  accessibleLevel?: number | null | undefined;
25
+ /** Whether the widget blocks interaction with everything behind it. */
18
26
  accessibleModal?: boolean | null | undefined;
27
+ /** Whether the text input accepts more than one line. */
19
28
  accessibleMultiLine?: boolean | null | undefined;
29
+ /** Whether more than one of the widget's items can be selected at a time. */
20
30
  accessibleMultiSelectable?: boolean | null | undefined;
31
+ /** Whether the widget arranges its items horizontally or vertically. */
21
32
  accessibleOrientation?: Gtk.Orientation | null | undefined;
33
+ /** Hint announced while the input is empty. */
22
34
  accessiblePlaceholder?: string | null | undefined;
35
+ /** Whether the value can be read but not changed. */
23
36
  accessibleReadOnly?: boolean | null | undefined;
37
+ /** Whether a value has to be supplied before the form can be submitted. */
24
38
  accessibleRequired?: boolean | null | undefined;
39
+ /** Wording that replaces the default announcement of the widget's role. */
25
40
  accessibleRoleDescription?: string | null | undefined;
41
+ /** Direction the widget's items are sorted in. */
26
42
  accessibleSort?: Gtk.AccessibleSort | null | undefined;
43
+ /** Upper bound of the widget's value range. */
27
44
  accessibleValueMax?: number | null | undefined;
45
+ /** Lower bound of the widget's value range. */
28
46
  accessibleValueMin?: number | null | undefined;
47
+ /** Current value within the widget's range. */
29
48
  accessibleValueNow?: number | null | undefined;
49
+ /** Wording announced in place of the numeric value. */
30
50
  accessibleValueText?: string | null | undefined;
51
+ /** Help text describing how to use the widget. */
31
52
  accessibleHelpText?: string | null | undefined;
53
+ /** Whether the widget is still loading and its content may yet change. */
32
54
  accessibleBusy?: boolean | null | undefined;
55
+ /** Checked state of a check button or menu item, which may be mixed. */
33
56
  accessibleChecked?: Gtk.AccessibleTristate | null | undefined;
57
+ /** Whether the widget is visible but cannot be edited or operated. */
34
58
  accessibleDisabled?: boolean | null | undefined;
59
+ /** Whether the content the widget discloses is showing. */
35
60
  accessibleExpanded?: boolean | null | undefined;
61
+ /** Whether the widget is kept out of the accessibility tree. */
36
62
  accessibleHidden?: boolean | null | undefined;
63
+ /** Whether the entered value fails validation, and in what way. */
37
64
  accessibleInvalid?: Gtk.AccessibleInvalidState | null | undefined;
65
+ /** Pressed state of a toggle button, which may be mixed. */
38
66
  accessiblePressed?: Gtk.AccessibleTristate | null | undefined;
67
+ /** Whether the widget is selected within its container. */
39
68
  accessibleSelected?: boolean | null | undefined;
69
+ /** Whether the link has already been followed. */
40
70
  accessibleVisited?: boolean | null | undefined;
71
+ /** Descendant that holds the focus while the widget itself keeps it. */
41
72
  accessibleActiveDescendant?: Gtk.Widget | null | undefined;
73
+ /** Total number of columns in the table, including any that are not rendered. */
42
74
  accessibleColCount?: number | null | undefined;
75
+ /** One-based column position of the cell within its table. */
43
76
  accessibleColIndex?: number | null | undefined;
77
+ /** Wording announced in place of the numeric column position. */
44
78
  accessibleColIndexText?: string | null | undefined;
79
+ /** Number of columns the cell spans. */
45
80
  accessibleColSpan?: number | null | undefined;
81
+ /** Widgets whose content or presence this widget controls. */
46
82
  accessibleControls?: Gtk.Widget[] | null | undefined;
83
+ /** Widgets that describe this one. */
47
84
  accessibleDescribedBy?: Gtk.Widget[] | null | undefined;
85
+ /** Widgets holding extended detail about this one. */
48
86
  accessibleDetails?: Gtk.Widget[] | null | undefined;
87
+ /** Widgets holding the message that explains why the value is invalid. */
49
88
  accessibleErrorMessage?: Gtk.Widget[] | null | undefined;
89
+ /** Widgets to read next, overriding the default reading order. */
50
90
  accessibleFlowTo?: Gtk.Widget[] | null | undefined;
91
+ /** Widgets that label this one. */
51
92
  accessibleLabelledBy?: Gtk.Widget[] | null | undefined;
93
+ /** Widgets this one owns that the widget hierarchy does not already imply. */
52
94
  accessibleOwns?: Gtk.Widget[] | null | undefined;
95
+ /** One-based position of the widget within its set. */
53
96
  accessiblePosInSet?: number | null | undefined;
97
+ /** Total number of rows in the table, including any that are not rendered. */
54
98
  accessibleRowCount?: number | null | undefined;
99
+ /** One-based row position of the cell within its table. */
55
100
  accessibleRowIndex?: number | null | undefined;
101
+ /** Wording announced in place of the numeric row position. */
56
102
  accessibleRowIndexText?: string | null | undefined;
103
+ /** Number of rows the cell spans. */
57
104
  accessibleRowSpan?: number | null | undefined;
105
+ /** Total number of items in the set the widget belongs to. */
58
106
  accessibleSetSize?: number | null | undefined;
59
107
  };
60
108
 
@@ -9,12 +9,6 @@ type RefProp<T extends object> = T | RefObject<T | null> | null | undefined;
9
9
  const isRefObject = <T extends object>(value: T | RefObject<T | null>): value is RefObject<T | null> =>
10
10
  typeof value === "object" && "current" in value;
11
11
 
12
- /**
13
- * Resolves a {@link RefProp} to the concrete object it points at, or null when it is absent or unresolved.
14
- *
15
- * @param prop The target object, a ref to one, or null/undefined.
16
- * @returns The resolved object, or null.
17
- */
18
12
  const resolveRefProp = <T extends object>(prop: RefProp<T>): T | null => {
19
13
  if (prop === null || prop === undefined) {
20
14
  return null;
@@ -1,13 +1,19 @@
1
1
  import type * as Gio from "@gtkx/gi/gio";
2
2
  import { packVariant, parseVariantType, unpackVariant, type VariantValue } from "./variant.js";
3
3
 
4
+ /** Maps each key of a GSettings schema to its kind: a GVariant type string, or `enum` or `flags`. */
4
5
  type SettingsSchemaKeys = Record<string, string>;
5
6
  type SettingKindValue<S extends string> = S extends "enum" | "flags" ? number : VariantValue<S>;
7
+ /** The JavaScript type key `P` holds: `number` for `enum` and `flags`, otherwise the unpacked GVariant. */
6
8
  type SettingValue<K extends SettingsSchemaKeys, P extends keyof K> = SettingKindValue<K[P] & string>;
7
9
 
10
+ /** A GSettings schema, as described by the modules GTKX generates from a project's `.gschema.xml` files. */
8
11
  type SettingsSchema<K extends SettingsSchemaKeys = SettingsSchemaKeys> = {
12
+ /** Schema id it is looked up by, such as `org.gtkx.Example`. */
9
13
  id: string;
14
+ /** Path a relocatable schema is instantiated at, or `null` to use the schema's own path. */
10
15
  path: string | null;
16
+ /** Kind of every key the schema declares, which types reads and writes of that key. */
11
17
  keys: K;
12
18
  };
13
19