@doenet/v06-to-v07 0.7.26-dev.581 → 0.7.26-dev.582

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.
@@ -47916,7 +47916,7 @@ async function cidFromArrayBuffer(data) {
47916
47916
  await crypto.subtle.digest("SHA-256", new Uint8Array());
47917
47917
  digest = (data2) => crypto.subtle.digest("SHA-256", data2);
47918
47918
  } catch (e22) {
47919
- const sha256 = (await import("./sha256-8sXzDnE0-CGiFZhfh-BBk7ox76.js").then((n2) => n2.s)).default;
47919
+ const sha256 = (await import("./sha256-8sXzDnE0-CfHuPfKu-CMZLq65_.js").then((n2) => n2.s)).default;
47920
47920
  digest = (data2) => sha256(data2, {
47921
47921
  asBytes: true
47922
47922
  });
@@ -56639,21 +56639,25 @@ async function addReplacementsToResolver({
56639
56639
  updateOldReplacementsEnd,
56640
56640
  blankStringReplacements
56641
56641
  });
56642
+ const fragmentParent = replacementActingAsFragmentParent(
56643
+ serializedReplacements,
56644
+ component
56645
+ );
56642
56646
  const fragmentChildren = [];
56643
56647
  let parentSourceSequence = null;
56644
- if (component.attributes.createComponentIdx != null) {
56645
- if (serializedReplacements[0]?.children) {
56646
- fragmentChildren.push(...serializedReplacements[0].children);
56648
+ if (fragmentParent) {
56649
+ if (fragmentParent.children) {
56650
+ fragmentChildren.push(...fragmentParent.children);
56647
56651
  }
56648
- for (const attrName in serializedReplacements[0]?.attributes) {
56649
- const attribute = serializedReplacements[0].attributes[attrName];
56652
+ for (const attrName in fragmentParent.attributes) {
56653
+ const attribute = fragmentParent.attributes[attrName];
56650
56654
  if (attribute.type === "component") {
56651
56655
  fragmentChildren.push(attribute.component);
56652
56656
  } else if (attribute.type === "references") {
56653
56657
  fragmentChildren.push(...attribute.references);
56654
56658
  }
56655
56659
  }
56656
- let sourceSequence = serializedReplacements[0]?.attributes["source:sequence"];
56660
+ let sourceSequence = fragmentParent.attributes["source:sequence"];
56657
56661
  const createComponentIdxPrimitive = component.attributes.createComponentIdx?.primitive;
56658
56662
  if (sourceSequence && createComponentIdxPrimitive?.type === "number") {
56659
56663
  parentSourceSequence = {
@@ -56698,6 +56702,17 @@ async function addReplacementsToResolver({
56698
56702
  }
56699
56703
  }
56700
56704
  }
56705
+ function replacementActingAsFragmentParent(serializedReplacements, component) {
56706
+ const createComponentIdx = component.attributes.createComponentIdx?.primitive?.value;
56707
+ if (createComponentIdx == null || serializedReplacements.length !== 1) {
56708
+ return null;
56709
+ }
56710
+ const replacement = serializedReplacements[0];
56711
+ if (typeof replacement !== "object" || replacement === null || getEffectiveComponentIdx(replacement) !== createComponentIdx) {
56712
+ return null;
56713
+ }
56714
+ return replacement;
56715
+ }
56701
56716
  async function determineParentAndIndexResolutionForResolver({
56702
56717
  core: core2,
56703
56718
  component,
@@ -57226,16 +57241,11 @@ async function expandCompositeComponent({
57226
57241
  }
57227
57242
  if (result2.replacements) {
57228
57243
  let serializedReplacements = result2.replacements;
57229
- await addReplacementsToResolver({
57230
- core: core2,
57231
- serializedReplacements,
57232
- component
57233
- });
57234
- reserveComponentIndices(core2, newNComponents);
57235
57244
  await createAndSetReplacements({
57236
57245
  core: core2,
57237
57246
  component,
57238
- serializedReplacements
57247
+ serializedReplacements,
57248
+ newNComponents
57239
57249
  });
57240
57250
  } else {
57241
57251
  throw Error(
@@ -57424,16 +57434,11 @@ async function expandShadowingComposite({
57424
57434
  );
57425
57435
  }
57426
57436
  component.replacementsWorkspace.replacementsCreated = stateIdInfo.num;
57427
- await addReplacementsToResolver({
57428
- core: core2,
57429
- serializedReplacements,
57430
- component
57431
- });
57432
- reserveComponentIndices(core2, newNComponents);
57433
57437
  await createAndSetReplacements({
57434
57438
  core: core2,
57435
57439
  component,
57436
- serializedReplacements
57440
+ serializedReplacements,
57441
+ newNComponents
57437
57442
  });
57438
57443
  if (shadowedComposite.replacementsToWithhold > 0) {
57439
57444
  component.replacementsToWithhold = shadowedComposite.replacementsToWithhold;
@@ -57482,30 +57487,49 @@ function adjustForCreateComponentIdxName({
57482
57487
  async function createAndSetReplacements({
57483
57488
  core: core2,
57484
57489
  component,
57485
- serializedReplacements
57490
+ serializedReplacements,
57491
+ newNComponents
57486
57492
  }) {
57487
- core2.parameterStack.push(component.sharedParameters, false);
57493
+ reserveComponentIndices(core2, newNComponents);
57494
+ let registrationFailure = null;
57488
57495
  try {
57489
- let replacementResult = await createIsolatedComponents({
57496
+ await addReplacementsToResolver({
57490
57497
  core: core2,
57491
- serializedComponents: serializedReplacements,
57492
- ancestors: component.ancestors,
57493
- shadow: true,
57494
- componentsReplacementOf: component
57498
+ serializedReplacements,
57499
+ component
57495
57500
  });
57496
- component.replacements = replacementResult.components;
57497
57501
  } catch (e32) {
57498
- console.error(e32);
57499
- component.replacements = await core2.setErrorReplacements({
57500
- composite: component,
57501
- message: e32.message,
57502
- source: e32
57503
- });
57502
+ registrationFailure = e32;
57503
+ }
57504
+ core2.parameterStack.push(component.sharedParameters, false);
57505
+ if (registrationFailure) {
57506
+ await setReplacementsToError(core2, component, registrationFailure);
57507
+ } else {
57508
+ try {
57509
+ let replacementResult = await createIsolatedComponents({
57510
+ core: core2,
57511
+ serializedComponents: serializedReplacements,
57512
+ ancestors: component.ancestors,
57513
+ shadow: true,
57514
+ componentsReplacementOf: component
57515
+ });
57516
+ component.replacements = replacementResult.components;
57517
+ } catch (e32) {
57518
+ await setReplacementsToError(core2, component, e32);
57519
+ }
57504
57520
  }
57505
57521
  core2.parameterStack.pop();
57506
57522
  await core2.dependencies.addBlockersFromChangedReplacements(component);
57507
57523
  component.isExpanded = true;
57508
57524
  }
57525
+ async function setReplacementsToError(core2, component, e32) {
57526
+ console.error(e32);
57527
+ component.replacements = await core2.setErrorReplacements({
57528
+ composite: component,
57529
+ message: e32.message,
57530
+ source: e32
57531
+ });
57532
+ }
57509
57533
  async function replaceCompositeChildren({
57510
57534
  core: core2,
57511
57535
  parent
@@ -70179,18 +70203,18 @@ class CompositeReplacementUpdater {
70179
70203
  overwriteDoenetMLRange
70180
70204
  });
70181
70205
  const newNComponents = change.nComponents;
70182
- await addReplacementsToResolver({
70183
- core: this.core,
70184
- serializedReplacements,
70185
- component,
70186
- updateOldReplacementsStart,
70187
- updateOldReplacementsEnd,
70188
- blankStringReplacements
70189
- });
70190
70206
  if (newNComponents > this.core._components.length) {
70191
70207
  this.core._components[newNComponents - 1] = void 0;
70192
70208
  }
70193
70209
  try {
70210
+ await addReplacementsToResolver({
70211
+ core: this.core,
70212
+ serializedReplacements,
70213
+ component,
70214
+ updateOldReplacementsStart,
70215
+ updateOldReplacementsEnd,
70216
+ blankStringReplacements
70217
+ });
70194
70218
  const createResult = await createIsolatedComponents({
70195
70219
  core: this.core,
70196
70220
  serializedComponents: serializedReplacements,
@@ -70385,7 +70409,18 @@ class CompositeReplacementUpdater {
70385
70409
  };
70386
70410
  return results;
70387
70411
  }
70388
- async setErrorReplacements({
70412
+ /**
70413
+ * Report `message` against `composite` and stop the composite being
70414
+ * updated again.
70415
+ *
70416
+ * This is the half of `setErrorReplacements` that does not touch the
70417
+ * composite's replacements, for the caller that has nowhere to put an
70418
+ * `_error` component: a composite that fails partway through *changing*
70419
+ * its replacements already has some, and the machinery that would splice
70420
+ * new ones in is the machinery that just failed. Reporting and standing
70421
+ * still leaves the reader the page and the message.
70422
+ */
70423
+ markCompositeInError({
70389
70424
  composite,
70390
70425
  message,
70391
70426
  source
@@ -70397,6 +70432,14 @@ class CompositeReplacementUpdater {
70397
70432
  position: composite.position,
70398
70433
  sourceDoc: composite.sourceDoc
70399
70434
  });
70435
+ composite.isInErrorState = true;
70436
+ }
70437
+ async setErrorReplacements({
70438
+ composite,
70439
+ message,
70440
+ source
70441
+ }) {
70442
+ this.markCompositeInError({ composite, message, source });
70400
70443
  let errorReplacements = [
70401
70444
  {
70402
70445
  type: "serialized",
@@ -70413,7 +70456,6 @@ class CompositeReplacementUpdater {
70413
70456
  }
70414
70457
  ];
70415
70458
  this.core._components[this.core._components.length] = void 0;
70416
- composite.isInErrorState = true;
70417
70459
  let createResult = await createIsolatedComponents({
70418
70460
  core: this.core,
70419
70461
  serializedComponents: errorReplacements,
@@ -70635,35 +70677,36 @@ class CompositeReplacementUpdater {
70635
70677
  serializedReplacements: newSerializedReplacements,
70636
70678
  composite: shadowingComponent
70637
70679
  });
70638
- await addReplacementsToResolver({
70639
- core: this.core,
70640
- serializedReplacements: newSerializedReplacements,
70641
- component: shadowingComponent,
70642
- updateOldReplacementsStart,
70643
- updateOldReplacementsEnd,
70644
- blankStringReplacements
70645
- });
70646
70680
  if (newNComponents > this.core._components.length) {
70647
70681
  this.core._components[newNComponents - 1] = void 0;
70648
70682
  }
70649
- newSerializedReplacements = postProcessCopy({
70650
- serializedComponents: newSerializedReplacements,
70651
- componentIdx: shadowingComponent.shadows.compositeIdx
70652
- });
70653
- if (shadowingComponent.attributes.isResponse) {
70654
- let compositeAttributesObj = preprocessAttributesObject(
70655
- shadowingComponent.constructor.createAttributesObject()
70656
- );
70657
- for (let repl of newSerializedReplacements) {
70658
- if (typeof repl !== "object") {
70659
- continue;
70660
- }
70661
- if (!repl.attributes) {
70662
- repl.attributes = {};
70663
- }
70664
- let nComponents2 = this.core._components.length;
70665
- const res = convertUnresolvedAttributesForComponentType(
70666
- {
70683
+ let registrationFailure = null;
70684
+ try {
70685
+ await addReplacementsToResolver({
70686
+ core: this.core,
70687
+ serializedReplacements: newSerializedReplacements,
70688
+ component: shadowingComponent,
70689
+ updateOldReplacementsStart,
70690
+ updateOldReplacementsEnd,
70691
+ blankStringReplacements
70692
+ });
70693
+ newSerializedReplacements = postProcessCopy({
70694
+ serializedComponents: newSerializedReplacements,
70695
+ componentIdx: shadowingComponent.shadows.compositeIdx
70696
+ });
70697
+ if (shadowingComponent.attributes.isResponse) {
70698
+ let compositeAttributesObj = preprocessAttributesObject(
70699
+ shadowingComponent.constructor.createAttributesObject()
70700
+ );
70701
+ for (let repl of newSerializedReplacements) {
70702
+ if (typeof repl !== "object") {
70703
+ continue;
70704
+ }
70705
+ if (!repl.attributes) {
70706
+ repl.attributes = {};
70707
+ }
70708
+ let nComponents2 = this.core._components.length;
70709
+ const res = convertUnresolvedAttributesForComponentType({
70667
70710
  attributes: {
70668
70711
  isResponse: shadowingComponent.attributes.isResponse
70669
70712
  },
@@ -70671,15 +70714,20 @@ class CompositeReplacementUpdater {
70671
70714
  componentInfoObjects: this.core.componentInfoObjects,
70672
70715
  compositeAttributesObj,
70673
70716
  nComponents: nComponents2
70717
+ });
70718
+ const attributesFromComposite = res.attributes;
70719
+ nComponents2 = res.nComponents;
70720
+ if (nComponents2 > this.core._components.length) {
70721
+ this.core._components[nComponents2 - 1] = void 0;
70674
70722
  }
70675
- );
70676
- const attributesFromComposite = res.attributes;
70677
- nComponents2 = res.nComponents;
70678
- if (nComponents2 > this.core._components.length) {
70679
- this.core._components[nComponents2 - 1] = void 0;
70723
+ Object.assign(
70724
+ repl.attributes,
70725
+ attributesFromComposite
70726
+ );
70680
70727
  }
70681
- Object.assign(repl.attributes, attributesFromComposite);
70682
70728
  }
70729
+ } catch (e32) {
70730
+ registrationFailure = e32;
70683
70731
  }
70684
70732
  let newComponents;
70685
70733
  let unproxiedShadowingComponent = this.core._components[shadowingComponent.componentIdx];
@@ -70687,21 +70735,30 @@ class CompositeReplacementUpdater {
70687
70735
  unproxiedShadowingComponent.sharedParameters,
70688
70736
  false
70689
70737
  );
70690
- try {
70691
- let createResult = await createIsolatedComponents({
70692
- core: this.core,
70693
- serializedComponents: newSerializedReplacements,
70694
- ancestors: shadowingComponent.ancestors,
70695
- componentsReplacementOf: shadowingComponent
70696
- });
70697
- newComponents = createResult.components;
70698
- } catch (e32) {
70699
- console.error(e32);
70738
+ if (registrationFailure) {
70739
+ console.error(registrationFailure);
70700
70740
  newComponents = await this.setErrorReplacements({
70701
70741
  composite: shadowingComponent,
70702
- message: e32.message,
70703
- source: e32
70742
+ message: registrationFailure.message,
70743
+ source: registrationFailure
70704
70744
  });
70745
+ } else {
70746
+ try {
70747
+ let createResult = await createIsolatedComponents({
70748
+ core: this.core,
70749
+ serializedComponents: newSerializedReplacements,
70750
+ ancestors: shadowingComponent.ancestors,
70751
+ componentsReplacementOf: shadowingComponent
70752
+ });
70753
+ newComponents = createResult.components;
70754
+ } catch (e32) {
70755
+ console.error(e32);
70756
+ newComponents = await this.setErrorReplacements({
70757
+ composite: shadowingComponent,
70758
+ message: e32.message,
70759
+ source: e32
70760
+ });
70761
+ }
70705
70762
  }
70706
70763
  this.core.parameterStack.pop();
70707
70764
  let shadowingParent;
@@ -70806,41 +70863,54 @@ class CompositeReplacementUpdater {
70806
70863
  componentChanges.push(newChange);
70807
70864
  }
70808
70865
  if (adjustResolver) {
70809
- const blankStringReplacements = component.replacements.map(
70810
- (repl) => typeof repl === "string" && repl.trim() === ""
70811
- );
70812
- const { indexResolution } = await determineParentAndIndexResolutionForResolver({
70813
- core: this.core,
70814
- component,
70815
- updateOldReplacementsStart: 0,
70816
- updateOldReplacementsEnd: component.replacements.length - (component.replacementsToWithhold ?? 0),
70817
- blankStringReplacements
70818
- });
70819
- let indexParent = indexResolution.ReplaceAll?.parent ?? indexResolution.ReplaceRange?.parent ?? null;
70820
- if (indexParent !== null && indexParent !== component.componentIdx) {
70821
- const indexParentComposite = this.core._components[indexParent];
70822
- if (indexParentComposite) {
70823
- if (this.core.replaceIndexResolutionsInResolver) {
70824
- const newContentForIndex = component.replacements.slice(
70825
- 0,
70826
- component.replacements.length - change.replacementsToWithhold
70827
- ).map((repl) => {
70828
- if (typeof repl === "string") {
70829
- return repl;
70830
- } else {
70831
- return repl.componentIdx;
70832
- }
70833
- });
70834
- this.core.replaceIndexResolutionsInResolver(
70835
- { content: newContentForIndex },
70836
- indexResolution
70837
- );
70838
- this.core.rootNames = this.core.calculateRootNames?.().names;
70839
- await this.core.dependencies.addBlockersFromChangedReplacements(
70840
- indexParentComposite
70841
- );
70866
+ let indexParentComposite = null;
70867
+ try {
70868
+ const blankStringReplacements = component.replacements.map(
70869
+ (repl) => typeof repl === "string" && repl.trim() === ""
70870
+ );
70871
+ const { indexResolution } = await determineParentAndIndexResolutionForResolver({
70872
+ core: this.core,
70873
+ component,
70874
+ updateOldReplacementsStart: 0,
70875
+ updateOldReplacementsEnd: component.replacements.length - (component.replacementsToWithhold ?? 0),
70876
+ blankStringReplacements
70877
+ });
70878
+ let indexParent = indexResolution.ReplaceAll?.parent ?? indexResolution.ReplaceRange?.parent ?? null;
70879
+ if (indexParent !== null && indexParent !== component.componentIdx) {
70880
+ const candidate = this.core._components[indexParent];
70881
+ if (candidate) {
70882
+ if (this.core.replaceIndexResolutionsInResolver) {
70883
+ const newContentForIndex = component.replacements.slice(
70884
+ 0,
70885
+ component.replacements.length - change.replacementsToWithhold
70886
+ ).map((repl) => {
70887
+ if (typeof repl === "string") {
70888
+ return repl;
70889
+ } else {
70890
+ return repl.componentIdx;
70891
+ }
70892
+ });
70893
+ this.core.replaceIndexResolutionsInResolver(
70894
+ { content: newContentForIndex },
70895
+ indexResolution
70896
+ );
70897
+ this.core.rootNames = this.core.calculateRootNames?.().names;
70898
+ indexParentComposite = candidate;
70899
+ }
70842
70900
  }
70843
70901
  }
70902
+ } catch (e32) {
70903
+ console.error(e32);
70904
+ this.markCompositeInError({
70905
+ composite: component,
70906
+ message: e32.message,
70907
+ source: e32
70908
+ });
70909
+ }
70910
+ if (indexParentComposite) {
70911
+ await this.core.dependencies.addBlockersFromChangedReplacements(
70912
+ indexParentComposite
70913
+ );
70844
70914
  }
70845
70915
  }
70846
70916
  component.replacementsToWithhold = replacementsToWithhold;
@@ -70848,6 +70918,9 @@ class CompositeReplacementUpdater {
70848
70918
  component
70849
70919
  );
70850
70920
  for (const shadowingComponent of iterateExpandableShadows(component)) {
70921
+ if (!shadowingComponent.isExpanded) {
70922
+ continue;
70923
+ }
70851
70924
  await this.adjustReplacementsToWithhold({
70852
70925
  component: shadowingComponent,
70853
70926
  change,
@@ -248702,4 +248775,4 @@ export {
248702
248775
  getDefaultExportFromCjs$1 as g,
248703
248776
  updateSyntaxFromV06toV07 as u
248704
248777
  };
248705
- //# sourceMappingURL=index-DGyduyFg.js.map
248778
+ //# sourceMappingURL=index-DAy9ScBT.js.map