From 445da1a3a37298838ec18e419dae264e26b61f3f Mon Sep 17 00:00:00 2001 From: sakastudio Date: Sat, 3 Aug 2024 22:17:19 +0900 Subject: [PATCH 1/7] =?UTF-8?q?=E3=83=87=E3=83=95=E3=82=A9=E3=83=AB?= =?UTF-8?q?=E3=83=88=E5=80=A4=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=81=AE=E3=82=B5?= =?UTF-8?q?=E3=83=B3=E3=83=97=E3=83=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SchemaEditor/inputs/PrimitiveTypeInput.tsx | 6 +++++- .../app/components/SchemaEditor/inputs/VectorInput.tsx | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx index 8a232ef..dd45f03 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx @@ -21,10 +21,14 @@ interface Props { export function PrimitiveTypeInput({ showLabel = false, property, propertySchema, value, onChange }: Props) { const context = useOutletContext<{ master: ReturnType }>() const label = showLabel ? property : undefined + + const defaultValue = propertySchema && 'default' in propertySchema ? propertySchema['default'] : undefined; const props = { label, - value: value ?? (propertySchema && 'default' in propertySchema ? propertySchema['default'] : undefined), + value: value, + defaultValue: defaultValue } + if ('enum' in propertySchema) { return String(value))} onChange={onChange} /> } else if ('autoGenerated' in propertySchema && propertySchema.autoGenerated) { diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx index 310786f..e332217 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx @@ -5,6 +5,7 @@ import { FormWrapper } from '~/components/FormWrapper' type Props = ComponentProps & { dimensions: number, value: Array, + defaultValue?: Array, onChange(value: Array): void; } @@ -15,6 +16,11 @@ export const VectorInput = ({ ...props }: Props) => { const value = props.value ? props.value : new Array(dimensions).fill(null) + + if (!props.value && props.defaultValue) { + onChange(props.defaultValue); + } + return ( From ff4613930acb0238684eb11a19941b44d904fd10 Mon Sep 17 00:00:00 2001 From: sakastudio Date: Sun, 4 Aug 2024 14:52:49 +0900 Subject: [PATCH 2/7] =?UTF-8?q?value=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/components/SchemaEditor/inputs/VectorInput.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx index e332217..e62ce68 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/VectorInput.tsx @@ -15,12 +15,13 @@ export const VectorInput = ({ onChange, ...props }: Props) => { - const value = props.value ? props.value : new Array(dimensions).fill(null) if (!props.value && props.defaultValue) { onChange(props.defaultValue); } + const value = props.value ? props.value : new Array(dimensions).fill(null) + return ( From be0497d591bc752f4cd9e76ab43875ada59703c1 Mon Sep 17 00:00:00 2001 From: sakastudio Date: Sun, 4 Aug 2024 14:53:09 +0900 Subject: [PATCH 3/7] =?UTF-8?q?array=E3=81=AE=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E5=9C=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SchemaEditor/inputs/ArrayInput.tsx | 10 +++++++- apps/mooreseditor/app/schema/items.json | 23 +++++-------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx index a2c6dcf..7582022 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx @@ -7,12 +7,14 @@ import { PrimitiveTypeInput } from "./PrimitiveTypeInput"; type Props = ComponentProps & { propertySchema: ArraySchema, value: any, + defaultValue?: any, onChange(value: any): void; } export const ArrayInput = ({ propertySchema, - value = [], + value, + defaultValue, onChange, }: Props) => { const add = () => { @@ -21,6 +23,12 @@ export const ArrayInput = ({ '' ]) } + + if (!value && defaultValue) { + onChange(defaultValue as any); + } + value = value ? value : [] + return ( {value.map((eachValue: any, i: number) => { diff --git a/apps/mooreseditor/app/schema/items.json b/apps/mooreseditor/app/schema/items.json index b32f838..094f468 100644 --- a/apps/mooreseditor/app/schema/items.json +++ b/apps/mooreseditor/app/schema/items.json @@ -11,25 +11,14 @@ "thumbnail": "imagePath", "properties": { - "itemId": { - "type": "string", - "format": "uuid", - "autoGenerated": true - }, - "imagePath": { - "type": "string", - "pattern": "@imagePath", - "thumbnail": true - }, - "name": { - "type": "string" - }, - - "maxStack": { - "type": "integer", - "default" : 100 + "array2": { + "type": "array", + "items": { + "type": "string" + }, + "default": ["a", "b", "c"] } } } From 607a70bbaf8851f065ee201b33b5a98aa13e0542 Mon Sep 17 00:00:00 2001 From: sakastudio Date: Tue, 6 Aug 2024 00:03:54 +0900 Subject: [PATCH 4/7] =?UTF-8?q?arrayinput=E3=81=AE=E3=83=87=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AB=E3=83=88=E5=80=A4=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/components/SchemaEditor/inputs/ArrayInput.tsx | 5 ++--- .../components/SchemaEditor/inputs/PrimitiveTypeInput.tsx | 2 +- apps/mooreseditor/app/schema.ts | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx index 7582022..75e2ad1 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/ArrayInput.tsx @@ -14,7 +14,6 @@ type Props = ComponentProps & { export const ArrayInput = ({ propertySchema, value, - defaultValue, onChange, }: Props) => { const add = () => { @@ -24,8 +23,8 @@ export const ArrayInput = ({ ]) } - if (!value && defaultValue) { - onChange(defaultValue as any); + if (!value && propertySchema.default) { + onChange(propertySchema.default as any); } value = value ? value : [] diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx index a40d8c9..5da933c 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx @@ -68,7 +68,7 @@ export function PrimitiveTypeInput({ showLabel = false, property, propertySchema case '@vector4Int': return default: - return onChange(values)} /> + return onChange(values)} /> } default: null diff --git a/apps/mooreseditor/app/schema.ts b/apps/mooreseditor/app/schema.ts index 442bebd..003b441 100644 --- a/apps/mooreseditor/app/schema.ts +++ b/apps/mooreseditor/app/schema.ts @@ -53,26 +53,31 @@ export interface StringSchema { format?: string; foreignKey?: string; enum?: Array; + default?: string; } export interface IntegerSchema { type: 'integer'; enum?: Array; + default?: number; } export interface FloatSchema { type: 'number'; enum?: Array; + default?: number; } export interface BooleanSchema { type: 'boolean'; + default?: boolean; } export interface ArraySchema { type: 'array'; pattern?: string; items: Schema; + default?: Array; } export const isArraySchema = (schema: Schema): schema is ArraySchema => { From 26c59a4e3cc3212f36a5d9859e84b644656087d4 Mon Sep 17 00:00:00 2001 From: sakastudio Date: Tue, 6 Aug 2024 01:05:43 +0900 Subject: [PATCH 5/7] =?UTF-8?q?string=E3=81=AE=E3=83=87=E3=83=95=E3=82=A9?= =?UTF-8?q?=E3=83=AB=E3=83=88=E5=80=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/SchemaEditor/inputs/PrimitiveTypeInput.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx index 5da933c..61a06f6 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx @@ -47,12 +47,20 @@ export function PrimitiveTypeInput({ showLabel = false, property, propertySchema switch (propertySchema.type) { case 'integer': return + case 'number': return + case 'boolean': return + case 'string': + // TODO このデフォルト値はStringInputの中に入れたいがやり方が良くわからないのでとりあえずここに書いておく + if (!props.value && props.defaultValue) { + onChange(props.defaultValue as string); + } return onChange(e.currentTarget.value)} /> + case 'array': switch (propertySchema.pattern) { case '@vector2': From 4aedab13bd74adae01942b2e3f019d762c9af20e Mon Sep 17 00:00:00 2001 From: sakastudio Date: Tue, 6 Aug 2024 01:08:20 +0900 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BB=96=E3=81=AE=E3=83=87=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AB=E3=83=88=E5=80=A4=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SchemaEditor/inputs/PrimitiveTypeInput.tsx | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx index 61a06f6..58f278a 100644 --- a/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx +++ b/apps/mooreseditor/app/components/SchemaEditor/inputs/PrimitiveTypeInput.tsx @@ -46,17 +46,25 @@ export function PrimitiveTypeInput({ showLabel = false, property, propertySchema } else { switch (propertySchema.type) { case 'integer': + if (!props.value && props.defaultValue) {// TODO このデフォルト値はIntegerInputの中に入れたいがやり方が良くわからないのでとりあえずここに書いておく + onChange(props.defaultValue as number); + } return - + case 'number': + if (!props.value && props.defaultValue) {// TODO このデフォルト値はNumberInputの中に入れたいがやり方が良くわからないのでとりあえずここに書いておく + onChange(props.defaultValue as number); + } return case 'boolean': + if (!props.value && props.defaultValue) {// TODO このデフォルト値はBooleanInputの中に入れたいがやり方が良くわからないのでとりあえずここに書いておく + onChange(props.defaultValue as boolean); + } return case 'string': - // TODO このデフォルト値はStringInputの中に入れたいがやり方が良くわからないのでとりあえずここに書いておく - if (!props.value && props.defaultValue) { + if (!props.value && props.defaultValue) {// TODO このデフォルト値はStringInputの中に入れたいがやり方が良くわからないのでとりあえずここに書いておく onChange(props.defaultValue as string); } return onChange(e.currentTarget.value)} /> From 4f6af68530625ba9e7d3b25fae9ab34b4a3733b8 Mon Sep 17 00:00:00 2001 From: sakastudio Date: Tue, 6 Aug 2024 01:08:44 +0900 Subject: [PATCH 7/7] =?UTF-8?q?item=E3=81=AE=E3=82=B9=E3=82=AD=E3=83=BC?= =?UTF-8?q?=E3=83=9E=E3=82=92=E3=82=82=E3=81=A8=E3=81=AB=E6=88=BB=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/mooreseditor/app/schema/items.json | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/apps/mooreseditor/app/schema/items.json b/apps/mooreseditor/app/schema/items.json index 094f468..b32f838 100644 --- a/apps/mooreseditor/app/schema/items.json +++ b/apps/mooreseditor/app/schema/items.json @@ -11,14 +11,25 @@ "thumbnail": "imagePath", "properties": { + "itemId": { + "type": "string", + "format": "uuid", + "autoGenerated": true + }, + "imagePath": { + "type": "string", + "pattern": "@imagePath", + "thumbnail": true + }, - "array2": { - "type": "array", - "items": { - "type": "string" - }, - "default": ["a", "b", "c"] + "name": { + "type": "string" + }, + + "maxStack": { + "type": "integer", + "default" : 100 } } }