@worksafevictoria/wcl7.5 1.17.0-beta.6 → 1.17.0-beta.7

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worksafevictoria/wcl7.5",
3
- "version": "1.17.0-beta.6",
3
+ "version": "1.17.0-beta.7",
4
4
  "description": "WorkSafe Victoria Component Library - GitHub Actions Migration Test",
5
5
  "main": "src/index.js",
6
6
  "license": "MIT",
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  convertStringWithDotNotationToObject,
3
3
  generateUniqueId,
4
- isEmpty
4
+ isEmpty,
5
5
  } from '../models/form-utils'
6
6
 
7
7
  export function parseElementStates(webformElement) {
@@ -75,17 +75,38 @@ function ruleToString(rule) {
75
75
  }
76
76
 
77
77
  function ruleItemToString(ruleItem, itemKey) {
78
- const fieldName = itemKey.split(' ')[1] || itemKey.split(' ')[0]
79
- const formElementID = fieldName?.match(/"([^']+)"/)[1]
78
+ // Regex 1: Matches standard selectors (name="foo"). Captures 'foo'.
79
+ const standardMatch = itemKey.match(/name="([^"]+)"/)
80
+ // Regex 2: Matches array selectors (name="foo[bar]"). Captures 'foo' and 'bar'.
81
+ const arrayMatch = itemKey.match(/name="([^"]+)\[([^\]]+)\]"/)
82
+
83
+ let formComponentID = null // The Formio component key (e.g., 'checkboxes')
84
+ let checkboxOptionKey = null // The specific option key (e.g., 'foo bar')
85
+
86
+ if (arrayMatch && arrayMatch[1] && arrayMatch[2]) {
87
+ // Array Notation found (e.g., name="checkboxes[foo bar]")
88
+ formComponentID = arrayMatch[1]
89
+ checkboxOptionKey = arrayMatch[2]
90
+ } else if (standardMatch && standardMatch[1]) {
91
+ // Standard Notation found (e.g., name="foobar")
92
+ formComponentID = standardMatch[1]
93
+ }
94
+
95
+ // ... (rest of the function)
96
+
97
+ // Now pass BOTH keys to getTrigger for array-based lookups
80
98
  const conditions = Object.keys(ruleItem)
81
99
  .map((elementProp) =>
82
- formElementID ? getTrigger(formElementID, ruleItem, elementProp) : null
100
+ formComponentID
101
+ ? getTrigger(formComponentID, ruleItem, elementProp, checkboxOptionKey)
102
+ : null,
83
103
  )
84
104
  .filter((trigger) => !!trigger)
85
105
  .reduce((triggers, trigger) => {
86
106
  triggers.push(trigger)
87
107
  return triggers
88
108
  }, [])
109
+
89
110
  return conditions.join('')
90
111
  }
91
112
 
@@ -95,7 +116,7 @@ function createNewLogic(actionName, actionValue) {
95
116
  convertStringWithDotNotationToObject(
96
117
  defaultProps,
97
118
  actionName,
98
- !!!actionValue
119
+ !!!actionValue,
99
120
  )
100
121
  } else {
101
122
  defaultProps[actionName] = !!!actionValue
@@ -104,7 +125,7 @@ function createNewLogic(actionName, actionValue) {
104
125
  name: generateUniqueId(),
105
126
  trigger: {
106
127
  type: 'javascript',
107
- javascript: ''
128
+ javascript: '',
108
129
  },
109
130
  defaultProps,
110
131
  actions: [
@@ -114,20 +135,31 @@ function createNewLogic(actionName, actionValue) {
114
135
  property: {
115
136
  label: generateUniqueId(),
116
137
  value: actionName,
117
- type: 'boolean'
138
+ type: 'boolean',
118
139
  },
119
- state: actionValue
120
- }
121
- ]
140
+ state: actionValue,
141
+ },
142
+ ],
122
143
  }
123
144
  }
124
145
 
125
- function getTrigger(formElementID, ruleItem, prop) {
146
+ function getTrigger(formComponentID, ruleItem, prop, checkboxOptionKey = null) {
126
147
  if (ruleItem.hasOwnProperty(prop)) {
127
148
  const value = ruleItem[prop] ?? ''
149
+
150
+ let variable = `data.{${formComponentID}}`
151
+ console.log('🚀 ~ getTrigger ~ variable:', variable)
128
152
  let valueDelimeter = typeof value === 'string' ? "'" : ''
129
153
  let expression = `${valueDelimeter}${value}${valueDelimeter}`
130
- let variable = `data.{${formElementID}}`
154
+
155
+ if (checkboxOptionKey && prop === 'checked' && value === true) {
156
+ return `(${variable}['${checkboxOptionKey}']===true)`
157
+ }
158
+
159
+ if (checkboxOptionKey && prop === 'unchecked' && value === true) {
160
+ return `(!(${variable}['${checkboxOptionKey}']===true))`
161
+ }
162
+
131
163
  if (typeof value !== 'object' && prop === 'value') {
132
164
  return `${variable} === ${expression}`
133
165
  } else if (typeof value === 'object' && prop === 'value') {
@@ -177,7 +177,7 @@ export default {
177
177
  },
178
178
  initialDisplyLimit: {
179
179
  type: Number,
180
- default: 0,
180
+ default: 1000,
181
181
  },
182
182
  fetchContent: {
183
183
  type: Function,