@openmrs/esm-form-engine-lib 4.1.1-pre.2348 → 4.1.1-pre.2355

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.
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAoD7F;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAQjG;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,WAM7E"}
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/components/repeat/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAI9D,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,aAoD7F;AAED,wBAAgB,yBAAyB,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAajG;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,WAM7E"}
@@ -45,15 +45,16 @@ export function cloneRepeatField(srcField, value, idSuffix) {
45
45
  return clonedField;
46
46
  }
47
47
  export function updateFieldIdInExpression(expression, index, questionIds) {
48
- let uniqueQuestionIds = [
48
+ const uniqueQuestionIds = [
49
49
  ...new Set(questionIds)
50
50
  ];
51
- uniqueQuestionIds.forEach((id)=>{
52
- if (expression.match(id)) {
53
- expression = expression.replace(new RegExp(id, 'g'), `${id}_${index}`);
54
- }
55
- });
56
- return expression;
51
+ if (!uniqueQuestionIds.length) {
52
+ return expression;
53
+ }
54
+ // Sort by length desc so longer ids are tried before their shorter prefixes (e.g. `status_code` before `status`).
55
+ // Word boundaries keep the match from landing inside a longer identifier; regex metachars in ids are escaped.
56
+ const pattern = uniqueQuestionIds.slice().sort((a, b)=>b.length - a.length).map((id)=>id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('|');
57
+ return expression.replace(new RegExp(`\\b(?:${pattern})\\b`, 'g'), (match)=>`${match}_${index}`);
57
58
  }
58
59
  export function disableRepeatAddButton(limit, counter) {
59
60
  const repeatLimit = Number(limit);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/esm-form-engine-lib",
3
- "version": "4.1.1-pre.2348",
3
+ "version": "4.1.1-pre.2355",
4
4
  "description": "React Form Engine for O3",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -59,13 +59,18 @@ export function cloneRepeatField(srcField: FormField, value: OpenmrsResource, id
59
59
  }
60
60
 
61
61
  export function updateFieldIdInExpression(expression: string, index: number, questionIds: string[]) {
62
- let uniqueQuestionIds = [...new Set(questionIds)];
63
- uniqueQuestionIds.forEach((id) => {
64
- if (expression.match(id)) {
65
- expression = expression.replace(new RegExp(id, 'g'), `${id}_${index}`);
66
- }
67
- });
68
- return expression;
62
+ const uniqueQuestionIds = [...new Set(questionIds)];
63
+ if (!uniqueQuestionIds.length) {
64
+ return expression;
65
+ }
66
+ // Sort by length desc so longer ids are tried before their shorter prefixes (e.g. `status_code` before `status`).
67
+ // Word boundaries keep the match from landing inside a longer identifier; regex metachars in ids are escaped.
68
+ const pattern = uniqueQuestionIds
69
+ .slice()
70
+ .sort((a, b) => b.length - a.length)
71
+ .map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
72
+ .join('|');
73
+ return expression.replace(new RegExp(`\\b(?:${pattern})\\b`, 'g'), (match) => `${match}_${index}`);
69
74
  }
70
75
 
71
76
  export function disableRepeatAddButton(limit: string | number, counter: number) {