MCPcopy Index your code
hub / github.com/tinyplex/tinybase / EditableThing

Function EditableThing

src/ui-react-dom/common/components.tsx:142–330  ·  view source on GitHub ↗
({
  thing,
  onThingChange,
  className,
  hasSchema,
  showType = true,
}: {
  readonly thing: Cell | Value | undefined;
  readonly onThingChange: (thing: Cell | Value) => void;
  readonly className: string;
  readonly hasSchema: (() => boolean) | undefined;
  readonly showType?: boolean;
})

Source from the content-addressed store, hash-verified

140);
141
142export const EditableThing = ({
143 thing,
144 onThingChange,
145 className,
146 hasSchema,
147 showType = true,
148}: {
149 readonly thing: Cell | Value | undefined;
150 readonly onThingChange: (thing: Cell | Value) => void;
151 readonly className: string;
152 readonly hasSchema: (() => boolean) | undefined;
153 readonly showType?: boolean;
154}) => {
155 const [thingType, setThingType] = useState<CellOrValueType>();
156 const [currentThing, setCurrentThing] = useState<Cell | Value>();
157 const [stringThing, setStringThing] = useState<string>();
158 const [numberThing, setNumberThing] = useState<number>();
159 const [booleanThing, setBooleanThing] = useState<boolean>();
160 const [objectThing, setObjectThing] = useState<string>('{}');
161 const [arrayThing, setArrayThing] = useState<string>('[]');
162
163 const [objectClassName, setObjectClassName] = useState<string>('');
164 const [arrayClassName, setArrayClassName] = useState<string>('');
165
166 if (currentThing !== thing) {
167 setThingType(getCellOrValueType(thing));
168 setCurrentThing(thing);
169 if (isObject(thing)) {
170 setObjectThing(jsonString(thing));
171 } else if (isArray(thing)) {
172 setArrayThing(jsonString(thing));
173 } else {
174 setStringThing(string(thing));
175 setNumberThing(number(thing) || 0);
176 setBooleanThing(boolean(thing));
177 }
178 }
179
180 const handleThingChange = useCallback(
181 <T extends Cell | Value>(thing: T, setTypedThing: (thing: T) => void) => {
182 setTypedThing(thing);
183 setCurrentThing(thing);
184 onThingChange(thing);
185 },
186 [onThingChange],
187 );
188
189 const handleJsonThingChange = useCallback(
190 (
191 value: string,
192 setTypedThing: (value: string) => void,
193 isThing: (thing: any) => boolean,
194 setTypedClassName: (className: string) => void,
195 ) => {
196 setTypedThing(value);
197 try {
198 const object = jsonParse(value);
199 if (isThing(object)) {

Callers

nothing calls this directly

Calls 9

getCellOrValueTypeFunction · 0.90
isObjectFunction · 0.90
isArrayFunction · 0.90
stringFunction · 0.90
numberFunction · 0.90
getTypeCaseFunction · 0.90
tryReturnFunction · 0.90
handleThingChangeFunction · 0.50
handleJsonThingChangeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…