@magmonium/cli 0.10.1 → 0.10.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/codegen/index.js CHANGED
@@ -1835,6 +1835,7 @@ __export(index_exports, {
1835
1835
  variantsForCode: () => variantsForCode,
1836
1836
  variantsForNewControl: () => variantsForNewControl,
1837
1837
  variantsReferencing: () => variantsReferencing,
1838
+ vscodeSettings: () => vscodeSettings,
1838
1839
  watchFields: () => watchFields,
1839
1840
  watchKey: () => watchKey,
1840
1841
  wcClassName: () => wcClassName,
@@ -9196,6 +9197,20 @@ var walkKeys = (keyIds, rootShapeId2, shapes) => {
9196
9197
  }
9197
9198
  return names;
9198
9199
  };
9200
+ var keysHeldPresent = (keyIds, rootShapeId2, shapes) => {
9201
+ const held = [];
9202
+ let shapeId = rootShapeId2;
9203
+ for (const keyId of keyIds) {
9204
+ const key2 = (shapeId ? shapes[shapeId] : void 0)?.keys.find(
9205
+ (k) => k.id === keyId
9206
+ );
9207
+ held.push(
9208
+ !!key2 && key2.dataType?.type === "shape" && (key2.cardinality ?? "one") === "one" && !key2.optional
9209
+ );
9210
+ shapeId = key2?.dataType?.type === "shape" ? key2.dataType.shapeId : void 0;
9211
+ }
9212
+ return held;
9213
+ };
9199
9214
  var rootShapeId = (binding, scope, seen) => {
9200
9215
  const root = binding.root;
9201
9216
  if (root.kind === "property") {
@@ -9475,15 +9490,16 @@ var bindingExpression = (binding, scope, guardAlias) => {
9475
9490
  const fn = computed ? screenComputedFunction(computed, scope.functions ?? {}) : void 0;
9476
9491
  if (!fn || returnCardinalityOf(fn) !== "one") return void 0;
9477
9492
  }
9478
- const names = walkKeys(
9479
- binding.path,
9480
- rootShapeId(binding, scope, /* @__PURE__ */ new Set()),
9481
- shapesOf(scope)
9482
- );
9493
+ const shapeId = rootShapeId(binding, scope, /* @__PURE__ */ new Set());
9494
+ const names = walkKeys(binding.path, shapeId, shapesOf(scope));
9483
9495
  if (!names) return void 0;
9484
- const present = !!guardAlias || rootIsPresent(binding, scope);
9485
- const [first, ...rest] = names;
9486
- expr = `${head}${memberStep(present ? "." : "?.", first)}${rest.map((name3) => memberStep("?.", name3)).join("")}`;
9496
+ const held = keysHeldPresent(binding.path, shapeId, shapesOf(scope));
9497
+ let present = !!guardAlias || rootIsPresent(binding, scope);
9498
+ expr = names.reduce((text3, name3, i) => {
9499
+ const step = memberStep(present ? "." : "?.", name3);
9500
+ present = present && held[i];
9501
+ return `${text3}${step}`;
9502
+ }, head);
9487
9503
  }
9488
9504
  if (!binding.transform) return expr;
9489
9505
  const roots = transformRoots(scope);
@@ -9665,9 +9681,11 @@ var repeatHeader = (control, scope) => {
9665
9681
  if (!source) return void 0;
9666
9682
  const spec = repeatSpec(control);
9667
9683
  const expr = bindingExpression(source, scope);
9684
+ const present = !!expr && sourceIsPresent(source, expr, scope);
9668
9685
  if (expr && isKeyedRepeat(control, scope)) {
9669
9686
  const entry2 = repeatEntryName(spec.itemAlias);
9670
- return `${entry2} of ((${expr} | keyvalue) ?? []); track ${entry2}.key; let ${spec.indexAlias} = $index`;
9687
+ const entries = present ? `(${expr} | keyvalue)` : `((${expr} | keyvalue) ?? [])`;
9688
+ return `${entry2} of ${entries}; track ${entry2}.key; let ${spec.indexAlias} = $index`;
9671
9689
  }
9672
9690
  if (!spec.track) return void 0;
9673
9691
  if (!expr) return void 0;
@@ -9679,7 +9697,34 @@ var repeatHeader = (control, scope) => {
9679
9697
  scope
9680
9698
  );
9681
9699
  if (!track) return void 0;
9682
- return `${spec.itemAlias} of (${expr} ?? []); track ${track}; let ${spec.indexAlias} = $index`;
9700
+ const items = present ? `(${expr})` : `(${expr} ?? [])`;
9701
+ return `${spec.itemAlias} of ${items}; track ${track}; let ${spec.indexAlias} = $index`;
9702
+ };
9703
+ var sourceIsPresent = (source, expr, scope) => {
9704
+ if (source.transform || expr.includes("?.")) return false;
9705
+ if (!source.path.length) {
9706
+ const root = source.root;
9707
+ if (root.kind !== "screen_computed") return rootIsPresent(source, scope);
9708
+ const computed = scope.screenComputeds?.[root.id];
9709
+ const fn = computed ? screenComputedFunction(computed, scope.functions ?? {}) : void 0;
9710
+ return !!computed && !!fn && fn.returnUndefined !== true && !screenComputedIsOptional(
9711
+ computed,
9712
+ fn,
9713
+ scope.inputs ?? {},
9714
+ scope.screenComputeds ?? {},
9715
+ scope.functions ?? {}
9716
+ );
9717
+ }
9718
+ const shapes = shapesOf(scope);
9719
+ let shapeId = rootShapeId(source, scope, /* @__PURE__ */ new Set());
9720
+ let last;
9721
+ for (const keyId of source.path) {
9722
+ last = (shapeId ? shapes[shapeId] : void 0)?.keys.find(
9723
+ (k) => k.id === keyId
9724
+ );
9725
+ shapeId = last?.dataType?.type === "shape" ? last.dataType.shapeId : void 0;
9726
+ }
9727
+ return !!last && !last.optional;
9683
9728
  };
9684
9729
  var repeatEntryName = (itemAlias) => `${itemAlias}Entry`;
9685
9730
  var repeatEntryLets = (control, scope) => {
@@ -22940,8 +22985,9 @@ function renderBranch(node, indent2, names, methods, operationOf, storeProp, ctx
22940
22985
  const children = entry2.arm.childrens.filter(
22941
22986
  (child) => projectionSlotOf(child) === slot
22942
22987
  );
22943
- const wrap = !!slot && children.length > 1;
22944
- const inner = render(children, indent2 + (wrap ? 2 : 1));
22988
+ const rendered = render(children, indent2 + 1);
22989
+ const wrap = !!slot && (children.length > 1 || rendered.some((text3) => opensWithLet(text3, `${pad2} `)));
22990
+ const inner = wrap ? rendered.map(indentLines) : rendered;
22945
22991
  if (!inner.length) return;
22946
22992
  if (wrap) {
22947
22993
  lines.push(
@@ -23002,15 +23048,16 @@ function renderRepeat(node, indent2, names, methods, operationOf, storeProp, ctx
23002
23048
  (child) => child.type !== "repeat_empty" /* REPEAT_EMPTY */
23003
23049
  );
23004
23050
  const table = enclosingSectionTable(control, ctx.controlMap ?? {});
23005
- const sorted = table ? header.replace(
23006
- / of \((.*) \?\? \[\]\); track /,
23051
+ const sorted = table && !isKeyedRepeat(control, scope) ? header.replace(
23052
+ / of \((.*?)(?: \?\? \[\])?\); track /,
23007
23053
  (_, expr) => ` of ((${expr}) | sectionTableSort: ${sectionTableRef(table.id)}.sort()); track `
23008
23054
  ) : header;
23009
23055
  const lines = [`${pad2}@for (${sorted}) {`];
23056
+ const inner = body(rows, indent2 + 1);
23010
23057
  for (const line of repeatEntryLets(control, scope)) {
23011
- lines.push(`${pad2} ${line}`);
23058
+ const name3 = letName(line);
23059
+ if (name3 && spellsName(inner, name3)) lines.push(`${pad2} ${line}`);
23012
23060
  }
23013
- const inner = body(rows, indent2 + 1);
23014
23061
  if (inner) lines.push(inner);
23015
23062
  if (empty) {
23016
23063
  const emptyInner = body(empty.childrens, indent2 + 1);
@@ -23160,11 +23207,25 @@ function renderNode(node, indent2, names, methods, operationOf, storeProp, ctx,
23160
23207
  );
23161
23208
  ctx.letSink = outerSink;
23162
23209
  if (!drawn) return "";
23210
+ const read = lets.filter((line) => {
23211
+ const name3 = letName(line);
23212
+ if (name3 && spellsName(drawn, name3)) return true;
23213
+ if (name3) ctx.letNames?.delete(name3);
23214
+ return false;
23215
+ });
23163
23216
  const innerPad = " ".repeat(inner);
23164
- const tag = `${lets.map((line) => `${innerPad}${line}
23217
+ const tag = `${read.map((line) => `${innerPad}${line}
23165
23218
  `).join("")}${drawn}`;
23166
- return `${gaps}${wrapInGuard(tag, guard, " ".repeat(indent2))}`;
23167
- }
23219
+ const slot = read.length && guard ? projectionSlotOf(node) : "";
23220
+ return `${gaps}${wrapInGuard(projectedRoot(tag, slot, innerPad), guard, " ".repeat(indent2))}`;
23221
+ }
23222
+ var letName = (line) => /^@let ([A-Za-z_$][\w$]*) =/.exec(line.trim())?.[1];
23223
+ var spellsName = (markup, name3) => new RegExp(`(^|[^\\w$])${name3.replace(/\$/g, "\\$")}(?![\\w$])`).test(markup);
23224
+ var projectedRoot = (markup, slot, pad2) => slot ? `${pad2}<ng-container ngProjectAs="${slot}">
23225
+ ${indentLines(markup)}
23226
+ ${pad2}</ng-container>` : markup;
23227
+ var indentLines = (markup) => markup.replace(/^(?=.)/gm, " ");
23228
+ var opensWithLet = (markup, pad2) => markup.split("\n").some((line) => line.startsWith(`${pad2}@let `));
23168
23229
  var hoistLet = (ctx, read) => {
23169
23230
  const sink = ctx.letSink;
23170
23231
  const taken = ctx.letNames;
@@ -24433,7 +24494,10 @@ function renderPluginTag(node, pad2, tag, methods, operationOf, storeProp, ctx)
24433
24494
  OUTPUT_ATTR
24434
24495
  )
24435
24496
  ].map(
24436
- ([, name3, handler]) => `${inner}<m-plugin-output name="${name3}" (fired)="${handler}" />`
24497
+ ([, name3, handler]) => `${inner}<m-plugin-output name="${name3}" (fired)="${handler.replace(
24498
+ /\$event\b/g,
24499
+ "$any($event)"
24500
+ )}" />`
24437
24501
  );
24438
24502
  if (inputs.length) ctx.writtenTags.add("m-plugin-input");
24439
24503
  if (outputs.length) ctx.writtenTags.add("m-plugin-output");
@@ -29007,7 +29071,7 @@ __export(package_exports2, {
29007
29071
  version: () => version2
29008
29072
  });
29009
29073
  var name2 = "@magmonium/cli";
29010
- var version2 = "0.10.1";
29074
+ var version2 = "0.10.4";
29011
29075
  var description2 = "A powerful and extensible asset compilation tool that can be shared across multiple projects";
29012
29076
  var bin = {
29013
29077
  "mag-cli": "bin/cli.js"
@@ -34350,6 +34414,12 @@ var packageJson = (appName, version3, extraDeps = {}) => JSON.stringify(
34350
34414
  "gen:test": "mag-cli gen-test",
34351
34415
  prestart: "npm run gen:code && npm run assets:compile",
34352
34416
  start: "ng serve",
34417
+ // Working from an IDE with the editor closed: every `.magmonium/` save
34418
+ // regenerates the code, and a hand edit to a generated file is put back
34419
+ // (ADR 0222). Hand-written code lives in `src/app/custom/`.
34420
+ "gen:watch": "mag-cli gen-code --watch",
34421
+ predev: "npm run assets:compile",
34422
+ dev: 'mag-cli gen-code --watch --run "ng serve"',
34353
34423
  prebuild: "npm run gen:code && npm run assets:compile",
34354
34424
  build: "ng build",
34355
34425
  "prebuild:wc": "npm run gen:code",
@@ -35540,6 +35610,8 @@ coverage/
35540
35610
  # Compiled from mag_assets by \`npm run assets:compile\` \u2014 never hand-edited,
35541
35611
  # and never committed.
35542
35612
  public/assets/
35613
+ # The web-component build's cache, written by \`npm run build\`.
35614
+ .mag-cache/
35543
35615
 
35544
35616
  # The GeneratedSet: regenerated from the design source by \`npm run gen:code\`
35545
35617
  # on every start, build and test, never committed (ADR 0181).
@@ -35585,6 +35657,20 @@ ${GENERATED_SET.map((line) => line.slice(1)).join("\n")}
35585
35657
  angular.json
35586
35658
  tsconfig.app.json
35587
35659
  `;
35660
+ var vscodeSettings = () => `${JSON.stringify(
35661
+ {
35662
+ "files.readonlyInclude": Object.fromEntries(
35663
+ GENERATED_SET.map((line) => [
35664
+ line.endsWith("/") ? `${line.slice(1)}**` : line.slice(1),
35665
+ true
35666
+ ])
35667
+ ),
35668
+ "files.readonlyExclude": { "src/app/custom/**": true }
35669
+ },
35670
+ null,
35671
+ 2
35672
+ )}
35673
+ `;
35588
35674
  var editorconfig = () => `root = true
35589
35675
 
35590
35676
  [*]
@@ -35618,6 +35704,7 @@ function scaffoldFiles(appName, config, environment, extraDeps = {}, plugins = [
35618
35704
  { path: ".prettierrc", contents: prettierrc() },
35619
35705
  { path: ".prettierignore", contents: prettierignore() },
35620
35706
  { path: ".editorconfig", contents: editorconfig() },
35707
+ { path: ".vscode/settings.json", contents: vscodeSettings() },
35621
35708
  { path: "mag-cli.config.js", contents: magCliConfig() },
35622
35709
  { path: "scripts/copy-one-assets.cjs", contents: copyOneAssetsCjs() },
35623
35710
  {
@@ -39385,6 +39472,7 @@ var HISTORY_SELECTION_KEYS = [
39385
39472
  variantsForCode,
39386
39473
  variantsForNewControl,
39387
39474
  variantsReferencing,
39475
+ vscodeSettings,
39388
39476
  watchFields,
39389
39477
  watchKey,
39390
39478
  wcClassName,