UNPKG

6.83 kBSource Map (JSON)View Raw
1{"version":3,"sources":["@wordpress/block-library/src/table/state.js"],"names":["createTable","rowCount","columnCount","body","cells","content","tag","updateCellContent","state","section","rowIndex","columnIndex","map","row","currentRowIndex","cell","currentColumnIndex","insertRow","cellCount","length","slice","deleteRow","filter","index","insertColumn","deleteColumn"],"mappings":";;;;;;;;;;;;;;;;;;;;AAGA;;AAHA;;;;AAKA;;;;;;;;AAQO,SAASA,WAAT,OAGH;AAAA,MAFHC,QAEG,QAFHA,QAEG;AAAA,MADHC,WACG,QADHA,WACG;AACH,SAAO;AACNC,IAAAA,IAAI,EAAE,mBAAOF,QAAP,EAAiB;AAAA,aAAQ;AAC9BG,QAAAA,KAAK,EAAE,mBAAOF,WAAP,EAAoB;AAAA,iBAAQ;AAClCG,YAAAA,OAAO,EAAE,EADyB;AAElCC,YAAAA,GAAG,EAAE;AAF6B,WAAR;AAAA,SAApB;AADuB,OAAR;AAAA,KAAjB;AADA,GAAP;AAQA;AAED;;;;;;;;;;;;;AAWO,SAASC,iBAAT,CAA4BC,KAA5B,SAKH;AAAA,MAJHC,OAIG,SAJHA,OAIG;AAAA,MAHHC,QAGG,SAHHA,QAGG;AAAA,MAFHC,WAEG,SAFHA,WAEG;AAAA,MADHN,OACG,SADHA,OACG;AACH,2CACGI,OADH,EACcD,KAAK,CAAEC,OAAF,CAAL,CAAiBG,GAAjB,CAAsB,UAAEC,GAAF,EAAOC,eAAP,EAA4B;AAC9D,QAAKA,eAAe,KAAKJ,QAAzB,EAAoC;AACnC,aAAOG,GAAP;AACA;;AAED,WAAO;AACNT,MAAAA,KAAK,EAAES,GAAG,CAACT,KAAJ,CAAUQ,GAAV,CAAe,UAAEG,IAAF,EAAQC,kBAAR,EAAgC;AACrD,YAAKA,kBAAkB,KAAKL,WAA5B,EAA0C;AACzC,iBAAOI,IAAP;AACA;;AAED,+CACIA,IADJ;AAECV,UAAAA,OAAO,EAAPA;AAFD;AAIA,OATM;AADD,KAAP;AAYA,G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,GAAG,CAACT,KAAJ,CAAUgB,KAAV,CAAiBT,WAAjB,CANC;AAD0C,KAAb;AAAA,GAAtB,CADd;AAYA;AAED;;;;;;;;;;;AASO,SAASc,YAAT,CAAuBjB,KAAvB,UAGH;AAAA,MAFHC,OAEG,UAFHA,OAEG;AAAA,MADHE,WACG,UADHA,WACG;AACH,2CACGF,OADH,EACcD,KAAK,CAAEC,OAAF,CAAL,CAAiBG,GAAjB,CAAsB,UAAEC,GAAF;AAAA,WAAa;AAC/CT,MAAAA,KAAK,EAAES,GAAG,CAACT,KAAJ,CAAUkB,MAAV,CAAkB,UAAEP,IAAF,EAAQQ,KAAR;AAAA,eAAmBA,KAAK,KAAKZ,WAA7B;AAAA,OAAlB;AADwC,KAAb;AAAA,GAAtB,EAEPW,MAFO,CAEC,UAAET,GAAF;AAAA,WAAWA,GAAG,CAACT,KAAJ,CAAUe,MAArB;AAAA,GAFD,CADd;AAKA","sourcesContent":["/**\n * External dependencies\n */\nimport { times } from 'lodash';\n\n/**\n * Creates a table state.\n *\n * @param {number} options.rowCount Row count for the table to create.\n * @param {number} options.columnCount Column count for the table to create.\n *\n * @return {Object} New table state.\n */\nexport function createTable( {\n\trowCount,\n\tcolumnCount,\n} ) {\n\treturn {\n\t\tbody: times( rowCount, () => ( {\n\t\t\tcells: times( columnCount, () => ( {\n\t\t\t\tcontent: '',\n\t\t\t\ttag: 'td',\n\t\t\t} ) ),\n\t\t} ) ),\n\t};\n}\n\n/**\n * Updates cell content in the table state.\n *\n * @param {Object} state Current table state.\n * @param {string} options.section Section of the cell to update.\n * @param {number} options.rowIndex Row index of the cell to update.\n * @param {number} options.columnIndex Column index of the cell to update.\n * @param {Array} options.content Content to set for the cell.\n *\n * @return {Object} New table state.\n */\nexport function updateCellContent( state, {\n\tsection,\n\trowIndex,\n\tcolumnIndex,\n\tcontent,\n} ) {\n\treturn {\n\t\t[ section ]: state[ section ].map( ( row, currentRowIndex ) => {\n\t\t\tif ( currentRowIndex !== rowIndex ) {\n\t\t\t\treturn row;\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tcells: row.cells.map( ( cell, currentColumnIndex ) => {\n\t\t\t\t\tif ( currentColumnIndex !== columnIndex ) {\n\t\t\t\t\t\treturn cell;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...cell,\n\t\t\t\t\t\tcontent,\n\t\t\t\t\t};\n\t\t\t\t} ),\n\t\t\t};\n\t\t} ),\n\t};\n}\n\n/**\n * Inserts a row in the table state.\n *\n * @param {Object} state Current table state.\n * @param {string} options.section Section in which to insert the row.\n * @param {number} options.rowIndex Row index at which to insert the row.\n *\n * @return {Object} New table state.\n */\nexport function insertRow( state, {\n\tsection,\n\trowIndex,\n} ) {\n\tconst cellCount = state[ section ][ 0 ].cells.length;\n\n\treturn {\n\t\t[ section ]: [\n\t\t\t...state[ section ].slice( 0, rowIndex ),\n\t\t\t{\n\t\t\t\tcells: times( cellCount, () => ( {\n\t\t\t\t\tcontent: '',\n\t\t\t\t\ttag: 'td',\n\t\t\t\t} ) ),\n\t\t\t},\n\t\t\t...state[ section ].slice( rowIndex ),\n\t\t],\n\t};\n}\n\n/**\n * Deletes a row from the table state.\n *\n * @param {Object} state Current table state.\n * @param {string} options.section Section in which to delete the row.\n * @param {number} options.rowIndex Row index to delete.\n *\n * @return {Object} New table state.\n */\nexport function deleteRow( state, {\n\tsection,\n\trowIndex,\n} ) {\n\treturn {\n\t\t[ section ]: state[ section ].filter( ( row, index ) => index !== rowIndex ),\n\t};\n}\n\n/**\n * Inserts a column in the table state.\n *\n * @param {Object} state Current table state.\n * @param {string} options.section Section in which to insert the column.\n * @param {number} options.columnIndex Column index at which to insert the column.\n *\n * @return {Object} New table state.\n */\nexport function insertColumn( state, {\n\tsection,\n\tcolumnIndex,\n} ) {\n\treturn {\n\t\t[ section ]: state[ section ].map( ( row ) => ( {\n\t\t\tcells: [\n\t\t\t\t...row.cells.slice( 0, columnIndex ),\n\t\t\t\t{\n\t\t\t\t\tcontent: '',\n\t\t\t\t\ttag: 'td',\n\t\t\t\t},\n\t\t\t\t...row.cells.slice( columnIndex ),\n\t\t\t],\n\t\t} ) ),\n\t};\n}\n\n/**\n * Deletes a column from the table state.\n *\n * @param {Object} state Current table state.\n * @param {string} options.section Section in which to delete the column.\n * @param {number} options.columnIndex Column index to delete.\n *\n * @return {Object} New table state.\n */\nexport function deleteColumn( state, {\n\tsection,\n\tcolumnIndex,\n} ) {\n\treturn {\n\t\t[ section ]: state[ section ].map( ( row ) => ( {\n\t\t\tcells: row.cells.filter( ( cell, index ) => index !== columnIndex ),\n\t\t} ) ).filter( ( row ) => row.cells.length ),\n\t};\n}\n"]}
\No newline at end of file