Skip to content

Commit c4918aa

Browse files
committed
feat: add hasDefault field to property spec
1 parent b932e92 commit c4918aa

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

packages/react/src/editor/BlockGroup/BlockGroup.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ export const BlockGroup: FC<Props> = ({ category, blocks }) => (
2222
const propertySpecs = block.props ?? {};
2323

2424
const defaultProps = Object.entries(propertySpecs).reduce(
25-
(acc, [key, value]) =>
26-
value?.default && !value.optional
27-
? {
28-
...acc,
29-
[key]:
30-
propertySpecs[key].type === 'node'
31-
? Parser.parse(toJsxString(value.default))
32-
: value.default,
33-
}
34-
: acc,
25+
(acc, [key, value]) => {
26+
if (value?.hasDefault) {
27+
acc[key] =
28+
propertySpecs[key].type === 'node'
29+
? Parser.parse(toJsxString(value.default))
30+
: value.default;
31+
}
32+
33+
return acc;
34+
},
3535
{} as Record<string, unknown>,
3636
);
3737

packages/react/src/renderer/Catalog/Catalog.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export const clear = () => {
9090
};
9191

9292
const setSpecDefault = (spec: PropertySpec<any>): void => {
93+
spec.hasDefault = typeof spec.default !== 'undefined';
94+
9395
switch (spec.type) {
9496
case 'array':
9597
spec.default ??= [];

packages/react/src/renderer/PropertySpec/PropertySpec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
/** biome-ignore-all lint/suspicious/noExplicitAny: for arbitrary values */
2+
import type { ReactNode } from 'react';
3+
24
type DefaultPropertySpec<Value> = {
35
label: string;
46
default?: Value;
57
optional?: boolean;
8+
hasDefault?: boolean;
69
};
710

811
export type BooleanPropertySpec<Value> = DefaultPropertySpec<Value> & { type: 'boolean' };
@@ -34,7 +37,7 @@ export type RadioPropertySpec<Value> = DefaultPropertySpec<Value> & {
3437
} & (
3538
| {
3639
options: {
37-
label: string;
40+
label: ReactNode;
3841
value: Value;
3942
}[];
4043
}

0 commit comments

Comments
 (0)