@gramlot/gramlot 0.3.35 → 0.3.37
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/dist/components/charts/__init__.py +1 -1
- package/dist/components/charts/assets/collection.js +9 -9
- package/dist/components/charts/assets/index.js +1 -1
- package/dist/components/charts/grammar.json +0 -30
- package/dist/components/drawing/__init__.py +1 -1
- package/dist/components/drawing/assets/collection.js +3 -3
- package/dist/components/drawing/assets/index.js +1 -1
- package/dist/components/editors/__init__.py +2 -2
- package/dist/components/editors/assets/collection.js +4 -2
- package/dist/components/editors/assets/index.js +1 -1
- package/dist/components/editors/assets/modules/addon-fit-L6JK4OJX.js +12 -0
- package/dist/components/editors/assets/modules/xterm-BF3OSWRI.js +286 -0
- package/dist/components/editors/assets/modules/xterm-UBEXZEYY.js +47 -0
- package/dist/components/editors/grammar.json +207 -0
- package/dist/components/grid/__init__.py +1 -1
- package/dist/components/grid/assets/collection.js +6 -6
- package/dist/components/grid/assets/index.js +1 -1
- package/dist/components/grid/grammar.json +0 -2
- package/dist/components/inputs/__init__.py +1 -1
- package/dist/components/inputs/assets/collection.js +8 -8
- package/dist/components/inputs/assets/index.js +1 -1
- package/dist/components/inputs/grammar.json +2 -1
- package/dist/components/layout/__init__.py +1 -1
- package/dist/components/layout/assets/collection.js +9 -9
- package/dist/components/layout/assets/index.js +1 -1
- package/dist/components/layout/grammar.json +2 -2
- package/dist/components/selection_trial/__init__.py +1 -1
- package/dist/components/selection_trial/assets/collection.js +3 -3
- package/dist/components/selection_trial/assets/index.js +1 -1
- package/dist/components/tree/__init__.py +1 -1
- package/dist/components/tree/assets/collection.js +6 -6
- package/dist/components/tree/assets/index.js +1 -1
- package/dist/components/tree/grammar.json +0 -1
- package/dist/components/uploads/__init__.py +1 -1
- package/dist/components/uploads/assets/collection.js +3 -3
- package/dist/components/uploads/assets/index.js +1 -1
- package/dist/components/uploads/grammar.json +0 -3
- package/dist/gramlot.js +1238 -627
- package/dist/gramlot.min.js +45 -45
- package/dist/libraries.json +27 -0
- package/dist/standard-collections.js +1 -1
- package/package.json +4 -3
- package/src/binding/data-binder.js +11 -3
- package/src/binding/grid-struct.js +7 -4
- package/src/binding/runtime.js +203 -46
- package/src/builder/binding.json +23 -1
- package/src/builder/gramlot-builder.d.ts +1 -4
- package/src/builder/source.js +185 -29
- package/src/chat.js +26 -20
- package/src/components/attachment-manager.js +38 -34
- package/src/components/chart-data-view.js +4 -7
- package/src/components/chart-fields.js +18 -6
- package/src/components/chart-renderer.js +10 -3
- package/src/components/chart-timeline.js +7 -5
- package/src/components/charts.js +74 -67
- package/src/components/check-box-text-editor.js +3 -3
- package/src/components/check-box-text.js +7 -22
- package/src/components/check-box-tree.js +20 -16
- package/src/components/choice-editor.js +1 -1
- package/src/components/drawing.js +47 -34
- package/src/components/editors.js +3 -1
- package/src/components/grid-cell-editor.js +72 -29
- package/src/components/grid-column-filters.js +47 -40
- package/src/components/grid-formulas.js +22 -17
- package/src/components/grid-header-interaction.js +9 -11
- package/src/components/grid-row-interaction.js +25 -24
- package/src/components/grid-row-layout.js +28 -29
- package/src/components/grid-search-box.js +3 -3
- package/src/components/grid-search.js +3 -8
- package/src/components/grid-selection.js +33 -29
- package/src/components/grid-structure.js +48 -10
- package/src/components/grid-tools.js +14 -14
- package/src/components/grid.js +83 -79
- package/src/components/image-crop-dialog.js +2 -2
- package/src/components/image-crop.js +16 -9
- package/src/components/image-uploader.js +21 -28
- package/src/components/inputs.js +19 -1
- package/src/components/registry.js +3 -5
- package/src/components/terminal.js +158 -0
- package/src/components/tray-pane.js +85 -61
- package/src/components/tree.js +332 -239
- package/src/components/upload-engine.js +10 -2
- package/src/components/uploader.js +31 -27
- package/src/editing-session.d.ts +4 -1
- package/src/editing-session.js +120 -83
- package/src/experiments/window-selection.js +4 -6
- package/src/filesystem.js +2 -2
- package/src/gramlot.js +1 -0
- package/src/handlers/device-handler.js +219 -213
- package/src/handlers/rpc-handler.d.ts +17 -0
- package/src/handlers/rpc-handler.js +22 -0
- package/src/ide-documents.js +29 -11
- package/src/ide-runtime.js +33 -31
- package/src/index-page-runtime.d.ts +2 -2
- package/src/index-page-runtime.js +67 -48
- package/src/libraries.js +9 -0
- package/src/message-port-connection.js +100 -0
- package/src/message-port-store.js +158 -0
- package/src/page-store-connection.js +14 -1
- package/src/renderer/gramlot-renderer.js +21 -2
- package/src/source-picker.d.ts +2 -2
- package/src/source-picker.js +15 -6
- package/src/stores/bag-collection-store.js +25 -7
- package/src/stores/bag-collection-view.js +23 -22
- package/src/view/controls.js +1 -1
- package/src/view/html.js +45 -20
- package/src/visual-editor-canvas.js +1 -1
- package/src/visual-editor.js +18 -19
- package/tools/gramlot-tools-inspector.js +400 -374
- package/tools/inspector-agent.js +223 -49
- package/dist/components/vizabi/__init__.py +0 -13
- package/dist/components/vizabi/assets/collection.js +0 -4
- package/dist/components/vizabi/assets/index.js +0 -3
- package/dist/components/vizabi/commands.json +0 -7
- package/dist/components/vizabi/grammar.json +0 -128
- package/src/components/vizabi-session.js +0 -66
- package/src/components/vizabi.js +0 -66
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
1
|
+
var z=Object.defineProperty;var ht=Object.getOwnPropertyDescriptor;var dt=Object.getOwnPropertyNames;var ut=Object.prototype.hasOwnProperty;var pt=(s,t)=>{for(var e in t)z(s,e,{get:t[e],enumerable:!0})},I=(s,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of dt(t))!ut.call(s,r)&&r!==e&&z(s,r,{get:()=>t[r],enumerable:!(i=ht(t,r))||i.enumerable});return s},k=(s,t,e)=>(I(s,t,"default"),e&&I(e,t,"default"));import Ut from"@gramlot/collections/tree";import{Bag as G}from"@gramlot/gramlot";import{sharedModules as mt}from"@gramlot/gramlot";var ft=s=>mt["./components/choices.js"][s];var V=ft("parseChoices");import{sharedModules as gt}from"@gramlot/gramlot";var bt=s=>gt["./components/popup.js"][s],w=bt("positionPopup");import{Bag as $}from"@gramlot/gramlot";var L=class{#t=new Set;#e;constructor(t,e){this.owner=t,this.#e=e,this.element=t.ownerDocument.createElement("gramlot-tree"),this.element.setSourceContext({...e,treeStore:()=>e.getStaticData(e.attrDatapath("values")),writeParameter:(i,r)=>{if(i!=="checkedPaths"||!t.pageContext?.isActive())return;let o=(r||"").split(",").filter(Boolean),n=(t.readControlValue()||"").split(",").filter(Boolean).filter(l=>!this.#t.has(l)||o.includes(l));for(let l of o)n.includes(l)||n.push(l);let c=n.join(",")||null;c!==t.readControlValue()&&t.acceptTreeValue(c)},readRelativeData:()=>t.readControlValue(),setRelativeData:(i,r)=>{t.pageContext?.isActive()&&(r||null)!==t.readControlValue()&&t.acceptTreeValue(r||null)}}),t.control.append(this.element)}options(){let{identifier:t,labelAttribute:e}=this.owner.parameters,i=this.#e.getStaticData(this.#e.attrDatapath("values"));if(!(i instanceof $))throw new TypeError("hierarchical checkBoxText requires a Bag in values");let r=[],o=new Set,a=new Set,n=(c,l)=>{if(a.has(c))throw new TypeError("Hierarchical options require an acyclic Bag");a.add(c);for(let h of c.getNodes()){let d=l?`${l}.${h.label}`:h.label,u=t?h.getAttr(t):d;if(typeof u!="string"||!u||u.includes(",")||o.has(u))throw new TypeError("Hierarchical option identifiers must be unique comma-free text on every loaded node");let b=e?h.getAttr(e)??h.label:h.label;if(typeof b!="string")throw new TypeError("Hierarchical captions must be text");o.add(u),r.push({id:u,path:d,caption:b,disabled:h.attr.checked==="disabled:on"||h.attr.checked==="disabled:off"}),h.staticValue instanceof $&&n(h.staticValue,d)}a.delete(c)};return n(i,""),r}project(t){let e=this.owner.parameters;this.#t=new Set(this.options().map(r=>r.path)),this.element.inert=!!(e.disabled||e.readonly),this.element.setAttribute("aria-disabled",String(this.element.inert));let i=e.identifier?{[`checked_${e.identifier}`]:"value"}:{checkedPaths:t};this.element.projectAttributes({...i,checkChildren:e.checkChildren,labelAttribute:e.labelAttribute??null,hideValues:!0})}focus(){this.element.shadowRoot.querySelector("[role=treeitem]")?.focus()}dispose(){this.element.remove()}};var N=class{constructor(t){this.owner=t;let e=t.ownerDocument;this.input=e.createElement("input"),this.input.type="text",this.input.className="summary",this.input.placeholder="Select options",this.input.autocomplete="off",this.input.setAttribute("aria-label","Selected descriptions"),this.list=e.createElement("datalist"),this.list.id="description-options",this.input.setAttribute("list",this.list.id),this.toggle=e.createElement("button"),this.toggle.type="button",this.toggle.className="choice-toggle",this.toggle.setAttribute("aria-label","Show options"),this.element=e.createElement("div"),this.element.className="summary-row choice-field",this.element.append(this.input,this.toggle,this.list),this.toggle.addEventListener("click",()=>t.openChoices()),this.input.addEventListener("input",i=>{this.locked||(t.cancelValidation(),this.state.draft={text:this.input.value,value:t.readControlValue()},t.pageContext?.formSelectionError("Confirm the edited selection."),i.isComposing||(t.closeChoices(),this.suggest()))}),this.input.addEventListener("compositionend",()=>this.suggest()),this.input.addEventListener("change",()=>this.commit()),this.input.addEventListener("keydown",i=>{i.isComposing||this.locked||(i.key==="Enter"&&(i.preventDefault(),this.commit()),i.key==="Escape"&&(i.preventDefault(),t.cancelValidation(),this.clear(),t.closeChoices(),t.updateSummary()))}),t.control.addEventListener("change",i=>{i.target!==t.control&&this.clear()})}get state(){return this.source._internal}get locked(){return this.input.disabled||this.input.readOnly||!this.owner.pageContext?.isActive()}attach(t){this.source=t,t._internal.draft??=null}clear(){this.source&&(this.state.draft=null),this.owner.pageContext?.formSelectionError(""),this.input.setCustomValidity(""),this.input.setAttribute("aria-invalid","false"),this.owner.error("")}project(t,e){this.source&&this.state.draft&&!Object.is(this.state.draft.value,t)&&this.clear();let i=this.source&&this.state.draft?this.state.draft.text:e??"";this.input.value!==i&&(this.input.value=i),this.toggle.disabled=this.input.disabled,this.element.hidden=this.input.hidden,this.suggest()}suggest(){let t=this.input.value,e=t.lastIndexOf(",")+1,i=t.slice(0,e),r=t.slice(e).trim().toLocaleLowerCase(),o=this.owner.textOptions(),a=new Set(i.split(",").map(n=>n.trim().toLocaleLowerCase()));this.list.replaceChildren(...o.filter(n=>!n.disabled&&!a.has(n.caption.toLocaleLowerCase())&&n.caption.toLocaleLowerCase().includes(r)).map(n=>{let c=this.owner.ownerDocument.createElement("option");return c.value=i+n.caption,c.label=n.id,c}))}candidate(){if(!this.source||!this.state.draft)return{value:this.owner.readControlValue()};let t=this.state.draft.text.trim();if(!t)return{value:null};let e=this.owner.textOptions(),i=[],r=(this.state.draft.value||"").split(",");for(let o of t.split(",").map(a=>a.trim())){let a=e.filter(n=>!n.disabled&&n.caption.toLocaleLowerCase()===o.toLocaleLowerCase());if(a.length!==1){if(o&&r.includes(o)&&!e.some(n=>n.id===o)){i.push(o);continue}return{error:a.length>1?"Ambiguous description: choose its checkbox.":"Choose a description from the options."}}i.includes(a[0].id)||i.push(a[0].id)}return{value:i.join(",")||null}}commit(){this.locked||!this.state.draft||this.owner.control.dispatchEvent(new this.owner.ownerDocument.defaultView.Event("change",{bubbles:!0}))}reject(t){this.input.setCustomValidity(t),this.input.setAttribute("aria-invalid","true"),this.owner.error(t),this.owner.pageContext?.formSelectionError(t)}};import{sharedModules as xt}from"@gramlot/gramlot";var yt=s=>xt["./components/choice-field-styles.js"][s],B=yt("choiceFieldStyles");function Z(s){return class extends s{#t;#e;#r;#i;#o;#s;#n=[];#a=!0;#l=!1;#h;constructor(){super();let t=this.ownerDocument;this.#t=new N(this),this.summary=this.#t.input,this.summary.hidden=!0,this.summary.className="summary",this.summary.setAttribute("aria-haspopup","dialog"),this.summary.setAttribute("aria-expanded","false"),this.panel=t.createElement("div"),this.panel.id="checkbox-options",this.panel.setAttribute("popover","manual"),this.panel.setAttribute("role","dialog"),this.panel.setAttribute("aria-label","Options"),this.panel.hidden=!0,this.summary.setAttribute("aria-controls",this.panel.id),this.optionsMessage=t.createElement("div"),this.optionsMessage.setAttribute("role","status");let e=t.createElement("style");e.textContent=B+`.summary{min-width:0;box-sizing:border-box;font:inherit;text-align:start;width:100%;padding:var(--gramlot-field-padding,.25em .5em);min-height:var(--gramlot-field-height,28px);border:1px solid var(--gramlot-border-control,#7a8798);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-field-background,Canvas);color:var(--gramlot-ink,CanvasText)}
|
|
2
2
|
.summary:disabled{opacity:.6}.summary[aria-invalid=true]{border-color:var(--gramlot-error,#8c1d18)}
|
|
3
3
|
[popover]{position:fixed;inset:auto;margin:0;padding:8px;max-width:var(--gramlot-popup-available-width,100vw);max-height:min(20rem,var(--gramlot-popup-available-height,100vh));overflow:auto;border:1px solid var(--gramlot-border-control,#7a8798);border-radius:var(--gramlot-radius-sm,4px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);font:inherit}
|
|
4
|
-
[hidden]{display:none!important}`,this.controlBox.prepend(e,this.#
|
|
4
|
+
[hidden]{display:none!important}`,this.controlBox.prepend(e,this.#t.element),this.controlBox.append(this.panel,this.optionsMessage),this.summary.addEventListener("click",()=>this.#l?this.closeChoices():this.openChoices()),this.summary.addEventListener("keydown",i=>{i.altKey&&["ArrowDown","ArrowUp"].includes(i.key)&&(i.preventDefault(),this.openChoices())}),this.panel.addEventListener("keydown",i=>{i.key==="Escape"&&(i.preventDefault(),i.stopPropagation(),this.closeChoices(),this.summary.focus())})}setSourceContext(t){this.#e=t,this.#t.attach(t.sourceNode)}get choiceType(){return"checkbox"}get multiple(){return!0}choiceOptions(){let{values:t,identifier:e,labelAttribute:i,dbtable:r,method:o,hierarchical:a}=this.parameters;if(a)return[];if(r||o)return this.#n;if(typeof t=="string")return V(t);let n=this.#e.getStaticData(this.#e.attrDatapath("values"));if(!(n instanceof G))throw new TypeError("values must be text or a Bag");let c=new Set;return n.getNodes().map(l=>{let h=b=>l.staticValue instanceof G?l.staticValue.getItem(b):l.getAttr(b),d=e?h(e):l.label,u=i?h(i):l.label;if(typeof d!="string"||!d||d.includes(",")||c.has(d)||typeof u!="string")throw new TypeError("Options require unique comma-free text codes and text captions");return c.add(d),{id:d,caption:u}})}projectAttributes(t,e){let i=this.readControlValue();this.#i=t;let r=super.projectAttributes(t,e),{values:o,popup:a,disabled:n,readonly:c,dbtable:l,method:h,hierarchical:d}=this.parameters;if(d&&(l||h))throw new TypeError("Load hierarchical values into a Bag with dataRemote, not the flat selector service");if(d&&!this.#r&&(this.#r=new L(this,this.#e)),!d&&this.#r&&(this.#r.dispose(),this.#r=null),(l||h)&&o!=="")throw new TypeError("Remote choices and values are mutually exclusive");this.summary.hidden=!a,this.summary.disabled=!!(n||c||!this.#a);for(let v of this.control.querySelectorAll("input"))v.disabled=this.summary.disabled;(!a||this.summary.disabled)&&this.closeChoices();let u=a?this.panel:this.controlBox;this.control.parentNode!==u&&u.append(this.control),this.writeControlValue(i);let b=Object.fromEntries(Object.entries(t).filter(([v])=>["dbtable","method","caption_field","order_by","condition"].includes(v)||v.startsWith("condition_"))),y=JSON.stringify(b);y!==this.#s&&(this.#s=y,this.loadOptions(b));for(let v of Object.keys(r))v.startsWith("condition_")&&delete r[v];return r}setPageContext(t){super.setPageContext(t),this.#s=void 0,this.projectAttributes(this.#i)}async loadOptions(t){if(this.#o?.abort(),this.#o=null,!(t.dbtable||t.method)){this.#a=!0,this.optionsMessage.textContent="",this.summary.disabled=!!(this.parameters.disabled||this.parameters.readonly);for(let o of this.control.querySelectorAll("input"))o.disabled=this.summary.disabled;return}if(!this.pageContext)return;let e=new AbortController;this.#o=e,this.closeChoices(),this.#a=!1,this.summary.disabled=!0;for(let o of this.control.querySelectorAll("input"))o.disabled=!0;this.optionsMessage.textContent="Loading options\u2026",this.summary.setAttribute("aria-busy","true");let{method:i,...r}=t;try{for(let c of Object.keys(r))if(c.startsWith("condition_")){let l=c.slice(10);if(!l||l.startsWith("_")||["limit","dbtable","condition","caption_field","order_by"].includes(l))throw new TypeError("Invalid condition parameter");r[l]=r[c],delete r[c]}let o=await this.pageContext.remote(i||"dbSelect",{...r,_querystring:"",limit:null},e.signal);if(e.signal.aborted||!this.pageContext.isActive())return;if(!o||!Array.isArray(o.rows)||typeof o.identifier!="string"||typeof o.caption!="string")throw new TypeError("Options require {rows, identifier, caption}");let a=new Set;this.#n=o.rows.map(c=>{let l=c[o.identifier],h=c[o.caption];if(!(typeof l=="string"||Number.isSafeInteger(l))||l===""||String(l).includes(",")||typeof h!="string"||a.has(String(l)))throw new TypeError("Invalid or duplicate option");let d=String(l);return a.add(d),{id:d,caption:h}}),this.#a=!0;let n=this.readControlValue();this.projectAttributes(this.#i),this.writeControlValue(n),this.optionsMessage.textContent=""}catch(o){!e.signal.aborted&&this.pageContext.isActive()&&(this.optionsMessage.textContent=o.message)}finally{this.#o===e&&this.summary.setAttribute("aria-busy","false")}}acceptTreeValue(t){this.#t.clear(),super.writeControlValue(t),this.control.dispatchEvent(new this.ownerDocument.defaultView.Event("change",{bubbles:!0}))}restoreFormValue(t){this.#t.clear(),super.restoreFormValue(t)}textOptions(){return this.#r?this.#r.options():this.choiceOptions()}acceptControlValue(){let t=this.#t.candidate();return t.error?(this.#t.reject(t.error),{ok:!1}):(this.pageContext?.formSelectionError(""),this.validateCandidate(t.value,e=>{this.#t.clear(),this.writeControlValue(e)}))}writeControlValue(t){super.writeControlValue(t),this.#r?.project(t),this.updateSummary(t)}updateSummary(t=this.readControlValue()){let e=new Map(this.textOptions().map(r=>[r.id,r.caption])),i=t?t.split(",").map(r=>e.get(r)??r).join(","):null;this.#t.project(t,i),this.pageContext?.selectionDisplay(i,t)}openChoices(){if(this.#l||!this.parameters.popup||this.summary.disabled||!this.pageContext?.isActive())return;this.panel.hidden=!1,this.panel.showPopover(),this.#l=!0,this.summary.setAttribute("aria-expanded","true"),w(this.panel,this.summary,{matchWidth:!0});let t=this.ownerDocument,e=t.defaultView,i=o=>{o.composedPath().includes(this)||this.closeChoices()},r=()=>w(this.panel,this.summary,{matchWidth:!0});t.addEventListener("pointerdown",i),t.addEventListener("focusin",i),e.addEventListener("resize",r),e.addEventListener("scroll",r,!0),this.#h=()=>{t.removeEventListener("pointerdown",i),t.removeEventListener("focusin",i),e.removeEventListener("resize",r),e.removeEventListener("scroll",r,!0)},this.summary.focus()}closeChoices(){this.#l&&(this.#h(),this.#h=null,this.panel.hidePopover(),this.panel.hidden=!0,this.#l=!1,this.summary.setAttribute("aria-expanded","false"))}focus(t){this.parameters.popup?this.summary.focus(t):this.#r?this.#r.focus():super.focus(t)}releaseControl(){this.closeChoices(),this.#o?.abort(),this.#r?.dispose(),this.#r=null,super.releaseControl()}}}import{Bag as Tt}from"@gramlot/gramlot";var p={};pt(p,{defineCollection:()=>O});k(p,Se);import*as Se from"@gramlot/gramlot/components";import{defineCollection as wt}from"@gramlot/gramlot/components";function O(s){if(s.name!=="inputs")throw new Error("Unexpected bundled collection");let t=[],e={};s.css?.forEach((i,r)=>{i.href=t[r].href});for(let[i,r]of Object.entries(s.assets??{}))r.href=e[i].href;return wt({...s,css:t,assets:e})}import{sharedModules as vt}from"@gramlot/gramlot";var Ct=s=>vt["./components/parameters.js"][s];var Y=Ct("projectParameters");function P(s){return class extends s{constructor(){super();let t=this.attachShadow({mode:"open"}),e=this.ownerDocument.createElement("style");e.textContent=`:host{box-sizing:border-box;display:block;min-width:0;font:inherit;color:var(--gramlot-ink,CanvasText)}
|
|
5
5
|
*,*::before,*::after{box-sizing:border-box}.control-box{min-width:0}slot{display:contents}
|
|
6
|
-
::slotted(*){min-width:0;max-width:100%}`,this.controlBox=this.ownerDocument.createElement("div"),this.controlBox.className="control-box",this.control=this.controlBox,this.control.id="control",this.control.append(this.ownerDocument.createElement("slot")),t.append(e,this.controlBox)}projectAttributes(t){return
|
|
6
|
+
::slotted(*){min-width:0;max-width:100%}`,this.controlBox=this.ownerDocument.createElement("div"),this.controlBox.className="control-box",this.control=this.controlBox,this.control.id="control",this.control.append(this.ownerDocument.createElement("slot")),t.append(e,this.controlBox)}projectAttributes(t){return Y(this,t)}}}P.parameters={};import{sharedModules as Et}from"@gramlot/gramlot";var kt=s=>Et["./renderer/attributes.js"][s],E=kt("SVG_NS");var X=`
|
|
7
7
|
:host{display:inline-block;font:inherit;color:var(--gramlot-ink,CanvasText)}
|
|
8
8
|
.control-box{display:flex;align-items:center;gap:.35rem}
|
|
9
9
|
button{font:inherit;color:inherit;cursor:pointer;border:0;background:transparent;border-radius:var(--gramlot-radius-sm,4px)}
|
|
@@ -27,7 +27,7 @@ li button{display:block;width:100%;text-align:start;padding:.55rem .35rem}
|
|
|
27
27
|
.previous,.notice{color:var(--gramlot-text-secondary,GrayText)}
|
|
28
28
|
.arrow{padding:0 .5rem}
|
|
29
29
|
.notice{font-size:.9em;margin:.5rem .35rem .15rem}
|
|
30
|
-
`;var
|
|
30
|
+
`;var K=(0,p.defineComponent)({name:"editingStatus",tag:"gramlot-editing-status",base:P,sourceContext:!0,parameters:{},implementation:s=>class extends s{#t;#e;#r=new Map;#i;#o;#s;#n;#a;constructor(){super();let t=this.ownerDocument,e=t.createElement("style");e.textContent=X,this.shadowRoot.append(e),this.control.replaceChildren(),this.control.setAttribute("role","group"),this.control.setAttribute("aria-label","Editing reports");for(let[o,a,n]of[["errors","Errors","M12 3L22 21H2ZM12 9V14M12 17V17.1"],["changes","Changes","M4 5H14M4 10H10M4 15H8M13 20L20 13L17 10L10 17L9 21Z"]]){let c=t.createElement("button");c.type="button",c.dataset.kind=o,c.setAttribute("aria-haspopup","dialog"),c.setAttribute("aria-expanded","false"),c.setAttribute("aria-controls","editing-report");let l=t.createElementNS(E,"svg");l.setAttribute("viewBox","0 0 24 24"),l.setAttribute("aria-hidden","true");let h=t.createElementNS(E,"path");h.setAttribute("d",n),l.append(h);let d=t.createElement("span");d.textContent=a;let u=t.createElement("span");u.className="count",u.textContent="0",c.append(l,d,u),this.control.append(c),this.#r.set(o,{button:c,count:u}),c.addEventListener("click",()=>{let b=this.#i.matches(":popover-open");if(b&&this.#a===o){this.#i.hidePopover();return}this.#a=o,this.#u(),b||this.#i.showPopover(),this.#h(),w(this.#i,c,{align:"end"})})}this.#i=t.createElement("section"),this.#i.id="editing-report",this.#i.className="report",this.#i.setAttribute("popover","auto"),this.#i.setAttribute("role","dialog"),this.#i.setAttribute("aria-labelledby","report-title");let i=t.createElement("header");this.#o=t.createElement("strong"),this.#o.id="report-title";let r=t.createElement("button");r.type="button",r.textContent="\xD7",r.setAttribute("aria-label","Close report"),r.addEventListener("click",()=>this.#i.hidePopover()),i.append(this.#o,r),this.#s=t.createElement("ul"),this.#n=t.createElement("p"),this.#n.className="notice",this.#n.setAttribute("role","status"),this.#i.append(i,this.#s,this.#n),this.shadowRoot.append(this.#i),this.#i.addEventListener("toggle",()=>this.#h())}setSourceContext(t){if(this.#e?.(),this.#e=null,this.#t=t.sourceNode.formState,!this.#t)throw new Error("editingStatus requires a shared editing session.");this.#l()}connectedCallback(){this.#l()}disconnectedCallback(){this.#e?.(),this.#e=null,this.#i.matches(":popover-open")&&this.#i.hidePopover()}#l(){!this.#t||this.#e||!this.isConnected||(this.#e=this.#t.subscribe(()=>this.#d()),this.#d())}#h(){let t=this.#i.matches(":popover-open");for(let[e,{button:i}]of this.#r)i.setAttribute("aria-expanded",String(t&&e===this.#a))}#d(){this.#r.get("errors").count.textContent=String(this.#t.errorEntries.length),this.#r.get("changes").count.textContent=String(this.#t.changeEntries.length),this.#r.get("errors").button.classList.toggle("invalid",this.#t.errorEntries.length>0),this.#i.matches(":popover-open")&&this.#u()}#c(t,e){return e?t==null?"\u2205":t instanceof Tt?`${t.length} fields`:t instanceof Date?t.toLocaleString():String(t):"Not present"}#u(){let t=this.#a==="errors",e=t?this.#t.errorEntries:this.#t.changeEntries;this.#o.textContent=t?"Validation errors":"Unsaved changes",this.#n.textContent=e.length?"Select an entry to return to its field.":t?"No validation errors.":"No changes since the accepted snapshot.";let i=this.shadowRoot.activeElement?.dataset.path;this.#s.replaceChildren();for(let r of e){let o=this.ownerDocument,a=o.createElement("li"),n=o.createElement("button");n.type="button",n.dataset.path=r.path;let c=o.createElement("span");c.className="field",c.textContent=r.path.slice(this.#t.path?this.#t.path.length+1:0);let l=o.createElement("span");if(l.className="detail",t)l.textContent=r.message;else{let h=o.createElement("span");h.className="previous",h.textContent=this.#c(r.previous,r.existed);let d=o.createElement("span");d.className="arrow",d.textContent="\u2192";let u=o.createElement("span");u.className="current",u.textContent=this.#c(r.current,r.exists),l.append(h,d,u)}n.append(c,l),a.append(n),this.#s.append(a),n.addEventListener("click",()=>{this.#t.focusField(r.path)?this.#i.hidePopover():this.#n.textContent="This field is not visible. Check the grid filter or whether the row still exists."}),r.path===i&&n.focus({preventScroll:!0})}}}});import{sharedModules as St}from"@gramlot/gramlot";var M=s=>St["./components/bases.js"][s],U=M("ChoiceGroup"),g=M("NativeControl"),J=M("controlElement");import{sharedModules as Dt}from"@gramlot/gramlot";var At=s=>Dt["./components/labelbox.js"][s],m=At("Labelbox");import{sharedModules as Vt}from"@gramlot/gramlot";var Lt=s=>Vt["@genrojs/toolbox"][s],Q=Lt("parseDateExpression");function x(s,t,e){let i=new Date(0);return i.setUTCFullYear(s,t,e),i}function S(s){if(s!==null&&(!(s instanceof Date)||!Number.isFinite(s.getTime())||s.getUTCHours()||s.getUTCMinutes()||s.getUTCSeconds()||s.getUTCMilliseconds()))throw new TypeError("Expected a civil Date at UTC midnight")}var j=(s,t)=>s===t||s instanceof Date&&t instanceof Date&&s.getTime()===t.getTime(),Nt=s=>s.toISOString().slice(0,10),T=class{constructor(t,e){this.container=t,this.select=e,this.value=null;let i=t.ownerDocument,r=i.createElement("style");r.textContent=`.calendar{width:var(--gramlot-calendar-width,18em);max-width:100%;font:inherit;color:inherit}
|
|
31
31
|
.calendar button{min-height:var(--gramlot-touch-target,0px);font:inherit;color:inherit;border:1px solid transparent;border-radius:3px;background:transparent;cursor:pointer;padding:.25em}
|
|
32
32
|
.calendar button:focus-visible{outline:2px solid var(--gramlot-focus-ring,#4369c5);outline-offset:-2px}
|
|
33
33
|
.calendar button:disabled{opacity:.5;cursor:default}
|
|
@@ -37,14 +37,14 @@ li button{display:block;width:100%;text-align:start;padding:.55rem .35rem}
|
|
|
37
37
|
.calendar-weekday{text-align:center;font-size:.85em;color:var(--gramlot-text-secondary,#64748b)}
|
|
38
38
|
.calendar button[aria-pressed=true]{background:var(--gramlot-brand-blue,#4369c5);color:white}
|
|
39
39
|
.calendar button[data-today=true]{border-color:var(--gramlot-brand-blue,#4369c5)}
|
|
40
|
-
.calendar button:hover:not(:disabled){background:var(--gramlot-selected,#e5ebf7);color:var(--gramlot-ink,#203047)}`,t.classList.add("calendar"),this.header=i.createElement("div"),this.header.className="calendar-header",this.month=i.createElement("span"),this.month.className="calendar-month",this.month.setAttribute("aria-live","polite"),this.previous=this.button("\u2039","Previous month",()=>this.moveMonth(-1)),this.next=this.button("\u203A","Next month",()=>this.moveMonth(1)),this.header.append(this.previous,this.month,this.next),this.grid=i.createElement("div"),this.grid.className="calendar-grid",this.footer=i.createElement("div"),this.footer.className="calendar-footer",this.todayButton=this.button("Today","Today",()=>this.choose(this.today)),this.clearButton=this.button("Clear","Clear date",()=>this.choose(null)),this.footer.append(this.todayButton,this.clearButton),t.append(r,this.header,this.grid,this.footer),this.grid.addEventListener("keydown",o=>{if(this.locked||!o.target.dataset.date)return;let a={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7};if(o.key in a)o.preventDefault(),this.active=x(this.active.getUTCFullYear(),this.active.getUTCMonth(),this.active.getUTCDate()+a[o.key]);else if(o.key==="Home"||o.key==="End"){o.preventDefault();let n=(this.active.getUTCDay()+6)%7;this.active=x(this.active.getUTCFullYear(),this.active.getUTCMonth(),this.active.getUTCDate()+(o.key==="Home"?-n:6-n))}else if(o.key==="PageUp"||o.key==="PageDown"){o.preventDefault(),this.moveMonth(o.key==="PageUp"?-1:1,!0);return}else return;this.render(),this.focusDay()})}button(t,e,i){let r=this.container.ownerDocument.createElement("button");return r.type="button",r.textContent=t,r.setAttribute("aria-label",e),r.addEventListener("click",i),r}configure({value:t,locale:e,workdate:i,locked:r=!1}){S(t);let o=new Date;this.today=i?x(...i.split("-").map((n,
|
|
40
|
+
.calendar button:hover:not(:disabled){background:var(--gramlot-selected,#e5ebf7);color:var(--gramlot-ink,#203047)}`,t.classList.add("calendar"),this.header=i.createElement("div"),this.header.className="calendar-header",this.month=i.createElement("span"),this.month.className="calendar-month",this.month.setAttribute("aria-live","polite"),this.previous=this.button("\u2039","Previous month",()=>this.moveMonth(-1)),this.next=this.button("\u203A","Next month",()=>this.moveMonth(1)),this.header.append(this.previous,this.month,this.next),this.grid=i.createElement("div"),this.grid.className="calendar-grid",this.footer=i.createElement("div"),this.footer.className="calendar-footer",this.todayButton=this.button("Today","Today",()=>this.choose(this.today)),this.clearButton=this.button("Clear","Clear date",()=>this.choose(null)),this.footer.append(this.todayButton,this.clearButton),t.append(r,this.header,this.grid,this.footer),this.grid.addEventListener("keydown",o=>{if(this.locked||!o.target.dataset.date)return;let a={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7};if(o.key in a)o.preventDefault(),this.active=x(this.active.getUTCFullYear(),this.active.getUTCMonth(),this.active.getUTCDate()+a[o.key]);else if(o.key==="Home"||o.key==="End"){o.preventDefault();let n=(this.active.getUTCDay()+6)%7;this.active=x(this.active.getUTCFullYear(),this.active.getUTCMonth(),this.active.getUTCDate()+(o.key==="Home"?-n:6-n))}else if(o.key==="PageUp"||o.key==="PageDown"){o.preventDefault(),this.moveMonth(o.key==="PageUp"?-1:1,!0);return}else return;this.render(),this.focusDay()})}button(t,e,i){let r=this.container.ownerDocument.createElement("button");return r.type="button",r.textContent=t,r.setAttribute("aria-label",e),r.addEventListener("click",i),r}configure({value:t,locale:e,workdate:i,locked:r=!1}){S(t);let o=new Date;this.today=i?x(...i.split("-").map((n,c)=>Number(n)-(c===1?1:0))):x(o.getFullYear(),o.getMonth(),o.getDate()),(!this.active||!j(this.value,t))&&(this.active=t??this.today),this.value=t,this.locale=e,this.locked=r;let a=this.grid.contains(this.container.getRootNode().activeElement);this.render(),a&&!r&&this.focusDay()}choose(t){this.locked||(this.value=t,this.active=t??this.today,this.render(),this.focusDay(),this.select(t))}moveMonth(t,e=!1){if(this.locked)return;let i=this.active.getUTCFullYear(),r=this.active.getUTCMonth()+t;this.active=x(i,r,Math.min(this.active.getUTCDate(),x(i,r+1,0).getUTCDate())),this.render(),e&&this.focusDay()}render(){let t=this.active.getUTCFullYear(),e=this.active.getUTCMonth();this.month.textContent=new Intl.DateTimeFormat(this.locale,{month:"long",year:"numeric",timeZone:"UTC"}).format(this.active),this.grid.replaceChildren();let i=new Intl.DateTimeFormat(this.locale,{weekday:"short",timeZone:"UTC"});for(let a=0;a<7;a++){let n=this.container.ownerDocument.createElement("span");n.className="calendar-weekday",n.textContent=i.format(x(2024,0,1+a)),this.grid.append(n)}let r=(x(t,e,1).getUTCDay()+6)%7;for(let a=0;a<r;a++)this.grid.append(this.container.ownerDocument.createElement("span"));let o=new Intl.DateTimeFormat(this.locale,{dateStyle:"full",timeZone:"UTC"});for(let a=1;a<=x(t,e+1,0).getUTCDate();a++){let n=x(t,e,a),c=this.button(String(a),o.format(n),()=>this.choose(n));c.dataset.date=Nt(n),c.dataset.today=String(j(n,this.today)),c.setAttribute("aria-pressed",String(j(n,this.value))),c.disabled=this.locked,c.tabIndex=a===this.active.getUTCDate()?0:-1,this.grid.append(c)}for(let a of[this.previous,this.next,this.todayButton,this.clearButton])a.disabled=this.locked}focusDay(){this.grid.querySelector('button[tabindex="0"]')?.focus()}};function R(s){return class extends J(s){#t=null;constructor(){super(),this.control=this.ownerDocument.createElement("div"),this.control.id="control",this.control.setAttribute("role","group"),this.controlBox.append(this.control),this.calendarView=new T(this.control,t=>{this.#t=t,this.control.dispatchEvent(new this.ownerDocument.defaultView.Event("change",{bubbles:!0}))})}get commitOnChange(){return!0}readControlValue(){return this.#t}sameControlValue(t,e){return j(t,e)}writeControlValue(t){S(t),this.#t=t,this.syncCalendar()}projectAttributes(t,e){let i=super.projectAttributes(t,e);return this.control.disabled=!!this.parameters.disabled,this.control.readOnly=!!this.parameters.readonly,this.syncCalendar(),i}syncCalendar(){!this.pageContext||!this.parameters||this.calendarView.configure({value:this.#t,locale:this.parameters.locale??this.pageContext.locale,workdate:this.parameters.workdate,locked:this.control.disabled||this.control.readOnly})}focus(){this.calendarView.focusDay()}releaseControl(){this.calendarView.locked=!0}}}R.parameters={value:{dtype:"D",nullable:!0,binding:"twoWay"},disabled:{dtype:"B",default:!1,binding:"read"},readonly:{dtype:"B",default:!1,binding:"read"},locale:{dtype:"T",nullable:!0,binding:"read"},workdate:{dtype:"T",nullable:!0,binding:"read"}};var Bt=(s,t,e)=>s instanceof Date&&t instanceof Date?s.getTime()===t.getTime():e(s)&&e(t)?s.eq(t):Object.is(s,t),jt=s=>!["NaN","Infinity","-Infinity"].includes(s.toString()),D=s=>String(s).padStart(2,"0");function tt(s){let t=new Intl.NumberFormat(s).formatToParts(-12345.6);return{decimal:t.find(e=>e.type==="decimal").value,group:t.find(e=>e.type==="group")?.value,minus:t.find(e=>e.type==="minusSign").value}}function A(s){return class extends g(s){#t=null;#e=!1;#r=!1;#i=null;#o=null;#s=!1;constructor(){super(),this.control.addEventListener("focus",()=>{if(this.#r=!0,!this.#e){let t=this.control.selectionStart,e=this.control.selectionEnd,i=t===0&&e===this.control.value.length;this.#i=this.context(),this.display(),this.control.setSelectionRange(t,i?this.control.value.length:e)}}),this.control.addEventListener("input",()=>{this.#s||(this.#o=null),this.#e=!0,this.#i??=this.context(),this.error("")}),this.control.addEventListener("blur",()=>{this.#r=!1,this.#e&&this.control.dispatchEvent(new this.ownerDocument.defaultView.Event("change")),this.#e||(this.#i=null,this.display())}),this.control.addEventListener("keydown",t=>{t.isComposing||this.control.disabled||this.control.readOnly||(t.key==="Escape"?(t.preventDefault(),this.#o=null,this.#e=!1,this.#i=null,this.pageContext.form&&this.pageContext.formClearDraft(),this.error(""),this.display(),this.pageContext.form&&this.validateCandidate(this.#t,()=>{})):t.key==="Enter"&&(t.preventDefault(),this.control.dispatchEvent(new this.ownerDocument.defaultView.Event("change"))))})}createControl(){let t=this.ownerDocument.createElement("input");return t.type="text",t}context(){return{locale:this.parameters.locale??this.pageContext.locale,timeZone:this.pageContext.timeZone,pattern:this.parameters.format,dtype:this.parameters.dtype}}readControlValue(){return this.#t}readDraftValue(){return this.#e?this.control.value.trim()===""?null:this.parse(this.control.value,this.#i??this.context()):this.#t}sameControlValue(t,e){return Bt(t,e,this.pageContext.isDecimal)}writeControlValue(t){if(this.checkValue(t),this.sameControlValue(t,this.#t)){!this.#e&&!this.#r&&this.display();return}this.#t=t,this.#o=null,this.#e=!1,this.#i=null,this.error(""),this.display()}selectControlValue(t){this.checkValue(t),this.control.value=t===null?"":this.editText(t,this.context()),this.#o={value:t},this.#s=!0;try{for(let e of["input","change"])this.control.dispatchEvent(new this.ownerDocument.defaultView.Event(e,{bubbles:!0}))}finally{this.#s=!1}}acceptControlValue(){if(!this.#e)return{ok:!1};try{let t=this.#o?this.#o.value:this.readDraftValue();return this.checkValue(t),this.validateCandidate(t,e=>{this.checkValue(e),this.acceptDraft(e,this.#o?null:this.control.value,this.#i??this.context()),this.#t=e,this.#o=null,this.#e=!1,(!this.#r||!this.sameControlValue(t,e))&&(this.#i=null,this.display())})}catch(t){return this.pageContext.form&&this.pageContext.formParseError(t.message),this.error(t.message),{ok:!1}}}acceptDraft(t,e,i){}restoreFormDraft(t){this.#e=!0,this.#i=this.context(),this.control.value=t}restoreFormValue(t){this.#e=!1,this.#i=null,this.#o=null,this.error(""),this.writeControlValue(t),this.display()}display(){if(!this.pageContext||!this.parameters)return;let t=this.#t==null?"":this.#r?this.editText(this.#t,this.#i??this.context()):this.pageContext.format(this.#t,this.context());this.control.value!==t&&(this.control.value=t)}projectAttributes(t,e){let i=super.projectAttributes(t,e);return!this.#e&&!this.#r&&this.display(),i}}}A.parameters={...g.parameters,placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"},locale:{dtype:"T",nullable:!0,binding:"read"},format:{dtype:"T",nullable:!0,binding:"read"}};var rt=s=>class extends s{createControl(){let t=super.createControl();return t.inputMode="decimal",t}static validationValueCheck(t){let e=t.isDecimal;return i=>et(i,e)}checkValue(t){et(t,this.pageContext.isDecimal)}context(){return{...super.context(),pattern:this.parameters.format??"0.####################"}}editText(t,e){return String(t).replace(".",tt(e.locale).decimal)}parse(t,e){let{decimal:i,group:r,minus:o}=tt(e.locale),a=t.trim().replaceAll(o,"-");if(r&&a.includes(r))throw new Error("Enter the number without grouping separators.");if(a=a.replace(i,"."),!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(a))throw new Error("Enter a complete number.");let n=e.dtype==="N"||this.pageContext.isDecimal(this.readControlValue());if(n&&this.pageContext.getDecimalLibrary()==="number")throw new Error("A Decimal backend is required.");let c=n?this.pageContext.createDecimal(a):Number(a);if(this.checkValue(c),e.dtype==="L"&&!Number.isSafeInteger(c))throw new Error("Enter a safe integer.");for(let[l,h]of[["min",-1],["max",1]]){let d=this.parameters[l];if(d!=null&&(n?c.cmp(d):Math.sign(c-d))===h)throw new Error(`${l}: ${d}`)}return c}},ot=s=>class extends s{#t=!1;#e;constructor(){super();let t=this.ownerDocument,e=t.createElement("style");e.textContent=`.date-entry{position:relative;max-width:100%}
|
|
41
41
|
.date-entry #control{display:block;min-width:0;width:100%}
|
|
42
42
|
.date-entry:has(.calendar-toggle:not([hidden])) #control{padding-right:calc(var(--gramlot-touch-target,1.6em) + .4em)}
|
|
43
43
|
.calendar-toggle{position:absolute;right:0;top:0;bottom:0;width:var(--gramlot-touch-target,1.6em);min-width:0;min-height:0;font:inherit;font-size:var(--gramlot-field-font-size,1em);line-height:inherit;padding:0;border:0;border-radius:var(--gramlot-radius-sm,4px);background:transparent;color:inherit;cursor:pointer}
|
|
44
44
|
.calendar-toggle:disabled{cursor:default;opacity:.6}
|
|
45
45
|
.calendar-toggle svg{display:block;width:1.1em;height:1.1em;margin:auto;pointer-events:none}
|
|
46
46
|
.calendar-popup{position:fixed;inset:auto;margin:0;padding:.5em;max-width:var(--gramlot-popup-available-width,100vw);max-height:var(--gramlot-popup-available-height,100vh);overflow:auto;
|
|
47
|
-
border:1px solid var(--gramlot-border-control,#aab4c4);border-radius:var(--gramlot-radius,5px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);box-shadow:var(--gramlot-shadow,0 3px 12px #0003);font:inherit}`,this.shadowRoot.append(e);let i=t.createElement("div");i.className="date-entry",this.control.parentElement.replaceWith(i),i.append(this.control),this.calendarButton=t.createElement("button"),this.calendarButton.type="button",this.calendarButton.className="calendar-toggle";let r=t.createElementNS(E,"svg");for(let[n,
|
|
47
|
+
border:1px solid var(--gramlot-border-control,#aab4c4);border-radius:var(--gramlot-radius,5px);background:var(--gramlot-surface,Canvas);color:var(--gramlot-ink,CanvasText);box-shadow:var(--gramlot-shadow,0 3px 12px #0003);font:inherit}`,this.shadowRoot.append(e);let i=t.createElement("div");i.className="date-entry",this.control.parentElement.replaceWith(i),i.append(this.control),this.calendarButton=t.createElement("button"),this.calendarButton.type="button",this.calendarButton.className="calendar-toggle";let r=t.createElementNS(E,"svg");for(let[n,c]of Object.entries({viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.8","stroke-linecap":"round","stroke-linejoin":"round","aria-hidden":"true",focusable:"false"}))r.setAttribute(n,c);let o=t.createElementNS(E,"path");o.setAttribute("d","M5 5h14a2 2 0 0 1 2 2v13a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V7a2 2 0 0 1 2-2Z M7 2v6 M17 2v6 M3 11h18 M7 15h2 M15 15h2 M7 18h2 M15 18h2"),r.append(o),this.calendarButton.append(r),this.calendarButton.setAttribute("aria-label","Open calendar"),this.calendarButton.setAttribute("aria-haspopup","dialog"),this.calendarButton.setAttribute("aria-expanded","false"),this.calendarButton.setAttribute("aria-controls","calendar-popup"),i.append(this.calendarButton),this.calendarPopup=t.createElement("div"),this.calendarPopup.className="calendar-popup",this.calendarPopup.id="calendar-popup",this.calendarPopup.setAttribute("popover","auto"),this.calendarPopup.setAttribute("role","dialog"),this.calendarPopup.setAttribute("aria-label","Choose date"),this.shadowRoot.append(this.calendarPopup);let a=t.createElement("div");this.calendarPopup.append(a),this.calendarView=new T(a,n=>{this.control.disabled||this.control.readOnly||!this.pageContext.isActive()||(this.closeCalendar(),this.control.focus(),this.selectControlValue(n))}),this.calendarButton.addEventListener("click",()=>this.#t?this.closeCalendar():this.openCalendar()),this.control.addEventListener("keydown",n=>{n.altKey&&n.key==="ArrowDown"&&(n.preventDefault(),this.openCalendar())}),this.calendarPopup.addEventListener("keydown",n=>{n.key==="Escape"&&(n.preventDefault(),n.stopPropagation(),this.closeCalendar(),this.control.focus())}),this.calendarPopup.addEventListener("toggle",n=>{n.newState==="closed"&&(this.#t=!1,this.cleanupCalendar())})}openCalendar(){if(!this.parameters.calendar||this.control.disabled||this.control.readOnly||!this.pageContext.isActive())return;let t=this.readControlValue();try{t=this.readDraftValue()}catch{}this.calendarView.configure({value:t,locale:this.context().locale,workdate:this.parameters.workdate}),this.calendarPopup.showPopover(),this.#t=!0,this.calendarButton.setAttribute("aria-expanded","true");let e=this.ownerDocument.defaultView,i=()=>w(this.calendarPopup,this.control);this.#e?.(),i(),e.addEventListener("resize",i),e.addEventListener("scroll",i,!0),this.#e=()=>{e.removeEventListener("resize",i),e.removeEventListener("scroll",i,!0)},this.calendarView.focusDay()}cleanupCalendar(){this.#e?.(),this.#e=null,this.calendarButton.setAttribute("aria-expanded","false")}closeCalendar(){this.#t&&this.calendarPopup.hidePopover(),this.#t=!1,this.cleanupCalendar()}projectAttributes(t,e){let i=super.projectAttributes(t,e);return this.calendarButton.hidden=!this.parameters.calendar,this.calendarButton.disabled=this.control.disabled||this.control.readOnly,!this.parameters.calendar||this.calendarButton.disabled?this.closeCalendar():this.#t&&this.calendarView.configure({value:this.readControlValue(),locale:this.context().locale,workdate:this.parameters.workdate}),i}writeControlValue(t){super.writeControlValue(t),this.#t&&this.calendarView.configure({value:t,locale:this.context().locale,workdate:this.parameters.workdate})}releaseControl(){this.closeCalendar(),super.releaseControl()}context(){return{...super.context(),dtype:"D",pattern:this.parameters.format??"short"}}static validationValueCheck(){return S}checkValue(t){S(t)}editText(t,e){return this.pageContext.format(t,{...e,pattern:"short"})}dateExpression(t,e){let i=new Date,r=this.parameters.workdate??`${i.getFullYear()}-${D(i.getMonth()+1)}-${D(i.getDate())}`,o={locale:e.locale,workdate:r},a=Q(t,o);if(!a.ok)throw new Error(a.error.message);if(a.kind!=="date"&&!this.parameters.period_to)throw new Error("Enter one complete date, not a period.");return a}acceptDraft(t,e,i){if(!e?.trim()||!this.parameters.period_to)return;let r=this.dateExpression(e,i);r.kind==="period"&&this.pageContext.periodOutput(this.parameters.period_to,new Date(r.end+"T00:00:00Z"))}parse(t,e){let i=this.dateExpression(t,e),[r,o,a]=(i.kind==="date"?i.date:i.start).split("-").map(Number),n=new Date(0);return n.setUTCFullYear(r,o-1,a),n}},st=s=>class extends s{context(){return{...super.context(),dtype:"H",pattern:this.parameters.format??"short"}}static validationValueCheck(){return it}checkValue(t){it(t)}editText(t){return`${D(t.getUTCHours())}:${D(t.getUTCMinutes())}:${D(t.getUTCSeconds())}`+(t.getUTCMilliseconds()?`.${String(t.getUTCMilliseconds()).padStart(3,"0")}`:"")}parse(t){let e=/^(\d{1,2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?$/.exec(t.trim());if(!e||+e[1]>23||+e[2]>59||+(e[3]??0)>59)throw new Error("Enter HH:mm or HH:mm:ss, using the 24-hour clock.");return new Date(Date.UTC(1970,0,1,+e[1],+e[2],+(e[3]??0),+(e[4]??"").padEnd(3,"0")))}};function et(s,t){if(s!==null&&!(typeof s=="number"&&Number.isFinite(s))&&!(t(s)&&jt(s)))throw new TypeError("Expected a finite number or Decimal")}function it(s){if(s!==null&&(!(s instanceof Date)||!Number.isFinite(s.getTime())||s.getUTCFullYear()!==1970||s.getUTCMonth()!==0||s.getUTCDate()!==1))throw new TypeError("Expected a civil time on the TYTX epoch date")}import{sharedModules as _t}from"@gramlot/gramlot";var Ot=s=>_t["./components/field-state.js"][s],f=Ot("FieldState");import{Bag as Pt}from"@gramlot/gramlot";function C(s){return class extends g(s){#t;#e=[];#r=-1;#i=0;#o=!1;#s=!1;#n=null;#a;#l;#h;#d;#c=!1;#u;constructor(){super();let t=this.ownerDocument,e=t.createElement("style");e.textContent=B+`.option{position:relative} #control{width:100%;padding-right:calc(var(--gramlot-choice-toggle-width,1.6em) + .2em)}
|
|
48
48
|
#control:focus-visible{outline:1px solid var(--gramlot-border-control,#7a8798);outline-offset:-3px}
|
|
49
49
|
|
|
50
50
|
.choices{min-width:min(var(--gramlot-choice-popup-min-width,0px),var(--gramlot-popup-available-width,100vw));max-width:var(--gramlot-popup-available-width,100vw);position:fixed;inset:auto;margin:0;padding:var(--gramlot-popup-padding,4px);box-sizing:border-box;max-height:min(var(--gramlot-choice-max-height,20rem),var(--gramlot-popup-available-height,100vh));overflow:auto;
|
|
@@ -53,7 +53,7 @@ li button{display:block;width:100%;text-align:start;padding:.55rem .35rem}
|
|
|
53
53
|
.choice:nth-child(even){background:var(--gramlot-choice-alternate-background,var(--gramlot-surface-subtle,transparent))}
|
|
54
54
|
.choice:hover{background:var(--gramlot-selected,Highlight)}
|
|
55
55
|
.choice-detail{margin-inline-start:var(--gramlot-space-3,.75rem);color:var(--gramlot-text-secondary,GrayText)}
|
|
56
|
-
.choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText)}`,this.toggle=t.createElement("button"),this.toggle.className="toggle choice-toggle",this.toggle.type="button",this.toggle.tabIndex=-1,this.control.parentElement.classList.add("choice-field"),this.toggle.setAttribute("aria-label","Show options"),this.control.parentElement.append(this.toggle),this.choices=t.createElement("div"),this.choices.id="choices",this.choices.className="choices",this.choices.hidden=!0,this.choices.setAttribute("role","listbox"),this.choices.setAttribute("popover","manual"),this.controlBox.append(e,this.choices),this.toggle.addEventListener("mousedown",i=>i.preventDefault()),this.toggle.addEventListener("click",()=>{this.locked||(this.control.focus({preventScroll:!0}),this.#o?this.closeChoices():this.search(""))}),this.choices.addEventListener("mousedown",i=>i.preventDefault()),this.control.addEventListener("input",i=>{this.#r=!0,this.#n=null,i.isComposing||this.scheduleSearch(this.control.value)}),this.control.addEventListener("compositionend",()=>this.scheduleSearch(this.control.value)),this.control.addEventListener("keydown",i=>{if(!(i.isComposing||this.locked))if(i.key==="ArrowDown"||i.key==="ArrowUp"){i.preventDefault();let r=i.key==="ArrowDown"?1:-1;this.#o?this.activate(this.#s<0?r>0?0:this.#e.length-1:Math.max(0,this.#s+r)):this.search("",r)}else i.key==="Enter"?(i.preventDefault(),this.#o&&this.#e[this.#s]?this.choose(this.#e[this.#s]):this.commitDraft()):i.key==="Escape"&&(this.closeChoices(),this.#r=!1,this.#n=null,this.constrained?this.resolveValue():(this.control.value=this.#t??"",this.error("")))}),this.control.addEventListener("blur",()=>{!this.autoHighlight&&this.#o&&this.#e[this.#s]?this.choose(this.#e[this.#s]):this.#r&&this.commitDraft(),this.closeChoices()})}createControl(){let t=this.ownerDocument.createElement("input");return t.type="text",t.setAttribute("role","combobox"),t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-controls","choices"),t.setAttribute("aria-expanded","false"),t.autocomplete="off",t}static get constrained(){return!0}get constrained(){return this.constructor.constrained}get revalidateDraftOnSourceChange(){return!1}get autoHighlight(){return!0}get matchTypedChoice(){return!0}get emptyChoice(){return null}get choiceSource(){return this.parameters.store??this.parameters.callback??this.parameters.values}get searchDelay(){return 0}textValue(t){return t}selectionAccepted(t){}selectionResolved(t){}renderChoice(t,e){e.textContent=t.caption}scheduleSearch(t){if(this.closeChoices(),!this.searchDelay)return this.search(t);this.#h=setTimeout(()=>{this.#h=null,this.search(t)},this.searchDelay)}get commitOnChange(){return this.constrained}get locked(){return this.control.disabled||this.control.readOnly}get active(){return this.isConnected&&this.pageContext?.isActive()}projectAttributes(t,e){let i=super.projectAttributes(t,e),r=this.choiceSource,o=r!==this.#l||this.parameters.separator!==this.#d;return this.#d=this.parameters.separator,this.#l=r,this.toggle.disabled=this.locked,o&&this.revalidateDraftOnSourceChange&&(this.#r=!1),o&&(this.#e=[],this.#n=null),(o||this.locked)&&this.closeChoices({cancelLookup:o}),o&&this.active&&!this.#r&&this.resolveValue(),i}setPageContext(t){super.setPageContext(t),this.resolveValue()}connectedCallback(){super.connectedCallback(),this.resolveValue()}readControlValue(){return this.#t}writeControlValue(t){Object.is(t,this.#t)||(this.#t=t,this.#r=!1,this.#n=null,this.closeChoices({cancelLookup:!0}),this.resolveValue())}restoreFormDraft(t){this.closeChoices({cancelLookup:!0}),this.#r=!0,this.#n=null,this.control.value=t}restoreFormValue(t){this.#t=t,this.#r=!1,this.#n=null,this.closeChoices({cancelLookup:!0}),this.resolveValue()}static validationValueCheck(){let t=this.constrained;return(e,i)=>{if(t&&e!==i)throw new Error("Validation cannot replace a selected code; update the Data explicitly.")}}static validationSelection(t,e){return this.constrained?async(i,r)=>{if(i==null)return!0;let o=await this.loadChoices(t,e,{_id:i},r);return lt(o.find(a=>a.id===i),i)}:super.validationSelection(t,e)}validationSelection(){if(!this.constrained)return super.validationSelection();let t=this.#e.map(({id:i,error:r})=>({id:i,error:r})),e=this.#n?{id:this.#n.id,error:this.#n.error}:null;return i=>{let r=e?.id===i?e:t.find(o=>o.id===i);return lt(r,i)}}acceptControlValue(){if(!this.#r)return this.validateCandidate(this.#t,o=>this.writeControlValue(o));let t=this.#n??(!this.autoHighlight&&this.#o?this.#e[this.#s]:null),e=t&&!this.constrained?t.caption:this.control.value,i=t?[t]:this.matchTypedChoice?this.#e.filter(o=>o.caption===e):[];if(this.constrained&&e!==""&&i.length!==1)return this.error("Choose a value from the list."),{ok:!1};let r=this.constrained?e===""?null:i[0].id:this.textValue(e);return this.validateCandidate(r,o=>{this.validationValueCheck()(o,r),this.#t=o,this.#r=!1,this.#n=null,(o==null||!this.constrained)&&(this.control.value=o??""),this.selectionAccepted(i.length===1&&o===r&&i[0].id!==null?i[0]:null),t&&!this.autoHighlight&&this.closeChoices()})}commitDraft(){this.closeChoices();let t=this.ownerDocument.defaultView.Event;this.control.dispatchEvent(new t("change",{bubbles:!0}))}choose(t){this.locked||!this.active||(this.pageContext.form&&this.pageContext.formSelectionError(t.error??""),this.#n=t,this.#r=!0,this.control.value=t.id===null?"":t.caption,this.closeChoices(),this.commitDraft())}async request(t,{selection:e=!1}={}){this.#c?.abort();let i=new AbortController;this.#c=i,this.#a=e||Object.hasOwn(t,"_id"),this.pageContext.form&&this.#a&&this.pageContext.formSelectionPending(!0);let r=++this.#i;this.control.setAttribute("aria-busy","true"),this.error("");try{let o=await this.loadChoices(t,i.signal);return r!==this.#i||!this.active?null:o}catch(o){return r===this.#i&&this.active&&(this.error(o.message),this.pageContext.form&&this.#a&&this.pageContext.formSelectionError(o.message)),null}finally{r===this.#i&&(this.pageContext.form&&this.#a&&this.pageContext.formSelectionPending(!1),this.#c=null,this.#a=!1,this.control.setAttribute("aria-busy","false"))}}async resolveValue(){if(this.#t==null||this.#t===""){this.pageContext?.form&&(this.pageContext.formSelectionPending(!1),this.pageContext.formSelectionError("")),this.control.value="",this.error(""),this.active&&this.selectionResolved(null);return}if(!this.active)return;if(this.control.value=this.#t,!this.constrained){this.error(""),this.selectionResolved(null);return}let t=this.request({_id:this.#t}),e=this.#i,i=await t;if(!i){e===this.#i&&this.active&&(this.selectionResolved(null),this.pageContext.form&&this.pageContext.formValidate());return}let r=i.find(a=>a.id===this.#t);this.#e=i,this.control.value=r?r.caption:this.#t;let o=r?r.error??"":"Value is not in the list.";this.error(o),this.pageContext.form&&(this.pageContext.formSelectionError(o),this.pageContext.formValidate()),this.selectionResolved(r??null)}async search(t,e=0){if(this.locked||!this.active)return;this.closeChoices(),this.#e=[];let i=await this.request({_querystring:t});if(!i||this.locked||this.shadowRoot.activeElement!==this.control)return;let r=this.emptyChoice;this.#e=r?[r,...i]:i;let o=this.ownerDocument;this.choices.replaceChildren(...this.#e.map((d,b)=>{let y=o.createElement("div");return y.id=`choice-${b}`,y.className="choice",y.setAttribute("role","option"),this.renderChoice(d,y),y.addEventListener("click",()=>this.choose(d)),y})),this.#e.length||(this.choices.textContent="No results");let a=o.defaultView;this.choices.hidden=!1,this.choices.showPopover(),this.#o=!0;let n=parseFloat(a.getComputedStyle(this).getPropertyValue("--gramlot-choice-popup-inset")||"2");w(this.choices,this.control,{matchWidth:!0,inset:n}),this.control.setAttribute("aria-expanded","true");let l=this.constrained&&!this.#r&&t===""&&this.#t!=null;this.activate(l?this.#e.findIndex(d=>d.id===this.#t):e<0?this.#e.length-1:e>0?0:this.autoHighlight&&i.length?r?1:0:-1);let h=()=>this.closeChoices(),c=d=>{d.composedPath().includes(this)||h()},u=d=>{d.composedPath().includes(this.choices)||h()};o.addEventListener("pointerdown",c,!0),o.addEventListener("scroll",u,!0),a.addEventListener("resize",h),this.#u=()=>{o.removeEventListener("pointerdown",c,!0),o.removeEventListener("scroll",u,!0),a.removeEventListener("resize",h)}}activate(t){this.#s=this.#e.length&&t>=0?Math.min(t,this.#e.length-1):-1;for(let[e,i]of[...this.choices.children].entries())i.setAttribute("aria-selected",String(e===this.#s)),e===this.#s&&i.scrollIntoView({block:"nearest"});this.#s<0?this.control.removeAttribute("aria-activedescendant"):this.control.setAttribute("aria-activedescendant",`choice-${this.#s}`)}closeChoices({cancelLookup:t=!1}={}){clearTimeout(this.#h),this.#h=null,(t||!this.#a)&&(this.pageContext?.form&&this.#a&&this.pageContext.formSelectionPending(!1),this.#c?.abort(),this.#c=null,this.#a=!1,++this.#i,this.control.setAttribute("aria-busy","false")),this.#u?.(),this.#u=null,this.#o&&this.choices.hidePopover(),this.#o=!1,this.choices.hidden=!0,this.control.setAttribute("aria-expanded","false"),this.control.removeAttribute("aria-activedescendant")}releaseControl(){this.closeChoices({cancelLookup:!0})}disconnectedCallback(){this.releaseControl()}}}C.parameters={...g.parameters,value:{dtype:"T",nullable:!0,binding:"twoWay"},placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"}};function R(s){return class extends s{loadChoices(t){return this.constructor.loadChoices(this.parameters,this.pageContext,t)}static loadChoices(t,e,i){let r;if(t.store!=null){if(!(t.store instanceof Ft))throw new TypeError("store must be a Bag");if(t.values)throw new TypeError("store and values are mutually exclusive");let o=new Set;r=t.store.getNodes().map(a=>{let n=a.staticValue,l=a.attr.caption;if(typeof n!="string"||!n||typeof l!="string"||o.has(n))throw new TypeError("Invalid or duplicate store choice");return o.add(n),{id:n,caption:l}})}else r=V(t.values??"",t.separator);return r.filter(o=>Object.hasOwn(i,"_id")?o.id===i._id:o.caption.toLocaleLowerCase().includes(i._querystring.toLocaleLowerCase()))}}}function ct(s){return class extends s{loadChoices(t){return this.constructor.loadChoices(this.parameters,this.pageContext,t)}static async loadChoices(t,e,i){let r=await e.callLogic(t.callback,i);if(!r||!Array.isArray(r.rows)||typeof r.identifier!="string"||typeof r.caption!="string")throw new TypeError("callbackSelect requires {rows, identifier, caption}");let o=new Set;return r.rows.map(a=>{let n=a[r.identifier],l=a[r.caption];if(typeof n!="string"||!n||typeof l!="string"||o.has(n))throw new TypeError("Invalid or duplicate choice code/caption");return o.add(n),{id:n,caption:l}})}}}function lt(s,t){return s?.error?{errorcode:"condition",message:s.error}:t==null||s?!0:{errorcode:"missing",message:"Choose a value from the list."}}import{createDOMPurify as Rt}from"@gramlot/gramlot";var H={dbtable:{dtype:"T",binding:"read"},caption_field:{dtype:"T",binding:"read"},condition:{dtype:"T",binding:"read"},weakCondition:{dtype:["B","T"],default:!1,binding:"read"},method:{dtype:"T",default:"dbSelect",binding:"read"},columns:{dtype:"T",binding:"read"},hiddenColumns:{dtype:"T",binding:"read"},auxColumns:{dtype:"T",binding:"read"},template:{dtype:"T",binding:"read"},templateNull:{dtype:"T",default:"",binding:"read"},order_by:{dtype:"T",binding:"read"},limit:{dtype:"L",default:10,binding:"read"},searchDelay:{dtype:"L",default:300,binding:"read"},ignoreCase:{dtype:"B",default:!0,binding:"read"},hasDownArrow:{dtype:"B",default:!0,binding:"read"},emptyLabel:{dtype:"T",qualification:"intl_str",default:"Clear selection",binding:"read"},selectedCaption:{dtype:"T"},selectedRecord:{dtype:"T"},selectedCb:{dtype:"T"}},W=["dbtable","method","caption_field","columns","hiddenColumns","auxColumns","order_by","limit","ignoreCase","condition","weakCondition"];function I(s){return class extends s{#t={};#e=!1;#s={};#i=0;#o;#r;#n;constructor(){super(),this.#n=Rt(this.ownerDocument.defaultView)}get choiceSource(){return this.#i}get searchDelay(){return this.parameters.searchDelay}get revalidateDraftOnSourceChange(){return this.constrained}get autoHighlight(){return this.constrained}get matchTypedChoice(){return this.constrained}get emptyChoice(){return this.constrained&&!this.parameters.validate_notnull?{id:null,caption:this.parameters.emptyLabel}:null}get commitOnChange(){return!0}textValue(t){return t===""?null:t}projectAttributes(t,e){let i=Object.fromEntries(Object.entries(t).filter(([c])=>W.includes(c)||["autoSelect","template","templateNull","emptyLabel","validate_notnull"].includes(c)||c.startsWith("condition_")||c.startsWith("selected_"))),r=new Set([...Object.keys(i),...Object.keys(this.#t)].filter(c=>c==="condition"||c==="weakCondition"||c.startsWith("condition_")));Object.keys(this.#t).length&&[...r].some(c=>!Object.is(i[c],this.#t[c]))&&(this.#e=!0),[...new Set([...Object.keys(i),...Object.keys(this.#t)])].some(c=>!Object.is(i[c],this.#t[c]))&&(this.cancelValidation(),this.#o=void 0,this.#t=i,this.#i++),this.#s=Object.fromEntries(Object.entries(t).filter(([c])=>c.startsWith("selected_")));let a=super.projectAttributes(t,e);if(this.#r=null,this.parameters.template!=null){this.#r=this.#n.sanitize(this.parameters.template,{USE_PROFILES:{html:!0},RETURN_DOM_FRAGMENT:!0,FORBID_TAGS:["style","form","input","button","select","textarea","a","audio","video","details","summary"],FORBID_ATTR:["id","name","role","tabindex","contenteditable","autofocus"]});for(let c of this.#r.querySelectorAll("*"))if([...c.attributes].some(u=>/\{[A-Za-z0-9_]+\}/.test(u.value)))throw this.#r=null,new TypeError("Selector template placeholders belong in text, not HTML attributes.")}if(this.choices.style.minWidth=this.#r?"min(var(--gramlot-choice-popup-min-width,28rem),var(--gramlot-popup-available-width,100vw))":"",this.parameters.caption_field!=null&&!this.parameters.caption_field.trim())throw new TypeError("caption_field must be a nonempty field name.");if(this.parameters.condition!=null&&!this.parameters.condition.trim())throw new TypeError("condition must be a nonempty expression.");if(typeof this.parameters.weakCondition!="boolean"&&(typeof this.parameters.weakCondition!="string"||!this.parameters.weakCondition.trim()))throw new TypeError("weakCondition must be boolean or a nonempty expression.");let{limit:n,searchDelay:l,hasDownArrow:h}=this.parameters;if(!Number.isInteger(n)||n<1)throw new TypeError("limit must be a positive integer.");if(!Number.isInteger(l)||l<0)throw new TypeError("searchDelay must be a non-negative integer.");this.toggle.hidden=!h,this.control.style.paddingRight=h?"":"var(--gramlot-field-padding, .25em)";for(let c of Object.keys(a))(c.startsWith("condition_")||c.startsWith("selected_"))&&delete a[c];return a}loadChoices(t,e){let i=new Set(Object.entries(this.#s).filter(([,r])=>r).map(([r])=>r.slice(9)));if(this.#r){let r=this.ownerDocument.createTreeWalker(this.#r,4);for(;r.nextNode();)for(let o of r.currentNode.data.matchAll(/\{([A-Za-z0-9_]+)\}/g))i.add(o[1])}return this.constructor.loadChoices({...this.parameters,...this.#t},this.pageContext,t,e,i)}static async loadChoices(t,e,i,r,o=new Set){let a=Object.fromEntries(W.filter(h=>h!=="method"&&t[h]!=null).map(h=>[h,t[h]]));a.weakCondition===!1&&delete a.weakCondition,o.size&&(a.hiddenColumns=[...new Set([...(a.hiddenColumns??"").split(",").map(h=>h.trim()).filter(Boolean),...o])].join(","));for(let[h,c]of Object.entries(t))if(h.startsWith("condition_")){let u=h.slice(10);if(!u||u.startsWith("_")||W.includes(u))throw new TypeError("Invalid condition parameter.");a[u]=c}let n=await e.remote(t.method,{...a,...i},r);if(!n||!Array.isArray(n.rows)||typeof n.identifier!="string"||typeof n.caption!="string")throw new TypeError("Database selectors require {rows, identifier, caption}.");if(a.auxColumns!=null){if(!Array.isArray(n.columns)||!Array.isArray(n.headers)||n.columns.length!==n.headers.length||!n.columns.length||n.columns.some(h=>typeof h!="string"||!h)||n.headers.some(h=>typeof h!="string")||new Set(n.columns).size!==n.columns.length)throw new TypeError("auxColumns requires columns and headers display metadata.");for(let h of n.columns)o.add(h)}if(n.errors!=null&&(typeof n.errors!="string"||!Object.hasOwn(i,"_id")))throw new TypeError("Selector errors must be literal text attached to identity lookup.");let l=new Set;return n.rows.map(h=>{let c=h[n.identifier],u=h[n.caption];if(!(typeof c=="string"&&c.length||Number.isSafeInteger(c))||typeof u!="string"||l.has(c))throw new TypeError("Invalid or duplicate database choice identity/caption.");for(let d of o)if(!Object.hasOwn(h,d))throw new TypeError(`Missing requested selector column: ${d}`);return l.add(c),{id:c,caption:u,record:h,error:n.errors,captionField:n.caption,columns:a.auxColumns!=null?n.columns:null,headers:a.auxColumns!=null?n.headers:null}})}selectionAccepted(t){this.#o=t}renderChoice(t,e){if(t.id===null){super.renderChoice(t,e),e.style.color="var(--gramlot-text-secondary,GrayText)",e.style.borderBottom="1px solid var(--gramlot-border,#d5dce5)",e.style.marginBottom="var(--gramlot-space-1,.25rem)";return}if(this.#r){let i=this.#r.cloneNode(!0),r=this.ownerDocument.createTreeWalker(i,4);for(;r.nextNode();)r.currentNode.data=r.currentNode.data.replace(/\{([A-Za-z0-9_]+)\}/g,(o,a)=>t.record[a]==null?this.parameters.templateNull:String(t.record[a]));e.style.display="block",e.style.overflowWrap="anywhere",e.replaceChildren(i);return}if(t.columns){e.style.display="grid",e.style.gridTemplateColumns=`repeat(${t.columns.length}, minmax(0, 1fr))`,e.style.gap="var(--gramlot-space-3,.75rem)",e.style.alignItems="start",e.replaceChildren(...t.columns.map((i,r)=>{let o=this.ownerDocument.createElement("span");o.style.overflowWrap="anywhere";let a=this.ownerDocument.createElement("small");a.textContent=t.headers[r],a.style.display="block",a.style.opacity=".7";let n=this.ownerDocument.createElement("span");return n.textContent=t.record[i]??"",o.append(a,n),o}));return}super.renderChoice(t,e);for(let i of(this.parameters.columns??"").split(",").map(r=>r.trim()).filter(r=>r&&r!==t.captionField)){let r=this.ownerDocument.createElement("span");r.className="choice-detail",r.textContent=t.record[i]??"",e.append(r)}}selectionResolved(t){this.#l(t)}#l(t){let{selectedCaption:e,selectedRecord:i}=this.parameters;this.pageContext.selectionOutputs({selectedCaption:e,selectedRecord:i,fields:this.#s},t)}finishValidation(t){if(t.ok&&this.#o!==void 0){let e=this.#o;if(this.#o=void 0,this.#l(e),this.parameters.selectedCb){let i=r=>console.error("Selection notification failed:",r);try{let r=this.pageContext.callLogic(this.parameters.selectedCb,{value:t.value,record:e?.record??null});r instanceof Promise&&r.catch(i)}catch(r){i(r)}}}super.finishValidation(t)}async resolveValue(){let t=this.#e;if(this.#e=!1,t&&this.active&&!this.locked&&this.constrained&&this.parameters.validate_notnull){let r=await this.request({_querystring:"",limit:2},{selection:!0});if(!r)return;if(r.length===1){this.choose(r[0]);return}}let e=this.readControlValue(),i=super.resolveValue();if(e!=null&&e!=="")return i;if(await i,this.active&&!this.locked&&this.parameters.autoSelect&&this.readControlValue()==null&&this.control.value===""){let r=await this.request({_querystring:"",limit:2},{selection:!0});r?.length===1&&this.readControlValue()==null&&!this.locked&&this.choose(r[0])}}}}var Ht=(0,p.defineComponent)({name:"textbox",tag:"gramlot-textbox",base:g,mixins:[m,f],parameters:{value:{dtype:"T",nullable:!0,binding:"twoWay"},placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"}},implementation:O("input","text")}),It=(0,p.defineComponent)({name:"checkbox",tag:"gramlot-checkbox",base:g,mixins:[m,f],parameters:{value:{dtype:"B",binding:"twoWay"},mode:{dtype:"T",default:"checkbox",binding:"read",enum:["checkbox","switch"]},switch_color:{dtype:"T",nullable:!0,default:null,binding:"read"},label:{dtype:"T",qualification:"intl_str",default:"",target:"optionCaption"}},implementation:s=>class extends s{createControl(){let t=this.ownerDocument.createElement("input");return t.type="checkbox",t}constructor(){super();let t=this.ownerDocument.createElement("style");t.textContent=`input[role=switch]{appearance:none;position:relative;flex:none;cursor:pointer;
|
|
56
|
+
.choice[aria-selected=true]{background:var(--gramlot-selected,Highlight);color:var(--gramlot-ink,HighlightText)}`,this.toggle=t.createElement("button"),this.toggle.className="toggle choice-toggle",this.toggle.type="button",this.toggle.tabIndex=-1,this.control.parentElement.classList.add("choice-field"),this.toggle.setAttribute("aria-label","Show options"),this.control.parentElement.append(this.toggle),this.choices=t.createElement("div"),this.choices.id="choices",this.choices.className="choices",this.choices.hidden=!0,this.choices.setAttribute("role","listbox"),this.choices.setAttribute("popover","manual"),this.controlBox.append(e,this.choices),this.toggle.addEventListener("mousedown",i=>i.preventDefault()),this.toggle.addEventListener("click",()=>{this.locked||(this.control.focus({preventScroll:!0}),this.#o?this.closeChoices():this.search(""))}),this.choices.addEventListener("mousedown",i=>i.preventDefault()),this.control.addEventListener("input",i=>{this.#s=!0,this.#n=null,i.isComposing||this.scheduleSearch(this.control.value)}),this.control.addEventListener("compositionend",()=>this.scheduleSearch(this.control.value)),this.control.addEventListener("keydown",i=>{if(!(i.isComposing||this.locked))if(i.key==="ArrowDown"||i.key==="ArrowUp"){i.preventDefault();let r=i.key==="ArrowDown"?1:-1;this.#o?this.activate(this.#r<0?r>0?0:this.#e.length-1:Math.max(0,this.#r+r)):this.search("",r)}else i.key==="Enter"?(i.preventDefault(),this.#o&&this.#e[this.#r]?this.choose(this.#e[this.#r]):this.commitDraft()):i.key==="Escape"&&(this.closeChoices(),this.#s=!1,this.#n=null,this.constrained?this.resolveValue():(this.control.value=this.#t??"",this.error("")))}),this.control.addEventListener("blur",()=>{!this.autoHighlight&&this.#o&&this.#e[this.#r]?this.choose(this.#e[this.#r]):this.#s&&this.commitDraft(),this.closeChoices()})}createControl(){let t=this.ownerDocument.createElement("input");return t.type="text",t.setAttribute("role","combobox"),t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-controls","choices"),t.setAttribute("aria-expanded","false"),t.autocomplete="off",t}static get constrained(){return!0}get constrained(){return this.constructor.constrained}get revalidateDraftOnSourceChange(){return!1}get autoHighlight(){return!0}get matchTypedChoice(){return!0}get emptyChoice(){return null}get choiceSource(){return this.parameters.callback??this.parameters.values}get searchDelay(){return 0}textValue(t){return t}selectionAccepted(t){}selectionResolved(t){}renderChoice(t,e){e.textContent=t.caption}scheduleSearch(t){if(this.closeChoices(),!this.searchDelay)return this.search(t);this.#u=setTimeout(()=>{this.#u=null,this.search(t)},this.searchDelay)}get commitOnChange(){return this.constrained}get locked(){return this.control.disabled||this.control.readOnly}get active(){return this.isConnected&&this.pageContext?.isActive()}projectAttributes(t,e){let i=super.projectAttributes(t,e),r=this.choiceSource,o=r!==this.#a||this.parameters.separator!==this.#l;return this.#l=this.parameters.separator,this.#a=r,this.toggle.disabled=this.locked,o&&this.revalidateDraftOnSourceChange&&(this.#s=!1),o&&(this.#e=[],this.#n=null),(o||this.locked)&&this.closeChoices({cancelLookup:o}),o&&this.active&&!this.#s&&this.resolveValue(),i}setPageContext(t){super.setPageContext(t),this.resolveValue()}connectedCallback(){super.connectedCallback(),this.resolveValue()}readControlValue(){return this.#t}writeControlValue(t){Object.is(t,this.#t)||(this.#t=t,this.#s=!1,this.#n=null,this.closeChoices({cancelLookup:!0}),this.resolveValue())}restoreFormDraft(t){this.closeChoices({cancelLookup:!0}),this.#s=!0,this.#n=null,this.control.value=t}restoreFormValue(t){this.#t=t,this.#s=!1,this.#n=null,this.closeChoices({cancelLookup:!0}),this.resolveValue()}static validationValueCheck(){let t=this.constrained;return(e,i)=>{if(t&&e!==i)throw new Error("Validation cannot replace a selected code; update the Data explicitly.")}}static validationSelection(t,e){return this.constrained?async(i,r)=>{if(i==null)return!0;let o=await this.loadChoices(t,e,{_id:i},r);return nt(o.find(a=>a.id===i),i)}:super.validationSelection(t,e)}validationSelection(){if(!this.constrained)return super.validationSelection();let t=this.#e.map(({id:i,error:r})=>({id:i,error:r})),e=this.#n?{id:this.#n.id,error:this.#n.error}:null;return i=>{let r=e?.id===i?e:t.find(o=>o.id===i);return nt(r,i)}}acceptControlValue(){if(!this.#s)return this.validateCandidate(this.#t,o=>this.writeControlValue(o));let t=this.#n??(!this.autoHighlight&&this.#o?this.#e[this.#r]:null),e=t&&!this.constrained?t.caption:this.control.value,i=t?[t]:this.matchTypedChoice?this.#e.filter(o=>o.caption===e):[];if(this.constrained&&e!==""&&i.length!==1)return this.error("Choose a value from the list."),{ok:!1};let r=this.constrained?e===""?null:i[0].id:this.textValue(e);return this.validateCandidate(r,o=>{this.validationValueCheck()(o,r),this.#t=o,this.#s=!1,this.#n=null,(o==null||!this.constrained)&&(this.control.value=o??""),this.selectionAccepted(i.length===1&&o===r&&i[0].id!==null?i[0]:null),t&&!this.autoHighlight&&this.closeChoices()})}commitDraft(){this.closeChoices();let t=this.ownerDocument.defaultView.Event;this.control.dispatchEvent(new t("change",{bubbles:!0}))}choose(t){this.locked||!this.active||(this.pageContext.form&&this.pageContext.formSelectionError(t.error??""),this.#n=t,this.#s=!0,this.control.value=t.id===null?"":t.caption,this.closeChoices(),this.commitDraft())}async request(t,{selection:e=!1}={}){this.#d?.abort();let i=new AbortController;this.#d=i,this.#c=e||Object.hasOwn(t,"_id"),this.pageContext.form&&this.#c&&this.pageContext.formSelectionPending(!0);let r=++this.#i;this.control.setAttribute("aria-busy","true"),this.error("");try{let o=await this.loadChoices(t,i.signal);return r!==this.#i||!this.active?null:o}catch(o){return r===this.#i&&this.active&&(this.error(o.message),this.pageContext.form&&this.#c&&this.pageContext.formSelectionError(o.message)),null}finally{r===this.#i&&(this.pageContext.form&&this.#c&&this.pageContext.formSelectionPending(!1),this.#d=null,this.#c=!1,this.control.setAttribute("aria-busy","false"))}}async resolveValue(){if(this.#t==null||this.#t===""){this.pageContext?.form&&(this.pageContext.formSelectionPending(!1),this.pageContext.formSelectionError("")),this.control.value="",this.error(""),this.active&&this.selectionResolved(null);return}if(!this.active)return;if(this.control.value=this.#t,!this.constrained){this.error(""),this.selectionResolved(null);return}let t=this.request({_id:this.#t}),e=this.#i,i=await t;if(!i){e===this.#i&&this.active&&(this.selectionResolved(null),this.pageContext.form&&this.pageContext.formValidate());return}let r=i.find(a=>a.id===this.#t);this.#e=i,this.control.value=r?r.caption:this.#t;let o=r?r.error??"":"Value is not in the list.";this.error(o),this.pageContext.form&&(this.pageContext.formSelectionError(o),this.pageContext.formValidate()),this.selectionResolved(r??null)}async search(t,e=0){if(this.locked||!this.active)return;this.closeChoices(),this.#e=[];let i=await this.request({_querystring:t});if(!i||this.locked||this.shadowRoot.activeElement!==this.control)return;let r=this.emptyChoice;this.#e=r?[r,...i]:i;let o=this.ownerDocument;this.choices.replaceChildren(...this.#e.map((u,b)=>{let y=o.createElement("div");return y.id=`choice-${b}`,y.className="choice",y.setAttribute("role","option"),this.renderChoice(u,y),y.addEventListener("click",()=>this.choose(u)),y})),this.#e.length||(this.choices.textContent="No results");let a=o.defaultView;this.choices.hidden=!1,this.choices.showPopover(),this.#o=!0;let n=parseFloat(a.getComputedStyle(this).getPropertyValue("--gramlot-choice-popup-inset")||"2");w(this.choices,this.control,{matchWidth:!0,inset:n}),this.control.setAttribute("aria-expanded","true");let c=this.constrained&&!this.#s&&t===""&&this.#t!=null;this.activate(c?this.#e.findIndex(u=>u.id===this.#t):e<0?this.#e.length-1:e>0?0:this.autoHighlight&&i.length?r?1:0:-1);let l=()=>this.closeChoices(),h=u=>{u.composedPath().includes(this)||l()},d=u=>{u.composedPath().includes(this.choices)||l()};o.addEventListener("pointerdown",h,!0),o.addEventListener("scroll",d,!0),a.addEventListener("resize",l),this.#h=()=>{o.removeEventListener("pointerdown",h,!0),o.removeEventListener("scroll",d,!0),a.removeEventListener("resize",l)}}activate(t){this.#r=this.#e.length&&t>=0?Math.min(t,this.#e.length-1):-1;for(let[e,i]of[...this.choices.children].entries())i.setAttribute("aria-selected",String(e===this.#r)),e===this.#r&&i.scrollIntoView({block:"nearest"});this.#r<0?this.control.removeAttribute("aria-activedescendant"):this.control.setAttribute("aria-activedescendant",`choice-${this.#r}`)}closeChoices({cancelLookup:t=!1}={}){clearTimeout(this.#u),this.#u=null,(t||!this.#c)&&(this.pageContext?.form&&this.#c&&this.pageContext.formSelectionPending(!1),this.#d?.abort(),this.#d=null,this.#c=!1,++this.#i,this.control.setAttribute("aria-busy","false")),this.#h?.(),this.#h=null,this.#o&&this.choices.hidePopover(),this.#o=!1,this.choices.hidden=!0,this.control.setAttribute("aria-expanded","false"),this.control.removeAttribute("aria-activedescendant")}releaseControl(){this.closeChoices({cancelLookup:!0})}disconnectedCallback(){this.releaseControl()}}}C.parameters={...g.parameters,value:{dtype:"T",nullable:!0,binding:"twoWay"},placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"}};function q(s){return class extends s{loadChoices(t){return this.constructor.loadChoices(this.parameters,this.pageContext,t)}static loadChoices(t,e,i){let r;if(t.store!=null){if(!(t.store instanceof Pt))throw new TypeError("store must be a Bag");if(t.values)throw new TypeError("store and values are mutually exclusive");let o=new Set;r=t.store.getNodes().map(a=>{let n=a.staticValue,c=a.attr.caption;if(typeof n!="string"||!n||typeof c!="string"||o.has(n))throw new TypeError("Invalid or duplicate store choice");return o.add(n),{id:n,caption:c}})}else r=V(t.values??"",t.separator);return r.filter(o=>Object.hasOwn(i,"_id")?o.id===i._id:o.caption.toLocaleLowerCase().includes(i._querystring.toLocaleLowerCase()))}}}function at(s){return class extends s{loadChoices(t){return this.constructor.loadChoices(this.parameters,this.pageContext,t)}static async loadChoices(t,e,i){let r=await e.callLogic(t.callback,i);if(!r||!Array.isArray(r.rows)||typeof r.identifier!="string"||typeof r.caption!="string")throw new TypeError("callbackSelect requires {rows, identifier, caption}");let o=new Set;return r.rows.map(a=>{let n=a[r.identifier],c=a[r.caption];if(typeof n!="string"||!n||typeof c!="string"||o.has(n))throw new TypeError("Invalid or duplicate choice code/caption");return o.add(n),{id:n,caption:c}})}}}function nt(s,t){return s?.error?{errorcode:"condition",message:s.error}:t==null||s?!0:{errorcode:"missing",message:"Choose a value from the list."}}import{createDOMPurify as Mt}from"@gramlot/gramlot";var W={dbtable:{dtype:"T",binding:"read"},caption_field:{dtype:"T",binding:"read"},condition:{dtype:"T",binding:"read"},weakCondition:{dtype:["B","T"],default:!1,binding:"read"},method:{dtype:"T",default:"dbSelect",binding:"read"},columns:{dtype:"T",binding:"read"},hiddenColumns:{dtype:"T",binding:"read"},auxColumns:{dtype:"T",binding:"read"},template:{dtype:"T",binding:"read"},templateNull:{dtype:"T",default:"",binding:"read"},order_by:{dtype:"T",binding:"read"},limit:{dtype:"L",default:10,binding:"read"},searchDelay:{dtype:"L",default:300,binding:"read"},ignoreCase:{dtype:"B",default:!0,binding:"read"},hasDownArrow:{dtype:"B",default:!0,binding:"read"},emptyLabel:{dtype:"T",qualification:"intl_str",default:"Clear selection",binding:"read"},selectedCaption:{dtype:"T"},selectedRecord:{dtype:"T"},selectedCb:{dtype:"T"}},F=["dbtable","method","caption_field","columns","hiddenColumns","auxColumns","order_by","limit","ignoreCase","condition","weakCondition"];function H(s){return class extends s{#t={};#e=!1;#r={};#i=0;#o;#s;#n;constructor(){super(),this.#n=Mt(this.ownerDocument.defaultView)}get choiceSource(){return this.#i}get searchDelay(){return this.parameters.searchDelay}get revalidateDraftOnSourceChange(){return this.constrained}get autoHighlight(){return this.constrained}get matchTypedChoice(){return this.constrained}get emptyChoice(){return this.constrained&&!this.parameters.validate_notnull?{id:null,caption:this.parameters.emptyLabel}:null}get commitOnChange(){return!0}textValue(t){return t===""?null:t}projectAttributes(t,e){let i=Object.fromEntries(Object.entries(t).filter(([h])=>F.includes(h)||["autoSelect","template","templateNull","emptyLabel","validate_notnull"].includes(h)||h.startsWith("condition_")||h.startsWith("selected_"))),r=new Set([...Object.keys(i),...Object.keys(this.#t)].filter(h=>h==="condition"||h==="weakCondition"||h.startsWith("condition_")));Object.keys(this.#t).length&&[...r].some(h=>!Object.is(i[h],this.#t[h]))&&(this.#e=!0),[...new Set([...Object.keys(i),...Object.keys(this.#t)])].some(h=>!Object.is(i[h],this.#t[h]))&&(this.cancelValidation(),this.#o=void 0,this.#t=i,this.#i++),this.#r=Object.fromEntries(Object.entries(t).filter(([h])=>h.startsWith("selected_")));let a=super.projectAttributes(t,e);if(this.#s=null,this.parameters.template!=null){this.#s=this.#n.sanitize(this.parameters.template,{USE_PROFILES:{html:!0},RETURN_DOM_FRAGMENT:!0,FORBID_TAGS:["style","form","input","button","select","textarea","a","audio","video","details","summary"],FORBID_ATTR:["id","name","role","tabindex","contenteditable","autofocus"]});for(let h of this.#s.querySelectorAll("*"))if([...h.attributes].some(d=>/\{[A-Za-z0-9_]+\}/.test(d.value)))throw this.#s=null,new TypeError("Selector template placeholders belong in text, not HTML attributes.")}if(this.choices.style.minWidth=this.#s?"min(var(--gramlot-choice-popup-min-width,28rem),var(--gramlot-popup-available-width,100vw))":"",this.parameters.caption_field!=null&&!this.parameters.caption_field.trim())throw new TypeError("caption_field must be a nonempty field name.");if(this.parameters.condition!=null&&!this.parameters.condition.trim())throw new TypeError("condition must be a nonempty expression.");if(typeof this.parameters.weakCondition!="boolean"&&(typeof this.parameters.weakCondition!="string"||!this.parameters.weakCondition.trim()))throw new TypeError("weakCondition must be boolean or a nonempty expression.");let{limit:n,searchDelay:c,hasDownArrow:l}=this.parameters;if(!Number.isInteger(n)||n<1)throw new TypeError("limit must be a positive integer.");if(!Number.isInteger(c)||c<0)throw new TypeError("searchDelay must be a non-negative integer.");this.toggle.hidden=!l,this.control.style.paddingRight=l?"":"var(--gramlot-field-padding, .25em)";for(let h of Object.keys(a))(h.startsWith("condition_")||h.startsWith("selected_"))&&delete a[h];return a}loadChoices(t,e){let i=new Set(Object.entries(this.#r).filter(([,r])=>r).map(([r])=>r.slice(9)));if(this.#s){let r=this.ownerDocument.createTreeWalker(this.#s,4);for(;r.nextNode();)for(let o of r.currentNode.data.matchAll(/\{([A-Za-z0-9_]+)\}/g))i.add(o[1])}return this.constructor.loadChoices({...this.parameters,...this.#t},this.pageContext,t,e,i)}static async loadChoices(t,e,i,r,o=new Set){let a=Object.fromEntries(F.filter(l=>l!=="method"&&t[l]!=null).map(l=>[l,t[l]]));a.weakCondition===!1&&delete a.weakCondition,o.size&&(a.hiddenColumns=[...new Set([...(a.hiddenColumns??"").split(",").map(l=>l.trim()).filter(Boolean),...o])].join(","));for(let[l,h]of Object.entries(t))if(l.startsWith("condition_")){let d=l.slice(10);if(!d||d.startsWith("_")||F.includes(d))throw new TypeError("Invalid condition parameter.");a[d]=h}let n=await e.remote(t.method,{...a,...i},r);if(!n||!Array.isArray(n.rows)||typeof n.identifier!="string"||typeof n.caption!="string")throw new TypeError("Database selectors require {rows, identifier, caption}.");if(a.auxColumns!=null){if(!Array.isArray(n.columns)||!Array.isArray(n.headers)||n.columns.length!==n.headers.length||!n.columns.length||n.columns.some(l=>typeof l!="string"||!l)||n.headers.some(l=>typeof l!="string")||new Set(n.columns).size!==n.columns.length)throw new TypeError("auxColumns requires columns and headers display metadata.");for(let l of n.columns)o.add(l)}if(n.errors!=null&&(typeof n.errors!="string"||!Object.hasOwn(i,"_id")))throw new TypeError("Selector errors must be literal text attached to identity lookup.");let c=new Set;return n.rows.map(l=>{let h=l[n.identifier],d=l[n.caption];if(!(typeof h=="string"&&h.length||Number.isSafeInteger(h))||typeof d!="string"||c.has(h))throw new TypeError("Invalid or duplicate database choice identity/caption.");for(let u of o)if(!Object.hasOwn(l,u))throw new TypeError(`Missing requested selector column: ${u}`);return c.add(h),{id:h,caption:d,record:l,error:n.errors,captionField:n.caption,columns:a.auxColumns!=null?n.columns:null,headers:a.auxColumns!=null?n.headers:null}})}selectionAccepted(t){this.#o=t}renderChoice(t,e){if(t.id===null){super.renderChoice(t,e),e.style.color="var(--gramlot-text-secondary,GrayText)",e.style.borderBottom="1px solid var(--gramlot-border,#d5dce5)",e.style.marginBottom="var(--gramlot-space-1,.25rem)";return}if(this.#s){let i=this.#s.cloneNode(!0),r=this.ownerDocument.createTreeWalker(i,4);for(;r.nextNode();)r.currentNode.data=r.currentNode.data.replace(/\{([A-Za-z0-9_]+)\}/g,(o,a)=>t.record[a]==null?this.parameters.templateNull:String(t.record[a]));e.style.display="block",e.style.overflowWrap="anywhere",e.replaceChildren(i);return}if(t.columns){e.style.display="grid",e.style.gridTemplateColumns=`repeat(${t.columns.length}, minmax(0, 1fr))`,e.style.gap="var(--gramlot-space-3,.75rem)",e.style.alignItems="start",e.replaceChildren(...t.columns.map((i,r)=>{let o=this.ownerDocument.createElement("span");o.style.overflowWrap="anywhere";let a=this.ownerDocument.createElement("small");a.textContent=t.headers[r],a.style.display="block",a.style.opacity=".7";let n=this.ownerDocument.createElement("span");return n.textContent=t.record[i]??"",o.append(a,n),o}));return}super.renderChoice(t,e);for(let i of(this.parameters.columns??"").split(",").map(r=>r.trim()).filter(r=>r&&r!==t.captionField)){let r=this.ownerDocument.createElement("span");r.className="choice-detail",r.textContent=t.record[i]??"",e.append(r)}}selectionResolved(t){this.#a(t)}#a(t){let{selectedCaption:e,selectedRecord:i}=this.parameters;this.pageContext.selectionOutputs({selectedCaption:e,selectedRecord:i,fields:this.#r},t)}finishValidation(t){if(t.ok&&this.#o!==void 0){let e=this.#o;if(this.#o=void 0,this.#a(e),this.parameters.selectedCb){let i=r=>console.error("Selection notification failed:",r);try{let r=this.pageContext.callLogic(this.parameters.selectedCb,{value:t.value,record:e?.record??null});r instanceof Promise&&r.catch(i)}catch(r){i(r)}}}super.finishValidation(t)}async resolveValue(){let t=this.#e;if(this.#e=!1,t&&this.active&&!this.locked&&this.constrained&&this.parameters.validate_notnull){let r=await this.request({_querystring:"",limit:2},{selection:!0});if(!r)return;if(r.length===1){this.choose(r[0]);return}}let e=this.readControlValue(),i=super.resolveValue();if(e!=null&&e!=="")return i;if(await i,this.active&&!this.locked&&this.parameters.autoSelect&&this.readControlValue()==null&&this.control.value===""){let r=await this.request({_querystring:"",limit:2},{selection:!0});r?.length===1&&this.readControlValue()==null&&!this.locked&&this.choose(r[0])}}}}var Rt=(0,p.defineComponent)({name:"textbox",tag:"gramlot-textbox",base:g,mixins:[m,f],parameters:{value:{dtype:"T",nullable:!0,binding:"twoWay"},placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"}},implementation:_("input","text")}),qt=(0,p.defineComponent)({name:"checkbox",tag:"gramlot-checkbox",base:g,mixins:[m,f],parameters:{value:{dtype:"B",binding:"twoWay"},mode:{dtype:"T",default:"checkbox",binding:"read",enum:["checkbox","switch"]},switch_color:{dtype:"T",nullable:!0,default:null,binding:"read"},label:{dtype:"T",qualification:"intl_str",default:"",target:"optionCaption"}},implementation:s=>class extends s{createControl(){let t=this.ownerDocument.createElement("input");return t.type="checkbox",t}constructor(){super();let t=this.ownerDocument.createElement("style");t.textContent=`input[role=switch]{appearance:none;position:relative;flex:none;cursor:pointer;
|
|
57
57
|
width:var(--gramlot-switch-width,2.5em);height:var(--gramlot-switch-height,1.4em);min-width:0;min-height:0;
|
|
58
58
|
margin:0;border:1px solid var(--gramlot-border-control,#888);border-radius:2em;
|
|
59
59
|
background:var(--gramlot-switch-off,var(--gramlot-field-readonly-background,#bbb));transition:background 120ms}
|
|
@@ -62,4 +62,4 @@ li button{display:block;width:100%;text-align:start;padding:.55rem .35rem}
|
|
|
62
62
|
input[role=switch]:checked{background:var(--gramlot-switch-on,var(--gramlot-brand-blue,Highlight))}
|
|
63
63
|
input[role=switch]:checked::before{left:calc(100% - var(--gramlot-switch-height,1.4em) + var(--gramlot-switch-inset,2px) + 2px)}
|
|
64
64
|
input[role=switch]:disabled{cursor:not-allowed}
|
|
65
|
-
@media(prefers-reduced-motion:reduce){input[role=switch],input[role=switch]::before{transition:none}}`,this.shadowRoot.append(t),this.control.addEventListener("click",e=>{this.control.readOnly&&e.preventDefault()})}projectAttributes(t,e){let i=super.projectAttributes(t,e),r=this.parameters.mode;if(!this.constructor.gramlotComponent.parameters.mode.enum.includes(r))throw new TypeError("checkbox mode must be checkbox or switch");return r==="switch"?this.control.setAttribute("role","switch"):this.control.removeAttribute("role"),r==="switch"&&this.parameters.switch_color!=null?this.control.style.setProperty("--gramlot-switch-on",this.parameters.switch_color):this.control.style.removeProperty("--gramlot-switch-on"),i}readControlValue(){return this.control.checked}writeControlValue(t){this.control.checked=t}}}),
|
|
65
|
+
@media(prefers-reduced-motion:reduce){input[role=switch],input[role=switch]::before{transition:none}}`,this.shadowRoot.append(t),this.control.addEventListener("click",e=>{this.control.readOnly&&e.preventDefault()})}projectAttributes(t,e){let i=super.projectAttributes(t,e),r=this.parameters.mode;if(!this.constructor.gramlotComponent.parameters.mode.enum.includes(r))throw new TypeError("checkbox mode must be checkbox or switch");return r==="switch"?this.control.setAttribute("role","switch"):this.control.removeAttribute("role"),r==="switch"&&this.parameters.switch_color!=null?this.control.style.setProperty("--gramlot-switch-on",this.parameters.switch_color):this.control.style.removeProperty("--gramlot-switch-on"),i}readControlValue(){return this.control.checked}writeControlValue(t){this.control.checked=t}}}),Ft=(0,p.defineComponent)({name:"radioButtonText",tag:"gramlot-radio-button-text",base:U,mixins:[m,f],parameters:{value:{dtype:"T",nullable:!0,binding:"twoWay"},values:{dtype:"T",binding:"read"},cols:{dtype:"L",default:1,binding:"read"}},implementation:s=>class extends s{get choiceType(){return"radio"}get multiple(){return!1}}});function _(s,t){return e=>class extends e{createControl(){let i=this.ownerDocument.createElement(s);return s==="input"&&(i.type=t),i}readControlValue(){return this.control.value}writeControlValue(i){this.control.value!==(i??"")&&(this.control.value=i??"")}}}var Wt=(0,p.defineComponent)({name:"textBoxArea",tag:"gramlot-text-box-area",base:g,mixins:[m,f],parameters:{value:{dtype:"T",nullable:!0,binding:"twoWay"},placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"},rows:{dtype:"L",default:4,binding:"read",target:"control"},cols:{dtype:"L",default:24,binding:"read",target:"control"}},implementation:_("textarea")}),Ht=(0,p.defineComponent)({name:"passwordbox",tag:"gramlot-passwordbox",base:g,mixins:[m,f],parameters:{value:{dtype:"T",nullable:!0,binding:"twoWay"},placeholder:{dtype:"T",qualification:"intl_str",default:"",target:"control"}},implementation:_("input","password")}),It=(0,p.defineComponent)({name:"radioButton",tag:"gramlot-radio-button",base:g,mixins:[m,f],parameters:{value:{dtype:"B",default:!1,binding:"twoWay"},label:{dtype:"T",qualification:"intl_str",default:"",target:"optionCaption"},group:{dtype:"T",nullable:!0,binding:"read"}},implementation:s=>class extends s{createControl(){let t=this.ownerDocument.createElement("input");return t.type="radio",t}readControlValue(){return this.control.checked}writeControlValue(t){this.control.checked=t}}}),zt=(0,p.defineComponent)({name:"colorpicker",tag:"gramlot-colorpicker",base:g,mixins:[m,f],parameters:{value:{dtype:"T",default:"#000000",binding:"twoWay"}},implementation:_("input","color")}),lt={value:{dtype:"R",default:0,binding:"twoWay"},min:{dtype:"R",default:0,binding:"read",target:"control"},max:{dtype:"R",default:100,binding:"read",target:"control"},step:{dtype:"R",default:1,binding:"read",target:"control"}};function ct(s){return t=>class extends t{#t;#e=!1;setSourceContext(e){this.#t=e}projectAttributes(e,i){let r=this.parameters,o=super.projectAttributes(e,i);return r&&["min","max","step"].some(a=>r[a]!==this.parameters[a])&&this.writeControlValue(this.parameters.value),o}createControl(){let e=this.ownerDocument.createElement("input");return e.type="range",s?(e.style.cssText="writing-mode:vertical-lr;direction:rtl;width:var(--gramlot-slider-width,1.5rem);height:var(--gramlot-slider-height,10rem)",e.setAttribute("aria-orientation","vertical")):e.style.width="100%",e}readControlValue(){return this.control.valueAsNumber}writeControlValue(e){this.control.value=String(e);let i=this.control.valueAsNumber;if(!this.#e&&Number.isFinite(e)&&Number.isFinite(i)&&i!==e){this.#e=!0;try{this.#t.writeParameter("value",i)}finally{this.#e=!1}}}}}var $t=(0,p.defineComponent)({name:"horizontalSlider",tag:"gramlot-horizontal-slider",base:g,mixins:[m,f],parameters:lt,sourceContext:!0,implementation:ct(!1)}),Gt=(0,p.defineComponent)({name:"verticalSlider",tag:"gramlot-vertical-slider",base:g,mixins:[m,f],parameters:lt,sourceContext:!0,implementation:ct(!0)}),Zt=(0,p.defineComponent)({name:"numberTextBox",tag:"gramlot-number-text-box",base:A,mixins:[m,f],parameters:{value:{dtype:["L","R","N"],nullable:!0,binding:"twoWay"},dtype:{dtype:"T",default:"R"},min:{dtype:"R",nullable:!0,binding:"read"},max:{dtype:"R",nullable:!0,binding:"read"}},implementation:rt}),Yt=(0,p.defineComponent)({name:"dateTextBox",tag:"gramlot-date-text-box",base:A,mixins:[m,f],parameters:{value:{dtype:"D",nullable:!0,binding:"twoWay"},workdate:{dtype:"T",nullable:!0,binding:"read"},period_to:{dtype:"T",nullable:!0},calendar:{dtype:"B",default:!0,binding:"read"}},implementation:ot}),Xt=(0,p.defineComponent)({name:"dateCalendar",tag:"gramlot-date-calendar",base:R,mixins:[m,f],parameters:{},implementation:s=>class extends s{}}),Kt=(0,p.defineComponent)({name:"timeTextBox",tag:"gramlot-time-text-box",base:A,mixins:[m,f],parameters:{value:{dtype:"H",nullable:!0,binding:"twoWay"}},implementation:st}),Jt=(0,p.defineComponent)({name:"filteringSelect",tag:"gramlot-filtering-select",base:C,mixins:[m,f],parameters:{values:{dtype:"T",default:"",binding:"read"},separator:{dtype:"T",default:",",binding:"read"}},implementation:q}),Qt=(0,p.defineComponent)({name:"callbackSelect",tag:"gramlot-callback-select",base:C,mixins:[m,f],parameters:{callback:{dtype:"T"}},implementation:at}),te=(0,p.defineComponent)({name:"comboBox",tag:"gramlot-combo-box",base:C,mixins:[m,f],sourceContext:!0,parameters:{values:{dtype:"T",default:"",binding:"read"},separator:{dtype:"T",default:",",binding:"read"},store:{dtype:"X",nullable:!0,default:null,binding:"read"}},implementation:s=>class extends q(s){static get constrained(){return!1}#t;#e=null;setSourceContext(t){this.#t=t}projectAttributes(t,e,i=null){let r=this.#t.attrDatapath("store");return r===null?this.#e=null:(this.#e?.path!==r||i===null||i===r||i.startsWith(`${r}.`)||r.startsWith(`${i}.`))&&(this.#e={path:r}),super.projectAttributes(t,e)}get choiceSource(){return this.#e??super.choiceSource}loadChoices(t){let e=this.#t.getStaticData(this.#t.attrDatapath("store"));return this.constructor.loadChoices({...this.parameters,store:e},this.pageContext,t)}}}),ee=(0,p.defineComponent)({name:"dbSelect",tag:"gramlot-db-select",base:C,mixins:[m,f],parameters:{...W,value:{dtype:["T","L"],nullable:!0,binding:"twoWay"},autoSelect:{dtype:"B",default:!1,binding:"read"}},implementation:H}),ie=(0,p.defineComponent)({name:"dbComboBox",tag:"gramlot-db-combo-box",base:C,mixins:[m,f],parameters:W,implementation:s=>class extends H(s){static get constrained(){return!1}}}),re=(0,p.defineComponent)({name:"checkBoxText",tag:"gramlot-check-box-text",sourceContext:!0,base:U,mixins:[m,f],parameters:{value:{dtype:"T",nullable:!0,binding:"twoWay"},values:{dtype:["T","X"],default:"",binding:"read"},cols:{dtype:"L",default:1,binding:"read"},popup:{dtype:"B",default:!1,binding:"read"},hierarchical:{dtype:"B",default:!1,binding:"read"},checkChildren:{dtype:"B",default:!0,binding:"read"},identifier:{dtype:"T",binding:"read"},labelAttribute:{dtype:"T",binding:"read"},dbtable:{dtype:"T",binding:"read"},method:{dtype:"T",binding:"read"},caption_field:{dtype:"T",binding:"read"},order_by:{dtype:"T",binding:"read"},condition:{dtype:"T",binding:"read"}},implementation:Z}),ji=O({name:"inputs",dependencies:[Ut],components:[K,Rt,qt,Ft,Wt,Ht,It,zt,$t,Gt,Zt,Yt,Kt,Jt,Qt,te,ee,ie,re,Xt]});export{Qt as CallbackSelect,re as CheckBoxText,qt as Checkbox,zt as Colorpicker,te as ComboBox,Xt as DateCalendar,Yt as DateTextBox,ie as DbComboBox,ee as DbSelect,Jt as FilteringSelect,$t as HorizontalSlider,Zt as NumberTextBox,Ht as Passwordbox,It as RadioButton,Ft as RadioButtonText,Wt as TextBoxArea,Rt as Textbox,Kt as TimeTextBox,Gt as VerticalSlider,ji as default};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export {default} from "./collection.js";
|
|
2
2
|
export * from "./collection.js";
|
|
3
|
-
export const buildId = "sha256:
|
|
3
|
+
export const buildId = "sha256:ce7739715731d46ee8154e34725c8795cb477021fcb2ca61f70ad7420c00d6e4";
|
|
@@ -8,6 +8,6 @@ mygramlot = GramlotCollection(
|
|
|
8
8
|
module="assets/index.js",
|
|
9
9
|
css=(),
|
|
10
10
|
dependencies=(),
|
|
11
|
-
build_id="sha256:
|
|
11
|
+
build_id="sha256:945c1f71eb89a0feed45e100104ee10ff92173b501ea2e57cc1795b39095a680",
|
|
12
12
|
files=("assets/collection.js", "assets/index.js", "commands.json", "grammar.json",),
|
|
13
13
|
)
|