uidex 0.5.2 → 0.6.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.
package/dist/cli/cli.cjs CHANGED
@@ -533,6 +533,7 @@ function freezeEntity(entity, flows) {
533
533
  function createRegistry() {
534
534
  const store = emptyStore();
535
535
  let flowsCache = null;
536
+ const patternCache = /* @__PURE__ */ new Map();
536
537
  const getFlows = () => {
537
538
  if (flowsCache === null) flowsCache = Array.from(store.flow.values());
538
539
  return flowsCache;
@@ -542,6 +543,7 @@ function createRegistry() {
542
543
  const key = entityKey(entity);
543
544
  store[entity.kind].set(key, entity);
544
545
  flowsCache = null;
546
+ patternCache.delete(entity.kind);
545
547
  };
546
548
  const get = (kind, id) => {
547
549
  assertEntityKind(kind);
@@ -549,6 +551,38 @@ function createRegistry() {
549
551
  if (raw === void 0) return void 0;
550
552
  return freezeEntity(raw, getFlows());
551
553
  };
554
+ const getPatternsForKind = (kind) => {
555
+ const cached = patternCache.get(kind);
556
+ if (cached !== void 0)
557
+ return cached;
558
+ const patterns = [];
559
+ for (const [key, entity] of store[kind]) {
560
+ if (key.endsWith("*")) {
561
+ patterns.push({
562
+ prefix: key.slice(0, -1),
563
+ entity
564
+ });
565
+ }
566
+ }
567
+ patternCache.set(
568
+ kind,
569
+ patterns
570
+ );
571
+ return patterns;
572
+ };
573
+ const matchPattern = (kind, id) => {
574
+ assertEntityKind(kind);
575
+ const patterns = getPatternsForKind(kind);
576
+ if (patterns.length === 0) return void 0;
577
+ let best;
578
+ for (const entry of patterns) {
579
+ if (id.startsWith(entry.prefix) && (best === void 0 || entry.prefix.length > best.prefix.length)) {
580
+ best = entry;
581
+ }
582
+ }
583
+ if (best === void 0) return void 0;
584
+ return freezeEntity(best.entity, getFlows());
585
+ };
552
586
  const list = (kind) => {
553
587
  assertEntityKind(kind);
554
588
  const flows = getFlows();
@@ -599,6 +633,7 @@ function createRegistry() {
599
633
  return {
600
634
  add,
601
635
  get,
636
+ matchPattern,
602
637
  list,
603
638
  query,
604
639
  byScope,
@@ -740,10 +775,18 @@ function audit(opts) {
740
775
  }
741
776
  if (lint) {
742
777
  const dynamicAttrRe = /\bdata-uidex(?:-(region|widget|primitive))?\s*=\s*\{/g;
778
+ const templateWithPrefixRe = /\bdata-uidex(?:-(region|widget|primitive))?\s*=\s*\{\s*`[^`$]+\$\{/g;
743
779
  for (const f of files) {
780
+ const templatePrefixPositions = /* @__PURE__ */ new Set();
781
+ templateWithPrefixRe.lastIndex = 0;
782
+ let tm;
783
+ while ((tm = templateWithPrefixRe.exec(f.content)) !== null) {
784
+ templatePrefixPositions.add(tm.index);
785
+ }
744
786
  let m;
745
787
  dynamicAttrRe.lastIndex = 0;
746
788
  while ((m = dynamicAttrRe.exec(f.content)) !== null) {
789
+ if (templatePrefixPositions.has(m.index)) continue;
747
790
  const kind = m[1] ?? "element";
748
791
  let line = 1;
749
792
  for (let i = 0; i < m.index; i++) if (f.content[i] === "\n") line++;
@@ -827,7 +870,7 @@ function audit(opts) {
827
870
  if (lint && coverageEnabled) {
828
871
  for (const flow of registry.list("flow")) {
829
872
  for (const touchedId of flow.touches) {
830
- const found = registry.get("element", touchedId) ?? registry.get("widget", touchedId) ?? registry.get("region", touchedId);
873
+ const found = registry.get("element", touchedId) ?? registry.get("widget", touchedId) ?? registry.get("region", touchedId) ?? registry.matchPattern("element", touchedId) ?? registry.matchPattern("widget", touchedId) ?? registry.matchPattern("region", touchedId);
831
874
  if (!found) {
832
875
  diagnostics.push({
833
876
  code: "unknown-reference",
@@ -2097,6 +2140,7 @@ function posAt(content, offset) {
2097
2140
 
2098
2141
  // src/scanner/scan/jsx-ancestry.ts
2099
2142
  var DATA_ATTR_RE = /\bdata-uidex(?:-(region|widget|primitive))?\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
2143
+ var PATTERN_ATTR_RE = /\bdata-uidex(?:-(region|widget|primitive))?\s*=\s*\{\s*`([^`$]+)\$\{/g;
2100
2144
  function parseDataAttrs(tagSource) {
2101
2145
  if (!tagSource.includes("data-uidex")) return [];
2102
2146
  const out2 = [];
@@ -2105,6 +2149,11 @@ function parseDataAttrs(tagSource) {
2105
2149
  const id = m[2] ?? m[3];
2106
2150
  if (id) out2.push({ kind, id });
2107
2151
  }
2152
+ for (const m of tagSource.matchAll(PATTERN_ATTR_RE)) {
2153
+ const kind = m[1] ?? "element";
2154
+ const prefix = m[2];
2155
+ if (prefix) out2.push({ kind, id: `${prefix}*` });
2156
+ }
2108
2157
  return out2;
2109
2158
  }
2110
2159
  function collectJSXAncestry(content) {