@cratis/components.migrator 4.14.1 → 4.14.2

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/README.md CHANGED
@@ -181,27 +181,16 @@ The transform never guesses through JSX spreads, dynamic legacy values, duplicat
181
181
 
182
182
  ## `change-handler`
183
183
 
184
- `cratis-components-change-handler` resolves affected Components-owned JSX identifiers imported with aliases or namespaces from `@cratis/components/Dropdown`, `@cratis/components/CommandForm`, and `@cratis/components/CommandForm/fields`. It rewrites only a structurally-proven single forwarding callback:
184
+ `cratis-components-change-handler` resolves Components-owned JSX identifiers imported with aliases or namespaces from `@cratis/components/Dropdown`, `@cratis/components/CommandForm`, and `@cratis/components/CommandForm/fields`. It rewrites structurally-proven single forwarding callbacks on standalone `Dropdown` and CommandForm field `onValueChange` props:
185
185
 
186
186
  ```tsx
187
- // Safe rewrites
187
+ // Before
188
188
  <Dropdown onChange={(event) => setRole(event.value)} />
189
- <InputTextField onChange={(event) => setName(event.target.value)} />
190
- <CheckboxField onChange={({ target: { checked } }) => setEnabled(checked)} />
191
-
192
- // become
189
+ // After
193
190
  <Dropdown onChange={(value) => setRole(value)} />
194
- <InputTextField onChange={(value) => setName(value)} />
195
- <CheckboxField onChange={(value) => setEnabled(value)} />
196
191
  ```
197
192
 
198
- The affected CommandForm fields cover legacy `target`/`currentTarget` `value`, `checked`, and `valueAsNumber` payloads, plus `DropdownField`/`MultiSelectField` `event.value`. Already-semantic callbacks and callback references such as `onChange={setValue}` are unchanged.
199
-
200
- The transform changes a callback's shape, not where it lives. With Arc 22.16.0, `CommandForm` calls an
201
- `onChange` placed on a field with the new value at runtime, but the Components 4 CommandForm field
202
- types do not declare `onChange`, so type-checked TSX reports TS2322 on a field that keeps one. Move
203
- those side effects to `CommandForm`'s `onFieldChange` callback. The standalone `Dropdown` declares
204
- `onChange` and is not affected. The [Components 3 to 4 migration guide](https://cratis.io/components/migration/3-to-4/) covers this case.
193
+ For Components 4 CommandForm fields, the codemod leaves `onChange` unchanged and reports an actionable diagnostic instead of changing its callback. Arc's `asCommandFormField` wrappers do not expose `onChange` as a field prop in Components 4, so keeping the attribute would produce TS2322 even if the callback were rewritten. Move its side effects to the enclosing `CommandForm`'s `onFieldChange(command, fieldName, oldValue, newValue, validationInfo?)` callback. Legacy `onValueChange` field callbacks with a proven event payload are rewritten to semantic values; already-semantic `onValueChange` callbacks are untouched. The [Components 3 to 4 migration guide](https://cratis.io/components/migration/3-to-4/) covers this case.
205
194
 
206
195
  Multi-statement, multi-use, wrong-payload, destructuring-with-default/rest, and native-event-dependent callbacks are refused, reported, and annotated once:
207
196
 
@@ -96,6 +96,14 @@ export function transformChangeHandlers(fileName, text, options = {}) {
96
96
  if (!ts.isJsxAttribute(attribute)) continue;
97
97
  const propName = attribute.name.getText(sourceFile);
98
98
  if (propName !== 'onChange' && propName !== 'onValueChange') continue;
99
+ if (target.group === 'CommandForm' && propName === 'onChange') {
100
+ report(
101
+ attribute,
102
+ target.component,
103
+ "Components 4 field props do not accept onChange; move the handler to the enclosing CommandForm's onFieldChange(command, fieldName, oldValue, newValue, validationInfo?)",
104
+ );
105
+ continue;
106
+ }
99
107
  if (
100
108
  !attribute.initializer ||
101
109
  !ts.isJsxExpression(attribute.initializer) ||
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/components.migrator",
3
- "version": "4.14.1",
3
+ "version": "4.14.2",
4
4
  "description": "Migration tooling for updating @cratis/components consumers from Components 3 to Components 4.",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",