@immense/vue-pom-generator 1.0.86 → 1.0.87

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/index.mjs CHANGED
@@ -236,6 +236,7 @@ function resolveInjectionSupportOptions(options) {
236
236
  layoutDirs: isNuxt ? ["app/layouts"] : options.layoutDirs ?? ["src/layouts"],
237
237
  wrapperSearchRoots: isNuxt ? [] : options.wrapperSearchRoots ?? [],
238
238
  nativeWrappers: options.nativeWrappers ?? {},
239
+ optionKeyAttribute: options.optionKeyAttribute ?? {},
239
240
  excludedComponents: options.excludedComponents ?? [],
240
241
  existingIdBehavior: options.existingIdBehavior ?? "error",
241
242
  testIdAttribute: (options.testIdAttribute ?? "data-testid").trim() || "data-testid"
@@ -1286,12 +1287,13 @@ function findDirectiveByName(node, directiveName, argumentName) {
1286
1287
  return matchesDirective;
1287
1288
  });
1288
1289
  }
1290
+ const ACTION_EVENTS = /* @__PURE__ */ new Set(["click", "change", "mousedown"]);
1289
1291
  function isClickDirective(prop) {
1290
1292
  if (prop.type !== NodeTypes.DIRECTIVE) {
1291
1293
  return false;
1292
1294
  }
1293
1295
  const directive = prop;
1294
- return directive.name === "on" && directive.arg?.type === NodeTypes.SIMPLE_EXPRESSION && directive.arg.content === "click";
1296
+ return directive.name === "on" && directive.arg?.type === NodeTypes.SIMPLE_EXPRESSION && ACTION_EVENTS.has(directive.arg.content);
1295
1297
  }
1296
1298
  function tryGetClickDirective(node) {
1297
1299
  return node.props.find((p) => isClickDirective(p));
@@ -1693,6 +1695,17 @@ function getKeyDirectiveInfo(node) {
1693
1695
  const runtimeSource = getVueExpressionSource(keyExpression, "loc", "compiled");
1694
1696
  return toResolvedKeyInfo(selectorSource, runtimeSource);
1695
1697
  }
1698
+ function getBindingKeyInfo(node, attrName) {
1699
+ const directive = findDirectiveByName(node, "bind", attrName);
1700
+ const exp = directive?.exp;
1701
+ if (!exp || exp.type !== NodeTypes.SIMPLE_EXPRESSION && exp.type !== NodeTypes.COMPOUND_EXPRESSION) {
1702
+ return null;
1703
+ }
1704
+ const expression = exp;
1705
+ const selectorSource = getVueExpressionSource(expression, "compiled", "loc");
1706
+ const runtimeSource = getVueExpressionSource(expression, "loc", "compiled");
1707
+ return toResolvedKeyInfo(selectorSource, runtimeSource);
1708
+ }
1696
1709
  function getModelBindingValues(node) {
1697
1710
  let vModel = "";
1698
1711
  const vModelDirective = findDirectiveByName(node, "model");
@@ -1712,6 +1725,15 @@ function getModelBindingValues(node) {
1712
1725
  }
1713
1726
  return { vModel, modelValue };
1714
1727
  }
1728
+ function getBindingValueHint(node) {
1729
+ const directive = findDirectiveByName(node, "bind", "value");
1730
+ const exp = directive?.exp;
1731
+ if (!exp || exp.type !== NodeTypes.SIMPLE_EXPRESSION && exp.type !== NodeTypes.COMPOUND_EXPRESSION) {
1732
+ return null;
1733
+ }
1734
+ const source = getVueExpressionSource(exp, "loc", "content");
1735
+ return source || null;
1736
+ }
1715
1737
  function getStaticIdOrNameHint(node) {
1716
1738
  let idAttr = findAttributeByKey(node, "id");
1717
1739
  if (!idAttr) {
@@ -7490,6 +7512,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7490
7512
  const wrapperSearchRoots = options.wrapperSearchRoots ?? [];
7491
7513
  const annotatorMetadata = options.annotatorMetadata ?? null;
7492
7514
  const crossFileKeyRegistry = options.crossFileKeyRegistry;
7515
+ const optionKeyAttribute = options.optionKeyAttribute ?? {};
7493
7516
  const safeRealpath2 = (p) => {
7494
7517
  try {
7495
7518
  return fs.existsSync(p) ? fs.realpathSync(p) : p;
@@ -7670,6 +7693,13 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
7670
7693
  const getBestAvailableKeyInfo = () => {
7671
7694
  const parentNode = context.parent && typeof context.parent === "object" ? context.parent : null;
7672
7695
  const isDirectVForChild = parentNode?.type === NodeTypes.FOR;
7696
+ const configuredAttrName = optionKeyAttribute[componentName];
7697
+ if (configuredAttrName && configuredAttrName !== "key") {
7698
+ const bindingKeyInfo = getBindingKeyInfo(element, configuredAttrName);
7699
+ if (bindingKeyInfo) {
7700
+ return bindingKeyInfo;
7701
+ }
7702
+ }
7673
7703
  const vForKeyInfo = (isDirectVForChild ? getKeyDirectiveInfo(element) : null) || getContainedInVForDirectiveKeyInfo(context, element, hierarchyMap);
7674
7704
  if (vForKeyInfo) {
7675
7705
  return vForKeyInfo;
@@ -7877,7 +7907,8 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
7877
7907
  const rawIdentifier = getStaticAttributeContent(element, "id") || getStaticAttributeContent(element, "name");
7878
7908
  const labelText = getAssociatedLabelText(element, hierarchyMap);
7879
7909
  const { vModel, modelValue } = getModelBindingValues(element);
7880
- const bindingHint = modelValue || vModel || null;
7910
+ const valueBindingHint = nativeHtmlRole === "radio" || nativeHtmlRole === "checkbox" ? getBindingValueHint(element) : null;
7911
+ const bindingHint = modelValue || vModel || valueBindingHint || null;
7881
7912
  const labelToken = labelText ? toPascalCase(labelText) : "";
7882
7913
  const bindingToken = bindingHint ? toPascalCase(bindingHint) : "";
7883
7914
  let identifierToken = null;
@@ -8048,6 +8079,7 @@ function createBuildProcessorPlugin(options) {
8048
8079
  generation,
8049
8080
  projectRootRef,
8050
8081
  nativeWrappers,
8082
+ optionKeyAttribute,
8051
8083
  excludedComponents,
8052
8084
  getWrapperSearchRoots,
8053
8085
  getResolvedRouterEntry,
@@ -8180,7 +8212,8 @@ function createBuildProcessorPlugin(options) {
8180
8212
  warn: (message) => loggerRef.current.warn(message),
8181
8213
  vueFilesPathMap,
8182
8214
  wrapperSearchRoots: getWrapperSearchRoots(),
8183
- crossFileKeyRegistry
8215
+ crossFileKeyRegistry,
8216
+ optionKeyAttribute
8184
8217
  }
8185
8218
  )
8186
8219
  ]
@@ -8299,6 +8332,7 @@ function createBuildProcessorPlugin(options) {
8299
8332
  function createDevProcessorPlugin(options) {
8300
8333
  const {
8301
8334
  nativeWrappers,
8335
+ optionKeyAttribute,
8302
8336
  excludedComponents,
8303
8337
  getPageDirs,
8304
8338
  getComponentDirs,
@@ -8532,7 +8566,8 @@ function createDevProcessorPlugin(options) {
8532
8566
  warn: (message) => loggerRef.current.warn(message),
8533
8567
  vueFilesPathMap: provisionalVuePathMap,
8534
8568
  wrapperSearchRoots: getWrapperSearchRoots(),
8535
- crossFileKeyRegistry: provisionalKeyRegistry
8569
+ crossFileKeyRegistry: provisionalKeyRegistry,
8570
+ optionKeyAttribute
8536
8571
  }
8537
8572
  )
8538
8573
  ]
@@ -9063,6 +9098,7 @@ function createInternalPlugins(options) {
9063
9098
  elementMetadata,
9064
9099
  vueFilesPathMap,
9065
9100
  nativeWrappers,
9101
+ optionKeyAttribute,
9066
9102
  excludedComponents,
9067
9103
  getPageDirs,
9068
9104
  getComponentDirs,
@@ -9113,6 +9149,7 @@ function createInternalPlugins(options) {
9113
9149
  generation,
9114
9150
  projectRootRef,
9115
9151
  nativeWrappers,
9152
+ optionKeyAttribute,
9116
9153
  excludedComponents,
9117
9154
  getWrapperSearchRoots,
9118
9155
  getResolvedRouterEntry: resolveRouterEntry2,
@@ -9120,6 +9157,7 @@ function createInternalPlugins(options) {
9120
9157
  });
9121
9158
  const devProcessor = createDevProcessorPlugin({
9122
9159
  nativeWrappers,
9160
+ optionKeyAttribute,
9123
9161
  excludedComponents,
9124
9162
  getPageDirs,
9125
9163
  getComponentDirs,
@@ -9324,6 +9362,7 @@ function createVuePluginWithTestIds(options) {
9324
9362
  nameCollisionBehavior,
9325
9363
  missingSemanticNameBehavior = "error",
9326
9364
  nativeWrappers,
9365
+ optionKeyAttribute,
9327
9366
  elementMetadata,
9328
9367
  semanticNameMap,
9329
9368
  componentHierarchyMap,
@@ -9398,7 +9437,8 @@ function createVuePluginWithTestIds(options) {
9398
9437
  vueFilesPathMap,
9399
9438
  wrapperSearchRoots: getWrapperSearchRoots(),
9400
9439
  annotatorMetadata,
9401
- crossFileKeyRegistry
9440
+ crossFileKeyRegistry,
9441
+ optionKeyAttribute
9402
9442
  }
9403
9443
  )
9404
9444
  );
@@ -9455,7 +9495,8 @@ function createVuePluginWithTestIds(options) {
9455
9495
  vueFilesPathMap,
9456
9496
  wrapperSearchRoots: getWrapperSearchRoots(),
9457
9497
  annotatorMetadata,
9458
- crossFileKeyRegistry
9498
+ crossFileKeyRegistry,
9499
+ optionKeyAttribute
9459
9500
  }
9460
9501
  );
9461
9502
  perFileTransform.set(componentName, transform);
@@ -9792,6 +9833,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9792
9833
  layoutDirs: injection.layoutDirs,
9793
9834
  wrapperSearchRoots: injection.wrapperSearchRoots,
9794
9835
  nativeWrappers: injection.nativeWrappers,
9836
+ optionKeyAttribute: injection.optionKeyAttribute,
9795
9837
  excludedComponents: injection.excludeComponents,
9796
9838
  existingIdBehavior: injection.existingIdBehavior,
9797
9839
  testIdAttribute: injection.attribute
@@ -9799,6 +9841,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9799
9841
  };
9800
9842
  const resolvedInjectionOptions = resolvedInjectionOptionsRef.current;
9801
9843
  const nativeWrappers = resolvedInjectionOptions.nativeWrappers;
9844
+ const optionKeyAttribute = resolvedInjectionOptions.optionKeyAttribute;
9802
9845
  const excludedComponents = resolvedInjectionOptions.excludedComponents;
9803
9846
  const testIdAttribute = resolvedInjectionOptions.testIdAttribute;
9804
9847
  const routerEntry = !isNuxt ? vueGenerationOptions?.router?.entry : void 0;
@@ -9921,6 +9964,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9921
9964
  nameCollisionBehavior: resolvedGenerationOptions.nameCollisionBehavior,
9922
9965
  missingSemanticNameBehavior: resolvedGenerationOptions.missingSemanticNameBehavior,
9923
9966
  nativeWrappers,
9967
+ optionKeyAttribute,
9924
9968
  elementMetadata,
9925
9969
  semanticNameMap,
9926
9970
  componentHierarchyMap,
@@ -9946,6 +9990,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9946
9990
  elementMetadata,
9947
9991
  vueFilesPathMap,
9948
9992
  nativeWrappers,
9993
+ optionKeyAttribute,
9949
9994
  excludedComponents,
9950
9995
  getPageDirs,
9951
9996
  getComponentDirs,