@b9g/crank 0.7.2 → 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.cjs CHANGED
@@ -401,6 +401,7 @@ function getRootRetainer(renderer, bridge, { children, root, hydrate, }) {
401
401
  tagName: getTagName(Portal),
402
402
  props: stripSpecialProps(ret.el.props),
403
403
  scope: undefined,
404
+ root,
404
405
  });
405
406
  // remember that typeof null === "object"
406
407
  if (typeof root === "object" && root !== null && children != null) {
@@ -423,32 +424,32 @@ function renderRoot(adapter, root, ret, children) {
423
424
  const schedulePromises = [];
424
425
  if (_utils.isPromiseLike(diff)) {
425
426
  return diff.then(() => {
426
- commit(adapter, ret, ret, ret.ctx, ret.scope, 0, schedulePromises, undefined);
427
+ commit(adapter, ret, ret, ret.ctx, ret.scope, root, 0, schedulePromises, undefined);
427
428
  if (schedulePromises.length > 0) {
428
429
  return Promise.all(schedulePromises).then(() => {
429
430
  if (typeof root !== "object" || root === null) {
430
- unmount(adapter, ret, ret.ctx, ret, false);
431
+ unmount(adapter, ret, ret.ctx, root, ret, false);
431
432
  }
432
433
  return adapter.read(_utils.unwrap(getChildValues(ret)));
433
434
  });
434
435
  }
435
436
  if (typeof root !== "object" || root === null) {
436
- unmount(adapter, ret, ret.ctx, ret, false);
437
+ unmount(adapter, ret, ret.ctx, root, ret, false);
437
438
  }
438
439
  return adapter.read(_utils.unwrap(getChildValues(ret)));
439
440
  });
440
441
  }
441
- commit(adapter, ret, ret, ret.ctx, ret.scope, 0, schedulePromises, undefined);
442
+ commit(adapter, ret, ret, ret.ctx, ret.scope, root, 0, schedulePromises, undefined);
442
443
  if (schedulePromises.length > 0) {
443
444
  return Promise.all(schedulePromises).then(() => {
444
445
  if (typeof root !== "object" || root === null) {
445
- unmount(adapter, ret, ret.ctx, ret, false);
446
+ unmount(adapter, ret, ret.ctx, root, ret, false);
446
447
  }
447
448
  return adapter.read(_utils.unwrap(getChildValues(ret)));
448
449
  });
449
450
  }
450
451
  if (typeof root !== "object" || root === null) {
451
- unmount(adapter, ret, ret.ctx, ret, false);
452
+ unmount(adapter, ret, ret.ctx, root, ret, false);
452
453
  }
453
454
  return adapter.read(_utils.unwrap(getChildValues(ret)));
454
455
  }
@@ -698,11 +699,12 @@ function diffHost(adapter, root, ctx, scope, ret) {
698
699
  tagName: getTagName(tag),
699
700
  props: el.props,
700
701
  scope,
702
+ root,
701
703
  });
702
704
  }
703
705
  return diffChildren(adapter, root, ret, ctx, scope, ret, ret.el.props.children);
704
706
  }
705
- function commit(adapter, host, ret, ctx, scope, index, schedulePromises, hydrationNodes) {
707
+ function commit(adapter, host, ret, ctx, scope, root, index, schedulePromises, hydrationNodes) {
706
708
  if (getFlag(ret, IsCopied) && getFlag(ret, DidCommit)) {
707
709
  return getValue(ret);
708
710
  }
@@ -735,19 +737,19 @@ function commit(adapter, host, ret, ctx, scope, index, schedulePromises, hydrati
735
737
  }
736
738
  else {
737
739
  if (tag === Fragment) {
738
- value = commitChildren(adapter, host, ctx, scope, ret, index, schedulePromises, hydrationNodes);
740
+ value = commitChildren(adapter, host, ctx, scope, root, ret, index, schedulePromises, hydrationNodes);
739
741
  }
740
742
  else if (tag === Text) {
741
- value = commitText(adapter, ret, el, scope, hydrationNodes);
743
+ value = commitText(adapter, ret, el, scope, hydrationNodes, root);
742
744
  }
743
745
  else if (tag === Raw) {
744
- value = commitRaw(adapter, host, ret, scope, hydrationNodes);
746
+ value = commitRaw(adapter, host, ret, scope, hydrationNodes, root);
745
747
  }
746
748
  else {
747
- value = commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes);
749
+ value = commitHost(adapter, ret, ctx, root, schedulePromises, hydrationNodes);
748
750
  }
749
751
  if (ret.fallback) {
750
- unmount(adapter, host, ctx, ret.fallback, false);
752
+ unmount(adapter, host, ctx, root, ret.fallback, false);
751
753
  ret.fallback = undefined;
752
754
  }
753
755
  }
@@ -765,7 +767,7 @@ function commit(adapter, host, ret, ctx, scope, index, schedulePromises, hydrati
765
767
  }
766
768
  return value;
767
769
  }
768
- function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromises, hydrationNodes) {
770
+ function commitChildren(adapter, host, ctx, scope, root, parent, index, schedulePromises, hydrationNodes) {
769
771
  let values = [];
770
772
  for (let i = 0, children = _utils.wrap(parent.children); i < children.length; i++) {
771
773
  let child = children[i];
@@ -788,6 +790,7 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
788
790
  node,
789
791
  parentNode: host.value,
790
792
  isNested: false,
793
+ root,
791
794
  });
792
795
  }
793
796
  }
@@ -847,7 +850,7 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
847
850
  schedulePromises.push(_utils.safeRace(schedulePromises1));
848
851
  }
849
852
  if (child) {
850
- const value = commit(adapter, host, child, ctx, scope, index, schedulePromises, hydrationNodes);
853
+ const value = commit(adapter, host, child, ctx, scope, root, index, schedulePromises, hydrationNodes);
851
854
  if (Array.isArray(value)) {
852
855
  for (let j = 0; j < value.length; j++) {
853
856
  values.push(value[j]);
@@ -863,7 +866,7 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
863
866
  if (parent.graveyard) {
864
867
  for (let i = 0; i < parent.graveyard.length; i++) {
865
868
  const child = parent.graveyard[i];
866
- unmount(adapter, host, ctx, child, false);
869
+ unmount(adapter, host, ctx, root, child, false);
867
870
  }
868
871
  parent.graveyard = undefined;
869
872
  }
@@ -874,17 +877,18 @@ function commitChildren(adapter, host, ctx, scope, parent, index, schedulePromis
874
877
  }
875
878
  return values;
876
879
  }
877
- function commitText(adapter, ret, el, scope, hydrationNodes) {
880
+ function commitText(adapter, ret, el, scope, hydrationNodes, root) {
878
881
  const value = adapter.text({
879
882
  value: el.props.value,
880
883
  scope,
881
884
  oldNode: ret.value,
882
885
  hydrationNodes,
886
+ root,
883
887
  });
884
888
  ret.value = value;
885
889
  return value;
886
890
  }
887
- function commitRaw(adapter, host, ret, scope, hydrationNodes) {
891
+ function commitRaw(adapter, host, ret, scope, hydrationNodes, root) {
888
892
  if (!ret.oldProps || ret.oldProps.value !== ret.el.props.value) {
889
893
  const oldNodes = _utils.wrap(ret.value);
890
894
  for (let i = 0; i < oldNodes.length; i++) {
@@ -893,18 +897,20 @@ function commitRaw(adapter, host, ret, scope, hydrationNodes) {
893
897
  node: oldNode,
894
898
  parentNode: host.value,
895
899
  isNested: false,
900
+ root,
896
901
  });
897
902
  }
898
903
  ret.value = adapter.raw({
899
904
  value: ret.el.props.value,
900
905
  scope,
901
906
  hydrationNodes,
907
+ root,
902
908
  });
903
909
  }
904
910
  ret.oldProps = stripSpecialProps(ret.el.props);
905
911
  return ret.value;
906
912
  }
907
- function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
913
+ function commitHost(adapter, ret, ctx, root, schedulePromises, hydrationNodes) {
908
914
  if (getFlag(ret, IsCopied) && getFlag(ret, DidCommit)) {
909
915
  return getValue(ret);
910
916
  }
@@ -957,6 +963,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
957
963
  node,
958
964
  props,
959
965
  scope,
966
+ root,
960
967
  });
961
968
  if (childHydrationNodes) {
962
969
  for (let i = 0; i < childHydrationNodes.length; i++) {
@@ -964,6 +971,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
964
971
  node: childHydrationNodes[i],
965
972
  parentNode: node,
966
973
  isNested: false,
974
+ root,
967
975
  });
968
976
  }
969
977
  }
@@ -992,6 +1000,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
992
1000
  node: nextChild,
993
1001
  props,
994
1002
  scope,
1003
+ root,
995
1004
  });
996
1005
  if (childHydrationNodes) {
997
1006
  node = nextChild;
@@ -1000,6 +1009,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1000
1009
  node: childHydrationNodes[i],
1001
1010
  parentNode: node,
1002
1011
  isNested: false,
1012
+ root,
1003
1013
  });
1004
1014
  }
1005
1015
  }
@@ -1014,6 +1024,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1014
1024
  tagName: getTagName(tag),
1015
1025
  props,
1016
1026
  scope,
1027
+ root,
1017
1028
  });
1018
1029
  }
1019
1030
  ret.value = node;
@@ -1027,13 +1038,14 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1027
1038
  props,
1028
1039
  oldProps,
1029
1040
  scope,
1041
+ root,
1030
1042
  copyProps,
1031
1043
  isHydrating: !!childHydrationNodes,
1032
1044
  quietProps,
1033
1045
  });
1034
1046
  }
1035
1047
  if (!copyChildren) {
1036
- const children = commitChildren(adapter, ret, ctx, scope, ret, 0, schedulePromises, hydrationMetaProp && !hydrationMetaProp.includes("children")
1048
+ const children = commitChildren(adapter, ret, ctx, scope, tag === Portal ? node : root, ret, 0, schedulePromises, hydrationMetaProp && !hydrationMetaProp.includes("children")
1037
1049
  ? undefined
1038
1050
  : childHydrationNodes);
1039
1051
  adapter.arrange({
@@ -1043,6 +1055,7 @@ function commitHost(adapter, ret, ctx, schedulePromises, hydrationNodes) {
1043
1055
  props,
1044
1056
  children,
1045
1057
  oldProps,
1058
+ root,
1046
1059
  });
1047
1060
  }
1048
1061
  ret.oldProps = props;
@@ -1143,10 +1156,10 @@ function flush(adapter, root, initiator) {
1143
1156
  }
1144
1157
  }
1145
1158
  }
1146
- function unmount(adapter, host, ctx, ret, isNested) {
1159
+ function unmount(adapter, host, ctx, root, ret, isNested) {
1147
1160
  // TODO: set the IsUnmounted flag consistently for all retainers
1148
1161
  if (ret.fallback) {
1149
- unmount(adapter, host, ctx, ret.fallback, isNested);
1162
+ unmount(adapter, host, ctx, root, ret.fallback, isNested);
1150
1163
  ret.fallback = undefined;
1151
1164
  }
1152
1165
  if (getFlag(ret, IsResurrecting)) {
@@ -1157,7 +1170,7 @@ function unmount(adapter, host, ctx, ret, isNested) {
1157
1170
  const lingerers = ret.lingerers[i];
1158
1171
  if (lingerers) {
1159
1172
  for (const lingerer of lingerers) {
1160
- unmount(adapter, host, ctx, lingerer, isNested);
1173
+ unmount(adapter, host, ctx, root, lingerer, isNested);
1161
1174
  }
1162
1175
  }
1163
1176
  }
@@ -1167,16 +1180,16 @@ function unmount(adapter, host, ctx, ret, isNested) {
1167
1180
  unmountComponent(ret.ctx, isNested);
1168
1181
  }
1169
1182
  else if (ret.el.tag === Fragment) {
1170
- unmountChildren(adapter, host, ctx, ret, isNested);
1183
+ unmountChildren(adapter, host, ctx, root, ret, isNested);
1171
1184
  }
1172
1185
  else if (ret.el.tag === Portal) {
1173
- unmountChildren(adapter, ret, ctx, ret, false);
1186
+ unmountChildren(adapter, ret, ctx, ret.value, ret, false);
1174
1187
  if (ret.value != null) {
1175
1188
  adapter.finalize(ret.value);
1176
1189
  }
1177
1190
  }
1178
1191
  else {
1179
- unmountChildren(adapter, ret, ctx, ret, true);
1192
+ unmountChildren(adapter, ret, ctx, root, ret, true);
1180
1193
  if (getFlag(ret, DidCommit)) {
1181
1194
  if (ctx) {
1182
1195
  // Remove the value from every context which shares the same host.
@@ -1186,22 +1199,23 @@ function unmount(adapter, host, ctx, ret, isNested) {
1186
1199
  node: ret.value,
1187
1200
  parentNode: host.value,
1188
1201
  isNested,
1202
+ root,
1189
1203
  });
1190
1204
  }
1191
1205
  }
1192
1206
  }
1193
- function unmountChildren(adapter, host, ctx, ret, isNested) {
1207
+ function unmountChildren(adapter, host, ctx, root, ret, isNested) {
1194
1208
  if (ret.graveyard) {
1195
1209
  for (let i = 0; i < ret.graveyard.length; i++) {
1196
1210
  const child = ret.graveyard[i];
1197
- unmount(adapter, host, ctx, child, isNested);
1211
+ unmount(adapter, host, ctx, root, child, isNested);
1198
1212
  }
1199
1213
  ret.graveyard = undefined;
1200
1214
  }
1201
1215
  for (let i = 0, children = _utils.wrap(ret.children); i < children.length; i++) {
1202
1216
  const child = children[i];
1203
1217
  if (typeof child === "object") {
1204
- unmount(adapter, host, ctx, child, isNested);
1218
+ unmount(adapter, host, ctx, root, child, isNested);
1205
1219
  }
1206
1220
  }
1207
1221
  }
@@ -1995,7 +2009,7 @@ function commitComponent(ctx, schedulePromises, hydrationNodes) {
1995
2009
  });
1996
2010
  return getValue(ctx.ret);
1997
2011
  }
1998
- const values = commitChildren(ctx.adapter, ctx.host, ctx, ctx.scope, ctx.ret, ctx.index, schedulePromises, hydrationNodes);
2012
+ const values = commitChildren(ctx.adapter, ctx.host, ctx, ctx.scope, ctx.root, ctx.ret, ctx.index, schedulePromises, hydrationNodes);
1999
2013
  if (getFlag(ctx.ret, IsUnmounted)) {
2000
2014
  return;
2001
2015
  }
@@ -2019,7 +2033,7 @@ function commitComponent(ctx, schedulePromises, hydrationNodes) {
2019
2033
  setFlag(ctx.ret, IsScheduling, wasScheduling);
2020
2034
  propagateComponent(ctx);
2021
2035
  if (ctx.ret.fallback) {
2022
- unmount(ctx.adapter, ctx.host, ctx.parent, ctx.ret.fallback, false);
2036
+ unmount(ctx.adapter, ctx.host, ctx.parent, ctx.root, ctx.ret.fallback, false);
2023
2037
  }
2024
2038
  ctx.ret.fallback = undefined;
2025
2039
  });
@@ -2045,7 +2059,7 @@ function commitComponent(ctx, schedulePromises, hydrationNodes) {
2045
2059
  propagateComponent(ctx);
2046
2060
  }
2047
2061
  if (ctx.ret.fallback) {
2048
- unmount(ctx.adapter, ctx.host, ctx.parent, ctx.ret.fallback, false);
2062
+ unmount(ctx.adapter, ctx.host, ctx.parent, ctx.root, ctx.ret.fallback, false);
2049
2063
  }
2050
2064
  ctx.ret.fallback = undefined;
2051
2065
  setFlag(ctx.ret, IsUpdating, false);
@@ -2111,6 +2125,7 @@ function propagateComponent(ctx) {
2111
2125
  props,
2112
2126
  oldProps: props,
2113
2127
  children: hostChildren,
2128
+ root: ctx.root,
2114
2129
  });
2115
2130
  flush(ctx.adapter, ctx.root, ctx);
2116
2131
  }
@@ -2165,7 +2180,7 @@ async function unmountComponent(ctx, isNested) {
2165
2180
  ctx.schedule = undefined;
2166
2181
  }
2167
2182
  eventTarget.clearEventListeners(ctx.ctx);
2168
- unmountChildren(ctx.adapter, ctx.host, ctx, ctx.ret, isNested);
2183
+ unmountChildren(ctx.adapter, ctx.host, ctx, ctx.root, ctx.ret, isNested);
2169
2184
  if (didLinger) {
2170
2185
  // If we lingered, we call finalize to ensure rendering is finalized
2171
2186
  if (ctx.root != null) {