@wix/zero-config-implementation 1.9.0 → 1.10.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/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.10.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",
|
|
@@ -74,5 +74,5 @@
|
|
|
74
74
|
]
|
|
75
75
|
}
|
|
76
76
|
},
|
|
77
|
-
"falconPackageHash": "
|
|
77
|
+
"falconPackageHash": "21d3bc497b17268af6551d502a02de709d17f09eaa98040d2017ae4b"
|
|
78
78
|
}
|
|
@@ -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 { PRESETS_WRAPPER_CLASS_NAME } from '../../utils/mock-generator'
|
|
11
12
|
import type { CssPropertiesData } from '../css-properties'
|
|
12
13
|
import { addTextProperties } from '../css-properties'
|
|
13
14
|
import type { ExtractorStore } from './store'
|
|
@@ -175,6 +176,22 @@ function getElementNamePart(element: Element, getElementById: (id: string) => El
|
|
|
175
176
|
// Tree Building
|
|
176
177
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
177
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Replaces any presetsWrapper element (identified by PRESETS_WRAPPER_CLASS_NAME on its class
|
|
181
|
+
* attribute) with its children, so the real root element is promoted to the top level.
|
|
182
|
+
* The presetsWrapper is injected by the Wix renderer and is not a real component element.
|
|
183
|
+
*/
|
|
184
|
+
function unwrapPresetsWrappers(nodes: Node[]): Node[] {
|
|
185
|
+
return nodes.flatMap((node) => {
|
|
186
|
+
if (!isElement(node)) return [node]
|
|
187
|
+
const classAttr = getAttribute(node, 'class')
|
|
188
|
+
if (getAttribute(node, TRACE_ATTR) && classAttr?.includes(PRESETS_WRAPPER_CLASS_NAME)) {
|
|
189
|
+
return [...node.childNodes] as Array<Node>
|
|
190
|
+
}
|
|
191
|
+
return [node]
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
|
|
178
195
|
/**
|
|
179
196
|
* Builds an element tree from HTML, merging with store data.
|
|
180
197
|
* Each element gets a semantic name from concatenated ancestor names.
|
|
@@ -260,10 +277,12 @@ export function buildElementTree(html: string, store: ExtractorStore): Extracted
|
|
|
260
277
|
}
|
|
261
278
|
|
|
262
279
|
// Start with empty ancestor path, first traced element is root
|
|
280
|
+
const topLevelNodes = unwrapPresetsWrappers([...fragment.childNodes])
|
|
281
|
+
|
|
263
282
|
let isFirst = true
|
|
264
283
|
const result: ExtractedElement[] = []
|
|
265
284
|
|
|
266
|
-
for (const node of
|
|
285
|
+
for (const node of topLevelNodes) {
|
|
267
286
|
const elements = walkTree(node, '', isFirst)
|
|
268
287
|
if (elements.length > 0) {
|
|
269
288
|
result.push(...elements)
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { faker } from '@faker-js/faker'
|
|
7
7
|
import type { ComponentInfo, DefaultValue, PropInfo, ResolvedType } from '../../ts/types'
|
|
8
8
|
|
|
9
|
+
export const PRESETS_WRAPPER_CLASS_NAME = 'mock-presets-wrapper-probe'
|
|
10
|
+
|
|
9
11
|
// Unique primes used as traceable number values. Each rendered number prop gets
|
|
10
12
|
// one; the value is distinct enough to be identified in DOM attributes later.
|
|
11
13
|
const TRACEABLE_PRIMES = [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
|
|
@@ -51,6 +53,12 @@ export function generateMockProps(componentInfo: ComponentInfo, registrar?: Prop
|
|
|
51
53
|
mockProps[propName] = generateMockValue(propInfo, propName, `props.${propName}`, registrar)
|
|
52
54
|
}
|
|
53
55
|
|
|
56
|
+
// Always inject wix renderer object; components that don't use it will ignore it
|
|
57
|
+
mockProps.wix = {
|
|
58
|
+
elementsRemovalState: {},
|
|
59
|
+
presetsWrapperProps: { className: PRESETS_WRAPPER_CLASS_NAME },
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
return mockProps
|
|
55
63
|
}
|
|
56
64
|
|