@cratis/scene.react 4.30.0 → 4.31.0

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": "@cratis/scene.react",
3
- "version": "4.30.0",
3
+ "version": "4.31.0",
4
4
  "description": "The React renderer implementing Scene.Engine's Renderer contract against real React/DOM.",
5
5
  "keywords": [
6
6
  "cratis",
@@ -51,12 +51,12 @@
51
51
  "build-storybook": "storybook build"
52
52
  },
53
53
  "dependencies": {
54
- "@cratis/scene.engine": "4.30.0",
55
- "@cratis/scene.model": "4.30.0"
54
+ "@cratis/scene.engine": "4.31.0",
55
+ "@cratis/scene.model": "4.31.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@cratis/scene.engine": "4.30.0",
59
- "@cratis/scene.model": "4.30.0",
58
+ "@cratis/scene.engine": "4.31.0",
59
+ "@cratis/scene.model": "4.31.0",
60
60
  "@storybook/addon-links": "^10.6.1",
61
61
  "@storybook/react": "^10.6.1",
62
62
  "@storybook/react-vite": "^10.6.1",
@@ -16,4 +16,7 @@ export interface SliceCommandField {
16
16
 
17
17
  /** Whether the field must have a value. */
18
18
  required?: boolean;
19
+
20
+ /** The value the field starts with - a preview fills it from the active sample data pack; a running application leaves it out. */
21
+ initialValue?: string | number | boolean;
19
22
  }
@@ -44,6 +44,17 @@ function inputTypeOf(field: SliceCommandField): string {
44
44
  }
45
45
  }
46
46
 
47
+ /** What the form starts with: the fields that carry an initial value, as the strings and booleans the inputs hold. */
48
+ function initialValuesOf(fields: SliceCommandField[]): Record<string, string | boolean> {
49
+ const values: Record<string, string | boolean> = {};
50
+ for (const field of fields) {
51
+ if (field.initialValue === undefined) continue;
52
+ values[field.name] = typeof field.initialValue === 'boolean' && inputTypeOf(field) === 'checkbox' ? field.initialValue : String(field.initialValue);
53
+ }
54
+
55
+ return values;
56
+ }
57
+
47
58
  /** The payload a form's values make: numbers and booleans as such, an empty number left out. */
48
59
  export function slicePayload(fields: SliceCommandField[], values: Record<string, string | boolean>): Record<string, unknown> {
49
60
  const payload: Record<string, unknown> = {};
@@ -88,7 +99,7 @@ export function SliceDialogView({ slice: sliceProp, command: commandProp, title:
88
99
  return index.findSlice(slice)?.id ?? slice.split('.').pop() ?? slice;
89
100
  }, [model, slice]);
90
101
 
91
- const [values, setValues] = useState<Record<string, string | boolean>>({});
102
+ const [values, setValues] = useState<Record<string, string | boolean>>(() => initialValuesOf(fields));
92
103
  const [errors, setErrors] = useState<InvocationValidationError[]>([]);
93
104
  const [submitting, setSubmitting] = useState(false);
94
105
  const form = useRef<HTMLFormElement>(null);