123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656type'valueref={mutablecurrent:'value}typedomRef=CallbackDomRefof(Dom.elementJs.nullable->unit)|CurrentDomRefofDom.elementJs.nullablerefmoduleRef=structtypet=domReftypecurrentDomRef=Dom.elementJs.nullablereftypecallbackDomRef=Dom.elementJs.nullable->unitletdomRef(v:currentDomRef)=CurrentDomRefvletcallbackDomRef(v:callbackDomRef)=CallbackDomRefvendletcreateRef()={current=None}letuseRefvalue={current=value}letforwardReff=f()moduleEvent=structtype'asyntheticmoduleMakeEventWithType(Type:sigtypetend)=structletbubbles:Type.t->bool=fun_->falseletcancelable:Type.t->bool=fun_->falseletcurrentTarget:Type.t-><..>Js.t=fun_->objectendletdefaultPrevented:Type.t->bool=fun_->falseleteventPhase:Type.t->int=fun_->0letisTrusted:Type.t->bool=fun_->falseletnativeEvent:Type.t-><..>Js.t=fun_->objectendletpreventDefault:Type.t->unit=fun_->()letisDefaultPrevented:Type.t->bool=fun_->falseletstopPropagation:Type.t->unit=fun_->()letisPropagationStopped:Type.t->bool=fun_->falselettarget:Type.t-><..>Js.t=fun_->objectendlettimeStamp:Type.t->float=fun_->0.lettype_:Type.t->string=fun_->""letpersist:Type.t->unit=fun_->()endmoduleSynthetic=structtypetagtypet=tagsyntheticletbubbles:'asynthetic->bool=fun_->falseletcancelable:'asynthetic->bool=fun_->falseletcurrentTarget:'asynthetic-><..>Js.t=fun_->objectendletdefaultPrevented:'asynthetic->bool=fun_->falseleteventPhase:'asynthetic->int=fun_->0letisTrusted:'asynthetic->bool=fun_->falseletnativeEvent:'asynthetic-><..>Js.t=fun_->objectendletpreventDefault:'asynthetic->unit=fun_->()letisDefaultPrevented:'asynthetic->bool=fun_->falseletstopPropagation:'asynthetic->unit=fun_->()letisPropagationStopped:'asynthetic->bool=fun_->falselettarget:'asynthetic-><..>Js.t=fun_->objectendlettimeStamp:'asynthetic->float=fun_->0.lettype_:'asynthetic->string=fun_->""letpersist:'asynthetic->unit=fun_->()end(* let toSyntheticEvent : 'a synthetic -> Synthetic.t = i -> i *)moduleClipboard=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letclipboardData:t-><..>Js.t=fun_->objectendendmoduleComposition=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdata:t->string=fun_->""endmoduleKeyboard=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletcharCode:t->int=fun_->0letctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletkey:t->string=fun_->""letkeyCode:t->int=fun_->0letlocale:t->string=fun_->""letlocation:t->int=fun_->0letmetaKey:t->bool=fun_->falseletrepeat:t->bool=fun_->falseletshiftKey:t->bool=fun_->falseletwhich:t->int=fun_->0endmoduleFocus=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letrelatedTarget:t-><..>Js.toption=fun_->NoneendmoduleForm=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleMouse=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletbutton:t->int=fun_->0letbuttons:t->int=fun_->0letclientX:t->int=fun_->0letclientY:t->int=fun_->0letctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletmetaKey:t->bool=fun_->falseletmovementX:t->int=fun_->0letmovementY:t->int=fun_->0letpageX:t->int=fun_->0letpageY:t->int=fun_->0letrelatedTarget:t-><..>Js.toption=fun_->NoneletscreenX:t->int=fun_->0letscreenY:t->int=fun_->0letshiftKey:t->bool=fun_->falseendmodulePointer=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdetail:t->int=fun_->0(* let view : t -> Dom.window = fun _ -> object end *)letscreenX:t->int=fun_->0letscreenY:t->int=fun_->0letclientX:t->int=fun_->0letclientY:t->int=fun_->0letpageX:t->int=fun_->0letpageY:t->int=fun_->0letmovementX:t->int=fun_->0letmovementY:t->int=fun_->0letctrlKey:t->bool=fun_->falseletshiftKey:t->bool=fun_->falseletaltKey:t->bool=fun_->falseletmetaKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletbutton:t->int=fun_->0letbuttons:t->int=fun_->0letrelatedTarget:t-><..>Js.toption=fun_->None(* let pointerId : t -> Dom.eventPointerId *)letwidth:t->float=fun_->0.letheight:t->float=fun_->0.letpressure:t->float=fun_->0.lettangentialPressure:t->float=fun_->0.lettiltX:t->int=fun_->0lettiltY:t->int=fun_->0lettwist:t->int=fun_->0letpointerType:t->string=fun_->""letisPrimary:t->bool=fun_->falseendmoduleSelection=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleTouch=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletchangedTouches:t-><..>Js.t=fun_->objectendletctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletmetaKey:t->bool=fun_->falseletshiftKey:t->bool=fun_->falselettargetTouches:t-><..>Js.t=fun_->objectendlettouches:t-><..>Js.t=fun_->objectendendmoduleUI=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdetail:t->int=fun_->0(* let view : t -> Dom.window *)endmoduleWheel=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letdeltaMode:t->int=fun_->0letdeltaX:t->float=fun_->0.letdeltaY:t->float=fun_->0.letdeltaZ:t->float=fun_->0.endmoduleMedia=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleImage=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)endmoduleAnimation=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letanimationName:t->string=fun_->""letpseudoElement:t->string=fun_->""letelapsedTime:t->float=fun_->0.endmoduleTransition=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letpropertyName:t->string=fun_->""letpseudoElement:t->string=fun_->""letelapsedTime:t->float=fun_->0.endmoduleDrag=structtypetagtypet=tagsyntheticincludeMakeEventWithType(structtypenonrect=t[@@nonrec]end)letaltKey:t->bool=fun_->falseletbutton:t->int=fun_->0letbuttons:t->int=fun_->0letclientX:t->int=fun_->0letclientY:t->int=fun_->0letctrlKey:t->bool=fun_->falseletgetModifierState:t->string->bool=fun__->falseletmetaKey:t->bool=fun_->falseletmovementX:t->int=fun_->0letmovementY:t->int=fun_->0letpageX:t->int=fun_->0letpageY:t->int=fun_->0letrelatedTarget:t-><..>Js.toption=fun_->NoneletscreenX:t->int=fun_->0letscreenY:t->int=fun_->0letshiftKey:t->bool=fun_->falseletdataTransfer:t-><..>Js.toption=fun_->NoneendendmoduleJSX=structtypeevent=|Dragof(Event.Drag.t->unit)|Mouseof(Event.Mouse.t->unit)|Selectionof(Event.Selection.t->unit)|Touchof(Event.Touch.t->unit)|UIof(Event.UI.t->unit)|Wheelof(Event.Wheel.t->unit)|Clipboardof(Event.Clipboard.t->unit)|Compositionof(Event.Composition.t->unit)|Transitionof(Event.Transition.t->unit)|Animationof(Event.Animation.t->unit)|Pointerof(Event.Pointer.t->unit)|Keyboardof(Event.Keyboard.t->unit)|Focusof(Event.Focus.t->unit)|Formof(Event.Form.t->unit)|Mediaof(Event.Media.t->unit)|Inlineofstringtypeprop=|Action:(string*string*_Runtime.server_function)->prop|Boolof(string*string*bool)|Stringof(string*string*string)|Styleof(string*string*string)list|DangerouslyInnerHtmlofstring|RefofRef.t|Eventofstring*eventletboolnamejsxNamevalue=Bool(name,jsxName,value)letstringnamejsxNamevalue=String(name,jsxName,value)letstylevalue=StylevalueletintnamejsxNamevalue=String(name,jsxName,Int.to_stringvalue)letfloatnamejsxNamevalue=String(name,jsxName,Float.to_stringvalue)letdangerouslyInnerHtmlvalue=DangerouslyInnerHtmlvalue#__htmlletrefvalue=Refvalueleteventkeyvalue=Event(key,value)moduleEvent=structletdragkeyvalue=eventkey(Dragvalue)letmousekeyvalue=eventkey(Mousevalue)letselectionkeyvalue=eventkey(Selectionvalue)lettouchkeyvalue=eventkey(Touchvalue)letuikeyvalue=eventkey(UIvalue)letwheelkeyvalue=eventkey(Wheelvalue)letclipboardkeyvalue=eventkey(Clipboardvalue)letcompositionkeyvalue=eventkey(Compositionvalue)lettransitionkeyvalue=eventkey(Transitionvalue)letanimationkeyvalue=eventkey(Animationvalue)letpointerkeyvalue=eventkey(Pointervalue)letkeyboardkeyvalue=eventkey(Keyboardvalue)letfocuskeyvalue=eventkey(Focusvalue)letformkeyvalue=eventkey(Formvalue)letmediakeyvalue=eventkey(Mediavalue)endendtypeerror={message:string;stack:Yojson.Basic.t;env:string;digest:string}moduleModel=structtype'elementt=|Function:'server_functionRuntime.server_function->'elementt|List:'elementtlist->'elementt|Assoc:(string*'elementt)list->'elementt|Json:Yojson.Basic.t->'elementt|Error:error->'elementt|Element:'element->'elementt|Promise:'aJs.Promise.t*('a->Yojson.Basic.t)->'elementtendtypeelement=|Lower_case_elementoflower_case_element|Upper_case_componentofstring*(unit->element)|Async_componentofstring*(unit->elementLwt.t)|Client_componentof{props:client_props;client:element;import_module:string;import_name:string}|Listofelementlist|Arrayofelementarray|Textofstring|DangerouslyInnerHtmlofstring|Fragmentofelement|Empty|Providerofelement|Consumerofelement|Suspenseof{key:stringoption;children:element;fallback:element}andlower_case_element={key:stringoption;tag:string;attributes:JSX.proplist;children:elementlist}andclient_props=(string*elementModel.t)listandmodel_value=elementModel.texceptionInvalid_childrenofstringletcompare_attribute(left:JSX.prop)(right:JSX.prop)=match(left,right)with|Bool(left_key,_,_),Bool(right_key,_,_)|String(left_key,_,_),String(right_key,_,_)->String.compareleft_keyright_key|Styleleft_styles,Styleright_styles->List.compare(fun(left_property,_,left_value)(right_property,_,right_value)->Int.compare(String.compareleft_propertyright_property)(String.compareleft_valueright_value))left_stylesright_styles|_->0letclone_attributeacc(attr:JSX.prop)(new_attr:JSX.prop)=match(attr,new_attr)with|Bool(left,_,_),Bool(right,_,_)whenleft==right->new_attr::acc|String(left,_,_),String(right,_,_)whenleft==right->new_attr::acc|_->new_attr::accmoduleStringMap=Map.Make(String)letattributes_to_mapattributes=List.fold_left(funacc(attr:JSX.prop)->matchattrwith|(Bool(key,_,_)|String(key,_,_))asprop->acc|>StringMap.addkeyprop(* The following constructors shoudn't be part of the StringMap *)|DangerouslyInnerHtml_->acc|Ref_->acc|Event_->acc|Action_->acc|Style_->acc)StringMap.emptyattributesletclone_attributesattributesnew_attributes=letattribute_map=attributes_to_mapattributesinletnew_attribute_map=attributes_to_mapnew_attributesinStringMap.merge(fun_keyattrnew_attr->match(attr,new_attr)with|Someattr,Somenew_attr->Some(clone_attribute[]attrnew_attr)|Someattr,None->Some[attr]|None,Somenew_attr->Some[new_attr]|None,None->None)attribute_mapnew_attribute_map|>StringMap.bindings|>List.map(fun(_,attrs)->attrs)|>List.flatten|>List.rev|>List.sortcompare_attributeletcreate_element_with_key?keytagattributeschildren=matchHtml.is_self_closing_tagtagwith|truewhenList.lengthchildren>0->raise(Invalid_children(Printf.sprintf{|"%s" is a self-closing tag and must not have "children".\n|}tag))|truewhenList.exists(functionJSX.DangerouslyInnerHtml_->true|_->false)attributes->raise(Invalid_children(Printf.sprintf{|"%s" is a self-closing tag and must not have "dangerouslySetInnerHTML".\n|}tag))|true->Lower_case_element{key;tag;attributes;children=[]}|false->Lower_case_element{key;tag;attributes;children}letcreateElement=create_element_with_key?key:NoneletcreateElementWithKey=create_element_with_key(* `cloneElement` overrides childrens and props on lower case components, It raises Invalid_argument for the rest.
React.js can clone uppercase components, since it stores their props on each element's object but since we just store the fn and don't have the props, we can't clone them).
TODO: Check original implementation for exact error message/exception type *)letcloneElementelementnew_attributes=matchelementwith|Lower_case_element{key;tag;attributes;children}->Lower_case_element{key;tag;attributes=clone_attributesattributesnew_attributes;children}|Upper_case_component_->raise(Invalid_argument"In server-reason-react, a component can't be cloned")|DangerouslyInnerHtml_->raise(Invalid_argument"can't clone innerHtml")|Fragment_->raise(Invalid_argument"can't clone a fragment")|Text_->raise(Invalid_argument"can't clone a text element")|Empty->raise(Invalid_argument"can't clone a null element")|List_->raise(Invalid_argument"can't clone a list element")|Array_->raise(Invalid_argument"can't clone an array element")|Provider_->raise(Invalid_argument"can't clone a Provider")|Consumer_->raise(Invalid_argument"can't clone a Consumer")|Async_component_->raise(Invalid_argument"can't clone an async component")|Suspense_->raise(Invalid_argument"can't clone a Supsense component")|Client_component_->raise(Invalid_argument"can't clone a Client component")moduleFragment=structletmake~children?key:_()=Fragmentchildrenendletfragmentchildren=Fragment.make~children?key:None()(* ReasonReact APIs *)letstringtxt=Texttxtletnull=Emptyletinti=Text(string_of_inti)(* FIXME: float_of_string might be different from the browser *)letfloatf=Text(string_of_floatf)letarrayarr=Arrayarrletlistl=Listltype'aprovider=value:'a->children:element->unit->elementmoduleContext=structtype'at={current_value:'aref;provider:'aprovider;consumer:children:element->element}letproviderctx=ctx.providerendletcreateContext(initial_value:'a):'aContext.t=letref_value={current=initial_value}inletprovider~value~children()=ref_value.current<-value;Providerchildreninletconsumer~children=Consumerchildrenin{current_value=ref_value;provider;consumer}moduleSuspense=structletor_react_null=functionNone->null|Somex->xletmake?key?fallback?children()=Suspense{key;fallback=or_react_nullfallback;children=or_react_nullchildren}end(* let memo f : 'props * 'props -> bool = f
let memoCustomCompareProps f _compare : 'props * 'props -> bool = f *)letuseContext(context:'aContext.t)=context.current_value.currentletuseState(make_initial_value:unit->'state)=letinitial_value:'state=make_initial_value()inletsetState(fn:'state->'state)=let_=fninitial_valuein()in(initial_value,setState)type('input,'output)callback='input->'outputletuseSyncExternalStore~subscribe:_~getSnapshot=getSnapshot()letuseSyncExternalStoreWithServer~subscribe:_~getSnapshot:_~getServerSnapshot=getServerSnapshot()letinternal_id=ref0letuseId()=internal_id:=!internal_id+1;Int.to_string!internal_idletuseMemofn=fn()letuseMemo0fn=fn()letuseMemo1fn_=fn()letuseMemo2fn_=fn()letuseMemo3fn_=fn()letuseMemo4fn_=fn()letuseMemo5fn_=fn()letuseMemo6fn_=fn()letuseCallbackfn=fnletuseCallback0fn=fnletuseCallback1fn_=fnletuseCallback2fn_=fnletuseCallback3fn_=fnletuseCallback4fn_=fnletuseCallback5fn_=fnletuseCallback6fn_=fnletuseReducer_s=(s,fun_->())letuseReducerWithMapState_smapper=(mappers,fun_->())letuseEffect_=()letuseEffect0_=()letuseEffect1__=()letuseEffect2__=()letuseEffect3__=()letuseEffect4__=()letuseEffect5__=()letuseEffect6__=()letuseLayoutEffect0_=()letuseLayoutEffect1__=()letuseLayoutEffect2__=()letuseLayoutEffect3__=()letuseLayoutEffect4__=()letuseLayoutEffect5__=()letuseLayoutEffect6__=()moduleChildren=structletmapelementfn=matchelementwith|Listchildren->List.mapfnchildren|>list|Arraychildren->Array.mapfnchildren|>array|_->fnelementletmapWithIndexelementfn=matchelementwith|Listchildren->List.mapi(funindexelement->fnelementindex)children|>list|Arraychildren->Array.mapi(funindexelement->fnelementindex)children|>array|_->fnelement0letforEachelementfn=matchelementwith|Listchildren->List.iterfnchildren|Arraychildren->Array.iterfnchildren|_->let_=fnelementin()letforEachWithIndexelementfn=matchelementwith|Listchildren->List.iteri(funindexelement->fnelementindex)children|Arraychildren->Array.iteri(funindexelement->fnelementindex)children|_->let_=fnelement0in()letcountelement=matchelementwith|Listchildren->List.lengthchildren|Arraychildren->Array.lengthchildren|Empty->0|_->1letonlyelement=matchelementwith|List(child::_)->child|List[]->raise(Invalid_argument"Expected at least one child")|Arraychildren->ifArray.lengthchildren>=1thenArray.getchildren0elseraise(Invalid_argument"Expected at least one child")|_->element(* TODO: silly way to convert children to array, but isn't necessary in most cases *)lettoArrayelement=[|element|]endletsetDisplayName__=()letuseTransition()=(false,fun(_cb:unit->unit)->())letuseDebugValue:'value->?format:('value->string)->unit=fun[@warning"-16"]_?format:_->()letuseDeferredValuevalue=value(* `exception Suspend of 'a Lwt`
exceptions can't have type params, this is called existential wrapper *)typeany_promise=Any_promise:'aLwt.t->any_promiseexceptionSuspendofany_promiseletsuspendpromise=raise(Suspend(Any_promisepromise))moduleExperimental=structletusePromisepromise=matchLwt.statepromisewith|Sleep->suspendpromise(* TODO: Fail should raise a FailedSupense and catch at renderTo*? *)|Faile->raisee|Returnv->vend