@doenet/v06-to-v07 0.7.26-dev.547 → 0.7.26-dev.548

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.
@@ -47285,7 +47285,7 @@ async function cidFromArrayBuffer(data) {
47285
47285
  await crypto.subtle.digest("SHA-256", new Uint8Array());
47286
47286
  digest = (data2) => crypto.subtle.digest("SHA-256", data2);
47287
47287
  } catch (e22) {
47288
- const sha256 = (await import("./sha256-DT5xJ2Hv-B3IOSUHf-IZrBz-rp.js").then((n2) => n2.s)).default;
47288
+ const sha256 = (await import("./sha256-DT5xJ2Hv-BG3R96t1-BIoU3hjd.js").then((n2) => n2.s)).default;
47289
47289
  digest = (data2) => sha256(data2, {
47290
47290
  asBytes: true
47291
47291
  });
@@ -91167,8 +91167,33 @@ function returnBreakStringsIntoTypeSugarInstruction(componentName) {
91167
91167
  }
91168
91168
  return { replacementFunction: breakStringsMacrosIntoTypeBySpaces };
91169
91169
  }
91170
- function diagnosticsForNoIndex(result2, componentType) {
91171
- switch (result2.reason) {
91170
+ function returnListTypeAttribute({ readsTarget = false } = {}) {
91171
+ return {
91172
+ createPrimitiveOfType: "string",
91173
+ description: readsTarget ? "Component type to interpret bare string children as. Also decides how a `target` is read, since it has no type of its own." : "Component type to interpret bare string children as.",
91174
+ highlighted: true,
91175
+ validValues: [
91176
+ {
91177
+ value: "number",
91178
+ description: "Read bare strings as numbers, ordered by value."
91179
+ },
91180
+ {
91181
+ value: "math",
91182
+ description: "Read bare strings as math expressions, ordered by value."
91183
+ },
91184
+ {
91185
+ value: "text",
91186
+ description: "Read bare strings as text, ordered alphabetically."
91187
+ },
91188
+ {
91189
+ value: "boolean",
91190
+ description: "Read bare strings as booleans, ordered with false before true."
91191
+ }
91192
+ ]
91193
+ };
91194
+ }
91195
+ function diagnosticsForNoIndex(reason, componentType) {
91196
+ switch (reason) {
91172
91197
  case "noTarget":
91173
91198
  return [
91174
91199
  codedDiagnostic({
@@ -91189,6 +91214,67 @@ function diagnosticsForNoIndex(result2, componentType) {
91189
91214
  return [];
91190
91215
  }
91191
91216
  }
91217
+ function diagnosticsForNoIndices(results, componentType) {
91218
+ const reasons = /* @__PURE__ */ new Set();
91219
+ for (const result2 of results) {
91220
+ if (result2?.reason) {
91221
+ reasons.add(result2.reason);
91222
+ }
91223
+ }
91224
+ return [...reasons].flatMap(
91225
+ (reason) => diagnosticsForNoIndex(reason, componentType)
91226
+ );
91227
+ }
91228
+ function returnTargetAttribute(description) {
91229
+ return {
91230
+ createComponentOfType: "_componentListWithSelectableType",
91231
+ description,
91232
+ highlighted: true
91233
+ };
91234
+ }
91235
+ function returnComparableTargetsStateVariableDefinition() {
91236
+ return {
91237
+ comparableTargets: {
91238
+ returnDependencies: () => ({
91239
+ targetAttr: {
91240
+ dependencyType: "attributeComponent",
91241
+ attributeName: "target",
91242
+ variableNames: ["values"]
91243
+ }
91244
+ }),
91245
+ definition({ dependencyValues }) {
91246
+ if (dependencyValues.targetAttr === null) {
91247
+ return { setValue: { comparableTargets: null } };
91248
+ }
91249
+ return {
91250
+ setValue: {
91251
+ comparableTargets: dependencyValues.targetAttr.stateValues.values.map(
91252
+ comparableValueFromRaw
91253
+ )
91254
+ }
91255
+ };
91256
+ }
91257
+ }
91258
+ };
91259
+ }
91260
+ function locateEachTarget({ values: values2, targets, numeric: numeric2, locate }) {
91261
+ if (targets === null) {
91262
+ return [{ index: 0, reason: "noTarget" }];
91263
+ }
91264
+ return targets.map((target) => {
91265
+ if (target === null) {
91266
+ return { index: 0, reason: "noTarget" };
91267
+ }
91268
+ if (values2.length === 0) {
91269
+ return { index: 0, reason: "noValues" };
91270
+ }
91271
+ return locate({
91272
+ values: values2,
91273
+ target,
91274
+ numeric: numeric2 && target.isNumeric
91275
+ });
91276
+ });
91277
+ }
91192
91278
  class ListIndexBaseOperator extends MathComponent {
91193
91279
  static componentType = "_listIndexOperator";
91194
91280
  static rendererType = "math";
@@ -91197,29 +91283,7 @@ class ListIndexBaseOperator extends MathComponent {
91197
91283
  static descendantCompositesMustHaveAReplacement = false;
91198
91284
  static createAttributesObject() {
91199
91285
  let attributes = super.createAttributesObject();
91200
- attributes.type = {
91201
- createPrimitiveOfType: "string",
91202
- description: "Component type to interpret bare string children as. Also decides how a `target` is read, since it has no type of its own.",
91203
- highlighted: true,
91204
- validValues: [
91205
- {
91206
- value: "number",
91207
- description: "Read bare strings as numbers, ordered by value."
91208
- },
91209
- {
91210
- value: "math",
91211
- description: "Read bare strings as math expressions, ordered by value."
91212
- },
91213
- {
91214
- value: "text",
91215
- description: "Read bare strings as text, ordered alphabetically."
91216
- },
91217
- {
91218
- value: "boolean",
91219
- description: "Read bare strings as booleans, ordered with false before true."
91220
- }
91221
- ]
91222
- };
91286
+ attributes.type = returnListTypeAttribute();
91223
91287
  for (const attrName of ["format", "simplify", "displayDigits"]) {
91224
91288
  if (attributes[attrName]) {
91225
91289
  const { highlighted: _highlighted, ...rest2 } = attributes[attrName];
@@ -91301,11 +91365,10 @@ class ListIndexBaseOperator extends MathComponent {
91301
91365
  values: dependencyValues.listValues,
91302
91366
  numeric: dependencyValues.allAreNumeric
91303
91367
  });
91304
- const index2 = result2.index;
91305
91368
  return {
91306
- setValue: { unnormalizedValue: Context.fromAst(index2) },
91369
+ setValue: { unnormalizedValue: Context.fromAst(result2.index) },
91307
91370
  sendDiagnostics: diagnosticsForNoIndex(
91308
- result2,
91371
+ result2.reason,
91309
91372
  componentType
91310
91373
  )
91311
91374
  };
@@ -91314,50 +91377,167 @@ class ListIndexBaseOperator extends MathComponent {
91314
91377
  return stateVariableDefinitions;
91315
91378
  }
91316
91379
  }
91317
- function returnTargetAttribute(description) {
91318
- return {
91319
- createComponentOfType: "_componentWithSelectableType",
91320
- createStateVariable: "target",
91321
- defaultValue: null,
91322
- description,
91323
- highlighted: true
91324
- };
91325
- }
91326
- function returnTargetStateVariableDefinition() {
91327
- return {
91328
- comparableTarget: {
91380
+ class ListIndexBaseListOperator extends CompositeComponent {
91381
+ static componentType = "_listIndexListOperator";
91382
+ static takesIndex = true;
91383
+ static stateVariableToEvaluateAfterReplacements = "readyToExpandWhenResolved";
91384
+ static allowInSchemaAsComponent = ["math"];
91385
+ // Since the operator treats each child as a separate argument,
91386
+ // composites with no replacement should be ignored.
91387
+ static descendantCompositesMustHaveAReplacement = false;
91388
+ // The reference pages show this text, and the two operators do not mean
91389
+ // the same thing by `target`: `<indexOf>` looks its target up in the list,
91390
+ // which is the wording below, while `<searchSorted>` places a target that
91391
+ // need not be in the list at all and overrides it.
91392
+ static targetDescription = "The value, or list of values, to look for.";
91393
+ static createAttributesObject() {
91394
+ let attributes = super.createAttributesObject();
91395
+ attributes.type = {
91396
+ ...returnListTypeAttribute({ readsTarget: true }),
91397
+ createStateVariable: "type",
91398
+ defaultValue: null
91399
+ };
91400
+ attributes.target = returnTargetAttribute(this.targetDescription);
91401
+ Object.assign(attributes, returnPassThroughAttributeDeclarations());
91402
+ attributes.asList = {
91403
+ createPrimitiveOfType: "boolean",
91404
+ createStateVariable: "asList",
91405
+ defaultValue: true,
91406
+ highlighted: true,
91407
+ description: "Whether to render the items separated by commas (true) or with no separator (false)."
91408
+ };
91409
+ return attributes;
91410
+ }
91411
+ // Include children that can be added due to sugar
91412
+ static additionalSchemaChildren = ["string"];
91413
+ static returnSugarInstructions() {
91414
+ let sugarInstructions = super.returnSugarInstructions();
91415
+ sugarInstructions.push(
91416
+ returnBreakStringsIntoTypeSugarInstruction(this.componentType)
91417
+ );
91418
+ return sugarInstructions;
91419
+ }
91420
+ static returnChildGroups() {
91421
+ return [
91422
+ {
91423
+ group: "anything",
91424
+ componentTypes: ["_base"]
91425
+ }
91426
+ ];
91427
+ }
91428
+ static returnStateVariableDefinitions() {
91429
+ let stateVariableDefinitions = super.returnStateVariableDefinitions();
91430
+ const componentType = this.componentType;
91431
+ Object.assign(
91432
+ stateVariableDefinitions,
91433
+ returnListValueStateVariableDefinitions({
91434
+ componentName: this.componentType,
91435
+ supportProps: false
91436
+ }),
91437
+ returnComparableTargetsStateVariableDefinition()
91438
+ );
91439
+ stateVariableDefinitions.locate = {
91440
+ returnDependencies: () => ({}),
91441
+ definition: () => ({
91442
+ setValue: { locate: () => ({ index: 0 }) }
91443
+ })
91444
+ };
91445
+ stateVariableDefinitions.operatorResults = {
91329
91446
  returnDependencies: () => ({
91330
- target: {
91447
+ listValues: {
91331
91448
  dependencyType: "stateVariable",
91332
- variableName: "target"
91449
+ variableName: "listValues"
91450
+ },
91451
+ allAreNumeric: {
91452
+ dependencyType: "stateVariable",
91453
+ variableName: "allAreNumeric"
91454
+ },
91455
+ comparableTargets: {
91456
+ dependencyType: "stateVariable",
91457
+ variableName: "comparableTargets"
91458
+ },
91459
+ locate: {
91460
+ dependencyType: "stateVariable",
91461
+ variableName: "locate"
91333
91462
  }
91334
91463
  }),
91335
91464
  definition({ dependencyValues }) {
91465
+ const results = locateEachTarget({
91466
+ values: dependencyValues.listValues,
91467
+ targets: dependencyValues.comparableTargets,
91468
+ numeric: dependencyValues.allAreNumeric,
91469
+ locate: dependencyValues.locate
91470
+ });
91336
91471
  return {
91337
91472
  setValue: {
91338
- comparableTarget: comparableValueFromRaw(
91339
- dependencyValues.target
91473
+ operatorResults: results.map(
91474
+ (result2) => Context.fromAst(result2.index)
91340
91475
  )
91341
- }
91476
+ },
91477
+ sendDiagnostics: diagnosticsForNoIndices(
91478
+ results,
91479
+ componentType
91480
+ )
91342
91481
  };
91343
91482
  }
91344
- }
91345
- };
91346
- }
91347
- function returnTargetSearchingIndexOperator(target, locate) {
91348
- return ({ values: values2, numeric: numeric2 }) => {
91349
- if (target === null) {
91350
- return { index: 0, reason: "noTarget" };
91351
- }
91352
- if (values2.length === 0) {
91353
- return { index: 0, reason: "noValues" };
91354
- }
91355
- return locate({
91356
- values: values2,
91357
- target,
91358
- numeric: numeric2 && target.isNumeric
91483
+ };
91484
+ stateVariableDefinitions.readyToExpandWhenResolved = {
91485
+ returnDependencies: () => ({
91486
+ operatorResults: {
91487
+ dependencyType: "stateVariable",
91488
+ variableName: "operatorResults"
91489
+ }
91490
+ }),
91491
+ // When this state variable is marked stale it indicates we should
91492
+ // update replacements. For this to work, we must get its value in
91493
+ // the replacement functions so that the variable is marked fresh.
91494
+ markStale: () => ({ updateReplacements: true }),
91495
+ definition: function() {
91496
+ return { setValue: { readyToExpandWhenResolved: true } };
91497
+ }
91498
+ };
91499
+ return stateVariableDefinitions;
91500
+ }
91501
+ static async createSerializedReplacements({
91502
+ component,
91503
+ componentInfoObjects: componentInfoObjects2,
91504
+ workspace,
91505
+ nComponents
91506
+ }) {
91507
+ return createValueListReplacements({
91508
+ component,
91509
+ values: await component.stateValues.operatorResults,
91510
+ componentType: "math",
91511
+ attributesToConvert: returnPassThroughAttributes(component),
91512
+ componentInfoObjects: componentInfoObjects2,
91513
+ workspace,
91514
+ nComponents
91359
91515
  });
91360
- };
91516
+ }
91517
+ static async calculateReplacementChanges({
91518
+ component,
91519
+ componentInfoObjects: componentInfoObjects2,
91520
+ workspace,
91521
+ nComponents
91522
+ }) {
91523
+ return calculateValueListReplacementChanges({
91524
+ component,
91525
+ values: await component.stateValues.operatorResults,
91526
+ componentType: "math",
91527
+ attributesToConvert: returnPassThroughAttributes(component),
91528
+ componentInfoObjects: componentInfoObjects2,
91529
+ workspace,
91530
+ nComponents
91531
+ });
91532
+ }
91533
+ addOwnPotentialRendererTypes(rendererTypes, visited) {
91534
+ super.addOwnPotentialRendererTypes(rendererTypes, visited);
91535
+ addReplacementRendererType({
91536
+ component: this,
91537
+ componentType: "math",
91538
+ rendererTypes
91539
+ });
91540
+ }
91361
91541
  }
91362
91542
  function returnConstantIndexOperatorDefinition(indexOperator) {
91363
91543
  return {
@@ -91365,22 +91545,13 @@ function returnConstantIndexOperatorDefinition(indexOperator) {
91365
91545
  definition: () => ({ setValue: { indexOperator } })
91366
91546
  };
91367
91547
  }
91368
- function returnTargetSearchingIndexOperatorDefinition(locate, extraDependencies = {}) {
91548
+ function returnLocateDefinition(locate, extraDependencies = {}) {
91369
91549
  return {
91370
- returnDependencies: () => ({
91371
- comparableTarget: {
91372
- dependencyType: "stateVariable",
91373
- variableName: "comparableTarget"
91374
- },
91375
- ...extraDependencies
91376
- }),
91550
+ returnDependencies: () => ({ ...extraDependencies }),
91377
91551
  definition({ dependencyValues }) {
91378
91552
  return {
91379
91553
  setValue: {
91380
- indexOperator: returnTargetSearchingIndexOperator(
91381
- dependencyValues.comparableTarget,
91382
- (args) => locate({ ...args, dependencyValues })
91383
- )
91554
+ locate: (args) => locate({ ...args, dependencyValues })
91384
91555
  }
91385
91556
  };
91386
91557
  }
@@ -91429,49 +91600,32 @@ class ArgMax extends ListIndexBaseOperator {
91429
91600
  });
91430
91601
  }
91431
91602
  }
91432
- class IndexOf extends ListIndexBaseOperator {
91603
+ class IndexOf extends ListIndexBaseListOperator {
91433
91604
  static componentType = "indexOf";
91434
91605
  static componentDocs = {
91435
- summary: "The index of the first value in a list equal to a target, or 0 if there is none"
91606
+ summary: "The index of the first value in a list equal to each target, or 0 where there is none"
91436
91607
  };
91437
- static createAttributesObject() {
91438
- let attributes = super.createAttributesObject();
91439
- attributes.target = returnTargetAttribute("The value to look for.");
91440
- return attributes;
91441
- }
91442
91608
  static returnStateVariableDefinitions() {
91443
- return Object.assign(
91444
- super.returnStateVariableDefinitions(),
91445
- returnTargetStateVariableDefinition(),
91446
- {
91447
- indexOperator: returnTargetSearchingIndexOperatorDefinition(
91448
- ({ values: values2, target, numeric: numeric2 }) => {
91449
- for (let [ind, value] of values2.entries()) {
91450
- if (compareExtractedValues(
91451
- value,
91452
- target,
91453
- numeric2
91454
- ) === 0) {
91455
- return { index: ind + 1 };
91456
- }
91457
- }
91458
- return { index: 0 };
91609
+ return Object.assign(super.returnStateVariableDefinitions(), {
91610
+ locate: returnLocateDefinition(({ values: values2, target, numeric: numeric2 }) => {
91611
+ for (let [ind, value] of values2.entries()) {
91612
+ if (compareExtractedValues(value, target, numeric2) === 0) {
91613
+ return { index: ind + 1 };
91459
91614
  }
91460
- )
91461
- }
91462
- );
91615
+ }
91616
+ return { index: 0 };
91617
+ })
91618
+ });
91463
91619
  }
91464
91620
  }
91465
- class SearchSorted extends ListIndexBaseOperator {
91621
+ class SearchSorted extends ListIndexBaseListOperator {
91466
91622
  static componentType = "searchSorted";
91467
91623
  static componentDocs = {
91468
- summary: "The position at which a target would be inserted to keep a sorted list sorted"
91624
+ summary: "The position at which each target would be inserted to keep a sorted list sorted"
91469
91625
  };
91626
+ static targetDescription = "The value, or list of values, to locate within the sorted list.";
91470
91627
  static createAttributesObject() {
91471
91628
  let attributes = super.createAttributesObject();
91472
- attributes.target = returnTargetAttribute(
91473
- "The value to locate within the sorted list."
91474
- );
91475
91629
  attributes.side = {
91476
91630
  createComponentOfType: "text",
91477
91631
  createStateVariable: "side",
@@ -91494,34 +91648,30 @@ class SearchSorted extends ListIndexBaseOperator {
91494
91648
  return attributes;
91495
91649
  }
91496
91650
  static returnStateVariableDefinitions() {
91497
- return Object.assign(
91498
- super.returnStateVariableDefinitions(),
91499
- returnTargetStateVariableDefinition(),
91500
- {
91501
- indexOperator: returnTargetSearchingIndexOperatorDefinition(
91502
- ({ values: values2, target, numeric: numeric2, dependencyValues }) => {
91503
- let count = 0;
91504
- for (let value of values2) {
91505
- let comparison = compareExtractedValues(
91506
- value,
91507
- target,
91508
- numeric2
91509
- );
91510
- if (comparison < 0 || dependencyValues.side === "right" && comparison === 0) {
91511
- count++;
91512
- }
91513
- }
91514
- return { index: count + 1 };
91515
- },
91516
- {
91517
- side: {
91518
- dependencyType: "stateVariable",
91519
- variableName: "side"
91651
+ return Object.assign(super.returnStateVariableDefinitions(), {
91652
+ locate: returnLocateDefinition(
91653
+ ({ values: values2, target, numeric: numeric2, dependencyValues }) => {
91654
+ let count = 0;
91655
+ for (let value of values2) {
91656
+ let comparison = compareExtractedValues(
91657
+ value,
91658
+ target,
91659
+ numeric2
91660
+ );
91661
+ if (comparison < 0 || dependencyValues.side === "right" && comparison === 0) {
91662
+ count++;
91520
91663
  }
91521
91664
  }
91522
- )
91523
- }
91524
- );
91665
+ return { index: count + 1 };
91666
+ },
91667
+ {
91668
+ side: {
91669
+ dependencyType: "stateVariable",
91670
+ variableName: "side"
91671
+ }
91672
+ }
91673
+ )
91674
+ });
91525
91675
  }
91526
91676
  }
91527
91677
  const ListIndexOperators = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
@@ -241751,4 +241901,4 @@ export {
241751
241901
  getDefaultExportFromCjs$1 as g,
241752
241902
  updateSyntaxFromV06toV07 as u
241753
241903
  };
241754
- //# sourceMappingURL=index-CjWZS5b_.js.map
241904
+ //# sourceMappingURL=index-DJZickZD.js.map