@wix/zero-config-implementation 1.15.0 → 1.17.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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Returns true if the class name looks like a global semantic class —
3
+ * i.e. not a CSS Module hash-suffixed class.
4
+ */
5
+ export declare function isGlobalSemanticClass(className: string): boolean;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "registry": "https://registry.npmjs.org/",
5
5
  "access": "public"
6
6
  },
7
- "version": "1.15.0",
7
+ "version": "1.17.0",
8
8
  "description": "Core library for extracting component manifests from JS and CSS files",
9
9
  "type": "module",
10
10
  "main": "dist/index.js",
@@ -75,5 +75,5 @@
75
75
  ]
76
76
  }
77
77
  },
78
- "falconPackageHash": "1d9fc602e0ba357d71e273c769064f5c8c38b293c6fbf5e964991825"
78
+ "falconPackageHash": "453ef72fecd4eac2958f740eea8a7764343b089244f2a0afdd2b9d15"
79
79
  }
@@ -16,6 +16,7 @@ import type {
16
16
  ElementItem,
17
17
  } from '../schema'
18
18
  import { ELEMENTS } from '../schema'
19
+ import { isGlobalSemanticClass } from '../utils/css-class'
19
20
  import { buildDataItem } from './data-item-builder'
20
21
  import { formatDisplayName } from './utils'
21
22
 
@@ -44,7 +45,8 @@ function buildEditorElement(component: ComponentInfoWithCss): EditorElement {
44
45
 
45
46
  function buildSelector(rootElement?: ExtractedElement): string {
46
47
  if (rootElement?.attributes.class) {
47
- return `.${rootElement.attributes.class.split(' ')[0]}`
48
+ const semanticClass = rootElement.attributes.class.split(' ').find(isGlobalSemanticClass)
49
+ if (semanticClass) return `.${semanticClass}`
48
50
  }
49
51
  return rootElement?.tag ?? ''
50
52
  }
@@ -8,6 +8,7 @@
8
8
  import { pascalCase } from 'case-anything'
9
9
  import { type DefaultTreeAdapterMap, parseFragment } from 'parse5'
10
10
  import { TRACE_ATTR } from '../../../../component-renderer'
11
+ import { isGlobalSemanticClass } from '../../../../utils/css-class'
11
12
  import { PRESETS_WRAPPER_CLASS_NAME } from '../../utils/mock-generator'
12
13
  import type { CssPropertiesData } from '../css-properties'
13
14
  import { addTextProperties } from '../css-properties'
@@ -169,6 +170,12 @@ function getElementNamePart(element: Element, getElementById: (id: string) => El
169
170
  }
170
171
  }
171
172
 
173
+ const classAttr = getAttribute(element, 'class')
174
+ if (classAttr) {
175
+ const semanticClass = classAttr.split(' ').find(isGlobalSemanticClass)
176
+ if (semanticClass) return pascalCase(semanticClass)
177
+ }
178
+
172
179
  return normalizeTagName(element.tagName)
173
180
  }
174
181
 
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Matches CSS Module hash suffixes: one or more underscores followed by a
3
+ * segment containing at least one digit (e.g. `_x7k9p2`, `__3xKqP`).
4
+ * BEM modifiers like `--primary` or `--active` contain no digits and won't match.
5
+ */
6
+ const CSS_MODULE_HASH_PATTERN = /_+\w*\d\w*$/
7
+
8
+ /**
9
+ * Returns true if the class name looks like a global semantic class —
10
+ * i.e. not a CSS Module hash-suffixed class.
11
+ */
12
+ export function isGlobalSemanticClass(className: string): boolean {
13
+ return !CSS_MODULE_HASH_PATTERN.test(className)
14
+ }