@wix/builder-utils 1.21.1
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/bundles/debug/es/builder-utils.mjs +979 -0
- package/dist/bundles/debug/es/builder-utils.mjs.map +1 -0
- package/dist/bundles/debug/umd/builder-utils.js +983 -0
- package/dist/bundles/debug/umd/builder-utils.js.map +1 -0
- package/dist/bundles/es/builder-utils.mjs +618 -0
- package/dist/bundles/es/builder-utils.mjs.map +1 -0
- package/dist/bundles/umd/builder-utils.js +2 -0
- package/dist/bundles/umd/builder-utils.js.map +1 -0
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mergeUtils.d.ts +2 -0
- package/dist/cjs/mergeUtils.js +60 -0
- package/dist/cjs/mergeUtils.js.map +1 -0
- package/dist/cjs/signalUtils.d.ts +6 -0
- package/dist/cjs/signalUtils.js +28 -0
- package/dist/cjs/signalUtils.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/mergeUtils.d.ts +2 -0
- package/dist/esm/mergeUtils.js +52 -0
- package/dist/esm/mergeUtils.js.map +1 -0
- package/dist/esm/signalUtils.d.ts +6 -0
- package/dist/esm/signalUtils.js +24 -0
- package/dist/esm/signalUtils.js.map +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/mergeUtils.d.ts +3 -0
- package/dist/types/mergeUtils.d.ts.map +1 -0
- package/dist/types/signalUtils.d.ts +7 -0
- package/dist/types/signalUtils.d.ts.map +1 -0
- package/package.json +64 -0
- package/src/index.ts +2 -0
- package/src/mergeUtils.ts +66 -0
- package/src/signalUtils.ts +31 -0
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@wix/builder-utils",
|
|
3
|
+
"version": "1.21.1",
|
|
4
|
+
"description": "Builder utilities for merging props with custom logic",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"types": "dist/types/index.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"license": "UNLICENSED",
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"dist",
|
|
12
|
+
"!**/*.tsbuildinfo"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "yarn run build:esm && yarn run build:cjs && yarn run build:types && yarn run -T build:bundles builder-utils",
|
|
16
|
+
"build:esm": "tsc --project tsconfig.json --outDir dist/esm --module ES2022 --moduleResolution Bundler",
|
|
17
|
+
"build:cjs": "tsc --project tsconfig.json --outDir dist/cjs --module CommonJS --moduleResolution Node",
|
|
18
|
+
"build:types": "tsc --emitDeclarationOnly --declaration --declarationMap --outDir dist/types",
|
|
19
|
+
"lint": "yarn run -T lint:package $npm_package_name",
|
|
20
|
+
"test-type-check": "tsc --project tsconfig.test.json",
|
|
21
|
+
"test": "yarn test-type-check && vitest --run",
|
|
22
|
+
"clean": "rm -rf coverage dist target tsconfig.tsbuildinfo"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"lodash": "^4.17.21"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/lodash": "^4.14.200",
|
|
29
|
+
"typescript": "^5.3.3",
|
|
30
|
+
"vitest": "^4.0.10"
|
|
31
|
+
},
|
|
32
|
+
"publishUnscoped": false,
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"registry": "https://registry.npmjs.org/",
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"wix": {
|
|
38
|
+
"artifact": {
|
|
39
|
+
"groupId": "com.wixpress.npm",
|
|
40
|
+
"artifactId": "builder-utils",
|
|
41
|
+
"targets": {
|
|
42
|
+
"static": {
|
|
43
|
+
"folderToUpload": "dist/bundles"
|
|
44
|
+
},
|
|
45
|
+
"docker": false
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"validations": {
|
|
49
|
+
"postBuild": [
|
|
50
|
+
"test",
|
|
51
|
+
"lint"
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"import": "./dist/esm/index.js",
|
|
58
|
+
"require": "./dist/cjs/index.js",
|
|
59
|
+
"types": "./dist/types/index.d.ts"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"module": "dist/esm/index.js",
|
|
63
|
+
"falconPackageHash": "f75c1f6c5a3c718c2a212b4e99c9ff41d2497c4cdcad1bb017400714"
|
|
64
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import mergeWith from 'lodash/mergeWith'
|
|
2
|
+
import merge from 'lodash/merge'
|
|
3
|
+
import isPlainObject from 'lodash/isPlainObject'
|
|
4
|
+
|
|
5
|
+
type WixProps = { elementProps: unknown }
|
|
6
|
+
|
|
7
|
+
function mergeClassName(class1: unknown, class2: unknown) {
|
|
8
|
+
if (typeof class1 === 'string' && typeof class2 === 'string') {
|
|
9
|
+
const classSet = new Set([...class1.split(' '), ...class2.split(' ')])
|
|
10
|
+
return Array.from(classSet).join(' ')
|
|
11
|
+
}
|
|
12
|
+
return class1 || class2
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function customMergeClasses(objValue: unknown, srcValue: unknown, key: string) {
|
|
16
|
+
if (!objValue) {
|
|
17
|
+
return srcValue
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!srcValue) {
|
|
21
|
+
return objValue
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (key === 'className') {
|
|
25
|
+
return mergeClassName(objValue, srcValue)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return srcValue
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function customMerge(objValue: unknown, srcValue: unknown, key: string) {
|
|
32
|
+
if (key === 'className') {
|
|
33
|
+
return mergeClassName(objValue, srcValue)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!objValue) {
|
|
37
|
+
return srcValue
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!srcValue) {
|
|
41
|
+
return objValue
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (key === 'wix') {
|
|
45
|
+
return merge(objValue, srcValue, true)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if ((objValue as WixProps)?.elementProps || (srcValue as WixProps).elementProps || key === 'elementProps') {
|
|
49
|
+
return mergeWith(objValue, srcValue, customMerge)
|
|
50
|
+
}
|
|
51
|
+
if (srcValue && objValue && isPlainObject(srcValue) && isPlainObject(objValue)) {
|
|
52
|
+
return mergeWith(objValue, srcValue, customMergeClasses)
|
|
53
|
+
}
|
|
54
|
+
return srcValue
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const mergeProps = (srcProps: Record<string, unknown>, valueProps?: Record<string, unknown>) =>
|
|
58
|
+
mergeWith(srcProps || {}, valueProps, customMerge)
|
|
59
|
+
|
|
60
|
+
export const removeElementProps = (obj: Record<string, unknown>): Record<string, unknown> | undefined => {
|
|
61
|
+
if (!obj) {
|
|
62
|
+
return undefined
|
|
63
|
+
}
|
|
64
|
+
const { elementProps, ...rest } = obj
|
|
65
|
+
return rest
|
|
66
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type Signal = {
|
|
2
|
+
get: () => unknown
|
|
3
|
+
peek: () => unknown
|
|
4
|
+
set: (value: unknown) => void
|
|
5
|
+
}
|
|
6
|
+
const isSignal = (maybeSignal: unknown): maybeSignal is Signal => {
|
|
7
|
+
return (
|
|
8
|
+
typeof maybeSignal === 'object' &&
|
|
9
|
+
maybeSignal !== null &&
|
|
10
|
+
'get' in maybeSignal &&
|
|
11
|
+
'peek' in maybeSignal &&
|
|
12
|
+
'set' in maybeSignal
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Traverses a dot-separated path starting from target, unwrapping signals at every step.
|
|
18
|
+
* An empty path simply unwraps target itself if it is a signal.
|
|
19
|
+
* Mirrors the runtime's getSignalValueDeep in feature-builder-context-providers.
|
|
20
|
+
*/
|
|
21
|
+
export const getSignalValueDeep = (target: unknown, path = ''): unknown => {
|
|
22
|
+
let value = target
|
|
23
|
+
for (const segment of path.split('.').filter(Boolean)) {
|
|
24
|
+
if (value == null) {
|
|
25
|
+
break
|
|
26
|
+
}
|
|
27
|
+
const next = (value as Record<string, unknown>)[segment]
|
|
28
|
+
value = isSignal(next) ? next.get() : next
|
|
29
|
+
}
|
|
30
|
+
return isSignal(value) ? value.get() : value
|
|
31
|
+
}
|