MCPcopy Create free account
hub / github.com/tinyplex/tinybase / EditableThing

Function EditableThing

docs/pseudo.esm.sh/tinybase@9.0.0/ui-react-dom/index.js:755–933  ·  view source on GitHub ↗
({
  thing,
  onThingChange,
  className,
  hasSchema,
  showType = true
})

Source from the content-addressed store, hash-verified

753 ]
754});
755var EditableThing = ({
756 thing,
757 onThingChange,
758 className,
759 hasSchema,
760 showType = true
761}) => {
762 const [thingType, setThingType] = useState2();
763 const [currentThing, setCurrentThing] = useState2();
764 const [stringThing, setStringThing] = useState2();
765 const [numberThing, setNumberThing] = useState2();
766 const [booleanThing, setBooleanThing] = useState2();
767 const [objectThing, setObjectThing] = useState2("{}");
768 const [arrayThing, setArrayThing] = useState2("[]");
769 const [objectClassName, setObjectClassName] = useState2("");
770 const [arrayClassName, setArrayClassName] = useState2("");
771 if (currentThing !== thing) {
772 setThingType(getCellOrValueType(thing));
773 setCurrentThing(thing);
774 if (isObject2(thing)) {
775 setObjectThing(jsonString2(thing));
776 } else if (isArray2(thing)) {
777 setArrayThing(jsonString2(thing));
778 } else {
779 setStringThing(string(thing));
780 setNumberThing(number(thing) || 0);
781 setBooleanThing(boolean(thing));
782 }
783 }
784 const handleThingChange = useCallback2(
785 (thing2, setTypedThing) => {
786 setTypedThing(thing2);
787 setCurrentThing(thing2);
788 onThingChange(thing2);
789 },
790 [onThingChange]
791 );
792 const handleJsonThingChange = useCallback2(
793 (value, setTypedThing, isThing, setTypedClassName) => {
794 setTypedThing(value);
795 try {
796 const object3 = jsonParse(value);
797 if (isThing(object3)) {
798 setCurrentThing(object3);
799 onThingChange(object3);
800 setTypedClassName("");
801 }
802 } catch {
803 setTypedClassName("invalid");
804 }
805 },
806 [onThingChange]
807 );
808 const handleTypeChange = useCallback2(() => {
809 if (!hasSchema?.()) {
810 const nextType = getTypeCase(
811 thingType,
812 NUMBER,

Callers

nothing calls this directly

Calls 9

stringFunction · 0.85
numberFunction · 0.85
getCellOrValueTypeFunction · 0.70
isObject2Function · 0.70
isArray2Function · 0.70
getTypeCaseFunction · 0.70
tryReturnFunction · 0.70
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…