one 2.13.10 → 2.14.1

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 (43) hide show
  1. package/android/src/main/java/dev/onejs/one/OneKotlinHostView.kt +53 -14
  2. package/android/src/main/java/dev/onejs/one/OneNativeSourceKeyedState.kt +23 -0
  3. package/android/src/main/java/dev/onejs/one/OneNativeSourceViewDispatch.kt +16 -3
  4. package/dist/cjs/platform/native-source/view.native.cjs +4 -4
  5. package/dist/cjs/platform/native-source/view.native.js +4 -4
  6. package/dist/cjs/platform/native-source/view.native.js.map +1 -1
  7. package/dist/cjs/platform/native-source/wire.native.cjs +152 -49
  8. package/dist/cjs/platform/native-source/wire.native.js +152 -49
  9. package/dist/cjs/platform/native-source/wire.native.js.map +1 -1
  10. package/dist/cjs/platform/native-source/wireProps.native.cjs +138 -0
  11. package/dist/cjs/platform/native-source/wireProps.native.js +140 -0
  12. package/dist/cjs/platform/native-source/wireProps.native.js.map +1 -0
  13. package/dist/cjs/platform/swift/index.native.cjs +12 -8
  14. package/dist/cjs/platform/swift/index.native.js +12 -8
  15. package/dist/cjs/platform/swift/index.native.js.map +1 -1
  16. package/dist/esm/platform/native-source/view.native.js +5 -5
  17. package/dist/esm/platform/native-source/view.native.js.map +1 -1
  18. package/dist/esm/platform/native-source/wire.native.js +149 -49
  19. package/dist/esm/platform/native-source/wire.native.js.map +1 -1
  20. package/dist/esm/platform/native-source/wireProps.native.js +113 -0
  21. package/dist/esm/platform/native-source/wireProps.native.js.map +1 -0
  22. package/dist/esm/platform/swift/index.native.js +13 -9
  23. package/dist/esm/platform/swift/index.native.js.map +1 -1
  24. package/ios/OneNativeComposition.swift +1 -0
  25. package/ios/OneNativeHostingController.swift +113 -0
  26. package/ios/OneSwiftHostComponentView.mm +28 -4
  27. package/ios/OneSwiftHostView.swift +63 -9
  28. package/ios/OneSwiftPackage.swift +6 -1
  29. package/package.json +13 -13
  30. package/src/platform/native-source/view.native.tsx +4 -5
  31. package/src/platform/native-source/wire.native.ts +108 -26
  32. package/src/platform/native-source/wireProps.native.test.ts +57 -0
  33. package/src/platform/native-source/wireProps.native.ts +124 -0
  34. package/src/platform/swift/index.native.tsx +9 -7
  35. package/src/platform/swift/types.ts +4 -2
  36. package/types/platform/native-source/view.native.d.ts.map +1 -1
  37. package/types/platform/native-source/wire.native.d.ts +3 -0
  38. package/types/platform/native-source/wire.native.d.ts.map +1 -1
  39. package/types/platform/native-source/wireProps.native.d.ts +15 -0
  40. package/types/platform/native-source/wireProps.native.d.ts.map +1 -0
  41. package/types/platform/swift/index.native.d.ts.map +1 -1
  42. package/types/platform/swift/types.d.ts +4 -1
  43. package/types/platform/swift/types.d.ts.map +1 -1
@@ -14,6 +14,14 @@ import com.facebook.react.uimanager.UIManagerHelper
14
14
  import com.facebook.react.views.view.ReactViewGroup
15
15
 
16
16
  class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
17
+ companion object {
18
+ // matches RESYNC_EVENT in wireProps.native: emitted when a change
19
+ // document cannot apply, answered by a full document
20
+ const val RESYNC_EVENT = "\$resync"
21
+ }
22
+
23
+ private val keyedState = OneNativeSourceKeyedState()
24
+
17
25
  private val composeView =
18
26
  ComposeView(context).apply {
19
27
  layoutParams =
@@ -32,7 +40,8 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
32
40
  private var committedSource by mutableStateOf("")
33
41
  private var committedView by mutableStateOf("")
34
42
  private var committedContractHash by mutableStateOf("")
35
- private var committedProps by mutableStateOf("{}")
43
+ private var committedPropsText = "{}"
44
+ private var resyncPending = false
36
45
 
37
46
  private val contentLayout = Runnable { layoutComposeContent() }
38
47
 
@@ -46,23 +55,19 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
46
55
  clipChildren = false
47
56
  addView(composeView)
48
57
  composeView.setContent {
58
+ // the props were merged into the keyed state at commit;
59
+ // composition only renders. Content reads the state's revision
60
+ // itself, so every apply resubscribes the rendering scope.
49
61
  val source = committedSource
50
62
  val view = committedView
51
- val hash = committedContractHash
52
- val props = committedProps
53
63
 
54
64
  if (source.isNotEmpty() && view.isNotEmpty()) {
55
65
  val dispatch = OneNativeSourceViewRegistry.get(source)
56
- if (dispatch.contractHash != hash) {
57
- error(
58
- "native view $source.$view changed (contract hash mismatch: expected $hash, got ${dispatch.contractHash}); rebuild the app"
59
- )
60
- }
61
66
  Layout(
62
67
  content = {
63
68
  dispatch.Content(
64
69
  view = view,
65
- propsJson = props,
70
+ state = keyedState,
66
71
  emit = { eventName, eventArgs ->
67
72
  onHostEvent(source, view, eventName, eventArgs)
68
73
  },
@@ -123,12 +128,30 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
123
128
  observedWidth = -1
124
129
  observedHeight = -1
125
130
  }
131
+ if (sourceOrViewChanged || nextHash != committedContractHash) {
132
+ keyedState.reset()
133
+ }
126
134
 
127
- if (sourceOrViewChanged || nextHash != committedContractHash || nextProps != committedProps) {
135
+ if (sourceOrViewChanged || nextHash != committedContractHash || nextProps != committedPropsText) {
136
+ if (nextSource.isNotEmpty() && nextView.isNotEmpty()) {
137
+ val dispatch = OneNativeSourceViewRegistry.get(nextSource)
138
+ if (dispatch.contractHash != nextHash) {
139
+ error(
140
+ "native view $nextSource.$nextView changed (contract hash mismatch: expected $nextHash, got ${dispatch.contractHash}); rebuild the app"
141
+ )
142
+ }
143
+ // decode and merge at commit, whether or not the composition
144
+ // is attached: a refused change asks for a resync instead of
145
+ // committing anything.
146
+ if (!dispatch.apply(nextView, nextProps, keyedState)) {
147
+ emitKeyedResync()
148
+ return
149
+ }
150
+ }
128
151
  committedSource = nextSource
129
152
  committedView = nextView
130
153
  committedContractHash = nextHash
131
- committedProps = nextProps
154
+ committedPropsText = nextProps
132
155
  requestLayout()
133
156
  }
134
157
  }
@@ -144,8 +167,20 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
144
167
  private fun onHostEvent(eventSource: String, eventView: String, name: String, args: String) {
145
168
  // discard events from a detached or replaced source/view
146
169
  if (!isAttachedToWindow || eventSource != committedSource || eventView != committedView) return
147
- val reactContext = UIManagerHelper.getReactContext(this) ?: return
148
- val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id) ?: return
170
+ dispatchHostEvent(name, args)
171
+ }
172
+
173
+ // asks javascript for a full document after refusing a change document.
174
+ // runs during the prop commit (never composition), so it cannot compare
175
+ // against committed props the way view events do. commits also run while
176
+ // detached, so a resync the dispatcher cannot take yet waits for attach.
177
+ private fun emitKeyedResync() {
178
+ if (!dispatchHostEvent(RESYNC_EVENT, "[]")) resyncPending = true
179
+ }
180
+
181
+ private fun dispatchHostEvent(name: String, args: String): Boolean {
182
+ val reactContext = UIManagerHelper.getReactContext(this) ?: return false
183
+ val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, id) ?: return false
149
184
  dispatcher.dispatchEvent(
150
185
  OneKotlinHostEvent(
151
186
  surfaceId = UIManagerHelper.getSurfaceId(this),
@@ -154,6 +189,7 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
154
189
  args = args,
155
190
  )
156
191
  )
192
+ return true
157
193
  }
158
194
 
159
195
  private fun onContentSizeChanged(
@@ -189,6 +225,7 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
189
225
 
190
226
  override fun onAttachedToWindow() {
191
227
  super.onAttachedToWindow()
228
+ if (resyncPending && dispatchHostEvent(RESYNC_EVENT, "[]")) resyncPending = false
192
229
  post(contentLayout)
193
230
  }
194
231
 
@@ -248,6 +285,8 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
248
285
 
249
286
  internal fun resetForReuse() {
250
287
  removeCallbacks(contentLayout)
288
+ keyedState.reset()
289
+ resyncPending = false
251
290
  reportedWidth = -1.0
252
291
  reportedHeight = -1.0
253
292
  observedWidth = -1
@@ -255,7 +294,7 @@ class OneKotlinHostView(context: Context) : ReactViewGroup(context) {
255
294
  committedSource = ""
256
295
  committedView = ""
257
296
  committedContractHash = ""
258
- committedProps = "{}"
297
+ committedPropsText = "{}"
259
298
  stagedSource = null
260
299
  stagedView = null
261
300
  stagedContractHash = null
@@ -0,0 +1,23 @@
1
+ package dev.onejs.one
2
+
3
+ import androidx.compose.runtime.getValue
4
+ import androidx.compose.runtime.mutableIntStateOf
5
+ import androidx.compose.runtime.setValue
6
+
7
+ // held keyed-props state for one host view instance. the host owns the
8
+ // lifetime (reset on source/view/contract change and on recycle) while the
9
+ // generated glue owns the contents: the last applied seq, one untyped holder
10
+ // per view (each read back only by the glue that created it), and the
11
+ // applied-commit revision the glue bumps and Content reads so composition
12
+ // resubscribes on every apply. touched from the ui thread (host commits)
13
+ // and composition (glue reads) only.
14
+ class OneNativeSourceKeyedState {
15
+ var seq: Int = -1
16
+ val views = mutableMapOf<String, Any?>()
17
+ var revision by mutableIntStateOf(0)
18
+
19
+ fun reset() {
20
+ seq = -1
21
+ views.clear()
22
+ }
23
+ }
@@ -2,12 +2,25 @@ package dev.onejs.one
2
2
 
3
3
  import androidx.compose.runtime.Composable
4
4
 
5
- // generated per .kt source that declares public @Composable functions: renders
6
- // one of them from the host's json props. a callback reports its arguments
5
+ // generated per .kt source that declares public @Composable functions. apply
6
+ // decodes one props document and merges it into the host-owned state on the
7
+ // ui thread at prop commit: full documents always apply, a change applies
8
+ // onto the held seq and refuses otherwise (the host answers $resync).
9
+ // Content only renders the held props; a callback reports its arguments
7
10
  // through emit as a json array.
8
11
  interface OneNativeSourceViewDispatch {
9
12
  val contractHash: String
10
13
 
14
+ fun apply(
15
+ view: String,
16
+ propsJson: String,
17
+ state: OneNativeSourceKeyedState,
18
+ ): Boolean
19
+
11
20
  @Composable
12
- fun Content(view: String, propsJson: String, emit: (String, String) -> Unit)
21
+ fun Content(
22
+ view: String,
23
+ state: OneNativeSourceKeyedState,
24
+ emit: (String, String) -> Unit,
25
+ )
13
26
  }
@@ -34,10 +34,11 @@ var import_react = require("react");
34
34
  var import_react_native = require("react-native");
35
35
  var import_OneKotlinHostNativeComponent = __toESM(require("../specs/OneKotlinHostNativeComponent.native.js"), 1);
36
36
  var import_wire = require("./wire.native.js");
37
+ var import_wireProps = require("./wireProps.native.js");
37
38
  function KotlinSourceView(param) {
38
39
  var { source, view, contractHash, props, wires } = param;
40
+ var keyed = (0, import_wireProps.useNativeSourceProps)(props, wires, view !== "");
39
41
  var [contentSize, setContentSize] = (0, import_react.useState)();
40
- var encoded = wires ? (0, import_wire.encodeNativeSourceProps)(props, wires.props, wires.structs) : props;
41
42
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, {
42
43
  style: props.style,
43
44
  collapsable: false,
@@ -48,10 +49,9 @@ function KotlinSourceView(param) {
48
49
  source,
49
50
  view,
50
51
  contractHash,
51
- props: JSON.stringify(encoded, function(_key, value) {
52
- return typeof value === "function" ? true : value;
53
- }),
52
+ props: keyed.text,
54
53
  onHostEvent: function onHostEvent(event) {
54
+ if (event.nativeEvent.name === import_wireProps.RESYNC_EVENT) return keyed.resync();
55
55
  var callback = props[event.nativeEvent.name];
56
56
  if (typeof callback === "function") {
57
57
  var _ref;
@@ -34,10 +34,11 @@ var import_react = require("react");
34
34
  var import_react_native = require("react-native");
35
35
  var import_OneKotlinHostNativeComponent = __toESM(require("../specs/OneKotlinHostNativeComponent.native.js"), 1);
36
36
  var import_wire = require("./wire.native.js");
37
+ var import_wireProps = require("./wireProps.native.js");
37
38
  function KotlinSourceView(param) {
38
39
  var { source, view, contractHash, props, wires } = param;
40
+ var keyed = (0, import_wireProps.useNativeSourceProps)(props, wires, view !== "");
39
41
  var [contentSize, setContentSize] = (0, import_react.useState)();
40
- var encoded = wires ? (0, import_wire.encodeNativeSourceProps)(props, wires.props, wires.structs) : props;
41
42
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, {
42
43
  style: props.style,
43
44
  collapsable: false,
@@ -48,10 +49,9 @@ function KotlinSourceView(param) {
48
49
  source,
49
50
  view,
50
51
  contractHash,
51
- props: JSON.stringify(encoded, function(_key, value) {
52
- return typeof value === "function" ? true : value;
53
- }),
52
+ props: keyed.text,
54
53
  onHostEvent: function onHostEvent(event) {
54
+ if (event.nativeEvent.name === import_wireProps.RESYNC_EVENT) return keyed.resync();
55
55
  var callback = props[event.nativeEvent.name];
56
56
  if (typeof callback === "function") {
57
57
  var _ref;
@@ -1 +1 @@
1
- {"version":3,"file":"view.native.js","names":[],"sources":["cjs/platform/native-source/view.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar view_native_exports = {};\n__export(view_native_exports, {\n KotlinSourceView: () => KotlinSourceView\n});\nmodule.exports = __toCommonJS(view_native_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_react = require(\"react\");\nvar import_react_native = require(\"react-native\");\nvar import_OneKotlinHostNativeComponent = __toESM(require(\"../specs/OneKotlinHostNativeComponent\"), 1);\nvar import_wire = require(\"./wire.native\");\nfunction KotlinSourceView(param) {\n var { source, view, contractHash, props, wires } = param;\n var [contentSize, setContentSize] = (0, import_react.useState)();\n var encoded = wires ? (0, import_wire.encodeNativeSourceProps)(props, wires.props, wires.structs) : props;\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, {\n style: props.style,\n collapsable: false,\n children: [\n /* yoga uses the natural child size while retaining parent flex and stretch. */\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {\n pointerEvents: \"none\",\n style: contentSize\n }),\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneKotlinHostNativeComponent.default, {\n source,\n view,\n contractHash,\n props: JSON.stringify(encoded, function(_key, value) {\n return typeof value === \"function\" ? true : value;\n }),\n onHostEvent: function onHostEvent(event) {\n var callback = props[event.nativeEvent.name];\n if (typeof callback === \"function\") {\n var _ref;\n var args = JSON.parse(event.nativeEvent.args);\n var argWires = wires === null || wires === void 0 ? void 0 : wires.callbacks[event.nativeEvent.name];\n callback(...argWires ? (0, import_wire.decodeNativeSourceCallback)(args, argWires, (_ref = wires === null || wires === void 0 ? void 0 : wires.structs) !== null && _ref !== void 0 ? _ref : {}, event.nativeEvent.name) : args);\n }\n },\n onHostSizeChange: function onHostSizeChange(event) {\n setContentSize({\n width: event.nativeEvent.width,\n height: event.nativeEvent.height\n });\n },\n style: import_react_native.StyleSheet.absoluteFill\n })\n ]\n });\n}\n//# sourceMappingURL=view.native.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;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5E,OAAO,MAAM;EACb,aAAa;EACb,UAAU,CAEQ,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oBAAoB,MAAM;GACpE,eAAe;GACf,OAAO;EACT,CAAC,GACe,iBAAC,GAAG,mBAAmB,IAAG,CAAE,oCAAoC,SAAS;GACvF;GACA;GACA;GACA,OAAO,KAAK,UAAU,SAAS,SAAS,MAAM,OAAO;IACnD,OAAO,OAAO,UAAU,aAAa,OAAO;GAC9C,CAAC;GACD,aAAa,SAAS,YAAY,OAAO;IACvC,IAAI,WAAW,MAAM,MAAM,YAAY;IACvC,IAAI,OAAO,aAAa,YAAY;KAClC,IAAI;KACJ,IAAI,OAAO,KAAK,MAAM,MAAM,YAAY,IAAI;KAC5C,IAAI,WAAW,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,UAAU,MAAM,YAAY;KAC/F,SAAS,GAAG,YAAY,GAAG,YAAY,2BAA0B,CAAE,MAAM,WAAW,OAAO,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,aAAa,QAAQ,SAAS,KAAK,IAAI,OAAO,CAAC,GAAG,MAAM,YAAY,IAAI,IAAI,IAAI;IACjO;GACF;GACA,kBAAkB,SAAS,iBAAiB,OAAO;IACjD,eAAe;KACb,OAAO,MAAM,YAAY;KACzB,QAAQ,MAAM,YAAY;IAC5B,CAAC;GACH;GACA,OAAO,oBAAoB,WAAW;EACxC,CAAC,CACH;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"view.native.js","names":[],"sources":["cjs/platform/native-source/view.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar view_native_exports = {};\n__export(view_native_exports, {\n KotlinSourceView: () => KotlinSourceView\n});\nmodule.exports = __toCommonJS(view_native_exports);\nvar import_jsx_runtime = require(\"react/jsx-runtime\");\nvar import_react = require(\"react\");\nvar import_react_native = require(\"react-native\");\nvar import_OneKotlinHostNativeComponent = __toESM(require(\"../specs/OneKotlinHostNativeComponent\"), 1);\nvar import_wire = require(\"./wire.native\");\nvar import_wireProps = require(\"./wireProps.native\");\nfunction KotlinSourceView(param) {\n var { source, view, contractHash, props, wires } = param;\n var keyed = (0, import_wireProps.useNativeSourceProps)(props, wires, view !== \"\");\n var [contentSize, setContentSize] = (0, import_react.useState)();\n return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, {\n style: props.style,\n collapsable: false,\n children: [\n /* yoga uses the natural child size while retaining parent flex and stretch. */\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, {\n pointerEvents: \"none\",\n style: contentSize\n }),\n /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_OneKotlinHostNativeComponent.default, {\n source,\n view,\n contractHash,\n props: keyed.text,\n onHostEvent: function onHostEvent(event) {\n if (event.nativeEvent.name === import_wireProps.RESYNC_EVENT) return keyed.resync();\n var callback = props[event.nativeEvent.name];\n if (typeof callback === \"function\") {\n var _ref;\n var args = JSON.parse(event.nativeEvent.args);\n var argWires = wires === null || wires === void 0 ? void 0 : wires.callbacks[event.nativeEvent.name];\n callback(...argWires ? (0, import_wire.decodeNativeSourceCallback)(args, argWires, (_ref = wires === null || wires === void 0 ? void 0 : wires.structs) !== null && _ref !== void 0 ? _ref : {}, event.nativeEvent.name) : args);\n }\n },\n onHostSizeChange: function onHostSizeChange(event) {\n setContentSize({\n width: event.nativeEvent.width,\n height: event.nativeEvent.height\n });\n },\n style: import_react_native.StyleSheet.absoluteFill\n })\n ]\n });\n}\n//# sourceMappingURL=view.native.js.map\n"],"mappings":";;;AACA,IAAI,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ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,IAAI,KAAK,IAAI,MAAM,UAAU,MAAM,YAAY;KAC/F,SAAS,GAAG,YAAY,GAAG,YAAY,2BAA0B,CAAE,MAAM,WAAW,OAAO,UAAU,QAAQ,UAAU,KAAK,IAAI,KAAK,IAAI,MAAM,aAAa,QAAQ,SAAS,KAAK,IAAI,OAAO,CAAC,GAAG,MAAM,YAAY,IAAI,IAAI,IAAI;IACjO;GACF;GACA,kBAAkB,SAAS,iBAAiB,OAAO;IACjD,eAAe;KACb,OAAO,MAAM,YAAY;KACzB,QAAQ,MAAM,YAAY;IAC5B,CAAC;GACH;GACA,OAAO,oBAAoB,WAAW;EACxC,CAAC,CACH;CACF,CAAC;AACH"}
@@ -27,7 +27,10 @@ __export(wire_native_exports, {
27
27
  decodeNativeSourceCallback: () => decodeNativeSourceCallback,
28
28
  decodeNativeSourceResult: () => decodeNativeSourceResult,
29
29
  encodeNativeSourceArgs: () => encodeNativeSourceArgs,
30
- encodeNativeSourceProps: () => encodeNativeSourceProps
30
+ encodeNativeSourceListItem: () => encodeNativeSourceListItem,
31
+ encodeNativeSourceProp: () => encodeNativeSourceProp,
32
+ encodeNativeSourceProps: () => encodeNativeSourceProps,
33
+ stringifyNativeSourceProps: () => stringifyNativeSourceProps
31
34
  });
32
35
  module.exports = __toCommonJS(wire_native_exports);
33
36
  var BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -66,105 +69,165 @@ function base64Decode(text) {
66
69
  function isRecord(value) {
67
70
  return typeof value === "object" && value !== null && !Array.isArray(value);
68
71
  }
69
- function encodeValue(value, wire, structs, path) {
72
+ var trail = [];
73
+ function trailText() {
74
+ var text = String(trail[0]);
75
+ for (var i = 1; i < trail.length; i++) {
76
+ text += typeof trail[i] === "number" ? `[${trail[i]}]` : `.${trail[i]}`;
77
+ }
78
+ return text;
79
+ }
80
+ var plainStructs = /* @__PURE__ */ new WeakMap();
81
+ function encodeValue(value, wire, structs) {
70
82
  switch (wire.kind) {
71
83
  case "date":
72
- if (!(value instanceof Date)) throw new TypeError(`${path}: expected Date`);
84
+ if (!(value instanceof Date)) throw new TypeError(`${trailText()}: expected Date`);
73
85
  return value;
74
86
  case "data":
75
- if (!(value instanceof Uint8Array)) throw new TypeError(`${path}: expected Uint8Array`);
87
+ if (!(value instanceof Uint8Array)) throw new TypeError(`${trailText()}: expected Uint8Array`);
76
88
  return base64Encode(value);
77
89
  case "enum":
78
90
  if (typeof value !== "string" && typeof value !== "number") {
79
- throw new TypeError(`${path}: expected an enum value`);
91
+ throw new TypeError(`${trailText()}: expected an enum value`);
80
92
  }
81
93
  return value;
82
94
  case "struct": {
83
- if (!isRecord(value)) throw new TypeError(`${path}: expected ${wire.name}`);
95
+ if (!isRecord(value)) throw new TypeError(`${trailText()}: expected ${wire.name}`);
84
96
  var table = structs[wire.name];
85
- if (!table) throw new TypeError(`${path}: unknown struct ${wire.name}`);
97
+ if (!table) throw new TypeError(`${trailText()}: unknown struct ${wire.name}`);
98
+ var plain = plainStructs.get(table);
99
+ if (plain === void 0) {
100
+ plain = table.fields.every(function(field2) {
101
+ return field2.wire === void 0;
102
+ });
103
+ plainStructs.set(table, plain);
104
+ }
105
+ if (plain) {
106
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
107
+ try {
108
+ for (var _iterator = table.fields[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
109
+ var field = _step.value;
110
+ if (value[field.name] === void 0 && !field.optional) {
111
+ trail.push(field.name);
112
+ throw new TypeError(`${trailText()}: required`);
113
+ }
114
+ }
115
+ } catch (err) {
116
+ _didIteratorError = true;
117
+ _iteratorError = err;
118
+ } finally {
119
+ try {
120
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
121
+ _iterator.return();
122
+ }
123
+ } finally {
124
+ if (_didIteratorError) {
125
+ throw _iteratorError;
126
+ }
127
+ }
128
+ }
129
+ return value;
130
+ }
86
131
  var out = {};
87
- var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
132
+ var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
88
133
  try {
89
134
  var _loop = function() {
90
- var key2 = _step.value;
135
+ var key2 = _step1.value;
91
136
  if (!table.fields.some(function(field2) {
92
137
  return field2.name === key2;
93
138
  })) out[key2] = value[key2];
94
139
  };
95
- for (var _iterator = Object.keys(value)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) _loop();
140
+ for (var _iterator1 = Object.keys(value)[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) _loop();
96
141
  } catch (err) {
97
- _didIteratorError = true;
98
- _iteratorError = err;
142
+ _didIteratorError1 = true;
143
+ _iteratorError1 = err;
99
144
  } finally {
100
145
  try {
101
- if (!_iteratorNormalCompletion && _iterator.return != null) {
102
- _iterator.return();
146
+ if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
147
+ _iterator1.return();
103
148
  }
104
149
  } finally {
105
- if (_didIteratorError) {
106
- throw _iteratorError;
150
+ if (_didIteratorError1) {
151
+ throw _iteratorError1;
107
152
  }
108
153
  }
109
154
  }
110
- var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
155
+ var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
111
156
  try {
112
- for (var _iterator1 = table.fields[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
113
- var field = _step1.value;
114
- var present = value[field.name] !== void 0;
157
+ for (var _iterator2 = table.fields[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
158
+ var field1 = _step2.value;
159
+ var present = value[field1.name] !== void 0;
115
160
  if (!present) {
116
- if (!field.optional) throw new TypeError(`${path}.${field.name}: required`);
161
+ if (!field1.optional) {
162
+ trail.push(field1.name);
163
+ throw new TypeError(`${trailText()}: required`);
164
+ }
165
+ continue;
166
+ }
167
+ if (field1.wire === void 0) {
168
+ out[field1.name] = value[field1.name];
117
169
  continue;
118
170
  }
119
- out[field.name] = field.wire === void 0 ? value[field.name] : encodeValue(value[field.name], field.wire, structs, `${path}.${field.name}`);
171
+ trail.push(field1.name);
172
+ out[field1.name] = encodeValue(value[field1.name], field1.wire, structs);
173
+ trail.pop();
120
174
  }
121
175
  } catch (err) {
122
- _didIteratorError1 = true;
123
- _iteratorError1 = err;
176
+ _didIteratorError2 = true;
177
+ _iteratorError2 = err;
124
178
  } finally {
125
179
  try {
126
- if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
127
- _iterator1.return();
180
+ if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
181
+ _iterator2.return();
128
182
  }
129
183
  } finally {
130
- if (_didIteratorError1) {
131
- throw _iteratorError1;
184
+ if (_didIteratorError2) {
185
+ throw _iteratorError2;
132
186
  }
133
187
  }
134
188
  }
135
189
  return out;
136
190
  }
137
- case "array":
138
- if (!Array.isArray(value)) throw new TypeError(`${path}: expected an array`);
139
- return value.map(function(item, index) {
140
- return encodeValue(item, wire.element, structs, `${path}[${index}]`);
141
- });
191
+ case "array": {
192
+ if (!Array.isArray(value)) throw new TypeError(`${trailText()}: expected an array`);
193
+ var out1 = new Array(value.length);
194
+ trail.push(0);
195
+ var at = trail.length - 1;
196
+ for (var index = 0; index < value.length; index++) {
197
+ trail[at] = index;
198
+ out1[index] = encodeValue(value[index], wire.element, structs);
199
+ }
200
+ trail.pop();
201
+ return out1;
202
+ }
142
203
  case "map": {
143
- if (!isRecord(value)) throw new TypeError(`${path}: expected an object`);
144
- var out1 = {};
145
- var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
204
+ if (!isRecord(value)) throw new TypeError(`${trailText()}: expected an object`);
205
+ var out2 = {};
206
+ var _iteratorNormalCompletion3 = true, _didIteratorError3 = false, _iteratorError3 = void 0;
146
207
  try {
147
- for (var _iterator2 = Object.keys(value)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
148
- var key = _step2.value;
149
- out1[key] = encodeValue(value[key], wire.value, structs, `${path}.${key}`);
208
+ for (var _iterator3 = Object.keys(value)[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
209
+ var key = _step3.value;
210
+ trail.push(key);
211
+ out2[key] = encodeValue(value[key], wire.value, structs);
212
+ trail.pop();
150
213
  }
151
214
  } catch (err) {
152
- _didIteratorError2 = true;
153
- _iteratorError2 = err;
215
+ _didIteratorError3 = true;
216
+ _iteratorError3 = err;
154
217
  } finally {
155
218
  try {
156
- if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
157
- _iterator2.return();
219
+ if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
220
+ _iterator3.return();
158
221
  }
159
222
  } finally {
160
- if (_didIteratorError2) {
161
- throw _iteratorError2;
223
+ if (_didIteratorError3) {
224
+ throw _iteratorError3;
162
225
  }
163
226
  }
164
227
  }
165
- return out1;
228
+ return out2;
166
229
  }
167
- case "nullable": return value === null || value === void 0 ? null : encodeValue(value, wire.inner, structs, path);
230
+ case "nullable": return value === null || value === void 0 ? null : encodeValue(value, wire.inner, structs);
168
231
  }
169
232
  }
170
233
  function decodeValue(value, wire, structs, path) {
@@ -281,10 +344,15 @@ function decodeValue(value, wire, structs, path) {
281
344
  case "nullable": return value === null || value === void 0 ? null : decodeValue(value, wire.inner, structs, path);
282
345
  }
283
346
  }
347
+ function encodeAt(path, value, wire, structs) {
348
+ trail.length = 0;
349
+ trail.push(...path);
350
+ return encodeValue(value, wire, structs);
351
+ }
284
352
  function encodeNativeSourceArgs(args, wires, structs) {
285
353
  return args.map(function(arg, index) {
286
354
  var wire = wires[index];
287
- return wire === void 0 || wire === null ? arg : encodeValue(arg, wire, structs, `args[${index}]`);
355
+ return wire === void 0 || wire === null ? arg : encodeAt(["args", index], arg, wire, structs);
288
356
  });
289
357
  }
290
358
  function decodeNativeSourceResult(value, wire, structs) {
@@ -297,7 +365,7 @@ function encodeNativeSourceProps(props, wires, structs) {
297
365
  for (var _iterator = Object.keys(wires)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
298
366
  var name = _step.value;
299
367
  if (out[name] === void 0) continue;
300
- out[name] = encodeValue(out[name], wires[name], structs, `props.${name}`);
368
+ out[name] = encodeAt(["props", name], out[name], wires[name], structs);
301
369
  }
302
370
  } catch (err) {
303
371
  _didIteratorError = true;
@@ -315,6 +383,41 @@ function encodeNativeSourceProps(props, wires, structs) {
315
383
  }
316
384
  return out;
317
385
  }
386
+ function encodeNativeSourceProp(name, value, wires) {
387
+ var wire = wires === null || wires === void 0 ? void 0 : wires.props[name];
388
+ return wire === void 0 ? value : encodeAt(["props", name], value, wire, wires.structs);
389
+ }
390
+ function encodeNativeSourceListItem(name, index, item, element, structs) {
391
+ return encodeAt([
392
+ "props",
393
+ name,
394
+ index
395
+ ], item, element, structs);
396
+ }
397
+ function stringifyNativeSourceProps(props, wires) {
398
+ var out = wires ? encodeNativeSourceProps(props, wires.props, wires.structs) : { ...props };
399
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
400
+ try {
401
+ for (var _iterator = Object.keys(out)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
402
+ var key = _step.value;
403
+ if (typeof out[key] === "function") out[key] = true;
404
+ }
405
+ } catch (err) {
406
+ _didIteratorError = true;
407
+ _iteratorError = err;
408
+ } finally {
409
+ try {
410
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
411
+ _iterator.return();
412
+ }
413
+ } finally {
414
+ if (_didIteratorError) {
415
+ throw _iteratorError;
416
+ }
417
+ }
418
+ }
419
+ return JSON.stringify(out);
420
+ }
318
421
  function decodeNativeSourceCallback(args, wires, structs, event) {
319
422
  return args.map(function(arg, index) {
320
423
  var wire = wires[index];