@univerjs-pro/bases 1.6.1 → 1.7.0-alpha.0
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/{config-BLXIbpvl.js → config-AfiyXtDJ.js} +1 -1
- package/lib/cjs/facade.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/worker.js +1 -1
- package/lib/{config-pca1eLu8.js → config-D64l6SYF.js} +1 -1
- package/lib/es/{config-pca1eLu8.js → config-D64l6SYF.js} +1 -1
- package/lib/es/facade.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/es/worker.js +1 -1
- package/lib/facade.js +1 -1
- package/lib/index.js +1 -1
- package/lib/types/commands/commands/update-base-field.command.d.ts +2 -0
- package/lib/types/controllers/base-active-dirty.controller.d.ts +1 -1
- package/lib/types/controllers/base-formula-calculation.controller.d.ts +1 -2
- package/lib/types/embed-host-anchor.d.ts +0 -9
- package/lib/types/facade/f-field.d.ts +2 -2
- package/lib/types/facade/f-table.d.ts +2 -2
- package/lib/types/fields/select-options.d.ts +19 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/models/base-cell-data.d.ts +0 -1
- package/lib/types/ot/json1-op-factory.d.ts +1 -1
- package/lib/types/services/base-command.service.d.ts +1 -0
- package/lib/types/services/base-formula.service.d.ts +1 -1
- package/lib/types/services/base-performance.service.d.ts +0 -1
- package/lib/umd/facade.js +1 -1
- package/lib/umd/index.js +2 -2
- package/lib/worker.js +1 -1
- package/package.json +9 -10
- package/lib/types/commands/undo-redo.d.ts +0 -2
- package/lib/types/controllers/base-formula-optional-identifier.d.ts +0 -1
- package/lib/types/ot/json1-adapter.d.ts +0 -102
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
let e=require("@univerjs/core");function t(t){let n=t.config.targetTableId,r=t.config.multiple,i=t.config.displayFieldId,a=t.config.pickerFieldIds,o=t.config.relationRole;return typeof n!=`string`||!n||typeof r!=`boolean`||i!==void 0&&(typeof i!=`string`||!i)||o!==void 0&&o!==e.BaseRecordLinkRole.Parent||a!==void 0&&(!Array.isArray(a)||a.some(e=>typeof e!=`string`||!e)||new Set(a).size!==a.length)?null:{targetTableId:n,multiple:r,...i?{displayFieldId:i}:{},...a?{pickerFieldIds:[...a]}:{},...o?{relationRole:o}:{}}}function n(e){return typeof e!=`string`||e===``?[]:e.split(`,`)}function r(e){return Array.from(new Set(e)).join(`,`)}function i(t,n){if(typeof t!=`string`)return{valid:!1,reason:`[RecordLink]: value must be a canonical string.`};if(t===``)return{valid:!0};let i=t.split(`,`);return!n&&i.length>1?{valid:!1,reason:`[RecordLink]: a single link accepts only one record id.`}:i.some(t=>!(0,e.isValidBaseRecordId)(t))||new Set(i).size!==i.length||r(i)!==t?{valid:!1,reason:`[RecordLink]: value is not a canonical record id list.`}:{valid:!0}}function a(n,r){if(r.type!==e.BaseFieldType.RecordLink)return{valid:!0};let i=t(r),a=i?n.tables[i.targetTableId]:void 0;if(!i||!a)return{valid:!1,reason:`[RecordLink]: target table does not exist in this Base.`};let o=[...i.displayFieldId?[i.displayFieldId]:[],...i.pickerFieldIds??[]].find(t=>{let n=a.fields[t];return!n||n.system===!0||n.type===e.BaseFieldType.RecordId});return o?{valid:!1,reason:`[RecordLink]: display field "${o}" must be a non-system field in the target table.`}:{valid:!0}}function o(r,a,o,s={}){let c=t(a);if(a.type!==e.BaseFieldType.RecordLink||!c)return{valid:!1,reason:`[RecordLink]: field config is invalid.`};let l=i(o,c.multiple);if(!l.valid||s.allowDangling)return l;let u=r.tables[c.targetTableId];if(!u)return{valid:!1,reason:`[RecordLink]: target table does not exist in this Base.`};let d=n(o).find(e=>!u.records[e]);return d?{valid:!1,reason:`[RecordLink]: target record "${d}" does not exist.`}:{valid:!0}}function s(n,r){return Object.values(n.tables).flatMap(n=>Object.values(n.fields).flatMap(i=>{let a=i.type===e.BaseFieldType.RecordLink?t(i):null;return(a==null?void 0:a.targetTableId)===r?[{tableId:n.id,fieldId:i.id}]:[]}))}function c(e,t,r){let i=[e],a=/* @__PURE__ */ new Set;for(;i.length;){let e=i.pop();if(e===t)return!0;if(!a.has(e)){a.add(e);for(let t of n(r(e)))i.push(t)}}return!1}function l(t,n){return(n==null?void 0:n.type)===e.BaseFieldType.RecordLink&&!n.system&&!n.readonly&&n.config.targetTableId===t&&n.config.multiple===!0&&n.config.relationRole===void 0}const u=`__base_hierarchy_parent__`;let d=/* @__PURE__ */ function(e){return e.InvalidField=`invalidField`,e.MissingRecord=`missingRecord`,e.SelfParent=`selfParent`,e.Cycle=`cycle`,e.MaxDepth=`maxDepth`,e.SortedView=`sortedView`,e}({});var f=class extends Error{constructor(e,t=`[BaseHierarchy]: ${e}`){super(t),this.code=e,this.name=`BaseHierarchyError`}};let p=/* @__PURE__ */ function(e){return e.UI=`ui`,e.Facade=`facade`,e.Remote=`remote`,e.Undo=`undo`,e.Redo=`redo`,e.Import=`import`,e}({});function m(n,r){if(!r)return!1;let i=n.fields[r];if(!i||i.type!==e.BaseFieldType.RecordLink)return!1;let a=t(i);return a?a.targetTableId===n.id&&a.multiple===!1:!1}function h(n){return[...n.fieldOrder,...Object.keys(n.fields).filter(e=>!n.fieldOrder.includes(e)).sort()].find(r=>{var i;return m(n,r)?((i=t(n.fields[r]))==null?void 0:i.relationRole)===e.BaseRecordLinkRole.Parent:!1})??null}function g(e){let t=h(e);if(t)return t;let n=u,r=2;for(;e.fields[n];)n=`${u}_${r++}`;return n}function _(t,n=g(t),r=`Parent Items`){return{id:n,name:r,type:e.BaseFieldType.RecordLink,config:{targetTableId:t.id,multiple:!1,displayFieldId:t.primaryFieldId,pickerFieldIds:[t.primaryFieldId],relationRole:e.BaseRecordLinkRole.Parent}}}function v(e){let t=h(e);return t?[t]:[]}function y(e,t){let n=[...v(e)].filter(e=>t.some(t=>Object.prototype.hasOwnProperty.call(t.values,e)));if(!n.length)return[];let r={...e.records};t.forEach(e=>{let t=r[e.recordId];t&&(r[e.recordId]={...t,values:{...t.values,...e.values}})});let i={...e,records:r},a=[];return n.forEach(n=>{let r=C(e,n),o=C(i,n);for(let[e,i]of o.invalidReasonByRecordId){let a=t.some(t=>t.recordId===e&&Object.prototype.hasOwnProperty.call(t.values,n));if(r.invalidReasonByRecordId.get(e)!==i||a)throw new f(x(i))}t.forEach(t=>{if(!Object.prototype.hasOwnProperty.call(t.values,n))return;let i=r.parentByRecordId.get(t.recordId)??null,s=o.parentByRecordId.get(t.recordId)??null;i!==s&&a.push({tableId:e.id,fieldId:n,recordId:t.recordId,oldParentRecordId:i,parentRecordId:s})})}),a}function b(e,t){let n=t.map(e=>e.id);if(new Set(n).size!==n.length||n.some(t=>e.records[t]))return[];let r=v(e),i=r.length?null:g(e),a=[...r,...i&&t.some(e=>Object.prototype.hasOwnProperty.call(e.values,i))?[i]:[]].filter(e=>t.some(t=>Object.prototype.hasOwnProperty.call(t.values,e)));if(!a.length)return[];let o={...e,records:{...e.records,...Object.fromEntries(t.map(e=>[e.id,e]))},recordOrder:[...e.recordOrder??[],...t.map(e=>e.id)]},s=[];return a.forEach(n=>{let r=C(o,n);t.forEach(t=>{let i=r.invalidReasonByRecordId.get(t.id);if(i)throw new f(x(i));let a=r.parentByRecordId.get(t.id)??null;a&&s.push({tableId:e.id,fieldId:n,recordId:t.id,oldParentRecordId:null,parentRecordId:a})})}),s}function x(t){switch(t){case e.BaseHierarchyInvalidReason.MissingParent:return`missingRecord`;case e.BaseHierarchyInvalidReason.SelfParent:return`selfParent`;case e.BaseHierarchyInvalidReason.Cycle:return`cycle`;case e.BaseHierarchyInvalidReason.MaxDepth:return`maxDepth`}}function S(e,t){let r=new Set(t),i=v(e);return Object.values(e.records).flatMap(t=>r.has(t.id)?[]:Array.from(i).flatMap(i=>{let a=n(t.values[i])[0]??null;return a&&r.has(a)?[{tableId:e.id,fieldId:i,recordId:t.id,oldParentRecordId:a,parentRecordId:null}]:[]}))}function C(t,r,i=t.recordOrder??Object.keys(t.records)){if((t.fields[r]||r!==g(t))&&!m(t,r))throw Error(`[BaseHierarchy]: field "${r}" must be a same-table, single-value RecordLink.`);let a=te(t,i),o=/* @__PURE__ */ new Map,s=/* @__PURE__ */ new Map;for(let i of a){var c;let a=n((c=t.records[i])==null?void 0:c.values[r])[0]??null;a?a===i?(o.set(i,null),s.set(i,e.BaseHierarchyInvalidReason.SelfParent)):t.records[a]?o.set(i,a):(o.set(i,null),s.set(i,e.BaseHierarchyInvalidReason.MissingParent)):o.set(i,null)}ne(o,s,a),re(o,s,a);let l=new Map(a.map((e,t)=>[e,t])),u=/* @__PURE__ */ new Map;for(let e of a){let t=o.get(e)??null,n=u.get(t)??[];n.push(e),u.set(t,n)}u.forEach(e=>e.sort((e,t)=>(l.get(e)??0)-(l.get(t)??0)));let d=u.get(null)??[],f=/* @__PURE__ */ new Map,p=/* @__PURE__ */ new Map,h=[],_=(e,t)=>{f.set(e,t),h.push(e);let n=0;for(let r of u.get(e)??[])n=Math.max(n,1+_(r,t+1));return p.set(e,n),n};return d.forEach(e=>_(e,0)),{fieldId:r,parentByRecordId:o,childrenByParentId:u,depthByRecordId:f,subtreeHeightByRecordId:p,invalidReasonByRecordId:s,rootRecordIds:d,orderedRecordIds:h}}function w(e,t,n=new Set(t.map(e=>e.recordId))){let r=new Set(n);for(let t of n){let n=e.parentByRecordId.get(t)??null;for(;n;)r.add(n),n=e.parentByRecordId.get(n)??null}let i=new Map(t.map(e=>[e.recordId,e])),a=e.orderedRecordIds.filter(e=>r.has(e)),o=a.flatMap(e=>{let t=i.get(e);return t?[t]:[]}),s={};for(let t=0;t<a.length;t++){let n=a[t];s[n]={recordId:n,parentRecordId:e.parentByRecordId.get(n)??null,depth:e.depthByRecordId.get(n)??0,directChildCount:(e.childrenByParentId.get(n)??[]).length,subtreeHeight:e.subtreeHeightByRecordId.get(n)??0,subtreeEndIndex:t,invalidReason:e.invalidReasonByRecordId.get(n)}}let c=[];for(let e=0;e<a.length;e++){let t=a[e],n=s[t].depth;for(;c.length&&c[c.length-1].depth>=n;){let t=c.pop();s[t.recordId].subtreeEndIndex=e-1}c.push({recordId:t,depth:n})}return c.forEach(({recordId:e})=>{s[e].subtreeEndIndex=a.length-1}),{rows:o,hierarchy:{fieldId:e.fieldId,rootRecordIds:e.rootRecordIds.filter(e=>r.has(e)),orderedRecordIds:a,nodes:s}}}function T(e,t){if(!e.hierarchy||!(t!=null&&t.size))return e.rows;let n=[],r=0;for(;r<e.rows.length;){let i=e.rows[r];n.push(i);let a=e.hierarchy.nodes[i.recordId];r=t.has(i.recordId)&&a?a.subtreeEndIndex+1:r+1}return n}function ee(t,n,r){if(!r)return{valid:!0};if(n===r)return{valid:!1,reason:e.BaseHierarchyInvalidReason.SelfParent};let i=r;for(;i;){if(i===n)return{valid:!1,reason:e.BaseHierarchyInvalidReason.Cycle};i=t.parentByRecordId.get(i)??null}return(t.depthByRecordId.get(r)??0)+1+(t.subtreeHeightByRecordId.get(n)??0)>=5?{valid:!1,reason:e.BaseHierarchyInvalidReason.MaxDepth}:{valid:!0}}function te(e,t){let n=/* @__PURE__ */ new Set,r=[];for(let i of t)e.records[i]&&!n.has(i)&&(n.add(i),r.push(i));return Object.keys(e.records).sort().forEach(e=>{n.has(e)||r.push(e)}),r}function ne(t,n,r){let i=/* @__PURE__ */ new Set;for(let a of r){if(i.has(a))continue;let r=[],o=/* @__PURE__ */ new Map,s=a;for(;s&&!i.has(s);){let i=o.get(s);if(i!=null){let a=[...r.slice(i)].sort().pop();t.set(a,null),n.set(a,e.BaseHierarchyInvalidReason.Cycle);break}o.set(s,r.length),r.push(s),s=t.get(s)??null}r.forEach(e=>i.add(e))}}function re(t,n,r){let i=/* @__PURE__ */ new Map,a=r=>{let o=i.get(r);if(o!=null)return o;let s=t.get(r)??null;if(!s)return i.set(r,0),0;let c=a(s)+1;return c>=5?(t.set(r,null),n.set(r,e.BaseHierarchyInvalidReason.MaxDepth),i.set(r,0),0):(i.set(r,c),c)};r.forEach(a)}let ie=0;function ae(){if(globalThis.__UNIVER_BASE_PERF__===!0)return!0;try{let e=typeof location>`u`?``:location.search,t=new URLSearchParams(e);if(t.get(`basePerf`)===`1`||t.get(`basePerf`)===`true`||t.get(`base-perf`)===`1`)return!0}catch{}try{let e=typeof localStorage>`u`?null:localStorage.getItem(`univer.basePerf`);return e===`1`||e===`true`}catch{return!1}}function E(e,t,n){if(!ae())return t();let r=se(),i=`base-perf-${ie++}`;ce(`${i}:start`);try{return t()}finally{let t=se()-r;ce(`${i}:end`),le(e,`${i}:start`,`${i}:end`),oe(e,t,n)}}function oe(e,t,n){if(!ae())return;let r=Math.round(t*100)/100,i=n&&Object.keys(n).length?` ${JSON.stringify(n)}`:``;console.info(`[BasePerf] ${e}: ${r}ms${i}`)}function se(){return typeof performance<`u`&&typeof performance.now==`function`?performance.now():Date.now()}function ce(e){try{if(typeof performance<`u`){var t,n;(t=(n=performance).mark)==null||t.call(n,e)}}catch{}}function le(e,t,n){try{if(typeof performance<`u`){var r,i;(r=(i=performance).measure)==null||r.call(i,`[BasePerf] ${e}`,t,n)}}catch{}}function D(e){var t;return ae()?E(`IBaseCellData.ensureTableCellLayout`,()=>ue(e),{tableId:e.id,records:Object.keys(e.records??{}).length,fields:e.fieldOrder.length,hasRecordOrder:!!((t=e.recordOrder)!=null&&t.length)}):ue(e)}function ue(t){var n;let r=t.records??{},i=t.fields??{},a=((n=t.recordOrder)==null?void 0:n.filter(e=>r[e]))??[],o=new Set(a),s=[];for(let e of Object.values(r))o.has(e.id)||s.push(e);let c=s.length?[...a,...Te(s)]:a,l=t.fieldOrder.filter(e=>i[e]),u={...t.rowId??{}},d={...t.colId??{}},f={...t.cellData??{}};t.recordOrder=c,t.rowIndex={},t.rowId={},t.colIndex={},t.colId={},t.cellData={},t.resources={...t.resources??{}},t.resources.attachmentSets={...t.resources.attachmentSets??{}},t.resources.attachments={...t.resources.attachments??{}};let p=t.rowIndex,m=t.rowId,h=t.colIndex,g=t.colId,_=t.cellData;return c.forEach((e,t)=>{p[e]=t,m[t]=e}),l.forEach((e,t)=>{h[e]=t,g[t]=e}),Object.entries(f).forEach(([e,t])=>{let n=Number(e),r=u[n]??c[n],i=r?p[r]:void 0;i!=null&&(_[i]={..._[i]??{}},Object.entries(t??{}).forEach(([e,t])=>{let n=Number(e),r=d[n]??l[n],a=r?h[r]:void 0;a!=null&&(_[i][a]=_e(t))}))}),Object.values(r).forEach(n=>{let r=p[n.id];r!=null&&(n.values={...n.values??{},[e.BASE_RECORD_ID_FIELD_ID]:n.id},_[r]={..._[r]??{},0:{v:n.id,t:e.CellValueType.STRING}},Object.entries(n.values??{}).forEach(([a,o])=>{let s=i[a];(s==null?void 0:s.type)===e.BaseFieldType.Attachment&&be(t,n.id,a,o);let c=h[a];if(c==null)return;let l=_[r][c];(l==null||Ce(l,s,o))&&(_[r][c]=ge(o,s))}))}),t}function de(t,n){return t.records=Object.fromEntries(Object.entries(t.records).map(([e,t])=>[e,{...t}])),D(t),Object.entries(t.rowId??{}).forEach(([r,i])=>{var a;let o=Number(r),s=t.records[i];s&&(s.values={...s.values??{}},Object.entries(((a=t.cellData)==null?void 0:a[o])??{}).forEach(([r,a])=>{var o;let c=(o=t.colId)==null?void 0:o[Number(r)];c&&n&&!n(i,c)||(c===e.BASE_RECORD_ID_FIELD_ID?s.values[e.BASE_RECORD_ID_FIELD_ID]=s.id:c&&(s.values[c]=k(a,t.fields[c],t,i)))}))}),t}function fe(t,n){for(let{row:o,col:s}of n){var r,i,a;let n=(r=t.rowId)==null?void 0:r[o],c=(i=t.colId)==null?void 0:i[s],l=n?t.records[n]:void 0;if(!l||!c)continue;if(c===e.BASE_RECORD_ID_FIELD_ID){l.values[e.BASE_RECORD_ID_FIELD_ID]=l.id;continue}let u=(a=t.cellData)==null||(a=a[o])==null?void 0:a[s];(u!=null||Object.prototype.hasOwnProperty.call(l.values??{},c))&&(l.values={...l.values??{}},l.values[c]=k(u,t.fields[c],t,n))}return t}function pe(e,t,n){var r,i,a,o,s,c;let l=(r=e.rowIndex)==null?void 0:r[t],u=(i=e.colIndex)==null?void 0:i[n];if(l!=null&&u!=null&&((a=e.rowId)==null?void 0:a[l])===t&&((o=e.colId)==null?void 0:o[u])===n)return{row:l,col:u};let d=D(e),f=(s=d.rowIndex)==null?void 0:s[t],p=(c=d.colIndex)==null?void 0:c[n];return f==null||p==null?null:{row:f,col:p}}function me(e,t,n){var r;let i=pe(e,t,n);if(i)return(r=e.cellData)==null||(r=r[i.row])==null?void 0:r[i.col]}function O(t,n,r){var i;let a=me(t,n,r),o=t.fields[r];if((o==null?void 0:o.type)===e.BaseFieldType.Attachment){var s;return xe(t,n,r)??j((s=t.records[n])==null||(s=s.values)==null?void 0:s[r])}if(M(o)||N(o)||(o==null?void 0:o.type)===e.BaseFieldType.Link){var c;let e=(c=t.records[n])==null||(c=c.values)==null?void 0:c[r];return e!=null&&e!==``?Se(e,o):k(a,o,t,n)}return a&&Object.prototype.hasOwnProperty.call(a,`v`)?a.v??null:((i=t.records[n])==null||(i=i.values)==null?void 0:i[r])??null}function he(e,t,n){var r;let i=me(e,t,n);if(i&&Object.prototype.hasOwnProperty.call(i,`v`))return i.v??null;let a=e.fields[n];return ge(((r=e.records[t])==null||(r=r.values)==null?void 0:r[n])??null,a).v??null}function ge(t,n){if(A(t))return(n==null?void 0:n.type)===e.BaseFieldType.Attachment?{...t,v:``,t:e.CellValueType.STRING}:_e(t);if((n==null?void 0:n.type)===e.BaseFieldType.Attachment)return{v:``,t:e.CellValueType.STRING};if(N(n)){let e=P(t);return{v:e,t:I(e)}}if(M(n))return{v:F(t).join(`, `),t:e.CellValueType.STRING};if((n==null?void 0:n.type)===e.BaseFieldType.Link&&t&&typeof t==`object`&&!Array.isArray(t)){let n=t;return{v:String(n.text??n.url??``),t:e.CellValueType.STRING}}return t===null||typeof t==`string`||typeof t==`number`||typeof t==`boolean`?{v:t,t:I(t)}:{v:null,t:null}}function _e(e){let t=Ee(e.t,e.v);if(t===void 0){let{t,...n}=e;return n}return{...e,t}}function k(t,n,r,i){if(!t)return null;if((n==null?void 0:n.type)===e.BaseFieldType.Attachment)return r&&i?xe(r,i,n.id)??[]:[];if(M(n))return F(t.v);if((n==null?void 0:n.type)===e.BaseFieldType.Link&&r&&i){var a;let e=(a=r.records[i])==null||(a=a.values)==null?void 0:a[n.id];if(e&&typeof e==`object`&&!Array.isArray(e))return e}return Object.prototype.hasOwnProperty.call(t,`v`)?t.v??null:null}function ve(t,n,r,i,a){return(r==null?void 0:r.type)===e.BaseFieldType.Attachment?j(t):N(r)?P(t):M(r)?F(t):(r==null?void 0:r.type)===e.BaseFieldType.Link&&(t==null||t===``)?null:(r==null?void 0:r.type)===e.BaseFieldType.Link&&t&&typeof t==`object`&&!Array.isArray(t)&&!A(t)?t:k(n,r,i,a)}function A(e){return!!e&&typeof e==`object`&&(Object.prototype.hasOwnProperty.call(e,`v`)||Object.prototype.hasOwnProperty.call(e,`t`)||Object.prototype.hasOwnProperty.call(e,`p`)||Object.prototype.hasOwnProperty.call(e,`f`)||Object.prototype.hasOwnProperty.call(e,`si`))}function ye(e,t){return`${e}${t}`}function be(e,t,n,r){let i=j(r);e.resources={...e.resources??{}},e.resources.attachmentSets={...e.resources.attachmentSets??{}},e.resources.attachments={...e.resources.attachments??{}};let a=ye(n,t),o=[];for(let t=0;t<i.length;t++){if(!(t in i))continue;let n=i[t],r=String(n.id??`${a}${t}`),s={...n,id:r};e.resources.attachments[r]=s,o.push(r)}e.resources.attachmentSets[a]=o}function xe(e,t,n){var r;let i=ye(n,t),a=(r=e.resources)==null||(r=r.attachmentSets)==null?void 0:r[i];if(!a)return null;let o=[];for(let t=0;t<a.length;t++){var s;if(!(t in a))continue;let n=(s=e.resources)==null||(s=s.attachments)==null?void 0:s[a[t]];n&&o.push({...n})}return o}function j(e){if(e==null||e===``||A(e)&&!(`id`in e)&&!(`name`in e))return[];let t=Array.isArray(e)?e:[e],n=[];for(let e=0;e<t.length;e++){if(!(e in t))continue;let r=t[e],i=r&&typeof r==`object`?{...r}:{id:`attachment-${e}`,name:String(r)};Object.keys(i).length>0&&n.push(i)}return n}function Se(t,n){return(n==null?void 0:n.type)===e.BaseFieldType.Attachment?j(t):N(n)?P(t):M(n)?F(t):t}function Ce(t,n,r){return(n==null?void 0:n.type)===e.BaseFieldType.Attachment?t.v!==``:N(n)?t.v!==P(r):M(n)?Array.isArray(r)&&(t.v==null||t.v===``):!1}function M(t){return(t==null?void 0:t.type)===e.BaseFieldType.MultiSelect||(t==null?void 0:t.type)===e.BaseFieldType.Group||(t==null?void 0:t.type)===e.BaseFieldType.Person&&t.config.allowMultiple===!0}function N(t){return(t==null?void 0:t.type)===e.BaseFieldType.Person&&t.config.allowMultiple!==!0}function P(e){let t=A(e)?e.v:e,n=Array.isArray(t)?t[0]:t;return n==null||n===``?null:String(n)}function F(e){if(e==null||e===``)return[];let t=[];if(Array.isArray(e)){for(let n=0;n<e.length;n++){if(!(n in e))continue;let r=we(e[n]);r&&t.push(r)}return t}for(let n of String(e).split(`,`)){let e=n.trim();e&&t.push(e)}return t}function we(e){if(e==null)return``;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return String(e);if(typeof e==`object`){let t=e;return String(t.id??t.name??t.text??``)}return String(e)}function I(t){return t==null?null:typeof t==`number`?e.CellValueType.NUMBER:typeof t==`boolean`?e.CellValueType.BOOLEAN:e.CellValueType.STRING}function Te(e){e.sort((e,t)=>e.orderKey.localeCompare(t.orderKey));let t=[];for(let n of e)t.push(n.id);return t}function Ee(t,n){return t===e.CellValueType.STRING||t===e.CellValueType.NUMBER||t===e.CellValueType.BOOLEAN||t===e.CellValueType.FORCE_STRING||t==null?t:I(n??null)}function De(t){let n=null;for(let r of t)n=n===null?r:e.JSON1.type.compose(n,r);return n}var Oe=class t{static tryMaterializeSnapshot(e,n){let r=[];for(let t of n){let n=ke(t);if(!n||n.unitId!==e.id)return null;r.push(n.op)}try{let n=De(r);return n===null?e:new t().applyOp(e,n)}catch{return null}}applyOp(t,n){let r=this.getAffectedRanges(n),i=E(`BaseJson1.cloneForOp`,()=>ze(t,n),{invalidations:r.length}),a=E(`BaseJson1.json1Apply`,()=>e.JSON1.type.apply(i,n),{invalidations:r.length}),o=je(a,r);return E(`BaseJson1.syncCellInvalidations`,()=>Ae(a,r),{invalidations:r.length})?(Me(a,o),a):(E(`BaseJson1.normalizeTables`,()=>{this._getTablesToNormalize(a,r).forEach(e=>{let n=r.filter(t=>t.tableId===e.id),i=n.length>0&&n.every(e=>e.reason===`field`||e.reason===`view`||e.reason===`cell`||e.reason===`record`)?new Set(n.flatMap(n=>{var r;if(n.reason!==`field`||!n.fieldId)return[];let i=(r=t.tables[e.id])==null?void 0:r.fields[n.fieldId],a=e.fields[n.fieldId];return(i==null?void 0:i.type)!==(a==null?void 0:a.type)||(i==null?void 0:i.config.allowMultiple)!==(a==null?void 0:a.config.allowMultiple)?[n.fieldId]:[]})):void 0,a=new Set(n.flatMap(t=>{var n,r;return t.reason!==`cell`||t.row==null||t.column==null?[]:[JSON.stringify([(n=e.rowId)==null?void 0:n[t.row],(r=e.colId)==null?void 0:r[t.column]])]}));de(e,i?(e,t)=>i.has(t)||a.has(JSON.stringify([e,t])):void 0)})},{invalidations:r.length}),Me(a,o),a)}invertOp(t,n){return e.JSON1.type.invertWithDoc(n,t)}getAffectedRanges(e){let t=Ie(e);return t.length?Le(t.flatMap(e=>this.getAffectedRanges(e))):Ne(e)}_getTablesToNormalize(e,t){let n=t.filter(e=>e.reason!==`view`);return n.length?n.some(e=>!e.tableId)?Object.values(e.tables??{}):Array.from(new Set(n.map(e=>e.tableId))).flatMap(t=>{var n;let r=(n=e.tables)==null?void 0:n[t];return r?[r]:[]}):[]}};function ke(e){let t=e.params;return e.id!==`base.mutation.apply-base-json1`||typeof t!=`object`||!t||!(`unitId`in t)||typeof t.unitId!=`string`||!(`op`in t)||t.op!==null&&!Array.isArray(t.op)?null:{unitId:t.unitId,op:t.op}}function Ae(e,t){if(!t.length||t.some(e=>e.reason!==`cell`))return!1;let n=/* @__PURE__ */ new Map;for(let e of t){if(!e.tableId||e.row==null||e.column==null)continue;let t=n.get(e.tableId)??[];t.push({row:e.row,col:e.column}),n.set(e.tableId,t)}return n.forEach((t,n)=>{var r;let i=(r=e.tables)==null?void 0:r[n];i&&fe(i,t)}),!0}function je(e,t){let n=/* @__PURE__ */ new Set;return t.flatMap(t=>{var r;if(!t.tableId||!t.recordId||!t.fieldId)return[];let i=`${t.tableId}\u001F${t.recordId}\u001F${t.fieldId}`;if(n.has(i))return[];n.add(i);let a=(r=e.tables[t.tableId])==null||(r=r.records[t.recordId])==null?void 0:r.values;return a?[{tableId:t.tableId,recordId:t.recordId,fieldId:t.fieldId,exists:Object.prototype.hasOwnProperty.call(a,t.fieldId),value:a[t.fieldId]}]:[]})}function Me(e,t){t.forEach(t=>{var n;let r=(n=e.tables[t.tableId])==null||(n=n.records[t.recordId])==null?void 0:n.values;r&&(t.exists?r[t.fieldId]=t.value:delete r[t.fieldId])})}function Ne(e){if(!Array.isArray(e)||e.length<2)return[{tableId:``,reason:`unknown`}];let t=e,n=t.indexOf(`tables`);return n===-1||typeof t[n+1]!=`string`?t[0]===`tableOrder`?[]:[{tableId:``,reason:`unknown`}]:Pe(t,n,String(t[n+1]))}function Pe(e,t,n){let r=e[t+2];return r===`records`&&typeof e[t+3]==`string`?Fe(e,t,n,String(e[t+3])):r===`cellData`&&e[t+3]!=null&&e[t+4]!=null?[{tableId:n,reason:`cell`,row:Number(e[t+3]),column:Number(e[t+4])}]:r===`fields`&&typeof e[t+3]==`string`?[{tableId:n,reason:`field`,fieldId:String(e[t+3])}]:r===`fieldOrder`?[{tableId:n,reason:`field`}]:r===`recordOrder`?[{tableId:n,reason:`record`}]:r===`views`&&typeof e[t+3]==`string`?[{tableId:n,reason:`view`,viewId:String(e[t+3])}]:r===`viewOrder`?[{tableId:n,reason:`view`}]:r===`resources`?[{tableId:n,reason:`cell`}]:[{tableId:n,reason:r===void 0?`table`:`unknown`}]}function Fe(e,t,n,r){return e[t+4]===`values`&&typeof e[t+5]==`string`?[{tableId:n,reason:`cell`,recordId:r,fieldId:String(e[t+5])}]:e[t+4]===`updatedAt`||e[t+4]===`updatedBy`?[]:[{tableId:n,reason:`record`,recordId:r}]}function Ie(e){if(!Array.isArray(e))return[];let t=e.filter(Array.isArray);if(t.length>1&&t.length===e.length)return t;let n=e.findIndex(Array.isArray);if(n>0&&e.slice(n).every(Array.isArray)){let t=e.slice(0,n);return e.slice(n).map(e=>[...t,...e])}let r=e.indexOf(`tables`);if(r===-1||typeof e[r+1]!=`string`)return[];let i=String(e[r+1]),a=e.slice(r+2).filter(Array.isArray);return a.length<=1?[]:a.map(e=>[`tables`,i,...e])}function Le(e){let t=/* @__PURE__ */ new Set;return e.filter(e=>{let n=JSON.stringify(e);return!t.has(n)&&(t.add(n),!0)})}function Re(t){return e.Tools.deepClone(t)}function ze(e,t){let n=Be(t);if(!n.length)return Re(e);let r=qe(e),i=/* @__PURE__ */ new Set;for(let e of n)Ue(r,e,i);return r}function Be(e){let t=[];return Ve(e,[],t),t}function Ve(e,t,n){if(!Array.isArray(e))return;let r=[];for(let i of e)Array.isArray(i)?Ve(i,[...t,...r],n):He(i)?n.push([...t,...r]):(typeof i==`string`||typeof i==`number`)&&r.push(i)}function He(e){if(!e||typeof e!=`object`||Array.isArray(e))return!1;let t=e;return`i`in t||`r`in t||`p`in t||`d`in t||`es`in t||`ena`in t||`et`in t}function Ue(e,t,n){let r=e,i=[];for(let e=0;e<t.length-1;e++){let a=t[e];i.push(a);let o=We(r,a);if(!Ke(o))return;let s=JSON.stringify(i);n.has(s)||(Ge(r,a,qe(o)),n.add(s));let c=We(r,a);if(!Ke(c))return;r=c}}function We(e,t){return Array.isArray(e)?typeof t==`number`?e[t]:void 0:Reflect.get(e,t)}function Ge(e,t,n){Array.isArray(e)?typeof t==`number`&&(e[t]=n):Reflect.set(e,t,n)}function Ke(e){return!!e&&typeof e==`object`}function qe(e){return Array.isArray(e)?e.slice():{...e}}const L=`yyyy/mm/dd`,Je=/\s+hh:mm\s*$/i,Ye={"yyyy/mm/dd":`YYYY/MM/DD`,"yyyy-mm-dd":`YYYY-MM-DD`,"mm-dd":`MM-DD`,"mm/dd/yyyy":`MM/DD/YYYY`,"dd/mm/yyyy":`DD/MM/YYYY`,"mmm d, yyyy":`MMM D, YYYY`};function R(t,n=e.DateSystem.Date1900){let r=(0,e.dateKit)(t).valueOf();return(0,e.excelDateTimeSerial)(new Date(r),n)}function Xe(t,n=e.DateSystem.Date1900){return(0,e.excelSerialToDateTime)(t,n).getTime()}function z(t,n=e.DateSystem.Date1900){if(t==null||t===``)return null;if(t instanceof Date)return R(t,n);if(typeof t==`number`)return Number.isFinite(t)?t>1e6?R(t,n):t:null;let r=Date.parse(String(t));return Number.isNaN(r)?null:R(r,n)}function B(t,n=e.DateSystem.Date1900){let r=z(t,n);return r==null?null:Xe(r,n)}function Ze(e={}){let t=String(e.pattern??e.format??e.dateFormat??L).trim()||L,n=Je.test(t);return{pattern:t.replace(Je,``)||L,includeTime:typeof e.includeTime==`boolean`?e.includeTime:n,hourCycle:e.hourCycle===`h12`?`h12`:`h24`}}function Qe(e={}){let{format:t,dateFormat:n,...r}=e;return{...r,...Ze(e)}}function $e(t,n={}){let r=B(t);if(r==null||!Number.isFinite(r))return``;let i=Ze(n);return(0,e.dateKit)(r).format(et(i))}function et(e){let{pattern:t,includeTime:n,hourCycle:r}=e,i=Ye[t]??Ye[L];return n?`${i} ${r===`h12`?`h:mm a`:`HH:mm`}`:i}const tt={editable:!0,sortable:!0,filterable:!0,groupable:!1,usableAsKanbanGroup:!1,usableAsCalendarDate:!1,usableAsGanttStart:!1,usableAsGanttEnd:!1,usableAsGanttProgress:!1,usableAsCardCover:!1,usableAsTitle:!1},nt=/* @__PURE__ */ new Set([e.BaseFieldType.RecordId]);function rt(t){switch(t){case e.BaseFieldType.Number:case e.BaseFieldType.Currency:case e.BaseFieldType.Progress:case e.BaseFieldType.Rating:return[e.BaseConditionalColorOperator.IS,e.BaseConditionalColorOperator.IS_NOT,e.BaseConditionalColorOperator.GREATER_THAN,e.BaseConditionalColorOperator.LESS_THAN,e.BaseConditionalColorOperator.IS_EMPTY,e.BaseConditionalColorOperator.IS_NOT_EMPTY];case e.BaseFieldType.Date:case e.BaseFieldType.CreatedAt:case e.BaseFieldType.UpdatedAt:return[e.BaseConditionalColorOperator.IS,e.BaseConditionalColorOperator.IS_NOT,e.BaseConditionalColorOperator.BEFORE,e.BaseConditionalColorOperator.AFTER,e.BaseConditionalColorOperator.IS_EMPTY,e.BaseConditionalColorOperator.IS_NOT_EMPTY];case e.BaseFieldType.Checkbox:return[e.BaseConditionalColorOperator.IS,e.BaseConditionalColorOperator.IS_NOT];default:return[e.BaseConditionalColorOperator.IS,e.BaseConditionalColorOperator.IS_NOT,e.BaseConditionalColorOperator.CONTAINS,e.BaseConditionalColorOperator.NOT_CONTAINS,e.BaseConditionalColorOperator.IS_EMPTY,e.BaseConditionalColorOperator.IS_NOT_EMPTY]}}function it(t){return t===e.BaseFieldType.Date||t===e.BaseFieldType.CreatedAt||t===e.BaseFieldType.UpdatedAt}function at(e,t){return e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e-t:String(e).localeCompare(String(t))}function ot(t,n,r,i,a={}){if(n===`isEmpty`)return st(t);if(n===`isNotEmpty`)return!st(t);switch(i.type){case e.BaseFieldType.Number:case e.BaseFieldType.Currency:case e.BaseFieldType.Progress:case e.BaseFieldType.Rating:return ct(t,n,r);case e.BaseFieldType.Date:case e.BaseFieldType.CreatedAt:case e.BaseFieldType.UpdatedAt:return ut(t,n,r,a);case e.BaseFieldType.Checkbox:return gt(t,n,r);case e.BaseFieldType.SingleSelect:case e.BaseFieldType.MultiSelect:case e.BaseFieldType.Person:case e.BaseFieldType.Group:return vt(t,n,r,i);default:return yt(t,n,r)}}function st(e){return e==null?!0:Array.isArray(e)?e.length===0:typeof e==`string`&&e.trim()===``}function ct(e,t,n){let r=lt(e),i=lt(n);if(r==null||i==null)return!1;switch(t){case`is`:return r===i;case`isNot`:return r!==i;case`greaterThan`:return r>i;case`greaterThanOrEqual`:return r>=i;case`lessThan`:return r<i;case`lessThanOrEqual`:return r<=i;default:return!1}}function lt(e){if(e==null||e===``)return null;let t=Number(e);return Number.isFinite(t)?t:null}function ut(t,n,r,i){let a=ft(t);if(a==null)return!1;let o=dt(i.dateMode??e.BaseConditionalDateMode.EXACT,r,i.now);if(!o)return!1;switch(n){case e.BaseConditionalColorOperator.IS:return a>=o.start&&a<=o.end;case e.BaseConditionalColorOperator.IS_NOT:return a<o.start||a>o.end;case e.BaseConditionalColorOperator.BEFORE:return a<o.start;case e.BaseConditionalColorOperator.AFTER:return a>o.end;default:return!1}}function dt(t,n,r=Date.now()){let i=pt(r);switch(t){case e.BaseConditionalDateMode.EXACT:{let e=ft(n);return e==null?null:V(e,0,1)}case e.BaseConditionalDateMode.TODAY:return V(i,0,1);case e.BaseConditionalDateMode.TOMORROW:return V(i,1,1);case e.BaseConditionalDateMode.YESTERDAY:return V(i,-1,1);case e.BaseConditionalDateMode.THIS_WEEK:return mt(i,0);case e.BaseConditionalDateMode.LAST_WEEK:return mt(i,-1);case e.BaseConditionalDateMode.THIS_MONTH:return ht(i,0);case e.BaseConditionalDateMode.LAST_MONTH:return ht(i,-1);case e.BaseConditionalDateMode.PAST_7_DAYS:return V(i,-6,7);case e.BaseConditionalDateMode.NEXT_7_DAYS:return V(i,0,7);case e.BaseConditionalDateMode.PAST_30_DAYS:return V(i,-29,30);case e.BaseConditionalDateMode.NEXT_30_DAYS:return V(i,0,30)}}function ft(e){let t=z(e);return t==null?null:pt(Xe(t))}function pt(e){let t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}function mt(e,t){return V(e,-((new Date(e).getDay()+6)%7)+t*7,7)}function V(t,n,r){let i=(0,e.dateKit)(t).add(n,`day`);return{start:i.valueOf(),end:i.add(r,`day`).valueOf()-1}}function ht(e,t){let n=new Date(e),r=new Date(n.getFullYear(),n.getMonth()+t,1),i=new Date(n.getFullYear(),n.getMonth()+t+1,1);return{start:r.getTime(),end:i.getTime()-1}}function gt(e,t,n){let r=_t(e),i=_t(n);switch(t){case`is`:return r===i;case`isNot`:return r!==i;default:return!1}}function _t(e){return e===!0||e===`true`||e===1||e===`1`}function vt(e,t,n,r){let i=bt(e,r),a=bt(n,r),o=a.length>0&&a.some(e=>i.includes(e));switch(t){case`is`:case`contains`:return o;case`isNot`:case`notContains`:return!o;default:return!1}}function yt(e,t,n){let r=H(e),i=H(n);switch(t){case`is`:return r===i;case`isNot`:return r!==i;case`contains`:return i?r.includes(i):!1;case`notContains`:return!i||!r.includes(i);default:return!1}}function H(e){if(Array.isArray(e))return e.map(e=>H(e)).join(`
|
|
2
|
-
`);if(e&&typeof e==`object`){let t=e;return String(t.name??t.label??t.text??t.value??t.id??``).trim().toLowerCase()}return String(e??``).trim().toLowerCase()}function bt(e,t){let n=U(e),r=xt(t.config??{});return n.flatMap(e=>r.get(e)??[e]).filter((e,t,n)=>e!==``&&n.indexOf(e)===t)}function U(e){if(e==null||e===``)return[];if(Array.isArray(e))return e.flatMap(e=>U(e));if(e&&typeof e==`object`){let t=e;return[`id`,`name`,`label`,`value`,`text`].flatMap(e=>U(t[e])).filter((e,t,n)=>n.indexOf(e)===t)}return[H(e)]}function xt(e){let t=/* @__PURE__ */ new Map;return(Array.isArray(e.options)?e.options:[]).forEach(e=>{if(!e||typeof e!=`object`)return;let n=U(e),r=n.filter((e,t)=>e!==``&&n.indexOf(e)===t);r.forEach(e=>t.set(e,r))}),t}function W(e,t={},n=e=>e,r={}){let i=!nt.has(e),a=n??(e=>e);return{type:e,i18nKey:`base.fieldType.${e}`,enabled:i,visibleInCreateMenu:i,createDefaultConfig:r.createDefaultConfig??(()=>({})),createDefaultValue:r.createDefaultValue??(e=>e.defaultValue??null),normalize:(e,t)=>a(e,t),validate:(e,t)=>{var n;return i?((n=r.validate)==null?void 0:n.call(r,e,t))??{valid:!0}:{valid:!1}},compare:(e,t)=>at(e,t),filter:(e,t,n,r)=>ot(e,t,n,r),toPlainText:r.toPlainText??(e=>e==null?``:String(e)),fromPlainText:r.fromPlainText??(t=>a(t,{id:``,name:``,type:e,config:{}})),getCapabilities:()=>({...tt,...t,editable:i&&(t.editable??tt.editable)})}}function St(){return[W(e.BaseFieldType.Text,{groupable:!0,usableAsTitle:!0},void 0,{createDefaultConfig:()=>({placeholder:`bases.fieldConfig.textPlaceholder`}),createDefaultValue:e=>e.defaultValue??``}),W(e.BaseFieldType.SingleSelect,{groupable:!0,usableAsKanbanGroup:!0,supportsOptions:!0},e=>e==null||e===``?null:String(e),{createDefaultConfig:()=>({options:[],optionSource:{type:`manual`}})}),W(e.BaseFieldType.MultiSelect,{filterable:!0,usableAsKanbanGroup:!0,supportsOptions:!0,supportsMultipleValues:!0},e=>Array.isArray(e)?e.map(String):e==null?[]:[String(e)],{createDefaultConfig:()=>({options:[],optionSource:{type:`manual`}}),createDefaultValue:e=>e.defaultValue??[]}),W(e.BaseFieldType.Person,{groupable:!0,usableAsKanbanGroup:!0,supportsMultipleValues:!0},Dt,{createDefaultConfig:()=>({allowMultiple:!1,provider:`person`}),validate:Ot}),W(e.BaseFieldType.Group,{groupable:!0,usableAsKanbanGroup:!0,supportsMultipleValues:!0},Tt,{createDefaultConfig:()=>({allowMultiple:!0,provider:`group`}),createDefaultValue:e=>e.defaultValue??[],validate:kt}),W(e.BaseFieldType.Date,{groupable:!0,usableAsCalendarDate:!0,usableAsGanttStart:!0,usableAsGanttEnd:!0},e=>z(e),{createDefaultConfig:()=>wt(),validate:At}),W(e.BaseFieldType.Attachment,{usableAsCardCover:!0,supportsMultipleValues:!0},e=>e==null?[]:Array.isArray(e)?e:[e],{createDefaultValue:e=>e.defaultValue??[]}),W(e.BaseFieldType.Number,{},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>Ct(),validate:jt}),W(e.BaseFieldType.Checkbox,{groupable:!0,usableAsKanbanGroup:!0},e=>e===!0||e===`true`||e===1||e===`1`,{createDefaultConfig:()=>({icon:`check`,color:`#16a34a`}),createDefaultValue:e=>e.defaultValue??!1,validate:e=>typeof e==`boolean`?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid checkbox value.`}}),W(e.BaseFieldType.Link,{supportsRelation:!0},Nt,{createDefaultConfig:()=>({placeholder:`bases.fieldConfig.linkPlaceholder`}),toPlainText:e=>Pt(e),fromPlainText:e=>Nt(e)}),W(e.BaseFieldType.Formula,{editable:!1},void 0,{createDefaultConfig:()=>({formula:``,dependencies:[],numfmt:{type:`general`,pattern:`General`}}),createDefaultValue:()=>null}),W(e.BaseFieldType.Numbering,{editable:!1,usableAsTitle:!0},void 0,{createDefaultConfig:()=>({mode:`autoIncrement`}),createDefaultValue:()=>null}),W(e.BaseFieldType.Phone,{usableAsTitle:!0},e=>e==null?null:String(e).trim(),{validate:e=>e==null||e===``||/^\+?[0-9 ()-]{6,20}$/.test(String(e))?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid phone value.`}}),W(e.BaseFieldType.Email,{usableAsTitle:!0},e=>e==null?null:String(e).trim(),{validate:e=>e==null||e===``||It(String(e))?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid email value.`}}),W(e.BaseFieldType.Progress,{usableAsGanttProgress:!0},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>({format:`percent`,decimalPlaces:0,color:`blue`,customRange:!1,start:0,end:100}),validate:(e,t)=>Mt(e,t,`[BaseField]: invalid progress value.`)}),W(e.BaseFieldType.Currency,{},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>({...Ct(),currencySymbol:`$`}),validate:jt}),W(e.BaseFieldType.Rating,{groupable:!0,usableAsKanbanGroup:!0},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>({icon:`star`,min:1,max:5}),createDefaultValue:()=>null,validate:(e,t)=>Mt(e,t,`[BaseField]: invalid rating value.`)}),W(e.BaseFieldType.RecordLink,{supportsRelation:!0,supportsMultipleValues:!0},Et,{createDefaultConfig:()=>({targetTableId:``,multiple:!1}),createDefaultValue:()=>``,validate:(e,t)=>i(e,t.config.multiple===!0)}),W(e.BaseFieldType.RecordId,{editable:!1,sortable:!0,filterable:!0,usableAsTitle:!0}),W(e.BaseFieldType.CreatedBy,{editable:!1,groupable:!0},e=>e==null?null:String(e),{createDefaultConfig:()=>({provider:`user`}),createDefaultValue:()=>null}),W(e.BaseFieldType.UpdatedBy,{editable:!1,groupable:!0},e=>e==null?null:String(e),{createDefaultConfig:()=>({provider:`user`}),createDefaultValue:()=>null}),W(e.BaseFieldType.CreatedAt,{editable:!1,usableAsCalendarDate:!0,usableAsGanttStart:!0,usableAsGanttEnd:!0},e=>z(e),{createDefaultConfig:()=>wt(),createDefaultValue:()=>null,validate:At}),W(e.BaseFieldType.UpdatedAt,{editable:!1,usableAsCalendarDate:!0,usableAsGanttStart:!0,usableAsGanttEnd:!0},e=>z(e),{createDefaultConfig:()=>wt(),createDefaultValue:()=>null,validate:At})]}function Ct(){return{pattern:`#,##0.00`,decimalPlaces:2,separatorStyle:`local`,useThousands:!0,abbreviation:`none`,allowNegative:!0}}function wt(){return{locale:`en-US`,pattern:`yyyy/mm/dd`,includeTime:!1,hourCycle:`h24`,defaultMode:`none`}}function Tt(e){return e==null||e===``?[]:Array.isArray(e)?e.map(String):[String(e)]}function Et(e){return typeof e==`string`?e:``}function Dt(e,t){return e==null||e===``?t.config.allowMultiple===!0?[]:null:t.config.allowMultiple===!0?Array.isArray(e)?e.map(String):[String(e)]:Array.isArray(e)?String(e[0]??``)||null:String(e)}function Ot(e,t){return t.config.allowMultiple===!0?kt(e):e==null||e===``||typeof e==`string`?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid person value.`}}function kt(e){return e==null||Array.isArray(e)&&e.every(e=>typeof e==`string`)?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid multi-value reference.`}}function At(e){return e==null||typeof e==`number`&&Number.isFinite(e)?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid date value.`}}function jt(e,t){return e==null||e===``?{valid:!0}:typeof e!=`number`||!Number.isFinite(e)?{valid:!1,reason:`[BaseField]: invalid number value.`}:t.config.allowNegative===!1&&e<0?{valid:!1,reason:`[BaseField]: negative numbers are disabled.`}:{valid:!0}}function Mt(e,t,n){let r=jt(e,t);if(!r.valid||e==null||e===``)return r;let i=Number(t.config.min??t.config.start??0),a=Number(t.config.max??t.config.end??100),o=Number(e);return o>=i&&o<=a?{valid:!0}:{valid:!1,reason:n}}function Nt(e){if(e==null||e===``)return null;if(typeof e==`object`&&!Array.isArray(e)){let t=e,n=typeof t.text==`string`?t.text.trim():``,r=typeof t.url==`string`?t.url.trim():``,i=Ft(r||n);return i?{text:n||r||i,url:i}:null}let t=String(e).trim(),n=Ft(t);return n?{text:t,url:n}:null}function Pt(e){if(e==null)return``;if(typeof e==`object`&&!Array.isArray(e)){let t=e;return String(t.text||t.url||``)}return String(e)}function Ft(e){let t=e.trim();if(!t)return``;let n=/^[a-z][a-z\d+.-]*:/i.test(t)?t:t.startsWith(`//`)?`https:${t}`:`https://${t}`;try{let e=new URL(n);return e.protocol===`http:`||e.protocol===`https:`?e.href:``}catch{return``}}function It(e){let t=e.indexOf(`@`);if(t<=0||t!==e.lastIndexOf(`@`))return!1;let n=e.slice(t+1);return n.includes(`.`)&&!e.includes(` `)&&!n.startsWith(`.`)&&!n.endsWith(`.`)}function G(e){"@babel/helpers - typeof";return G=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},G(e)}function Lt(e,t){if(G(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Rt(e){var t=Lt(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=Rt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const zt=(0,e.createIdentifier)(`base.field-registry.service`);var Bt=class extends e.Disposable{constructor(...e){super(...e),K(this,`_plugins`,/* @__PURE__ */ new Map)}register(t){return this._plugins.set(t.type,t),(0,e.toDisposable)(()=>this._plugins.delete(t.type))}get(e){let t=this._plugins.get(e);if(!t)throw Error(`[BaseFieldRegistryService]: field type "${e}" is not registered.`);return t}getTypePlugin(e){return this._plugins.get(e)}getAll(){return Array.from(this._plugins.values())}};function Vt(e,t){return function(n,r){t(n,r,e)}}function Ht(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}function Ut(e){let t=e&&typeof e==`object`?e:{},n=Number(t.start??0),r=Number(t.end??100);return t.customRange===!0?{start:Number.isFinite(n)?n:0,end:Number.isFinite(r)?r:100}:{start:0,end:100}}function Wt(e,t){let n=t&&typeof t==`object`&&!Array.isArray(t)?t:{},r=e.toFixed(Gt(n.decimalPlaces));return n.format===`number`?r:`${r}%`}function Gt(e){if(e==null||e===``)return 0;let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(0,Math.min(2,Math.round(t))):0}const Kt=/* @__PURE__ */ new Set([e.BaseFieldType.Progress,e.BaseFieldType.Rating,e.BaseFieldType.Checkbox]);function qt(t){let n=t.fields[t.primaryFieldId];if((!n||n.system!==!0&&n.id.toLowerCase()!==`id`&&n.name.trim().toLowerCase()!==`id`)&&n)return n.id;for(let n of t.fieldOrder){let r=t.fields[n];if(r&&r.id!==t.primaryFieldId&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)return r.id}return t.primaryFieldId}function q(t,n=[],r=5){let i=new Set(n.filter(e=>!!e)),a=[],o=[];for(let n of t.fieldOrder){let r=t.fields[n];r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId&&!i.has(r.id)&&(Kt.has(r.type)?a:o).push(r.id)}return[...a,...o].slice(0,r)}function Jt(){return[{type:e.BaseViewType.Grid,i18nKey:`base.viewType.grid`,createDefaultConfig:()=>({}),validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Grid projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Kanban,i18nKey:`base.viewType.kanban`,createDefaultConfig:e=>{let t=Yt(e);return{groupFieldId:t,coverFieldId:null,cardLayout:`normal`,showFieldNames:!0,fieldSettings:{},columnSettings:{},card:{titleFieldId:e.primaryFieldId,fieldIds:q(e,[e.primaryFieldId,t])}}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Kanban projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Calendar,i18nKey:`base.viewType.calendar`,createDefaultConfig:e=>{let t=Xt(e);return{startDateFieldId:t,endDateFieldId:Zt(e,t),titleFieldId:e.primaryFieldId,mode:`month`,timeslotSize:`medium`,timeZone:`local`,displayColor:{type:`custom`,color:`#3b82f6`},fieldSettings:{}}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Calendar projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Gantt,i18nKey:`base.viewType.gantt`,createDefaultConfig:e=>{let t=Xt(e);return{startDateFieldId:t,endDateFieldId:Zt(e,t)??t,titleFieldId:e.primaryFieldId,scale:`month`,showTodayLine:!0,displayColor:{type:`custom`,color:`#3b82f6`},fieldSettings:{},workingDaysOnly:!1}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Gantt projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Gallery,i18nKey:`base.viewType.gallery`,createDefaultConfig:e=>{let t=qt(e);return{coverFieldId:null,cardLayout:`normal`,showFieldNames:!0,fieldSettings:{},card:{titleFieldId:t,coverFieldId:null,fieldIds:q(e,[t,e.primaryFieldId])},cardSize:`medium`}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Gallery projection is implemented by BaseProjectionService.`)}}]}function Yt(t){var n,r,i;let a=t.fieldOrder.map(e=>t.fields[e]).filter(e=>!!e);return((n=a.find(t=>t.type===e.BaseFieldType.SingleSelect||t.type===e.BaseFieldType.MultiSelect||t.type===e.BaseFieldType.Group))==null?void 0:n.id)??((r=a.find(t=>t.type===e.BaseFieldType.Text))==null?void 0:r.id)??((i=a.find(t=>t.type===e.BaseFieldType.Date||t.type===e.BaseFieldType.CreatedAt||t.type===e.BaseFieldType.UpdatedAt))==null?void 0:i.id)??t.primaryFieldId}function Xt(e){var t;return((t=e.fieldOrder.map(t=>e.fields[t]).find(Qt))==null?void 0:t.id)??``}function Zt(e,t){var n;return(n=e.fieldOrder.map(t=>e.fields[t]).find(e=>Qt(e)&&e.id!==t))==null?void 0:n.id}function Qt(t){return!!t&&t.type===e.BaseFieldType.Date&&t.readonly!==!0&&t.system!==!0}const $t=(0,e.createIdentifier)(`base.projection.service`),en=/* @__PURE__ */ new Set([e.BaseFieldType.Number,e.BaseFieldType.Currency,e.BaseFieldType.Progress,e.BaseFieldType.Rating,e.BaseFieldType.Date,e.BaseFieldType.CreatedAt,e.BaseFieldType.UpdatedAt,e.BaseFieldType.Checkbox]),J=864e5;let tn=class extends e.Disposable{constructor(e){super(),this._fieldRegistry=e,K(this,`_views`,/* @__PURE__ */ new Map),K(this,`_projectionCache`,/* @__PURE__ */ new WeakMap),K(this,`_projectedRowsCache`,/* @__PURE__ */ new Map),K(this,`_projectedViewRowsCache`,/* @__PURE__ */ new Map),K(this,`_projectedGroupsCache`,/* @__PURE__ */ new Map),K(this,`_hierarchyIndexCache`,/* @__PURE__ */ new Map),K(this,`_globalRevision`,0),K(this,`_tableRevisions`,/* @__PURE__ */ new Map),K(this,`_cellRevisions`,/* @__PURE__ */ new Map),K(this,`_cellInvalidations`,/* @__PURE__ */ new Map),K(this,`_viewRevisions`,/* @__PURE__ */ new Map)}registerView(t){return this._views.set(t.type,t),(0,e.toDisposable)(()=>this._views.delete(t.type))}getProjection(t,n,r){var i,a,o;return E(`BaseProjection.getProjection`,()=>{let i=this._getCachedProjection(t,n,r);if(i)return i;let a=t.tables[n],o=a==null?void 0:a.views[r];if(!a||!o)return this._setCachedProjection(t,n,r,{type:`invalid`,viewType:(o==null?void 0:o.type)??e.BaseViewType.Grid,reason:`missingField`});let s;switch(o.type){case e.BaseViewType.Grid:s=this._buildGrid(a,o);break;case e.BaseViewType.Gantt:s=this._buildGantt(a,o);break;case e.BaseViewType.Kanban:s=this._buildKanban(a,o);break;case e.BaseViewType.Calendar:s=this._buildCalendar(a,o);break;case e.BaseViewType.Gallery:s=this._buildGallery(a,o);break;default:s={type:`invalid`,viewType:o.type,reason:`missingField`}}return this._setCachedProjection(t,n,r,s)},{tableId:n,viewId:r,viewType:(i=t.tables[n])==null||(i=i.views[r])==null?void 0:i.type,records:((a=t.tables[n])==null||(a=a.recordOrder)==null?void 0:a.length)??Object.keys(((o=t.tables[n])==null?void 0:o.records)??{}).length})}repairViewConfig(e,t,n){var r,i,a;let o=e.tables[t],s=o==null?void 0:o.views[n];if(!o||!s)throw Error(`[BaseProjectionService]: missing view "${n}".`);let c=e=>!!o.fields[e],l={...s,filter:s.filter?{...s.filter,conditions:s.filter.conditions.filter(e=>c(e.fieldId))}:s.filter,sort:(r=s.sort)==null?void 0:r.filter(e=>c(e.fieldId)),group:(i=s.group)==null?void 0:i.filter(e=>c(e.fieldId)),fieldOrder:(a=s.fieldOrder)==null?void 0:a.filter(c),fieldSettings:Object.fromEntries(Object.entries(s.fieldSettings??{}).filter(([e])=>c(e)))};if(l.type===`kanban`){var u;let e=l.config??{},t=this._resolveKanbanGroupFieldId(o,l),n=this._resolveCardTitleFieldId(o,(u=e.card)==null?void 0:u.titleFieldId);l.config={...e,groupFieldId:t??e.groupFieldId,coverFieldId:this._resolveKanbanCoverFieldId(o,e),cardLayout:e.cardLayout===`compose`?`compose`:`normal`,showFieldNames:e.showFieldNames!==!1,fieldSettings:Object.fromEntries(Object.entries(e.fieldSettings??{}).filter(([e])=>c(e))),columnSettings:e.columnSettings??{},card:{...e.card??{},titleFieldId:n,fieldIds:this._resolveKanbanCardFieldIds(o,l,t??``,n)}}}return{repaired:JSON.stringify(l)!==JSON.stringify(s),view:l}}invalidateByOp(){this._globalRevision++}invalidateByCell(e,t,n){let r=this._getCellRevision(e)+1;this._cellRevisions.set(e,r);let i=this._cellInvalidations.get(e)??[];i.push({revision:r,recordId:t,fieldId:n}),this._cellInvalidations.set(e,i)}invalidateByField(e,t){this._bumpTableRevision(e)}invalidateByView(e,t){this._viewRevisions.set(this._viewRevisionKey(e,t),this._getViewRevision(e,t)+1)}_getCachedProjection(e,t,n){var r;let i=(r=this._projectionCache.get(e))==null?void 0:r.get(this._cacheKey(t,n));return i&&i.globalRevision===this._globalRevision&&i.tableRevision===this._getTableRevision(t)&&i.cellRevision===this._getCellRevision(t)&&i.viewRevision===this._getViewRevision(t,n)?i.projection:null}_setCachedProjection(e,t,n,r){let i=this._projectionCache.get(e);return i||(i=/* @__PURE__ */ new Map,this._projectionCache.set(e,i)),i.set(this._cacheKey(t,n),{projection:r,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(t),cellRevision:this._getCellRevision(t),viewRevision:this._getViewRevision(t,n)}),r}_bumpTableRevision(e){this._tableRevisions.set(e,this._getTableRevision(e)+1)}_getTableRevision(e){return this._tableRevisions.get(e)??0}_getCellRevision(e){return this._cellRevisions.get(e)??0}_getViewRevision(e,t){return this._viewRevisions.get(this._viewRevisionKey(e,t))??0}_cacheKey(e,t){return`${e}\u0000${t}`}_viewRowsCacheKey(e,t){return`${e}\u0000${this._rowTransformCacheSegment(t)}`}_groupsCacheKey(e,t,n){return`${e}\u0000${this._rowTransformCacheSegment(t)}\u0000${this._groupConfigCacheSegment(n)}`}_rowTransformCacheSegment(e){return e?Y({filter:on(e.filter),sort:cn(e.sort)}):`__all__`}_groupConfigCacheSegment(e){return Y(e.map(e=>({fieldId:e.fieldId,direction:e.direction??null})))}_viewRevisionKey(e,t){return`${e}\u0000${t}`}_buildGrid(t,n){let{rows:r,hierarchy:i}=this._projectHierarchyRows(t,n,g(t));return{type:e.BaseViewType.Grid,fields:this._projectFields(t,n),rows:r,groups:this._projectHierarchyGroups(t,n,r,i),hierarchy:i,frozenFieldCount:typeof n.config.frozenFieldCount==`number`?n.config.frozenFieldCount:0}}_projectHierarchyRows(e,t,n){var r;let i=this._projectRows(e,t),a=(r=t.filter)!=null&&r.conditions.length?this._projectRows(e,{...t,filter:null}):i;return w(this._getHierarchyIndex(e,n,t.id,a.map(e=>e.recordId)),a,new Set(i.map(e=>e.recordId)))}_getHierarchyIndex(e,t,n,r){let i=`${e.id}\u0000${t}\u0000${n}`,a=this._getCellRevision(e.id),o=this._hierarchyIndexCache.get(i);if(o&&o.globalRevision===this._globalRevision&&o.tableRevision===this._getTableRevision(e.id)&&o.orderedRecordIds.length===r.length&&o.orderedRecordIds.every((e,t)=>e===r[t])){if(o.cellRevision===a&&o.table===e)return o.index;if(!this._cellInvalidationsTouchFields(e.id,o.cellRevision,a,/* @__PURE__ */ new Set([t])))return this._hierarchyIndexCache.set(i,{...o,table:e,cellRevision:a}),o.index}let s=C(e,t,r);return this._hierarchyIndexCache.set(i,{table:e,index:s,orderedRecordIds:r,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:a}),s}_projectHierarchyGroups(e,t,n,r){var i;if(!((i=t.group)!=null&&i.length))return[];let a=new Map(n.map(e=>[e.recordId,e])),o=r.rootRecordIds.flatMap(e=>{let t=a.get(e);return t?[t]:[]}),s=this._projectGroups(e,t,o),c=new Map(r.orderedRecordIds.map((e,t)=>[e,t])),l=e=>{let t=r.nodes[e],n=c.get(e)??-1;return n<0||!t?[]:r.orderedRecordIds.slice(n,t.subtreeEndIndex+1)},u=e=>{var t,n;return{...e,recordIds:(t=e.children)!=null&&t.length?e.recordIds:e.recordIds.flatMap(l),children:(n=e.children)==null?void 0:n.map(u)}};return s.map(u)}_buildKanban(t,n){var r;let i=this._resolveKanbanGroupFieldId(t,n),a=i?t.fields[i]:void 0;if(!a)return{type:`invalid`,viewType:e.BaseViewType.Kanban,reason:`invalidGroupField`,fieldId:n.config.groupFieldId};let o=this._projectRows(t,n),s=this._projectFields(t,n),c=n.config??{},l=this._resolveCardTitleFieldId(t,(r=c.card)==null?void 0:r.titleFieldId),u=this._resolveKanbanCardFieldIds(t,n,a.id,l),d=/* @__PURE__ */ new Map;if(m(t,a.id)){let r=this._getHierarchyIndex(t,a.id,n.id,o.map(e=>e.recordId)),i=/* @__PURE__ */ new Map;return o.forEach(e=>{let n=r.parentByRecordId.get(e.recordId)??null,o=n??``,s=n?t.records[n]:void 0,l=i.get(o)??{key:o,title:s?String(O(t,s.id,t.primaryFieldId)??n):this._kanbanLaneTitle(a,o,c),recordIds:[]};l.recordIds.push(e.recordId),i.set(o,l)}),{type:e.BaseViewType.Kanban,fields:s,rows:o,groups:[],groupFieldId:a.id,titleFieldId:l,coverFieldId:this._resolveKanbanCoverFieldId(t,c),cardLayout:c.cardLayout===`compose`?`compose`:`normal`,showFieldNames:c.showFieldNames!==!1,visibleCardFieldIds:u,lanes:[``,...r.orderedRecordIds].flatMap(e=>{let t=i.get(e);return t!=null&&t.recordIds.length?[t]:[]})}}return this._getKanbanConfiguredLanes(a,c).forEach(e=>d.set(e.key,{...e,recordIds:[]})),o.forEach(e=>{this._kanbanGroupKeys(a,e.values[a.id]).forEach(t=>{let n=d.get(t)??{key:t,title:this._kanbanLaneTitle(a,t,c),color:this._kanbanLaneColor(a,t,c),recordIds:[]};n.recordIds.push(e.recordId),d.set(t,n)})}),{type:e.BaseViewType.Kanban,fields:s,rows:o,groups:this._projectGroups(t,n,o),groupFieldId:a.id,titleFieldId:l,coverFieldId:this._resolveKanbanCoverFieldId(t,c),cardLayout:c.cardLayout===`compose`?`compose`:`normal`,showFieldNames:c.showFieldNames!==!1,visibleCardFieldIds:u,lanes:Array.from(d.values())}}_resolveKanbanGroupFieldId(e,t){var n;let r=(n=t.config)==null?void 0:n.groupFieldId;return r&&this._isKanbanGroupField(e,r)?r:this._findKanbanGroupField(e,e=>this._isAllowedKanbanGroupField(e))}_findKanbanGroupField(e,t){for(let n of e.fieldOrder){let r=e.fields[n];if(r&&t(r))return r.id}return null}_isKanbanGroupField(e,t){let n=e.fields[t];return this._isAllowedKanbanGroupField(n)||m(e,t)}_isAllowedKanbanGroupField(t){return!!t&&(t.type===e.BaseFieldType.SingleSelect||t.type===e.BaseFieldType.MultiSelect||t.type===e.BaseFieldType.Rating||t.type===e.BaseFieldType.Person||t.type===e.BaseFieldType.Group||t.type===e.BaseFieldType.Checkbox)}_isColorfulKanbanGroupField(t){return t.type===e.BaseFieldType.SingleSelect||t.type===e.BaseFieldType.MultiSelect}_resolveKanbanCoverFieldId(e,t){var n;let r=t.coverFieldId??((n=t.card)==null?void 0:n.coverFieldId)??null;if(!r)return null;let i=e.fields[r];return i&&this._capabilities(i).usableAsCardCover?i.id:null}_resolveKanbanCardFieldIds(t,n,r,i=this._resolveCardTitleFieldId(t,(()=>{var e;return(e=n.config)==null||(e=e.card)==null?void 0:e.titleFieldId})())){var a;let o=n.config??{},s=(a=o.card)!=null&&(a=a.fieldIds)!=null&&a.length?o.card.fieldIds:q(t,[i,t.primaryFieldId,r]),c=o.fieldSettings??{};return s.filter(a=>{var o,s;let l=t.fields[a];return!(!l||l.system===!0||l.type===e.BaseFieldType.RecordId||l.id===r||l.id===i||(o=n.fieldSettings)!=null&&(o=o[a])!=null&&o.hidden||(s=c[a])!=null&&s.hidden)}).sort((e,t)=>{var n,r;return(((n=c[e])==null?void 0:n.order)??s.indexOf(e))-(((r=c[t])==null?void 0:r.order)??s.indexOf(t))})}_getKanbanConfiguredLanes(e,t){var n;let r=(Array.isArray((n=e.config)==null?void 0:n.options)?e.config.options:[]).flatMap((n,r)=>{if(n==null)return[];let i=typeof n==`string`?{id:n,name:n,color:void 0}:n,a=String(i.id??i.name??`option-${r+1}`);return[{key:a,title:String(i.name??i.id??a),color:this._kanbanLaneColor(e,a,t)}]});return Object.entries(t.columnSettings??{}).forEach(([n,i])=>{r.some(e=>e.key===n)||r.push({key:n,title:this._isColorfulKanbanGroupField(e)?i.title??this._kanbanLaneTitle(e,n,t):this._kanbanLaneTitle(e,n,t),color:this._kanbanLaneColor(e,n,t)})}),r}_kanbanGroupKeys(e,t){let n=t=>{var n;let r=t==null?``:String(t);return!r||!this._isColorfulKanbanGroupField(e)?r:((n=$(e,r))==null?void 0:n.id)??r};if(Array.isArray(t)){let e=t.map(n).filter(e=>e!==``);return e.length?e:[``]}return[n(t)]}_kanbanLaneTitle(e,t,n){if(!t)return`Uncategorized`;let r=$(e,t);return(r==null?void 0:r.name)??t}_kanbanLaneColor(e,t,n){var r;if(this._isColorfulKanbanGroupField(e))return(r=$(e,t))==null?void 0:r.color}_buildCalendar(t,n){let r=this._normalizeCalendarConfig(t,n.config??{}),i=t.fields[r.startDateFieldId];if(!i||i.type!==e.BaseFieldType.Date||i.readonly===!0||i.system===!0||!this._capabilities(i).usableAsCalendarDate)return{type:`invalid`,viewType:e.BaseViewType.Calendar,reason:`invalidDateField`,fieldId:r.startDateFieldId};let a=r.endDateFieldId?t.fields[r.endDateFieldId]:void 0,o=this._projectRows(t,n);return{type:e.BaseViewType.Calendar,config:r,fields:this._projectFields(t,n),rows:o,groups:this._projectGroups(t,n,o),events:o.flatMap(e=>{let n=B(e.values[r.startDateFieldId]);if(!Number.isFinite(n))return[];let o=e.values[r.startDateFieldId],s=r.endDateFieldId==null?void 0:e.values[r.endDateFieldId],c=r.endDateFieldId==null?void 0:B(s),l=Number.isFinite(c)?c:void 0;return[{recordId:e.recordId,title:this._title(t,e,r.titleFieldId),start:n,end:l,color:this._calendarEventColor(t,e,r),startMs:n,endMs:l,allDay:this._isAllDayCalendarEvent(i,a,o,s),fieldValues:e.values}]})}}_normalizeCalendarConfig(t,n){let r=this._resolveCalendarDateFieldId(t,n.startDateFieldId),i=n.endDateFieldId&&this._isCalendarDateField(t,n.endDateFieldId)?n.endDateFieldId:this._findCalendarDateFieldId(t,r)??void 0,a=n.titleFieldId?t.fields[n.titleFieldId]:void 0,o=a&&a.system!==!0&&a.type!==e.BaseFieldType.RecordId?n.titleFieldId:t.primaryFieldId,s=n.mode===`day`||n.mode===`week`?n.mode:`month`,c=n.timeslotSize===`short`||n.timeslotSize===`long`?n.timeslotSize:`medium`,l=typeof n.timeZone==`string`&&n.timeZone.trim()?n.timeZone:`local`,u=this._normalizeCalendarDisplayColor(t,n);return{...n,startDateFieldId:r,endDateFieldId:i,titleFieldId:o,mode:s,timeslotSize:c,timeZone:l,displayColor:u,fieldSettings:Object.fromEntries(Object.entries(n.fieldSettings??{}).filter(([n])=>{let r=t.fields[n];return!!(r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)}))}}_resolveCalendarDateFieldId(e,t){return t&&this._isCalendarDateField(e,t)?t:this._findCalendarDateFieldId(e)??t??``}_findCalendarDateFieldId(e,t){for(let n of e.fieldOrder)if(n!==t&&this._isCalendarDateField(e,n))return n;return null}_isCalendarDateField(t,n){let r=t.fields[n];return!!r&&r.type===e.BaseFieldType.Date&&r.readonly!==!0&&r.system!==!0&&this._capabilities(r).usableAsCalendarDate}_normalizeCalendarDisplayColor(t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`selectField`){let n=t.fields[r.fieldId];if(n&&n.type===e.BaseFieldType.SingleSelect)return r}if((r==null?void 0:r.type)===`custom`&&typeof r.color==`string`&&r.color.trim())return{type:`custom`,color:r.color};if(n.colorFieldId){let r=t.fields[n.colorFieldId];if(r&&r.type===e.BaseFieldType.SingleSelect)return{type:`selectField`,fieldId:n.colorFieldId}}return{type:`custom`,color:`#3b82f6`}}_calendarEventColor(e,t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`selectField`){var i;let n=e.fields[r.fieldId];if(!n)return;let a=t.values[r.fieldId],o=Array.isArray(a)?a[0]:a;return o==null||(i=$(n,String(o)))==null?void 0:i.color}if((r==null?void 0:r.type)===`custom`)return r.color}_isAllDayCalendarEvent(e,t,n,r){var i,a;let o=((i=e.config)==null?void 0:i.includeTime)===!0,s=(t==null||(a=t.config)==null?void 0:a.includeTime)===!0;return!o&&!s}_isAllDayGanttDateRange(e,t){var n,r;let i=((n=e.config)==null?void 0:n.includeTime)===!0,a=((r=t.config)==null?void 0:r.includeTime)===!0;return!i&&!a}_buildGantt(t,r){let i=this._normalizeGanttConfig(t,r.config),a=t.fields[i.startDateFieldId];if(!a||a.type!==e.BaseFieldType.Date||a.readonly===!0||a.system===!0||!this._capabilities(a).usableAsGanttStart)return{type:`invalid`,viewType:e.BaseViewType.Gantt,reason:`invalidGanttStartField`,fieldId:i.startDateFieldId};let o=t.fields[i.endDateFieldId];if(!o||o.type!==e.BaseFieldType.Date||o.readonly===!0||o.system===!0||!this._capabilities(o).usableAsGanttEnd)return{type:`invalid`,viewType:e.BaseViewType.Gantt,reason:`invalidGanttEndField`,fieldId:i.endDateFieldId};let s=this._isAllDayGanttDateRange(a,o),c=h(t),u=c?this._projectHierarchyRows(t,r,c):void 0,d=u==null?void 0:u.hierarchy,f=(u==null?void 0:u.rows)??this._projectRows(t,r),p=i.dependencyFieldId,m=p&&l(t.id,t.fields[p])?p:void 0,g=t.fields[i.progressFieldId??``],_=(g==null?void 0:g.type)===e.BaseFieldType.Progress&&!g.system?{id:g.id,...Ut(g.config),editable:!g.readonly}:void 0,v=f.flatMap(e=>{let r=B(e.values[i.startDateFieldId]),a=B(e.values[i.endDateFieldId]);if(!Number.isFinite(r)||!Number.isFinite(a))return[];let o=Math.min(r,a),s=Math.max(r,a),c=e.values[i.progressFieldId??``],l=c==null||c===``?void 0:Number(c),u=l!=null&&Number.isFinite(l)&&_&&_.start!==_.end?Math.max(0,Math.min(1,(l-_.start)/(_.end-_.start))):void 0;return[{recordId:e.recordId,title:this._title(t,e,i.titleFieldId),start:o,end:s,color:this._ganttBarColor(t,e,i),progress:Number.isFinite(l)?l:void 0,completion:u,workingDayCount:i.workingDaysOnly?yn(o,s,i.workingDays):void 0,dependencyRecordIds:m?n(e.values[m]):void 0}]}),y=i.showPlanComparison===!0?this._buildGanttPlan(t,f,i):void 0,b=1/0,x=-1/0;for(let e of[v,(y==null?void 0:y.bars)??[]])for(let t of e)b=Math.min(b,t.start),x=Math.max(x,t.end);let S=Date.now(),C=Z((Number.isFinite(b)?b:S)-90*J),w=Z((Number.isFinite(x)?x:S)+91*J),T=un(i.scale,C,w,i.workingDaysOnly?i.workingDays:void 0);return{type:e.BaseViewType.Gantt,fields:this._projectFields(t,{...r,config:i}),rows:f,groups:d?this._projectHierarchyGroups(t,r,f,d):this._projectGroups(t,r,f),...d?{hierarchy:d}:{},config:{...i,dependencyFieldId:m},..._?{progressField:_}:{},dateRangeAllDay:s,timeline:{scale:i.scale,start:C,end:w,unitWidth:T.unitWidth,majorHeaders:T.majorHeaders,columns:T.columns},bars:v,...y?{plan:y}:{}}}_buildGanttPlan(e,t,n){let{planStartDateFieldId:r,planEndDateFieldId:i}=n,a={bars:[],needsDateFields:!0,invalidRecordIds:[]};if(!r||!i||!this._isGanttDateField(e,r,`start`)||!this._isGanttDateField(e,i,`end`))return a;a.needsDateFields=!1;for(let o of t){let t=B(o.values[r]),s=B(o.values[i]);t!=null&&s!=null&&Number.isFinite(t)&&Number.isFinite(s)&&(t>s?a.invalidRecordIds.push(o.recordId):a.bars.push({recordId:o.recordId,title:this._title(e,o,n.titleFieldId),start:t,end:s}))}return a}_normalizeGanttConfig(t,n){let r=this._resolveGanttDateFieldId(t,n.startDateFieldId,`start`),i=this._resolveGanttDateFieldId(t,n.endDateFieldId,`end`)||r,a=n.titleFieldId?t.fields[n.titleFieldId]:void 0,o=a&&a.system!==!0&&a.type!==e.BaseFieldType.RecordId?n.titleFieldId:t.primaryFieldId,s=n.scale===`week`||n.scale===`quarter`||n.scale===`year`?n.scale:`month`,c=X(n.workingDays);return{...n,startDateFieldId:r,endDateFieldId:i,titleFieldId:o,scale:s,leftPaneWidth:typeof n.leftPaneWidth==`number`?n.leftPaneWidth:void 0,leftPaneCollapsed:n.leftPaneCollapsed===!0,showTodayLine:n.showTodayLine!==!1,displayColor:this._normalizeGanttDisplayColor(t,n),fieldSettings:Object.fromEntries(Object.entries(n.fieldSettings??{}).filter(([n])=>{let r=t.fields[n];return!!(r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)})),workingDaysOnly:n.workingDaysOnly===!0,workingDays:c}}_resolveGanttDateFieldId(e,t,n){if(t&&this._isGanttDateField(e,t,n)||t)return t;for(let t of e.fieldOrder)if(this._isGanttDateField(e,t,n))return t;return t??``}_isGanttDateField(t,n,r){let i=t.fields[n];if(!i||i.type!==e.BaseFieldType.Date||i.readonly===!0||i.system===!0)return!1;let a=this._capabilities(i);return r===`start`?a.usableAsGanttStart:a.usableAsGanttEnd}_normalizeGanttDisplayColor(t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`selectField`){let n=t.fields[r.fieldId];if(n&&n.type===e.BaseFieldType.SingleSelect)return r}return(r==null?void 0:r.type)===`conditional`&&Array.isArray(r.rules)?{type:`conditional`,rules:r.rules.filter(e=>!!t.fields[e.fieldId])}:(r==null?void 0:r.type)===`custom`&&typeof r.color==`string`&&r.color.trim()?{type:`custom`,color:r.color}:{type:`custom`,color:`#14b8a6`}}_ganttBarColor(e,t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`conditional`){let n=r.rules.find(n=>this._matchesGanttColorRule(e,t,n));if(n)return n.color}if((r==null?void 0:r.type)===`selectField`){let n=e.fields[r.fieldId];if(n){var i;let e=t.values[r.fieldId],a=Array.isArray(e)?e[0]:e,o=a==null||(i=$(n,String(a)))==null?void 0:i.color;if(o)return o}}return(r==null?void 0:r.type)===`custom`?r.color:`#14b8a6`}_matchesGanttColorRule(e,t,n){let r=e.fields[n.fieldId];return r?ot(t.values[r.id],n.operator,n.operand,r,{dateMode:n.dateMode}):!1}_buildGallery(t,n){let r=this._projectRows(t,n),i=this._normalizeGalleryConfig(t,n.config??{}),a=this._projectFields(t,n);return{type:e.BaseViewType.Gallery,fields:a,rows:r,groups:this._projectGroups(t,n,r),titleFieldId:i.card.titleFieldId,coverFieldId:i.coverFieldId,cardLayout:i.cardLayout??`normal`,showFieldNames:i.showFieldNames!==!1,visibleCardFieldIds:this._resolveGalleryCardFieldIds(t,n,i),cardSize:i.cardSize??`medium`,cards:r.map(e=>({recordId:e.recordId,title:this._title(t,e,i.card.titleFieldId),values:e.values}))}}_normalizeGalleryConfig(t,n){let r=n.card??{fieldIds:[]},i=this._resolveCardTitleFieldId(t,r.titleFieldId),a=this._resolveGalleryCoverFieldId(t,n),o=n.cardSize===`small`||n.cardSize===`large`?n.cardSize:`medium`;return{...n,coverFieldId:a,cardLayout:n.cardLayout===`compose`?`compose`:`normal`,showFieldNames:n.showFieldNames!==!1,fieldSettings:Object.fromEntries(Object.entries(n.fieldSettings??{}).filter(([n])=>{let r=t.fields[n];return!!(r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)})),card:{...r,titleFieldId:i,coverFieldId:a,fieldIds:Array.isArray(r.fieldIds)?r.fieldIds:[]},cardSize:o}}_resolveCardTitleFieldId(t,n){let r=n?t.fields[n]:void 0;return r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId?r.id:qt(t)}_resolveGalleryCoverFieldId(e,t){var n;let r=t.coverFieldId??((n=t.card)==null?void 0:n.coverFieldId)??null;if(!r)return null;let i=e.fields[r];return i&&this._capabilities(i).usableAsCardCover?i.id:null}_resolveGalleryCardFieldIds(t,n,r){var i,a,o;let s=r.fieldSettings??{},c=((i=r.card)==null?void 0:i.titleFieldId)??qt(t),l=r.coverFieldId??((a=r.card)==null?void 0:a.coverFieldId)??null,u=(o=r.card)!=null&&(o=o.fieldIds)!=null&&o.length?r.card.fieldIds:q(t,[c,l,t.primaryFieldId]);return u.filter(r=>{var i,a;let o=t.fields[r];return!(!o||o.system===!0||o.type===e.BaseFieldType.RecordId||o.id===c||o.id===l||(i=n.fieldSettings)!=null&&(i=i[r])!=null&&i.hidden||(a=s[r])!=null&&a.hidden)}).sort((e,t)=>{var n,r;return(((n=s[e])==null?void 0:n.order)??u.indexOf(e))-(((r=s[t])==null?void 0:r.order)??u.indexOf(t))})}_projectFields(t,n){var r;return((r=n.fieldOrder)!=null&&r.length?n.fieldOrder:t.fieldOrder).flatMap(r=>{var i;let a=t.fields[r],o=((i=n.fieldSettings)==null?void 0:i[r])??{};return!a||a.system===!0||a.type===e.BaseFieldType.RecordId||o.hidden?[]:[{id:a.id,name:a.name,description:a.description,type:a.type,config:a.config,width:o.width,setting:o}]})}_projectRows(e,t){var n;return E(`BaseProjection.projectRows`,()=>{var n,r;let i=this._projectTableRows(e),a=this._viewRowsCacheKey(e.id,t),o=this._getCellRevision(e.id),s=this._projectedViewRowsCache.get(a);if(s&&s.globalRevision===this._globalRevision&&s.tableRevision===this._getTableRevision(e.id)){if(s.cellRevision===o&&s.baseRows===i)return s.rows;if(s.cellRevision!==o&&!this._cellInvalidationsTouchFields(e.id,s.cellRevision,o,this._filterSortFieldIds(t))){let e=s.rows===s.baseRows?i:this._patchCachedProjectedRows(s.rows,i);if(e)return this._projectedViewRowsCache.set(a,{...s,rows:e,baseRows:i,cellRevision:o}),e}}let c=E(`BaseProjection.filterAndSortRows`,()=>this._sortRows(e,t,this._filterRows(e,t,i)),{tableId:e.id,viewId:t==null?void 0:t.id,viewType:t==null?void 0:t.type,rows:i.length,filters:(t==null||(n=t.filter)==null?void 0:n.conditions.length)??0,sorts:(t==null||(r=t.sort)==null?void 0:r.length)??0});return this._projectedViewRowsCache.set(a,{table:e,rows:c,baseRows:i,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:o}),c},{tableId:e.id,viewId:t==null?void 0:t.id,viewType:t==null?void 0:t.type,records:((n=e.recordOrder)==null?void 0:n.length)??Object.keys(e.records??{}).length})}_projectTableRows(e){var t;return E(`BaseProjection.projectTableRows`,()=>{var t;let n=this._getCellRevision(e.id),r=this._projectedRowsCache.get(e.id);if(r&&r.globalRevision===this._globalRevision&&r.tableRevision===this._getTableRevision(e.id)){if(r.cellRevision===n&&sn(r.table,e))return r.table=e,r.rows;let t=this._patchProjectedRowsForCellInvalidations(e,r,n);if(t)return t}an(e)||D(e);let i=(t=e.recordOrder)!=null&&t.length?e.recordOrder:ln(e.records),a=E(`BaseProjection.materializeTableRows`,()=>{let t=[];for(let n of i){let r=e.records[n];if(!r)continue;let i={};for(let t of e.fieldOrder)i[t]=O(e,r.id,t);t.push({recordId:r.id,values:i})}return t},{tableId:e.id,records:i.length,fields:e.fieldOrder.length});return this._projectedRowsCache.set(e.id,{table:e,rows:a,rowIndexById:rn(a),globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:n}),a},{tableId:e.id,records:((t=e.recordOrder)==null?void 0:t.length)??Object.keys(e.records??{}).length,fields:e.fieldOrder.length})}_patchProjectedRowsForCellInvalidations(e,t,n){let r=(this._cellInvalidations.get(e.id)??[]).filter(e=>e.revision>t.cellRevision&&e.revision<=n);if(!r.length)return t.table===e?t.rows:null;let i=t.rows,a=/* @__PURE__ */ new Map;for(let e of r){let t=a.get(e.recordId);t||(t=/* @__PURE__ */ new Set,a.set(e.recordId,t)),t.add(e.fieldId)}for(let[n,r]of a){if(!e.records[n])return null;let a=t.rowIndexById.get(n);if(a==null)return null;i===t.rows&&(i=[...t.rows]);let o=i[a],s={...o.values};r.forEach(t=>{s[t]=O(e,n,t)}),i[a]={...o,values:s}}let o={table:e,rows:i,rowIndexById:t.rowIndexById,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:n};return this._projectedRowsCache.set(e.id,o),this._cellInvalidations.set(e.id,(this._cellInvalidations.get(e.id)??[]).filter(e=>e.revision>Math.max(0,n-256))),i}_patchCachedProjectedRows(e,t){let n=new Map(t.map(e=>[e.recordId,e])),r=!1,i=e.map(e=>{let t=n.get(e.recordId);return t?t===e?e:(r=!0,t):e});return r?i:e}_cellInvalidationsTouchFields(e,t,n,r){return!r.size||t===n?!1:n-t>256||(this._cellInvalidations.get(e)??[]).some(e=>e.revision>t&&e.revision<=n&&r.has(e.fieldId))}_filterSortFieldIds(e){var t,n;let r=/* @__PURE__ */ new Set;return e==null||(t=e.filter)==null||t.conditions.forEach(e=>r.add(e.fieldId)),e==null||(n=e.sort)==null||n.forEach(e=>r.add(e.fieldId)),r}_groupProjectionFieldIds(e){var t;let n=this._filterSortFieldIds(e);return(t=e.group)==null||t.forEach(e=>n.add(e.fieldId)),n}_filterRows(t,n,r){let i=n==null?void 0:n.filter;if(!(i!=null&&i.conditions.length))return r;let a=i.conditions.filter(e=>!kn(e));return a.length?r.filter(n=>{if(i.conjunction===e.BaseFilterConjunction.OR){for(let e of a){let r=t.fields[e.fieldId];if(!r||this._fieldRegistry.get(r.type).filter(n.values[r.id],e.operator,e.operand,r))return!0}return!1}for(let e of a){let r=t.fields[e.fieldId];if(r&&!this._fieldRegistry.get(r.type).filter(n.values[r.id],e.operator,e.operand,r))return!1}return!0}):r}_sortRows(t,n,r){let i=(n==null?void 0:n.sort)??[];if(!i.length)return r;let a=i.flatMap(e=>{let n=t.fields[e.fieldId];return n?[{...e,field:n}]:[]});return a.length?this._canUseFastSort(a)?this._fastSortRows(a,r):[...r].sort((t,n)=>{for(let r of a){let i=r.field,a=this._fieldRegistry.get(i.type).compare(t.values[i.id],n.values[i.id],i);if(a!==0)return r.direction===e.BaseSortDirection.DESC?-a:a}return 0}):r}_canUseFastSort(e){return e.every(e=>en.has(e.field.type))}_fastSortRows(t,n){return n.map((e,n)=>({row:e,index:n,keys:t.map(t=>e.values[t.fieldId])})).sort((n,r)=>{for(let i=0;i<t.length;i++){let a=On(n.keys[i],r.keys[i]);if(a!==0)return t[i].direction===e.BaseSortDirection.DESC?-a:a}return n.index-r.index}).map(e=>e.row)}_projectGroups(e,t,n){var r;return E(`BaseProjection.projectGroups`,()=>{var r;if(!((r=t.group)!=null&&r.length))return[];let i=t.group.filter(t=>e.fields[t.fieldId]);if(!i.length)return[];let a=this._groupsCacheKey(e.id,t,i),o=this._getCellRevision(e.id),s=this._projectedGroupsCache.get(a);if(s&&s.globalRevision===this._globalRevision&&s.tableRevision===this._getTableRevision(e.id)){if(s.cellRevision===o&&s.rows===n)return s.groups;if(s.cellRevision!==o&&!this._cellInvalidationsTouchFields(e.id,s.cellRevision,o,this._groupProjectionFieldIds(t)))return this._projectedGroupsCache.set(a,{...s,rows:n,cellRevision:o}),s.groups}let c=/* @__PURE__ */ new Map;for(let e of n){let t=c,n=``;for(let r=0;r<i.length;r++){let a=i[r],o=e.values[a.fieldId],s=nn(o),c=`${a.fieldId}\u0000${s}`,l=`${n}/${a.fieldId}:${s}`,u=t.get(c);u||(u={key:s,value:o,path:l,label:s||`Empty`,fieldId:a.fieldId,level:r,recordIds:[],children:/* @__PURE__ */ new Map},t.set(c,u)),u.recordIds.push(e.recordId),t=u.children,n=l}}let l=this._materializeGroups(i,c,0);return this._projectedGroupsCache.set(a,{table:e,rows:n,groups:l,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:o}),l},{tableId:e.id,viewId:t.id,viewType:t.type,rows:n.length,groupFields:((r=t.group)==null?void 0:r.length)??0})}_materializeGroups(t,n,r){var i;let a=Array.from(n.values()),o=(i=t[r])==null?void 0:i.direction;return o&&a.sort((t,n)=>{let r=t.key.localeCompare(n.key);return o===e.BaseSortDirection.DESC?-r:r}),a.map(e=>({key:e.key,value:e.value,path:e.path,label:e.label,fieldId:e.fieldId,level:e.level,recordIds:e.recordIds,children:this._materializeGroups(t,e.children,r+1)}))}_title(e,t,n){let r=n??e.primaryFieldId,i=t.values[r];return i==null?``:String(i)}_capabilities(e){return this._fieldRegistry.get(e.type).getCapabilities(e)}};tn=Ht([Vt(0,(0,e.Inject)(zt))],tn);function nn(e){return e==null?``:String(e)}function rn(e){return new Map(e.map((e,t)=>[e.recordId,t]))}function an(e){return!!(Array.isArray(e.recordOrder)&&e.rowIndex&&e.rowId&&e.colIndex&&e.colId&&e.cellData)}function on(e){let t=(e==null?void 0:e.conditions.filter(e=>!kn(e)))??[];return!e||!t.length?null:{conjunction:e.conjunction,conditions:t.map(e=>({fieldId:e.fieldId,operator:e.operator,operand:e.operand}))}}function sn(e,t){return e.records===t.records&&e.recordOrder===t.recordOrder&&e.fields===t.fields&&e.fieldOrder===t.fieldOrder&&e.cellData===t.cellData&&e.rowIndex===t.rowIndex&&e.rowId===t.rowId&&e.colIndex===t.colIndex&&e.colId===t.colId}function cn(e){return e!=null&&e.length?e.map(e=>({fieldId:e.fieldId,direction:e.direction})):null}function Y(e){if(typeof e!=`object`||!e)return JSON.stringify(e)??`undefined`;if(Array.isArray(e))return`[${e.map(Y).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${Y(t[e])}`).join(`,`)}}`}function ln(e){let t=Object.values(e).sort((e,t)=>e.orderKey.localeCompare(t.orderKey)),n=[];for(let e of t)n.push(e.id);return n}function X(e){return{weekdays:Array.isArray(e==null?void 0:e.weekdays)&&e.weekdays.length?[...new Set(e.weekdays.filter(e=>Number.isInteger(e)&&e>=1&&e<=7))]:[1,2,3,4,5],exceptions:Array.isArray(e==null?void 0:e.exceptions)?e.exceptions.flatMap(e=>!e||!Number.isFinite(e.date)?[]:[{id:String(e.id||`exception-${e.date}`),date:Z(Number(e.date)),name:String(e.name||`Working day`),type:e.type===`working`?`working`:`off`}]):[]}}function un(e,t,n,r){let i=mn(e,t),a=hn(e,n),o=dn(e,i,a,r);return{scale:e,start:i,end:a,unitWidth:pn(e),majorHeaders:fn(e,i,a),columns:o}}function dn(e,t,n,r){let i=[],a=t;for(;a<n;){let t=e===`quarter`?Q(a,7):e===`year`?Tn(a,1):Q(a,1);i.push({id:`${e}-${a}`,label:gn(e,a,t),majorLabel:_n(e,a),start:a,end:t,nonWorking:bn(a,t,r)}),a=t}return i}function fn(e,t,n){let r=[],i=e===`year`?wn(t):Cn(t);for(;i<n;){let t=e===`year`?En(i,1):Tn(i,1);r.push({id:`major-${i}`,label:e===`year`?String(new Date(i).getUTCFullYear()):Dn(i),start:i,end:t}),i=t}return r}function pn(e){switch(e){case`week`:return 172;case`quarter`:return 172;case`year`:return 136;default:return 86}}function mn(e,t){return e===`year`?wn(t):e===`quarter`?Sn(t):Z(t)}function hn(e,t){return e===`year`?En(wn(t),1):e===`quarter`?Q(Sn(t),7):Q(Z(t),1)}function gn(e,t,n){let r=new Date(t);return e===`quarter`?`${r.getUTCDate()}-${(/* @__PURE__ */ new Date(n-J)).getUTCDate()}`:e===`year`?r.toLocaleString(`en-US`,{month:`short`,timeZone:`UTC`}):String(r.getUTCDate())}function _n(e,t){return e===`year`?String(new Date(t).getUTCFullYear()):Dn(t)}function vn(e,t,n){let r=Z(e),i=Z(t);if(r===i||!Number.isFinite(r)||!Number.isFinite(i))return 0;let a=Math.min(r,i),o=Math.max(r,i),s=(o-a)/J,c=X(n),l=e=>{let t=new Date(e).getUTCDay();return c.weekdays.some(e=>e%7===t)},u=Math.floor(s/7)*c.weekdays.length;for(let e=1;e<=s%7;e++)u+=Number(l(Q(a,e)));let d=/* @__PURE__ */ new Set;for(let e of c.exceptions)e.date>a&&e.date<=o&&!d.has(e.date)&&(d.add(e.date),u+=Number(e.type===`working`)-Number(l(e.date)));return i<r&&u!==0?-u:u}function yn(e,t,n){let r=X(n),i=0;for(let n=Z(e);n<=Z(t);n=Q(n,1))xn(n,r)||i++;return i}function bn(e,t,n){if(!n)return!1;let r=X(n);for(let n=Z(e);n<t;n=Q(n,1))if(!xn(n,r))return!1;return!0}function xn(e,t){let n=Z(e),r=t.exceptions.find(e=>Z(e.date)===n);if(r)return r.type===`off`;let i=new Date(n).getUTCDay(),a=i===0?7:i;return!t.weekdays.includes(a)}function Z(e){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())}function Sn(e){let t=Z(e),n=new Date(t).getUTCDay();return Q(t,-(n===0?6:n-1))}function Cn(e){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),1)}function wn(e){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),0,1)}function Q(e,t){return e+t*J}function Tn(e,t){let n=new Date(e);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)}function En(e,t){let n=new Date(e);return Date.UTC(n.getUTCFullYear()+t,0,1)}function Dn(e){let t=new Date(e);return`${t.toLocaleString(`en-US`,{month:`short`,timeZone:`UTC`})} ${t.getUTCFullYear()}`}function On(e,t){if(e==null&&t==null)return 0;if(e==null)return-1;if(t==null)return 1;if(typeof e==`boolean`||typeof t==`boolean`)return Number(e===!0)-Number(t===!0);let n=Number(e),r=Number(t),i=Number.isFinite(n),a=Number.isFinite(r);return i&&a?n-r:i?1:a?-1:String(e).localeCompare(String(t))}function kn(e){if(e.operator!==`is`&&e.operator!==`isNot`)return!1;let t=e.operand;return t==null?!0:typeof t==`string`?t.trim()===``:Array.isArray(t)?t.length===0:!1}function $(e,t){var n;let r=Array.isArray((n=e.config)==null?void 0:n.options)?e.config.options:[];for(let e of r){if(e==null)continue;if(typeof e==`string`){if(e===t)return{id:e,name:e};continue}let n=e,r=String(n.id??n.name??``),i=String(n.name??n.id??r);if(r===t||i===t)return{id:r,name:i,color:n.color==null?void 0:String(n.color)}}return null}let An=/* @__PURE__ */ function(e){return e.CreateView=`create-view`,e.DeleteView=`delete-view`,e}({});const jn={id:`base.mutation.apply-base-json1`,type:e.CommandType.MUTATION,handler(t,r){let{unitId:i,op:a,ganttPredecessorAddition:o}=r,s=t.get(e.IUniverInstanceService).getUnit(i,e.UniverInstanceType.UNIVER_BASE);if(!s)return!1;if(!a)return!0;let l=s.getSnapshot(),u=new Oe,d=u.getAffectedRanges(a),f=u.applyOp(l,a);if(o){var p,m,h;let{tableId:e,fieldId:t,predecessorId:r,successorId:i}=o,a=(p=f.tables[e])==null?void 0:p.records;if(n(a==null||(m=a[i])==null?void 0:m.values[t]).includes(r)&&!n((h=l.tables[e])==null||(h=h.records[i])==null?void 0:h.values[t]).includes(r)&&c(r,i,e=>{var n;return a==null||(n=a[e])==null?void 0:n.values[t]}))return!1}return s.setSnapshot(f),Mn(f,d,t.get($t)),!0}};function Mn(e,t,n){let r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let o of t){if(o.reason===`view`&&o.tableId&&o.viewId){let e=`${o.tableId}\u0000${o.viewId}`;a.has(e)||(a.add(e),n.invalidateByView(o.tableId,o.viewId));continue}if(o.reason===`field`&&o.tableId&&o.fieldId){let e=`${o.tableId}\u0000${o.fieldId}`;i.has(e)||(i.add(e),n.invalidateByField(o.tableId,o.fieldId));continue}if(o.reason!==`cell`){n.invalidateByOp();return}let t=Nn(e,o);if(!t){n.invalidateByOp();return}let s=`${t.tableId}\u0000${t.recordId}\u0000${t.fieldId}`;r.has(s)||(r.add(s),n.invalidateByCell(t.tableId,t.recordId,t.fieldId))}}function Nn(e,t){var n,r;if(!t.tableId)return null;if(t.recordId&&t.fieldId)return{tableId:t.tableId,recordId:t.recordId,fieldId:t.fieldId};if(t.row==null||t.column==null)return null;let i=e.tables[t.tableId],a=i==null||(n=i.rowId)==null?void 0:n[t.row],o=i==null||(r=i.colId)==null?void 0:r[t.column];return!a||!o?null:{tableId:t.tableId,recordId:a,fieldId:o}}var Pn=`@univerjs-pro/bases`,Fn=`1.6.1`;const In={},Ln={};Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Qe}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return 5}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Vt}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Pn}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return vn}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Jt}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Ht}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Gt}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Ln}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return tn}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Ut}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return`bases.remote.config`}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Fn}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Wt}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return In}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return jn}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return`bases.config`}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return $t}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Bt}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return St}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return zt}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return j}});
|
|
2
|
+
`);if(e&&typeof e==`object`){let t=e;return String(t.name??t.label??t.text??t.value??t.id??``).trim().toLowerCase()}return String(e??``).trim().toLowerCase()}function bt(e,t){let n=U(e),r=xt(t.config??{});return n.flatMap(e=>r.get(e)??[e]).filter((e,t,n)=>e!==``&&n.indexOf(e)===t)}function U(e){if(e==null||e===``)return[];if(Array.isArray(e))return e.flatMap(e=>U(e));if(e&&typeof e==`object`){let t=e;return[`id`,`name`,`label`,`value`,`text`].flatMap(e=>U(t[e])).filter((e,t,n)=>n.indexOf(e)===t)}return[H(e)]}function xt(e){let t=/* @__PURE__ */ new Map;return(Array.isArray(e.options)?e.options:[]).forEach(e=>{if(!e||typeof e!=`object`)return;let n=U(e),r=n.filter((e,t)=>e!==``&&n.indexOf(e)===t);r.forEach(e=>t.set(e,r))}),t}function W(e,t={},n=e=>e,r={}){let i=!nt.has(e),a=n??(e=>e);return{type:e,i18nKey:`base.fieldType.${e}`,enabled:i,visibleInCreateMenu:i,createDefaultConfig:r.createDefaultConfig??(()=>({})),createDefaultValue:r.createDefaultValue??(e=>e.defaultValue??null),normalize:(e,t)=>a(e,t),validate:(e,t)=>{var n;return i?((n=r.validate)==null?void 0:n.call(r,e,t))??{valid:!0}:{valid:!1}},compare:(e,t)=>at(e,t),filter:(e,t,n,r)=>ot(e,t,n,r),toPlainText:r.toPlainText??(e=>e==null?``:String(e)),fromPlainText:r.fromPlainText??(t=>a(t,{id:``,name:``,type:e,config:{}})),getCapabilities:()=>({...tt,...t,editable:i&&(t.editable??tt.editable)})}}function St(){return[W(e.BaseFieldType.Text,{groupable:!0,usableAsTitle:!0},void 0,{createDefaultConfig:()=>({placeholder:`bases.fieldConfig.textPlaceholder`}),createDefaultValue:e=>e.defaultValue??``}),W(e.BaseFieldType.SingleSelect,{groupable:!0,usableAsKanbanGroup:!0,supportsOptions:!0},e=>e==null||e===``?null:String(e),{createDefaultConfig:()=>({options:[],optionSource:{type:`manual`}})}),W(e.BaseFieldType.MultiSelect,{filterable:!0,usableAsKanbanGroup:!0,supportsOptions:!0,supportsMultipleValues:!0},e=>Array.isArray(e)?e.map(String):e==null?[]:[String(e)],{createDefaultConfig:()=>({options:[],optionSource:{type:`manual`}}),createDefaultValue:e=>e.defaultValue??[]}),W(e.BaseFieldType.Person,{groupable:!0,usableAsKanbanGroup:!0,supportsMultipleValues:!0},Dt,{createDefaultConfig:()=>({allowMultiple:!1,provider:`person`}),validate:Ot}),W(e.BaseFieldType.Group,{groupable:!0,usableAsKanbanGroup:!0,supportsMultipleValues:!0},Tt,{createDefaultConfig:()=>({allowMultiple:!0,provider:`group`}),createDefaultValue:e=>e.defaultValue??[],validate:kt}),W(e.BaseFieldType.Date,{groupable:!0,usableAsCalendarDate:!0,usableAsGanttStart:!0,usableAsGanttEnd:!0},e=>z(e),{createDefaultConfig:()=>wt(),validate:At}),W(e.BaseFieldType.Attachment,{usableAsCardCover:!0,supportsMultipleValues:!0},e=>e==null?[]:Array.isArray(e)?e:[e],{createDefaultValue:e=>e.defaultValue??[]}),W(e.BaseFieldType.Number,{},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>Ct(),validate:jt}),W(e.BaseFieldType.Checkbox,{groupable:!0,usableAsKanbanGroup:!0},e=>e===!0||e===`true`||e===1||e===`1`,{createDefaultConfig:()=>({icon:`check`,color:`#16a34a`}),createDefaultValue:e=>e.defaultValue??!1,validate:e=>typeof e==`boolean`?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid checkbox value.`}}),W(e.BaseFieldType.Link,{supportsRelation:!0},Nt,{createDefaultConfig:()=>({placeholder:`bases.fieldConfig.linkPlaceholder`}),toPlainText:e=>Pt(e),fromPlainText:e=>Nt(e)}),W(e.BaseFieldType.Formula,{editable:!1},void 0,{createDefaultConfig:()=>({formula:``,dependencies:[],numfmt:{type:`general`,pattern:`General`}}),createDefaultValue:()=>null}),W(e.BaseFieldType.Numbering,{editable:!1,usableAsTitle:!0},void 0,{createDefaultConfig:()=>({mode:`autoIncrement`}),createDefaultValue:()=>null}),W(e.BaseFieldType.Phone,{usableAsTitle:!0},e=>e==null?null:String(e).trim(),{validate:e=>e==null||e===``||/^\+?[0-9 ()-]{6,20}$/.test(String(e))?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid phone value.`}}),W(e.BaseFieldType.Email,{usableAsTitle:!0},e=>e==null?null:String(e).trim(),{validate:e=>e==null||e===``||It(String(e))?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid email value.`}}),W(e.BaseFieldType.Progress,{usableAsGanttProgress:!0},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>({format:`percent`,decimalPlaces:0,color:`blue`,customRange:!1,start:0,end:100}),validate:(e,t)=>Mt(e,t,`[BaseField]: invalid progress value.`)}),W(e.BaseFieldType.Currency,{},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>({...Ct(),currencySymbol:`$`}),validate:jt}),W(e.BaseFieldType.Rating,{groupable:!0,usableAsKanbanGroup:!0},e=>e==null||e===``?null:Number(e),{createDefaultConfig:()=>({icon:`star`,min:1,max:5}),createDefaultValue:()=>null,validate:(e,t)=>Mt(e,t,`[BaseField]: invalid rating value.`)}),W(e.BaseFieldType.RecordLink,{supportsRelation:!0,supportsMultipleValues:!0},Et,{createDefaultConfig:()=>({targetTableId:``,multiple:!1}),createDefaultValue:()=>``,validate:(e,t)=>i(e,t.config.multiple===!0)}),W(e.BaseFieldType.RecordId,{editable:!1,sortable:!0,filterable:!0,usableAsTitle:!0}),W(e.BaseFieldType.CreatedBy,{editable:!1,groupable:!0},e=>e==null?null:String(e),{createDefaultConfig:()=>({provider:`user`}),createDefaultValue:()=>null}),W(e.BaseFieldType.UpdatedBy,{editable:!1,groupable:!0},e=>e==null?null:String(e),{createDefaultConfig:()=>({provider:`user`}),createDefaultValue:()=>null}),W(e.BaseFieldType.CreatedAt,{editable:!1,usableAsCalendarDate:!0,usableAsGanttStart:!0,usableAsGanttEnd:!0},e=>z(e),{createDefaultConfig:()=>wt(),createDefaultValue:()=>null,validate:At}),W(e.BaseFieldType.UpdatedAt,{editable:!1,usableAsCalendarDate:!0,usableAsGanttStart:!0,usableAsGanttEnd:!0},e=>z(e),{createDefaultConfig:()=>wt(),createDefaultValue:()=>null,validate:At})]}function Ct(){return{pattern:`#,##0.00`,decimalPlaces:2,separatorStyle:`local`,useThousands:!0,abbreviation:`none`,allowNegative:!0}}function wt(){return{locale:`en-US`,pattern:`yyyy/mm/dd`,includeTime:!1,hourCycle:`h24`,defaultMode:`none`}}function Tt(e){return e==null||e===``?[]:Array.isArray(e)?e.map(String):[String(e)]}function Et(e){return typeof e==`string`?e:``}function Dt(e,t){return e==null||e===``?t.config.allowMultiple===!0?[]:null:t.config.allowMultiple===!0?Array.isArray(e)?e.map(String):[String(e)]:Array.isArray(e)?String(e[0]??``)||null:String(e)}function Ot(e,t){return t.config.allowMultiple===!0?kt(e):e==null||e===``||typeof e==`string`?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid person value.`}}function kt(e){return e==null||Array.isArray(e)&&e.every(e=>typeof e==`string`)?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid multi-value reference.`}}function At(e){return e==null||typeof e==`number`&&Number.isFinite(e)?{valid:!0}:{valid:!1,reason:`[BaseField]: invalid date value.`}}function jt(e,t){return e==null||e===``?{valid:!0}:typeof e!=`number`||!Number.isFinite(e)?{valid:!1,reason:`[BaseField]: invalid number value.`}:t.config.allowNegative===!1&&e<0?{valid:!1,reason:`[BaseField]: negative numbers are disabled.`}:{valid:!0}}function Mt(e,t,n){let r=jt(e,t);if(!r.valid||e==null||e===``)return r;let i=Number(t.config.min??t.config.start??0),a=Number(t.config.max??t.config.end??100),o=Number(e);return o>=i&&o<=a?{valid:!0}:{valid:!1,reason:n}}function Nt(e){if(e==null||e===``)return null;if(typeof e==`object`&&!Array.isArray(e)){let t=e,n=typeof t.text==`string`?t.text.trim():``,r=typeof t.url==`string`?t.url.trim():``,i=Ft(r||n);return i?{text:n||r||i,url:i}:null}let t=String(e).trim(),n=Ft(t);return n?{text:t,url:n}:null}function Pt(e){if(e==null)return``;if(typeof e==`object`&&!Array.isArray(e)){let t=e;return String(t.text||t.url||``)}return String(e)}function Ft(e){let t=e.trim();if(!t)return``;let n=/^[a-z][a-z\d+.-]*:/i.test(t)?t:t.startsWith(`//`)?`https:${t}`:`https://${t}`;try{let e=new URL(n);return e.protocol===`http:`||e.protocol===`https:`?e.href:``}catch{return``}}function It(e){let t=e.indexOf(`@`);if(t<=0||t!==e.lastIndexOf(`@`))return!1;let n=e.slice(t+1);return n.includes(`.`)&&!e.includes(` `)&&!n.startsWith(`.`)&&!n.endsWith(`.`)}function G(e){"@babel/helpers - typeof";return G=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},G(e)}function Lt(e,t){if(G(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Rt(e){var t=Lt(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=Rt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}const zt=(0,e.createIdentifier)(`base.field-registry.service`);var Bt=class extends e.Disposable{constructor(...e){super(...e),K(this,`_plugins`,/* @__PURE__ */ new Map)}register(t){return this._plugins.set(t.type,t),(0,e.toDisposable)(()=>this._plugins.delete(t.type))}get(e){let t=this._plugins.get(e);if(!t)throw Error(`[BaseFieldRegistryService]: field type "${e}" is not registered.`);return t}getTypePlugin(e){return this._plugins.get(e)}getAll(){return Array.from(this._plugins.values())}};function Vt(e,t){return function(n,r){t(n,r,e)}}function Ht(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}function Ut(e){let t=e&&typeof e==`object`?e:{},n=Number(t.start??0),r=Number(t.end??100);return t.customRange===!0?{start:Number.isFinite(n)?n:0,end:Number.isFinite(r)?r:100}:{start:0,end:100}}function Wt(e,t){let n=t&&typeof t==`object`&&!Array.isArray(t)?t:{},r=e.toFixed(Gt(n.decimalPlaces));return n.format===`number`?r:`${r}%`}function Gt(e){if(e==null||e===``)return 0;let t=typeof e==`number`?e:Number(e);return Number.isFinite(t)?Math.max(0,Math.min(2,Math.round(t))):0}const Kt=/* @__PURE__ */ new Set([e.BaseFieldType.Progress,e.BaseFieldType.Rating,e.BaseFieldType.Checkbox]);function qt(t){let n=t.fields[t.primaryFieldId];if((!n||n.system!==!0&&n.id.toLowerCase()!==`id`&&n.name.trim().toLowerCase()!==`id`)&&n)return n.id;for(let n of t.fieldOrder){let r=t.fields[n];if(r&&r.id!==t.primaryFieldId&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)return r.id}return t.primaryFieldId}function q(t,n=[],r=5){let i=new Set(n.filter(e=>!!e)),a=[],o=[];for(let n of t.fieldOrder){let r=t.fields[n];r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId&&!i.has(r.id)&&(Kt.has(r.type)?a:o).push(r.id)}return[...a,...o].slice(0,r)}function Jt(){return[{type:e.BaseViewType.Grid,i18nKey:`base.viewType.grid`,createDefaultConfig:()=>({}),validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Grid projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Kanban,i18nKey:`base.viewType.kanban`,createDefaultConfig:e=>{let t=Yt(e);return{groupFieldId:t,coverFieldId:null,cardLayout:`normal`,showFieldNames:!0,fieldSettings:{},columnSettings:{},card:{titleFieldId:e.primaryFieldId,fieldIds:q(e,[e.primaryFieldId,t])}}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Kanban projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Calendar,i18nKey:`base.viewType.calendar`,createDefaultConfig:e=>{let t=Xt(e);return{startDateFieldId:t,endDateFieldId:Zt(e,t),titleFieldId:e.primaryFieldId,mode:`month`,timeslotSize:`medium`,timeZone:`local`,displayColor:{type:`custom`,color:`#3b82f6`},fieldSettings:{}}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Calendar projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Gantt,i18nKey:`base.viewType.gantt`,createDefaultConfig:e=>{let t=Xt(e);return{startDateFieldId:t,endDateFieldId:Zt(e,t)??t,titleFieldId:e.primaryFieldId,scale:`month`,showTodayLine:!0,displayColor:{type:`custom`,color:`#3b82f6`},fieldSettings:{},workingDaysOnly:!1}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Gantt projection is implemented by BaseProjectionService.`)}},{type:e.BaseViewType.Gallery,i18nKey:`base.viewType.gallery`,createDefaultConfig:e=>{let t=qt(e);return{coverFieldId:null,cardLayout:`normal`,showFieldNames:!0,fieldSettings:{},card:{titleFieldId:t,coverFieldId:null,fieldIds:q(e,[t,e.primaryFieldId])},cardSize:`medium`}},validateConfig:()=>({valid:!0}),buildProjection:()=>{throw Error(`Gallery projection is implemented by BaseProjectionService.`)}}]}function Yt(t){var n,r,i;let a=t.fieldOrder.map(e=>t.fields[e]).filter(e=>!!e);return((n=a.find(t=>t.type===e.BaseFieldType.SingleSelect||t.type===e.BaseFieldType.MultiSelect||t.type===e.BaseFieldType.Group))==null?void 0:n.id)??((r=a.find(t=>t.type===e.BaseFieldType.Text))==null?void 0:r.id)??((i=a.find(t=>t.type===e.BaseFieldType.Date||t.type===e.BaseFieldType.CreatedAt||t.type===e.BaseFieldType.UpdatedAt))==null?void 0:i.id)??t.primaryFieldId}function Xt(e){var t;return((t=e.fieldOrder.map(t=>e.fields[t]).find(Qt))==null?void 0:t.id)??``}function Zt(e,t){var n;return(n=e.fieldOrder.map(t=>e.fields[t]).find(e=>Qt(e)&&e.id!==t))==null?void 0:n.id}function Qt(t){return!!t&&t.type===e.BaseFieldType.Date&&t.readonly!==!0&&t.system!==!0}const $t=(0,e.createIdentifier)(`base.projection.service`),en=/* @__PURE__ */ new Set([e.BaseFieldType.Number,e.BaseFieldType.Currency,e.BaseFieldType.Progress,e.BaseFieldType.Rating,e.BaseFieldType.Date,e.BaseFieldType.CreatedAt,e.BaseFieldType.UpdatedAt,e.BaseFieldType.Checkbox]),J=864e5;let tn=class extends e.Disposable{constructor(e){super(),this._fieldRegistry=e,K(this,`_views`,/* @__PURE__ */ new Map),K(this,`_projectionCache`,/* @__PURE__ */ new WeakMap),K(this,`_projectedRowsCache`,/* @__PURE__ */ new Map),K(this,`_projectedViewRowsCache`,/* @__PURE__ */ new Map),K(this,`_projectedGroupsCache`,/* @__PURE__ */ new Map),K(this,`_hierarchyIndexCache`,/* @__PURE__ */ new Map),K(this,`_globalRevision`,0),K(this,`_tableRevisions`,/* @__PURE__ */ new Map),K(this,`_cellRevisions`,/* @__PURE__ */ new Map),K(this,`_cellInvalidations`,/* @__PURE__ */ new Map),K(this,`_viewRevisions`,/* @__PURE__ */ new Map)}registerView(t){return this._views.set(t.type,t),(0,e.toDisposable)(()=>this._views.delete(t.type))}getProjection(t,n,r){var i,a,o;return E(`BaseProjection.getProjection`,()=>{let i=this._getCachedProjection(t,n,r);if(i)return i;let a=t.tables[n],o=a==null?void 0:a.views[r];if(!a||!o)return this._setCachedProjection(t,n,r,{type:`invalid`,viewType:(o==null?void 0:o.type)??e.BaseViewType.Grid,reason:`missingField`});let s;switch(o.type){case e.BaseViewType.Grid:s=this._buildGrid(a,o);break;case e.BaseViewType.Gantt:s=this._buildGantt(a,o);break;case e.BaseViewType.Kanban:s=this._buildKanban(a,o);break;case e.BaseViewType.Calendar:s=this._buildCalendar(a,o);break;case e.BaseViewType.Gallery:s=this._buildGallery(a,o);break;default:s={type:`invalid`,viewType:o.type,reason:`missingField`}}return this._setCachedProjection(t,n,r,s)},{tableId:n,viewId:r,viewType:(i=t.tables[n])==null||(i=i.views[r])==null?void 0:i.type,records:((a=t.tables[n])==null||(a=a.recordOrder)==null?void 0:a.length)??Object.keys(((o=t.tables[n])==null?void 0:o.records)??{}).length})}repairViewConfig(e,t,n){var r,i,a;let o=e.tables[t],s=o==null?void 0:o.views[n];if(!o||!s)throw Error(`[BaseProjectionService]: missing view "${n}".`);let c=e=>!!o.fields[e],l={...s,filter:s.filter?{...s.filter,conditions:s.filter.conditions.filter(e=>c(e.fieldId))}:s.filter,sort:(r=s.sort)==null?void 0:r.filter(e=>c(e.fieldId)),group:(i=s.group)==null?void 0:i.filter(e=>c(e.fieldId)),fieldOrder:(a=s.fieldOrder)==null?void 0:a.filter(c),fieldSettings:Object.fromEntries(Object.entries(s.fieldSettings??{}).filter(([e])=>c(e)))};if(l.type===`kanban`){var u;let e=l.config??{},t=this._resolveKanbanGroupFieldId(o,l),n=this._resolveCardTitleFieldId(o,(u=e.card)==null?void 0:u.titleFieldId);l.config={...e,groupFieldId:t??e.groupFieldId,coverFieldId:this._resolveKanbanCoverFieldId(o,e),cardLayout:e.cardLayout===`compose`?`compose`:`normal`,showFieldNames:e.showFieldNames!==!1,fieldSettings:Object.fromEntries(Object.entries(e.fieldSettings??{}).filter(([e])=>c(e))),columnSettings:e.columnSettings??{},card:{...e.card??{},titleFieldId:n,fieldIds:this._resolveKanbanCardFieldIds(o,l,t??``,n)}}}return{repaired:JSON.stringify(l)!==JSON.stringify(s),view:l}}invalidateByOp(){this._globalRevision++}invalidateByCell(e,t,n){let r=this._getCellRevision(e)+1;this._cellRevisions.set(e,r);let i=this._cellInvalidations.get(e)??[];i.push({revision:r,recordId:t,fieldId:n}),this._cellInvalidations.set(e,i)}invalidateByField(e,t){this._bumpTableRevision(e)}invalidateByView(e,t){this._viewRevisions.set(this._viewRevisionKey(e,t),this._getViewRevision(e,t)+1)}_getCachedProjection(e,t,n){var r;let i=(r=this._projectionCache.get(e))==null?void 0:r.get(this._cacheKey(t,n));return i&&i.globalRevision===this._globalRevision&&i.tableRevision===this._getTableRevision(t)&&i.cellRevision===this._getCellRevision(t)&&i.viewRevision===this._getViewRevision(t,n)?i.projection:null}_setCachedProjection(e,t,n,r){let i=this._projectionCache.get(e);return i||(i=/* @__PURE__ */ new Map,this._projectionCache.set(e,i)),i.set(this._cacheKey(t,n),{projection:r,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(t),cellRevision:this._getCellRevision(t),viewRevision:this._getViewRevision(t,n)}),r}_bumpTableRevision(e){this._tableRevisions.set(e,this._getTableRevision(e)+1)}_getTableRevision(e){return this._tableRevisions.get(e)??0}_getCellRevision(e){return this._cellRevisions.get(e)??0}_getViewRevision(e,t){return this._viewRevisions.get(this._viewRevisionKey(e,t))??0}_cacheKey(e,t){return`${e}\u0000${t}`}_viewRowsCacheKey(e,t){return`${e}\u0000${this._rowTransformCacheSegment(t)}`}_groupsCacheKey(e,t,n){return`${e}\u0000${this._rowTransformCacheSegment(t)}\u0000${this._groupConfigCacheSegment(n)}`}_rowTransformCacheSegment(e){return e?Y({filter:on(e.filter),sort:cn(e.sort)}):`__all__`}_groupConfigCacheSegment(e){return Y(e.map(e=>({fieldId:e.fieldId,direction:e.direction??null})))}_viewRevisionKey(e,t){return`${e}\u0000${t}`}_buildGrid(t,n){let{rows:r,hierarchy:i}=this._projectHierarchyRows(t,n,g(t));return{type:e.BaseViewType.Grid,fields:this._projectFields(t,n),rows:r,groups:this._projectHierarchyGroups(t,n,r,i),hierarchy:i,frozenFieldCount:typeof n.config.frozenFieldCount==`number`?n.config.frozenFieldCount:0}}_projectHierarchyRows(e,t,n){var r;let i=this._projectRows(e,t),a=(r=t.filter)!=null&&r.conditions.length?this._projectRows(e,{...t,filter:null}):i;return w(this._getHierarchyIndex(e,n,t.id,a.map(e=>e.recordId)),a,new Set(i.map(e=>e.recordId)))}_getHierarchyIndex(e,t,n,r){let i=`${e.id}\u0000${t}\u0000${n}`,a=this._getCellRevision(e.id),o=this._hierarchyIndexCache.get(i);if(o&&o.globalRevision===this._globalRevision&&o.tableRevision===this._getTableRevision(e.id)&&o.orderedRecordIds.length===r.length&&o.orderedRecordIds.every((e,t)=>e===r[t])){if(o.cellRevision===a&&o.table===e)return o.index;if(!this._cellInvalidationsTouchFields(e.id,o.cellRevision,a,/* @__PURE__ */ new Set([t])))return this._hierarchyIndexCache.set(i,{...o,table:e,cellRevision:a}),o.index}let s=C(e,t,r);return this._hierarchyIndexCache.set(i,{table:e,index:s,orderedRecordIds:r,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:a}),s}_projectHierarchyGroups(e,t,n,r){var i;if(!((i=t.group)!=null&&i.length))return[];let a=new Map(n.map(e=>[e.recordId,e])),o=r.rootRecordIds.flatMap(e=>{let t=a.get(e);return t?[t]:[]}),s=this._projectGroups(e,t,o),c=new Map(r.orderedRecordIds.map((e,t)=>[e,t])),l=e=>{let t=r.nodes[e],n=c.get(e)??-1;return n<0||!t?[]:r.orderedRecordIds.slice(n,t.subtreeEndIndex+1)},u=e=>{var t,n;return{...e,recordIds:(t=e.children)!=null&&t.length?e.recordIds:e.recordIds.flatMap(l),children:(n=e.children)==null?void 0:n.map(u)}};return s.map(u)}_buildKanban(t,n){var r;let i=this._resolveKanbanGroupFieldId(t,n),a=i?t.fields[i]:void 0;if(!a)return{type:`invalid`,viewType:e.BaseViewType.Kanban,reason:`invalidGroupField`,fieldId:n.config.groupFieldId};let o=this._projectRows(t,n),s=this._projectFields(t,n),c=n.config??{},l=this._resolveCardTitleFieldId(t,(r=c.card)==null?void 0:r.titleFieldId),u=this._resolveKanbanCardFieldIds(t,n,a.id,l),d=/* @__PURE__ */ new Map;if(m(t,a.id)){let r=this._getHierarchyIndex(t,a.id,n.id,o.map(e=>e.recordId)),i=/* @__PURE__ */ new Map;return o.forEach(e=>{let n=r.parentByRecordId.get(e.recordId)??null,o=n??``,s=n?t.records[n]:void 0,l=i.get(o)??{key:o,title:s?String(O(t,s.id,t.primaryFieldId)??n):this._kanbanLaneTitle(a,o,c),recordIds:[]};l.recordIds.push(e.recordId),i.set(o,l)}),{type:e.BaseViewType.Kanban,fields:s,rows:o,groups:[],groupFieldId:a.id,titleFieldId:l,coverFieldId:this._resolveKanbanCoverFieldId(t,c),cardLayout:c.cardLayout===`compose`?`compose`:`normal`,showFieldNames:c.showFieldNames!==!1,visibleCardFieldIds:u,lanes:[``,...r.orderedRecordIds].flatMap(e=>{let t=i.get(e);return t!=null&&t.recordIds.length?[t]:[]})}}return this._getKanbanConfiguredLanes(a,c).forEach(e=>d.set(e.key,{...e,recordIds:[]})),o.forEach(e=>{this._kanbanGroupKeys(a,e.values[a.id]).forEach(t=>{let n=d.get(t)??{key:t,title:this._kanbanLaneTitle(a,t,c),color:this._kanbanLaneColor(a,t,c),recordIds:[]};n.recordIds.push(e.recordId),d.set(t,n)})}),{type:e.BaseViewType.Kanban,fields:s,rows:o,groups:this._projectGroups(t,n,o),groupFieldId:a.id,titleFieldId:l,coverFieldId:this._resolveKanbanCoverFieldId(t,c),cardLayout:c.cardLayout===`compose`?`compose`:`normal`,showFieldNames:c.showFieldNames!==!1,visibleCardFieldIds:u,lanes:Array.from(d.values())}}_resolveKanbanGroupFieldId(e,t){var n;let r=(n=t.config)==null?void 0:n.groupFieldId;return r&&this._isKanbanGroupField(e,r)?r:this._findKanbanGroupField(e,e=>this._isAllowedKanbanGroupField(e))}_findKanbanGroupField(e,t){for(let n of e.fieldOrder){let r=e.fields[n];if(r&&t(r))return r.id}return null}_isKanbanGroupField(e,t){let n=e.fields[t];return this._isAllowedKanbanGroupField(n)||m(e,t)}_isAllowedKanbanGroupField(t){return!!t&&(t.type===e.BaseFieldType.SingleSelect||t.type===e.BaseFieldType.MultiSelect||t.type===e.BaseFieldType.Rating||t.type===e.BaseFieldType.Person||t.type===e.BaseFieldType.Group||t.type===e.BaseFieldType.Checkbox)}_isColorfulKanbanGroupField(t){return t.type===e.BaseFieldType.SingleSelect||t.type===e.BaseFieldType.MultiSelect}_resolveKanbanCoverFieldId(e,t){var n;let r=t.coverFieldId??((n=t.card)==null?void 0:n.coverFieldId)??null;if(!r)return null;let i=e.fields[r];return i&&this._capabilities(i).usableAsCardCover?i.id:null}_resolveKanbanCardFieldIds(t,n,r,i=this._resolveCardTitleFieldId(t,(()=>{var e;return(e=n.config)==null||(e=e.card)==null?void 0:e.titleFieldId})())){var a;let o=n.config??{},s=(a=o.card)!=null&&(a=a.fieldIds)!=null&&a.length?o.card.fieldIds:q(t,[i,t.primaryFieldId,r]),c=o.fieldSettings??{};return s.filter(a=>{var o,s;let l=t.fields[a];return!(!l||l.system===!0||l.type===e.BaseFieldType.RecordId||l.id===r||l.id===i||(o=n.fieldSettings)!=null&&(o=o[a])!=null&&o.hidden||(s=c[a])!=null&&s.hidden)}).sort((e,t)=>{var n,r;return(((n=c[e])==null?void 0:n.order)??s.indexOf(e))-(((r=c[t])==null?void 0:r.order)??s.indexOf(t))})}_getKanbanConfiguredLanes(e,t){var n;let r=(Array.isArray((n=e.config)==null?void 0:n.options)?e.config.options:[]).flatMap((n,r)=>{if(n==null)return[];let i=typeof n==`string`?{id:n,name:n,color:void 0}:n,a=String(i.id??i.name??`option-${r+1}`);return[{key:a,title:String(i.name??i.id??a),color:this._kanbanLaneColor(e,a,t)}]});return Object.entries(t.columnSettings??{}).forEach(([n,i])=>{r.some(e=>e.key===n)||r.push({key:n,title:this._isColorfulKanbanGroupField(e)?i.title??this._kanbanLaneTitle(e,n,t):this._kanbanLaneTitle(e,n,t),color:this._kanbanLaneColor(e,n,t)})}),r}_kanbanGroupKeys(e,t){let n=t=>{var n;let r=t==null?``:String(t);return!r||!this._isColorfulKanbanGroupField(e)?r:((n=$(e,r))==null?void 0:n.id)??r};if(Array.isArray(t)){let e=t.map(n).filter(e=>e!==``);return e.length?e:[``]}return[n(t)]}_kanbanLaneTitle(e,t,n){if(!t)return`Uncategorized`;let r=$(e,t);return(r==null?void 0:r.name)??t}_kanbanLaneColor(e,t,n){var r;if(this._isColorfulKanbanGroupField(e))return(r=$(e,t))==null?void 0:r.color}_buildCalendar(t,n){let r=this._normalizeCalendarConfig(t,n.config??{}),i=t.fields[r.startDateFieldId];if(!i||i.type!==e.BaseFieldType.Date||i.readonly===!0||i.system===!0||!this._capabilities(i).usableAsCalendarDate)return{type:`invalid`,viewType:e.BaseViewType.Calendar,reason:`invalidDateField`,fieldId:r.startDateFieldId};let a=r.endDateFieldId?t.fields[r.endDateFieldId]:void 0,o=this._projectRows(t,n);return{type:e.BaseViewType.Calendar,config:r,fields:this._projectFields(t,n),rows:o,groups:this._projectGroups(t,n,o),events:o.flatMap(e=>{let n=B(e.values[r.startDateFieldId]);if(!Number.isFinite(n))return[];let o=e.values[r.startDateFieldId],s=r.endDateFieldId==null?void 0:e.values[r.endDateFieldId],c=r.endDateFieldId==null?void 0:B(s),l=Number.isFinite(c)?c:void 0;return[{recordId:e.recordId,title:this._title(t,e,r.titleFieldId),start:n,end:l,color:this._calendarEventColor(t,e,r),startMs:n,endMs:l,allDay:this._isAllDayCalendarEvent(i,a,o,s),fieldValues:e.values}]})}}_normalizeCalendarConfig(t,n){let r=this._resolveCalendarDateFieldId(t,n.startDateFieldId),i=n.endDateFieldId&&this._isCalendarDateField(t,n.endDateFieldId)?n.endDateFieldId:this._findCalendarDateFieldId(t,r)??void 0,a=n.titleFieldId?t.fields[n.titleFieldId]:void 0,o=a&&a.system!==!0&&a.type!==e.BaseFieldType.RecordId?n.titleFieldId:t.primaryFieldId,s=n.mode===`day`||n.mode===`week`?n.mode:`month`,c=n.timeslotSize===`short`||n.timeslotSize===`long`?n.timeslotSize:`medium`,l=typeof n.timeZone==`string`&&n.timeZone.trim()?n.timeZone:`local`,u=this._normalizeCalendarDisplayColor(t,n);return{...n,startDateFieldId:r,endDateFieldId:i,titleFieldId:o,mode:s,timeslotSize:c,timeZone:l,displayColor:u,fieldSettings:Object.fromEntries(Object.entries(n.fieldSettings??{}).filter(([n])=>{let r=t.fields[n];return!!(r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)}))}}_resolveCalendarDateFieldId(e,t){return t&&this._isCalendarDateField(e,t)?t:this._findCalendarDateFieldId(e)??t??``}_findCalendarDateFieldId(e,t){for(let n of e.fieldOrder)if(n!==t&&this._isCalendarDateField(e,n))return n;return null}_isCalendarDateField(t,n){let r=t.fields[n];return!!r&&r.type===e.BaseFieldType.Date&&r.readonly!==!0&&r.system!==!0&&this._capabilities(r).usableAsCalendarDate}_normalizeCalendarDisplayColor(t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`selectField`){let n=t.fields[r.fieldId];if(n&&n.type===e.BaseFieldType.SingleSelect)return r}if((r==null?void 0:r.type)===`custom`&&typeof r.color==`string`&&r.color.trim())return{type:`custom`,color:r.color};if(n.colorFieldId){let r=t.fields[n.colorFieldId];if(r&&r.type===e.BaseFieldType.SingleSelect)return{type:`selectField`,fieldId:n.colorFieldId}}return{type:`custom`,color:`#3b82f6`}}_calendarEventColor(e,t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`selectField`){var i;let n=e.fields[r.fieldId];if(!n)return;let a=t.values[r.fieldId],o=Array.isArray(a)?a[0]:a;return o==null||(i=$(n,String(o)))==null?void 0:i.color}if((r==null?void 0:r.type)===`custom`)return r.color}_isAllDayCalendarEvent(e,t,n,r){var i,a;let o=((i=e.config)==null?void 0:i.includeTime)===!0,s=(t==null||(a=t.config)==null?void 0:a.includeTime)===!0;return!o&&!s}_isAllDayGanttDateRange(e,t){var n,r;let i=((n=e.config)==null?void 0:n.includeTime)===!0,a=((r=t.config)==null?void 0:r.includeTime)===!0;return!i&&!a}_buildGantt(t,r){let i=this._normalizeGanttConfig(t,r.config),a=t.fields[i.startDateFieldId];if(!a||a.type!==e.BaseFieldType.Date||a.readonly===!0||a.system===!0||!this._capabilities(a).usableAsGanttStart)return{type:`invalid`,viewType:e.BaseViewType.Gantt,reason:`invalidGanttStartField`,fieldId:i.startDateFieldId};let o=t.fields[i.endDateFieldId];if(!o||o.type!==e.BaseFieldType.Date||o.readonly===!0||o.system===!0||!this._capabilities(o).usableAsGanttEnd)return{type:`invalid`,viewType:e.BaseViewType.Gantt,reason:`invalidGanttEndField`,fieldId:i.endDateFieldId};let s=this._isAllDayGanttDateRange(a,o),c=h(t),u=c?this._projectHierarchyRows(t,r,c):void 0,d=u==null?void 0:u.hierarchy,f=(u==null?void 0:u.rows)??this._projectRows(t,r),p=i.dependencyFieldId,m=p&&l(t.id,t.fields[p])?p:void 0,g=t.fields[i.progressFieldId??``],_=(g==null?void 0:g.type)===e.BaseFieldType.Progress&&!g.system?{id:g.id,...Ut(g.config),editable:!g.readonly}:void 0,v=f.flatMap(e=>{let r=B(e.values[i.startDateFieldId]),a=B(e.values[i.endDateFieldId]);if(!Number.isFinite(r)||!Number.isFinite(a))return[];let o=Math.min(r,a),s=Math.max(r,a),c=e.values[i.progressFieldId??``],l=c==null||c===``?void 0:Number(c),u=l!=null&&Number.isFinite(l)&&_&&_.start!==_.end?Math.max(0,Math.min(1,(l-_.start)/(_.end-_.start))):void 0;return[{recordId:e.recordId,title:this._title(t,e,i.titleFieldId),start:o,end:s,color:this._ganttBarColor(t,e,i),progress:Number.isFinite(l)?l:void 0,completion:u,workingDayCount:i.workingDaysOnly?yn(o,s,i.workingDays):void 0,dependencyRecordIds:m?n(e.values[m]):void 0}]}),y=i.showPlanComparison===!0?this._buildGanttPlan(t,f,i):void 0,b=1/0,x=-1/0;for(let e of[v,(y==null?void 0:y.bars)??[]])for(let t of e)b=Math.min(b,t.start),x=Math.max(x,t.end);let S=Date.now(),C=Z((Number.isFinite(b)?b:S)-90*J),w=Z((Number.isFinite(x)?x:S)+91*J),T=un(i.scale,C,w,i.workingDaysOnly?i.workingDays:void 0);return{type:e.BaseViewType.Gantt,fields:this._projectFields(t,{...r,config:i}),rows:f,groups:d?this._projectHierarchyGroups(t,r,f,d):this._projectGroups(t,r,f),...d?{hierarchy:d}:{},config:{...i,dependencyFieldId:m},..._?{progressField:_}:{},dateRangeAllDay:s,timeline:{scale:i.scale,start:C,end:w,unitWidth:T.unitWidth,majorHeaders:T.majorHeaders,columns:T.columns},bars:v,...y?{plan:y}:{}}}_buildGanttPlan(e,t,n){let{planStartDateFieldId:r,planEndDateFieldId:i}=n,a={bars:[],needsDateFields:!0,invalidRecordIds:[]};if(!r||!i||!this._isGanttDateField(e,r,`start`)||!this._isGanttDateField(e,i,`end`))return a;a.needsDateFields=!1;for(let o of t){let t=B(o.values[r]),s=B(o.values[i]);t!=null&&s!=null&&Number.isFinite(t)&&Number.isFinite(s)&&(t>s?a.invalidRecordIds.push(o.recordId):a.bars.push({recordId:o.recordId,title:this._title(e,o,n.titleFieldId),start:t,end:s}))}return a}_normalizeGanttConfig(t,n){let r=this._resolveGanttDateFieldId(t,n.startDateFieldId,`start`),i=this._resolveGanttDateFieldId(t,n.endDateFieldId,`end`)||r,a=n.titleFieldId?t.fields[n.titleFieldId]:void 0,o=a&&a.system!==!0&&a.type!==e.BaseFieldType.RecordId?n.titleFieldId:t.primaryFieldId,s=n.scale===`week`||n.scale===`quarter`||n.scale===`year`?n.scale:`month`,c=X(n.workingDays);return{...n,startDateFieldId:r,endDateFieldId:i,titleFieldId:o,scale:s,leftPaneWidth:typeof n.leftPaneWidth==`number`?n.leftPaneWidth:void 0,leftPaneCollapsed:n.leftPaneCollapsed===!0,showTodayLine:n.showTodayLine!==!1,displayColor:this._normalizeGanttDisplayColor(t,n),fieldSettings:Object.fromEntries(Object.entries(n.fieldSettings??{}).filter(([n])=>{let r=t.fields[n];return!!(r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)})),workingDaysOnly:n.workingDaysOnly===!0,workingDays:c}}_resolveGanttDateFieldId(e,t,n){if(t&&this._isGanttDateField(e,t,n)||t)return t;for(let t of e.fieldOrder)if(this._isGanttDateField(e,t,n))return t;return t??``}_isGanttDateField(t,n,r){let i=t.fields[n];if(!i||i.type!==e.BaseFieldType.Date||i.readonly===!0||i.system===!0)return!1;let a=this._capabilities(i);return r===`start`?a.usableAsGanttStart:a.usableAsGanttEnd}_normalizeGanttDisplayColor(t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`selectField`){let n=t.fields[r.fieldId];if(n&&n.type===e.BaseFieldType.SingleSelect)return r}return(r==null?void 0:r.type)===`conditional`&&Array.isArray(r.rules)?{type:`conditional`,rules:r.rules.filter(e=>!!t.fields[e.fieldId])}:(r==null?void 0:r.type)===`custom`&&typeof r.color==`string`&&r.color.trim()?{type:`custom`,color:r.color}:{type:`custom`,color:`#14b8a6`}}_ganttBarColor(e,t,n){let r=n.displayColor;if((r==null?void 0:r.type)===`conditional`){let n=r.rules.find(n=>this._matchesGanttColorRule(e,t,n));if(n)return n.color}if((r==null?void 0:r.type)===`selectField`){let n=e.fields[r.fieldId];if(n){var i;let e=t.values[r.fieldId],a=Array.isArray(e)?e[0]:e,o=a==null||(i=$(n,String(a)))==null?void 0:i.color;if(o)return o}}return(r==null?void 0:r.type)===`custom`?r.color:`#14b8a6`}_matchesGanttColorRule(e,t,n){let r=e.fields[n.fieldId];return r?ot(t.values[r.id],n.operator,n.operand,r,{dateMode:n.dateMode}):!1}_buildGallery(t,n){let r=this._projectRows(t,n),i=this._normalizeGalleryConfig(t,n.config??{}),a=this._projectFields(t,n);return{type:e.BaseViewType.Gallery,fields:a,rows:r,groups:this._projectGroups(t,n,r),titleFieldId:i.card.titleFieldId,coverFieldId:i.coverFieldId,cardLayout:i.cardLayout??`normal`,showFieldNames:i.showFieldNames!==!1,visibleCardFieldIds:this._resolveGalleryCardFieldIds(t,n,i),cardSize:i.cardSize??`medium`,cards:r.map(e=>({recordId:e.recordId,title:this._title(t,e,i.card.titleFieldId),values:e.values}))}}_normalizeGalleryConfig(t,n){let r=n.card??{fieldIds:[]},i=this._resolveCardTitleFieldId(t,r.titleFieldId),a=this._resolveGalleryCoverFieldId(t,n),o=n.cardSize===`small`||n.cardSize===`large`?n.cardSize:`medium`;return{...n,coverFieldId:a,cardLayout:n.cardLayout===`compose`?`compose`:`normal`,showFieldNames:n.showFieldNames!==!1,fieldSettings:Object.fromEntries(Object.entries(n.fieldSettings??{}).filter(([n])=>{let r=t.fields[n];return!!(r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId)})),card:{...r,titleFieldId:i,coverFieldId:a,fieldIds:Array.isArray(r.fieldIds)?r.fieldIds:[]},cardSize:o}}_resolveCardTitleFieldId(t,n){let r=n?t.fields[n]:void 0;return r&&r.system!==!0&&r.type!==e.BaseFieldType.RecordId?r.id:qt(t)}_resolveGalleryCoverFieldId(e,t){var n;let r=t.coverFieldId??((n=t.card)==null?void 0:n.coverFieldId)??null;if(!r)return null;let i=e.fields[r];return i&&this._capabilities(i).usableAsCardCover?i.id:null}_resolveGalleryCardFieldIds(t,n,r){var i,a,o;let s=r.fieldSettings??{},c=((i=r.card)==null?void 0:i.titleFieldId)??qt(t),l=r.coverFieldId??((a=r.card)==null?void 0:a.coverFieldId)??null,u=(o=r.card)!=null&&(o=o.fieldIds)!=null&&o.length?r.card.fieldIds:q(t,[c,l,t.primaryFieldId]);return u.filter(r=>{var i,a;let o=t.fields[r];return!(!o||o.system===!0||o.type===e.BaseFieldType.RecordId||o.id===c||o.id===l||(i=n.fieldSettings)!=null&&(i=i[r])!=null&&i.hidden||(a=s[r])!=null&&a.hidden)}).sort((e,t)=>{var n,r;return(((n=s[e])==null?void 0:n.order)??u.indexOf(e))-(((r=s[t])==null?void 0:r.order)??u.indexOf(t))})}_projectFields(t,n){var r;return((r=n.fieldOrder)!=null&&r.length?n.fieldOrder:t.fieldOrder).flatMap(r=>{var i;let a=t.fields[r],o=((i=n.fieldSettings)==null?void 0:i[r])??{};return!a||a.system===!0||a.type===e.BaseFieldType.RecordId||o.hidden?[]:[{id:a.id,name:a.name,description:a.description,type:a.type,config:a.config,width:o.width,setting:o}]})}_projectRows(e,t){var n;return E(`BaseProjection.projectRows`,()=>{var n,r;let i=this._projectTableRows(e),a=this._viewRowsCacheKey(e.id,t),o=this._getCellRevision(e.id),s=this._projectedViewRowsCache.get(a);if(s&&s.globalRevision===this._globalRevision&&s.tableRevision===this._getTableRevision(e.id)){if(s.cellRevision===o&&s.baseRows===i)return s.rows;if(s.cellRevision!==o&&!this._cellInvalidationsTouchFields(e.id,s.cellRevision,o,this._filterSortFieldIds(t))){let e=s.rows===s.baseRows?i:this._patchCachedProjectedRows(s.rows,i);if(e)return this._projectedViewRowsCache.set(a,{...s,rows:e,baseRows:i,cellRevision:o}),e}}let c=E(`BaseProjection.filterAndSortRows`,()=>this._sortRows(e,t,this._filterRows(e,t,i)),{tableId:e.id,viewId:t==null?void 0:t.id,viewType:t==null?void 0:t.type,rows:i.length,filters:(t==null||(n=t.filter)==null?void 0:n.conditions.length)??0,sorts:(t==null||(r=t.sort)==null?void 0:r.length)??0});return this._projectedViewRowsCache.set(a,{table:e,rows:c,baseRows:i,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:o}),c},{tableId:e.id,viewId:t==null?void 0:t.id,viewType:t==null?void 0:t.type,records:((n=e.recordOrder)==null?void 0:n.length)??Object.keys(e.records??{}).length})}_projectTableRows(e){var t;return E(`BaseProjection.projectTableRows`,()=>{var t;let n=this._getCellRevision(e.id),r=this._projectedRowsCache.get(e.id);if(r&&r.globalRevision===this._globalRevision&&r.tableRevision===this._getTableRevision(e.id)){if(r.cellRevision===n&&sn(r.table,e))return r.table=e,r.rows;let t=this._patchProjectedRowsForCellInvalidations(e,r,n);if(t)return t}an(e)||D(e);let i=(t=e.recordOrder)!=null&&t.length?e.recordOrder:ln(e.records),a=E(`BaseProjection.materializeTableRows`,()=>{let t=[];for(let n of i){let r=e.records[n];if(!r)continue;let i={};for(let t of e.fieldOrder)i[t]=O(e,r.id,t);t.push({recordId:r.id,values:i})}return t},{tableId:e.id,records:i.length,fields:e.fieldOrder.length});return this._projectedRowsCache.set(e.id,{table:e,rows:a,rowIndexById:rn(a),globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:n}),a},{tableId:e.id,records:((t=e.recordOrder)==null?void 0:t.length)??Object.keys(e.records??{}).length,fields:e.fieldOrder.length})}_patchProjectedRowsForCellInvalidations(e,t,n){let r=(this._cellInvalidations.get(e.id)??[]).filter(e=>e.revision>t.cellRevision&&e.revision<=n);if(!r.length)return t.table===e?t.rows:null;let i=t.rows,a=/* @__PURE__ */ new Map;for(let e of r){let t=a.get(e.recordId);t||(t=/* @__PURE__ */ new Set,a.set(e.recordId,t)),t.add(e.fieldId)}for(let[n,r]of a){if(!e.records[n])return null;let a=t.rowIndexById.get(n);if(a==null)return null;i===t.rows&&(i=[...t.rows]);let o=i[a],s={...o.values};r.forEach(t=>{s[t]=O(e,n,t)}),i[a]={...o,values:s}}let o={table:e,rows:i,rowIndexById:t.rowIndexById,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:n};return this._projectedRowsCache.set(e.id,o),this._cellInvalidations.set(e.id,(this._cellInvalidations.get(e.id)??[]).filter(e=>e.revision>Math.max(0,n-256))),i}_patchCachedProjectedRows(e,t){let n=new Map(t.map(e=>[e.recordId,e])),r=!1,i=e.map(e=>{let t=n.get(e.recordId);return t?t===e?e:(r=!0,t):e});return r?i:e}_cellInvalidationsTouchFields(e,t,n,r){return!r.size||t===n?!1:n-t>256||(this._cellInvalidations.get(e)??[]).some(e=>e.revision>t&&e.revision<=n&&r.has(e.fieldId))}_filterSortFieldIds(e){var t,n;let r=/* @__PURE__ */ new Set;return e==null||(t=e.filter)==null||t.conditions.forEach(e=>r.add(e.fieldId)),e==null||(n=e.sort)==null||n.forEach(e=>r.add(e.fieldId)),r}_groupProjectionFieldIds(e){var t;let n=this._filterSortFieldIds(e);return(t=e.group)==null||t.forEach(e=>n.add(e.fieldId)),n}_filterRows(t,n,r){let i=n==null?void 0:n.filter;if(!(i!=null&&i.conditions.length))return r;let a=i.conditions.filter(e=>!kn(e));return a.length?r.filter(n=>{if(i.conjunction===e.BaseFilterConjunction.OR){for(let e of a){let r=t.fields[e.fieldId];if(!r||this._fieldRegistry.get(r.type).filter(n.values[r.id],e.operator,e.operand,r))return!0}return!1}for(let e of a){let r=t.fields[e.fieldId];if(r&&!this._fieldRegistry.get(r.type).filter(n.values[r.id],e.operator,e.operand,r))return!1}return!0}):r}_sortRows(t,n,r){let i=(n==null?void 0:n.sort)??[];if(!i.length)return r;let a=i.flatMap(e=>{let n=t.fields[e.fieldId];return n?[{...e,field:n}]:[]});return a.length?this._canUseFastSort(a)?this._fastSortRows(a,r):[...r].sort((t,n)=>{for(let r of a){let i=r.field,a=this._fieldRegistry.get(i.type).compare(t.values[i.id],n.values[i.id],i);if(a!==0)return r.direction===e.BaseSortDirection.DESC?-a:a}return 0}):r}_canUseFastSort(e){return e.every(e=>en.has(e.field.type))}_fastSortRows(t,n){return n.map((e,n)=>({row:e,index:n,keys:t.map(t=>e.values[t.fieldId])})).sort((n,r)=>{for(let i=0;i<t.length;i++){let a=On(n.keys[i],r.keys[i]);if(a!==0)return t[i].direction===e.BaseSortDirection.DESC?-a:a}return n.index-r.index}).map(e=>e.row)}_projectGroups(e,t,n){var r;return E(`BaseProjection.projectGroups`,()=>{var r;if(!((r=t.group)!=null&&r.length))return[];let i=t.group.filter(t=>e.fields[t.fieldId]);if(!i.length)return[];let a=this._groupsCacheKey(e.id,t,i),o=this._getCellRevision(e.id),s=this._projectedGroupsCache.get(a);if(s&&s.globalRevision===this._globalRevision&&s.tableRevision===this._getTableRevision(e.id)){if(s.cellRevision===o&&s.rows===n)return s.groups;if(s.cellRevision!==o&&!this._cellInvalidationsTouchFields(e.id,s.cellRevision,o,this._groupProjectionFieldIds(t)))return this._projectedGroupsCache.set(a,{...s,rows:n,cellRevision:o}),s.groups}let c=/* @__PURE__ */ new Map;for(let e of n){let t=c,n=``;for(let r=0;r<i.length;r++){let a=i[r],o=e.values[a.fieldId],s=nn(o),c=`${a.fieldId}\u0000${s}`,l=`${n}/${a.fieldId}:${s}`,u=t.get(c);u||(u={key:s,value:o,path:l,label:s||`Empty`,fieldId:a.fieldId,level:r,recordIds:[],children:/* @__PURE__ */ new Map},t.set(c,u)),u.recordIds.push(e.recordId),t=u.children,n=l}}let l=this._materializeGroups(i,c,0);return this._projectedGroupsCache.set(a,{table:e,rows:n,groups:l,globalRevision:this._globalRevision,tableRevision:this._getTableRevision(e.id),cellRevision:o}),l},{tableId:e.id,viewId:t.id,viewType:t.type,rows:n.length,groupFields:((r=t.group)==null?void 0:r.length)??0})}_materializeGroups(t,n,r){var i;let a=Array.from(n.values()),o=(i=t[r])==null?void 0:i.direction;return o&&a.sort((t,n)=>{let r=t.key.localeCompare(n.key);return o===e.BaseSortDirection.DESC?-r:r}),a.map(e=>({key:e.key,value:e.value,path:e.path,label:e.label,fieldId:e.fieldId,level:e.level,recordIds:e.recordIds,children:this._materializeGroups(t,e.children,r+1)}))}_title(e,t,n){let r=n??e.primaryFieldId,i=t.values[r];return i==null?``:String(i)}_capabilities(e){return this._fieldRegistry.get(e.type).getCapabilities(e)}};tn=Ht([Vt(0,(0,e.Inject)(zt))],tn);function nn(e){return e==null?``:String(e)}function rn(e){return new Map(e.map((e,t)=>[e.recordId,t]))}function an(e){return!!(Array.isArray(e.recordOrder)&&e.rowIndex&&e.rowId&&e.colIndex&&e.colId&&e.cellData)}function on(e){let t=(e==null?void 0:e.conditions.filter(e=>!kn(e)))??[];return!e||!t.length?null:{conjunction:e.conjunction,conditions:t.map(e=>({fieldId:e.fieldId,operator:e.operator,operand:e.operand}))}}function sn(e,t){return e.records===t.records&&e.recordOrder===t.recordOrder&&e.fields===t.fields&&e.fieldOrder===t.fieldOrder&&e.cellData===t.cellData&&e.rowIndex===t.rowIndex&&e.rowId===t.rowId&&e.colIndex===t.colIndex&&e.colId===t.colId}function cn(e){return e!=null&&e.length?e.map(e=>({fieldId:e.fieldId,direction:e.direction})):null}function Y(e){if(typeof e!=`object`||!e)return JSON.stringify(e)??`undefined`;if(Array.isArray(e))return`[${e.map(Y).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${Y(t[e])}`).join(`,`)}}`}function ln(e){let t=Object.values(e).sort((e,t)=>e.orderKey.localeCompare(t.orderKey)),n=[];for(let e of t)n.push(e.id);return n}function X(e){return{weekdays:Array.isArray(e==null?void 0:e.weekdays)&&e.weekdays.length?[...new Set(e.weekdays.filter(e=>Number.isInteger(e)&&e>=1&&e<=7))]:[1,2,3,4,5],exceptions:Array.isArray(e==null?void 0:e.exceptions)?e.exceptions.flatMap(e=>!e||!Number.isFinite(e.date)?[]:[{id:String(e.id||`exception-${e.date}`),date:Z(Number(e.date)),name:String(e.name||`Working day`),type:e.type===`working`?`working`:`off`}]):[]}}function un(e,t,n,r){let i=mn(e,t),a=hn(e,n),o=dn(e,i,a,r);return{scale:e,start:i,end:a,unitWidth:pn(e),majorHeaders:fn(e,i,a),columns:o}}function dn(e,t,n,r){let i=[],a=t;for(;a<n;){let t=e===`quarter`?Q(a,7):e===`year`?Tn(a,1):Q(a,1);i.push({id:`${e}-${a}`,label:gn(e,a,t),majorLabel:_n(e,a),start:a,end:t,nonWorking:bn(a,t,r)}),a=t}return i}function fn(e,t,n){let r=[],i=e===`year`?wn(t):Cn(t);for(;i<n;){let t=e===`year`?En(i,1):Tn(i,1);r.push({id:`major-${i}`,label:e===`year`?String(new Date(i).getUTCFullYear()):Dn(i),start:i,end:t}),i=t}return r}function pn(e){switch(e){case`week`:return 172;case`quarter`:return 172;case`year`:return 136;default:return 86}}function mn(e,t){return e===`year`?wn(t):e===`quarter`?Sn(t):Z(t)}function hn(e,t){return e===`year`?En(wn(t),1):e===`quarter`?Q(Sn(t),7):Q(Z(t),1)}function gn(e,t,n){let r=new Date(t);return e===`quarter`?`${r.getUTCDate()}-${(/* @__PURE__ */ new Date(n-J)).getUTCDate()}`:e===`year`?r.toLocaleString(`en-US`,{month:`short`,timeZone:`UTC`}):String(r.getUTCDate())}function _n(e,t){return e===`year`?String(new Date(t).getUTCFullYear()):Dn(t)}function vn(e,t,n){let r=Z(e),i=Z(t);if(r===i||!Number.isFinite(r)||!Number.isFinite(i))return 0;let a=Math.min(r,i),o=Math.max(r,i),s=(o-a)/J,c=X(n),l=e=>{let t=new Date(e).getUTCDay();return c.weekdays.some(e=>e%7===t)},u=Math.floor(s/7)*c.weekdays.length;for(let e=1;e<=s%7;e++)u+=Number(l(Q(a,e)));let d=/* @__PURE__ */ new Set;for(let e of c.exceptions)e.date>a&&e.date<=o&&!d.has(e.date)&&(d.add(e.date),u+=Number(e.type===`working`)-Number(l(e.date)));return i<r&&u!==0?-u:u}function yn(e,t,n){let r=X(n),i=0;for(let n=Z(e);n<=Z(t);n=Q(n,1))xn(n,r)||i++;return i}function bn(e,t,n){if(!n)return!1;let r=X(n);for(let n=Z(e);n<t;n=Q(n,1))if(!xn(n,r))return!1;return!0}function xn(e,t){let n=Z(e),r=t.exceptions.find(e=>Z(e.date)===n);if(r)return r.type===`off`;let i=new Date(n).getUTCDay(),a=i===0?7:i;return!t.weekdays.includes(a)}function Z(e){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate())}function Sn(e){let t=Z(e),n=new Date(t).getUTCDay();return Q(t,-(n===0?6:n-1))}function Cn(e){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),1)}function wn(e){let t=new Date(e);return Date.UTC(t.getUTCFullYear(),0,1)}function Q(e,t){return e+t*J}function Tn(e,t){let n=new Date(e);return Date.UTC(n.getUTCFullYear(),n.getUTCMonth()+t,1)}function En(e,t){let n=new Date(e);return Date.UTC(n.getUTCFullYear()+t,0,1)}function Dn(e){let t=new Date(e);return`${t.toLocaleString(`en-US`,{month:`short`,timeZone:`UTC`})} ${t.getUTCFullYear()}`}function On(e,t){if(e==null&&t==null)return 0;if(e==null)return-1;if(t==null)return 1;if(typeof e==`boolean`||typeof t==`boolean`)return Number(e===!0)-Number(t===!0);let n=Number(e),r=Number(t),i=Number.isFinite(n),a=Number.isFinite(r);return i&&a?n-r:i?1:a?-1:String(e).localeCompare(String(t))}function kn(e){if(e.operator!==`is`&&e.operator!==`isNot`)return!1;let t=e.operand;return t==null?!0:typeof t==`string`?t.trim()===``:Array.isArray(t)?t.length===0:!1}function $(e,t){var n;let r=Array.isArray((n=e.config)==null?void 0:n.options)?e.config.options:[];for(let e of r){if(e==null)continue;if(typeof e==`string`){if(e===t)return{id:e,name:e};continue}let n=e,r=String(n.id??n.name??``),i=String(n.name??n.id??r);if(r===t||i===t)return{id:r,name:i,color:n.color==null?void 0:String(n.color)}}return null}let An=/* @__PURE__ */ function(e){return e.CreateView=`create-view`,e.DeleteView=`delete-view`,e}({});const jn={id:`base.mutation.apply-base-json1`,type:e.CommandType.MUTATION,handler(t,r){let{unitId:i,op:a,ganttPredecessorAddition:o}=r,s=t.get(e.IUniverInstanceService).getUnit(i,e.UniverInstanceType.UNIVER_BASE);if(!s)return!1;if(!a)return!0;let l=s.getSnapshot(),u=new Oe,d=u.getAffectedRanges(a),f=u.applyOp(l,a);if(o){var p,m,h;let{tableId:e,fieldId:t,predecessorId:r,successorId:i}=o,a=(p=f.tables[e])==null?void 0:p.records;if(n(a==null||(m=a[i])==null?void 0:m.values[t]).includes(r)&&!n((h=l.tables[e])==null||(h=h.records[i])==null?void 0:h.values[t]).includes(r)&&c(r,i,e=>{var n;return a==null||(n=a[e])==null?void 0:n.values[t]}))return!1}return s.setSnapshot(f),Mn(f,d,t.get($t)),!0}};function Mn(e,t,n){let r=/* @__PURE__ */ new Set,i=/* @__PURE__ */ new Set,a=/* @__PURE__ */ new Set;for(let o of t){if(o.reason===`view`&&o.tableId&&o.viewId){let e=`${o.tableId}\u0000${o.viewId}`;a.has(e)||(a.add(e),n.invalidateByView(o.tableId,o.viewId));continue}if(o.reason===`field`&&o.tableId&&o.fieldId){let e=`${o.tableId}\u0000${o.fieldId}`;i.has(e)||(i.add(e),n.invalidateByField(o.tableId,o.fieldId));continue}if(o.reason!==`cell`){n.invalidateByOp();return}let t=Nn(e,o);if(!t){n.invalidateByOp();return}let s=`${t.tableId}\u0000${t.recordId}\u0000${t.fieldId}`;r.has(s)||(r.add(s),n.invalidateByCell(t.tableId,t.recordId,t.fieldId))}}function Nn(e,t){var n,r;if(!t.tableId)return null;if(t.recordId&&t.fieldId)return{tableId:t.tableId,recordId:t.recordId,fieldId:t.fieldId};if(t.row==null||t.column==null)return null;let i=e.tables[t.tableId],a=i==null||(n=i.rowId)==null?void 0:n[t.row],o=i==null||(r=i.colId)==null?void 0:r[t.column];return!a||!o?null:{tableId:t.tableId,recordId:a,fieldId:o}}var Pn=`@univerjs-pro/bases`,Fn=`1.7.0-alpha.0`;const In={},Ln={};Object.defineProperty(exports,"$",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return Ze}}),Object.defineProperty(exports,"B",{enumerable:!0,get:function(){return ge}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return it}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return $e}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,"G",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"H",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"J",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"K",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Qe}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"Q",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"R",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return rt}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"U",{enumerable:!0,get:function(){return 5}}),Object.defineProperty(exports,"V",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"W",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"X",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"Y",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"Z",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return Vt}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return Pn}}),Object.defineProperty(exports,"at",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return An}}),Object.defineProperty(exports,"ct",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return vn}}),Object.defineProperty(exports,"dt",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"et",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Jt}}),Object.defineProperty(exports,"ft",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Ht}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Gt}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Ln}}),Object.defineProperty(exports,"it",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return tn}}),Object.defineProperty(exports,"lt",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Ut}}),Object.defineProperty(exports,"mt",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return`bases.remote.config`}}),Object.defineProperty(exports,"nt",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Fn}}),Object.defineProperty(exports,"ot",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return Wt}}),Object.defineProperty(exports,"pt",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"q",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return In}}),Object.defineProperty(exports,"rt",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return jn}}),Object.defineProperty(exports,"st",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return`bases.config`}}),Object.defineProperty(exports,"tt",{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return $t}}),Object.defineProperty(exports,"ut",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return Bt}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return ot}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return St}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return zt}}),Object.defineProperty(exports,"z",{enumerable:!0,get:function(){return j}});
|
package/lib/cjs/facade.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("@univerjs-pro/bases"),l=require("@univerjs/core"),u=require("@univerjs/core/facade");u=s(u);let d=require("@univerjs/protocol"),f=require("@univerjs-pro/engine-formula");var p=class{constructor(e,t,n){this._unitId=e,this._commandService=t,this._permissionService=n}async setObjectPermissions(e){return this._commandService.executeCommand(c.SetBasePermissionsCommand.id,{unitId:this._unitId,changes:e})}async setPoint(e,t){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:e,value:t})}getPoint(e){return(0,c.getBasePermissionValue)(this._permissionService,this._unitId,this._unitId,e)}async setEditable(e=!0){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:d.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:d.UnitAction.Edit,value:!1})}canEdit(){return(0,c.getBasePermissionValue)(this._permissionService,this._unitId,this._unitId,d.UnitAction.Edit)}},m=class{constructor(e,t,n,r,i){this._unitId=e,this._objectId=t,this._parentObjectIds=n,this._commandService=r,this._permissionService=i}async setEditable(e=!0){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:d.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:d.UnitAction.Edit,value:!1})}canEdit(){return(0,c.canEditBaseTargets)(this._permissionService,this._unitId,[...this._parentObjectIds,this._objectId])}};function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let _=class{constructor(e,t,n,r,i){this._base=e,this._table=t,this._fieldId=n,this._commandService=r,this._permissionService=i}getId(){return this._fieldId}getPermission(){let e=this._table.getId();return new m(this._base.getId(),(0,c.getBaseFieldPermissionObjectId)(e,this._fieldId),[(0,c.getBaseTablePermissionObjectId)(e)],this._commandService,this._permissionService)}getField(){return this._getField()}getName(){return this._getField().name}getType(){return this._getField().type}getConfig(){return this._getField().config}getDefaultValue(){return this._getField().defaultValue}getDescription(){return this._getField().description}isReadonly(){return!!this._getField().readonly}setName(e){return this.update({name:e})}setConfig(e,t){return this.update({config:e},t)}setDefaultValue(e){return this.update({defaultValue:e})}update(e,t){let n=this._getField().type;return(e.type??n)===l.BaseFieldType.Formula&&(Object.prototype.hasOwnProperty.call(e,`config`)||e.type===l.BaseFieldType.Formula)&&!this._writeFormulaExternalReferences(t)?!1:this._commandService.syncExecuteCommand(c.UpdateBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId,patch:e})}changeType(e,t={},n){return e===l.BaseFieldType.Formula&&!this._writeFormulaExternalReferences(n)?!1:this._commandService.syncExecuteCommand(c.ChangeBaseFieldTypeCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId,input:{type:e,config:t}})}delete(){return this._commandService.syncExecuteCommand(c.DeleteBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId})}move(e){return this._commandService.syncExecuteCommand(c.MoveBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId,target:e})}_getField(){let e=this._table.getTable().fields[this._fieldId];if(!e)throw Error(`[FField]: field "${this._fieldId}" does not exist.`);return e}_writeFormulaExternalReferences(e){if(!e||!Array.isArray(e.externalReferences))return console.warn(`[Base Field Facade]: Formula writes require { externalReferences }. Use [] only for a Host-local formula.`),!1;if(e.externalReferences.length===0)return!0;let t=this._commandService.syncExecuteCommand(f.UpsertHostExternalReferencesCommand.id,{unitId:this._base.getId(),references:e.externalReferences});return t||console.warn(`[Base Field Facade]: Failed to bind External References.`),t}};_=g([h(3,l.ICommandService),h(4,l.IPermissionService)],_);let v=/* @__PURE__ */ function(e){return e.Id=`id`,e.Name=`name`,e.Auto=`auto`,e}({});function y(e){return!!(e&&e.system!==!0&&e.type!==l.BaseFieldType.RecordId)}function b(e,t,n=`id`){if(!t)return{};let r={};return Object.entries(t).forEach(([t,i])=>{let a=S(e,t,n);r[a]=x(e.fields[a],i)}),r}function x(e,t){if((e==null?void 0:e.type)!==l.BaseFieldType.Attachment||t==null)return t;if(!Array.isArray(t))throw TypeError(`Invalid attachment value for field "${e.name}": expected an array.`);return t.map((t,n)=>C(e,t,n))}function S(e,t,n){if(n===`id`||n===`auto`&&e.fields[t])return t;let r=Object.values(e.fields).filter(e=>e.name===t);if(r.length===1)return r[0].id;throw r.length>1?Error(`Duplicate Base field name: ${t}`):Error(`Base field not found: ${t}`)}function C(e,t,n){let r=`Invalid attachment at index ${n} for field "${e.name}"`;if(!O(t))throw TypeError(`${r}: expected an object.`);if(`url`in t)throw TypeError(`${r}: "url" is not supported; use "source".`);if(`type`in t)throw TypeError(`${r}: "type" is not supported; use "mimeType".`);let i=T(t.id,r,`id`),a=T(t.name,r,`name`),o=T(t.source,r,`source`);return{id:i,name:a,source:o,sourceType:w(t.sourceType,o,r),...E(t,`mimeType`,r),...D(t,`size`,r),...D(t,`width`,r),...D(t,`height`,r),...E(t,`thumbnail`,r)}}function w(e,t,n){if(e==null)return t.startsWith(`data:`)?l.ImageSourceType.BASE64:l.ImageSourceType.URL;if(e===l.ImageSourceType.URL||e===l.ImageSourceType.UUID||e===l.ImageSourceType.BASE64)return e;throw TypeError(`${n}: "sourceType" must be URL, UUID, or BASE64.`)}function T(e,t,n){if(typeof e!=`string`||!e.trim())throw TypeError(`${t}: "${n}" must be a non-empty string.`);return e}function E(e,t,n){let r=e[t];if(r==null)return{};if(typeof r!=`string`||!r.trim())throw TypeError(`${n}: "${t}" must be a non-empty string when provided.`);return{[t]:r}}function D(e,t,n){let r=e[t];if(r==null)return{};if(typeof r!=`number`||!Number.isFinite(r)||r<0)throw TypeError(`${n}: "${t}" must be a non-negative finite number when provided.`);return{[t]:r}}function O(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var k;let A=k=class{constructor(e,t,n,r,i){this._base=e,this._table=t,this._range=n,this._inject=r,this._commandService=i,this._assertInBounds()}getBaseId(){return this._base.getId()}getTableId(){return this._table.getId()}getRange(){return{...this._range}}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getNumRows(){return this._range.endRow-this._range.startRow+1}getNumColumns(){return this._range.endColumn-this._range.startColumn+1}getValues(){let e=this._getTable(),t=this._getFieldIds(e),n=[];for(let i=this._range.startRow;i<=this._range.endRow;i++){var r;let a=(r=e.rowId)==null?void 0:r[i],o=[];for(let n=this._range.startColumn;n<=this._range.endColumn;n++){let r=t[n];o.push(a&&r?(0,c.getBaseCellValue)(e,a,r):null)}n.push(o)}return n}getValue(){var e;return((e=this.getValues()[0])==null?void 0:e[0])??null}setValue(e){return this.setValues([[e]])}setValues(e){let t=this.getNumRows(),n=this.getNumColumns();if(e.length>t||e.some(e=>e.length>n)){var r;throw Error(`[FBaseRange]: values size ${e.length}x${((r=e[0])==null?void 0:r.length)??0} exceeds range size ${t}x${n}.`)}let i=this._getTable(),a=this._getFieldIds(i),o=e.flatMap((e,t)=>e.map((e,n)=>{var r;let o=this._range.startRow+t,s=a[this._range.startColumn+n],c=(r=i.rowId)==null?void 0:r[o];if(!s||!c)throw Error(`[FBaseRange]: cannot resolve the public Base range address.`);return{recordId:c,fieldId:s,value:e}}));return this._commandService.syncExecuteCommand(c.SetBaseRangeValuesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),patches:o,source:c.BaseEventSource.Facade})}clear(){return this.setValues(Array.from({length:this.getNumRows()},()=>Array.from({length:this.getNumColumns()},()=>null)))}offset(e,t,n=this.getNumRows(),r=this.getNumColumns()){return this._inject.createInstance(k,this._base,this._table,{startRow:this._range.startRow+e,startColumn:this._range.startColumn+t,endRow:this._range.startRow+e+n-1,endColumn:this._range.startColumn+t+r-1},this._inject)}_getTable(){let e=this._table.getTable();if(!e)throw Error(`[FBaseRange]: table does not exist.`);return(0,c.ensureBaseTableCellLayout)(e)}_assertInBounds(){var e;let t=this._getTable(),n=((e=t.recordOrder)==null?void 0:e.length)??0,r=this._getFieldIds(t).length;if(this._range.startRow<0||this._range.startColumn<0||this._range.endRow<this._range.startRow||this._range.endColumn<this._range.startColumn||this._range.endRow>=Math.max(n,1)||this._range.endColumn>=Math.max(r,1))throw Error(`[FBaseRange]: range is out of bounds. Max rows: ${n}, max columns: ${r}, range: ${JSON.stringify(this._range)}.`)}_getFieldIds(e){return e.fieldOrder.filter(t=>y(e.fields[t]))}};A=k=g([h(4,l.ICommandService)],A);function j(e){"@babel/helpers - typeof";return j=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},j(e)}function M(e,t){if(j(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(j(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function N(e){var t=M(e,`string`);return j(t)==`symbol`?t:t+``}function P(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var F;let I=F=class extends u.FBaseInitialable{constructor(e,t,n,r,i,a){super(r),this._base=e,this._table=t,this._recordId=n,this._injector=r,this._commandService=i,this._permissionService=a,P(this,`_baseUnitId`,void 0),P(this,`_baseTableId`,void 0),this._baseUnitId=e.getId(),this._baseTableId=t.getId()}getBaseFacade(){return this._base}getTableFacade(){return this._table}getId(){return this._recordId}getPermission(){let e=this._table.getId();return new m(this._base.getId(),(0,c.getBaseRecordPermissionObjectId)(e,this._recordId),[(0,c.getBaseTablePermissionObjectId)(e)],this._commandService,this._permissionService)}getRecord(){return{...this._getRecord(),values:this.getValues()}}getValue(e){return y(this._table.getTable().fields[e])?this._getRecord().values[e]??null:null}getValues(){let e=this._table.getTable();return Object.fromEntries(Object.entries(this._getRecord().values).filter(([t])=>y(e.fields[t])))}setValue(e,t){let n=this._table.getTable().fields[e];return this._commandService.syncExecuteCommand(c.UpdateBaseCellCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,fieldId:e,value:x(n,t),source:c.BaseEventSource.Facade})}setAttachments(e,t){return this.setValue(e,t.map(e=>({...e})))}getAttachments(e){this._getAttachmentField(e);let t=this.getValue(e);return Array.isArray(t)?t.map((t,n)=>R(t,e,n)):[]}deleteAttachments(e,t){this._getAttachmentField(e);let n=new Set(t.map(e=>e.id));if(!n.size)return!0;let r=this.getAttachments(e),i=r.filter(e=>!n.has(e.id));return i.length===r.length||this.setAttachments(e,i)}setValues(e,t=`id`){let n=this._table.getTable(),r=[{recordId:this._recordId,values:b(n,e,t)}];return this._commandService.syncExecuteCommand(c.SetBaseRecordValuesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),patches:r,source:c.BaseEventSource.Facade})}delete(){return this._commandService.syncExecuteCommand(c.DeleteBaseRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,source:c.BaseEventSource.Facade})}duplicate(e){let t={...this._getRecord(),...e,id:(0,l.generateRandomId)(6)};t.values={...t.values,...e==null?void 0:e.values},Reflect.deleteProperty(t.values,l.BASE_RECORD_ID_FIELD_ID);let n=Date.now();if(t.orderKey||=`${n}`,t.createdAt||=n,t.updatedAt||=n,!this._commandService.syncExecuteCommand(c.DuplicateBaseRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),sourceRecordId:this._recordId,record:t,source:c.BaseEventSource.Facade}))throw Error(`[FRecord]: failed to duplicate record "${this._recordId}".`);return this._injector.createInstance(F,this._base,this._table,t.id,this._injector)}setOrderKey(e){return this._commandService.syncExecuteCommand(c.UpdateBaseRecordOrderCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,orderKey:e})}getLinkedRecordIds(e){let t=this._getRecordLinkField(e),n=this.getValue(t.id);return(0,c.parseRecordLinkIds)(n)}setLinkedRecordIds(e,t){let n=this._getRecordLinkField(e),r=(0,c.serializeRecordLinkIds)(t),i=(0,c.validateRecordLinkValue)(this._base.getBase().getSnapshot(),n,r);if(!i.valid)throw Error(i.reason??`[FRecord]: invalid RecordLink value.`);return this._commandService.syncExecuteCommand(c.UpdateBaseCellCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,fieldId:e,value:r,source:c.BaseEventSource.Facade})}addLinkedRecord(e,t){let n=this._getRecordLinkField(e),r=(0,c.getRecordLinkFieldConfig)(n);if(!r)throw Error(`[FRecord]: RecordLink field "${e}" has invalid config.`);let i=this.getLinkedRecordIds(e);return r.multiple&&i.includes(t)?!0:this.setLinkedRecordIds(e,r.multiple?[...i,t]:[t])}removeLinkedRecord(e,t){let n=this.getLinkedRecordIds(e);return!n.includes(t)||this.setLinkedRecordIds(e,n.filter(e=>e!==t))}getParent(e){let t=this._getHierarchyIndex(e).parentByRecordId.get(this._recordId)??null;return t?this._table.getRecordById(t):null}getChildren(e){return(this._getHierarchyIndex(e).childrenByParentId.get(this._recordId)??[]).flatMap(e=>{let t=this._table.getRecordById(e);return t?[t]:[]})}getAncestors(e){let t=this._getHierarchyIndex(e),n=[],r=t.parentByRecordId.get(this._recordId)??null;for(;r;){let e=this._table.getRecordById(r);e&&n.push(e),r=t.parentByRecordId.get(r)??null}return n}getDescendants(e){let t=this._getHierarchyIndex(e),n=t.orderedRecordIds.indexOf(this._recordId),r=t.subtreeHeightByRecordId.has(this._recordId)?this._collectDescendantIds(t.childrenByParentId,this._recordId):[];return n<0?[]:r.flatMap(e=>{let t=this._table.getRecordById(e);return t?[t]:[]})}setParent(e,t,n){return this._commandService.syncExecuteCommand(c.MoveBaseHierarchyRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:e,recordId:this._recordId,parentRecordId:t,orderKey:n,source:c.BaseEventSource.Facade})}addChild(e,t,n=`id`,r){let i=this._table.getTable(),a=Date.now(),o={...r,id:(0,l.generateRandomId)(6),values:b(i,t,n),orderKey:(r==null?void 0:r.orderKey)||`${a}`,createdAt:(r==null?void 0:r.createdAt)||a,updatedAt:(r==null?void 0:r.updatedAt)||a};if(!this._commandService.syncExecuteCommand(c.CreateBaseChildRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:e,parentRecordId:this._recordId,record:o,source:c.BaseEventSource.Facade}))throw Error(`[FRecord]: failed to create child under "${this._recordId}".`);return this._injector.createInstance(F,this._base,this._table,o.id,this._injector)}_getHierarchyIndex(e){return(0,c.buildBaseHierarchyIndex)(this._table.getTable(),e)}_collectDescendantIds(e,t){let n=[],r=t=>{for(let i of e.get(t)??[])n.push(i),r(i)};return r(t),n}_getRecord(){let e=this._table.getTable().records[this._recordId];if(!e)throw Error(`[FRecord]: record "${this._recordId}" does not exist.`);return e}_getRecordLinkField(e){let t=this._table.getTable().fields[e];if(!t||t.type!==l.BaseFieldType.RecordLink)throw Error(`[FRecord]: field "${e}" is not a RecordLink field.`);return t}_getAttachmentField(e){let t=this._table.getTable().fields[e];if(!t||t.type!==l.BaseFieldType.Attachment)throw Error(`[FRecord]: field "${e}" is not an Attachment field.`);return t}};I=F=g([h(4,l.ICommandService),h(5,l.IPermissionService)],I);function L(e){return!!(e&&typeof e==`object`&&`id`in e&&typeof e.id==`string`&&`name`in e&&typeof e.name==`string`)}function R(e,t,n){if(!L(e))throw Error(`[FRecord]: attachment at index ${n} in field "${t}" is invalid.`);return{...e}}let z=class{constructor(e,t,n,r,i,a,o){this._base=e,this._table=t,this._viewId=n,this._injector=r,this._commandService=i,this._permissionService=a,this._projectionService=o}getId(){return this._viewId}getPermission(){let e=this._table.getId();return new m(this._base.getId(),(0,c.getBaseViewPermissionObjectId)(e,this._viewId),[(0,c.getBaseTablePermissionObjectId)(e)],this._commandService,this._permissionService)}getView(){return this._getView()}getName(){return this._getView().name}getType(){return this._getView().type}setName(e){return this._commandService.syncExecuteCommand(c.RenameBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,name:e})}getConfig(){let e=this.getType(),t=this._getView().config;switch(e){case l.BaseViewType.Grid:return t;case l.BaseViewType.Kanban:return t;case l.BaseViewType.Calendar:return t;case l.BaseViewType.Gantt:return t;case l.BaseViewType.Gallery:return t;default:return t}}updateConfig(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConfigCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,patch:e})}getConditionalColorRules(){var e;return l.Tools.deepClone(((e=this._getView().config.conditionalColoring)==null?void 0:e.rules)??[])}setConditionalColorRules(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Set,rules:e})}addConditionalColorRule(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Add,rule:e})}deleteConditionalColorRule(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Delete,ruleId:e})}clearConditionalColorRules(){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Clear})}getFilter(){return this._getView().filter??null}setFilter(e){return this._commandService.syncExecuteCommand(c.SetBaseViewFilterCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,filter:e})}getSort(){return this._getView().sort??[]}setSort(e){return this._commandService.syncExecuteCommand(c.SetBaseViewSortCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,sort:e})}getGroup(){return this._getView().group??[]}setGroup(e){return this._commandService.syncExecuteCommand(c.SetBaseViewGroupCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,group:e})}getFieldSettings(e){var t;return y(this._table.getTable().fields[e])?((t=this._getView().fieldSettings)==null?void 0:t[e])??{}:{}}getVisibleFields(){let e=this._table.getTable(),t=this._getView();return(t.fieldOrder??e.fieldOrder).filter(n=>{var r;let i=e.fields[n];return y(i)&&!((r=t.fieldSettings)!=null&&(r=r[n])!=null&&r.hidden)}).map(e=>this._injector.createInstance(_,this._base,this._table,e))}setFieldVisible(e,t){return y(this._table.getTable().fields[e])?this._commandService.syncExecuteCommand(c.SetBaseViewFieldVisibleCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,fieldId:e,visible:t}):!1}setFieldWidth(e,t){return y(this._table.getTable().fields[e])?this._commandService.syncExecuteCommand(c.SetBaseViewFieldWidthCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,fieldId:e,width:t}):!1}moveField(e,t){let n=this._table.getTable(),r=t.beforeFieldId??t.afterFieldId;return!y(n.fields[e])||!r||!y(n.fields[r])?!1:this._commandService.syncExecuteCommand(c.SetBaseViewFieldOrderCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,fieldId:e,target:t})}move(e){return this._commandService.syncExecuteCommand(c.MoveBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,target:e})}delete(){return this._commandService.syncExecuteCommand(c.DeleteBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId})}getProjection(){return this._projectionService.getProjection(this._base.getBase().getSnapshot(),this._table.getId(),this._viewId)}_getView(){let e=this._table.getTable().views[this._viewId];if(!e)throw Error(`[FView]: view "${this._viewId}" does not exist.`);return e}};z=g([h(4,l.ICommandService),h(5,l.IPermissionService),h(6,c.IBaseProjectionService)],z);let B=class{constructor(e,t,n,r,i,a){this._base=e,this._tableId=t,this._injector=n,this._commandService=r,this._permissionService=i,this._projectionService=a}getBase(){return this._base.getBase()}getTable(){return this._getTable()}getId(){return this._tableId}getPermission(){return new m(this.getBase().getUnitId(),(0,c.getBaseTablePermissionObjectId)(this._tableId),[],this._commandService,this._permissionService)}getHierarchyFieldId(){return(0,c.resolveBaseHierarchyFieldId)(this._getTable())}setHierarchyField(e){return this._commandService.syncExecuteCommand(c.SetBaseTableHierarchyFieldCommand.id,{unitId:this._base.getId(),tableId:this._tableId,fieldId:e})}getName(){return this._getTable().name}getFormulaName(){let e=this._base.getBase().getSnapshot();return(0,c.getBaseFormulaTableName)(this._getTable(),e)}setName(e){let t=(0,c.validateBaseTableName)(this._base.getBase().getSnapshot(),e,this._tableId);if(!t.valid)throw Error(`[FBaseTable]: invalid table name "${e}". ${c.BASE_TABLE_NAME_REQUIREMENTS} ${t.reason}`);return this._commandService.syncExecuteCommand(c.RenameBaseTableCommand.id,{unitId:this._base.getId(),tableId:this._tableId,name:e})}search(e,t){let n=this._base.getBase().getSnapshot(),r=this._getTable();if(t){let i=this._projectionService.getProjection(n,this._tableId,t),a=r.views[t],o=e.fieldIds??J(r,a,i),s=`rows`in i&&Array.isArray(i.rows)?i.rows:[];return(0,c.searchBaseTable)({...e,table:r,fieldIds:o,rows:s})}let i=(r.recordOrder?r.recordOrder.map(e=>r.records[e]):Object.values(r.records).sort((e,t)=>e.orderKey.localeCompare(t.orderKey))).filter(e=>e).map(e=>({recordId:e.id,values:e.values})),a=e.fieldIds??r.fieldOrder.filter(e=>y(r.fields[e]));return(0,c.searchBaseTable)({...e,table:r,fieldIds:a,rows:i})}getPrimaryFieldId(){return this._getTable().primaryFieldId}getFields(){let e=this._getTable();return e.fieldOrder.map(t=>e.fields[t]).filter(y).map(e=>this._injector.createInstance(_,this._base,this,e.id))}getFieldById(e){let t=this._getTable().fields[e];return y(t)?this._injector.createInstance(_,this._base,this,t.id):null}getFieldByName(e){let t=this._getTable().fields,n=Object.values(t).find(t=>y(t)&&t.name===e);return n?this._injector.createInstance(_,this._base,this,n.id):null}getPrimaryField(){let e=this._getTable().primaryFieldId;return this._injector.createInstance(_,this._base,this,e)}addField(e,t,n){var r,i;if(!Object.values(l.BaseFieldType).some(e=>e===t))throw Error(`Unsupported Base field type "${String(t)}".`);if(t===l.BaseFieldType.Formula&&this._prepareFormulaFieldReferences(e,n),t===l.BaseFieldType.RecordLink&&(typeof(n==null||(r=n.field)==null||(r=r.config)==null?void 0:r.targetTableId)!=`string`||typeof n.field.config.multiple!=`boolean`))throw Error(`RecordLink fields require config { targetTableId, multiple }.`);let a={...n==null?void 0:n.field,id:(0,l.generateRandomId)(6),name:e,type:t,config:(n==null||(i=n.field)==null?void 0:i.config)??{}};if(!this._commandService.syncExecuteCommand(c.CreateBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._tableId,field:a,index:n==null?void 0:n.index}))throw Error(`Failed to add field "${e}"`);return this._injector.createInstance(_,this._base,this,a.id)}_prepareFormulaFieldReferences(e,t){var n;if(!t||!(`externalReferences`in t)||!Array.isArray(t.externalReferences))throw Error(`Formula fields require options.externalReferences. Use [] only for a Host-local formula.`);let r=this._commandService.syncExecuteCommand(c.ValidateBaseFormulaCommand.id,{unitId:this._base.getId(),tableId:this._tableId,formula:String(((n=t.field)==null||(n=n.config)==null?void 0:n.formula)??``)});if(!r.valid)throw Error(r.reason??`Invalid Base formula.`);if(t.externalReferences.length>0&&!this._commandService.syncExecuteCommand(f.UpsertHostExternalReferencesCommand.id,{unitId:this._base.getId(),references:t.externalReferences}))throw Error(`Failed to bind External References for formula field "${e}"`)}getRecords(){return this._resolveRecordIds().map(e=>this._injector.createInstance(I,this._base,this,e,this._injector))}getRecordById(e){return this._getTable().records[e]?this._injector.createInstance(I,this._base,this,e,this._injector):null}queryRecords(e={}){let t=this._getTable(),n=this._resolveRecordIds(e),r=Math.max(0,e.offset??0),i=e.limit==null?null:Math.max(0,e.limit),a=H(n.map(e=>t.records[e]).filter(n=>W(n,t,e.filter)),t,e.sort);return{records:V(a,e).map(e=>this._injector.createInstance(I,this._base,this,e.id,this._injector)),total:a.length,offset:r,limit:i,hasMore:i!=null&&r+i<a.length}}addRecord(e,t=`id`,n){let r=this._getTable(),i=Date.now(),a={...n,id:(0,l.generateRandomId)(6),values:b(r,e,t),orderKey:(n==null?void 0:n.orderKey)||`${i}`,createdAt:(n==null?void 0:n.createdAt)||i,updatedAt:(n==null?void 0:n.updatedAt)||i};if(!this._commandService.syncExecuteCommand(c.CreateBaseRecordCommand.id,{unitId:this._base.getId(),tableId:this._tableId,record:a,source:c.BaseEventSource.Facade}))throw Error(`Failed to add record with id "${a.id}"`);return this._injector.createInstance(I,this._base,this,a.id,this._injector)}addRecords(e){if(!e.length)return[];let t=this._getTable(),n=Date.now(),r=e.map((e,r)=>{var i,a,o;return{...e.record,id:(0,l.generateRandomId)(6),values:b(t,e.values,e.fieldKey??`id`),orderKey:((i=e.record)==null?void 0:i.orderKey)||`${n+r}`,createdAt:((a=e.record)==null?void 0:a.createdAt)||n,updatedAt:((o=e.record)==null?void 0:o.updatedAt)||n}});if(!this._commandService.syncExecuteCommand(c.BatchCreateBaseRecordsCommand.id,{unitId:this._base.getId(),tableId:this._tableId,records:r,source:c.BaseEventSource.Facade}))throw Error(`Failed to add records`);return r.map(e=>this._injector.createInstance(I,this._base,this,e.id,this._injector))}deleteRecords(e){return!e.length||this._commandService.syncExecuteCommand(c.BatchDeleteBaseRecordsCommand.id,{unitId:this._base.getId(),tableId:this._tableId,recordIds:e,source:c.BaseEventSource.Facade})}getRange(e,t,n=1,r=1){return this._injector.createInstance(A,this._base,this,{startRow:e,endRow:e+n-1,startColumn:t,endColumn:t+r-1},this._injector)}getDataRange(){var e;let t=(0,c.ensureBaseTableCellLayout)(this._getTable()),n=((e=t.recordOrder)==null?void 0:e.length)??0,r=t.fieldOrder.filter(e=>y(t.fields[e])).length;return this.getRange(0,0,Math.max(n,1),Math.max(r,1))}getViews(){let e=this._getTable();return e.viewOrder.filter(t=>e.views[t]).map(e=>this._injector.createInstance(z,this._base,this,e,this._injector))}getViewById(e){return this._getTable().views[e]?this._injector.createInstance(z,this._base,this,e,this._injector):null}getViewByName(e){let t=this._getTable(),n=Object.values(t.views).find(t=>t.name===e);return n?this._injector.createInstance(z,this._base,this,n.id,this._injector):null}createView(e,t,n){var r,i,a,o;let s=this._getTable(),u=(n==null||(r=n.view)==null?void 0:r.fieldOrder)??s.fieldOrder,d=[l.BASE_RECORD_ID_FIELD_ID,...u.filter(e=>y(s.fields[e]))],f={...n==null?void 0:n.view,id:(0,l.generateRandomId)(6),name:e,type:t,tableId:this._tableId,config:(n==null||(i=n.view)==null?void 0:i.config)??{},fieldOrder:d,fieldSettings:{...n==null||(a=n.view)==null?void 0:a.fieldSettings,[l.BASE_RECORD_ID_FIELD_ID]:{...n==null||(o=n.view)==null||(o=o.fieldSettings)==null?void 0:o[l.BASE_RECORD_ID_FIELD_ID],hidden:!0}}};if(!this._commandService.syncExecuteCommand(c.CreateBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._tableId,view:f,index:n==null?void 0:n.index}))throw Error(`Failed to create view "${e}"`);return this._injector.createInstance(z,this._base,this,f.id,this._injector)}getSchema(){let e=this._getTable(),t=e.fieldOrder.filter(t=>y(e.fields[t])),n=e.viewOrder.filter(t=>e.views[t]);return{id:e.id,name:e.name,formulaName:this.getFormulaName(),primaryFieldId:e.primaryFieldId,fieldIds:t,viewIds:n,recordCount:this._resolveRecordIds().length,fields:t.map(t=>{let n=e.fields[t];return{id:n.id,name:n.name,type:n.type,config:n.config,readonly:n.readonly,description:n.description}}),views:n.map(t=>{let n=e.views[t];return{id:n.id,name:n.name,type:n.type}})}}_getTable(){let e=this._base.getBase().getSnapshot().tables[this._tableId];if(!e)throw Error(`[FTable]: table "${this._tableId}" does not exist.`);return e}_resolveRecordIds(e={}){let t=this._base.getBase().getSnapshot(),n=this._getTable();if(e.viewId){let n=this._projectionService.getProjection(t,this._tableId,e.viewId);if(`rows`in n&&Array.isArray(n.rows))return n.rows.map(e=>e.recordId)}return(n.recordOrder?n.recordOrder.map(e=>n.records[e]):Object.values(n.records).sort((e,t)=>e.orderKey.localeCompare(t.orderKey))).filter(e=>e).map(e=>e.id)}};B=g([h(3,l.ICommandService),h(4,l.IPermissionService),h(5,c.IBaseProjectionService)],B);function V(e,t){let n=Math.max(0,t.offset??0);return t.limit==null?e.slice(n):e.slice(n,n+Math.max(0,t.limit))}function H(e,t,n=[]){return n.length?[...e].sort((e,r)=>{for(let a of n){var i;let n=a.direction===l.BaseSortDirection.DESC?-1:1,o=U(e.values[a.fieldId],r.values[a.fieldId],(i=t.fields[a.fieldId])==null?void 0:i.type);if(o!==0)return o*n}return String(e.orderKey??e.id).localeCompare(String(r.orderKey??r.id))}):e}function U(e,t,n){return e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e-t:n===l.BaseFieldType.Date?Number(e)-Number(t):String(e).localeCompare(String(t))}function W(e,t,n){var r;if(!n||!((r=n.conditions)!=null&&r.length))return!0;let{conjunction:i=l.BaseFilterConjunction.OR,conditions:a}=n;return i===l.BaseFilterConjunction.AND&&a.length>1?a.every(n=>G(e,t,n)):a.some(n=>G(e,t,n))}function G(e,t,n){let r=e.values[n.fieldId],i=t.fields[n.fieldId];if(K(n)){let e=q(n).test(String(r??``));return n.operator===`matches`?e:!e}return!i||(0,c.matchesBaseCondition)(r,n.operator,n.value,i)}function K(e){return e.operator===`matches`||e.operator===`notMatches`}function q(e){let t=String(e.value??``);if(t.length>512)throw Error(`Base regex filter is too long. Maximum length is 512.`);try{return new RegExp(t,e.caseSensitive?void 0:`i`)}catch(e){throw Error(`Invalid Base regex filter: ${t}. ${e instanceof Error?e.message:String(e)}`)}}function J(e,t,n){if(n.type!==`invalid`&&n.type!==`custom`){var r;if(n.type===l.BaseViewType.Kanban){var i;let t=[((i=n.fields)==null||(i=i[0])==null?void 0:i.id)??e.primaryFieldId,...n.visibleCardFieldIds??[]];return Array.from(new Set(t.filter(t=>!!e.fields[t])))}if((r=n.fields)!=null&&r.length)return n.fields.map(e=>e.id).filter(n=>{var r;return!(!e.fields[n]||t!=null&&(r=t.fieldSettings)!=null&&(r=r[n])!=null&&r.hidden)})}return e.fieldOrder.filter(n=>{var r;return!(!e.fields[n]||t!=null&&(r=t.fieldSettings)!=null&&(r=r[n])!=null&&r.hidden)})}let Y=class extends u.FBase{constructor(e,t,n,r,i){super(),this._base=e,this._injector=t,this._resourceLoaderService=n,this._commandService=r,this._permissionService=i}getBase(){return this._base}getId(){return this._base.getUnitId()}getPermission(){return new p(this.getId(),this._commandService,this._permissionService)}save(){return this._resourceLoaderService.saveUnit(this.getId())??l.Tools.deepClone(this._base.getSnapshot())}getName(){return this._base.getSnapshot().name}setName(e){this._commandService.syncExecuteCommand(c.SetBaseNameCommand.id,{unitId:this.getId(),name:e})}getTables(){let e=this._base.getSnapshot();return e.tableOrder.map(t=>e.tables[t]).filter(e=>e).map(e=>this._injector.createInstance(B,this,e.id,this._injector))}getTableById(e){let t=this._base.getSnapshot().tables[e];return t?this._injector.createInstance(B,this,t.id,this._injector):null}getTableByName(e){let t=this._base.getSnapshot(),n=Object.values(t.tables).find(t=>t.name===e);return n?this._injector.createInstance(B,this,n.id,this._injector):null}insertTable(e,t){let n=(0,l.createDefaultBaseTableSnapshot)({id:(0,l.generateRandomId)(),name:e,...t==null?void 0:t.table,primaryFieldName:t==null?void 0:t.primaryFieldName}),r=l.Tools.commonExtend(n,(t==null?void 0:t.table)??{}),i=(0,c.validateBaseTableName)(this._base.getSnapshot(),r.name);if(!i.valid)throw Error(`[FBase]: invalid table name "${r.name}". ${c.BASE_TABLE_NAME_REQUIREMENTS} ${i.reason}`);if(!this._commandService.syncExecuteCommand(c.CreateBaseTableCommand.id,{unitId:this._base.getUnitId(),table:r,index:t==null?void 0:t.index}))throw Error(`Failed to create table "${e}".`);return this._injector.createInstance(B,this,r.id,this._injector)}deleteTable(e){let t=typeof e==`string`?e:e.getId();if(!this._commandService.syncExecuteCommand(c.DeleteBaseTableCommand.id,{unitId:this._base.getUnitId(),tableId:t}))throw Error(`Failed to delete table "${t}".`);return!0}duplicateTable(e,t){let n=this._base.getSnapshot(),r=typeof e==`string`?e:e.getId(),i=n.tables[r];if(!i)throw Error(`[FBase]: table "${r}" does not exist.`);let a=n.tableOrder.indexOf(r)+1,o=(0,l.generateRandomId)(),s=(0,c.copyBaseTableSnapshot)(i,{id:o,name:(0,c.createUniqueBaseTableName)(n,`${i.name} Copy`),includeRecords:(t==null?void 0:t.includeRecords)??!1,regenerateViewIds:(t==null?void 0:t.regenerateViewIds)??!1});if(!this._commandService.syncExecuteCommand(c.CreateBaseTableCommand.id,{unitId:this._base.getUnitId(),table:s,index:a}))throw Error(`Failed to duplicate table "${r}".`);return this._injector.createInstance(B,this,s.id,this._injector)}getSchema(){let e=this._base.getSnapshot();return{id:e.id,name:e.name,tables:this.getTables().map(e=>e.getSchema())}}};Y=g([h(1,(0,l.Inject)(l.Injector)),h(2,l.IResourceLoaderService),h(3,l.ICommandService),h(4,l.IPermissionService)],Y);var X=class extends u.FUniver{_initialize(){this._initBaseBeforeEvents(),this._initBaseAfterEvents()}createBase(e={},t){let n=this._univerInstanceService.createUnit(l.UniverInstanceType.UNIVER_BASE,e,t);return this._injector.createInstance(Y,n)}getActiveBase(){let e=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_BASE);return e?this._injector.createInstance(Y,e):null}getBase(e){let t=this._univerInstanceService.getUnit(e,l.UniverInstanceType.UNIVER_BASE);return t?this._injector.createInstance(Y,t):null}getBases(){return this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_BASE).map(e=>this._injector.createInstance(Y,e))}_initBaseAfterEvents(){this.disposeWithMe(this.registerEventHandler(this.Event.BaseHierarchyChanged,()=>this._commandService.onCommandExecuted((e,t)=>{var n;if(!Z(e,c.ApplyBaseJson1Mutation))return;let r=e.params;if(!((n=r.hierarchyChanges)!=null&&n.length))return;let i=this.getBase(r.unitId),a=i==null?void 0:i.getTableById(r.hierarchyChanges[0].tableId);if(!i||!a)return;let o={base:i,table:a,changes:r.hierarchyChanges,source:t!=null&&t.fromCollab?c.BaseEventSource.Remote:r.source??c.BaseEventSource.UI};this.fireEvent(this.Event.BaseHierarchyChanged,o)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseTableCommand.id)return;let{unitId:t,table:n,index:r}=e.params,i=this.getBase(t);if(!i)return;let a={base:i,table:n,index:r};this.fireEvent(this.Event.BaseTableCreated,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableFieldCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseFieldCommand.id)return;let{unitId:t,tableId:n,field:r,index:i,viewIndexes:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let l={base:o,table:s,field:r,index:i,viewIndexes:a};this.fireEvent(this.Event.BaseTableFieldCreated,l)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableRecordCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseRecordCommand.id&&e.id!==c.BatchCreateBaseRecordsCommand.id)return;let t=e.params,{unitId:n,tableId:r}=t,i=t.records??[t.record],a=this.getBase(n);if(!a)return;let o=a.getTableById(r);if(!o)return;let s={base:a,table:o,records:i};this.fireEvent(this.Event.BaseTableRecordCreated,s)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableViewCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseViewCommand.id)return;let{unitId:t,tableId:n,view:r,index:i}=e.params,a=this.getBase(t);if(!a)return;let o=a.getTableById(n);if(!o)return;let s={base:a,table:o,view:r,index:i};this.fireEvent(this.Event.BaseTableViewCreated,s)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableCellValueChanged,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.UpdateBaseCellCommand.id)return;let{unitId:t,tableId:n,recordId:r,fieldId:i,value:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let l=s.getFieldById(i);if(!l)return;let u=s.getRecordById(r);if(!u)return;let d={base:o,table:s,field:l,record:u,value:a};this.fireEvent(this.Event.BaseTableCellValueChanged,d)})))}_initBaseBeforeEvents(){this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseHierarchyChange,()=>this._commandService.beforeCommandExecuted(e=>{if(Z(e,c.SetBaseRecordValuesCommand)){let{unitId:t,tableId:n,patches:r,source:i=c.BaseEventSource.UI}=e.params,a=this._getHierarchyEventContext(t,n);if(!a)return;this._fireBeforeHierarchyChange(a.base,a.table,(0,c.validateBaseHierarchyRecordPatches)(a.table.getTable(),r),i);return}if(Z(e,c.SetBaseRangeValuesCommand)){let{unitId:t,tableId:n,patches:r,source:i=c.BaseEventSource.UI}=e.params,a=this._getHierarchyEventContext(t,n);if(!a)return;let o=a.table.getTable();this._fireBeforeHierarchyChange(a.base,a.table,(0,c.validateBaseHierarchyRecordPatches)(o,(0,c.resolveBaseRangeHierarchyPatches)(o,r)),i);return}if(Z(e,c.CreateBaseRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.validateBaseHierarchyRecordCreations)(n.table.getTable(),[t.record]),t.source??c.BaseEventSource.UI);return}if(Z(e,c.BatchCreateBaseRecordsCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.validateBaseHierarchyRecordCreations)(n.table.getTable(),t.records),t.source??c.BaseEventSource.UI);return}if(Z(e,c.DuplicateBaseRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.validateBaseHierarchyRecordCreations)(n.table.getTable(),[t.record]),t.source??c.BaseEventSource.UI);return}if(Z(e,c.MoveBaseHierarchyRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;let r=n.table.getTable(),i=t.fieldId??(0,c.resolveBaseHierarchyFieldId)(r),a=(0,c.buildBaseHierarchyIndex)(r,i).parentByRecordId.get(t.recordId)??null;this._fireBeforeHierarchyChange(n.base,n.table,[{tableId:t.tableId,fieldId:i,recordId:t.recordId,oldParentRecordId:a,parentRecordId:t.parentRecordId}],t.source??c.BaseEventSource.UI);return}if(Z(e,c.CreateBaseChildRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;let r=t.fieldId??(0,c.resolveBaseHierarchyFieldId)(n.table.getTable());this._fireBeforeHierarchyChange(n.base,n.table,[{tableId:t.tableId,fieldId:r,recordId:t.record.id,oldParentRecordId:null,parentRecordId:t.parentRecordId}],t.source??c.BaseEventSource.UI);return}if(Z(e,c.DeleteBaseRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.getBaseHierarchyDeletePromotions)(n.table.getTable(),[t.recordId]),t.source??c.BaseEventSource.UI);return}if(Z(e,c.BatchDeleteBaseRecordsCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.getBaseHierarchyDeletePromotions)(n.table.getTable(),t.recordIds),t.source??c.BaseEventSource.UI);return}if(!Z(e,c.UpdateBaseCellCommand))return;let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;let r=n.table.getTable();if(!(0,c.getActiveBaseHierarchyFieldIds)(r).includes(t.fieldId))return;let i=(0,c.buildBaseHierarchyIndex)(r,t.fieldId).parentByRecordId.get(t.recordId)??null,a=(0,c.parseRecordLinkIds)(t.value)[0]??null;i!==a&&this._fireBeforeHierarchyChange(n.base,n.table,[{tableId:t.tableId,fieldId:t.fieldId,recordId:t.recordId,oldParentRecordId:i,parentRecordId:a}],t.source??c.BaseEventSource.UI)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseTableCommand.id)return;let{unitId:t,table:n,index:r}=e.params,i=this.getBase(t);if(!i)return;let a={base:i,table:n,index:r};if(this.fireEvent(this.Event.BeforeBaseTableCreate,a),a.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableFieldCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseFieldCommand.id)return;let{unitId:t,tableId:n,field:r,index:i,viewIndexes:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let u={base:o,table:s,field:r,index:i,viewIndexes:a};if(this.fireEvent(this.Event.BeforeBaseTableFieldCreate,u),u.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableRecordCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseRecordCommand.id&&e.id!==c.BatchCreateBaseRecordsCommand.id)return;let t=e.params,{unitId:n,tableId:r}=t,i=t.records??[t.record],a=this.getBase(n);if(!a)return;let o=a.getTableById(r);if(!o)return;let s={base:a,table:o,records:i};if(this.fireEvent(this.Event.BeforeBaseTableRecordCreate,s),s.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableViewCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseViewCommand.id)return;let{unitId:t,tableId:n,view:r,index:i}=e.params,a=this.getBase(t);if(!a)return;let o=a.getTableById(n);if(!o)return;let s={base:a,table:o,view:r,index:i};if(this.fireEvent(this.Event.BeforeBaseTableViewCreate,s),s.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableCellValueChange,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.UpdateBaseCellCommand.id)return;let{unitId:t,tableId:n,recordId:r,fieldId:i,value:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let u=s.getFieldById(i);if(!u)return;let d=s.getRecordById(r);if(!d)return;let f={base:o,table:s,field:u,record:d,value:a};if(this.fireEvent(this.Event.BeforeBaseTableCellValueChange,f),f.cancel)throw new l.CanceledError})))}_getHierarchyEventContext(e,t){let n=this.getBase(e),r=n==null?void 0:n.getTableById(t);return n&&r?{base:n,table:r}:null}_fireBeforeHierarchyChange(e,t,n,r){if(!n.length)return;let i={base:e,table:t,changes:n,source:r};if(this.fireEvent(this.Event.BeforeBaseHierarchyChange,i),i.cancel)throw new l.CanceledError}};function Z(e,t){return e.id===t.id&&e.params!==void 0}u.FUniver.extend(X);var Q=class extends u.FEnum{get BaseFieldType(){return l.BaseFieldType}get BaseFilterConjunction(){return l.BaseFilterConjunction}get BaseFilterOperator(){return l.BaseFilterOperator}get BaseFieldKeyEnum(){return v}get BaseViewType(){return l.BaseViewType}get BaseConditionalColorTarget(){return l.BaseConditionalColorTarget}get BaseConditionalColorOperator(){return l.BaseConditionalColorOperator}get BaseConditionalDateMode(){return l.BaseConditionalDateMode}get BaseSortDirection(){return l.BaseSortDirection}get BaseEventSource(){return c.BaseEventSource}get BaseHierarchyErrorCode(){return c.BaseHierarchyErrorCode}get BaseHierarchyInvalidReason(){return l.BaseHierarchyInvalidReason}get BaseRecordLinkRole(){return l.BaseRecordLinkRole}};u.FEnum.extend(Q);var $=class extends u.FEventName{get BaseTableCreated(){return`BaseTableCreated`}get BeforeBaseTableCreate(){return`BeforeBaseTableCreate`}get BaseTableFieldCreated(){return`BaseTableFieldCreated`}get BeforeBaseTableFieldCreate(){return`BeforeBaseTableFieldCreate`}get BaseTableRecordCreated(){return`BaseTableRecordCreated`}get BeforeBaseTableRecordCreate(){return`BeforeBaseTableRecordCreate`}get BaseTableViewCreated(){return`BaseTableViewCreated`}get BeforeBaseTableViewCreate(){return`BeforeBaseTableViewCreate`}get BaseTableCellValueChanged(){return`BaseTableCellValueChanged`}get BeforeBaseTableCellValueChange(){return`BeforeBaseTableCellValueChange`}get BaseHierarchyChanged(){return`BaseHierarchyChanged`}get BeforeBaseHierarchyChange(){return`BeforeBaseHierarchyChange`}};u.FEventName.extend($),exports.BaseFieldKeyEnum=v,Object.defineProperty(exports,"FBase",{enumerable:!0,get:function(){return Y}}),exports.FBaseObjectPermission=m,exports.FBasePermission=p,Object.defineProperty(exports,"FBaseTable",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"FBaseTableField",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"FBaseTableRange",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"FBaseTableRecord",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"FBaseTableView",{enumerable:!0,get:function(){return z}}),exports.FBasesEventNameMixin=$,exports.resolveBaseFieldKey=S,exports.resolveBaseFieldValues=b;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));let c=require("@univerjs-pro/bases"),l=require("@univerjs/core"),u=require("@univerjs/core/facade");u=s(u);let d=require("@univerjs/protocol"),f=require("@univerjs/engine-formula");var p=class{constructor(e,t,n){this._unitId=e,this._commandService=t,this._permissionService=n}async setObjectPermissions(e){return this._commandService.executeCommand(c.SetBasePermissionsCommand.id,{unitId:this._unitId,changes:e})}async setPoint(e,t){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:e,value:t})}getPoint(e){return(0,c.getBasePermissionValue)(this._permissionService,this._unitId,this._unitId,e)}async setEditable(e=!0){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:d.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._unitId,action:d.UnitAction.Edit,value:!1})}canEdit(){return(0,c.getBasePermissionValue)(this._permissionService,this._unitId,this._unitId,d.UnitAction.Edit)}},m=class{constructor(e,t,n,r,i){this._unitId=e,this._objectId=t,this._parentObjectIds=n,this._commandService=r,this._permissionService=i}async setEditable(e=!0){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:d.UnitAction.Edit,value:e})}async setReadOnly(){await this._commandService.executeCommand(c.SetBasePermissionCommand.id,{unitId:this._unitId,objectId:this._objectId,action:d.UnitAction.Edit,value:!1})}canEdit(){return(0,c.canEditBaseTargets)(this._permissionService,this._unitId,[...this._parentObjectIds,this._objectId])}};function h(e,t){return function(n,r){t(n,r,e)}}function g(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let _=class{constructor(e,t,n,r,i){this._base=e,this._table=t,this._fieldId=n,this._commandService=r,this._permissionService=i}getId(){return this._fieldId}getPermission(){let e=this._table.getId();return new m(this._base.getId(),(0,c.getBaseFieldPermissionObjectId)(e,this._fieldId),[(0,c.getBaseTablePermissionObjectId)(e)],this._commandService,this._permissionService)}getField(){return this._getField()}getName(){return this._getField().name}getType(){return this._getField().type}getConfig(){return this._getField().config}getDefaultValue(){return this._getField().defaultValue}getDescription(){return this._getField().description}isReadonly(){return!!this._getField().readonly}setName(e){return this.update({name:e})}setConfig(e,t){return this.update({config:e},t)}setDefaultValue(e){return this.update({defaultValue:e})}update(e,t){let n=this._getField().type;return(e.type??n)===l.BaseFieldType.Formula&&(Object.prototype.hasOwnProperty.call(e,`config`)||e.type===l.BaseFieldType.Formula)&&!this._writeFormulaExternalReferences(t)?!1:this._commandService.syncExecuteCommand(c.UpdateBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId,patch:e})}changeType(e,t={},n){return e===l.BaseFieldType.Formula&&!this._writeFormulaExternalReferences(n)?!1:this._commandService.syncExecuteCommand(c.ChangeBaseFieldTypeCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId,input:{type:e,config:t}})}delete(){return this._commandService.syncExecuteCommand(c.DeleteBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId})}move(e){return this._commandService.syncExecuteCommand(c.MoveBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:this._fieldId,target:e})}_getField(){let e=this._table.getTable().fields[this._fieldId];if(!e)throw Error(`[FField]: field "${this._fieldId}" does not exist.`);return e}_writeFormulaExternalReferences(e){if(!e||!Array.isArray(e.externalReferences))return console.warn(`[Base Field Facade]: Formula writes require { externalReferences }. Use [] only for a Host-local formula.`),!1;if(e.externalReferences.length===0)return!0;let t=this._commandService.syncExecuteCommand(f.UpsertHostExternalReferencesCommand.id,{unitId:this._base.getId(),references:e.externalReferences});return t||console.warn(`[Base Field Facade]: Failed to bind External References.`),t}};_=g([h(3,l.ICommandService),h(4,l.IPermissionService)],_);let v=/* @__PURE__ */ function(e){return e.Id=`id`,e.Name=`name`,e.Auto=`auto`,e}({});function y(e){return!!(e&&e.system!==!0&&e.type!==l.BaseFieldType.RecordId)}function b(e,t,n=`id`){if(!t)return{};let r={};return Object.entries(t).forEach(([t,i])=>{let a=S(e,t,n);r[a]=x(e.fields[a],i)}),r}function x(e,t){if((e==null?void 0:e.type)!==l.BaseFieldType.Attachment||t==null)return t;if(!Array.isArray(t))throw TypeError(`Invalid attachment value for field "${e.name}": expected an array.`);return t.map((t,n)=>C(e,t,n))}function S(e,t,n){if(n===`id`||n===`auto`&&e.fields[t])return t;let r=Object.values(e.fields).filter(e=>e.name===t);if(r.length===1)return r[0].id;throw r.length>1?Error(`Duplicate Base field name: ${t}`):Error(`Base field not found: ${t}`)}function C(e,t,n){let r=`Invalid attachment at index ${n} for field "${e.name}"`;if(!O(t))throw TypeError(`${r}: expected an object.`);if(`url`in t)throw TypeError(`${r}: "url" is not supported; use "source".`);if(`type`in t)throw TypeError(`${r}: "type" is not supported; use "mimeType".`);let i=T(t.id,r,`id`),a=T(t.name,r,`name`),o=T(t.source,r,`source`);return{id:i,name:a,source:o,sourceType:w(t.sourceType,o,r),...E(t,`mimeType`,r),...D(t,`size`,r),...D(t,`width`,r),...D(t,`height`,r),...E(t,`thumbnail`,r)}}function w(e,t,n){if(e==null)return t.startsWith(`data:`)?l.ImageSourceType.BASE64:l.ImageSourceType.URL;if(e===l.ImageSourceType.URL||e===l.ImageSourceType.UUID||e===l.ImageSourceType.BASE64)return e;throw TypeError(`${n}: "sourceType" must be URL, UUID, or BASE64.`)}function T(e,t,n){if(typeof e!=`string`||!e.trim())throw TypeError(`${t}: "${n}" must be a non-empty string.`);return e}function E(e,t,n){let r=e[t];if(r==null)return{};if(typeof r!=`string`||!r.trim())throw TypeError(`${n}: "${t}" must be a non-empty string when provided.`);return{[t]:r}}function D(e,t,n){let r=e[t];if(r==null)return{};if(typeof r!=`number`||!Number.isFinite(r)||r<0)throw TypeError(`${n}: "${t}" must be a non-negative finite number when provided.`);return{[t]:r}}function O(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var k;let A=k=class{constructor(e,t,n,r,i){this._base=e,this._table=t,this._range=n,this._inject=r,this._commandService=i,this._assertInBounds()}getBaseId(){return this._base.getId()}getTableId(){return this._table.getId()}getRange(){return{...this._range}}getRow(){return this._range.startRow}getColumn(){return this._range.startColumn}getNumRows(){return this._range.endRow-this._range.startRow+1}getNumColumns(){return this._range.endColumn-this._range.startColumn+1}getValues(){let e=this._getTable(),t=this._getFieldIds(e),n=[];for(let i=this._range.startRow;i<=this._range.endRow;i++){var r;let a=(r=e.rowId)==null?void 0:r[i],o=[];for(let n=this._range.startColumn;n<=this._range.endColumn;n++){let r=t[n];o.push(a&&r?(0,c.getBaseCellValue)(e,a,r):null)}n.push(o)}return n}getValue(){var e;return((e=this.getValues()[0])==null?void 0:e[0])??null}setValue(e){return this.setValues([[e]])}setValues(e){let t=this.getNumRows(),n=this.getNumColumns();if(e.length>t||e.some(e=>e.length>n)){var r;throw Error(`[FBaseRange]: values size ${e.length}x${((r=e[0])==null?void 0:r.length)??0} exceeds range size ${t}x${n}.`)}let i=this._getTable(),a=this._getFieldIds(i),o=e.flatMap((e,t)=>e.map((e,n)=>{var r;let o=this._range.startRow+t,s=a[this._range.startColumn+n],c=(r=i.rowId)==null?void 0:r[o];if(!s||!c)throw Error(`[FBaseRange]: cannot resolve the public Base range address.`);return{recordId:c,fieldId:s,value:e}}));return this._commandService.syncExecuteCommand(c.SetBaseRangeValuesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),patches:o,source:c.BaseEventSource.Facade})}clear(){return this.setValues(Array.from({length:this.getNumRows()},()=>Array.from({length:this.getNumColumns()},()=>null)))}offset(e,t,n=this.getNumRows(),r=this.getNumColumns()){return this._inject.createInstance(k,this._base,this._table,{startRow:this._range.startRow+e,startColumn:this._range.startColumn+t,endRow:this._range.startRow+e+n-1,endColumn:this._range.startColumn+t+r-1},this._inject)}_getTable(){let e=this._table.getTable();if(!e)throw Error(`[FBaseRange]: table does not exist.`);return(0,c.ensureBaseTableCellLayout)(e)}_assertInBounds(){var e;let t=this._getTable(),n=((e=t.recordOrder)==null?void 0:e.length)??0,r=this._getFieldIds(t).length;if(this._range.startRow<0||this._range.startColumn<0||this._range.endRow<this._range.startRow||this._range.endColumn<this._range.startColumn||this._range.endRow>=Math.max(n,1)||this._range.endColumn>=Math.max(r,1))throw Error(`[FBaseRange]: range is out of bounds. Max rows: ${n}, max columns: ${r}, range: ${JSON.stringify(this._range)}.`)}_getFieldIds(e){return e.fieldOrder.filter(t=>y(e.fields[t]))}};A=k=g([h(4,l.ICommandService)],A);function j(e){"@babel/helpers - typeof";return j=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},j(e)}function M(e,t){if(j(e)!=`object`||!e)return e;var n;if(typeof Symbol<`u`&&(n=e[Symbol.toPrimitive])!==void 0){var r=n.call(e,t||`default`);if(j(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function N(e){var t=M(e,`string`);return j(t)==`symbol`?t:t+``}function P(e,t,n){return(t=N(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var F;let I=F=class extends u.FBaseInitialable{constructor(e,t,n,r,i,a){super(r),this._base=e,this._table=t,this._recordId=n,this._injector=r,this._commandService=i,this._permissionService=a,P(this,`_baseUnitId`,void 0),P(this,`_baseTableId`,void 0),this._baseUnitId=e.getId(),this._baseTableId=t.getId()}getBaseFacade(){return this._base}getTableFacade(){return this._table}getId(){return this._recordId}getPermission(){let e=this._table.getId();return new m(this._base.getId(),(0,c.getBaseRecordPermissionObjectId)(e,this._recordId),[(0,c.getBaseTablePermissionObjectId)(e)],this._commandService,this._permissionService)}getRecord(){return{...this._getRecord(),values:this.getValues()}}getValue(e){return y(this._table.getTable().fields[e])?this._getRecord().values[e]??null:null}getValues(){let e=this._table.getTable();return Object.fromEntries(Object.entries(this._getRecord().values).filter(([t])=>y(e.fields[t])))}setValue(e,t){let n=this._table.getTable().fields[e];return this._commandService.syncExecuteCommand(c.UpdateBaseCellCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,fieldId:e,value:x(n,t),source:c.BaseEventSource.Facade})}setAttachments(e,t){return this.setValue(e,t.map(e=>({...e})))}getAttachments(e){this._getAttachmentField(e);let t=this.getValue(e);return Array.isArray(t)?t.map((t,n)=>R(t,e,n)):[]}deleteAttachments(e,t){this._getAttachmentField(e);let n=new Set(t.map(e=>e.id));if(!n.size)return!0;let r=this.getAttachments(e),i=r.filter(e=>!n.has(e.id));return i.length===r.length||this.setAttachments(e,i)}setValues(e,t=`id`){let n=this._table.getTable(),r=[{recordId:this._recordId,values:b(n,e,t)}];return this._commandService.syncExecuteCommand(c.SetBaseRecordValuesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),patches:r,source:c.BaseEventSource.Facade})}delete(){return this._commandService.syncExecuteCommand(c.DeleteBaseRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,source:c.BaseEventSource.Facade})}duplicate(e){let t={...this._getRecord(),...e,id:(0,l.generateRandomId)(6)};t.values={...t.values,...e==null?void 0:e.values},Reflect.deleteProperty(t.values,l.BASE_RECORD_ID_FIELD_ID);let n=Date.now();if(t.orderKey||=`${n}`,t.createdAt||=n,t.updatedAt||=n,!this._commandService.syncExecuteCommand(c.DuplicateBaseRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),sourceRecordId:this._recordId,record:t,source:c.BaseEventSource.Facade}))throw Error(`[FRecord]: failed to duplicate record "${this._recordId}".`);return this._injector.createInstance(F,this._base,this._table,t.id,this._injector)}setOrderKey(e){return this._commandService.syncExecuteCommand(c.UpdateBaseRecordOrderCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,orderKey:e})}getLinkedRecordIds(e){let t=this._getRecordLinkField(e),n=this.getValue(t.id);return(0,c.parseRecordLinkIds)(n)}setLinkedRecordIds(e,t){let n=this._getRecordLinkField(e),r=(0,c.serializeRecordLinkIds)(t),i=(0,c.validateRecordLinkValue)(this._base.getBase().getSnapshot(),n,r);if(!i.valid)throw Error(i.reason??`[FRecord]: invalid RecordLink value.`);return this._commandService.syncExecuteCommand(c.UpdateBaseCellCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),recordId:this._recordId,fieldId:e,value:r,source:c.BaseEventSource.Facade})}addLinkedRecord(e,t){let n=this._getRecordLinkField(e),r=(0,c.getRecordLinkFieldConfig)(n);if(!r)throw Error(`[FRecord]: RecordLink field "${e}" has invalid config.`);let i=this.getLinkedRecordIds(e);return r.multiple&&i.includes(t)?!0:this.setLinkedRecordIds(e,r.multiple?[...i,t]:[t])}removeLinkedRecord(e,t){let n=this.getLinkedRecordIds(e);return!n.includes(t)||this.setLinkedRecordIds(e,n.filter(e=>e!==t))}getParent(e){let t=this._getHierarchyIndex(e).parentByRecordId.get(this._recordId)??null;return t?this._table.getRecordById(t):null}getChildren(e){return(this._getHierarchyIndex(e).childrenByParentId.get(this._recordId)??[]).flatMap(e=>{let t=this._table.getRecordById(e);return t?[t]:[]})}getAncestors(e){let t=this._getHierarchyIndex(e),n=[],r=t.parentByRecordId.get(this._recordId)??null;for(;r;){let e=this._table.getRecordById(r);e&&n.push(e),r=t.parentByRecordId.get(r)??null}return n}getDescendants(e){let t=this._getHierarchyIndex(e),n=t.orderedRecordIds.indexOf(this._recordId),r=t.subtreeHeightByRecordId.has(this._recordId)?this._collectDescendantIds(t.childrenByParentId,this._recordId):[];return n<0?[]:r.flatMap(e=>{let t=this._table.getRecordById(e);return t?[t]:[]})}setParent(e,t,n){return this._commandService.syncExecuteCommand(c.MoveBaseHierarchyRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:e,recordId:this._recordId,parentRecordId:t,orderKey:n,source:c.BaseEventSource.Facade})}addChild(e,t,n=`id`,r){let i=this._table.getTable(),a=Date.now(),o={...r,id:(0,l.generateRandomId)(6),values:b(i,t,n),orderKey:(r==null?void 0:r.orderKey)||`${a}`,createdAt:(r==null?void 0:r.createdAt)||a,updatedAt:(r==null?void 0:r.updatedAt)||a};if(!this._commandService.syncExecuteCommand(c.CreateBaseChildRecordCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),fieldId:e,parentRecordId:this._recordId,record:o,source:c.BaseEventSource.Facade}))throw Error(`[FRecord]: failed to create child under "${this._recordId}".`);return this._injector.createInstance(F,this._base,this._table,o.id,this._injector)}_getHierarchyIndex(e){return(0,c.buildBaseHierarchyIndex)(this._table.getTable(),e)}_collectDescendantIds(e,t){let n=[],r=t=>{for(let i of e.get(t)??[])n.push(i),r(i)};return r(t),n}_getRecord(){let e=this._table.getTable().records[this._recordId];if(!e)throw Error(`[FRecord]: record "${this._recordId}" does not exist.`);return e}_getRecordLinkField(e){let t=this._table.getTable().fields[e];if(!t||t.type!==l.BaseFieldType.RecordLink)throw Error(`[FRecord]: field "${e}" is not a RecordLink field.`);return t}_getAttachmentField(e){let t=this._table.getTable().fields[e];if(!t||t.type!==l.BaseFieldType.Attachment)throw Error(`[FRecord]: field "${e}" is not an Attachment field.`);return t}};I=F=g([h(4,l.ICommandService),h(5,l.IPermissionService)],I);function L(e){return!!(e&&typeof e==`object`&&`id`in e&&typeof e.id==`string`&&`name`in e&&typeof e.name==`string`)}function R(e,t,n){if(!L(e))throw Error(`[FRecord]: attachment at index ${n} in field "${t}" is invalid.`);return{...e}}let z=class{constructor(e,t,n,r,i,a,o){this._base=e,this._table=t,this._viewId=n,this._injector=r,this._commandService=i,this._permissionService=a,this._projectionService=o}getId(){return this._viewId}getPermission(){let e=this._table.getId();return new m(this._base.getId(),(0,c.getBaseViewPermissionObjectId)(e,this._viewId),[(0,c.getBaseTablePermissionObjectId)(e)],this._commandService,this._permissionService)}getView(){return this._getView()}getName(){return this._getView().name}getType(){return this._getView().type}setName(e){return this._commandService.syncExecuteCommand(c.RenameBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,name:e})}getConfig(){let e=this.getType(),t=this._getView().config;switch(e){case l.BaseViewType.Grid:return t;case l.BaseViewType.Kanban:return t;case l.BaseViewType.Calendar:return t;case l.BaseViewType.Gantt:return t;case l.BaseViewType.Gallery:return t;default:return t}}updateConfig(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConfigCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,patch:e})}getConditionalColorRules(){var e;return l.Tools.deepClone(((e=this._getView().config.conditionalColoring)==null?void 0:e.rules)??[])}setConditionalColorRules(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Set,rules:e})}addConditionalColorRule(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Add,rule:e})}deleteConditionalColorRule(e){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Delete,ruleId:e})}clearConditionalColorRules(){return this._commandService.syncExecuteCommand(c.UpdateBaseViewConditionalColorRulesCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,type:c.BaseConditionalColorRuleUpdateType.Clear})}getFilter(){return this._getView().filter??null}setFilter(e){return this._commandService.syncExecuteCommand(c.SetBaseViewFilterCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,filter:e})}getSort(){return this._getView().sort??[]}setSort(e){return this._commandService.syncExecuteCommand(c.SetBaseViewSortCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,sort:e})}getGroup(){return this._getView().group??[]}setGroup(e){return this._commandService.syncExecuteCommand(c.SetBaseViewGroupCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,group:e})}getFieldSettings(e){var t;return y(this._table.getTable().fields[e])?((t=this._getView().fieldSettings)==null?void 0:t[e])??{}:{}}getVisibleFields(){let e=this._table.getTable(),t=this._getView();return(t.fieldOrder??e.fieldOrder).filter(n=>{var r;let i=e.fields[n];return y(i)&&!((r=t.fieldSettings)!=null&&(r=r[n])!=null&&r.hidden)}).map(e=>this._injector.createInstance(_,this._base,this._table,e))}setFieldVisible(e,t){return y(this._table.getTable().fields[e])?this._commandService.syncExecuteCommand(c.SetBaseViewFieldVisibleCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,fieldId:e,visible:t}):!1}setFieldWidth(e,t){return y(this._table.getTable().fields[e])?this._commandService.syncExecuteCommand(c.SetBaseViewFieldWidthCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,fieldId:e,width:t}):!1}moveField(e,t){let n=this._table.getTable(),r=t.beforeFieldId??t.afterFieldId;return!y(n.fields[e])||!r||!y(n.fields[r])?!1:this._commandService.syncExecuteCommand(c.SetBaseViewFieldOrderCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,fieldId:e,target:t})}move(e){return this._commandService.syncExecuteCommand(c.MoveBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId,target:e})}delete(){return this._commandService.syncExecuteCommand(c.DeleteBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._table.getId(),viewId:this._viewId})}getProjection(){return this._projectionService.getProjection(this._base.getBase().getSnapshot(),this._table.getId(),this._viewId)}_getView(){let e=this._table.getTable().views[this._viewId];if(!e)throw Error(`[FView]: view "${this._viewId}" does not exist.`);return e}};z=g([h(4,l.ICommandService),h(5,l.IPermissionService),h(6,c.IBaseProjectionService)],z);let B=class{constructor(e,t,n,r,i,a){this._base=e,this._tableId=t,this._injector=n,this._commandService=r,this._permissionService=i,this._projectionService=a}getBase(){return this._base.getBase()}getTable(){return this._getTable()}getId(){return this._tableId}getPermission(){return new m(this.getBase().getUnitId(),(0,c.getBaseTablePermissionObjectId)(this._tableId),[],this._commandService,this._permissionService)}getHierarchyFieldId(){return(0,c.resolveBaseHierarchyFieldId)(this._getTable())}setHierarchyField(e){return this._commandService.syncExecuteCommand(c.SetBaseTableHierarchyFieldCommand.id,{unitId:this._base.getId(),tableId:this._tableId,fieldId:e})}getName(){return this._getTable().name}getFormulaName(){let e=this._base.getBase().getSnapshot();return(0,c.getBaseFormulaTableName)(this._getTable(),e)}setName(e){let t=(0,c.validateBaseTableName)(this._base.getBase().getSnapshot(),e,this._tableId);if(!t.valid)throw Error(`[FBaseTable]: invalid table name "${e}". ${c.BASE_TABLE_NAME_REQUIREMENTS} ${t.reason}`);return this._commandService.syncExecuteCommand(c.RenameBaseTableCommand.id,{unitId:this._base.getId(),tableId:this._tableId,name:e})}search(e,t){let n=this._base.getBase().getSnapshot(),r=this._getTable();if(t){let i=this._projectionService.getProjection(n,this._tableId,t),a=r.views[t],o=e.fieldIds??J(r,a,i),s=`rows`in i&&Array.isArray(i.rows)?i.rows:[];return(0,c.searchBaseTable)({...e,table:r,fieldIds:o,rows:s})}let i=(r.recordOrder?r.recordOrder.map(e=>r.records[e]):Object.values(r.records).sort((e,t)=>e.orderKey.localeCompare(t.orderKey))).filter(e=>e).map(e=>({recordId:e.id,values:e.values})),a=e.fieldIds??r.fieldOrder.filter(e=>y(r.fields[e]));return(0,c.searchBaseTable)({...e,table:r,fieldIds:a,rows:i})}getPrimaryFieldId(){return this._getTable().primaryFieldId}getFields(){let e=this._getTable();return e.fieldOrder.map(t=>e.fields[t]).filter(y).map(e=>this._injector.createInstance(_,this._base,this,e.id))}getFieldById(e){let t=this._getTable().fields[e];return y(t)?this._injector.createInstance(_,this._base,this,t.id):null}getFieldByName(e){let t=this._getTable().fields,n=Object.values(t).find(t=>y(t)&&t.name===e);return n?this._injector.createInstance(_,this._base,this,n.id):null}getPrimaryField(){let e=this._getTable().primaryFieldId;return this._injector.createInstance(_,this._base,this,e)}addField(e,t,n){var r,i;if(!Object.values(l.BaseFieldType).some(e=>e===t))throw Error(`Unsupported Base field type "${String(t)}".`);if(t===l.BaseFieldType.Formula&&this._prepareFormulaFieldReferences(e,n),t===l.BaseFieldType.RecordLink&&(typeof(n==null||(r=n.field)==null||(r=r.config)==null?void 0:r.targetTableId)!=`string`||typeof n.field.config.multiple!=`boolean`))throw Error(`RecordLink fields require config { targetTableId, multiple }.`);let a={...n==null?void 0:n.field,id:(0,l.generateRandomId)(6),name:e,type:t,config:(n==null||(i=n.field)==null?void 0:i.config)??{}};if(!this._commandService.syncExecuteCommand(c.CreateBaseFieldCommand.id,{unitId:this._base.getId(),tableId:this._tableId,field:a,index:n==null?void 0:n.index}))throw Error(`Failed to add field "${e}"`);return this._injector.createInstance(_,this._base,this,a.id)}_prepareFormulaFieldReferences(e,t){var n;if(!t||!(`externalReferences`in t)||!Array.isArray(t.externalReferences))throw Error(`Formula fields require options.externalReferences. Use [] only for a Host-local formula.`);let r=this._commandService.syncExecuteCommand(c.ValidateBaseFormulaCommand.id,{unitId:this._base.getId(),tableId:this._tableId,formula:String(((n=t.field)==null||(n=n.config)==null?void 0:n.formula)??``)});if(!r.valid)throw Error(r.reason??`Invalid Base formula.`);if(t.externalReferences.length>0&&!this._commandService.syncExecuteCommand(f.UpsertHostExternalReferencesCommand.id,{unitId:this._base.getId(),references:t.externalReferences}))throw Error(`Failed to bind External References for formula field "${e}"`)}getRecords(){return this._resolveRecordIds().map(e=>this._injector.createInstance(I,this._base,this,e,this._injector))}getRecordById(e){return this._getTable().records[e]?this._injector.createInstance(I,this._base,this,e,this._injector):null}queryRecords(e={}){let t=this._getTable(),n=this._resolveRecordIds(e),r=Math.max(0,e.offset??0),i=e.limit==null?null:Math.max(0,e.limit),a=H(n.map(e=>t.records[e]).filter(n=>W(n,t,e.filter)),t,e.sort);return{records:V(a,e).map(e=>this._injector.createInstance(I,this._base,this,e.id,this._injector)),total:a.length,offset:r,limit:i,hasMore:i!=null&&r+i<a.length}}addRecord(e,t=`id`,n){let r=this._getTable(),i=Date.now(),a={...n,id:(0,l.generateRandomId)(6),values:b(r,e,t),orderKey:(n==null?void 0:n.orderKey)||`${i}`,createdAt:(n==null?void 0:n.createdAt)||i,updatedAt:(n==null?void 0:n.updatedAt)||i};if(!this._commandService.syncExecuteCommand(c.CreateBaseRecordCommand.id,{unitId:this._base.getId(),tableId:this._tableId,record:a,source:c.BaseEventSource.Facade}))throw Error(`Failed to add record with id "${a.id}"`);return this._injector.createInstance(I,this._base,this,a.id,this._injector)}addRecords(e){if(!e.length)return[];let t=this._getTable(),n=Date.now(),r=e.map((e,r)=>{var i,a,o;return{...e.record,id:(0,l.generateRandomId)(6),values:b(t,e.values,e.fieldKey??`id`),orderKey:((i=e.record)==null?void 0:i.orderKey)||`${n+r}`,createdAt:((a=e.record)==null?void 0:a.createdAt)||n,updatedAt:((o=e.record)==null?void 0:o.updatedAt)||n}});if(!this._commandService.syncExecuteCommand(c.BatchCreateBaseRecordsCommand.id,{unitId:this._base.getId(),tableId:this._tableId,records:r,source:c.BaseEventSource.Facade}))throw Error(`Failed to add records`);return r.map(e=>this._injector.createInstance(I,this._base,this,e.id,this._injector))}deleteRecords(e){return!e.length||this._commandService.syncExecuteCommand(c.BatchDeleteBaseRecordsCommand.id,{unitId:this._base.getId(),tableId:this._tableId,recordIds:e,source:c.BaseEventSource.Facade})}getRange(e,t,n=1,r=1){return this._injector.createInstance(A,this._base,this,{startRow:e,endRow:e+n-1,startColumn:t,endColumn:t+r-1},this._injector)}getDataRange(){var e;let t=(0,c.ensureBaseTableCellLayout)(this._getTable()),n=((e=t.recordOrder)==null?void 0:e.length)??0,r=t.fieldOrder.filter(e=>y(t.fields[e])).length;return this.getRange(0,0,Math.max(n,1),Math.max(r,1))}getViews(){let e=this._getTable();return e.viewOrder.filter(t=>e.views[t]).map(e=>this._injector.createInstance(z,this._base,this,e,this._injector))}getViewById(e){return this._getTable().views[e]?this._injector.createInstance(z,this._base,this,e,this._injector):null}getViewByName(e){let t=this._getTable(),n=Object.values(t.views).find(t=>t.name===e);return n?this._injector.createInstance(z,this._base,this,n.id,this._injector):null}createView(e,t,n){var r,i,a,o;let s=this._getTable(),u=(n==null||(r=n.view)==null?void 0:r.fieldOrder)??s.fieldOrder,d=[l.BASE_RECORD_ID_FIELD_ID,...u.filter(e=>y(s.fields[e]))],f={...n==null?void 0:n.view,id:(0,l.generateRandomId)(6),name:e,type:t,tableId:this._tableId,config:(n==null||(i=n.view)==null?void 0:i.config)??{},fieldOrder:d,fieldSettings:{...n==null||(a=n.view)==null?void 0:a.fieldSettings,[l.BASE_RECORD_ID_FIELD_ID]:{...n==null||(o=n.view)==null||(o=o.fieldSettings)==null?void 0:o[l.BASE_RECORD_ID_FIELD_ID],hidden:!0}}};if(!this._commandService.syncExecuteCommand(c.CreateBaseViewCommand.id,{unitId:this._base.getId(),tableId:this._tableId,view:f,index:n==null?void 0:n.index}))throw Error(`Failed to create view "${e}"`);return this._injector.createInstance(z,this._base,this,f.id,this._injector)}getSchema(){let e=this._getTable(),t=e.fieldOrder.filter(t=>y(e.fields[t])),n=e.viewOrder.filter(t=>e.views[t]);return{id:e.id,name:e.name,formulaName:this.getFormulaName(),primaryFieldId:e.primaryFieldId,fieldIds:t,viewIds:n,recordCount:this._resolveRecordIds().length,fields:t.map(t=>{let n=e.fields[t];return{id:n.id,name:n.name,type:n.type,config:n.config,readonly:n.readonly,description:n.description}}),views:n.map(t=>{let n=e.views[t];return{id:n.id,name:n.name,type:n.type}})}}_getTable(){let e=this._base.getBase().getSnapshot().tables[this._tableId];if(!e)throw Error(`[FTable]: table "${this._tableId}" does not exist.`);return e}_resolveRecordIds(e={}){let t=this._base.getBase().getSnapshot(),n=this._getTable();if(e.viewId){let n=this._projectionService.getProjection(t,this._tableId,e.viewId);if(`rows`in n&&Array.isArray(n.rows))return n.rows.map(e=>e.recordId)}return(n.recordOrder?n.recordOrder.map(e=>n.records[e]):Object.values(n.records).sort((e,t)=>e.orderKey.localeCompare(t.orderKey))).filter(e=>e).map(e=>e.id)}};B=g([h(3,l.ICommandService),h(4,l.IPermissionService),h(5,c.IBaseProjectionService)],B);function V(e,t){let n=Math.max(0,t.offset??0);return t.limit==null?e.slice(n):e.slice(n,n+Math.max(0,t.limit))}function H(e,t,n=[]){return n.length?[...e].sort((e,r)=>{for(let a of n){var i;let n=a.direction===l.BaseSortDirection.DESC?-1:1,o=U(e.values[a.fieldId],r.values[a.fieldId],(i=t.fields[a.fieldId])==null?void 0:i.type);if(o!==0)return o*n}return String(e.orderKey??e.id).localeCompare(String(r.orderKey??r.id))}):e}function U(e,t,n){return e==null&&t==null?0:e==null?-1:t==null?1:typeof e==`number`&&typeof t==`number`?e-t:n===l.BaseFieldType.Date?Number(e)-Number(t):String(e).localeCompare(String(t))}function W(e,t,n){var r;if(!n||!((r=n.conditions)!=null&&r.length))return!0;let{conjunction:i=l.BaseFilterConjunction.OR,conditions:a}=n;return i===l.BaseFilterConjunction.AND&&a.length>1?a.every(n=>G(e,t,n)):a.some(n=>G(e,t,n))}function G(e,t,n){let r=e.values[n.fieldId],i=t.fields[n.fieldId];if(K(n)){let e=q(n).test(String(r??``));return n.operator===`matches`?e:!e}return!i||(0,c.matchesBaseCondition)(r,n.operator,n.value,i)}function K(e){return e.operator===`matches`||e.operator===`notMatches`}function q(e){let t=String(e.value??``);if(t.length>512)throw Error(`Base regex filter is too long. Maximum length is 512.`);try{return new RegExp(t,e.caseSensitive?void 0:`i`)}catch(e){throw Error(`Invalid Base regex filter: ${t}. ${e instanceof Error?e.message:String(e)}`)}}function J(e,t,n){if(n.type!==`invalid`&&n.type!==`custom`){var r;if(n.type===l.BaseViewType.Kanban){var i;let t=[((i=n.fields)==null||(i=i[0])==null?void 0:i.id)??e.primaryFieldId,...n.visibleCardFieldIds??[]];return Array.from(new Set(t.filter(t=>!!e.fields[t])))}if((r=n.fields)!=null&&r.length)return n.fields.map(e=>e.id).filter(n=>{var r;return!(!e.fields[n]||t!=null&&(r=t.fieldSettings)!=null&&(r=r[n])!=null&&r.hidden)})}return e.fieldOrder.filter(n=>{var r;return!(!e.fields[n]||t!=null&&(r=t.fieldSettings)!=null&&(r=r[n])!=null&&r.hidden)})}let Y=class extends u.FBase{constructor(e,t,n,r,i){super(),this._base=e,this._injector=t,this._resourceLoaderService=n,this._commandService=r,this._permissionService=i}getBase(){return this._base}getId(){return this._base.getUnitId()}getPermission(){return new p(this.getId(),this._commandService,this._permissionService)}save(){return this._resourceLoaderService.saveUnit(this.getId())??l.Tools.deepClone(this._base.getSnapshot())}getName(){return this._base.getSnapshot().name}setName(e){this._commandService.syncExecuteCommand(c.SetBaseNameCommand.id,{unitId:this.getId(),name:e})}getTables(){let e=this._base.getSnapshot();return e.tableOrder.map(t=>e.tables[t]).filter(e=>e).map(e=>this._injector.createInstance(B,this,e.id,this._injector))}getTableById(e){let t=this._base.getSnapshot().tables[e];return t?this._injector.createInstance(B,this,t.id,this._injector):null}getTableByName(e){let t=this._base.getSnapshot(),n=Object.values(t.tables).find(t=>t.name===e);return n?this._injector.createInstance(B,this,n.id,this._injector):null}insertTable(e,t){let n=(0,l.createDefaultBaseTableSnapshot)({id:(0,l.generateRandomId)(),name:e,...t==null?void 0:t.table,primaryFieldName:t==null?void 0:t.primaryFieldName}),r=l.Tools.commonExtend(n,(t==null?void 0:t.table)??{}),i=(0,c.validateBaseTableName)(this._base.getSnapshot(),r.name);if(!i.valid)throw Error(`[FBase]: invalid table name "${r.name}". ${c.BASE_TABLE_NAME_REQUIREMENTS} ${i.reason}`);if(!this._commandService.syncExecuteCommand(c.CreateBaseTableCommand.id,{unitId:this._base.getUnitId(),table:r,index:t==null?void 0:t.index}))throw Error(`Failed to create table "${e}".`);return this._injector.createInstance(B,this,r.id,this._injector)}deleteTable(e){let t=typeof e==`string`?e:e.getId();if(!this._commandService.syncExecuteCommand(c.DeleteBaseTableCommand.id,{unitId:this._base.getUnitId(),tableId:t}))throw Error(`Failed to delete table "${t}".`);return!0}duplicateTable(e,t){let n=this._base.getSnapshot(),r=typeof e==`string`?e:e.getId(),i=n.tables[r];if(!i)throw Error(`[FBase]: table "${r}" does not exist.`);let a=n.tableOrder.indexOf(r)+1,o=(0,l.generateRandomId)(),s=(0,c.copyBaseTableSnapshot)(i,{id:o,name:(0,c.createUniqueBaseTableName)(n,`${i.name} Copy`),includeRecords:(t==null?void 0:t.includeRecords)??!1,regenerateViewIds:(t==null?void 0:t.regenerateViewIds)??!1});if(!this._commandService.syncExecuteCommand(c.CreateBaseTableCommand.id,{unitId:this._base.getUnitId(),table:s,index:a}))throw Error(`Failed to duplicate table "${r}".`);return this._injector.createInstance(B,this,s.id,this._injector)}getSchema(){let e=this._base.getSnapshot();return{id:e.id,name:e.name,tables:this.getTables().map(e=>e.getSchema())}}};Y=g([h(1,(0,l.Inject)(l.Injector)),h(2,l.IResourceLoaderService),h(3,l.ICommandService),h(4,l.IPermissionService)],Y);var X=class extends u.FUniver{_initialize(){this._initBaseBeforeEvents(),this._initBaseAfterEvents()}createBase(e={},t){let n=this._univerInstanceService.createUnit(l.UniverInstanceType.UNIVER_BASE,e,t);return this._injector.createInstance(Y,n)}getActiveBase(){let e=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_BASE);return e?this._injector.createInstance(Y,e):null}getBase(e){let t=this._univerInstanceService.getUnit(e,l.UniverInstanceType.UNIVER_BASE);return t?this._injector.createInstance(Y,t):null}getBases(){return this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_BASE).map(e=>this._injector.createInstance(Y,e))}_initBaseAfterEvents(){this.disposeWithMe(this.registerEventHandler(this.Event.BaseHierarchyChanged,()=>this._commandService.onCommandExecuted((e,t)=>{var n;if(!Z(e,c.ApplyBaseJson1Mutation))return;let r=e.params;if(!((n=r.hierarchyChanges)!=null&&n.length))return;let i=this.getBase(r.unitId),a=i==null?void 0:i.getTableById(r.hierarchyChanges[0].tableId);if(!i||!a)return;let o={base:i,table:a,changes:r.hierarchyChanges,source:t!=null&&t.fromCollab?c.BaseEventSource.Remote:r.source??c.BaseEventSource.UI};this.fireEvent(this.Event.BaseHierarchyChanged,o)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseTableCommand.id)return;let{unitId:t,table:n,index:r}=e.params,i=this.getBase(t);if(!i)return;let a={base:i,table:n,index:r};this.fireEvent(this.Event.BaseTableCreated,a)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableFieldCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseFieldCommand.id)return;let{unitId:t,tableId:n,field:r,index:i,viewIndexes:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let l={base:o,table:s,field:r,index:i,viewIndexes:a};this.fireEvent(this.Event.BaseTableFieldCreated,l)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableRecordCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseRecordCommand.id&&e.id!==c.BatchCreateBaseRecordsCommand.id)return;let t=e.params,{unitId:n,tableId:r}=t,i=t.records??[t.record],a=this.getBase(n);if(!a)return;let o=a.getTableById(r);if(!o)return;let s={base:a,table:o,records:i};this.fireEvent(this.Event.BaseTableRecordCreated,s)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableViewCreated,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.CreateBaseViewCommand.id)return;let{unitId:t,tableId:n,view:r,index:i}=e.params,a=this.getBase(t);if(!a)return;let o=a.getTableById(n);if(!o)return;let s={base:a,table:o,view:r,index:i};this.fireEvent(this.Event.BaseTableViewCreated,s)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BaseTableCellValueChanged,()=>this._commandService.onCommandExecuted(e=>{if(e.id!==c.UpdateBaseCellCommand.id)return;let{unitId:t,tableId:n,recordId:r,fieldId:i,value:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let l=s.getFieldById(i);if(!l)return;let u=s.getRecordById(r);if(!u)return;let d={base:o,table:s,field:l,record:u,value:a};this.fireEvent(this.Event.BaseTableCellValueChanged,d)})))}_initBaseBeforeEvents(){this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseHierarchyChange,()=>this._commandService.beforeCommandExecuted(e=>{if(Z(e,c.SetBaseRecordValuesCommand)){let{unitId:t,tableId:n,patches:r,source:i=c.BaseEventSource.UI}=e.params,a=this._getHierarchyEventContext(t,n);if(!a)return;this._fireBeforeHierarchyChange(a.base,a.table,(0,c.validateBaseHierarchyRecordPatches)(a.table.getTable(),r),i);return}if(Z(e,c.SetBaseRangeValuesCommand)){let{unitId:t,tableId:n,patches:r,source:i=c.BaseEventSource.UI}=e.params,a=this._getHierarchyEventContext(t,n);if(!a)return;let o=a.table.getTable();this._fireBeforeHierarchyChange(a.base,a.table,(0,c.validateBaseHierarchyRecordPatches)(o,(0,c.resolveBaseRangeHierarchyPatches)(o,r)),i);return}if(Z(e,c.CreateBaseRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.validateBaseHierarchyRecordCreations)(n.table.getTable(),[t.record]),t.source??c.BaseEventSource.UI);return}if(Z(e,c.BatchCreateBaseRecordsCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.validateBaseHierarchyRecordCreations)(n.table.getTable(),t.records),t.source??c.BaseEventSource.UI);return}if(Z(e,c.DuplicateBaseRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.validateBaseHierarchyRecordCreations)(n.table.getTable(),[t.record]),t.source??c.BaseEventSource.UI);return}if(Z(e,c.MoveBaseHierarchyRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;let r=n.table.getTable(),i=t.fieldId??(0,c.resolveBaseHierarchyFieldId)(r),a=(0,c.buildBaseHierarchyIndex)(r,i).parentByRecordId.get(t.recordId)??null;this._fireBeforeHierarchyChange(n.base,n.table,[{tableId:t.tableId,fieldId:i,recordId:t.recordId,oldParentRecordId:a,parentRecordId:t.parentRecordId}],t.source??c.BaseEventSource.UI);return}if(Z(e,c.CreateBaseChildRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;let r=t.fieldId??(0,c.resolveBaseHierarchyFieldId)(n.table.getTable());this._fireBeforeHierarchyChange(n.base,n.table,[{tableId:t.tableId,fieldId:r,recordId:t.record.id,oldParentRecordId:null,parentRecordId:t.parentRecordId}],t.source??c.BaseEventSource.UI);return}if(Z(e,c.DeleteBaseRecordCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.getBaseHierarchyDeletePromotions)(n.table.getTable(),[t.recordId]),t.source??c.BaseEventSource.UI);return}if(Z(e,c.BatchDeleteBaseRecordsCommand)){let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;this._fireBeforeHierarchyChange(n.base,n.table,(0,c.getBaseHierarchyDeletePromotions)(n.table.getTable(),t.recordIds),t.source??c.BaseEventSource.UI);return}if(!Z(e,c.UpdateBaseCellCommand))return;let t=e.params,n=this._getHierarchyEventContext(t.unitId,t.tableId);if(!n)return;let r=n.table.getTable();if(!(0,c.getActiveBaseHierarchyFieldIds)(r).includes(t.fieldId))return;let i=(0,c.buildBaseHierarchyIndex)(r,t.fieldId).parentByRecordId.get(t.recordId)??null,a=(0,c.parseRecordLinkIds)(t.value)[0]??null;i!==a&&this._fireBeforeHierarchyChange(n.base,n.table,[{tableId:t.tableId,fieldId:t.fieldId,recordId:t.recordId,oldParentRecordId:i,parentRecordId:a}],t.source??c.BaseEventSource.UI)}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseTableCommand.id)return;let{unitId:t,table:n,index:r}=e.params,i=this.getBase(t);if(!i)return;let a={base:i,table:n,index:r};if(this.fireEvent(this.Event.BeforeBaseTableCreate,a),a.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableFieldCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseFieldCommand.id)return;let{unitId:t,tableId:n,field:r,index:i,viewIndexes:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let u={base:o,table:s,field:r,index:i,viewIndexes:a};if(this.fireEvent(this.Event.BeforeBaseTableFieldCreate,u),u.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableRecordCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseRecordCommand.id&&e.id!==c.BatchCreateBaseRecordsCommand.id)return;let t=e.params,{unitId:n,tableId:r}=t,i=t.records??[t.record],a=this.getBase(n);if(!a)return;let o=a.getTableById(r);if(!o)return;let s={base:a,table:o,records:i};if(this.fireEvent(this.Event.BeforeBaseTableRecordCreate,s),s.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableViewCreate,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.CreateBaseViewCommand.id)return;let{unitId:t,tableId:n,view:r,index:i}=e.params,a=this.getBase(t);if(!a)return;let o=a.getTableById(n);if(!o)return;let s={base:a,table:o,view:r,index:i};if(this.fireEvent(this.Event.BeforeBaseTableViewCreate,s),s.cancel)throw new l.CanceledError}))),this.disposeWithMe(this.registerEventHandler(this.Event.BeforeBaseTableCellValueChange,()=>this._commandService.beforeCommandExecuted(e=>{if(e.id!==c.UpdateBaseCellCommand.id)return;let{unitId:t,tableId:n,recordId:r,fieldId:i,value:a}=e.params,o=this.getBase(t);if(!o)return;let s=o.getTableById(n);if(!s)return;let u=s.getFieldById(i);if(!u)return;let d=s.getRecordById(r);if(!d)return;let f={base:o,table:s,field:u,record:d,value:a};if(this.fireEvent(this.Event.BeforeBaseTableCellValueChange,f),f.cancel)throw new l.CanceledError})))}_getHierarchyEventContext(e,t){let n=this.getBase(e),r=n==null?void 0:n.getTableById(t);return n&&r?{base:n,table:r}:null}_fireBeforeHierarchyChange(e,t,n,r){if(!n.length)return;let i={base:e,table:t,changes:n,source:r};if(this.fireEvent(this.Event.BeforeBaseHierarchyChange,i),i.cancel)throw new l.CanceledError}};function Z(e,t){return e.id===t.id&&e.params!==void 0}u.FUniver.extend(X);var Q=class extends u.FEnum{get BaseFieldType(){return l.BaseFieldType}get BaseFilterConjunction(){return l.BaseFilterConjunction}get BaseFilterOperator(){return l.BaseFilterOperator}get BaseFieldKeyEnum(){return v}get BaseViewType(){return l.BaseViewType}get BaseConditionalColorTarget(){return l.BaseConditionalColorTarget}get BaseConditionalColorOperator(){return l.BaseConditionalColorOperator}get BaseConditionalDateMode(){return l.BaseConditionalDateMode}get BaseSortDirection(){return l.BaseSortDirection}get BaseEventSource(){return c.BaseEventSource}get BaseHierarchyErrorCode(){return c.BaseHierarchyErrorCode}get BaseHierarchyInvalidReason(){return l.BaseHierarchyInvalidReason}get BaseRecordLinkRole(){return l.BaseRecordLinkRole}};u.FEnum.extend(Q);var $=class extends u.FEventName{get BaseTableCreated(){return`BaseTableCreated`}get BeforeBaseTableCreate(){return`BeforeBaseTableCreate`}get BaseTableFieldCreated(){return`BaseTableFieldCreated`}get BeforeBaseTableFieldCreate(){return`BeforeBaseTableFieldCreate`}get BaseTableRecordCreated(){return`BaseTableRecordCreated`}get BeforeBaseTableRecordCreate(){return`BeforeBaseTableRecordCreate`}get BaseTableViewCreated(){return`BaseTableViewCreated`}get BeforeBaseTableViewCreate(){return`BeforeBaseTableViewCreate`}get BaseTableCellValueChanged(){return`BaseTableCellValueChanged`}get BeforeBaseTableCellValueChange(){return`BeforeBaseTableCellValueChange`}get BaseHierarchyChanged(){return`BaseHierarchyChanged`}get BeforeBaseHierarchyChange(){return`BeforeBaseHierarchyChange`}};u.FEventName.extend($),exports.BaseFieldKeyEnum=v,Object.defineProperty(exports,"FBase",{enumerable:!0,get:function(){return Y}}),exports.FBaseObjectPermission=m,exports.FBasePermission=p,Object.defineProperty(exports,"FBaseTable",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"FBaseTableField",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"FBaseTableRange",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"FBaseTableRecord",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"FBaseTableView",{enumerable:!0,get:function(){return z}}),exports.FBasesEventNameMixin=$,exports.resolveBaseFieldKey=S,exports.resolveBaseFieldValues=b;
|