@univerjs/sheets-sort 0.20.0 → 0.20.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/index.js CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets`),n=require(`@univerjs/engine-formula`),r=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),i=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const a=e=>e.replace(/-/gi,``).replace(/'/gi,``),o=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?i.ZERO:n?i.POSITIVE:r?i.NEGATIVE:null},s=(e,t,n)=>{let a=typeof e==`number`,o=typeof t==`number`;return a&&o?e<t?n===r.ASC?i.NEGATIVE:i.POSITIVE:e>t?n===r.ASC?i.POSITIVE:i.NEGATIVE:i.ZERO:a?n===r.ASC?i.POSITIVE:i.NEGATIVE:o?n===r.ASC?i.NEGATIVE:i.POSITIVE:null},c=(e,t,n)=>{let o=typeof e==`string`,s=typeof t==`string`;if(o&&(e=a(e.toLocaleLowerCase())),s&&(t=a(t.toLocaleLowerCase())),!o&&!s)return null;if(o&&s){let a=e,o=t;return a<o?n===r.ASC?i.NEGATIVE:i.POSITIVE:a>o?n===r.ASC?i.POSITIVE:i.NEGATIVE:i.ZERO}return o?n===r.ASC?i.POSITIVE:i.NEGATIVE:s?n===r.ASC?i.NEGATIVE:i.POSITIVE:null},l=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e,t){return function(n,r){t(n,r,e)}}function h(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let g=class extends e.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,p(this,`_compareFns`,[])}mergeCheck(t){var n;let{unitId:r,subUnitId:i,range:a}=t,o=(n=this._univerInstanceService.getUnit(r))==null?void 0:n.getSheetBySheetId(i);if(!o)return!1;let s=o.getMergeData().filter(t=>e.Rectangle.contains(a,t));return s.length===0?!0:_(a,s)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!l(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(t){var n;let{unitId:r,subUnitId:i,range:a}=t,o=(n=this._formulaDataModel.getArrayFormulaRange())==null||(n=n[r])==null?void 0:n[i];for(let t in o){let n=o[Number(t)];for(let t in n){let r=n[Number(t)];if(r&&e.Rectangle.intersects(a,r))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,n,r){var i;let{unitId:a,subUnitId:o}=(0,t.getSheetCommandTarget)(this._univerInstanceService)||{};this._commandService.executeCommand(v.id,{orderRules:e.orderRules,range:e.range,hasTitle:(i=e.hasTitle)==null?!1:i,unitId:n||a,subUnitId:r||o})}};g=h([m(0,e.IUniverInstanceService),m(1,e.ICommandService),m(2,(0,e.Inject)(n.FormulaDataModel))],g);function _(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}const v={id:`sheet.command.sort-range`,type:e.CommandType.COMMAND,handler:(n,r)=>{let{range:i,orderRules:a,hasTitle:o,unitId:s,subUnitId:c}=r,l=n.get(g),{worksheet:u}=(0,t.getSheetCommandTarget)(n.get(e.IUniverInstanceService),r)||{};if(!u)return!1;let d=u.getMergeData().filter(t=>e.Rectangle.contains(i,t)),f=d.map(e=>e.startRow),{startRow:p,endRow:m}=i,h=o?p+1:p,_=[],v=[];for(let e=h;e<=m;e++)u.getRowFiltered(e)||u.getRowRawVisible(e)!==!1&&(d.length&&!f.includes(e)||(_.push({index:e,value:y(u,e,a)}),v.push(e)));let S=l.getAllCompareFns();_.sort(x(a,b(S)));let C={};_.forEach(({index:e,value:t},n)=>{C[v[n]]=e});let w={id:t.ReorderRangeCommand.id,params:{unitId:s,subUnitId:c,range:i,order:C}},T=n.get(e.ICommandService);return(0,e.sequenceExecute)([w],T).result}};function y(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function b(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function x(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var S=`@univerjs/sheets-sort`,C=`0.20.0`;const w=`sheets-sort.config`;Symbol(w);const T={};let E=class extends e.Disposable{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[v].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[o,c,s];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return l(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.CellValueType.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.CellValueType.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.CellValueType.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.CellValueType.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};E=h([m(0,e.ICommandService),m(1,(0,e.Inject)(g))],E);let D=class extends e.Plugin{constructor(t=T,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},T,this._config);this._configService.setConfig(w,i)}onStarting(){[[E],[g]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(E)}};p(D,`type`,e.UniverInstanceType.UNIVER_SHEET),p(D,`pluginName`,`SHEET_SORT_PLUGIN`),p(D,`packageName`,S),p(D,`version`,C),D=h([(0,e.DependentOn)(t.UniverSheetsPlugin,n.UniverFormulaEnginePlugin),m(1,(0,e.Inject)(e.Injector)),m(2,e.IConfigService)],D),Object.defineProperty(exports,`SheetsSortService`,{enumerable:!0,get:function(){return g}}),exports.SortRangeCommand=v,exports.SortType=r,Object.defineProperty(exports,`UniverSheetsSortPlugin`,{enumerable:!0,get:function(){return D}});
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets`),n=require(`@univerjs/engine-formula`),r=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),i=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const a=e=>e.replace(/-/gi,``).replace(/'/gi,``),o=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?i.ZERO:n?i.POSITIVE:r?i.NEGATIVE:null},s=(e,t,n)=>{let a=typeof e==`number`,o=typeof t==`number`;return a&&o?e<t?n===r.ASC?i.NEGATIVE:i.POSITIVE:e>t?n===r.ASC?i.POSITIVE:i.NEGATIVE:i.ZERO:a?n===r.ASC?i.POSITIVE:i.NEGATIVE:o?n===r.ASC?i.NEGATIVE:i.POSITIVE:null},c=(e,t,n)=>{let o=typeof e==`string`,s=typeof t==`string`;if(o&&(e=a(e.toLocaleLowerCase())),s&&(t=a(t.toLocaleLowerCase())),!o&&!s)return null;if(o&&s){let a=e,o=t;return a<o?n===r.ASC?i.NEGATIVE:i.POSITIVE:a>o?n===r.ASC?i.POSITIVE:i.NEGATIVE:i.ZERO}return o?n===r.ASC?i.POSITIVE:i.NEGATIVE:s?n===r.ASC?i.NEGATIVE:i.POSITIVE:null},l=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function u(e){"@babel/helpers - typeof";return u=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},u(e)}function d(e,t){if(u(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(u(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function f(e){var t=d(e,`string`);return u(t)==`symbol`?t:t+``}function p(e,t,n){return(t=f(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function m(e,t){return function(n,r){t(n,r,e)}}function h(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let g=class extends e.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,p(this,`_compareFns`,[])}mergeCheck(t){var n;let{unitId:r,subUnitId:i,range:a}=t,o=(n=this._univerInstanceService.getUnit(r))==null?void 0:n.getSheetBySheetId(i);if(!o)return!1;let s=o.getMergeData().filter(t=>e.Rectangle.contains(a,t));return s.length===0?!0:_(a,s)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!l(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(t){var n;let{unitId:r,subUnitId:i,range:a}=t,o=(n=this._formulaDataModel.getArrayFormulaRange())==null||(n=n[r])==null?void 0:n[i];for(let t in o){let n=o[Number(t)];for(let t in n){let r=n[Number(t)];if(r&&e.Rectangle.intersects(a,r))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,n,r){var i;let{unitId:a,subUnitId:o}=(0,t.getSheetCommandTarget)(this._univerInstanceService)||{};this._commandService.executeCommand(v.id,{orderRules:e.orderRules,range:e.range,hasTitle:(i=e.hasTitle)==null?!1:i,unitId:n||a,subUnitId:r||o})}};g=h([m(0,e.IUniverInstanceService),m(1,e.ICommandService),m(2,(0,e.Inject)(n.FormulaDataModel))],g);function _(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}const v={id:`sheet.command.sort-range`,type:e.CommandType.COMMAND,handler:(n,r)=>{let{range:i,orderRules:a,hasTitle:o,unitId:s,subUnitId:c}=r,l=n.get(g),{worksheet:u}=(0,t.getSheetCommandTarget)(n.get(e.IUniverInstanceService),r)||{};if(!u)return!1;let d=u.getMergeData().filter(t=>e.Rectangle.contains(i,t)),f=d.map(e=>e.startRow),{startRow:p,endRow:m}=i,h=o?p+1:p,_=[],v=[];for(let e=h;e<=m;e++)u.getRowFiltered(e)||u.getRowRawVisible(e)!==!1&&(d.length&&!f.includes(e)||(_.push({index:e,value:y(u,e,a)}),v.push(e)));let S=l.getAllCompareFns();_.sort(x(a,b(S)));let C={};_.forEach(({index:e,value:t},n)=>{C[v[n]]=e});let w={id:t.ReorderRangeCommand.id,params:{unitId:s,subUnitId:c,range:i,order:C}},T=n.get(e.ICommandService);return(0,e.sequenceExecute)([w],T).result}};function y(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function b(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function x(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var S=`@univerjs/sheets-sort`,C=`0.20.1`;const w=`sheets-sort.config`;Symbol(w);const T={};let E=class extends e.Disposable{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[v].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[o,c,s];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return l(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.CellValueType.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.CellValueType.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.CellValueType.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.CellValueType.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};E=h([m(0,e.ICommandService),m(1,(0,e.Inject)(g))],E);let D=class extends e.Plugin{constructor(t=T,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{...i}=(0,e.merge)({},T,this._config);this._configService.setConfig(w,i)}onStarting(){[[E],[g]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(E)}};p(D,`type`,e.UniverInstanceType.UNIVER_SHEET),p(D,`pluginName`,`SHEET_SORT_PLUGIN`),p(D,`packageName`,S),p(D,`version`,C),D=h([(0,e.DependentOn)(t.UniverSheetsPlugin,n.UniverFormulaEnginePlugin),m(1,(0,e.Inject)(e.Injector)),m(2,e.IConfigService)],D),Object.defineProperty(exports,`SheetsSortService`,{enumerable:!0,get:function(){return g}}),exports.SortRangeCommand=v,exports.SortType=r,Object.defineProperty(exports,`UniverSheetsSortPlugin`,{enumerable:!0,get:function(){return D}});
package/lib/es/index.js CHANGED
@@ -1 +1 @@
1
- import{CellValueType as e,CommandType as t,DependentOn as n,Disposable as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,Plugin as l,Rectangle as u,UniverInstanceType as d,merge as f,sequenceExecute as p}from"@univerjs/core";import{ReorderRangeCommand as m,UniverSheetsPlugin as h,getSheetCommandTarget as g}from"@univerjs/sheets";import{FormulaDataModel as _,UniverFormulaEnginePlugin as v}from"@univerjs/engine-formula";let y=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),b=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const x=e=>e.replace(/-/gi,``).replace(/'/gi,``),S=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?b.ZERO:n?b.POSITIVE:r?b.NEGATIVE:null},C=(e,t,n)=>{let r=typeof e==`number`,i=typeof t==`number`;return r&&i?e<t?n===y.ASC?b.NEGATIVE:b.POSITIVE:e>t?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO:r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},w=(e,t,n)=>{let r=typeof e==`string`,i=typeof t==`string`;if(r&&(e=x(e.toLocaleLowerCase())),i&&(t=x(t.toLocaleLowerCase())),!r&&!i)return null;if(r&&i){let r=e,i=t;return r<i?n===y.ASC?b.NEGATIVE:b.POSITIVE:r>i?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO}return r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},T=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let M=class extends r{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,k(this,`_compareFns`,[])}mergeCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;let o=a.getMergeData().filter(e=>u.contains(i,e));return o.length===0?!0:N(i,o)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!T(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._formulaDataModel.getArrayFormulaRange())==null||(t=t[n])==null?void 0:t[r];for(let e in a){let t=a[Number(e)];for(let e in t){let n=t[Number(e)];if(n&&u.intersects(i,n))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,n){var r;let{unitId:i,subUnitId:a}=g(this._univerInstanceService)||{};this._commandService.executeCommand(P.id,{orderRules:e.orderRules,range:e.range,hasTitle:(r=e.hasTitle)==null?!1:r,unitId:t||i,subUnitId:n||a})}};M=j([A(0,o),A(1,i),A(2,s(_))],M);function N(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}const P={id:`sheet.command.sort-range`,type:t.COMMAND,handler:(e,t)=>{let{range:n,orderRules:r,hasTitle:a,unitId:s,subUnitId:c}=t,l=e.get(M),{worksheet:d}=g(e.get(o),t)||{};if(!d)return!1;let f=d.getMergeData().filter(e=>u.contains(n,e)),h=f.map(e=>e.startRow),{startRow:_,endRow:v}=n,y=a?_+1:_,b=[],x=[];for(let e=y;e<=v;e++)d.getRowFiltered(e)||d.getRowRawVisible(e)!==!1&&(f.length&&!h.includes(e)||(b.push({index:e,value:F(d,e,r)}),x.push(e)));let S=l.getAllCompareFns();b.sort(L(r,I(S)));let C={};b.forEach(({index:e,value:t},n)=>{C[x[n]]=e});let w={id:m.id,params:{unitId:s,subUnitId:c,range:n,order:C}},T=e.get(i);return p([w],T).result}};function F(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function I(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function L(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var R=`@univerjs/sheets-sort`,z=`0.20.0`;const B=`sheets-sort.config`;Symbol(B);const V={};let H=class extends r{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[S,w,C];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return T(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};H=j([A(0,i),A(1,s(M))],H);let U=class extends l{constructor(e=V,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=f({},V,this._config);this._configService.setConfig(B,r)}onStarting(){[[H],[M]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(H)}};k(U,`type`,d.UNIVER_SHEET),k(U,`pluginName`,`SHEET_SORT_PLUGIN`),k(U,`packageName`,R),k(U,`version`,z),U=j([n(h,v),A(1,s(c)),A(2,a)],U);export{M as SheetsSortService,P as SortRangeCommand,y as SortType,U as UniverSheetsSortPlugin};
1
+ import{CellValueType as e,CommandType as t,DependentOn as n,Disposable as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,Plugin as l,Rectangle as u,UniverInstanceType as d,merge as f,sequenceExecute as p}from"@univerjs/core";import{ReorderRangeCommand as m,UniverSheetsPlugin as h,getSheetCommandTarget as g}from"@univerjs/sheets";import{FormulaDataModel as _,UniverFormulaEnginePlugin as v}from"@univerjs/engine-formula";let y=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),b=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const x=e=>e.replace(/-/gi,``).replace(/'/gi,``),S=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?b.ZERO:n?b.POSITIVE:r?b.NEGATIVE:null},C=(e,t,n)=>{let r=typeof e==`number`,i=typeof t==`number`;return r&&i?e<t?n===y.ASC?b.NEGATIVE:b.POSITIVE:e>t?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO:r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},w=(e,t,n)=>{let r=typeof e==`string`,i=typeof t==`string`;if(r&&(e=x(e.toLocaleLowerCase())),i&&(t=x(t.toLocaleLowerCase())),!r&&!i)return null;if(r&&i){let r=e,i=t;return r<i?n===y.ASC?b.NEGATIVE:b.POSITIVE:r>i?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO}return r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},T=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let M=class extends r{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,k(this,`_compareFns`,[])}mergeCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;let o=a.getMergeData().filter(e=>u.contains(i,e));return o.length===0?!0:N(i,o)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!T(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._formulaDataModel.getArrayFormulaRange())==null||(t=t[n])==null?void 0:t[r];for(let e in a){let t=a[Number(e)];for(let e in t){let n=t[Number(e)];if(n&&u.intersects(i,n))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,n){var r;let{unitId:i,subUnitId:a}=g(this._univerInstanceService)||{};this._commandService.executeCommand(P.id,{orderRules:e.orderRules,range:e.range,hasTitle:(r=e.hasTitle)==null?!1:r,unitId:t||i,subUnitId:n||a})}};M=j([A(0,o),A(1,i),A(2,s(_))],M);function N(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}const P={id:`sheet.command.sort-range`,type:t.COMMAND,handler:(e,t)=>{let{range:n,orderRules:r,hasTitle:a,unitId:s,subUnitId:c}=t,l=e.get(M),{worksheet:d}=g(e.get(o),t)||{};if(!d)return!1;let f=d.getMergeData().filter(e=>u.contains(n,e)),h=f.map(e=>e.startRow),{startRow:_,endRow:v}=n,y=a?_+1:_,b=[],x=[];for(let e=y;e<=v;e++)d.getRowFiltered(e)||d.getRowRawVisible(e)!==!1&&(f.length&&!h.includes(e)||(b.push({index:e,value:F(d,e,r)}),x.push(e)));let S=l.getAllCompareFns();b.sort(L(r,I(S)));let C={};b.forEach(({index:e,value:t},n)=>{C[x[n]]=e});let w={id:m.id,params:{unitId:s,subUnitId:c,range:n,order:C}},T=e.get(i);return p([w],T).result}};function F(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function I(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function L(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var R=`@univerjs/sheets-sort`,z=`0.20.1`;const B=`sheets-sort.config`;Symbol(B);const V={};let H=class extends r{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[S,w,C];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return T(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};H=j([A(0,i),A(1,s(M))],H);let U=class extends l{constructor(e=V,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=f({},V,this._config);this._configService.setConfig(B,r)}onStarting(){[[H],[M]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(H)}};k(U,`type`,d.UNIVER_SHEET),k(U,`pluginName`,`SHEET_SORT_PLUGIN`),k(U,`packageName`,R),k(U,`version`,z),U=j([n(h,v),A(1,s(c)),A(2,a)],U);export{M as SheetsSortService,P as SortRangeCommand,y as SortType,U as UniverSheetsSortPlugin};
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- import{CellValueType as e,CommandType as t,DependentOn as n,Disposable as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,Plugin as l,Rectangle as u,UniverInstanceType as d,merge as f,sequenceExecute as p}from"@univerjs/core";import{ReorderRangeCommand as m,UniverSheetsPlugin as h,getSheetCommandTarget as g}from"@univerjs/sheets";import{FormulaDataModel as _,UniverFormulaEnginePlugin as v}from"@univerjs/engine-formula";let y=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),b=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const x=e=>e.replace(/-/gi,``).replace(/'/gi,``),S=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?b.ZERO:n?b.POSITIVE:r?b.NEGATIVE:null},C=(e,t,n)=>{let r=typeof e==`number`,i=typeof t==`number`;return r&&i?e<t?n===y.ASC?b.NEGATIVE:b.POSITIVE:e>t?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO:r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},w=(e,t,n)=>{let r=typeof e==`string`,i=typeof t==`string`;if(r&&(e=x(e.toLocaleLowerCase())),i&&(t=x(t.toLocaleLowerCase())),!r&&!i)return null;if(r&&i){let r=e,i=t;return r<i?n===y.ASC?b.NEGATIVE:b.POSITIVE:r>i?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO}return r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},T=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let M=class extends r{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,k(this,`_compareFns`,[])}mergeCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;let o=a.getMergeData().filter(e=>u.contains(i,e));return o.length===0?!0:N(i,o)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!T(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._formulaDataModel.getArrayFormulaRange())==null||(t=t[n])==null?void 0:t[r];for(let e in a){let t=a[Number(e)];for(let e in t){let n=t[Number(e)];if(n&&u.intersects(i,n))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,n){var r;let{unitId:i,subUnitId:a}=g(this._univerInstanceService)||{};this._commandService.executeCommand(P.id,{orderRules:e.orderRules,range:e.range,hasTitle:(r=e.hasTitle)==null?!1:r,unitId:t||i,subUnitId:n||a})}};M=j([A(0,o),A(1,i),A(2,s(_))],M);function N(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}const P={id:`sheet.command.sort-range`,type:t.COMMAND,handler:(e,t)=>{let{range:n,orderRules:r,hasTitle:a,unitId:s,subUnitId:c}=t,l=e.get(M),{worksheet:d}=g(e.get(o),t)||{};if(!d)return!1;let f=d.getMergeData().filter(e=>u.contains(n,e)),h=f.map(e=>e.startRow),{startRow:_,endRow:v}=n,y=a?_+1:_,b=[],x=[];for(let e=y;e<=v;e++)d.getRowFiltered(e)||d.getRowRawVisible(e)!==!1&&(f.length&&!h.includes(e)||(b.push({index:e,value:F(d,e,r)}),x.push(e)));let S=l.getAllCompareFns();b.sort(L(r,I(S)));let C={};b.forEach(({index:e,value:t},n)=>{C[x[n]]=e});let w={id:m.id,params:{unitId:s,subUnitId:c,range:n,order:C}},T=e.get(i);return p([w],T).result}};function F(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function I(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function L(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var R=`@univerjs/sheets-sort`,z=`0.20.0`;const B=`sheets-sort.config`;Symbol(B);const V={};let H=class extends r{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[S,w,C];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return T(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};H=j([A(0,i),A(1,s(M))],H);let U=class extends l{constructor(e=V,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=f({},V,this._config);this._configService.setConfig(B,r)}onStarting(){[[H],[M]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(H)}};k(U,`type`,d.UNIVER_SHEET),k(U,`pluginName`,`SHEET_SORT_PLUGIN`),k(U,`packageName`,R),k(U,`version`,z),U=j([n(h,v),A(1,s(c)),A(2,a)],U);export{M as SheetsSortService,P as SortRangeCommand,y as SortType,U as UniverSheetsSortPlugin};
1
+ import{CellValueType as e,CommandType as t,DependentOn as n,Disposable as r,ICommandService as i,IConfigService as a,IUniverInstanceService as o,Inject as s,Injector as c,Plugin as l,Rectangle as u,UniverInstanceType as d,merge as f,sequenceExecute as p}from"@univerjs/core";import{ReorderRangeCommand as m,UniverSheetsPlugin as h,getSheetCommandTarget as g}from"@univerjs/sheets";import{FormulaDataModel as _,UniverFormulaEnginePlugin as v}from"@univerjs/engine-formula";let y=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),b=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({});const x=e=>e.replace(/-/gi,``).replace(/'/gi,``),S=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?b.ZERO:n?b.POSITIVE:r?b.NEGATIVE:null},C=(e,t,n)=>{let r=typeof e==`number`,i=typeof t==`number`;return r&&i?e<t?n===y.ASC?b.NEGATIVE:b.POSITIVE:e>t?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO:r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},w=(e,t,n)=>{let r=typeof e==`string`,i=typeof t==`string`;if(r&&(e=x(e.toLocaleLowerCase())),i&&(t=x(t.toLocaleLowerCase())),!r&&!i)return null;if(r&&i){let r=e,i=t;return r<i?n===y.ASC?b.NEGATIVE:b.POSITIVE:r>i?n===y.ASC?b.POSITIVE:b.NEGATIVE:b.ZERO}return r?n===y.ASC?b.POSITIVE:b.NEGATIVE:i?n===y.ASC?b.NEGATIVE:b.POSITIVE:null},T=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function E(e){"@babel/helpers - typeof";return E=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},E(e)}function D(e,t){if(E(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(E(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function O(e){var t=D(e,`string`);return E(t)==`symbol`?t:t+``}function k(e,t,n){return(t=O(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function A(e,t){return function(n,r){t(n,r,e)}}function j(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let M=class extends r{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,k(this,`_compareFns`,[])}mergeCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;let o=a.getMergeData().filter(e=>u.contains(i,e));return o.length===0?!0:N(i,o)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!T(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._formulaDataModel.getArrayFormulaRange())==null||(t=t[n])==null?void 0:t[r];for(let e in a){let t=a[Number(e)];for(let e in t){let n=t[Number(e)];if(n&&u.intersects(i,n))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,n){var r;let{unitId:i,subUnitId:a}=g(this._univerInstanceService)||{};this._commandService.executeCommand(P.id,{orderRules:e.orderRules,range:e.range,hasTitle:(r=e.hasTitle)==null?!1:r,unitId:t||i,subUnitId:n||a})}};M=j([A(0,o),A(1,i),A(2,s(_))],M);function N(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}const P={id:`sheet.command.sort-range`,type:t.COMMAND,handler:(e,t)=>{let{range:n,orderRules:r,hasTitle:a,unitId:s,subUnitId:c}=t,l=e.get(M),{worksheet:d}=g(e.get(o),t)||{};if(!d)return!1;let f=d.getMergeData().filter(e=>u.contains(n,e)),h=f.map(e=>e.startRow),{startRow:_,endRow:v}=n,y=a?_+1:_,b=[],x=[];for(let e=y;e<=v;e++)d.getRowFiltered(e)||d.getRowRawVisible(e)!==!1&&(f.length&&!h.includes(e)||(b.push({index:e,value:F(d,e,r)}),x.push(e)));let S=l.getAllCompareFns();b.sort(L(r,I(S)));let C={};b.forEach(({index:e,value:t},n)=>{C[x[n]]=e});let w={id:m.id,params:{unitId:s,subUnitId:c,range:n,order:C}},T=e.get(i);return p([w],T).result}};function F(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function I(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function L(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var R=`@univerjs/sheets-sort`,z=`0.20.1`;const B=`sheets-sort.config`;Symbol(B);const V={};let H=class extends r{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[P].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[S,w,C];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(t){var n;return T(t)?null:(t==null||(n=t.p)==null||(n=n.body)==null?void 0:n.dataStream)||((t==null?void 0:t.t)===e.NUMBER?Number.parseFloat(`${t.v}`):(t==null?void 0:t.t)===e.STRING?typeof t.v==`number`?t.v:`${t.v}`:(t==null?void 0:t.t)===e.BOOLEAN?`${t.v}`:(t==null?void 0:t.t)===e.FORCE_STRING?Number.parseFloat(`${t.v}`):`${t==null?void 0:t.v}`)}};H=j([A(0,i),A(1,s(M))],H);let U=class extends l{constructor(e=V,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{...r}=f({},V,this._config);this._configService.setConfig(B,r)}onStarting(){[[H],[M]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(H)}};k(U,`type`,d.UNIVER_SHEET),k(U,`pluginName`,`SHEET_SORT_PLUGIN`),k(U,`packageName`,R),k(U,`version`,z),U=j([n(h,v),A(1,s(c)),A(2,a)],U);export{M as SheetsSortService,P as SortRangeCommand,y as SortType,U as UniverSheetsSortPlugin};
package/lib/umd/index.js CHANGED
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsSort={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),a=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({}),o=e=>e.replace(/-/gi,``).replace(/'/gi,``),s=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?a.ZERO:n?a.POSITIVE:r?a.NEGATIVE:null},c=(e,t,n)=>{let r=typeof e==`number`,o=typeof t==`number`;return r&&o?e<t?n===i.ASC?a.NEGATIVE:a.POSITIVE:e>t?n===i.ASC?a.POSITIVE:a.NEGATIVE:a.ZERO:r?n===i.ASC?a.POSITIVE:a.NEGATIVE:o?n===i.ASC?a.NEGATIVE:a.POSITIVE:null},l=(e,t,n)=>{let r=typeof e==`string`,s=typeof t==`string`;if(r&&(e=o(e.toLocaleLowerCase())),s&&(t=o(t.toLocaleLowerCase())),!r&&!s)return null;if(r&&s){let r=e,o=t;return r<o?n===i.ASC?a.NEGATIVE:a.POSITIVE:r>o?n===i.ASC?a.POSITIVE:a.NEGATIVE:a.ZERO}return r?n===i.ASC?a.POSITIVE:a.NEGATIVE:s?n===i.ASC?a.NEGATIVE:a.POSITIVE:null},u=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let _=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,m(this,`_compareFns`,[])}mergeCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._univerInstanceService.getUnit(r))==null?void 0:n.getSheetBySheetId(i);if(!o)return!1;let s=o.getMergeData().filter(e=>t.Rectangle.contains(a,e));return s.length===0?!0:v(a,s)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!u(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._formulaDataModel.getArrayFormulaRange())==null||(n=n[r])==null?void 0:n[i];for(let e in o){let n=o[Number(e)];for(let e in n){let r=n[Number(e)];if(r&&t.Rectangle.intersects(a,r))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,r){var i;let{unitId:a,subUnitId:o}=(0,n.getSheetCommandTarget)(this._univerInstanceService)||{};this._commandService.executeCommand(y.id,{orderRules:e.orderRules,range:e.range,hasTitle:(i=e.hasTitle)==null?!1:i,unitId:t||a,subUnitId:r||o})}};_=g([h(0,t.IUniverInstanceService),h(1,t.ICommandService),h(2,(0,t.Inject)(r.FormulaDataModel))],_);function v(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}let y={id:`sheet.command.sort-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let{range:i,orderRules:a,hasTitle:o,unitId:s,subUnitId:c}=r,l=e.get(_),{worksheet:u}=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r)||{};if(!u)return!1;let d=u.getMergeData().filter(e=>t.Rectangle.contains(i,e)),f=d.map(e=>e.startRow),{startRow:p,endRow:m}=i,h=o?p+1:p,g=[],v=[];for(let e=h;e<=m;e++)u.getRowFiltered(e)||u.getRowRawVisible(e)!==!1&&(d.length&&!f.includes(e)||(g.push({index:e,value:b(u,e,a)}),v.push(e)));let y=l.getAllCompareFns();g.sort(S(a,x(y)));let C={};g.forEach(({index:e,value:t},n)=>{C[v[n]]=e});let w={id:n.ReorderRangeCommand.id,params:{unitId:s,subUnitId:c,range:i,order:C}},T=e.get(t.ICommandService);return(0,t.sequenceExecute)([w],T).result}};function b(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function x(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function S(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var C=`@univerjs/sheets-sort`,w=`0.20.0`;let T=`sheets-sort.config`;Symbol(T);let E={},D=class extends t.Disposable{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[y].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[s,l,c];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(e){var n;return u(e)?null:(e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)||((e==null?void 0:e.t)===t.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===t.CellValueType.STRING?typeof e.v==`number`?e.v:`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};D=g([h(0,t.ICommandService),h(1,(0,t.Inject)(_))],D);let O=class extends t.Plugin{constructor(e=E,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},E,this._config);this._configService.setConfig(T,i)}onStarting(){[[D],[_]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(D)}};m(O,`type`,t.UniverInstanceType.UNIVER_SHEET),m(O,`pluginName`,`SHEET_SORT_PLUGIN`),m(O,`packageName`,C),m(O,`version`,w),O=g([(0,t.DependentOn)(n.UniverSheetsPlugin,r.UniverFormulaEnginePlugin),h(1,(0,t.Inject)(t.Injector)),h(2,t.IConfigService)],O),Object.defineProperty(e,`SheetsSortService`,{enumerable:!0,get:function(){return _}}),e.SortRangeCommand=y,e.SortType=i,Object.defineProperty(e,`UniverSheetsSortPlugin`,{enumerable:!0,get:function(){return O}})});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/sheets`),require(`@univerjs/engine-formula`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets`,`@univerjs/engine-formula`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsSort={},e.UniverCore,e.UniverSheets,e.UniverEngineFormula))})(this,function(e,t,n,r){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let i=function(e){return e.DESC=`desc`,e.ASC=`asc`,e}({}),a=function(e){return e[e.POSITIVE=1]=`POSITIVE`,e[e.NEGATIVE=-1]=`NEGATIVE`,e[e.ZERO=0]=`ZERO`,e}({}),o=e=>e.replace(/-/gi,``).replace(/'/gi,``),s=(e,t)=>{let n=e===null||e===``,r=t===null||t===``;return n&&r?a.ZERO:n?a.POSITIVE:r?a.NEGATIVE:null},c=(e,t,n)=>{let r=typeof e==`number`,o=typeof t==`number`;return r&&o?e<t?n===i.ASC?a.NEGATIVE:a.POSITIVE:e>t?n===i.ASC?a.POSITIVE:a.NEGATIVE:a.ZERO:r?n===i.ASC?a.POSITIVE:a.NEGATIVE:o?n===i.ASC?a.NEGATIVE:a.POSITIVE:null},l=(e,t,n)=>{let r=typeof e==`string`,s=typeof t==`string`;if(r&&(e=o(e.toLocaleLowerCase())),s&&(t=o(t.toLocaleLowerCase())),!r&&!s)return null;if(r&&s){let r=e,o=t;return r<o?n===i.ASC?a.NEGATIVE:a.POSITIVE:r>o?n===i.ASC?a.POSITIVE:a.NEGATIVE:a.ZERO}return r?n===i.ASC?a.POSITIVE:a.NEGATIVE:s?n===i.ASC?a.NEGATIVE:a.POSITIVE:null},u=e=>!e||Object.keys(e).length===0||(e==null?void 0:e.v)==null&&(e==null?void 0:e.p)==null;function d(e){"@babel/helpers - typeof";return d=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},d(e)}function f(e,t){if(d(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(d(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function p(e){var t=f(e,`string`);return d(t)==`symbol`?t:t+``}function m(e,t,n){return(t=p(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let _=class extends t.Disposable{constructor(e,t,n){super(),this._univerInstanceService=e,this._commandService=t,this._formulaDataModel=n,m(this,`_compareFns`,[])}mergeCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._univerInstanceService.getUnit(r))==null?void 0:n.getSheetBySheetId(i);if(!o)return!1;let s=o.getMergeData().filter(e=>t.Rectangle.contains(a,e));return s.length===0?!0:v(a,s)}emptyCheck(e){var t;let{unitId:n,subUnitId:r,range:i}=e,a=(t=this._univerInstanceService.getUnit(n))==null?void 0:t.getSheetBySheetId(r);if(!a)return!1;for(let e=i.startRow;e<=i.endRow;e++)for(let t=i.startColumn;t<=i.endColumn;t++)if(!u(a.getCellRaw(e,t)))return!0;return!1}singleCheck(e){return e.range.startRow!==e.range.endRow}formulaCheck(e){var n;let{unitId:r,subUnitId:i,range:a}=e,o=(n=this._formulaDataModel.getArrayFormulaRange())==null||(n=n[r])==null?void 0:n[i];for(let e in o){let n=o[Number(e)];for(let e in n){let r=n[Number(e)];if(r&&t.Rectangle.intersects(a,r))return!1}}return!0}registerCompareFn(e){this._compareFns.unshift(e)}getAllCompareFns(){return this._compareFns}applySort(e,t,r){var i;let{unitId:a,subUnitId:o}=(0,n.getSheetCommandTarget)(this._univerInstanceService)||{};this._commandService.executeCommand(y.id,{orderRules:e.orderRules,range:e.range,hasTitle:(i=e.hasTitle)==null?!1:i,unitId:t||a,subUnitId:r||o})}};_=g([h(0,t.IUniverInstanceService),h(1,t.ICommandService),h(2,(0,t.Inject)(r.FormulaDataModel))],_);function v(e,t){let n=e.endRow-e.startRow+1,r=e.endColumn-e.startColumn+1,i=null,a=null,o=n*r,s=0;for(let n of t)if(n.startRow>=e.startRow&&n.endRow<=e.endRow&&n.startColumn>=e.startColumn&&n.endColumn<=e.endColumn){let e=n.endRow-n.startRow+1,t=n.endColumn-n.startColumn+1;if(i===null&&a===null)i=e,a=t;else if(e!==i||t!==a)return!1;s+=e*t}return s===o}let y={id:`sheet.command.sort-range`,type:t.CommandType.COMMAND,handler:(e,r)=>{let{range:i,orderRules:a,hasTitle:o,unitId:s,subUnitId:c}=r,l=e.get(_),{worksheet:u}=(0,n.getSheetCommandTarget)(e.get(t.IUniverInstanceService),r)||{};if(!u)return!1;let d=u.getMergeData().filter(e=>t.Rectangle.contains(i,e)),f=d.map(e=>e.startRow),{startRow:p,endRow:m}=i,h=o?p+1:p,g=[],v=[];for(let e=h;e<=m;e++)u.getRowFiltered(e)||u.getRowRawVisible(e)!==!1&&(d.length&&!f.includes(e)||(g.push({index:e,value:b(u,e,a)}),v.push(e)));let y=l.getAllCompareFns();g.sort(S(a,x(y)));let C={};g.forEach(({index:e,value:t},n)=>{C[v[n]]=e});let w={id:n.ReorderRangeCommand.id,params:{unitId:s,subUnitId:c,range:i,order:C}},T=e.get(t.ICommandService);return(0,t.sequenceExecute)([w],T).result}};function b(e,t,n){let r=[];return n.forEach(({colIndex:n})=>{r.push(e.getCellRaw(t,n))}),r}function x(e){return(t,n,r)=>{for(let i=0;i<e.length;i++){let a=e[i](t,n,r);if(a!=null)return a}return 0}}function S(e,t){return function(n,r){let i=null;for(let a=0;a<e.length;a++){let o=n.value[a],s=r.value[a];if(i=t(e[a].type,o,s),i!==0&&i!=null)return i}return 0}}var C=`@univerjs/sheets-sort`,w=`0.20.1`;let T=`sheets-sort.config`;Symbol(T);let E={},D=class extends t.Disposable{constructor(e,t){super(),this._commandService=e,this._sortService=t,this._initCommands(),this._registerCompareFns()}_initCommands(){[y].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_registerCompareFns(){this._sortService.registerCompareFn((e,t,n)=>{let r=this._getCommonValue(t),i=this._getCommonValue(n),a=[s,l,c];for(let t=0;t<a.length;t++){let n=a[t](r,i,e);if(n!==null)return n}return null})}_getCommonValue(e){var n;return u(e)?null:(e==null||(n=e.p)==null||(n=n.body)==null?void 0:n.dataStream)||((e==null?void 0:e.t)===t.CellValueType.NUMBER?Number.parseFloat(`${e.v}`):(e==null?void 0:e.t)===t.CellValueType.STRING?typeof e.v==`number`?e.v:`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.BOOLEAN?`${e.v}`:(e==null?void 0:e.t)===t.CellValueType.FORCE_STRING?Number.parseFloat(`${e.v}`):`${e==null?void 0:e.v}`)}};D=g([h(0,t.ICommandService),h(1,(0,t.Inject)(_))],D);let O=class extends t.Plugin{constructor(e=E,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{...i}=(0,t.merge)({},E,this._config);this._configService.setConfig(T,i)}onStarting(){[[D],[_]].forEach(e=>this._injector.add(e))}onReady(){this._injector.get(D)}};m(O,`type`,t.UniverInstanceType.UNIVER_SHEET),m(O,`pluginName`,`SHEET_SORT_PLUGIN`),m(O,`packageName`,C),m(O,`version`,w),O=g([(0,t.DependentOn)(n.UniverSheetsPlugin,r.UniverFormulaEnginePlugin),h(1,(0,t.Inject)(t.Injector)),h(2,t.IConfigService)],O),Object.defineProperty(e,`SheetsSortService`,{enumerable:!0,get:function(){return _}}),e.SortRangeCommand=y,e.SortType=i,Object.defineProperty(e,`UniverSheetsSortPlugin`,{enumerable:!0,get:function(){return O}})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-sort",
3
- "version": "0.20.0",
3
+ "version": "0.20.1",
4
4
  "private": false,
5
5
  "description": "A library for sorting data in Univer Sheet",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -58,14 +58,14 @@
58
58
  "lib"
59
59
  ],
60
60
  "dependencies": {
61
- "@univerjs/core": "0.20.0",
62
- "@univerjs/engine-formula": "0.20.0",
63
- "@univerjs/sheets": "0.20.0"
61
+ "@univerjs/engine-formula": "0.20.1",
62
+ "@univerjs/sheets": "0.20.1",
63
+ "@univerjs/core": "0.20.1"
64
64
  },
65
65
  "devDependencies": {
66
66
  "typescript": "^6.0.2",
67
67
  "vitest": "^4.1.1",
68
- "@univerjs-infra/shared": "0.20.0"
68
+ "@univerjs-infra/shared": "0.20.1"
69
69
  },
70
70
  "scripts": {
71
71
  "test": "vitest run",