@saastro/studio 0.3.3 → 0.4.0

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.
@@ -3,7 +3,7 @@ import {
3
3
  injectVersionMetaTag,
4
4
  injectVisibilityStyle,
5
5
  readVisibilityConfigSync
6
- } from "./chunk-NICLSTZK.js";
6
+ } from "./chunk-IPVMSMB4.js";
7
7
 
8
8
  // src/vite/index.ts
9
9
  import { promises as fs } from "node:fs";
@@ -607,7 +607,7 @@ function injectSchema(source, schema, options = {}) {
607
607
 
608
608
  // src/vite/instrument-fields.ts
609
609
  var FRONTMATTER_RE4 = /^\s*---\s*\n[\s\S]*?\n---\s*\n/;
610
- function instrumentFields(source, schema, _options = {}) {
610
+ function instrumentFields(source, schema, options = {}) {
611
611
  if (!schema.fields.length) return source;
612
612
  if (!source.includes("data-saastro=")) return source;
613
613
  const fmMatch = FRONTMATTER_RE4.exec(source);
@@ -626,19 +626,28 @@ function instrumentFields(source, schema, _options = {}) {
626
626
  head = template;
627
627
  tail = "";
628
628
  }
629
- const transformed = transformTemplate(head, schema.fields);
629
+ const transformed = transformTemplate(
630
+ head,
631
+ schema.fields,
632
+ options.componentPath,
633
+ source
634
+ );
630
635
  return source.slice(0, templateStart) + transformed + tail;
631
636
  }
632
- function instrumentJsxFields(source, schema, _options = {}) {
637
+ function instrumentJsxFields(source, schema, options = {}) {
633
638
  if (!schema.fields.length) return source;
634
639
  if (!/<[A-Za-z]/.test(source)) return source;
635
- return transformTemplate(source, schema.fields);
640
+ return transformTemplate(source, schema.fields, options.componentPath, source);
636
641
  }
637
- function transformTemplate(template, fields) {
642
+ function transformTemplate(template, fields, componentPath, source = template) {
638
643
  let out = template;
639
644
  for (const field of fields) {
640
645
  if (field.kind !== "array") continue;
641
- out = transformArrayField(out, field);
646
+ const res = transformArrayField(out, field);
647
+ out = res.out;
648
+ if (!res.matched && hasMapReference(source, field.name) && !hasHandWrittenFieldMarker(template, field.name)) {
649
+ warnUninstrumentedArray(componentPath, field.name);
650
+ }
642
651
  }
643
652
  for (const field of fields) {
644
653
  if (field.kind === "array") continue;
@@ -646,6 +655,21 @@ function transformTemplate(template, fields) {
646
655
  }
647
656
  return out;
648
657
  }
658
+ function hasHandWrittenFieldMarker(template, name) {
659
+ const n = escapeReg(name);
660
+ return new RegExp(
661
+ "data-saastro(?:-field)?\\s*=\\s*\\{\\s*`[^`]*\\b" + n + "[[.]"
662
+ ).test(template);
663
+ }
664
+ function warnUninstrumentedArray(componentPath, name) {
665
+ const where = componentPath ? ` in ${componentPath}` : "";
666
+ console.warn(
667
+ `[saastro/studio] array prop "${name}"${where} was not auto-instrumented: no \`${name}.map(...)\` found in the template (it may be iterated via a derived variable, a chained method, or a destructured param). Its items won't be editable in the Studio until you hand-write data-saastro-field markers \u2014 e.g. <img src={item.image} data-saastro-field={\`${name}[\${i}].image\`} />.`
668
+ );
669
+ }
670
+ function hasMapReference(source, name) {
671
+ return new RegExp("\\b" + escapeReg(name) + "\\s*\\.\\s*map\\s*\\(").test(source);
672
+ }
649
673
  function transformArrayField(template, field) {
650
674
  const name = field.name;
651
675
  const subFields = field.items?.fields ?? [];
@@ -655,8 +679,10 @@ function transformArrayField(template, field) {
655
679
  );
656
680
  let result = "";
657
681
  let cursor = 0;
682
+ let matchCount = 0;
658
683
  let m;
659
684
  while ((m = re.exec(template)) !== null) {
685
+ matchCount++;
660
686
  const headerStart = m.index;
661
687
  const paramName = m[1];
662
688
  const existingIdx = m[2] ?? null;
@@ -683,7 +709,7 @@ function transformArrayField(template, field) {
683
709
  re.lastIndex = cursor;
684
710
  }
685
711
  result += template.slice(cursor);
686
- return result;
712
+ return { out: result, matched: matchCount > 0 };
687
713
  }
688
714
  function readArrowBody(template, start) {
689
715
  let i = start;
@@ -1258,4 +1284,4 @@ async function loadTsx(path) {
1258
1284
  export {
1259
1285
  studioAutoWrap
1260
1286
  };
1261
- //# sourceMappingURL=chunk-M5BCEVWK.js.map
1287
+ //# sourceMappingURL=chunk-5EXFBVC2.js.map