@evotecit/canopyx 0.3.6 → 0.3.8
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/CanopyX.Html/Assets/canopyx-calendar.js +4 -3
- package/CanopyX.Html/Assets/canopyx-changes.css +240 -0
- package/CanopyX.Html/Assets/canopyx-changes.js +224 -0
- package/CanopyX.Html/Assets/canopyx-detail-rows.js +2 -2
- package/CanopyX.Html/Assets/canopyx-filter-editor.js +2 -1
- package/CanopyX.Html/Assets/canopyx-formatting.js +7 -6
- package/CanopyX.Html/Assets/canopyx-grid-module.mjs +71 -44
- package/CanopyX.Html/Assets/canopyx-grid.css +24 -0
- package/CanopyX.Html/Assets/canopyx-grid.js +71 -44
- package/CanopyX.Html/Assets/canopyx-interactive.js +6 -6
- package/CanopyX.Html/Assets/canopyx-labels-de.js +76 -2
- package/CanopyX.Html/Assets/canopyx-labels-es.js +76 -2
- package/CanopyX.Html/Assets/canopyx-labels-fr.js +76 -2
- package/CanopyX.Html/Assets/canopyx-labels-it.js +76 -2
- package/CanopyX.Html/Assets/canopyx-labels-pl.js +76 -2
- package/CanopyX.Html/Assets/canopyx-live.js +4 -3
- package/CanopyX.Html/Assets/canopyx-matrix.css +16 -3
- package/CanopyX.Html/Assets/canopyx-matrix.js +22 -14
- package/CanopyX.Html/Assets/canopyx-module.mjs +6 -6
- package/CanopyX.Html/Assets/canopyx-reporting-module.mjs +73 -46
- package/CanopyX.Html/Assets/canopyx-reporting.css +24 -0
- package/CanopyX.Html/Assets/canopyx-reporting.js +73 -46
- package/CanopyX.Html/Assets/canopyx-tree-tools.js +7 -6
- package/CanopyX.Html/Assets/canopyx.js +6 -6
- package/JavaScript/changes.d.ts +252 -0
- package/JavaScript/grid.d.ts +15 -5
- package/JavaScript/locales/de.mjs +76 -2
- package/JavaScript/locales/es.mjs +76 -2
- package/JavaScript/locales/fr.mjs +76 -2
- package/JavaScript/locales/it.mjs +76 -2
- package/JavaScript/locales/pl.mjs +76 -2
- package/JavaScript/matrix.d.ts +2 -0
- package/JavaScript/protocol.d.ts +1 -1
- package/README.md +7 -2
- package/package.json +5 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(global){"use strict";const installed=new WeakSet();const part={version:"
|
|
1
|
+
(function(global){"use strict";const installed=new WeakSet();const part={version:"a27c818b731c22e3",install(context){if(installed.has(context.DataGrid.prototype))return;const{DataGrid,h,setText,fill,gridButton,gridIcon,gridQuery,gridResultShape,gridQueryRows,gridCompare,gridOrder,gridIdOrder,validateGridRows,validateGridPage,validateGridCursorPage,gridFreeze,requireIdentifier,checkDocument,cellValue,PROTOCOL,GRID_REPORTING,VIEW_MODES,inlineGridSource}=context;const LIVE_KEYS=new Set(["stableOrder","flash","batchMs","pollMs","load","announce","pauseWhenHidden"]);const LIVE_MAX_ROWS=100000;function liveOptions(view,options){const read=value=>{if(value===undefined||value===true||value===false)return{};if(!value||typeof value!=="object"||Array.isArray(value)||Object.keys(value).some(key=>!LIVE_KEYS.has(key)))
|
|
2
2
|
throw new Error("CanopyX: live takes stableOrder, flash, batchMs, pollMs, load, announce and pauseWhenHidden.");return value};const merged=options.live===false?{}:{...read(view.live),...read(options.live)},flash=merged.flash;const integer=(value,min,max)=>value===undefined||Number.isInteger(value)&&value>=min&&value<=max;if(["stableOrder","announce","pauseWhenHidden"].some(key=>merged[key]!==undefined&&typeof merged[key]!=="boolean")||
|
|
3
3
|
!(flash===undefined||typeof flash==="boolean"||flash&&typeof flash==="object"&&Object.keys(flash).every(key=>key==="durationMs")&&integer(flash.durationMs,100,10000))||
|
|
4
4
|
!integer(merged.batchMs,0,60000)||!(merged.pollMs===undefined||merged.pollMs===0||integer(merged.pollMs,250,86400000))||
|
|
@@ -68,8 +68,9 @@ this.lifetime.signal.addEventListener("abort",()=>{bar.remove();this.host.classL
|
|
|
68
68
|
const wasHidden=this.liveBar.hidden||this.liveBarCursor!==cursor;setText(this.liveBarText,cursor?this.labels.gridLiveNewData:this.labels.gridLiveOrderChanged);setText(this.liveBarButton,cursor?this.labels.gridLiveRefresh:this.labels.gridLiveResort);this.liveBarButton.title=cursor?"":this.labels.gridLiveOrderHint;this.liveBarCursor=cursor;if(this.liveBar.classList.contains("cx-live-float"))this.liveBar.style.top=this.grid.offsetTop+this.head.offsetHeight+6+"px";this.liveBar.hidden=false;if(wasHidden)this.liveNote(cursor?this.labels.gridLiveNewData:this.labels.gridLiveOrderChanged+". "+this.labels.gridLiveOrderHint)},liveFlash(changed){const duration=this.liveOpts?.flashMs;if(!duration||!changed.size)return;const now=performance.now(),flashes=this.liveFlashes||=new Map();for(const[id,columns]of changed){const existing=flashes.get(id),merged=columns==="*"||existing?.columns==="*"?"*":new Set([...(existing?.columns||[]),...columns]);if(merged!=="*"&&!merged.size)continue;flashes.set(id,{columns:merged,start:now,until:now+duration})}
|
|
69
69
|
clearTimeout(this.liveFlashTimer);this.liveFlashTimer=setTimeout(()=>this.liveFlashExpire(),duration+20);this.version++;this.scheduleRender()},liveFlashExpire(){if(this.destroyed||!this.liveFlashes)return;const now=performance.now();for(const[id,flash]of this.liveFlashes)if(flash.until<=now)this.liveFlashes.delete(id);if(this.liveFlashes.size)this.liveFlashTimer=setTimeout(()=>this.liveFlashExpire(),Math.max(20,Math.min(...[...this.liveFlashes.values()].map(flash=>flash.until))- now+20));this.version++;this.scheduleRender()},liveAnnounce(result){if(!this.liveOpts?.announce||!result.added.length&&!result.removed.length)return;const counts=this.liveCounts||={added:0,updated:0,removed:0};counts.added +=result.added.length;counts.updated +=result.updated.length;counts.removed +=result.removed.length;if(this.liveAnnounceTimer)return;if(!this.liveSpoke||performance.now()- this.liveSpoke>=LIVE_ANNOUNCE_MS){this.liveNote(this.liveCountText());this.liveCoolDown()}
|
|
70
70
|
else this.liveAnnounceTimer=setTimeout(()=>{this.liveAnnounceTimer=0;this.liveSay(this.liveCountText());this.liveCoolDown()},LIVE_ANNOUNCE_MS -(performance.now()- this.liveSpoke))},liveCountText(){const numbers=new Intl.NumberFormat(this.lang),counts=this.liveCounts;this.liveCounts=null;return counts?fill(this.labels.gridLiveChanged,{added:numbers.format(counts.added),updated:numbers.format(counts.updated),removed:numbers.format(counts.removed)}):""},liveCoolDown(){this.liveSpoke=performance.now();this.liveAnnounceTimer=setTimeout(()=>{this.liveAnnounceTimer=0;if(this.liveCounts&&!this.destroyed){this.liveSay(this.liveCountText());this.liveCoolDown()}},LIVE_ANNOUNCE_MS)}});const LIVE_FILL=DataGrid.prototype.fillRow;DataGrid.prototype.fillRow=function(element,row){LIVE_FILL.call(this,element,row);const flash=this.liveFlashes?.size&&!row.status&&row.key?this.liveFlashes.get(row.key):null,mark=flash?row.key+"@"+flash.start:null;if(element._cxFlash&&element._cxFlashMark===mark&&element._cxFlashLayout===element._layout)return;if(element._cxFlash){for(const cell of element._cxFlash){cell.classList.remove("cx-live-flash");cell.style.removeProperty("animation-delay")}element._cxFlash=null;element._cxFlashMark=null}
|
|
71
|
-
if(!flash||!element._cells)return;const now=performance.now();if(flash.until<=now)return;const marked=[];element._cells.forEach((slot,index)=>{const column=this.cols[index];if(!slot||!column||flash.columns!=="*"&&!flash.columns.has(column.id))return;slot.cell.classList.add("cx-live-flash");slot.cell.style.animationDelay=Math.round(flash.start-now)+ "ms";marked.push(slot.cell)});if(marked.length){element._cxFlash=marked;element._cxFlashMark=mark;element._cxFlashLayout=element._layout}};Object.assign(DataGrid.prototype,{startLive(){if(this.destroyed)throw new DOMException("Grid was destroyed.","AbortError");if(this.liveOpts)return;this.liveOpts=liveOptions(this.view,this.opts);this.liveQueue=new Map();this.liveWaiters=[];this.liveScheduled=new Set();if(this.liveOpts.flashMs)this.host.style.setProperty("--cx-live-flash-ms",this.liveOpts.flashMs+"ms");this.host.addEventListener("canopyx:query",()=>{if(this.liveOrder&&this.liveOrder.shape!==gridResultShape(this.acceptedQuery))this.liveOrder=null;this.livePending=null;this.liveMoved=false;this.liveSyncPrompt()},{signal:this.lifetime.signal});this.lifetime.signal.addEventListener("abort",()=>{clearTimeout(this.liveTimer);clearTimeout(this.liveFlashTimer);clearTimeout(this.liveAnnounceTimer);this.host.style.removeProperty("--cx-live-flash-ms");for(const waiter of this.liveWaiters.splice(0))waiter.reject(new DOMException("Grid was destroyed.","AbortError"))},{once:true});if(this.liveOpts.pollMs)this.livePoll({intervalMs:this.liveOpts.pollMs})},liveStatus(){const queued=new Set(this.liveQueue?.keys());for(const{change}of this.liveScheduled||[])if(change){for(const row of[...change.add,...change.update])queued.add(row.id);change.remove.forEach(id=>queued.add(id))}
|
|
72
|
-
return gridFreeze({orderChanged:!!(this.liveOrder?.dirty||this.livePending?.pages||this.livePending?.refresh||this.liveMoved),newData:!!this.livePending?.cursor,pending:queued.size,polling:!!this.livePoller?.active,revision:this.snapshot?.revision??null})},liveRun(task){return this.liveChain=(this.liveChain||Promise.resolve()).catch(()=>{}).then(async()=>{this.startLive();await this.liveSettle();return task()})},applyTransaction(input){return this.liveQueueChange(liveTransaction(this,input),"api")},addRows(rows){return this.applyTransaction({add:rows})},updateRows(rows){return this.applyTransaction({update:rows})},removeRows(ids){return this.applyTransaction({remove:ids})},async setRows(rows){if(!this.liveInline())throw new Error("CanopyX: setRows replaces inline rows; a hosted grid's rows change at its source, then refreshRows().");validateGridRows(rows,this.view.columns);const owned=liveCopy(rows);return this.liveQueueChange(null,"api",owned)},liveQueueChange(change,source,replacement){if(this.destroyed)return Promise.reject(new DOMException("Grid was destroyed.","AbortError"));this.startLive()
|
|
71
|
+
if(!flash||!element._cells)return;const now=performance.now();if(flash.until<=now)return;const marked=[];element._cells.forEach((slot,index)=>{const column=this.cols[index];if(!slot||!column||flash.columns!=="*"&&!flash.columns.has(column.id))return;slot.cell.classList.add("cx-live-flash");slot.cell.style.animationDelay=Math.round(flash.start-now)+ "ms";marked.push(slot.cell)});if(marked.length){element._cxFlash=marked;element._cxFlashMark=mark;element._cxFlashLayout=element._layout}};Object.assign(DataGrid.prototype,{startLive(){if(this.view.rowIdentity==="ordinal")throw new Error("CanopyX: ordinal row identity is snapshot-local; keyed live updates require stable row keys.");if(this.destroyed)throw new DOMException("Grid was destroyed.","AbortError");if(this.liveOpts)return;this.liveOpts=liveOptions(this.view,this.opts);this.liveQueue=new Map();this.liveWaiters=[];this.liveScheduled=new Set();if(this.liveOpts.flashMs)this.host.style.setProperty("--cx-live-flash-ms",this.liveOpts.flashMs+"ms");this.host.addEventListener("canopyx:query",()=>{if(this.liveOrder&&this.liveOrder.shape!==gridResultShape(this.acceptedQuery))this.liveOrder=null;this.livePending=null;this.liveMoved=false;this.liveSyncPrompt()},{signal:this.lifetime.signal});this.lifetime.signal.addEventListener("abort",()=>{clearTimeout(this.liveTimer);clearTimeout(this.liveFlashTimer);clearTimeout(this.liveAnnounceTimer);this.host.style.removeProperty("--cx-live-flash-ms");for(const waiter of this.liveWaiters.splice(0))waiter.reject(new DOMException("Grid was destroyed.","AbortError"))},{once:true});if(this.liveOpts.pollMs)this.livePoll({intervalMs:this.liveOpts.pollMs})},liveStatus(){const queued=new Set(this.liveQueue?.keys());for(const{change}of this.liveScheduled||[])if(change){for(const row of[...change.add,...change.update])queued.add(row.id);change.remove.forEach(id=>queued.add(id))}
|
|
72
|
+
return gridFreeze({orderChanged:!!(this.liveOrder?.dirty||this.livePending?.pages||this.livePending?.refresh||this.liveMoved),newData:!!this.livePending?.cursor,pending:queued.size,polling:!!this.livePoller?.active,revision:this.snapshot?.revision??null})},liveRun(task){return this.liveChain=(this.liveChain||Promise.resolve()).catch(()=>{}).then(async()=>{this.startLive();await this.liveSettle();return task()})},applyTransaction(input){return this.liveQueueChange(liveTransaction(this,input),"api")},addRows(rows){return this.applyTransaction({add:rows})},updateRows(rows){return this.applyTransaction({update:rows})},removeRows(ids){return this.applyTransaction({remove:ids})},async setRows(rows){if(!this.liveInline())throw new Error("CanopyX: setRows replaces inline rows; a hosted grid's rows change at its source, then refreshRows().");validateGridRows(rows,this.view.columns);const owned=liveCopy(rows);return this.liveQueueChange(null,"api",owned)},liveQueueChange(change,source,replacement){if(this.destroyed)return Promise.reject(new DOMException("Grid was destroyed.","AbortError"));try{this.startLive()}catch(error){return Promise.reject(error)}
|
|
73
|
+
if(this.view.source.kind==="inline"&&this.opts.source)
|
|
73
74
|
return Promise.reject(new Error("CanopyX: this grid's rows belong to its own source; change them through it (an enhanced grid's setData, addRows and removeRows)."));if(!this.liveInline()&&(change.add.length||change.remove.length))
|
|
74
75
|
return Promise.reject(new Error("CanopyX: rows of a hosted grid are added and removed at its source; call refreshRows() after."));const scheduled={change};this.liveScheduled.add(scheduled);let waiter;const promise=new Promise((resolve,reject)=>{waiter={resolve,reject}});this.liveRun(async()=>{if(replacement){await this.liveFlush().catch(()=>{});change=liveTransaction(this,liveDiff(replacement,this.liveRows()))}
|
|
75
76
|
this.liveScheduled.delete(scheduled);this.liveEnqueueChange(change,source,waiter)}).catch(error=>{this.liveScheduled.delete(scheduled);waiter.reject(error)});return promise},liveEnqueueChange(change,source,waiter){liveEnqueue(this.liveQueue,change);this.liveWaiters.push(waiter);this.liveSource=this.liveSource&&this.liveSource!==source?"api":source;if(!this.liveOpts.batchMs)this.flushTransactions().catch(()=>{});else if(!this.liveTimer)this.liveTimer=setTimeout(()=>this.flushTransactions().catch(()=>{}),this.liveOpts.batchMs)},flushTransactions(){clearTimeout(this.liveTimer);this.liveTimer=0;return this.liveRun(()=>this.liveFlush())},async liveFlush(){clearTimeout(this.liveTimer);this.liveTimer=0;const queue=this.liveQueue,waiters=this.liveWaiters.splice(0),source=this.liveSource||"api";this.liveQueue=new Map();this.liveSource=null;try{const result=queue.size?await this.liveApply(queue,source):liveResult();waiters.forEach(waiter=>waiter.resolve(result));return result}catch(error){waiters.forEach(waiter=>waiter.reject(error));throw error}},async liveSettle(){if(!this.acceptedQuery&&!this.pendingQuery)await this.ready.catch(()=>{});while(!this.destroyed&&this.pendingQuery)await new Promise(resolve=>setTimeout(resolve,16));if(this.destroyed)throw new DOMException("Grid was destroyed.","AbortError");if(!this.acceptedQuery)throw new Error("CanopyX: live changes need an accepted query.");if(this.view.rowData&&this.liveInline()){await this.source.decoded;delete this.view.rowData;this.source=inlineGridSource(this.view)}},liveInlinePages(order){const rows=this.liveRows(),size=this.pageSize;return(anchor,focus)=>{const span=Math.ceil((this.grid.clientHeight||600)/ this.rowH) + 30, offsets = new Set();
|
|
@@ -140,11 +140,24 @@ border:var(--cx-size-1px) solid var(--cx-line-strong);border-radius:var(--cx-rad
|
|
|
140
140
|
.cx-matrix .cx-mx-bar,.cx-matrix .cx-mx-scroll,.cx-matrix .cx-mx-cards,.cx-matrix .cx-mx-tip{display:none !important;}
|
|
141
141
|
.cx-matrix .cx-mx-print{display:block;}
|
|
142
142
|
.cx-matrix-host{max-height:none !important;}
|
|
143
|
-
.cx-mx-printtable{border-collapse:collapse;font-size:var(--cx-size-11px);}
|
|
143
|
+
.cx-mx-printtable{border-collapse:collapse;font-size:var(--cx-size-11px);-webkit-print-color-adjust:exact;print-color-adjust:exact;}
|
|
144
144
|
.cx-mx-printtable :is(th,td){border:var(--cx-size-1px) solid var(--cx-line);padding:var(--cx-size-2px) var(--cx-size-4px);text-align:center;}
|
|
145
|
-
.cx-mx-printtable th
|
|
145
|
+
.cx-mx-printtable thead th{background:var(--cx-head-bg);}
|
|
146
|
+
.cx-mx-printtable :is(th[scope="row"],th[scope="rowgroup"]){text-align:start;}
|
|
146
147
|
.cx-mx-printtable caption{text-align:start;font-weight:600;padding-bottom:var(--cx-size-6px);}
|
|
147
|
-
.cx-mx-
|
|
148
|
+
.cx-mx-printgroup > th,.cx-mx-printgroup > td,.cx-mx-printrolled > th{background:var(--cx-head-bg);font-weight:600;}
|
|
149
|
+
.cx-mx-printcount{font-weight:400;color:var(--cx-muted);}
|
|
150
|
+
.cx-mx-printmember{padding-inline-start:var(--cx-size-16px) !important;font-weight:400;}
|
|
151
|
+
.cx-mx-printcell{color:var(--cx-muted);}
|
|
152
|
+
.cx-mx-printcell.cx-tone-danger{color:var(--cx-tone-danger);}
|
|
153
|
+
.cx-mx-printcell.cx-tone-warning{color:var(--cx-tone-warning);}
|
|
154
|
+
.cx-mx-printcell.cx-tone-info{color:var(--cx-tone-info);}
|
|
155
|
+
.cx-mx-printcell.cx-tone-success{color:var(--cx-quiet);}
|
|
156
|
+
.cx-mx-printcell.cx-toned{color:var(--cx-t);}
|
|
157
|
+
.cx-mx-printcell.cx-mx-attn{background:var(--mx-bg,var(--cx-hover-bg));font-weight:700;}
|
|
158
|
+
.cx-mx-printcell.cx-mx-attn.cx-tone-success{color:var(--cx-tone-success);}
|
|
159
|
+
.cx-mx-printnone{color:var(--mx-none);}
|
|
160
|
+
.cx-mx-printself{background:var(--cx-hover-bg);}
|
|
148
161
|
}
|
|
149
162
|
@media (forced-colors:active){
|
|
150
163
|
.cx-mx-cell.cx-mx-attn{border:var(--cx-size-1px) solid CanvasText;}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(global){"use strict";const installed=new WeakSet();const part={version:"
|
|
1
|
+
(function(global){"use strict";const installed=new WeakSet();const part={version:"16ab7faa98c96b46",install(context){if(installed.has(context.MATRIX_IMPL))return;const{MATRIX_IMPL,h,setText,fill,plural,foldText,numberFormat,gridFreeze,toneOf,applyTone,toneColors,AxisWindow,PROTOCOL}=context;const MATRIX_LABELS={matrixRows:"Rows",matrixColumns:"Columns",matrixSearch:"Find rows and columns",matrixSortBy:"Sort by",matrixGroupBy:"Group by",matrixByLabel:"Name",matrixByTotal:"Total",matrixAsListed:"As listed",matrixNoGrouping:"No groups",matrixDescending:"Descending",matrixOnlyProblems:"Only problems",matrixHideEmpty:"Hide empty rows and columns",matrixSize:"{rows} × {columns}",matrixShown:"Rows: {rows} of {totalRows}, columns: {columns} of {totalColumns}",matrixAttention:"Need attention: {count}",matrixLegend:"States",matrixFilter:"Filter",matrixClearFilters:"Clear filters",matrixNoMatches:"No rows or columns match.",matrixSelf:"Same item",matrixNoData:"No data",matrixCell:"{row} and {column}: {state}",matrixTotal:"Total",matrixItemTotal:"{item}: {count}",matrixExpandGroup:"Expand {group}",matrixCollapseGroup:"Collapse {group}",matrixGroupCount:"{count}",matrixCellCount:"Cells: {count}",matrixDetails:"Details",matrixClose:"Close",matrixValue:"Value",matrixState:"State",matrixAllClear:"Nothing needs attention",matrixShowMore:"Show more"};function matrixLabels(...sources){const labels={...MATRIX_LABELS};for(const source of sources){if(source==null)continue;if(typeof source!=="object"||Array.isArray(source))matrixFail("labels must be an object of strings");for(const[name,text]of Object.entries(source)){if(!Object.hasOwn(labels,name)){if(/^matrix[A-Z]/.test(name)) matrixFail("there is no matrix label '" + name + "'"); continue; }
|
|
2
2
|
if(typeof text!=="string"||!/\S/.test(text)) matrixFail("label '" + name + "' must be a string with visible text");
|
|
3
3
|
labels[name]=text}}
|
|
4
4
|
return Object.freeze(labels)}
|
|
@@ -16,12 +16,14 @@ function matrixHref(value){if(typeof value!=="string"||!value.length||value.leng
|
|
|
16
16
|
const colon=value.indexOf(":"),boundary=value.search(/[/?#]/);
|
|
17
17
|
return colon<0||boundary>=0&&boundary<colon||/^(?:https?|mailto)$/i.test(value.slice(0, colon));
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function matrixPluralText(text){if(!text.startsWith("["))return text.includes("{count}");const forms=[...text.matchAll(/\[(zero|one|two|few|many|other)\]([^[]*)/g)];
|
|
20
|
+
return forms.reduce((sum,form)=>sum+form[0].length,0)===text.length&&forms.some(form=>form[1]==="other")&&forms.every(form=>form[2].includes("{count}"))}
|
|
21
|
+
function matrixAxis(input,what){const axis=matrixKeys(input,["title","noun","groupCount","attributes","items","groupBy","sort"],what);const attributes=[],byId=new Map();if(axis.attributes!==undefined&&(!Array.isArray(axis.attributes)||axis.attributes.length>32))matrixFail(what+" has at most 32 attributes");for(const entry of axis.attributes||[]){const attribute=matrixKeys(entry,["id","title","kind","facet"],what+" attribute");const id=matrixId(attribute.id,"an attribute id");if(id[0]==="#"||byId.has(id))matrixFail("the attribute '"+id+"' must be unique and not start with #");const kind=attribute.kind===undefined?"text":attribute.kind;if(!["text","number","datetime"].includes(kind)||attribute.facet!==undefined&&typeof attribute.facet!=="boolean")matrixFail("the attribute '"+id+"' has an unknown kind or facet");const item=Object.freeze({id,title:matrixText(attribute.title,"the title of attribute '"+id+"'",200),kind,facet:attribute.facet===true});attributes.push(item);byId.set(id,item)}
|
|
20
22
|
if(!Array.isArray(axis.items)||!axis.items.length||axis.items.length>10000)matrixFail(what+" needs 1 to 10000 items");const ids=new Map(),items=axis.items.map((entry,index)=>{const item=matrixKeys(entry,["id","label","secondary","href","values"],what+" item");const id=matrixId(item.id,"an item id");if(ids.has(id))matrixFail("the item '"+id+"' appears twice on "+what);if(item.href!==undefined&&!matrixHref(item.href))matrixFail("the link of '"+id+"' is not an http, https, mailto or relative address");const values=Object.create(null);if(item.values!==undefined){if(!matrixObject(item.values))matrixFail("the values of '"+id+"' must be an object");for(const[key,raw]of Object.entries(item.values)){const attribute=byId.get(key);if(!attribute)matrixFail("'"+id+"' has a value for the undeclared attribute '"+key+"'");const cell=matrixObject(raw)?matrixKeys(raw,["value","text"],"a value"):{value:raw};const value=cell.value??null;const fits=value===null||(attribute.kind==="number"?typeof value==="number"&&Number.isFinite(value):attribute.kind==="datetime"?
|
|
21
23
|
typeof value==="string"&&/^\d{4}-\d\d-\d\d(?:T\d\d:\d\d(?::\d\d(?:\.\d{1,7})?)?(?:Z|[+-]\d\d:\d\d)?)?$/.test(value) && Number.isFinite(matrixMoment(value)) : typeof value === "string" || typeof value === "boolean");
|
|
22
24
|
if(!fits||cell.text!==undefined&&typeof cell.text!=="string")matrixFail("the value of '"+key+"' of '"+id+"' does not fit its kind");values[key]={value,text:cell.text??null}}}
|
|
23
25
|
const result=Object.freeze({id,index,label:matrixText(item.label,"the label of '"+id+"'",200),secondary:matrixText(item.secondary,"the secondary text of '"+id+"'",200,true),href:item.href??null,values:Object.freeze(values)});ids.set(id,result);return result});if(axis.groupBy!==undefined&&!byId.has(axis.groupBy))matrixFail(what+" groups by an undeclared attribute");let sort=null;if(axis.sort!==undefined){const value=matrixKeys(axis.sort,["by","direction"],what+" sort");if(!["#label","#total"].includes(value.by)&&!byId.has(value.by)||![undefined,"asc","desc"].includes(value.direction))matrixFail(what+" sorts by an unknown key");sort={by:value.by,direction:value.direction||"asc"}}
|
|
24
|
-
if(axis.noun!==undefined)matrixText(axis.noun,what+" noun",64);return Object.freeze({title:matrixText(axis.title,what+" title",200,true),noun:axis.noun??null,attributes:Object.freeze(attributes),attributeById:byId,items:Object.freeze(items),byId:ids,groupBy:axis.groupBy??null,sort})}
|
|
26
|
+
if(axis.noun!==undefined)matrixText(axis.noun,what+" noun",64);const groupCount=matrixText(axis.groupCount,what+" group count",200,true);if(groupCount!==null&&!matrixPluralText(groupCount))matrixFail(what+" group count needs {count} in every form, and plural forms that end with [other]");return Object.freeze({title:matrixText(axis.title,what+" title",200,true),noun:axis.noun??null,groupCount,attributes:Object.freeze(attributes),attributeById:byId,items:Object.freeze(items),byId:ids,groupBy:axis.groupBy??null,sort})}
|
|
25
27
|
function matrixDocument(input){const doc=matrixKeys(input,MATRIX_KEYS,"the document");if(doc.protocol!==PROTOCOL||doc.type!=="matrix")matrixFail("it needs protocol "+PROTOCOL+" and type \"matrix\"");const id=matrixId(doc.id,"the matrix id"),label=matrixText(doc.label,"the label",200);if(doc.square!==undefined&&typeof doc.square!=="boolean")matrixFail("square must be true or false");const square=doc.square===true,rows=matrixAxis(doc.rows,"rows");if(square&&doc.columns!==undefined||!square&&(doc.columns===undefined||doc.columnTitle!==undefined))matrixFail("a matrix has columns, or is square and has none (and may have a columnTitle)");const columns=square?rows:matrixAxis(doc.columns,"columns");if(![undefined,"self","data"].includes(doc.diagonal)||doc.diagonal!==undefined&&!square)matrixFail("only a square matrix has a diagonal, self or data");if(rows.items.length*columns.items.length>1000000)matrixFail("a matrix holds at most 1000000 cells");if(!Array.isArray(doc.states)||!doc.states.length||doc.states.length>36)matrixFail("it needs 1 to 36 states");const stateIds=new Set(),states=doc.states.map((entry,index)=>{const state=matrixKeys(entry,["id","label","tone","symbol","attention"],"a state");if(typeof state.id!=="string"||!/^[A-Za-z][\w-]{0,63}$/.test(state.id) || stateIds.has(state.id)) matrixFail("states need unique ids");
|
|
26
28
|
stateIds.add(state.id);if(state.tone!==undefined&&(typeof state.tone!=="string"||!/^[a-z][a-z0-9-]{0,31}$/.test(state.tone) || /-bg$/.test(state.tone))) matrixFail("the state '" + state.id + "' has an invalid tone");
|
|
27
29
|
if(!MATRIX_SYMBOLS.includes(state.symbol)||state.attention!==undefined&&typeof state.attention!=="boolean")matrixFail("the state '"+state.id+"' needs one of the symbols");return Object.freeze({id:state.id,index,label:matrixText(state.label,"the label of state '"+state.id+"'",200),tone:state.tone||null,symbol:state.symbol,attention:state.attention===true})});const R=rows.items.length,C=columns.items.length,grid=new Uint8Array(R*C).fill(MATRIX_NONE);if(!Array.isArray(doc.cells)||doc.cells.length!==R)matrixFail("cells needs one string per row");doc.cells.forEach((line,r)=>{if(typeof line!=="string"||line.length!==C)matrixFail("each cells string needs one character per column");for(let c=0;c<C;c++){const ch=line.charCodeAt(c);if(ch===46)continue;const index=MATRIX_DIGITS.indexOf(line[c]);if(index<0||index>=states.length)matrixFail("cells name an undeclared state");grid[r*C+c]=index}});const diagonal=doc.diagonal||"self";if(square&&diagonal==="self")for(let r=0;r<R;r++)grid[r*C+r]=MATRIX_SELF;const notes=new Map();if(doc.notes!==undefined&&!Array.isArray(doc.notes))matrixFail("notes must be a list");for(const note of doc.notes||[]){if(!Array.isArray(note)||note.length<3||note.length>6||!Number.isInteger(note[0])||!Number.isInteger(note[1])||note[0]<0||note[1]<0||note[0]>=R||note[1]>=C)matrixFail("a note names no cell");const at=note[0]*C+note[1];if(grid[at]>=MATRIX_SELF||notes.has(at))matrixFail("a note names a cell without a state, or twice");const[,,value=null,text=null,title=null,details=null]=note;if(value!==null&&(typeof value!=="number"||!Number.isFinite(value)||Math.abs(value)>Number.MAX_SAFE_INTEGER))matrixFail("a note value must be a finite number");if(text!==null)matrixText(text,"a note text",64);if(title!==null)matrixText(title,"a note title",1000);if(details!==null&&(!Array.isArray(details)||details.length>16||details.some(pair=>!Array.isArray(pair)||pair.length!==2||
|
|
@@ -71,21 +73,21 @@ fitNow(){const host=this.host,style=host.style;if(this.fitInline===undefined){co
|
|
|
71
73
|
if(this.doc.autoHeight===false||Number.isNaN(this.fitMax)){if(style.maxHeight!==this.fitInline)style.maxHeight=this.fitInline;return}
|
|
72
74
|
if(!host.offsetHeight)return;const parts=[this.bar,this.legend,this.scroll,this.empty,this.cards].filter(part=>!part.hidden),hostStyle=getComputedStyle(host);let content=(parts.length-1)*(parseFloat(getComputedStyle(this.root).rowGap)||0);for(const part of parts){let height=part.getBoundingClientRect().height;if(part===this.scroll||part===this.cards)height=Math.min(height+part.scrollHeight-part.clientHeight,parseFloat(getComputedStyle(part).maxHeight)||Infinity);content +=height}
|
|
73
75
|
const chrome=["paddingTop","paddingBottom","borderTopWidth","borderBottomWidth"].reduce((sum,name)=>sum +(parseFloat(hostStyle[name])||0),0);const value=Math.min(this.fitMax,Math.ceil(chrome+content))+ "px";if(style.maxHeight!==value)style.maxHeight=value}}
|
|
74
|
-
Object.assign(MatrixView.prototype,{scheduleRender(){if(this.destroyed||this.frame)return;this.frame=requestAnimationFrame(()=>{this.frame=0;this.render()})},recycleAll(){this.lookCache=null;for(const row of this.rowsMounted.values())this.releaseRow(row);this.rowsMounted.clear();for(const map of[this.headMounted,this.footMounted,this.bandMounted]){for(const element of map.values())element.remove();map.clear()}},releaseRow(row){row.remove();row._key=null;if(this.rowPool.length<200)this.rowPool.push(row)},windows(){const scroll=this.scroll,viewH=Math.max(this.rowH,scroll.clientHeight-this.headH-this.bandH-this.footH),viewW=Math.max(this.cellW,scroll.clientWidth-this.rowHeadW-this.totalW);const rows=this.rowWindow.window(scroll.scrollTop,viewH,MATRIX_OVERSCAN),columns=this.columnWindow.window(Math.abs(scroll.scrollLeft),viewW,MATRIX_OVERSCAN);return{rows,columns,viewH,viewW}},render(){if(this.destroyed||this.scroll.hidden)return;const{rows,columns}=this.windows(),model=this.model,focus=this.focus,scroll=this.scroll,top=scroll.scrollTop;const below=scroll.scrollHeight-scroll.clientHeight-top>1;this.head.classList.toggle("cx-mx-raised",top>0);this.foot.classList.toggle("cx-mx-raised",below);const columnList=[];for(let c=columns.first;c<=columns.last;c++)columnList.push(c);if(focus.column>=0&&focus.column<model.columns.length&&(focus.column<columns.first||focus.column>columns.last))columnList.push(focus.column);const rowList=[];for(let r=rows.first;r<=rows.last;r++)rowList.push(r);if(focus.row>=0&&focus.row<model.rows.length&&(focus.row<rows.first||focus.row>rows.last))rowList.push(focus.row);this.paintHeader(columnList);this.paintBand(columns);this.placeBands();this.paintFoot(columnList);const keep=new Set();for(const r of rowList){const entry=model.rows[r];if(!entry)continue;keep.add(entry.key);let row=this.rowsMounted.get(entry.key);if(!row){row=this.rowPool.pop()||this.newRow();this.rowsMounted.set(entry.key,row);this.fillRow(row,entry,r);this.body.appendChild(row)}
|
|
76
|
+
Object.assign(MatrixView.prototype,{groupCount(axis,count){const template=(axis==="columns"?this.doc.columns:this.doc.rows).groupCount||this.labels.matrixGroupCount;return fill(plural(template,count,this.lang),{count:this.format.format(count)})},scheduleRender(){if(this.destroyed||this.frame)return;this.frame=requestAnimationFrame(()=>{this.frame=0;this.render()})},recycleAll(){this.lookCache=null;for(const row of this.rowsMounted.values())this.releaseRow(row);this.rowsMounted.clear();for(const map of[this.headMounted,this.footMounted,this.bandMounted]){for(const element of map.values())element.remove();map.clear()}},releaseRow(row){row.remove();row._key=null;if(this.rowPool.length<200)this.rowPool.push(row)},windows(){const scroll=this.scroll,viewH=Math.max(this.rowH,scroll.clientHeight-this.headH-this.bandH-this.footH),viewW=Math.max(this.cellW,scroll.clientWidth-this.rowHeadW-this.totalW);const rows=this.rowWindow.window(scroll.scrollTop,viewH,MATRIX_OVERSCAN),columns=this.columnWindow.window(Math.abs(scroll.scrollLeft),viewW,MATRIX_OVERSCAN);return{rows,columns,viewH,viewW}},render(){if(this.destroyed||this.scroll.hidden)return;const{rows,columns}=this.windows(),model=this.model,focus=this.focus,scroll=this.scroll,top=scroll.scrollTop;const below=scroll.scrollHeight-scroll.clientHeight-top>1;this.head.classList.toggle("cx-mx-raised",top>0);this.foot.classList.toggle("cx-mx-raised",below);const columnList=[];for(let c=columns.first;c<=columns.last;c++)columnList.push(c);if(focus.column>=0&&focus.column<model.columns.length&&(focus.column<columns.first||focus.column>columns.last))columnList.push(focus.column);const rowList=[];for(let r=rows.first;r<=rows.last;r++)rowList.push(r);if(focus.row>=0&&focus.row<model.rows.length&&(focus.row<rows.first||focus.row>rows.last))rowList.push(focus.row);this.paintHeader(columnList);this.paintBand(columns);this.placeBands();this.paintFoot(columnList);const keep=new Set();for(const r of rowList){const entry=model.rows[r];if(!entry)continue;keep.add(entry.key);let row=this.rowsMounted.get(entry.key);if(!row){row=this.rowPool.pop()||this.newRow();this.rowsMounted.set(entry.key,row);this.fillRow(row,entry,r);this.body.appendChild(row)}
|
|
75
77
|
else if(row._index!==r)this.placeRow(row,r);this.drawRow(row,entry,columns.first,entry.kind==="heading"?-1:columns.last)}
|
|
76
78
|
for(const[key,row]of this.rowsMounted)if(!keep.has(key)){this.releaseRow(row);this.rowsMounted.delete(key)}
|
|
77
79
|
this.syncTabStop()},newRow(){const row=h("div","cx-mx-row"),head=h("div","cx-mx-rowhead"),spacer=h("div","cx-mx-spacer"),total=h("div","cx-mx-total");row.setAttribute("role","row");head.setAttribute("role","rowheader");head.setAttribute("aria-colindex","1");total.setAttribute("role","gridcell");row.append(head,spacer,total);row._head=head;row._total=total;return row},placeRow(row,r){row._index=r;row.style.transform="translateY("+this.rowWindow.offset(r)+ "px)";row.setAttribute("aria-rowindex",String(r +(this.bandH?3:2)));row._head._r=r;row._total._r=r},fillRow(row,entry,r){row._key=entry.key;row._entry=entry;this.placeRow(row,r);row.className="cx-mx-row" +(entry.kind==="heading"?" cx-mx-heading":entry.kind==="rollup"?" cx-mx-rolledrow":entry.band?" cx-mx-member":"");const head=row._head,labels=this.labels;head.replaceChildren();head._c=-1;head.tabIndex=-1;if(entry.kind==="item"){const item=entry.item,text=item.href?h("a","cx-mx-label cx-link"):h("span","cx-mx-label");if(item.href){text.href=item.href;text.tabIndex=-1}
|
|
78
80
|
setText(text,item.label);head.appendChild(text);if(item.secondary){const sub=h("span","cx-mx-sub");setText(sub,item.secondary);head.appendChild(sub)}
|
|
79
|
-
head.title=item.secondary?item.label+" — "+item.secondary:item.label}else{const toggle=h("button","cx-mx-toggle"),open=entry.kind==="heading";toggle.type="button";toggle.tabIndex=-1;toggle.setAttribute("aria-expanded",String(open));toggle.setAttribute("aria-label",fill(open?labels.matrixCollapseGroup:labels.matrixExpandGroup,{group:entry.label}));toggle._group={axis:"rows",key:entry.group.key};const label=h("span","cx-mx-label"),count=h("span","cx-mx-sub");setText(label,entry.label);setText(count,
|
|
81
|
+
head.title=item.secondary?item.label+" — "+item.secondary:item.label}else{const toggle=h("button","cx-mx-toggle"),open=entry.kind==="heading";toggle.type="button";toggle.tabIndex=-1;toggle.setAttribute("aria-expanded",String(open));toggle.setAttribute("aria-label",fill(open?labels.matrixCollapseGroup:labels.matrixExpandGroup,{group:entry.label}));toggle._group={axis:"rows",key:entry.group.key};const label=h("span","cx-mx-label"),count=h("span","cx-mx-sub");setText(label,entry.label);setText(count,this.groupCount("rows",entry.members.length));toggle.append(label,count);head.appendChild(toggle);head.removeAttribute("title")}
|
|
80
82
|
const total=row._total;total.hidden=!this.totalW;if(this.totalW)this.paintTotal(total,entry,r,this.model.columns.length)},paintTotal(element,entry,r,c){const value=entry.total||0;setText(element,this.format.format(value));element.classList.toggle("cx-mx-zero",!value);element.setAttribute("aria-label",fill(this.labels.matrixItemTotal,{item:entry.label,count:this.format.format(value)}));element._r=r;element._c=c;element.tabIndex=-1;element.setAttribute("aria-colindex",String(this.model.columns.length+2))},paintHeader(columnList){const wanted=new Set(columnList),mounted=this.headMounted,model=this.model;for(const[c,element]of mounted)if(!wanted.has(c)||element._key!==model.columns[c]?.key){element.remove();mounted.delete(c)}
|
|
81
83
|
for(const c of columnList){const entry=model.columns[c];if(!entry||mounted.has(c))continue;const element=h("div","cx-mx-hcell" +(entry.kind==="rollup"?" cx-mx-rolledcol":""));element.setAttribute("role","columnheader");element.setAttribute("aria-colindex",String(c+2));element.style.insetInlineStart=this.rowHeadW+this.columnWindow.offset(c)+ "px";element._r=-1;element._c=c;element._key=entry.key;element.tabIndex=-1;if(entry.kind==="rollup"){const toggle=h("button","cx-mx-toggle");toggle.type="button";toggle.tabIndex=-1;toggle.setAttribute("aria-expanded","false");toggle.setAttribute("aria-label",fill(this.labels.matrixExpandGroup,{group:entry.label}));toggle._group={axis:"columns",key:entry.group.key};const text=h("span","cx-mx-vlabel");setText(text,entry.label);toggle.appendChild(text);element.appendChild(toggle)}else{const item=entry.item,text=h(item.href?"a":"span","cx-mx-vlabel" +(item.href?" cx-link":""));if(item.href){text.href=item.href;text.tabIndex=-1}
|
|
82
84
|
setText(text,item.label);element.appendChild(text);element.title=item.secondary?item.label+" — "+item.secondary:item.label}
|
|
83
|
-
mounted.set(c,element);this.headRow.appendChild(element)}},paintBand(columns){const mounted=this.bandMounted,model=this.model;if(!this.bandH)return;const seen=new Set();for(let c=columns.first;c<=columns.last&&c>=0;c++){const entry=model.columns[c];if(!entry||!entry.band||seen.has(entry.band.key))continue;seen.add(entry.band.key);if(mounted.has(entry.band.key))continue;const band=entry.band,first=model.columns.findIndex(item=>item.band===band),element=h("div","cx-mx-bcell");element._from=this.columnWindow.offset(first);element._width=band.members.length*this.cellW;element.style.insetInlineStart=this.rowHeadW+element._from+"px";element.style.width=element._width+"px";element.setAttribute("role","columnheader");element.setAttribute("aria-colindex",String(first+2));element.setAttribute("aria-colspan",String(band.members.length));const toggle=h("button","cx-mx-toggle");toggle.type="button";toggle.tabIndex=-1;toggle.setAttribute("aria-expanded","true");toggle.setAttribute("aria-label",fill(this.labels.matrixCollapseGroup,{group:band.label}));toggle._group={axis:"columns",key:band.key};const text=h("span","cx-mx-label");setText(text,band.label);toggle.appendChild(text);element.appendChild(toggle);element.title=band.label;mounted.set(band.key,element);this.band.appendChild(element)}
|
|
85
|
+
mounted.set(c,element);this.headRow.appendChild(element)}},paintBand(columns){const mounted=this.bandMounted,model=this.model;if(!this.bandH)return;const seen=new Set();for(let c=columns.first;c<=columns.last&&c>=0;c++){const entry=model.columns[c];if(!entry||!entry.band||seen.has(entry.band.key))continue;seen.add(entry.band.key);if(mounted.has(entry.band.key))continue;const band=entry.band,first=model.columns.findIndex(item=>item.band===band),element=h("div","cx-mx-bcell");element._from=this.columnWindow.offset(first);element._width=band.members.length*this.cellW;element.style.insetInlineStart=this.rowHeadW+element._from+"px";element.style.width=element._width+"px";element.setAttribute("role","columnheader");element.setAttribute("aria-colindex",String(first+2));element.setAttribute("aria-colspan",String(band.members.length));const toggle=h("button","cx-mx-toggle");toggle.type="button";toggle.tabIndex=-1;toggle.setAttribute("aria-expanded","true");toggle.setAttribute("aria-label",fill(this.labels.matrixCollapseGroup,{group:band.label}));toggle._group={axis:"columns",key:band.key};const text=h("span","cx-mx-label");setText(text,band.label);toggle.appendChild(text);element.appendChild(toggle);element.title=band.label+" · "+this.groupCount("columns",band.members.length);mounted.set(band.key,element);this.band.appendChild(element)}
|
|
84
86
|
for(const[key,element]of mounted)if(!seen.has(key)){element.remove();mounted.delete(key)}},placeBands(){if(!this.bandH)return;const start=Math.abs(this.scroll.scrollLeft),end=start+Math.max(0,this.scroll.clientWidth-this.rowHeadW-this.totalW);for(const element of this.bandMounted.values()){const from=element._from,shown=Math.min(end,from+element._width)- Math.max(start,from),toggle=element.firstChild;toggle.style.marginInlineStart=Math.max(0,start-from)+ "px";toggle.style.maxWidth=Math.max(0,shown-8)+ "px";element.classList.toggle("cx-mx-bclip",shown<Math.min(40,element._width))}},paintFoot(columnList){if(!this.footH)return;const wanted=new Set(columnList),mounted=this.footMounted,model=this.model,rows=model.rows.length +(this.bandH?3:2);this.footRow.setAttribute("aria-rowindex",String(rows));for(const[c,element]of mounted)if(!wanted.has(c)||element._key!==model.columns[c]?.key){element.remove();mounted.delete(c)}
|
|
85
87
|
for(const c of columnList){const entry=model.columns[c];if(!entry||mounted.has(c))continue;const element=h("div","cx-mx-fcell");element.setAttribute("role","gridcell");element.style.insetInlineStart=this.rowHeadW+this.columnWindow.offset(c)+ "px";this.paintTotal(element,entry,model.rows.length,c);element.setAttribute("aria-colindex",String(c+2));element._key=entry.key;mounted.set(c,element);this.footRow.appendChild(element)}
|
|
86
88
|
if(this.totalW)this.paintTotal(this.footGrand,{label:this.labels.matrixTotal,total:model.grandTotal},model.rows.length,model.columns.length);this.footHeader._r=model.rows.length;this.footHeader._c=-1}});const MATRIX_PATHS=new Map(),MATRIX_TILE=16;function matrixPath(name){if(!MATRIX_PATHS.has(name))MATRIX_PATHS.set(name,name==="dot"?null:new Path2D(MATRIX_SYMBOL_PATHS[name]));return MATRIX_PATHS.get(name)}
|
|
87
89
|
Object.assign(MatrixView.prototype,{looks(){if(this.lookCache&&this.lookCache.doc===this.doc)return this.lookCache.items;const items=new Map(),probe=h("span","cx-mx-cell"),forced=global.matchMedia?.("(forced-colors: active)").matches;probe.style.display="none";this.root.appendChild(probe);const read=(cls,tone)=>{probe.className=cls;toneColors(probe,tone);const style=getComputedStyle(probe),fill=style.backgroundColor;return{ink:style.color,fill:/rgba\(\d+, \d+, \d+, 0\)|transparent/.test(fill) ? null : fill, font: style.fontWeight + " " + style.fontSize + " " + style.fontFamily };
|
|
88
|
-
};this.doc.states.forEach((state,index)=>{const tone=toneOf(state.tone),look=read("cx-mx-cell" +(state.attention?" cx-mx-attn":"")+ tone.cls,tone);items.set(index,Object.assign(look,{symbol:state.symbol,name:state.label,attention:state.attention,forced}))});items.set(MATRIX_NONE,Object.assign(read("cx-mx-cell cx-mx-none",toneOf(null)),{symbol:null,name:this.labels.matrixNoData,none:true}));items.set(MATRIX_SELF,Object.assign(read("cx-mx-cell cx-mx-self",toneOf(null)),{symbol:null,name:this.labels.matrixSelf,self:true}));probe.className="cx-mx-gridline";this.lineColor=getComputedStyle(probe).color;probe.remove();this.lookCache={doc:this.doc,items};this.cellName=matrixTemplate(this.labels.matrixCell);this.canvasVersion=(this.canvasVersion||0)+ 1;return items},drawRow(row,entry,first,last){const ratio=global.devicePixelRatio||1,tiles=row._tiles||=new Map(),version=this.canvasVersion+":"+ratio+":"+entry.key;
|
|
90
|
+
};this.doc.states.forEach((state,index)=>{const tone=toneOf(state.tone),look=read("cx-mx-cell" +(state.attention?" cx-mx-attn":"")+ tone.cls,tone);items.set(index,Object.assign(look,{symbol:state.symbol,name:state.label,attention:state.attention,forced}))});items.set(MATRIX_NONE,Object.assign(read("cx-mx-cell cx-mx-none",toneOf(null)),{symbol:null,name:this.labels.matrixNoData,none:true}));items.set(MATRIX_SELF,Object.assign(read("cx-mx-cell cx-mx-self",toneOf(null)),{symbol:null,name:this.labels.matrixSelf,self:true}));probe.className="cx-mx-gridline";this.lineColor=getComputedStyle(probe).color;probe.remove();this.lookCache={doc:this.doc,items};this.cellName=matrixTemplate(this.labels.matrixCell);this.canvasVersion=(this.canvasVersion||0)+ 1;return items},drawRow(row,entry,first,last){this.looks();const ratio=global.devicePixelRatio||1,tiles=row._tiles||=new Map(),version=this.canvasVersion+":"+ratio+":"+entry.key;const from=last>=first?Math.floor(first / MATRIX_TILE) : 0, to = last >= first ? Math.floor(last / MATRIX_TILE) : -1;
|
|
89
91
|
for(const[index,tile]of tiles)if(index<from||index>to){tiles.delete(index);tile.remove();if(this.tilePool.length<400)this.tilePool.push(tile)}
|
|
90
92
|
for(let index=from;index<=to;index++){let tile=tiles.get(index);if(!tile){tile=this.tilePool.pop();if(!tile){tile=h("canvas","cx-mx-canvas");tile.setAttribute("aria-hidden","true")}
|
|
91
93
|
tile._drawn=null;tiles.set(index,tile);row.insertBefore(tile,row._total)}
|
|
@@ -120,7 +122,7 @@ this.legend.replaceChildren(...items)},togglePanel(axis){if(!this.panel.hidden&&
|
|
|
120
122
|
this.panelAxis=axis;this.fillPanel(axis);this.panel.hidden=false;for(const name of MATRIX_AXES)this.axisButtons[name].setAttribute("aria-expanded",String(name===axis));this.panel.querySelector("select,input")?.focus()},closePanel(returnFocus){if(this.panel.hidden)return;this.panel.hidden=true;for(const name of MATRIX_AXES)this.axisButtons[name].setAttribute("aria-expanded","false");if(returnFocus)this.axisButtons[this.panelAxis].focus()},fillPanel(axis){const labels=this.labels,doc=this.doc,data=doc[axis==="rows"?"rows":"columns"],query=this.query,panel=this.panel,signal=this.lifetime.signal;panel.setAttribute("aria-label",this.axisTitle(axis));const focused=panel.contains(document.activeElement)?document.activeElement.dataset.cxControl:null;const field=(text,control)=>{const label=h("label","cx-mx-field"),name=h("span");setText(name,text);label.append(name,control);return label};const select=(options,value,change,key)=>{const element=h("select","cx-mx-input");element.dataset.cxControl=key;for(const[optionValue,text]of options){const option=h("option");option.value=optionValue;setText(option,text);element.appendChild(option)}
|
|
121
123
|
element.value=value;element.addEventListener("change",()=>change(element.value),{signal});return element};const sort=query.sort[axis];const sortBy=select([["",labels.matrixAsListed],["#label",labels.matrixByLabel],["#total",labels.matrixByTotal],...data.attributes.map(attribute=>[attribute.id,attribute.title])],sort?sort.by:"",value=>this.sort(axis,value||null,value==="#total"?"desc":query.sort[axis]?.direction||"asc"),"sort");const descending=h("input","cx-mx-check");descending.type="checkbox";descending.checked=!!sort&&sort.direction==="desc";descending.disabled=!sort;descending.dataset.cxControl="direction";descending.addEventListener("change",()=>this.sort(axis,query.sort[axis]?.by||null,descending.checked?"desc":"asc"),{signal});const descendingLabel=h("label","cx-mx-switch"),descendingText=h("span");setText(descendingText,labels.matrixDescending);descendingLabel.append(descending,descendingText);const groupBy=select([["",labels.matrixNoGrouping],...data.attributes.map(attribute=>[attribute.id,attribute.title])],query.group[axis]||"",value=>this.group(axis,value||null),"group");const children=[field(labels.matrixSortBy,sortBy),descendingLabel];if(data.attributes.length)children.push(field(labels.matrixGroupBy,groupBy));for(const attribute of data.attributes.filter(item=>item.facet))children.push(this.facetList(axis,data,attribute));const close=h("button","cx-mx-button");close.type="button";setText(close,labels.matrixClose);close.dataset.cxControl="close";close.addEventListener("click",()=>this.closePanel(true),{signal});children.push(close);panel.replaceChildren(...children);if(focused)panel.querySelector('[data-cx-control="'+CSS.escape(focused)+ '"]')?.focus()},facetList(axis,data,attribute){const set=h("fieldset","cx-mx-facet"),legend=h("legend"),counts=new Map(),chosen=new Set(this.query.filters[axis][attribute.id]||[]),signal=this.lifetime.signal;setText(legend,attribute.title);set.appendChild(legend);for(const item of data.items){const key=matrixValueKey(item.values[attribute.id]);if(!counts.has(key))counts.set(key,{key,text:matrixValueText(item.values[attribute.id],attribute,this.format)||"—",count:0});counts.get(key).count++}
|
|
122
124
|
for(const value of[...counts.values()].sort((a,b)=>matrixNatural(a.text,b.text)).slice(0,200)){const label=h("label","cx-mx-switch"),box=h("input","cx-mx-check"),text=h("span"),count=h("span","cx-mx-keycount");box.type="checkbox";box.checked=chosen.has(value.key);box.dataset.cxControl="facet:"+attribute.id+":"+value.key;box.addEventListener("change",()=>{const next=new Set(this.query.filters[axis][attribute.id]||[]);if(box.checked)next.add(value.key);else next.delete(value.key);this.filter(axis,attribute.id,[...next])},{signal});setText(text,value.text);setText(count,this.format.format(value.count));label.append(box,text,count);set.appendChild(label)}
|
|
123
|
-
return set}});Object.assign(MatrixView.prototype,{cellInfo(cell){const row=this.model.rows[cell._r],column=this.model.columns[cell._c];if(!row||!column)return null;const info=this.model.cell(row,column),state=info.state<MATRIX_SELF?this.doc.states[info.state]:null;return{row,column,info,state}},cellLines(data){const labels=this.labels,lines=[],note=data.info.note;const stateText=data.state?data.state.label:data.info.state===MATRIX_SELF?labels.matrixSelf:labels.matrixNoData;lines.push([labels.matrixState,stateText]);if(note&¬e.value!=null)lines.push([labels.matrixValue,this.format.format(note.value)]);if(note&¬e.text)lines.push([note.value!=null?"":labels.matrixValue,note.text]);if(data.info.rolled){lines.push(["",fill(labels.
|
|
125
|
+
return set}});Object.assign(MatrixView.prototype,{cellInfo(cell){const row=this.model.rows[cell._r],column=this.model.columns[cell._c];if(!row||!column)return null;const info=this.model.cell(row,column),state=info.state<MATRIX_SELF?this.doc.states[info.state]:null;return{row,column,info,state}},cellLines(data){const labels=this.labels,lines=[],note=data.info.note;const stateText=data.state?data.state.label:data.info.state===MATRIX_SELF?labels.matrixSelf:labels.matrixNoData;lines.push([labels.matrixState,stateText]);if(note&¬e.value!=null)lines.push([labels.matrixValue,this.format.format(note.value)]);if(note&¬e.text)lines.push([note.value!=null?"":labels.matrixValue,note.text]);if(data.info.rolled){lines.push(["",fill(labels.matrixCellCount,{count:this.format.format(data.info.members)})]);if(data.info.attention)lines.push(["",fill(labels.matrixAttention,{count:this.format.format(data.info.attention)})])}
|
|
124
126
|
if(note&¬e.title)lines.push(["",note.title]);for(const[label,value]of note&¬e.details||[])lines.push([label,value]);return lines},onPointer(event){const target=this.cellAt(event);if(target&&this.pointerCell&&target._r===this.pointerCell._r&&target._c===this.pointerCell._c)return;this.pointerCell=target;this.hoverCell(target);clearTimeout(this.tipTimer);if(!target){if(!this.tipKeyboard)this.hideTip();return}
|
|
125
127
|
this.tipTimer=setTimeout(()=>{if(!this.destroyed&&this.pointerCell===target)this.showTip(target,false)},250)},showTip(cell,keyboard){const data=this.cellInfo(cell);if(!data)return;this.tipKeyboard=keyboard;const tip=this.tip,title=h("div","cx-mx-tiptitle"),list=h("dl","cx-mx-tiplist");setText(title,data.row.label+" · "+data.column.label);for(const[label,value]of this.cellLines(data).slice(0,8)){const term=h("dt"),text=h("dd");setText(term,label);setText(text,value);list.append(term,text)}
|
|
126
128
|
tip.replaceChildren(title,list);tip.hidden=false;const box=this.cellRect(cell._r,cell._c),frame=this.root.getBoundingClientRect(),width=tip.offsetWidth,height=tip.offsetHeight;if(!box){this.hideTip();return}
|
|
@@ -133,14 +135,20 @@ const cells=this.attentionCells(entry),items=h("ul","cx-mx-cardcells");for(const
|
|
|
133
135
|
if(cells.length>12){const more=h("li","cx-mx-sub");setText(more,"+"+this.format.format(cells.length-12));items.appendChild(more)}
|
|
134
136
|
if(!cells.length){const clear=h("div","cx-mx-sub cx-mx-clear-text");setText(clear,labels.matrixAllClear);card.appendChild(clear)}else card.appendChild(items);list.appendChild(card)}
|
|
135
137
|
const children=[list];if(rows.length>limit){const more=h("button","cx-mx-button");more.type="button";setText(more,labels.matrixShowMore);more.addEventListener("click",()=>{this.cardLimit +=100;this.renderCards()},{signal:this.lifetime.signal});children.push(more)}
|
|
136
|
-
this.cards.replaceChildren(...children)},stateGlyph(info){if(info.state===MATRIX_SELF)return "";if(info.state===MATRIX_NONE)return "";const state=this.doc.states[info.state];return(MATRIX_GLYPHS[state.symbol]||"")+(info.note&&info.note.text?" "+info.note.text:info.note&&info.note.value!=null?" "+this.format.format(info.note.value):"")},
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
this.cards.replaceChildren(...children)},stateGlyph(info){if(info.state===MATRIX_SELF)return "";if(info.state===MATRIX_NONE)return "";const state=this.doc.states[info.state];return(MATRIX_GLYPHS[state.symbol]||"")+(info.note&&info.note.text?" "+info.note.text:info.note&&info.note.value!=null?" "+this.format.format(info.note.value):"")},printCell(info){const td=h("td"),state=info.state<MATRIX_SELF?this.doc.states[info.state]:null,labels=this.labels;setText(td,info.state===MATRIX_NONE?"·":this.stateGlyph(info)+(info.rolled&&info.attention?" "+this.format.format(info.attention):""));td.title=state?state.label:info.state===MATRIX_SELF?labels.matrixSelf:labels.matrixNoData;if(state)applyTone(td,"cx-mx-printcell" +(state.attention?" cx-mx-attn":""),toneOf(state.tone));else td.className=info.state===MATRIX_SELF?"cx-mx-printself":"cx-mx-printnone";return td},printHead(table,columns){const head=h("thead"),colgroup=span=>{const group=h("colgroup");group.span=span;table.appendChild(group)};if(columns.some(entry=>entry.band)){const band=h("tr");band.appendChild(h("td"));colgroup(1);for(let c=0;c<columns.length;){const group=columns[c].band,th=h(group?"th":"td");let span=1;if(group){while(c+span<columns.length&&columns[c+span].band===group)span++;const count=h("span","cx-mx-printcount");th.scope="colgroup";setText(th,group.label);setText(count," · "+this.groupCount("columns",group.members.length));th.appendChild(count)}
|
|
139
|
+
th.colSpan=span;band.appendChild(th);colgroup(span);c +=span}
|
|
140
|
+
if(this.totalW){band.appendChild(h("td"));colgroup(1)}
|
|
141
|
+
head.appendChild(band)}
|
|
142
|
+
const row=h("tr"),corner=h("th");corner.scope="col";setText(corner,this.axisTitle("rows"));row.appendChild(corner);for(const column of columns){const th=h("th");th.scope="col";setText(th,column.label);row.appendChild(th)}
|
|
143
|
+
if(this.totalW){const th=h("th");th.scope="col";setText(th,this.labels.matrixTotal);row.appendChild(th)}
|
|
144
|
+
head.appendChild(row);table.appendChild(head)},renderPrint(){if(this.destroyed)return;const model=this.model,labels=this.labels,table=h("table","cx-mx-printtable"),caption=h("caption");setText(caption,this.doc.label+" — "+this.summaryText());table.appendChild(caption);const columns=model.columns,rows=model.rows.filter(entry=>entry.kind!=="heading");if(rows.length*columns.length<=2500){this.printHead(table,columns);let body=h("tbody");for(const entry of model.rows){if(entry.kind!=="item"&&body.childElementCount){table.appendChild(body);body=h("tbody")}
|
|
145
|
+
const tr=h("tr"),th=h("th"),total=h("td");setText(total,this.format.format(entry.total||0));setText(th,entry.label);if(entry.kind!=="item"){const count=h("span","cx-mx-printcount");setText(count," · "+this.groupCount("rows",entry.members.length));th.appendChild(count);tr.className=entry.kind==="heading"?"cx-mx-printgroup":"cx-mx-printrolled"}
|
|
146
|
+
th.scope=entry.kind==="heading"?"rowgroup":"row";tr.appendChild(th);if(entry.kind==="heading")th.colSpan=columns.length+1;else{if(entry.band)th.className="cx-mx-printmember";for(const column of columns)tr.appendChild(this.printCell(model.cell(entry,column)))}
|
|
147
|
+
if(this.totalW)tr.appendChild(total);body.appendChild(tr)}
|
|
148
|
+
table.appendChild(body)}else{const head=h("tr");for(const text of[this.axisTitle("rows"),this.axisTitle("columns"),labels.matrixState,labels.matrixValue]){const th=h("th");th.scope="col";setText(th,text);head.appendChild(th)}
|
|
141
149
|
table.appendChild(head);let written=0,left=0;for(const row of rows){for(const{column,info,state}of this.attentionCells(row)){if(written>=5000){left++;continue}
|
|
142
150
|
written++;const tr=h("tr");for(const text of[row.label,column.label,state.label,info.note&&(info.note.text||(info.note.value!=null?this.format.format(info.note.value):""))||""]){const td=h("td");setText(td,text);tr.appendChild(td)}
|
|
143
|
-
table.appendChild(tr)}}
|
|
151
|
+
const stateCell=tr.children[2];applyTone(stateCell,"cx-mx-printcell cx-mx-attn",toneOf(state.tone));setText(stateCell,(MATRIX_GLYPHS[state.symbol]||"")+ " "+state.label);table.appendChild(tr)}}
|
|
144
152
|
if(left){const tr=h("tr"),td=h("td");td.colSpan=4;setText(td,"+"+this.format.format(left));tr.appendChild(td);table.appendChild(tr)}}
|
|
145
153
|
this.print.replaceChildren(table)}});function matrixAxisName(axis){if(!MATRIX_AXES.includes(axis))throw new Error("CanopyX: a matrix axis is \"rows\" or \"columns\".");return axis}
|
|
146
154
|
Object.assign(MatrixView.prototype,{axisData(axis){return matrixAxisName(axis)==="rows"?this.doc.rows:this.doc.columns},checkSort(axis,sort){if(sort==null)return null;if(typeof sort!=="object"||(sort.by!=="#label"&&sort.by!=="#total"&&!this.axisData(axis).attributeById.has(sort.by))||![undefined,"asc","desc"].includes(sort.direction))
|
|
@@ -62,7 +62,7 @@ function fill(template,values){return template.replace(/\{(\w+)\}/g, (match, nam
|
|
|
62
62
|
const pluralRules=new Map();function plural(template,count,lang){if(!template.startsWith("["))return template;const forms={};for(const match of template.matchAll(/\[(zero|one|two|few|many|other)\]([^[]*)/g)) forms[match[1]] = match[2];
|
|
63
63
|
let rules=pluralRules.get(lang);if(!rules){try{rules=new Intl.PluralRules(lang||"en")}catch(_){rules=new Intl.PluralRules("en")}pluralRules.set(lang,rules)}
|
|
64
64
|
return forms[rules.select(Number(count))]??forms.other??template}
|
|
65
|
-
let DEFAULT_LABELS=Object.freeze({searchPlaceholder:"Search",searchResults:"Search results",searchResultCount:"{count} results",searchResultCountOfTotal:"{count} of {total} results",searchResultCountOfMany:"{count} of many results",searchNoResults:"No results",searchTooShort:"Type at least {min} characters",searchWordTooShort:"Type a word of at least {min} characters",searchFailed:"Search failed: {error}",columns:"Columns",visibleColumns:"Visible columns",resizeColumn:"Resize {column}",columnWidth:"{width} pixels",loading:"Loading…",loadError:"Could not load: {error} (Enter to retry)",queryFailed:"Could not update the view: {error}",showMore:"Show more ({loaded} of {total} loaded)",showMoreUnknownTotal:"Show more ({loaded} loaded)",pageLoaded:"{loaded} of {total} loaded",itemsLoaded:"{count} items",yes:"Yes",no:"No",utcTime:"{time} UTC",localTime:"{time} local time",mountError:"This view could not be displayed: {error}"});function labelsFor(...sources){const labels=Object.assign({},DEFAULT_LABELS);for(const source of sources){if(source==null)continue;if(typeof source!=="object"||Array.isArray(source))throw new Error("CanopyX: labels must be an object of strings.");Object.keys(source).forEach((name)=>{if(!Object.hasOwn(DEFAULT_LABELS,name)&&!/^(?:gridEdit|format|calendar|flow|matrix)[A-Z]\w{0,63}$/.test(name)) throw new Error("CanopyX: there is no label '" + name + "'.");
|
|
65
|
+
let DEFAULT_LABELS=Object.freeze({searchPlaceholder:"Search",searchResults:"Search results",searchResultCount:"{count} results",searchResultCountOfTotal:"{count} of {total} results",searchResultCountOfMany:"{count} of many results",searchNoResults:"No results",searchTooShort:"Type at least {min} characters",searchWordTooShort:"Type a word of at least {min} characters",searchFailed:"Search failed: {error}",columns:"Columns",hiddenColumns:"[one]+{count} column[other]+{count} columns",visibleColumns:"Visible columns",resizeColumn:"Resize {column}",columnWidth:"{width} pixels",loading:"Loading…",loadError:"Could not load: {error} (Enter to retry)",queryFailed:"Could not update the view: {error}",showMore:"Show more ({loaded} of {total} loaded)",showMoreUnknownTotal:"Show more ({loaded} loaded)",pageLoaded:"{loaded} of {total} loaded",itemsLoaded:"{count} items",yes:"Yes",no:"No",utcTime:"{time} UTC",localTime:"{time} local time",mountError:"This view could not be displayed: {error}"});function labelsFor(...sources){const labels=Object.assign({},DEFAULT_LABELS);for(const source of sources){if(source==null)continue;if(typeof source!=="object"||Array.isArray(source))throw new Error("CanopyX: labels must be an object of strings.");Object.keys(source).forEach((name)=>{if(!Object.hasOwn(DEFAULT_LABELS,name)&&!/^(?:gridEdit|format|calendar|flow|matrix|change)[A-Z]\w{0,63}$/.test(name)) throw new Error("CanopyX: there is no label '" + name + "'.");
|
|
66
66
|
if(typeof source[name]!=="string"||!/\S/.test(source[name])) throw new Error("CanopyX: label '" + name + "' must be a string with visible text.");
|
|
67
67
|
if((name==="utcTime"||name==="localTime")&&source[name].indexOf("{time}")<0)throw new Error("CanopyX: label '"+name+"' must hold {time}.");labels[name]=source[name]})}
|
|
68
68
|
return Object.freeze(labels)}
|
|
@@ -76,7 +76,7 @@ function trusted(kind,value){if(trustPolicy===undefined){try{trustPolicy=global.
|
|
|
76
76
|
catch(_){trustPolicy=null}}
|
|
77
77
|
return trustPolicy?trustPolicy["create"+kind](value):value}
|
|
78
78
|
function hostHtml(element,html,sanitize,kind){const text=String(html??""),value=sanitize?sanitize(text,{kind}):text;if(value?.nodeType)element.replaceChildren(value);else if(typeof value==="string")element.innerHTML=trusted("HTML",value);else if(global.trustedTypes?.isHTML?.(value))element.innerHTML=value;else throw new Error("CanopyX: invalid sanitizeHtml result.")}
|
|
79
|
-
DEFAULT_LABELS=Object.freeze(Object.assign({},DEFAULT_LABELS,{gridViews:"Views",gridViewName:"View name",gridSaveView:"Save view",gridRemoveView:"Remove view",gridResetView:"Reset view",gridChooseView:"Choose a saved view",gridApply:"Apply",gridFindColumn:"Find a column…",gridShowAllColumns:"Show all",gridResetColumns:"Reset columns",gridReorderColumn:"{column}: drag, or press Alt+Up or Alt+Down to move",gridPinnedLeft:"Pinned left",gridPinnedRight:"Pinned right",gridResponsiveHidden:"Hidden at this width",gridExport:"Export",gridVisibleRows:"Visible rows",gridSelectedRows:"Selected rows",gridAllRows:"All rows",gridDownloadCsv:"Download CSV",gridCopy:"Copy",gridExportProgress:"{completed} of {total} records",gridExportReading:"{completed} records",gridExportCancelled:"Export cancelled",gridCancelExport:"Cancel export",gridMore:"More",gridPrint:"Print",gridDetails:"Record details",gridDetailsSection:"Details",gridPreviousRecord:"Previous record",gridNextRecord:"Next record",gridCloseRecord:"Close
|
|
79
|
+
DEFAULT_LABELS=Object.freeze(Object.assign({},DEFAULT_LABELS,{gridViews:"Views",gridViewName:"View name",gridSaveView:"Save view",gridRemoveView:"Remove view",gridResetView:"Reset view",gridChooseView:"Choose a saved view",gridApply:"Apply",gridFindColumn:"Find a column…",gridShowAllColumns:"Show all",gridResetColumns:"Reset columns",gridReorderColumn:"{column}: drag, or press Alt+Up or Alt+Down to move",gridPinnedLeft:"Pinned left",gridPinnedRight:"Pinned right",gridResponsiveHidden:"Hidden at this width",gridExport:"Export",gridVisibleRows:"Visible rows",gridSelectedRows:"Selected rows",gridAllRows:"All rows",gridDownloadCsv:"Download CSV",gridCopy:"Copy",gridExportProgress:"{completed} of {total} records",gridExportReading:"{completed} records",gridExportCancelled:"Export cancelled",gridCancelExport:"Cancel export",gridMore:"More",gridPrint:"Print",gridDetails:"Record details",gridDetailsSection:"Details",gridPreviousRecord:"Previous record",gridNextRecord:"Next record",gridCloseRecord:"Close"}));DEFAULT_LABELS=Object.freeze(Object.assign({},DEFAULT_LABELS,{recordBack:"Back",recordBackTo:"Back to {record}",recordTrail:"Record trail",recordShowing:"Showing {record}",recordTabs:"Record views",recordSections:"Jump to a section",recordOtherFields:"Other fields",recordShowEmpty:"Show empty fields ({count})",recordHideEmpty:"Hide empty fields",recordActions:"Record actions",recordCopyValues:"Copy values",recordCopyJson:"Copy as JSON",recordCopyLink:"Copy link",recordCopied:"Copied to the clipboard",recordPrint:"Print record",recordExportCsv:"Export CSV",recordExportJson:"Export JSON",recordOpenAll:"Open all in grid",recordLoadMore:"Load more",recordCount:"{shown} of {total}",recordItems:"{count} items",recordMore:"+{count}",recordShowAll:"Show all {count}",recordRetry:"Retry",recordLoadFailed:"Could not load the record details: {error}",recordUnavailable:"Record {id} is not available here.",recordField:"Field",recordValue:"Value",recordSection:"Section",recordBefore:"Before",recordAfter:"After",recordAdded:"Added",recordRemoved:"Removed",recordChanged:"{count} changed fields"}));function boundedPattern(source,exact=true,whole=false){const bad=()=>{throw new Error("CanopyX: pattern requires literals, character classes and at most one variable repetition anchored at the start; groups, alternatives and backreferences are unsupported.")};if(typeof source!=="string"||source.length>256)bad();let width=0,variable=0;for(let i=0;i<source.length;){const unit=source[i++];if(unit==="^"&&i===1||unit==="$"&&i===source.length)continue;if(unit==="\\"){const escape=source[i++];if(!escape||!/^[dDsSwWbBnrtfv\\.^$*+?{}\[\]()|/]$/.test(escape)) bad();
|
|
80
80
|
}else if(unit==="["){let closed=false;while(i<source.length){const c=source[i++];if(c==="\\"){const escape=source[i++];if(!escape||!/^[dDsSwWbnrtfv\\.^$*+?{}\[\]()|/-]$/.test(escape)) bad(); }
|
|
81
81
|
else if(c==="]"){closed=true;break}}
|
|
82
82
|
if(!closed)bad()}else if("()|^$*+?{}]".includes(unit))bad();let count=1;if(i<source.length&&"*+?".includes(source[i])){variable++;i++}
|
|
@@ -336,7 +336,7 @@ function hostRenderers(renderers,columns,plugins){if(![Object.prototype,null].in
|
|
|
336
336
|
Object.keys(renderers).some(id=>typeof renderers[id]!=="function"||!columns.some(column=>column.id===id)))
|
|
337
337
|
throw new Error("CanopyX: invalid column renderers.");const named=Object.assign(Object.create(null),...plugins.map(item=>item.cellRenderers));return Object.assign(Object.create(null),...columns.filter(column=>typeof column.renderer==="string"&&named[column.renderer])
|
|
338
338
|
.map(column=>({[column.id]:named[column.renderer]})),renderers)}
|
|
339
|
-
function disposeHostSlot(slot){const lifetime=slot.hostLifetime;if(!lifetime)return;delete slot.hostLifetime;lifetime.dispose()}
|
|
339
|
+
function disposeHostSlot(slot){slot.childSlots?.forEach(disposeHostSlot);const lifetime=slot.hostLifetime;if(!lifetime)return;delete slot.hostLifetime;lifetime.dispose()}
|
|
340
340
|
function disposeRowHostCells(row){row._cells?.forEach(disposeHostSlot)}
|
|
341
341
|
class HostCellContext{#controller;#cleanups;constructor(slot,column,level,expanded,index){slot.hostLifetime=this;this.column=column;this.level=level;this.expanded=expanded;this.index=index}
|
|
342
342
|
get signal(){this.#controller||=new AbortController();if(this.#cleanups===null)this.#controller.abort();return this.#controller.signal}
|
|
@@ -506,7 +506,7 @@ if(active>=0){list.children[active].setAttribute("aria-selected","false")}
|
|
|
506
506
|
active=active<0?(delta<0?hits.length-1:0):(active+delta+hits.length)%hits.length;const item=list.children[active];item.setAttribute("aria-selected","true");input.setAttribute("aria-activedescendant",item.id);item.scrollIntoView({block:"nearest"})};input.addEventListener("input",()=>{cancelNavigation();sequence++;clearTimeout(timer);hits=[];close();timer=setTimeout(run,150)});input.addEventListener("keydown",(e)=>{if(e.defaultPrevented||e.isComposing)return;if(e.key==="ArrowDown"||e.key==="ArrowUp"){move(e.key==="ArrowDown"?1:-1)}else if(e.key==="Enter"){if(!list.hidden){choose(active>=0?active:0)}}else if(e.key==="Escape"){cancelNavigation();sequence++;clearTimeout(timer);if(list.hidden){input.value=""}
|
|
507
507
|
close()}else{return}
|
|
508
508
|
e.preventDefault()});input.addEventListener("blur",()=>{cancelNavigation();sequence++;clearTimeout(timer);clearTimeout(blurTimer);blurTimer=setTimeout(close,150)});this.cancelSearch=()=>{cancelNavigation();sequence++;clearTimeout(timer);clearTimeout(blurTimer);hits=[];close()};box.appendChild(input);box.appendChild(list);box.appendChild(status);bar.appendChild(box);this.searchInput=input}});function watchFlyout(anchorElement,panel,isOpen){const position=()=>{if(!isOpen())return;const anchor=anchorElement.getBoundingClientRect(),fixed=getComputedStyle(panel).position==="fixed";const below=Math.max(0,global.innerHeight-anchor.bottom-8);const above=Math.max(0,anchor.top-8);const opensAbove=below<120&&above>below,room=opensAbove?above:below;panel.style.maxHeight=(panel.classList.contains("cx-fb")?room:Math.min(320,room))+ "px";panel.style.top=opensAbove?"auto":fixed?anchor.bottom+"px":"100%";panel.style.bottom=opensAbove?fixed?global.innerHeight-anchor.top+"px":"100%":"auto";const width=panel.getBoundingClientRect().width;panel.style.left=Math.max(8,Math.min(anchor.left,global.innerWidth-width-8))-(fixed?0:anchor.left)+ "px"};global.addEventListener("resize",position);global.addEventListener("scroll",position,true);return{position,dispose:()=>{global.removeEventListener("resize",position);global.removeEventListener("scroll",position,true)}}}
|
|
509
|
-
const PART_URL=typeof document!=="undefined"&&document.currentScript?.src;const PARTS={"tree-tools":["
|
|
509
|
+
const PART_URL=typeof document!=="undefined"&&document.currentScript?.src;const PARTS={"tree-tools":["4c6c4101089c4444","canopyx-tree-tools.510207e8f47014fd.js","canopyx-tree-tools.ef7a3fb9c9115a82.css"],"export":["8b99c0b7b0ec37c5","canopyx-export.6989ea36f5d6da7b.js"],"links":["f1ab7e32b501ce37","canopyx-links.d96addeefb3eccf5.js"],"search":["521eebd6e1bbbd35","canopyx-search.14c69f4551c69f23.js"],"link":["fa0c9e888463553b","canopyx-link.4ec39bc39fa6cf50.js","canopyx-link.8435c892613926ac.css"],"highlight":["f39423961654c1e2","canopyx-highlight.a6f93893d36ab343.js","canopyx-highlight.5b6d2e0d979f9f9b.css"],"layouts":["fa8c686f21626884","canopyx-layouts.e7250c82a6abf52e.js","canopyx-layouts.0b75738924533ee8.css"],"record-panel":["bcc06276c7933af6","canopyx-record-panel.a374fb4254f9115c.js","canopyx-record-panel.f3691d54cefaab04.css"]},PART_CODE=new Map(),partName=name=>typeof name==="string"&&/^[a-z][a-z\d-]{0,31}$/.test(name);
|
|
510
510
|
function registerPart(name,part){if(!partName(name)||!part||typeof part.version!=="string"||typeof part.install!=="function"||
|
|
511
511
|
part.requires!==undefined&&!(Array.isArray(part.requires)&&part.requires.every(partName)))throw new Error("CanopyX: invalid part.");PART_CODE.set(name,part)}
|
|
512
512
|
function definePart(View,name,label,context){const parts=View.prototype.parts||={};return parts[name]={name,label,context,parts}}
|
|
@@ -742,5 +742,5 @@ watcher.observe(host)}
|
|
|
742
742
|
function mount(root,automatic){const scope=root||document;const created=[];const showError=(host,err,api,view)=>{if(api){api.destroy();if(host.canopyx===api)delete host.canopyx}
|
|
743
743
|
const message=err&&err.message?err.message:String(err);let labels=DEFAULT_LABELS;for(const attempt of[()=>labelsFor(view&&view.labels,view&&configured.has(view.id)?configured.get(view.id).labels:null),()=>labelsFor(view&&view.labels)]){try{labels=attempt();break}catch(e){labels=DEFAULT_LABELS}}
|
|
744
744
|
const notice=document.createElement("div");notice.className="cx-mount-error";notice.setAttribute("role","alert");setText(notice,fill(labels.mountError,{error:message}));host.classList.add("cx-host");host.setAttribute("data-canopyx-mounted","true");host.setAttribute("data-cx-error",message);host.appendChild(notice);if(global.console)global.console.error(err)};const selector="[data-canopyx-host]:not([data-canopyx-mounted])";(scope.matches?.(selector)?[scope]:scope.querySelectorAll(selector)).forEach((host)=>{const config=host.querySelector("script.cx-config"),mode=host.getAttribute("data-cx-mount");if(!config||(automatic===true&&mode==="manual")){return}
|
|
745
|
-
if(mode==="visible"&&host!==scope&&global.IntersectionObserver)return mountWhenVisible(host);watcher?.unobserve(host);host.setAttribute("data-canopyx-mounted","true");let view=null;try{view=JSON.parse(config.textContent);if(view===Object(view))parsedViews.add(view);const flow=view&&view.kind==="flow"&&typeof FLOW_API==="object",matrix=view&&view.type==="matrix"&&typeof MATRIX_API==="object";const create=flow?FLOW_API.createFlow:matrix?MATRIX_API.createMatrix:view&&view.type==="grid"&&typeof createDataGrid==="function"?createDataGrid:createTreeGrid;const api=create(host,Object.assign({},view&&configured.get(view.id),flow?{flow:view}:{view}));created.push(api);api.ready.catch((err)=>{if(view.type!=="grid"&&!matrix&&activeGrids.get(host)===api&&host.canopyx===api)showError(host,err,api,view)})}catch(err){showError(host,err,null,view)}});return created}
|
|
746
|
-
global.CanopyX=Object.freeze(Object.assign({protocol:PROTOCOL,createTreeGrid,configure,unconfigure,mount:(root)=>mount(root,false),sources:Object.freeze({inline:inlineSource,sidecar:sidecarSource,remote:remoteSource}),badge:hostBadge,labels:DEFAULT_LABELS,registerExportFormat,use,registerPart,setNonce},typeof GRID_API==="object"?GRID_API:{},typeof FLOW_API==="object"?FLOW_API:{},typeof MATRIX_API==="object"?MATRIX_API:{}));if(typeof document!=="undefined"){const navigation=global.performance&&performance.getEntriesByType?performance.getEntriesByType("navigation")[0]:null;if(document.readyState==="loading"||(document.readyState==="interactive"&&navigation&&navigation.domContentLoadedEventStart===0)){document.addEventListener("DOMContentLoaded",()=>mount(document,true))}else{mount(document,true)}}})(runtimeHost);const CanopyX=runtimeHost.CanopyX;const{protocol,createTreeGrid,configure,unconfigure,mount,sources,badge,labels,registerExportFormat,use,registerPart,setNonce}=CanopyX;export{protocol,createTreeGrid,configure,unconfigure,mount,sources,badge,labels,registerExportFormat,use,registerPart,setNonce};export default CanopyX;
|
|
745
|
+
if(mode==="visible"&&host!==scope&&global.IntersectionObserver)return mountWhenVisible(host);watcher?.unobserve(host);host.setAttribute("data-canopyx-mounted","true");let view=null;try{view=JSON.parse(config.textContent);if(view===Object(view))parsedViews.add(view);const flow=view&&view.kind==="flow"&&typeof FLOW_API==="object",matrix=view&&view.type==="matrix"&&typeof MATRIX_API==="object";const change=view&&typeof CHANGE_VIEW_TYPES==="object"&&Object.hasOwn(CHANGE_VIEW_TYPES,view.type)?CHANGE_VIEW_TYPES[view.type]:null;const create=flow?FLOW_API.createFlow:matrix?MATRIX_API.createMatrix:change?change:view&&view.type==="grid"&&typeof createDataGrid==="function"?createDataGrid:createTreeGrid;const api=create(host,Object.assign({},view&&configured.get(view.id),flow?{flow:view}:{view}));created.push(api);api.ready.catch((err)=>{if(view.type!=="grid"&&!matrix&&!change&&activeGrids.get(host)===api&&host.canopyx===api)showError(host,err,api,view)})}catch(err){showError(host,err,null,view)}});return created}
|
|
746
|
+
global.CanopyX=Object.freeze(Object.assign({protocol:PROTOCOL,createTreeGrid,configure,unconfigure,mount:(root)=>mount(root,false),sources:Object.freeze({inline:inlineSource,sidecar:sidecarSource,remote:remoteSource}),badge:hostBadge,labels:DEFAULT_LABELS,registerExportFormat,use,registerPart,setNonce},typeof GRID_API==="object"?GRID_API:{},typeof FLOW_API==="object"?FLOW_API:{},typeof MATRIX_API==="object"?MATRIX_API:{},typeof CHANGES_API==="object"?CHANGES_API:{}));if(typeof document!=="undefined"){const navigation=global.performance&&performance.getEntriesByType?performance.getEntriesByType("navigation")[0]:null;if(document.readyState==="loading"||(document.readyState==="interactive"&&navigation&&navigation.domContentLoadedEventStart===0)){document.addEventListener("DOMContentLoaded",()=>mount(document,true))}else{mount(document,true)}}})(runtimeHost);const CanopyX=runtimeHost.CanopyX;const{protocol,createTreeGrid,configure,unconfigure,mount,sources,badge,labels,registerExportFormat,use,registerPart,setNonce}=CanopyX;export{protocol,createTreeGrid,configure,unconfigure,mount,sources,badge,labels,registerExportFormat,use,registerPart,setNonce};export default CanopyX;
|