shelving 1.230.1 → 1.231.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
package/ui/form/SchemaInput.js
CHANGED
|
@@ -80,7 +80,7 @@ export function BooleanSchemaInput({ schema, value, ...props }) {
|
|
|
80
80
|
return _jsx(CheckboxInput, { ...schema, value: !!value, ...props });
|
|
81
81
|
}
|
|
82
82
|
export function StringSchemaInput({ schema, value, ...props }) {
|
|
83
|
-
return _jsx(TextInput, { ...schema, value: getString(value), ...props });
|
|
83
|
+
return _jsx(TextInput, { ...schema, value: getString(value), formatter: str => schema.format(schema.sanitize(str)), ...props });
|
|
84
84
|
}
|
|
85
85
|
export function ArraySchemaInput({ schema, value, ...props }) {
|
|
86
86
|
return _jsx(ArrayInput, { ...schema, value: isArray(value) ? value : undefined, ...props });
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { renderToStaticMarkup } from "react-dom/server";
|
|
3
|
+
import { StringSchema } from "../../schema/index.js";
|
|
4
|
+
import { PASSTHROUGH } from "../../util/function.js";
|
|
5
|
+
import { StringSchemaInput } from "./SchemaInput.js";
|
|
6
|
+
|
|
7
|
+
describe("StringSchemaInput", () => {
|
|
8
|
+
test("formats the initial value to its clean sanitized value", () => {
|
|
9
|
+
// The `formatter` runs `schema.sanitize()` then `schema.format()`, so runs of whitespace collapse and the value trims.
|
|
10
|
+
const schema = new StringSchema({});
|
|
11
|
+
const html = renderToStaticMarkup(<StringSchemaInput name="title" schema={schema} value=" hello world " onValue={PASSTHROUGH} />);
|
|
12
|
+
|
|
13
|
+
expect(html).toContain('value="hello world"');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test("applies the schema case when sanitizing", () => {
|
|
17
|
+
// An `upper` schema sanitizes to uppercase, so the clean value is uppercased.
|
|
18
|
+
const schema = new StringSchema({ case: "upper" });
|
|
19
|
+
const html = renderToStaticMarkup(<StringSchemaInput name="code" schema={schema} value=" ab cd " onValue={PASSTHROUGH} />);
|
|
20
|
+
|
|
21
|
+
expect(html).toContain('value="AB CD"');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("applies a subclass `format()` after sanitizing", () => {
|
|
25
|
+
// A subclass `format()` is non-identity (here wrapping in brackets), so the clean value is sanitized then formatted.
|
|
26
|
+
class BracketSchema extends StringSchema {
|
|
27
|
+
override format(str: string): string {
|
|
28
|
+
return str ? `[${str}]` : str;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const schema = new BracketSchema({});
|
|
32
|
+
const html = renderToStaticMarkup(<StringSchemaInput name="tag" schema={schema} value=" abc " onValue={PASSTHROUGH} />);
|
|
33
|
+
|
|
34
|
+
expect(html).toContain('value="[abc]"');
|
|
35
|
+
});
|
|
36
|
+
});
|
package/ui/form/SchemaInput.tsx
CHANGED
|
@@ -115,7 +115,7 @@ export function BooleanSchemaInput({ schema, value, ...props }: BooleanSchemaInp
|
|
|
115
115
|
export interface StringSchemaInputProps extends SchemaInputProps<StringSchema, unknown> {}
|
|
116
116
|
|
|
117
117
|
export function StringSchemaInput({ schema, value, ...props }: StringSchemaInputProps): ReactElement {
|
|
118
|
-
return <TextInput {...schema} value={getString(value)} {...props} />;
|
|
118
|
+
return <TextInput {...schema} value={getString(value)} formatter={str => schema.format(schema.sanitize(str))} {...props} />;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface ArraySchemaInputProps extends SchemaInputProps<ArraySchema<unknown>, unknown> {}
|