import { FC, useCallback, useEffect, useState } from "react"; import { useObjectStateWrapper } from "../../hooks/useObjectState"; import { ValueField } from "./value-field"; import { HelpPopper } from "../Poppables/help"; import { Icon } from "../Icon"; import { RESERVED_FIELDS } from "../../constants/ReservedFields"; import { fieldTypeOptions, FieldTypes, fieldTypesWithValues, } from "./fieldtypes"; interface IProps { update: (arg: FieldType) => void; field: FieldType; fieldName: string; deleteField: (arg: string) => void; } export const FieldEditor: FC = ( { update, field, fieldName, deleteField }, ) => { const { bindProperty, bindPropertyCheck } = useObjectStateWrapper( field, (e) => update(typeof e === "function" ? e(field) : e), ); const shouldShowValueField = useCallback( () => fieldTypesWithValues.includes(field.type) || field.isConstant, [field.isConstant, field.type], ); const [reserved, setReserved] = useState( RESERVED_FIELDS[fieldName], ); useEffect(() => { setReserved(RESERVED_FIELDS[fieldName]); }, [fieldName]); // useEffect(() => { // console.log(field.value); // }, [field]) return (
  • {fieldName}

    {reserved && (

    This is a reserved field name, these exist for internal purposes, but are still useful when creating a type, and as such have specific settings that you cannot override. If you need control over the field properties, please use a different field name

    )}
    {!reserved && (
    {shouldShowValueField() && ( )}

    Constant values can't be overwritten in publications. When a dice field is set to a constant value, it instead rolls a dice of that value whenever this field is displayed (unless exported). This could be useful for a randomly generated scenario or for cards being drawn as the dice value will automatically be determined by the dice roll.

    Minimum and Limit apply to the number of entries allowed for this field, not the maximum and minimum value. Set the minimum to 0 to make a field optional. Set the limit to 0 to allow for unlimited entries.

    )}
  • ); };