@b9g/crank 0.7.3 → 0.7.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.
package/crank.d.ts CHANGED
@@ -243,6 +243,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
243
243
  tagName: string;
244
244
  props: Record<string, any>;
245
245
  scope: TScope | undefined;
246
+ root: TRoot | undefined;
246
247
  }): TNode;
247
248
  /**
248
249
  * Adopts existing nodes during hydration.
@@ -274,6 +275,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
274
275
  props: Record<string, any>;
275
276
  node: TNode | undefined;
276
277
  scope: TScope | undefined;
278
+ root: TRoot | undefined;
277
279
  }): Array<TNode> | undefined;
278
280
  /**
279
281
  * Creates or updates a text node.
@@ -303,6 +305,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
303
305
  scope: TScope | undefined;
304
306
  oldNode: TNode | undefined;
305
307
  hydrationNodes: Array<TNode> | undefined;
308
+ root: TRoot | undefined;
306
309
  }): TNode;
307
310
  /**
308
311
  * Computes scope context for child elements.
@@ -332,6 +335,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
332
335
  tagName: string;
333
336
  props: Record<string, any>;
334
337
  scope: TScope | undefined;
338
+ root: TRoot | undefined;
335
339
  }): TScope | undefined;
336
340
  /**
337
341
  * Handles raw values (strings or nodes) that bypass normal element processing.
@@ -360,6 +364,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
360
364
  value: string | TNode;
361
365
  scope: TScope | undefined;
362
366
  hydrationNodes: Array<TNode> | undefined;
367
+ root: TRoot | undefined;
363
368
  }): ElementValue<TNode>;
364
369
  /**
365
370
  * Updates a node's properties.
@@ -400,6 +405,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
400
405
  props: Record<string, any>;
401
406
  oldProps: Record<string, any> | undefined;
402
407
  scope: TScope | undefined;
408
+ root: TRoot | undefined;
403
409
  copyProps: Set<string> | undefined;
404
410
  isHydrating: boolean;
405
411
  quietProps: Set<string> | undefined;
@@ -437,6 +443,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
437
443
  props: Record<string, any>;
438
444
  children: Array<TNode>;
439
445
  oldProps: Record<string, any> | undefined;
446
+ root: TRoot | undefined;
440
447
  }): void;
441
448
  /**
442
449
  * Removes a node from its parent.
@@ -464,6 +471,7 @@ export interface RenderAdapter<TNode, TScope, TRoot extends TNode | undefined =
464
471
  node: TNode;
465
472
  parentNode: TNode;
466
473
  isNested: boolean;
474
+ root: TRoot | undefined;
467
475
  }): void;
468
476
  /**
469
477
  * Reads the final rendered value from an ElementValue.
package/crank.js CHANGED
@@ -398,6 +398,7 @@ function getRootRetainer(renderer, bridge, { children, root, hydrate, }) {
398
398
  tagName: getTagName(Portal),
399
399
  props: stripSpecialProps(ret.el.props),
400
400
  scope: undefined,
401
+ root,
401
402
  });
402
403
  // remember that typeof null === "object"
403
404
  if (typeof root === "object" && root !== null && children != null) {
@@ -420,32 +421,32 @@ function renderRoot(adapter, root, ret, children) {
420
421
  const schedulePromises = [];
421
422
  if (isPromiseLike(diff)) {
422
423
  return diff.then(() => {
423
- commit(adapter, ret, ret, ret.ctx, ret.scope, 0, schedulePromises, undefined);
424
+ commit(adapter, ret, ret, ret.ctx, ret.scope, root, 0, schedulePromises, undefined);
424
425
  if (schedulePromises.length > 0) {
425
426
  return Promise.all(schedulePromises).then(() => {
426
427
  if (typeof root !== "object" || root === null) {
427
- unmount(adapter, ret, ret.ctx, ret, false);
428
+ unmount(adapter, ret, ret.ctx, root, ret, false);
428
429
  }
429
430
  return adapter.read(unwrap(getChildValues(ret)));
430
431
  });
431
432
  }
432
433
  if (typeof root !== "object" || root === null) {
433
- unmount(adapter, ret, ret.ctx, ret, false);
434
+ unmount(adapter, ret, ret.ctx, root, ret, false);
434
435
  }
435
436
  return adapter.read(unwrap(getChildValues(ret)));
436
437
  });
437
438
  }
438
- commit(adapter, ret, ret, ret.ctx, ret.scope, 0, schedulePromises, undefined);
439
+ commit(adapter, ret, ret, ret.ctx, ret.scope, root, 0, schedulePromises, undefined);
439
440
  if (schedulePromises.length > 0) {
440
441
  return Promise.all(schedulePromises).then(() => {
441
442
  if (typeof root !== "object" || root === null) {
442
- unmount(adapter, ret, ret.ctx, ret, false);
443
+ unmount(adapter, ret, ret.ctx, root, ret, false);
443
444
  }
444
445
  return adapter.read(unwrap(getChildValues(ret)));
445
446
  });
446
447
  }
447
448
  if (typeof root !== "object" || root === null) {
448
- unmount(adapter, ret, ret.ctx, ret, false);
449
+ unmount(adapter, ret, ret.ctx, root, ret, false);
449
450
  }
450
451
  return adapter.read(unwrap(getChildValues(ret)));
451
452
  }
@@ -695,11 +696,12 @@ function diffHost(adapter, root, ctx, scope, ret) {
695
696
  tagName: getTagName(tag),
696
697
  props: el.props,
697
698
  scope,
699
+ root,
698
700
  });
699
701
  }
700
702
  return diffChildren(adapter, root, ret, ctx, scope, ret, ret.el.props.children);
701
703
  }
702
- function commit(adapter, host, ret, ctx, scope, index, schedulePromises, hydrationNodes) {
704
+ function commit(adapter, host, ret, ctx, scope, root, index, schedulePromises, hydrationNodes) {
703
705
  if (getFlag(ret, IsCopied) && getFlag(ret, DidCommit)) {
704
706
  return getValue(ret);
705
707
  }
@@ -732,19 +734,19 @@ function commit(adapter, host, ret, ctx, scope, index, schedulePromises, hydrati
732
734
  }
733
735
  else {
734
736
  if (tag === Fragment) {
735
- value = commitChildren(adapter, host, ctx, scope, ret, index, schedulePromises, hydrationNodes);
737
+ value = commitChildren(adapter, host, ctx, scope, root, ret, index, schedulePromises, hydrationNodes);
736
738
  }
737
739
  else if (tag === Text) {
738
- value = commitText(adapter, ret, el, scope, hydrationNodes);
740
+ value = commitText(adapter, ret, el, scope, hydrationNodes, root);
739
741
  }
740
742
  else if (tag === Raw) {
741
- value = commitRaw(adapter, host, ret, scope, hydrationNodes);
743
+ value = commitRaw(adapter, host, ret, scope, hydrationNodes, root);
742
744
  }
743
745
  else {
744
- value = commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes);
746
+ value = commitHost(adapter, ret, ctx, root, schedulePromises, hydrationNodes);
745
747
  }
746
748
  if (ret.fallback) {
747
- unmount(adapter, host, ctx, ret.fallback, false);
749
+ unmount(adapter, host, ctx, root, ret.fallback, false);
748
750
  ret.fallback = undefined;
749
751
  }
750
752
  }
@@ -762,7 +764,7 @@ function commit(adapter, host, ret, ctx, scope, index, schedulePromises, hydrati
762
764
  }
763
765
  return value;
764
766
  }
765
- function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromises, hydrationNodes) {
767
+ function commitChildren(adapter, host, ctx, scope, root, parent, index, schedulePromises, hydrationNodes) {
766
768
  let values = [];
767
769
  for (let i = 0, children = wrap(parent.children); i < children.length; i++) {
768
770
  let child = children[i];
@@ -785,6 +787,7 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
785
787
  node,
786
788
  parentNode: host.value,
787
789
  isNested: false,
790
+ root,
788
791
  });
789
792
  }
790
793
  }
@@ -844,7 +847,7 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
844
847
  schedulePromises.push(safeRace(schedulePromises1));
845
848
  }
846
849
  if (child) {
847
- const value = commit(adapter, host, child, ctx, scope, index, schedulePromises, hydrationNodes);
850
+ const value = commit(adapter, host, child, ctx, scope, root, index, schedulePromises, hydrationNodes);
848
851
  if (Array.isArray(value)) {
849
852
  for (let j = 0; j < value.length; j++) {
850
853
  values.push(value[j]);
@@ -860,7 +863,7 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
860
863
  if (parent.graveyard) {
861
864
  for (let i = 0; i < parent.graveyard.length; i++) {
862
865
  const child = parent.graveyard[i];
863
- unmount(adapter, host, ctx, child, false);
866
+ unmount(adapter, host, ctx, root, child, false);
864
867
  }
865
868
  parent.graveyard = undefined;
866
869
  }
@@ -871,17 +874,18 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
871
874
  }
872
875
  return values;
873
876
  }
874
- function commitText(adapter, ret, el, scope, hydrationNodes) {
877
+ function commitText(adapter, ret, el, scope, hydrationNodes, root) {
875
878
  const value = adapter.text({
876
879
  value: el.props.value,
877
880
  scope,
878
881
  oldNode: ret.value,
879
882
  hydrationNodes,
883
+ root,
880
884
  });
881
885
  ret.value = value;
882
886
  return value;
883
887
  }
884
- function commitRaw(adapter, host, ret, scope, hydrationNodes) {
888
+ function commitRaw(adapter, host, ret, scope, hydrationNodes, root) {
885
889
  if (!ret.oldProps || ret.oldProps.value !== ret.el.props.value) {
886
890
  const oldNodes = wrap(ret.value);
887
891
  for (let i = 0; i < oldNodes.length; i++) {
@@ -890,18 +894,20 @@ function commitRaw(adapter, host, ret, scope, hydrationNodes) {
890
894
  node: oldNode,
891
895
  parentNode: host.value,
892
896
  isNested: false,
897
+ root,
893
898
  });
894
899
  }
895
900
  ret.value = adapter.raw({
896
901
  value: ret.el.props.value,
897
902
  scope,
898
903
  hydrationNodes,
904
+ root,
899
905
  });
900
906
  }
901
907
  ret.oldProps = stripSpecialProps(ret.el.props);
902
908
  return ret.value;
903
909
  }
904
- function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
910
+ function commitHost(adapter, ret, ctx, root, schedulePromises, hydrationNodes) {
905
911
  if (getFlag(ret, IsCopied) && getFlag(ret, DidCommit)) {
906
912
  return getValue(ret);
907
913
  }
@@ -954,6 +960,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
954
960
  node,
955
961
  props,
956
962
  scope,
963
+ root,
957
964
  });
958
965
  if (childHydrationNodes) {
959
966
  for (let i = 0; i < childHydrationNodes.length; i++) {
@@ -961,6 +968,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
961
968
  node: childHydrationNodes[i],
962
969
  parentNode: node,
963
970
  isNested: false,
971
+ root,
964
972
  });
965
973
  }
966
974
  }
@@ -989,6 +997,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
989
997
  node: nextChild,
990
998
  props,
991
999
  scope,
1000
+ root,
992
1001
  });
993
1002
  if (childHydrationNodes) {
994
1003
  node = nextChild;
@@ -997,6 +1006,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
997
1006
  node: childHydrationNodes[i],
998
1007
  parentNode: node,
999
1008
  isNested: false,
1009
+ root,
1000
1010
  });
1001
1011
  }
1002
1012
  }
@@ -1011,6 +1021,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1011
1021
  tagName: getTagName(tag),
1012
1022
  props,
1013
1023
  scope,
1024
+ root,
1014
1025
  });
1015
1026
  }
1016
1027
  ret.value = node;
@@ -1024,13 +1035,14 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1024
1035
  props,
1025
1036
  oldProps,
1026
1037
  scope,
1038
+ root,
1027
1039
  copyProps,
1028
1040
  isHydrating: !!childHydrationNodes,
1029
1041
  quietProps,
1030
1042
  });
1031
1043
  }
1032
1044
  if (!copyChildren) {
1033
- const children = commitChildren(adapter, ret, ctx, scope, ret, 0, schedulePromises, hydrationMetaProp && !hydrationMetaProp.includes("children")
1045
+ const children = commitChildren(adapter, ret, ctx, scope, tag === Portal ? node : root, ret, 0, schedulePromises, hydrationMetaProp && !hydrationMetaProp.includes("children")
1034
1046
  ? undefined
1035
1047
  : childHydrationNodes);
1036
1048
  adapter.arrange({
@@ -1040,6 +1052,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1040
1052
  props,
1041
1053
  children,
1042
1054
  oldProps,
1055
+ root,
1043
1056
  });
1044
1057
  }
1045
1058
  ret.oldProps = props;
@@ -1140,10 +1153,10 @@ function flush(adapter, root, initiator) {
1140
1153
  }
1141
1154
  }
1142
1155
  }
1143
- function unmount(adapter, host, ctx, ret, isNested) {
1156
+ function unmount(adapter, host, ctx, root, ret, isNested) {
1144
1157
  // TODO: set the IsUnmounted flag consistently for all retainers
1145
1158
  if (ret.fallback) {
1146
- unmount(adapter, host, ctx, ret.fallback, isNested);
1159
+ unmount(adapter, host, ctx, root, ret.fallback, isNested);
1147
1160
  ret.fallback = undefined;
1148
1161
  }
1149
1162
  if (getFlag(ret, IsResurrecting)) {
@@ -1154,7 +1167,7 @@ function unmount(adapter, host, ctx, ret, isNested) {
1154
1167
  const lingerers = ret.lingerers[i];
1155
1168
  if (lingerers) {
1156
1169
  for (const lingerer of lingerers) {
1157
- unmount(adapter, host, ctx, lingerer, isNested);
1170
+ unmount(adapter, host, ctx, root, lingerer, isNested);
1158
1171
  }
1159
1172
  }
1160
1173
  }
@@ -1164,16 +1177,16 @@ function unmount(adapter, host, ctx, ret, isNested) {
1164
1177
  unmountComponent(ret.ctx, isNested);
1165
1178
  }
1166
1179
  else if (ret.el.tag === Fragment) {
1167
- unmountChildren(adapter, host, ctx, ret, isNested);
1180
+ unmountChildren(adapter, host, ctx, root, ret, isNested);
1168
1181
  }
1169
1182
  else if (ret.el.tag === Portal) {
1170
- unmountChildren(adapter, ret, ctx, ret, false);
1183
+ unmountChildren(adapter, ret, ctx, ret.value, ret, false);
1171
1184
  if (ret.value != null) {
1172
1185
  adapter.finalize(ret.value);
1173
1186
  }
1174
1187
  }
1175
1188
  else {
1176
- unmountChildren(adapter, ret, ctx, ret, true);
1189
+ unmountChildren(adapter, ret, ctx, root, ret, true);
1177
1190
  if (getFlag(ret, DidCommit)) {
1178
1191
  if (ctx) {
1179
1192
  // Remove the value from every context which shares the same host.
@@ -1183,22 +1196,23 @@ function unmount(adapter, host, ctx, ret, isNested) {
1183
1196
  node: ret.value,
1184
1197
  parentNode: host.value,
1185
1198
  isNested,
1199
+ root,
1186
1200
  });
1187
1201
  }
1188
1202
  }
1189
1203
  }
1190
- function unmountChildren(adapter, host, ctx, ret, isNested) {
1204
+ function unmountChildren(adapter, host, ctx, root, ret, isNested) {
1191
1205
  if (ret.graveyard) {
1192
1206
  for (let i = 0; i < ret.graveyard.length; i++) {
1193
1207
  const child = ret.graveyard[i];
1194
- unmount(adapter, host, ctx, child, isNested);
1208
+ unmount(adapter, host, ctx, root, child, isNested);
1195
1209
  }
1196
1210
  ret.graveyard = undefined;
1197
1211
  }
1198
1212
  for (let i = 0, children = wrap(ret.children); i < children.length; i++) {
1199
1213
  const child = children[i];
1200
1214
  if (typeof child === "object") {
1201
- unmount(adapter, host, ctx, child, isNested);
1215
+ unmount(adapter, host, ctx, root, child, isNested);
1202
1216
  }
1203
1217
  }
1204
1218
  }
@@ -1992,7 +2006,7 @@ function commitComponent(ctx, schedulePromises, hydrationNodes) {
1992
2006
  });
1993
2007
  return getValue(ctx.ret);
1994
2008
  }
1995
- const values = commitChildren(ctx.adapter, ctx.host, ctx, ctx.scope, ctx.ret, ctx.index, schedulePromises, hydrationNodes);
2009
+ const values = commitChildren(ctx.adapter, ctx.host, ctx, ctx.scope, ctx.root, ctx.ret, ctx.index, schedulePromises, hydrationNodes);
1996
2010
  if (getFlag(ctx.ret, IsUnmounted)) {
1997
2011
  return;
1998
2012
  }
@@ -2016,7 +2030,7 @@ function commitComponent(ctx, schedulePromises, hydrationNodes) {
2016
2030
  setFlag(ctx.ret, IsScheduling, wasScheduling);
2017
2031
  propagateComponent(ctx);
2018
2032
  if (ctx.ret.fallback) {
2019
- unmount(ctx.adapter, ctx.host, ctx.parent, ctx.ret.fallback, false);
2033
+ unmount(ctx.adapter, ctx.host, ctx.parent, ctx.root, ctx.ret.fallback, false);
2020
2034
  }
2021
2035
  ctx.ret.fallback = undefined;
2022
2036
  });
@@ -2042,7 +2056,7 @@ function commitComponent(ctx, schedulePromises, hydrationNodes) {
2042
2056
  propagateComponent(ctx);
2043
2057
  }
2044
2058
  if (ctx.ret.fallback) {
2045
- unmount(ctx.adapter, ctx.host, ctx.parent, ctx.ret.fallback, false);
2059
+ unmount(ctx.adapter, ctx.host, ctx.parent, ctx.root, ctx.ret.fallback, false);
2046
2060
  }
2047
2061
  ctx.ret.fallback = undefined;
2048
2062
  setFlag(ctx.ret, IsUpdating, false);
@@ -2108,6 +2122,7 @@ function propagateComponent(ctx) {
2108
2122
  props,
2109
2123
  oldProps: props,
2110
2124
  children: hostChildren,
2125
+ root: ctx.root,
2111
2126
  });
2112
2127
  flush(ctx.adapter, ctx.root, ctx);
2113
2128
  }
@@ -2162,7 +2177,7 @@ async function unmountComponent(ctx, isNested) {
2162
2177
  ctx.schedule = undefined;
2163
2178
  }
2164
2179
  clearEventListeners(ctx.ctx);
2165
- unmountChildren(ctx.adapter, ctx.host, ctx, ctx.ret, isNested);
2180
+ unmountChildren(ctx.adapter, ctx.host, ctx, ctx.root, ctx.ret, isNested);
2166
2181
  if (didLinger) {
2167
2182
  // If we lingered, we call finalize to ensure rendering is finalized
2168
2183
  if (ctx.root != null) {