instant_record 0.1.0 → 0.3.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 (198) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +58 -0
  3. data/README.md +267 -61
  4. data/app/controllers/instant_record/bootstraps_controller.rb +39 -12
  5. data/app/controllers/instant_record/events_controller.rb +58 -6
  6. data/app/controllers/instant_record/files_controller.rb +116 -0
  7. data/app/controllers/instant_record/mutations_controller.rb +84 -5
  8. data/app/controllers/instant_record/native_screens_controller.rb +60 -0
  9. data/app/controllers/instant_record/records_controller.rb +86 -8
  10. data/app/controllers/instant_record/shells_controller.rb +64 -0
  11. data/app/controllers/instant_record/sync_notices_controller.rb +81 -0
  12. data/app/helpers/instant_record/sync_notices_helper.rb +41 -0
  13. data/app/jobs/instant_record/shell_build_job.rb +16 -0
  14. data/app/models/instant_record/change.rb +36 -3
  15. data/app/models/instant_record/mutation_applier.rb +633 -50
  16. data/app/views/instant_record/sync_notices/_notices.html.erb +63 -0
  17. data/compiled/README.md +272 -0
  18. data/compiled/pipeline/browser_migrations.rb +18 -0
  19. data/compiled/pipeline/build.rb +13 -0
  20. data/compiled/pipeline/build_native.rb +14 -0
  21. data/compiled/pipeline/native/host.c +78 -0
  22. data/compiled/pipeline/native/instant_record_native.h +57 -0
  23. data/compiled/pipeline/native_shim.c +149 -0
  24. data/compiled/pipeline/reactor_shim.c +66 -0
  25. data/compiled/pipeline/sqlite/rh_shim.c +5 -0
  26. data/compiled/pipeline/sqlite_release.rb +43 -0
  27. data/compiled/toolchain.env.example +22 -0
  28. data/compiled/web/index.html +20 -0
  29. data/compiled/web/package-lock.json +884 -0
  30. data/compiled/web/package.json +17 -0
  31. data/compiled/web/src/app-host-core.js +556 -0
  32. data/compiled/web/src/app-host.js +16 -0
  33. data/compiled/web/src/branch-manager.js +140 -0
  34. data/compiled/web/src/branch-preview.js +397 -0
  35. data/compiled/web/src/changes.js +191 -0
  36. data/compiled/web/src/faults.js +172 -0
  37. data/compiled/web/src/flight-recorder.js +347 -0
  38. data/compiled/web/src/history-fill.js +68 -0
  39. data/compiled/web/src/http-headers.js +100 -0
  40. data/compiled/web/src/leader-election.js +705 -0
  41. data/compiled/web/src/main.js +608 -0
  42. data/compiled/web/src/manifest.js +112 -0
  43. data/compiled/web/src/opfs-wasi-core.js +109 -0
  44. data/compiled/web/src/opfs-wasi-file.js +8 -0
  45. data/compiled/web/src/reactor-runtime.js +1692 -0
  46. data/compiled/web/src/redactor.js +518 -0
  47. data/compiled/web/src/release-updates.js +48 -0
  48. data/compiled/web/src/replay.js +338 -0
  49. data/compiled/web/src/schema-recovery.js +204 -0
  50. data/compiled/web/src/server-request.js +68 -0
  51. data/compiled/web/src/sha256.js +98 -0
  52. data/compiled/web/src/shell.js +52 -0
  53. data/compiled/web/src/snapshot-store.js +38 -0
  54. data/compiled/web/src/sqlite-redactor.js +111 -0
  55. data/compiled/web/src/storage-backend.js +159 -0
  56. data/compiled/web/src/stream-leader.js +675 -0
  57. data/compiled/web/src/sync-context.js +91 -0
  58. data/compiled/web/src/sync-drain.js +104 -0
  59. data/compiled/web/src/sync-schedule.js +9 -0
  60. data/compiled/web/src/wasi-minimal.js +275 -0
  61. data/compiled/web/src/worker.js +39 -0
  62. data/compiled/web/vite.config.js +27 -0
  63. data/config/routes.rb +25 -0
  64. data/db/migrate/20261119000201_add_scope_to_instant_record_changes.rb +7 -0
  65. data/db/migrate/20261121000001_create_instant_record_sync_notices.rb +21 -0
  66. data/db/migrate/20261121000101_add_partition_to_instant_record_changes.rb +8 -0
  67. data/db/migrate/20261121230300_add_delay_line_to_instant_record_outbox.rb +10 -0
  68. data/exe/instant_record_mcp +6 -0
  69. data/frontend/LiveList.js +67 -0
  70. data/frontend/chord.js +79 -0
  71. data/frontend/file.js +65 -0
  72. data/frontend/files.js +738 -0
  73. data/frontend/focus.js +10 -0
  74. data/frontend/held.js +192 -0
  75. data/frontend/http.js +76 -0
  76. data/frontend/index.js +53 -0
  77. data/frontend/keyboard.js +56 -0
  78. data/frontend/live.js +298 -0
  79. data/frontend/notices.js +118 -0
  80. data/frontend/package.json +15 -0
  81. data/frontend/range.js +10 -0
  82. data/frontend/selection.js +47 -0
  83. data/frontend/shortcuts.js +25 -0
  84. data/frontend/sync-notices.js +130 -0
  85. data/frontend/undo.js +48 -0
  86. data/frontend/window.js +181 -0
  87. data/lib/generators/instant_record/install/install_generator.rb +18 -30
  88. data/lib/generators/instant_record/install/templates/instant_record.rb +34 -0
  89. data/lib/generators/instant_record/ios/ios_generator.rb +71 -0
  90. data/lib/generators/instant_record/ios/templates/App.swift.tt +35 -0
  91. data/lib/generators/instant_record/ios/templates/Info.plist +11 -0
  92. data/lib/generators/instant_record/ios/templates/LibraryEngine.swift +30 -0
  93. data/lib/instant_record/branch/sqlite_store.rb +142 -0
  94. data/lib/instant_record/branch.rb +388 -0
  95. data/lib/instant_record/client/notifier.rb +8 -12
  96. data/lib/instant_record/client/rebaser.rb +565 -0
  97. data/lib/instant_record/client/transport.rb +64 -42
  98. data/lib/instant_record/client.rb +1600 -169
  99. data/lib/instant_record/compiled_site.rb +85 -0
  100. data/lib/instant_record/compiler/app_stage.rb +212 -0
  101. data/lib/instant_record/compiler/ast_lowerer.rb +659 -0
  102. data/lib/instant_record/compiler/browser_migrations.rb +161 -0
  103. data/lib/instant_record/compiler/entry_builder.rb +832 -0
  104. data/lib/instant_record/compiler/fts5_smoke.rb +205 -0
  105. data/lib/instant_record/compiler/gem_vendor.rb +194 -0
  106. data/lib/instant_record/compiler/host_adapters.rb +506 -0
  107. data/lib/instant_record/compiler/kotlin_codegen.rb +209 -0
  108. data/lib/instant_record/compiler/manifest.rb +178 -0
  109. data/lib/instant_record/compiler/native_build.rb +586 -0
  110. data/lib/instant_record/compiler/native_contracts.rb +338 -0
  111. data/lib/instant_record/compiler/path_scrubber.rb +31 -0
  112. data/lib/instant_record/compiler/reachability_tracer.rb +1188 -0
  113. data/lib/instant_record/compiler/route_analyzer.rb +623 -0
  114. data/lib/instant_record/compiler/runner.rb +42 -0
  115. data/lib/instant_record/compiler/schema_lock.rb +606 -0
  116. data/lib/instant_record/compiler/source_pages.rb +77 -0
  117. data/lib/instant_record/compiler/static_linter.rb +770 -0
  118. data/lib/instant_record/compiler/swift_codegen.rb +341 -0
  119. data/lib/instant_record/compiler/toolchain.rb +219 -0
  120. data/lib/instant_record/compiler/wasm_build.rb +704 -0
  121. data/lib/instant_record/compiler/wasm_tree.rb +518 -0
  122. data/lib/instant_record/compiler.rb +277 -0
  123. data/lib/instant_record/configuration.rb +104 -0
  124. data/lib/instant_record/engine.rb +68 -18
  125. data/lib/instant_record/file_store.rb +162 -0
  126. data/lib/instant_record/files.rb +92 -0
  127. data/lib/instant_record/hlc.rb +387 -0
  128. data/lib/instant_record/host.rb +66 -0
  129. data/lib/instant_record/inertia/renderer.rb +52 -0
  130. data/lib/instant_record/inertia.rb +222 -0
  131. data/lib/instant_record/mcp/cli.rb +319 -0
  132. data/lib/instant_record/mcp/host_process.rb +229 -0
  133. data/lib/instant_record/mcp/http_exchange.rb +233 -0
  134. data/lib/instant_record/mcp/replica.rb +556 -0
  135. data/lib/instant_record/mcp/runtime.rb +406 -0
  136. data/lib/instant_record/mcp/server.rb +429 -0
  137. data/lib/instant_record/mcp.rb +47 -0
  138. data/lib/instant_record/native/contract.rb +367 -0
  139. data/lib/instant_record/native/node.rb +125 -0
  140. data/lib/instant_record/native/screen.rb +366 -0
  141. data/lib/instant_record/native/xcode_project.rb +344 -0
  142. data/lib/instant_record/native.rb +41 -0
  143. data/lib/instant_record/outbox_mutation.rb +81 -9
  144. data/lib/instant_record/outbox_upcaster.rb +161 -0
  145. data/lib/instant_record/read_tracker.rb +610 -0
  146. data/lib/instant_record/routing.rb +33 -0
  147. data/lib/instant_record/runtime_scoped.rb +4 -0
  148. data/lib/instant_record/shell.rb +486 -0
  149. data/lib/instant_record/sync_actions.rb +800 -0
  150. data/lib/instant_record/sync_metadata.rb +17 -2
  151. data/lib/instant_record/sync_notice.rb +234 -0
  152. data/lib/instant_record/sync_partition.rb +63 -0
  153. data/lib/instant_record/sync_scope.rb +300 -0
  154. data/lib/instant_record/sync_shape.rb +102 -0
  155. data/lib/instant_record/sync_window.rb +92 -15
  156. data/lib/instant_record/syncable.rb +313 -17
  157. data/lib/instant_record/testing/authoritative_server.rb +547 -0
  158. data/lib/instant_record/testing/chaos_simulator.rb +429 -0
  159. data/lib/instant_record/testing/cruby_host_bridge.rb +370 -0
  160. data/lib/instant_record/testing/fault_network.rb +140 -0
  161. data/lib/instant_record/testing/parity_suite.rb +435 -0
  162. data/lib/instant_record/testing/runtimes/base.rb +184 -0
  163. data/lib/instant_record/testing/runtimes/cruby_runtime.rb +255 -0
  164. data/lib/instant_record/testing/runtimes/native_runtime.rb +346 -0
  165. data/lib/instant_record/testing/runtimes/wasm_runtime.rb +371 -0
  166. data/lib/instant_record/testing/wasm_host_bridge.mjs +240 -0
  167. data/lib/instant_record/testing.rb +333 -0
  168. data/lib/instant_record/trace/redactor.rb +278 -0
  169. data/lib/instant_record/trace/replayer.rb +126 -0
  170. data/lib/instant_record/trace/schema_extractor.rb +37 -0
  171. data/lib/instant_record/trace.rb +22 -0
  172. data/lib/instant_record/version.rb +1 -1
  173. data/lib/instant_record.rb +107 -37
  174. data/lib/tasks/instant_record.rake +299 -47
  175. data/native/ios/InstantRecordNative/Package.swift +12 -0
  176. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/AppHost.swift +706 -0
  177. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Engine.swift +64 -0
  178. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/FileStore.swift +1048 -0
  179. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/HTTPEngine.swift +36 -0
  180. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Icons.swift +19 -0
  181. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Node.swift +64 -0
  182. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/ScreenView.swift +481 -0
  183. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Screens.swift +94 -0
  184. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/StreamClient.swift +74 -0
  185. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/SyncNotice.swift +282 -0
  186. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/SyncSchedule.swift +153 -0
  187. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Theme.swift +140 -0
  188. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/Transport.swift +108 -0
  189. data/native/ios/InstantRecordNative/Sources/InstantRecordNative/TypedContracts.swift +237 -0
  190. data/native/ios/README.md +341 -0
  191. data/sig/instant_record/inertia.rbs +47 -0
  192. data/sig/instant_record/native.rbs +38 -0
  193. metadata +194 -18
  194. data/lib/generators/instant_record/install/templates/database.js +0 -32
  195. data/lib/generators/instant_record/install/templates/index.html +0 -69
  196. data/lib/generators/instant_record/install/templates/rails.sw.js +0 -750
  197. data/lib/instant_record/local_schema.rb +0 -75
  198. data/lib/instant_record/pglite_compat.rb +0 -40
@@ -0,0 +1,366 @@
1
+ module InstantRecord
2
+ module Native
3
+ # A screen of a native app, written in Ruby.
4
+ #
5
+ # class MailboxScreen < InstantRecord::Native::Screen
6
+ # def body
7
+ # navigation title: "Support" do
8
+ # list do
9
+ # MailEntry.open_messages.each do |entry|
10
+ # row id: entry.id, link: "thread", params: { "id" => entry.id } do
11
+ # text entry.author, style: "headline"
12
+ # text entry.subject, lines: 1
13
+ # swipe "Archive", action: "archive", args: { "id" => entry.id }, role: "destructive"
14
+ # end
15
+ # end
16
+ # end
17
+ # end
18
+ # end
19
+ #
20
+ # def perform(action, args, values)
21
+ # case action
22
+ # when "archive" then archive(args["id"])
23
+ # end
24
+ # end
25
+ # end
26
+ #
27
+ # `body` describes the screen with the words iOS draws. The app's renderer
28
+ # turns the description into native views and knows nothing else about the
29
+ # app. A tap comes back as `perform` with the action and `args` the
30
+ # element named, together with what was typed into the screen's fields
31
+ # (`values`), and the screen is rendered again afterwards. A screen that
32
+ # was just opened over another is told so: `perform("open", {}, {})`.
33
+ #
34
+ # A screen, or one part of it, can instead be a view the app wrote in
35
+ # SwiftUI. `swift` names the view and hands it props, as a Rails action
36
+ # hands a React page its props with `render inertia: "Email/Index",
37
+ # props: { ... }`:
38
+ #
39
+ # def body
40
+ # swift "ConversationView" do
41
+ # prop "subject", message.subject
42
+ # props "messages" do
43
+ # replies.each do |reply|
44
+ # record do
45
+ # prop "author", reply.author
46
+ # prop "body", reply.body
47
+ # end
48
+ # end
49
+ # end
50
+ # end
51
+ # end
52
+ #
53
+ # The app registers the view under that name and reads `props["subject"]`
54
+ # and `props.list("messages")`. `flag`, `number` and `time` hand it a
55
+ # boolean, a whole number and a moment. What the view does comes back through
56
+ # `perform`, like any tap. Used inside a list or a stack, `swift` puts one
57
+ # hand-written view among the stock ones, as a partial would.
58
+ #
59
+ # Keep to plain Ruby here: blocks, `yield` and `case`. The phone runs this
60
+ # file through an ahead-of-time compiler with no `method_missing`, no
61
+ # `instance_eval` and no `send` to a computed name.
62
+ class Screen
63
+ # `params` are what the screen was opened with, strings by name. Every
64
+ # hash a screen gives to `params:` or `args:` holds strings too: write
65
+ # `entry.id.to_s` for a value that comes from a record, since the
66
+ # phone's compiler types a hash by what it holds and refuses another.
67
+ def initialize(params = Node.strings)
68
+ open_with(params)
69
+ @open = []
70
+ end
71
+
72
+ # Keeps the params. A method of its own because the phone's compilers
73
+ # take a type for it from sig/instant_record/native.rbs, which they do
74
+ # not for `initialize`.
75
+ def open_with(params)
76
+ @given = params
77
+ end
78
+
79
+ # What a host sent as a JSON object, as strings by name. Anything that
80
+ # is not an object gives an empty hash.
81
+ def self.strings(parsed)
82
+ out = Node.strings
83
+ parsed.each { |name, value| out[name.to_s] = value.to_s } if parsed.is_a?(Hash)
84
+ out
85
+ end
86
+
87
+ # One of the params, or "" when the screen was opened without it.
88
+ def param(name)
89
+ @given.fetch(name, "").to_s
90
+ end
91
+
92
+ def body
93
+ end
94
+
95
+ # A tap. `args` are what the tapped element was given, and `values` are
96
+ # what a form's fields held, both strings by name.
97
+ def perform(action, args, values)
98
+ end
99
+
100
+ def render
101
+ root = Node.new("screen")
102
+ @open = [root]
103
+ body
104
+ root
105
+ end
106
+
107
+ def json
108
+ render.json
109
+ end
110
+
111
+ # A navigation bar with a title over whatever the block holds.
112
+ def navigation(title: "")
113
+ node = add("navigation")
114
+ node.set("title", title)
115
+ inside(node) { yield }
116
+ end
117
+
118
+ # `refreshable: true` lets a pull on the list sync and draw it again.
119
+ def list(refreshable: false)
120
+ node = add("list")
121
+ node.set("refresh", "true") if refreshable
122
+ inside(node) { yield } if block_given?
123
+ node
124
+ end
125
+
126
+ def section(title = "")
127
+ node = add("section")
128
+ node.text = title
129
+ inside(node) { yield }
130
+ end
131
+
132
+ # One line of a list. `id` is the record it shows, which is how the list
133
+ # keeps its place when it is drawn again. `link` names the screen a tap
134
+ # opens over this one and `params` are handed to that screen, which
135
+ # hears of it as `perform("open", ...)`.
136
+ def row(id: "", link: "", params: Node.strings)
137
+ node = add("row")
138
+ node.id = id
139
+ node.link_params = params
140
+ node.set("link", link)
141
+ inside(node) { yield }
142
+ end
143
+
144
+ # Elements side by side ("horizontal") or one under another ("vertical").
145
+ def stack(axis = "vertical")
146
+ node = add("stack")
147
+ node.set("axis", axis)
148
+ inside(node) { yield }
149
+ end
150
+
151
+ # Empty room in a stack: what follows it sits at the far edge.
152
+ def spacer
153
+ add("spacer")
154
+ end
155
+
156
+ # `style` is one of the system's text styles: "headline", "body",
157
+ # "subheadline", "caption", "title". `tone` is "secondary" for quieter
158
+ # text. `lines` is the most lines it may take, or 0 for as many as it
159
+ # needs.
160
+ def text(value, style: "", tone: "", lines: 0)
161
+ node = add("text")
162
+ node.text = value
163
+ node.set("style", style)
164
+ node.set("tone", tone)
165
+ node.set("lines", lines.to_s) if lines > 0
166
+ node
167
+ end
168
+
169
+ # A moment, as ISO 8601. The phone writes it out in its own language and
170
+ # time zone. `style` and `tone` are as for text.
171
+ def date(iso8601, style: "", tone: "")
172
+ node = add("date")
173
+ node.text = iso8601
174
+ node.set("style", style)
175
+ node.set("tone", tone)
176
+ node
177
+ end
178
+
179
+ # An icon by what it means: "person", "filter", "archive", "inbox",
180
+ # "unread", "read", "send", "compose". The renderer picks the platform's
181
+ # symbol for it and says its name aloud. A name it does not know is
182
+ # used as the platform's own, such as "envelope.badge".
183
+ def image(name, tone: "")
184
+ node = add("image")
185
+ node.text = name
186
+ node.set("tone", tone)
187
+ node
188
+ end
189
+
190
+ # In a toolbar, `position` is "leading" or "trailing". A button given a
191
+ # block is a menu, and the block holds its items.
192
+ def button(label, action: "", args: Node.strings, role: "", image: "", position: "")
193
+ node = add("button")
194
+ act(node, label, action, args, role)
195
+ node.set("image", image)
196
+ node.set("position", position)
197
+ inside(node) { yield } if block_given?
198
+ node
199
+ end
200
+
201
+ # One line of a menu. With an `action` it is performed like a button's.
202
+ # With a `link` it opens that screen with `params` over this one, as a
203
+ # row does. With `replace` the screen it names takes the place of the
204
+ # first screen, as choosing another account does. With `sheet` the screen
205
+ # it names comes up over this one and is dismissed, not gone back from.
206
+ # `selected` gives it a tick.
207
+ def item(title, action: "", args: Node.strings, link: "", replace: "", sheet: "", params: Node.strings, image: "", role: "", selected: false)
208
+ places = 0
209
+ places += 1 if link.length > 0
210
+ places += 1 if replace.length > 0
211
+ places += 1 if sheet.length > 0
212
+ raise ArgumentError, "Give a menu item one of link:, replace: or sheet:" if places > 1
213
+ node = add("item")
214
+ act(node, title, action, args, role)
215
+ node.link_params = params
216
+ node.set("link", link)
217
+ node.set("replace", replace)
218
+ node.set("sheet", sheet)
219
+ node.set("image", image)
220
+ node.set("selected", "true") if selected
221
+ node
222
+ end
223
+
224
+ # A swipe on the row that holds it. `edge` is "trailing" or "leading".
225
+ def swipe(label, action:, args: Node.strings, role: "", edge: "", image: "")
226
+ node = add("swipe")
227
+ act(node, label, action, args, role)
228
+ node.set("edge", edge)
229
+ node.set("image", image)
230
+ node
231
+ end
232
+
233
+ # A view written in SwiftUI (or Compose), by the name the app registered
234
+ # it under. The block hands it typed props.
235
+ def swift(name)
236
+ node = add("swift")
237
+ node.text = name
238
+ inside(node) { yield } if block_given?
239
+ node
240
+ end
241
+
242
+ # Platform-neutral alias for `swift`: hands typed props to a registered
243
+ # native component.
244
+ def component(name)
245
+ node = add("swift")
246
+ node.text = name
247
+ inside(node) { yield } if block_given?
248
+ node
249
+ end
250
+
251
+ # A string for the native view, by name: `props["subject"]` in Swift.
252
+ # Passing nil omits the prop (matching an optional field in a contract).
253
+ def prop(name, value)
254
+ return nil if value.nil?
255
+ typed(name, "string", value.to_s)
256
+ end
257
+
258
+ # A yes or no for the native view: `props.bool("archived")`.
259
+ def flag(name, value)
260
+ return nil if value.nil?
261
+ typed(name, "bool", value ? "true" : "false")
262
+ end
263
+
264
+ # A whole number for the native view: `props.int("unread")`.
265
+ def number(name, value)
266
+ return nil if value.nil?
267
+ typed(name, "int", value.to_s)
268
+ end
269
+
270
+ # A floating-point number for the native view: `props.double("score")`.
271
+ def decimal(name, value)
272
+ return nil if value.nil?
273
+ typed(name, "float", value.to_s)
274
+ end
275
+
276
+ # A moment for the native view, as ISO 8601: `props.date("sent")`.
277
+ def time(name, iso8601)
278
+ return nil if iso8601.nil?
279
+ typed(name, "date", iso8601.to_s)
280
+ end
281
+
282
+ # A list for the native view, by name. The block holds its records or
283
+ # unnamed scalar items (`prop "", value`).
284
+ def props(name)
285
+ node = add("props")
286
+ node.set("name", name)
287
+ inside(node) { yield }
288
+ end
289
+
290
+ # One entry of a list (`record { ... }`), or a named nested object
291
+ # (`record("sender") { ... }`): the block holds its props.
292
+ def record(name = "")
293
+ node = add("record")
294
+ node.set("name", name)
295
+ inside(node) { yield }
296
+ end
297
+
298
+ # Controls in the navigation bar: buttons, and buttons that open a menu.
299
+ def toolbar
300
+ inside(add("toolbar")) { yield }
301
+ end
302
+
303
+ # A bar pinned under the screen, above the keyboard: a reply box.
304
+ def bottom
305
+ inside(add("bottom")) { yield }
306
+ end
307
+
308
+ # A box to type in. `label` is what it shows while empty and what it is
309
+ # called aloud. What is typed stays on the phone until the next action
310
+ # from this screen, reaches `perform` in `values` under `name`, and the
311
+ # box is emptied once that action has been performed. A button beside a
312
+ # field cannot be pressed while every field of the screen is blank.
313
+ def field(name, label: "", value: "", multiline: false)
314
+ node = add("field")
315
+ node.text = value
316
+ node.set("name", name)
317
+ node.set("label", label)
318
+ node.set("multiline", "true") if multiline
319
+ node
320
+ end
321
+
322
+ # The list goes on at the server. When this comes into view the app
323
+ # asks the sync address for `records?<query>` and hands the answer to
324
+ # the library, which keeps the page and writes down whether more lies
325
+ # below it: `InstantRecord::SyncMetadata.get("history:" + key)` is
326
+ # "more" or "end", and nil before any page. The screen is then drawn
327
+ # again, and leaves this out once the answer is "end".
328
+ def more(key, query:)
329
+ node = add("more")
330
+ node.id = key
331
+ node.set("query", query)
332
+ node
333
+ end
334
+
335
+ private
336
+
337
+ def add(kind)
338
+ node = Node.new(kind)
339
+ @open.last.children << node
340
+ node
341
+ end
342
+
343
+ def inside(node)
344
+ @open << node
345
+ yield
346
+ @open.pop
347
+ node
348
+ end
349
+
350
+ def act(node, label, action, args, role)
351
+ node.text = label
352
+ node.action = action
353
+ node.args = args
354
+ node.set("role", role)
355
+ end
356
+
357
+ def typed(name, type, value)
358
+ node = add("prop")
359
+ node.set("name", name)
360
+ node.set("type", type)
361
+ node.text = value
362
+ node
363
+ end
364
+ end
365
+ end
366
+ end