MCPcopy
hub / github.com/tinyplex/tinybase / EditableThing

Function EditableThing

src/ui-solid-dom/common/components.tsx:146–309  ·  view source on GitHub ↗
(props: {
  readonly thing: Cell | Value | undefined;
  readonly onThingChange: (thing: Cell | Value) => void;
  readonly class: string;
  readonly hasSchema: (() => boolean) | undefined;
  readonly showType?: boolean;
})

Source from the content-addressed store, hash-verified

144};
145
146export const EditableThing = (props: {
147 readonly thing: Cell | Value | undefined;
148 readonly onThingChange: (thing: Cell | Value) => void;
149 readonly class: string;
150 readonly hasSchema: (() => boolean) | undefined;
151 readonly showType?: boolean;
152}) => {
153 const [thingType, setThingType] = createSignal<CellOrValueType>();
154 const [currentThing, setCurrentThing] = createSignal<Cell | Value>();
155 const [stringThing, setStringThing] = createSignal<string>();
156 const [numberThing, setNumberThing] = createSignal<number>();
157 const [booleanThing, setBooleanThing] = createSignal<boolean>();
158 const [objectThing, setObjectThing] = createSignal<string>('{}');
159 const [arrayThing, setArrayThing] = createSignal<string>('[]');
160
161 const [objectClassName, setObjectClassName] = createSignal<string>('');
162 const [arrayClassName, setArrayClassName] = createSignal<string>('');
163
164 createRenderEffect(() => {
165 const thing = props.thing;
166 if (untrack(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
181 const handleThingChange = <Thing extends Cell | Value>(
182 thing: Thing,
183 setTypedThing: (thing: Thing) => void,
184 ) => {
185 setTypedThing(thing);
186 setCurrentThing(() => thing);
187 props.onThingChange(thing);
188 };
189
190 const handleJsonThingChange = (
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)) {
200 setCurrentThing(() => object);
201 props.onThingChange(object);
202 setTypedClassName('');
203 }

Callers 2

EditableCellViewFunction · 0.90
EditableValueViewFunction · 0.90

Calls 6

getCellOrValueTypeFunction · 0.90
isObjectFunction · 0.90
isArrayFunction · 0.90
stringFunction · 0.90
numberFunction · 0.90
contentFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…