@wix/zero-config-implementation 1.37.0 → 1.39.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 +4108 -4080
- package/package.json +2 -2
- package/src/component-renderer.ts +0 -10
- package/src/information-extractors/react/extractors/css-properties.ts +52 -0
- package/src/information-extractors/react/extractors/index.ts +1 -1
- package/src/information-extractors/react/index.ts +1 -0
- package/src/manifest-pipeline.ts +3 -1
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.39.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",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
]
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
"falconPackageHash": "
|
|
87
|
+
"falconPackageHash": "7a722b2c0d3a2401e9c24708c061591e14e588d2901397bab2ddb304"
|
|
88
88
|
}
|
|
@@ -138,8 +138,6 @@ export function renderWithExtractors(
|
|
|
138
138
|
): string {
|
|
139
139
|
let nextId = 0
|
|
140
140
|
const getNextId = () => `t${++nextId}`
|
|
141
|
-
const globalScopeWithReact = globalThis as typeof globalThis & { React?: typeof React }
|
|
142
|
-
const hasExistingGlobalReact = Object.prototype.hasOwnProperty.call(globalScopeWithReact, 'React')
|
|
143
141
|
|
|
144
142
|
// Store originals
|
|
145
143
|
const originalCreateElement = React.createElement
|
|
@@ -167,11 +165,6 @@ export function renderWithExtractors(
|
|
|
167
165
|
const interceptedJsxDEV = createInterceptor(originalJsxDEV as ElementCreator, listeners, getNextId, store)
|
|
168
166
|
|
|
169
167
|
try {
|
|
170
|
-
// Provide a scoped global React binding only when absent, for classic bundles
|
|
171
|
-
// that reference `React.createElement` without a runtime React import.
|
|
172
|
-
if (!hasExistingGlobalReact) {
|
|
173
|
-
globalScopeWithReact.React = React
|
|
174
|
-
}
|
|
175
168
|
// @ts-expect-error Monkey-patch createElement
|
|
176
169
|
React.createElement = interceptedCreateElement
|
|
177
170
|
// Use the interceptor API for jsx-runtime (includes jsxDEV for dev mode)
|
|
@@ -195,8 +188,5 @@ export function renderWithExtractors(
|
|
|
195
188
|
cjsRuntime.jsx = origCjsJsx
|
|
196
189
|
cjsRuntime.jsxs = origCjsJsxs
|
|
197
190
|
cjsDevRuntime.jsxDEV = origCjsJsxDEV
|
|
198
|
-
if (!hasExistingGlobalReact) {
|
|
199
|
-
Reflect.deleteProperty(globalScopeWithReact, 'React')
|
|
200
|
-
}
|
|
201
191
|
}
|
|
202
192
|
}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { CSS_PROPERTIES } from '@wix/zero-config-schema'
|
|
9
|
+
import type { CssSelectorMatch, MatchedCssData } from '../../css/types'
|
|
10
|
+
import type { ExtractedElement } from './core/tree-builder'
|
|
9
11
|
import type { CreateElementEvent, ReactExtractor } from './core/types'
|
|
10
12
|
|
|
11
13
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -199,6 +201,56 @@ export function addTextProperties(existing: string[]): string[] {
|
|
|
199
201
|
return result
|
|
200
202
|
}
|
|
201
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Adds gap CSS property to an existing property list if not already present.
|
|
206
|
+
*/
|
|
207
|
+
export function addGapProperty(existing: string[]): string[] {
|
|
208
|
+
if (existing.includes(CSS_PROPERTY_TYPE.gap)) return existing
|
|
209
|
+
return [...existing, CSS_PROPERTY_TYPE.gap]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
213
|
+
// Gap Enrichment
|
|
214
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
215
|
+
|
|
216
|
+
const FLEX_GRID_DISPLAY_VALUES = new Set(['flex', 'grid', 'inline-flex', 'inline-grid'])
|
|
217
|
+
|
|
218
|
+
function hasFlexOrGridDisplay(matches: CssSelectorMatch[]): boolean {
|
|
219
|
+
for (const match of matches) {
|
|
220
|
+
for (const property of match.properties) {
|
|
221
|
+
if (property.name === 'display' && FLEX_GRID_DISPLAY_VALUES.has(property.value)) {
|
|
222
|
+
return true
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return false
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Walks the element tree and adds `gap` to relevant CSS properties
|
|
231
|
+
* for elements that have display: flex|grid and more than 1 child.
|
|
232
|
+
* Must be called after CSS selector matching (requires css-matcher data).
|
|
233
|
+
*/
|
|
234
|
+
export function enrichGapProperties(elements: ExtractedElement[]): ExtractedElement[] {
|
|
235
|
+
return elements.map((element) => {
|
|
236
|
+
if (element.children.length > 1) {
|
|
237
|
+
const matcherData = element.extractorData.get('css-matcher') as MatchedCssData | undefined
|
|
238
|
+
if (matcherData && hasFlexOrGridDisplay(matcherData.matches)) {
|
|
239
|
+
const cssData = element.extractorData.get('css-properties') as CssPropertiesData | undefined
|
|
240
|
+
if (cssData) {
|
|
241
|
+
element.extractorData.set('css-properties', {
|
|
242
|
+
relevant: addGapProperty(cssData.relevant),
|
|
243
|
+
})
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return {
|
|
248
|
+
...element,
|
|
249
|
+
children: enrichGapProperties(element.children),
|
|
250
|
+
}
|
|
251
|
+
})
|
|
252
|
+
}
|
|
253
|
+
|
|
202
254
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
203
255
|
// Factory
|
|
204
256
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -24,5 +24,5 @@ export type {
|
|
|
24
24
|
export { createPropTrackerExtractor } from './prop-tracker'
|
|
25
25
|
export type { PropTrackerData, PropTrackerExtractorState } from './prop-tracker'
|
|
26
26
|
|
|
27
|
-
export { createCssPropertiesExtractor } from './css-properties'
|
|
27
|
+
export { createCssPropertiesExtractor, enrichGapProperties } from './css-properties'
|
|
28
28
|
export type { CssPropertiesData } from './css-properties'
|
package/src/manifest-pipeline.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type RunExtractorsOptions,
|
|
10
10
|
createCssPropertiesExtractor,
|
|
11
11
|
createPropTrackerExtractor,
|
|
12
|
+
enrichGapProperties,
|
|
12
13
|
runExtractors,
|
|
13
14
|
} from './information-extractors/react'
|
|
14
15
|
import type { CoupledComponentInfo, CoupledProp, DOMBinding, TrackingStores } from './information-extractors/react'
|
|
@@ -154,9 +155,10 @@ export function processComponent(
|
|
|
154
155
|
if (html && extractedElements.length > 0 && css.length > 0) {
|
|
155
156
|
try {
|
|
156
157
|
const matchResult = matchCssSelectors(html, extractedElements, css)
|
|
158
|
+
const gapEnrichedElements = enrichGapProperties(matchResult.elements)
|
|
157
159
|
enhancedInfo = {
|
|
158
160
|
...enhancedInfo,
|
|
159
|
-
elements: convertElements(
|
|
161
|
+
elements: convertElements(gapEnrichedElements),
|
|
160
162
|
}
|
|
161
163
|
varUsedByTraceId = matchResult.varUsedByTraceId
|
|
162
164
|
} catch (thrownError) {
|