MCPcopy
hub / github.com/glideapps/glide-data-grid / pasteToCell

Function pasteToCell

packages/core/src/data-editor/data-editor.tsx:3300–3352  ·  view source on GitHub ↗
(
                inner: InnerGridCell,
                target: Item,
                rawValue: string | boolean | string[] | number | boolean | BooleanEmpty | BooleanIndeterminate,
                formatted?: string | string[]
            )

Source from the content-addressed store, hash-verified

3298 async (e?: ClipboardEvent) => {
3299 if (!keybindings.paste) return;
3300 function pasteToCell(
3301 inner: InnerGridCell,
3302 target: Item,
3303 rawValue: string | boolean | string[] | number | boolean | BooleanEmpty | BooleanIndeterminate,
3304 formatted?: string | string[]
3305 ): EditListItem | undefined {
3306 const stringifiedRawValue =
3307 typeof rawValue === "object" ? rawValue?.join("\n") ?? "" : rawValue?.toString() ?? "";
3308
3309 if (!isInnerOnlyCell(inner) && isReadWriteCell(inner) && inner.readonly !== true) {
3310 const coerced = coercePasteValue?.(stringifiedRawValue, inner);
3311 if (coerced !== undefined && isEditableGridCell(coerced)) {
3312 if (process.env.NODE_ENV !== "production" && coerced.kind !== inner.kind) {
3313 // eslint-disable-next-line no-console
3314 console.warn("Coercion should not change cell kind.");
3315 }
3316 return {
3317 location: target,
3318 value: coerced,
3319 };
3320 }
3321 const r = getCellRenderer(inner);
3322 if (r === undefined) return undefined;
3323 if (r.kind === GridCellKind.Custom) {
3324 assert(inner.kind === GridCellKind.Custom);
3325 const newVal = (r as unknown as CustomRenderer<CustomCell<any>>).onPaste?.(
3326 stringifiedRawValue,
3327 inner.data
3328 );
3329 if (newVal === undefined) return undefined;
3330 return {
3331 location: target,
3332 value: {
3333 ...inner,
3334 data: newVal,
3335 },
3336 };
3337 } else {
3338 const newVal = r.onPaste?.(stringifiedRawValue, inner, {
3339 formatted,
3340 formattedString: typeof formatted === "string" ? formatted : formatted?.join("\n"),
3341 rawValue,
3342 });
3343 if (newVal === undefined) return undefined;
3344 assert(newVal.kind === inner.kind);
3345 return {
3346 location: target,
3347 value: newVal,
3348 };
3349 }
3350 }
3351 return undefined;
3352 }
3353
3354 const selectedColumns = gridSelection.columns;
3355 const selectedRows = gridSelection.rows;

Callers 1

DataEditorImplFunction · 0.85

Calls 5

isInnerOnlyCellFunction · 0.85
isReadWriteCellFunction · 0.85
isEditableGridCellFunction · 0.85
assertFunction · 0.85
getCellRendererFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…