@flowgram.ai/form-materials 0.2.26 → 0.2.27
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/esm/index.js +40 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +39 -5
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/effects/auto-rename-ref/index.ts +59 -8
package/dist/esm/index.js
CHANGED
|
@@ -3146,7 +3146,7 @@ var provideBatchOutputsEffect = createEffectFromVariableProvider2({
|
|
|
3146
3146
|
});
|
|
3147
3147
|
|
|
3148
3148
|
// src/effects/auto-rename-ref/index.ts
|
|
3149
|
-
import { isArray, isObject as isObject2 } from "lodash";
|
|
3149
|
+
import { isArray, isObject as isObject2, uniq } from "lodash";
|
|
3150
3150
|
import {
|
|
3151
3151
|
DataEvent,
|
|
3152
3152
|
VariableFieldKeyRenameService
|
|
@@ -3167,9 +3167,30 @@ var autoRenameRefEffect = [
|
|
|
3167
3167
|
after.key
|
|
3168
3168
|
];
|
|
3169
3169
|
traverseRef(name, form.getValueIn(name), (_drilldownName, _v) => {
|
|
3170
|
-
if (
|
|
3171
|
-
|
|
3172
|
-
|
|
3170
|
+
if (_v.type === "ref") {
|
|
3171
|
+
if (isKeyPathMatch(_v.content, beforeKeyPath)) {
|
|
3172
|
+
_v.content = [...afterKeyPath, ...(_v.content || [])?.slice(beforeKeyPath.length)];
|
|
3173
|
+
form.setValueIn(_drilldownName, _v);
|
|
3174
|
+
}
|
|
3175
|
+
} else if (_v.type === "template") {
|
|
3176
|
+
const templateKeyPaths = getTemplateKeyPaths(_v);
|
|
3177
|
+
let hasMatch = false;
|
|
3178
|
+
templateKeyPaths.forEach((_keyPath) => {
|
|
3179
|
+
if (isKeyPathMatch(_keyPath, beforeKeyPath)) {
|
|
3180
|
+
hasMatch = true;
|
|
3181
|
+
const nextKeyPath = [
|
|
3182
|
+
...afterKeyPath,
|
|
3183
|
+
...(_keyPath || [])?.slice(beforeKeyPath.length)
|
|
3184
|
+
];
|
|
3185
|
+
_v.content = _v.content?.replace(
|
|
3186
|
+
`{{${_keyPath.join(".")}}`,
|
|
3187
|
+
`{{${nextKeyPath.join(".")}}`
|
|
3188
|
+
);
|
|
3189
|
+
}
|
|
3190
|
+
});
|
|
3191
|
+
if (hasMatch) {
|
|
3192
|
+
form.setValueIn(_drilldownName, { ..._v });
|
|
3193
|
+
}
|
|
3173
3194
|
}
|
|
3174
3195
|
});
|
|
3175
3196
|
});
|
|
@@ -3179,18 +3200,31 @@ var autoRenameRefEffect = [
|
|
|
3179
3200
|
}
|
|
3180
3201
|
}
|
|
3181
3202
|
];
|
|
3182
|
-
function
|
|
3183
|
-
return targetKeyPath.every((_key, index) => _key ===
|
|
3203
|
+
function isKeyPathMatch(keyPath = [], targetKeyPath) {
|
|
3204
|
+
return targetKeyPath.every((_key, index) => _key === keyPath[index]);
|
|
3205
|
+
}
|
|
3206
|
+
function getTemplateKeyPaths(value) {
|
|
3207
|
+
const keyPathReg = /{{(.*?)}}/g;
|
|
3208
|
+
return uniq(value.content?.match(keyPathReg) || []).map(
|
|
3209
|
+
(_keyPath) => _keyPath.slice(2, -2).split(".")
|
|
3210
|
+
);
|
|
3184
3211
|
}
|
|
3185
3212
|
function isRef(value) {
|
|
3186
3213
|
return value?.type === "ref" && Array.isArray(value?.content) && typeof value?.content[0] === "string";
|
|
3187
3214
|
}
|
|
3215
|
+
function isTemplate(value) {
|
|
3216
|
+
return value?.type === "template" && typeof value?.content === "string";
|
|
3217
|
+
}
|
|
3188
3218
|
function traverseRef(name, value, cb) {
|
|
3189
3219
|
if (isObject2(value)) {
|
|
3190
3220
|
if (isRef(value)) {
|
|
3191
3221
|
cb(name, value);
|
|
3192
3222
|
return;
|
|
3193
3223
|
}
|
|
3224
|
+
if (isTemplate(value)) {
|
|
3225
|
+
cb(name, value);
|
|
3226
|
+
return;
|
|
3227
|
+
}
|
|
3194
3228
|
Object.entries(value).forEach(([_key, _value]) => {
|
|
3195
3229
|
traverseRef(`${name}.${_key}`, _value, cb);
|
|
3196
3230
|
});
|