@wix/zero-config-implementation 1.91.0 → 1.92.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/index.js +5507 -5503
- package/package.json +2 -2
- package/src/converters/to-editor-component.test.ts +65 -0
- package/src/converters/to-editor-component.ts +9 -3
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"registry": "https://registry.npmjs.org/",
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "1.
|
|
7
|
+
"version": "1.92.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",
|
|
@@ -106,5 +106,5 @@
|
|
|
106
106
|
]
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
|
-
"falconPackageHash": "
|
|
109
|
+
"falconPackageHash": "db2c3fec617a486d30e2d52ed7e239747365a40d14666a5ea04cf07d"
|
|
110
110
|
}
|
|
@@ -166,6 +166,71 @@ describe('toEditorReactComponent display conversion', () => {
|
|
|
166
166
|
})
|
|
167
167
|
})
|
|
168
168
|
|
|
169
|
+
describe('toEditorReactComponent selector conversion', () => {
|
|
170
|
+
it.each([
|
|
171
|
+
['a', 'a___'],
|
|
172
|
+
['div', 'div_'],
|
|
173
|
+
['span', 'span'],
|
|
174
|
+
])('pads the root selector %j to at least four characters', (tag, expectedSelector) => {
|
|
175
|
+
const rootElement = createElementWithDisplayMatcher(tag, matcherDataFromCss(''))
|
|
176
|
+
|
|
177
|
+
const editorElement = toEditorReactComponent(createComponent(rootElement)).editorElement
|
|
178
|
+
|
|
179
|
+
expect(editorElement?.selector).toBe(expectedSelector)
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
it('pads a short semantic class selector', () => {
|
|
183
|
+
const rootElement = createSemanticElement({
|
|
184
|
+
traceId: 'trace-root',
|
|
185
|
+
name: 'root',
|
|
186
|
+
className: 'a',
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
const editorElement = toEditorReactComponent(createComponent(rootElement)).editorElement
|
|
190
|
+
|
|
191
|
+
expect(editorElement?.selector).toBe('.a__')
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('pads short inline and ref element selectors', () => {
|
|
195
|
+
const inlineElement: ExtractedElement = {
|
|
196
|
+
traceId: 'trace-link',
|
|
197
|
+
name: 'link',
|
|
198
|
+
tag: 'a',
|
|
199
|
+
attributes: {},
|
|
200
|
+
extractorData: new Map<string, unknown>(),
|
|
201
|
+
children: [],
|
|
202
|
+
}
|
|
203
|
+
const refElement: ExtractedElement = {
|
|
204
|
+
traceId: 'trace-action-button',
|
|
205
|
+
name: 'actionButton',
|
|
206
|
+
tag: 'div',
|
|
207
|
+
attributes: {},
|
|
208
|
+
extractorData: new Map<string, unknown>([
|
|
209
|
+
[
|
|
210
|
+
'ref-element',
|
|
211
|
+
{
|
|
212
|
+
elementPropsPath: 'actionButton',
|
|
213
|
+
refComponentType: 'test.Button',
|
|
214
|
+
selector: '.a',
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
]),
|
|
218
|
+
children: [],
|
|
219
|
+
}
|
|
220
|
+
const rootElement = createSemanticElement({
|
|
221
|
+
traceId: 'trace-root',
|
|
222
|
+
name: 'root',
|
|
223
|
+
className: 'root',
|
|
224
|
+
children: [inlineElement, refElement],
|
|
225
|
+
})
|
|
226
|
+
|
|
227
|
+
const elements = toEditorReactComponent(createComponent(rootElement)).editorElement?.elements
|
|
228
|
+
|
|
229
|
+
expect(elements?.link?.inlineElement?.selector).toBe('a___')
|
|
230
|
+
expect(elements?.actionButton?.refElement?.selector).toBe('.a__')
|
|
231
|
+
})
|
|
232
|
+
})
|
|
233
|
+
|
|
169
234
|
function cssInfoFromStylesheet(cssString: string): ExtractedCssInfo {
|
|
170
235
|
const api = parseCss(cssString)
|
|
171
236
|
const properties = new Map<string, string>()
|
|
@@ -34,6 +34,8 @@ import type { StateClassTrigger } from './state-class-trigger'
|
|
|
34
34
|
import { buildStatesBlock } from './states-builder'
|
|
35
35
|
import { formatDisplayName } from './utils'
|
|
36
36
|
|
|
37
|
+
const MINIMUM_SELECTOR_LENGTH = 4
|
|
38
|
+
|
|
37
39
|
/**
|
|
38
40
|
* Merges native and custom state blocks. Native states take precedence on any
|
|
39
41
|
* key collision (e.g. an author wrapping `isDisabled` in `ElementState<>` does not
|
|
@@ -140,9 +142,13 @@ function getSemanticBlockName(element: ExtractedElement | undefined): string | u
|
|
|
140
142
|
function buildSelector(rootElement?: ExtractedElement): string {
|
|
141
143
|
if (rootElement?.attributes.class) {
|
|
142
144
|
const semanticClass = findPreferredSemanticClass(normalizeClassNames(rootElement.attributes.class))
|
|
143
|
-
if (semanticClass) return `.${semanticClass}`
|
|
145
|
+
if (semanticClass) return padSelector(`.${semanticClass}`)
|
|
144
146
|
}
|
|
145
|
-
return rootElement?.tag ?? ''
|
|
147
|
+
return padSelector(rootElement?.tag ?? '')
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function padSelector(selector: string): string {
|
|
151
|
+
return selector.padEnd(MINIMUM_SELECTOR_LENGTH, '_')
|
|
146
152
|
}
|
|
147
153
|
|
|
148
154
|
function buildInnerElementDisplayName(element: ExtractedElement, ancestorSemanticClasses: string[]): string {
|
|
@@ -206,7 +212,7 @@ function buildElements(
|
|
|
206
212
|
result[buildRefElementManifestKey(refElementMatch.elementPropsPath, parentElementPropsPath)] = {
|
|
207
213
|
elementType: ELEMENTS.ELEMENT_TYPE.refElement,
|
|
208
214
|
refElement: {
|
|
209
|
-
selector: refElementMatch.selector,
|
|
215
|
+
selector: padSelector(refElementMatch.selector),
|
|
210
216
|
type: refElementMatch.refComponentType,
|
|
211
217
|
},
|
|
212
218
|
}
|