@univerjs/sheets-table-ui 0.20.0 → 0.20.1-insiders.20260418-3a69981
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 +2569 -1
- package/lib/cjs/locale/ca-ES.js +119 -1
- package/lib/cjs/locale/en-US.js +134 -1
- package/lib/cjs/locale/es-ES.js +119 -1
- package/lib/cjs/locale/fa-IR.js +119 -1
- package/lib/cjs/locale/fr-FR.js +119 -1
- package/lib/cjs/locale/ja-JP.js +119 -1
- package/lib/cjs/locale/ko-KR.js +119 -1
- package/lib/cjs/locale/ru-RU.js +119 -1
- package/lib/cjs/locale/sk-SK.js +119 -1
- package/lib/cjs/locale/vi-VN.js +119 -1
- package/lib/cjs/locale/zh-CN.js +119 -1
- package/lib/cjs/locale/zh-TW.js +119 -1
- package/lib/es/index.js +2563 -1
- package/lib/es/locale/ca-ES.js +118 -1
- package/lib/es/locale/en-US.js +133 -1
- package/lib/es/locale/es-ES.js +118 -1
- package/lib/es/locale/fa-IR.js +118 -1
- package/lib/es/locale/fr-FR.js +118 -1
- package/lib/es/locale/ja-JP.js +118 -1
- package/lib/es/locale/ko-KR.js +118 -1
- package/lib/es/locale/ru-RU.js +118 -1
- package/lib/es/locale/sk-SK.js +118 -1
- package/lib/es/locale/vi-VN.js +118 -1
- package/lib/es/locale/zh-CN.js +118 -1
- package/lib/es/locale/zh-TW.js +118 -1
- package/lib/index.js +2563 -1
- package/lib/locale/ca-ES.js +118 -1
- package/lib/locale/en-US.js +133 -1
- package/lib/locale/es-ES.js +118 -1
- package/lib/locale/fa-IR.js +118 -1
- package/lib/locale/fr-FR.js +118 -1
- package/lib/locale/ja-JP.js +118 -1
- package/lib/locale/ko-KR.js +118 -1
- package/lib/locale/ru-RU.js +118 -1
- package/lib/locale/sk-SK.js +118 -1
- package/lib/locale/vi-VN.js +118 -1
- package/lib/locale/zh-CN.js +118 -1
- package/lib/locale/zh-TW.js +118 -1
- package/lib/umd/index.js +1 -1
- package/package.json +14 -14
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,2569 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/engine-render`),n=require(`@univerjs/sheets-table`),r=require(`@univerjs/sheets-ui`),i=require(`@univerjs/ui`),a=require(`rxjs`),o=require(`@univerjs/design`),s=require(`@univerjs/icons`),c=require(`@univerjs/sheets`),l=require(`@univerjs/sheets-sort`),u=require(`react`),d=require(`react/jsx-runtime`),f=require(`@univerjs/engine-formula`),p=require(`@univerjs/sheets-formula-ui`);var m=`@univerjs/sheets-table-ui`,h=`0.20.0`;const g=`SHEETS_TABLE_FILTER_PANEL_OPENED_KEY`,_=`TABLE_TOOLBAR_BUTTON`,v=`TABLE_SELECTOR_DIALOG`,y=`SHEET_TABLE_THEME_PANEL`,b=`table-custom-`,x=`rgb(255, 255, 255)`,S=`none`,C=`1px solid rgb(var(--grey-200))`;let w=function(e){return e.Items=`items`,e.Condition=`condition`,e}({});function T(e){"@babel/helpers - typeof";return T=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},T(e)}function E(e,t){if(T(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(T(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function D(e){var t=E(e,`string`);return T(t)==`symbol`?t:t+``}function O(e,t,n){return(t=D(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function k(e,t){return function(n,r){t(n,r,e)}}function A(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 j=class extends e.Disposable{constructor(e,t,n,r,i){super(),this._tableManager=e,this._sheetTableService=t,this._univerInstanceService=n,this._commandService=r,this._localeService=i,O(this,`_itemsCache`,new Map),this._registerTableFilterChangeEvent()}_registerTableFilterChangeEvent(){this._commandService.onCommandExecuted(t=>{if(t.id===c.SetRangeValuesMutation.id){let{unitId:n,subUnitId:r,cellValue:i}=t.params,a=this._tableManager.getTablesBySubunitId(n,r);if(!a.length)return;new e.ObjectMatrix(i).forValue((t,n,r)=>{let i=(0,e.cellToRange)(t,n),o=a.find(t=>{let n=t.getTableFilterRange();return e.Rectangle.intersects(n,i)});if(o){let e=n-o.getRange().startColumn;this._itemsCache.delete(o.getId()+e)}})}else if(t.id===n.SetSheetTableFilterCommand.id){let{unitId:e,tableId:n}=t.params,r=this._tableManager.getTable(e,n);if(!r)return;let i=r.getSubunitId();this._tableManager.getTablesBySubunitId(e,i).forEach(e=>{let t=e.getRange();for(let n=t.startColumn;n<=t.endColumn;n++)this._itemsCache.delete(e.getId()+n)})}})}getTableFilterPanelInitProps(e,t,r,i){let a=this._tableManager.getTable(e,r),o=a.getRange(),s=a.getTableFilterColumn(i-o.startColumn);return{unitId:e,subUnitId:t,tableFilter:s,currentFilterBy:(0,n.isConditionFilter)(s)?w.Condition:w.Items,tableId:r,columnIndex:i-o.startColumn}}getTableFilterCheckedItems(e,t,r){let i=this._tableManager.getTable(e,t),a=[];if(i){let e=i.getTableFilterColumn(r);e&&(0,n.isManualTableFilter)(e)&&a.push(...e.values)}return a}setTableFilter(e,t,r,i){if(!this._tableManager.getTable(e,t))return;let a={unitId:e,tableId:t,column:r,tableFilter:i};this._commandService.executeCommand(n.SetSheetTableFilterCommand.id,a)}getTableFilterItems(e,t,n,r){var i;if(this._itemsCache.has(n+r))return this._itemsCache.get(n+r)||{data:[],itemsCountMap:new Map,allItemsCount:0};let a=this._tableManager.getTable(e,n);if(!a)return{data:[],itemsCountMap:new Map,allItemsCount:0};let{startRow:o,endRow:s,startColumn:c}=a.getTableFilterRange(),l=c+r,u=(i=this._univerInstanceService.getUnit(e))==null?void 0:i.getSheetBySheetId(t);if(!u)return{data:[],itemsCountMap:new Map,allItemsCount:0};let d=[],f=new Map,p=0;for(let e=o;e<=s;e++){if(u.isRowFiltered(e))continue;let t=this._sheetTableService.getCellValueWithConditionType(u,e,l);t===void 0&&(t=this._localeService.t(`sheets-table.condition.empty`)),f.has(t)||d.push({title:t,key:`${l}_${e}`,leaf:!0}),p++,f.set(t,(f.get(t)||0)+1)}return this._itemsCache.set(n+r,{data:d,itemsCountMap:f,allItemsCount:p}),{data:d,itemsCountMap:f,allItemsCount:p}}};j=A([k(0,(0,e.Inject)(n.TableManager)),k(1,(0,e.Inject)(n.SheetTableService)),k(2,(0,e.Inject)(e.IUniverInstanceService)),k(3,e.ICommandService),k(4,(0,e.Inject)(e.LocaleService))],j);let M=function(e){return e.DatePicker=`DatePicker`,e.DateRange=`DateRange`,e.Input=`Input`,e.Inputs=`Inputs`,e.Select=`Select`,e.None=`None`,e}({});function N(t){let r=t.get(e.LocaleService).t;return[{value:n.TableConditionTypeEnum.String,label:r(`sheets-table.condition.${n.TableConditionTypeEnum.String}`),children:[{value:n.TableStringCompareTypeEnum.Equal,label:r(`sheets-table.string.compare.${n.TableStringCompareTypeEnum.Equal}`)},{value:n.TableStringCompareTypeEnum.NotEqual,label:r(`sheets-table.string.compare.${n.TableStringCompareTypeEnum.NotEqual}`)},{value:n.TableStringCompareTypeEnum.Contains,label:r(`sheets-table.string.compare.${n.TableStringCompareTypeEnum.Contains}`)},{value:n.TableStringCompareTypeEnum.NotContains,label:r(`sheets-table.string.compare.${n.TableStringCompareTypeEnum.NotContains}`)},{value:n.TableStringCompareTypeEnum.StartsWith,label:r(`sheets-table.string.compare.${n.TableStringCompareTypeEnum.StartsWith}`)},{value:n.TableStringCompareTypeEnum.EndsWith,label:r(`sheets-table.string.compare.${n.TableStringCompareTypeEnum.EndsWith}`)}]},{value:n.TableConditionTypeEnum.Number,label:r(`sheets-table.condition.${n.TableConditionTypeEnum.Number}`),children:[{value:n.TableNumberCompareTypeEnum.Equal,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.Equal}`)},{value:n.TableNumberCompareTypeEnum.NotEqual,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.NotEqual}`)},{value:n.TableNumberCompareTypeEnum.GreaterThan,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.GreaterThan}`)},{value:n.TableNumberCompareTypeEnum.GreaterThanOrEqual,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.GreaterThanOrEqual}`)},{value:n.TableNumberCompareTypeEnum.LessThan,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.LessThan}`)},{value:n.TableNumberCompareTypeEnum.LessThanOrEqual,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.LessThanOrEqual}`)},{value:n.TableNumberCompareTypeEnum.Between,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.Between}`)},{value:n.TableNumberCompareTypeEnum.NotBetween,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.NotBetween}`)},{value:n.TableNumberCompareTypeEnum.Above,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.Above}`)},{value:n.TableNumberCompareTypeEnum.Below,label:r(`sheets-table.number.compare.${n.TableNumberCompareTypeEnum.Below}`)}]},{value:n.TableConditionTypeEnum.Date,label:r(`sheets-table.condition.${n.TableConditionTypeEnum.Date}`),children:[{value:n.TableDateCompareTypeEnum.Equal,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Equal}`)},{value:n.TableDateCompareTypeEnum.NotEqual,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.NotEqual}`)},{value:n.TableDateCompareTypeEnum.After,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.After}`)},{value:n.TableDateCompareTypeEnum.AfterOrEqual,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.AfterOrEqual}`)},{value:n.TableDateCompareTypeEnum.Before,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Before}`)},{value:n.TableDateCompareTypeEnum.BeforeOrEqual,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.BeforeOrEqual}`)},{value:n.TableDateCompareTypeEnum.Between,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Between}`)},{value:n.TableDateCompareTypeEnum.NotBetween,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.NotBetween}`)},{value:n.TableDateCompareTypeEnum.Today,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Today}`)},{value:n.TableDateCompareTypeEnum.Yesterday,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Yesterday}`)},{value:n.TableDateCompareTypeEnum.Tomorrow,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Tomorrow}`)},{value:n.TableDateCompareTypeEnum.ThisWeek,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.ThisWeek}`)},{value:n.TableDateCompareTypeEnum.LastWeek,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.LastWeek}`)},{value:n.TableDateCompareTypeEnum.NextWeek,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.NextWeek}`)},{value:n.TableDateCompareTypeEnum.ThisMonth,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.ThisMonth}`)},{value:n.TableDateCompareTypeEnum.LastMonth,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.LastMonth}`)},{value:n.TableDateCompareTypeEnum.NextMonth,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.NextMonth}`)},{value:n.TableDateCompareTypeEnum.ThisYear,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.ThisYear}`)},{value:n.TableDateCompareTypeEnum.LastYear,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.LastYear}`)},{value:n.TableDateCompareTypeEnum.NextYear,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.NextYear}`)},{value:n.TableDateCompareTypeEnum.Quarter,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Quarter}`)},{value:n.TableDateCompareTypeEnum.Month,label:r(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Month}`)}]}]}function P(t,r){if(!r)return[];let i=t.get(e.LocaleService).t;switch(r){case n.TableDateCompareTypeEnum.Quarter:return[{value:n.TableDateCompareTypeEnum.Q1,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Q1}`)},{value:n.TableDateCompareTypeEnum.Q2,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Q2}`)},{value:n.TableDateCompareTypeEnum.Q3,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Q3}`)},{value:n.TableDateCompareTypeEnum.Q4,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.Q4}`)}];case n.TableDateCompareTypeEnum.Month:return[{value:n.TableDateCompareTypeEnum.M1,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M1}`)},{value:n.TableDateCompareTypeEnum.M2,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M2}`)},{value:n.TableDateCompareTypeEnum.M3,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M3}`)},{value:n.TableDateCompareTypeEnum.M4,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M4}`)},{value:n.TableDateCompareTypeEnum.M5,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M5}`)},{value:n.TableDateCompareTypeEnum.M6,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M6}`)},{value:n.TableDateCompareTypeEnum.M7,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M7}`)},{value:n.TableDateCompareTypeEnum.M8,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M8}`)},{value:n.TableDateCompareTypeEnum.M9,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M9}`)},{value:n.TableDateCompareTypeEnum.M10,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M10}`)},{value:n.TableDateCompareTypeEnum.M11,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M11}`)},{value:n.TableDateCompareTypeEnum.M12,label:i(`sheets-table.date.compare.${n.TableDateCompareTypeEnum.M12}`)}];default:return[]}}const F=new Set([n.TableDateCompareTypeEnum.Equal,n.TableDateCompareTypeEnum.NotEqual,n.TableDateCompareTypeEnum.After,n.TableDateCompareTypeEnum.AfterOrEqual,n.TableDateCompareTypeEnum.Before,n.TableDateCompareTypeEnum.BeforeOrEqual]);function I(e,t){return t?e===n.TableConditionTypeEnum.String?M.Input:e===n.TableConditionTypeEnum.Number?t===n.TableNumberCompareTypeEnum.Between||t===n.TableNumberCompareTypeEnum.NotBetween?M.Inputs:M.Input:e===n.TableConditionTypeEnum.Date?t===n.TableDateCompareTypeEnum.Between||t===n.TableDateCompareTypeEnum.NotBetween?M.DateRange:t===n.TableDateCompareTypeEnum.Quarter||t===n.TableDateCompareTypeEnum.Month?M.Select:F.has(t)?M.DatePicker:M.None:M.None:M.None}function ee(e){if(!e||e.filterType!==`condition`)return{type:n.TableConditionTypeEnum.String,compareType:n.TableStringCompareTypeEnum.Equal,info:{}};let t=e.filterInfo,{conditionType:r,compareType:i}=t;if(r===n.TableConditionTypeEnum.Date)if(i===n.TableDateCompareTypeEnum.Between||i===n.TableDateCompareTypeEnum.NotBetween){let e;return Array.isArray(t.expectedValue)&&(e=t.expectedValue.map(e=>typeof e==`string`?new Date(e):e)),{type:r,compare:i,info:{dateRange:e}}}else if(i===n.TableDateCompareTypeEnum.Today||i===n.TableDateCompareTypeEnum.Yesterday||i===n.TableDateCompareTypeEnum.Tomorrow||i===n.TableDateCompareTypeEnum.ThisWeek||i===n.TableDateCompareTypeEnum.LastWeek||i===n.TableDateCompareTypeEnum.NextWeek||i===n.TableDateCompareTypeEnum.ThisMonth||i===n.TableDateCompareTypeEnum.LastMonth||i===n.TableDateCompareTypeEnum.NextMonth||i===n.TableDateCompareTypeEnum.ThisYear||i===n.TableDateCompareTypeEnum.LastYear||i===n.TableDateCompareTypeEnum.NextYear)return{type:r,compare:i,info:{}};else if(F.has(i)){let e;if(typeof t.expectedValue==`string`)e=new Date(t.expectedValue);else if(Array.isArray(t.expectedValue))for(let e=0;e<t.expectedValue.length;e++)typeof t.expectedValue[e]==`string`&&(t.expectedValue[e]=new Date(t.expectedValue[e]));return{type:r,compare:i,info:{date:e}}}else if(new Set([n.TableDateCompareTypeEnum.Q1,n.TableDateCompareTypeEnum.Q2,n.TableDateCompareTypeEnum.Q3,n.TableDateCompareTypeEnum.Q4]).has(i))return{type:r,compare:n.TableDateCompareTypeEnum.Quarter,info:{dateSelect:t.compareType}};else return{type:r,compare:n.TableDateCompareTypeEnum.Month,info:{dateSelect:t.compareType}};else if(r===n.TableConditionTypeEnum.Number)return i===n.TableNumberCompareTypeEnum.Between||i===n.TableNumberCompareTypeEnum.NotBetween?{type:r,compare:i,info:{numberRange:t.expectedValue}}:{type:r,compare:i,info:{number:t.expectedValue}};else if(r===n.TableConditionTypeEnum.String)return{type:r,compare:i,info:{string:t.expectedValue}};return{type:n.TableConditionTypeEnum.String,compare:n.TableStringCompareTypeEnum.Equal,info:{}}}const te=t=>{var r,a,c,l,f,p,m,h;let{conditionInfo:g,onChange:_}=t,v=(0,i.useDependency)(e.LocaleService),[y,b]=(0,u.useState)(!1),x=(0,i.useDependency)(e.Injector),S=N(x),C=(e,t,n)=>{_({type:t==null?g.type:t,compare:n==null?g.compare:n,info:e})},w=e=>{var t;let r=e[0],i=e[1];i&&b(!1);let a={};r===n.TableConditionTypeEnum.Date?i===n.TableDateCompareTypeEnum.Quarter?a.dateSelect=n.TableDateCompareTypeEnum.Q1:i===n.TableDateCompareTypeEnum.Month?a.dateSelect=n.TableDateCompareTypeEnum.M1:F.has(i)?a.date=new Date:a.dateRange=[new Date,new Date]:r===n.TableConditionTypeEnum.Number?a.number=0:r===n.TableConditionTypeEnum.String&&(a.string=``),C(a,e[0],(t=e[1])==null?n.TableStringCompareTypeEnum.Equal:t)},T=I(g.type,g.compare),E=``;E=g.compare?`${v.t(`sheets-table.condition.${g.type}`)} - ${v.t(`sheets-table.${g.type}.compare.${g.compare}`)}`:v.t(`sheets-table.condition.${g.type}`);let D=P(x,g.compare);return(0,d.jsxs)(`div`,{children:[(0,d.jsx)(o.Dropdown,{align:`start`,open:y,onOpenChange:b,overlay:(0,d.jsx)(o.CascaderList,{value:[g.type,g.compare],options:S,onChange:w,contentClassName:`univer-flex-1`,wrapperClassName:`!univer-h-[150px]`}),children:(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-box-border univer-flex univer-h-8 univer-w-full univer-items-center univer-justify-between univer-rounded-md univer-bg-white univer-px-2 univer-text-sm univer-transition-colors univer-duration-200 hover:univer-border-primary-600 focus:univer-border-primary-600 focus:univer-outline-none focus:univer-ring-2 dark:!univer-bg-gray-700 dark:!univer-text-white`,o.borderClassName),children:[(0,d.jsx)(`span`,{children:E}),(0,d.jsx)(s.MoreDownIcon,{})]})}),(0,d.jsxs)(`div`,{className:`univer-mt-3 univer-w-full`,children:[T===M.Input&&(0,d.jsx)(d.Fragment,{children:g.type===n.TableConditionTypeEnum.String?(0,d.jsx)(o.Input,{className:`univer-w-full`,placeholder:`请输入`,value:g.info.string,onChange:e=>C({string:e})}):(0,d.jsx)(o.InputNumber,{className:`univer-h-7 univer-w-full`,value:g.info.number,controls:!1,onChange:e=>{e!==null&&C({number:e})}})}),T===M.DatePicker&&(0,d.jsx)(`div`,{id:`univer-table-date-picker-wrapper`,children:(0,d.jsx)(o.DatePicker,{className:`univer-w-full`,value:(r=g.info.date)==null?new Date:r,onValueChange:e=>C({date:e})})}),T===M.DateRange&&(0,d.jsx)(`div`,{id:`univer-table-date-range-wrapper`,children:(0,d.jsx)(o.DateRangePicker,{className:`univer-w-full`,value:[(a=(c=g.info.dateRange)==null?void 0:c[0])==null?new Date:a,(l=(f=g.info.dateRange)==null?void 0:f[1])==null?new Date:l],onValueChange:e=>{C(e?{dateRange:e}:{})}})}),T===M.Inputs&&(0,d.jsxs)(`div`,{className:`univer-flex univer-items-center univer-gap-2`,children:[(0,d.jsx)(o.InputNumber,{className:`univer-w-full`,value:(p=g.info.numberRange)==null?void 0:p[0],onChange:e=>{if(e!==null){var t;C({numberRange:[e,(t=g.info.numberRange)==null?void 0:t[1]]})}},controls:!1}),(0,d.jsx)(`span`,{children:` - `}),(0,d.jsx)(o.InputNumber,{className:`univer-w-full`,value:(m=g.info.numberRange)==null?void 0:m[1],controls:!1,onChange:e=>{if(e!==null){var t;C({numberRange:[(t=g.info.numberRange)==null?void 0:t[0],e]})}}})]}),T===M.Select&&(0,d.jsx)(o.Select,{className:`univer-w-full`,value:(h=g.info.dateSelect)==null?D[0].value:h,options:D,onChange:e=>C({dateSelect:e})})]})]})},L=e=>{let t=0;return e.forEach(e=>{t+=e}),t};function R(t){let{unitId:n,tableId:r,subUnitId:a,columnIndex:s,checkedItemSet:c,setCheckedItemSet:l,tableFilter:f}=t,p=(0,i.useDependency)(e.LocaleService),{data:m,itemsCountMap:h,allItemsCount:g}=(0,i.useDependency)(j).getTableFilterItems(n,a,r,s),[_,v]=(0,u.useState)(f===void 0?!0:c.size===h.size),[y,b]=(0,u.useState)(_?g:L(h)),x=!_&&c.size>0,[S,C]=(0,u.useState)(``),w=(0,u.useMemo)(()=>S?m.filter(e=>String(e.title).toLowerCase().includes(S.toLowerCase())):m,[S,m]),T=(0,u.useCallback)(()=>{_?(c.clear(),l(new Set(c)),v(!1)):(w.forEach(e=>{c.add(e.title)}),l(new Set(c)),v(!0))},[_]),E=(0,u.useCallback)(e=>{e===``?(v(!0),m.forEach(e=>{c.add(e.title)}),b(g)):(c.clear(),v(!1),b(0)),C(e)},[]),D=e=>{if(_){v(!1);let t=new Set;for(let{title:n}of m)e!==n&&t.add(n);b(g-h.get(e)),l(t)}else c.has(e)?(c.delete(e),b(y-h.get(e))):(c.add(e),b(y+h.get(e))),l(new Set(c))};return(0,d.jsxs)(`div`,{className:`univer-flex univer-h-full univer-flex-col`,children:[(0,d.jsx)(o.Input,{autoFocus:!0,value:S,placeholder:p.t(`sheets-table.filter.search-placeholder`),onChange:E}),(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-mt-2 univer-box-border univer-flex univer-h-[180px] univer-max-h-[180px] univer-flex-grow univer-flex-col univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-pl-2`,o.borderClassName),children:(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-h-40 univer-overflow-y-auto univer-py-1 univer-pl-2`,o.scrollbarClassName),children:(0,d.jsxs)(`div`,{className:`univer-h-full`,children:[(0,d.jsx)(`div`,{className:`univer-flex univer-items-center univer-px-2 univer-py-1`,children:(0,d.jsx)(o.Checkbox,{indeterminate:x,disabled:m.length===0,checked:_,onChange:T,children:(0,d.jsxs)(`div`,{className:`univer-flex univer-h-5 univer-flex-1 univer-items-center univer-text-sm`,children:[(0,d.jsx)(`span`,{className:`univer-inline-block univer-truncate`,children:`${p.t(`sheets-table.filter.select-all`)}`}),(0,d.jsx)(`span`,{className:`univer-ml univer-text-gray-400`,children:`(${y}/${S?w.length:g})`})]})})}),w.map(e=>(0,d.jsx)(`div`,{className:`univer-flex univer-items-center univer-px-2 univer-py-1`,children:(0,d.jsx)(o.Checkbox,{checked:_||c.has(e.title),onChange:()=>{D(e.title)},children:(0,d.jsxs)(`div`,{className:`univer-flex univer-h-5 univer-flex-1 univer-text-sm`,children:[(0,d.jsx)(`span`,{className:`univer-inline-block univer-truncate`,children:e.title}),(0,d.jsx)(`span`,{className:`univer-ml-1 univer-text-gray-400`,children:`(${h.get(e.title)||0})`})]})})},e.key))]})})})]})}function z(){var t;let r=(0,i.useDependency)(e.LocaleService),a=B(r),f=(0,i.useDependency)(j),p=(0,i.useDependency)(n.TableManager),m=(0,i.useDependency)(e.ICommandService),h=(0,i.useDependency)(e.IPermissionService),g=(0,i.useDependency)(V),_=g.getCurrentTableFilterInfo(),v=f.getTableFilterPanelInitProps(_.unitId,_.subUnitId,_.tableId,_.column),{unitId:y,subUnitId:b,tableId:x,tableFilter:S,currentFilterBy:C,columnIndex:T}=v,{data:E}=f.getTableFilterItems(y,b,x,T),D=f.getTableFilterCheckedItems(y,x,T),[O,k]=(0,u.useState)(new Set(D)),[A,M]=(0,u.useState)(C||w.Items),[N,P]=(0,u.useState)(()=>{let e=v.tableFilter;return ee(e)}),F=p.getTable(y,x);if(!F)return null;let I=F.getTableFilters(),L=I.getSortState();L.columnIndex===T&&(L.sortState,n.SheetsTableSortStateEnum.Asc),L.columnIndex===T&&(L.sortState,n.SheetsTableSortStateEnum.Desc);let z=()=>{g.closeFilterPanel()},H=()=>{z()},U=e=>{let t=F.getTableFilterRange();m.executeCommand(l.SortRangeCommand.id,{unitId:y,subUnitId:b,range:t,orderRules:[{colIndex:T+t.startColumn,type:e?l.SortType.ASC:l.SortType.DESC}],hasTitle:!1}),I.setSortState(T,e?n.SheetsTableSortStateEnum.Asc:n.SheetsTableSortStateEnum.Desc),z()},W=()=>{if(A===w.Items){let e=[];for(let t of E)O.has(t.title)&&e.push(t.title);let t=F.getTableFilterColumn(T);if(t){if(t.values.join(`,`)===e.join(`,`)){z();return}}else if(e.length===0){z();return}let r={filterType:n.TableColumnFilterTypeEnum.manual,values:e};f.setTableFilter(y,x,T,r)}else{let e;e=N.compare===n.TableDateCompareTypeEnum.Quarter||N.compare===n.TableDateCompareTypeEnum.Month?{conditionType:N.type,compareType:Object.values(N.info)[0]}:{conditionType:N.type,compareType:N.compare,expectedValue:Object.values(N.info)[0]};let t={filterType:n.TableColumnFilterTypeEnum.condition,filterInfo:e};f.setTableFilter(y,x,T,t)}z()},G=()=>{f.setTableFilter(y,x,T,void 0),z()},K=new c.WorkbookEditablePermission(y).id;return(0,d.jsxs)(`div`,{className:`univer-box-border univer-flex univer-min-w-[312px] univer-flex-col univer-rounded-[10px] univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700`,children:[((t=h.getPermissionPoint(K))==null?void 0:t.value)&&(0,d.jsx)(`div`,{className:`univer-mb-3 univer-flex`,children:(0,d.jsxs)(o.ButtonGroup,{className:`univer-mb-3 !univer-flex univer-w-full`,children:[(0,d.jsxs)(o.Button,{className:`univer-w-1/2`,onClick:()=>U(!0),children:[(0,d.jsx)(s.AscendingIcon,{className:`univer-mr-1`}),r.t(`sheets-sort.general.sort-asc`)]}),(0,d.jsxs)(o.Button,{className:`univer-w-1/2`,onClick:()=>U(!1),children:[(0,d.jsx)(s.DescendingIcon,{className:`univer-mr-1`}),r.t(`sheets-sort.general.sort-desc`)]})]})}),(0,d.jsx)(`div`,{className:`univer-w-full`,children:(0,d.jsx)(o.Segmented,{value:A,items:a,onChange:e=>M(e)})}),(0,d.jsx)(`div`,{className:`univer-z-10 univer-h-60`,children:(0,d.jsx)(`div`,{className:`univer-mt-3 univer-size-full`,children:A===w.Items?(0,d.jsx)(R,{tableFilter:S,unitId:y,subUnitId:b,tableId:x,columnIndex:T,checkedItemSet:O,setCheckedItemSet:k}):(0,d.jsx)(te,{tableFilter:S,unitId:y,subUnitId:b,tableId:x,columnIndex:T,conditionInfo:N,onChange:P})})}),(0,d.jsxs)(`div`,{className:`univer-flex-wrap-nowrap univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-justify-between univer-gap-6 univer-overflow-hidden`,children:[(0,d.jsx)(o.Button,{disabled:S===void 0,onClick:G,children:r.t(`sheets-table.filter.clear-filter`)}),(0,d.jsxs)(`div`,{children:[(0,d.jsx)(o.Button,{className:`univer-mr-2`,onClick:H,children:r.t(`sheets-table.filter.cancel`)}),(0,d.jsx)(o.Button,{variant:`primary`,onClick:W,children:r.t(`sheets-table.filter.confirm`)})]})]})]})}function B(e){return(0,u.useMemo)(()=>[{label:e.t(`sheets-table.filter.by-values`),value:w.Items},{label:e.t(`sheets-table.filter.by-conditions`),value:w.Condition}],[e.getCurrentLocale(),e])}let V=class extends e.Disposable{constructor(e,t,n,r){super(),this._componentManager=e,this._contextService=t,this._sheetCanvasPopupService=n,this._dialogService=r,O(this,`_popupDisposable`,void 0),O(this,`_currentTableFilterInfo`,null),this._initComponents(),this._initUIPopup()}setCurrentTableFilterInfo(e){this._currentTableFilterInfo=e}clearCurrentTableFilterInfo(){this._currentTableFilterInfo=null}getCurrentTableFilterInfo(){return this._currentTableFilterInfo}_initComponents(){[[g,z]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initUIPopup(){this.disposeWithMe(this._contextService.subscribeContextValue$(g).pipe((0,a.startWith)(void 0),(0,a.distinctUntilChanged)()).subscribe(e=>{e?this._openFilterPopup():e===!1&&this._closeFilterPopup()}))}closeFilterPanel(){this._contextService.setContextValue(g,!1)}_openFilterPopup(){let e=this._currentTableFilterInfo;if(!e)throw Error(`[SheetsFilterUIController]: no filter model when opening filter popup!`);let{row:t,column:n}=e;this._popupDisposable=this._sheetCanvasPopupService.attachPopupToCell(t,n,{componentKey:g,direction:`horizontal`,onClickOutside:()=>{this._dialogService.close(`UNIVER_SHEET_Table_FILTER_PANEL_ID`),this._contextService.setContextValue(g,!1)},offset:[5,0],portal:!0})}_closeFilterPopup(){var e;(e=this._popupDisposable)==null||e.dispose(),this._popupDisposable=null,this.clearCurrentTableFilterInfo()}};V=A([k(0,(0,e.Inject)(i.ComponentManager)),k(1,e.IContextService),k(2,(0,e.Inject)(r.SheetCanvasPopManagerService)),k(3,(0,e.Inject)(i.IDialogService))],V);const H={type:e.CommandType.OPERATION,id:`sheet.operation.open-table-filter-panel`,async handler(t,r){if(!r)return!1;let{row:i,col:a,unitId:o,subUnitId:s,tableId:c}=r,l=t.get(n.TableManager),u=t.get(e.IContextService),d=t.get(V);return l.getTable(o,c)?(u.getContextValue(`SHEETS_TABLE_FILTER_PANEL_OPENED_KEY`)||(d.setCurrentTableFilterInfo({unitId:o,subUnitId:s,row:i,tableId:c,column:a}),u.setContextValue(g,!0)),!0):!1}},U={type:e.CommandType.OPERATION,id:`sheet.operation.open-table-selector`,async handler(t){var r;let i=t.get(e.IUniverInstanceService),a=t.get(e.ICommandService),o=(0,c.getSheetCommandTarget)(i);if(!o)return!1;let{unitId:s,subUnitId:l,worksheet:u}=o,d=t.get(c.SheetsSelectionsService).getCurrentLastSelection(),f=(r=d==null?void 0:d.range)==null?{startRow:0,endRow:0,startColumn:0,endColumn:0}:r,p=await W(t,s,l,(0,c.isSingleCellSelection)(d)?(0,c.expandToContinuousRange)(f,{up:!0,left:!0,right:!0,down:!0},u):f);return p?(a.executeCommand(n.AddSheetTableCommand.id,{...p}),!0):!1}};async function W(t,n,r,a,o){let s=t.get(i.IDialogService),c=t.get(e.LocaleService);return new Promise(e=>{let t={unitId:n,subUnitId:r,range:a,tableId:o,onConfirm:t=>{e(t),s.close(v)},onCancel:()=>{e(null),s.close(v)}};s.open({id:v,title:{title:c.t(`sheets-table.selectRange`)},draggable:!0,destroyOnClose:!0,mask:!1,maskClosable:!1,children:{label:{name:v,props:t}},width:300,onClose:()=>{e(null),s.close(v)}})})}const G=`sheets-table-ui.config`;Symbol(G);const K={anchorHeight:24,anchorBackgroundColor:`rgb(134,139,156)`};let q=class extends e.Disposable{constructor(e){super(),this._commandService=e,O(this,`_refreshTable`,new a.Subject),O(this,`refreshTable$`,this._refreshTable.asObservable()),this._initListener()}_initListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===c.SetRangeThemeMutation.id){let{styleName:t}=e.params;t.startsWith(n.SHEET_TABLE_CUSTOM_THEME_PREFIX)&&this._refreshTable.next(Math.random())}}))}};q=A([k(0,(0,e.Inject)(e.ICommandService))],q);const J=()=>{var t,r;let[a,l]=(0,u.useState)(``),[f,p]=(0,u.useState)(``),m=(0,i.useDependency)(i.ISidebarService),[h,g]=(0,u.useState)({}),_=(0,i.useDependency)(e.Injector),v=(0,i.useObservable)((0,i.useDependency)(Y).anchorPosition$),b=(0,i.useDependency)(e.ICommandService),x=(0,i.useDependency)(e.IUniverInstanceService),S=(0,i.useObservable)((0,i.useDependency)(c.WorkbookPermissionService).unitPermissionInitStateChange$,!1),C=(0,i.useDependency)(n.TableManager),w=(0,i.useDependency)(c.SheetRangeThemeModel),T=(0,i.useObservable)((0,i.useDependency)(q).refreshTable$),E=(0,i.useDependency)(e.LocaleService),D=(0,i.useObservable)((0,i.useDependency)(c.SheetsSelectionsService).selectionChanged$,[{range:(0,e.cellToRange)(0,0),primary:null}]),[,O]=(0,u.useState)(Math.random()),k=(0,i.useDependency)(e.IConfigService).getConfig(G),A=(t=k==null?void 0:k.anchorHeight)==null?24:t,j=(r=k==null?void 0:k.anchorBackgroundColor)==null?`rgb(53,91,183)`:r,M=(e,t)=>{g(n=>({...n,[e]:t}))};if((0,u.useEffect)(()=>{O(Math.random())},[T]),!(v!=null&&v.length))return null;let N=(0,c.getSheetCommandTarget)(x);if(!N)return null;let{unitId:P,subUnitId:F}=N,I=(e,t)=>{var r;if(((r=C.getTableById(P,e))==null?void 0:r.getDisplayName())===t){l(``),p(``);return}b.executeCommand(n.SetSheetTableCommand.id,{tableId:e,unitId:P,name:t}),p(``),l(``)},ee=async e=>{let t=C.getTableById(P,e);if(!t)return;let r=await W(_,P,F,t.getRange(),e);r&&b.executeCommand(n.SetSheetTableCommand.id,{tableId:e,unitId:P,updateRange:{newRange:r.range}})};return S?(0,d.jsx)(`div`,{className:`univer-absolute univer-z-50 univer-size-0`,children:v.map(t=>{var r,i,c,u,g;let _=C.getTableById(P,t.tableId);if(!_)return null;let v=w.getRangeThemeStyle(P,_.getTableStyleId()),x=(r=v==null||(i=v.getHeaderRowStyle())==null||(i=i.bg)==null?void 0:i.rgb)==null?j:r,S=(c=v==null||(u=v.getHeaderRowStyle())==null||(u=u.cl)==null?void 0:u.rgb)==null?`rgb(255, 255, 255)`:c,T=_.getRange();if(!(D!=null&&D.length))return null;let O=D[D.length-1].range,k=!e.Rectangle.intersects(T,O)&&t.y<=20;return(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-shadow-xs univer-absolute univer-box-border univer-cursor-pointer univer-items-center univer-rounded-xl univer-px-2`,o.borderClassName,{"univer-flex":!k,"univer-hidden":k}),style:{left:t.x,top:Math.max(t.y,0),backgroundColor:x,color:S,borderWidth:`0.5px`,height:A?`${A}px`:`24px`},children:[(0,d.jsx)(`div`,{className:`univer-text-nowrap`,children:a===t.tableId?(0,d.jsx)(o.Input,{className:`univer-h-[18px] univer-min-w-16 univer-rounded-none`,inputClass:`univer-h-[18px] univer-w-[80px]`,value:f,onChange:e=>p(e),onBlur:()=>I(t.tableId,f),onKeyDown:e=>{e.key===`Enter`&&I(t.tableId,f)},autoFocus:a===t.tableId}):(0,d.jsx)(`div`,{className:`univer-h-[18px] univer-max-w-24 univer-truncate univer-text-sm`,children:t.tableName})}),(0,d.jsx)(o.Dropdown,{align:`start`,overlay:(0,d.jsxs)(`div`,{className:`univer-py-2`,children:[(0,d.jsxs)(`div`,{className:`univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-gap-2 univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200`,onClick:()=>{l(t.tableId),p(t.tableName)},children:[(0,d.jsx)(s.RenameIcon,{}),E.t(`sheets-table.rename`)]}),(0,d.jsx)(`div`,{className:`univer-my-1 univer-h-px univer-w-full univer-bg-gray-200`}),(0,d.jsxs)(`div`,{onClick:()=>ee(t.tableId),className:`univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-gap-2 univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200`,children:[(0,d.jsx)(s.GridOutlineIcon,{}),E.t(`sheets-table.updateRange`)]}),(0,d.jsxs)(`div`,{className:`univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-gap-2 univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200`,onClick:()=>{M(t.tableId,!1);let e=C.getTableById(P,t.tableId);if(!e)return;let n=e.getTableConfig(),r={id:`SHEET_TABLE_THEME_PANEL_ID`,header:{title:E.t(`sheets-table.tableStyle`)},children:{label:y,oldConfig:n,unitId:P,subUnitId:F,tableId:t.tableId},width:330};m.open(r)},children:[(0,d.jsx)(s.PaintBucketDoubleIcon,{extend:{colorChannel1:`rgb(53,91,183)`}}),E.t(`sheets-table.setTheme`)]}),(0,d.jsx)(`div`,{className:`univer-my-1 univer-h-px univer-w-full univer-bg-gray-200`}),(0,d.jsxs)(`div`,{className:`univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200`,onClick:()=>{M(t.tableId,!1),b.executeCommand(n.DeleteSheetTableCommand.id,{tableId:t.tableId,subUnitId:F,unitId:P})},children:[(0,d.jsx)(s.DeleteIcon,{className:`univer-mr-2`}),E.t(`sheets-table.removeTable`)]})]}),open:(g=h[t.tableId])==null?!1:g,onOpenChange:e=>{M(t.tableId,e)},children:(0,d.jsx)(`div`,{children:(0,d.jsx)(s.MoreDownIcon,{})})},t.tableId)]},t.tableId)})}):null};let Y=class extends e.Disposable{constructor(e,t,n,r,i,o,s,c,l,u,d){super(),this._context=e,this._injector=t,this._sheetSkeletonManagerService=n,this._renderManagerService=r,this._commandService=i,this._univerInstanceService=o,this._uiPartsService=s,this._tableManager=c,this._scrollManagerService=l,this._workbookPermissionService=u,this._permissionService=d,O(this,`_anchorVisible$`,new a.BehaviorSubject(!0)),O(this,`_timer`,void 0),O(this,`_anchorPosition$`,new a.BehaviorSubject([])),O(this,`anchorPosition$`,this._anchorPosition$.asObservable()),this._initUI(),this._initListener(),this._initTableAnchor()}_initUI(){this.disposeWithMe(this._uiPartsService.registerComponent(i.BuiltInUIPart.CONTENT,()=>(0,i.connectInjector)(J,this._injector)))}_initListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{(e.id===r.SetZoomRatioOperation.id||e.id===r.SetScrollOperation.id)&&(this._anchorVisible$.next(!1),this._timer&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._anchorVisible$.next(!0)},300))}))}_initTableAnchor(){this.disposeWithMe((0,a.merge)(this._context.unit.activeSheet$,this._sheetSkeletonManagerService.currentSkeleton$,this._scrollManagerService.validViewportScrollInfo$,this._tableManager.tableAdd$,this._tableManager.tableDelete$,this._tableManager.tableNameChanged$,this._tableManager.tableRangeChanged$,this._tableManager.tableThemeChanged$,this._workbookPermissionService.unitPermissionInitStateChange$.pipe((0,a.filter)(e=>e)),this._permissionService.permissionPointUpdate$.pipe((0,a.debounceTime)(300)),this._anchorVisible$).subscribe(()=>{var e;if(!this._anchorVisible$.getValue()){this._anchorPosition$.next([]);return}let n=this._context.unit,i=n.getActiveSheet(),a=i==null?void 0:i.getSheetId(),o=this._tableManager.getTableList(this._context.unitId).filter(e=>e.subUnitId===a),s=this._renderManagerService.getRenderById(this._context.unitId);if(!s){this._anchorPosition$.next([]);return}if(!((e=this._permissionService.getPermissionPoint(new c.WorkbookEditablePermission(n.getUnitId()).id))!=null&&e.value)){this._anchorPosition$.next([]);return}let l=o.reduce((e,n)=>{let{startRow:i,startColumn:a}=n.range,o=s.with(r.SheetSkeletonManagerService),c=(0,r.getSheetObject)(this._univerInstanceService,this._renderManagerService);if(!c)return e;let{scene:l}=c,u=l.getViewport(t.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!u)return e;let d=l==null?void 0:l.scaleX,f=l==null?void 0:l.scaleY,p=l==null?void 0:l.getViewportScrollXY(u);if(!d||!l||!f||!p)return e;let m=o.getCurrentSkeleton();if(!m)return e;let h=m.getNoMergeCellWithCoordByIndex(i,a),g=(0,t.convertTransformToOffsetX)(h.startX,d,p),_=(0,t.convertTransformToOffsetY)(h.startY,f,p)-25-4;return _>=-10&&g>=45&&e.push({x:g,y:_,tableId:n.id,tableName:n.name}),e},[]);this._anchorPosition$.next(l)}))}};Y=A([k(1,(0,e.Inject)(e.Injector)),k(2,(0,e.Inject)(r.SheetSkeletonManagerService)),k(3,t.IRenderManagerService),k(4,e.ICommandService),k(5,e.IUniverInstanceService),k(6,i.IUIPartsService),k(7,(0,e.Inject)(n.TableManager)),k(8,(0,e.Inject)(r.SheetScrollManagerService)),k(9,(0,e.Inject)(c.WorkbookPermissionService)),k(10,(0,e.Inject)(e.IPermissionService))],Y),new Path2D(`M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z`);var X=class{static drawNoSetting(e,n,r,i){e.save(),t.Rect.drawWith(e,{radius:2,width:16,height:16,fill:i}),e.lineCap=`square`,e.strokeStyle=r,e.scale(n/16,n/16),e.beginPath(),e.lineWidth=1,e.lineCap=`round`,e.moveTo(3,4),e.lineTo(13,4),e.moveTo(4.5,8),e.lineTo(11.5,8),e.moveTo(6,12),e.lineTo(10,12),e.stroke(),e.restore()}static drawIconByPath(e,n,r,i){e.save(),e.strokeStyle=r,e.fillStyle=i,t.Rect.drawWith(e,{radius:2,width:16,height:16,fill:i}),n.forEach(t=>{let n=new Path2D(t);e.fillStyle=r,e.fill(n,`evenodd`)}),e.restore()}};const ne=[`M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z`],re=[`M12.4008 13.1831C12.6907 13.1831 12.9258 12.9481 12.9258 12.6581V4.60873L14.013 5.69597C14.218 5.901 14.5505 5.901 14.7555 5.69597C14.9605 5.49094 14.9605 5.15853 14.7555 4.95351L12.7721 2.97017C12.5671 2.76515 12.2347 2.76515 12.0297 2.97017L10.0463 4.95351C9.84132 5.15853 9.84132 5.49094 10.0463 5.69597C10.2514 5.901 10.5838 5.901 10.7888 5.69597L11.8758 4.60901V12.6581C11.8758 12.9481 12.1108 13.1831 12.4008 13.1831Z`,`M1.28069 4.85447C0.842195 4.33439 1.21191 3.5391 1.89218 3.5391H8.59333C9.2736 3.5391 9.64331 4.33439 9.20482 4.85447L6.51052 8.0501V11.6601C6.51052 12.2245 5.94174 12.6114 5.41683 12.404L4.48092 12.0343C4.1756 11.9136 3.97498 11.6187 3.97498 11.2904V8.0501L1.28069 4.85447Z`],ie=[`M12.4008 2.81641C12.6907 2.81641 12.9258 3.05146 12.9258 3.34141V11.3908L14.013 10.3036C14.218 10.0986 14.5505 10.0986 14.7555 10.3036C14.9605 10.5086 14.9605 10.841 14.7555 11.046L12.7721 13.0294C12.5671 13.2344 12.2347 13.2344 12.0297 13.0294L10.0463 11.046C9.84132 10.841 9.84132 10.5086 10.0463 10.3036C10.2514 10.0986 10.5838 10.0986 10.7888 10.3036L11.8758 11.3905V3.34141C11.8758 3.05146 12.1108 2.81641 12.4008 2.81641Z`,`M1.28069 4.85444C0.842195 4.33435 1.21191 3.53906 1.89218 3.53906H8.59333C9.2736 3.53906 9.64331 4.33435 9.20482 4.85443L6.51052 8.05006V11.6601C6.51052 12.2245 5.94174 12.6113 5.41683 12.404L4.48092 12.0342C4.1756 11.9136 3.97498 11.6186 3.97498 11.2903V8.05006L1.28069 4.85444Z`],ae=[`M11.9003 13.7046C11.9003 13.9969 11.6633 14.2339 11.371 14.2339C11.0787 14.2339 10.8417 13.9969 10.8417 13.7046V3.57272L9.74577 4.66862C9.53906 4.87534 9.20391 4.87534 8.9972 4.66862C8.79048 4.46191 8.79048 4.12676 8.9972 3.92005L10.9969 1.92039C11.2036 1.71368 11.5387 1.71368 11.7454 1.92039L13.7451 3.92005C13.9518 4.12676 13.9518 4.46191 13.7451 4.66862C13.5384 4.87534 13.2032 4.87534 12.9965 4.66862L11.9003 3.57243V13.7046Z`,`M2.69779 10.0113C2.40546 10.0113 2.16847 9.77429 2.16847 9.48196C2.16847 9.18962 2.40546 8.95264 2.69779 8.95264H6.67804C6.89213 8.95264 7.08514 9.0816 7.16707 9.2794C7.249 9.47719 7.20371 9.70486 7.05233 9.85624L3.97569 12.9329H6.67804C6.97038 12.9329 7.20736 13.1699 7.20736 13.4622C7.20736 13.7545 6.97038 13.9915 6.67804 13.9915H2.69779C2.4837 13.9915 2.29069 13.8626 2.20876 13.6648C2.12684 13.467 2.17212 13.2393 2.32351 13.0879L5.40015 10.0113H2.69779Z`,`M5.51638 2.58693C5.23363 1.81542 4.14248 1.81543 3.85973 2.58693L2.13245 7.29995C2.03185 7.57443 2.17281 7.87849 2.4473 7.97909C2.72178 8.07969 3.02584 7.93872 3.12644 7.66424L3.64346 6.25351L3.64504 6.25351H5.73266L6.24968 7.66424C6.35027 7.93872 6.65433 8.07969 6.92882 7.97909C7.2033 7.87849 7.34426 7.57443 7.24367 7.29995L5.51638 2.58693ZM5.34467 5.19487L4.68806 3.40325L4.03144 5.19487H5.34467Z`],oe=[`M11.9003 2.29495C11.9003 2.00261 11.6633 1.76562 11.371 1.76562C11.0787 1.76562 10.8417 2.00261 10.8417 2.29495V12.4268L9.74577 11.3309C9.53906 11.1242 9.20391 11.1242 8.9972 11.3309C8.79048 11.5376 8.79048 11.8727 8.9972 12.0795L10.9969 14.0791C11.2036 14.2858 11.5387 14.2858 11.7454 14.0791L13.7451 12.0795C13.9518 11.8727 13.9518 11.5376 13.7451 11.3309C13.5384 11.1242 13.2032 11.1242 12.9965 11.3309L11.9003 12.4271V2.29495Z`,`M2.69792 10.0113C2.40558 10.0113 2.16859 9.77429 2.16859 9.48196C2.16859 9.18962 2.40558 8.95264 2.69792 8.95264H6.67816C6.89225 8.95264 7.08526 9.0816 7.16719 9.2794C7.24912 9.47719 7.20384 9.70486 7.05245 9.85624L3.97581 12.9329H6.67816C6.9705 12.9329 7.20749 13.1699 7.20749 13.4622C7.20749 13.7545 6.9705 13.9915 6.67816 13.9915H2.69792C2.48383 13.9915 2.29082 13.8626 2.20889 13.6648C2.12696 13.467 2.17224 13.2393 2.32363 13.0879L5.40027 10.0113H2.69792Z`,`M5.5165 2.58693C5.23375 1.81542 4.1426 1.81543 3.85985 2.58693L2.13257 7.29995C2.03197 7.57443 2.17294 7.8785 2.44742 7.97909C2.7219 8.07969 3.02596 7.93872 3.12656 7.66424L3.64358 6.25351L3.64516 6.25351H5.73278L6.2498 7.66424C6.35039 7.93872 6.65446 8.07969 6.92894 7.97909C7.20342 7.8785 7.34438 7.57443 7.24379 7.29995L5.5165 2.58693ZM5.34479 5.19487L4.68818 3.40325L4.03156 5.19487H5.34479Z`];let se=class extends t.Shape{constructor(e,t,n,r,i){super(e,t),this._contextService=n,this._commandService=r,this._themeService=i,O(this,`_cellWidth`,0),O(this,`_cellHeight`,0),O(this,`_filterParams`,void 0),O(this,`_hovered`,!1),this.setShapeProps(t),this.onPointerDown$.subscribeEvent(e=>this.onPointerDown(e)),this.onPointerEnter$.subscribeEvent(()=>this.onPointerEnter()),this.onPointerLeave$.subscribeEvent(()=>this.onPointerLeave())}setShapeProps(e){e.cellHeight!==void 0&&(this._cellHeight=e.cellHeight),e.cellWidth!==void 0&&(this._cellWidth=e.cellWidth),e.filterParams!==void 0&&(this._filterParams=e.filterParams),this.transformByState({width:e.width,height:e.height})}_draw(e){let t=this._cellHeight,r=this._cellWidth,i=16-r,a=16-t;e.save();let o=new Path2D;o.rect(i,a,r,t),e.clip(o);let{buttonState:s}=this._filterParams,c=this._themeService.getColorFromTheme(`primary.600`),l=this._hovered?this._themeService.getColorFromTheme(`gray.50`):`rgba(255, 255, 255, 1.0)`,u;switch(s){case n.SheetsTableButtonStateEnum.FilteredSortNone:u=ne;break;case n.SheetsTableButtonStateEnum.FilteredSortAsc:u=re;break;case n.SheetsTableButtonStateEnum.FilteredSortDesc:u=ie;break;case n.SheetsTableButtonStateEnum.FilterNoneSortNone:break;case n.SheetsTableButtonStateEnum.FilterNoneSortAsc:u=ae;break;case n.SheetsTableButtonStateEnum.FilterNoneSortDesc:u=oe;break}u?X.drawIconByPath(e,u,c,l):s!==void 0&&X.drawNoSetting(e,16,c,l),e.restore()}onPointerDown(e){if(e.button===2)return;let{row:t,col:n,unitId:r,subUnitId:i,tableId:a}=this._filterParams;this._contextService.getContextValue(`SHEETS_TABLE_FILTER_PANEL_OPENED_KEY`)||!this._commandService.hasCommand(H.id)||setTimeout(()=>{let e={row:t,col:n,unitId:r,subUnitId:i,tableId:a};this._commandService.executeCommand(H.id,e)},200)}onPointerEnter(){this._hovered=!0,this.makeDirty(!0)}onPointerLeave(){this._hovered=!1,this.makeDirty(!0)}};se=A([k(2,e.IContextService),k(3,e.ICommandService),k(4,(0,e.Inject)(e.ThemeService))],se);const ce=(t,n,r,i)=>{switch(i){case e.VerticalAlign.TOP:return t+1;case e.VerticalAlign.MIDDLE:return t+Math.max(0,(r-16)/2);case e.VerticalAlign.BOTTOM:default:return n-16-1}};let le=class extends e.RxDisposable{constructor(e,t,n,r,i,a){super(),this._context=e,this._injector=t,this._sheetSkeletonManagerService=n,this._sheetInterceptorService=r,this._tableManager=i,this._commandService=a,O(this,`_buttonRenderDisposable`,null),O(this,`_tableFilterButtonShapes`,[]),this._initRenderer(),this._initCommandExecuted()}dispose(){super.dispose(),this._disposeRendering()}_initRenderer(){let e=this._tableManager;this._sheetSkeletonManagerService.currentSkeleton$.pipe((0,a.switchMap)(t=>{var n;if(!t)return(0,a.of)(null);let{unit:r,unitId:i}=this._context,o=((n=r.getActiveSheet())==null?void 0:n.getSheetId())||``,s=()=>({unitId:i,worksheetId:o,tableFilterRanges:this._tableManager.getSheetFilterRangeWithState(r.getUnitId(),o),skeleton:t.skeleton});return(0,a.merge)(e.tableAdd$,e.tableNameChanged$,e.tableRangeChanged$,e.tableThemeChanged$,e.tableDelete$,e.tableFilterChanged$).pipe((0,a.map)(()=>s()),(0,a.startWith)(s()))}),(0,a.takeUntil)(this.dispose$)).subscribe(e=>{this._disposeRendering(),!(!e||!e.tableFilterRanges)&&this._renderButtons(e)})}_initCommandExecuted(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t;if(e.id!==c.SetVerticalTextAlignCommand.id)return;let{unit:n,unitId:r}=this._context,i=((t=n.getActiveSheet())==null?void 0:t.getSheetId())||``,a=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!a)return;let o={unitId:r,worksheetId:i,tableFilterRanges:this._tableManager.getSheetFilterRangeWithState(n.getUnitId(),i),skeleton:a};this._disposeRendering(),!(!o||!o.tableFilterRanges)&&this._renderButtons(o)}))}_renderButtons(t){let{tableFilterRanges:n,unitId:i,skeleton:a,worksheetId:o}=t,{unit:s,scene:c}=this._context,l=s.getSheetBySheetId(o);if(l){for(let{range:t,states:s,tableId:u}of n){let{startRow:n,startColumn:d,endColumn:f}=t;this._interceptCellContent(i,o,t);for(let t=d;t<=f;t++){let f=`sheets-table-filter-button-${n}-${t}`,p=(0,r.getCoordByCell)(n,t,c,a),m=l.getCellStyle(n,t),h=(m==null?void 0:m.vt)||e.VerticalAlign.BOTTOM,{startX:g,startY:_,endX:v,endY:y}=p,b=v-g,x=y-_;if(x<=1||b<=1)continue;let S=s[t-d],C={left:v-16-1,top:ce(_,y,x,h),height:16,width:16,zIndex:5e3,cellHeight:x,cellWidth:b,filterParams:{unitId:i,subUnitId:o,row:n,col:t,buttonState:S,tableId:u}},w=this._injector.createInstance(se,f,C);this._tableFilterButtonShapes.push(w)}}c.addObjects(this._tableFilterButtonShapes),c.makeDirty()}}_interceptCellContent(t,n,r){let{startRow:i,startColumn:a,endColumn:o}=r;this._buttonRenderDisposable=this._sheetInterceptorService.intercept(c.INTERCEPTOR_POINT.CELL_CONTENT,{effect:e.InterceptorEffectEnum.Style,handler:(e,r,s)=>{let{row:c,col:l,unitId:u,subUnitId:d}=r;return u!==t||d!==n||c!==i||l<a||l>o?s(e):((!e||e===r.rawData)&&(e={...r.rawData}),e.fontRenderExtension={...e==null?void 0:e.fontRenderExtension,rightOffset:16},s(e))},priority:10})}_disposeRendering(){var e;this._tableFilterButtonShapes.forEach(e=>e.dispose()),(e=this._buttonRenderDisposable)==null||e.dispose(),this._buttonRenderDisposable=null,this._tableFilterButtonShapes=[]}};le=A([k(1,(0,e.Inject)(e.Injector)),k(2,(0,e.Inject)(r.SheetSkeletonManagerService)),k(3,(0,e.Inject)(c.SheetInterceptorService)),k(4,(0,e.Inject)(n.TableManager)),k(5,e.ICommandService)],le);let ue=class extends e.RxDisposable{constructor(e,t,n,r,i){super(),this._context=e,this._injector=t,this._sheetSkeletonManagerService=n,this._tableManager=r,this._sheetTableThemeUIController=i,this._initListener()}_dirtySkeleton(){var e;(e=this._context.mainComponent)==null||e.makeDirty();let t=this._sheetSkeletonManagerService.getCurrentParam();if(t){let e={...t,dirty:!0};this._sheetSkeletonManagerService.reCalculate(e)}}_initListener(){let e=this._tableManager,t=this._dirtySkeleton.bind(this);this.disposeWithMe((0,a.merge)(e.tableAdd$,e.tableDelete$,e.tableNameChanged$,e.tableRangeChanged$,e.tableThemeChanged$,e.tableFilterChanged$,e.tableInitStatus$,this._sheetTableThemeUIController.refreshTable$).subscribe(t))}};ue=A([k(1,(0,e.Inject)(e.Injector)),k(2,(0,e.Inject)(r.SheetSkeletonManagerService)),k(3,(0,e.Inject)(n.TableManager)),k(4,(0,e.Inject)(q))],ue);let Z=class extends e.Disposable{constructor(e,t,n){super(),this._sheetInterceptorService=e,this._univerInstanceService=t,this._tableManager=n,this._initSelectionChange()}_initSelectionChange(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:t=>{if(t.id===r.SelectAllCommand.id){let n=(0,c.getSheetCommandTarget)(this._univerInstanceService);if(!n)return{redos:[],undos:[]};let{range:r}=t.params,{unitId:i,subUnitId:a,worksheet:o}=n,s=this._tableManager.getTablesBySubunitId(i,a).find(t=>{let n=t.getRange();return e.Rectangle.contains(n,r)});if(s){let t=s.getRange(),n={...t,startRow:t.startRow+1};return e.Rectangle.equals(t,r)?{undos:[],redos:[]}:e.Rectangle.equals(n,r)?{undos:[],redos:[{id:c.SetSelectionsOperation.id,params:{unitId:i,subUnitId:a,selections:[{range:t,primary:(0,c.getPrimaryForRange)(t,o)}]}}]}:{undos:[],redos:[{id:c.SetSelectionsOperation.id,params:{unitId:i,subUnitId:a,selections:[{range:n,primary:(0,c.getPrimaryForRange)(n,o)}]}}]}}}return{redos:[],undos:[]}}}))}};Z=A([k(0,(0,e.Inject)(c.SheetInterceptorService)),k(1,(0,e.Inject)(e.IUniverInstanceService)),k(2,(0,e.Inject)(n.TableManager))],Z);const de=t=>{let{unitId:r,subUnitId:a,range:s,onCancel:l,onConfirm:m,tableId:h}=t,g=(0,i.useDependency)(n.TableManager),[_,v]=(0,u.useState)(s),[y,b]=(0,u.useState)(``),x=(0,i.useDependency)(e.LocaleService),S=(0,i.useDependency)(e.IUniverInstanceService);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(p.RangeSelector,{maxRangeCount:1,unitId:r,subUnitId:a,initialValue:(0,f.serializeRange)(s),onChange:(t,n)=>{let i=(0,f.serializeRange)(s),o=(0,f.deserializeRangeWithSheet)(n).range,l=(0,c.getSheetCommandTarget)(S,{unitId:r,subUnitId:a});if(!l)return;if(l.worksheet.getMergeData().some(t=>e.Rectangle.intersects(o,t))){b(x.t(`sheets-table.tableRangeWithMergeError`));return}if(g.getTablesBySubunitId(r,a).some(t=>{if(t.getId()===h)return!1;let n=t.getRange();return e.Rectangle.intersects(o,n)})){b(x.t(`sheets-table.tableRangeWithOtherTableError`));return}let{startRow:u,endRow:d}=o;if(u===d){b(x.t(`sheets-table.tableRangeSingleRowError`));return}if(i!==n){if(h){let t=g.getTableById(r,h);if(t){let n=t.getRange();if(e.Rectangle.intersects(o,n)&&n.startRow===o.startRow){v(o),b(``),m({unitId:r,subUnitId:a,range:o});return}else{b(x.t(`sheets-table.updateError`));return}}}v(o),b(``)}},supportAcrossSheet:!1}),y&&(0,d.jsx)(`div`,{className:`univer-mt-1 univer-text-xs univer-text-red-500`,children:y}),(0,d.jsxs)(`div`,{className:`univer-mt-4 univer-flex univer-justify-end`,children:[(0,d.jsx)(o.Button,{onClick:l,children:x.t(`sheets-table.cancel`)}),(0,d.jsx)(o.Button,{variant:`primary`,onClick:()=>{y||m({unitId:r,subUnitId:a,range:_})},className:`univer-ml-2`,children:x.t(`sheets-table.confirm`)})]})]})},fe=t=>{var r,a,l,f,p,m,h,g;let{unitId:_,subUnitId:v,tableId:y}=t,w=(0,i.useDependency)(e.ICommandService),T=(0,i.useDependency)(e.LocaleService),E=(0,i.useDependency)(n.TableManager),D=E.getTableById(_,y),O=(0,i.useDependency)(c.SheetRangeThemeModel),k=(0,i.useDependency)(q),A=(0,i.useObservable)(O.rangeThemeMapChange$),j=(0,i.useObservable)(k.refreshTable$),M=(0,i.useDependency)(e.ErrorService),[,N]=(0,u.useState)(Math.random()),P=(0,i.useObservable)(E.tableThemeChanged$,{theme:D==null?void 0:D.getTableStyleId(),oldTheme:D==null?void 0:D.getTableStyleId(),unitId:_,subUnitId:v,tableId:y}),F=O.getRegisteredRangeThemes().filter(e=>e==null?void 0:e.startsWith(`table-default-`)),I=O.getALLRegisteredTheme(_).filter(e=>e==null?void 0:e.startsWith(b)),ee=D==null?void 0:D.getTableStyleId(),te=I.find(e=>e===ee),L=te||I[0],R=O.getCustomRangeThemeStyle(_,L),z=(r=R==null||(a=R.getHeaderRowStyle())==null||(a=a.bg)==null?void 0:a.rgb)==null?x:r,B=(l=R==null||(f=R.getFirstRowStyle())==null||(f=f.bg)==null?void 0:f.rgb)==null?x:l,V=(p=R==null||(m=R.getSecondRowStyle())==null||(m=m.bg)==null?void 0:m.rgb)==null?x:p,H=(h=R==null||(g=R.getLastRowStyle())==null||(g=g.bg)==null?void 0:g.rgb)==null?x:h,[U,W]=(0,u.useState)(null),G=e=>{w.executeCommand(n.SetSheetTableCommand.id,{unitId:_,tableId:y,theme:e})},K=()=>{if(I.length>=11){M.emit(T.t(`sheets-table.customTooMore`));return}let e=I[I.length-1],t=`${b}1`;e&&(t=`${b}${Number(e.split(`-`)[2])+1}`);let r=new c.RangeThemeStyle(t,{...n.customEmptyThemeWithBorderStyle});w.executeCommand(n.AddTableThemeCommand.id,{unitId:_,tableId:y,themeStyle:r})},J=(e,t)=>{w.executeCommand(c.SetRangeThemeMutation.id,{unitId:_,subUnitId:v,styleName:e,style:t})},Y=e=>{w.executeCommand(n.RemoveTableThemeCommand.id,{unitId:_,tableId:y,themeName:e})};if((0,u.useEffect)(()=>{N(Math.random())},[A,j]),!D)return null;let X=new e.ColorKit(z).isDark(),ne=new e.ColorKit(B).isDark(),re=new e.ColorKit(V).isDark(),ie=new e.ColorKit(H).isDark();return(0,d.jsxs)(`div`,{children:[(0,d.jsx)(`h5`,{children:T.t(`sheets-table.defaultStyle`)}),(0,d.jsx)(`div`,{className:`univer-flex univer-gap-2`,children:F.map(e=>{var t,n,r,i;let a=O.getDefaultRangeThemeStyle(e),s=(a==null||(t=a.getHeaderRowStyle())==null||(t=t.bg)==null?void 0:t.rgb)||`rgb(255, 255, 255)`,c=(a==null||(n=a.getFirstRowStyle())==null||(n=n.bg)==null?void 0:n.rgb)||`rgb(255, 255, 255)`,l=(a==null||(r=a.getSecondRowStyle())==null||(r=r.bg)==null?void 0:r.rgb)||`rgb(255, 255, 255)`,u=(a==null||(i=a.getLastRowStyle())==null||(i=i.bg)==null?void 0:i.rgb)||`rgb(255, 255, 255)`;return(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-h-10 univer-w-8 univer-cursor-pointer univer-border univer-border-solid univer-border-gray-200 univer-p-px [&>div]:univer-box-border [&>div]:univer-h-2.5`,{"univer-border-blue-500":e===P.theme}),onClick:()=>G(e),children:[(0,d.jsx)(`div`,{style:{background:s,border:`${s?S:C}`}}),(0,d.jsx)(`div`,{style:{background:c,border:`${c?S:C}`}}),(0,d.jsx)(`div`,{style:{background:l,border:`${l?S:C}`}}),(0,d.jsx)(`div`,{style:{background:u,border:`${u?S:C}`}})]},e)})}),(0,d.jsx)(`h5`,{children:T.t(`sheets-table.customStyle`)}),(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-w-full univer-rounded-sm`,o.borderClassName),children:[(0,d.jsxs)(`div`,{className:`univer-flex univer-flex-wrap univer-gap-2 univer-p-2`,children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-h-10 univer-w-8 univer-cursor-pointer univer-p-px univer-text-center univer-leading-10`,o.borderClassName),onClick:K,children:`+`}),I.map(e=>{var t,n,r,i;let a=O.getCustomRangeThemeStyle(_,e),s=a==null||(t=a.getHeaderRowStyle())==null||(t=t.bg)==null?void 0:t.rgb,c=a==null||(n=a.getFirstRowStyle())==null||(n=n.bg)==null?void 0:n.rgb,l=a==null||(r=a.getSecondRowStyle())==null||(r=r.bg)==null?void 0:r.rgb,u=a==null||(i=a.getLastRowStyle())==null||(i=i.bg)==null?void 0:i.rgb;return(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-relative univer-h-10 univer-w-8 univer-cursor-pointer univer-border univer-border-solid univer-border-gray-200 univer-p-px`,{"univer-border-blue-500":e===P.theme}),onClick:()=>G(e),onMouseEnter:()=>W(e),onMouseLeave:()=>W(null),children:[(0,d.jsx)(`div`,{className:`univer-box-border univer-h-2.5`,style:{background:s==null?S:s,border:`${s?S:C}`}}),(0,d.jsx)(`div`,{className:`univer-box-border univer-h-2.5`,style:{background:c==null?S:c,border:`${c?S:C}`}}),(0,d.jsx)(`div`,{className:`univer-box-border univer-h-2.5`,style:{background:l==null?S:l,border:`${l?S:C}`}}),(0,d.jsx)(`div`,{className:`univer-box-border univer-h-2.5`,style:{background:u==null?S:u,border:`${u?S:C}`}}),(0,d.jsx)(`div`,{className:`univer-absolute univer-right-[-3px] univer-top-[-3px] univer-size-3 univer-rounded-md univer-bg-gray-200 univer-text-center univer-text-xs univer-leading-[10px]`,style:{display:U===e?`block`:`none`},onClick:t=>{t.stopPropagation(),Y(e)},children:`x`})]},e)})]}),te&&(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`div`,{className:`univer-h-px univer-w-full univer-bg-gray-200`}),(0,d.jsxs)(`div`,{className:`univer-flex univer-flex-col univer-gap-2 univer-p-2`,children:[(0,d.jsxs)(`div`,{className:`univer-flex univer-h-9 univer-gap-2`,children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9`,o.borderClassName,{"univer-text-white":X,"univer-text-gray-900":!X}),style:{background:z},children:T.t(`sheets-table.header`)}),(0,d.jsx)(o.Dropdown,{overlay:(0,d.jsx)(`div`,{className:`univer-p-2`,children:(0,d.jsx)(o.ColorPicker,{value:z,onChange:t=>{let r=(0,n.processStyleWithBorderStyle)(`headerRowStyle`,{bg:{rgb:t},cl:{rgb:new e.ColorKit(t).isDark()?`#fff`:`#000`}});J(D.getTableStyleId(),{headerRowStyle:r})}})}),children:(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1`,o.borderClassName),children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-size-4 univer-rounded-lg univer-bg-gray-400`,o.borderClassName,{"univer-text-white":X,"univer-text-gray-900":!X}),style:{background:z}}),(0,d.jsx)(s.DropdownIcon,{className:`univer-size-2`})]})})]}),(0,d.jsxs)(`div`,{className:`univer-flex univer-h-9 univer-gap-2`,children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9`,o.borderClassName,{"univer-text-white":ne,"univer-text-gray-900":!ne}),style:{background:B},children:T.t(`sheets-table.firstLine`)}),(0,d.jsx)(o.Dropdown,{overlay:(0,d.jsx)(`div`,{className:`univer-p-2`,children:(0,d.jsx)(o.ColorPicker,{value:B,onChange:t=>{J(D.getTableStyleId(),{firstRowStyle:{bg:{rgb:t},cl:{rgb:new e.ColorKit(t).isDark()?`#fff`:`#000`}}})}})}),children:(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1`,o.borderClassName),children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-size-4 univer-rounded-lg univer-bg-gray-400`,o.borderClassName),style:{background:B}}),(0,d.jsx)(s.DropdownIcon,{className:`univer-size-2`})]})})]}),(0,d.jsxs)(`div`,{className:`univer-flex univer-h-9 univer-gap-2`,children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9`,o.borderClassName,{"univer-text-white":re,"univer-text-gray-900":!re}),style:{background:V},children:T.t(`sheets-table.secondLine`)}),(0,d.jsx)(o.Dropdown,{overlay:(0,d.jsx)(`div`,{className:`univer-p-2`,children:(0,d.jsx)(o.ColorPicker,{value:V,onChange:t=>J(D.getTableStyleId(),{secondRowStyle:{bg:{rgb:t},cl:{rgb:new e.ColorKit(t).isDark()?`#fff`:`#000`}}})})}),children:(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1`,o.borderClassName),children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-size-4 univer-rounded-lg univer-bg-gray-400`,o.borderClassName),style:{background:V}}),(0,d.jsx)(s.DropdownIcon,{className:`univer-size-2`})]})})]}),(0,d.jsxs)(`div`,{className:`univer-flex univer-h-9 univer-gap-2`,children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9`,o.borderClassName,{"univer-text-white":ie,"univer-text-gray-900":!ie}),style:{background:H},children:T.t(`sheets-table.footer`)}),(0,d.jsx)(o.Dropdown,{overlay:(0,d.jsx)(`div`,{className:`univer-p-2`,children:(0,d.jsx)(o.ColorPicker,{value:H,onChange:t=>{let r=(0,n.processStyleWithBorderStyle)(`lastRowStyle`,{bg:{rgb:t},cl:{rgb:new e.ColorKit(t).isDark()?`#fff`:`#000`}});J(D.getTableStyleId(),{lastRowStyle:r})}})}),children:(0,d.jsxs)(`div`,{className:(0,o.clsx)(`univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1`,o.borderClassName),children:[(0,d.jsx)(`div`,{className:(0,o.clsx)(`univer-size-4 univer-rounded-lg univer-bg-gray-400`,o.borderClassName),style:{background:H}}),(0,d.jsx)(s.DropdownIcon,{className:`univer-size-2`})]})})]})]})]})]})]})},pe=`sheet.table.context-insert_menu-id`,me=`sheet.table.context-remove_menu-id`;function he(t){return{id:U.id,type:i.MenuItemType.BUTTON,icon:_,tooltip:`sheets-table.title`,title:`sheets-table.title`,hidden$:(0,i.getMenuHiddenObservable)(t,e.UniverInstanceType.UNIVER_SHEET),disabled$:(0,r.getCurrentRangeDisable$)(t,{},!0)}}function ge(e){return{id:pe,type:i.MenuItemType.SUBITEMS,icon:`InsertDoubleIcon`,title:`sheets-table.insert.main`,hidden$:Se(e)}}function _e(e){return{id:me,type:i.MenuItemType.SUBITEMS,icon:`ReduceDoubleIcon`,title:`sheets-table.remove.main`,hidden$:Se(e)}}function ve(e){return{id:n.SheetTableInsertRowCommand.id,type:i.MenuItemType.BUTTON,title:`sheets-table.insert.row`,hidden$:Ce(e)}}function ye(e){return{id:n.SheetTableInsertColCommand.id,title:`sheets-table.insert.col`,type:i.MenuItemType.BUTTON}}function be(e){return{id:n.SheetTableRemoveRowCommand.id,type:i.MenuItemType.BUTTON,title:`sheets-table.remove.row`,hidden$:Ce(e)}}function xe(e){return{id:n.SheetTableRemoveColCommand.id,title:`sheets-table.remove.col`,type:i.MenuItemType.BUTTON}}function Se(t){let r=t.get(c.SheetsSelectionsService);return t.get(e.IUniverInstanceService).getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>e?e.activeSheet$.pipe((0,a.switchMap)(i=>i?r.selectionMoveEnd$.pipe((0,a.switchMap)(r=>{if(!r.length||r.length>1)return(0,a.of)(!0);let o=r[0].range;return(0,a.of)(!t.get(n.SheetsTableController).getContainerTableWithRange(e.getUnitId(),i.getSheetId(),o))})):(0,a.of)(!0))):(0,a.of)(!0)))}function Ce(t){let r=t.get(c.SheetsSelectionsService);return t.get(e.IUniverInstanceService).getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>e?e.activeSheet$.pipe((0,a.switchMap)(i=>i?r.selectionMoveEnd$.pipe((0,a.switchMap)(r=>{if(!r.length||r.length>1)return(0,a.of)(!0);let o=r[0].range,s=t.get(n.SheetsTableController).getContainerTableWithRange(e.getUnitId(),i.getSheetId(),o);if(!s)return(0,a.of)(!0);let c=s.getRange();return o.startRow===c.startRow?(0,a.of)(!0):(0,a.of)(!1)})):(0,a.of)(!0))):(0,a.of)(!0)))}const we={[i.RibbonDataGroup.ORGANIZATION]:{[U.id]:{order:0,menuItemFactory:he}},[i.ContextMenuPosition.MAIN_AREA]:{[i.ContextMenuGroup.LAYOUT]:{[pe]:{order:5,menuItemFactory:ge,[n.SheetTableInsertRowCommand.id]:{order:1,menuItemFactory:ve},[n.SheetTableInsertColCommand.id]:{order:2,menuItemFactory:ye}},[me]:{order:6,menuItemFactory:_e,[n.SheetTableRemoveRowCommand.id]:{order:1,menuItemFactory:be},[n.SheetTableRemoveColCommand.id]:{order:2,menuItemFactory:xe}}}}};let Q=class extends e.Disposable{constructor(e,t){super(),this._componentManager=e,this._menuManagerService=t,this._initComponents(),this._initMenu()}_initComponents(){[[_,s.TableIcon],[v,de],[y,fe]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}_initMenu(){this._menuManagerService.mergeMenu(we)}};Q=A([k(0,(0,e.Inject)(i.ComponentManager)),k(1,(0,e.Inject)(i.IMenuManagerService))],Q);let $=class extends e.Plugin{constructor(t=K,n,r,i,a){super(),this._config=t,this._injector=n,this._commandService=r,this._configService=i,this._renderManagerService=a;let{menu:o,...s}=(0,e.merge)({},K,this._config);o&&this._configService.setConfig(`menu`,o,{merge:!0}),this._configService.setConfig(G,s),this._initRegisterCommand()}onStarting(){(0,e.registerDependencies)(this._injector,[[V],[j],[Q],[q],[Z]])}onReady(){(0,e.touchDependencies)(this._injector,[[V],[j],[Q],[q],[Z]])}onRendered(){this._registerRenderModules()}_registerRenderModules(){let t=[[le],[ue]];this._config.hideAnchor!==!0&&t.push([Y]),t.forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(e.UniverInstanceType.UNIVER_SHEET,t))})}_initRegisterCommand(){[H,U].forEach(e=>this._commandService.registerCommand(e))}};O($,`pluginName`,`SHEET_TABLE_UI_PLUGIN`),O($,`packageName`,m),O($,`version`,h),O($,`type`,e.UniverInstanceType.UNIVER_SHEET),$=A([(0,e.DependentOn)(n.UniverSheetsTablePlugin),k(1,(0,e.Inject)(e.Injector)),k(2,(0,e.Inject)(e.ICommandService)),k(3,e.IConfigService),k(4,t.IRenderManagerService)],$),Object.defineProperty(exports,`UniverSheetsTableUIPlugin`,{enumerable:!0,get:function(){return $}});
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
4
|
+
let _univerjs_sheets_table = require("@univerjs/sheets-table");
|
|
5
|
+
let _univerjs_sheets_ui = require("@univerjs/sheets-ui");
|
|
6
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
7
|
+
let rxjs = require("rxjs");
|
|
8
|
+
let _univerjs_design = require("@univerjs/design");
|
|
9
|
+
let _univerjs_icons = require("@univerjs/icons");
|
|
10
|
+
let _univerjs_sheets = require("@univerjs/sheets");
|
|
11
|
+
let _univerjs_sheets_sort = require("@univerjs/sheets-sort");
|
|
12
|
+
let react = require("react");
|
|
13
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
14
|
+
let _univerjs_engine_formula = require("@univerjs/engine-formula");
|
|
15
|
+
let _univerjs_sheets_formula_ui = require("@univerjs/sheets-formula-ui");
|
|
16
|
+
|
|
17
|
+
//#region package.json
|
|
18
|
+
var name = "@univerjs/sheets-table-ui";
|
|
19
|
+
var version = "0.20.1-insiders.20260418-3a69981";
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/const.ts
|
|
23
|
+
/**
|
|
24
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
25
|
+
*
|
|
26
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
27
|
+
* you may not use this file except in compliance with the License.
|
|
28
|
+
* You may obtain a copy of the License at
|
|
29
|
+
*
|
|
30
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
31
|
+
*
|
|
32
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
33
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
34
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
35
|
+
* See the License for the specific language governing permissions and
|
|
36
|
+
* limitations under the License.
|
|
37
|
+
*/
|
|
38
|
+
const PLUGIN_NAME = "SHEET_TABLE_UI_PLUGIN";
|
|
39
|
+
const SHEETS_TABLE_FILTER_PANEL_OPENED_KEY = "SHEETS_TABLE_FILTER_PANEL_OPENED_KEY";
|
|
40
|
+
const UNIVER_SHEET_TABLE_FILTER_PANEL_ID = "UNIVER_SHEET_Table_FILTER_PANEL_ID";
|
|
41
|
+
const TABLE_TOOLBAR_BUTTON = "TABLE_TOOLBAR_BUTTON";
|
|
42
|
+
const TABLE_SELECTOR_DIALOG = "TABLE_SELECTOR_DIALOG";
|
|
43
|
+
const SHEET_TABLE_THEME_PANEL_ID = "SHEET_TABLE_THEME_PANEL_ID";
|
|
44
|
+
const SHEET_TABLE_THEME_PANEL = "SHEET_TABLE_THEME_PANEL";
|
|
45
|
+
const TABLE_CUSTOM_NAME_PREFIX = "table-custom-";
|
|
46
|
+
const TABLE_DEFAULT_NAME_PREFIX = "table-default-";
|
|
47
|
+
const TABLE_DEFAULT_BG_COLOR = "rgb(255, 255, 255)";
|
|
48
|
+
const TABLE_BORDER_NONE = "none";
|
|
49
|
+
const TABLE_BORDER_DEFAULT = "1px solid rgb(var(--grey-200))";
|
|
50
|
+
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/types.ts
|
|
53
|
+
/**
|
|
54
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
55
|
+
*
|
|
56
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
57
|
+
* you may not use this file except in compliance with the License.
|
|
58
|
+
* You may obtain a copy of the License at
|
|
59
|
+
*
|
|
60
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
61
|
+
*
|
|
62
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
63
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
64
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
65
|
+
* See the License for the specific language governing permissions and
|
|
66
|
+
* limitations under the License.
|
|
67
|
+
*/
|
|
68
|
+
let FilterByEnum = /* @__PURE__ */ function(FilterByEnum) {
|
|
69
|
+
FilterByEnum["Items"] = "items";
|
|
70
|
+
FilterByEnum["Condition"] = "condition";
|
|
71
|
+
return FilterByEnum;
|
|
72
|
+
}({});
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
76
|
+
function _typeof(o) {
|
|
77
|
+
"@babel/helpers - typeof";
|
|
78
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
79
|
+
return typeof o;
|
|
80
|
+
} : function(o) {
|
|
81
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
82
|
+
}, _typeof(o);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
87
|
+
function toPrimitive(t, r) {
|
|
88
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
89
|
+
var e = t[Symbol.toPrimitive];
|
|
90
|
+
if (void 0 !== e) {
|
|
91
|
+
var i = e.call(t, r || "default");
|
|
92
|
+
if ("object" != _typeof(i)) return i;
|
|
93
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
94
|
+
}
|
|
95
|
+
return ("string" === r ? String : Number)(t);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
100
|
+
function toPropertyKey(t) {
|
|
101
|
+
var i = toPrimitive(t, "string");
|
|
102
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
107
|
+
function _defineProperty(e, r, t) {
|
|
108
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
109
|
+
value: t,
|
|
110
|
+
enumerable: !0,
|
|
111
|
+
configurable: !0,
|
|
112
|
+
writable: !0
|
|
113
|
+
}) : e[r] = t, e;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
118
|
+
function __decorateParam(paramIndex, decorator) {
|
|
119
|
+
return function(target, key) {
|
|
120
|
+
decorator(target, key, paramIndex);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
//#endregion
|
|
125
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
126
|
+
function __decorate(decorators, target, key, desc) {
|
|
127
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
128
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
129
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
130
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
//#region src/services/sheets-table-ui-service.ts
|
|
135
|
+
let SheetsTableUiService = class SheetsTableUiService extends _univerjs_core.Disposable {
|
|
136
|
+
constructor(_tableManager, _sheetTableService, _univerInstanceService, _commandService, _localeService) {
|
|
137
|
+
super();
|
|
138
|
+
this._tableManager = _tableManager;
|
|
139
|
+
this._sheetTableService = _sheetTableService;
|
|
140
|
+
this._univerInstanceService = _univerInstanceService;
|
|
141
|
+
this._commandService = _commandService;
|
|
142
|
+
this._localeService = _localeService;
|
|
143
|
+
_defineProperty(this, "_itemsCache", /* @__PURE__ */ new Map());
|
|
144
|
+
this._registerTableFilterChangeEvent();
|
|
145
|
+
}
|
|
146
|
+
_registerTableFilterChangeEvent() {
|
|
147
|
+
this._commandService.onCommandExecuted((command) => {
|
|
148
|
+
if (command.id === _univerjs_sheets.SetRangeValuesMutation.id) {
|
|
149
|
+
const { unitId, subUnitId, cellValue } = command.params;
|
|
150
|
+
const tables = this._tableManager.getTablesBySubunitId(unitId, subUnitId);
|
|
151
|
+
if (!tables.length) return;
|
|
152
|
+
new _univerjs_core.ObjectMatrix(cellValue).forValue((row, col, _value) => {
|
|
153
|
+
const cellRange = (0, _univerjs_core.cellToRange)(row, col);
|
|
154
|
+
const overlapTable = tables.find((table) => {
|
|
155
|
+
const tableRange = table.getTableFilterRange();
|
|
156
|
+
return _univerjs_core.Rectangle.intersects(tableRange, cellRange);
|
|
157
|
+
});
|
|
158
|
+
if (overlapTable) {
|
|
159
|
+
const colIndex = col - overlapTable.getRange().startColumn;
|
|
160
|
+
this._itemsCache.delete(overlapTable.getId() + colIndex);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
} else if (command.id === _univerjs_sheets_table.SetSheetTableFilterCommand.id) {
|
|
164
|
+
const { unitId, tableId } = command.params;
|
|
165
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
166
|
+
if (!table) return;
|
|
167
|
+
const subUnitId = table.getSubunitId();
|
|
168
|
+
this._tableManager.getTablesBySubunitId(unitId, subUnitId).forEach((table) => {
|
|
169
|
+
const range = table.getRange();
|
|
170
|
+
for (let i = range.startColumn; i <= range.endColumn; i++) this._itemsCache.delete(table.getId() + i);
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
getTableFilterPanelInitProps(unitId, subUnitId, tableId, column) {
|
|
176
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
177
|
+
const tableRange = table.getRange();
|
|
178
|
+
const tableFilter = table.getTableFilterColumn(column - tableRange.startColumn);
|
|
179
|
+
return {
|
|
180
|
+
unitId,
|
|
181
|
+
subUnitId,
|
|
182
|
+
tableFilter,
|
|
183
|
+
currentFilterBy: (0, _univerjs_sheets_table.isConditionFilter)(tableFilter) ? FilterByEnum.Condition : FilterByEnum.Items,
|
|
184
|
+
tableId,
|
|
185
|
+
columnIndex: column - tableRange.startColumn
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
getTableFilterCheckedItems(unitId, tableId, columnIndex) {
|
|
189
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
190
|
+
const checkedItems = [];
|
|
191
|
+
if (table) {
|
|
192
|
+
const filter = table.getTableFilterColumn(columnIndex);
|
|
193
|
+
if (filter && (0, _univerjs_sheets_table.isManualTableFilter)(filter)) checkedItems.push(...filter.values);
|
|
194
|
+
}
|
|
195
|
+
return checkedItems;
|
|
196
|
+
}
|
|
197
|
+
setTableFilter(unitId, tableId, columnIndex, tableFilter) {
|
|
198
|
+
if (!this._tableManager.getTable(unitId, tableId)) return;
|
|
199
|
+
const setTableFilterParams = {
|
|
200
|
+
unitId,
|
|
201
|
+
tableId,
|
|
202
|
+
column: columnIndex,
|
|
203
|
+
tableFilter
|
|
204
|
+
};
|
|
205
|
+
this._commandService.executeCommand(_univerjs_sheets_table.SetSheetTableFilterCommand.id, setTableFilterParams);
|
|
206
|
+
}
|
|
207
|
+
getTableFilterItems(unitId, subUnitId, tableId, columnIndex) {
|
|
208
|
+
var _this$_univerInstance;
|
|
209
|
+
if (this._itemsCache.has(tableId + columnIndex)) return this._itemsCache.get(tableId + columnIndex) || {
|
|
210
|
+
data: [],
|
|
211
|
+
itemsCountMap: /* @__PURE__ */ new Map(),
|
|
212
|
+
allItemsCount: 0
|
|
213
|
+
};
|
|
214
|
+
const table = this._tableManager.getTable(unitId, tableId);
|
|
215
|
+
if (!table) return {
|
|
216
|
+
data: [],
|
|
217
|
+
itemsCountMap: /* @__PURE__ */ new Map(),
|
|
218
|
+
allItemsCount: 0
|
|
219
|
+
};
|
|
220
|
+
const { startRow, endRow, startColumn } = table.getTableFilterRange();
|
|
221
|
+
const column = startColumn + columnIndex;
|
|
222
|
+
const worksheet = (_this$_univerInstance = this._univerInstanceService.getUnit(unitId)) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetBySheetId(subUnitId);
|
|
223
|
+
if (!worksheet) return {
|
|
224
|
+
data: [],
|
|
225
|
+
itemsCountMap: /* @__PURE__ */ new Map(),
|
|
226
|
+
allItemsCount: 0
|
|
227
|
+
};
|
|
228
|
+
const data = [];
|
|
229
|
+
const map = /* @__PURE__ */ new Map();
|
|
230
|
+
let allItemsCount = 0;
|
|
231
|
+
for (let row = startRow; row <= endRow; row++) {
|
|
232
|
+
if (worksheet.isRowFiltered(row)) continue;
|
|
233
|
+
let stringItem = this._sheetTableService.getCellValueWithConditionType(worksheet, row, column);
|
|
234
|
+
if (stringItem === void 0) stringItem = this._localeService.t("sheets-table.condition.empty");
|
|
235
|
+
if (!map.has(stringItem)) data.push({
|
|
236
|
+
title: stringItem,
|
|
237
|
+
key: `${column}_${row}`,
|
|
238
|
+
leaf: true
|
|
239
|
+
});
|
|
240
|
+
allItemsCount++;
|
|
241
|
+
map.set(stringItem, (map.get(stringItem) || 0) + 1);
|
|
242
|
+
}
|
|
243
|
+
this._itemsCache.set(tableId + columnIndex, {
|
|
244
|
+
data,
|
|
245
|
+
itemsCountMap: map,
|
|
246
|
+
allItemsCount
|
|
247
|
+
});
|
|
248
|
+
return {
|
|
249
|
+
data,
|
|
250
|
+
itemsCountMap: map,
|
|
251
|
+
allItemsCount
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
SheetsTableUiService = __decorate([
|
|
256
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets_table.TableManager)),
|
|
257
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_sheets_table.SheetTableService)),
|
|
258
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
|
|
259
|
+
__decorateParam(3, _univerjs_core.ICommandService),
|
|
260
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
|
|
261
|
+
], SheetsTableUiService);
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region src/views/components/type.ts
|
|
265
|
+
let ConditionSubComponentEnum = /* @__PURE__ */ function(ConditionSubComponentEnum) {
|
|
266
|
+
ConditionSubComponentEnum["DatePicker"] = "DatePicker";
|
|
267
|
+
ConditionSubComponentEnum["DateRange"] = "DateRange";
|
|
268
|
+
ConditionSubComponentEnum["Input"] = "Input";
|
|
269
|
+
ConditionSubComponentEnum["Inputs"] = "Inputs";
|
|
270
|
+
ConditionSubComponentEnum["Select"] = "Select";
|
|
271
|
+
ConditionSubComponentEnum["None"] = "None";
|
|
272
|
+
return ConditionSubComponentEnum;
|
|
273
|
+
}({});
|
|
274
|
+
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/views/components/util.ts
|
|
277
|
+
function getCascaderListOptions(injector) {
|
|
278
|
+
const t = injector.get(_univerjs_core.LocaleService).t;
|
|
279
|
+
return [
|
|
280
|
+
{
|
|
281
|
+
value: _univerjs_sheets_table.TableConditionTypeEnum.String,
|
|
282
|
+
label: t(`sheets-table.condition.${_univerjs_sheets_table.TableConditionTypeEnum.String}`),
|
|
283
|
+
children: [
|
|
284
|
+
{
|
|
285
|
+
value: _univerjs_sheets_table.TableStringCompareTypeEnum.Equal,
|
|
286
|
+
label: t(`sheets-table.string.compare.${_univerjs_sheets_table.TableStringCompareTypeEnum.Equal}`)
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
value: _univerjs_sheets_table.TableStringCompareTypeEnum.NotEqual,
|
|
290
|
+
label: t(`sheets-table.string.compare.${_univerjs_sheets_table.TableStringCompareTypeEnum.NotEqual}`)
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
value: _univerjs_sheets_table.TableStringCompareTypeEnum.Contains,
|
|
294
|
+
label: t(`sheets-table.string.compare.${_univerjs_sheets_table.TableStringCompareTypeEnum.Contains}`)
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
value: _univerjs_sheets_table.TableStringCompareTypeEnum.NotContains,
|
|
298
|
+
label: t(`sheets-table.string.compare.${_univerjs_sheets_table.TableStringCompareTypeEnum.NotContains}`)
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
value: _univerjs_sheets_table.TableStringCompareTypeEnum.StartsWith,
|
|
302
|
+
label: t(`sheets-table.string.compare.${_univerjs_sheets_table.TableStringCompareTypeEnum.StartsWith}`)
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
value: _univerjs_sheets_table.TableStringCompareTypeEnum.EndsWith,
|
|
306
|
+
label: t(`sheets-table.string.compare.${_univerjs_sheets_table.TableStringCompareTypeEnum.EndsWith}`)
|
|
307
|
+
}
|
|
308
|
+
]
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
value: _univerjs_sheets_table.TableConditionTypeEnum.Number,
|
|
312
|
+
label: t(`sheets-table.condition.${_univerjs_sheets_table.TableConditionTypeEnum.Number}`),
|
|
313
|
+
children: [
|
|
314
|
+
{
|
|
315
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.Equal,
|
|
316
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.Equal}`)
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.NotEqual,
|
|
320
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.NotEqual}`)
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.GreaterThan,
|
|
324
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.GreaterThan}`)
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.GreaterThanOrEqual,
|
|
328
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.GreaterThanOrEqual}`)
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.LessThan,
|
|
332
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.LessThan}`)
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.LessThanOrEqual,
|
|
336
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.LessThanOrEqual}`)
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.Between,
|
|
340
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.Between}`)
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.NotBetween,
|
|
344
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.NotBetween}`)
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.Above,
|
|
348
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.Above}`)
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
value: _univerjs_sheets_table.TableNumberCompareTypeEnum.Below,
|
|
352
|
+
label: t(`sheets-table.number.compare.${_univerjs_sheets_table.TableNumberCompareTypeEnum.Below}`)
|
|
353
|
+
}
|
|
354
|
+
]
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
value: _univerjs_sheets_table.TableConditionTypeEnum.Date,
|
|
358
|
+
label: t(`sheets-table.condition.${_univerjs_sheets_table.TableConditionTypeEnum.Date}`),
|
|
359
|
+
children: [
|
|
360
|
+
{
|
|
361
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Equal,
|
|
362
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Equal}`)
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.NotEqual,
|
|
366
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.NotEqual}`)
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.After,
|
|
370
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.After}`)
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.AfterOrEqual,
|
|
374
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.AfterOrEqual}`)
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Before,
|
|
378
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Before}`)
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.BeforeOrEqual,
|
|
382
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.BeforeOrEqual}`)
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Between,
|
|
386
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Between}`)
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.NotBetween,
|
|
390
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.NotBetween}`)
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Today,
|
|
394
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Today}`)
|
|
395
|
+
},
|
|
396
|
+
{
|
|
397
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Yesterday,
|
|
398
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Yesterday}`)
|
|
399
|
+
},
|
|
400
|
+
{
|
|
401
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Tomorrow,
|
|
402
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Tomorrow}`)
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.ThisWeek,
|
|
406
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.ThisWeek}`)
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.LastWeek,
|
|
410
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.LastWeek}`)
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.NextWeek,
|
|
414
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.NextWeek}`)
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.ThisMonth,
|
|
418
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.ThisMonth}`)
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.LastMonth,
|
|
422
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.LastMonth}`)
|
|
423
|
+
},
|
|
424
|
+
{
|
|
425
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.NextMonth,
|
|
426
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.NextMonth}`)
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.ThisYear,
|
|
430
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.ThisYear}`)
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.LastYear,
|
|
434
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.LastYear}`)
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.NextYear,
|
|
438
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.NextYear}`)
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Quarter,
|
|
442
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Quarter}`)
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Month,
|
|
446
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Month}`)
|
|
447
|
+
}
|
|
448
|
+
]
|
|
449
|
+
}
|
|
450
|
+
];
|
|
451
|
+
}
|
|
452
|
+
function getConditionDateSelect(injector, dateType) {
|
|
453
|
+
if (!dateType) return [];
|
|
454
|
+
const t = injector.get(_univerjs_core.LocaleService).t;
|
|
455
|
+
switch (dateType) {
|
|
456
|
+
case _univerjs_sheets_table.TableDateCompareTypeEnum.Quarter: return [
|
|
457
|
+
{
|
|
458
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Q1,
|
|
459
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Q1}`)
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Q2,
|
|
463
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Q2}`)
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Q3,
|
|
467
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Q3}`)
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.Q4,
|
|
471
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.Q4}`)
|
|
472
|
+
}
|
|
473
|
+
];
|
|
474
|
+
case _univerjs_sheets_table.TableDateCompareTypeEnum.Month: return [
|
|
475
|
+
{
|
|
476
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M1,
|
|
477
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M1}`)
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M2,
|
|
481
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M2}`)
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M3,
|
|
485
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M3}`)
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M4,
|
|
489
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M4}`)
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M5,
|
|
493
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M5}`)
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M6,
|
|
497
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M6}`)
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M7,
|
|
501
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M7}`)
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M8,
|
|
505
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M8}`)
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M9,
|
|
509
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M9}`)
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M10,
|
|
513
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M10}`)
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M11,
|
|
517
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M11}`)
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
value: _univerjs_sheets_table.TableDateCompareTypeEnum.M12,
|
|
521
|
+
label: t(`sheets-table.date.compare.${_univerjs_sheets_table.TableDateCompareTypeEnum.M12}`)
|
|
522
|
+
}
|
|
523
|
+
];
|
|
524
|
+
default: return [];
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
const datePickerSet = new Set([
|
|
528
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.Equal,
|
|
529
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.NotEqual,
|
|
530
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.After,
|
|
531
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.AfterOrEqual,
|
|
532
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.Before,
|
|
533
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.BeforeOrEqual
|
|
534
|
+
]);
|
|
535
|
+
function getSubComponentType(type, compare) {
|
|
536
|
+
if (!compare) return ConditionSubComponentEnum.None;
|
|
537
|
+
if (type === _univerjs_sheets_table.TableConditionTypeEnum.String) return ConditionSubComponentEnum.Input;
|
|
538
|
+
else if (type === _univerjs_sheets_table.TableConditionTypeEnum.Number) if (compare === _univerjs_sheets_table.TableNumberCompareTypeEnum.Between || compare === _univerjs_sheets_table.TableNumberCompareTypeEnum.NotBetween) return ConditionSubComponentEnum.Inputs;
|
|
539
|
+
else return ConditionSubComponentEnum.Input;
|
|
540
|
+
else if (type === _univerjs_sheets_table.TableConditionTypeEnum.Date) {
|
|
541
|
+
if (compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Between || compare === _univerjs_sheets_table.TableDateCompareTypeEnum.NotBetween) return ConditionSubComponentEnum.DateRange;
|
|
542
|
+
else if (compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Quarter || compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Month) return ConditionSubComponentEnum.Select;
|
|
543
|
+
else if (datePickerSet.has(compare)) return ConditionSubComponentEnum.DatePicker;
|
|
544
|
+
return ConditionSubComponentEnum.None;
|
|
545
|
+
}
|
|
546
|
+
return ConditionSubComponentEnum.None;
|
|
547
|
+
}
|
|
548
|
+
function getInitConditionInfo(tableFilter) {
|
|
549
|
+
if (!tableFilter || tableFilter.filterType !== "condition") return {
|
|
550
|
+
type: _univerjs_sheets_table.TableConditionTypeEnum.String,
|
|
551
|
+
compareType: _univerjs_sheets_table.TableStringCompareTypeEnum.Equal,
|
|
552
|
+
info: {}
|
|
553
|
+
};
|
|
554
|
+
const filterInfo = tableFilter.filterInfo;
|
|
555
|
+
const { conditionType, compareType } = filterInfo;
|
|
556
|
+
if (conditionType === _univerjs_sheets_table.TableConditionTypeEnum.Date) if (compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.Between || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.NotBetween) {
|
|
557
|
+
let dateRange;
|
|
558
|
+
if (Array.isArray(filterInfo.expectedValue)) dateRange = filterInfo.expectedValue.map((i) => typeof i === "string" ? new Date(i) : i);
|
|
559
|
+
return {
|
|
560
|
+
type: conditionType,
|
|
561
|
+
compare: compareType,
|
|
562
|
+
info: { dateRange }
|
|
563
|
+
};
|
|
564
|
+
} else if (compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.Today || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.Yesterday || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.Tomorrow || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.ThisWeek || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.LastWeek || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.NextWeek || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.ThisMonth || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.LastMonth || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.NextMonth || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.ThisYear || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.LastYear || compareType === _univerjs_sheets_table.TableDateCompareTypeEnum.NextYear) return {
|
|
565
|
+
type: conditionType,
|
|
566
|
+
compare: compareType,
|
|
567
|
+
info: {}
|
|
568
|
+
};
|
|
569
|
+
else if (datePickerSet.has(compareType)) {
|
|
570
|
+
let date;
|
|
571
|
+
if (typeof filterInfo.expectedValue === "string") date = new Date(filterInfo.expectedValue);
|
|
572
|
+
else if (Array.isArray(filterInfo.expectedValue)) {
|
|
573
|
+
for (let i = 0; i < filterInfo.expectedValue.length; i++) if (typeof filterInfo.expectedValue[i] === "string") filterInfo.expectedValue[i] = new Date(filterInfo.expectedValue[i]);
|
|
574
|
+
}
|
|
575
|
+
return {
|
|
576
|
+
type: conditionType,
|
|
577
|
+
compare: compareType,
|
|
578
|
+
info: { date }
|
|
579
|
+
};
|
|
580
|
+
} else if (new Set([
|
|
581
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.Q1,
|
|
582
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.Q2,
|
|
583
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.Q3,
|
|
584
|
+
_univerjs_sheets_table.TableDateCompareTypeEnum.Q4
|
|
585
|
+
]).has(compareType)) return {
|
|
586
|
+
type: conditionType,
|
|
587
|
+
compare: _univerjs_sheets_table.TableDateCompareTypeEnum.Quarter,
|
|
588
|
+
info: { dateSelect: filterInfo.compareType }
|
|
589
|
+
};
|
|
590
|
+
else return {
|
|
591
|
+
type: conditionType,
|
|
592
|
+
compare: _univerjs_sheets_table.TableDateCompareTypeEnum.Month,
|
|
593
|
+
info: { dateSelect: filterInfo.compareType }
|
|
594
|
+
};
|
|
595
|
+
else if (conditionType === _univerjs_sheets_table.TableConditionTypeEnum.Number) if (compareType === _univerjs_sheets_table.TableNumberCompareTypeEnum.Between || compareType === _univerjs_sheets_table.TableNumberCompareTypeEnum.NotBetween) return {
|
|
596
|
+
type: conditionType,
|
|
597
|
+
compare: compareType,
|
|
598
|
+
info: { numberRange: filterInfo.expectedValue }
|
|
599
|
+
};
|
|
600
|
+
else return {
|
|
601
|
+
type: conditionType,
|
|
602
|
+
compare: compareType,
|
|
603
|
+
info: { number: filterInfo.expectedValue }
|
|
604
|
+
};
|
|
605
|
+
else if (conditionType === _univerjs_sheets_table.TableConditionTypeEnum.String) return {
|
|
606
|
+
type: conditionType,
|
|
607
|
+
compare: compareType,
|
|
608
|
+
info: { string: filterInfo.expectedValue }
|
|
609
|
+
};
|
|
610
|
+
return {
|
|
611
|
+
type: _univerjs_sheets_table.TableConditionTypeEnum.String,
|
|
612
|
+
compare: _univerjs_sheets_table.TableStringCompareTypeEnum.Equal,
|
|
613
|
+
info: {}
|
|
614
|
+
};
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
//#endregion
|
|
618
|
+
//#region src/views/components/SheetTableConditionPanel.tsx
|
|
619
|
+
const SheetTableConditionPanel = (props) => {
|
|
620
|
+
var _conditionInfo$info$d, _conditionInfo$info$d2, _conditionInfo$info$d3, _conditionInfo$info$d4, _conditionInfo$info$d5, _conditionInfo$info$n, _conditionInfo$info$n3, _conditionInfo$info$d6;
|
|
621
|
+
const { conditionInfo, onChange } = props;
|
|
622
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
623
|
+
const [conditionVisible, setConditionVisible] = (0, react.useState)(false);
|
|
624
|
+
const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
|
|
625
|
+
const cascaderOptions = getCascaderListOptions(injector);
|
|
626
|
+
const handleConditionInfo = (info, type, compare) => {
|
|
627
|
+
onChange({
|
|
628
|
+
type: type !== null && type !== void 0 ? type : conditionInfo.type,
|
|
629
|
+
compare: compare !== null && compare !== void 0 ? compare : conditionInfo.compare,
|
|
630
|
+
info
|
|
631
|
+
});
|
|
632
|
+
};
|
|
633
|
+
const handleChange = (value) => {
|
|
634
|
+
var _ref;
|
|
635
|
+
const type = value[0];
|
|
636
|
+
const compare = value[1];
|
|
637
|
+
if (compare) setConditionVisible(false);
|
|
638
|
+
const info = {};
|
|
639
|
+
if (type === _univerjs_sheets_table.TableConditionTypeEnum.Date) if (compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Quarter) info.dateSelect = _univerjs_sheets_table.TableDateCompareTypeEnum.Q1;
|
|
640
|
+
else if (compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Month) info.dateSelect = _univerjs_sheets_table.TableDateCompareTypeEnum.M1;
|
|
641
|
+
else if (datePickerSet.has(compare)) info.date = /* @__PURE__ */ new Date();
|
|
642
|
+
else info.dateRange = [/* @__PURE__ */ new Date(), /* @__PURE__ */ new Date()];
|
|
643
|
+
else if (type === _univerjs_sheets_table.TableConditionTypeEnum.Number) info.number = 0;
|
|
644
|
+
else if (type === _univerjs_sheets_table.TableConditionTypeEnum.String) info.string = "";
|
|
645
|
+
handleConditionInfo(info, value[0], (_ref = value[1]) !== null && _ref !== void 0 ? _ref : _univerjs_sheets_table.TableStringCompareTypeEnum.Equal);
|
|
646
|
+
};
|
|
647
|
+
const subComponentType = getSubComponentType(conditionInfo.type, conditionInfo.compare);
|
|
648
|
+
let selectType = "";
|
|
649
|
+
if (conditionInfo.compare) selectType = `${localeService.t(`sheets-table.condition.${conditionInfo.type}`)} - ${localeService.t(`sheets-table.${conditionInfo.type}.compare.${conditionInfo.compare}`)}`;
|
|
650
|
+
else selectType = localeService.t(`sheets-table.condition.${conditionInfo.type}`);
|
|
651
|
+
const conditionDateOptions = getConditionDateSelect(injector, conditionInfo.compare);
|
|
652
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
653
|
+
align: "start",
|
|
654
|
+
open: conditionVisible,
|
|
655
|
+
onOpenChange: setConditionVisible,
|
|
656
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.CascaderList, {
|
|
657
|
+
value: [conditionInfo.type, conditionInfo.compare],
|
|
658
|
+
options: cascaderOptions,
|
|
659
|
+
onChange: handleChange,
|
|
660
|
+
contentClassName: "univer-flex-1",
|
|
661
|
+
wrapperClassName: "!univer-h-[150px]"
|
|
662
|
+
}),
|
|
663
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
664
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-flex univer-h-8 univer-w-full univer-items-center univer-justify-between univer-rounded-md univer-bg-white univer-px-2 univer-text-sm univer-transition-colors univer-duration-200 hover:univer-border-primary-600 focus:univer-border-primary-600 focus:univer-outline-none focus:univer-ring-2 dark:!univer-bg-gray-700 dark:!univer-text-white", _univerjs_design.borderClassName),
|
|
665
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: selectType }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {})]
|
|
666
|
+
})
|
|
667
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
668
|
+
className: "univer-mt-3 univer-w-full",
|
|
669
|
+
children: [
|
|
670
|
+
subComponentType === ConditionSubComponentEnum.Input && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: conditionInfo.type === _univerjs_sheets_table.TableConditionTypeEnum.String ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
671
|
+
className: "univer-w-full",
|
|
672
|
+
placeholder: "请输入",
|
|
673
|
+
value: conditionInfo.info.string,
|
|
674
|
+
onChange: (v) => handleConditionInfo({ string: v })
|
|
675
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
676
|
+
className: "univer-h-7 univer-w-full",
|
|
677
|
+
value: conditionInfo.info.number,
|
|
678
|
+
controls: false,
|
|
679
|
+
onChange: (v) => {
|
|
680
|
+
if (v !== null) handleConditionInfo({ number: v });
|
|
681
|
+
}
|
|
682
|
+
}) }),
|
|
683
|
+
!!(subComponentType === ConditionSubComponentEnum.DatePicker) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
684
|
+
id: "univer-table-date-picker-wrapper",
|
|
685
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DatePicker, {
|
|
686
|
+
className: "univer-w-full",
|
|
687
|
+
value: (_conditionInfo$info$d = conditionInfo.info.date) !== null && _conditionInfo$info$d !== void 0 ? _conditionInfo$info$d : /* @__PURE__ */ new Date(),
|
|
688
|
+
onValueChange: (v) => handleConditionInfo({ date: v })
|
|
689
|
+
})
|
|
690
|
+
}),
|
|
691
|
+
!!(subComponentType === ConditionSubComponentEnum.DateRange) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
692
|
+
id: "univer-table-date-range-wrapper",
|
|
693
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DateRangePicker, {
|
|
694
|
+
className: "univer-w-full",
|
|
695
|
+
value: [(_conditionInfo$info$d2 = (_conditionInfo$info$d3 = conditionInfo.info.dateRange) === null || _conditionInfo$info$d3 === void 0 ? void 0 : _conditionInfo$info$d3[0]) !== null && _conditionInfo$info$d2 !== void 0 ? _conditionInfo$info$d2 : /* @__PURE__ */ new Date(), (_conditionInfo$info$d4 = (_conditionInfo$info$d5 = conditionInfo.info.dateRange) === null || _conditionInfo$info$d5 === void 0 ? void 0 : _conditionInfo$info$d5[1]) !== null && _conditionInfo$info$d4 !== void 0 ? _conditionInfo$info$d4 : /* @__PURE__ */ new Date()],
|
|
696
|
+
onValueChange: (v) => {
|
|
697
|
+
if (v) handleConditionInfo({ dateRange: v });
|
|
698
|
+
else handleConditionInfo({});
|
|
699
|
+
}
|
|
700
|
+
})
|
|
701
|
+
}),
|
|
702
|
+
subComponentType === ConditionSubComponentEnum.Inputs && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
703
|
+
className: "univer-flex univer-items-center univer-gap-2",
|
|
704
|
+
children: [
|
|
705
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
706
|
+
className: "univer-w-full",
|
|
707
|
+
value: (_conditionInfo$info$n = conditionInfo.info.numberRange) === null || _conditionInfo$info$n === void 0 ? void 0 : _conditionInfo$info$n[0],
|
|
708
|
+
onChange: (v) => {
|
|
709
|
+
if (v !== null) {
|
|
710
|
+
var _conditionInfo$info$n2;
|
|
711
|
+
handleConditionInfo({ numberRange: [v, (_conditionInfo$info$n2 = conditionInfo.info.numberRange) === null || _conditionInfo$info$n2 === void 0 ? void 0 : _conditionInfo$info$n2[1]] });
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
controls: false
|
|
715
|
+
}),
|
|
716
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: " - " }),
|
|
717
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
718
|
+
className: "univer-w-full",
|
|
719
|
+
value: (_conditionInfo$info$n3 = conditionInfo.info.numberRange) === null || _conditionInfo$info$n3 === void 0 ? void 0 : _conditionInfo$info$n3[1],
|
|
720
|
+
controls: false,
|
|
721
|
+
onChange: (v) => {
|
|
722
|
+
if (v !== null) {
|
|
723
|
+
var _conditionInfo$info$n4;
|
|
724
|
+
handleConditionInfo({ numberRange: [(_conditionInfo$info$n4 = conditionInfo.info.numberRange) === null || _conditionInfo$info$n4 === void 0 ? void 0 : _conditionInfo$info$n4[0], v] });
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
})
|
|
728
|
+
]
|
|
729
|
+
}),
|
|
730
|
+
!!(subComponentType === ConditionSubComponentEnum.Select) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
731
|
+
className: "univer-w-full",
|
|
732
|
+
value: (_conditionInfo$info$d6 = conditionInfo.info.dateSelect) !== null && _conditionInfo$info$d6 !== void 0 ? _conditionInfo$info$d6 : conditionDateOptions[0].value,
|
|
733
|
+
options: conditionDateOptions,
|
|
734
|
+
onChange: (v) => handleConditionInfo({ dateSelect: v })
|
|
735
|
+
})
|
|
736
|
+
]
|
|
737
|
+
})] });
|
|
738
|
+
};
|
|
739
|
+
|
|
740
|
+
//#endregion
|
|
741
|
+
//#region src/views/components/SheetTableItemsFilterPanel.tsx
|
|
742
|
+
const getCheckedCount = (map) => {
|
|
743
|
+
let count = 0;
|
|
744
|
+
map.forEach((value) => {
|
|
745
|
+
count += value;
|
|
746
|
+
});
|
|
747
|
+
return count;
|
|
748
|
+
};
|
|
749
|
+
function SheetTableItemsFilterPanel(props) {
|
|
750
|
+
const { unitId, tableId, subUnitId, columnIndex, checkedItemSet, setCheckedItemSet, tableFilter } = props;
|
|
751
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
752
|
+
const { data: items, itemsCountMap, allItemsCount } = (0, _univerjs_ui.useDependency)(SheetsTableUiService).getTableFilterItems(unitId, subUnitId, tableId, columnIndex);
|
|
753
|
+
const [allChecked, setAllChecked] = (0, react.useState)(tableFilter === void 0 ? true : checkedItemSet.size === itemsCountMap.size);
|
|
754
|
+
const [checkedCount, setCheckedCount] = (0, react.useState)(allChecked ? allItemsCount : getCheckedCount(itemsCountMap));
|
|
755
|
+
const indeterminate = !allChecked && checkedItemSet.size > 0;
|
|
756
|
+
const [searchText, setSearchText] = (0, react.useState)("");
|
|
757
|
+
const displayItems = (0, react.useMemo)(() => {
|
|
758
|
+
return searchText ? items.filter((item) => {
|
|
759
|
+
return String(item.title).toLowerCase().includes(searchText.toLowerCase());
|
|
760
|
+
}) : items;
|
|
761
|
+
}, [searchText, items]);
|
|
762
|
+
const onCheckAllToggled = (0, react.useCallback)(() => {
|
|
763
|
+
if (allChecked) {
|
|
764
|
+
checkedItemSet.clear();
|
|
765
|
+
setCheckedItemSet(new Set(checkedItemSet));
|
|
766
|
+
setAllChecked(false);
|
|
767
|
+
} else {
|
|
768
|
+
displayItems.forEach((item) => {
|
|
769
|
+
checkedItemSet.add(item.title);
|
|
770
|
+
});
|
|
771
|
+
setCheckedItemSet(new Set(checkedItemSet));
|
|
772
|
+
setAllChecked(true);
|
|
773
|
+
}
|
|
774
|
+
}, [allChecked]);
|
|
775
|
+
const onSearchValueChange = (0, react.useCallback)((str) => {
|
|
776
|
+
if (str === "") {
|
|
777
|
+
setAllChecked(true);
|
|
778
|
+
items.forEach((item) => {
|
|
779
|
+
checkedItemSet.add(item.title);
|
|
780
|
+
});
|
|
781
|
+
setCheckedCount(allItemsCount);
|
|
782
|
+
} else {
|
|
783
|
+
checkedItemSet.clear();
|
|
784
|
+
setAllChecked(false);
|
|
785
|
+
setCheckedCount(0);
|
|
786
|
+
}
|
|
787
|
+
setSearchText(str);
|
|
788
|
+
}, []);
|
|
789
|
+
const onCheckItemToggled = (key) => {
|
|
790
|
+
if (allChecked) {
|
|
791
|
+
setAllChecked(false);
|
|
792
|
+
const newSet = /* @__PURE__ */ new Set();
|
|
793
|
+
for (const { title } of items) if (key !== title) newSet.add(title);
|
|
794
|
+
setCheckedCount(allItemsCount - itemsCountMap.get(key));
|
|
795
|
+
setCheckedItemSet(newSet);
|
|
796
|
+
} else {
|
|
797
|
+
if (checkedItemSet.has(key)) {
|
|
798
|
+
checkedItemSet.delete(key);
|
|
799
|
+
setCheckedCount(checkedCount - itemsCountMap.get(key));
|
|
800
|
+
} else {
|
|
801
|
+
checkedItemSet.add(key);
|
|
802
|
+
setCheckedCount(checkedCount + itemsCountMap.get(key));
|
|
803
|
+
}
|
|
804
|
+
setCheckedItemSet(new Set(checkedItemSet));
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
808
|
+
className: "univer-flex univer-h-full univer-flex-col",
|
|
809
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
810
|
+
autoFocus: true,
|
|
811
|
+
value: searchText,
|
|
812
|
+
placeholder: localeService.t("sheets-table.filter.search-placeholder"),
|
|
813
|
+
onChange: onSearchValueChange
|
|
814
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
815
|
+
className: (0, _univerjs_design.clsx)("univer-mt-2 univer-box-border univer-flex univer-h-[180px] univer-max-h-[180px] univer-flex-grow univer-flex-col univer-overflow-hidden univer-rounded-md univer-py-1.5 univer-pl-2", _univerjs_design.borderClassName),
|
|
816
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
817
|
+
className: (0, _univerjs_design.clsx)("univer-h-40 univer-overflow-y-auto univer-py-1 univer-pl-2", _univerjs_design.scrollbarClassName),
|
|
818
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
819
|
+
className: "univer-h-full",
|
|
820
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
821
|
+
className: "univer-flex univer-items-center univer-px-2 univer-py-1",
|
|
822
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
|
|
823
|
+
indeterminate,
|
|
824
|
+
disabled: items.length === 0,
|
|
825
|
+
checked: allChecked,
|
|
826
|
+
onChange: onCheckAllToggled,
|
|
827
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
828
|
+
className: "univer-flex univer-h-5 univer-flex-1 univer-items-center univer-text-sm",
|
|
829
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
830
|
+
className: "univer-inline-block univer-truncate",
|
|
831
|
+
children: `${localeService.t("sheets-table.filter.select-all")}`
|
|
832
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
833
|
+
className: "univer-ml univer-text-gray-400",
|
|
834
|
+
children: `(${checkedCount}/${searchText ? displayItems.length : allItemsCount})`
|
|
835
|
+
})]
|
|
836
|
+
})
|
|
837
|
+
})
|
|
838
|
+
}), displayItems.map((item) => {
|
|
839
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
840
|
+
className: "univer-flex univer-items-center univer-px-2 univer-py-1",
|
|
841
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
|
|
842
|
+
checked: allChecked || checkedItemSet.has(item.title),
|
|
843
|
+
onChange: () => {
|
|
844
|
+
onCheckItemToggled(item.title);
|
|
845
|
+
},
|
|
846
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
847
|
+
className: "univer-flex univer-h-5 univer-flex-1 univer-text-sm",
|
|
848
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
849
|
+
className: "univer-inline-block univer-truncate",
|
|
850
|
+
children: item.title
|
|
851
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
|
|
852
|
+
className: "univer-ml-1 univer-text-gray-400",
|
|
853
|
+
children: `(${itemsCountMap.get(item.title) || 0})`
|
|
854
|
+
})]
|
|
855
|
+
})
|
|
856
|
+
})
|
|
857
|
+
}, item.key);
|
|
858
|
+
})]
|
|
859
|
+
})
|
|
860
|
+
})
|
|
861
|
+
})]
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
//#endregion
|
|
866
|
+
//#region src/views/components/SheetTableFilterPanel.tsx
|
|
867
|
+
function SheetTableFilterPanel() {
|
|
868
|
+
var _permissionService$ge;
|
|
869
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
870
|
+
const filterByItems = useFilterByOptions(localeService);
|
|
871
|
+
const tableUiService = (0, _univerjs_ui.useDependency)(SheetsTableUiService);
|
|
872
|
+
const tableManager = (0, _univerjs_ui.useDependency)(_univerjs_sheets_table.TableManager);
|
|
873
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
874
|
+
const permissionService = (0, _univerjs_ui.useDependency)(_univerjs_core.IPermissionService);
|
|
875
|
+
const sheetsTableComponentController = (0, _univerjs_ui.useDependency)(SheetsTableComponentController);
|
|
876
|
+
const tableFilterPanelInfo = sheetsTableComponentController.getCurrentTableFilterInfo();
|
|
877
|
+
const props = tableUiService.getTableFilterPanelInitProps(tableFilterPanelInfo.unitId, tableFilterPanelInfo.subUnitId, tableFilterPanelInfo.tableId, tableFilterPanelInfo.column);
|
|
878
|
+
const { unitId, subUnitId, tableId, tableFilter, currentFilterBy, columnIndex } = props;
|
|
879
|
+
const { data } = tableUiService.getTableFilterItems(unitId, subUnitId, tableId, columnIndex);
|
|
880
|
+
const checkedItems = tableUiService.getTableFilterCheckedItems(unitId, tableId, columnIndex);
|
|
881
|
+
const [checkedItemSet, setCheckedItemSet] = (0, react.useState)(new Set(checkedItems));
|
|
882
|
+
const [filterBy, setFilterBy] = (0, react.useState)(currentFilterBy || FilterByEnum.Items);
|
|
883
|
+
const [conditionInfo, setConditionInfo] = (0, react.useState)(() => {
|
|
884
|
+
const tableFilter = props.tableFilter;
|
|
885
|
+
return getInitConditionInfo(tableFilter);
|
|
886
|
+
});
|
|
887
|
+
const table = tableManager.getTable(unitId, tableId);
|
|
888
|
+
if (!table) return null;
|
|
889
|
+
const tableFilters = table.getTableFilters();
|
|
890
|
+
const sortState = tableFilters.getSortState();
|
|
891
|
+
sortState.columnIndex === columnIndex && (sortState.sortState, _univerjs_sheets_table.SheetsTableSortStateEnum.Asc);
|
|
892
|
+
sortState.columnIndex === columnIndex && (sortState.sortState, _univerjs_sheets_table.SheetsTableSortStateEnum.Desc);
|
|
893
|
+
const closeDialog = () => {
|
|
894
|
+
sheetsTableComponentController.closeFilterPanel();
|
|
895
|
+
};
|
|
896
|
+
const onCancel = () => {
|
|
897
|
+
closeDialog();
|
|
898
|
+
};
|
|
899
|
+
const applySort = (asc) => {
|
|
900
|
+
const range = table.getTableFilterRange();
|
|
901
|
+
commandService.executeCommand(_univerjs_sheets_sort.SortRangeCommand.id, {
|
|
902
|
+
unitId,
|
|
903
|
+
subUnitId,
|
|
904
|
+
range,
|
|
905
|
+
orderRules: [{
|
|
906
|
+
colIndex: columnIndex + range.startColumn,
|
|
907
|
+
type: asc ? _univerjs_sheets_sort.SortType.ASC : _univerjs_sheets_sort.SortType.DESC
|
|
908
|
+
}],
|
|
909
|
+
hasTitle: false
|
|
910
|
+
});
|
|
911
|
+
tableFilters.setSortState(columnIndex, asc ? _univerjs_sheets_table.SheetsTableSortStateEnum.Asc : _univerjs_sheets_table.SheetsTableSortStateEnum.Desc);
|
|
912
|
+
closeDialog();
|
|
913
|
+
};
|
|
914
|
+
const onApply = () => {
|
|
915
|
+
if (filterBy === FilterByEnum.Items) {
|
|
916
|
+
const filteredItems = [];
|
|
917
|
+
for (const itemInfo of data) if (checkedItemSet.has(itemInfo.title)) filteredItems.push(itemInfo.title);
|
|
918
|
+
const originFilter = table.getTableFilterColumn(columnIndex);
|
|
919
|
+
if (originFilter) {
|
|
920
|
+
if (originFilter.values.join(",") === filteredItems.join(",")) {
|
|
921
|
+
closeDialog();
|
|
922
|
+
return;
|
|
923
|
+
}
|
|
924
|
+
} else if (filteredItems.length === 0) {
|
|
925
|
+
closeDialog();
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
const tableFilter = {
|
|
929
|
+
filterType: _univerjs_sheets_table.TableColumnFilterTypeEnum.manual,
|
|
930
|
+
values: filteredItems
|
|
931
|
+
};
|
|
932
|
+
tableUiService.setTableFilter(unitId, tableId, columnIndex, tableFilter);
|
|
933
|
+
} else {
|
|
934
|
+
let filterInfo;
|
|
935
|
+
if (conditionInfo.compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Quarter || conditionInfo.compare === _univerjs_sheets_table.TableDateCompareTypeEnum.Month) filterInfo = {
|
|
936
|
+
conditionType: conditionInfo.type,
|
|
937
|
+
compareType: Object.values(conditionInfo.info)[0]
|
|
938
|
+
};
|
|
939
|
+
else filterInfo = {
|
|
940
|
+
conditionType: conditionInfo.type,
|
|
941
|
+
compareType: conditionInfo.compare,
|
|
942
|
+
expectedValue: Object.values(conditionInfo.info)[0]
|
|
943
|
+
};
|
|
944
|
+
const tableFilter = {
|
|
945
|
+
filterType: _univerjs_sheets_table.TableColumnFilterTypeEnum.condition,
|
|
946
|
+
filterInfo
|
|
947
|
+
};
|
|
948
|
+
tableUiService.setTableFilter(unitId, tableId, columnIndex, tableFilter);
|
|
949
|
+
}
|
|
950
|
+
closeDialog();
|
|
951
|
+
};
|
|
952
|
+
const onClearFilter = () => {
|
|
953
|
+
tableUiService.setTableFilter(unitId, tableId, columnIndex, void 0);
|
|
954
|
+
closeDialog();
|
|
955
|
+
};
|
|
956
|
+
const workbookEditableId = new _univerjs_sheets.WorkbookEditablePermission(unitId).id;
|
|
957
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
958
|
+
className: "univer-box-border univer-flex univer-min-w-[312px] univer-flex-col univer-rounded-[10px] univer-bg-white univer-p-4 univer-shadow-lg dark:!univer-border-gray-600 dark:!univer-bg-gray-700",
|
|
959
|
+
children: [
|
|
960
|
+
((_permissionService$ge = permissionService.getPermissionPoint(workbookEditableId)) === null || _permissionService$ge === void 0 ? void 0 : _permissionService$ge.value) && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
961
|
+
className: "univer-mb-3 univer-flex",
|
|
962
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.ButtonGroup, {
|
|
963
|
+
className: "univer-mb-3 !univer-flex univer-w-full",
|
|
964
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
965
|
+
className: "univer-w-1/2",
|
|
966
|
+
onClick: () => applySort(true),
|
|
967
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AscendingIcon, { className: "univer-mr-1" }), localeService.t("sheets-sort.general.sort-asc")]
|
|
968
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
969
|
+
className: "univer-w-1/2",
|
|
970
|
+
onClick: () => applySort(false),
|
|
971
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DescendingIcon, { className: "univer-mr-1" }), localeService.t("sheets-sort.general.sort-desc")]
|
|
972
|
+
})]
|
|
973
|
+
})
|
|
974
|
+
}),
|
|
975
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
976
|
+
className: "univer-w-full",
|
|
977
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Segmented, {
|
|
978
|
+
value: filterBy,
|
|
979
|
+
items: filterByItems,
|
|
980
|
+
onChange: (value) => setFilterBy(value)
|
|
981
|
+
})
|
|
982
|
+
}),
|
|
983
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
984
|
+
className: "univer-z-10 univer-h-60",
|
|
985
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
986
|
+
className: "univer-mt-3 univer-size-full",
|
|
987
|
+
children: filterBy === FilterByEnum.Items ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetTableItemsFilterPanel, {
|
|
988
|
+
tableFilter,
|
|
989
|
+
unitId,
|
|
990
|
+
subUnitId,
|
|
991
|
+
tableId,
|
|
992
|
+
columnIndex,
|
|
993
|
+
checkedItemSet,
|
|
994
|
+
setCheckedItemSet
|
|
995
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SheetTableConditionPanel, {
|
|
996
|
+
tableFilter,
|
|
997
|
+
unitId,
|
|
998
|
+
subUnitId,
|
|
999
|
+
tableId,
|
|
1000
|
+
columnIndex,
|
|
1001
|
+
conditionInfo,
|
|
1002
|
+
onChange: setConditionInfo
|
|
1003
|
+
})
|
|
1004
|
+
})
|
|
1005
|
+
}),
|
|
1006
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1007
|
+
className: "univer-flex-wrap-nowrap univer-mt-4 univer-inline-flex univer-flex-shrink-0 univer-flex-grow-0 univer-justify-between univer-gap-6 univer-overflow-hidden",
|
|
1008
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
1009
|
+
disabled: tableFilter === void 0,
|
|
1010
|
+
onClick: onClearFilter,
|
|
1011
|
+
children: localeService.t("sheets-table.filter.clear-filter")
|
|
1012
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
1013
|
+
className: "univer-mr-2",
|
|
1014
|
+
onClick: onCancel,
|
|
1015
|
+
children: localeService.t("sheets-table.filter.cancel")
|
|
1016
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
1017
|
+
variant: "primary",
|
|
1018
|
+
onClick: onApply,
|
|
1019
|
+
children: localeService.t("sheets-table.filter.confirm")
|
|
1020
|
+
})] })]
|
|
1021
|
+
})
|
|
1022
|
+
]
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
function useFilterByOptions(localeService) {
|
|
1026
|
+
return (0, react.useMemo)(() => [{
|
|
1027
|
+
label: localeService.t("sheets-table.filter.by-values"),
|
|
1028
|
+
value: FilterByEnum.Items
|
|
1029
|
+
}, {
|
|
1030
|
+
label: localeService.t("sheets-table.filter.by-conditions"),
|
|
1031
|
+
value: FilterByEnum.Condition
|
|
1032
|
+
}], [localeService.getCurrentLocale(), localeService]);
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
//#endregion
|
|
1036
|
+
//#region src/controllers/sheet-table-component.controller.ts
|
|
1037
|
+
let SheetsTableComponentController = class SheetsTableComponentController extends _univerjs_core.Disposable {
|
|
1038
|
+
constructor(_componentManager, _contextService, _sheetCanvasPopupService, _dialogService) {
|
|
1039
|
+
super();
|
|
1040
|
+
this._componentManager = _componentManager;
|
|
1041
|
+
this._contextService = _contextService;
|
|
1042
|
+
this._sheetCanvasPopupService = _sheetCanvasPopupService;
|
|
1043
|
+
this._dialogService = _dialogService;
|
|
1044
|
+
_defineProperty(this, "_popupDisposable", void 0);
|
|
1045
|
+
_defineProperty(this, "_currentTableFilterInfo", null);
|
|
1046
|
+
this._initComponents();
|
|
1047
|
+
this._initUIPopup();
|
|
1048
|
+
}
|
|
1049
|
+
setCurrentTableFilterInfo(info) {
|
|
1050
|
+
this._currentTableFilterInfo = info;
|
|
1051
|
+
}
|
|
1052
|
+
clearCurrentTableFilterInfo() {
|
|
1053
|
+
this._currentTableFilterInfo = null;
|
|
1054
|
+
}
|
|
1055
|
+
getCurrentTableFilterInfo() {
|
|
1056
|
+
return this._currentTableFilterInfo;
|
|
1057
|
+
}
|
|
1058
|
+
_initComponents() {
|
|
1059
|
+
[[SHEETS_TABLE_FILTER_PANEL_OPENED_KEY, SheetTableFilterPanel]].forEach(([key, comp]) => {
|
|
1060
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
_initUIPopup() {
|
|
1064
|
+
this.disposeWithMe(this._contextService.subscribeContextValue$(SHEETS_TABLE_FILTER_PANEL_OPENED_KEY).pipe((0, rxjs.startWith)(void 0), (0, rxjs.distinctUntilChanged)()).subscribe((open) => {
|
|
1065
|
+
if (open) this._openFilterPopup();
|
|
1066
|
+
else if (open === false) this._closeFilterPopup();
|
|
1067
|
+
}));
|
|
1068
|
+
}
|
|
1069
|
+
closeFilterPanel() {
|
|
1070
|
+
this._contextService.setContextValue(SHEETS_TABLE_FILTER_PANEL_OPENED_KEY, false);
|
|
1071
|
+
}
|
|
1072
|
+
_openFilterPopup() {
|
|
1073
|
+
const currentFilterModel = this._currentTableFilterInfo;
|
|
1074
|
+
if (!currentFilterModel) throw new Error("[SheetsFilterUIController]: no filter model when opening filter popup!");
|
|
1075
|
+
const { row: startRow, column: col } = currentFilterModel;
|
|
1076
|
+
this._popupDisposable = this._sheetCanvasPopupService.attachPopupToCell(startRow, col, {
|
|
1077
|
+
componentKey: SHEETS_TABLE_FILTER_PANEL_OPENED_KEY,
|
|
1078
|
+
direction: "horizontal",
|
|
1079
|
+
onClickOutside: () => {
|
|
1080
|
+
this._dialogService.close(UNIVER_SHEET_TABLE_FILTER_PANEL_ID);
|
|
1081
|
+
this._contextService.setContextValue(SHEETS_TABLE_FILTER_PANEL_OPENED_KEY, false);
|
|
1082
|
+
},
|
|
1083
|
+
offset: [5, 0],
|
|
1084
|
+
portal: true
|
|
1085
|
+
});
|
|
1086
|
+
}
|
|
1087
|
+
_closeFilterPopup() {
|
|
1088
|
+
var _this$_popupDisposabl;
|
|
1089
|
+
(_this$_popupDisposabl = this._popupDisposable) === null || _this$_popupDisposabl === void 0 || _this$_popupDisposabl.dispose();
|
|
1090
|
+
this._popupDisposable = null;
|
|
1091
|
+
this.clearCurrentTableFilterInfo();
|
|
1092
|
+
}
|
|
1093
|
+
};
|
|
1094
|
+
SheetsTableComponentController = __decorate([
|
|
1095
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
|
|
1096
|
+
__decorateParam(1, _univerjs_core.IContextService),
|
|
1097
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetCanvasPopManagerService)),
|
|
1098
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_ui.IDialogService))
|
|
1099
|
+
], SheetsTableComponentController);
|
|
1100
|
+
|
|
1101
|
+
//#endregion
|
|
1102
|
+
//#region src/commands/operations/open-table-filter-dialog.opration.ts
|
|
1103
|
+
const OpenTableFilterPanelOperation = {
|
|
1104
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
1105
|
+
id: "sheet.operation.open-table-filter-panel",
|
|
1106
|
+
async handler(accessor, params) {
|
|
1107
|
+
if (!params) return false;
|
|
1108
|
+
const { row, col, unitId, subUnitId, tableId } = params;
|
|
1109
|
+
const tableManager = accessor.get(_univerjs_sheets_table.TableManager);
|
|
1110
|
+
const contextService = accessor.get(_univerjs_core.IContextService);
|
|
1111
|
+
const sheetsTableComponentController = accessor.get(SheetsTableComponentController);
|
|
1112
|
+
if (!tableManager.getTable(unitId, tableId)) return false;
|
|
1113
|
+
if (!contextService.getContextValue("SHEETS_TABLE_FILTER_PANEL_OPENED_KEY")) {
|
|
1114
|
+
sheetsTableComponentController.setCurrentTableFilterInfo({
|
|
1115
|
+
unitId,
|
|
1116
|
+
subUnitId,
|
|
1117
|
+
row,
|
|
1118
|
+
tableId,
|
|
1119
|
+
column: col
|
|
1120
|
+
});
|
|
1121
|
+
contextService.setContextValue(SHEETS_TABLE_FILTER_PANEL_OPENED_KEY, true);
|
|
1122
|
+
}
|
|
1123
|
+
return true;
|
|
1124
|
+
}
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/commands/operations/open-table-selector.operation.ts
|
|
1129
|
+
const OpenTableSelectorOperation = {
|
|
1130
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
1131
|
+
id: "sheet.operation.open-table-selector",
|
|
1132
|
+
async handler(accessor) {
|
|
1133
|
+
var _lastSelection$range;
|
|
1134
|
+
const univerInstanceService = accessor.get(_univerjs_core.IUniverInstanceService);
|
|
1135
|
+
const commandService = accessor.get(_univerjs_core.ICommandService);
|
|
1136
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
|
|
1137
|
+
if (!target) return false;
|
|
1138
|
+
const { unitId, subUnitId, worksheet } = target;
|
|
1139
|
+
const lastSelection = accessor.get(_univerjs_sheets.SheetsSelectionsService).getCurrentLastSelection();
|
|
1140
|
+
const range = (_lastSelection$range = lastSelection === null || lastSelection === void 0 ? void 0 : lastSelection.range) !== null && _lastSelection$range !== void 0 ? _lastSelection$range : {
|
|
1141
|
+
startRow: 0,
|
|
1142
|
+
endRow: 0,
|
|
1143
|
+
startColumn: 0,
|
|
1144
|
+
endColumn: 0
|
|
1145
|
+
};
|
|
1146
|
+
const rangeInfo = await openRangeSelector(accessor, unitId, subUnitId, (0, _univerjs_sheets.isSingleCellSelection)(lastSelection) ? (0, _univerjs_sheets.expandToContinuousRange)(range, {
|
|
1147
|
+
up: true,
|
|
1148
|
+
left: true,
|
|
1149
|
+
right: true,
|
|
1150
|
+
down: true
|
|
1151
|
+
}, worksheet) : range);
|
|
1152
|
+
if (!rangeInfo) return false;
|
|
1153
|
+
commandService.executeCommand(_univerjs_sheets_table.AddSheetTableCommand.id, { ...rangeInfo });
|
|
1154
|
+
return true;
|
|
1155
|
+
}
|
|
1156
|
+
};
|
|
1157
|
+
async function openRangeSelector(accessor, unitId, subUnitId, range, tableId) {
|
|
1158
|
+
const dialogService = accessor.get(_univerjs_ui.IDialogService);
|
|
1159
|
+
const localeService = accessor.get(_univerjs_core.LocaleService);
|
|
1160
|
+
return new Promise((resolve) => {
|
|
1161
|
+
const dialogProps = {
|
|
1162
|
+
unitId,
|
|
1163
|
+
subUnitId,
|
|
1164
|
+
range,
|
|
1165
|
+
tableId,
|
|
1166
|
+
onConfirm: (info) => {
|
|
1167
|
+
resolve(info);
|
|
1168
|
+
dialogService.close(TABLE_SELECTOR_DIALOG);
|
|
1169
|
+
},
|
|
1170
|
+
onCancel: () => {
|
|
1171
|
+
resolve(null);
|
|
1172
|
+
dialogService.close(TABLE_SELECTOR_DIALOG);
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
dialogService.open({
|
|
1176
|
+
id: TABLE_SELECTOR_DIALOG,
|
|
1177
|
+
title: { title: localeService.t("sheets-table.selectRange") },
|
|
1178
|
+
draggable: true,
|
|
1179
|
+
destroyOnClose: true,
|
|
1180
|
+
mask: false,
|
|
1181
|
+
maskClosable: false,
|
|
1182
|
+
children: { label: {
|
|
1183
|
+
name: TABLE_SELECTOR_DIALOG,
|
|
1184
|
+
props: dialogProps
|
|
1185
|
+
} },
|
|
1186
|
+
width: 300,
|
|
1187
|
+
onClose: () => {
|
|
1188
|
+
resolve(null);
|
|
1189
|
+
dialogService.close(TABLE_SELECTOR_DIALOG);
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
});
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
//#endregion
|
|
1196
|
+
//#region src/config/config.ts
|
|
1197
|
+
const SHEETS_TABLE_UI_PLUGIN_CONFIG_KEY = "sheets-table-ui.config";
|
|
1198
|
+
const configSymbol = Symbol(SHEETS_TABLE_UI_PLUGIN_CONFIG_KEY);
|
|
1199
|
+
const defaultPluginConfig = {
|
|
1200
|
+
anchorHeight: 24,
|
|
1201
|
+
anchorBackgroundColor: "rgb(134,139,156)"
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
//#endregion
|
|
1205
|
+
//#region src/controllers/sheet-table-theme-ui.controller.ts
|
|
1206
|
+
let SheetTableThemeUIController = class SheetTableThemeUIController extends _univerjs_core.Disposable {
|
|
1207
|
+
constructor(_commandService) {
|
|
1208
|
+
super();
|
|
1209
|
+
this._commandService = _commandService;
|
|
1210
|
+
_defineProperty(this, "_refreshTable", new rxjs.Subject());
|
|
1211
|
+
_defineProperty(this, "refreshTable$", this._refreshTable.asObservable());
|
|
1212
|
+
this._initListener();
|
|
1213
|
+
}
|
|
1214
|
+
_initListener() {
|
|
1215
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1216
|
+
if (command.id === _univerjs_sheets.SetRangeThemeMutation.id) {
|
|
1217
|
+
const { styleName } = command.params;
|
|
1218
|
+
if (styleName.startsWith(_univerjs_sheets_table.SHEET_TABLE_CUSTOM_THEME_PREFIX)) this._refreshTable.next(Math.random());
|
|
1219
|
+
}
|
|
1220
|
+
}));
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
SheetTableThemeUIController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_core.ICommandService))], SheetTableThemeUIController);
|
|
1224
|
+
|
|
1225
|
+
//#endregion
|
|
1226
|
+
//#region src/views/components/SheetTableAnchor.tsx
|
|
1227
|
+
const SheetTableAnchor = () => {
|
|
1228
|
+
var _tableConfig$anchorHe, _tableConfig$anchorBa;
|
|
1229
|
+
const [inputFocusId, setInputFocusId] = (0, react.useState)("");
|
|
1230
|
+
const [inputValue, setInputValue] = (0, react.useState)("");
|
|
1231
|
+
const sidebarService = (0, _univerjs_ui.useDependency)(_univerjs_ui.ISidebarService);
|
|
1232
|
+
const [openStates, setOpenStates] = (0, react.useState)({});
|
|
1233
|
+
const injector = (0, _univerjs_ui.useDependency)(_univerjs_core.Injector);
|
|
1234
|
+
const anchorPosition = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(SheetTableAnchorController).anchorPosition$);
|
|
1235
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
1236
|
+
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
1237
|
+
const workbookPermissionInitState = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_sheets.WorkbookPermissionService).unitPermissionInitStateChange$, false);
|
|
1238
|
+
const tableManager = (0, _univerjs_ui.useDependency)(_univerjs_sheets_table.TableManager);
|
|
1239
|
+
const rangeThemeModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetRangeThemeModel);
|
|
1240
|
+
const tableRefresh$ = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(SheetTableThemeUIController).refreshTable$);
|
|
1241
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
1242
|
+
const selections = (0, _univerjs_ui.useObservable)((0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetsSelectionsService).selectionChanged$, [{
|
|
1243
|
+
range: (0, _univerjs_core.cellToRange)(0, 0),
|
|
1244
|
+
primary: null
|
|
1245
|
+
}]);
|
|
1246
|
+
const [, setRefresh] = (0, react.useState)(Math.random());
|
|
1247
|
+
const tableConfig = (0, _univerjs_ui.useDependency)(_univerjs_core.IConfigService).getConfig(SHEETS_TABLE_UI_PLUGIN_CONFIG_KEY);
|
|
1248
|
+
const anchorHeight = (_tableConfig$anchorHe = tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.anchorHeight) !== null && _tableConfig$anchorHe !== void 0 ? _tableConfig$anchorHe : 24;
|
|
1249
|
+
const anchorBackgroundColor = (_tableConfig$anchorBa = tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.anchorBackgroundColor) !== null && _tableConfig$anchorBa !== void 0 ? _tableConfig$anchorBa : "rgb(53,91,183)";
|
|
1250
|
+
const updateOpenState = (tableId, isOpen) => {
|
|
1251
|
+
setOpenStates((prev) => ({
|
|
1252
|
+
...prev,
|
|
1253
|
+
[tableId]: isOpen
|
|
1254
|
+
}));
|
|
1255
|
+
};
|
|
1256
|
+
(0, react.useEffect)(() => {
|
|
1257
|
+
setRefresh(Math.random());
|
|
1258
|
+
}, [tableRefresh$]);
|
|
1259
|
+
if (!(anchorPosition === null || anchorPosition === void 0 ? void 0 : anchorPosition.length)) return null;
|
|
1260
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService);
|
|
1261
|
+
if (!target) return null;
|
|
1262
|
+
const { unitId, subUnitId } = target;
|
|
1263
|
+
const handleChangeTableName = (tableId, name) => {
|
|
1264
|
+
var _tableManager$getTabl;
|
|
1265
|
+
if (((_tableManager$getTabl = tableManager.getTableById(unitId, tableId)) === null || _tableManager$getTabl === void 0 ? void 0 : _tableManager$getTabl.getDisplayName()) === name) {
|
|
1266
|
+
setInputFocusId("");
|
|
1267
|
+
setInputValue("");
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
commandService.executeCommand(_univerjs_sheets_table.SetSheetTableCommand.id, {
|
|
1271
|
+
tableId,
|
|
1272
|
+
unitId,
|
|
1273
|
+
name
|
|
1274
|
+
});
|
|
1275
|
+
setInputValue("");
|
|
1276
|
+
setInputFocusId("");
|
|
1277
|
+
};
|
|
1278
|
+
const handleChangeRange = async (tableId) => {
|
|
1279
|
+
const table = tableManager.getTableById(unitId, tableId);
|
|
1280
|
+
if (!table) return;
|
|
1281
|
+
const selection = await openRangeSelector(injector, unitId, subUnitId, table.getRange(), tableId);
|
|
1282
|
+
if (!selection) return;
|
|
1283
|
+
commandService.executeCommand(_univerjs_sheets_table.SetSheetTableCommand.id, {
|
|
1284
|
+
tableId,
|
|
1285
|
+
unitId,
|
|
1286
|
+
updateRange: { newRange: selection.range }
|
|
1287
|
+
});
|
|
1288
|
+
};
|
|
1289
|
+
if (!workbookPermissionInitState) return null;
|
|
1290
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1291
|
+
className: "univer-absolute univer-z-50 univer-size-0",
|
|
1292
|
+
children: anchorPosition.map((item) => {
|
|
1293
|
+
var _rangeTheme$getHeader, _rangeTheme$getHeader2, _rangeTheme$getHeader3, _rangeTheme$getHeader4, _openStates$item$tabl;
|
|
1294
|
+
const table = tableManager.getTableById(unitId, item.tableId);
|
|
1295
|
+
if (!table) return null;
|
|
1296
|
+
const rangeTheme = rangeThemeModel.getRangeThemeStyle(unitId, table.getTableStyleId());
|
|
1297
|
+
const headerBgColor = (_rangeTheme$getHeader = rangeTheme === null || rangeTheme === void 0 || (_rangeTheme$getHeader2 = rangeTheme.getHeaderRowStyle()) === null || _rangeTheme$getHeader2 === void 0 || (_rangeTheme$getHeader2 = _rangeTheme$getHeader2.bg) === null || _rangeTheme$getHeader2 === void 0 ? void 0 : _rangeTheme$getHeader2.rgb) !== null && _rangeTheme$getHeader !== void 0 ? _rangeTheme$getHeader : anchorBackgroundColor;
|
|
1298
|
+
const headerTextColor = (_rangeTheme$getHeader3 = rangeTheme === null || rangeTheme === void 0 || (_rangeTheme$getHeader4 = rangeTheme.getHeaderRowStyle()) === null || _rangeTheme$getHeader4 === void 0 || (_rangeTheme$getHeader4 = _rangeTheme$getHeader4.cl) === null || _rangeTheme$getHeader4 === void 0 ? void 0 : _rangeTheme$getHeader4.rgb) !== null && _rangeTheme$getHeader3 !== void 0 ? _rangeTheme$getHeader3 : "rgb(255, 255, 255)";
|
|
1299
|
+
const tableRange = table.getRange();
|
|
1300
|
+
if (!(selections === null || selections === void 0 ? void 0 : selections.length)) return null;
|
|
1301
|
+
const lastRange = selections[selections.length - 1].range;
|
|
1302
|
+
const shouldHidden = !_univerjs_core.Rectangle.intersects(tableRange, lastRange) && item.y <= 20;
|
|
1303
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1304
|
+
className: (0, _univerjs_design.clsx)("univer-shadow-xs univer-absolute univer-box-border univer-cursor-pointer univer-items-center univer-rounded-xl univer-px-2", _univerjs_design.borderClassName, {
|
|
1305
|
+
"univer-flex": !shouldHidden,
|
|
1306
|
+
"univer-hidden": shouldHidden
|
|
1307
|
+
}),
|
|
1308
|
+
style: {
|
|
1309
|
+
left: item.x,
|
|
1310
|
+
top: Math.max(item.y, 0),
|
|
1311
|
+
backgroundColor: headerBgColor,
|
|
1312
|
+
color: headerTextColor,
|
|
1313
|
+
borderWidth: "0.5px",
|
|
1314
|
+
height: anchorHeight ? `${anchorHeight}px` : "24px"
|
|
1315
|
+
},
|
|
1316
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1317
|
+
className: "univer-text-nowrap",
|
|
1318
|
+
children: inputFocusId === item.tableId ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Input, {
|
|
1319
|
+
className: "univer-h-[18px] univer-min-w-16 univer-rounded-none",
|
|
1320
|
+
inputClass: "univer-h-[18px] univer-w-[80px]",
|
|
1321
|
+
value: inputValue,
|
|
1322
|
+
onChange: (v) => setInputValue(v),
|
|
1323
|
+
onBlur: () => handleChangeTableName(item.tableId, inputValue),
|
|
1324
|
+
onKeyDown: (e) => {
|
|
1325
|
+
if (e.key === "Enter") handleChangeTableName(item.tableId, inputValue);
|
|
1326
|
+
},
|
|
1327
|
+
autoFocus: inputFocusId === item.tableId
|
|
1328
|
+
}) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1329
|
+
className: "univer-h-[18px] univer-max-w-24 univer-truncate univer-text-sm",
|
|
1330
|
+
children: item.tableName
|
|
1331
|
+
})
|
|
1332
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
1333
|
+
align: "start",
|
|
1334
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1335
|
+
className: "univer-py-2",
|
|
1336
|
+
children: [
|
|
1337
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1338
|
+
className: "univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-gap-2 univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200",
|
|
1339
|
+
onClick: () => {
|
|
1340
|
+
setInputFocusId(item.tableId);
|
|
1341
|
+
setInputValue(item.tableName);
|
|
1342
|
+
},
|
|
1343
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.RenameIcon, {}), localeService.t("sheets-table.rename")]
|
|
1344
|
+
}),
|
|
1345
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "univer-my-1 univer-h-px univer-w-full univer-bg-gray-200" }),
|
|
1346
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1347
|
+
onClick: () => handleChangeRange(item.tableId),
|
|
1348
|
+
className: "univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-gap-2 univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200",
|
|
1349
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.GridOutlineIcon, {}), localeService.t("sheets-table.updateRange")]
|
|
1350
|
+
}),
|
|
1351
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1352
|
+
className: "univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-gap-2 univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200",
|
|
1353
|
+
onClick: () => {
|
|
1354
|
+
updateOpenState(item.tableId, false);
|
|
1355
|
+
const table = tableManager.getTableById(unitId, item.tableId);
|
|
1356
|
+
if (!table) return;
|
|
1357
|
+
const tableConfig = table.getTableConfig();
|
|
1358
|
+
const sidebarConfig = {
|
|
1359
|
+
id: SHEET_TABLE_THEME_PANEL_ID,
|
|
1360
|
+
header: { title: localeService.t("sheets-table.tableStyle") },
|
|
1361
|
+
children: {
|
|
1362
|
+
label: SHEET_TABLE_THEME_PANEL,
|
|
1363
|
+
oldConfig: tableConfig,
|
|
1364
|
+
unitId,
|
|
1365
|
+
subUnitId,
|
|
1366
|
+
tableId: item.tableId
|
|
1367
|
+
},
|
|
1368
|
+
width: 330
|
|
1369
|
+
};
|
|
1370
|
+
sidebarService.open(sidebarConfig);
|
|
1371
|
+
},
|
|
1372
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.PaintBucketDoubleIcon, { extend: { colorChannel1: "rgb(53,91,183)" } }), localeService.t("sheets-table.setTheme")]
|
|
1373
|
+
}),
|
|
1374
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "univer-my-1 univer-h-px univer-w-full univer-bg-gray-200" }),
|
|
1375
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1376
|
+
className: "univer-flex univer-min-w-32 univer-cursor-pointer univer-items-center univer-px-2 univer-py-1 univer-text-sm hover:univer-bg-gray-200",
|
|
1377
|
+
onClick: () => {
|
|
1378
|
+
updateOpenState(item.tableId, false);
|
|
1379
|
+
commandService.executeCommand(_univerjs_sheets_table.DeleteSheetTableCommand.id, {
|
|
1380
|
+
tableId: item.tableId,
|
|
1381
|
+
subUnitId,
|
|
1382
|
+
unitId
|
|
1383
|
+
});
|
|
1384
|
+
},
|
|
1385
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DeleteIcon, { className: "univer-mr-2" }), localeService.t("sheets-table.removeTable")]
|
|
1386
|
+
})
|
|
1387
|
+
]
|
|
1388
|
+
}),
|
|
1389
|
+
open: (_openStates$item$tabl = openStates[item.tableId]) !== null && _openStates$item$tabl !== void 0 ? _openStates$item$tabl : false,
|
|
1390
|
+
onOpenChange: (isOpen) => {
|
|
1391
|
+
updateOpenState(item.tableId, isOpen);
|
|
1392
|
+
},
|
|
1393
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, {}) })
|
|
1394
|
+
}, item.tableId)]
|
|
1395
|
+
}, item.tableId);
|
|
1396
|
+
})
|
|
1397
|
+
});
|
|
1398
|
+
};
|
|
1399
|
+
|
|
1400
|
+
//#endregion
|
|
1401
|
+
//#region src/controllers/sheet-table-anchor.controller.ts
|
|
1402
|
+
let SheetTableAnchorController = class SheetTableAnchorController extends _univerjs_core.Disposable {
|
|
1403
|
+
constructor(_context, _injector, _sheetSkeletonManagerService, _renderManagerService, _commandService, _univerInstanceService, _uiPartsService, _tableManager, _scrollManagerService, _workbookPermissionService, _permissionService) {
|
|
1404
|
+
super();
|
|
1405
|
+
this._context = _context;
|
|
1406
|
+
this._injector = _injector;
|
|
1407
|
+
this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
|
|
1408
|
+
this._renderManagerService = _renderManagerService;
|
|
1409
|
+
this._commandService = _commandService;
|
|
1410
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1411
|
+
this._uiPartsService = _uiPartsService;
|
|
1412
|
+
this._tableManager = _tableManager;
|
|
1413
|
+
this._scrollManagerService = _scrollManagerService;
|
|
1414
|
+
this._workbookPermissionService = _workbookPermissionService;
|
|
1415
|
+
this._permissionService = _permissionService;
|
|
1416
|
+
_defineProperty(this, "_anchorVisible$", new rxjs.BehaviorSubject(true));
|
|
1417
|
+
_defineProperty(this, "_timer", void 0);
|
|
1418
|
+
_defineProperty(this, "_anchorPosition$", new rxjs.BehaviorSubject([]));
|
|
1419
|
+
_defineProperty(this, "anchorPosition$", this._anchorPosition$.asObservable());
|
|
1420
|
+
this._initUI();
|
|
1421
|
+
this._initListener();
|
|
1422
|
+
this._initTableAnchor();
|
|
1423
|
+
}
|
|
1424
|
+
_initUI() {
|
|
1425
|
+
this.disposeWithMe(this._uiPartsService.registerComponent(_univerjs_ui.BuiltInUIPart.CONTENT, () => (0, _univerjs_ui.connectInjector)(SheetTableAnchor, this._injector)));
|
|
1426
|
+
}
|
|
1427
|
+
_initListener() {
|
|
1428
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1429
|
+
if (command.id === _univerjs_sheets_ui.SetZoomRatioOperation.id || command.id === _univerjs_sheets_ui.SetScrollOperation.id) {
|
|
1430
|
+
this._anchorVisible$.next(false);
|
|
1431
|
+
if (this._timer) clearTimeout(this._timer);
|
|
1432
|
+
this._timer = setTimeout(() => {
|
|
1433
|
+
this._anchorVisible$.next(true);
|
|
1434
|
+
}, 300);
|
|
1435
|
+
}
|
|
1436
|
+
}));
|
|
1437
|
+
}
|
|
1438
|
+
_initTableAnchor() {
|
|
1439
|
+
this.disposeWithMe((0, rxjs.merge)(this._context.unit.activeSheet$, this._sheetSkeletonManagerService.currentSkeleton$, this._scrollManagerService.validViewportScrollInfo$, this._tableManager.tableAdd$, this._tableManager.tableDelete$, this._tableManager.tableNameChanged$, this._tableManager.tableRangeChanged$, this._tableManager.tableThemeChanged$, this._workbookPermissionService.unitPermissionInitStateChange$.pipe((0, rxjs.filter)((v) => v)), this._permissionService.permissionPointUpdate$.pipe((0, rxjs.debounceTime)(300)), this._anchorVisible$).subscribe(() => {
|
|
1440
|
+
var _this$_permissionServ;
|
|
1441
|
+
if (!this._anchorVisible$.getValue()) {
|
|
1442
|
+
this._anchorPosition$.next([]);
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
const workbook = this._context.unit;
|
|
1446
|
+
const worksheet = workbook.getActiveSheet();
|
|
1447
|
+
const subUnitId = worksheet === null || worksheet === void 0 ? void 0 : worksheet.getSheetId();
|
|
1448
|
+
const tables = this._tableManager.getTableList(this._context.unitId).filter((table) => {
|
|
1449
|
+
return table.subUnitId === subUnitId;
|
|
1450
|
+
});
|
|
1451
|
+
const renderUnit = this._renderManagerService.getRenderById(this._context.unitId);
|
|
1452
|
+
if (!renderUnit) {
|
|
1453
|
+
this._anchorPosition$.next([]);
|
|
1454
|
+
return;
|
|
1455
|
+
}
|
|
1456
|
+
if (!((_this$_permissionServ = this._permissionService.getPermissionPoint(new _univerjs_sheets.WorkbookEditablePermission(workbook.getUnitId()).id)) === null || _this$_permissionServ === void 0 ? void 0 : _this$_permissionServ.value)) {
|
|
1457
|
+
this._anchorPosition$.next([]);
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const tableInfos = tables.reduce((acc, table) => {
|
|
1461
|
+
const { startRow, startColumn } = table.range;
|
|
1462
|
+
const sheetSkeletonManagerService = renderUnit.with(_univerjs_sheets_ui.SheetSkeletonManagerService);
|
|
1463
|
+
const sheetObject = (0, _univerjs_sheets_ui.getSheetObject)(this._univerInstanceService, this._renderManagerService);
|
|
1464
|
+
if (!sheetObject) return acc;
|
|
1465
|
+
const { scene } = sheetObject;
|
|
1466
|
+
const viewport = scene.getViewport(_univerjs_engine_render.SHEET_VIEWPORT_KEY.VIEW_MAIN);
|
|
1467
|
+
if (!viewport) return acc;
|
|
1468
|
+
const scaleX = scene === null || scene === void 0 ? void 0 : scene.scaleX;
|
|
1469
|
+
const scaleY = scene === null || scene === void 0 ? void 0 : scene.scaleY;
|
|
1470
|
+
const scrollXY = scene === null || scene === void 0 ? void 0 : scene.getViewportScrollXY(viewport);
|
|
1471
|
+
if (!scaleX || !scene || !scaleY || !scrollXY) return acc;
|
|
1472
|
+
const skeleton = sheetSkeletonManagerService.getCurrentSkeleton();
|
|
1473
|
+
if (!skeleton) return acc;
|
|
1474
|
+
const position = skeleton.getNoMergeCellWithCoordByIndex(startRow, startColumn);
|
|
1475
|
+
const startX = (0, _univerjs_engine_render.convertTransformToOffsetX)(position.startX, scaleX, scrollXY);
|
|
1476
|
+
const startY = (0, _univerjs_engine_render.convertTransformToOffsetY)(position.startY, scaleY, scrollXY) - 25 - 4;
|
|
1477
|
+
if (startY >= -10 && startX >= 45) acc.push({
|
|
1478
|
+
x: startX,
|
|
1479
|
+
y: startY,
|
|
1480
|
+
tableId: table.id,
|
|
1481
|
+
tableName: table.name
|
|
1482
|
+
});
|
|
1483
|
+
return acc;
|
|
1484
|
+
}, []);
|
|
1485
|
+
this._anchorPosition$.next(tableInfos);
|
|
1486
|
+
}));
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
SheetTableAnchorController = __decorate([
|
|
1490
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1491
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService)),
|
|
1492
|
+
__decorateParam(3, _univerjs_engine_render.IRenderManagerService),
|
|
1493
|
+
__decorateParam(4, _univerjs_core.ICommandService),
|
|
1494
|
+
__decorateParam(5, _univerjs_core.IUniverInstanceService),
|
|
1495
|
+
__decorateParam(6, _univerjs_ui.IUIPartsService),
|
|
1496
|
+
__decorateParam(7, (0, _univerjs_core.Inject)(_univerjs_sheets_table.TableManager)),
|
|
1497
|
+
__decorateParam(8, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetScrollManagerService)),
|
|
1498
|
+
__decorateParam(9, (0, _univerjs_core.Inject)(_univerjs_sheets.WorkbookPermissionService)),
|
|
1499
|
+
__decorateParam(10, (0, _univerjs_core.Inject)(_univerjs_core.IPermissionService))
|
|
1500
|
+
], SheetTableAnchorController);
|
|
1501
|
+
|
|
1502
|
+
//#endregion
|
|
1503
|
+
//#region src/views/widgets/drawings.ts
|
|
1504
|
+
const BUTTON_VIEWPORT = 16;
|
|
1505
|
+
const PIVOT_BUTTON_EMPTY = new Path2D("M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z");
|
|
1506
|
+
var TableButton = class {
|
|
1507
|
+
static drawNoSetting(ctx, size, fgColor, bgColor) {
|
|
1508
|
+
ctx.save();
|
|
1509
|
+
_univerjs_engine_render.Rect.drawWith(ctx, {
|
|
1510
|
+
radius: 2,
|
|
1511
|
+
width: BUTTON_VIEWPORT,
|
|
1512
|
+
height: BUTTON_VIEWPORT,
|
|
1513
|
+
fill: bgColor
|
|
1514
|
+
});
|
|
1515
|
+
ctx.lineCap = "square";
|
|
1516
|
+
ctx.strokeStyle = fgColor;
|
|
1517
|
+
ctx.scale(size / BUTTON_VIEWPORT, size / BUTTON_VIEWPORT);
|
|
1518
|
+
ctx.beginPath();
|
|
1519
|
+
ctx.lineWidth = 1;
|
|
1520
|
+
ctx.lineCap = "round";
|
|
1521
|
+
ctx.moveTo(3, 4);
|
|
1522
|
+
ctx.lineTo(13, 4);
|
|
1523
|
+
ctx.moveTo(4.5, 8);
|
|
1524
|
+
ctx.lineTo(11.5, 8);
|
|
1525
|
+
ctx.moveTo(6, 12);
|
|
1526
|
+
ctx.lineTo(10, 12);
|
|
1527
|
+
ctx.stroke();
|
|
1528
|
+
ctx.restore();
|
|
1529
|
+
}
|
|
1530
|
+
static drawIconByPath(ctx, pathData, fgColor, bgColor) {
|
|
1531
|
+
ctx.save();
|
|
1532
|
+
ctx.strokeStyle = fgColor;
|
|
1533
|
+
ctx.fillStyle = bgColor;
|
|
1534
|
+
_univerjs_engine_render.Rect.drawWith(ctx, {
|
|
1535
|
+
radius: 2,
|
|
1536
|
+
width: BUTTON_VIEWPORT,
|
|
1537
|
+
height: BUTTON_VIEWPORT,
|
|
1538
|
+
fill: bgColor
|
|
1539
|
+
});
|
|
1540
|
+
pathData.forEach((d) => {
|
|
1541
|
+
const path = new Path2D(d);
|
|
1542
|
+
ctx.fillStyle = fgColor;
|
|
1543
|
+
ctx.fill(path, "evenodd");
|
|
1544
|
+
});
|
|
1545
|
+
ctx.restore();
|
|
1546
|
+
}
|
|
1547
|
+
};
|
|
1548
|
+
|
|
1549
|
+
//#endregion
|
|
1550
|
+
//#region src/views/widgets/icons.ts
|
|
1551
|
+
/**
|
|
1552
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
1553
|
+
*
|
|
1554
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
1555
|
+
* you may not use this file except in compliance with the License.
|
|
1556
|
+
* You may obtain a copy of the License at
|
|
1557
|
+
*
|
|
1558
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
1559
|
+
*
|
|
1560
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
1561
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
1562
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
1563
|
+
* See the License for the specific language governing permissions and
|
|
1564
|
+
* limitations under the License.
|
|
1565
|
+
*/
|
|
1566
|
+
const filterPartial = ["M3.30363 3C2.79117 3 2.51457 3.60097 2.84788 3.99024L6.8 8.60593V12.5662C6.8 12.7184 6.8864 12.8575 7.02289 12.9249L8.76717 13.7863C8.96655 13.8847 9.2 13.7396 9.2 13.5173V8.60593L13.1521 3.99024C13.4854 3.60097 13.2088 3 12.6964 3H3.30363Z"];
|
|
1567
|
+
const filteredSortAsc = ["M12.4008 13.1831C12.6907 13.1831 12.9258 12.9481 12.9258 12.6581V4.60873L14.013 5.69597C14.218 5.901 14.5505 5.901 14.7555 5.69597C14.9605 5.49094 14.9605 5.15853 14.7555 4.95351L12.7721 2.97017C12.5671 2.76515 12.2347 2.76515 12.0297 2.97017L10.0463 4.95351C9.84132 5.15853 9.84132 5.49094 10.0463 5.69597C10.2514 5.901 10.5838 5.901 10.7888 5.69597L11.8758 4.60901V12.6581C11.8758 12.9481 12.1108 13.1831 12.4008 13.1831Z", "M1.28069 4.85447C0.842195 4.33439 1.21191 3.5391 1.89218 3.5391H8.59333C9.2736 3.5391 9.64331 4.33439 9.20482 4.85447L6.51052 8.0501V11.6601C6.51052 12.2245 5.94174 12.6114 5.41683 12.404L4.48092 12.0343C4.1756 11.9136 3.97498 11.6187 3.97498 11.2904V8.0501L1.28069 4.85447Z"];
|
|
1568
|
+
const filteredSortDesc = ["M12.4008 2.81641C12.6907 2.81641 12.9258 3.05146 12.9258 3.34141V11.3908L14.013 10.3036C14.218 10.0986 14.5505 10.0986 14.7555 10.3036C14.9605 10.5086 14.9605 10.841 14.7555 11.046L12.7721 13.0294C12.5671 13.2344 12.2347 13.2344 12.0297 13.0294L10.0463 11.046C9.84132 10.841 9.84132 10.5086 10.0463 10.3036C10.2514 10.0986 10.5838 10.0986 10.7888 10.3036L11.8758 11.3905V3.34141C11.8758 3.05146 12.1108 2.81641 12.4008 2.81641Z", "M1.28069 4.85444C0.842195 4.33435 1.21191 3.53906 1.89218 3.53906H8.59333C9.2736 3.53906 9.64331 4.33435 9.20482 4.85443L6.51052 8.05006V11.6601C6.51052 12.2245 5.94174 12.6113 5.41683 12.404L4.48092 12.0342C4.1756 11.9136 3.97498 11.6186 3.97498 11.2903V8.05006L1.28069 4.85444Z"];
|
|
1569
|
+
const filterNoneSortAsc = [
|
|
1570
|
+
"M11.9003 13.7046C11.9003 13.9969 11.6633 14.2339 11.371 14.2339C11.0787 14.2339 10.8417 13.9969 10.8417 13.7046V3.57272L9.74577 4.66862C9.53906 4.87534 9.20391 4.87534 8.9972 4.66862C8.79048 4.46191 8.79048 4.12676 8.9972 3.92005L10.9969 1.92039C11.2036 1.71368 11.5387 1.71368 11.7454 1.92039L13.7451 3.92005C13.9518 4.12676 13.9518 4.46191 13.7451 4.66862C13.5384 4.87534 13.2032 4.87534 12.9965 4.66862L11.9003 3.57243V13.7046Z",
|
|
1571
|
+
"M2.69779 10.0113C2.40546 10.0113 2.16847 9.77429 2.16847 9.48196C2.16847 9.18962 2.40546 8.95264 2.69779 8.95264H6.67804C6.89213 8.95264 7.08514 9.0816 7.16707 9.2794C7.249 9.47719 7.20371 9.70486 7.05233 9.85624L3.97569 12.9329H6.67804C6.97038 12.9329 7.20736 13.1699 7.20736 13.4622C7.20736 13.7545 6.97038 13.9915 6.67804 13.9915H2.69779C2.4837 13.9915 2.29069 13.8626 2.20876 13.6648C2.12684 13.467 2.17212 13.2393 2.32351 13.0879L5.40015 10.0113H2.69779Z",
|
|
1572
|
+
"M5.51638 2.58693C5.23363 1.81542 4.14248 1.81543 3.85973 2.58693L2.13245 7.29995C2.03185 7.57443 2.17281 7.87849 2.4473 7.97909C2.72178 8.07969 3.02584 7.93872 3.12644 7.66424L3.64346 6.25351L3.64504 6.25351H5.73266L6.24968 7.66424C6.35027 7.93872 6.65433 8.07969 6.92882 7.97909C7.2033 7.87849 7.34426 7.57443 7.24367 7.29995L5.51638 2.58693ZM5.34467 5.19487L4.68806 3.40325L4.03144 5.19487H5.34467Z"
|
|
1573
|
+
];
|
|
1574
|
+
const filterNoneSortDesc = [
|
|
1575
|
+
"M11.9003 2.29495C11.9003 2.00261 11.6633 1.76562 11.371 1.76562C11.0787 1.76562 10.8417 2.00261 10.8417 2.29495V12.4268L9.74577 11.3309C9.53906 11.1242 9.20391 11.1242 8.9972 11.3309C8.79048 11.5376 8.79048 11.8727 8.9972 12.0795L10.9969 14.0791C11.2036 14.2858 11.5387 14.2858 11.7454 14.0791L13.7451 12.0795C13.9518 11.8727 13.9518 11.5376 13.7451 11.3309C13.5384 11.1242 13.2032 11.1242 12.9965 11.3309L11.9003 12.4271V2.29495Z",
|
|
1576
|
+
"M2.69792 10.0113C2.40558 10.0113 2.16859 9.77429 2.16859 9.48196C2.16859 9.18962 2.40558 8.95264 2.69792 8.95264H6.67816C6.89225 8.95264 7.08526 9.0816 7.16719 9.2794C7.24912 9.47719 7.20384 9.70486 7.05245 9.85624L3.97581 12.9329H6.67816C6.9705 12.9329 7.20749 13.1699 7.20749 13.4622C7.20749 13.7545 6.9705 13.9915 6.67816 13.9915H2.69792C2.48383 13.9915 2.29082 13.8626 2.20889 13.6648C2.12696 13.467 2.17224 13.2393 2.32363 13.0879L5.40027 10.0113H2.69792Z",
|
|
1577
|
+
"M5.5165 2.58693C5.23375 1.81542 4.1426 1.81543 3.85985 2.58693L2.13257 7.29995C2.03197 7.57443 2.17294 7.8785 2.44742 7.97909C2.7219 8.07969 3.02596 7.93872 3.12656 7.66424L3.64358 6.25351L3.64516 6.25351H5.73278L6.2498 7.66424C6.35039 7.93872 6.65446 8.07969 6.92894 7.97909C7.20342 7.8785 7.34438 7.57443 7.24379 7.29995L5.5165 2.58693ZM5.34479 5.19487L4.68818 3.40325L4.03156 5.19487H5.34479Z"
|
|
1578
|
+
];
|
|
1579
|
+
|
|
1580
|
+
//#endregion
|
|
1581
|
+
//#region src/views/widgets/table-filter-button.shape.ts
|
|
1582
|
+
const FILTER_ICON_SIZE = 16;
|
|
1583
|
+
let SheetsTableFilterButtonShape = class SheetsTableFilterButtonShape extends _univerjs_engine_render.Shape {
|
|
1584
|
+
constructor(key, props, _contextService, _commandService, _themeService) {
|
|
1585
|
+
super(key, props);
|
|
1586
|
+
this._contextService = _contextService;
|
|
1587
|
+
this._commandService = _commandService;
|
|
1588
|
+
this._themeService = _themeService;
|
|
1589
|
+
_defineProperty(this, "_cellWidth", 0);
|
|
1590
|
+
_defineProperty(this, "_cellHeight", 0);
|
|
1591
|
+
_defineProperty(this, "_filterParams", void 0);
|
|
1592
|
+
_defineProperty(this, "_hovered", false);
|
|
1593
|
+
this.setShapeProps(props);
|
|
1594
|
+
this.onPointerDown$.subscribeEvent((evt) => this.onPointerDown(evt));
|
|
1595
|
+
this.onPointerEnter$.subscribeEvent(() => this.onPointerEnter());
|
|
1596
|
+
this.onPointerLeave$.subscribeEvent(() => this.onPointerLeave());
|
|
1597
|
+
}
|
|
1598
|
+
setShapeProps(props) {
|
|
1599
|
+
if (typeof props.cellHeight !== "undefined") this._cellHeight = props.cellHeight;
|
|
1600
|
+
if (typeof props.cellWidth !== "undefined") this._cellWidth = props.cellWidth;
|
|
1601
|
+
if (typeof props.filterParams !== "undefined") this._filterParams = props.filterParams;
|
|
1602
|
+
this.transformByState({
|
|
1603
|
+
width: props.width,
|
|
1604
|
+
height: props.height
|
|
1605
|
+
});
|
|
1606
|
+
}
|
|
1607
|
+
_draw(ctx) {
|
|
1608
|
+
const cellHeight = this._cellHeight;
|
|
1609
|
+
const cellWidth = this._cellWidth;
|
|
1610
|
+
const left = 16 - cellWidth;
|
|
1611
|
+
const top = 16 - cellHeight;
|
|
1612
|
+
ctx.save();
|
|
1613
|
+
const cellRegion = new Path2D();
|
|
1614
|
+
cellRegion.rect(left, top, cellWidth, cellHeight);
|
|
1615
|
+
ctx.clip(cellRegion);
|
|
1616
|
+
const { buttonState } = this._filterParams;
|
|
1617
|
+
const fgColor = this._themeService.getColorFromTheme("primary.600");
|
|
1618
|
+
const bgColor = this._hovered ? this._themeService.getColorFromTheme("gray.50") : "rgba(255, 255, 255, 1.0)";
|
|
1619
|
+
let icons;
|
|
1620
|
+
switch (buttonState) {
|
|
1621
|
+
case _univerjs_sheets_table.SheetsTableButtonStateEnum.FilteredSortNone:
|
|
1622
|
+
icons = filterPartial;
|
|
1623
|
+
break;
|
|
1624
|
+
case _univerjs_sheets_table.SheetsTableButtonStateEnum.FilteredSortAsc:
|
|
1625
|
+
icons = filteredSortAsc;
|
|
1626
|
+
break;
|
|
1627
|
+
case _univerjs_sheets_table.SheetsTableButtonStateEnum.FilteredSortDesc:
|
|
1628
|
+
icons = filteredSortDesc;
|
|
1629
|
+
break;
|
|
1630
|
+
case _univerjs_sheets_table.SheetsTableButtonStateEnum.FilterNoneSortNone: break;
|
|
1631
|
+
case _univerjs_sheets_table.SheetsTableButtonStateEnum.FilterNoneSortAsc:
|
|
1632
|
+
icons = filterNoneSortAsc;
|
|
1633
|
+
break;
|
|
1634
|
+
case _univerjs_sheets_table.SheetsTableButtonStateEnum.FilterNoneSortDesc:
|
|
1635
|
+
icons = filterNoneSortDesc;
|
|
1636
|
+
break;
|
|
1637
|
+
}
|
|
1638
|
+
if (icons) TableButton.drawIconByPath(ctx, icons, fgColor, bgColor);
|
|
1639
|
+
else if (buttonState !== void 0) TableButton.drawNoSetting(ctx, 16, fgColor, bgColor);
|
|
1640
|
+
ctx.restore();
|
|
1641
|
+
}
|
|
1642
|
+
onPointerDown(evt) {
|
|
1643
|
+
if (evt.button === 2) return;
|
|
1644
|
+
const { row, col, unitId, subUnitId, tableId } = this._filterParams;
|
|
1645
|
+
if (this._contextService.getContextValue("SHEETS_TABLE_FILTER_PANEL_OPENED_KEY") || !this._commandService.hasCommand(OpenTableFilterPanelOperation.id)) return;
|
|
1646
|
+
setTimeout(() => {
|
|
1647
|
+
const cmdParams = {
|
|
1648
|
+
row,
|
|
1649
|
+
col,
|
|
1650
|
+
unitId,
|
|
1651
|
+
subUnitId,
|
|
1652
|
+
tableId
|
|
1653
|
+
};
|
|
1654
|
+
this._commandService.executeCommand(OpenTableFilterPanelOperation.id, cmdParams);
|
|
1655
|
+
}, 200);
|
|
1656
|
+
}
|
|
1657
|
+
onPointerEnter() {
|
|
1658
|
+
this._hovered = true;
|
|
1659
|
+
this.makeDirty(true);
|
|
1660
|
+
}
|
|
1661
|
+
onPointerLeave() {
|
|
1662
|
+
this._hovered = false;
|
|
1663
|
+
this.makeDirty(true);
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
SheetsTableFilterButtonShape = __decorate([
|
|
1667
|
+
__decorateParam(2, _univerjs_core.IContextService),
|
|
1668
|
+
__decorateParam(3, _univerjs_core.ICommandService),
|
|
1669
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_core.ThemeService))
|
|
1670
|
+
], SheetsTableFilterButtonShape);
|
|
1671
|
+
|
|
1672
|
+
//#endregion
|
|
1673
|
+
//#region src/controllers/sheet-table-filter-button-render.controller.ts
|
|
1674
|
+
const SHEETS_FILTER_BUTTON_Z_INDEX = 5e3;
|
|
1675
|
+
const computeIconTop = (startY, endY, cellHeight, verticalAlign) => {
|
|
1676
|
+
switch (verticalAlign) {
|
|
1677
|
+
case _univerjs_core.VerticalAlign.TOP: return startY + 1;
|
|
1678
|
+
case _univerjs_core.VerticalAlign.MIDDLE: return startY + Math.max(0, (cellHeight - 16) / 2);
|
|
1679
|
+
case _univerjs_core.VerticalAlign.BOTTOM:
|
|
1680
|
+
default: return endY - 16 - 1;
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
let SheetsTableFilterButtonRenderController = class SheetsTableFilterButtonRenderController extends _univerjs_core.RxDisposable {
|
|
1684
|
+
constructor(_context, _injector, _sheetSkeletonManagerService, _sheetInterceptorService, _tableManager, _commandService) {
|
|
1685
|
+
super();
|
|
1686
|
+
this._context = _context;
|
|
1687
|
+
this._injector = _injector;
|
|
1688
|
+
this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
|
|
1689
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
1690
|
+
this._tableManager = _tableManager;
|
|
1691
|
+
this._commandService = _commandService;
|
|
1692
|
+
_defineProperty(this, "_buttonRenderDisposable", null);
|
|
1693
|
+
_defineProperty(this, "_tableFilterButtonShapes", []);
|
|
1694
|
+
this._initRenderer();
|
|
1695
|
+
this._initCommandExecuted();
|
|
1696
|
+
}
|
|
1697
|
+
dispose() {
|
|
1698
|
+
super.dispose();
|
|
1699
|
+
this._disposeRendering();
|
|
1700
|
+
}
|
|
1701
|
+
_initRenderer() {
|
|
1702
|
+
const tableManager = this._tableManager;
|
|
1703
|
+
this._sheetSkeletonManagerService.currentSkeleton$.pipe((0, rxjs.switchMap)((skeletonParams) => {
|
|
1704
|
+
var _workbook$getActiveSh;
|
|
1705
|
+
if (!skeletonParams) return (0, rxjs.of)(null);
|
|
1706
|
+
const { unit: workbook, unitId } = this._context;
|
|
1707
|
+
const worksheetId = ((_workbook$getActiveSh = workbook.getActiveSheet()) === null || _workbook$getActiveSh === void 0 ? void 0 : _workbook$getActiveSh.getSheetId()) || "";
|
|
1708
|
+
const getParams = () => ({
|
|
1709
|
+
unitId,
|
|
1710
|
+
worksheetId,
|
|
1711
|
+
tableFilterRanges: this._tableManager.getSheetFilterRangeWithState(workbook.getUnitId(), worksheetId),
|
|
1712
|
+
skeleton: skeletonParams.skeleton
|
|
1713
|
+
});
|
|
1714
|
+
return (0, rxjs.merge)(tableManager.tableAdd$, tableManager.tableNameChanged$, tableManager.tableRangeChanged$, tableManager.tableThemeChanged$, tableManager.tableDelete$, tableManager.tableFilterChanged$).pipe((0, rxjs.map)(() => getParams()), (0, rxjs.startWith)(getParams()));
|
|
1715
|
+
}), (0, rxjs.takeUntil)(this.dispose$)).subscribe((renderParams) => {
|
|
1716
|
+
this._disposeRendering();
|
|
1717
|
+
if (!renderParams || !renderParams.tableFilterRanges) return;
|
|
1718
|
+
this._renderButtons(renderParams);
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
_initCommandExecuted() {
|
|
1722
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1723
|
+
var _workbook$getActiveSh2;
|
|
1724
|
+
if (command.id !== _univerjs_sheets.SetVerticalTextAlignCommand.id) return;
|
|
1725
|
+
const { unit: workbook, unitId } = this._context;
|
|
1726
|
+
const worksheetId = ((_workbook$getActiveSh2 = workbook.getActiveSheet()) === null || _workbook$getActiveSh2 === void 0 ? void 0 : _workbook$getActiveSh2.getSheetId()) || "";
|
|
1727
|
+
const skeleton = this._sheetSkeletonManagerService.getCurrentSkeleton();
|
|
1728
|
+
if (!skeleton) return;
|
|
1729
|
+
const renderParams = {
|
|
1730
|
+
unitId,
|
|
1731
|
+
worksheetId,
|
|
1732
|
+
tableFilterRanges: this._tableManager.getSheetFilterRangeWithState(workbook.getUnitId(), worksheetId),
|
|
1733
|
+
skeleton
|
|
1734
|
+
};
|
|
1735
|
+
this._disposeRendering();
|
|
1736
|
+
if (!renderParams || !renderParams.tableFilterRanges) return;
|
|
1737
|
+
this._renderButtons(renderParams);
|
|
1738
|
+
}));
|
|
1739
|
+
}
|
|
1740
|
+
_renderButtons(params) {
|
|
1741
|
+
const { tableFilterRanges, unitId, skeleton, worksheetId } = params;
|
|
1742
|
+
const { unit: workbook, scene } = this._context;
|
|
1743
|
+
const worksheet = workbook.getSheetBySheetId(worksheetId);
|
|
1744
|
+
if (!worksheet) return;
|
|
1745
|
+
for (const { range, states, tableId } of tableFilterRanges) {
|
|
1746
|
+
const { startRow, startColumn, endColumn } = range;
|
|
1747
|
+
this._interceptCellContent(unitId, worksheetId, range);
|
|
1748
|
+
for (let col = startColumn; col <= endColumn; col++) {
|
|
1749
|
+
const key = `sheets-table-filter-button-${startRow}-${col}`;
|
|
1750
|
+
const startPosition = (0, _univerjs_sheets_ui.getCoordByCell)(startRow, col, scene, skeleton);
|
|
1751
|
+
const cellStyle = worksheet.getCellStyle(startRow, col);
|
|
1752
|
+
const verticalAlign = (cellStyle === null || cellStyle === void 0 ? void 0 : cellStyle.vt) || _univerjs_core.VerticalAlign.BOTTOM;
|
|
1753
|
+
const { startX, startY, endX, endY } = startPosition;
|
|
1754
|
+
const cellWidth = endX - startX;
|
|
1755
|
+
const cellHeight = endY - startY;
|
|
1756
|
+
if (cellHeight <= 1 || cellWidth <= 1) continue;
|
|
1757
|
+
const state = states[col - startColumn];
|
|
1758
|
+
const props = {
|
|
1759
|
+
left: endX - 16 - 1,
|
|
1760
|
+
top: computeIconTop(startY, endY, cellHeight, verticalAlign),
|
|
1761
|
+
height: 16,
|
|
1762
|
+
width: 16,
|
|
1763
|
+
zIndex: SHEETS_FILTER_BUTTON_Z_INDEX,
|
|
1764
|
+
cellHeight,
|
|
1765
|
+
cellWidth,
|
|
1766
|
+
filterParams: {
|
|
1767
|
+
unitId,
|
|
1768
|
+
subUnitId: worksheetId,
|
|
1769
|
+
row: startRow,
|
|
1770
|
+
col,
|
|
1771
|
+
buttonState: state,
|
|
1772
|
+
tableId
|
|
1773
|
+
}
|
|
1774
|
+
};
|
|
1775
|
+
const buttonShape = this._injector.createInstance(SheetsTableFilterButtonShape, key, props);
|
|
1776
|
+
this._tableFilterButtonShapes.push(buttonShape);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
scene.addObjects(this._tableFilterButtonShapes);
|
|
1780
|
+
scene.makeDirty();
|
|
1781
|
+
}
|
|
1782
|
+
_interceptCellContent(workbookId, worksheetId, range) {
|
|
1783
|
+
const { startRow, startColumn, endColumn } = range;
|
|
1784
|
+
this._buttonRenderDisposable = this._sheetInterceptorService.intercept(_univerjs_sheets.INTERCEPTOR_POINT.CELL_CONTENT, {
|
|
1785
|
+
effect: _univerjs_core.InterceptorEffectEnum.Style,
|
|
1786
|
+
handler: (cell, pos, next) => {
|
|
1787
|
+
const { row, col, unitId, subUnitId } = pos;
|
|
1788
|
+
if (unitId !== workbookId || subUnitId !== worksheetId || row !== startRow || col < startColumn || col > endColumn) return next(cell);
|
|
1789
|
+
if (!cell || cell === pos.rawData) cell = { ...pos.rawData };
|
|
1790
|
+
cell.fontRenderExtension = {
|
|
1791
|
+
...cell === null || cell === void 0 ? void 0 : cell.fontRenderExtension,
|
|
1792
|
+
rightOffset: 16
|
|
1793
|
+
};
|
|
1794
|
+
return next(cell);
|
|
1795
|
+
},
|
|
1796
|
+
priority: 10
|
|
1797
|
+
});
|
|
1798
|
+
}
|
|
1799
|
+
_disposeRendering() {
|
|
1800
|
+
var _this$_buttonRenderDi;
|
|
1801
|
+
this._tableFilterButtonShapes.forEach((s) => s.dispose());
|
|
1802
|
+
(_this$_buttonRenderDi = this._buttonRenderDisposable) === null || _this$_buttonRenderDi === void 0 || _this$_buttonRenderDi.dispose();
|
|
1803
|
+
this._buttonRenderDisposable = null;
|
|
1804
|
+
this._tableFilterButtonShapes = [];
|
|
1805
|
+
}
|
|
1806
|
+
};
|
|
1807
|
+
SheetsTableFilterButtonRenderController = __decorate([
|
|
1808
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1809
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService)),
|
|
1810
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
1811
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(_univerjs_sheets_table.TableManager)),
|
|
1812
|
+
__decorateParam(5, _univerjs_core.ICommandService)
|
|
1813
|
+
], SheetsTableFilterButtonRenderController);
|
|
1814
|
+
|
|
1815
|
+
//#endregion
|
|
1816
|
+
//#region src/controllers/sheet-table-render.controller.ts
|
|
1817
|
+
let SheetsTableRenderController = class SheetsTableRenderController extends _univerjs_core.RxDisposable {
|
|
1818
|
+
constructor(_context, _injector, _sheetSkeletonManagerService, _tableManager, _sheetTableThemeUIController) {
|
|
1819
|
+
super();
|
|
1820
|
+
this._context = _context;
|
|
1821
|
+
this._injector = _injector;
|
|
1822
|
+
this._sheetSkeletonManagerService = _sheetSkeletonManagerService;
|
|
1823
|
+
this._tableManager = _tableManager;
|
|
1824
|
+
this._sheetTableThemeUIController = _sheetTableThemeUIController;
|
|
1825
|
+
this._initListener();
|
|
1826
|
+
}
|
|
1827
|
+
_dirtySkeleton() {
|
|
1828
|
+
var _this$_context$mainCo;
|
|
1829
|
+
(_this$_context$mainCo = this._context.mainComponent) === null || _this$_context$mainCo === void 0 || _this$_context$mainCo.makeDirty();
|
|
1830
|
+
const currentParam = this._sheetSkeletonManagerService.getCurrentParam();
|
|
1831
|
+
if (currentParam) {
|
|
1832
|
+
const param = {
|
|
1833
|
+
...currentParam,
|
|
1834
|
+
dirty: true
|
|
1835
|
+
};
|
|
1836
|
+
this._sheetSkeletonManagerService.reCalculate(param);
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
_initListener() {
|
|
1840
|
+
const tableManager = this._tableManager;
|
|
1841
|
+
const dirtySkeleton = this._dirtySkeleton.bind(this);
|
|
1842
|
+
this.disposeWithMe((0, rxjs.merge)(tableManager.tableAdd$, tableManager.tableDelete$, tableManager.tableNameChanged$, tableManager.tableRangeChanged$, tableManager.tableThemeChanged$, tableManager.tableFilterChanged$, tableManager.tableInitStatus$, this._sheetTableThemeUIController.refreshTable$).subscribe(dirtySkeleton));
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
SheetsTableRenderController = __decorate([
|
|
1846
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
1847
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_ui.SheetSkeletonManagerService)),
|
|
1848
|
+
__decorateParam(3, (0, _univerjs_core.Inject)(_univerjs_sheets_table.TableManager)),
|
|
1849
|
+
__decorateParam(4, (0, _univerjs_core.Inject)(SheetTableThemeUIController))
|
|
1850
|
+
], SheetsTableRenderController);
|
|
1851
|
+
|
|
1852
|
+
//#endregion
|
|
1853
|
+
//#region src/controllers/sheet-table-selection.controller.ts
|
|
1854
|
+
let SheetTableSelectionController = class SheetTableSelectionController extends _univerjs_core.Disposable {
|
|
1855
|
+
constructor(_sheetInterceptorService, _univerInstanceService, _tableManager) {
|
|
1856
|
+
super();
|
|
1857
|
+
this._sheetInterceptorService = _sheetInterceptorService;
|
|
1858
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1859
|
+
this._tableManager = _tableManager;
|
|
1860
|
+
this._initSelectionChange();
|
|
1861
|
+
}
|
|
1862
|
+
_initSelectionChange() {
|
|
1863
|
+
this.disposeWithMe(this._sheetInterceptorService.interceptCommand({ getMutations: (command) => {
|
|
1864
|
+
if (command.id === _univerjs_sheets_ui.SelectAllCommand.id) {
|
|
1865
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(this._univerInstanceService);
|
|
1866
|
+
if (!target) return {
|
|
1867
|
+
redos: [],
|
|
1868
|
+
undos: []
|
|
1869
|
+
};
|
|
1870
|
+
const { range } = command.params;
|
|
1871
|
+
const { unitId, subUnitId, worksheet } = target;
|
|
1872
|
+
const overlapTable = this._tableManager.getTablesBySubunitId(unitId, subUnitId).find((table) => {
|
|
1873
|
+
const tableRange = table.getRange();
|
|
1874
|
+
return _univerjs_core.Rectangle.contains(tableRange, range);
|
|
1875
|
+
});
|
|
1876
|
+
if (overlapTable) {
|
|
1877
|
+
const tableRange = overlapTable.getRange();
|
|
1878
|
+
const tableRangeWithoutHeader = {
|
|
1879
|
+
...tableRange,
|
|
1880
|
+
startRow: tableRange.startRow + 1
|
|
1881
|
+
};
|
|
1882
|
+
if (_univerjs_core.Rectangle.equals(tableRange, range)) return {
|
|
1883
|
+
undos: [],
|
|
1884
|
+
redos: []
|
|
1885
|
+
};
|
|
1886
|
+
else if (_univerjs_core.Rectangle.equals(tableRangeWithoutHeader, range)) return {
|
|
1887
|
+
undos: [],
|
|
1888
|
+
redos: [{
|
|
1889
|
+
id: _univerjs_sheets.SetSelectionsOperation.id,
|
|
1890
|
+
params: {
|
|
1891
|
+
unitId,
|
|
1892
|
+
subUnitId,
|
|
1893
|
+
selections: [{
|
|
1894
|
+
range: tableRange,
|
|
1895
|
+
primary: (0, _univerjs_sheets.getPrimaryForRange)(tableRange, worksheet)
|
|
1896
|
+
}]
|
|
1897
|
+
}
|
|
1898
|
+
}]
|
|
1899
|
+
};
|
|
1900
|
+
else return {
|
|
1901
|
+
undos: [],
|
|
1902
|
+
redos: [{
|
|
1903
|
+
id: _univerjs_sheets.SetSelectionsOperation.id,
|
|
1904
|
+
params: {
|
|
1905
|
+
unitId,
|
|
1906
|
+
subUnitId,
|
|
1907
|
+
selections: [{
|
|
1908
|
+
range: tableRangeWithoutHeader,
|
|
1909
|
+
primary: (0, _univerjs_sheets.getPrimaryForRange)(tableRangeWithoutHeader, worksheet)
|
|
1910
|
+
}]
|
|
1911
|
+
}
|
|
1912
|
+
}]
|
|
1913
|
+
};
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return {
|
|
1917
|
+
redos: [],
|
|
1918
|
+
undos: []
|
|
1919
|
+
};
|
|
1920
|
+
} }));
|
|
1921
|
+
}
|
|
1922
|
+
};
|
|
1923
|
+
SheetTableSelectionController = __decorate([
|
|
1924
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_sheets.SheetInterceptorService)),
|
|
1925
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.IUniverInstanceService)),
|
|
1926
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_sheets_table.TableManager))
|
|
1927
|
+
], SheetTableSelectionController);
|
|
1928
|
+
|
|
1929
|
+
//#endregion
|
|
1930
|
+
//#region src/views/components/SheetTableSelector.tsx
|
|
1931
|
+
const SheetTableSelector = (props) => {
|
|
1932
|
+
const { unitId, subUnitId, range, onCancel, onConfirm, tableId } = props;
|
|
1933
|
+
const tableManager = (0, _univerjs_ui.useDependency)(_univerjs_sheets_table.TableManager);
|
|
1934
|
+
const [selectedRange, setSelectedRange] = (0, react.useState)(range);
|
|
1935
|
+
const [rangeError, setRangeError] = (0, react.useState)("");
|
|
1936
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
1937
|
+
const univerInstanceService = (0, _univerjs_ui.useDependency)(_univerjs_core.IUniverInstanceService);
|
|
1938
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
1939
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_sheets_formula_ui.RangeSelector, {
|
|
1940
|
+
maxRangeCount: 1,
|
|
1941
|
+
unitId,
|
|
1942
|
+
subUnitId,
|
|
1943
|
+
initialValue: (0, _univerjs_engine_formula.serializeRange)(range),
|
|
1944
|
+
onChange: (_, text) => {
|
|
1945
|
+
const originValue = (0, _univerjs_engine_formula.serializeRange)(range);
|
|
1946
|
+
const newRange = (0, _univerjs_engine_formula.deserializeRangeWithSheet)(text).range;
|
|
1947
|
+
const target = (0, _univerjs_sheets.getSheetCommandTarget)(univerInstanceService, {
|
|
1948
|
+
unitId,
|
|
1949
|
+
subUnitId
|
|
1950
|
+
});
|
|
1951
|
+
if (!target) return;
|
|
1952
|
+
if (target.worksheet.getMergeData().some((merge) => {
|
|
1953
|
+
return _univerjs_core.Rectangle.intersects(newRange, merge);
|
|
1954
|
+
})) {
|
|
1955
|
+
setRangeError(localeService.t("sheets-table.tableRangeWithMergeError"));
|
|
1956
|
+
return;
|
|
1957
|
+
}
|
|
1958
|
+
if (tableManager.getTablesBySubunitId(unitId, subUnitId).some((table) => {
|
|
1959
|
+
if (table.getId() === tableId) return false;
|
|
1960
|
+
const tableRange = table.getRange();
|
|
1961
|
+
return _univerjs_core.Rectangle.intersects(newRange, tableRange);
|
|
1962
|
+
})) {
|
|
1963
|
+
setRangeError(localeService.t("sheets-table.tableRangeWithOtherTableError"));
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
const { startRow, endRow } = newRange;
|
|
1967
|
+
if (startRow === endRow) {
|
|
1968
|
+
setRangeError(localeService.t("sheets-table.tableRangeSingleRowError"));
|
|
1969
|
+
return;
|
|
1970
|
+
}
|
|
1971
|
+
if (originValue === text) return;
|
|
1972
|
+
if (tableId) {
|
|
1973
|
+
const table = tableManager.getTableById(unitId, tableId);
|
|
1974
|
+
if (table) {
|
|
1975
|
+
const oldRange = table.getRange();
|
|
1976
|
+
if (_univerjs_core.Rectangle.intersects(newRange, oldRange) && oldRange.startRow === newRange.startRow) {
|
|
1977
|
+
setSelectedRange(newRange);
|
|
1978
|
+
setRangeError("");
|
|
1979
|
+
onConfirm({
|
|
1980
|
+
unitId,
|
|
1981
|
+
subUnitId,
|
|
1982
|
+
range: newRange
|
|
1983
|
+
});
|
|
1984
|
+
return;
|
|
1985
|
+
} else {
|
|
1986
|
+
setRangeError(localeService.t("sheets-table.updateError"));
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
setSelectedRange(newRange);
|
|
1992
|
+
setRangeError("");
|
|
1993
|
+
},
|
|
1994
|
+
supportAcrossSheet: false
|
|
1995
|
+
}),
|
|
1996
|
+
rangeError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
1997
|
+
className: "univer-mt-1 univer-text-xs univer-text-red-500",
|
|
1998
|
+
children: rangeError
|
|
1999
|
+
}),
|
|
2000
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2001
|
+
className: "univer-mt-4 univer-flex univer-justify-end",
|
|
2002
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
2003
|
+
onClick: onCancel,
|
|
2004
|
+
children: localeService.t("sheets-table.cancel")
|
|
2005
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Button, {
|
|
2006
|
+
variant: "primary",
|
|
2007
|
+
onClick: () => {
|
|
2008
|
+
if (rangeError) return;
|
|
2009
|
+
onConfirm({
|
|
2010
|
+
unitId,
|
|
2011
|
+
subUnitId,
|
|
2012
|
+
range: selectedRange
|
|
2013
|
+
});
|
|
2014
|
+
},
|
|
2015
|
+
className: "univer-ml-2",
|
|
2016
|
+
children: localeService.t("sheets-table.confirm")
|
|
2017
|
+
})]
|
|
2018
|
+
})
|
|
2019
|
+
] });
|
|
2020
|
+
};
|
|
2021
|
+
|
|
2022
|
+
//#endregion
|
|
2023
|
+
//#region src/views/components/SheetTableThemePanel.tsx
|
|
2024
|
+
const SheetTableThemePanel = (props) => {
|
|
2025
|
+
var _customStyle$getHeade, _customStyle$getHeade2, _customStyle$getFirst, _customStyle$getFirst2, _customStyle$getSecon, _customStyle$getSecon2, _customStyle$getLastR, _customStyle$getLastR2;
|
|
2026
|
+
const { unitId, subUnitId, tableId } = props;
|
|
2027
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
2028
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2029
|
+
const tableManager = (0, _univerjs_ui.useDependency)(_univerjs_sheets_table.TableManager);
|
|
2030
|
+
const table = tableManager.getTableById(unitId, tableId);
|
|
2031
|
+
const rangeThemeModel = (0, _univerjs_ui.useDependency)(_univerjs_sheets.SheetRangeThemeModel);
|
|
2032
|
+
const sheetTableThemeUIController = (0, _univerjs_ui.useDependency)(SheetTableThemeUIController);
|
|
2033
|
+
const rangeThemeMapChanged = (0, _univerjs_ui.useObservable)(rangeThemeModel.rangeThemeMapChange$);
|
|
2034
|
+
const tableRefresh = (0, _univerjs_ui.useObservable)(sheetTableThemeUIController.refreshTable$);
|
|
2035
|
+
const errorService = (0, _univerjs_ui.useDependency)(_univerjs_core.ErrorService);
|
|
2036
|
+
const [, setRefresh] = (0, react.useState)(Math.random());
|
|
2037
|
+
const themeConfig = (0, _univerjs_ui.useObservable)(tableManager.tableThemeChanged$, {
|
|
2038
|
+
theme: table === null || table === void 0 ? void 0 : table.getTableStyleId(),
|
|
2039
|
+
oldTheme: table === null || table === void 0 ? void 0 : table.getTableStyleId(),
|
|
2040
|
+
unitId,
|
|
2041
|
+
subUnitId,
|
|
2042
|
+
tableId
|
|
2043
|
+
});
|
|
2044
|
+
const defaultRangeThemes = rangeThemeModel.getRegisteredRangeThemes().filter((item) => item === null || item === void 0 ? void 0 : item.startsWith(TABLE_DEFAULT_NAME_PREFIX));
|
|
2045
|
+
const customRangeThemes = rangeThemeModel.getALLRegisteredTheme(unitId).filter((item) => item === null || item === void 0 ? void 0 : item.startsWith(TABLE_CUSTOM_NAME_PREFIX));
|
|
2046
|
+
const selectedTheme = table === null || table === void 0 ? void 0 : table.getTableStyleId();
|
|
2047
|
+
const customSelected = customRangeThemes.find((item) => item === selectedTheme);
|
|
2048
|
+
const customStyleName = customSelected || customRangeThemes[0];
|
|
2049
|
+
const customStyle = rangeThemeModel.getCustomRangeThemeStyle(unitId, customStyleName);
|
|
2050
|
+
const headerBg = (_customStyle$getHeade = customStyle === null || customStyle === void 0 || (_customStyle$getHeade2 = customStyle.getHeaderRowStyle()) === null || _customStyle$getHeade2 === void 0 || (_customStyle$getHeade2 = _customStyle$getHeade2.bg) === null || _customStyle$getHeade2 === void 0 ? void 0 : _customStyle$getHeade2.rgb) !== null && _customStyle$getHeade !== void 0 ? _customStyle$getHeade : TABLE_DEFAULT_BG_COLOR;
|
|
2051
|
+
const firstRowBg = (_customStyle$getFirst = customStyle === null || customStyle === void 0 || (_customStyle$getFirst2 = customStyle.getFirstRowStyle()) === null || _customStyle$getFirst2 === void 0 || (_customStyle$getFirst2 = _customStyle$getFirst2.bg) === null || _customStyle$getFirst2 === void 0 ? void 0 : _customStyle$getFirst2.rgb) !== null && _customStyle$getFirst !== void 0 ? _customStyle$getFirst : TABLE_DEFAULT_BG_COLOR;
|
|
2052
|
+
const secondRowBg = (_customStyle$getSecon = customStyle === null || customStyle === void 0 || (_customStyle$getSecon2 = customStyle.getSecondRowStyle()) === null || _customStyle$getSecon2 === void 0 || (_customStyle$getSecon2 = _customStyle$getSecon2.bg) === null || _customStyle$getSecon2 === void 0 ? void 0 : _customStyle$getSecon2.rgb) !== null && _customStyle$getSecon !== void 0 ? _customStyle$getSecon : TABLE_DEFAULT_BG_COLOR;
|
|
2053
|
+
const lastRowBg = (_customStyle$getLastR = customStyle === null || customStyle === void 0 || (_customStyle$getLastR2 = customStyle.getLastRowStyle()) === null || _customStyle$getLastR2 === void 0 || (_customStyle$getLastR2 = _customStyle$getLastR2.bg) === null || _customStyle$getLastR2 === void 0 ? void 0 : _customStyle$getLastR2.rgb) !== null && _customStyle$getLastR !== void 0 ? _customStyle$getLastR : TABLE_DEFAULT_BG_COLOR;
|
|
2054
|
+
const [hoverCustomId, setHoverCustomId] = (0, react.useState)(null);
|
|
2055
|
+
const handleThemeChange = (theme) => {
|
|
2056
|
+
commandService.executeCommand(_univerjs_sheets_table.SetSheetTableCommand.id, {
|
|
2057
|
+
unitId,
|
|
2058
|
+
tableId,
|
|
2059
|
+
theme
|
|
2060
|
+
});
|
|
2061
|
+
};
|
|
2062
|
+
const handleAddCustomTheme = () => {
|
|
2063
|
+
if (customRangeThemes.length >= 11) {
|
|
2064
|
+
errorService.emit(localeService.t("sheets-table.customTooMore"));
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
const lastCustomTheme = customRangeThemes[customRangeThemes.length - 1];
|
|
2068
|
+
let newThemeName = `${TABLE_CUSTOM_NAME_PREFIX}1`;
|
|
2069
|
+
if (lastCustomTheme) newThemeName = `${TABLE_CUSTOM_NAME_PREFIX}${Number(lastCustomTheme.split("-")[2]) + 1}`;
|
|
2070
|
+
const newTheme = new _univerjs_sheets.RangeThemeStyle(newThemeName, { ..._univerjs_sheets_table.customEmptyThemeWithBorderStyle });
|
|
2071
|
+
commandService.executeCommand(_univerjs_sheets_table.AddTableThemeCommand.id, {
|
|
2072
|
+
unitId,
|
|
2073
|
+
tableId,
|
|
2074
|
+
themeStyle: newTheme
|
|
2075
|
+
});
|
|
2076
|
+
};
|
|
2077
|
+
const setCustomTheme = (themeName, tableThemeStyle) => {
|
|
2078
|
+
commandService.executeCommand(_univerjs_sheets.SetRangeThemeMutation.id, {
|
|
2079
|
+
unitId,
|
|
2080
|
+
subUnitId,
|
|
2081
|
+
styleName: themeName,
|
|
2082
|
+
style: tableThemeStyle
|
|
2083
|
+
});
|
|
2084
|
+
};
|
|
2085
|
+
const removeCustomTheme = (themeName) => {
|
|
2086
|
+
commandService.executeCommand(_univerjs_sheets_table.RemoveTableThemeCommand.id, {
|
|
2087
|
+
unitId,
|
|
2088
|
+
tableId,
|
|
2089
|
+
themeName
|
|
2090
|
+
});
|
|
2091
|
+
};
|
|
2092
|
+
(0, react.useEffect)(() => {
|
|
2093
|
+
setRefresh(Math.random());
|
|
2094
|
+
}, [rangeThemeMapChanged, tableRefresh]);
|
|
2095
|
+
if (!table) return null;
|
|
2096
|
+
const headerBgIsDark = new _univerjs_core.ColorKit(headerBg).isDark();
|
|
2097
|
+
const firstRowBgIsDark = new _univerjs_core.ColorKit(firstRowBg).isDark();
|
|
2098
|
+
const secondRowBgIsDark = new _univerjs_core.ColorKit(secondRowBg).isDark();
|
|
2099
|
+
const lastRowBgIsDark = new _univerjs_core.ColorKit(lastRowBg).isDark();
|
|
2100
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [
|
|
2101
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h5", { children: localeService.t("sheets-table.defaultStyle") }),
|
|
2102
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2103
|
+
className: "univer-flex univer-gap-2",
|
|
2104
|
+
children: defaultRangeThemes.map((item) => {
|
|
2105
|
+
var _rangeThemeItem$getHe, _rangeThemeItem$getFi, _rangeThemeItem$getSe, _rangeThemeItem$getLa;
|
|
2106
|
+
const rangeThemeItem = rangeThemeModel.getDefaultRangeThemeStyle(item);
|
|
2107
|
+
const headerRowBg = (rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getHe = rangeThemeItem.getHeaderRowStyle()) === null || _rangeThemeItem$getHe === void 0 || (_rangeThemeItem$getHe = _rangeThemeItem$getHe.bg) === null || _rangeThemeItem$getHe === void 0 ? void 0 : _rangeThemeItem$getHe.rgb) || "rgb(255, 255, 255)";
|
|
2108
|
+
const firstRowBg = (rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getFi = rangeThemeItem.getFirstRowStyle()) === null || _rangeThemeItem$getFi === void 0 || (_rangeThemeItem$getFi = _rangeThemeItem$getFi.bg) === null || _rangeThemeItem$getFi === void 0 ? void 0 : _rangeThemeItem$getFi.rgb) || "rgb(255, 255, 255)";
|
|
2109
|
+
const secondRowBg = (rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getSe = rangeThemeItem.getSecondRowStyle()) === null || _rangeThemeItem$getSe === void 0 || (_rangeThemeItem$getSe = _rangeThemeItem$getSe.bg) === null || _rangeThemeItem$getSe === void 0 ? void 0 : _rangeThemeItem$getSe.rgb) || "rgb(255, 255, 255)";
|
|
2110
|
+
const lastRowBg = (rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getLa = rangeThemeItem.getLastRowStyle()) === null || _rangeThemeItem$getLa === void 0 || (_rangeThemeItem$getLa = _rangeThemeItem$getLa.bg) === null || _rangeThemeItem$getLa === void 0 ? void 0 : _rangeThemeItem$getLa.rgb) || "rgb(255, 255, 255)";
|
|
2111
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2112
|
+
className: (0, _univerjs_design.clsx)("univer-h-10 univer-w-8 univer-cursor-pointer univer-border univer-border-solid univer-border-gray-200 univer-p-px [&>div]:univer-box-border [&>div]:univer-h-2.5", { "univer-border-blue-500": item === themeConfig.theme }),
|
|
2113
|
+
onClick: () => handleThemeChange(item),
|
|
2114
|
+
children: [
|
|
2115
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
2116
|
+
background: headerRowBg,
|
|
2117
|
+
border: `${headerRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2118
|
+
} }),
|
|
2119
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
2120
|
+
background: firstRowBg,
|
|
2121
|
+
border: `${firstRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2122
|
+
} }),
|
|
2123
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
2124
|
+
background: secondRowBg,
|
|
2125
|
+
border: `${secondRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2126
|
+
} }),
|
|
2127
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: {
|
|
2128
|
+
background: lastRowBg,
|
|
2129
|
+
border: `${lastRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2130
|
+
} })
|
|
2131
|
+
]
|
|
2132
|
+
}, item);
|
|
2133
|
+
})
|
|
2134
|
+
}),
|
|
2135
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h5", { children: localeService.t("sheets-table.customStyle") }),
|
|
2136
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2137
|
+
className: (0, _univerjs_design.clsx)("univer-w-full univer-rounded-sm", _univerjs_design.borderClassName),
|
|
2138
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2139
|
+
className: "univer-flex univer-flex-wrap univer-gap-2 univer-p-2",
|
|
2140
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2141
|
+
className: (0, _univerjs_design.clsx)("univer-h-10 univer-w-8 univer-cursor-pointer univer-p-px univer-text-center univer-leading-10", _univerjs_design.borderClassName),
|
|
2142
|
+
onClick: handleAddCustomTheme,
|
|
2143
|
+
children: "+"
|
|
2144
|
+
}), customRangeThemes.map((item) => {
|
|
2145
|
+
var _rangeThemeItem$getHe2, _rangeThemeItem$getFi2, _rangeThemeItem$getSe2, _rangeThemeItem$getLa2;
|
|
2146
|
+
const rangeThemeItem = rangeThemeModel.getCustomRangeThemeStyle(unitId, item);
|
|
2147
|
+
const headerRowBg = rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getHe2 = rangeThemeItem.getHeaderRowStyle()) === null || _rangeThemeItem$getHe2 === void 0 || (_rangeThemeItem$getHe2 = _rangeThemeItem$getHe2.bg) === null || _rangeThemeItem$getHe2 === void 0 ? void 0 : _rangeThemeItem$getHe2.rgb;
|
|
2148
|
+
const firstRowBg = rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getFi2 = rangeThemeItem.getFirstRowStyle()) === null || _rangeThemeItem$getFi2 === void 0 || (_rangeThemeItem$getFi2 = _rangeThemeItem$getFi2.bg) === null || _rangeThemeItem$getFi2 === void 0 ? void 0 : _rangeThemeItem$getFi2.rgb;
|
|
2149
|
+
const secondRowBg = rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getSe2 = rangeThemeItem.getSecondRowStyle()) === null || _rangeThemeItem$getSe2 === void 0 || (_rangeThemeItem$getSe2 = _rangeThemeItem$getSe2.bg) === null || _rangeThemeItem$getSe2 === void 0 ? void 0 : _rangeThemeItem$getSe2.rgb;
|
|
2150
|
+
const lastRowBg = rangeThemeItem === null || rangeThemeItem === void 0 || (_rangeThemeItem$getLa2 = rangeThemeItem.getLastRowStyle()) === null || _rangeThemeItem$getLa2 === void 0 || (_rangeThemeItem$getLa2 = _rangeThemeItem$getLa2.bg) === null || _rangeThemeItem$getLa2 === void 0 ? void 0 : _rangeThemeItem$getLa2.rgb;
|
|
2151
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2152
|
+
className: (0, _univerjs_design.clsx)("univer-relative univer-h-10 univer-w-8 univer-cursor-pointer univer-border univer-border-solid univer-border-gray-200 univer-p-px", { "univer-border-blue-500": item === themeConfig.theme }),
|
|
2153
|
+
onClick: () => handleThemeChange(item),
|
|
2154
|
+
onMouseEnter: () => setHoverCustomId(item),
|
|
2155
|
+
onMouseLeave: () => setHoverCustomId(null),
|
|
2156
|
+
children: [
|
|
2157
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2158
|
+
className: "univer-box-border univer-h-2.5",
|
|
2159
|
+
style: {
|
|
2160
|
+
background: headerRowBg !== null && headerRowBg !== void 0 ? headerRowBg : TABLE_BORDER_NONE,
|
|
2161
|
+
border: `${headerRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2162
|
+
}
|
|
2163
|
+
}),
|
|
2164
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2165
|
+
className: "univer-box-border univer-h-2.5",
|
|
2166
|
+
style: {
|
|
2167
|
+
background: firstRowBg !== null && firstRowBg !== void 0 ? firstRowBg : TABLE_BORDER_NONE,
|
|
2168
|
+
border: `${firstRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2169
|
+
}
|
|
2170
|
+
}),
|
|
2171
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2172
|
+
className: "univer-box-border univer-h-2.5",
|
|
2173
|
+
style: {
|
|
2174
|
+
background: secondRowBg !== null && secondRowBg !== void 0 ? secondRowBg : TABLE_BORDER_NONE,
|
|
2175
|
+
border: `${secondRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2176
|
+
}
|
|
2177
|
+
}),
|
|
2178
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2179
|
+
className: "univer-box-border univer-h-2.5",
|
|
2180
|
+
style: {
|
|
2181
|
+
background: lastRowBg !== null && lastRowBg !== void 0 ? lastRowBg : TABLE_BORDER_NONE,
|
|
2182
|
+
border: `${lastRowBg ? TABLE_BORDER_NONE : TABLE_BORDER_DEFAULT}`
|
|
2183
|
+
}
|
|
2184
|
+
}),
|
|
2185
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2186
|
+
className: "univer-absolute univer-right-[-3px] univer-top-[-3px] univer-size-3 univer-rounded-md univer-bg-gray-200 univer-text-center univer-text-xs univer-leading-[10px]",
|
|
2187
|
+
style: { display: hoverCustomId === item ? "block" : "none" },
|
|
2188
|
+
onClick: (e) => {
|
|
2189
|
+
e.stopPropagation();
|
|
2190
|
+
removeCustomTheme(item);
|
|
2191
|
+
},
|
|
2192
|
+
children: "x"
|
|
2193
|
+
})
|
|
2194
|
+
]
|
|
2195
|
+
}, item);
|
|
2196
|
+
})]
|
|
2197
|
+
}), customSelected && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { className: "univer-h-px univer-w-full univer-bg-gray-200" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2198
|
+
className: "univer-flex univer-flex-col univer-gap-2 univer-p-2",
|
|
2199
|
+
children: [
|
|
2200
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2201
|
+
className: "univer-flex univer-h-9 univer-gap-2",
|
|
2202
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2203
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9", _univerjs_design.borderClassName, {
|
|
2204
|
+
"univer-text-white": headerBgIsDark,
|
|
2205
|
+
"univer-text-gray-900": !headerBgIsDark
|
|
2206
|
+
}),
|
|
2207
|
+
style: { background: headerBg },
|
|
2208
|
+
children: localeService.t("sheets-table.header")
|
|
2209
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
2210
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2211
|
+
className: "univer-p-2",
|
|
2212
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.ColorPicker, {
|
|
2213
|
+
value: headerBg,
|
|
2214
|
+
onChange: (val) => {
|
|
2215
|
+
const headerRowStyle = (0, _univerjs_sheets_table.processStyleWithBorderStyle)("headerRowStyle", {
|
|
2216
|
+
bg: { rgb: val },
|
|
2217
|
+
cl: { rgb: new _univerjs_core.ColorKit(val).isDark() ? "#fff" : "#000" }
|
|
2218
|
+
});
|
|
2219
|
+
setCustomTheme(table.getTableStyleId(), { headerRowStyle });
|
|
2220
|
+
}
|
|
2221
|
+
})
|
|
2222
|
+
}),
|
|
2223
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2224
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1", _univerjs_design.borderClassName),
|
|
2225
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2226
|
+
className: (0, _univerjs_design.clsx)("univer-size-4 univer-rounded-lg univer-bg-gray-400", _univerjs_design.borderClassName, {
|
|
2227
|
+
"univer-text-white": headerBgIsDark,
|
|
2228
|
+
"univer-text-gray-900": !headerBgIsDark
|
|
2229
|
+
}),
|
|
2230
|
+
style: { background: headerBg }
|
|
2231
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DropdownIcon, { className: "univer-size-2" })]
|
|
2232
|
+
})
|
|
2233
|
+
})]
|
|
2234
|
+
}),
|
|
2235
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2236
|
+
className: "univer-flex univer-h-9 univer-gap-2",
|
|
2237
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2238
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9", _univerjs_design.borderClassName, {
|
|
2239
|
+
"univer-text-white": firstRowBgIsDark,
|
|
2240
|
+
"univer-text-gray-900": !firstRowBgIsDark
|
|
2241
|
+
}),
|
|
2242
|
+
style: { background: firstRowBg },
|
|
2243
|
+
children: localeService.t("sheets-table.firstLine")
|
|
2244
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
2245
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2246
|
+
className: "univer-p-2",
|
|
2247
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.ColorPicker, {
|
|
2248
|
+
value: firstRowBg,
|
|
2249
|
+
onChange: (val) => {
|
|
2250
|
+
setCustomTheme(table.getTableStyleId(), { firstRowStyle: {
|
|
2251
|
+
bg: { rgb: val },
|
|
2252
|
+
cl: { rgb: new _univerjs_core.ColorKit(val).isDark() ? "#fff" : "#000" }
|
|
2253
|
+
} });
|
|
2254
|
+
}
|
|
2255
|
+
})
|
|
2256
|
+
}),
|
|
2257
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2258
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1", _univerjs_design.borderClassName),
|
|
2259
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2260
|
+
className: (0, _univerjs_design.clsx)("univer-size-4 univer-rounded-lg univer-bg-gray-400", _univerjs_design.borderClassName),
|
|
2261
|
+
style: { background: firstRowBg }
|
|
2262
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DropdownIcon, { className: "univer-size-2" })]
|
|
2263
|
+
})
|
|
2264
|
+
})]
|
|
2265
|
+
}),
|
|
2266
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2267
|
+
className: "univer-flex univer-h-9 univer-gap-2",
|
|
2268
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2269
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9", _univerjs_design.borderClassName, {
|
|
2270
|
+
"univer-text-white": secondRowBgIsDark,
|
|
2271
|
+
"univer-text-gray-900": !secondRowBgIsDark
|
|
2272
|
+
}),
|
|
2273
|
+
style: { background: secondRowBg },
|
|
2274
|
+
children: localeService.t("sheets-table.secondLine")
|
|
2275
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
2276
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2277
|
+
className: "univer-p-2",
|
|
2278
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.ColorPicker, {
|
|
2279
|
+
value: secondRowBg,
|
|
2280
|
+
onChange: (val) => setCustomTheme(table.getTableStyleId(), { secondRowStyle: {
|
|
2281
|
+
bg: { rgb: val },
|
|
2282
|
+
cl: { rgb: new _univerjs_core.ColorKit(val).isDark() ? "#fff" : "#000" }
|
|
2283
|
+
} })
|
|
2284
|
+
})
|
|
2285
|
+
}),
|
|
2286
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2287
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1", _univerjs_design.borderClassName),
|
|
2288
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2289
|
+
className: (0, _univerjs_design.clsx)("univer-size-4 univer-rounded-lg univer-bg-gray-400", _univerjs_design.borderClassName),
|
|
2290
|
+
style: { background: secondRowBg }
|
|
2291
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DropdownIcon, { className: "univer-size-2" })]
|
|
2292
|
+
})
|
|
2293
|
+
})]
|
|
2294
|
+
}),
|
|
2295
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2296
|
+
className: "univer-flex univer-h-9 univer-gap-2",
|
|
2297
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2298
|
+
className: (0, _univerjs_design.clsx)("univer-box-border univer-h-full univer-w-52 univer-rounded-sm univer-text-center univer-leading-9", _univerjs_design.borderClassName, {
|
|
2299
|
+
"univer-text-white": lastRowBgIsDark,
|
|
2300
|
+
"univer-text-gray-900": !lastRowBgIsDark
|
|
2301
|
+
}),
|
|
2302
|
+
style: { background: lastRowBg },
|
|
2303
|
+
children: localeService.t("sheets-table.footer")
|
|
2304
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Dropdown, {
|
|
2305
|
+
overlay: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2306
|
+
className: "univer-p-2",
|
|
2307
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.ColorPicker, {
|
|
2308
|
+
value: lastRowBg,
|
|
2309
|
+
onChange: (val) => {
|
|
2310
|
+
const lastRowStyle = (0, _univerjs_sheets_table.processStyleWithBorderStyle)("lastRowStyle", {
|
|
2311
|
+
bg: { rgb: val },
|
|
2312
|
+
cl: { rgb: new _univerjs_core.ColorKit(val).isDark() ? "#fff" : "#000" }
|
|
2313
|
+
});
|
|
2314
|
+
setCustomTheme(table.getTableStyleId(), { lastRowStyle });
|
|
2315
|
+
}
|
|
2316
|
+
})
|
|
2317
|
+
}),
|
|
2318
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2319
|
+
className: (0, _univerjs_design.clsx)("univer-flex univer-cursor-pointer univer-items-center univer-gap-2 univer-rounded-sm univer-bg-white univer-p-1", _univerjs_design.borderClassName),
|
|
2320
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2321
|
+
className: (0, _univerjs_design.clsx)("univer-size-4 univer-rounded-lg univer-bg-gray-400", _univerjs_design.borderClassName),
|
|
2322
|
+
style: { background: lastRowBg }
|
|
2323
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.DropdownIcon, { className: "univer-size-2" })]
|
|
2324
|
+
})
|
|
2325
|
+
})]
|
|
2326
|
+
})
|
|
2327
|
+
]
|
|
2328
|
+
})] })]
|
|
2329
|
+
})
|
|
2330
|
+
] });
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
//#endregion
|
|
2334
|
+
//#region src/menu/menu.ts
|
|
2335
|
+
const SHEET_TABLE_CONTEXT_INSERT_MENU_ID = "sheet.table.context-insert_menu-id";
|
|
2336
|
+
const SHEET_TABLE_CONTEXT_REMOVE_MENU_ID = "sheet.table.context-remove_menu-id";
|
|
2337
|
+
function sheetTableToolbarInsertMenuFactory(accessor) {
|
|
2338
|
+
return {
|
|
2339
|
+
id: OpenTableSelectorOperation.id,
|
|
2340
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
2341
|
+
icon: TABLE_TOOLBAR_BUTTON,
|
|
2342
|
+
tooltip: "sheets-table.title",
|
|
2343
|
+
title: "sheets-table.title",
|
|
2344
|
+
hidden$: (0, _univerjs_ui.getMenuHiddenObservable)(accessor, _univerjs_core.UniverInstanceType.UNIVER_SHEET),
|
|
2345
|
+
disabled$: (0, _univerjs_sheets_ui.getCurrentRangeDisable$)(accessor, {}, true)
|
|
2346
|
+
};
|
|
2347
|
+
}
|
|
2348
|
+
function SheetTableInsertContextMenuFactory(accessor) {
|
|
2349
|
+
return {
|
|
2350
|
+
id: SHEET_TABLE_CONTEXT_INSERT_MENU_ID,
|
|
2351
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
2352
|
+
icon: "InsertDoubleIcon",
|
|
2353
|
+
title: "sheets-table.insert.main",
|
|
2354
|
+
hidden$: getSheetTableRowColOperationHidden$(accessor)
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
function SheetTableRemoveContextMenuFactory(accessor) {
|
|
2358
|
+
return {
|
|
2359
|
+
id: SHEET_TABLE_CONTEXT_REMOVE_MENU_ID,
|
|
2360
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
2361
|
+
icon: "ReduceDoubleIcon",
|
|
2362
|
+
title: "sheets-table.remove.main",
|
|
2363
|
+
hidden$: getSheetTableRowColOperationHidden$(accessor)
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
function SheetTableInsertRowMenuFactory(accessor) {
|
|
2367
|
+
return {
|
|
2368
|
+
id: _univerjs_sheets_table.SheetTableInsertRowCommand.id,
|
|
2369
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
2370
|
+
title: "sheets-table.insert.row",
|
|
2371
|
+
hidden$: getSheetTableHeaderOperationHidden$(accessor)
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
function SheetTableInsertColMenuFactory(accessor) {
|
|
2375
|
+
return {
|
|
2376
|
+
id: _univerjs_sheets_table.SheetTableInsertColCommand.id,
|
|
2377
|
+
title: "sheets-table.insert.col",
|
|
2378
|
+
type: _univerjs_ui.MenuItemType.BUTTON
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
function SheetTableRemoveRowMenuFactory(accessor) {
|
|
2382
|
+
return {
|
|
2383
|
+
id: _univerjs_sheets_table.SheetTableRemoveRowCommand.id,
|
|
2384
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
2385
|
+
title: "sheets-table.remove.row",
|
|
2386
|
+
hidden$: getSheetTableHeaderOperationHidden$(accessor)
|
|
2387
|
+
};
|
|
2388
|
+
}
|
|
2389
|
+
function SheetTableRemoveColMenuFactory(accessor) {
|
|
2390
|
+
return {
|
|
2391
|
+
id: _univerjs_sheets_table.SheetTableRemoveColCommand.id,
|
|
2392
|
+
title: "sheets-table.remove.col",
|
|
2393
|
+
type: _univerjs_ui.MenuItemType.BUTTON
|
|
2394
|
+
};
|
|
2395
|
+
}
|
|
2396
|
+
function getSheetTableRowColOperationHidden$(accessor) {
|
|
2397
|
+
const sheetsSelectionsService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
2398
|
+
return accessor.get(_univerjs_core.IUniverInstanceService).getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => {
|
|
2399
|
+
if (!workbook) return (0, rxjs.of)(true);
|
|
2400
|
+
return workbook.activeSheet$.pipe((0, rxjs.switchMap)((sheet) => {
|
|
2401
|
+
if (!sheet) return (0, rxjs.of)(true);
|
|
2402
|
+
return sheetsSelectionsService.selectionMoveEnd$.pipe((0, rxjs.switchMap)((selections) => {
|
|
2403
|
+
if (!selections.length || selections.length > 1) return (0, rxjs.of)(true);
|
|
2404
|
+
const range = selections[0].range;
|
|
2405
|
+
return (0, rxjs.of)(!accessor.get(_univerjs_sheets_table.SheetsTableController).getContainerTableWithRange(workbook.getUnitId(), sheet.getSheetId(), range));
|
|
2406
|
+
}));
|
|
2407
|
+
}));
|
|
2408
|
+
}));
|
|
2409
|
+
}
|
|
2410
|
+
function getSheetTableHeaderOperationHidden$(accessor) {
|
|
2411
|
+
const sheetsSelectionsService = accessor.get(_univerjs_sheets.SheetsSelectionsService);
|
|
2412
|
+
return accessor.get(_univerjs_core.IUniverInstanceService).getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => {
|
|
2413
|
+
if (!workbook) return (0, rxjs.of)(true);
|
|
2414
|
+
return workbook.activeSheet$.pipe((0, rxjs.switchMap)((sheet) => {
|
|
2415
|
+
if (!sheet) return (0, rxjs.of)(true);
|
|
2416
|
+
return sheetsSelectionsService.selectionMoveEnd$.pipe((0, rxjs.switchMap)((selections) => {
|
|
2417
|
+
if (!selections.length || selections.length > 1) return (0, rxjs.of)(true);
|
|
2418
|
+
const range = selections[0].range;
|
|
2419
|
+
const isInTable = accessor.get(_univerjs_sheets_table.SheetsTableController).getContainerTableWithRange(workbook.getUnitId(), sheet.getSheetId(), range);
|
|
2420
|
+
if (!isInTable) return (0, rxjs.of)(true);
|
|
2421
|
+
const tableRange = isInTable.getRange();
|
|
2422
|
+
if (range.startRow === tableRange.startRow) return (0, rxjs.of)(true);
|
|
2423
|
+
return (0, rxjs.of)(false);
|
|
2424
|
+
}));
|
|
2425
|
+
}));
|
|
2426
|
+
}));
|
|
2427
|
+
}
|
|
2428
|
+
|
|
2429
|
+
//#endregion
|
|
2430
|
+
//#region src/menu/schema.ts
|
|
2431
|
+
const menuSchema = {
|
|
2432
|
+
[_univerjs_ui.RibbonDataGroup.ORGANIZATION]: { [OpenTableSelectorOperation.id]: {
|
|
2433
|
+
order: 0,
|
|
2434
|
+
menuItemFactory: sheetTableToolbarInsertMenuFactory
|
|
2435
|
+
} },
|
|
2436
|
+
[_univerjs_ui.ContextMenuPosition.MAIN_AREA]: { [_univerjs_ui.ContextMenuGroup.LAYOUT]: {
|
|
2437
|
+
[SHEET_TABLE_CONTEXT_INSERT_MENU_ID]: {
|
|
2438
|
+
order: 5,
|
|
2439
|
+
menuItemFactory: SheetTableInsertContextMenuFactory,
|
|
2440
|
+
[_univerjs_sheets_table.SheetTableInsertRowCommand.id]: {
|
|
2441
|
+
order: 1,
|
|
2442
|
+
menuItemFactory: SheetTableInsertRowMenuFactory
|
|
2443
|
+
},
|
|
2444
|
+
[_univerjs_sheets_table.SheetTableInsertColCommand.id]: {
|
|
2445
|
+
order: 2,
|
|
2446
|
+
menuItemFactory: SheetTableInsertColMenuFactory
|
|
2447
|
+
}
|
|
2448
|
+
},
|
|
2449
|
+
[SHEET_TABLE_CONTEXT_REMOVE_MENU_ID]: {
|
|
2450
|
+
order: 6,
|
|
2451
|
+
menuItemFactory: SheetTableRemoveContextMenuFactory,
|
|
2452
|
+
[_univerjs_sheets_table.SheetTableRemoveRowCommand.id]: {
|
|
2453
|
+
order: 1,
|
|
2454
|
+
menuItemFactory: SheetTableRemoveRowMenuFactory
|
|
2455
|
+
},
|
|
2456
|
+
[_univerjs_sheets_table.SheetTableRemoveColCommand.id]: {
|
|
2457
|
+
order: 2,
|
|
2458
|
+
menuItemFactory: SheetTableRemoveColMenuFactory
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
} }
|
|
2462
|
+
};
|
|
2463
|
+
|
|
2464
|
+
//#endregion
|
|
2465
|
+
//#region src/menu/sheet-table-menu.controller.ts
|
|
2466
|
+
/**
|
|
2467
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
2468
|
+
*
|
|
2469
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
2470
|
+
* you may not use this file except in compliance with the License.
|
|
2471
|
+
* You may obtain a copy of the License at
|
|
2472
|
+
*
|
|
2473
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
2474
|
+
*
|
|
2475
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
2476
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
2477
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
2478
|
+
* See the License for the specific language governing permissions and
|
|
2479
|
+
* limitations under the License.
|
|
2480
|
+
*/
|
|
2481
|
+
let SheetTableMenuController = class SheetTableMenuController extends _univerjs_core.Disposable {
|
|
2482
|
+
constructor(_componentManager, _menuManagerService) {
|
|
2483
|
+
super();
|
|
2484
|
+
this._componentManager = _componentManager;
|
|
2485
|
+
this._menuManagerService = _menuManagerService;
|
|
2486
|
+
this._initComponents();
|
|
2487
|
+
this._initMenu();
|
|
2488
|
+
}
|
|
2489
|
+
_initComponents() {
|
|
2490
|
+
[
|
|
2491
|
+
[TABLE_TOOLBAR_BUTTON, _univerjs_icons.TableIcon],
|
|
2492
|
+
[TABLE_SELECTOR_DIALOG, SheetTableSelector],
|
|
2493
|
+
[SHEET_TABLE_THEME_PANEL, SheetTableThemePanel]
|
|
2494
|
+
].forEach(([key, comp]) => {
|
|
2495
|
+
this.disposeWithMe(this._componentManager.register(key, comp));
|
|
2496
|
+
});
|
|
2497
|
+
}
|
|
2498
|
+
_initMenu() {
|
|
2499
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
2500
|
+
}
|
|
2501
|
+
};
|
|
2502
|
+
SheetTableMenuController = __decorate([__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)), __decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_ui.IMenuManagerService))], SheetTableMenuController);
|
|
2503
|
+
|
|
2504
|
+
//#endregion
|
|
2505
|
+
//#region src/plugin.ts
|
|
2506
|
+
let UniverSheetsTableUIPlugin = class UniverSheetsTableUIPlugin extends _univerjs_core.Plugin {
|
|
2507
|
+
constructor(_config = defaultPluginConfig, _injector, _commandService, _configService, _renderManagerService) {
|
|
2508
|
+
super();
|
|
2509
|
+
this._config = _config;
|
|
2510
|
+
this._injector = _injector;
|
|
2511
|
+
this._commandService = _commandService;
|
|
2512
|
+
this._configService = _configService;
|
|
2513
|
+
this._renderManagerService = _renderManagerService;
|
|
2514
|
+
const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
2515
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
2516
|
+
this._configService.setConfig(SHEETS_TABLE_UI_PLUGIN_CONFIG_KEY, rest);
|
|
2517
|
+
this._initRegisterCommand();
|
|
2518
|
+
}
|
|
2519
|
+
onStarting() {
|
|
2520
|
+
(0, _univerjs_core.registerDependencies)(this._injector, [
|
|
2521
|
+
[SheetsTableComponentController],
|
|
2522
|
+
[SheetsTableUiService],
|
|
2523
|
+
[SheetTableMenuController],
|
|
2524
|
+
[SheetTableThemeUIController],
|
|
2525
|
+
[SheetTableSelectionController]
|
|
2526
|
+
]);
|
|
2527
|
+
}
|
|
2528
|
+
onReady() {
|
|
2529
|
+
(0, _univerjs_core.touchDependencies)(this._injector, [
|
|
2530
|
+
[SheetsTableComponentController],
|
|
2531
|
+
[SheetsTableUiService],
|
|
2532
|
+
[SheetTableMenuController],
|
|
2533
|
+
[SheetTableThemeUIController],
|
|
2534
|
+
[SheetTableSelectionController]
|
|
2535
|
+
]);
|
|
2536
|
+
}
|
|
2537
|
+
onRendered() {
|
|
2538
|
+
this._registerRenderModules();
|
|
2539
|
+
}
|
|
2540
|
+
_registerRenderModules() {
|
|
2541
|
+
const renderDependencies = [[SheetsTableFilterButtonRenderController], [SheetsTableRenderController]];
|
|
2542
|
+
if (this._config.hideAnchor !== true) renderDependencies.push([SheetTableAnchorController]);
|
|
2543
|
+
renderDependencies.forEach((m) => {
|
|
2544
|
+
this.disposeWithMe(this._renderManagerService.registerRenderModule(_univerjs_core.UniverInstanceType.UNIVER_SHEET, m));
|
|
2545
|
+
});
|
|
2546
|
+
}
|
|
2547
|
+
_initRegisterCommand() {
|
|
2548
|
+
[OpenTableFilterPanelOperation, OpenTableSelectorOperation].forEach((m) => this._commandService.registerCommand(m));
|
|
2549
|
+
}
|
|
2550
|
+
};
|
|
2551
|
+
_defineProperty(UniverSheetsTableUIPlugin, "pluginName", PLUGIN_NAME);
|
|
2552
|
+
_defineProperty(UniverSheetsTableUIPlugin, "packageName", name);
|
|
2553
|
+
_defineProperty(UniverSheetsTableUIPlugin, "version", version);
|
|
2554
|
+
_defineProperty(UniverSheetsTableUIPlugin, "type", _univerjs_core.UniverInstanceType.UNIVER_SHEET);
|
|
2555
|
+
UniverSheetsTableUIPlugin = __decorate([
|
|
2556
|
+
(0, _univerjs_core.DependentOn)(_univerjs_sheets_table.UniverSheetsTablePlugin),
|
|
2557
|
+
__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)),
|
|
2558
|
+
__decorateParam(2, (0, _univerjs_core.Inject)(_univerjs_core.ICommandService)),
|
|
2559
|
+
__decorateParam(3, _univerjs_core.IConfigService),
|
|
2560
|
+
__decorateParam(4, _univerjs_engine_render.IRenderManagerService)
|
|
2561
|
+
], UniverSheetsTableUIPlugin);
|
|
2562
|
+
|
|
2563
|
+
//#endregion
|
|
2564
|
+
Object.defineProperty(exports, 'UniverSheetsTableUIPlugin', {
|
|
2565
|
+
enumerable: true,
|
|
2566
|
+
get: function () {
|
|
2567
|
+
return UniverSheetsTableUIPlugin;
|
|
2568
|
+
}
|
|
2569
|
+
});
|