import{__rest as e,__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import r from"../../../node_modules/lodash/debounce.js";import l,{useMemo as o,useState as n,useCallback as a}from"react";import{createEditor as i,Range as d,Editor as c,Element as m,Point as s}from"../../../node_modules/slate/dist/index.es.js";import{withHistory as u}from"../../../node_modules/slate-history/dist/index.es.js";import{withReact as p,Slate as b,Editable as f}from"../../../node_modules/slate-react/dist/index.es.js";import h from"./TableCommands/useTableActions.js";import w,{Leaf as y}from"./TableElementsRenderer.js";import{TableElementTypes as T}from"./TableTypes.js";var C=function(e){var t=e.deleteBackward,r=e.deleteForward,l=e.insertBreak;return e.deleteBackward=function(r){var l=e.selection;if(l&&d.isCollapsed(l)){var o=c.nodes(e,{match:function(e){return!c.isEditor(e)&&m.isElement(e)&&"table-cell"===e.type}})[0];if(o){var n=o[1],a=c.start(e,n);if(s.equals(l.anchor,a))return}}t(r)},e.deleteForward=function(t){var l=e.selection;if(l&&d.isCollapsed(l)){var o=c.nodes(e,{match:function(e){return!c.isEditor(e)&&m.isElement(e)&&"table-cell"===e.type}})[0];if(o){var n=o[1],a=c.end(e,n);if(s.equals(l.anchor,a))return}}r(t)},e.insertBreak=function(){if(e.selection&&c.nodes(e,{match:function(e){return!c.isEditor(e)&&m.isElement(e)&&"table"===e.type}})[0])return;l()},e},x=[{children:[{text:"Header:"}]},{type:T.Table,children:[{type:T.TableHead,children:[{type:T.TableRow,row:-1,children:[{type:T.TableCell,row:-1,column:0,children:[{text:"Header 1"}]},{type:T.TableCell,row:-1,column:1,children:[{text:"Header 2"}]},{type:T.TableCell,row:-1,column:2,children:[{text:"Header 3"}]},{type:T.TableCell,row:-1,column:3,children:[{text:"Header 4"}]}]}]},{type:T.TableBody,children:[{type:T.TableRow,row:0,children:[{type:T.TableCell,row:0,column:0,children:[{text:""}]},{row:0,column:1,type:T.TableCell,children:[{text:"Human",bold:!0}]},{row:0,column:2,type:T.TableCell,children:[{text:"Dog",bold:!0}]},{row:0,column:3,type:T.TableCell,children:[{text:"Cat",bold:!0}]}]},{type:T.TableRow,row:1,children:[{row:1,column:0,type:T.TableCell,children:[{text:"# of Feet",bold:!0}]},{row:1,column:1,type:T.TableCell,children:[{text:"2"}]},{row:1,column:2,type:T.TableCell,children:[{text:"4"}]},{row:1,column:3,type:T.TableCell,children:[{text:"4"}]}]}]}]},{children:[{text:"Footer"}]}];export default function(d){var c=d.onBlocChange,m=d.bloc;e(d,["onBlocChange","bloc"]);var s=o((function(){return C(u(p(i())))}),[]),T=m.properties.tableData,v=n(void 0===T?x:T),E=v[0],j=v[1],R=a((function(e){return c({properties:t(t({},m.properties),{tableData:e})})}),[c]),B=a(r(R,1e3),[R]),H=a((function(e){j(e),R(e)}),[j,R]),A=h({updateTableData:H,tableData:E,editor:s}),D=A.addRowAfter,_=A.removeRow,g=A.addColumnAfter,k=A.removeColumn,F=a((function(e){return l.createElement(w,t({},e,{properties:m.properties,addRowAfter:D,removeRow:_,addColumnAfter:g,removeColumn:k}))}),[D]),q=a((function(e){return l.createElement(y,t({},e))}),[]);return l.createElement(b,{editor:s,value:E,onChange:function(e){j(e),B(e)}},l.createElement(f,{renderElement:F,renderLeaf:q}))}
//# sourceMappingURL=TableEditMode.js.map
