1+ import React from "https://esm.sh/react@19.0"
2+ import ReactDOM from "https://esm.sh/react-dom@19.0/client"
3+ import { AgGridReact } from "https://esm.sh/ag-grid-react@32.2.0?deps=react@19.0,react-dom@19.0,react-is@19.0" ;
4+ export { AgGridReact } ;
5+
6+ loadCSS ( "https://unpkg.com/@ag-grid-community/styles@32.2.0/ag-grid.css" ) ;
7+ loadCSS ( "https://unpkg.com/@ag-grid-community/styles@32.2.0/ag-theme-quartz.css" )
8+
9+ function loadCSS ( href ) {
10+ var head = document . getElementsByTagName ( 'head' ) [ 0 ] ;
11+
12+ if ( document . querySelectorAll ( `link[href="${ href } "]` ) . length === 0 ) {
13+ // Creating link element
14+ var style = document . createElement ( 'link' ) ;
15+ style . id = href ;
16+ style . href = href ;
17+ style . type = 'text/css' ;
18+ style . rel = 'stylesheet' ;
19+ head . append ( style ) ;
20+ }
21+ }
22+
23+ export function bind ( node , config ) {
24+ const root = ReactDOM . createRoot ( node ) ;
25+ return {
26+ create : ( component , props , children ) =>
27+ React . createElement ( component , wrapEventHandlers ( props ) , ...children ) ,
28+ render : ( element ) => root . render ( element ) ,
29+ unmount : ( ) => root . unmount ( )
30+ } ;
31+ }
32+
33+ function wrapEventHandlers ( props ) {
34+ const newProps = Object . assign ( { } , props ) ;
35+ for ( const [ key , value ] of Object . entries ( props ) ) {
36+ if ( typeof value === "function" && value . toString ( ) . includes ( '.sendMessage' ) ) {
37+ newProps [ key ] = makeJsonSafeEventHandler ( value ) ;
38+ }
39+ }
40+ return newProps ;
41+ }
42+
43+ function stringifyToDepth ( val , depth , replacer , space ) {
44+ depth = isNaN ( + depth ) ? 1 : depth ;
45+ function _build ( key , val , depth , o , a ) { // (JSON.stringify() has it's own rules, which we respect here by using it for property iteration)
46+ return ! val || typeof val != 'object' ? val : ( a = Array . isArray ( val ) , JSON . stringify ( val , function ( k , v ) { if ( a || depth > 0 ) { if ( replacer ) v = replacer ( k , v ) ; if ( ! k ) return ( a = Array . isArray ( v ) , val = v ) ; ! o && ( o = a ?[ ] :{ } ) ; o [ k ] = _build ( k , v , a ?depth :depth - 1 ) ; } } ) , o || ( a ?[ ] :{ } ) ) ;
47+ }
48+ return JSON . stringify ( _build ( '' , val , depth ) , null , space ) ;
49+ }
50+
51+ function makeJsonSafeEventHandler ( oldHandler ) {
52+ // Since we can't really know what the event handlers get passed we have to check if
53+ // they are JSON serializable or not. We can allow normal synthetic events to pass
54+ // through since the original handler already knows how to serialize those for us.
55+ return function safeEventHandler ( ) {
56+
57+ var filteredArguments = [ ] ;
58+ Array . from ( arguments ) . forEach ( function ( arg ) {
59+ if ( typeof arg === "object" && arg . nativeEvent ) {
60+ // this is probably a standard React synthetic event
61+ filteredArguments . push ( arg ) ;
62+ } else {
63+ filteredArguments . push ( JSON . parse ( stringifyToDepth ( arg , 3 , ( key , value ) => {
64+ if ( key === '' ) return value ;
65+ try {
66+ JSON . stringify ( value ) ;
67+ return value ;
68+ } catch ( err ) {
69+ return ( typeof value === 'object' ) ? value : undefined ;
70+ }
71+ } ) ) )
72+ }
73+ } ) ;
74+ oldHandler ( ...Array . from ( filteredArguments ) ) ;
75+ } ;
76+ }
0 commit comments